' Il seguente snippet mostra come sia possibile generare movimenti di magazzino tramite un task a partire dal materiale registrato in un movimento di intervento
' Nell'esempio il magazzino di prelievo si chiama "MGES" e la causale utilizzata è "SCA".
dim QWSess as QWSession
QWSess=DB.QWSession
MovMag_Apertura_Archivi(QWSess)
dim q as new qwTable()
q.database=DB
q.sql="select distinct * from MOVMAG where CANC=0 and TIPODOC='**' and NUMDOC like 'MS%' and not exists (select * from RICREVST where NUMDOC='MS'+replace(ricrevst.NUMMOV,' ','0') and movmag.CODART=ricrevst.CODART and QTMOV=QTA)"
q.requestlive=false
q.active=true
dim ok as boolean
while not q.rowset.endofset
ok=MovMag_Elimina(QWSess,q.rowset.fields("TIPODOC").value,q.rowset.fields("NUMDOC").value)
if not ok
Write_LogDoc(QWSess,"**","QDAEMON",100,"Errore cancellando il movimento di magazzino da assistenza "+q.rowset.fields("NUMDOC").value)
End If
q.rowset.next()
end while
q.active=false
q.sql="select r.NUMMOV,r.CODART,r.QTA,m.DATA from RICREVST r join MOVSTRUM m on m.NUMMOV=r.NUMMOV where m.DATA>convert(datetime,'07/03/2022',103) and not exists(select * from MOVMAG where CANC=0 and TIPODOC='**' and NUMDOC='MS'+replace(r.NUMMOV,' ','0') and movmag.CODART=r.CODART and QTMOV=QTA)"
q.requestlive=false
q.active=true
dim errmsg as string
while not q.rowset.endofset()
ok=MovMag_Crea_Nuovo(QWSess, q.rowset.fields("CODART").value,"SCA", "MGES", "", "**", "MS"+replace(q.rowset.fields("NUMMOV").value," ","0"), q.rowset.fields("QTA").value,0,nothing,dttod(q.rowset.fields("DATA").value),errmsg)
if not ok
errmsg="Errore nella generazione del movimento di magazzino da assistenza per il movimento n. "+q.rowset.fields("NUMMOV").value+": "+errmsg
Write_LogDoc(QWSess,"**","QDAEMON",100,errmsg)
end if
q.rowset.next()
end while
q.active=false