This commit is contained in:
parent
3cfbffe70b
commit
b4f0ce50d9
|
|
@ -157,7 +157,7 @@ public class MaterialOutBillPlugin extends AbstractBillPlugIn implements BeforeF
|
|||
if (warehouse != null && transType != null && "REDUCE".equals(transType.getString("type")) && org != null && material != null) {
|
||||
DynamicObject warehouse1 = (DynamicObject) warehouse;//发货仓库
|
||||
DynamicObject project = warehouse1.getDynamicObject("project");//发货仓库-项目
|
||||
QFilter qFilters = new QFilter("warehouse", QCP.equals, warehouse1.getPkValue());
|
||||
QFilter qFilters = new QFilter("warehouse", QCP.equals, warehouse1.getPkValue());//即时库存-仓库
|
||||
if (project != null) {
|
||||
qFilters.and(new QFilter("project", QCP.equals, project.getPkValue()));//即时库存-项目
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,592 @@
|
|||
//
|
||||
// Source code recreated from a .class file by IntelliJ IDEA
|
||||
// (powered by FernFlower decompiler)
|
||||
//
|
||||
|
||||
package zcgj.zcdev.zcdev.pr.plugin.operate;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
import kd.bos.dataentity.entity.DynamicObject;
|
||||
import kd.bos.dataentity.entity.DynamicObjectCollection;
|
||||
import kd.bos.dataentity.resource.ResManager;
|
||||
import kd.bos.dataentity.utils.ArrayUtils;
|
||||
import kd.bos.dataentity.utils.StringUtils;
|
||||
import kd.bos.dlock.DLock;
|
||||
import kd.bos.entity.EntityMetadataCache;
|
||||
import kd.bos.entity.plugin.AbstractOperationServicePlugIn;
|
||||
import kd.bos.entity.plugin.AddValidatorsEventArgs;
|
||||
import kd.bos.entity.plugin.PreparePropertysEventArgs;
|
||||
import kd.bos.entity.plugin.args.BeforeOperationArgs;
|
||||
import kd.bos.entity.plugin.args.BeginOperationTransactionArgs;
|
||||
import kd.bos.exception.KDBizException;
|
||||
import kd.bos.orm.ORM;
|
||||
import kd.bos.orm.query.QFilter;
|
||||
import kd.bos.servicehelper.BusinessDataServiceHelper;
|
||||
import kd.bos.servicehelper.QueryServiceHelper;
|
||||
import kd.bos.servicehelper.operation.SaveServiceHelper;
|
||||
import kd.ec.basedata.business.model.ecma.MaterialInBillConstant;
|
||||
import kd.ec.basedata.business.model.ecma.PoundConstant;
|
||||
import kd.ec.basedata.common.utils.CurrencyHelper;
|
||||
import kd.ec.contract.common.enums.BillStatusEnum;
|
||||
import kd.ec.contract.common.enums.PayDirectionEnum;
|
||||
import kd.ec.material.common.utils.MaterialInventoryUtils;
|
||||
import kd.ec.material.opplugin.validator.InvAdjustBillExistValidator;
|
||||
import kd.ec.material.opplugin.validator.MaterialInBillValidator;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
|
||||
public class MaterialInBillOpExt extends AbstractOperationServicePlugIn {
|
||||
private static final String ecco_mainmatcost = "ecco_mainmatcost";
|
||||
private static final String ecco_sporadicmatcost = "ecco_sporadicmatcost";
|
||||
private static final String success = "success";
|
||||
private DLock lock;
|
||||
|
||||
public MaterialInBillOpExt() {
|
||||
}
|
||||
|
||||
public void onPreparePropertys(PreparePropertysEventArgs e) {
|
||||
e.getFieldKeys().add(MaterialInBillConstant.ID_ENTITY_PK);
|
||||
e.getFieldKeys().add("billno");
|
||||
e.getFieldKeys().add("billname");
|
||||
e.getFieldKeys().add("transamount");
|
||||
e.getFieldKeys().add("purchaseorder");
|
||||
e.getFieldKeys().add("transtype");
|
||||
e.getFieldKeys().add("project");
|
||||
e.getFieldKeys().add("contract");
|
||||
e.getFieldKeys().add("warehouse");
|
||||
e.getFieldKeys().add("entryentity");
|
||||
e.getFieldKeys().add("ftransamount");
|
||||
e.getFieldKeys().add("amount");
|
||||
e.getFieldKeys().add("lot");
|
||||
e.getFieldKeys().add("lotid");
|
||||
e.getFieldKeys().add("material");
|
||||
e.getFieldKeys().add("measureunit");
|
||||
e.getFieldKeys().add("modelnum");
|
||||
e.getFieldKeys().add("oftaxamount");
|
||||
e.getFieldKeys().add("price");
|
||||
e.getFieldKeys().add("qty");
|
||||
e.getFieldKeys().add("orderentryid");
|
||||
e.getFieldKeys().add("ismulticurrency");
|
||||
e.getFieldKeys().add("exchangerate");
|
||||
e.getFieldKeys().add("currency");
|
||||
e.getFieldKeys().add("stdcurrency");
|
||||
e.getFieldKeys().add("exratetable");
|
||||
e.getFieldKeys().add("exchangedate");
|
||||
e.getFieldKeys().add("contract");
|
||||
e.getFieldKeys().add("unitproject");
|
||||
e.getFieldKeys().add("unitprojectpro");
|
||||
e.getFieldKeys().add("poundid");
|
||||
e.getFieldKeys().add("poundno");
|
||||
e.getFieldKeys().add("poundin");
|
||||
e.getFieldKeys().add("splittype");
|
||||
e.getFieldKeys().add("org");
|
||||
e.getFieldKeys().add("bizdate");
|
||||
}
|
||||
|
||||
public void onAddValidators(AddValidatorsEventArgs e) {
|
||||
e.getValidators().add(new MaterialInBillValidator());
|
||||
e.getValidators().add(new InvAdjustBillExistValidator());
|
||||
}
|
||||
|
||||
public void beforeExecuteOperationTransaction(BeforeOperationArgs e) {
|
||||
super.beforeExecuteOperationTransaction(e);
|
||||
String operationKey = e.getOperationKey();
|
||||
DynamicObject[] dataEntities = e.getDataEntities();
|
||||
switch (operationKey) {
|
||||
case "unaudit":
|
||||
DynamicObject[] var6 = dataEntities;
|
||||
int var7 = dataEntities.length;
|
||||
|
||||
for(int var8 = 0; var8 < var7; ++var8) {
|
||||
DynamicObject bill = var6[var8];
|
||||
String billId = bill.getString(MaterialInBillConstant.ID_ENTITY_PK);
|
||||
QFilter payDirectionFilter = new QFilter("paydirection", "=", PayDirectionEnum.OUT.getValue());
|
||||
QFilter matIdFilter = new QFilter("materialinentry.materialinbillid", "=", billId);
|
||||
QFilter[] qFilters = new QFilter[]{payDirectionFilter, matIdFilter};
|
||||
DynamicObject[] objects = BusinessDataServiceHelper.load("ec_out_contract_settle", "id,billno,materialinentry.materialinbillid", qFilters);
|
||||
if (objects.length > 0) {
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
|
||||
for(int i = 0; i < objects.length; ++i) {
|
||||
stringBuilder.append(objects[i].getString("billno"));
|
||||
if (i != objects.length - 1) {
|
||||
stringBuilder.append("、");
|
||||
}
|
||||
}
|
||||
|
||||
e.setCancel(true);
|
||||
e.setCancelMessage(String.format(ResManager.loadKDString("当前采购入库单已被编号%s的支出合同结算单所引用", "MaterialInBillOp_0", "ec-ecma-opplugin", new Object[0]), stringBuilder));
|
||||
}
|
||||
}
|
||||
default:
|
||||
}
|
||||
}
|
||||
|
||||
public void beginOperationTransaction(BeginOperationTransactionArgs e) {
|
||||
super.beginOperationTransaction(e);
|
||||
String operationKey = e.getOperationKey();
|
||||
DynamicObject[] dataEntities = e.getDataEntities();
|
||||
ArrayList succObjs;
|
||||
DynamicObject obj1;//二开替代
|
||||
// DynamicObject obj;//系统源码
|
||||
// String msg;//系统源码
|
||||
QFilter entryIdFilter;
|
||||
DynamicObject[] materialinBills;
|
||||
String result1;//二开替代
|
||||
// String result;//系统源码
|
||||
// String msg;//系统源码
|
||||
String msg1;//二开替代
|
||||
DynamicObject[] var34;
|
||||
int var35;
|
||||
int var37;
|
||||
DynamicObject o;
|
||||
DynamicObject orderF7;
|
||||
switch (operationKey) {
|
||||
case "save":
|
||||
for(int i = 0; i < dataEntities.length; ++i) {
|
||||
DynamicObject obj = dataEntities[i];
|
||||
this.doSaveLot(obj);
|
||||
}
|
||||
|
||||
return;
|
||||
case "audit":
|
||||
succObjs = new ArrayList();
|
||||
ArrayList<DynamicObject> orders = new ArrayList();
|
||||
|
||||
for(int i = 0; i < dataEntities.length; ++i) {
|
||||
DynamicObject obj = dataEntities[i];
|
||||
obj = obj.getDynamicObject("purchaseorder");
|
||||
DynamicObjectCollection inEntry = obj.getDynamicObjectCollection("entryentity");
|
||||
if (obj != null) {
|
||||
o = BusinessDataServiceHelper.loadSingle(obj.getPkValue(), "ecma_purchaseorderbill");
|
||||
DynamicObjectCollection orderEntry = o.getDynamicObjectCollection("orderentry");
|
||||
Map<String, BigDecimal> inEntriesMap = new HashMap();
|
||||
Iterator var43 = inEntry.iterator();
|
||||
|
||||
while(var43.hasNext()) {
|
||||
DynamicObject in = (DynamicObject)var43.next();
|
||||
if (StringUtils.isNotBlank(in.getString("orderentryid"))) {
|
||||
inEntriesMap.put(in.getString("orderentryid"), in.getBigDecimal("qty"));
|
||||
}
|
||||
}
|
||||
|
||||
Boolean allIn = true;
|
||||
Iterator var48 = orderEntry.iterator();
|
||||
|
||||
while(var48.hasNext()) {
|
||||
orderF7 = (DynamicObject)var48.next();
|
||||
BigDecimal inQty = (BigDecimal)inEntriesMap.getOrDefault(orderF7.getString("id"), BigDecimal.ZERO);
|
||||
BigDecimal surplusQty = orderF7.getBigDecimal("surplusqty").subtract(inQty);
|
||||
orderF7.set("surplusqty", surplusQty);
|
||||
if (surplusQty.compareTo(BigDecimal.ZERO) > 0) {
|
||||
allIn = false;
|
||||
}
|
||||
}
|
||||
|
||||
o.set("isallin", allIn);
|
||||
o.set("isalreadyin", "1");
|
||||
SaveServiceHelper.save(EntityMetadataCache.getDataEntityType("ecma_purchaseorderbill"), new DynamicObject[]{o});
|
||||
orders.add(o);
|
||||
}
|
||||
|
||||
msg1 = this.updatematBalance(obj, true);
|
||||
if (!"success".equals(msg1)) {
|
||||
throw new KDBizException(msg1);
|
||||
}
|
||||
|
||||
succObjs.add(obj);
|
||||
}
|
||||
|
||||
if (orders.size() > 0) {
|
||||
SaveServiceHelper.save(((DynamicObject)orders.get(0)).getDynamicObjectType(), orders.toArray(new DynamicObject[orders.size()]));
|
||||
}
|
||||
|
||||
e.setDataEntities((DynamicObject[])succObjs.toArray(new DynamicObject[succObjs.size()]));
|
||||
break;
|
||||
case "unaudit":
|
||||
succObjs = new ArrayList();
|
||||
this.rewritePoundBills(dataEntities, true);
|
||||
ArrayList<DynamicObject> orders1 = new ArrayList();
|
||||
var34 = dataEntities;
|
||||
var35 = dataEntities.length;
|
||||
|
||||
for(var37 = 0; var37 < var35; ++var37) {
|
||||
o = var34[var37];
|
||||
Object[] objects = o.getDynamicObjectCollection("entryentity").stream().map((entry) -> {
|
||||
return entry.getPkValue();
|
||||
}).toArray();
|
||||
entryIdFilter = new QFilter("entryentity.materialentryid", "in", objects);
|
||||
materialinBills = BusinessDataServiceHelper.load("ecco_mainmatcost", "id,billno,entryentity,entryentity.materialentryid", new QFilter[]{entryIdFilter});
|
||||
if (materialinBills.length > 0) {
|
||||
result1 = String.format(ResManager.loadKDString("单据名称:%s的分录已被主要材料成本核算单分录引用,无法反审核!", "MaterialInBillOp_1", "ec-ecma-opplugin", new Object[0]), o.getString("billname"));
|
||||
throw new KDBizException(result1);
|
||||
}
|
||||
|
||||
DynamicObject[] sporadicEntry = BusinessDataServiceHelper.load("ecco_sporadicmatcost", "id,billno,entryentity,entryentity.materialentryid", new QFilter[]{entryIdFilter});
|
||||
if (sporadicEntry.length > 0) {
|
||||
msg1 = String.format(ResManager.loadKDString("单据名称:%s的分录已被零星材料成本核算单分录引用,无法反审核!", "MaterialInBillOp_2", "ec-ecma-opplugin", new Object[0]), o.getString("billname"));
|
||||
throw new KDBizException(msg1);
|
||||
}
|
||||
|
||||
orderF7 = o.getDynamicObject("purchaseorder");
|
||||
DynamicObjectCollection inEntry = o.getDynamicObjectCollection("entryentity");
|
||||
if (orderF7 != null) {
|
||||
QFilter orderFilter = new QFilter("purchaseorder", "=", orderF7.getPkValue());
|
||||
QFilter statusFilter = new QFilter("billstatus", "=", BillStatusEnum.AUDIT);
|
||||
QFilter notThisFilter = new QFilter(MaterialInBillConstant.ID_ENTITY_PK, "!=", o.getPkValue());
|
||||
DynamicObjectCollection query = QueryServiceHelper.query("ecma_materialinbill", "id,purchaseorder,billstatus", new QFilter[]{orderFilter, statusFilter, notThisFilter});
|
||||
DynamicObject order = BusinessDataServiceHelper.loadSingle(orderF7.getPkValue(), "ecma_purchaseorderbill");
|
||||
DynamicObjectCollection orderEntry = order.getDynamicObjectCollection("orderentry");
|
||||
Map<String, BigDecimal> inEntriesMap = new HashMap();
|
||||
Iterator var26 = inEntry.iterator();
|
||||
|
||||
while(var26.hasNext()) {
|
||||
DynamicObject in = (DynamicObject)var26.next();
|
||||
if (StringUtils.isNotBlank(in.getString("orderentryid"))) {
|
||||
inEntriesMap.put(in.getString("orderentryid"), in.getBigDecimal("qty"));
|
||||
}
|
||||
}
|
||||
|
||||
Boolean allIn = true;
|
||||
Iterator var53 = orderEntry.iterator();
|
||||
|
||||
while(var53.hasNext()) {
|
||||
DynamicObject ordE = (DynamicObject)var53.next();
|
||||
BigDecimal inQty = (BigDecimal)inEntriesMap.getOrDefault(ordE.getString("id"), BigDecimal.ZERO);
|
||||
BigDecimal surplusQty = inQty.add(ordE.getBigDecimal("surplusqty"));
|
||||
ordE.set("surplusqty", surplusQty);
|
||||
if (surplusQty.compareTo(BigDecimal.ZERO) > 0) {
|
||||
allIn = false;
|
||||
}
|
||||
}
|
||||
|
||||
order.set("isallin", allIn);
|
||||
if (query.size() < 1) {
|
||||
order.set("isalreadyin", "0");
|
||||
}
|
||||
|
||||
SaveServiceHelper.save(EntityMetadataCache.getDataEntityType("ecma_purchaseorderbill"), new DynamicObject[]{order});
|
||||
orders1.add(order);
|
||||
}
|
||||
|
||||
String msg = this.updatematBalance(o, false);
|
||||
if (!"success".equals(msg)) {
|
||||
throw new KDBizException(msg);
|
||||
}
|
||||
|
||||
succObjs.add(o);
|
||||
}
|
||||
|
||||
SaveServiceHelper.save(EntityMetadataCache.getDataEntityType("ecma_purchaseorderbill"), orders1.toArray(new DynamicObject[orders1.size()]));
|
||||
e.setDataEntities((DynamicObject[])succObjs.toArray(new DynamicObject[succObjs.size()]));
|
||||
break;
|
||||
case "submit":
|
||||
succObjs = new ArrayList();
|
||||
this.rewritePoundBills(dataEntities, false);
|
||||
var34 = dataEntities;
|
||||
var35 = dataEntities.length;
|
||||
|
||||
for(var37 = 0; var37 < var35; ++var37) {
|
||||
o = var34[var37];
|
||||
this.doSaveLot(o);
|
||||
String billNumber = o.getString("billno");
|
||||
entryIdFilter = new QFilter("billno", "=", billNumber);
|
||||
entryIdFilter.and(new QFilter("matbilltype", "=", "materialin"));
|
||||
entryIdFilter.and(new QFilter("billstatus", "in", new String[]{"B", "C"}));
|
||||
materialinBills = BusinessDataServiceHelper.load("ecma_materialinbill", "billno,matbilltype", new QFilter[]{entryIdFilter});
|
||||
if (materialinBills != null && materialinBills.length > 0) {
|
||||
result1 = String.format(ResManager.loadKDString("单据编码%s重复,请重新输入单据编码!", "MaterialInBillOp_3", "ec-ecma-opplugin", new Object[0]), billNumber);
|
||||
throw new KDBizException(result1);
|
||||
}
|
||||
|
||||
result1 = this.updateMatLocked(o, true, true);
|
||||
if (!"success".equals(result1)) {
|
||||
msg1 = String.format(ResManager.loadKDString("提交失败!%s", "MaterialInBillOp_4", "ec-ecma-opplugin", new Object[0]), result1);
|
||||
throw new KDBizException(msg1);
|
||||
}
|
||||
|
||||
succObjs.add(o);
|
||||
}
|
||||
|
||||
e.setDataEntities((DynamicObject[])succObjs.toArray(new DynamicObject[succObjs.size()]));
|
||||
break;
|
||||
case "unsubmit":
|
||||
succObjs = new ArrayList();
|
||||
this.rewritePoundBills(dataEntities, true);
|
||||
|
||||
for(int i = 0; i < dataEntities.length; ++i) {
|
||||
obj1 = dataEntities[i];
|
||||
String result = this.updateMatLocked(obj1, false, false);
|
||||
if (!"success".equals(result)) {
|
||||
msg1 = String.format(ResManager.loadKDString("撤销失败!%s", "MaterialInBillOp_5", "ec-ecma-opplugin", new Object[0]), result);
|
||||
throw new KDBizException(msg1);
|
||||
}
|
||||
|
||||
succObjs.add(obj1);
|
||||
}
|
||||
|
||||
e.setDataEntities((DynamicObject[])succObjs.toArray(new DynamicObject[succObjs.size()]));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected void rewritePoundBills(DynamicObject[] dataEntities, boolean revoke) {
|
||||
if (!ArrayUtils.isEmpty(dataEntities)) {
|
||||
Set<Long> poundIds = new HashSet();
|
||||
Arrays.stream(dataEntities).filter((dataEntity) -> {
|
||||
return dataEntity.getBoolean("poundin");
|
||||
}).forEach((dataEntity) -> {
|
||||
DynamicObjectCollection entryEntity = dataEntity.getDynamicObjectCollection("entryentity");
|
||||
if (!CollectionUtils.isEmpty(entryEntity)) {
|
||||
Set<Long> entryPoundIds = (Set)entryEntity.stream().map((dynamicObject) -> {
|
||||
return dynamicObject.getLong("poundid");
|
||||
}).collect(Collectors.toSet());
|
||||
poundIds.addAll(entryPoundIds);
|
||||
}
|
||||
});
|
||||
if (!CollectionUtils.isEmpty(poundIds)) {
|
||||
QFilter poundPkIdFilter = new QFilter(PoundConstant.ID_ENTITY_PK, "in", poundIds);
|
||||
DynamicObject[] poundEntities = BusinessDataServiceHelper.load("ecma_poundbill", "depotstatus,opt_type", new QFilter[]{poundPkIdFilter});
|
||||
if (!ArrayUtils.isEmpty(poundEntities)) {
|
||||
Arrays.stream(poundEntities).forEach((poundEntity) -> {
|
||||
poundEntity.set("depotstatus", !revoke);
|
||||
poundEntity.set("opt_type", "0");
|
||||
});
|
||||
SaveServiceHelper.save(poundEntities);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void doSaveLot(DynamicObject bill) {
|
||||
DynamicObjectCollection inEntry = bill.getDynamicObjectCollection("entryentity");
|
||||
int count = inEntry.size();
|
||||
DynamicObject obj = null;
|
||||
DynamicObject lotObj = null;
|
||||
String lotNum = "";
|
||||
String modelnum = "";
|
||||
ArrayList<DynamicObject> addLotList = new ArrayList();
|
||||
DynamicObject addObj = null;
|
||||
DynamicObject material = null;
|
||||
ORM orm = ORM.create();
|
||||
Map<Integer, DynamicObject> rowLotMap = new HashMap();
|
||||
|
||||
for(int i = 0; i < count; ++i) {
|
||||
obj = (DynamicObject)inEntry.get(i);
|
||||
lotNum = obj.getString("lot");
|
||||
lotObj = obj.getDynamicObject("lotid");
|
||||
material = obj.getDynamicObject("material");
|
||||
modelnum = obj.getString("modelnum");
|
||||
if (StringUtils.isNotEmpty(lotNum.trim()) && lotObj == null && material != null) {
|
||||
QFilter filter = new QFilter("number", "=", lotNum);
|
||||
filter.and(new QFilter("modelnum", "=", modelnum));
|
||||
filter.and(new QFilter("material.id", "=", material.getPkValue()));
|
||||
filter.and(new QFilter("org", "=", bill.getDynamicObject("org").getPkValue()));
|
||||
filter.and(new QFilter("warehouse", "=", bill.getDynamicObject("warehouse").getPkValue()));
|
||||
if (bill.get("project") != null) {
|
||||
filter.and(new QFilter("project", "=", bill.getDynamicObject("project").getPkValue()));
|
||||
}
|
||||
|
||||
if (bill.get("unitprojectpro") != null) {
|
||||
filter.and(new QFilter("unitprojectpro", "=", bill.getDynamicObject("unitprojectpro").getPkValue()));
|
||||
}
|
||||
|
||||
filter.and(new QFilter("bizdate", "=", bill.getDate("bizdate")));
|
||||
boolean exists = QueryServiceHelper.exists("ecma_material_lot", new QFilter[]{filter});
|
||||
if (exists) {
|
||||
throw new KDBizException(String.format(ResManager.loadKDString("物料-%1$s,编号:%2$s已经存在,请重新填写批号。", "MaterialInBillOp_6", "ec-ecma-opplugin", new Object[0]), material.get("name"), lotNum));
|
||||
}
|
||||
|
||||
addObj = new DynamicObject(EntityMetadataCache.getDataEntityType("ecma_material_lot"));
|
||||
addObj.set("number", lotNum);
|
||||
addObj.set("material", material);
|
||||
addObj.set("modelnum", modelnum);
|
||||
addObj.set("org", bill.get("org"));
|
||||
addObj.set("warehouse", bill.get("warehouse"));
|
||||
addObj.set("project", bill.get("project"));
|
||||
addObj.set("unitprojectpro", bill.get("unitprojectpro"));
|
||||
addObj.set("bizdate", bill.get("bizdate"));
|
||||
addLotList.add(addObj);
|
||||
rowLotMap.put(i, addObj);
|
||||
}
|
||||
|
||||
if (StringUtils.isNotEmpty(lotNum.trim()) && lotObj != null && material != null) {
|
||||
Boolean needUpdate = false;
|
||||
addObj = BusinessDataServiceHelper.loadSingle(lotObj.getPkValue(), "ecma_material_lot");
|
||||
if (!StringUtils.equals(addObj.getString("number"), lotNum)) {
|
||||
needUpdate = true;
|
||||
}
|
||||
|
||||
if (!material.getPkValue().equals(addObj.getDynamicObject("material").getPkValue())) {
|
||||
needUpdate = true;
|
||||
}
|
||||
|
||||
if (!StringUtils.equals(addObj.getString("modelnum"), modelnum)) {
|
||||
needUpdate = true;
|
||||
}
|
||||
|
||||
Long orgId = addObj.getDynamicObject("org") == null ? 0L : addObj.getDynamicObject("org").getLong("id");
|
||||
Long billOrgId = bill.getDynamicObject("org").getLong("id");
|
||||
if (!orgId.equals(billOrgId)) {
|
||||
needUpdate = true;
|
||||
}
|
||||
|
||||
Long warehouseId = addObj.getDynamicObject("warehouse") == null ? 0L : addObj.getDynamicObject("warehouse").getLong("id");
|
||||
Long billWarehouseId = bill.getDynamicObject("warehouse").getLong("id");
|
||||
if (!warehouseId.equals(billWarehouseId)) {
|
||||
needUpdate = true;
|
||||
}
|
||||
|
||||
Long unitprojectproId = addObj.getDynamicObject("unitprojectpro") == null ? 0L : addObj.getDynamicObject("unitprojectpro").getLong("id");
|
||||
Long billUnitprojectproId = bill.getDynamicObject("unitprojectpro") == null ? 0L : bill.getDynamicObject("unitprojectpro").getLong("id");
|
||||
if (!unitprojectproId.equals(billUnitprojectproId)) {
|
||||
needUpdate = true;
|
||||
}
|
||||
|
||||
Long projectId = addObj.getDynamicObject("project") == null ? 0L : addObj.getDynamicObject("project").getLong("id");
|
||||
Long billProjectId = bill.getDynamicObject("project") == null ? 0L : bill.getDynamicObject("project").getLong("id");
|
||||
if (!projectId.equals(billProjectId)) {
|
||||
needUpdate = true;
|
||||
}
|
||||
|
||||
Date date = addObj.getDate("bizdate");
|
||||
Date date1 = bill.getDate("bizdate");
|
||||
if (date == null || date.compareTo(date1) != 0) {
|
||||
needUpdate = true;
|
||||
}
|
||||
|
||||
if (needUpdate) {
|
||||
QFilter filter = new QFilter("number", "=", lotNum);
|
||||
filter.and(new QFilter("modelnum", "=", modelnum));
|
||||
filter.and(new QFilter("material.id", "=", material.getPkValue()));
|
||||
filter.and(new QFilter("org", "=", bill.getDynamicObject("org").getPkValue()));
|
||||
filter.and(new QFilter("warehouse", "=", bill.getDynamicObject("warehouse").getPkValue()));
|
||||
if (bill.get("project") != null) {
|
||||
filter.and(new QFilter("project", "=", bill.getDynamicObject("project").getPkValue()));
|
||||
}
|
||||
|
||||
if (bill.get("unitprojectpro") != null) {
|
||||
filter.and(new QFilter("unitprojectpro", "=", bill.getDynamicObject("unitprojectpro").getPkValue()));
|
||||
}
|
||||
|
||||
filter.and(new QFilter("bizdate", "=", bill.getDate("bizdate")));
|
||||
boolean exists = QueryServiceHelper.exists("ecma_material_lot", new QFilter[]{filter});
|
||||
if (exists) {
|
||||
throw new KDBizException(String.format(ResManager.loadKDString("物料-%1$s,编号:%2$s已经存在,请重新填写批号。", "MaterialInBillOp_6", "ec-ecma-opplugin", new Object[0]), material.get("name"), lotNum));
|
||||
}
|
||||
|
||||
addObj.set("number", lotNum);
|
||||
addObj.set("material", material);
|
||||
addObj.set("modelnum", modelnum);
|
||||
addObj.set("org", bill.get("org"));
|
||||
addObj.set("warehouse", bill.get("warehouse"));
|
||||
addObj.set("project", bill.get("project"));
|
||||
addObj.set("unitprojectpro", bill.get("unitprojectpro"));
|
||||
addObj.set("bizdate", bill.get("bizdate"));
|
||||
addLotList.add(addObj);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Iterator var27 = rowLotMap.entrySet().iterator();
|
||||
|
||||
while(var27.hasNext()) {
|
||||
Map.Entry<Integer, DynamicObject> entry = (Map.Entry)var27.next();
|
||||
Integer row = (Integer)entry.getKey();
|
||||
DynamicObject lot = (DynamicObject)entry.getValue();
|
||||
long genLotId = orm.genLongId("ecma_material_lot");
|
||||
lot.set("id", genLotId);
|
||||
((DynamicObject)inEntry.get(row)).set("lotid", lot);
|
||||
}
|
||||
|
||||
SaveServiceHelper.save((DynamicObject[])addLotList.toArray(new DynamicObject[addLotList.size()]));
|
||||
}
|
||||
|
||||
private String updateMatLocked(DynamicObject obj, boolean isLock, boolean isSubmit) {
|
||||
String orgId = obj.getDynamicObject("org").getString("id");
|
||||
DynamicObject warehouse = obj.getDynamicObject("warehouse");
|
||||
DynamicObject projectobj = warehouse.getDynamicObject("project");
|
||||
String projectId = projectobj == null ? "0" : projectobj.getString("id");
|
||||
String warehouseId = obj.getDynamicObject("warehouse").getString("id");
|
||||
DynamicObjectCollection entryCol = obj.getDynamicObjectCollection("entryentity");
|
||||
DynamicObject transType = obj.getDynamicObject("transtype");
|
||||
String type = transType.getString("type");
|
||||
String result = "success";
|
||||
if ("REDUCE".equals(type)) {
|
||||
if (isSubmit) {
|
||||
String msg1 = MaterialInventoryUtils.checkMatAsOut(orgId, projectId, warehouseId, (DynamicObject[])entryCol.toArray(new DynamicObject[entryCol.size()]));
|
||||
if (!"success".equals(msg1)) {
|
||||
return msg1;
|
||||
}
|
||||
}
|
||||
|
||||
result = MaterialInventoryUtils.matBalanceLocked(orgId, projectId, warehouseId, (DynamicObject[])entryCol.toArray(new DynamicObject[entryCol.size()]), isLock);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private String updatematBalance(DynamicObject obj, boolean isAudit) {
|
||||
String result = "success";
|
||||
String orgId = obj.getDynamicObject("org").getString("id");
|
||||
DynamicObject warehouse = obj.getDynamicObject("warehouse");
|
||||
String warehouseId = warehouse.getString("id");
|
||||
DynamicObject projectobj = warehouse.getDynamicObject("project");
|
||||
String projectId = projectobj == null ? "0" : projectobj.getString("id");
|
||||
DynamicObjectCollection entryCol = obj.getDynamicObjectCollection("entryentity");
|
||||
DynamicObject transType = obj.getDynamicObject("transtype");
|
||||
boolean ismulticurrency = obj.getBoolean("ismulticurrency");
|
||||
BigDecimal exchangerate = BigDecimal.ONE;
|
||||
if (ismulticurrency) {
|
||||
DynamicObject stdCurrency = obj.getDynamicObject("stdcurrency");
|
||||
DynamicObject orgCurrency = CurrencyHelper.getCurrency(Long.valueOf(orgId));
|
||||
if (orgCurrency.getPkValue().equals(stdCurrency.getPkValue())) {
|
||||
exchangerate = obj.getBigDecimal("exchangerate");
|
||||
} else {
|
||||
DynamicObject currency = obj.getDynamicObject("currency");
|
||||
DynamicObject exratetable = obj.getDynamicObject("exratetable");
|
||||
Date exchangedate = obj.getDate("exchangedate");
|
||||
if (currency != null && exratetable != null && exchangedate != null) {
|
||||
BigDecimal rate = CurrencyHelper.getExChangeRate(currency.getLong("id"), orgCurrency.getLong("id"), exratetable.getLong("id"), exchangedate);
|
||||
if (rate != null) {
|
||||
exchangerate = rate;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
String type = transType.getString("type");
|
||||
if ("INCREASE".equals(type)) {
|
||||
if (!isAudit) {
|
||||
String msg1 = MaterialInventoryUtils.checkMatAsOut(orgId, projectId, warehouseId, (DynamicObject[])entryCol.toArray(new DynamicObject[entryCol.size()]));
|
||||
if (!"success".equals(msg1)) {
|
||||
result = String.format(ResManager.loadKDString("反审核失败。%s", "MaterialInBillOp_7", "ec-ecma-opplugin", new Object[0]), msg1);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
MaterialInventoryUtils.matBalanceUpdate(orgId, projectId, warehouseId, (DynamicObject[])entryCol.toArray(new DynamicObject[entryCol.size()]), isAudit, exchangerate);
|
||||
} else if ("REDUCE".equals(type)) {
|
||||
if (isAudit) {
|
||||
String msg1 = MaterialInventoryUtils.checkInventoryQty(orgId, projectId, warehouseId, (DynamicObject[])entryCol.toArray(new DynamicObject[entryCol.size()]));
|
||||
if (!"success".equals(msg1)) {
|
||||
result = String.format(ResManager.loadKDString("审核失败。%s", "MaterialInBillOp_8", "ec-ecma-opplugin", new Object[0]), msg1);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
boolean isAdd = !isAudit;
|
||||
MaterialInventoryUtils.matBalanceLockAndUpdate(orgId, projectId, warehouseId, (DynamicObject[])entryCol.toArray(new DynamicObject[entryCol.size()]), isAdd, exchangerate, false);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,410 @@
|
|||
//
|
||||
// Source code recreated from a .class file by IntelliJ IDEA
|
||||
// (powered by FernFlower decompiler)
|
||||
//
|
||||
|
||||
package zcgj.zcdev.zcdev.pr.plugin.operate;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
import kd.bos.dataentity.entity.DynamicObject;
|
||||
import kd.bos.dataentity.metadata.dynamicobject.DynamicObjectType;
|
||||
import kd.bos.dataentity.resource.ResManager;
|
||||
import kd.bos.dataentity.utils.StringUtils;
|
||||
import kd.bos.dlock.DLock;
|
||||
import kd.bos.dlock.DLockInfo;
|
||||
import kd.bos.entity.EntityMetadataCache;
|
||||
import kd.bos.exception.KDBizException;
|
||||
import kd.bos.logging.Log;
|
||||
import kd.bos.logging.LogFactory;
|
||||
import kd.bos.orm.query.QFilter;
|
||||
import kd.bos.servicehelper.BusinessDataServiceHelper;
|
||||
import kd.bos.servicehelper.operation.SaveServiceHelper;
|
||||
import kd.ec.basedata.common.utils.CurrencyHelper;
|
||||
import kd.ec.basedata.common.utils.EcNumberHelper;
|
||||
import kd.ec.material.common.utils.MaterialInventoryUtils;
|
||||
|
||||
public class MaterialInventoryUtilsExt2 {
|
||||
private static final Log log = LogFactory.getLog(MaterialInventoryUtils.class);
|
||||
public static final DynamicObjectType matInvDT = EntityMetadataCache.getDataEntityType("ecma_matinventory");
|
||||
public static final String MatInv_Lot = "lot";
|
||||
public static final String MatInv_Price = "price";
|
||||
public static final String MatInv_Qty = "qty";
|
||||
public static final String MatInv_Amount = "amount";
|
||||
public static final String MatInv_Lockedqty = "lockedqty";
|
||||
public static final String MatInv_Tempqty = "tempqty";
|
||||
public static final String MatInv_Modelnum = "modelnum";
|
||||
public static final String MatInv_Project = "project";
|
||||
public static final String MatInv_Org = "org";
|
||||
public static final String MatInv_Material = "material";
|
||||
public static final String MatInv_Warehouse = "warehouse";
|
||||
public static final String MatInv_Measureunit = "measureunit";
|
||||
public static final String MatInv_Currency = "currency";
|
||||
public static final String selProperty = "id,measureunit,lot,currency,price,qty,amount,lockedqty,tempqty,modelnum,saleprice,measureuint,project,org,material,warehouse";
|
||||
|
||||
private MaterialInventoryUtilsExt2() {
|
||||
}
|
||||
|
||||
public static void matBalanceUpdate(String orgId, String projectId, String warehouseId, DynamicObject[] entrys, boolean isAdd, BigDecimal exchangerate) {
|
||||
matBalanceUpdateNoDLock(orgId, projectId, warehouseId, entrys, isAdd, exchangerate);
|
||||
}
|
||||
|
||||
public static void matBalanceLockAndUpdate(String orgId, String projectId, String warehouseId, DynamicObject[] entrys, boolean isAdd, BigDecimal exchangerate, boolean isLocked) {
|
||||
String lockKey = String.format("ec/ecma/inventory_lock_%1$s_%2$s", projectId, warehouseId);
|
||||
String lockDesc = String.format(ResManager.loadKDString("即时库存分布式锁_%1$s_%2$s", "MaterialInventoryUtils_14", "ec-ecma-common", new Object[0]), projectId, warehouseId);
|
||||
DLock lock = DLock.create(lockKey, lockDesc).fastMode();
|
||||
boolean tryLock = lock.tryLock(50000L);
|
||||
if (!tryLock) {
|
||||
throw new KDBizException(ResManager.loadKDString("获取锁失败,请联系管理员。", "MaterialInventoryUtils_15", "ec-ecma-common", new Object[0]));
|
||||
} else {
|
||||
try {
|
||||
DLockInfo lockInfo = DLock.getLockInfo(lockKey);
|
||||
if (lockInfo != null) {
|
||||
log.info(lockInfo.toString());
|
||||
}
|
||||
|
||||
matBalanceLockedNoDLock(orgId, projectId, warehouseId, entrys, isLocked);
|
||||
matBalanceUpdateNoDLock(orgId, projectId, warehouseId, entrys, isAdd, exchangerate);
|
||||
} finally {
|
||||
try {
|
||||
lock.unlock();
|
||||
} catch (Throwable var17) {
|
||||
log.info(String.format("ecma_lock %1$s unlock error :%2$s", lockKey, var17));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private static void matBalanceUpdateNoDLock(String orgId, String projectId, String warehouseId, DynamicObject[] entrys, boolean isAdd, BigDecimal exchangerate) {
|
||||
BigDecimal coef = BigDecimal.ONE;
|
||||
if (!isAdd) {
|
||||
coef = BigDecimal.valueOf(-1L);
|
||||
}
|
||||
|
||||
List<String> mergedFields = new ArrayList();
|
||||
mergedFields.add("qty");
|
||||
mergedFields.add("amount");
|
||||
if (entrys.length > 0 && entrys[0].getDataEntityType().getProperties().containsKey("ftransamount")) {
|
||||
mergedFields.add("ftransamount");
|
||||
}
|
||||
|
||||
DynamicObject[] mergedEntrys = mergeSameMaterial(entrys, mergedFields);
|
||||
Set<Long> materialIdSet = new HashSet();
|
||||
DynamicObject[] var10 = mergedEntrys;
|
||||
int var11 = mergedEntrys.length;
|
||||
|
||||
for(int var12 = 0; var12 < var11; ++var12) {
|
||||
DynamicObject mergedEntry = var10[var12];
|
||||
Long materialId = mergedEntry.getLong("material_id");
|
||||
if (materialId != null && materialId != 0L) {
|
||||
materialIdSet.add(materialId);
|
||||
}
|
||||
}
|
||||
|
||||
QFilter filter = new QFilter("org", "=", StringUtils.isBlank(orgId) ? 0L : Long.parseLong(orgId));
|
||||
filter.and(new QFilter("project", "=", StringUtils.isBlank(projectId) ? 0L : Long.parseLong(projectId)));
|
||||
filter.and(new QFilter("warehouse", "=", StringUtils.isBlank(warehouseId) ? 0L : Long.parseLong(warehouseId)));
|
||||
QFilter materialIdFilter = new QFilter("material", "in", materialIdSet);
|
||||
DynamicObject[] ecmaMatinventories = BusinessDataServiceHelper.load("ecma_matinventory", "id,measureunit,lot,currency,price,qty,amount,lockedqty,tempqty,modelnum,saleprice,measureuint,project,org,material,warehouse", new QFilter[]{filter, materialIdFilter});
|
||||
Map<String, DynamicObject> matInventoryMap = new HashMap();
|
||||
DynamicObject[] var33 = ecmaMatinventories;
|
||||
int i = ecmaMatinventories.length;
|
||||
|
||||
String matId;
|
||||
String modelnum;
|
||||
String lot;
|
||||
String unitId;
|
||||
String key;
|
||||
for(int var16 = 0; var16 < i; ++var16) {
|
||||
DynamicObject ecmaMatinventory = var33[var16];
|
||||
matId = ecmaMatinventory.getDynamicObject("material").getString("id");
|
||||
modelnum = "".equals(ecmaMatinventory.getString("modelnum")) ? " " : ecmaMatinventory.getString("modelnum");
|
||||
lot = "".equals(ecmaMatinventory.getString("lot")) ? " " : ecmaMatinventory.getString("lot");
|
||||
unitId = ecmaMatinventory.getDynamicObject("measureunit") == null ? "" : ecmaMatinventory.getDynamicObject("measureunit").getString("id");
|
||||
key = String.format("%1$s_%2$s_%3$s_%4$s", matId, modelnum, lot, unitId);
|
||||
matInventoryMap.put(key, ecmaMatinventory);
|
||||
}
|
||||
|
||||
List<DynamicObject> matInvList = new ArrayList();
|
||||
|
||||
for(i = 0; i < mergedEntrys.length; ++i) {
|
||||
DynamicObject entryInfo = mergedEntrys[i];
|
||||
boolean isFirst = false;
|
||||
matId = entryInfo.getDynamicObject("material").getString("id");
|
||||
modelnum = "".equals(entryInfo.getString("modelnum")) ? " " : entryInfo.getString("modelnum");
|
||||
lot = "".equals(entryInfo.getString("lot")) ? " " : entryInfo.getString("lot");
|
||||
unitId = entryInfo.getDynamicObject("measureunit") == null ? "" : entryInfo.getDynamicObject("measureunit").getString("id");
|
||||
key = String.format("%1$s_%2$s_%3$s_%4$s", matId, modelnum, lot, unitId);
|
||||
DynamicObject matInvInfo = (DynamicObject)matInventoryMap.get(key);
|
||||
BigDecimal qty;
|
||||
if (matInvInfo == null || BigDecimal.ZERO.compareTo(matInvInfo.getBigDecimal("tempqty")) == 0) {
|
||||
if (entryInfo.getDataEntityType().getProperties().containsKey("ftransamount")) {
|
||||
qty = entryInfo.getBigDecimal("ftransamount");
|
||||
if (BigDecimal.ZERO.compareTo(qty) == 0) {
|
||||
isFirst = true;
|
||||
}
|
||||
} else {
|
||||
isFirst = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (matInvInfo == null) {
|
||||
matInvInfo = setMatInvInfo(orgId, projectId, warehouseId, entryInfo, coef, exchangerate);
|
||||
} else {
|
||||
qty = entryInfo.getBigDecimal("qty").multiply(coef);
|
||||
BigDecimal amount = entryInfo.getBigDecimal("amount").multiply(exchangerate);
|
||||
amount = amount.multiply(coef);
|
||||
BigDecimal totalQty = matInvInfo.getBigDecimal("qty");
|
||||
BigDecimal totalTmpQty = matInvInfo.getBigDecimal("tempqty");
|
||||
if (BigDecimal.ZERO.compareTo(totalTmpQty) == 0) {
|
||||
matInvInfo.set("price", entryInfo.getBigDecimal("price").multiply(exchangerate));
|
||||
}
|
||||
|
||||
totalQty = EcNumberHelper.add(totalQty, qty);
|
||||
BigDecimal totalAmount = matInvInfo.getBigDecimal("amount");
|
||||
totalAmount = EcNumberHelper.add(totalAmount, amount);
|
||||
totalTmpQty = EcNumberHelper.add(totalTmpQty, qty);
|
||||
matInvInfo.set("qty", totalQty);
|
||||
matInvInfo.set("tempqty", totalTmpQty);
|
||||
matInvInfo.set("amount", totalAmount);
|
||||
if (!isFirst && totalQty.compareTo(BigDecimal.ZERO) != 0) {
|
||||
matInvInfo.set("price", totalAmount.divide(totalTmpQty, 10, 4));
|
||||
}
|
||||
}
|
||||
|
||||
matInvList.add(matInvInfo);
|
||||
}
|
||||
|
||||
if (!matInvList.isEmpty()) {
|
||||
SaveServiceHelper.save((DynamicObject[])matInvList.toArray(new DynamicObject[0]));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static String matBalanceLockedNoDLock(String orgId, String projectId, String warehouseId, DynamicObject[] entrys, boolean isLocked) {
|
||||
BigDecimal coef = BigDecimal.ONE;
|
||||
if (!isLocked) {
|
||||
coef = BigDecimal.valueOf(-1L);
|
||||
}
|
||||
|
||||
List<DynamicObject> matInvList = new ArrayList();
|
||||
|
||||
for(int i = 0; i < entrys.length; ++i) {
|
||||
DynamicObject entryInfo = entrys[i];
|
||||
DynamicObject material = entryInfo.getDynamicObject("material");
|
||||
String matId = material.getString("id");
|
||||
String modelnum = "".equals(entryInfo.getString("modelnum")) ? " " : entryInfo.getString("modelnum");
|
||||
String lot = "".equals(entryInfo.getString("lot")) ? " " : entryInfo.getString("lot");
|
||||
String unitId = entryInfo.getDynamicObject("measureunit") == null ? "" : entryInfo.getDynamicObject("measureunit").getString("id");
|
||||
String unitName = entryInfo.getDynamicObject("measureunit") == null ? "" : entryInfo.getDynamicObject("measureunit").getString("name");
|
||||
DynamicObject matInvInfo = getMatInvInfo(orgId, projectId, warehouseId, matId, modelnum, lot, unitId);
|
||||
if (matInvInfo == null) {
|
||||
String errMsg = String.format(ResManager.loadKDString("编码为%1$s,名称为%2$s,规格型号为%3$s,计量单位为%4$s,批次为%5$s的物料无法在即时库存中找到", "MaterialInventoryUtils_11", "ec-ecma-common", new Object[0]), material.getString("number"), material.getString("name"), modelnum, unitName, lot);
|
||||
return errMsg;
|
||||
}
|
||||
|
||||
BigDecimal qty = entryInfo.getBigDecimal("qty").multiply(coef);
|
||||
BigDecimal totalLockedQty = matInvInfo.getBigDecimal("lockedqty");
|
||||
BigDecimal totalQty = matInvInfo.getBigDecimal("qty");
|
||||
totalLockedQty = EcNumberHelper.add(totalLockedQty, qty);
|
||||
totalQty = EcNumberHelper.subtract(totalQty, qty);
|
||||
matInvInfo.set("lockedqty", totalLockedQty);
|
||||
matInvInfo.set("qty", totalQty);
|
||||
matInvList.add(matInvInfo);
|
||||
}
|
||||
|
||||
if (!matInvList.isEmpty()) {
|
||||
SaveServiceHelper.save(((DynamicObject)matInvList.get(0)).getDataEntityType(), matInvList.toArray(new DynamicObject[0]));
|
||||
}
|
||||
|
||||
return "success";
|
||||
}
|
||||
|
||||
public static String matBalanceLocked(String orgId, String projectId, String warehouseId, DynamicObject[] entrys, boolean isLocked) {
|
||||
return matBalanceLockedNoDLock(orgId, projectId, warehouseId, entrys, isLocked);
|
||||
}
|
||||
|
||||
public static DynamicObject[] mergeSameMaterial(DynamicObject[] entrys, List<String> mergeFields) {
|
||||
if (entrys != null && entrys.length > 0) {
|
||||
List<String> dimensionList = new ArrayList();
|
||||
dimensionList.add("material");
|
||||
dimensionList.add("modelnum");
|
||||
dimensionList.add("lot");
|
||||
dimensionList.add("measureunit");
|
||||
dimensionList.add("price");
|
||||
List<DynamicObject> copiedList = new ArrayList();
|
||||
|
||||
for(int i = 0; i < entrys.length; ++i) {
|
||||
DynamicObject entryInfo = entrys[i];
|
||||
DynamicObject copiedObj = new DynamicObject(entrys[0].getDynamicObjectType());
|
||||
if (copiedList.isEmpty()) {
|
||||
dimensionList.forEach((dimension) -> {
|
||||
copiedObj.set(dimension, entryInfo.get(dimension));
|
||||
});
|
||||
mergeFields.forEach((field) -> {
|
||||
copiedObj.set(field, entryInfo.get(field));
|
||||
});
|
||||
copiedList.add(copiedObj);
|
||||
} else {
|
||||
String matId = entryInfo.getDynamicObject("material").getString("id");
|
||||
String modelnum = "".equals(entryInfo.getString("modelnum")) ? " " : entryInfo.getString("modelnum");
|
||||
String lot = entryInfo.getString("lot");
|
||||
String unitId = entryInfo.getDynamicObject("measureunit") == null ? "" : entryInfo.getDynamicObject("measureunit").getString("id");
|
||||
List<DynamicObject> sameList = (List)copiedList.stream().filter((obj) -> {
|
||||
return matId.equals(obj.getDynamicObject("material").getString("id")) && modelnum.equals(obj.getString("modelnum") != null && !"".equals(obj.getString("modelnum")) ? obj.getString("modelnum") : " ") && unitId.equals(obj.getDynamicObject("measureunit") == null ? "" : obj.getDynamicObject("measureunit").getString("id")) && lot.equals(obj.getString("lot"));
|
||||
}).collect(Collectors.toList());
|
||||
if (sameList.isEmpty()) {
|
||||
dimensionList.forEach((dimension) -> {
|
||||
copiedObj.set(dimension, entryInfo.get(dimension));
|
||||
});
|
||||
mergeFields.forEach((field) -> {
|
||||
copiedObj.set(field, entryInfo.get(field));
|
||||
});
|
||||
copiedList.add(copiedObj);
|
||||
} else {
|
||||
DynamicObject mergedMatInfo = (DynamicObject)sameList.get(0);
|
||||
mergeFields.forEach((field) -> {
|
||||
mergedMatInfo.set(field, EcNumberHelper.add(mergedMatInfo.getBigDecimal(field), entryInfo.getBigDecimal(field)));
|
||||
});
|
||||
BigDecimal qty = mergedMatInfo.getBigDecimal("qty");
|
||||
BigDecimal price = qty != null && qty.compareTo(BigDecimal.ZERO) != 0 ? mergedMatInfo.getBigDecimal("amount").divide(qty, 10, 4) : BigDecimal.ZERO;
|
||||
mergedMatInfo.set("price", price);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return (DynamicObject[])copiedList.toArray(new DynamicObject[0]);
|
||||
} else {
|
||||
return new DynamicObject[0];
|
||||
}
|
||||
}
|
||||
|
||||
public static String checkMatAsOut(String orgId, String projectId, String warehouseId, DynamicObject[] entrys) {
|
||||
List<String> mergedFields = new ArrayList();
|
||||
mergedFields.add("qty");
|
||||
DynamicObject[] mergedEntrys = mergeSameMaterial(entrys, mergedFields);
|
||||
|
||||
for(int i = 0; i < mergedEntrys.length; ++i) {
|
||||
DynamicObject entryInfo = mergedEntrys[i];
|
||||
DynamicObject material = entryInfo.getDynamicObject("material");
|
||||
String matId = material.getString("id");
|
||||
String modelnum = "".equals(entryInfo.getString("modelnum")) ? " " : entryInfo.getString("modelnum");
|
||||
String lot = "".equals(entryInfo.getString("lot")) ? " " : entryInfo.getString("lot");
|
||||
String unitId = entryInfo.getDynamicObject("measureunit") == null ? "" : entryInfo.getDynamicObject("measureunit").getString("id");
|
||||
BigDecimal outQty = entryInfo.getBigDecimal("qty");
|
||||
DynamicObject matInvInfo = getMatInvInfo(orgId, projectId, warehouseId, matId, modelnum, lot, unitId);
|
||||
String unitName = entryInfo.getDynamicObject("measureunit") == null ? "" : entryInfo.getDynamicObject("measureunit").getString("name");
|
||||
if (matInvInfo == null) {
|
||||
String errMsg = String.format(ResManager.loadKDString("编码为%1$s,名称为%2$s,规格型号为%3$s,计量单位为%4$s,批次为%5$s的物料无法在即时库存中找到", "MaterialInventoryUtils_11", "ec-ecma-common", new Object[0]), material.getString("number"), material.getString("name"), " ".equals(modelnum) ? ResManager.loadKDString("空", "MaterialInventoryUtils_2", "ec-ecma-common", new Object[0]) : modelnum, "".equals(unitName) ? ResManager.loadKDString("空", "MaterialInventoryUtils_2", "ec-ecma-common", new Object[0]) : unitName, " ".equals(lot) ? ResManager.loadKDString("空", "MaterialInventoryUtils_2", "ec-ecma-common", new Object[0]) : lot);
|
||||
return errMsg;
|
||||
}
|
||||
|
||||
BigDecimal invQty = matInvInfo.getBigDecimal("qty");
|
||||
if (outQty.compareTo(invQty) > 0) {
|
||||
return String.format(ResManager.loadKDString("编码为%1$s,名称为%2$s,规格型号为%3$s,计量单位为%4$s,批次为%5$s的物料库存不足。", "MaterialInventoryUtils_12", "ec-ecma-common", new Object[0]), material.getString("number"), material.getString("name"), " ".equals(modelnum) ? ResManager.loadKDString("空", "MaterialInventoryUtils_2", "ec-ecma-common", new Object[0]) : modelnum, "".equals(unitName) ? ResManager.loadKDString("空", "MaterialInventoryUtils_2", "ec-ecma-common", new Object[0]) : unitName, " ".equals(lot) ? ResManager.loadKDString("空", "MaterialInventoryUtils_2", "ec-ecma-common", new Object[0]) : lot);
|
||||
}
|
||||
}
|
||||
|
||||
return "success";
|
||||
}
|
||||
|
||||
public static String checkInventoryQty(String orgId, String projectId, String warehouseId, DynamicObject[] entrys) {
|
||||
List<String> mergedFields = new ArrayList();
|
||||
mergedFields.add("qty");
|
||||
DynamicObject[] mergedEntrys = mergeSameMaterial(entrys, mergedFields);
|
||||
|
||||
for(int i = 0; i < mergedEntrys.length; ++i) {
|
||||
DynamicObject entryInfo = mergedEntrys[i];
|
||||
DynamicObject material = entryInfo.getDynamicObject("material");
|
||||
String matId = material.getString("id");
|
||||
String modelnum = "".equals(entryInfo.getString("modelnum")) ? " " : entryInfo.getString("modelnum");
|
||||
String lot = "".equals(entryInfo.getString("lot")) ? " " : entryInfo.getString("lot");
|
||||
String unitId = entryInfo.getDynamicObject("measureunit") == null ? "" : entryInfo.getDynamicObject("measureunit").getString("id");
|
||||
BigDecimal outQty = entryInfo.getBigDecimal("qty");
|
||||
DynamicObject matInvInfo = getMatInvInfo(orgId, projectId, warehouseId, matId, modelnum, lot, unitId);
|
||||
String unitName = entryInfo.getDynamicObject("measureunit") == null ? "" : entryInfo.getDynamicObject("measureunit").getString("name");
|
||||
if (matInvInfo == null) {
|
||||
String errMsg = String.format(ResManager.loadKDString("编码为%1$s,名称为%2$s,规格型号为%3$s,计量单位为%4$s,批次为%5$s的物料无法在即时库存中找到", "MaterialInventoryUtils_11", "ec-ecma-common", new Object[0]), material.getString("number"), material.getString("name"), " ".equals(modelnum) ? ResManager.loadKDString("空", "MaterialInventoryUtils_2", "ec-ecma-common", new Object[0]) : modelnum, "".equals(unitName) ? ResManager.loadKDString("空", "MaterialInventoryUtils_2", "ec-ecma-common", new Object[0]) : unitName, " ".equals(lot) ? ResManager.loadKDString("空", "MaterialInventoryUtils_2", "ec-ecma-common", new Object[0]) : lot);
|
||||
return errMsg;
|
||||
}
|
||||
|
||||
BigDecimal invQty = matInvInfo.getBigDecimal("qty");
|
||||
if (invQty.compareTo(BigDecimal.ZERO) < 0 && outQty.compareTo(BigDecimal.ZERO) > 0) {
|
||||
String errMsg = String.format(ResManager.loadKDString("编码为%1$s,名称为%2$s,规格型号为%3$s,计量单位为%4$s,批次为%5$s的物料库存不足。", "MaterialInventoryUtils_12", "ec-ecma-common", new Object[0]), material.getString("number"), material.getString("name"), " ".equals(modelnum) ? ResManager.loadKDString("空", "MaterialInventoryUtils_2", "ec-ecma-common", new Object[0]) : modelnum, "".equals(unitName) ? ResManager.loadKDString("空", "MaterialInventoryUtils_2", "ec-ecma-common", new Object[0]) : unitName, " ".equals(lot) ? ResManager.loadKDString("空", "MaterialInventoryUtils_2", "ec-ecma-common", new Object[0]) : lot);
|
||||
return errMsg;
|
||||
}
|
||||
}
|
||||
|
||||
return "success";
|
||||
}
|
||||
|
||||
private static DynamicObject setMatInvInfo(String orgId, String projectId, String warehouseId, DynamicObject entryInfo, BigDecimal coef, BigDecimal exchangerate) {
|
||||
DynamicObject matInf = BusinessDataServiceHelper.loadSingle("ecma_matinventory", "id,measureunit,lot,currency,price,qty,amount,lockedqty,tempqty,modelnum,saleprice,measureuint,project,org,material,warehouse", new QFilter[]{new QFilter("id", "!=", 0)});
|
||||
DynamicObject matInvInfo;
|
||||
if (matInf != null) {
|
||||
matInvInfo = new DynamicObject(matInf.getDynamicObjectType());
|
||||
} else {
|
||||
matInvInfo = new DynamicObject(matInvDT);
|
||||
}
|
||||
|
||||
matInvInfo.set("org", orgId);
|
||||
matInvInfo.set("project", projectId);
|
||||
matInvInfo.set("warehouse", warehouseId);
|
||||
matInvInfo.set("material", entryInfo.getDynamicObject("material").getString("id"));
|
||||
matInvInfo.set("lot", entryInfo.getString("lot"));
|
||||
matInvInfo.set("measureunit", entryInfo.getDynamicObject("measureunit"));
|
||||
matInvInfo.set("currency", CurrencyHelper.getCurrency(Long.valueOf(orgId)));
|
||||
matInvInfo.set("price", entryInfo.getBigDecimal("price").multiply(exchangerate));
|
||||
matInvInfo.set("qty", entryInfo.getBigDecimal("qty").multiply(coef));
|
||||
matInvInfo.set("amount", entryInfo.getBigDecimal("amount").multiply(coef).multiply(exchangerate));
|
||||
matInvInfo.set("tempqty", entryInfo.getBigDecimal("qty").multiply(coef));
|
||||
matInvInfo.set("modelnum", entryInfo.getString("modelnum"));
|
||||
return matInvInfo;
|
||||
}
|
||||
|
||||
private static DynamicObject getMatInvInfo(String orgId, String projectId, String warehouseId, String matId, String modelnum, String lot, String unitId) {
|
||||
QFilter filter = new QFilter("org", "=", StringUtils.isBlank(orgId) ? 0L : Long.parseLong(orgId));
|
||||
filter.and(new QFilter("project", "=", StringUtils.isBlank(projectId) ? 0L : Long.parseLong(projectId)));
|
||||
filter.and(new QFilter("warehouse", "=", StringUtils.isBlank(warehouseId) ? 0L : Long.parseLong(warehouseId)));
|
||||
filter.and(new QFilter("material", "=", StringUtils.isBlank(matId) ? 0L : Long.parseLong(matId)));
|
||||
filter.and(new QFilter("modelnum", "=", modelnum == "" ? " " : modelnum));
|
||||
filter.and(new QFilter("lot", "=", lot));
|
||||
filter.and(new QFilter("measureunit", "=", StringUtils.isBlank(unitId) ? 0L : Long.parseLong(unitId)));
|
||||
DynamicObject matInvInfo = BusinessDataServiceHelper.loadSingle("ecma_matinventory", "id,measureunit,lot,currency,price,qty,amount,lockedqty,tempqty,modelnum,saleprice,measureuint,project,org,material,warehouse", new QFilter[]{filter});
|
||||
return matInvInfo;
|
||||
}
|
||||
|
||||
public static String[] getEntryKeys() {
|
||||
return new String[]{"materialId", "modelnum", "lot"};
|
||||
}
|
||||
|
||||
public static String checkLotPrice(String orgId, String projectId, String warehouseId, DynamicObject[] entrys) {
|
||||
for(int i = 0; i < entrys.length; ++i) {
|
||||
DynamicObject entryInfo = entrys[i];
|
||||
String lot = entryInfo.getString("lot");
|
||||
if (lot != null && lot != "") {
|
||||
DynamicObject material = entryInfo.getDynamicObject("material");
|
||||
String matId = material.getString("id");
|
||||
String modelnum = "".equals(entryInfo.getString("modelnum")) ? " " : entryInfo.getString("modelnum");
|
||||
BigDecimal outPrice = entryInfo.getBigDecimal("price");
|
||||
String unitId = entryInfo.getDynamicObject("measureunit") == null ? "" : entryInfo.getDynamicObject("measureunit").getString("id");
|
||||
DynamicObject invMatInfo = getMatInvInfo(orgId, projectId, warehouseId, matId, modelnum, lot, unitId);
|
||||
BigDecimal invPrice = invMatInfo.getBigDecimal("price");
|
||||
if (outPrice.compareTo(invPrice) != 0) {
|
||||
String errMsg = String.format(ResManager.loadKDString("编码为%1$s,名称为%2$s,,规格型号为%3$s,批次为%4$s的物料存在批次且出库价格跟入库价格不一致!", "MaterialInventoryUtils_13", "ec-ecma-common", new Object[0]), material.getString("number"), material.getString("name"), modelnum, lot);
|
||||
return errMsg;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return "success";
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue