Quellcode durchsuchen

Merge remote-tracking branch 'origin/develop' into develop

shenjingwei vor 3 Monaten
Ursprung
Commit
e8648ca897
1 geänderte Dateien mit 97 neuen und 5 gelöschten Zeilen
  1. 97 5
      src/custom/restcontroller/webmanage/sale/period/period.java

+ 97 - 5
src/custom/restcontroller/webmanage/sale/period/period.java

@@ -143,11 +143,15 @@ public class period extends Controller {
     }
 
 
-    @API(title = "结账", apiversion = R.ID2025072314213503.v1.class)
+    @API(title = "库存结账", apiversion = R.ID2025072314213503.v1.class)
     @CACHEING_CLEAN( apiClass = {period.class})
-    public String close() throws YosException {
+    public String invbalclose() throws YosException {
         Long st_periodid = content.getLong("st_periodid");
-        boolean isclose = content.getBooleanValue("isclose");
+        boolean isclose = content.getBoolean("isclose");
+        Rows rows = dbConnect.runSqlQuery("select * from st_period where siteid='"+siteid+"' and st_periodid="+st_periodid);
+        if(rows.isEmpty()){
+            return getErrReturnObject().setErrMsg("会计期间不存在").toString();
+        }
         ArrayList<String> sqlList = new ArrayList<>();
         UpdateSQL updateSQL = SQLFactory.createUpdateSQL(this, "st_period");
         updateSQL.setUniqueid(st_periodid);
@@ -162,11 +166,99 @@ public class period extends Controller {
 
         sqlList.add(updateSQL.getSQL());
         if (isclose) {
+            YearMonth specificYearMonth = YearMonth.of(rows.get(0).getInteger("year"), rows.get(0).getInteger("month"));
+            // 获取上一个月
+            YearMonth previousMonth = specificYearMonth.minusMonths(1);
+
+            System.err.println("\n" +
+                    "\t\t\t\t\tselect t1.itemid,t3.stockid,ifnull(t2.qty,0) + ifnull(t3.qty,0) qty from plm_item t1 left join st_stock t0 on t1.stockno=t0.stockno and t1.siteid=t0.siteid and t0.isused=1 \n" +
+                    "\t\t\t\t\tleft join (\n" +
+                    "\t\t\t\t\tselect itemid,stockid,qty,siteid from  sa_inventoryear\n" +
+                    "\t\t\t\t\twhere year ='"+previousMonth.getYear()+"' and month ='"+ previousMonth.getMonthValue()+"'\n" +
+                    "\t\t\t\t\t)t2 on t1.itemid = t2.itemid and t1.siteid = t2.siteid\n" +
+                    "\t\t\t\tleft join (\n" +
+                    "\t\t\t\t\tselect itemid,stockid,siteid,sum(qty) qty from ( \n" +
+                    "\t\t\t\t\t\tselect t2.itemid,t2.stockid,t1.siteid, \n" +
+                    "\t\t\t\t\t\tcase when type like '%入%' and rb ='1' then  t2.qty\n" +
+                    "\t\t\t\t\t\t\t when type like '%入%' and rb ='0' then -t2.qty\n" +
+                    "\t\t\t\t\t\t\t when type like '%出%' and rb ='1' then -t2.qty\n" +
+                    "\t\t\t\t\t\t\t when type like '%出%' and rb ='0' then  t2.qty\n" +
+                    "\t\t\t\t\t\tend qty\n" +
+                    "\t\t\t\t\t\t from st_stockbill t1\n" +
+                    "\t\t\t\t\t\tjoin st_stockbill_items t2 on t1.st_stockbillid = t2.st_stockbillid and t1.siteid = t2.siteid \n" +
+                    "\t\t\t\t\t\twhere t1.status ='审核' and ifnull(t1.typemx,'') != '正品入库'\n" +
+                    "\t\t\t\t\t\tand  DATE_FORMAT(t1.billdate, '%Y-%m-%d') >='"+rows.get(0).getString("begdate")+"'\n" +
+                    "\t\t\t\t\t\tand  DATE_FORMAT(t1.billdate, '%Y-%m-%d') <='"+rows.get(0).getString("enddate")+"'\n" +
+                    "\t\t\t\t\t\tunion all \n" +
+                    "\t\t\t\t\t\tselect t2.itemid,t2.stockid,t1.siteid,  \n" +
+                    "\t\t\t\t\t\tcase when type like '%入%' and rb ='1' then  t2.qty\n" +
+                    "\t\t\t\t\t\t\t when type like '%入%' and rb ='0' then -t2.qty\n" +
+                    "\t\t\t\t\t\tend qty\n" +
+                    "\t\t\t\t\t\t from st_stockbill t1\n" +
+                    "\t\t\t\t\t\tjoin st_stockbill_items t2 on t1.st_stockbillid = t2.st_stockbillid and t1.siteid = t2.siteid\n" +
+                    "\t\t\t\t\t\twhere t1.status ='审核' and ifnull(t1.typemx,'')  = '正品入库' and ifnull(t2.amount,0) != 0\n" +
+                    "\t\t\t\t\t\tand  DATE_FORMAT(t1.billdate, '%Y-%m-%d') >='"+rows.get(0).getString("begdate")+"'\n" +
+                    "\t\t\t\t\t\tand  DATE_FORMAT(t1.billdate, '%Y-%m-%d') <='"+rows.get(0).getString("enddate")+"'\n" +
+                    "\t\t\t\t\t)t group by itemid,stockid,siteid\n" +
+                    "\t\t\t\t)t3 on t1.itemid = t3.itemid and t0.stockid = t3.stockid and t1.siteid = t3.siteid \n" +
+                    "\t\t\t\twhere  ifnull(t2.qty,0) + ifnull(t3.qty,0)!=0 ");
+            Rows invbalRows= dbConnect.runSqlQuery("\n" +
+                    "\t\t\t\t\tselect t1.itemid,t3.stockid,ifnull(t2.qty,0) + ifnull(t3.qty,0) qty from plm_item t1 left join st_stock t0 on t1.stockno=t0.stockno and t1.siteid=t0.siteid and t0.isused=1 \n" +
+                    "\t\t\t\t\tleft join (\n" +
+                    "\t\t\t\t\tselect itemid,stockid,qty,siteid from  sa_inventoryear\n" +
+                    "\t\t\t\t\twhere year ='"+previousMonth.getYear()+"' and month ='"+ previousMonth.getMonthValue()+"'\n" +
+                    "\t\t\t\t\t)t2 on t1.itemid = t2.itemid and t1.siteid = t2.siteid\n" +
+                    "\t\t\t\tleft join (\n" +
+                    "\t\t\t\t\tselect itemid,stockid,siteid,sum(qty) qty from ( \n" +
+                    "\t\t\t\t\t\tselect t2.itemid,t2.stockid,t1.siteid, \n" +
+                    "\t\t\t\t\t\tcase when type like '%入%' and rb ='1' then  t2.qty\n" +
+                    "\t\t\t\t\t\t\t when type like '%入%' and rb ='0' then -t2.qty\n" +
+                    "\t\t\t\t\t\t\t when type like '%出%' and rb ='1' then -t2.qty\n" +
+                    "\t\t\t\t\t\t\t when type like '%出%' and rb ='0' then  t2.qty\n" +
+                    "\t\t\t\t\t\tend qty\n" +
+                    "\t\t\t\t\t\t from st_stockbill t1\n" +
+                    "\t\t\t\t\t\tjoin st_stockbill_items t2 on t1.st_stockbillid = t2.st_stockbillid and t1.siteid = t2.siteid \n" +
+                    "\t\t\t\t\t\twhere t1.status ='审核' and ifnull(t1.typemx,'') != '正品入库'\n" +
+                    "\t\t\t\t\t\tand  DATE_FORMAT(t1.billdate, '%Y-%m-%d') >='"+rows.get(0).getString("begdate")+"'\n" +
+                    "\t\t\t\t\t\tand  DATE_FORMAT(t1.billdate, '%Y-%m-%d') <='"+rows.get(0).getString("enddate")+"'\n" +
+                    "\t\t\t\t\t\tunion all \n" +
+                    "\t\t\t\t\t\tselect t2.itemid,t2.stockid,t1.siteid,  \n" +
+                    "\t\t\t\t\t\tcase when type like '%入%' and rb ='1' then  t2.qty\n" +
+                    "\t\t\t\t\t\t\t when type like '%入%' and rb ='0' then -t2.qty\n" +
+                    "\t\t\t\t\t\tend qty\n" +
+                    "\t\t\t\t\t\t from st_stockbill t1\n" +
+                    "\t\t\t\t\t\tjoin st_stockbill_items t2 on t1.st_stockbillid = t2.st_stockbillid and t1.siteid = t2.siteid\n" +
+                    "\t\t\t\t\t\twhere t1.status ='审核' and ifnull(t1.typemx,'')  = '正品入库' and ifnull(t2.amount,0) != 0\n" +
+                    "\t\t\t\t\t\tand  DATE_FORMAT(t1.billdate, '%Y-%m-%d') >='"+rows.get(0).getString("begdate")+"'\n" +
+                    "\t\t\t\t\t\tand  DATE_FORMAT(t1.billdate, '%Y-%m-%d') <='"+rows.get(0).getString("enddate")+"'\n" +
+                    "\t\t\t\t\t)t group by itemid,stockid,siteid\n" +
+                    "\t\t\t\t)t3 on t1.itemid = t3.itemid and t0.stockid = t3.stockid and t1.siteid = t3.siteid \n" +
+                    "\t\t\t\twhere  ifnull(t2.qty,0) + ifnull(t3.qty,0)!=0 ");
+            if(invbalRows.isNotEmpty()){
+                for (Row row :invbalRows){
+                    InsertSQL insertSQL = SQLFactory.createInsertSQL(this, "sa_inventoryear");
+                    insertSQL.setUniqueid(createTableID("sa_inventoryear"));
+                    insertSQL.setSiteid(siteid);
+                    insertSQL.setValue("month", rows.get(0).getLong("month"));
+                    insertSQL.setValue("year", rows.get(0).getLong("year") );
+                    insertSQL.setValue("itemid",  row.getLong("itemid"));
+                    insertSQL.setValue("stockid", row.getLong("stockid"));
+                    insertSQL.setValue("qty",row.getBigDecimal("qty"));
+                    insertSQL.setValue("remarks", "月结转入");
+
+                    insertSQL.setValue("createby", username);
+                    insertSQL.setDateValue("createdate");
+                    insertSQL.setValue("changeby", username);
+                    insertSQL.setDateValue("changedate");
+                    sqlList.add(insertSQL.getSQL());
+                }
+            }
             sqlList.add(
-                    DataContrlLog.createLog(this, "st_period", st_periodid, "结账", "会计期间结账成功").getSQL());
+                    DataContrlLog.createLog(this, "st_period", st_periodid, "库存结账", "会计期间库存结账成功").getSQL());
         } else {
+            sqlList.add("delete from sa_inventoryear where year="+rows.get(0).getLong("year")+" and month="+rows.get(0).getLong("month"));
             sqlList.add(
-                    DataContrlLog.createLog(this, "st_period", st_periodid, "反结账", "会计期间反结账成功").getSQL());
+                    DataContrlLog.createLog(this, "st_period", st_periodid, "反库存结账", "会计期间反库存结账成功").getSQL());
         }
 
         dbConnect.runSqlUpdate(sqlList);