瀏覽代碼

新增发货单关闭接口

hu 2 年之前
父節點
當前提交
549ea1cd54

+ 4 - 0
src/custom/restcontroller/R.java

@@ -4648,6 +4648,10 @@ public class R {
         public static class v1 {
         }
     }
+    public static class ID20230404134703 {
+        public static class v1 {
+        }
+    }
 
 }
 

+ 1 - 0
src/custom/restcontroller/webmanage/sale/dispatch/SQL/发货单关闭.sql

@@ -0,0 +1 @@
+update sa_dispatch set status='关闭',closeby=$closeby$,closedate=CURRENT_TIMESTAMP where sa_dispatchid = $sa_dispatchid$ and siteid=$siteid$

+ 69 - 10
src/custom/restcontroller/webmanage/sale/dispatch/dispatch.java

@@ -335,15 +335,7 @@ public class dispatch extends Controller {
         sqlList.add(DataContrlLog.createLog(this, "sa_dispatch", sa_dispatchid, "审核", "发货单审核成功").getSQL());
         dbConnect.runSqlUpdate(sqlList);
 
-        //判断当前订单是否已发完货,如果发完,则生把订单变为关闭状态
-        //总数量
-        Rows totalRows = dbConnect.runSqlQuery("select * from sa_orderitems where siteid='" + siteid + "' and sa_orderid=" + sa_orderid);
-        //已发完数量
-        Rows deliRows = dbConnect.runSqlQuery("select * from sa_orderitems where undeliqty=0 and siteid='" + siteid + "' and sa_orderid=" + sa_orderid);
-
-        if (totalRows.size() == deliRows.size()) {
-            dbConnect.runSqlUpdate("update sa_order set status='关闭' where sa_orderid=" + sa_orderid + " and siteid='" + siteid + "'");
-        }
+
         Executor.sendEml(this, "dispatchrecheck", sa_dispatchid,new ArrayList<>());
         return getSucReturnObject().toString();
 
@@ -386,7 +378,6 @@ public class dispatch extends Controller {
                 sqlList.add("update sa_orderitems set undeliqty=" + rowsMap.get(row.getLong("sa_orderitemsid")).get(0).getBigDecimal("undeliqty").add(row.getBigDecimal("qty")) + ",deliedqty=" + rowsMap.get(row.getLong("sa_orderitemsid")).get(0).getBigDecimal("deliedqty").subtract(row.getBigDecimal("qty")) + " where sa_orderitemsid=" + row.getLong("sa_orderitemsid"));
             }
         }
-        sqlList.add("update sa_order set status='审核' where sa_orderid=" + sa_orderid + " and siteid='" + siteid + "'");
         SQLFactory sqlFactoryupdate = new SQLFactory(this, "发货单反审核");
         sqlFactoryupdate.addParameter("siteid", siteid);
         sqlFactoryupdate.addParameter("sa_dispatchid", sa_dispatchid);
@@ -397,6 +388,57 @@ public class dispatch extends Controller {
         return getSucReturnObject().toString();
     }
 
