REPORTFORM;invcard_col1.frf
TITLE;รายงานความเคลื่อนไหวแสดงต้นทุน
SQL;drop table if exists _invcard_col&
SQL;
SQL;create table _invcard_col
SQL;select invcard.ID, invmst.XDESC,
SQL;invcard.DOCNO, invcard.DATEDOC, invcard.TRTYPE,invcard.LOCID,cost,
SQL;if(invcard.TRTYPE="01",invcard.MQUAN,0) as QtyIn,
SQL;if(invcard.TRTYPE="01",invcard.COSTAMT,0) as AmtIn,
SQL;if(invcard.TRTYPE="02",invcard.MQUAN,0) as QtyOut,
SQL;if(invcard.TRTYPE="02",invcard.COSTAMT,0) as AmtOut,
SQL;0000000000.0000 as QtyBeg,0000000000.0000 as AmtBeg, 
SQL;invmst.UNIT,SPACE(50) as xremark,1 as xline
SQL;from 
SQL;invcard left join invmst on invcard.ID = invmst.ID
SQL;where invcard.id >= :m11 and invcard.id <= :m12
SQL;and invcard.datedoc >= :m21 and invcard.datedoc <= :m22
SQL;order by id,datedoc,trtype,docno&
SQL;
SQL;insert into _invcard_col
SQL;select invcard.ID, invmst.XDESC,
SQL;"ยอดยกมา", "", "00","",0,
SQL;0,
SQL;0,
SQL;0,
SQL;0,
SQL;sum(repbal) as QtyBeg,sum(costrepbal) as AmtBeg, 
SQL;invmst.UNIT,"",0 as xline
SQL;from 
SQL;invcard left join invmst on invcard.ID = invmst.ID
SQL;where invcard.id >= :m11 and invcard.id <= :m12
SQL;and invcard.datedoc < :m21 
SQL;group by invcard.ID, invmst.XDESC,invmst.unit
SQL;order by id,datedoc,trtype,docno&
SQL;
SQL;update _invcard_col inner join arcard on _invcard_col.docno = arcard.docno
SQL;inner join armst on arcard.accid = armst.accid
SQL;set  _invcard_col.xremark = concat("ขาย  ",arcard.accid," ",armst.xcomp)
SQL;where left(_invcard_col.docno,2) = "IV"&
SQL;
SQL;update _invcard_col inner join arcard on _invcard_col.docno = arcard.docno
SQL;inner join armst on arcard.accid = armst.accid
SQL;set  _invcard_col.xremark = concat("รับคืน  ",arcard.accid," ",armst.xcomp)
SQL;where left(_invcard_col.docno,2) = "RI"&
SQL;
SQL;update _invcard_col inner join apcard on _invcard_col.docno = apcard.docno
SQL;inner join apmst on apcard.accid = apmst.accid
SQL;set  _invcard_col.xremark = concat("ซื้อ  ",apcard.accid," ",apmst.xcomp)
SQL;where left(_invcard_col.docno,2) = "RC"&
SQL;
SQL;update _invcard_col inner join apcard on _invcard_col.docno = apcard.docno
SQL;inner join apmst on apcard.accid = apmst.accid
SQL;set  _invcard_col.xremark = concat("ส่งคืน  ",apcard.accid," ",apmst.xcomp)
SQL;where left(_invcard_col.docno,2) = "RO"&
SQL;
SQL;select * from _invcard_col
SQL;order by id,xline,datedoc,trtype,docno
CONDITION;ตั้งแต่รหัส~ID~Chr~2~SELECT ID FROM INVMST~INV
CONDITION;ตั้งแต่วันที่~DATEDOC~Date~2~~
