|
|
@@ -20,6 +20,119 @@ public class sendplandetail extends Controller {
|
|
|
super(content);
|
|
|
}
|
|
|
|
|
|
+ @API(title = "订单信息刷新(新)", apiversion = R.ID2025122609083103.v1.class)
|
|
|
+ public String orderRefresh_newtest() throws YosException {
|
|
|
+ long sa_sendplanid = content.getLongValue("sa_sendplanid");
|
|
|
+ Rows sendplanRows = dbConnect.runSqlQuery("select * from sa_sendplan where sa_sendplanid='" + sa_sendplanid + "' and siteid='" + siteid + "'");
|
|
|
+ if (sendplanRows.isEmpty()) {
|
|
|
+ return getErrReturnObject().setErrMsg("发货计划不存在,无法进行订单信息刷新").toString();
|
|
|
+ }
|
|
|
+ dbConnect.runSqlUpdate("delete from sa_sendplandetail where sa_sendplanid='" + sa_sendplanid + "' and siteid='" + siteid + "'");
|
|
|
+ /*
|
|
|
+ 过滤条件设置
|
|
|
+ */
|
|
|
+ StringBuffer where = new StringBuffer(" 1=1 and t1.undeliqty>0 and t3.type='" + sendplanRows.get(0).getString("type")
|
|
|
+ + "' and DATE_FORMAT(t3.checkdate, '%Y-%m-%d') >='" + sendplanRows.get(0).getString("begindate")
|
|
|
+ + "' and DATE_FORMAT(t3.checkdate, '%Y-%m-%d') <='" + sendplanRows.get(0).getString("enddate")
|
|
|
+ + "' and ( \n" +
|
|
|
+ "\t\t(t3.type in('标准订单','网销订单')) or\n" +
|
|
|
+ "\t\t(\n" +
|
|
|
+ "\t\t\tt3.type='配件订单'\n" +
|
|
|
+ "\t\t\tand t3.sys_enterpriseid in (\n" +
|
|
|
+ "\t\t\tselect distinct sys_enterpriseid from st_stockbill \n" +
|
|
|
+ "\t\t\twhere type='销售出库' and status='审核' and \n" +
|
|
|
+ "\t\t\tbilldate= '" + sendplanRows.get(0).getString("senddate") + "'\n" +
|
|
|
+ "\t\t\t)\n" +
|
|
|
+ "\t\t))");
|
|
|
+
|
|
|
+ SQLFactory sqlFactory = new SQLFactory(this, "发货计划订单未发货量(新)");
|
|
|
+ sqlFactory.addParameter_SQL("where", where);
|
|
|
+ sqlFactory.addParameter("siteid", siteid);
|
|
|
+ Rows rows = dbConnect.runSqlQuery(sqlFactory.getSQL());
|
|
|
+
|
|
|
+ Rows stockbillrows = dbConnect.runSqlQuery("select t2.itemid,sum(t2.undeliqty) qty from sa_order t1 " +
|
|
|
+ " inner join sa_orderitems t2 on t1.sa_orderid=t2.sa_orderid " +
|
|
|
+ " where t1.status='审核' and t2.isclose=0 and t2.undeliqty>0 and t1.siteid='" + siteid + "' " +
|
|
|
+ " group by t2.itemid ");
|
|
|
+ Rows invbalSalerows = dbConnect.runSqlQuery("select itemid,qty from st_invbal_sale");
|
|
|
+
|
|
|
+ RowsMap stockbillrowsMap = stockbillrows.toRowsMap("itemid");
|
|
|
+ RowsMap invbalSalerowsMap = invbalSalerows.toRowsMap("itemid");
|
|
|
+
|
|
|
+ ArrayList<String> list = new ArrayList<>();
|
|
|
+
|
|
|
+ long oldItemid= 0;
|
|
|
+ BigDecimal oldWilloutqty = BigDecimal.ZERO;
|
|
|
+ BigDecimal oldCanuseqty = BigDecimal.ZERO;
|
|
|
+ BigDecimal oldSendqty = BigDecimal.ZERO;
|
|
|
+ long[] sendplandetailids = createTableID("sa_sendplandetail", rows.size());
|
|
|
+ int i=0;
|
|
|
+ for (Row row :rows) {
|
|
|
+ InsertSQL insertSQL = SQLFactory.createInsertSQL(this, "sa_sendplandetail");
|
|
|
+ insertSQL.setUniqueid(sendplandetailids[i++]);
|
|
|
+ insertSQL.setSiteid(siteid);
|
|
|
+ insertSQL.setValue("sa_sendplanid", sa_sendplanid);
|
|
|
+ insertSQL.setValue("sa_orderid", row.getLong("sa_orderid"));
|
|
|
+ insertSQL.setValue("sa_orderitemsid", row.getLong("sa_orderitemsid"));
|
|
|
+ insertSQL.setValue("outplace", row.getString("outplace"));
|
|
|
+ insertSQL.setValue("sa_agentsid", row.getString("sa_agentsid"));
|
|
|
+ BigDecimal willoutqty = BigDecimal.ZERO;
|
|
|
+ BigDecimal invbalqty = BigDecimal.ZERO;
|
|
|
+ if (stockbillrowsMap.containsKey(row.getString("itemid"))) {
|
|
|
+ willoutqty = stockbillrowsMap.get(row.getString("itemid")).get(0).getBigDecimal("qty");
|
|
|
+ }
|
|
|
+ if (invbalSalerowsMap.containsKey(row.getString("itemid"))) {
|
|
|
+ // 查询库存总量
|
|
|
+ invbalqty = invbalSalerowsMap.get(row.getString("itemid")).get(0).getBigDecimal("qty");
|
|
|
+ }
|
|
|
+ insertSQL.setValue("willinqty", willoutqty);
|
|
|
+ insertSQL.setValue("sendqty", getBigDecimalOrZero(row.getBigDecimal("sendqty")));
|
|
|
+
|
|
|
+
|
|
|
+ long currentitemid = row.getLong("itemid");
|
|
|
+
|
|
|
+ if (oldItemid == 0 || oldItemid!=currentitemid) {
|
|
|
+ // 新物料
|
|
|
+ oldWilloutqty =willoutqty;
|
|
|
+
|
|
|
+ oldCanuseqty = invbalqty.subtract(oldWilloutqty);
|
|
|
+ } else {
|
|
|
+ // 相同物料
|
|
|
+ oldCanuseqty = oldCanuseqty.subtract(oldSendqty);
|
|
|
+ oldWilloutqty = oldWilloutqty.add(oldSendqty);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 设置计算后的值
|
|
|
+ insertSQL.setValue("canuseqty",oldCanuseqty);
|
|
|
+ insertSQL.setValue("willinqty",oldWilloutqty);
|
|
|
+
|
|
|
+
|
|
|
+ // 如果可用量<=0,设置发货量为0
|
|
|
+ if (oldCanuseqty.compareTo(BigDecimal.ZERO) <= 0) {
|
|
|
+ insertSQL.setValue("sendqty",BigDecimal.ZERO);
|
|
|
+ insertSQL.setValue("colorflag", 0);
|
|
|
+ }else{
|
|
|
+ if (oldCanuseqty.compareTo(row.getBigDecimal("sendqty")) >= 0) {
|
|
|
+ insertSQL.setValue("colorflag", 2);
|
|
|
+ } else {
|
|
|
+ insertSQL.setValue("colorflag", 3);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 保存当前值供下次循环使用
|
|
|
+ oldItemid = currentitemid;
|
|
|
+ oldSendqty = getBigDecimalOrZero(row.getBigDecimal("sendqty")).compareTo(BigDecimal.ZERO)>0?getBigDecimalOrZero(row.getBigDecimal("sendqty")):BigDecimal.ZERO;
|
|
|
+ list.add(insertSQL.getSQL());
|
|
|
+ }
|
|
|
+ dbConnect.runSqlUpdate(list);
|
|
|
+ list = new ArrayList<>();
|
|
|
+ Rows rows1 = dbConnect.runSqlQuery("select t1.sa_orderid from (select sa_orderid,count(0)count from sa_sendplandetail where sa_sendplanid=" + sa_sendplanid + " group by sa_orderid) t1 inner join (select sa_orderid,count(0)count from sa_sendplandetail where colorflag='2' and sa_sendplanid=" + sa_sendplanid + " group by sa_orderid) t2 on t1.sa_orderid=t2.sa_orderid and t1.count=t2.count");
|
|
|
+ for (Row row : rows1) {
|
|
|
+ list.add("update sa_sendplandetail set colorflag=1 where sa_sendplanid=" + sa_sendplanid + " and sa_orderid =" + row.getLong("sa_orderid"));
|
|
|
+ }
|
|
|
+ return getSucReturnObject().toString();
|
|
|
+ }
|
|
|
+
|
|
|
//ID2025120110193103
|
|
|
@API(title = "订单信息刷新(新)", apiversion = R.ID2025120110193103.v1.class)
|
|
|
public String orderRefresh_new() throws YosException {
|
|
|
@@ -55,14 +168,15 @@ public class sendplandetail extends Controller {
|
|
|
" inner join sa_orderitems t2 on t1.sa_orderid=t2.sa_orderid " +
|
|
|
" where t1.status='审核' and t2.isclose=0 and t2.undeliqty>0 and t1.siteid='" + siteid + "' " +
|
|
|
" group by t2.itemid ");
|
|
|
- Rows invbalrows = dbConnect.runSqlQuery("select itemid,sum(qty) qty from st_invbal t1 group by itemid");
|
|
|
+ Rows invbalSalerows = dbConnect.runSqlQuery("select itemid,qty from st_invbal_sale");
|
|
|
|
|
|
RowsMap stockbillrowsMap = stockbillrows.toRowsMap("itemid");
|
|
|
- RowsMap invbalrowsMap = invbalrows.toRowsMap("itemid");
|
|
|
+ RowsMap invbalSalerowsMap = invbalSalerows.toRowsMap("itemid");
|
|
|
|
|
|
ArrayList<String> list = new ArrayList<>();
|
|
|
long olditemid = 0;
|
|
|
BigDecimal oldcanuseqty = BigDecimal.ZERO;
|
|
|
+ BigDecimal oldwilloutqty = BigDecimal.ZERO;
|
|
|
BigDecimal oldsendqty = BigDecimal.ZERO;
|
|
|
long[] sendplandetailids = createTableID("sa_sendplandetail", rows.size());
|
|
|
int i = 0;
|
|
|
@@ -84,26 +198,32 @@ public class sendplandetail extends Controller {
|
|
|
if (stockbillrowsMap.containsKey(row.getString("itemid"))) {
|
|
|
willoutqty = stockbillrowsMap.get(row.getString("itemid")).get(0).getBigDecimal("qty");
|
|
|
}
|
|
|
- if (invbalrowsMap.containsKey(row.getString("itemid"))) {
|
|
|
- invbalqty = invbalrowsMap.get(row.getString("itemid")).get(0).getBigDecimal("qty");
|
|
|
+ if (invbalSalerowsMap.containsKey(row.getString("itemid"))) {
|
|
|
+ invbalqty = invbalSalerowsMap.get(row.getString("itemid")).get(0).getBigDecimal("qty");
|
|
|
}
|
|
|
canuseqty = invbalqty.subtract(willoutqty);
|
|
|
|
|
|
- insertSQL.setValue("willoutqty", willoutqty);
|
|
|
+
|
|
|
insertSQL.setValue("willinqty", 0);
|
|
|
insertSQL.setValue("canuseqty", canuseqty);
|
|
|
|
|
|
+
|
|
|
+
|
|
|
if (row.getLong("itemid") == olditemid) {
|
|
|
+ insertSQL.setValue("willoutqty", (oldwilloutqty.compareTo(BigDecimal.ZERO) == 0 ? willoutqty : oldwilloutqty).add(oldsendqty));
|
|
|
insertSQL.setValue("canuseqty", (oldcanuseqty.compareTo(BigDecimal.ZERO) == 0 ? canuseqty : oldcanuseqty).subtract(oldsendqty));
|
|
|
newcanuseqty=(oldcanuseqty.compareTo(BigDecimal.ZERO) == 0 ? canuseqty : oldcanuseqty).subtract(oldsendqty);
|
|
|
- oldcanuseqty = (oldcanuseqty.compareTo(BigDecimal.ZERO) == 0 ? canuseqty : oldcanuseqty).subtract(oldsendqty);
|
|
|
+ oldcanuseqty=(oldcanuseqty.compareTo(BigDecimal.ZERO) == 0 ? canuseqty : oldcanuseqty).subtract(oldsendqty);
|
|
|
+
|
|
|
} else {
|
|
|
+ insertSQL.setValue("willoutqty", willoutqty);
|
|
|
insertSQL.setValue("canuseqty", canuseqty);
|
|
|
newcanuseqty=canuseqty;
|
|
|
}
|
|
|
|
|
|
if (newcanuseqty.compareTo(BigDecimal.ZERO) <= 0) {
|
|
|
- insertSQL.setValue("sendqty", 0);
|
|
|
+ sendqty=BigDecimal.ZERO;
|
|
|
+ insertSQL.setValue("sendqty", sendqty);
|
|
|
insertSQL.setValue("colorflag", 0);
|
|
|
} else {
|
|
|
sendqty = row.getBigDecimal("sendqty");
|
|
|
@@ -192,11 +312,11 @@ public class sendplandetail extends Controller {
|
|
|
" inner join sa_orderitems t2 on t1.sa_orderid=t2.sa_orderid " +
|
|
|
" where t1.status='审核' and t2.isclose=0 and t2.undeliqty>0 and t1.siteid='" + siteid + "' " +
|
|
|
" group by t2.itemid ");
|
|
|
- Rows invbalrows = dbConnect.runSqlQuery("select itemid,sum(qty) qty from st_invbal t1 group by itemid");
|
|
|
+ Rows invbalSalerows = dbConnect.runSqlQuery("select itemid,qty from st_invbal_sale");
|
|
|
Rows sendplandetails = dbConnect.runSqlQuery("select t1.sa_sendplandetailid,t1.sa_orderid,t2.itemid,t1.sendqty from sa_sendplandetail t1 inner join sa_orderitems t2 on t1.sa_orderitemsid=t2.sa_orderitemsid and t1.siteid=t2.siteid where t1.sa_sendplanid=" + sa_sendplanid + " and t1.siteid='" + siteid + "' order by t2.sa_orderid desc");
|
|
|
|
|
|
RowsMap stockbillrowsMap = stockbillrows.toRowsMap("itemid");
|
|
|
- RowsMap invbalrowsMap = invbalrows.toRowsMap("itemid");
|
|
|
+ RowsMap invbalSalerowsMap = invbalSalerows.toRowsMap("itemid");
|
|
|
for (Row row : sendplandetails) {
|
|
|
BigDecimal canuseqty = BigDecimal.ZERO;
|
|
|
BigDecimal willoutqty = BigDecimal.ZERO;
|
|
|
@@ -206,8 +326,8 @@ public class sendplandetail extends Controller {
|
|
|
if (stockbillrowsMap.containsKey(row.getString("itemid"))) {
|
|
|
willoutqty = stockbillrowsMap.get(row.getString("itemid")).get(0).getBigDecimal("qty");
|
|
|
}
|
|
|
- if (invbalrowsMap.containsKey(row.getString("itemid"))) {
|
|
|
- invbalqty = invbalrowsMap.get(row.getString("itemid")).get(0).getBigDecimal("qty");
|
|
|
+ if (invbalSalerowsMap.containsKey(row.getString("itemid"))) {
|
|
|
+ invbalqty = invbalSalerowsMap.get(row.getString("itemid")).get(0).getBigDecimal("qty");
|
|
|
}
|
|
|
canuseqty = invbalqty.subtract(willoutqty);
|
|
|
updateSQL.setValue("willoutqty", willoutqty);
|
|
|
@@ -517,6 +637,17 @@ public class sendplandetail extends Controller {
|
|
|
querySQL_ck.setWhere("t1.itemid", rows.toArrayList("itemid"));
|
|
|
Rows rows_ck = querySQL_ck.query();
|
|
|
RowsMap rowsCkRowsMap = rows_ck.toRowsMap("stockno");
|
|
|
+
|
|
|
+
|
|
|
+ QuerySQL querySQL_cksale = SQLFactory.createQuerySQL(this, "st_invbal_sale", "itemid", "qty");
|
|
|
+ querySQL_cksale.setTableAlias("t1");
|
|
|
+ querySQL_cksale.setSiteid(siteid);
|
|
|
+ querySQL_cksale.setWhere("t1.itemid", rows.toArrayList("itemid"));
|
|
|
+ Rows rows_cksale = querySQL_cksale.query();
|
|
|
+ RowsMap rows_cksaleRowsMap = rows_cksale.toRowsMap("itemid");
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
for (Row row : rows) {
|
|
|
if (rowsCkRowsMap.containsKey("101")) {
|
|
|
if (rowsCkRowsMap.get("101").toRowsMap("itemid").containsKey(row.getString("itemid"))) {
|
|
|
@@ -548,6 +679,12 @@ public class sendplandetail extends Controller {
|
|
|
row.put("qty_mq", 0);
|
|
|
}
|
|
|
|
|
|
+ if (rows_cksaleRowsMap.containsKey(row.getString("itemid"))) {
|
|
|
+ row.put("qty_total", rows_cksaleRowsMap.get(row.getString("itemid")).get(0).getBigDecimal("qty"));
|
|
|
+ } else{
|
|
|
+ row.put("qty_total", 0);
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
return getSucReturnObject().setData(rows).toString();
|
|
|
}
|
|
|
@@ -585,5 +722,7 @@ public class sendplandetail extends Controller {
|
|
|
|
|
|
return result.toString();
|
|
|
}
|
|
|
-
|
|
|
+ private BigDecimal getBigDecimalOrZero(BigDecimal value) {
|
|
|
+ return value != null ? value : BigDecimal.ZERO;
|
|
|
+ }
|
|
|
}
|