Parcourir la source

出入库单红冲功能

hu il y a 2 mois
Parent
commit
a6b92b6e99

+ 56 - 1
src/custom/beans/stockbill/bills/BasicBill.java

@@ -86,6 +86,23 @@ public abstract class BasicBill {
             if (itemRows.min("qty").doubleValue() < 0) {
                 throw new YosException("表体数量不能小于0");
             }
+            if(rb==0){
+                Rows olditemRows =dbConnect.runSqlQuery("select * from st_stockbill_items where siteid='"+siteid+"' and st_stockbillid="+billRow.getLong("sourceid"));
+                RowsMap olditemRowsMap = olditemRows.toRowsMap("st_stockbill_itemsid");
+                for (Row row :itemRows){
+                    if(!row.getString("sourceobject").equals("st_stockbill_items")){
+                        throw new YosException("行号为:" + row.getString("rowno") + "的物料不在原单中,不可进行红冲");
+                    }
+                    if(olditemRowsMap.containsKey(row.getString("sourceid"))){
+                        Row row1=olditemRowsMap.get(row.getString("sourceid")).get(0);
+                        if(row.getBigDecimal("qty").compareTo((row1.getBigDecimal("qty").subtract(row1.getBigDecimal("hongqty"))))>0){
+                            throw new YosException("行号为:" + row.getString("rowno") + "的商品红冲数量超过原单可红冲数量"+row1.getBigDecimal("qty").subtract(row1.getBigDecimal("hongqty")));
+                        }
+                    }else{
+                        throw new YosException("行号为:" + row.getString("rowno") + "的物料不在原单中,不可进行红冲");
+                    }
+                }
+            }
         } else {
             if (!status.equals("审核")) {
                 throw new YosException("单号为:【" + billno + "】的出入库单为非审核状态,无法反审核");
@@ -97,6 +114,8 @@ public abstract class BasicBill {
         ArrayList<String> sqlList = new ArrayList<>();
         sqlList.addAll(updateInvbal(ischeck));//更新库存
         sqlList.addAll(updateMCode(ischeck));//更新序列号
+        sqlList.addAll(updateHongqty(ischeck));//更新红冲数量
+        sqlList.addAll(updateStatus(ischeck));//更新状态
         return sqlList;
     }
 
@@ -158,6 +177,42 @@ public abstract class BasicBill {
         }
         return sqlList;
     }
+    /**
+     * 更新已红冲数量
+     *
+     * @param ischeck
+     * @return
+     * @throws YosException
+     */
+    private ArrayList<String> updateHongqty(boolean ischeck) throws YosException {
+        ArrayList<String> sqlList = new ArrayList<>();
+        if(rb==0){
+            for (Row row : itemRows) {
+                long sourceid = row.getLong("sourceid");
+                BigDecimal qty = ischeck ? row.getBigDecimal("qty") : row.getBigDecimal("qty").negate();
+                sqlList.add("update st_stockbill_items set hongqty=ifnull(hongqty,0)+"+qty+" where st_stockbill_itemsid="+sourceid);
+            }
+        }
+        return sqlList;
+    }
+
+    /**
+     * 更新状态
+     *
+     * @param ischeck
+     * @return
+     * @throws YosException
+     */
+    private ArrayList<String> updateStatus(boolean ischeck) throws YosException {
+        ArrayList<String> sqlList = new ArrayList<>();
+
+        if(ischeck){
+            sqlList.add("update st_stockbill set status='审核',checkby='"+ controller.username+"',checkdate=CURRENT_TIMESTAMP where st_stockbillid = "+st_stockbillid+" and siteid='"+siteid+"'");
+        }else{
+            sqlList.add("update st_stockbill set status='新建',checkby='',checkdate=null where st_stockbillid = "+st_stockbillid+" and siteid='"+siteid+"'");
+        }
+        return sqlList;
+    }
 
     /**
      * 更新序列号
@@ -214,7 +269,7 @@ public abstract class BasicBill {
         this.siteid = billRow.getString("siteid");
         this.status = billRow.getString("status");
         itemRows = dbConnect.runSqlQuery("select t1.*,t2.skucontrol from st_stockbill_items t1 left join plm_item t2 on t1.itemid=t2.itemid and t1.siteid=t2.siteid where t1.st_stockbillid ='" + st_stockbillid + "'");
-        codeRows = dbConnect.runSqlQuery("select t1.* from st_stockbill_items_sku  where t1.st_stockbillid ='" + st_stockbillid + "'");
+        codeRows = dbConnect.runSqlQuery("select t1.* from st_stockbill_items_sku t1 where t1.st_stockbillid ='" + st_stockbillid + "'");
     }
 
 

+ 102 - 0
src/custom/restcontroller/webmanage/sale/stockbill/stockbill.java

@@ -647,6 +647,108 @@ public class stockbill extends Controller {
         return getSucReturnObject().toString();
     }
 
+    @API(title = "红冲", apiversion = R.ID2025072409344603.v1.class)
+    @CACHEING_CLEAN(apiClass = {stockbill.class, stockbillitems.class})
+    public String hongc() throws YosException {
+        long st_stockbillid=content.getLong("st_stockbillid");
+        ArrayList<String> sqlList = new ArrayList<>();
+        Rows rows = dbConnect.runSqlQuery("select t1.*,ifnull(t2.sa_sendrepairid,0) sa_sendrepairid from st_stockbill t1 left join sa_sendrepair t2 on t1.st_stockbillid=t2.sourceid and t1.siteid=t2.siteid and t2.sourcetable='st_stockbill'  where t1.st_stockbillid ='"
+                + st_stockbillid + "' and  t1.siteid='" + siteid + "'");
+        Rows rowsdetail = dbConnect.runSqlQuery("select t1.*,t2.skucontrol from st_stockbill_items t1 left join plm_item t2 on t1.itemid=t2.itemid and t1.siteid=t2.siteid where t1.st_stockbillid ='"
+                + st_stockbillid + "' and  t1.siteid='" + siteid + "'");
+        if(rows.isEmpty()){
+            return getErrReturnObject().setErrMsg("该出入库单不存在")
+                    .toString();
+        }
+        if(!rows.get(0).getString("status").equals("审核")){
+            return getErrReturnObject().setErrMsg("非审核的出入库单无法红冲")
+                    .toString();
+        }
+        if(rows.get(0).getInteger("rb")==0){
+            return getErrReturnObject().setErrMsg("只能红冲蓝字出入库单")
+                    .toString();
+        }
+        if(rows.get(0).getInteger("sa_sendrepairid")!=0){
+            return getErrReturnObject().setErrMsg("来源于送修单的出库单不能红冲")
+                    .toString();
+        }
+
+        st_stockbillid = createTableID("st_stockbill");
+        InsertSQL insertSQL = SQLFactory.createInsertSQL(this, "st_stockbill");
+        insertSQL.setUniqueid(st_stockbillid);
+        insertSQL.setSiteid(siteid);
+        insertSQL.setValue("sys_enterpriseid", rows.get(0).getLong("sys_enterpriseid"));
+        insertSQL.setValue("rec_contactsid", rows.get(0).getLong("rec_contactsid"));
+        insertSQL.setValue("departmentid", rows.get(0).getLong("departmentid"));
+        insertSQL.setValue("stockid", rows.get(0).getLong("stockid"));
+        insertSQL.setValue("type", rows.get(0).getString("type"));
+        insertSQL.setValue("typemx", rows.get(0).getString("typemx"));
+        insertSQL.setValue("sa_supplierid", rows.get(0).getLong("sa_supplierid"));
+        insertSQL.setValue("rb", 0);
+        insertSQL.setValue("remarks", rows.get(0).getString("remarks"));
+        insertSQL.setValue("billdate", getDateTime_Str());
+        insertSQL.setValue("billno", createBillCode("stockbill"));
+        insertSQL.setValue("outplace",  rows.get(0).getString("outplace"));
+        insertSQL.setValue("delivery",  rows.get(0).getString("delivery"));
+        insertSQL.setValue("invoice_enterprisename",  rows.get(0).getString("invoice_enterprisename"));
+        insertSQL.setValue("invoice_address",  rows.get(0).getString("invoice_address"));
+        insertSQL.setValue("invoice_taxno",  rows.get(0).getString("invoice_taxno"));
+        insertSQL.setValue("tracknumber",  rows.get(0).getString("tracknumber"));
+        insertSQL.setValue("isconfirm",  rows.get(0).getString("isconfirm"));
+
+        insertSQL.setValue("sourceobject",  "st_stockbill");
+        insertSQL.setValue("sourceid",  rows.get(0).getLong("st_stockbillid"));
+
+        insertSQL.setValue("period", rows.get(0).getString("period"));
+
+        insertSQL.setValue("createby", username);
+        insertSQL.setDateValue("createdate");
+        insertSQL.setValue("changeby", username);
+        insertSQL.setDateValue("changedate");
+        insertSQL.setValue("status", "新建");
+        insertSQL.setValue("payamount", 0);
+        insertSQL.setValue("paydiscountamount", 0);
+        sqlList.add(insertSQL.getSQL());
+
+        int i = 0;
+        for(Row row : rowsdetail){
+            InsertSQL  insertDetailSQL= SQLFactory.createInsertSQL(this, "st_stockbill_items");
+            insertDetailSQL.setUniqueid(createTableID("st_stockbill_items"));
+            insertDetailSQL.setSiteid(siteid);
+            insertDetailSQL.setValue("rowno",   i + 1);
+            insertDetailSQL.setValue("st_stockbillid", st_stockbillid);
+            insertDetailSQL.setValue("sa_orderitemsid", row.getLong("sa_orderitemsid"));
+            insertDetailSQL.setValue("itemid", row.getString("itemid"));
+            insertDetailSQL.setValue("sa_orderid", row.getString("sa_orderid"));
+            insertDetailSQL.setValue("qty", row.getString("qty"));
+            insertDetailSQL.setValue("discountrate", row.getBigDecimal("discountrate"));
+            insertDetailSQL.setValue("sa_dispatch_itemsid", 0);
+            insertDetailSQL.setValue("defaultprice", row.getBigDecimal("defaultprice"));
+            insertDetailSQL.setValue("remarks", row.getString("remarks"));
+            insertDetailSQL.setValue("sku", row.getString("sku"));
+            insertDetailSQL.setValue("itemno", row.getString("itemno"));
+            insertDetailSQL.setValue("itemname", row.getString("itemname"));
+            insertDetailSQL.setValue("model", row.getString("model"));
+            insertDetailSQL.setValue("price", row.getBigDecimal("price"));
+            insertDetailSQL.setValue("stockid", row.getString("stockid"));
+            insertDetailSQL.setValue("amount", row.getBigDecimal("qty").multiply(row.getBigDecimal("price")));
+            insertDetailSQL.setValue("untaxedprice", row.getBigDecimal("price").divide(new BigDecimal(1.13),2, BigDecimal.ROUND_HALF_UP));
+            insertDetailSQL.setValue("untaxedamount", row.getBigDecimal("qty").multiply(row.getBigDecimal("price").divide(new BigDecimal(1.13),2, BigDecimal.ROUND_HALF_UP)));
+
+            insertDetailSQL.setValue("sourceid", row.getLong("st_stockbill_itemsid"));
+            insertDetailSQL.setValue("sourceobject", "st_stockbill_items");
+            sqlList.add(insertDetailSQL.getSQL());
+        }
+
+        sqlList.add(DataContrlLog.createLog(this, "st_stockbill", st_stockbillid, "新增", "销售出库单新增成功").getSQL());
+
+        dbConnect.runSqlUpdate(sqlList);
+        content.put("st_stockbillid", st_stockbillid);
+
+
+        return queryStockbillMain();
+    }
+
 
     @API(title = "更新站点信息详情详情", apiversion = R.ID20230720143503.v1.class)
     public String updateParameterSiteInfo() throws YosException {