1.采购立项,项目自动携带,增行判断是否选项目,代码携带采购需求+去重

2.采购计划提交时,判断需要采购需求
3.采购需求审核时,若没有明细自动生成一行
4.采购需求,根据组织自动携带项目
This commit is contained in:
weiyunlong 2024-12-13 17:49:22 +08:00
parent 5cac03da1e
commit 70e2a3ef56
5 changed files with 249 additions and 138 deletions

View File

@ -5,9 +5,12 @@ import kd.bos.dataentity.entity.DynamicObject;
import kd.bos.dataentity.entity.DynamicObjectCollection;
import kd.bos.dataentity.metadata.IDataEntityProperty;
import kd.bos.dataentity.metadata.dynamicobject.DynamicPropertyCollection;
import kd.bos.dataentity.resource.ResManager;
import kd.bos.dataentity.utils.StringUtils;
import kd.bos.entity.datamodel.IDataModel;
import kd.bos.entity.datamodel.ListSelectedRow;
import kd.bos.entity.datamodel.ListSelectedRowCollection;
import kd.bos.entity.datamodel.events.PropertyChangedArgs;
import kd.bos.entity.list.option.ListUserOption;
import kd.bos.form.CloseCallBack;
import kd.bos.form.ShowFormHelper;
@ -24,124 +27,100 @@ import kd.sdk.plugin.Plugin;
import java.util.*;
/**
* 单据界面插件
* 采购立项
* qeug_rebm_project_ext
*/
public class ImportPurchaseApplyBillPlugin extends AbstractBillPlugIn implements Plugin {
/*
* 采购计划单/标前预备会-引入采购需求单
* */
@Override
public void afterBindData(EventObject e) {
super.afterBindData(e);
//根据组织携带项目
updateRenovationProject();
}
@Override
public void propertyChanged(PropertyChangedArgs e) {
super.propertyChanged(e);
String name = e.getProperty().getName();
//根据组织携带项目
if ("org".equals(name)) {
updateRenovationProject();
}
}
private void updateRenovationProject() {
DynamicObject org = (DynamicObject) this.getModel().getValue("org");
DynamicObject qeugRenovationProj = (DynamicObject) this.getModel().getValue("qeug_renovation_proj");
// 只有在需求组织不为空的情况下才进行查询
if (org != null) {
if (qeugRenovationProj == null) {
setRenovationProjectByOrg(org);
} else {
// 如果已存在项目字段且组织发生了变化需更新
setRenovationProjectByOrg(org);
}
} else {
// 组织为空清空项目
this.getModel().setValue("qeug_renovation_proj", null);
this.getView().updateView("qeug_renovation_proj");
}
}
private void setRenovationProjectByOrg(DynamicObject org) {
//采购项目
DynamicObject[] projectbills = BusinessDataServiceHelper.load("rebm_purproject", "id",
new QFilter[]{new QFilter("org.id", QCP.equals, org.getPkValue())});
if (projectbills.length > 0) {
DynamicObject projectbill = projectbills[0];
this.getModel().setValue("qeug_renovation_proj", projectbill);
this.getView().updateView("qeug_renovation_proj");
}
}
String[] fields = new String[]{
"qeug_auditoption",
"qeug_option",
"qeug_linetype",
"qeug_materialmasterid",
"qeug_materialname",
"qeug_materialversion",
"qeug_auxpty",
"qeug_unit",
"qeug_qty",
"qeug_classtype",
"qeug_baseunit",
"qeug_baseqty",
"qeug_auxunit",
"qeug_auxqty",
"qeug_reqdate",
"qeug_reqkind",
"qeug_entrybizorg",
"qeug_reqdes",
"qeug_project",
"qeug_supplier",
"qeug_originorg",
"qeug_material",
"qeug_entryorg",
"qeug_rowclosestatus",
"qeug_rowterminatestatus",
"qeug_entrycomment",
"qeug_entrycreator",
"qeug_entrycreatetime",
"qeug_entrymodifier",
"qeug_entrymodifytime",
"qeug_reqsource",
"qeug_srcbillentity",
"qeug_srcbillid",
"qeug_srcbillnumber",
"qeug_srcbillentryid",
"qeug_srcbillentryseq",
"qeug_propurqty",
"qeug_propurbaseqty",
"qeug_unionsumqty",
"qeug_unionsumbaseqty",
"qeug_sumqty",
"qeug_sumbaseqty",
"qeug_applyqty",
"qeug_applybaseqty",
"qeug_promatqty",
"qeug_promatbaseqty",
"qeug_matapplyqty",
"qeug_matapplybaseqty",
"qeug_matoutqty",
"qeug_matoutbaseqty",
"qeug_protranqty",
"qeug_protranbaseqty",
"qeug_balancestatus",
"qeug_project_info",
"qeug_quantities",
"qeug_added_tax",
"qeug_exctax_price",
"qeug_added_taxamount",
"qeug_price_includetax",
"qeug_totalprice_tax",
"qeug_labor_cost",
"qeug_auxmaterial_cost",
"qeug_mainma_price",
"qeug_mainma_brand",
"qeug_mainma_consum",
"qeug_mainma_unit",
"qeug_mainma_cost",
"qeug_equipment_costs",
"qeug_omnibus_fee",
"qeug_linetype_id",
"qeug_materialmasterid_id",
"qeug_materialversion_id",
"qeug_auxpty_id",
"qeug_unit_id",
"qeug_baseunit_id",
"qeug_auxunit_id",
"qeug_entrybizorg_id",
"qeug_project_id",
"qeug_supplier_id",
"qeug_originorg_id",
"qeug_material_id",
"qeug_entryorg_id",
"qeug_entrycreator_id",
"qeug_entrymodifier_id"};
@Override
public void beforeDoOperation(BeforeDoOperationEventArgs args) {
super.beforeDoOperation(args);
FormOperate operate = (FormOperate) args.getSource();
String operateKey = operate.getOperateKey();
if ("importpurchase".equals(operateKey)) {
//showPurchaseApplyBill("purchase");
} else if ("importpurchase2".equals(operateKey)) {
if ("importpurchase2".equals(operateKey)) {
showPurchaseApplyBill("purchase2");
}
//增行时检查是否选择了采购项目
if (StringUtils.equals(operateKey, "newprojectentry")) {
DynamicObject qeugRenovationProj = (DynamicObject) this.getModel().getValue("qeug_renovation_proj");
if (null == qeugRenovationProj) {
this.getView().showTipNotification(ResManager.loadKDString("请先选择采购项目", "BidPurPlanEditUI_12", "repc-rebm-formplugin", new Object[0]));
args.setCancel(true);
}
// else {
// //存在项目,携带到明细
// int index = this.getModel().createNewEntryRow("projectentry");
// this.getModel().setValue("purentryproject", qeugRenovationProj, index);
// }
}
}
/**
* 去重展示采购需求单
* @param actionId 操作标识
*/
private void showPurchaseApplyBill(String actionId) {
ListShowParameter listShowParameter = ShowFormHelper.createShowListForm("qeug_purchaseapplybill", true);
ListShowParameter listShowParameter = ShowFormHelper.createShowListForm("recon_settleplanbill", true);
listShowParameter.setFormId("bos_listf7");
listShowParameter.getOpenStyle().setShowType(ShowType.Modal);
listShowParameter.setCloseCallBack(new CloseCallBack(this, actionId));
if ("purchase2".equals(actionId)) {
IDataModel model = this.getModel();
List<Long> ids = new ArrayList<>();
DynamicObjectCollection bidSections = model.getEntryEntity("bidsection");
DynamicObjectCollection bidSections = model.getEntryEntity("bidsection");//标段
if (bidSections != null) {
for (DynamicObject bidSection : bidSections) {
DynamicObjectCollection projectEntries = bidSection.getDynamicObjectCollection("projectentry");
DynamicObjectCollection projectEntries = bidSection.getDynamicObjectCollection("projectentry");//采购明细
if (projectEntries != null) {
for (DynamicObject projectEntry : projectEntries) {
long id = projectEntry.getLong("qeug_purentry_id");
@ -153,44 +132,23 @@ public class ImportPurchaseApplyBillPlugin extends AbstractBillPlugIn implements
}
if (!ids.isEmpty()) {
listShowParameter.getListFilterParameter().getQFilters().add(new QFilter("qeug_entryentity.id", QCP.not_in, ids));
listShowParameter.getListFilterParameter().getQFilters().add(new QFilter("qeug_cgxqentry.id", QCP.not_in, ids));
}
}
}
this.getView().showForm(listShowParameter);
}
/**
* 反写页面子单据体
*/
@Override
public void closedCallBack(ClosedCallBackEvent closedCallBackEvent) {
super.closedCallBack(closedCallBackEvent);
String actionId = closedCallBackEvent.getActionId();
if ("purchase".equals(actionId)) {
IDataModel model = this.getModel();
ListSelectedRowCollection selectedRows = (ListSelectedRowCollection) closedCallBackEvent.getReturnData();
if (selectedRows != null && !selectedRows.isEmpty()) {
for (ListSelectedRow selectedRow : selectedRows) {
Object keyValue = selectedRow.getPrimaryKeyValue();
int rowKey = selectedRow.getRowKey();
DynamicObject purchase = BusinessDataServiceHelper.loadSingle(keyValue, "qeug_purchaseapplybill");
DynamicObjectCollection entryEntities = purchase.getDynamicObjectCollection("qeug_entryentity");// 明细
DynamicObject entry = entryEntities.get(rowKey);
int index = model.createNewEntryRow("entryentity");
for (String field : fields) {
model.setValue(field, entry.get(field), index);
}
model.setValue("planname", entry.get("qeug_materialname"), index);
DynamicObject project = entry.getDynamicObject("qeug_project");
if (project != null) {
QFilter projectQF = new QFilter("number", QCP.equals, project.getString("number"));
DynamicObject dynamicObject = BusinessDataServiceHelper.loadSingle("rebm_purproject", projectQF.toArray());
model.setValue("purentryproject", dynamicObject, index);
}
}
}
} else if ("purchase2".equals(actionId)) {
if ("purchase2".equals(actionId)) {
IDataModel model = this.getModel();
//获取采购需求id
ListSelectedRowCollection selectedRows = (ListSelectedRowCollection) closedCallBackEvent.getReturnData();
if (selectedRows != null && !selectedRows.isEmpty()) {
HashMap<Long, ArrayList<Long>> ids = new HashMap<>();
@ -213,27 +171,24 @@ public class ImportPurchaseApplyBillPlugin extends AbstractBillPlugIn implements
Set<Long> billIds = ids.keySet();
for (Long billId : billIds) {
DynamicObject dynamicObject = BusinessDataServiceHelper.loadSingle(billId, "qeug_purchaseapplybill");
DynamicObjectCollection entries = dynamicObject.getDynamicObjectCollection("qeug_entryentity");
DynamicObject dynamicObject = BusinessDataServiceHelper.loadSingle(billId, "recon_settleplanbill");//采购需求
DynamicObject project = dynamicObject.getDynamicObject("qeug_renovation_proj");//项目
DynamicObjectCollection entries = dynamicObject.getDynamicObjectCollection("qeug_cgxqentry");
for (DynamicObject entry : entries) {
long entryId = entry.getLong("id");
ArrayList<Long> entryIds = ids.get(billId);
if (entryIds.contains(entryId)) {
int index = model.createNewEntryRow("projectentry");
model.setValue("qeug_purentry_id", entryId, index);
model.setValue("qeug_purxq_id", billId, index);//需求id
model.setValue("qeug_purentry_id", entryId, index);//分录id
model.setValue("purentrycontent", entry.get("qeug_materialname"), index);// 物料名称
model.setValue("qeug_qty", entry.get("qeug_qty"), index);// 数量
model.setValue("qeug_unit", entry.get("qeug_unit"), index);// 单位
DynamicObject project = entry.getDynamicObject("qeug_project");// 项目
if (project != null) {
QFilter projectQF = new QFilter("number", QCP.equals, project.getString("number"));
DynamicObject purproject = BusinessDataServiceHelper.loadSingle("rebm_purproject", projectQF.toArray());
model.setValue("purentryproject", purproject, index);
}
// model.setValue("qeug_qty", entry.get("qeug_qty"), index);// 数量
model.setValue("purentryproject", project, index);// 项目
}
}
}
}
}
}
}

View File

@ -0,0 +1,65 @@
package shkd.repc.rebm.formplugin;
import kd.bos.dataentity.entity.DynamicObject;
import kd.bos.entity.datamodel.events.PropertyChangedArgs;
import kd.bos.form.plugin.AbstractFormPlugin;
import kd.bos.orm.query.QCP;
import kd.bos.orm.query.QFilter;
import kd.bos.servicehelper.BusinessDataServiceHelper;
import java.util.EventObject;
/**
* 采购需求
* qeug_recon_settleplan_ext
*/
public class PurDemandFormPlugin extends AbstractFormPlugin {
@Override
public void afterBindData(EventObject e) {
super.afterBindData(e);
//根据组织携带项目
updateRenovationProject();
}
@Override
public void propertyChanged(PropertyChangedArgs e) {
super.propertyChanged(e);
String name = e.getProperty().getName();
//根据组织携带项目
if ("org".equals(name)) {
updateRenovationProject();
}
}
private void updateRenovationProject() {
DynamicObject org = (DynamicObject) this.getModel().getValue("org");
DynamicObject qeugRenovationProj = (DynamicObject) this.getModel().getValue("qeug_renovation_proj");
// 只有在需求组织不为空的情况下才进行查询
if (org != null) {
if (qeugRenovationProj == null) {
setRenovationProjectByOrg(org);
} else {
// 如果已存在项目字段且组织发生了变化需更新
setRenovationProjectByOrg(org);
}
} else {
// 组织为空清空项目
this.getModel().setValue("qeug_renovation_proj", null);
this.getView().updateView("qeug_renovation_proj");
}
}
private void setRenovationProjectByOrg(DynamicObject org) {
//采购项目
DynamicObject[] projectbills = BusinessDataServiceHelper.load("rebm_purproject", "id",
new QFilter[]{new QFilter("org.id", QCP.equals, org.getPkValue())});
if (projectbills.length > 0) {
DynamicObject projectbill = projectbills[0];
this.getModel().setValue("qeug_renovation_proj", projectbill);
this.getView().updateView("qeug_renovation_proj");
}
}
}

View File

@ -5,6 +5,7 @@ import kd.bos.bill.BillShowParameter;
import kd.bos.bill.OperationStatus;
import kd.bos.dataentity.entity.DynamicObject;
import kd.bos.dataentity.entity.DynamicObjectCollection;
import kd.bos.entity.datamodel.events.PropertyChangedArgs;
import kd.bos.form.ShowType;
import kd.bos.form.control.EntryGrid;
import kd.bos.form.events.HyperLinkClickEvent;
@ -54,4 +55,51 @@ public class PurPlanFormPlugin extends AbstractBillPlugIn implements HyperLinkCl
}
}
}
@Override
public void afterBindData(EventObject e) {
super.afterBindData(e);
//根据组织携带项目
updateRenovationProject();
}
@Override
public void propertyChanged(PropertyChangedArgs e) {
super.propertyChanged(e);
String name = e.getProperty().getName();
//根据组织携带项目
if ("org".equals(name)) {
updateRenovationProject();
}
}
private void updateRenovationProject() {
DynamicObject org = (DynamicObject) this.getModel().getValue("org");
DynamicObject purproject = (DynamicObject) this.getModel().getValue("purproject");
// 只有在需求组织不为空的情况下才进行查询
if (org != null) {
if (purproject == null) {
setRenovationProjectByOrg(org);
} else {
// 如果已存在项目字段且组织发生了变化需更新
setRenovationProjectByOrg(org);
}
} else {
// 组织为空清空项目
this.getModel().setValue("purproject", null);
this.getView().updateView("purproject");
}
}
private void setRenovationProjectByOrg(DynamicObject org) {
//采购项目
DynamicObject[] projectbills = BusinessDataServiceHelper.load("rebm_purproject", "id",
new QFilter[]{new QFilter("org.id", QCP.equals, org.getPkValue())});
if (projectbills.length > 0) {
DynamicObject projectbill = projectbills[0];
this.getModel().setValue("purproject", projectbill);
this.getView().updateView("purproject");
}
}
}

