|
|
@@ -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");
|