入库单添加多条采购申请单过滤赋值逻辑

This commit is contained in:
xuhaihui 2025-10-23 17:42:20 +08:00
parent cfc9ec22b0
commit 942e1db53f
2 changed files with 199 additions and 79 deletions

View File

@ -7,8 +7,10 @@ import kd.bos.dataentity.metadata.dynamicobject.DynamicObjectType;
import kd.bos.dataentity.resource.ResManager;
import kd.bos.entity.datamodel.RowDataEntity;
import kd.bos.entity.datamodel.events.AfterAddRowEventArgs;
import kd.bos.entity.datamodel.events.BeforeDeleteRowEventArgs;
import kd.bos.entity.datamodel.events.ChangeData;
import kd.bos.entity.datamodel.events.PropertyChangedArgs;
import kd.bos.entity.property.EntryProp;
import kd.bos.form.*;
import kd.bos.form.control.EntryGrid;
import kd.bos.form.control.events.ItemClickEvent;
@ -48,9 +50,12 @@ public class MaterialInbPurchaseApplyPlugin extends AbstractBillPlugIn implement
super.registerListener(e);
RefBillEdit purchaseApply = getView().getControl("zcgj_purchaseapply");//采购申请
purchaseApply.addBeforeF7SelectListener(this);
BasedataEdit zcgj_purchaseapply_f7 = getView().getControl("zcgj_purchaseapply_f7");//采购申请分录-采购申请
zcgj_purchaseapply_f7.addBeforeF7SelectListener(this);
BasedataEdit zcgj_applidepart = getView().getControl("zcgj_applidepart");//申请人部门
zcgj_applidepart.addBeforeF7SelectListener(this);
this.addItemClickListeners("advcontoolbarap");//入库单明细工具栏
this.addItemClickListeners("zcgj_entrytoolbar111");//采购申请分录工具栏
}
@Override
@ -73,6 +78,40 @@ public class MaterialInbPurchaseApplyPlugin extends AbstractBillPlugIn implement
}
}
@Override
public void beforeDeleteRow(BeforeDeleteRowEventArgs e) {
super.beforeDeleteRow(e);
String entryName = e.getEntryProp().getName();
if ("zcgj_purchaseapplyentry".equals(entryName)) {
List<String> documentNumbers = new ArrayList<>();
int[] rowIndexs = e.getRowIndexs();
for (int rowIndex : rowIndexs) {
DynamicObject zcgj_purchaseapplyentry = this.getModel().getEntryRowEntity("zcgj_purchaseapplyentry", rowIndex);//采购申请分录
DynamicObject zcgj_purchaseapply_f7 = zcgj_purchaseapplyentry.getDynamicObject("zcgj_purchaseapply_f7");//采购申请分录-采购申请
if (zcgj_purchaseapply_f7 != null) {
String documentNumber = zcgj_purchaseapply_f7.getString("zcgj_number");
if (documentNumber != null) {
documentNumbers.add(documentNumber);
}
}
}
DynamicObjectCollection entryEntityCollection = this.getModel().getDataEntity(true).getDynamicObjectCollection("entryentity");//入库单分录
List<Integer> indexesToRemove = new ArrayList<>();
for (int i = 0; i < entryEntityCollection.size(); i++) {
DynamicObject entryEntity = entryEntityCollection.get(i);
String zcgj_purchaseapplynumb = entryEntity.getString("zcgj_purchaseapplynumb");
if (zcgj_purchaseapplynumb != null && documentNumbers.contains(zcgj_purchaseapplynumb)) {
indexesToRemove.add(i);
}
}
indexesToRemove.sort(Collections.reverseOrder());
for (int index : indexesToRemove) {
this.getModel().deleteEntryRow("entryentity", index);
}
this.getView().updateView("entryentity");
}
}
public void afterAddRow(AfterAddRowEventArgs e) {
super.afterAddRow(e);
String entryName = e.getEntryProp().getName();//新增行单据体名
@ -223,6 +262,18 @@ public class MaterialInbPurchaseApplyPlugin extends AbstractBillPlugIn implement
BigDecimal totalAmount = matAmount.add(transAmount);
this.getModel().setValue("totalamount", totalAmount);//入库总金额
}
} else if ("zcgj_ispurchaseapplys".equals(key)) {
//多采购申请
ChangeData[] changeSet = e.getChangeSet();
ChangeData changeData = changeSet[0];
boolean newValue = (boolean) changeData.getNewValue();//新值
if (newValue) {
this.getModel().setValue("zcgj_purchaseapply", null);//采购申请
} else {
DynamicObjectCollection zcgj_purchaseapplyentry = this.getModel().getDataEntity(true).getDynamicObjectCollection("zcgj_purchaseapplyentry");//采购申请分录
zcgj_purchaseapplyentry.clear();
this.getView().updateView("zcgj_purchaseapplyentry");//刷新分录
}
}
}
@ -231,8 +282,8 @@ public class MaterialInbPurchaseApplyPlugin extends AbstractBillPlugIn implement
ListShowParameter formShowParameter = (ListShowParameter) beforeF7SelectEvent.getFormShowParameter();
List<QFilter> qFilters = new ArrayList<>();
String propertyName = beforeF7SelectEvent.getProperty().getName();
if ("zcgj_purchaseapply".equals(propertyName)) {
//采购申请
if ("zcgj_purchaseapply".equals(propertyName) || "zcgj_purchaseapply_f7".equals(propertyName)) {
//采购申请采购申请分录-采购申请
Object fiaccountorg = this.getModel().getValue("fiaccountorg");//财务记账组织
if (fiaccountorg == null) {
this.getView().showErrorNotification("请先填写财务记账组织!!");
@ -286,9 +337,10 @@ public class MaterialInbPurchaseApplyPlugin extends AbstractBillPlugIn implement
long zcgj_bigintfield = returnData.getLong("zcgj_bigintfield");//采购申请单id
QFilter filter = new QFilter("purchaseentry.id", QCP.equals, zcgj_bigintfield);
DynamicObjectCollection purchaseApply = QueryServiceHelper.query("ecma_purchaseapply",
"purchaseentry,purchaseentry.material,purchaseentry.purchaseqty,purchaseentry.entrytaxrate,purchaseentry.price,purchaseentry.id,purchaseentry.remarks,purchaseentry.zcgj_incount,purchaseentry.zcgj_model",
"billno,purchaseentry,purchaseentry.material,purchaseentry.purchaseqty,purchaseentry.entrytaxrate,purchaseentry.price,purchaseentry.id,purchaseentry.remarks,purchaseentry.zcgj_incount,purchaseentry.zcgj_model",
new QFilter[]{filter});//采购申请单
Object billno = purchaseApply.get(0).get("billno");//单据编码
long material = purchaseApply.get(0).getLong("purchaseentry.material");//采购申请分录-资源编码
Object zcgj_model = purchaseApply.get(0).get("purchaseentry.zcgj_model");//采购申请分录-规格型号
BigDecimal purchaseQty = (BigDecimal) purchaseApply.get(0).get("purchaseentry.purchaseqty");//采购申请分录-采购数量
@ -297,6 +349,7 @@ public class MaterialInbPurchaseApplyPlugin extends AbstractBillPlugIn implement
Object price = purchaseApply.get(0).get("purchaseentry.price");//采购申请分录-预估单价
Object purchaseEntryId = purchaseApply.get(0).get("purchaseentry.id");//采购申请分录-预估单价
Object remarks = purchaseApply.get(0).get("purchaseentry.remarks");//采购申请分录-备注
this.getModel().setValue("zcgj_purchaseapplynumb", billno, curIndex);//单据编码
this.getModel().setValue("material", material, curIndex);//资源编码
this.getModel().setValue("modelnum", zcgj_model, curIndex);//规格型号
this.getModel().setValue("entrytaxrate", entryTaxRate, curIndex);//税率名称
@ -309,25 +362,42 @@ public class MaterialInbPurchaseApplyPlugin extends AbstractBillPlugIn implement
}
private void doPurchaseApply() {
DynamicObject purchaseApply = (DynamicObject) this.getModel().getValue("zcgj_purchaseapply");//采购申请单
if (purchaseApply == null) {
this.getView().showTipNotification(ResManager.loadKDString("请先选择采购申请。", "MaterialInBillEditPlugin_0", "ec-ecma-formplugin", new Object[0]));
} else {
FormShowParameter formShowParameter = new FormShowParameter();
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[] qFilter = new QFilter[]{new QFilter("id", QCP.equals, purchaseApplyId)};
DynamicObject ecma_purchaseApply = BusinessDataServiceHelper.loadSingle("ecma_purchaseapply",
boolean zcgj_ispurchaseapplys = (boolean) this.getModel().getValue("zcgj_ispurchaseapplys");//多采购申请
if (zcgj_ispurchaseapplys) {
DynamicObjectCollection purchaseApplyEntryCollection = this.getModel().getDataEntity(true).getDynamicObjectCollection("zcgj_purchaseapplyentry");//采购申请分录
if (purchaseApplyEntryCollection.size() == 0) {
this.getView().showTipNotification(ResManager.loadKDString("请先选择采购申请。", "MaterialInBillEditPlugin_0", "ec-ecma-formplugin", new Object[0]));
return;
}
List<Long> purchaseApplyIds = new ArrayList<>();
for (DynamicObject purchaseApplyEntry : purchaseApplyEntryCollection) {
DynamicObject purchaseApplyF7 = purchaseApplyEntry.getDynamicObject("zcgj_purchaseapply_f7");
if (purchaseApplyF7 != null) {
purchaseApplyIds.add(purchaseApplyF7.getLong("id"));
}
}
QFilter[] qFilter = new QFilter[0];
if (!purchaseApplyIds.isEmpty()) {
qFilter = new QFilter[]{new QFilter("id", QCP.in, purchaseApplyIds)};
} else {
// 如果没有有效的 id可以设置一个永远不匹配的条件或者处理为空的情况
qFilter = new QFilter[]{new QFilter("id", QCP.equals, -1L)};
}
DynamicObject[] ecma_purchaseapplies = BusinessDataServiceHelper.load("ecma_purchaseapply",
"purchaseentry,purchaseentry.purchaseqty,purchaseentry.zcgj_incount,purchaseentry.id", qFilter);//采购申请单
if (ecma_purchaseapplies.length == 0) {
this.getView().showTipNotification(ResManager.loadKDString("未找到相关采购申请数据。", "MaterialInBillEditPlugin_1", "ec-ecma-formplugin", new Object[0]));
return;
}
for (DynamicObject ecma_purchaseApply : ecma_purchaseapplies) {
DynamicObjectCollection purchaseEntryCollection = ecma_purchaseApply.getDynamicObjectCollection("purchaseentry");//采购明细单据体
for (DynamicObject purchaseEntry : purchaseEntryCollection) {
BigDecimal purchaseQty = purchaseEntry.getBigDecimal("purchaseqty");//采购数量
@ -337,22 +407,35 @@ public class MaterialInbPurchaseApplyPlugin extends AbstractBillPlugIn implement
entryIds.add(purchaseEntryId);
}
}
/* 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;
paramters.put("purchaseApplyIds", purchaseApplyIds);
}
} else {
DynamicObject purchaseApply = (DynamicObject) this.getModel().getValue("zcgj_purchaseapply");//采购申请单
if (purchaseApply == null) {
this.getView().showTipNotification(ResManager.loadKDString("请先选择采购申请。", "MaterialInBillEditPlugin_0", "ec-ecma-formplugin", new Object[0]));
} else {
long purchaseApplyId = purchaseApply.getLong("id");//采购申请单id
QFilter[] qFilter = new QFilter[]{new QFilter("id", QCP.equals, purchaseApplyId)};
DynamicObject ecma_purchaseApply = BusinessDataServiceHelper.loadSingle("ecma_purchaseapply",
"purchaseentry,purchaseentry.purchaseqty,purchaseentry.zcgj_incount,purchaseentry.id", qFilter);//采购申请单
if (ecma_purchaseApply == null) {
this.getView().showTipNotification(ResManager.loadKDString("未找到相关采购申请数据。", "MaterialInBillEditPlugin_1", "ec-ecma-formplugin", new Object[0]));
return;
}
DynamicObjectCollection purchaseEntryCollection = ecma_purchaseApply.getDynamicObjectCollection("purchaseentry");//采购明细单据体
for (DynamicObject purchaseEntry : purchaseEntryCollection) {
BigDecimal purchaseQty = purchaseEntry.getBigDecimal("purchaseqty");//采购数量
BigDecimal zcgj_inCount = purchaseEntry.getBigDecimal("zcgj_incount");//已入库数量
if (purchaseQty.compareTo(zcgj_inCount) == 0) {
long purchaseEntryId = purchaseEntry.getLong("id");
entryIds.add(purchaseEntryId);
}
}
entryIds.add(entryEntityId);
}
}*/
paramters.put("purchaseApplyId", purchaseApplyId);
}
}
paramters.put("entryIds", entryIds);
paramters.put("zcgj_ispurchaseapplys", zcgj_ispurchaseapplys);
formShowParameter.setCustomParams(paramters);
formShowParameter.setCaption("采购申请分录列表");
formShowParameter.setFormId("zcgj_purchaseapplyentry");
@ -366,7 +449,6 @@ public class MaterialInbPurchaseApplyPlugin extends AbstractBillPlugIn implement
openStyle.setInlineStyleCss(styleCss);
this.getView().showForm(formShowParameter);
}
}
private void setNewExpenseSummary() {
DynamicObjectCollection entryEntityCollection = this.getModel().getDataEntity(true).getDynamicObjectCollection("entryentity");//入库单分录

View File

@ -7,6 +7,8 @@ import kd.bos.form.control.Button;
import kd.bos.form.control.Control;
import kd.bos.form.control.EntryGrid;
import kd.bos.form.plugin.AbstractFormPlugin;
import kd.bos.orm.query.QCP;
import kd.bos.orm.query.QFilter;
import kd.bos.servicehelper.BusinessDataServiceHelper;
import kd.sdk.plugin.Plugin;
@ -53,9 +55,43 @@ public class PurchaseApplyEntryPlugin extends AbstractFormPlugin implements Plug
public void afterCreateNewData(EventObject e) {
super.afterCreateNewData(e);
Map<String, Object> customParams = this.getView().getFormShowParameter().getCustomParams();
List<Long> entryIds = (List<Long>) customParams.get("entryIds");
boolean zcgj_ispurchaseapplys = (boolean) customParams.get("zcgj_ispurchaseapplys");//多采购申请
if (zcgj_ispurchaseapplys) {
List<Long> purchaseApplyIds = (List<Long>) customParams.get("purchaseApplyIds");//采购申请单ID合集
if (!purchaseApplyIds.isEmpty()) {
QFilter[] qFiltes = new QFilter[]{new QFilter("id", QCP.in, purchaseApplyIds)};
DynamicObject[] ecma_purchaseApplys = BusinessDataServiceHelper.load("ecma_purchaseapply",
"billno,purchaseentry,purchaseentry.material,purchaseentry.purchaseqty," +
"purchaseentry.unit,purchaseentry.zcgj_incount,purchaseentry.id," +
"purchaseentry.remarks,purchaseentry.zcgj_model," +
"purchaseentry.oftaxprice,purchaseentry.oftaxamount", qFiltes);//采购申请单
for (DynamicObject ecma_purchaseApply : ecma_purchaseApplys) {
DynamicObjectCollection purchaseEntryCollection = ecma_purchaseApply.getDynamicObjectCollection("purchaseentry");//采购明细单据体
DynamicObjectCollection entryEntityCollection = this.getModel().getEntryEntity("zcgj_entryentity");//分录
for (DynamicObject purchaseEntry : purchaseEntryCollection) {
Long id = (Long) purchaseEntry.get("id");
if (entryIds != null && entryIds.contains(id)) {
continue;
}
DynamicObject entryEntityNew = entryEntityCollection.addNew();
entryEntityNew.set("zcgj_bigintfield", id);//分录id
entryEntityNew.set("zcgj_purchaseapplynumb", ecma_purchaseApply.getString("billno"));//单据编码
entryEntityNew.set("zcgj_material", purchaseEntry.get("material"));//物料
entryEntityNew.set("zcgj_modelnum", purchaseEntry.getDynamicObject("material").get("model"));//规格型号
entryEntityNew.set("zcgj_measureunit", purchaseEntry.get("unit"));//计量单位
entryEntityNew.set("zcgj_qty", purchaseEntry.get("purchaseqty"));//数量
entryEntityNew.set("zcgj_incount", purchaseEntry.get("zcgj_incount"));//已入库数量
entryEntityNew.set("zcgj_price", purchaseEntry.get("oftaxprice"));//合同单价含税
entryEntityNew.set("zcgj_oftaxamt", purchaseEntry.get("oftaxamount"));//本次订单金额含税
entryEntityNew.set("zcgj_description", purchaseEntry.get("remarks"));//备注
}
}
System.out.println();
}
} else {
Long purchaseApplyId = (Long) customParams.get("purchaseApplyId");//采购申请单ID
if (purchaseApplyId != null) {
List<Long> entryIds = (List<Long>) customParams.get("entryIds");
DynamicObject ecma_purchaseApply = BusinessDataServiceHelper.loadSingle(purchaseApplyId, "ecma_purchaseapply");//采购申请单
DynamicObjectCollection purchaseEntryCollection = ecma_purchaseApply.getDynamicObjectCollection("purchaseentry");//采购明细单据体
DynamicObjectCollection entryEntityCollection = this.getModel().getEntryEntity("zcgj_entryentity");//分录
@ -66,6 +102,7 @@ public class PurchaseApplyEntryPlugin extends AbstractFormPlugin implements Plug
}
DynamicObject entryEntityNew = entryEntityCollection.addNew();
entryEntityNew.set("zcgj_bigintfield", id);//分录id
entryEntityNew.set("zcgj_purchaseapplynumb", ecma_purchaseApply.getString("billno"));//单据编码
entryEntityNew.set("zcgj_material", purchaseEntry.get("material"));//物料
entryEntityNew.set("zcgj_modelnum", purchaseEntry.getDynamicObject("material").get("model"));//规格型号
entryEntityNew.set("zcgj_measureunit", purchaseEntry.get("unit"));//计量单位
@ -77,4 +114,5 @@ public class PurchaseApplyEntryPlugin extends AbstractFormPlugin implements Plug
}
}
}
}
}