|
|
@@ -908,7 +908,6 @@ public class stockbill extends Controller {
|
|
|
String sku = content.getString("sku");
|
|
|
long st_stockbillid = content.getLong("st_stockbillid");
|
|
|
long st_stockbill_itemsid = content.getLong("st_stockbill_itemsid");
|
|
|
- ArrayList<String> sqllist = new ArrayList<>();
|
|
|
String ss = "&&%$&&";
|
|
|
if (sku.contains(",")) {
|
|
|
ss = ",";
|
|
|
@@ -925,13 +924,10 @@ public class stockbill extends Controller {
|
|
|
|
|
|
Rows rows = dbConnect.runSqlQuery("select t1.*,t2.stockno from st_stockbill t1 left join st_stock t2 on t1.stockid=t2.stockid where t1.st_stockbillid ='"
|
|
|
+ st_stockbillid + "' and t1.siteid='" + siteid + "'");
|
|
|
- Rows stockbillitemsrows = dbConnect.runSqlQuery("select t1.itemid,t1.qty,t2.skucontrol from st_stockbill_items t1 left join plm_item t2 on t1.itemid=t2.itemid where t1.st_stockbillid ='"
|
|
|
- + st_stockbillid + "' and t1.siteid='" + siteid + "'");
|
|
|
- Rows stockbillitemskurows = dbConnect.runSqlQuery("select * from st_stockbill_items_sku where st_stockbillid ='"
|
|
|
- + st_stockbillid + "' and siteid='" + siteid + "'");
|
|
|
+
|
|
|
QuerySQL skuQuerySQL = SQLFactory.createQuerySQL(this, "sa_itemsku","*");
|
|
|
skuQuerySQL.setTableAlias("t1");
|
|
|
- skuQuerySQL.addJoinTable(JOINTYPE.left, "plm_item", "t2", "t1.itemid=t2.itemid","itemno");
|
|
|
+ skuQuerySQL.addJoinTable(JOINTYPE.left, "plm_item", "t2", "t1.itemid=t2.itemid","itemno","itemame","model");
|
|
|
skuQuerySQL.addJoinTable(JOINTYPE.left, "st_stock", "t3", "t1.stockid=t3.stockid","stockno");
|
|
|
skuQuerySQL.setWhere("t1.siteid",siteid);
|
|
|
skuQuerySQL.setWhere("t1.sku",CODE);
|
|
|
@@ -943,6 +939,12 @@ public class stockbill extends Controller {
|
|
|
}
|
|
|
Row st_stockbill = rows.get(0);
|
|
|
for (String FMACHINECODE : CODE) {
|
|
|
+ Rows stockbillitemsrows = dbConnect.runSqlQuery("select t1.itemid,t1.qty,t2.skucontrol from st_stockbill_items t1 left join plm_item t2 on t1.itemid=t2.itemid where t1.st_stockbillid ='"
|
|
|
+ + st_stockbillid + "' and t1.siteid='" + siteid + "'");
|
|
|
+ Rows stockbillitemskurows = dbConnect.runSqlQuery("select t1.*,t2.itemid from st_stockbill_items_sku t1 left join sa_itemsku t2 on t1.sku=t2.sku where t1.st_stockbillid ='"
|
|
|
+ + st_stockbillid + "' and t1.siteid='" + siteid + "'");
|
|
|
+
|
|
|
+ ArrayList<String> sqllist = new ArrayList<>();
|
|
|
if (FMACHINECODE.equals("")) {
|
|
|
continue;
|
|
|
}
|
|
|
@@ -985,7 +987,7 @@ public class stockbill extends Controller {
|
|
|
if (skustockid == 0 && stockid == 0) {
|
|
|
return getErrReturnObject().setErrMsg("请指定仓库").toString();
|
|
|
}
|
|
|
- if (!stockbillitemsrows.toRowsMap("skucontrol").get("1").toRowsMap("itemid").containsKey(
|
|
|
+ if (st_stockbill.getString("status").equals("审核") && !stockbillitemsrows.toRowsMap("skucontrol").get("1").toRowsMap("itemid").containsKey(
|
|
|
skuRowsMap.get(FMACHINECODE).get(0).getString("itemid"))) {
|
|
|
return getErrReturnObject().setErrMsg("序列号所属的商品编号没有包含在单据表体中").toString();
|
|
|
}
|
|
|
@@ -1018,23 +1020,77 @@ public class stockbill extends Controller {
|
|
|
scanqtyrefresh();
|
|
|
}
|
|
|
|
|
|
- InsertSQL insertSQL = SQLFactory.createInsertSQL(this, "st_stockbill_items_sku");
|
|
|
- long st_stockbill_items_skuid = createTableID("st_stockbill_items_sku");
|
|
|
- insertSQL.setUniqueid(st_stockbill_items_skuid);
|
|
|
- insertSQL.setSiteid(siteid);
|
|
|
+
|
|
|
if (stockrows.isNotEmpty()) {
|
|
|
skustockid = stockrows.get(0).getLong("stockid");
|
|
|
}
|
|
|
if (stockid == 0) {
|
|
|
skustockid = st_stockbill.getLong("stockid");
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
+ InsertSQL insertSQL = SQLFactory.createInsertSQL(this, "st_stockbill_items_sku");
|
|
|
+ long st_stockbill_items_skuid = createTableID("st_stockbill_items_sku");
|
|
|
+ insertSQL.setUniqueid(st_stockbill_items_skuid);
|
|
|
+ insertSQL.setSiteid(siteid);
|
|
|
insertSQL.setValue("stockid", skustockid);
|
|
|
insertSQL.setValue("itemid", skuitemid);
|
|
|
insertSQL.setValue("sku", FMACHINECODE);
|
|
|
- insertSQL.setValue("st_stockbillid", st_stockbillid);
|
|
|
- insertSQL.setValue("st_stockbill_itemsid", st_stockbill_itemsid==0?st_stockbillid:st_stockbill_itemsid);
|
|
|
+
|
|
|
+
|
|
|
+ if(!st_stockbill.getString("status").equals("审核")){
|
|
|
+ if(st_stockbill_itemsid==0){
|
|
|
+ if(!stockbillitemsrows.toRowsMap("itemid").containsKey(skuitemid)){
|
|
|
+ //新建表体
|
|
|
+ InsertSQL insertdetailSQL = SQLFactory.createInsertSQL(this, "st_stockbill_items");
|
|
|
+ long st_stockbill_itemsidnew = createTableID("st_stockbill_items");
|
|
|
+ insertdetailSQL.setUniqueid(st_stockbill_itemsidnew);
|
|
|
+ insertdetailSQL.setSiteid(siteid);
|
|
|
+ insertdetailSQL.setValue("rowno", 1);
|
|
|
+ insertdetailSQL.setValue("sa_dispatch_itemsid", 0);
|
|
|
+ insertdetailSQL.setValue("stockid",skustockid);
|
|
|
+ insertdetailSQL.setValue("itemid", skuitemid);
|
|
|
+ insertdetailSQL.setValue("itemno", skuRowsMap.get(FMACHINECODE).get(0).getString("itemno"));
|
|
|
+ insertdetailSQL.setValue("itemname", skuRowsMap.get(FMACHINECODE).get(0).getString("itemname"));
|
|
|
+ insertdetailSQL.setValue("model", skuRowsMap.get(FMACHINECODE).get(0).getString("model"));
|
|
|
+ insertdetailSQL.setValue("qty", 1);
|
|
|
+ insertdetailSQL.setValue("sku", FMACHINECODE);
|
|
|
+ insertdetailSQL.setValue("st_stockbillid", st_stockbillid);
|
|
|
+ sqllist.add(insertdetailSQL.getSQL());
|
|
|
+ insertSQL.setValue("st_stockbillid", st_stockbillid);
|
|
|
+ insertSQL.setValue("st_stockbill_itemsid", st_stockbill_itemsidnew);
|
|
|
+ }else{
|
|
|
+ if(stockbillitemsrows.toRowsMap("itemid").get(skuitemid).sum("qty").compareTo(stockbillitemskurows.toRowsMap("itemid").get(skuitemid).sum("qty"))<=0){
|
|
|
+ BigDecimal newqty = stockbillitemskurows.toRowsMap("itemid").get(skuitemid).sum("qty").subtract(stockbillitemsrows.toRowsMap("itemid").get(skuitemid).sum("qty")).add(BigDecimal.ONE);
|
|
|
+ sqllist.add("update set st_stockbill_items set qty=qty+"+newqty+" where st_stockbill_itemsid ="+stockbillitemsrows.toRowsMap("itemid").get(skuitemid).get(0).getLong("st_stockbill_itemsid"));
|
|
|
+ }
|
|
|
+ insertSQL.setValue("st_stockbillid", st_stockbillid);
|
|
|
+ insertSQL.setValue("st_stockbill_itemsid", stockbillitemsrows.toRowsMap("itemid").get(skuitemid).get(0).getLong("st_stockbill_itemsid"));
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ if(stockbillitemsrows.toRowsMap("st_stockbill_itemsid").get("st_stockbill_itemsid").sum("qty").compareTo(stockbillitemskurows.toRowsMap("st_stockbill_itemsid").get(st_stockbill_itemsid).sum("qty"))<=0){
|
|
|
+ BigDecimal newqty = stockbillitemskurows.toRowsMap("st_stockbill_itemsid").get(st_stockbill_itemsid).sum("qty").add(BigDecimal.ONE);
|
|
|
+ sqllist.add("update set st_stockbill_items set qty="+newqty+" where st_stockbill_itemsid ="+st_stockbill_itemsid);
|
|
|
+ }
|
|
|
+ insertSQL.setValue("st_stockbillid", st_stockbillid);
|
|
|
+ insertSQL.setValue("st_stockbill_itemsid", st_stockbill_itemsid);
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ if(st_stockbill_itemsid==0){
|
|
|
+ if(stockbillitemsrows.toRowsMap("itemid").get(skuitemid).sum("qty").compareTo(stockbillitemskurows.toRowsMap("itemid").get(skuitemid).sum("qty"))==0){
|
|
|
+ return getErrReturnObject().setErrMsg("序列号数量已经满足,不可继续添加").toString();
|
|
|
+ }else{
|
|
|
+ insertSQL.setValue("st_stockbillid", st_stockbillid);
|
|
|
+ insertSQL.setValue("st_stockbill_itemsid", st_stockbillid);
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ if(stockbillitemsrows.toRowsMap("st_stockbill_itemsid").get(st_stockbill_itemsid).sum("qty").compareTo(stockbillitemskurows.toRowsMap("st_stockbill_itemsid").get(st_stockbill_itemsid).sum("qty"))==0){
|
|
|
+ return getErrReturnObject().setErrMsg("序列号数量已经满足,不可继续添加").toString();
|
|
|
+ }else{
|
|
|
+ insertSQL.setValue("st_stockbillid", st_stockbillid);
|
|
|
+ insertSQL.setValue("st_stockbill_itemsid", st_stockbill_itemsid);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
sqllist.add(insertSQL.getSQL());
|
|
|
if (st_stockbill.getString("status").equals("审核")) {
|
|
|
if (isinstock(st_stockbill.getString("type"), st_stockbill.getString("rb"), true)) {
|
|
|
@@ -1053,9 +1109,8 @@ public class stockbill extends Controller {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+ dbConnect.runSqlUpdate(sqllist);
|
|
|
}
|
|
|
- dbConnect.runSqlUpdate(sqllist);
|
|
|
return getSucReturnObject().toString();
|
|
|
}
|
|
|
|
|
|
@@ -1065,13 +1120,24 @@ public class stockbill extends Controller {
|
|
|
long st_stockbillid = content.getLong("st_stockbillid");
|
|
|
ArrayList<String> sqllist = new ArrayList<>();
|
|
|
Rows stockbillskuRows = dbConnect.runSqlQuery("select t1.sku,t2.itemid,t1.st_stockbill_items_skuid from st_stockbill_items_sku t1 left join sa_itemsku t2 on t1.sku=t2.sku where t1.st_stockbillid=t1.st_stockbill_itemsid and t1.st_stockbillid="+st_stockbillid);
|
|
|
- Rows stockbilldetailRows = dbConnect.runSqlQuery("select t1.itemid,t1.st_stockbill_itemsid from st_stockbill_items t1 where t1.st_stockbillid="+st_stockbillid);
|
|
|
+ Rows stockbilldetailRows = dbConnect.runSqlQuery("select t1.itemid,t1.st_stockbill_itemsid,(t1.qty-t2.smqty) qty from st_stockbill_items t1 inner join (select st_stockbill_itemsid,count(1) smqty from st_stockbill_items_sku where st_stockbillid='"+st_stockbillid+"' and st_stockbillid!=st_stockbill_itemsid group by st_stockbill_itemsid) t2 on t1.st_stockbill_itemsid=t2.st_stockbill_itemsid where t1.st_stockbillid="+st_stockbillid +" and skucontrol=1");
|
|
|
RowsMap stockbilldetailRowsMap = stockbilldetailRows.toRowsMap("itemid");
|
|
|
+ HashMap<String,Integer> itemqtymap =new HashMap<>();
|
|
|
for(Row row :stockbillskuRows){
|
|
|
String itemid = row.getString("itemid");
|
|
|
+ if(itemqtymap.containsKey(itemid)){
|
|
|
+ itemqtymap.put(itemid,itemqtymap.get(itemid)+1);
|
|
|
+ }else{
|
|
|
+ itemqtymap.put(itemid,1);
|
|
|
+ }
|
|
|
long st_stockbill_items_skuid =row.getLong("st_stockbill_items_skuid");
|
|
|
if(stockbilldetailRowsMap.containsKey(itemid)){
|
|
|
- sqllist.add("update st_stockbill_items_sku set st_stockbill_itemsid="+stockbilldetailRowsMap.get(itemid).get(0).getLong("st_stockbill_itemsid")+" where st_stockbill_items_skuid="+st_stockbill_items_skuid);
|
|
|
+ for(Row rowdetail :stockbilldetailRowsMap.get(itemid)){
|
|
|
+ if(rowdetail.getInteger("qty")>=itemqtymap.get(itemid)){
|
|
|
+ sqllist.add("update st_stockbill_items_sku set st_stockbill_itemsid="+rowdetail.getLong("st_stockbill_itemsid")+" where st_stockbill_items_skuid="+st_stockbill_items_skuid);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|