From e04af0f28750098a16faa9b105163bec1e616b36 Mon Sep 17 00:00:00 2001 From: xuhaihui <2098865055@qq.com> Date: Fri, 29 Aug 2025 13:56:09 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../form/MaterialOutBillEditPluginExt.java | 1182 ++++++++++++++++- .../pr/plugin/form/PoundAutoFetchBizExt2.java | 272 ++++ 2 files changed, 1446 insertions(+), 8 deletions(-) create mode 100644 code/zcdev/zcgj-zcdev-zcdev-pr/src/main/java/zcgj/zcdev/zcdev/pr/plugin/form/PoundAutoFetchBizExt2.java diff --git a/code/zcdev/zcgj-zcdev-zcdev-pr/src/main/java/zcgj/zcdev/zcdev/pr/plugin/form/MaterialOutBillEditPluginExt.java b/code/zcdev/zcgj-zcdev-zcdev-pr/src/main/java/zcgj/zcdev/zcdev/pr/plugin/form/MaterialOutBillEditPluginExt.java index 49e36e0..f9699a3 100644 --- a/code/zcdev/zcgj-zcdev-zcdev-pr/src/main/java/zcgj/zcdev/zcdev/pr/plugin/form/MaterialOutBillEditPluginExt.java +++ b/code/zcdev/zcgj-zcdev-zcdev-pr/src/main/java/zcgj/zcdev/zcdev/pr/plugin/form/MaterialOutBillEditPluginExt.java @@ -1,24 +1,126 @@ +// +// Source code recreated from a .class file by IntelliJ IDEA +// (powered by FernFlower decompiler) +// + package zcgj.zcdev.zcdev.pr.plugin.form; +import com.google.common.collect.Sets; + +import java.math.BigDecimal; +import java.util.ArrayList; +import java.util.Calendar; +import java.util.Date; +import java.util.EventObject; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +import kd.bos.bill.BillShowParameter; import kd.bos.dataentity.entity.DynamicObject; import kd.bos.dataentity.entity.DynamicObjectCollection; import kd.bos.dataentity.entity.LocaleString; +import kd.bos.dataentity.resource.ResManager; +import kd.bos.dataentity.utils.StringUtils; +import kd.bos.entity.EntityMetadataCache; +import kd.bos.entity.datamodel.events.ChangeData; +import kd.bos.entity.datamodel.events.PropertyChangedArgs; +import kd.bos.form.CloseCallBack; +import kd.bos.form.FormShowParameter; +import kd.bos.form.ShowType; +import kd.bos.form.control.EntryGrid; +import kd.bos.form.events.AfterDoOperationEventArgs; +import kd.bos.form.events.BeforeDoOperationEventArgs; +import kd.bos.form.events.ClosedCallBackEvent; +import kd.bos.form.events.HyperLinkClickEvent; +import kd.bos.form.events.HyperLinkClickListener; import kd.bos.form.field.BasedataEdit; import kd.bos.form.field.ComboEdit; import kd.bos.form.field.ComboItem; -import kd.ec.material.formplugin.MaterialOutBillEditPlugin; - -import java.util.ArrayList; -import java.util.EventObject; -import java.util.Iterator; +import kd.bos.form.field.FieldEdit; +import kd.bos.form.field.events.BeforeF7SelectEvent; +import kd.bos.form.field.events.BeforeF7SelectListener; +import kd.bos.form.operate.FormOperate; +import kd.bos.list.ListShowParameter; +import kd.bos.orm.ORM; +import kd.bos.orm.query.QFilter; +import kd.bos.servicehelper.BusinessDataServiceHelper; +import kd.bos.servicehelper.QueryServiceHelper; +import kd.bos.servicehelper.operation.SaveServiceHelper; +import kd.ec.basedata.common.utils.ContractHelper; +import kd.ec.basedata.common.utils.CurrencyHelper; +import kd.ec.basedata.common.utils.OpenPageUtils; +import kd.ec.contract.common.enums.PayDirectionEnum; +import kd.ec.contract.common.utils.EcNumberHelper; +import kd.ec.material.common.enums.PoundTransTypeEnum; +import kd.ec.material.common.enums.TransTypeEnum; +import kd.ec.material.formplugin.AbstractEcmaBillPlugin; +import kd.ec.material.formplugin.materialout.PoundAutoFetchBiz; +import kd.ec.material.utils.UnitProjectUtil; /** * 出库单扩展系统代码:修改领料人必填逻辑 */ -public class MaterialOutBillEditPluginExt extends MaterialOutBillEditPlugin { +public class MaterialOutBillEditPluginExt extends AbstractEcmaBillPlugin implements BeforeF7SelectListener, HyperLinkClickListener { + private static final String PROJECT = "project"; + private static final String EC_PROJECT = "ec_project"; + private static final String DO_SAVE = "save"; + private static final String DO_NEW = "new"; + private static final String DO_POUND_FETCH = "poundfetch"; + public MaterialOutBillEditPluginExt() { } + public void registerListener(EventObject e) { + super.registerListener(e); + BasedataEdit contract = (BasedataEdit) this.getControl("contract"); + contract.addBeforeF7SelectListener(this); + BasedataEdit supplier = (BasedataEdit) this.getControl("supplier"); + supplier.addBeforeF7SelectListener(this); + BasedataEdit labour = (BasedataEdit) this.getControl("labour"); + labour.addBeforeF7SelectListener(this); + BasedataEdit requestPerson = (BasedataEdit) this.getControl("requestperson"); + requestPerson.addBeforeF7SelectListener(this); + BasedataEdit warehouse = (BasedataEdit) this.getControl("warehouse"); + warehouse.addBeforeF7SelectListener(this); + BasedataEdit material = (BasedataEdit) this.getControl("material"); + material.addBeforeF7SelectListener(this); + BasedataEdit cbs = (BasedataEdit) this.getControl("procbs"); + cbs.addBeforeF7SelectListener(this); + BasedataEdit boq = (BasedataEdit) this.getControl("proboq"); + boq.addBeforeF7SelectListener(this); + BasedataEdit ca = (BasedataEdit) this.getControl("ca"); + ca.addBeforeF7SelectListener(this); + BasedataEdit wbs = (BasedataEdit) this.getControl("prowbs"); + wbs.addBeforeF7SelectListener(this); + BasedataEdit batch = (BasedataEdit) this.getControl("lotid"); + batch.addBeforeF7SelectListener(this); + BasedataEdit unitProjectNew = (BasedataEdit) this.getControl("unitprojectpro"); + unitProjectNew.addBeforeF7SelectListener(this); + BasedataEdit applyBill = (BasedataEdit) this.getControl("applybill"); + applyBill.addBeforeF7SelectListener(this); + BasedataEdit proj = (BasedataEdit) this.getView().getControl("project"); + if (proj != null) { + proj.addBeforeF7ViewDetailListener((beforeF7ViewDetailEvent) -> { + beforeF7ViewDetailEvent.setCancel(true); + this.getView().showForm(OpenPageUtils.buildBillShowParam(beforeF7ViewDetailEvent.getPkId(), "ec_project")); + }); + proj.addBeforeF7SelectListener(this); + } + + BasedataEdit transType = (BasedataEdit) this.getView().getControl("transtype"); + if (transType != null) { + transType.addBeforeF7SelectListener(this); + } + + EntryGrid materialInEntry = (EntryGrid) this.getControl("entryentity"); + if (materialInEntry != null) { + materialInEntry.addHyperClickListener(this); + } + + } + public void afterBindData(EventObject e) { super.afterBindData(e); DynamicObject labour = (DynamicObject) this.getModel().getValue("labour"); @@ -28,6 +130,562 @@ public class MaterialOutBillEditPluginExt extends MaterialOutBillEditPlugin { this.setMustInputByCostType((String) this.getModel().getValue("costtype")); } + protected void setProjectAndUnitProEable() { + DynamicObject wareHouse = this.getModel().getDataEntity().getDynamicObject("warehouse"); + if (wareHouse != null) { + DynamicObject warePro = wareHouse.getDynamicObject("project"); + if (warePro != null) { + this.getView().setEnable(false, new String[]{"project"}); + } else { + this.getView().setEnable(true, new String[]{"project"}); + } + + DynamicObject unitProject = wareHouse.getDynamicObject("unitproject"); + if (unitProject != null) { + this.getView().setEnable(false, new String[]{"unitprojectpro"}); + } else { + this.getView().setEnable(true, new String[]{"unitprojectpro"}); + } + } + + } + + public void afterCreateNewData(EventObject arg0) { + super.afterCreateNewData(arg0); + Map customParams = this.getView().getFormShowParameter().getCustomParams(); + Object projectId = customParams.get("projectId"); + if (projectId != null) { + DynamicObject project = BusinessDataServiceHelper.loadSingle(projectId, "ec_project"); + DynamicObject org = project.getDynamicObject("org"); + this.getModel().setValue("project", project.getPkValue()); + this.getModel().setValue("org", org.getPkValue()); + } + + Calendar now = Calendar.getInstance(); + int year = now.get(1); + int month = now.get(2) + 1; + QFilter qFilter = new QFilter("periodyear", "=", year); + qFilter.and(new QFilter("periodnumber", "=", month)); + DynamicObject[] periods = BusinessDataServiceHelper.load("bd_period", "periodyear,periodquarter", new QFilter[]{qFilter}); + if (periods != null && periods.length > 0) { + this.getModel().setValue("period", periods[0].getPkValue()); + } + + this.getModel().setValue("bizdate", new Date()); + } + + public void beforeBindData(EventObject e) { + super.beforeBindData(e); + Boolean poundOut = (Boolean) this.getModel().getValue("poundout"); + this.changeViewSetForPound(poundOut); + if (poundOut) { + this.onWarehouseChanged(); + } + + } + + public void beforeDoOperation(BeforeDoOperationEventArgs args) { + super.beforeDoOperation(args); + FormOperate source = (FormOperate) args.getSource(); + switch (source.getOperateKey()) { + case "save": + this.beforeDoSave(args); + break; + case "poundfetch": + this.beforeDoPoundFetch(args); + } + + } + + protected void beforeDoPoundFetch(BeforeDoOperationEventArgs args) { +// (new PoundAutoFetchBiz(this)).doFetchPound(args);//原系统代码 + (new PoundAutoFetchBizExt2(this)).doFetchPound(args);//二开替代 + } + + protected void beforeDoSave(BeforeDoOperationEventArgs args) { + int count = this.getModel().getEntryRowCount("entryentity"); + DynamicObject obj = null; + DynamicObject lotObj = null; + String lotNum = ""; + String modelnum = ""; + ArrayList addLotList = new ArrayList(); + DynamicObject addObj = null; + DynamicObject material = null; + ORM orm = ORM.create(); + Map rowLotMap = new HashMap(); + + for (int i = 0; i < count; ++i) { + obj = this.getModel().getEntryRowEntity("entryentity", i); + lotNum = obj.getString("lot"); + lotObj = obj.getDynamicObject("lotid"); + material = obj.getDynamicObject("material"); + modelnum = obj.getString("modelnum"); + if (StringUtils.isNotEmpty(lotNum.trim()) && (lotObj == null || !lotNum.equals(lotObj.getString("number")))) { + QFilter filter = new QFilter("number", "=", lotNum); + filter.and(new QFilter("material.id", "=", material.getPkValue())); + boolean exists = QueryServiceHelper.exists("ecma_material_lot", new QFilter[]{filter}); + if (exists) { + this.getView().showTipNotification(String.format(ResManager.loadKDString("物料-%1$s,编号:%2$s已经存在,请重新填写批号。", "MaterialOutBillEditPlugin_7", "ec-ecma-formplugin", new Object[0]), material.get("name"), lotNum)); + args.setCancel(true); + return; + } + + addObj = new DynamicObject(EntityMetadataCache.getDataEntityType("ecma_material_lot")); + addObj.set("number", lotNum); + addObj.set("material", material); + addObj.set("modelnum", modelnum); + addLotList.add(addObj); + rowLotMap.put(i, addObj); + } + } + + Iterator var18 = rowLotMap.entrySet().iterator(); + + while (var18.hasNext()) { + Map.Entry entry = (Map.Entry) var18.next(); + Integer row = (Integer) entry.getKey(); + DynamicObject lot = (DynamicObject) entry.getValue(); + long genLotId = orm.genLongId("ecma_material_lot"); + lot.set("id", genLotId); + this.getModel().setValue("lotid", lot, row); + } + + SaveServiceHelper.save((DynamicObject[]) addLotList.toArray(new DynamicObject[addLotList.size()])); + } + + public void propertyChanged(PropertyChangedArgs e) { + super.propertyChanged(e); + switch (e.getProperty().getName()) { + case "project": + this.onProjectChanged(); + break; + case "contract": + this.onContractChanged(); + break; + case "supplier": + this.onSupplierChanged(e.getChangeSet()[0]); + break; + case "transtype": + this.onTranstypeChanged(); + break; + case "labour": + this.onLabourChanged(); + break; + case "amount": + this.onAmountChanged(); + break; + case "settleamount": + this.onSettleAmountChanged(); + break; + case "warehouse": + this.getModel().deleteEntryData("entryentity"); + this.onWarehouseChanged(); + break; + case "costtype": + String costType = (String) this.getModel().getValue("costtype"); + this.onCostTypeChanged(costType); + break; + case "isbasemateriel": + this.onIsBaseMaterielChanged(); + break; + case "material": + this.onMaterielChanged(e); + break; + case "lotid": + this.onBatchIdChanged(e); + break; + case "qty": + this.onQtyChanged(e); + break; + case "assqty": + this.onAssQtyChanged(e); + break; + case "measureunit": + this.onMeasureunitChanged(e); + break; + case "assmeasureunit": + this.onAssMeasureunitChanged(e); + break; + case "price": + this.onPriceChanged(e); + break; + case "proboq": + this.onProBoqChanged(e); + break; + case "unitprojectpro": + this.onUnitProjectNewChanged(e); + break; + case "poundout": + this.onPoundOutChanged(e); + break; + case "applybill": + this.onApplyBillChanged(e); + } + + } + + protected void onApplyBillChanged(PropertyChangedArgs e) { + DynamicObject applyBill = (DynamicObject) this.getModel().getValue("applybill"); + Boolean isBaseMat = (Boolean) this.getModel().getValue("isbasemateriel"); + if (applyBill != null && isBaseMat) { + this.getModel().setValue("isbasemateriel", false); + } + + this.setCosttype(applyBill); + } + + protected void setCosttype(DynamicObject applyBill) { + if (applyBill != null) { + this.getModel().setValue("costtype", applyBill.get("costtype")); + this.getView().setEnable(false, new String[]{"costtype"}); + } else { + this.getModel().setValue("costtype", (Object) null); + this.getView().setEnable(true, new String[]{"costtype"}); + } + + } + + protected void onPoundOutChanged(PropertyChangedArgs e) { + Boolean poundOut = (Boolean) this.getModel().getValue("poundout"); + this.changeViewSetForPound(poundOut); + this.getModel().deleteEntryData("entryentity"); + Long defaultTransType = poundOut ? PoundTransTypeEnum.POUND_OUT.getDefaultId() : null; + this.getModel().setValue("transtype", defaultTransType); + } + + protected void changeViewSetForPound(boolean poundOutOn) { + this.getView().setVisible(poundOutOn, new String[]{"poundfetch", "poundno"}); + this.getView().setEnable(!poundOutOn, new String[]{"newentry", "isbasemateriel", "applybill"}); + this.getView().setEnable(!poundOutOn, new String[]{"material", "qty"}); + } + + protected void onSupplierChanged(ChangeData changeData) { + DynamicObject supplier = (DynamicObject) changeData.getNewValue(); + DynamicObject labour = this.getModel().getDataEntity().getDynamicObject("labour"); + if (labour != null) { + DynamicObject labourSupplier = labour.getDynamicObject("supplier"); + if (labourSupplier != null && supplier != null && !labourSupplier.getPkValue().equals(supplier.getPkValue())) { + this.getModel().setValue("labour", (Object) null); + } + } + + } + + protected void onUnitProjectChanged(PropertyChangedArgs e) { + int rowIndex = e.getChangeSet()[0].getRowIndex(); + this.getModel().setValue("proboq", (Object) null, rowIndex); + } + + protected void onUnitProjectNewChanged(PropertyChangedArgs e) { + DynamicObjectCollection entryEntity = this.getModel().getEntryEntity("entryentity"); + if (entryEntity != null) { + for (int i = 0; i < entryEntity.getRowCount(); ++i) { + this.getModel().setValue("proboq", (Object) null, i); + } + + } + } + + protected void onProBoqChanged(PropertyChangedArgs e) { + DynamicObject proBoq = (DynamicObject) e.getChangeSet()[0].getNewValue(); + int rowIndex = e.getChangeSet()[0].getRowIndex(); + DynamicObject unitPro = (DynamicObject) this.getModel().getValue("unitproject", rowIndex); + if (proBoq != null && unitPro == null) { + DynamicObject unitproject = proBoq.getDynamicObject("unitproject"); + if (unitproject != null) { + this.getModel().beginInit(); + this.getModel().setValue("unitprojectpro", unitproject.getPkValue()); + this.getModel().endInit(); + this.getView().updateView("unitprojectpro"); + } + } + + } + + protected void onTranstypeChanged() { + DynamicObject value = (DynamicObject) this.getModel().getValue("transtype"); + boolean impactcost = value != null && value.getBoolean("impactcost"); + BasedataEdit projectControl = (BasedataEdit) this.getControl("project"); + projectControl.setMustInput(impactcost); + int entryRowCount = this.getModel().getEntryRowCount("entryentity"); + + for (int i = 0; i < entryRowCount; ++i) { + this.getModel().setValue("ismainmaterial", impactcost, i); + } + + } + + protected void onWarehouseChanged() { + DynamicObject wareHouse = this.getModel().getDataEntity().getDynamicObject("warehouse"); + if (wareHouse != null) { + DynamicObject warePro = wareHouse.getDynamicObject("project"); + if (warePro != null) { + this.getModel().beginInit(); + this.getModel().setValue("project", warePro.getPkValue()); + this.getModel().endInit(); + this.getView().setEnable(false, new String[]{"project"}); + this.getView().updateView("project"); + } else { + this.getView().setEnable(true, new String[]{"project"}); + this.setUnitProject(); + } + + DynamicObject unitProject = wareHouse.getDynamicObject("unitproject"); + if (unitProject != null) { + this.getModel().setValue("unitprojectpro", unitProject.getPkValue()); + this.getView().setEnable(false, new String[]{"unitprojectpro"}); + this.getView().updateView("unitprojectpro"); + } else { + this.getModel().setValue("unitprojectpro", (Object) null); + this.setUnitProject(); + } + } else if (wareHouse == null) { + this.getView().setEnable(true, new String[]{"project"}); + this.getModel().setValue("unitprojectpro", (Object) null); + this.setUnitProject(); + } + + } + + protected void onPriceChanged(PropertyChangedArgs e) { + String costType = (String) this.getModel().getValue("costtype"); + if ("b".equals(costType)) { + int rowIndex = e.getChangeSet()[0].getRowIndex(); + BigDecimal price = (BigDecimal) this.getModel().getValue("price", rowIndex); + if (price != null && !price.equals(BigDecimal.ZERO)) { + this.getModel().setValue("settleprice", price, rowIndex); + } + } + + } + + protected void onAssMeasureunitChanged(PropertyChangedArgs e) { + DynamicObject assMeasureunit = (DynamicObject) e.getChangeSet()[0].getNewValue(); + int rowIndex = e.getChangeSet()[0].getRowIndex(); + BigDecimal qty = (BigDecimal) this.getModel().getValue("qty", rowIndex); + DynamicObject measureunit = (DynamicObject) this.getModel().getValue("measureunit", rowIndex); + if (measureunit != null && assMeasureunit != null && qty != null && qty.compareTo(BigDecimal.ZERO) != 0) { + this.qtyAutoConvert(qty, rowIndex, measureunit, assMeasureunit, "assqty"); + } + } + + protected void onMeasureunitChanged(PropertyChangedArgs e) { + DynamicObject measureunit = (DynamicObject) e.getChangeSet()[0].getNewValue(); + int rowIndex = e.getChangeSet()[0].getRowIndex(); + BigDecimal assQty = (BigDecimal) this.getModel().getValue("assqty", rowIndex); + DynamicObject assMeasureunit = (DynamicObject) this.getModel().getValue("assmeasureunit", rowIndex); + if (measureunit != null && assMeasureunit != null && assQty != null && assQty.compareTo(BigDecimal.ZERO) != 0) { + this.qtyAutoConvert(assQty, rowIndex, assMeasureunit, measureunit, "qty"); + } + } + + protected void onAssQtyChanged(PropertyChangedArgs e) { + BigDecimal assQty = (BigDecimal) e.getChangeSet()[0].getNewValue(); + int rowIndex = e.getChangeSet()[0].getRowIndex(); + DynamicObject measureunit = (DynamicObject) this.getModel().getValue("measureunit", rowIndex); + DynamicObject assMeasureunit = (DynamicObject) this.getModel().getValue("assmeasureunit", rowIndex); + if (measureunit != null && assMeasureunit != null) { + this.qtyAutoConvert(assQty, rowIndex, assMeasureunit, measureunit, "qty"); + } + } + + protected void onQtyChanged(PropertyChangedArgs e) { + BigDecimal qty = (BigDecimal) e.getChangeSet()[0].getNewValue(); + qty = qty == null ? BigDecimal.ZERO : qty; + int rowIndex = e.getChangeSet()[0].getRowIndex(); + Object applyBill = this.getModel().getValue("applybill"); + BigDecimal applyQty = (BigDecimal) this.getModel().getValue("applyqty", rowIndex); + applyQty = applyQty == null ? BigDecimal.ZERO : applyQty; + if (applyBill != null && qty.compareTo(applyQty) > 0) { + this.getView().showTipNotification(ResManager.loadKDString("“数量”不可超“申请数量”,请重新填写。", "MaterialOutBillEditPlugin_1", "ec-ecma-formplugin", new Object[0]), 3000); + this.getModel().setValue("qty", 0, rowIndex); + } else { + DynamicObject measureunit = (DynamicObject) this.getModel().getValue("measureunit", rowIndex); + DynamicObject assMeasureunit = (DynamicObject) this.getModel().getValue("assmeasureunit", rowIndex); + if (measureunit != null && assMeasureunit != null) { + this.qtyAutoConvert(qty, rowIndex, measureunit, assMeasureunit, "assqty"); + } + } + } + + protected void qtyAutoConvert(BigDecimal srcQty, int rowIndex, DynamicObject srcMeasureunit, DynamicObject desMeasureunit, String qtyEntityId) { + QFilter qFilter = new QFilter("srcmuid", "=", srcMeasureunit.getPkValue()); + qFilter.and(new QFilter("desmuid", "=", desMeasureunit.getPkValue())); + BigDecimal assQty = BigDecimal.ZERO; + DynamicObject[] measureunitConvs = BusinessDataServiceHelper.load("bd_measureunitconv", "srcmuid,desmuid,numerator,denominator", new QFilter[]{qFilter}); + if (measureunitConvs != null && measureunitConvs.length > 0) { + BigDecimal numerator = measureunitConvs[0].getBigDecimal("numerator"); + assQty = EcNumberHelper.multiply(srcQty, numerator, desMeasureunit.getInt("precision")); + } else { + QFilter qFilter2 = new QFilter("srcmuid", "=", desMeasureunit.getPkValue()); + qFilter2.and(new QFilter("desmuid", "=", srcMeasureunit.getPkValue())); + DynamicObject[] measureunitConvs2 = BusinessDataServiceHelper.load("bd_measureunitconv", "srcmuid,desmuid,numerator,denominator", new QFilter[]{qFilter2}); + if (measureunitConvs2 == null || measureunitConvs2.length <= 0) { + this.getView().showErrorNotification(ResManager.loadKDString("没有找到对应的换算率,无法换算,请确认或添加至换算表!", "MaterialOutBillEditPlugin_2", "ec-ecma-formplugin", new Object[0])); + return; + } + + BigDecimal numerator = measureunitConvs2[0].getBigDecimal("numerator"); + assQty = EcNumberHelper.divide(srcQty, numerator, desMeasureunit.getInt("precision")); + } + + this.getModel().setValue(qtyEntityId, assQty, rowIndex); + } + + protected void onBatchIdChanged(PropertyChangedArgs e) { + DynamicObject batchObj = (DynamicObject) e.getChangeSet()[0].getNewValue(); + int curIndex = e.getChangeSet()[0].getRowIndex(); + if (batchObj != null) { + this.getModel().setValue("lot", batchObj.getString("number"), curIndex); + } else { + this.getModel().setValue("lot", (Object) null, curIndex); + } + + } + + protected void onMaterielChanged(PropertyChangedArgs e) { + DynamicObject materiel = (DynamicObject) e.getChangeSet()[0].getNewValue(); + int rowIndex = e.getChangeSet()[0].getRowIndex(); + boolean isBaseMaterial = (Boolean) this.getModel().getValue("isbasemateriel"); + if (isBaseMaterial) { + if (materiel != null) { + String modelNum = materiel.getString("model"); + DynamicObject measureUnit = materiel.getDynamicObject("measureunit"); + measureUnit = BusinessDataServiceHelper.loadSingle(measureUnit.getString("id"), "bd_measureunits"); + this.getModel().setValue("modelnum", modelNum, rowIndex); + this.getModel().setValue("measureunit", measureUnit, rowIndex); + } else { + this.getModel().setValue("modelnum", (Object) null, rowIndex); + this.getModel().setValue("measureunit", (Object) null, rowIndex); + } + } + + if (materiel != null) { + this.getModel().setValue("procbs", (Object) null, rowIndex); + DynamicObject enterpriseCbs = materiel.getDynamicObject("cbs"); + if (enterpriseCbs != null) { + QFilter cbsFilter = new QFilter("enterprisecbs", "=", enterpriseCbs.getPkValue()); + cbsFilter.and(new QFilter("isleaf", "=", "1")); + DynamicObject project = (DynamicObject) this.getModel().getValue("project"); + if (project != null) { + cbsFilter.and(new QFilter("project", "=", project.getPkValue())); + } + + DynamicObject[] cbsArr = BusinessDataServiceHelper.load("ec_ecbd_pro_cbs", "number,name", new QFilter[]{cbsFilter}); + if (cbsArr != null && cbsArr.length > 0) { + this.getModel().setValue("procbs", cbsArr[0].getPkValue(), rowIndex); + } + } + } + + } + + protected void onIsBaseMaterielChanged() { + this.getModel().deleteEntryData("entryentity"); + } + + protected void onCostTypeChanged(String costType) { + int rowCount = this.getModel().getEntryRowCount("entryentity"); + + for (int i = 0; i < rowCount; ++i) { + this.getModel().setValue("settleprice", (Object) null, i); + this.getModel().setValue("settleamount", (Object) null, i); + this.getModel().setValue("ismainmaterial", true, i); + this.getModel().setValue("ca", (Object) null, i); + this.getModel().setValue("procbs", (Object) null, i); + this.getModel().setValue("prowbs", (Object) null, i); + this.getModel().setValue("proboq", (Object) null, i); + } + + this.getModel().setValue("supplier", (Object) null); + this.setMustInputByCostType(costType); + } + + protected void setMustInputByCostType(String costType) { + BasedataEdit contract = (BasedataEdit) this.getControl("contract"); + BasedataEdit labour = (BasedataEdit) this.getControl("labour"); + if (StringUtils.equals(costType, "b")) { + contract.setMustInput(true); + labour.setMustInput(true); + this.getView().setVisible(true, new String[]{"labour"}); + } else { + contract.setMustInput(false); + labour.setMustInput(false); + this.getModel().setValue("labour", (Object) null); + this.getView().setVisible(false, new String[]{"labour"}); + } + + } + + protected void onProjectChanged() { + DynamicObject project = this.getModel().getDataEntity().getDynamicObject("project"); + this.getModel().setValue("labour", (Object) null); + UnitProjectUtil.clearUnitProject(this.getView(), "unitprojectpro", "project"); + if (project != null) { + DynamicObject contract = this.getModel().getDataEntity().getDynamicObject("contract"); + if (contract != null) { + DynamicObject contractPro = contract.getDynamicObject("project"); + if (contractPro == null || !project.getPkValue().equals(contractPro.getPkValue())) { + this.getModel().setValue("contract", (Object) null); + } + + this.getModel().setValue("applybill", (Object) null); + } + } + } + + protected void onSettleAmountChanged() { + DynamicObjectCollection entryEntity = this.getModel().getEntryEntity("entryentity"); + BigDecimal totalAmount = new BigDecimal(0); + + BigDecimal amount; + for (Iterator var3 = entryEntity.iterator(); var3.hasNext(); totalAmount = totalAmount.add(amount)) { + DynamicObject entity = (DynamicObject) var3.next(); + amount = entity.getBigDecimal("settleamount"); + } + + this.getModel().setValue("settleamt", totalAmount); + } + + protected void onAmountChanged() { + this.sumOutAmount(); + } + + public void sumOutAmount() { + DynamicObjectCollection entryEntity = this.getModel().getEntryEntity("entryentity"); + BigDecimal totalAmount = new BigDecimal(0); + + BigDecimal amount; + for (Iterator var3 = entryEntity.iterator(); var3.hasNext(); totalAmount = totalAmount.add(amount)) { + DynamicObject entity = (DynamicObject) var3.next(); + amount = entity.getBigDecimal("amount"); + } + + this.getModel().setValue("outamt", totalAmount); + } + + protected void onLabourChanged() { + DynamicObject labour = (DynamicObject) this.getModel().getValue("labour"); + this.buildRequestPerson(labour); + this.getModel().setValue("reqpersonname", ""); + this.getModel().setValue("requestperson", (Object) null); + if (labour != null) { + DynamicObjectCollection personEntryEntitys = labour.getDynamicObjectCollection("entryentity"); + if (personEntryEntitys != null && personEntryEntitys.size() > 0) { + String team = labour.getString("team"); + DynamicObject personEntryEntity = (DynamicObject) personEntryEntitys.get(0); + if ("01".equals(team)) { + DynamicObject requestPerson = personEntryEntity.getDynamicObject("pickmaterials"); + this.getModel().setValue("requestperson", requestPerson.getPkValue()); + } else if ("02".equals(team)) { + String requestPerson = personEntryEntity.getString("pickmaterialsname"); + this.getModel().setValue("reqpersonname", requestPerson); + } + } + } + + } + protected void buildRequestPerson(DynamicObject labour) { BasedataEdit reqPersonF7; if (labour != null) { @@ -38,7 +696,7 @@ public class MaterialOutBillEditPluginExt extends MaterialOutBillEditPlugin { reqPersonCombo.setMustInput(false); BasedataEdit reqPersonF71 = (BasedataEdit) this.getControl("requestperson"); this.getView().setVisible(true, new String[]{"requestperson"}); -// reqPersonF71.setMustInput(true); + reqPersonF71.setMustInput(true); } else if ("02".equals(team)) { reqPersonF7 = (BasedataEdit) this.getControl("requestperson"); this.getView().setVisible(false, new String[]{"requestperson"}); @@ -72,8 +730,516 @@ public class MaterialOutBillEditPluginExt extends MaterialOutBillEditPlugin { reqPersonF7 = (BasedataEdit) this.getControl("requestperson"); this.getView().setVisible(true, new String[]{"requestperson"}); // reqPersonF7.setMustInput(true);//系统代码 - reqPersonF7.setMustInput(false);//二开系统代码 + reqPersonF7.setMustInput(false);//二开替代 } } + + protected void onContractChanged() { + Object supplierValue = this.getModel().getValue("supplier"); + DynamicObject projectSelect = (DynamicObject) this.getModel().getValue("project"); + DynamicObject contractF7 = (DynamicObject) this.getModel().getValue("contract"); + if (contractF7 == null) { + if (projectSelect == null) { + this.getModel().setValue("unitprojectpro", (Object) null); + this.setUnitProject(); + } + + } else { + DynamicObject contract = BusinessDataServiceHelper.loadSingle(contractF7.getPkValue(), "ec_out_contract"); + DynamicObject project = contract.getDynamicObject("project"); + if (project != null) { + this.getModel().setValue("project", project.getPkValue()); + } + + DynamicObject unitProject = contract.getDynamicObject("unitproject"); + if (unitProject != null) { + this.getModel().setValue("unitprojectpro", unitProject.getPkValue()); + this.getView().setEnable(false, new String[]{"unitprojectpro"}); + } + + if (supplierValue == null) { + DynamicObject supplier = contract.getDynamicObject("partb"); + this.getModel().setValue("supplier", supplier.getPkValue()); + } + + } + } + + public void beforeF7Select(BeforeF7SelectEvent arg0) { + String name = arg0.getProperty().getName(); + ListShowParameter formShowParameter = (ListShowParameter) arg0.getFormShowParameter(); + switch (name) { + case "contract": + this.beforeContractSelect(formShowParameter); + break; + case "supplier": + this.beforeSupplierSelect(formShowParameter); + break; + case "labour": + this.beforeLabourSelect(formShowParameter); + break; + case "requestperson": + this.beforeRequestpersonSelect(arg0, formShowParameter); + break; + case "warehouse": + this.beforeWarehouseSelect(formShowParameter, arg0); + break; + case "material": + this.beforeMaterielSelect(arg0); + break; + case "prowbs": + this.beforeWbsSelect(formShowParameter); + break; + case "ca": + this.beforeCaSelect(formShowParameter); + break; + case "proboq": + this.beforeBoqSelect(arg0, formShowParameter); + break; + case "procbs": + this.beforeCbsSelect(arg0, formShowParameter); + break; + case "lotid": + this.beforeBatchSelect(arg0, formShowParameter); + break; + case "unitprojectpro": + this.beforeUnitProjectNewSelect(arg0, formShowParameter); + break; + case "applybill": + this.beforeApplyBillSelect(arg0, formShowParameter); + break; + case "transtype": + this.beforeTransTypeF7Selected(arg0); + break; + case "project": + this.beforeProjectF7Selected(arg0); + } + + } + + protected void beforeProjectF7Selected(BeforeF7SelectEvent arg) { + ListShowParameter formShowParameter = (ListShowParameter) arg.getFormShowParameter(); + DynamicObject org = (DynamicObject) this.getModel().getValue("org"); + if (null != org) { + QFilter orgFilter = new QFilter("projectorg", "=", org.getPkValue()); + formShowParameter.getListFilterParameter().getQFilters().add(orgFilter); + } + + } + + protected void beforeTransTypeF7Selected(BeforeF7SelectEvent arg) { + ListShowParameter formShowParameter = (ListShowParameter) arg.getFormShowParameter(); + Boolean poundOut = (Boolean) this.getModel().getValue("poundout"); + QFilter numberFilter = new QFilter("id", "in", Sets.newHashSet(new Long[]{PoundTransTypeEnum.POUND_OUT.getDefaultId()})); + if (!poundOut) { + numberFilter = new QFilter("id", "not in", Sets.newHashSet(new Long[]{PoundTransTypeEnum.POUND_IN.getDefaultId(), PoundTransTypeEnum.POUND_OUT.getDefaultId(), PoundTransTypeEnum.POUND_IN_THEN_OUT.getDefaultId()})); + } + + formShowParameter.getListFilterParameter().getQFilters().add(numberFilter); + } + + protected void beforeUnitProjectSelect(BeforeF7SelectEvent arg0, ListShowParameter formShowParameter) { + DynamicObject project = (DynamicObject) this.getModel().getValue("project"); + DynamicObject contract = (DynamicObject) this.getModel().getValue("contract"); + if (project == null) { + this.getView().showTipNotification(ResManager.loadKDString("必须选择工程项目。", "MaterialOutBillEditPlugin_3", "ec-ecma-formplugin", new Object[0])); + arg0.setCancel(true); + } else { + List unitProIds = this.getContUnitProIds(contract); + if (unitProIds.size() < 1) { + unitProIds = this.getProUnitProIds(project); + } + + formShowParameter.getListFilterParameter().getQFilters().add(new QFilter("id", "in", unitProIds)); + } + } + + protected void beforeApplyBillSelect(BeforeF7SelectEvent arg0, ListShowParameter formShowParameter) { + DynamicObject unitProject = (DynamicObject) this.getModel().getValue("unitprojectpro"); + if (unitProject != null) { + formShowParameter.getListFilterParameter().getQFilters().add(new QFilter("unitprojectpro", "=", unitProject.getPkValue())); + } + + } + + protected void beforeUnitProjectNewSelect(BeforeF7SelectEvent arg0, ListShowParameter formShowParameter) { + DynamicObject org = (DynamicObject) this.getModel().getValue("org"); + Long orgId = (Long) org.getPkValue(); + DynamicObject project = (DynamicObject) this.getModel().getValue("project"); + if (project != null) { + QFilter projectFilter = new QFilter("parent", "=", project.getPkValue()); + formShowParameter.getListFilterParameter().getQFilters().add(projectFilter); + Long projectOrgId = (Long) project.getDynamicObject("org").getPkValue(); + if (!projectOrgId.equals(orgId)) { + QFilter orgFilter = new QFilter("responsibleorg", "=", org.getPkValue()); + formShowParameter.getListFilterParameter().getQFilters().add(orgFilter); + } + } + } + + protected List getProUnitProIds(DynamicObject project) { + List unitProIds = new ArrayList(); + if (project != null) { + project = BusinessDataServiceHelper.loadSingle(project.getPkValue(), "ec_project"); + DynamicObjectCollection proUnitPros = project.getDynamicObjectCollection("unitproject"); + Iterator var4 = proUnitPros.iterator(); + + while (var4.hasNext()) { + DynamicObject entry = (DynamicObject) var4.next(); + unitProIds.add(entry.getPkValue()); + } + } + + return unitProIds; + } + + protected List getContUnitProIds(DynamicObject contract) { + List unitProIds = new ArrayList(); + if (contract != null) { + contract = BusinessDataServiceHelper.loadSingle(contract.getPkValue(), "ec_out_contract"); + DynamicObject contUnitPro = contract.getDynamicObject("unitproject"); + if (contUnitPro != null) { + unitProIds.add(contUnitPro.getPkValue()); + } + + if (contract.getBoolean("isonlist")) { + QFilter filter = new QFilter("contractid", "=", contract.getPkValue()); + DynamicObject[] outContListings = BusinessDataServiceHelper.load("ec_outtreelisting", "id,listunitproject", new QFilter[]{filter}); + DynamicObject[] var6 = outContListings; + int var7 = outContListings.length; + + for (int var8 = 0; var8 < var7; ++var8) { + DynamicObject listing = var6[var8]; + DynamicObject contListUnitPro = listing.getDynamicObject("listunitproject"); + if (contListUnitPro != null) { + unitProIds.add(contListUnitPro.getPkValue()); + } + } + } + } + + return unitProIds; + } + + protected void beforeCaSelect(ListShowParameter formShowParameter) { + QFilter qFilter = new QFilter("isleaf", "=", true); + formShowParameter.getListFilterParameter().getQFilters().add(qFilter); + } + + protected void beforeBatchSelect(BeforeF7SelectEvent arg0, ListShowParameter formShowParameter) { + int curRow = this.getModel().getEntryCurrentRowIndex("entryentity"); + DynamicObject material = (DynamicObject) this.getModel().getValue("material", curRow); + DynamicObject warehouse = (DynamicObject) this.getModel().getValue("warehouse"); + if (material == null) { + this.getView().showMessage(ResManager.loadKDString("请先选择基础物料。", "MaterialOutBillEditPlugin_4", "ec-ecma-formplugin", new Object[0])); + arg0.setCancel(true); + } else { + QFilter listFilter = new QFilter("material", "=", material.getPkValue()); + listFilter.and(new QFilter("warehouse", "=", warehouse.getPkValue())); + DynamicObject unitprojectpro; + if (warehouse.getDynamicObject("project") != null) { + unitprojectpro = warehouse.getDynamicObject("project"); + listFilter.and(new QFilter("project", "=", unitprojectpro.getPkValue())); + } + + if (warehouse.getDynamicObject("unitproject") != null) { + unitprojectpro = warehouse.getDynamicObject("unitproject"); + listFilter.and(new QFilter("unitprojectpro", "=", unitprojectpro.getPkValue())); + } + + String modelnum = (String) this.getModel().getValue("modelnum", curRow); + if (StringUtils.isNotBlank(modelnum)) { + listFilter.and(new QFilter("modelnum", "=", modelnum)); + } + + formShowParameter.getListFilterParameter().getQFilters().add(listFilter); + } + + } + + protected void beforeCbsSelect(BeforeF7SelectEvent arg0, ListShowParameter formShowParameter) { + DynamicObject project = (DynamicObject) this.getModel().getValue("project"); + if (project == null) { + this.getView().showTipNotification(ResManager.loadKDString("必须选择工程项目。", "MaterialOutBillEditPlugin_3", "ec-ecma-formplugin", new Object[0])); + arg0.setCancel(true); + } else { + QFilter qFilter = new QFilter("project", "=", project.getPkValue()); + qFilter.and(new QFilter("isleaf", "=", true)); + formShowParameter.getListFilterParameter().getQFilters().add(qFilter); + formShowParameter.setFormId("bos_listf7"); + } + } + + protected void beforeBoqSelect(BeforeF7SelectEvent arg0, ListShowParameter formShowParameter) { + DynamicObject project = (DynamicObject) this.getModel().getValue("project"); + DynamicObject contract = (DynamicObject) this.getModel().getValue("contract"); + if (project == null) { + this.getView().showTipNotification(ResManager.loadKDString("必须选择工程项目。", "MaterialOutBillEditPlugin_3", "ec-ecma-formplugin", new Object[0])); + arg0.setCancel(true); + } else { + QFilter qFilter = new QFilter("project", "=", project.getPkValue()); + qFilter.and(new QFilter("isleaf", "=", true)); + List treeFilter = formShowParameter.getTreeFilterParameter().getQFilters(); + treeFilter.add(new QFilter("project", "=", project.getPkValue())); + DynamicObject unitProject = (DynamicObject) this.getModel().getValue("unitprojectpro"); + if (unitProject != null) { + qFilter.and(new QFilter("unitproject", "=", unitProject.getPkValue())); + treeFilter.add(new QFilter("unitproject", "=", unitProject.getPkValue())); + } else { + List unitProIds = this.getContUnitProIds(contract); + if (unitProIds.size() > 0) { + qFilter.and(new QFilter("unitproject", "in", unitProIds)); + } else { + qFilter.and(new QFilter("project", "=", project.getPkValue())); + } + } + + formShowParameter.getListFilterParameter().getQFilters().add(qFilter); + } + } + + protected void beforeWbsSelect(ListShowParameter formShowParameter) { + DynamicObject project = (DynamicObject) this.getModel().getValue("project"); + if (project != null) { + QFilter qFilter = new QFilter("project", "=", project.getPkValue()); + qFilter.and(new QFilter("isleaf", "=", true)); + formShowParameter.getListFilterParameter().getQFilters().add(qFilter); + } + + formShowParameter.setFormId("bos_listf7"); + } + + protected void beforeMaterielSelect(BeforeF7SelectEvent arg0) { + boolean isBaseMateriel = (Boolean) this.getModel().getValue("isbasemateriel"); + DynamicObject warehouse = (DynamicObject) this.getModel().getValue("warehouse"); + if (warehouse == null) { + this.getView().showMessage(ResManager.loadKDString("请先选择发货仓库。", "MaterialOutBillEditPlugin_5", "ec-ecma-formplugin", new Object[0])); + arg0.setCancel(true); + } else { + if (!isBaseMateriel) { + DynamicObject transtype = (DynamicObject) this.getModel().getValue("transtype"); + if (transtype == null) { + this.getView().showMessage(ResManager.loadKDString("请先选择事务类型。", "MaterialOutBillEditPlugin_6", "ec-ecma-formplugin", new Object[0])); + arg0.setCancel(true); + return; + } + + String transactionType = transtype.getString("type"); + arg0.setCancel(true); + Map map = new HashMap(); + map.put("formId", "ecma_invmatf7"); + map.put("orgId", ((DynamicObject) this.getModel().getValue("org")).getPkValue().toString()); + map.put("depotId", warehouse.getPkValue().toString()); + if (TransTypeEnum.INCREASE.getValue().equals(transactionType)) { + map.put("isQtyZero", true); + } + + FormShowParameter showParameter = FormShowParameter.createFormShowParameter(map); + showParameter.getOpenStyle().setShowType(ShowType.Modal); + showParameter.setCloseCallBack(new CloseCallBack(this, "material")); + this.getView().showForm(showParameter); + } + + } + } + + protected void beforeWarehouseSelect(ListShowParameter formShowParameter, BeforeF7SelectEvent arg0) { + DynamicObject org = (DynamicObject) this.getModel().getValue("org"); + Long orgId = org == null ? 0L : (Long) org.getPkValue(); + formShowParameter.getListFilterParameter().getQFilters().add(new QFilter("org", "=", orgId)); + } + + protected void beforeRequestpersonSelect(BeforeF7SelectEvent arg0, ListShowParameter formShowParameter) { + DynamicObject labour = (DynamicObject) this.getModel().getValue("labour"); + if (labour != null) { + String team = labour.getString("team"); + if ("01".equals(team)) { + DynamicObjectCollection personEntry = labour.getDynamicObjectCollection("entryentity"); + ArrayList pkList = new ArrayList(); + Iterator var7 = personEntry.iterator(); + + while (var7.hasNext()) { + DynamicObject personEntryEntity = (DynamicObject) var7.next(); + DynamicObject requestPerson = personEntryEntity.getDynamicObject("pickmaterials"); + pkList.add(requestPerson.getPkValue()); + } + + formShowParameter.getListFilterParameter().getQFilters().add(new QFilter("id", "in", pkList)); + } + } + + } + + protected void beforeLabourSelect(ListShowParameter formShowParameter) { + DynamicObject supplier = (DynamicObject) this.getModel().getValue("supplier"); + if (supplier != null) { + formShowParameter.getListFilterParameter().getQFilters().add(new QFilter("supplier", "=", supplier.getPkValue())); + } + + DynamicObject contractF7 = (DynamicObject) this.getModel().getValue("contract"); + DynamicObject project; + DynamicObject unitProject; + if (contractF7 != null) { + project = BusinessDataServiceHelper.loadSingle(contractF7.getPkValue(), "ec_out_contract"); + unitProject = project.getDynamicObject("partb"); + formShowParameter.getListFilterParameter().getQFilters().add(new QFilter("supplier", "=", unitProject.getPkValue())); + } + + project = (DynamicObject) this.getModel().getValue("project"); + if (project != null) { + formShowParameter.getListFilterParameter().getQFilters().add(new QFilter("project", "=", project.getPkValue())); + } + + unitProject = (DynamicObject) this.getModel().getValue("unitprojectpro"); + if (unitProject != null) { + formShowParameter.getListFilterParameter().getQFilters().add(new QFilter("unitproject", "=", unitProject.getPkValue())); + } + + } + + protected void beforeSupplierSelect(ListShowParameter formShowParameter) { + DynamicObject contractF7 = (DynamicObject) this.getModel().getValue("contract"); + if (contractF7 != null) { + DynamicObject contract = BusinessDataServiceHelper.loadSingle(contractF7.getPkValue(), "ec_out_contract"); + DynamicObject supplier = contract.getDynamicObject("partb"); + formShowParameter.getListFilterParameter().getQFilters().add(new QFilter("id", "=", supplier.getPkValue())); + } + + } + + protected void beforeContractSelect(ListShowParameter formShowParameter) { + DynamicObject supplierValue = (DynamicObject) this.getModel().getValue("supplier"); + if (supplierValue != null) { + formShowParameter.getListFilterParameter().getQFilters().add(new QFilter("partb", "=", supplierValue.getPkValue())); + } + + DynamicObject labour = (DynamicObject) this.getModel().getValue("labour"); + if (labour != null && labour.getDynamicObject("supplier") != null) { + formShowParameter.getListFilterParameter().getQFilters().add(new QFilter("partb", "=", labour.getDynamicObject("supplier").getPkValue())); + } + + DynamicObject project = this.getModel().getDataEntity().getDynamicObject("project"); + if (project != null) { + formShowParameter.getListFilterParameter().getQFilters().add(new QFilter("project", "=", project.getPkValue())); + } + + ContractHelper.getContractByStatus("ecma_materialoutbill", formShowParameter, PayDirectionEnum.OUT.getValue()); + } + + public void closedCallBack(ClosedCallBackEvent closedcallbackevent) { + super.closedCallBack(closedcallbackevent); + String actionId = closedcallbackevent.getActionId(); + Object returnData = closedcallbackevent.getReturnData(); + if ("labour".equals(actionId)) { + DynamicObject labour = (DynamicObject) returnData; + if (labour != null) { + this.getModel().setValue("labour", labour.getPkValue()); + } + } else if ("material".equals(actionId)) { + String[] keys = (String[]) ((String[]) returnData); + if (keys != null && keys.length > 0) { + int rowCount = this.getModel().getEntryRowCount("entryentity"); + int rowIndex = this.getModel().getEntryCurrentRowIndex("entryentity"); + DynamicObject dataEntity = this.getModel().getDataEntity(); + DynamicObject currency = dataEntity.getDynamicObject("currency"); + DynamicObject rateTable = dataEntity.getDynamicObject("exratetable"); + Date rateDate = dataEntity.getDate("exchangedate"); + String[] var11 = keys; + int var12 = keys.length; + + for (int var13 = 0; var13 < var12; ++var13) { + String key = var11[var13]; + if (rowIndex >= rowCount) { + this.getModel().createNewEntryRow("entryentity"); + this.getModel().updateCache(); + } + + DynamicObject materialInventory = BusinessDataServiceHelper.loadSingle(key, "ecma_matinventory"); + DynamicObject material = materialInventory.getDynamicObject("material"); + String modelnum = materialInventory.getString("modelnum"); + String lot = materialInventory.getString("lot"); + DynamicObject measureunit = materialInventory.getDynamicObject("measureunit"); + String price = materialInventory.getString("price"); + BigDecimal priceNum = new BigDecimal(price); + BigDecimal qty = materialInventory.getBigDecimal("qty"); + QFilter filter = new QFilter("number", "=", lot); + filter.and(new QFilter("material.id", "=", material.getPkValue())); + filter.and(new QFilter("modelnum", "=", modelnum.trim())); + DynamicObject[] lots = BusinessDataServiceHelper.load("ecma_material_lot", "number", new QFilter[]{filter}); + if (lots != null && lots.length > 0) { + this.getModel().setValue("lotid", lots[0].getPkValue(), rowIndex); + } + + this.getModel().setValue("material", material.getPkValue(), rowIndex); + this.getModel().setValue("modelnum", modelnum, rowIndex); + this.getModel().setValue("lot", lot, rowIndex); + if (measureunit != null) { + this.getModel().setValue("measureunit", measureunit.getPkValue(), rowIndex); + } else { + this.getModel().setValue("measureunit", (Object) null, rowIndex); + } + + boolean isMultiCurrency = dataEntity.getBoolean("ismulticurrency"); + DynamicObject srcCurrency = materialInventory.getDynamicObject("currency"); + BigDecimal rate = BigDecimal.ONE; + if (isMultiCurrency && !StringUtils.equals(srcCurrency.getString("id"), currency.getString("id"))) { + DynamicObject stdCurrency = dataEntity.getDynamicObject("stdcurrency"); + if (!srcCurrency.getPkValue().equals(stdCurrency.getPkValue())) { + if (currency != null && rateTable != null && rateDate != null) { + rate = CurrencyHelper.getExChangeRate(srcCurrency.getLong("id"), currency.getLong("id"), rateTable.getLong("id"), rateDate); + rate = rate == null ? BigDecimal.ONE : rate; + } + } else { + BigDecimal directRate = dataEntity.getBigDecimal("exchangerate"); + directRate = directRate != null && directRate.compareTo(BigDecimal.ZERO) != 0 ? directRate : BigDecimal.ZERO; + rate = BigDecimal.ONE.divide(directRate, 10, 4); + } + } + + this.getModel().setValue("price", priceNum.multiply(rate), rowIndex); + this.getModel().setValue("qty", qty, rowIndex); + this.getModel().setValue("matinventory", materialInventory.getPkValue(), rowIndex); + ++rowIndex; + } + } + } + + } + + public void afterDoOperation(AfterDoOperationEventArgs afterDoOperationEventArgs) { + super.afterDoOperation(afterDoOperationEventArgs); + String operateKey = afterDoOperationEventArgs.getOperateKey(); + if (StringUtils.equals(operateKey, "deleteentry")) { + this.sumOutAmount(); + } + + } + + protected void setUnitProject() { + UnitProjectUtil.setUnitProject(this.getView(), "unitprojectpro", "project"); + DynamicObject warehouse = (DynamicObject) this.getModel().getValue("warehouse"); + DynamicObject project = (DynamicObject) this.getModel().getValue("project"); + if (warehouse != null && warehouse.getDynamicObject("unitproject") == null && project != null) { + FieldEdit var3 = (FieldEdit) this.getView().getControl("unitprojectpro"); + } + + } + + public void hyperLinkClick(HyperLinkClickEvent hyperLinkClickEvent) { + int rowIndex = hyperLinkClickEvent.getRowIndex(); + switch (hyperLinkClickEvent.getFieldName()) { + case "poundno": + this.onEntryEntityPoundNoLinkClick(rowIndex); + default: + } + } + + protected void onEntryEntityPoundNoLinkClick(int rowIndex) { + Long poundPkId = (Long) this.getModel().getValue("poundid", rowIndex); + if (poundPkId != null) { + BillShowParameter billShowParameter = OpenPageUtils.buildBillShowParam(poundPkId, "ecma_poundbill"); + this.getView().showForm(billShowParameter); + } + } } diff --git a/code/zcdev/zcgj-zcdev-zcdev-pr/src/main/java/zcgj/zcdev/zcdev/pr/plugin/form/PoundAutoFetchBizExt2.java b/code/zcdev/zcgj-zcdev-zcdev-pr/src/main/java/zcgj/zcdev/zcdev/pr/plugin/form/PoundAutoFetchBizExt2.java new file mode 100644 index 0000000..ff4cca7 --- /dev/null +++ b/code/zcdev/zcgj-zcdev-zcdev-pr/src/main/java/zcgj/zcdev/zcdev/pr/plugin/form/PoundAutoFetchBizExt2.java @@ -0,0 +1,272 @@ +// +// Source code recreated from a .class file by IntelliJ IDEA +// (powered by FernFlower decompiler) +// + +package zcgj.zcdev.zcdev.pr.plugin.form; + +import com.google.common.collect.Maps; +import java.math.BigDecimal; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Date; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.Set; +import java.util.function.Function; +import java.util.stream.Collectors; +import kd.bos.dataentity.Tuple; +import kd.bos.dataentity.entity.DynamicObject; +import kd.bos.dataentity.entity.DynamicObjectCollection; +import kd.bos.dataentity.resource.ResManager; +import kd.bos.dataentity.utils.ArrayUtils; +import kd.bos.dataentity.utils.StringUtils; +import kd.bos.entity.datamodel.IDataModel; +import kd.bos.form.IFormView; +import kd.bos.form.events.BeforeDoOperationEventArgs; +import kd.bos.orm.query.QFilter; +import kd.bos.servicehelper.BusinessDataServiceHelper; +import kd.ec.basedata.common.utils.CurrencyHelper; +import kd.ec.material.common.enums.PoundTransTypeEnum; +import kd.ec.material.formplugin.MaterialOutBillEditPlugin; +import org.apache.commons.collections4.CollectionUtils; + +public class PoundAutoFetchBizExt2 { + private final MaterialOutBillEditPluginExt plugin; + private final IFormView formView; + + public PoundAutoFetchBizExt2(MaterialOutBillEditPluginExt plugin) { + this.plugin = plugin; + this.formView = plugin.getView(); + } + + public void doFetchPound(BeforeDoOperationEventArgs args) { + IDataModel model = this.formView.getModel(); + DynamicObject warehouse = (DynamicObject)model.getValue("warehouse"); + if (warehouse == null) { + this.formView.showMessage(ResManager.loadKDString("请先选择发货仓库。", "PoundAutoFetchBiz_2", "ec-ecma-formplugin", new Object[0])); + args.setCancel(true); + } else { + DynamicObject transType = (DynamicObject)this.formView.getModel().getValue("transtype"); + if (transType == null) { + this.formView.getModel().setValue("transtype", PoundTransTypeEnum.POUND_OUT.getDefaultId()); + } + + int rowCount = this.formView.getModel().getEntryRowCount("entryentity"); + if (rowCount > 0) { + this.formView.getModel().deleteEntryData("entryentity"); + this.formView.updateView("entryentity"); + } + + DynamicObject[] matInventoryEntities = this.queryMatInventory(); + if (!ArrayUtils.isEmpty(matInventoryEntities)) { + Map> matInventoryGroup = (Map)Arrays.stream(matInventoryEntities).filter((dynamicObject) -> { + return Optional.ofNullable(dynamicObject.getDynamicObject("material")).isPresent(); + }).collect(Collectors.groupingBy((dynamicObject) -> { + return (Long)dynamicObject.getDynamicObject("material").getPkValue(); + })); + Set resourceIds = matInventoryGroup.keySet(); + DynamicObject[] poundEntities = this.queryPoundBills(resourceIds); + this.fillEntry(poundEntities, matInventoryGroup); + } + } + } + + protected DynamicObject[] queryMatInventory() { + DynamicObject org = (DynamicObject)this.formView.getModel().getValue("org"); + DynamicObject warehouse = (DynamicObject)this.formView.getModel().getValue("warehouse"); + DynamicObject project = (DynamicObject)this.formView.getModel().getValue("project"); + QFilter orgFilter = new QFilter("org", "=", org.getPkValue()); + QFilter warehouseFilter = new QFilter("warehouse", "=", warehouse.getPkValue()); + if (project != null) { + warehouseFilter = warehouseFilter.and(new QFilter("project", "=", project.getPkValue())); + } + + QFilter qtyFilter = new QFilter("qty", ">", 0); + String matInventorySelectProps = "material,modelnum,measureunit,lot,qty,price,amount,currency"; + return BusinessDataServiceHelper.load("ecma_matinventory", matInventorySelectProps, new QFilter[]{orgFilter, warehouseFilter, qtyFilter}); + } + + protected DynamicObject[] queryPoundBills(Set resourceIds) { + DynamicObject project = (DynamicObject)this.formView.getModel().getValue("project"); + DynamicObject warehouse = (DynamicObject)this.formView.getModel().getValue("warehouse"); + DynamicObject org = (DynamicObject)this.formView.getModel().getValue("org"); + QFilter orgFilter = new QFilter("org", "=", org.getPkValue()); + if (project != null) { + orgFilter = orgFilter.and(new QFilter("project", "=", project.getPkValue())); + } + + if (warehouse != null) { + orgFilter = orgFilter.and((new QFilter("out_depot", "=", warehouse.getPkValue())).or(new QFilter("out_depot", "=", 0))); + } + + QFilter depotStatusFilter = new QFilter("depotstatus", "=", Boolean.FALSE); + QFilter transTypeFilter = new QFilter("transtype", "=", PoundTransTypeEnum.POUND_OUT.getDefaultId()); + QFilter optTypeFilter = new QFilter("opt_type", "!=", "2"); + QFilter poundResourceFilter = new QFilter("material", "in", resourceIds); + return BusinessDataServiceHelper.load("ecma_poundbill", "id ,billno ,material ,actualweight", new QFilter[]{orgFilter, transTypeFilter, depotStatusFilter, optTypeFilter, poundResourceFilter}); + } + + protected void fillEntry(DynamicObject[] poundEntities, Map> matInventoryGroup) { + if (!ArrayUtils.isEmpty(poundEntities)) { + DynamicObject[] var3 = poundEntities; + int var4 = poundEntities.length; + + for(int var5 = 0; var5 < var4; ++var5) { + DynamicObject poundEntity = var3[var5]; + DynamicObject resource = poundEntity.getDynamicObject("material"); + List resourceListEntities = (List)matInventoryGroup.get((Long)resource.getPkValue()); + if (!CollectionUtils.isEmpty(resourceListEntities)) { + Map poundDataMap = Maps.newHashMap(); + poundDataMap.put("poundid", poundEntity.getPkValue()); + poundDataMap.put("poundno", poundEntity.getString("billno")); + poundDataMap.put("qty", poundEntity.getString("actualweight")); + List> tupleList = this.filterResourceListByLot(resource, resourceListEntities, new BigDecimal(poundEntity.getString("actualweight"))); + this.fillEntryByMatInventory(tupleList, poundDataMap); + } + } + + this.formView.updateView("entryentity"); + this.plugin.sumOutAmount(); + } + } + + protected List> filterResourceListByLot(DynamicObject resource, List resourceListEntities, BigDecimal targetQty) { + List> result = new ArrayList(); + if (CollectionUtils.isEmpty(resourceListEntities)) { + return result; + } else { + Map> lotMap = (Map)resourceListEntities.stream().collect(Collectors.groupingBy((dynamicObject) -> { + String lot = dynamicObject.getString("lot"); + return StringUtils.isNotEmpty(lot); + })); + List lotResourceList = (List)lotMap.get(true); + if (CollectionUtils.isNotEmpty(lotResourceList)) { + Map lotResourceMap = (Map)resourceListEntities.stream().collect(Collectors.toMap((materialInventory) -> { + return materialInventory.getString("lot"); + }, Function.identity(), (k1, k2) -> { + return k1; + })); + Set lotSet = lotResourceMap.keySet(); + QFilter filter = new QFilter("number", "in", lotSet); + filter.and(new QFilter("material", "=", resource.getPkValue())); + DynamicObject[] lotEntities = BusinessDataServiceHelper.load("ecma_material_lot", "number", new QFilter[]{filter}, "id"); + DynamicObject[] var11 = lotEntities; + int var12 = lotEntities.length; + + for(int var13 = 0; var13 < var12; ++var13) { + DynamicObject lotEntity = var11[var13]; + if (targetQty.compareTo(BigDecimal.ZERO) <= 0) { + break; + } + + String logNumber = lotEntity.getString("number"); + DynamicObject lotResource = (DynamicObject)lotResourceMap.get(logNumber); + BigDecimal qty = lotResource.getBigDecimal("qty"); + BigDecimal diff = targetQty.subtract(qty); + if (diff.compareTo(BigDecimal.ZERO) >= 0) { + result.add(Tuple.create(lotResource, qty)); + targetQty = diff; + } else { + result.add(Tuple.create(lotResource, targetQty)); + targetQty = BigDecimal.ZERO; + } + } + } + + List notLotResourceList = (List)lotMap.get(false); + if (CollectionUtils.isEmpty(notLotResourceList)) { + return result; + } else { + Iterator var20 = notLotResourceList.iterator(); + + while(var20.hasNext()) { + DynamicObject notLotResource = (DynamicObject)var20.next(); + if (targetQty.compareTo(BigDecimal.ZERO) <= 0) { + break; + } + + BigDecimal qty = notLotResource.getBigDecimal("qty"); + BigDecimal diff = targetQty.subtract(qty); + if (diff.compareTo(BigDecimal.ZERO) >= 0) { + result.add(Tuple.create(notLotResource, qty)); + targetQty = diff; + } else { + result.add(Tuple.create(notLotResource, targetQty)); + targetQty = BigDecimal.ZERO; + } + } + + return result; + } + } + } + + protected void fillEntryByMatInventory(List> resourceListEntities, Map poundDataMap) { + DynamicObject dataEntity = this.formView.getModel().getDataEntity(); + DynamicObject currency = dataEntity.getDynamicObject("currency"); + DynamicObject rateTable = dataEntity.getDynamicObject("exratetable"); + DynamicObjectCollection entryEntity = this.formView.getModel().getEntryEntity("entryentity"); + Date rateDate = dataEntity.getDate("exchangedate"); + Iterator var8 = resourceListEntities.iterator(); + + while(var8.hasNext()) { + Tuple materialInventoryTuple = (Tuple)var8.next(); + DynamicObject row = entryEntity.addNew(); + DynamicObject materialInventory = (DynamicObject)materialInventoryTuple.item1; + String modelNum = materialInventory.getString("modelnum"); + DynamicObject material = materialInventory.getDynamicObject("material"); + String lot = materialInventory.getString("lot"); + DynamicObject measureUnit = materialInventory.getDynamicObject("measureunit"); + String price = materialInventory.getString("price"); + BigDecimal priceNum = new BigDecimal(price); + QFilter filter = new QFilter("number", "=", lot); + filter.and(new QFilter("material", "=", material.getPkValue())); + filter.and(new QFilter("modelnum", "=", modelNum.trim())); + DynamicObject[] lots = BusinessDataServiceHelper.load("ecma_material_lot", "number", new QFilter[]{filter}); + if (ArrayUtils.isNotEmpty(lots)) { + row.set("lotid", lots[0]); + } + + row.set("material", material); + row.set("modelnum", modelNum); + row.set("lot", lot); + if (measureUnit != null) { + row.set("measureunit", measureUnit); + } else { + row.set("measureunit", (Object)null); + } + + boolean isMultiCurrency = dataEntity.getBoolean("ismulticurrency"); + DynamicObject srcCurrency = materialInventory.getDynamicObject("currency"); + BigDecimal rate = BigDecimal.ONE; + BigDecimal directRate; + if (isMultiCurrency && !StringUtils.equals(srcCurrency.getString("id"), currency.getString("id"))) { + DynamicObject stdCurrency = dataEntity.getDynamicObject("stdcurrency"); + if (!srcCurrency.getPkValue().equals(stdCurrency.getPkValue())) { + if (rateTable != null && rateDate != null) { + rate = CurrencyHelper.getExChangeRate(srcCurrency.getLong("id"), currency.getLong("id"), rateTable.getLong("id"), rateDate); + rate = rate == null ? BigDecimal.ONE : rate; + } + } else { + directRate = dataEntity.getBigDecimal("exchangerate"); + directRate = directRate != null && directRate.compareTo(BigDecimal.ZERO) != 0 ? directRate : BigDecimal.ZERO; + rate = BigDecimal.ONE.divide(directRate, 10, 4); + } + } + + BigDecimal entryPrice = priceNum.multiply(rate); + row.set("price", entryPrice); + row.set("poundid", poundDataMap.get("poundid")); + row.set("poundno", poundDataMap.get("poundno")); + directRate = (BigDecimal)materialInventoryTuple.item2; + row.set("qty", directRate); + row.set("amount", entryPrice.multiply(directRate)); + row.set("matinventory", materialInventory.getPkValue()); + } + + this.formView.getModel().updateEntryCache(entryEntity); + } +}