Преглед изворни кода

新增总仓库存查询接口

shenjingwei пре 1 месец
родитељ
комит
170bbfb36c

+ 72 - 0
src/custom/restcontroller/crm/agent/stock/SQL/总仓库存查询.sql

@@ -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

+ 9 - 4
src/custom/restcontroller/crm/agent/stock/invbal.java

@@ -5,7 +5,6 @@ import common.Controller;
 import common.YosException;
 import common.annotation.API;
 import common.data.QuerySQL;
-import common.data.Row;
 import common.data.Rows;
 import common.data.SQLFactory;
 import restcontroller.R;
@@ -18,7 +17,7 @@ public class invbal extends Controller {
 
     @API(title = "美大CRM_经销商_即时库存查询", type = API.Type.PageQuery, apiversion = R.ID2026031715005701.v1.class)
     public String sys_enterprise_invbal_querylist() throws YosException {
-        QuerySQL querySQL = SQLFactory.createQuerySQL(this, "sys_enterprise_invbal", "qty").setTableAlias("t1");
+        QuerySQL querySQL = SQLFactory.createQuerySQL(this, "sys_enterprise_invbal", "sys_enterprise_itemid", "qty").setTableAlias("t1");
         querySQL.addJoinTable(JOINTYPE.inner, "sys_enterprise_item", "t2", "t1.sys_enterprise_itemid=t2.sys_enterprise_itemid", "itemno", "itemname", "model", "spec", "color");
         querySQL.addJoinTable(JOINTYPE.inner, "sys_enterprise_stock", "t3", "t1.sys_enterprise_stockid=t3.sys_enterprise_stockid", "stockno", "stockname");
         querySQL.addJoinTable(JOINTYPE.left, "plm_unit", "t4", "t1.unitid=t4.unitid", "unitname");
@@ -30,8 +29,14 @@ public class invbal extends Controller {
 
     @API(title = "美大CRM_经销商_总仓库存查询", type = API.Type.PageQuery, apiversion = R.ID2026031715111701.v1.class)
     public String sys_enterprise_invbal_total_querylist() throws YosException {
-
-        return getSucReturnObject().setData(new Rows()).toString();
+        SQLFactory sqlFactory = new SQLFactory(this, "总仓库存查询");
+        sqlFactory.addParameter("sys_enterpriseid", sys_enterpriseid);
+        QuerySQL querySQL = SQLFactory.createQuerySQL(this, "sys_enterprise_item", "itemno", "itemname", "model", "safeqty", "spec").setTableAlias("t10");
+        querySQL.addJoinTable(JOINTYPE.left, "plm_item", "t11", "t10.itemid=t11.itemid", "topclassnum");
+        querySQL.addJoinTable(JOINTYPE.inner, sqlFactory, "t12", "t10.sys_enterprise_itemid=t2.sys_enterprise_itemid", "icqty", "undeliqty", "unreceiveqty", "willoutqty");
+        querySQL.setWhere("t10.sys_enterpriseid", sys_enterpriseid);
+        Rows icrows = querySQL.query();
+        return getSucReturnObject().setData(icrows).toString();
     }
 
 }