入库单优化审核生成即时库存单据中单价的赋值逻辑
This commit is contained in:
parent
2deeee51cb
commit
db0509d311
|
|
@ -135,20 +135,220 @@ public class MaterialInBillOpExt extends AbstractOperationServicePlugIn {
|
|||
}
|
||||
}
|
||||
|
||||
/* public void beginOperationTransaction(BeginOperationTransactionArgs e) {
|
||||
super.beginOperationTransaction(e);
|
||||
String operationKey = e.getOperationKey();
|
||||
DynamicObject[] dataEntities = e.getDataEntities();
|
||||
ArrayList succObjs;
|
||||
DynamicObject obj;
|
||||
String msg;
|
||||
QFilter entryIdFilter;
|
||||
DynamicObject[] materialinBills;
|
||||
String result;
|
||||
String msg;
|
||||
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);
|
||||
}
|
||||
|
||||
msg = this.updatematBalance(obj, true);
|
||||
if (!"success".equals(msg)) {
|
||||
throw new KDBizException(msg);
|
||||
}
|
||||
|
||||
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) {
|
||||
result = String.format(ResManager.loadKDString("单据名称:%s的分录已被主要材料成本核算单分录引用,无法反审核!", "MaterialInBillOp_1", "ec-ecma-opplugin", new Object[0]), o.getString("billname"));
|
||||
throw new KDBizException(result);
|
||||
}
|
||||
|
||||
DynamicObject[] sporadicEntry = BusinessDataServiceHelper.load("ecco_sporadicmatcost", "id,billno,entryentity,entryentity.materialentryid", new QFilter[]{entryIdFilter});
|
||||
if (sporadicEntry.length > 0) {
|
||||
msg = String.format(ResManager.loadKDString("单据名称:%s的分录已被零星材料成本核算单分录引用,无法反审核!", "MaterialInBillOp_2", "ec-ecma-opplugin", new Object[0]), o.getString("billname"));
|
||||
throw new KDBizException(msg);
|
||||
}
|
||||
|
||||
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) {
|
||||
result = String.format(ResManager.loadKDString("单据编码%s重复,请重新输入单据编码!", "MaterialInBillOp_3", "ec-ecma-opplugin", new Object[0]), billNumber);
|
||||
throw new KDBizException(result);
|
||||
}
|
||||
|
||||
result = this.updateMatLocked(o, true, true);
|
||||
if (!"success".equals(result)) {
|
||||
msg = String.format(ResManager.loadKDString("提交失败!%s", "MaterialInBillOp_4", "ec-ecma-opplugin", new Object[0]), result);
|
||||
throw new KDBizException(msg);
|
||||
}
|
||||
|
||||
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) {
|
||||
obj = dataEntities[i];
|
||||
String result = this.updateMatLocked(obj, false, false);
|
||||
if (!"success".equals(result)) {
|
||||
msg = String.format(ResManager.loadKDString("撤销失败!%s", "MaterialInBillOp_5", "ec-ecma-opplugin", new Object[0]), result);
|
||||
throw new KDBizException(msg);
|
||||
}
|
||||
|
||||
succObjs.add(obj);
|
||||
}
|
||||
|
||||
e.setDataEntities((DynamicObject[])succObjs.toArray(new DynamicObject[succObjs.size()]));
|
||||
}
|
||||
|
||||
}*///系统源码
|
||||
public void beginOperationTransaction(BeginOperationTransactionArgs e) {
|
||||
super.beginOperationTransaction(e);
|
||||
String operationKey = e.getOperationKey();
|
||||
DynamicObject[] dataEntities = e.getDataEntities();
|
||||
ArrayList succObjs;
|
||||
DynamicObject obj1;//二开替代
|
||||
// DynamicObject obj;//系统源码
|
||||
// String msg;//系统源码
|
||||
DynamicObject obj1;
|
||||
String msg1;
|
||||
QFilter entryIdFilter;
|
||||
DynamicObject[] materialinBills;
|
||||
String result1;//二开替代
|
||||
// String result;//系统源码
|
||||
// String msg;//系统源码
|
||||
String msg1;//二开替代
|
||||
String result1;
|
||||
DynamicObject[] var34;
|
||||
int var35;
|
||||
int var37;
|
||||
|
|
@ -168,7 +368,7 @@ public class MaterialInBillOpExt extends AbstractOperationServicePlugIn {
|
|||
|
||||
for (int i = 0; i < dataEntities.length; ++i) {
|
||||
DynamicObject obj = dataEntities[i];
|
||||
obj = obj.getDynamicObject("purchaseorder");
|
||||
/* obj = obj.getDynamicObject("purchaseorder");
|
||||
DynamicObjectCollection inEntry = obj.getDynamicObjectCollection("entryentity");
|
||||
if (obj != null) {
|
||||
o = BusinessDataServiceHelper.loadSingle(obj.getPkValue(), "ecma_purchaseorderbill");
|
||||
|
|
@ -200,7 +400,7 @@ public class MaterialInBillOpExt extends AbstractOperationServicePlugIn {
|
|||
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)) {
|
||||
|
|
@ -341,7 +541,8 @@ public class MaterialInBillOpExt extends AbstractOperationServicePlugIn {
|
|||
e.setDataEntities((DynamicObject[]) succObjs.toArray(new DynamicObject[succObjs.size()]));
|
||||
}
|
||||
|
||||
}
|
||||
}//二开替代
|
||||
|
||||
|
||||
protected void rewritePoundBills(DynamicObject[] dataEntities, boolean revoke) {
|
||||
if (!ArrayUtils.isEmpty(dataEntities)) {
|
||||
|
|
|
|||
|
|
@ -88,6 +88,111 @@ public class MaterialInventoryUtilsExt2 {
|
|||
}
|
||||
}
|
||||
|
||||
/* 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 void matBalanceUpdateNoDLock(String orgId, String projectId, String warehouseId, DynamicObject[] entrys, boolean isAdd, BigDecimal exchangerate) {
|
||||
BigDecimal coef = BigDecimal.ONE;
|
||||
if (!isAdd) {
|
||||
|
|
@ -169,10 +274,8 @@ public class MaterialInventoryUtilsExt2 {
|
|||
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);
|
||||
|
|
@ -180,8 +283,12 @@ public class MaterialInventoryUtilsExt2 {
|
|||
matInvInfo.set("qty", totalQty);
|
||||
matInvInfo.set("tempqty", totalTmpQty);
|
||||
matInvInfo.set("amount", totalAmount);
|
||||
if (!isFirst && totalQty.compareTo(BigDecimal.ZERO) != 0) {
|
||||
|
||||
// 统一使用 amount/tmpqty 计算价格
|
||||
if (totalTmpQty.compareTo(BigDecimal.ZERO) != 0) {
|
||||
matInvInfo.set("price", totalAmount.divide(totalTmpQty, 10, 4));
|
||||
} else {
|
||||
matInvInfo.set("price", BigDecimal.ZERO);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -191,8 +298,8 @@ public class MaterialInventoryUtilsExt2 {
|
|||
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;
|
||||
|
|
@ -351,6 +458,29 @@ public class MaterialInventoryUtilsExt2 {
|
|||
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 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;
|
||||
|
|
@ -360,6 +490,18 @@ public class MaterialInventoryUtilsExt2 {
|
|||
matInvInfo = new DynamicObject(matInvDT);
|
||||
}
|
||||
|
||||
// 计算数量和金额
|
||||
BigDecimal qty = entryInfo.getBigDecimal("qty").multiply(coef);
|
||||
BigDecimal amount = entryInfo.getBigDecimal("amount").multiply(coef).multiply(exchangerate);
|
||||
|
||||
// 计算价格,如果数量不为0则用amount/qty,否则用入库价格
|
||||
BigDecimal price;
|
||||
if (qty.compareTo(BigDecimal.ZERO) != 0) {
|
||||
price = amount.divide(qty.abs(), 10, BigDecimal.ROUND_HALF_UP);
|
||||
} else {
|
||||
price = entryInfo.getBigDecimal("price").multiply(exchangerate);
|
||||
}
|
||||
|
||||
matInvInfo.set("org", orgId);
|
||||
matInvInfo.set("project", projectId);
|
||||
matInvInfo.set("warehouse", warehouseId);
|
||||
|
|
@ -367,13 +509,14 @@ public class MaterialInventoryUtilsExt2 {
|
|||
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("price", price);
|
||||
matInvInfo.set("qty", qty);
|
||||
matInvInfo.set("amount", amount);
|
||||
matInvInfo.set("tempqty", qty);
|
||||
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));
|
||||
|
|
|
|||
Loading…
Reference in New Issue