入库单反写采购申请单逻辑添加与选择采购申请逻辑优化
This commit is contained in:
parent
465c959e30
commit
c36e23b893
|
|
@ -48,12 +48,28 @@ public class MaterialInbPurchaseApplyPlugin extends AbstractBillPlugIn implement
|
|||
HashMap<String, Object> paramters = new HashMap<>();
|
||||
DynamicObjectCollection entryEntityCollection = this.getModel().getDataEntity(true).getDynamicObjectCollection("entryentity");//入库单分录
|
||||
List<Long> entryIds = new ArrayList<>();
|
||||
List<Long> entryIds2 = new ArrayList<>();
|
||||
for (DynamicObject entryEntity : entryEntityCollection) {
|
||||
Long entryEntityId = entryEntity.getLong("listingid");//合同清单id
|
||||
entryIds.add(entryEntityId);
|
||||
entryIds2.add(entryEntityId);
|
||||
}
|
||||
|
||||
long purchaseApplyId = purchaseApply.getLong("id");//采购申请单id
|
||||
QFilter[] qFilte = new QFilter[]{new QFilter("zcgj_purchaseapply.id", QCP.equals, purchaseApplyId)};
|
||||
DynamicObject[] ecma_materialInBills = BusinessDataServiceHelper.load("ecma_materialinbill","entryentity,entryentity.listingid", qFilte);//入库单
|
||||
for (DynamicObject materialInBill : ecma_materialInBills) {
|
||||
DynamicObjectCollection entryEntityCollection1 = materialInBill.getDynamicObjectCollection("entryentity");//入库单分录
|
||||
for (DynamicObject entryEntity : entryEntityCollection1) {
|
||||
long entryEntityId = entryEntity.getLong("listingid");//入库单分录-合同清单id
|
||||
if (materialInBill.get("id").equals(this.getModel().getValue("id"))){
|
||||
if (!entryIds2.contains(entryEntityId)){
|
||||
break;
|
||||
}
|
||||
}
|
||||
entryIds.add(entryEntityId);
|
||||
}
|
||||
}
|
||||
paramters.put("purchaseApplyId", purchaseApplyId);
|
||||
paramters.put("entryIds", entryIds);
|
||||
formShowParameter.setCustomParams(paramters);
|
||||
|
|
|
|||
|
|
@ -0,0 +1,68 @@
|
|||
package zcgj.zcdev.zcdev.pr.plugin.operate;
|
||||
|
||||
import kd.bos.dataentity.entity.DynamicObject;
|
||||
import kd.bos.dataentity.entity.DynamicObjectCollection;
|
||||
import kd.bos.entity.plugin.AbstractOperationServicePlugIn;
|
||||
import kd.bos.entity.plugin.args.AfterOperationArgs;
|
||||
import kd.bos.orm.query.QFilter;
|
||||
import kd.bos.servicehelper.BusinessDataServiceHelper;
|
||||
import kd.bos.servicehelper.operation.SaveServiceHelper;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 入库单保存删除插件:保存、删除时,将入库单数量反写至采购申请单
|
||||
*/
|
||||
public class PurchaseReqBackWriteOp extends AbstractOperationServicePlugIn {
|
||||
|
||||
@Override
|
||||
public void afterExecuteOperationTransaction(AfterOperationArgs e) {
|
||||
super.afterExecuteOperationTransaction(e);
|
||||
|
||||
String operationKey = e.getOperationKey();//操作标识
|
||||
DynamicObject[] dataEntities = e.getDataEntities();
|
||||
List<DynamicObject> modifiedEntities = new ArrayList<>();
|
||||
|
||||
for (DynamicObject model : dataEntities) {
|
||||
long id = model.getLong("id");
|
||||
QFilter f1 = new QFilter("id", "=", id);
|
||||
DynamicObject ecma_MaterialInBill = BusinessDataServiceHelper.loadSingle("ecma_materialinbill", new QFilter[]{f1});//入库单
|
||||
String matInSource = ecma_MaterialInBill.getString("matinsource");//入库来源
|
||||
DynamicObject zcgj_purchaseApply = ecma_MaterialInBill.getDynamicObject("zcgj_purchaseapply");//采购申请
|
||||
if ("6".equals(matInSource) && zcgj_purchaseApply != null) {
|
||||
//为采购申请单时反写数量
|
||||
DynamicObject ecma_purchaseApply = BusinessDataServiceHelper.loadSingle("ecma_purchaseapply",
|
||||
new QFilter[]{new QFilter("id", "=", zcgj_purchaseApply.getLong("id"))});//采购申请单
|
||||
DynamicObjectCollection purchaseEntryCollection = ecma_purchaseApply.getDynamicObjectCollection("purchaseentry");//采购明细单据体
|
||||
DynamicObjectCollection entryEntityCollection = ecma_MaterialInBill.getDynamicObjectCollection("entryentity");//入库单分录
|
||||
for (DynamicObject entryEntity : entryEntityCollection) {
|
||||
String listingId = entryEntity.getString("listingid");//入库单分录-合同清单id
|
||||
|
||||
for (DynamicObject purchaseEntry : purchaseEntryCollection) {
|
||||
String purchaseEntryId = purchaseEntry.getString("id");//采购明细单据体-id
|
||||
if (purchaseEntryId != null && purchaseEntryId.equals(listingId)) {
|
||||
BigDecimal qty = entryEntity.getBigDecimal("qty");//入库单分录-数量
|
||||
BigDecimal inCount = purchaseEntry.getBigDecimal("zcgj_incount");//采购明细单据体-已入库数量
|
||||
if ("save".equals(operationKey)) {
|
||||
purchaseEntry.set("zcgj_incount", inCount.add(qty));//采购明细单据体-已入库数量
|
||||
} else {
|
||||
purchaseEntry.set("zcgj_incount", inCount.subtract(qty));//采购明细单据体-已入库数量
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
modifiedEntities.add(ecma_purchaseApply);
|
||||
}
|
||||
}
|
||||
if (!modifiedEntities.isEmpty()) {
|
||||
try {
|
||||
SaveServiceHelper.save(modifiedEntities.toArray(new DynamicObject[0]));
|
||||
} catch (Exception ex) {
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue