Просмотр исходного кода

经销商出库入库单审核验证新增单据所属月份判断。
新增经销商期初库存余额表

shenjingwei 3 недель назад
Родитель
Сommit
f65ea10e5b

+ 40 - 23
src/custom/beans/enterprise_stockbill/bills/BasicBill.java

@@ -9,13 +9,13 @@ import common.data.db.DBConnect;
 import org.apache.commons.lang.StringUtils;
 
 import java.math.BigDecimal;
-import java.util.ArrayList;
 
 public abstract class BasicBill {
     Controller controller;
     DBConnect dbConnect;
     UserInfo userInfo;
     long sys_enterprise_stockbillid;
+    long sys_enterprise_stockid;
     boolean issale;//是否销售出库
     String billType;//单据类型
     String billTypeMX;//单据类型
@@ -71,6 +71,17 @@ public abstract class BasicBill {
      * @throws YosException
      */
     public void checkValidate(boolean ischeck) throws YosException {
+        String billdate = billRow.getString("billdate");
+        if (billdate.isBlank()) {
+            throw new YosException("单据日期不能为空");
+        }
+
+        QuerySQL querySQL = SQLFactory.createQuerySQL(controller, "sys_enterprise_stockbill");
+        querySQL.setWhere("sys_enterprise_stockbillid", sys_enterprise_stockbillid);
+        querySQL.setWhere("DATE_FORMAT(billdate, '%Y-%m')>= DATE_FORMAT(NOW(), '%Y-%m')");
+        if (querySQL.query().isEmpty()) {
+            throw new YosException("单号为:【" + billno + "】的出入库单所在单据月份已关账,不可进行" + (ischeck ? "审核" : "反审核") + "操作!");
+        }
         if (ischeck) {
             if (!status.equals("新建")) {
                 throw new YosException("单号为:【" + billno + "】的出入库单为非新建状态,无法审核");
@@ -116,8 +127,8 @@ public abstract class BasicBill {
                 throw new YosException("单号为:【" + billno + "】的出入库单为非审核状态,无法反审核");
             }
         }
+        RowsMap itemskuRowsMap = SQLFactory.createQuerySQL(dbConnect, "sa_itemsku", "sys_enterpriseid", "sys_enterprise_stockid", "stockid", "sku").setWhere("sku", codeRows.toArrayList("sku")).query().toRowsMap("sku");
 
-        RowsMap itemskuRowsMap = SQLFactory.createQuerySQL(dbConnect, "sa_itemsku", "sys_enterpriseid", "stockid", "sku").setWhere("sku", codeRows.toArrayList("sku")).query().toRowsMap("sku");
         for (Row codeRow : codeRows) {
             String sku = codeRow.getString("sku");
             if (!itemskuRowsMap.containsKey(sku)) {
@@ -127,13 +138,18 @@ public abstract class BasicBill {
                 throw new YosException("序列号【" + sku + "】非当前经销商所属");
             }
             if (!isInStock(ischeck) && itemskuRowsMap.get(sku).get(0).getLong("stockid") != getAgentStockID()) {
+                throw new YosException("序列号【" + sku + "】不在经销商仓库中");
+            }
+            if (!isInStock(ischeck) && itemskuRowsMap.get(sku).get(0).getLong("sys_enterprise_stockid") != sys_enterprise_stockid) {
                 throw new YosException("序列号【" + sku + "】不在仓库中");
             }
             if (isInStock(ischeck) && itemskuRowsMap.get(sku).get(0).getLong("stockid") != 0) {
                 throw new YosException("序列号【" + sku + "】正在仓库中");
             }
+            if (isInStock(ischeck) && itemskuRowsMap.get(sku).get(0).getLong("sys_enterprise_stockid") != 0) {
+                throw new YosException("序列号【" + sku + "】正在仓库中");
+            }
         }
-
     }
 
     public SQLDump getCheckSql(boolean ischeck) throws YosException {
@@ -159,29 +175,26 @@ public abstract class BasicBill {
      */
 
     private SQLDump updateInvbal(boolean ischeck) throws YosException {
+        for (String sys_enterprise_itemid : itemRows.toArrayList("sys_enterprise_itemid")) {
+            InsertSQL invbalInsert = SQLFactory.createInsertSQL(controller, "sys_enterprise_invbal");
+            invbalInsert.setValue("siteid", siteid);
+            invbalInsert.setValue("sys_enterpriseid", sys_enterpriseid);
+            invbalInsert.setValue("sys_enterprise_stockid", sys_enterprise_stockid);
+            invbalInsert.setValue("sys_enterprise_itemid", sys_enterprise_itemid);
+            invbalInsert.setValue("qty", 0);
+            invbalInsert.setWhere("not exists(select * from sys_enterprise_invbal where siteid='" + siteid + "' and sys_enterpriseid=" + sys_enterpriseid + " and sys_enterprise_stockid=" + sys_enterprise_stockid + " and sys_enterprise_itemid=" + sys_enterprise_itemid + " )");
+            invbalInsert.insert();
+        }
         SQLDump sqlDump = new SQLDump();
-        RowsMap invbalsRowsMap = SQLFactory.createQuerySQL(dbConnect, "sys_enterprise_invbal").setWhere("siteid", siteid).setWhere("sys_enterpriseid", sys_enterpriseid).setWhere("sys_enterprise_itemid", itemRows.toArrayList("sys_enterprise_itemid")).query().toRowsMap("sys_enterprise_itemid");
         for (Row row : itemRows) {
-            long sys_enterprise_itemid = row.getLong("sys_enterprise_itemid");
-            long sys_enterprise_stockid = row.getLong("sys_enterprise_stockid");
             BigDecimal qty = isInStock(ischeck) ? row.getBigDecimal("qty") : row.getBigDecimal("qty").negate();
-            if (!invbalsRowsMap.containsKey(String.valueOf(sys_enterprise_itemid)) || !invbalsRowsMap.get(String.valueOf(sys_enterprise_itemid)).toRowsMap("sys_enterprise_stockid").containsKey(String.valueOf(sys_enterprise_stockid))) {
-                InsertSQL invbalInsert = SQLFactory.createInsertSQL(controller, "sys_enterprise_invbal");
-                invbalInsert.setValue("siteid", siteid);
-                invbalInsert.setValue("sys_enterpriseid", sys_enterpriseid);
-                invbalInsert.setValue("sys_enterprise_stockid", sys_enterprise_stockid);
-                invbalInsert.setValue("sys_enterprise_itemid", sys_enterprise_itemid);
-                invbalInsert.setValue("qty", qty.doubleValue());
-                sqlDump.add(invbalInsert.getSQL());
-            } else {
-                UpdateSQL invbalUpdate = SQLFactory.createUpdateSQL(controller, "sys_enterprise_invbal");
-                invbalUpdate.addValue("qty", qty);
-                invbalUpdate.setValue("sys_enterpriseid", sys_enterpriseid);
-                invbalUpdate.setWhere("sys_enterprise_itemid", sys_enterprise_itemid);
-                invbalUpdate.setWhere("sys_enterprise_stockid", sys_enterprise_stockid);
-                invbalUpdate.setWhere("siteid", siteid);
-                sqlDump.add(invbalUpdate.getSQL());
-            }
+            UpdateSQL invbalUpdate = SQLFactory.createUpdateSQL(controller, "sys_enterprise_invbal");
+            invbalUpdate.addValue("qty", qty.doubleValue());
+            invbalUpdate.setWhere("sys_enterpriseid", sys_enterpriseid);
+            invbalUpdate.setWhere("sys_enterprise_stockid", sys_enterprise_stockid);
+            invbalUpdate.setWhere("sys_enterprise_itemid", row.getLong("sys_enterprise_itemid"));
+            invbalUpdate.setWhere("siteid", siteid);
+            sqlDump.add(invbalUpdate.getSQL());
         }
         return sqlDump;
     }
@@ -238,14 +251,17 @@ public abstract class BasicBill {
             UpdateSQL saItemsku = SQLFactory.createUpdateSQL(controller, "sa_itemsku");
             if (isInStock(ischeck)) {
                 saItemsku.setValue("stockid", getAgentStockID());
+                saItemsku.setValue("sys_enterprise_stockid", sys_enterprise_stockid);
                 saItemsku.setValue("status", "售出");
                 saItemsku.setValue("sys_enterpriseid", sys_enterpriseid);
             } else {
                 saItemsku.setValue("stockid", 0);
+                saItemsku.setValue("sys_enterprise_stockid", 0);
                 saItemsku.setValue("status", "终端客户售出");
                 saItemsku.setValue("sys_enterpriseid", sys_enterpriseid);
             }
             saItemsku.setWhere("sku", sku);
+            saItemsku.setSiteid(siteid);
             sqlDump.add(saItemsku.getSQL());
         }
         return sqlDump;
@@ -271,6 +287,7 @@ public abstract class BasicBill {
         this.siteid = billRow.getString("siteid");
         this.status = billRow.getString("status");
         this.sys_enterpriseid = billRow.getLong("sys_enterpriseid");
+        this.sys_enterprise_stockid = billRow.getLong("sys_enterprise_stockid");
         itemRows = dbConnect.runSqlQuery("select t1.* from sys_enterprise_stockbill_items t1  where sys_enterpriseid=" + sys_enterpriseid + " and t1.sys_enterprise_stockbillid ='" + sys_enterprise_stockbillid + "'");
         codeRows = dbConnect.runSqlQuery("select t1.* from sys_enterprise_stockbill_skus t1 where sys_enterpriseid=" + sys_enterpriseid + " and t1.sys_enterprise_stockbillid ='" + sys_enterprise_stockbillid + "'");
     }

+ 11 - 0
src/custom/objectregister/sa_itemsku.java

@@ -0,0 +1,11 @@
+package objectregister;
+
+import common.annotation.Table;
+import common.annotation.TableCol;
+import common.data.db.initialization.base.YosObject;
+
+@Table(comment = "商品序列号档案", uniquecolumn = "sa_itemskuid", issystem = false)
+public class sa_itemsku extends YosObject {
+    @TableCol(title = "企业仓库ID", column_type = YosObject.ColumnType.bigint, is_nullable = true)
+    public Long sys_enterprise_stockid = 0L;
+}

+ 35 - 0
src/custom/objectregister/sys_enterprise_inventoryear.java

@@ -0,0 +1,35 @@
+package objectregister;
+
+import common.annotation.Table;
+import common.annotation.TableCol;
+import common.data.db.initialization.base.YosObject;
+
+@Table(comment = "企业暂存库存余额表", uniquecolumn = "sys_enterprise_inventoryearid", issystem = false)
+public class sys_enterprise_inventoryear {
+    @TableCol(title = "企业ID", column_type = YosObject.ColumnType.bigint, is_nullable = false)
+    public Long sys_enterpriseid = 0L;
+
+    @TableCol(title = "企业仓库ID", column_type = YosObject.ColumnType.bigint, is_nullable = false)
+    public Long sys_enterprise_stockid = 0L;
+
+    @TableCol(title = "企业商品档案ID", column_type = YosObject.ColumnType.bigint, is_nullable = false)
+    public Long sys_enterprise_itemid = 0L;
+
+    @TableCol(title = "年份", column_type = YosObject.ColumnType.integer, is_nullable = false)
+    public Integer year = 0;
+
+    @TableCol(title = "月份", column_type = YosObject.ColumnType.integer, is_nullable = false)
+    public Integer month = 0;
+
+    @TableCol(title = "数量", column_type = YosObject.ColumnType.decimal, is_nullable = false)
+    public Double qty = 0d;
+
+    @TableCol(title = "备注", column_type = YosObject.ColumnType.varchar, numeric_precision = 500)
+    public String remarks;
+
+    @TableCol(title = "创建时间", column_type = YosObject.ColumnType.datetime)
+    public String createdate;
+
+    @TableCol(title = "站点ID", column_type = YosObject.ColumnType.varchar)
+    public String siteid;
+}

+ 12 - 2
src/custom/restcontroller/crm/agent/stock/stock.java

@@ -33,8 +33,9 @@ public class stock extends Controller {
         boolean isused = content.getBooleanValue("isused");// 是否启用
         String stockno = content.getStringValue("stockno");// 仓库编号
         String stockname = content.getStringValue("stockname");// 仓库名称
+        Rows stockRows = SQLFactory.createQuerySQL(this, "sys_enterprise_stock", "sys_enterprise_stockid").setSiteid(siteid).setUniqueid(sys_enterprise_stockid).query();
         SQLDump sqldump = new SQLDump();
-        if (sys_enterprise_stockid <= 0 || SQLFactory.createQuerySQL(this, "sys_enterprise_stock", "sys_enterprise_stockid").setSiteid(siteid).setUniqueid(sys_enterprise_stockid).query().isEmpty()) {
+        if (sys_enterprise_stockid <= 0 || stockRows.isEmpty()) {
             InsertSQL insertSQL = SQLFactory.createInsertSQL(this, "sys_enterprise_stock");
             insertSQL.setValue("siteid", siteid);// 站点
             insertSQL.setValue("isused", isused);// 是否启用
@@ -44,6 +45,9 @@ public class stock extends Controller {
             insertSQL.setValue("sys_enterpriseid", sys_enterpriseid);// 合作企业档案ID
             sqldump.add(insertSQL);
         } else {
+            if (stockRows.get(0).getBoolean("issystem")) {
+                return getErrReturnObject().setErrMsg("系统预设仓库不可修改!").toString();
+            }
             UpdateSQL updateSQL = SQLFactory.createUpdateSQL(this, "sys_enterprise_stock");
             updateSQL.setValue("isused", isused);// 是否启用
             updateSQL.setValue("stockno", stockno);// 仓库编号
@@ -62,7 +66,13 @@ public class stock extends Controller {
     })
     public String sys_enterprise_stock_delete() throws YosException {
         long sys_enterprise_stockid = content.getLongValue("sys_enterprise_stockid");
-
+        Rows stockRows = SQLFactory.createQuerySQL(this, "sys_enterprise_stock", "sys_enterprise_stockid").setSiteid(siteid).setUniqueid(sys_enterprise_stockid).query();
+        if (stockRows.isEmpty()) {
+            return getErrReturnObject().setErrMsg("未找到该仓库!").toString();
+        }
+        if (stockRows.get(0).getBoolean("issystem")) {
+            return getErrReturnObject().setErrMsg("系统预设仓库不可删除!").toString();
+        }
         QuerySQL invbalQuery = SQLFactory.createQuerySQL(this, "sys_enterprise_invbal");
         invbalQuery.setSiteid(siteid);
         invbalQuery.setWhere("sys_enterprise_stockid", sys_enterprise_stockid);

+ 20 - 0
src/custom/service/CaculateEnterpriseInventor.java

@@ -0,0 +1,20 @@
+package service;
+
+import common.ServiceController;
+
+import java.util.Calendar;
+
+public class CaculateEnterpriseInventor extends ServiceController {
+    @Override
+    public ServiceParam paramSet() {
+        return new ServiceParam("更新经销商下月期初库存", 1, RunType.day);
+    }
+
+    @Override
+    public void serviceRun() throws Exception {
+        Calendar calendar = Calendar.getInstance();
+        int year = calendar.get(Calendar.YEAR);
+        int month = calendar.get(Calendar.MONTH);
+        dbConnect.runSqlUpdate("call caculateenterpriseinventor(" + year + "," + month + ")");
+    }
+}