|
|
@@ -37,33 +37,40 @@ public class costProductShipFormAfterSave extends ExecuteListener {
|
|
|
conn = DBSql.open();
|
|
|
conn.setAutoCommit(false);
|
|
|
|
|
|
- int shipQuantity = ObjToInt(productBO.get("QUANTITY"));
|
|
|
- // String SERIAL_NUMBERS = productBO.getString("SN");
|
|
|
+ int shipQuantity = ObjToInt(productBO.get("QUANTITY"));//配送数量
|
|
|
int notShipQuantity = ObjToInt(productBO.get("OLD_QUANTITY")) - shipQuantity;//剩余数量;
|
|
|
|
|
|
String SN = productBO.getString("SN");//原产品序列号
|
|
|
- String notShipSN = "," + SN + ",";
|
|
|
String SHIPPING_SN = productBO.getString("SHIPPING_SN");//配送产品序列号
|
|
|
- for (String spsn : SHIPPING_SN.split(",")) {
|
|
|
- notShipSN = notShipSN.replaceAll("," + spsn + ",", ",");
|
|
|
+ if (StringUtils.isNotBlank(SN) && StringUtils.isBlank(SHIPPING_SN)) {
|
|
|
+ throw new BPMNError("请选择要配送的产品");
|
|
|
+ }
|
|
|
+ String notShipSN = "";
|
|
|
+ if (StringUtils.isNotBlank(SN) && StringUtils.isNotBlank(SHIPPING_SN)) {
|
|
|
+ notShipSN = "," + SN + ",";
|
|
|
+ for (String spsn : SHIPPING_SN.split(",")) {
|
|
|
+ notShipSN = notShipSN.replaceAll("," + spsn + ",", ",");
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotBlank(notShipSN) && notShipSN.length() > 1 && !notShipSN.equals(",,"))
|
|
|
+ notShipSN = notShipSN.substring(1, notShipSN.length() - 1);//未配送的产品序列号
|
|
|
+ else
|
|
|
+ notShipSN = "";
|
|
|
}
|
|
|
- notShipSN = notShipSN.substring(1, notShipSN.length() - 1);//未配送的产品序列号
|
|
|
-
|
|
|
|
|
|
+ String oldStatusId = productBO.getString("STATUS_ID");//原状态
|
|
|
//全部配送
|
|
|
if (ObjToInt(productBO.get("OLD_QUANTITY")) == shipQuantity) {
|
|
|
productBO.set("IS_SHIP", "2");
|
|
|
productBO.set("STATUS_ID", 2159);
|
|
|
- SDK.getBOAPI().update("BO_EU_DNCTT_CONTRACT_COST_PRODUCT", productBO, conn);
|
|
|
+ //SDK.getBOAPI().update("BO_EU_DNCTT_CONTRACT_COST_PRODUCT", productBO, conn);
|
|
|
} else {
|
|
|
//部分配送
|
|
|
productBO.set("SN", SHIPPING_SN);
|
|
|
productBO.set("IS_SHIP", "2");
|
|
|
productBO.set("QUANTITY", shipQuantity);
|
|
|
- productBO.set("OLD_QUANTITY", productBO.get("QUANTITY"));
|
|
|
+ productBO.set("OLD_QUANTITY", shipQuantity);
|
|
|
productBO.set("STATUS_ID", 2159);//已配送
|
|
|
-
|
|
|
- SDK.getBOAPI().update("BO_EU_DNCTT_CONTRACT_COST_PRODUCT", productBO, conn);
|
|
|
+ //SDK.getBOAPI().update("BO_EU_DNCTT_CONTRACT_COST_PRODUCT", productBO, conn);
|
|
|
|
|
|
//未配送的生成一个新的物流单
|
|
|
BO toCostProductBO = new BO();
|
|
|
@@ -73,10 +80,12 @@ public class costProductShipFormAfterSave extends ExecuteListener {
|
|
|
toCostProductBO.set("WAREHOUSE_ID", productBO.get("WAREHOUSE_ID"));
|
|
|
toCostProductBO.set("CONTRACT_COST_ID", productBO.get("CONTRACT_COST_ID"));
|
|
|
toCostProductBO.set("QUANTITY", notShipQuantity);
|
|
|
- toCostProductBO.set("STATUS_ID", 2157);//已拣货
|
|
|
- toCostProductBO.set("OLD_QUANTITY", toCostProductBO.get("QUANTITY"));//配送数量
|
|
|
- productBO.set("SN", notShipSN);//未配送的产品序列号
|
|
|
- SDK.getBOAPI().createDataBO("BO_EU_DNCTT_CONTRACT_COST_PRODUCT", toCostProductBO, processExecutionContext.getUserContext(), conn);
|
|
|
+ toCostProductBO.set("ORDER_ID", productBO.getString("ORDER_ID"));
|
|
|
+ toCostProductBO.set("STATUS_ID", oldStatusId);
|
|
|
+ toCostProductBO.set("OLD_QUANTITY", notShipQuantity);//配送数量
|
|
|
+ toCostProductBO.set("SN", notShipSN);//未配送的产品序列号
|
|
|
+ toCostProductBO.set("SHIPPING_SN", notShipSN);
|
|
|
+ SDK.getBOAPI().create("BO_EU_DNCTT_CONTRACT_COST_PRODUCT", toCostProductBO, processInstance, processExecutionContext.getUserContext(), conn);
|
|
|
}
|
|
|
|
|
|
BO costBO = SDK.getBOAPI().get("BO_EU_DNCTT_CONTRACT_COST", productBO.getString("CONTRACT_COST_ID"));//获取合同产品
|
|
|
@@ -105,11 +114,24 @@ public class costProductShipFormAfterSave extends ExecuteListener {
|
|
|
fromWarehouseProductBO.set("QUANTITY", ObjToInt(fromWarehouseProductBO.get("QUANTITY")) - ObjToInt(shipQuantity));
|
|
|
SDK.getBOAPI().update("BO_EU_DNIVT_WAREHOUSE_PRODUCT", fromWarehouseProductBO, conn);
|
|
|
|
|
|
+ List<BO> lots = null;
|
|
|
+ //出库方式
|
|
|
+ String OUT_RULE = DBSql.getString(conn, "SELECT OUT_RULE FROM BO_EU_DNIVT_PRODUCT WHERE ID=?", new Object[]{fromWarehouseProductBO.getString("PRODUCT_ID")});
|
|
|
+
|
|
|
+ if (OUT_RULE.equals("1032"))//LIFO后进先出
|
|
|
+ {
|
|
|
+ lots = SDK.getBOAPI().query("BO_EU_DNIVT_WAREHOUSE_PRODUCT_LOT").addQuery("BINDID=", fromWarehouseProductBO.getBindId()).addQuery("QUANTITY>0", null).orderByCreated().desc().list();
|
|
|
+ } else {
|
|
|
+ //FIFO先进先出
|
|
|
+ lots = SDK.getBOAPI().query("BO_EU_DNIVT_WAREHOUSE_PRODUCT_LOT").addQuery("BINDID=", fromWarehouseProductBO.getBindId()).addQuery("QUANTITY>0", null).orderByCreated().asc().list();
|
|
|
+ }
|
|
|
+
|
|
|
//减少批次
|
|
|
- List<BO> lots = SDK.getBOAPI().query("BO_EU_DNIVT_WAREHOUSE_PRODUCT_LOT").addQuery("BINDID=", fromWarehouseProductBO.getBindId()).addQuery("QUANTITY>0", null).orderByCreated().list();
|
|
|
+ double totalCost = 0;//总成本
|
|
|
int cnt = 0;
|
|
|
- String[] shipSerials = SHIPPING_SN.split(",");
|
|
|
+ String[] shipSerials = SHIPPING_SN.split(",");//配送的批次
|
|
|
for (BO lot : lots) {
|
|
|
+ //序列号产品
|
|
|
if (StringUtils.isNotBlank(SHIPPING_SN)) {
|
|
|
boolean isIn = false;
|
|
|
String lotSN = lot.getString("SN");
|
|
|
@@ -136,7 +158,8 @@ public class costProductShipFormAfterSave extends ExecuteListener {
|
|
|
lot.set("SN", "");
|
|
|
lot.set("QUANTITY", 0);
|
|
|
}
|
|
|
-
|
|
|
+ totalCost += toSN.size() * Double.parseDouble(lot.getString("UNIT_COST"));
|
|
|
+ lot.set("SHIPPED_SN", StringUtils.join(toSN, ","));
|
|
|
//更新批次上序列号
|
|
|
SDK.getBOAPI().update("BO_EU_DNIVT_WAREHOUSE_PRODUCT_LOT", lot, conn);
|
|
|
|
|
|
@@ -146,19 +169,30 @@ public class costProductShipFormAfterSave extends ExecuteListener {
|
|
|
} else {
|
|
|
//无序列号处理
|
|
|
int QUANTITY = Integer.parseInt(lot.get("QUANTITY").toString());
|
|
|
+ int toQu = QUANTITY;
|
|
|
if (QUANTITY > shipQuantity) {
|
|
|
lot.set("QUANTITY", QUANTITY - shipQuantity);
|
|
|
- shipQuantity=0;
|
|
|
+ toQu = shipQuantity;
|
|
|
+ shipQuantity = 0;
|
|
|
+
|
|
|
} else {
|
|
|
lot.set("QUANTITY", 0);
|
|
|
+ toQu = QUANTITY;
|
|
|
shipQuantity = shipQuantity - QUANTITY;
|
|
|
}
|
|
|
+
|
|
|
+ totalCost += toQu * Double.parseDouble(lot.getString("UNIT_COST"));
|
|
|
+
|
|
|
SDK.getBOAPI().update("BO_EU_DNIVT_WAREHOUSE_PRODUCT_LOT", lot, conn);
|
|
|
- if (shipQuantity<=0)
|
|
|
+ if (shipQuantity <= 0)
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ productBO.set("UNIT_COST", totalCost / Integer.parseInt(productBO.getString("QUANTITY")));//计算平均成本
|
|
|
+
|
|
|
+ SDK.getBOAPI().update("BO_EU_DNCTT_CONTRACT_COST_PRODUCT", productBO, conn);
|
|
|
+
|
|
|
//生成运费成本
|
|
|
// 输入运费的物料计费代码,就会生成新的成本ctt_contract_cost
|
|
|
if (StringUtils.isNotBlank(productBO.getString("COST_CODE_ID"))) {
|
|
|
@@ -194,20 +228,33 @@ public class costProductShipFormAfterSave extends ExecuteListener {
|
|
|
|
|
|
|
|
|
//配送成功后,更新产品成本:产品来源于采购---从采购单获取,成本取自采购单;库存拣货,成本取自库存产品
|
|
|
+ if (DBSql.getInt(conn, "select count(ID) from BO_EU_DNCTT_CONTRACT_COST_PRODUCT where CONTRACT_COST_ID=? AND STATUS_ID<2159 AND CLOSED=0", new Object[]{costBO.getId()}) == 0) {
|
|
|
+ //已全部配送完成
|
|
|
|
|
|
+ costBO.set("STATUS_ID", 1237);//已配送
|
|
|
+ double UNIT_COST = 0;
|
|
|
+ if (OUT_RULE.equals("1030")) {
|
|
|
+ //库存平均单元成本
|
|
|
+ UNIT_COST = DBSql.getDouble(conn, "SELECT UNIT_COST_AVG FROM BO_EU_DNIVT_PRODUCT WHERE ID='" + fromWarehouseProductBO.getString("PRODUCT_ID") + "'", "UNIT_COST_AVG");
|
|
|
+
|
|
|
+ } else {
|
|
|
+ UNIT_COST = DBSql.getDouble(conn, "SELECT SUM(UNIT_COST*QUANTITY)/SUM(QUANTITY) AS UNIT_COST FROM BO_EU_DNCTT_CONTRACT_COST_PRODUCT WHERE CONTRACT_COST_ID='" + costBO.getId() + "' AND CLOSED=0", "UNIT_COST");
|
|
|
+ }
|
|
|
|
|
|
+ costBO.set("UNIT_COST", UNIT_COST);
|
|
|
+ costBO.set("EXTENDED_COST", UNIT_COST * Integer.parseInt(costBO.getString("QUANTITY")));
|
|
|
+ SDK.getBOAPI().update("BO_EU_DNCTT_CONTRACT_COST", costBO, conn);
|
|
|
|
|
|
+ }
|
|
|
conn.commit();
|
|
|
} catch (Exception e) {
|
|
|
conn.rollback();
|
|
|
+ e.printStackTrace();
|
|
|
throw new BPMNError("550", "库存转移失败");
|
|
|
} finally {
|
|
|
DBSql.close(conn);
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
}
|
|
|
|
|
|
|