Kaynağa Gözat

结账修复

shenjingwei 2 hafta önce
ebeveyn
işleme
ef1292cba9

+ 18 - 0
src/custom/restcontroller/webmanage/sale/period/SQL/本期结账库存查询.sql

@@ -0,0 +1,18 @@
+select t.itemid, t.stockid, sum(t.qty) as qty
+from (SELECT itemid, stockid, qty
+      FROM sa_inventoryear
+      WHERE YEAR = $year$ AND MONTH = $month$ and siteid=$siteid$
+      union all
+      SELECT itemid, stockid, sum (qty) qty
+      FROM (
+          SELECT t2.itemid, t2.stockid, t1.siteid, CASE WHEN type LIKE '%入%' AND rb = 1 THEN t2.qty WHEN type LIKE '%入%' AND rb = 0 THEN - t2.qty WHEN type LIKE '%出%' AND rb = 1 THEN - t2.qty WHEN type LIKE '%出%'
+          AND rb = 0 THEN t2.qty END qty FROM st_stockbill t1
+          JOIN st_stockbill_items t2 ON t1.st_stockbillid = t2.st_stockbillid AND t1.siteid = t2.siteid
+          WHERE t1.STATUS = '审核' AND ifnull(t1.typemx, '') != '正品入库' AND t1.billdate >= $begdate$ AND t1.billdate <= $enddate$ and t1.siteid=$siteid$
+          UNION ALL
+          SELECT t2.itemid, t2.stockid, t1.siteid, CASE WHEN type LIKE '%入%' AND rb = 1 THEN t2.qty WHEN type LIKE '%入%' AND rb = 0 THEN - t2.qty END qty FROM st_stockbill t1
+          JOIN st_stockbill_items t2 ON t1.st_stockbillid = t2.st_stockbillid AND t1.siteid = t2.siteid
+          WHERE t1.STATUS = '审核' AND ifnull(t1.typemx, '') = '正品入库' AND ifnull(t2.amount, 0) != 0 AND t1.billdate >= $begdate$ AND t1.billdate <= $enddate$ and t1.siteid=$siteid$) t
+      GROUP BY itemid, stockid, siteid) t
+group by t.itemid, t.stockid
+having sum(t.qty)!=0

+ 41 - 32
src/custom/restcontroller/webmanage/sale/period/period.java

@@ -237,38 +237,47 @@ public class period extends Controller {
             // 获取上一个月
             YearMonth previousMonth = specificYearMonth.minusMonths(1);
 
-            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 t1.billdate >='" + rows.get(0).getString("begdate") + "'\n" +
-                    "\t\t\t\t\t\tand t1.billdate <='" + 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 t1.billdate >='" + rows.get(0).getString("begdate") + "'\n" +
-                    "\t\t\t\t\t\tand t1.billdate <='" + 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 t1.billdate >='" + rows.get(0).getString("begdate") + "'\n" +
+//                    "\t\t\t\t\t\tand t1.billdate <='" + 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 t1.billdate >='" + rows.get(0).getString("begdate") + "'\n" +
+//                    "\t\t\t\t\t\tand t1.billdate <='" + 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 ");
+
+            SQLFactory sqlFactory = new SQLFactory(this, "本期结账库存查询");
+            sqlFactory.addParameter("siteid", siteid);
+            sqlFactory.addParameter("year", previousMonth.getYear());
+            sqlFactory.addParameter("month", previousMonth.getMonthValue());
+            sqlFactory.addParameter("begdate", rows.get(0).getString("begdate"));
+            sqlFactory.addParameter("enddate", rows.get(0).getString("enddate"));
+            Rows invbalRows = dbConnect.runSqlQuery(sqlFactory.getSQL());
+
             if (invbalRows.isNotEmpty()) {
                 for (Row row : invbalRows) {
                     InsertSQL insertSQL = SQLFactory.createInsertSQL(this, "sa_inventoryear");