+
+    @API(title = "手工关闭", apiversion = R.ID20230404134703.v1.class)
+    @CACHEING_CLEAN(apiClass = {Order.class, OrderItems.class, restcontroller.sale.order.Order.class, dispatch.class, dispatchItems.class, R.ID20230320160203.v1.class})
+    public String unclose() throws YosException {
+        Long sa_dispatchid = content.getLong("sa_dispatchid");
+        Long sa_orderid = 0L;
+        Rows rows = dbConnect.runSqlQuery("select sa_dispatchid,status,billno,sa_orderid from sa_dispatch where sa_dispatchid ='"
+                + sa_dispatchid + "' and  siteid='" + siteid + "'");
+        if (rows.isEmpty()) {
+            return getErrReturnObject().setErrMsg("该发货单不存在")
+                    .toString();
+        } else {
+            sa_orderid = rows.get(0).getLong("sa_orderid");
+            if (!rows.get(0).getString("status").equals("复核")) {
+                return getErrReturnObject().setErrMsg("单号为:【" + rows.get(0).getString("billno") + "】的发货单为非复核状态,无法手工关闭")
+                        .toString();
+            }
+        }
+
+        ArrayList<String> sqlList = new ArrayList<>();
+
+        Rows rowsOrderDetail = dbConnect.runSqlQuery("select t1.undeliqty,t1.deliedqty,t1.qty,t1.sa_orderitemsid from sa_orderitems t1 where t1.sa_orderitemsid in (select sa_orderitemsid from sa_dispatch_items where sa_dispatchid="+ sa_dispatchid+")" );
+        RowsMap rowsMap = rowsOrderDetail.toRowsMap("sa_orderitemsid");
+        Rows rowsDispatchDetail = dbConnect.runSqlQuery("select t1.qty,t1.outwarehouseqty,t1.sa_orderitemsid,t1.rowno,t2.itemname from sa_dispatch_items t1 left join plm_item t2 on t1.itemid=t2.itemid and t1.siteid=t2.siteid  where t1.sa_dispatchid=" + sa_dispatchid);
+        if (!rowsDispatchDetail.isEmpty()) {
+            for (Row row : rowsDispatchDetail) {
+//				if(rowsMap.get(row.getLong("sa_orderitemsid")).isEmpty()) {
+//					return getErrReturnObject().setErrMsg("行号为:【" + row.getString("rowno") + "】的发货单明细不存在对应得订单行,无法审核")
+//							.toString();
+//				}
+//				if(row.getBigDecimal("qty").compareTo(rowsMap.get(row.getLong("sa_orderitemsid")).get(0).getBigDecimal("undeliqty"))==1) {
+//					return getErrReturnObject().setErrMsg("行号为:【" + row.getString("rowno") + "】的发货单明细的数量大于对应订单行的未发货数量,无法审核")
+//							.toString();
+//				}
+                sqlList.add("update sa_orderitems set undeliqty=" + rowsMap.get(row.getLong("sa_orderitemsid")).get(0).getBigDecimal("undeliqty").add(row.getBigDecimal("qty").subtract(row.getBigDecimal("outwarehouseqty"))) + ",deliedqty=" + rowsMap.get(row.getLong("sa_orderitemsid")).get(0).getBigDecimal("deliedqty").subtract(row.getBigDecimal("qty").subtract(row.getBigDecimal("outwarehouseqty"))) + " where sa_orderitemsid=" + row.getLong("sa_orderitemsid"));
+            }
+        }
+        Rows orderRows =dbConnect.runSqlQuery("select distinct t1.sa_orderid from sa_orderitems t1 inner join sa_dispatch_items t2 on t1.siteid=t2.siteid and t1.sa_orderitemsid=t2.sa_orderitemsid where t1.siteid='" + siteid + "' and t2.sa_dispatchid=" + sa_dispatchid);
+        for (Row row:orderRows) {
+            dbConnect.runSqlUpdate("update sa_order set status='审核' where sa_orderid=" + row.getLong("sa_orderid") + " and siteid='" + siteid + "'");
+        }
+        SQLFactory sqlFactoryupdate = new SQLFactory(this, "发货单关闭");
+        sqlFactoryupdate.addParameter("siteid", siteid);
+        sqlFactoryupdate.addParameter("sa_dispatchid", sa_dispatchid);
+        sqlFactoryupdate.addParameter("closeby", username);
+        sqlList.add(sqlFactoryupdate.getSQL());
+        sqlList.add(DataContrlLog.createLog(this, "sa_dispatch", sa_dispatchid, "手工关闭", "发货单手工关闭成功").getSQL());
+        dbConnect.runSqlUpdate(sqlList);
+        return getSucReturnObject().toString();
+    }
+
     @API(title = "复核反复核", apiversion = R.ID20221114135803.v1.class)
     @CACHEING_CLEAN(apiversions = {R.ID20221114135303.v1.class, R.ID20221114135403.v1.class, R.ID20230320160203.v1.class})
     public String recheck() throws YosException {
@@ -422,6 +464,23 @@ public class dispatch extends Controller {
         SQLFactory sqlFactoryupdate;
         if (isrecheck) {
             sqlFactoryupdate = new SQLFactory(this, "发货单复核");
+            Rows orderRows =dbConnect.runSqlQuery("select distinct t1.sa_orderid from sa_orderitems t1 inner join sa_dispatch_items t2 on t1.siteid=t2.siteid and t1.sa_orderitemsid=t2.sa_orderitemsid where t1.siteid='" + siteid + "' and t2.sa_dispatchid=" + sa_dispatchid);
+
+            //判断当前订单是否已发完货,如果发完,则生把订单变为关闭状态
+            //总数量
+            Rows totalRows = dbConnect.runSqlQuery("select count(1) count,sa_orderid from sa_orderitems where siteid='" + siteid + "' group by sa_orderid");
+            RowsMap totalRowsMap=totalRows.toRowsMap("sa_orderid");
+            //已发完数量
+            Rows deliRows = dbConnect.runSqlQuery("select count(1) count,sa_orderid from sa_orderitems where undeliqty=0 and siteid='" + siteid + "' group by sa_orderid");
+            RowsMap deliRowsMap=deliRows.toRowsMap("sa_orderid");
+            for (Row row:orderRows) {
+                if(totalRowsMap.containsKey(row.getString("sa_orderid")) && deliRowsMap.containsKey(row.getString("sa_orderid"))){
+                    if (totalRowsMap.get(row.getString("sa_orderid")).get(0).getLong("count") ==deliRowsMap.get(row.getString("sa_orderid")).get(0).getLong("count")) {
+                        dbConnect.runSqlUpdate("update sa_order set status='关闭' where sa_orderid=" + row.getLong("sa_orderid") + " and siteid='" + siteid + "'");
+                    }
+                }
+            }
+
             sqlList.add(DataContrlLog.createLog(this, "sa_dispatch", sa_dispatchid, "复核", "发货单复核成功").getSQL());
         } else {
             sqlFactoryupdate = new SQLFactory(this, "发货单反复核");