View File

@ -0,0 +1,42 @@
package shkd.repc.rebm.opplugin;
import kd.bos.dataentity.entity.DynamicObject;
import kd.bos.dataentity.entity.DynamicObjectCollection;
import kd.bos.entity.ExtendedDataEntity;
import kd.bos.entity.plugin.AbstractOperationServicePlugIn;
import kd.bos.entity.plugin.AddValidatorsEventArgs;
import kd.bos.entity.validate.AbstractValidator;
import kd.bos.logging.Log;
import kd.bos.logging.LogFactory;
public class PurPlanSubmitOPPlugin extends AbstractOperationServicePlugIn {
private static final Log logger = LogFactory.getLog(PurPlanSubmitOPPlugin.class);
@Override
public void onAddValidators(AddValidatorsEventArgs e) {
super.onAddValidators(e);
e.addValidator(new AbstractValidator() {
@Override
public void validate() {
String operateKey = this.getOperateKey();
ExtendedDataEntity[] dataEntities1 = this.getDataEntities();
switch (operateKey) {
case "submit":
for (ExtendedDataEntity extendedDataEntity : dataEntities1) {
//采购需求明细
DynamicObject dataEntity = extendedDataEntity.getDataEntity();
DynamicObjectCollection cgxuentry = dataEntity.getDynamicObjectCollection("qeug_cgxuentryss");
if (cgxuentry.isEmpty()) {
this.addErrorMessage(extendedDataEntity, "采购需求明细不能为空,不允许提交。");
}
}
break;
default:
break;
}
}
});
}
}

View File

@ -4,10 +4,11 @@ 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.servicehelper.operation.SaveServiceHelper;
/**
* 采购需求单
* qeug_purchaseapplybill
* qeug_recon_settleplan_ext
*/
public class PurapplyAuditOPPlugin extends AbstractOperationServicePlugIn {
@ -15,15 +16,15 @@ public class PurapplyAuditOPPlugin extends AbstractOperationServicePlugIn {
public void afterExecuteOperationTransaction(AfterOperationArgs e) {
super.afterExecuteOperationTransaction(e);
String operationKey = e.getOperationKey();
if ("audit".equals(operationKey)) {
if ("audit1".equals(operationKey)) {
DynamicObject[] dataEntities = e.getDataEntities();
DynamicObject dataEntity = dataEntities[0];
DynamicObjectCollection collection = dataEntity.getDynamicObjectCollection("qeug_entryentity");
DynamicObjectCollection collection = dataEntity.getDynamicObjectCollection("qeug_cgxqentry");
if (collection.isEmpty()) {
DynamicObject add = collection.addNew();
// add.set("",);
add.set("qeug_reqdes","本次采购需求未填写明细");
}
SaveServiceHelper.save(new DynamicObject[]{dataEntity});
}
}