|
|
@@ -0,0 +1,72 @@
|
|
|
+select tt1.sys_enterpriseid,
|
|
|
+ tt1.sys_enterprise_itemid,
|
|
|
+ tt1.icqty,
|
|
|
+ tt1.undeliqty,
|
|
|
+ tt1.unreceiveqty,
|
|
|
+ tt1.willoutqty
|
|
|
+from (select t.sys_enterpriseid,
|
|
|
+ t.sys_enterprise_itemid,
|
|
|
+ sum(t.icqty) as icqty,
|
|
|
+ sum(t.undeliqty) as undeliqty,
|
|
|
+ sum(t.unreceiveqty) as unreceiveqty,
|
|
|
+ sum(t.willoutqty) as willoutqty
|
|
|
+ from (select t1.sys_enterpriseid,
|
|
|
+ t1.sys_enterprise_itemid,
|
|
|
+ t1.qty as icqty,
|
|
|
+ 0 as undeliqty,
|
|
|
+ 0 as unreceiveqty,
|
|
|
+ 0 as willoutqty
|
|
|
+ from sys_enterprise_invbal t1
|
|
|
+ inner join sys_enterprise_item t2 on t1.sys_enterpriseid = t2.sys_enterpriseid and
|
|
|
+ t1.sys_enterprise_itemid = t2.sys_enterprise_itemid
|
|
|
+ where t1.sys_enterpriseid = $sys_enterpriseid$
|
|
|
+ and t1.qty <> 0
|
|
|
+ union all
|
|
|
+ select t1.sys_enterpriseid,
|
|
|
+ t3.sys_enterprise_itemid,
|
|
|
+ 0 as icqty,
|
|
|
+ sum(t2.undeliqty) as undeliqty,
|
|
|
+ 0 as unreceiveqty,
|
|
|
+ 0 as willoutqty
|
|
|
+ from sa_order t1
|
|
|
+ inner join sa_orderitems t2
|
|
|
+ on t1.sa_orderid = t2.sa_orderid
|
|
|
+ inner join sys_enterprise_item t3
|
|
|
+ on t1.sys_enterpriseid = t3.sys_enterpriseid and t2.itemid = t3.itemid
|
|
|
+ where t2.undeliqty > 0
|
|
|
+ and t1.sys_enterpriseid = $sys_enterpriseid$
|
|
|
+ and t1.status in ('提交', '审核')
|
|
|
+ group by t1.sys_enterpriseid, t3.sys_enterprise_itemid
|
|
|
+ union ALL
|
|
|
+ select t1.sys_enterpriseid,
|
|
|
+ t3.sys_enterprise_itemid,
|
|
|
+ 0 as icqty,
|
|
|
+ 0 as undeliqty,
|
|
|
+ sum(t2.qty) as unreceiveqty,
|
|
|
+ 0 as willoutqty
|
|
|
+ from st_stockbill t1
|
|
|
+ inner join st_stockbill_items t2
|
|
|
+ on t1.st_stockbillid = t2.st_stockbillid
|
|
|
+ inner join sys_enterprise_item t3
|
|
|
+ on t1.sys_enterpriseid = t3.sys_enterpriseid and t2.itemid = t3.itemid
|
|
|
+ where t1.status in ('审核')
|
|
|
+ and t1.sys_enterpriseid = $sys_enterpriseid$
|
|
|
+ and t1.isreceiver = 0
|
|
|
+ and t1.type = '销售出库'
|
|
|
+ group by t1.sys_enterpriseid, t2.itemid, t3.sys_enterprise_itemid
|
|
|
+ union ALL
|
|
|
+ select t2.sys_enterpriseid,
|
|
|
+ t2.sys_enterprise_itemid,
|
|
|
+ 0 as icqty,
|
|
|
+ 0 as undeliqty,
|
|
|
+ 0 as unreceiveqty,
|
|
|
+ sum(t1.qty - t1.outqty) as willoutqty
|
|
|
+ from sa_custorderitems t1
|
|
|
+ inner join sys_enterprise_item t2
|
|
|
+ on t1.sys_enterprise_itemid = t2.sys_enterprise_itemid
|
|
|
+ inner join sa_custorder t3 on t1.sa_custorderid = t3.sa_custorderid
|
|
|
+ where t1.qty - t1.outqty > 0
|
|
|
+ and t2.sys_enterpriseid = $sys_enterpriseid$
|
|
|
+ and t3.`status` in ('待出库', '部分出库')
|
|
|
+ group by t2.sys_enterpriseid, t2.itemid, t2.sys_enterprise_itemid) t
|
|
|
+ group by t.sys_enterpriseid, t.sys_enterprise_itemid) tt1
|