入库单点击选择采购申请按钮后弹出对应采购申请分录内容,后通过选择弹出的采购申请分录行赋值给入库单中

This commit is contained in:
xuhaihui 2025-07-25 18:09:49 +08:00
parent e7142a269f
commit 465c959e30
2 changed files with 184 additions and 0 deletions

View File

@ -0,0 +1,106 @@
package zcgj.zcdev.zcdev.pr.plugin.form;
import kd.bos.algo.DataSet;
import kd.bos.algo.JoinDataSet;
import kd.bos.algo.JoinType;
import kd.bos.algo.Row;
import kd.bos.bill.AbstractBillPlugIn;
import kd.bos.dataentity.entity.DynamicObject;
import kd.bos.dataentity.entity.DynamicObjectCollection;
import kd.bos.dataentity.resource.ResManager;
import kd.bos.dataentity.utils.StringUtils;
import kd.bos.entity.EntityMetadataCache;
import kd.bos.entity.datamodel.ListSelectedRowCollection;
import kd.bos.form.*;
import kd.bos.form.events.AfterDoOperationEventArgs;
import kd.bos.form.events.BeforeDoOperationEventArgs;
import kd.bos.form.events.ClosedCallBackEvent;
import kd.bos.form.operate.FormOperate;
import kd.bos.list.ListShowParameter;
import kd.bos.orm.query.QCP;
import kd.bos.orm.query.QFilter;
import kd.bos.servicehelper.BusinessDataServiceHelper;
import kd.bos.servicehelper.QueryServiceHelper;
import kd.sdk.plugin.Plugin;
import java.util.*;
import java.util.stream.Collectors;
/**
* 入库单表单插件入库单点击选择采购申请按钮后弹出对应采购申请分录内容后通过选择弹出的采购申请分录行赋值给入库单中
*/
public class MaterialInbPurchaseApplyPlugin extends AbstractBillPlugIn implements Plugin {
public void beforeDoOperation(BeforeDoOperationEventArgs args) {
super.beforeDoOperation(args);
FormOperate operate = (FormOperate) args.getSource();
if ("purchaseapply".equals(operate.getOperateKey())) {
//选择采购申请单
this.doPurchaseApply();
}
}
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<>();
for (DynamicObject entryEntity : entryEntityCollection) {
Long entryEntityId = entryEntity.getLong("listingid");//合同清单id
entryIds.add(entryEntityId);
}
long purchaseApplyId = purchaseApply.getLong("id");//采购申请单id
paramters.put("purchaseApplyId", purchaseApplyId);
paramters.put("entryIds", entryIds);
formShowParameter.setCustomParams(paramters);
formShowParameter.setCaption("采购申请分录列表");
formShowParameter.setFormId("zcgj_purchaseapplyentry");
formShowParameter.setCloseCallBack(new CloseCallBack(this, "zcgj_selectpurchaseapply"));
StyleCss styleCss = new StyleCss();
styleCss.setWidth("900");
styleCss.setHeight("545");
OpenStyle openStyle = formShowParameter.getOpenStyle();
openStyle.setShowType(ShowType.Modal);
openStyle.setInlineStyleCss(styleCss);
this.getView().showForm(formShowParameter);
}
}
public void closedCallBack(ClosedCallBackEvent closedCallBackEvent) {
super.closedCallBack(closedCallBackEvent);
String actionId = closedCallBackEvent.getActionId();
DynamicObjectCollection returnDataCollection = (DynamicObjectCollection) closedCallBackEvent.getReturnData();
if (returnDataCollection == null) {
return;
}
if ("zcgj_selectpurchaseapply".equals(actionId) && returnDataCollection.size() > 0) {
for (DynamicObject returnData : returnDataCollection) {
int curIndex = this.getModel().createNewEntryRow("entryentity");
this.getModel().updateCache();
this.getView().setEnable(false, curIndex, new String[]{"oftaxamount", "notaxamount", "taxamount", "taxprice"});
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",
new QFilter[]{filter});//采购申请单
long material = purchaseApply.get(0).getLong("purchaseentry.material");//采购申请分录-资源编码
Object purchaseQty = purchaseApply.get(0).get("purchaseentry.purchaseqty");//采购申请分录-采购数量
Object entryTaxRate = purchaseApply.get(0).get("purchaseentry.entrytaxrate");//采购申请分录-税率
Object price = purchaseApply.get(0).get("purchaseentry.price");//采购申请分录-预估单价
Object purchaseEntryId = purchaseApply.get(0).get("purchaseentry.id");//采购申请分录-预估单价
this.getModel().setValue("material", material, curIndex);//资源编码
this.getModel().setValue("entrytaxrate", entryTaxRate, curIndex);//税率名称
this.getModel().setValue("qty", purchaseQty, curIndex);//数量
this.getModel().setValue("price", price, curIndex);//入库单价
this.getModel().setValue("listingid", purchaseEntryId, curIndex);//合同清单id
}
}
}
}

View File

@ -0,0 +1,78 @@
package zcgj.zcdev.zcdev.pr.plugin.form;
import com.alibaba.fastjson.JSONObject;
import kd.bos.dataentity.entity.DynamicObject;
import kd.bos.dataentity.entity.DynamicObjectCollection;
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.servicehelper.BusinessDataServiceHelper;
import kd.sdk.plugin.Plugin;
import java.util.EventObject;
import java.util.List;
import java.util.Map;
/*
* 采购申请单物料列表插件返回入库单点击选择采购申请信息
*/
public class PurchaseApplyEntryPlugin extends AbstractFormPlugin implements Plugin {
@Override
public void registerListener(EventObject e) {
super.registerListener(e);
Button btnok = this.getControl("btnok");//确定
btnok.addClickListener(this);
}
@Override
public void click(EventObject evt) {
super.click(evt);
Control source = (Control) evt.getSource();
if ("btnok".equals(source.getKey())) {
EntryGrid entryGrid = this.getControl("zcgj_entryentity");
int[] selectRows = entryGrid.getSelectRows();
int count = selectRows.length;
//分录行数只有一条的时候才能通过接下来两个if
if (count == 0) {
this.getView().showErrorNotification("请选择一条分录信息!");
return;
}
DynamicObjectCollection qeug_entryentity = getModel().getEntryEntity("zcgj_entryentity");//分录
DynamicObjectCollection collection = new DynamicObjectCollection();
for (int selectRow : selectRows) {
collection.add(qeug_entryentity.get(selectRow));
}
this.getView().returnDataToParent(collection);//返回所选数据给父级
this.getView().close();
}
}
@Override
public void afterCreateNewData(EventObject e) {
super.afterCreateNewData(e);
Map<String, Object> customParams = this.getView().getFormShowParameter().getCustomParams();
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");//分录
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_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_price", purchaseEntry.get("oftaxprice"));//合同单价含税
entryEntityNew.set("zcgj_oftaxamt", purchaseEntry.get("oftaxamount"));//本次订单金额含税
entryEntityNew.set("zcgj_description", purchaseEntry.get("remarks"));//备注
}
}
}
}