Przeglądaj źródła

新增自动收货入库功能

shenjingwei 4 dni temu
rodzic
commit
63941d73ff

+ 27 - 1
src/custom/beans/enterprise_stockbill/bills/BHRK.java

@@ -2,8 +2,12 @@ package beans.enterprise_stockbill.bills;
 
 import common.Controller;
 import common.YosException;
+import common.data.Row;
+import common.data.SQLFactory;
 import common.data.db.SQLList;
 
+import java.util.ArrayList;
+
 public class BHRK extends BasicBill {
 
     public BHRK(Controller controller, long st_stockbillid) throws YosException {
@@ -13,11 +17,33 @@ public class BHRK extends BasicBill {
     @Override
     public void checkValidate(boolean ischeck) throws YosException {
         super.checkValidate(ischeck);
+        String sourceobject = billRow.getString("sourceobject");
+        long sourceid = billRow.getLong("sourceid");
+
+        Row billRow = SQLFactory.getRow(controller, "st_stockbill", sourceid);
+        if (billRow.isEmpty()) {
+            throw new YosException("未找到源销售出库单");
+        }
+        if (billRow.getBoolean("isreceiver")) {
+            throw new YosException("源销售出库单已收货");
+        }
+        if (billRow.getString("status").equals("审核")) {
+            throw new YosException("源销售出库单未审核");
+        }
+        int itemqty = dbConnect.runSqlQuery("select sum(qty) as qty from st_stockbill_items where siteid='" + siteid + "' and skucontrol=1 and st_stockbillid=" + sourceid).get(0).getInteger("qty");//出库数量
+        ArrayList<String> skuList = dbConnect.runSqlQuery("select sku from st_stockbill_items_sku where siteid='" + siteid + "' and st_stockbillid=" + sourceid).toArrayList("sku");
+        if (itemqty != skuList.size()) {
+            throw new YosException("源销售出库单序列号和出库数量不一致");
+        }
     }
 
     @Override
     public SQLList getCheckSql(boolean ischeck) throws YosException {
-        return super.getCheckSql(ischeck);
+        SQLList sqlList = super.getCheckSql(ischeck);
+        String crmbillno = billRow.getString("billno");
+        long sourceid = billRow.getLong("sourceid");
+        sqlList.add(SQLFactory.createUpdateSQL(controller, "st_stockbill").setValue("isreceiver", true).setDateValue("receiverdate").setValue("crmbillno", crmbillno).setValue("receiverby", "crm").setSiteid(siteid).setWhere("st_stockbillid", sourceid));
+        return sqlList;
     }
 
 

+ 3 - 0
src/custom/beans/enterprise_stockbill/bills/BasicBill.java

@@ -1,6 +1,7 @@
 package beans.enterprise_stockbill.bills;
 
 import beans.datacontrllog.DataContrlLog;
+import beans.enterprise.Enterprise;
 import common.Controller;
 import common.UserInfo;
 import common.YosException;
@@ -263,11 +264,13 @@ public abstract class BasicBill {
                 saItemsku.setValue("sys_enterprise_stockid", sys_enterprise_stockid);
                 saItemsku.setValue("status", "售出");
                 saItemsku.setValue("sys_enterpriseid", sys_enterpriseid);
+                saItemsku.setValue("sa_agentsid", Enterprise.getAgentsID(controller, sys_enterpriseid));
             } else {
                 saItemsku.setValue("stockid", 0);
                 saItemsku.setValue("sys_enterprise_stockid", 0);
                 saItemsku.setValue("status", "终端客户售出");
                 saItemsku.setValue("sys_enterpriseid", sys_enterpriseid);
+                saItemsku.setValue("sa_agentsid", Enterprise.getAgentsID(controller, sys_enterpriseid));
             }
             saItemsku.setWhere("sku", sku);
             saItemsku.setSiteid(siteid);

+ 77 - 0
src/custom/beans/enterprise_stockbill/enterprise_Stockbill.java

@@ -1,9 +1,11 @@
 package beans.enterprise_stockbill;
 
+import beans.enterprise.Enterprise;
 import beans.enterprise_stockbill.bills.BasicBill;
 import common.BaseClass;
 import common.Controller;
 import common.YosException;
+import common.data.*;
 import common.data.db.SQLList;
 
 public class enterprise_Stockbill extends BaseClass {
@@ -17,4 +19,79 @@ public class enterprise_Stockbill extends BaseClass {
         getCheckSql(controller, sys_enterprise_stockbillid, ischeck).commit(controller);
     }
 
+    /**
+     * 创建到货入库单
+     */
+    public static long createReceivceBill(Controller controller, long st_stockbillid) throws YosException {
+        Row stockbillRow = SQLFactory.getRow(controller, "st_stockbill", st_stockbillid);
+        Rows stockbill_itemRows = SQLFactory.getRows(controller, "st_stockbill_items", "st_stockbillid", st_stockbillid);
+        long sys_enterpriseid = stockbillRow.getLong("sys_enterpriseid");
+
+        long sys_enterprise_stockid = SQLFactory.createQuerySQL(controller, "sys_enterprise_stock").setSiteid(controller.siteid).setWhere("isused", true).setWhere("issystem", true).query().get(0).getLong("sys_enterprise_stockid");
+
+        SQLList SQLList = new SQLList();
+
+        long sys_enterprise_stockbillid = controller.createTableID("sys_enterprise_stockbill");
+        InsertSQL insertSQL = SQLFactory.createInsertSQL(controller, "sys_enterprise_stockbill");
+        insertSQL.setValue("billno", controller.createBillCode("enterprise_stockbill"));// 单据编号
+        insertSQL.setValue("sourceobject", "st_stockbill");
+        insertSQL.setValue("sourceid", st_stockbillid);
+        insertSQL.setValue("rb", 1);// 红蓝字
+        insertSQL.setValue("type", "报货入库");// 单据类型
+        insertSQL.setValue("typemx", "收货入库");// 明细分类
+        insertSQL.setDateValue("billdate");// 单据日期
+        insertSQL.setValue("status", "新建");// 状态
+        insertSQL.setValue("remarks", "");// 备注说明
+        insertSQL.setValue("siteid", controller.siteid);// 站点
+        insertSQL.setValue("sys_enterprise_stockid", sys_enterprise_stockid);// 企业仓库ID
+        insertSQL.setValue("sys_enterpriseid", sys_enterpriseid);// 合作企业档案ID
+        insertSQL.setUniqueid(sys_enterprise_stockbillid);
+        SQLList.add(insertSQL);
+
+        Enterprise.addSiteItems(controller.dbConnect, controller.siteid, sys_enterpriseid, stockbill_itemRows.toArray("itemid", new Long[]{}));
+
+        QuerySQL itemQuery = SQLFactory.createQuerySQL(controller, "sys_enterprise_item");
+        itemQuery.setWhere("itemid", stockbill_itemRows.toArrayList("itemid"));
+        itemQuery.setWhere("sys_enterpriseid", sys_enterpriseid);
+        itemQuery.setWhere("siteid", controller.siteid);
+        RowsMap itemrowsMap = itemQuery.query().toRowsMap("itemid");
+
+        for (Row stockbill_itemRow : stockbill_itemRows) {
+            long itemid = stockbill_itemRow.getLong("itemid");
+            Row itemrow = itemrowsMap.get(String.valueOf(itemid)).get(0);
+
+            long sys_enterprise_stockbill_itemsid = controller.createTableID("sys_enterprise_stockbill_items");
+            InsertSQL iteminsertSQL = SQLFactory.createInsertSQL(controller, "sys_enterprise_stockbill_items");
+            iteminsertSQL.setValue("siteid", controller.siteid);// 站点
+            iteminsertSQL.setValue("sourceobject", controller.siteid);
+            iteminsertSQL.setValue("sourceid", stockbill_itemRow.getLong("st_stockbill_itemsid"));
+            iteminsertSQL.setValue("sys_enterpriseid", sys_enterpriseid);// 合作企业档案ID
+            iteminsertSQL.setValue("sys_enterprise_stockbillid", sys_enterprise_stockbillid);// 企业出入库单ID
+            iteminsertSQL.setValue("sa_custorderitemsid", 0);// C端订单商品表ID
+            iteminsertSQL.setValue("sys_enterprise_itemid", itemrow.getLong("sys_enterprise_itemid"));// 企业商品档案表ID
+            iteminsertSQL.setValue("hongqty", 0);// 已红冲数量
+            iteminsertSQL.setValue("remarks", "");// 备注说明
+            iteminsertSQL.setValue("itemno", itemrow.getString("itemno"));// 产品编号
+            iteminsertSQL.setValue("model", itemrow.getString("model"));// 型号
+            iteminsertSQL.setValue("itemname", itemrow.getString("itemname"));// 产品名称
+            iteminsertSQL.setValue("skucontrol", itemrow.getBoolean("skucontrol"));// 是否单品管理
+            iteminsertSQL.setValue("qty", stockbill_itemRow.getDouble("qty"));// 数量
+            iteminsertSQL.setUniqueid(sys_enterprise_stockbill_itemsid);
+            SQLList.add(iteminsertSQL);
+
+            Rows stockbill_items_skuRows = SQLFactory.getRows(controller, "st_stockbill_items_sku", "st_stockbill_itemsid", stockbill_itemRow.getLong("st_stockbill_itemsid"));
+
+            for (Row stockbill_items_skuRow : stockbill_items_skuRows) {
+                InsertSQL stockbill_skusSQL = SQLFactory.createInsertSQL(controller, "sys_enterprise_stockbill_skus");
+                stockbill_skusSQL.setValue("siteid", controller.siteid);// 站点
+                stockbill_skusSQL.setValue("sku", stockbill_items_skuRow.getString("sku"));// 序列号
+                stockbill_skusSQL.setValue("sys_enterprise_stockbillid", sys_enterprise_stockbillid);// 企业出入库单ID
+                stockbill_skusSQL.setValue("sys_enterprise_stockbill_itemsid", sys_enterprise_stockbill_itemsid);// 企业出入库单货品明细
+                stockbill_skusSQL.setValue("sys_enterpriseid", sys_enterpriseid);// 合作企业档案ID
+                SQLList.add(stockbill_skusSQL);
+            }
+        }
+        SQLList.commit(controller);
+        return sys_enterprise_stockbillid;
+    }
 }

+ 18 - 44
src/custom/restcontroller/sale/stockbill/stockbill.java

@@ -1,15 +1,15 @@
 package restcontroller.sale.stockbill;
 
+import beans.enterprise_stockbill.enterprise_Stockbill;
 import com.alibaba.fastjson2.JSONObject;
 import common.Controller;
 import common.YosException;
-import common.YosLogger;
 import common.annotation.API;
-import common.crm.bean.icstockbill;
-import common.crm.bean.sku;
-import common.data.*;
-import restcontroller.R;
 import common.annotation.CACHEING;
+import common.data.QuerySQL;
+import common.data.Rows;
+import common.data.SQLFactory;
+import restcontroller.R;
 
 import java.math.BigDecimal;
 
@@ -100,51 +100,25 @@ public class stockbill extends Controller {
                         .toString();
             }
         }
+        if (rows.get(0).getBoolean("isreceiver")) {
+            return getErrReturnObject().setErrMsg("单号为:【" + rows.get(0).getString("billno") + "】的出入库单已进行收货确认")
+                    .toString();
+        }
         Rows itemRows = dbConnect.runSqlQuery("select t1.*,ifnull(t1.sa_orderitemsid,0) sa_orderitemsidnum from st_stockbill_items t1 where t1.st_stockbillid ='" + st_stockbillid + "'");
         Rows codeRows = dbConnect.runSqlQuery("select t1.* from st_stockbill_items_sku t1 where t1.st_stockbillid ='" + st_stockbillid + "'");
-        if(isreceiver){
-//            RowsMap codeRowsMap = codeRows.toRowsMap("st_stockbill_itemsid");
-//            for(Row row:itemRows){
-//                if(row.getBoolean("skucontrol")){
-//                    if(codeRowsMap.containsKey(row.getString("st_stockbill_itemsid"))){
-//                        if(codeRowsMap.get(row.getString("st_stockbill_itemsid")).size()!=row.getInteger("qty")){
-//                            throw new YosException("行号:"+row.getString("rowno")+"序列号数量和出库数量不一致,无法到货确认!");
-//                        }
-//                    }else{
-//                    throw new YosException("受序列号管控的商品,到货确认必须有序列号");
-//                    }
-//                }
-//
-//            }
-            if(BigDecimal.valueOf(codeRows.size()).compareTo(itemRows.toRowsMap("skucontrol").get("1").sum("qty"))!=0){
+        if (isreceiver) {
+            if (BigDecimal.valueOf(codeRows.size()).compareTo(itemRows.toRowsMap("skucontrol").get("1").sum("qty")) != 0) {
                 throw new YosException("序列号数量和出库数量不一致,无法到货确认!");
             }
-        }
-         icstockbill icstockbill = new icstockbill(YosLogger.logger);
-         JSONObject jsonObject =icstockbill.oneAction(st_stockbillid);
-        if(isreceiver){
-            if(jsonObject.getBooleanValue("success")){
-                return getSucReturnObject().toString();
-            }else{
-                System.err.println(jsonObject);
-                return getErrReturnObject().setErrMsg(jsonObject.getString("msg")).toString();
+            long enterprise_Stockbillid = enterprise_Stockbill.createReceivceBill(this, st_stockbillid);
+            try {
+                enterprise_Stockbill.check(this, enterprise_Stockbillid, true);
+            } catch (Exception e) {
+                SQLFactory.createDeleteSQL(this, "sys_enterprise_stockbill").setUniqueid(enterprise_Stockbillid).delete();
+                throw new YosException(e);
             }
-        }else{
-            return getSucReturnObject().toString();
         }
-
-//        UpdateSQL updateSQL = SQLFactory.createUpdateSQL(this, "st_stockbill");
-//        updateSQL.setUniqueid(st_stockbillid);
-//        updateSQL.setSiteid(siteid);
-//        updateSQL.setValue("isreceiver", isreceiver);
-//        updateSQL.setValue("receiverby", username);
-//        updateSQL.setDateValue("receiverdate");
-
-//        dbConnect.runSqlQuery("select stockid from st_stock where stockno='00'");
-
-
-//        dbConnect.runSqlUpdate(updateSQL.getSQL());
-
+        return getSucReturnObject().toString();
     }
 
 

+ 48 - 0
src/custom/service/EnterpriceAutoReceive.java

@@ -0,0 +1,48 @@
+package service;
+
+import beans.enterprise_stockbill.enterprise_Stockbill;
+import common.ServiceController;
+import common.data.Row;
+import common.data.Rows;
+import common.data.SQLFactory;
+
+import java.util.Calendar;
+
+public class EnterpriceAutoReceive extends ServiceController {
+    public EnterpriceAutoReceive() {
+        super();
+    }
+
+    @Override
+    public void serviceRun() throws Exception {
+        //到期自动收货确认
+        Calendar startcalendar = Calendar.getInstance();
+        startcalendar.add(Calendar.DATE, -60);
+        String startdate = getDate_Str(startcalendar.getTime());
+
+        Calendar endcalendar = Calendar.getInstance();
+        endcalendar.add(Calendar.DATE, -30);
+        String enddate = getDate_Str(endcalendar.getTime());
+
+        Rows billRows = dbConnect.runSqlQuery("select distinct t1.st_stockbillid  from st_stockbill t1 \n" +
+                "inner join st_stockbill_items_sku t2 on t1.st_stockbillid=t2.st_stockbillid\n" +
+                "inner join sa_agents t3 on t1.sys_enterpriseid=t3.sys_enterpriseid and t3.type='普通'\n" +
+                "where t1.siteid='MD' and t1.type='销售出库'and t1.rb = 1 and t1.isreceiver = 0 and t1.status = '审核' and t1.iswx=0 and t1.autoreceiveerrtimes<10 and t1.checkdate>='" + startdate + "' and t1.checkdate<'" + enddate + "' \n" +
+                "order by t1.autoreceiveerrtimes,t1.st_stockbillid desc\n" +
+                "limit 100");
+        for (Row billRow : billRows) {
+            long enterprise_Stockbillid = enterprise_Stockbill.createReceivceBill(getSysController("MD"), billRow.getLong("st_stockbillid"));
+            try {
+                enterprise_Stockbill.check(getSysController(), enterprise_Stockbillid, true);
+            } catch (Exception e) {
+                SQLFactory.createDeleteSQL(dbConnect, "sys_enterprise_stockbill").setUniqueid(enterprise_Stockbillid).delete();
+            }
+        }
+    }
+
+
+    @Override
+    public ServiceParam paramSet() {
+        return new ServiceParam("经销商自动到货确认", 10, RunType.minute);
+    }
+}