Ver Fonte

发货单复核检测到erp地址为空时不调用

eganwu há 1 ano atrás
pai
commit
38d927a280

+ 90 - 80
src/custom/restcontroller/webmanage/sale/dispatch/dispatch.java

@@ -526,19 +526,21 @@ public class dispatch extends Controller {
         //对接erp生成erp发货单
         if (Parameter.get("system.ccerp_dockswitch").equalsIgnoreCase("true")) {
             ERPDocking erpDocking = new ERPDocking(siteid);
-            String result = erpDocking.closeErpSainvoice(rows.get(0).getString("billno"), true, this, sa_dispatchid);
-            if (!result.equals("true")) {
-                return getErrReturnObject().setErrMsg(result).toString();
-            } else {
-                JSONArray jsonArray = erpDocking.queryErpSainvoice(rows.get(0).getString("billno"));
-                ArrayList<String> dispatchsqlList = new ArrayList<>();
-                if (!jsonArray.isEmpty()) {
-                    for (Object object1 : jsonArray) {
-                        JSONObject jsonObject = (JSONObject) object1;
-                        dispatchsqlList.add("update sa_dispatch_items set outwarehouseqty=" + jsonObject.getBigDecimalValue("fqty1") + " where rowno =" + jsonObject.getIntValue("frownum") + " and sa_dispatchid='" + sa_dispatchid + "' and siteid='" + siteid + "'");
+            if (!erpDocking.getUrl().isEmpty()) {
+                String result = erpDocking.closeErpSainvoice(rows.get(0).getString("billno"), true, this, sa_dispatchid);
+                if (!result.equals("true")) {
+                    return getErrReturnObject().setErrMsg(result).toString();
+                } else {
+                    JSONArray jsonArray = erpDocking.queryErpSainvoice(rows.get(0).getString("billno"));
+                    ArrayList<String> dispatchsqlList = new ArrayList<>();
+                    if (!jsonArray.isEmpty()) {
+                        for (Object object1 : jsonArray) {
+                            JSONObject jsonObject = (JSONObject) object1;
+                            dispatchsqlList.add("update sa_dispatch_items set outwarehouseqty=" + jsonObject.getBigDecimalValue("fqty1") + " where rowno =" + jsonObject.getIntValue("frownum") + " and sa_dispatchid='" + sa_dispatchid + "' and siteid='" + siteid + "'");
+                        }
                     }
+                    dbConnect.runSqlUpdate(dispatchsqlList);
                 }
-                dbConnect.runSqlUpdate(dispatchsqlList);
             }
         }
         ArrayList<String> sqlList = new ArrayList<>();
@@ -613,13 +615,15 @@ public class dispatch extends Controller {
             }
             if (Parameter.get("system.ccerp_dockswitch").equalsIgnoreCase("true")) {
                 ERPDocking erpDocking = new ERPDocking(siteid);
-                String result = erpDocking.closeErpSainvoiceRow(row.getString("billno"), this, row.getLong("rowno"), row.getString("itemno"), row.getLong("sa_dispatchid"));
-                if (!result.equals("true")) {
-                    batchDeleteErr.addErr(row.getLong("sa_dispatch_itemsid"), result);
-                    continue;
-                } else {
-                    sqlList.add("update sa_dispatch_items set isclose=1 where sa_dispatch_itemsid=" + row.getLong("sa_dispatch_itemsid"));
-                    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"));
+                if (!erpDocking.getUrl().isEmpty()) {
+                    String result = erpDocking.closeErpSainvoiceRow(row.getString("billno"), this, row.getLong("rowno"), row.getString("itemno"), row.getLong("sa_dispatchid"));
+                    if (!result.equals("true")) {
+                        batchDeleteErr.addErr(row.getLong("sa_dispatch_itemsid"), result);
+                        continue;
+                    } else {
+                        sqlList.add("update sa_dispatch_items set isclose=1 where sa_dispatch_itemsid=" + row.getLong("sa_dispatch_itemsid"));
+                        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"));
+                    }
                 }
             }
         }
@@ -630,12 +634,14 @@ public class dispatch extends Controller {
         if (sumcountRows.get(0).getLong("sumcount") == closecountRows.get(0).getLong("closecount")) {
             if (Parameter.get("system.ccerp_dockswitch").equalsIgnoreCase("true")) {
                 ERPDocking erpDocking = new ERPDocking(siteid);
-                String result = erpDocking.closeErpSainvoice(rows.get(0).getString("billno"), true, this, rows.get(0).getLong("sa_dispatchid"));
-                if (!result.equals("true")) {
-                    return getErrReturnObject().setErrMsg(result).toString();
-                } else {
-                    dbConnect.runSqlUpdate("update sa_dispatch set status='手工关闭',closeby='" + username + "',closedate=CURRENT_TIMESTAMP  where sa_dispatchid=" + rows.get(0).getLong("sa_dispatchid"));
-                    dbConnect.runSqlUpdate(DataContrlLog.createLog(this, "sa_dispatch", rows.get(0).getLong("sa_dispatchid"), "手工关闭", "发货单手工关闭成功").getSQL());
+                if (!erpDocking.getUrl().isEmpty()) {
+                    String result = erpDocking.closeErpSainvoice(rows.get(0).getString("billno"), true, this, rows.get(0).getLong("sa_dispatchid"));
+                    if (!result.equals("true")) {
+                        return getErrReturnObject().setErrMsg(result).toString();
+                    } else {
+                        dbConnect.runSqlUpdate("update sa_dispatch set status='手工关闭',closeby='" + username + "',closedate=CURRENT_TIMESTAMP  where sa_dispatchid=" + rows.get(0).getLong("sa_dispatchid"));
+                        dbConnect.runSqlUpdate(DataContrlLog.createLog(this, "sa_dispatch", rows.get(0).getLong("sa_dispatchid"), "手工关闭", "发货单手工关闭成功").getSQL());
+                    }
                 }
             }
         }
@@ -654,35 +660,37 @@ public class dispatch extends Controller {
         RowsMap rowsMap = rowsdetail.toRowsMap("sa_dispatchid");
         ArrayList<String> sqlList = new ArrayList<>();
         ERPDocking erpDocking = new ERPDocking(siteid);
-        for (Row row : rows) {
-            String sa_dispatchid = row.getString("sa_dispatchid");
-            String billno = row.getString("billno");
-            String result = erpDocking.closeErpSainvoice(billno, false, this, row.getLong("sa_dispatchid"));
-            if (result.equals("true")) {
-                sqlList.add("update sa_dispatch set status='关闭' where sa_dispatchid='" + sa_dispatchid + "' and siteid='CCYOSG'");
-                SQLFactory sqlFactory = new SQLFactory(new DataContrlLog(), "数据操作日志新增");
-                sqlFactory.addParameter("ownertable", "sa_dispatch");
-                sqlFactory.addParameter("ownerid", sa_dispatchid);
-                sqlFactory.addParameter("action", "自动关闭");
-                sqlFactory.addParameter("remarks", "发货单自动关闭成功");
-                sqlFactory.addParameter("actionuserid", "1");
-                sqlFactory.addParameter("actionby", "admin");
-                sqlFactory.addParameter("siteid", "CCYOSG");
-                sqlList.add(sqlFactory.getSQL());
-            } else {
-                logger.info("发货单自动关闭错误:" + result);
-                return getErrReturnObject().setErrMsg(result).toString();
-            }
-            JSONArray jsonArray = erpDocking.queryErpSainvoice(billno);
-            if (!jsonArray.isEmpty()) {
-                for (Object object : jsonArray) {
-                    JSONObject jsonObject = (JSONObject) object;
-                    sqlList.add("update sa_dispatch_items set outwarehouseqty=" + jsonObject.getBigDecimalValue("fqty1") + " where rowno =" + jsonObject.getIntValue("frownum") + " and sa_dispatchid='" + sa_dispatchid + "' and siteid='CCYOSG'");
+        if (!erpDocking.getUrl().isEmpty()) {
+            for (Row row : rows) {
+                String sa_dispatchid = row.getString("sa_dispatchid");
+                String billno = row.getString("billno");
+                String result = erpDocking.closeErpSainvoice(billno, false, this, row.getLong("sa_dispatchid"));
+                if (result.equals("true")) {
+                    sqlList.add("update sa_dispatch set status='关闭' where sa_dispatchid='" + sa_dispatchid + "' and siteid='CCYOSG'");
+                    SQLFactory sqlFactory = new SQLFactory(new DataContrlLog(), "数据操作日志新增");
+                    sqlFactory.addParameter("ownertable", "sa_dispatch");
+                    sqlFactory.addParameter("ownerid", sa_dispatchid);
+                    sqlFactory.addParameter("action", "自动关闭");
+                    sqlFactory.addParameter("remarks", "发货单自动关闭成功");
+                    sqlFactory.addParameter("actionuserid", "1");
+                    sqlFactory.addParameter("actionby", "admin");
+                    sqlFactory.addParameter("siteid", "CCYOSG");
+                    sqlList.add(sqlFactory.getSQL());
+                } else {
+                    logger.info("发货单自动关闭错误:" + result);
+                    return getErrReturnObject().setErrMsg(result).toString();
+                }
+                JSONArray jsonArray = erpDocking.queryErpSainvoice(billno);
+                if (!jsonArray.isEmpty()) {
+                    for (Object object : jsonArray) {
+                        JSONObject jsonObject = (JSONObject) object;
+                        sqlList.add("update sa_dispatch_items set outwarehouseqty=" + jsonObject.getBigDecimalValue("fqty1") + " where rowno =" + jsonObject.getIntValue("frownum") + " and sa_dispatchid='" + sa_dispatchid + "' and siteid='CCYOSG'");
+                    }
                 }
             }
 
+            dbConnect.runSqlUpdate(sqlList);
         }
-        dbConnect.runSqlUpdate(sqlList);
         return getSucReturnObject().toString();
     }
 
@@ -765,36 +773,37 @@ public class dispatch extends Controller {
 
         if (!siteid.equalsIgnoreCase("lsa") && Parameter.get(siteid, "dispatchinstock").equals("1")) {
             ERPDocking erpDocking = new ERPDocking(siteid);
-
-            JSONArray jsonArray = erpDocking.getErpIcinvbalRows(200000, 1, rowsDispatchDetail.toJsonArray("itemno"));
-
-            SQLFactory sqlFactory1 = new SQLFactory(this, "商品发货数量汇总");
-            sqlFactory1.addParameter("siteid", siteid);
-            sqlFactory1.addParameter_in("itemno", rowsDispatchDetail.toArrayList("itemno", new ArrayList<>()));
-            Rows sumQtyRows = dbConnect.runSqlQuery(sqlFactory1);
-            RowsMap sumQtyRowsMap = sumQtyRows.toRowsMap("itemno");
-
-            for (Object obj : jsonArray) {
-                JSONObject jsonObject = (JSONObject) obj;
-                if (rowsMapDispatchDetailGroupByItem.containsKey(jsonObject.getString("fitemno"))) {
-                    if (rowsMapDispatchDetailGroupByItem.get(jsonObject.getString("fitemno")).isNotEmpty()) {
-                        rowsMapDispatchDetailGroupByItem.get(jsonObject.getString("fitemno")).get(0).put("invbalqty", jsonObject.getBigDecimalValue("fqty"));
-                    } else {
-                        rowsMapDispatchDetailGroupByItem.get(jsonObject.getString("fitemno")).get(0).put("invbalqty", 0);
+            if (!erpDocking.getUrl().isEmpty()) {
+                JSONArray jsonArray = erpDocking.getErpIcinvbalRows(200000, 1, rowsDispatchDetail.toJsonArray("itemno"));
+
+                SQLFactory sqlFactory1 = new SQLFactory(this, "商品发货数量汇总");
+                sqlFactory1.addParameter("siteid", siteid);
+                sqlFactory1.addParameter_in("itemno", rowsDispatchDetail.toArrayList("itemno", new ArrayList<>()));
+                Rows sumQtyRows = dbConnect.runSqlQuery(sqlFactory1);
+                RowsMap sumQtyRowsMap = sumQtyRows.toRowsMap("itemno");
+
+                for (Object obj : jsonArray) {
+                    JSONObject jsonObject = (JSONObject) obj;
+                    if (rowsMapDispatchDetailGroupByItem.containsKey(jsonObject.getString("fitemno"))) {
+                        if (rowsMapDispatchDetailGroupByItem.get(jsonObject.getString("fitemno")).isNotEmpty()) {
+                            rowsMapDispatchDetailGroupByItem.get(jsonObject.getString("fitemno")).get(0).put("invbalqty", jsonObject.getBigDecimalValue("fqty"));
+                        } else {
+                            rowsMapDispatchDetailGroupByItem.get(jsonObject.getString("fitemno")).get(0).put("invbalqty", 0);
+                        }
                     }
                 }
-            }
 
-            for (Row row : rowsDispatchDetailGroupByItem) {
-                if (sumQtyRowsMap.containsKey(row.getString("itemno"))) {
-                    row.put("delinvbalqty", (row.containsKey("invbalqty") ? row.getBigDecimal("invbalqty") : BigDecimal.ZERO).subtract(sumQtyRowsMap.get(row.getString("itemno")).get(0).getBigDecimal("qty")));
-                } else {
-                    row.put("delinvbalqty", row.containsKey("invbalqty") ? row.getBigDecimal("invbalqty") : BigDecimal.ZERO);
-                }
+                for (Row row : rowsDispatchDetailGroupByItem) {
+                    if (sumQtyRowsMap.containsKey(row.getString("itemno"))) {
+                        row.put("delinvbalqty", (row.containsKey("invbalqty") ? row.getBigDecimal("invbalqty") : BigDecimal.ZERO).subtract(sumQtyRowsMap.get(row.getString("itemno")).get(0).getBigDecimal("qty")));
+                    } else {
+                        row.put("delinvbalqty", row.containsKey("invbalqty") ? row.getBigDecimal("invbalqty") : BigDecimal.ZERO);
+                    }
 
-                if (row.getBigDecimal("qty").compareTo(row.getBigDecimal("delinvbalqty")) > 0) {
-                    return getErrReturnObject().setErrMsg("发货商品" + row.getString("itemno") + ",库存不足,无法操作复核!")
-                            .toString();
+                    if (row.getBigDecimal("qty").compareTo(row.getBigDecimal("delinvbalqty")) > 0) {
+                        return getErrReturnObject().setErrMsg("发货商品" + row.getString("itemno") + ",库存不足,无法操作复核!")
+                                .toString();
+                    }
                 }
             }
         }
@@ -848,10 +857,12 @@ public class dispatch extends Controller {
         //对接erp生成erp发货单
         if (Parameter.get("system.ccerp_dockswitch").equalsIgnoreCase("true")) {
             ERPDocking erpDocking = new ERPDocking(siteid);
-            String result = erpDocking.createErpSainvoice(rows.get(0), rowsdetail, this, sa_dispatchid);
-            if (!result.equals("true")) {
-                System.out.println(result);
-                return getErrReturnObject().setErrMsg(result).toString();
+            if (!erpDocking.getUrl().isEmpty()) {
+                String result = erpDocking.createErpSainvoice(rows.get(0), rowsdetail, this, sa_dispatchid);
+                if (!result.equals("true")) {
+                    System.out.println(result);
+                    return getErrReturnObject().setErrMsg(result).toString();
+                }
             }
         }
         //对接erp成功后统一更新订单数量
@@ -927,7 +938,6 @@ public class dispatch extends Controller {
         }
 
 
-
         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");