|
|
@@ -1,25 +1,10 @@
|
|
|
-select t2.sonum,
|
|
|
- t2.billdate,
|
|
|
- t4.itemno,
|
|
|
- t4.itemname,
|
|
|
- t1.price,
|
|
|
- t1.qty - ifnull(t3.sumoutwarehouseqty, 0) undeliqty,
|
|
|
- (t1.qty - ifnull(t3.sumoutwarehouseqty, 0)) * t1.price undeliamount
|
|
|
-from sa_orderitems t1
|
|
|
- inner join sa_order t2 on t1.sa_orderid = t2.sa_orderid and t1.siteid = t2.siteid
|
|
|
- left join (select t1.sa_orderitemsid, t1.siteid, sum(t1.outwarehouseqty) sumoutwarehouseqty
|
|
|
- from sa_dispatch_items t1
|
|
|
- inner join sa_orderitems t2
|
|
|
- on t1.sa_orderitemsid = t2.sa_orderitemsid and t1.siteid = t2.siteid
|
|
|
- inner join sa_dispatch t3 on t1.siteid = t3.siteid and t3.sa_dispatchid = t1.sa_dispatchid
|
|
|
- where t1.outwarehouseqty > 0
|
|
|
- and t1.siteid = $siteid$
|
|
|
- and t3.status in ('复核','关闭','手工关闭')
|
|
|
- and $where2$
|
|
|
- group by t1.sa_orderitemsid, t1.siteid) t3
|
|
|
- on t1.sa_orderitemsid = t3.sa_orderitemsid and t1.siteid = t3.siteid
|
|
|
- left join plm_item t4 on t1.itemid = t4.itemid and t1.siteid = t4.siteid
|
|
|
-where t2.status = '审核'
|
|
|
- and t1.siteid = $siteid$
|
|
|
- and $where$
|
|
|
- and t1.qty - ifnull(t3.sumoutwarehouseqty, 0) > 0
|
|
|
+select t3.sonum,t3.billdate,t5.itemno,t5.itemname,t2.sa_orderitemsid,t4.price,
|
|
|
+t4.qty - sum( t2.outwarehouseqty ) undeliqty,
|
|
|
+(t4.qty - sum( t2.outwarehouseqty )) * t4.price undeliamount
|
|
|
+from sa_dispatch t1
|
|
|
+inner join sa_dispatch_items t2 on t1.siteid=t2.siteid and t1.sa_dispatchid=t2.sa_dispatchid
|
|
|
+inner join sa_order t3 on t1.siteid=t3.siteid and t1.sa_orderid=t3.sa_orderid and t3.status='审核'
|
|
|
+inner join sa_orderitems t4 on t3.siteid=t4.siteid and t3.sa_orderid=t4.sa_orderid and t2.sa_orderitemsid=t4.sa_orderitemsid
|
|
|
+inner join plm_item t5 on t4.siteid=t5.siteid and t4.itemid=t5.itemid
|
|
|
+where t1.siteid = $siteid$ AND t2.outwarehouseqty>0 and $where$
|
|
|
+GROUP BY t3.sonum,t3.billdate,t5.itemno,t5.itemname,t2.sa_orderitemsid,t4.price ,t4.qty having t4.qty - sum( t2.outwarehouseqty ) > 0
|