From 470be319e06c118e166c579c46890053fe13386a Mon Sep 17 00:00:00 2001 From: xuhaihui <2098865055@qq.com> Date: Fri, 25 Jul 2025 10:13:56 +0800 Subject: [PATCH] =?UTF-8?q?=E6=A0=87=E8=AE=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../form/MaterialInBillEditPluginExt.java | 2098 +++++++++++++++++ .../pr/plugin/form/PoundAutoFetchBizExt.java | 375 +++ 2 files changed, 2473 insertions(+) create mode 100644 code/zcdev/zcgj-zcdev-zcdev-pr/src/main/java/zcgj/zcdev/zcdev/pr/plugin/form/MaterialInBillEditPluginExt.java create mode 100644 code/zcdev/zcgj-zcdev-zcdev-pr/src/main/java/zcgj/zcdev/zcdev/pr/plugin/form/PoundAutoFetchBizExt.java diff --git a/code/zcdev/zcgj-zcdev-zcdev-pr/src/main/java/zcgj/zcdev/zcdev/pr/plugin/form/MaterialInBillEditPluginExt.java b/code/zcdev/zcgj-zcdev-zcdev-pr/src/main/java/zcgj/zcdev/zcdev/pr/plugin/form/MaterialInBillEditPluginExt.java new file mode 100644 index 0000000..0a7819c --- /dev/null +++ b/code/zcdev/zcgj-zcdev-zcdev-pr/src/main/java/zcgj/zcdev/zcdev/pr/plugin/form/MaterialInBillEditPluginExt.java @@ -0,0 +1,2098 @@ +// +// 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.math.RoundingMode; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Calendar; +import java.util.Collections; +import java.util.Date; +import java.util.EventObject; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.stream.Collectors; + +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.ValueMapItem; +import kd.bos.entity.datamodel.ListSelectedRowCollection; +import kd.bos.entity.datamodel.RowDataEntity; +import kd.bos.entity.datamodel.events.AfterAddRowEventArgs; +import kd.bos.entity.datamodel.events.AfterDeleteEntryEventArgs; +import kd.bos.entity.datamodel.events.ChangeData; +import kd.bos.entity.datamodel.events.PropertyChangedArgs; +import kd.bos.entity.property.AmountProp; +import kd.bos.entity.property.ComboProp; +import kd.bos.form.CloseCallBack; +import kd.bos.form.FormShowParameter; +import kd.bos.form.ShowFormHelper; +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.BasedataPropEdit; +import kd.bos.form.field.ComboEdit; +import kd.bos.form.field.ComboItem; +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.query.QFilter; +import kd.bos.servicehelper.BusinessDataServiceHelper; +import kd.bos.servicehelper.org.OrgServiceHelper; +import kd.bos.servicehelper.org.OrgUnitServiceHelper; +import kd.ec.basedata.business.model.cont.OutTreeListingConstant; +import kd.ec.basedata.common.enums.StatusEnum; +import kd.ec.basedata.common.utils.ContractHelper; +import kd.ec.basedata.common.utils.OpenPageUtils; +import kd.ec.basedata.common.utils.StringHelper; +import kd.ec.contract.common.enums.PayDirectionEnum; +import kd.ec.contract.common.utils.CurrencyHelper; +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.materialin.PoundAutoFetchBiz; +import kd.pccs.placs.common.utils.ext.MetaDataUtil; +import org.apache.commons.lang.time.DateFormatUtils; + +public class MaterialInBillEditPluginExt extends AbstractEcmaBillPlugin implements BeforeF7SelectListener, HyperLinkClickListener { + private static final String KEY_ENTRYENTITY = "entryentity"; + private static final String DO_ENABLELOT = "enablelot"; + private static final String DO_AUTOGENLOT = "autogenlot"; + private static final String DO_DISABLELOT = "disablelot"; + private static final String DO_POUND_FETCH = "poundfetch"; + private static final String DO_TRANSCOSTSPLIT = "transcostsplit"; + private static final String DO_AUTOTRANSCOSTSPLIT = "autotranscostsplit"; + private static final String DO_NOTRANSCOSTSPLIT = "notranscostsplit"; + private static final String SELORDERLIST = "selorderlist"; + private static final String SELCONTLIST = "selcontlist"; + private static final String TRANSSPLIT = "transsplit"; + private static final String DELEENTRY = "deleentry"; + private static final String contractSource = "contractSource"; + private static final String purChaseOrderSource = "purChaseOrderSource"; + private static String entrySourceCaChe = "entrysourcecache"; + private final String PROJECTCBS = "PROJECTCBS"; + private static final String DO_SUBMIT = "submit"; + private static final String VIEW_RECONCILE = "viewreconcile"; + private static final String PROJECT = "project"; + private static final String EC_PROJECT = "ec_project"; + + public MaterialInBillEditPluginExt() { + } + + public void registerListener(EventObject e) { + super.registerListener(e); + BasedataEdit warehouse = (BasedataEdit) this.getControl("warehouse"); + warehouse.addBeforeF7SelectListener(this); + BasedataEdit proboq = (BasedataEdit) this.getControl("proboq"); + proboq.addBeforeF7SelectListener(this); + BasedataEdit procbs = (BasedataEdit) this.getControl("procbs"); + procbs.addBeforeF7SelectListener(this); + BasedataEdit flotid = (BasedataEdit) this.getControl("lotid"); + flotid.addBeforeF7SelectListener(this); + BasedataEdit contractEdit = (BasedataEdit) this.getControl("contract"); + contractEdit.addBeforeF7SelectListener(this); + BasedataEdit orderEdit = (BasedataEdit) this.getControl("purchaseorder"); + orderEdit.addBeforeF7SelectListener(this); + BasedataEdit unitPro = (BasedataEdit) this.getControl("unitprojectpro"); + unitPro.addBeforeF7SelectListener(this); + BasedataEdit material = (BasedataEdit) this.getControl("material"); + material.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")); + }); + } + + 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 beforeBindData(EventObject e) { + super.beforeBindData(e); + BasedataPropEdit costcontrol = (BasedataPropEdit) this.getView().getControl("costcontrol"); + costcontrol.setMustInput(true); + this.entryShowColumn(); + Boolean poundInOn = (Boolean) this.getModel().getValue("poundin"); + this.setEntryOpViewWithPound(poundInOn); + } + + public void afterBindData(EventObject e) { + super.afterBindData(e); + DynamicObject transtype = (DynamicObject) this.getModel().getValue("transtype"); + boolean impactcost = transtype == null ? false : (Boolean) transtype.get("impactcost"); + String billStatus = (String) this.getModel().getValue("billstatus"); + if (impactcost && StatusEnum.Checked.getValue().equalsIgnoreCase(billStatus)) { + this.getView().setVisible(true, new String[]{"splitamount", "iscompleted"}); + } else { + this.getView().setVisible(false, new String[]{"splitamount", "iscompleted"}); + } + + this.initMatinSource(); + this.setUnitProjectFieldStatus(); + this.setMainSourceItems(); + DynamicObjectCollection entryentity = this.getView().getModel().getEntryEntity("entryentity"); + if (entryentity.size() > 0) { + for (int i = 0; i < entryentity.size(); ++i) { + this.initFormPage(i); + } + } + + } + + protected void setMainSourceItems() { + String botpsource = (String) this.getModel().getValue("botpsource"); + if ("resp_deliveryform".equalsIgnoreCase(botpsource)) { + this.getView().setEnable(false, new String[]{"matinsource"}); + this.getView().setVisible(false, new String[]{"advconbaritemap", "selectorderlist", "selectcontractlist", "enablelot", "transcostsplit", "delentry"}); + } + + } + + protected void setUnitProjectFieldStatus() { + DynamicObject project = (DynamicObject) this.getModel().getValue("project"); + DynamicObject warehouse = (DynamicObject) this.getModel().getValue("warehouse"); + boolean flag = false; + if (project != null && project.getBoolean("editonunit") && warehouse != null && warehouse.getDynamicObject("unitproject") != null) { + flag = true; + } + + BasedataEdit unitProjectEdit = (BasedataEdit) this.getControl("unitprojectpro"); + unitProjectEdit.setMustInput(flag); + } + + public void afterCreateNewData(EventObject e) { + super.afterCreateNewData(e); + 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", "id,periodyear,periodquarter", new QFilter[]{qFilter}); + if (periods != null && periods.length > 0) { + this.getModel().setValue("period", periods[0].getPkValue()); + } + + Object transType = this.getModel().getValue("transtype"); + if (transType == null) { + QFilter increaseFilter = new QFilter("type", "=", TransTypeEnum.INCREASE.value); + DynamicObject[] types = BusinessDataServiceHelper.load("ecma_transtype", "id,number,name,type,inouttype,impactcost", new QFilter[]{increaseFilter}); + if (types.length > 0) { + this.getModel().setValue("transtype", types[0].getPkValue()); + } + } + + this.setFiOrgByOrg(); + } + + private void setFiOrgByOrg() { + DynamicObject org = (DynamicObject) this.getModel().getValue("org"); + if (org != null) { + Map bizOrg = OrgUnitServiceHelper.getCompanyByOrg(Long.valueOf(org.getPkValue().toString()), Boolean.FALSE, Boolean.TRUE); + this.getModel().setValue("fiaccountorg", bizOrg.get("id")); + } + + } + + private void entryShowColumn() { + DynamicObjectCollection items = this.getModel().getEntryEntity("entryentity"); + boolean hasLot = items.stream().anyMatch((i) -> { + return StringUtils.isNotEmpty(i.getString("lot")); + }); + boolean hasTransAmount = items.stream().anyMatch((i) -> { + return EcNumberHelper.isPositiveBigDecimal(i.getBigDecimal("ftransamount")); + }); + DynamicObject value = (DynamicObject) this.getModel().getValue("transtype"); + boolean impactcost = value == null ? false : (Boolean) value.get("impactcost"); + if (!hasLot) { + this.getView().setVisible(false, new String[]{"lotid", "lot"}); + } + + if (!hasTransAmount) { + } + + if (!impactcost) { + this.getView().setVisible(false, new String[]{"ismainmaterial", "procbs", "ca", "proboq"}); + BasedataEdit procbsControl = (BasedataEdit) this.getControl("procbs"); + procbsControl.setMustInput(false); + BasedataEdit caControl = (BasedataEdit) this.getControl("ca"); + caControl.setMustInput(false); + BasedataEdit proboqControl = (BasedataEdit) this.getControl("proboq"); + proboqControl.setMustInput(false); + } + + } + + public void propertyChanged(PropertyChangedArgs e) { + super.propertyChanged(e); + String key = e.getProperty().getName(); + ChangeData[] valueSet = e.getChangeSet(); + Object propValue = valueSet[0].getNewValue(); + int curIndex = valueSet[0].getRowIndex(); + switch (key) { + case "contract": + this.contractChanged((DynamicObject) propValue); + break; + case "material": + this.entryMaterialChanged((DynamicObject) propValue, curIndex); + break; + case "measureunit": + this.entryMeasureunitChanged((DynamicObject) propValue, curIndex); + break; + case "purchaseorder": + this.purchaseOrderChanged((DynamicObject) propValue, curIndex); + break; + case "transtype": + this.transtypeChanged((DynamicObject) propValue); + this.showSplitAmount(); + break; + case "warehouse": + this.warehouseChanged((DynamicObject) propValue); + break; + case "price": + this.priceChanged((BigDecimal) propValue, curIndex); + break; + case "taxprice": + this.taxPriceChanged((BigDecimal) propValue, curIndex); + break; + case "qty": + this.entryQtyChanged((BigDecimal) propValue, curIndex); + case "mataxrate": + case "transamount": + case "transoftaxamount": + case "transtaxamount": + default: + break; + case "entrytaxrate": + this.entrymataxrateChanged((DynamicObject) propValue, curIndex); + break; + case "lotid": + this.lotF7Changed((DynamicObject) propValue, curIndex); + break; + case "oftaxamount": + this.oftaxamountChanged((BigDecimal) propValue, curIndex); + break; + case "taxamount": + this.entryTaxamountChanged(); + break; + case "notaxamount": + this.entryAmountChanged((BigDecimal) propValue, curIndex); + break; + case "ftransamount": + this.entryFtransamountChanged((BigDecimal) propValue, curIndex); + break; + case "project": + this.projectChanged(); + break; + case "mataxamount": + this.mataxamountChanged((BigDecimal) propValue); + break; + case "matoftaxamount": + this.matoftaxamountChanged((BigDecimal) propValue); + break; + case "matamount": + this.matamountChanged((BigDecimal) propValue); + break; + case "proboq": + this.onProBoqChanged(e); + break; + case "fiaccountorg": + this.onFiaccountOrgChanged(e); + break; + case "matinsource": + this.initMatinSource(); + this.onMatinSourceChanged(); + break; + case "unitprojectpro": + this.onUnitprojectproChanged(); + break; + case "adjustamount": + this.adjustamountChange(); + break; + case "adjustoftax": + this.adjustoftaxChange(); + break; + case "inputtaxprice": + this.inputtaxpriceChange(); + break; + case "inputtotalprice": + this.inputtotalpriceChange(); + break; + case "poundin": + this.onPoundInChanged((Boolean) propValue); + } + + } + + protected void onPoundInChanged(Boolean poundInOn) { + this.setEntryOpViewWithPound(poundInOn); + this.clearEntryData(); + this.getModel().setValue("transtype", (Object) null); + } + + protected void setEntryOpViewWithPound(Boolean poundInOn) { + switch ((String) this.getModel().getValue("matinsource")) { + case "1": + this.getView().setVisible(poundInOn, new String[]{"poundfetch", "poundno"}); + this.getView().setEnable(!poundInOn, new String[]{"selectcontractlist", "qty", "material", "modelnum"}); + break; + case "2": + this.getView().setVisible(poundInOn, new String[]{"poundfetch", "poundno"}); + this.getView().setEnable(!poundInOn, new String[]{"selectorderlist", "qty", "material", "modelnum"}); + break; + case "4": + this.getView().setVisible(poundInOn, new String[]{"poundfetch", "poundno"}); + this.getView().setEnable(!poundInOn, new String[]{"advconbaritemap", "qty", "material", "modelnum"}); + } + + } + + protected void entryMeasureunitChanged(DynamicObject propValue, int curIndex) { + this.changValueInitPage(curIndex); + } + + protected void adjustamountChange() { + this.getView().getModel().beginInit(); + this.getView().getModel().setValue("adjustoftax", false); + this.getView().getModel().endInit(); + this.getView().updateView("adjustoftax"); + this.unlockHeaderField(); + this.fieldLockLogic(); + } + + protected void unlockHeaderField() { + this.getView().setEnable(true, new String[]{"org", "fiaccountorg", "transtype", "warehouse", "matinsource", "contract", "purchaseorder", "mataxrate", "ismulticurrency", "currency", "exchangerate", "exchangedate", "exratetable", "unitprojectpro", "enablelot"}); + } + + protected void adjustoftaxChange() { + this.getView().getModel().beginInit(); + this.getView().getModel().setValue("adjustamount", false); + this.getView().getModel().endInit(); + this.getView().updateView("adjustamount"); + this.unlockHeaderField(); + this.fieldLockLogic(); + } + + protected void inputtaxpriceChange() { + this.fieldLockLogic(); + } + + public void fieldLockLogic() { + boolean isAdjustamount = this.getModel().getDataEntity().getBoolean("adjustamount"); + boolean isAdjustoftax = this.getModel().getDataEntity().getBoolean("adjustoftax"); + boolean isInputtaxprice = this.getModel().getDataEntity().getBoolean("inputtaxprice"); + boolean isInputtotalprice = this.getModel().getDataEntity().getBoolean("inputtotalprice"); + DynamicObjectCollection entryentity = this.getView().getModel().getEntryEntity("entryentity"); + if (entryentity.size() >= 1) { + int i; + if (isInputtaxprice && !isAdjustamount && !isAdjustoftax && !isInputtotalprice) { + for (i = 0; i < entryentity.size(); ++i) { + this.onlyOpenInputtaxprice(i); + } + } else if (isInputtaxprice && isInputtotalprice && !isAdjustamount && !isAdjustoftax) { + for (i = 0; i < entryentity.size(); ++i) { + this.openTaxPriceAndtotalPrice(i); + } + } else if (!isInputtaxprice && !isAdjustamount && !isAdjustoftax && isInputtotalprice) { + for (i = 0; i < entryentity.size(); ++i) { + this.onlyOpenInputtotalprice(i); + } + } else if (isAdjustamount) { + for (i = 0; i < entryentity.size(); ++i) { + this.openContainAdjustamount(i); + } + } else if (isAdjustoftax) { + for (i = 0; i < entryentity.size(); ++i) { + this.openContainAjustoftax(i); + } + } else if (!isInputtaxprice && !isAdjustamount && !isAdjustoftax && !isInputtotalprice) { + for (i = 0; i < entryentity.size(); ++i) { + this.initFormPage(i); + } + } + + } + } + + protected void inputtotalpriceChange() { + this.fieldLockLogic(); + } + + private void openTaxPriceAndtotalPrice(int rowIndex) { + this.getView().setEnable(true, rowIndex, new String[]{"material", "lot", "lotid", "modelnum", "measureunit", "entrytaxrate", "qty", "oftaxamount"}); + this.getView().setEnable(false, rowIndex, new String[]{"taxprice", "taxamount", "contprice", "price", "ismainmaterial", "notaxamount"}); + } + + private void onlyOpenInputtotalprice(int rowIndex) { + this.getView().setEnable(true, rowIndex, new String[]{"material", "lot", "lotid", "modelnum", "measureunit", "entrytaxrate", "qty", "notaxamount"}); + this.getView().setEnable(false, rowIndex, new String[]{"taxprice", "taxamount", "contprice", "oftaxamount", "price", "ismainmaterial"}); + } + + protected void initFormPage(int rowIndex) { + this.getView().setEnable(true, rowIndex, new String[]{"lot", "lotid", "measureunit", "entrytaxrate", "price", "ismainmaterial"}); + this.getView().setEnable(false, rowIndex, new String[]{"taxprice", "taxamount", "contprice", "oftaxamount", "notaxamount"}); + Boolean poundIn = (Boolean) this.getModel().getValue("poundin"); + this.getView().setEnable(!poundIn, rowIndex, new String[]{"material", "modelnum", "qty"}); + } + + private void onlyOpenInputtaxprice(int rowIndex) { + this.getView().setEnable(true, rowIndex, new String[]{"material", "lot", "lotid", "modelnum", "measureunit", "entrytaxrate", "qty", "taxprice"}); + this.getView().setEnable(false, rowIndex, new String[]{"taxamount", "notaxamount", "contprice", "oftaxamount", "price", "ismainmaterial"}); + } + + protected void openContainAdjustamount(int rowIdex) { + this.getView().setEnable(true, rowIdex, new String[]{"taxamount", "notaxamount"}); + this.getView().setEnable(false, rowIdex, new String[]{"material", "lot", "lotid", "modelnum", "measureunit", "entrytaxrate", "contprice", "qty", "taxprice", "oftaxamount", "price", "ismainmaterial"}); + this.getView().setEnable(false, new String[]{"org", "fiaccountorg", "transtype", "warehouse", "matinsource", "contract", "purchaseorder", "mataxrate", "ismulticurrency", "currency", "exchangerate", "exchangedate", "exratetable", "unitprojectpro", "enablelot"}); + } + + protected void openContainAjustoftax(int rowIndex) { + this.getView().setEnable(true, rowIndex, new String[]{"taxamount", "oftaxamount"}); + this.getView().setEnable(false, rowIndex, new String[]{"material", "lot", "lotid", "modelnum", "measureunit", "entrytaxrate", "contprice", "qty", "taxprice", "notaxamount", "price", "ismainmaterial"}); + this.getView().setEnable(false, new String[]{"org", "fiaccountorg", "transtype", "warehouse", "matinsource", "contract", "purchaseorder", "mataxrate", "ismulticurrency", "currency", "exchangerate", "exchangedate", "exratetable", "unitprojectpro", "enablelot"}); + } + + protected void entrymataxrateChanged(DynamicObject propValue, int i) { + boolean isAdjustamount = this.getModel().getDataEntity().getBoolean("adjustamount"); + boolean isAdjustoftax = this.getModel().getDataEntity().getBoolean("adjustoftax"); + boolean isInputtaxprice = this.getModel().getDataEntity().getBoolean("inputtaxprice"); + boolean isInputtotalprice = this.getModel().getDataEntity().getBoolean("inputtotalprice"); + BigDecimal taxrate = new BigDecimal(0); + if (propValue != null) { + taxrate = BigDecimal.valueOf((long) propValue.getInt("taxrate")); + } + + if (isInputtaxprice && !isAdjustamount && !isAdjustoftax && !isInputtotalprice) { + this.updateNewData(i, taxrate); + } else if (isInputtotalprice && !isInputtaxprice && !isAdjustamount && !isAdjustoftax) { + this.updateNewDataBytotalPrice(i, taxrate); + } else if (isInputtaxprice && isInputtotalprice && !isAdjustamount && !isAdjustoftax) { + this.updateNewDataByTaxAndTotalPrice(i, taxrate); + } else if (!isInputtaxprice && !isAdjustamount && !isAdjustoftax && !isInputtotalprice) { + this.initPageCountLogic(i, taxrate); + } + + } + + protected void initPageCountLogic(int i, BigDecimal taxrate) { + this.getModel().beginInit(); + BigDecimal price = (BigDecimal) this.getModel().getValue("price", i); + BigDecimal taxprice = price.multiply(BigDecimal.ONE.add(taxrate.divide(BigDecimal.valueOf(100L)))); + this.getModel().setValue("taxprice", taxprice, i); + BigDecimal qty = (BigDecimal) this.getModel().getValue("qty", i); + BigDecimal notaxamount = price.multiply(qty); + BigDecimal oftaxamount = notaxamount.multiply(BigDecimal.ONE.add(taxrate.divide(BigDecimal.valueOf(100L)))); + int amtPrecision = this.getAmtPrecision(); + notaxamount = notaxamount.setScale(amtPrecision, RoundingMode.HALF_UP); + oftaxamount = oftaxamount.setScale(amtPrecision, RoundingMode.HALF_UP); + BigDecimal taxamount = oftaxamount.subtract(notaxamount); + this.getModel().setValue("notaxamount", notaxamount, i); + this.getModel().setValue("oftaxamount", oftaxamount, i); + this.getModel().setValue("taxamount", taxamount, i); + this.getModel().endInit(); + this.getView().updateView("taxprice", i); + this.getView().updateView("notaxamount", i); + this.getView().updateView("oftaxamount", i); + this.getView().updateView("taxamount", i); + this.sumMaoftaxAmount(); + this.sumMaAmount(); + this.sumMaTaxAmount(); + this.countAmount(i); + } + + public int getAmtPrecision() { + int amtPrecision = 10; + AmountProp ofTaxAmountProp = (AmountProp) this.getModel().getDataEntityType().findProperty("oftaxamount"); + String controlPropName = ofTaxAmountProp.getControlPropName(); + DynamicObject currency = this.getModel().getDataEntity().getDynamicObject(controlPropName); + if (currency != null) { + amtPrecision = currency.getInt("amtprecision"); + } + + return amtPrecision; + } + + private void updateNewDataByTaxAndTotalPrice(int i, BigDecimal taxrate) { + this.getModel().beginInit(); + BigDecimal oftaxamount = EcNumberHelper.toBigDecimal(this.getModel().getValue("oftaxamount", i)); + BigDecimal notaxamount = oftaxamount.divide(BigDecimal.ONE.add(taxrate.divide(BigDecimal.valueOf(100L))), 10, RoundingMode.HALF_UP); + BigDecimal qty = EcNumberHelper.toBigDecimal(this.getModel().getValue("qty", i)); + BigDecimal price = notaxamount.divide(qty, 10, RoundingMode.HALF_UP); + this.getModel().setValue("price", price, i); + BigDecimal taxprice = oftaxamount.divide(qty, 10, RoundingMode.HALF_UP); + this.getModel().setValue("taxprice", taxprice, i); + int amtPrecision = this.getAmtPrecision(); + notaxamount = notaxamount.setScale(amtPrecision, RoundingMode.HALF_UP); + oftaxamount = oftaxamount.setScale(amtPrecision, RoundingMode.HALF_UP); + BigDecimal taxamount = oftaxamount.subtract(notaxamount); + this.getModel().setValue("notaxamount", notaxamount, i); + this.getModel().setValue("taxamount", taxamount, i); + this.getModel().endInit(); + this.getView().updateView("notaxamount", i); + this.getView().updateView("price", i); + this.getView().updateView("taxprice", i); + this.getView().updateView("taxamount", i); + this.sumMaoftaxAmount(); + this.sumMaAmount(); + this.sumMaTaxAmount(); + this.countAmount(i); + } + + protected void updateNewDataBytotalPrice(int i, BigDecimal taxrate) { + this.getModel().beginInit(); + BigDecimal notaxamount = EcNumberHelper.toBigDecimal(this.getModel().getValue("notaxamount"), i); + BigDecimal qty = EcNumberHelper.toBigDecimal(this.getModel().getValue("qty", i)); + BigDecimal price = notaxamount.divide(qty, 10, RoundingMode.HALF_UP); + this.getModel().setValue("price", price, i); + BigDecimal oftaxamount = notaxamount.multiply(BigDecimal.ONE.add(taxrate.divide(BigDecimal.valueOf(100L)))); + BigDecimal taxprice = oftaxamount.divide(qty, 10, RoundingMode.HALF_UP); + this.getModel().setValue("taxprice", taxprice, i); + int amtPrecision = this.getAmtPrecision(); + notaxamount = notaxamount.setScale(amtPrecision, RoundingMode.HALF_UP); + oftaxamount = oftaxamount.setScale(amtPrecision, RoundingMode.HALF_UP); + BigDecimal taxamount = oftaxamount.subtract(notaxamount); + this.getModel().setValue("oftaxamount", oftaxamount, i); + this.getModel().setValue("taxamount", taxamount, i); + this.getModel().endInit(); + this.getView().updateView("price", i); + this.getView().updateView("oftaxamount", i); + this.getView().updateView("taxprice", i); + this.getView().updateView("taxamount", i); + this.sumMaoftaxAmount(); + this.sumMaAmount(); + this.sumMaTaxAmount(); + } + + protected void updateNewData(int i, BigDecimal taxrate) { + this.getModel().beginInit(); + BigDecimal taxprice = (BigDecimal) this.getModel().getValue("taxprice", i); + BigDecimal price = taxprice.divide(BigDecimal.ONE.add(taxrate.divide(BigDecimal.valueOf(100L))), 10, RoundingMode.HALF_UP); + this.getModel().setValue("price", price, i); + BigDecimal qty = (BigDecimal) this.getModel().getValue("qty", i); + BigDecimal notaxamount = price.multiply(qty); + BigDecimal oftaxamount = notaxamount.multiply(BigDecimal.ONE.add(taxrate.divide(BigDecimal.valueOf(100L)))); + int amtPrecision = this.getAmtPrecision(); + notaxamount = notaxamount.setScale(amtPrecision, RoundingMode.HALF_UP); + oftaxamount = oftaxamount.setScale(amtPrecision, RoundingMode.HALF_UP); + BigDecimal taxamount = oftaxamount.subtract(notaxamount); + this.getModel().setValue("notaxamount", notaxamount, i); + this.getModel().setValue("oftaxamount", oftaxamount, i); + this.getModel().setValue("taxamount", taxamount, i); + this.getModel().endInit(); + this.getView().updateView("price", i); + this.getView().updateView("notaxamount", i); + this.getView().updateView("oftaxamount", i); + this.getView().updateView("taxamount", i); + this.sumMaoftaxAmount(); + this.sumMaAmount(); + this.sumMaTaxAmount(); + this.countAmount(i); + } + + public void initContAndOrderData(int i, BigDecimal taxrate) { + this.sumMaoftaxAmount(); + this.sumMaAmount(); + this.sumMaTaxAmount(); + this.countAmount(i); + } + + protected void onUnitprojectproChanged() { + int entryRowCount = this.getModel().getEntryRowCount("entryentity"); + + for (int i = 0; i < entryRowCount; ++i) { + this.getModel().setValue("proboq", (Object) null, i); + } + + String materialSource = (String) this.getModel().getValue("matinsource"); + if (StringUtils.equals("2", materialSource)) { + DynamicObject purchaseorder = this.getModel().getDataEntity().getDynamicObject("purchaseorder"); + if (purchaseorder != null) { + long purChaseOrderUnitProId = purchaseorder.getLong("unitproject_id"); + long unitProId = this.getModel().getDataEntity().getLong("unitprojectpro_id"); + if (purChaseOrderUnitProId != unitProId) { + this.getModel().setValue("purchaseorder", (Object) null); + } + } + } + + } + + protected void initMatinSource() { + String matinsource = (String) this.getModel().getValue("matinsource"); + Boolean poundIn = (Boolean) this.getModel().getValue("poundin"); + if ("1".equals(matinsource)) { + this.getView().setVisible(true, new String[]{"contract", "contractname", "selectcontractlist"}); + this.getView().setVisible(false, new String[]{"purchaseorder", "advconbaritemap", "selectorderlist"}); + this.getView().setEnable(!poundIn, new String[]{"selectcontractlist"}); + } else if ("2".equals(matinsource)) { + this.getView().setVisible(true, new String[]{"purchaseorder", "selectorderlist"}); + this.getView().setVisible(false, new String[]{"contract", "contractname", "advconbaritemap", "selectcontractlist"}); + this.getView().setEnable(!poundIn, new String[]{"selectorderlist"}); + } else if ("4".equals(matinsource)) { + this.getView().setVisible(true, new String[]{"advconbaritemap"}); + this.getView().setVisible(false, new String[]{"contract", "contractname", "purchaseorder", "selectcontractlist", "selectorderlist"}); + this.getView().setEnable(!poundIn, new String[]{"advconbaritemap"}); + } else { + this.getView().setVisible(true, new String[]{"contract", "contractname", "purchaseorder", "advconbaritemap", "selectcontractlist", "selectorderlist"}); + } + + } + + protected void onMatinSourceChanged() { + this.getModel().setValue("contract", (Object) null); + this.getModel().setValue("purchaseorder", (Object) null); + this.clearEntryData(); + } + + private void onFiaccountOrgChanged(PropertyChangedArgs e) { + DynamicObject fiAccountOrg = this.getModel().getDataEntity().getDynamicObject("fiaccountorg"); + DynamicObject currency; + if (fiAccountOrg != null) { + currency = CurrencyHelper.getCurrency((Long) fiAccountOrg.getPkValue()); + if (currency != null) { + boolean isMutiCurrency = this.getModel().getDataEntity().getBoolean("ismulticurrency"); + if (isMutiCurrency) { + this.getModel().setValue("stdcurrency", currency); + } else { + this.getModel().setValue("stdcurrency", currency); + this.getModel().setValue("currency", currency); + } + } + } else { + currency = this.getModel().getDataEntity().getDynamicObject("org"); + if (currency != null) { +// DynamicObject currency = CurrencyHelper.getCurrency((Long)currency.getPkValue());//系统默认 + currency = CurrencyHelper.getCurrency((Long) currency.getPkValue());//二开替代 + if (currency != null) { + boolean isMutiCurrency = this.getModel().getDataEntity().getBoolean("ismulticurrency"); + if (isMutiCurrency) { + this.getModel().setValue("stdcurrency", currency); + } else { + this.getModel().setValue("stdcurrency", currency); + this.getModel().setValue("currency", currency); + } + } + } + } + + } + + public void afterDeleteEntry(AfterDeleteEntryEventArgs e) { + this.getModel().getValue("unitprojectpro"); + } + + private void onProBoqChanged(PropertyChangedArgs e) { + DynamicObject proBoq = (DynamicObject) e.getChangeSet()[0].getNewValue(); + DynamicObject unitPro = (DynamicObject) this.getModel().getValue("unitprojectpro"); + 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"); + } + } + + } + + private void showSplitAmount() { + DynamicObject transType = this.getModel().getDataEntity().getDynamicObject("transtype"); + if (transType != null) { + boolean impactcost = transType.getBoolean("impactcost"); + int rowCount; + int i; + if (impactcost) { + rowCount = this.getModel().getEntryRowCount("entryentity"); + + for (i = 0; i < rowCount; ++i) { + BigDecimal noTaxAmount = (BigDecimal) this.getModel().getValue("notaxamount", i); + this.getModel().setValue("splitamount", noTaxAmount, i); + } + } else { + rowCount = this.getModel().getEntryRowCount("entryentity"); + + for (i = 0; i < rowCount; ++i) { + this.getModel().setValue("splitamount", (Object) null, i); + } + } + + } + } + + private void mataxamountChanged(BigDecimal propValue) { + this.getModel().beginInit(); + BigDecimal exchangerate = (BigDecimal) this.getModel().getValue("exchangerate"); + this.getModel().setValue("stdmatetaxamount", propValue.multiply(exchangerate)); + this.getModel().endInit(); + this.getView().updateView("stdmatetaxamount"); + this.summaryTotalTaxAmount(); + } + + private void matoftaxamountChanged(BigDecimal propValue) { + this.getModel().beginInit(); + BigDecimal exchangerate = (BigDecimal) this.getModel().getValue("exchangerate"); + this.getModel().setValue("stdmateoftaxamount", propValue.multiply(exchangerate)); + this.getModel().endInit(); + this.getView().updateView("stdmateoftaxamount"); + this.summaryTotalOfTaxAmount(); + } + + private void matamountChanged(BigDecimal propValue) { + this.getModel().beginInit(); + BigDecimal exchangerate = (BigDecimal) this.getModel().getValue("exchangerate"); + this.getModel().setValue("stdmateamount", propValue.multiply(exchangerate)); + this.getModel().endInit(); + this.getView().updateView("stdmateamount"); + this.summaryTotalAmount(); + } + + private void summaryTotalAmount() { + BigDecimal matamount = this.getModel().getValue("matamount") != null ? (BigDecimal) this.getModel().getValue("matamount") : new BigDecimal(0); + BigDecimal transamount = this.getModel().getValue("transamount") != null ? (BigDecimal) this.getModel().getValue("transamount") : new BigDecimal(0); + BigDecimal totalamount = matamount.add(transamount); + this.getModel().setValue("totalamount", totalamount); + } + + private void summaryTotalOfTaxAmount() { + BigDecimal matoftaxamount = this.getModel().getValue("matoftaxamount") != null ? (BigDecimal) this.getModel().getValue("matoftaxamount") : new BigDecimal(0); + BigDecimal transoftaxamount = this.getModel().getValue("transoftaxamount") != null ? (BigDecimal) this.getModel().getValue("transoftaxamount") : new BigDecimal(0); + BigDecimal totaloftaxamount = matoftaxamount.add(transoftaxamount); + this.getModel().setValue("totaloftaxamount", totaloftaxamount); + } + + private void summaryTotalTaxAmount() { + BigDecimal mataxamount = this.getModel().getValue("mataxamount") != null ? (BigDecimal) this.getModel().getValue("mataxamount") : new BigDecimal(0); + BigDecimal transtaxamount = this.getModel().getValue("transtaxamount") != null ? (BigDecimal) this.getModel().getValue("transtaxamount") : new BigDecimal(0); + BigDecimal totalTaxAmount = mataxamount.add(transtaxamount); + this.getModel().setValue("totaltaxamount", totalTaxAmount); + } + + private void entryFtransamountChanged(BigDecimal propValue, int curIndex) { + BigDecimal ftransAmount = EcNumberHelper.toBigDecimal(propValue); + BigDecimal notaxAmount = EcNumberHelper.toBigDecimal(this.getModel().getValue("notaxamount", curIndex)); + this.getModel().setValue("amount", ftransAmount.add(notaxAmount), curIndex); + EntryGrid grid2 = (EntryGrid) this.getControl("entryentity"); + BigDecimal sum2 = grid2.getSum("ftransamount"); + } + + private void transtaxamountChanged(BigDecimal propValue) { + BigDecimal curTransAmount = EcNumberHelper.toBigDecimal(this.getModel().getValue("transamount")); + this.getModel().beginInit(); + BigDecimal exchangerate = (BigDecimal) this.getModel().getValue("exchangerate"); + this.getModel().setValue("stdtrantaxamount", propValue.multiply(exchangerate)); + this.getModel().setValue("stdtranoftaxamount", propValue.add(curTransAmount).multiply(exchangerate)); + this.getModel().endInit(); + this.getView().updateView("stdtranoftaxamount"); + this.getView().updateView("stdtrantaxamount"); + this.summaryTotalTaxAmount(); + } + + private void priceChanged(BigDecimal propValue, int curIndex) { + boolean isAdjustamount = this.getModel().getDataEntity().getBoolean("adjustamount"); + boolean isAdjustoftax = this.getModel().getDataEntity().getBoolean("adjustoftax"); + boolean isInputtaxprice = this.getModel().getDataEntity().getBoolean("inputtaxprice"); + boolean isInputtotalprice = this.getModel().getDataEntity().getBoolean("inputtotalprice"); + DynamicObject mattaxrateObj = ((DynamicObject) this.getModel().getEntryEntity("entryentity").get(curIndex)).getDynamicObject("entrytaxrate"); + BigDecimal taxrate = new BigDecimal(0); + if (mattaxrateObj != null) { + taxrate = mattaxrateObj.getBigDecimal("taxrate"); + } + + if (!isInputtaxprice && !isAdjustamount && !isAdjustoftax && !isInputtotalprice) { + this.initPageCountLogic(curIndex, taxrate); + } + + } + + protected Map getVisMap() { + ComboEdit comboEdit = (ComboEdit) this.getControl("matinsource"); + ComboProp property = (ComboProp) comboEdit.getProperty(); + List selectValues = property.getComboItems(); + Map hashMap = new HashMap(); + Iterator var5 = selectValues.iterator(); + + while (var5.hasNext()) { + ValueMapItem selectValue = (ValueMapItem) var5.next(); + hashMap.put(selectValue.getValue(), selectValue.isItemVisible()); + } + + return hashMap; + } + + private void projectChanged() { + int rowCount = this.getModel().getEntryRowCount("entryentity"); + + for (int i = 0; i < rowCount; ++i) { + this.getModel().setValue("procbs", (Object) null, i); + this.getModel().setValue("proboq", (Object) null, i); + } + + DynamicObject contract = (DynamicObject) this.getModel().getValue("contract"); + DynamicObject contractProject = contract == null ? null : contract.getDynamicObject("project"); + DynamicObject project = (DynamicObject) this.getModel().getValue("project"); + if (project == null && contractProject != null || project != null && contractProject != null && project.getLong("id") != contractProject.getLong("id")) { + this.getModel().setValue("contract", (Object) null); + } + + ArrayList comboItems = new ArrayList(3); + String[] caption = new String[]{ResManager.loadKDString("合同清单", "MaterialInBillEditPlugin_9", "ec-ecma-formplugin", new Object[0]), ResManager.loadKDString("采购订单", "MaterialInBillEditPlugin_10", "ec-ecma-formplugin", new Object[0]), ResManager.loadKDString("资源清单", "MaterialInBillEditPlugin_11", "ec-ecma-formplugin", new Object[0])}; + String[] value = new String[]{"1", "2", "4"}; + + for (int i = 0; i < 3; ++i) { + if ((Boolean) this.getVisMap().get(value[i])) { + ComboItem comboItem = new ComboItem(); + comboItem.setCaption(new LocaleString(caption[i])); + comboItem.setValue(value[i]); + comboItems.add(comboItem); + } + } + + ComboEdit matinsource = (ComboEdit) this.getControl("matinsource"); + if (project != null) { + String costcontrol = project.getString("costcontrol"); + if ("RESOURCE".equals(costcontrol)) { + if (comboItems.size() > 2) { + matinsource.setComboItems(comboItems.subList(0, 2)); + } + } else { + matinsource.setComboItems(comboItems); + } + } else { + matinsource.setComboItems(comboItems); + } + + DynamicObject newCont = (DynamicObject) this.getModel().getValue("contract"); + if (newCont == null) { + if (project != null) { + this.getModel().setValue("fiaccountorg", project.getDynamicObject("fiaccountorg")); + } else { + this.setFiOrgByOrg(); + } + } + + this.setUnitProjectFieldStatus(); + this.getModel().setValue("unitprojectpro", (Object) null); + DynamicObject purChaseOrder = this.getModel().getDataEntity().getDynamicObject("purchaseorder"); + if (purChaseOrder != null) { + purChaseOrder = BusinessDataServiceHelper.loadSingle("ecma_purchaseorderbill", "id,project", new QFilter[]{new QFilter("id", "=", purChaseOrder.getPkValue())}); + if (project != null && purChaseOrder.getLong("project_id") != project.getLong("id")) { + this.getModel().setValue("purchaseorder", (Object) null); + } + + } + } + + private void transoftaxamountChanged(BigDecimal propValue) { + this.getModel().beginInit(); + BigDecimal curTaxAmount = EcNumberHelper.toBigDecimal(this.getModel().getValue("transtaxamount")); + BigDecimal exchangerate = (BigDecimal) this.getModel().getValue("exchangerate"); + this.getModel().setValue("stdtranoftaxamount", propValue.multiply(exchangerate)); + this.getModel().setValue("stdtranamount", propValue.subtract(curTaxAmount).multiply(exchangerate)); + this.getModel().endInit(); + this.getView().updateView("stdtranoftaxamount"); + this.getView().updateView("stdtranamount"); + this.summaryTotalOfTaxAmount(); + } + + private void transamountChanged(BigDecimal propValue) { + this.getModel().beginInit(); + BigDecimal curTaxAmount = EcNumberHelper.toBigDecimal(this.getModel().getValue("transtaxamount")); + BigDecimal exchangerate = (BigDecimal) this.getModel().getValue("exchangerate"); + this.getModel().setValue("stdtranamount", propValue.multiply(exchangerate)); + this.getModel().setValue("stdtranoftaxamount", curTaxAmount.add(propValue).multiply(exchangerate)); + this.getModel().endInit(); + this.getView().updateView("stdtranoftaxamount"); + this.getView().updateView("stdtranamount"); + this.summaryTotalAmount(); + } + + private void entryAmountChanged(BigDecimal propValue, int curIndex) { + boolean isAdjustamount = this.getModel().getDataEntity().getBoolean("adjustamount"); + boolean isAdjustoftax = this.getModel().getDataEntity().getBoolean("adjustoftax"); + boolean isInputtaxprice = this.getModel().getDataEntity().getBoolean("inputtaxprice"); + boolean isInputtotalprice = this.getModel().getDataEntity().getBoolean("inputtotalprice"); + int rowIndex = this.getModel().getEntryCurrentRowIndex("entryentity"); + BigDecimal taxrate; + if (isAdjustamount) { + BigDecimal oftaxamount = (BigDecimal) this.getView().getModel().getValue("oftaxamount", rowIndex); + taxrate = (BigDecimal) this.getView().getModel().getValue("notaxamount", rowIndex); + BigDecimal taxamount = oftaxamount.subtract(taxrate); + this.getView().getModel().setValue("taxamount", taxamount, rowIndex); + this.sumMaTaxAmount(); + } else if (isInputtotalprice && !isInputtaxprice && !isAdjustamount && !isAdjustoftax) { + DynamicObject mattaxrateObj = ((DynamicObject) this.getModel().getEntryEntity("entryentity").get(curIndex)).getDynamicObject("entrytaxrate"); + taxrate = new BigDecimal(0); + if (mattaxrateObj != null) { + taxrate = mattaxrateObj.getBigDecimal("taxrate"); + } + + this.updateNewDataBytotalPrice(curIndex, taxrate); + } + + this.countAmount(rowIndex); + } + + private void countAmount(int rowIndex) { + BigDecimal notaxamount = EcNumberHelper.toBigDecimal(this.getView().getModel().getValue("notaxamount", rowIndex)); + BigDecimal transamount = EcNumberHelper.toBigDecimal(this.getView().getModel().getValue("ftransamount", rowIndex)); + BigDecimal amount = notaxamount.add(transamount); + this.getModel().setValue("amount", amount, rowIndex); + } + + private void entryTaxamountChanged() { + EntryGrid grid1 = (EntryGrid) this.getControl("entryentity"); + BigDecimal sum1 = grid1.getSum("taxamount"); + this.getModel().setValue("mataxamount", sum1); + boolean isAdjustamount = this.getModel().getDataEntity().getBoolean("adjustamount"); + boolean isAdjustoftax = this.getModel().getDataEntity().getBoolean("adjustoftax"); + int rowIndex = this.getModel().getEntryCurrentRowIndex("entryentity"); + BigDecimal notaxamount; + BigDecimal taxamount; + BigDecimal oftaxamount; + if (isAdjustamount) { + notaxamount = (BigDecimal) this.getView().getModel().getValue("oftaxamount", rowIndex); + taxamount = (BigDecimal) this.getView().getModel().getValue("taxamount", rowIndex); + oftaxamount = notaxamount.subtract(taxamount); + this.getView().getModel().setValue("notaxamount", oftaxamount, rowIndex); + BigDecimal sum = grid1.getSum("notaxamount"); + this.getModel().setValue("matamount", sum); + } else if (isAdjustoftax) { + notaxamount = (BigDecimal) this.getView().getModel().getValue("notaxamount", rowIndex); + taxamount = (BigDecimal) this.getView().getModel().getValue("taxamount", rowIndex); + oftaxamount = notaxamount.add(taxamount); + this.getView().getModel().setValue("oftaxamount", oftaxamount, rowIndex); + this.sumMaoftaxAmount(); + } + + } + + private void oftaxamountChanged(BigDecimal propValue, int curIndex) { + boolean isAdjustamount = this.getModel().getDataEntity().getBoolean("adjustamount"); + boolean isAdjustoftax = this.getModel().getDataEntity().getBoolean("adjustoftax"); + boolean isInputtaxprice = this.getModel().getDataEntity().getBoolean("inputtaxprice"); + boolean isInputtotalprice = this.getModel().getDataEntity().getBoolean("inputtotalprice"); + int rowIndex = this.getModel().getEntryCurrentRowIndex("entryentity"); + BigDecimal taxPrice; + BigDecimal ofTaxAmount; + BigDecimal qty; + if (isAdjustoftax) { + taxPrice = (BigDecimal) this.getView().getModel().getValue("oftaxamount", rowIndex); + ofTaxAmount = (BigDecimal) this.getView().getModel().getValue("notaxamount", rowIndex); + qty = taxPrice.subtract(ofTaxAmount); + this.getView().getModel().setValue("taxamount", qty, rowIndex); + this.sumMaTaxAmount(); + } else { + if (isInputtaxprice && isInputtotalprice && !isAdjustamount && !isAdjustoftax) { + DynamicObject mattaxrateObj = ((DynamicObject) this.getModel().getEntryEntity("entryentity").get(curIndex)).getDynamicObject("entrytaxrate"); + ofTaxAmount = new BigDecimal(0); + if (mattaxrateObj != null) { + ofTaxAmount = mattaxrateObj.getBigDecimal("taxrate"); + } + + this.updateNewDataByTaxAndTotalPrice(curIndex, ofTaxAmount); + return; + } + + taxPrice = EcNumberHelper.toBigDecimal(this.getModel().getValue("taxprice", curIndex)); + ofTaxAmount = EcNumberHelper.toBigDecimal(this.getModel().getValue("oftaxamount", curIndex)); + qty = EcNumberHelper.toBigDecimal(this.getModel().getValue("qty", curIndex)); + BigDecimal taxRateNum = this.getTaxRateNum(); + if (taxRateNum.compareTo(BigDecimal.ZERO) == 0) { + this.getModel().setValue("notaxamount", ofTaxAmount, curIndex); + } + + if (taxPrice.compareTo(BigDecimal.ZERO) == 0 && ofTaxAmount.compareTo(BigDecimal.ZERO) != 0 && qty.compareTo(BigDecimal.ZERO) != 0) { + taxPrice = ofTaxAmount.divide(qty, 10, RoundingMode.HALF_UP); + this.getModel().setValue("taxprice", taxPrice, curIndex); + } + } + + this.sumMaoftaxAmount(); + } + + private void sumMaoftaxAmount() { + EntryGrid grid = (EntryGrid) this.getControl("entryentity"); + BigDecimal sum = grid.getSum("oftaxamount"); + this.getModel().setValue("matoftaxamount", sum); + } + + private void sumMaTaxAmount() { + EntryGrid grid = (EntryGrid) this.getControl("entryentity"); + BigDecimal sum = grid.getSum("taxamount"); + this.getModel().setValue("mataxamount", sum); + } + + private void sumMaAmount() { + EntryGrid grid = (EntryGrid) this.getControl("entryentity"); + BigDecimal sum = grid.getSum("notaxamount"); + this.getModel().setValue("matamount", sum); + } + + private void lotF7Changed(DynamicObject propValue, int curIndex) { + boolean lotEnableEdit = true; + if (propValue != null) { + lotEnableEdit = false; + this.getModel().setValue("lot", propValue.getString("number"), curIndex); + this.getModel().setValue("modelnum", propValue.getString("modelnum"), curIndex); + } else { + this.getModel().setValue("lot", (Object) null, curIndex); + this.getModel().setValue("modelnum", (Object) null, curIndex); + } + + this.getView().setEnable(lotEnableEdit, curIndex, new String[]{"lot"}); + } + + private void taxPriceChanged(BigDecimal propValue, int curIndex) { + boolean isAdjustamount = this.getModel().getDataEntity().getBoolean("adjustamount"); + boolean isAdjustoftax = this.getModel().getDataEntity().getBoolean("adjustoftax"); + boolean isInputtaxprice = this.getModel().getDataEntity().getBoolean("inputtaxprice"); + boolean isInputtotalprice = this.getModel().getDataEntity().getBoolean("inputtotalprice"); + DynamicObject mattaxrateObj = ((DynamicObject) this.getModel().getEntryEntity("entryentity").get(curIndex)).getDynamicObject("entrytaxrate"); + BigDecimal taxrate = new BigDecimal(0); + if (mattaxrateObj != null) { + taxrate = mattaxrateObj.getBigDecimal("taxrate"); + } + + if (isInputtaxprice && !isAdjustamount && !isAdjustoftax && !isInputtotalprice) { + this.updateNewData(curIndex, taxrate); + } + + } + + private void entryQtyChanged(BigDecimal propValue, int curIndex) { + boolean isAdjustamount = this.getModel().getDataEntity().getBoolean("adjustamount"); + boolean isAdjustoftax = this.getModel().getDataEntity().getBoolean("adjustoftax"); + boolean isInputtaxprice = this.getModel().getDataEntity().getBoolean("inputtaxprice"); + boolean isInputtotalprice = this.getModel().getDataEntity().getBoolean("inputtotalprice"); + DynamicObject mattaxrateObj = ((DynamicObject) this.getModel().getEntryEntity("entryentity").get(curIndex)).getDynamicObject("entrytaxrate"); + BigDecimal taxrate = new BigDecimal(0); + if (mattaxrateObj != null) { + taxrate = mattaxrateObj.getBigDecimal("taxrate"); + } + + if (isInputtaxprice && !isInputtotalprice && !isAdjustamount && !isAdjustoftax) { + this.updateNewData(curIndex, taxrate); + } else if (isInputtotalprice && !isInputtaxprice && !isAdjustamount && !isAdjustoftax) { + this.updateNewDataBytotalPrice(curIndex, taxrate); + } else if (isInputtaxprice && isInputtotalprice && !isAdjustamount && !isAdjustoftax) { + this.updateNewDataByTaxAndTotalPrice(curIndex, taxrate); + } else if (!isInputtaxprice && !isAdjustamount && !isAdjustoftax && !isInputtotalprice) { + this.initPageCountLogic(curIndex, taxrate); + } + + } + + private void warehouseChanged(DynamicObject propValue) { + if (propValue != null) { + this.getModel().setValue("project", propValue.get("project")); + this.getModel().setValue("unitprojectpro", propValue.get("unitproject")); + this.getView().setEnable(false, new String[]{"unitprojectpro"}); + } else { + this.getModel().setValue("project", (Object) null); + this.getModel().setValue("unitprojectpro", (Object) null); + this.getView().setEnable(true, new String[]{"unitprojectpro"}); + } + + } + + private void transtypeChanged(DynamicObject propValue) { + boolean impactcost = propValue == null ? false : (Boolean) propValue.get("impactcost"); + BasedataEdit projectControl = (BasedataEdit) this.getControl("project"); + projectControl.setMustInput(impactcost); + BasedataEdit warehouse = (BasedataEdit) this.getControl("warehouse"); + if (impactcost) { + String type = propValue.getString("type"); + String inOutType = propValue.getString("inouttype"); + if ("UNIMPACT".equals(type) && "IN".equals(inOutType)) { + warehouse.setQFilters(new ArrayList()); + } else { + warehouse.setQFilter(new QFilter("project", "!=", 0)); + DynamicObject wareHouseobj = (DynamicObject) this.getModel().getValue("warehouse"); + if (wareHouseobj != null && wareHouseobj.get("project") == null) { + this.getModel().setValue("warehouse", (Object) null); + } + } + } else { + warehouse.setQFilters(new ArrayList()); + BasedataEdit procbsControl = (BasedataEdit) this.getControl("procbs"); + procbsControl.setMustInput(false); + BasedataEdit caControl = (BasedataEdit) this.getControl("ca"); + caControl.setMustInput(false); + BasedataEdit proboqControl = (BasedataEdit) this.getControl("proboq"); + proboqControl.setMustInput(false); + } + + this.getView().setVisible(impactcost, new String[]{"ismainmaterial", "procbs", "ca", "proboq"}); + int entryRowCount = this.getModel().getEntryRowCount("entryentity"); + + for (int i = 0; i < entryRowCount; ++i) { + this.getModel().setValue("ismainmaterial", impactcost, i); + } + + } + + private void purchaseOrderChanged(DynamicObject propValue, int curIndex) { + String entryCache = this.getPageCache().get(entrySourceCaChe); + if (entryCache == null) { + entryCache = ""; + } + + if (entryCache.equals("purChaseOrderSource")) { + this.clearEntryData(); + } + + if (propValue != null) { + if (propValue.get("contract") != null) { + this.getModel().setValue("contract", ((DynamicObject) propValue.get("contract")).getPkValue(), curIndex); + } else { + this.getModel().setValue("supplier", propValue.get("supplier")); + this.getView().setEnable(false, new String[]{"supplier"}); + } + + this.getModel().setValue("project", propValue.get("project")); + this.getModel().setValue("unitprojectpro", propValue.get("unitproject")); + } else { + this.getView().setEnable(true, new String[]{"supplier"}); + this.getModel().setValue("supplier", (Object) null); + } + + String materialSource = (String) this.getModel().getValue("matinsource"); + DynamicObject warehouse = this.getModel().getDataEntity().getDynamicObject("warehouse"); + boolean isHadWareHousePro = false; + if (warehouse != null) { + DynamicObject project = warehouse.getDynamicObject("project"); + if (project != null) { + isHadWareHousePro = true; + } + } + + boolean isHadWareHouseProUnit = false; + if (warehouse != null) { + DynamicObject unitproject = warehouse.getDynamicObject("unitproject"); + if (unitproject != null) { + isHadWareHouseProUnit = true; + } + } + + if (StringUtils.equals("2", materialSource) && propValue == null) { + if (!isHadWareHousePro) { + this.getModel().setValue("project", (Object) null); + } + + if (!isHadWareHouseProUnit) { + this.getModel().setValue("unitprojectpro", (Object) null); + } + + this.getModel().setValue("contract", (Object) null); + } + + this.getModel().updateCache(); + this.sumMaAmount(); + this.sumMaoftaxAmount(); + this.sumMaTaxAmount(); + this.getPageCache().put(entrySourceCaChe, (String) null); + } + + private void contractChanged(DynamicObject propValue) { + DynamicObject order = (DynamicObject) this.getModel().getValue("purchaseorder"); + DynamicObject warehouse; + DynamicObject project; + if (propValue != null) { + if (order != null) { + warehouse = order.getDynamicObject("contract"); + if (warehouse != null) { + if (!warehouse.getPkValue().equals(propValue.getPkValue())) { + this.getModel().setValue("purchaseorder", (Object) null); + } + } else { + this.getModel().setValue("purchaseorder", (Object) null); + } + } + + warehouse = (DynamicObject) this.getModel().getValue("warehouse"); + project = propValue.getDynamicObject("project"); + if (project != null) { + this.getModel().setValue("project", project.getPkValue()); + } else if (warehouse != null) { + DynamicObject wareProject = warehouse.getDynamicObject("project"); + if (wareProject == null) { + this.getModel().setValue("project", (Object) null); + } + } else { + this.getModel().setValue("project", (Object) null); + } + + this.getModel().setValue("supplier", propValue.get("partb")); + this.getView().setEnable(false, new String[]{"supplier"}); + } else { + if (order != null) { + this.getModel().setValue("purchaseorder", (Object) null); + } + + this.getModel().setValue("supplier", (Object) null); + this.getView().setEnable(true, new String[]{"supplier"}); + this.getView().updateView("supplier"); + warehouse = (DynamicObject) this.getModel().getValue("warehouse"); + if (warehouse != null) { + project = warehouse.getDynamicObject("project"); + if (project == null) { + this.getModel().setValue("project", (Object) null); + } + } else { + this.getModel().setValue("project", (Object) null); + } + + project = (DynamicObject) this.getModel().getValue("project"); + if (project != null) { + this.getModel().setValue("fiaccountorg", project.getDynamicObject("fiaccountorg")); + } + } + + String entrySource = this.getPageCache().get(entrySourceCaChe); + if (entrySource == null) { + entrySource = ""; + } + + String materialSource = (String) this.getModel().getValue("matinsource"); + if (entrySource.equals("contractSource") || StringUtils.equals(materialSource, "1")) { + this.clearEntryData(); + } + + } + + protected void clearEntryData() { + this.getModel().deleteEntryData("entryentity"); + this.getModel().setValue("matamount", BigDecimal.ZERO); + this.getModel().setValue("matoftaxamount", BigDecimal.ZERO); + this.getModel().setValue("mataxamount", BigDecimal.ZERO); + this.getModel().setValue("transamount", BigDecimal.ZERO); + this.getModel().setValue("transoftaxamount", BigDecimal.ZERO); + this.getModel().setValue("transtaxamount", BigDecimal.ZERO); + } + + private void entryMaterialChanged(DynamicObject propValue, int curIndex) { + if (propValue != null) { + String modelNum = propValue.getString("model"); + DynamicObject measureUnit = propValue.getDynamicObject("measureunit"); + String measureUnitId = null; + if (measureUnit != null) { + measureUnitId = measureUnit.getString("id"); + } + + this.getModel().setValue("modelnum", modelNum, curIndex); + this.getModel().setValue("measureunit", measureUnitId, curIndex); + String matinSourceName = (String) this.getModel().getValue("matinsource"); + if ("4".equals(matinSourceName)) { + BigDecimal priceValue = propValue.getBigDecimal("price"); + this.getModel().setValue("price", priceValue, curIndex); + } + } else { + this.getModel().setValue("measureunit", (Object) null, curIndex); + this.getModel().setValue("modelnum", (Object) null, curIndex); + this.getModel().setValue("qty", (Object) null, curIndex); + this.getModel().setValue("contprice", (Object) null, curIndex); + this.getModel().setValue("price", (Object) null, curIndex); + this.getModel().setValue("taxprice", (Object) null, curIndex); + this.getModel().setValue("notaxamount", (Object) null, curIndex); + this.getModel().setValue("amount", (Object) null, curIndex); + this.getModel().setValue("procbs", (Object) null, curIndex); + this.getModel().setValue("ca", (Object) null, curIndex); + this.getModel().setValue("ftransamount", (Object) null, curIndex); + this.getModel().setValue("ismainmaterial", (Object) null, curIndex); + this.getModel().setValue("lot", (Object) null, curIndex); + this.getModel().setValue("lotid", (Object) null, curIndex); + this.getModel().setValue("oftaxamount", (Object) null, curIndex); + this.getModel().setValue("taxamount", (Object) null, curIndex); + } + + this.changValueInitPage(curIndex); + } + + protected void changValueInitPage(int curIndex) { + boolean isAdjustamount = this.getModel().getDataEntity().getBoolean("adjustamount"); + boolean isAdjustoftax = this.getModel().getDataEntity().getBoolean("adjustoftax"); + boolean isInputtaxprice = this.getModel().getDataEntity().getBoolean("inputtaxprice"); + boolean isInputtotalprice = this.getModel().getDataEntity().getBoolean("inputtotalprice"); + if (isInputtaxprice && !isInputtotalprice && !isAdjustamount && !isAdjustoftax) { + this.onlyOpenInputtaxprice(curIndex); + } else if (isInputtotalprice && !isAdjustamount && !isAdjustoftax && !isInputtaxprice) { + this.onlyOpenInputtotalprice(curIndex); + } else if (isInputtotalprice && isInputtaxprice && !isAdjustamount && !isAdjustoftax) { + this.openTaxPriceAndtotalPrice(curIndex); + } else if (isAdjustamount) { + this.openContainAdjustamount(curIndex); + } else if (isAdjustoftax) { + this.openContainAjustoftax(curIndex); + } else { + this.initFormPage(curIndex); + } + + } + + public void beforeDoOperation(BeforeDoOperationEventArgs args) { + FormOperate operate = (FormOperate) args.getSource(); + switch (operate.getOperateKey()) { + case "autogenlot": + this.doGenLot(args); + break; + case "enablelot": + this.getView().setVisible(true, new String[]{"lotid", "lot"}); + break; + case "disablelot": + this.doDisableLot(); + break; + case "poundfetch": + this.doFetchPoundData(args); + break; + case "selcontlist": + this.doSelContList(); + break; + case "selorderlist": + this.doSelOrderList(); + break; + case "transsplit": + this.transSplit(); + break; + case "submit": + this.showSplitAmount(); + break; + case "viewreconcile": + this.viewReconcile(); + } + + super.beforeDoOperation(args); + } + + protected void transSplit() { + FormShowParameter transSplitFormParameter = new FormShowParameter(); + transSplitFormParameter.setFormId(MetaDataUtil.getEntityId("ecma", "transsplit")); + transSplitFormParameter.getOpenStyle().setShowType(ShowType.Modal); + transSplitFormParameter.setCloseCallBack(new CloseCallBack(this, MetaDataUtil.getEntityId("ecma", "transsplit"))); + this.getView().showForm(transSplitFormParameter); + } + + protected void viewReconcile() { + Object reconcileid = this.getView().getModel().getDataEntity().get("reconcileid"); + Map paramMap = new HashMap(); + paramMap.put("formId", "ecma_reconciliation"); + paramMap.put("pkId", String.valueOf(reconcileid)); + FormShowParameter showParameter = FormShowParameter.createFormShowParameter(paramMap); + showParameter.getOpenStyle().setShowType(ShowType.MainNewTabPage); + this.getView().showForm(showParameter); + } + + private void doSelOrderList() { + DynamicObject order = (DynamicObject) this.getModel().getValue("purchaseorder"); + if (order == null) { + this.getView().showTipNotification(ResManager.loadKDString("请选择采购订单。", "MaterialInBillEditPlugin_0", "ec-ecma-formplugin", new Object[0])); + } else { + ListShowParameter orderEntryParam = ShowFormHelper.createShowListForm("ecma_purchaseorderentry", true); + Long orderId = order.getLong("id"); + orderEntryParam.getListFilterParameter().getQFilters().add(new QFilter("orderentryid", "=", orderId)); + orderEntryParam.getListFilterParameter().getQFilters().add(new QFilter("surplusqty", ">", 0)); + orderEntryParam.setFormId("ecbd_listf7"); + CloseCallBack orderEntryCallback = new CloseCallBack(this, "selorderlist"); + orderEntryParam.setCloseCallBack(orderEntryCallback); + int entryRowCount = this.getModel().getEntryRowCount("entryentity"); + List selectedIds = new ArrayList(); + + for (int i = 0; i < entryRowCount; ++i) { + String id = (String) this.getModel().getValue("orderentryid", i); + if (StringUtils.isNotBlank(id)) { + selectedIds.add(Long.valueOf(id)); + } + } + + orderEntryParam.getListFilterParameter().getQFilters().add(new QFilter("id", "not in", selectedIds.toArray())); + this.getView().showForm(orderEntryParam); + } + } + + private void setOrderList() { + } + + private void doSelContList() { + DynamicObject contract = (DynamicObject) this.getModel().getValue("contract"); + if (contract == null) { + this.getView().showTipNotification(ResManager.loadKDString("请先选择合同。", "MaterialInBillEditPlugin_1", "ec-ecma-formplugin", new Object[0])); + } else { + boolean editunit = false; + DynamicObject project = (DynamicObject) this.getModel().getValue("project"); + DynamicObject unitproject = (DynamicObject) this.getModel().getValue("unitprojectpro"); + if (project != null) { + editunit = project.getBoolean("editonunit"); + } + + ListShowParameter parameter = ShowFormHelper.createShowListForm("ec_outtreelisting", true, 3, true); + parameter.getCustomParams().put("isFromMat", "true"); + Long contId = contract.getLong("id"); + parameter.getListFilterParameter().getQFilters().add(new QFilter("contractid", "=", contId)); + parameter.getListFilterParameter().getQFilters().add(new QFilter("resourceitem", "!=", 0)); + int rowCount = this.getModel().getEntryRowCount("entryentity"); + List selIds = new ArrayList(); + + for (int i = 0; i < rowCount; ++i) { + String id = (String) this.getModel().getValue("listingid", i); + if (StringUtils.isNotBlank(id)) { + selIds.add(Long.valueOf(id)); + } + } + + parameter.getListFilterParameter().getQFilters().add(new QFilter(OutTreeListingConstant.ID_ENTITY_PK, "not in", selIds.toArray())); + if (editunit && unitproject != null) { + QFilter filter = new QFilter("listunitproject", "in", new Object[]{unitproject.getPkValue(), 0}); + parameter.getListFilterParameter().getQFilters().add(filter); + } + + CloseCallBack callBack = new CloseCallBack(this, "selcontlist"); + parameter.setCloseCallBack(callBack); + this.getView().showForm(parameter); + } + } + + private void doNotSplitTransCost() { + this.getView().setVisible(false, new String[]{"ftransamount", "amount"}); + int entryRowCount2 = this.getModel().getEntryRowCount("entryentity"); + + for (int i = 0; i < entryRowCount2; ++i) { + this.getModel().setValue("ftransamount", (Object) null, i); + BigDecimal amount = (BigDecimal) this.getModel().getValue("notaxamount", i); + this.getModel().setValue("amount", amount, i); + } + + } + + private void doAutoTransCostSplit() { + this.getView().setVisible(true, new String[]{"ftransamount", "amount"}); + BigDecimal transamount = (BigDecimal) this.getModel().getValue("transamount"); + int entryRowCount3 = this.getModel().getEntryRowCount("entryentity"); + EntryGrid grid = (EntryGrid) this.getView().getControl("entryentity"); + BigDecimal totalAmount = grid.getSum("notaxamount"); + if (transamount.compareTo(BigDecimal.ZERO) == 0) { + this.getView().showTipNotification(ResManager.loadKDString("请填写表头运费不含税金额。", "MaterialInBillEditPlugin_2", "ec-ecma-formplugin", new Object[0])); + } else if (totalAmount.compareTo(BigDecimal.ZERO) == 0) { + this.getView().showTipNotification(ResManager.loadKDString("请填写入库单明细的金额(不含税)字段。", "MaterialInBillEditPlugin_3", "ec-ecma-formplugin", new Object[0])); + } else { + this.getModel().beginInit(); + + for (int i = 0; i < entryRowCount3; ++i) { + BigDecimal amount = (BigDecimal) this.getModel().getValue("notaxamount", i); + BigDecimal splitAmount = amount.divide(totalAmount, 10, RoundingMode.CEILING).multiply(transamount); + this.getModel().setValue("ftransamount", splitAmount, i); + this.getModel().setValue("amount", splitAmount.add(amount), i); + } + + this.getModel().endInit(); + this.getView().updateView("entryentity"); + } + } + + private void doTransSplit() { + this.getView().setVisible(true, new String[]{"ftransamount", "amount"}); + BigDecimal transamount = (BigDecimal) this.getModel().getValue("transamount"); + BigDecimal transoftaxamount = (BigDecimal) this.getModel().getValue("transoftaxamount"); + int entryRowCount3 = this.getModel().getEntryRowCount("entryentity"); + EntryGrid grid = (EntryGrid) this.getView().getControl("entryentity"); + BigDecimal totalAmount = grid.getSum("notaxamount"); + if (totalAmount.compareTo(BigDecimal.ZERO) == 0) { + this.getView().showTipNotification(ResManager.loadKDString("请填写入库单明细的金额(不含税)字段。", "MaterialInBillEditPlugin_3", "ec-ecma-formplugin", new Object[0])); + } else { + String splitType = this.getView().getModel().getDataEntity().getString("splittype"); + BigDecimal recordTransamount; + BigDecimal recordTransoftaxamount; + BigDecimal lastTransamount; + BigDecimal lastTransoftaxamount; + BigDecimal splitTaxAmount; + BigDecimal amount; + if ("1".equals(splitType)) { + recordTransamount = transamount.divide(new BigDecimal(entryRowCount3), 10, RoundingMode.CEILING); + recordTransoftaxamount = transoftaxamount.divide(new BigDecimal(entryRowCount3), 10, RoundingMode.CEILING); + this.getModel().beginInit(); + lastTransamount = new BigDecimal(0); + lastTransoftaxamount = new BigDecimal(0); + + for (int i = 0; i < entryRowCount3 - 1; ++i) { + splitTaxAmount = (BigDecimal) this.getModel().getValue("notaxamount", i); + this.getModel().setValue("ftransamount", recordTransamount, i); + lastTransamount = EcNumberHelper.add(lastTransamount, this.getModel().getValue("ftransamount", i)); + this.getModel().setValue("taxtransamount", recordTransoftaxamount, i); + lastTransoftaxamount = EcNumberHelper.add(lastTransoftaxamount, this.getModel().getValue("taxtransamount", i)); + this.getModel().setValue("amount", recordTransamount.add(splitTaxAmount), i); + } + + amount = transamount.subtract(lastTransamount); + splitTaxAmount = transoftaxamount.subtract(lastTransoftaxamount); +// BigDecimal amount = (BigDecimal)this.getModel().getValue("notaxamount", entryRowCount3 - 1);//系统默认 + amount = (BigDecimal) this.getModel().getValue("notaxamount", entryRowCount3 - 1);//二开替换 + this.getModel().setValue("ftransamount", amount, entryRowCount3 - 1); + this.getModel().setValue("taxtransamount", splitTaxAmount, entryRowCount3 - 1); + this.getModel().setValue("amount", EcNumberHelper.add(this.getModel().getValue("ftransamount", entryRowCount3 - 1), amount), entryRowCount3 - 1); + this.getModel().endInit(); + } else if ("2".equals(splitType)) { + this.getModel().beginInit(); + recordTransamount = new BigDecimal(0); + recordTransoftaxamount = new BigDecimal(0); + + for (int i = 0; i < entryRowCount3 - 1; ++i) { + lastTransoftaxamount = (BigDecimal) this.getModel().getValue("notaxamount", i); + amount = lastTransoftaxamount.divide(totalAmount, 10, RoundingMode.CEILING).multiply(transamount); + splitTaxAmount = lastTransoftaxamount.divide(totalAmount, 10, RoundingMode.CEILING).multiply(transoftaxamount); + this.getModel().setValue("ftransamount", amount, i); + recordTransamount = EcNumberHelper.add(recordTransamount, this.getModel().getValue("ftransamount", i)); + this.getModel().setValue("taxtransamount", splitTaxAmount, i); + recordTransoftaxamount = EcNumberHelper.add(recordTransoftaxamount, this.getModel().getValue("taxtransamount", i)); + this.getModel().setValue("amount", amount.add(lastTransoftaxamount), i); + } + + lastTransamount = transamount.subtract(recordTransamount); + lastTransoftaxamount = transoftaxamount.subtract(recordTransoftaxamount); + amount = (BigDecimal) this.getModel().getValue("notaxamount", entryRowCount3 - 1); + this.getModel().setValue("ftransamount", lastTransamount, entryRowCount3 - 1); + this.getModel().setValue("taxtransamount", lastTransoftaxamount, entryRowCount3 - 1); + this.getModel().setValue("amount", EcNumberHelper.add(this.getModel().getValue("ftransamount", entryRowCount3 - 1), amount), entryRowCount3 - 1); + this.getModel().endInit(); + } else { + for (int i = 0; i < entryRowCount3; ++i) { + this.getModel().setValue("ftransamount", 0, i); + this.getModel().setValue("taxtransamount", 0, i); + } + } + + this.getView().updateView("entryentity"); + this.fieldLockLogic(); + } + } + + private void doDisableLot() { + this.getView().setVisible(false, new String[]{"lotid", "lot"}); + int entryRowCount1 = this.getModel().getEntryRowCount("entryentity"); + + for (int i = 0; i < entryRowCount1; ++i) { + this.getModel().setValue("lot", (Object) null, i); + this.getModel().setValue("lotid", (Object) null, i); + } + + } + + private void doGenLot(BeforeDoOperationEventArgs args) { + this.getView().setVisible(true, new String[]{"lotid", "lot"}); + EntryGrid entryGrid = (EntryGrid) this.getView().getControl("entryentity"); + int[] selectRows = entryGrid.getSelectRows(); + if (selectRows.length < 1) { + this.getView().showTipNotification(ResManager.loadKDString("请选择需要自动生成批次的分录。", "MaterialInBillEditPlugin_4", "ec-ecma-formplugin", new Object[0])); + args.setCancel(true); + } else { + Date date = this.getModel().getValue("bizdate") != null ? (Date) this.getModel().getValue("bizdate") : new Date(); + String dateStr = DateFormatUtils.format(date, "yyyyMMddHHmmss"); + QFilter numFilter = new QFilter("number", "like", dateStr + "%"); + QFilter materialFilter = null; + int[] var8 = selectRows; + int var9 = selectRows.length; + + for (int var10 = 0; var10 < var9; ++var10) { + int i = var8[var10]; + DynamicObject material = (DynamicObject) this.getModel().getValue("material", i); + String modelNum = (String) this.getModel().getValue("modelnum", i); + if (material == null) { + this.getView().showTipNotification(ResManager.loadKDString("请选择物料,再生成批次。", "MaterialInBillEditPlugin_5", "ec-ecma-formplugin", new Object[0])); + break; + } + + materialFilter = new QFilter("material", "=", material.getPkValue()); + if (modelNum != null) { + materialFilter.and(new QFilter("modelnum", "=", modelNum)); + } + + DynamicObject bill = this.getModel().getDataEntity(); + materialFilter.and(new QFilter("org", "=", bill.getDynamicObject("org").getPkValue())); + materialFilter.and(new QFilter("warehouse", "=", bill.getDynamicObject("warehouse").getPkValue())); + if (bill.get("project") != null) { + materialFilter.and(new QFilter("project", "=", bill.getDynamicObject("project").getPkValue())); + } + + if (bill.get("unitprojectpro") != null) { + materialFilter.and(new QFilter("unitprojectpro", "=", bill.getDynamicObject("unitprojectpro").getPkValue())); + } + + materialFilter.and(new QFilter("bizdate", "=", bill.getDate("bizdate"))); + DynamicObject[] lotObjs = BusinessDataServiceHelper.load("ecma_material_lot", "id,number,material", new QFilter[]{numFilter, materialFilter}); + String genNum = ""; + if (lotObjs.length < 1) { + genNum = dateStr + StringHelper.formatString(3, 0); + } else { + int max = Arrays.stream(lotObjs).mapToInt((obj) -> { + String number = obj.getString("number").replace(dateStr, ""); + return Integer.valueOf(number); + }).max().getAsInt(); + genNum = dateStr + StringHelper.formatString(3, max); + } + + this.getModel().setValue("lot", genNum, i); + } + + } + } + + public void afterDoOperation(AfterDoOperationEventArgs e) { + super.afterDoOperation(e); + switch (e.getOperateKey()) { + case "deleentry": + this.getModel().beginInit(); + this.sumMaAmount(); + this.clearHead(); + this.sumMaoftaxAmount(); + this.sumMaTaxAmount(); + EntryGrid grid = (EntryGrid) this.getControl("entryentity"); + BigDecimal sum = grid.getSum("ftransamount"); + this.getView().updateView("matamount"); + this.getView().updateView("matoftaxamount"); + this.getView().updateView("mataxamount"); + this.summaryTotalTaxAmount(); + this.summaryTotalOfTaxAmount(); + this.summaryTotalAmount(); + this.getModel().endInit(); + this.getView().updateView("totalamount"); + this.getView().updateView("totaloftaxamount"); + this.getView().updateView("totaltaxamount"); + break; + case "unaudit": + this.getView().invokeOperation("refresh"); + break; + case "newentry": + int rowIndex = this.getModel().getEntryCurrentRowIndex("entryentity"); + boolean isAdjustamount = this.getModel().getDataEntity().getBoolean("adjustamount"); + boolean isAdjustoftax = this.getModel().getDataEntity().getBoolean("adjustoftax"); + boolean isInputtaxprice = this.getModel().getDataEntity().getBoolean("inputtaxprice"); + boolean isInputtotalprice = this.getModel().getDataEntity().getBoolean("inputtotalprice"); + if (isInputtaxprice && !isInputtotalprice && !isAdjustamount && !isAdjustoftax) { + this.onlyOpenInputtaxprice(rowIndex); + } else if (isInputtotalprice && !isAdjustamount && !isAdjustoftax && !isInputtaxprice) { + this.onlyOpenInputtotalprice(rowIndex); + } else if (isInputtotalprice && isInputtaxprice && !isAdjustamount && !isAdjustoftax) { + this.openTaxPriceAndtotalPrice(rowIndex); + } else if (isAdjustamount) { + this.openContainAdjustamount(rowIndex); + } else if (isAdjustoftax) { + this.openContainAjustoftax(rowIndex); + } else { + this.initFormPage(rowIndex); + } + } + + } + + protected void clearHead() { + int entryentity = this.getModel().getEntryRowCount("entryentity"); + DynamicObject warehouse = (DynamicObject) this.getModel().getValue("warehouse"); + if (entryentity <= 0 && (warehouse == null || warehouse.get("unitproject") == null)) { + this.getModel().beginInit(); + this.getModel().setValue("unitprojectpro", (Object) null); + this.getModel().endInit(); + this.getView().updateView("unitprojectpro"); + } + + } + + public void afterAddRow(AfterAddRowEventArgs e) { + String entryName = e.getEntryProp().getName(); + if (StringUtils.equals(entryName, "entryentity")) { + RowDataEntity[] rowDataEntities = e.getRowDataEntities(); + DynamicObject rate = this.getModel().getDataEntity().getDynamicObject("mataxrate"); + if (rowDataEntities == null || rowDataEntities.length == 0 || rate == null) { + return; + } + + RowDataEntity[] var5 = rowDataEntities; + int var6 = rowDataEntities.length; + + for (int var7 = 0; var7 < var6; ++var7) { + RowDataEntity rowDataEntity = var5[var7]; + this.getModel().setValue("entrytaxrate", rate.getPkValue(), rowDataEntity.getRowIndex()); + } + } + + } + + public void closedCallBack(ClosedCallBackEvent closedCallBackEvent) { + super.closedCallBack(closedCallBackEvent); + DynamicObject cbsInfo; + switch (closedCallBackEvent.getActionId()) { + case "selcontlist": + ListSelectedRowCollection rows = (ListSelectedRowCollection) closedCallBackEvent.getReturnData(); + if (rows != null && rows.size() > 0) { + List listIds = (List) rows.stream().map((obj) -> { + return obj.getPrimaryKeyValue(); + }).collect(Collectors.toList()); + DynamicObject[] listings = BusinessDataServiceHelper.load(listIds.toArray(new Long[listIds.size()]), EntityMetadataCache.getDataEntityType("ec_outtreelisting")); + this.fillEntryByContListing(listings); + this.fieldLockLogic(); + break; + } + + return; + case "selorderlist": + ListSelectedRowCollection rows1 = (ListSelectedRowCollection) closedCallBackEvent.getReturnData(); + if (rows1 != null && rows1.size() > 0) { + List listIds1 = (List) rows1.stream().map((obj) -> { + return obj.getPrimaryKeyValue(); + }).collect(Collectors.toList()); + DynamicObject[] purchaseorderentries = BusinessDataServiceHelper.load(listIds1.toArray(new Long[listIds1.size()]), EntityMetadataCache.getDataEntityType("ecma_purchaseorderentry")); + this.fillEntryByOrderListing(purchaseorderentries); + this.fieldLockLogic(); + break; + } + + return; + case "PROJECTCBS": + int row = this.getModel().getEntryCurrentRowIndex("entryentity"); + if (closedCallBackEvent.getReturnData() == null) { + break; + } + + List selectList = (ArrayList) closedCallBackEvent.getReturnData(); + if (selectList != null && selectList.size() >= 1) { + for (int i = 0; i < selectList.size(); ++i) { + cbsInfo = BusinessDataServiceHelper.loadSingle(selectList.get(i), EntityMetadataCache.getDataEntityType("ec_ecbd_pro_cbs")); + if (null != cbsInfo) { + this.getModel().setValue("procbs", cbsInfo.getPkValue(), row); + } + } + + return; + } + + return; + case "ecma_transsplit": + Object returnData = closedCallBackEvent.getReturnData(); + if (returnData == null) { + return; + } + + Map splitMap = (Map) returnData; + cbsInfo = (DynamicObject) splitMap.get("taxrate"); + BigDecimal transamount = (BigDecimal) splitMap.get("transamount"); + String splittype = (String) splitMap.get("splittype"); + BigDecimal transoftaxamount = (BigDecimal) splitMap.get("transoftaxamount"); + BigDecimal transtaxamount = (BigDecimal) splitMap.get("transtaxamount"); + this.getModel().beginInit(); + this.getView().getModel().setValue("transamount", transamount); + this.getView().getModel().setValue("transoftaxamount", transoftaxamount); + this.getView().getModel().setValue("transtaxamount", transtaxamount); + this.getView().getModel().setValue("splittype", splittype); + this.getView().getModel().setValue("taxrate", cbsInfo); + this.getModel().endInit(); + this.transamountChanged(transamount); + this.transoftaxamountChanged(transoftaxamount); + this.transtaxamountChanged(transtaxamount); + this.getView().updateView("transamount"); + this.getView().updateView("transoftaxamount"); + this.getView().updateView("transtaxamount"); + this.getView().updateView("splittype"); + this.getView().updateView("taxrate"); + this.getView().updateView("totalamount"); + this.getView().updateView("totaltaxamount"); + this.getView().updateView("totaloftaxamount"); + this.doTransSplit(); + } + + } + + private void fillEntryByOrderListing(DynamicObject[] orderEntries) { + this.getPageCache().put(entrySourceCaChe, "purChaseOrderSource"); + DynamicObject[] var2 = orderEntries; + int var3 = orderEntries.length; + + for (int var4 = 0; var4 < var3; ++var4) { + DynamicObject o = var2[var4]; + if (o.getBigDecimal("surplusqty").compareTo(BigDecimal.ZERO) > 0) { + int row = this.getModel().createNewEntryRow("entryentity"); + this.getModel().updateCache(); + if (o.getDynamicObject("material") != null) { + this.getModel().setValue("material", o.getDynamicObject("material").getPkValue(), row); + } + + this.getModel().setValue("modelnum", o.get("modelnum"), row); + if (o.getDynamicObject("measureunit") != null) { + this.getModel().setValue("measureunit", o.getDynamicObject("measureunit").getPkValue(), row); + } else { + this.getModel().setValue("measureunit", (Object) null, row); + } + + this.getModel().setValue("entrytaxrate", o.get("entrytaxrate"), row); + this.getModel().beginInit(); + this.getModel().setValue("qty", o.get("surplusqty"), row); + this.getModel().setValue("contprice", o.get("price"), row); + this.getModel().setValue("taxprice", o.get("price"), row); + this.getModel().setValue("price", o.get("oftaxprice"), row); + this.getModel().setValue("notaxamount", o.get("oftaxamount"), row); + this.getModel().setValue("oftaxamount", o.get("oftaxamt"), row); + this.getModel().setValue("taxamount", o.get("taxamount"), row); + this.getModel().endInit(); + this.getView().updateView("qty", row); + this.getView().updateView("taxprice", row); + this.getView().updateView("contprice", row); + this.getView().updateView("entrytaxrate", row); + this.getView().updateView("price", row); + this.getView().updateView("notaxamount", row); + this.getView().updateView("oftaxamount", row); + this.getView().updateView("taxamount", row); + DynamicObject mattaxrateObj = ((DynamicObject) this.getModel().getEntryEntity("entryentity").get(row)).getDynamicObject("entrytaxrate"); + BigDecimal taxrate = new BigDecimal(0); + if (mattaxrateObj != null) { + taxrate = mattaxrateObj.getBigDecimal("taxrate"); + } + + this.initContAndOrderData(row, taxrate); + this.getModel().setValue("orderentryid", o.getPkValue(), row); + } + } + + } + + private void fillEntryByContListing(DynamicObject[] listings) { + int rowCount = this.getModel().getEntryRowCount("entryentity"); + Set listingIdSet = new HashSet(); + + int i; + for (i = 0; i < rowCount; ++i) { + String id = (String) this.getModel().getValue("listingid", i); + if (id != null && id != " ") { + listingIdSet.add(id); + } + } + + for (i = 0; i < listings.length; ++i) { + if (!listingIdSet.contains(listings[i].getString("id"))) { + int curIndex = this.getModel().createNewEntryRow("entryentity"); + this.getModel().updateCache(); + this.getView().setEnable(false, curIndex, new String[]{"material", "measureunit", "contprice"}); + DynamicObject resourceItem = listings[i].getDynamicObject("resourceitem"); + if (resourceItem != null && resourceItem.get("model") != null && StringUtils.isNotBlank(resourceItem.get("model"))) { + this.getView().setEnable(false, curIndex, new String[]{"modelnum"}); + } + + this.getModel().setValue("material", resourceItem, curIndex); + this.getModel().setValue("measureunit", listings[i].get("measureunit"), curIndex); + this.getModel().setValue("entrytaxrate", listings[i].get("rateobj"), curIndex); + this.getModel().beginInit(); + this.getModel().setValue("qty", listings[i].get("totalqty"), curIndex); + this.getModel().setValue("taxprice", listings[i].get("curtaxprice"), curIndex); + this.getModel().setValue("contprice", listings[i].get("curtaxprice"), curIndex); + this.getModel().setValue("oftaxamount", listings[i].get("lstoftaxamount"), curIndex); + this.getModel().setValue("price", listings[i].get("currentprice"), curIndex); + this.getModel().setValue("notaxamount", listings[i].get("lasttotalamt"), curIndex); + this.getModel().setValue("oftaxamount", listings[i].get("lstoftaxamount"), curIndex); + this.getModel().setValue("taxamount", listings[i].getBigDecimal("lstoftaxamount").subtract(listings[i].getBigDecimal("lasttotalamt")), curIndex); + this.getModel().endInit(); + this.getView().updateView("qty", curIndex); + this.getView().updateView("taxprice", curIndex); + this.getView().updateView("contprice", curIndex); + this.getView().updateView("oftaxamount", curIndex); + this.getView().updateView("entrytaxrate", curIndex); + this.getView().updateView("price", curIndex); + this.getView().updateView("notaxamount", curIndex); + this.getView().updateView("oftaxamount", curIndex); + this.getView().updateView("taxamount", curIndex); + DynamicObject mattaxrateObj = ((DynamicObject) this.getModel().getEntryEntity("entryentity").get(curIndex)).getDynamicObject("entrytaxrate"); + BigDecimal taxrate = new BigDecimal(0); + if (mattaxrateObj != null) { + taxrate = mattaxrateObj.getBigDecimal("taxrate"); + } + + this.initContAndOrderData(curIndex, taxrate); + this.getModel().setValue("listingid", listings[i].get(OutTreeListingConstant.ID_ENTITY_PK), curIndex); + this.getModel().setValue("procbs", listings[i].get("cbsnumber"), curIndex); + this.getModel().setValue("proboq", listings[i].get("boqnumber"), curIndex); + } + } + + } + + public void beforeF7Select(BeforeF7SelectEvent e) { + String key = e.getProperty().getName(); + ListShowParameter param = (ListShowParameter) e.getFormShowParameter(); + param.setCustomParam("matinsource", this.getModel().getValue("matinsource")); + DynamicObject org = (DynamicObject) this.getModel().getValue("org"); + DynamicObject project = (DynamicObject) this.getModel().getValue("project"); + switch (key) { + case "warehouse": + Long orgId = org == null ? 0L : (Long) org.getPkValue(); + param.getListFilterParameter().getQFilters().add(new QFilter("org", "=", orgId)); + break; + case "procbs": + if (project == null) { + this.getView().showTipNotification(ResManager.loadKDString("必须选择工程项目。", "MaterialInBillEditPlugin_6", "ec-ecma-formplugin", new Object[0])); + e.setCancel(true); + } else { + QFilter qFilter = new QFilter("project", "=", project.getPkValue()); + qFilter.and(new QFilter("isleaf", "=", true)); + param.getListFilterParameter().getQFilters().add(qFilter); + param.setFormId("bos_listf7"); + param.getListFilterParameter().getQFilters().add(qFilter); + } + break; + case "proboq": + this.addF7FilterOfProject(e, param, project); + break; + case "lotid": + int curRow = this.getModel().getEntryCurrentRowIndex("entryentity"); + DynamicObject material = (DynamicObject) this.getModel().getValue("material", curRow); + if (material != null) { + param.getListFilterParameter().getQFilters().add(new QFilter("material", "=", material.getPkValue())); + } else { + this.getView().showTipNotification(ResManager.loadKDString("请选择物料,再选择批次。", "MaterialInBillEditPlugin_7", "ec-ecma-formplugin", new Object[0])); + e.setCancel(true); + } + break; + case "contract": + DynamicObject warehouse = (DynamicObject) this.getModel().getValue("warehouse"); + if (warehouse != null) { + DynamicObject wareProject = warehouse.getDynamicObject("project"); + if (wareProject != null) { + param.getListFilterParameter().getQFilters().add(new QFilter("project", "in", new Object[]{wareProject.getPkValue(), 0})); + } + } + + ContractHelper.getContractByStatus("ecma_materialinbill", param, PayDirectionEnum.OUT.getValue()); + break; + case "purchaseorder": + if (project != null) { + QFilter projectFilter = new QFilter("project", "=", project.getPkValue()); + param.getListFilterParameter().getQFilters().add(projectFilter); + DynamicObject unitPro = this.getModel().getDataEntity().getDynamicObject("unitprojectpro"); + if (unitPro != null) { + QFilter unitProFilter = new QFilter("unitproject", "=", unitPro.getPkValue()); + param.getListFilterParameter().getQFilters().add(unitProFilter); + } + } else { + List ids1 = OrgServiceHelper.getAllSubordinateOrgs("15", Collections.singletonList(org.getLong("id")), true); + param.getListFilterParameter().getQFilters().add(new QFilter("org", "in", ids1)); + } + break; + case "unitprojectpro": + this.beforeUnitProjectSelect(e, param); + break; + case "transtype": + this.beforeTransTypeF7Selected(e); + } + + } + + protected void beforeTransTypeF7Selected(BeforeF7SelectEvent e) { + Boolean poundIn = (Boolean) this.getModel().getValue("poundin"); + ListShowParameter param = (ListShowParameter) e.getFormShowParameter(); + QFilter numberFilter = new QFilter("id", "in", Sets.newHashSet(new Long[]{PoundTransTypeEnum.POUND_IN.getDefaultId(), PoundTransTypeEnum.POUND_IN_THEN_OUT.getDefaultId()})); + if (!poundIn) { + numberFilter = new QFilter("id", "not in", Sets.newHashSet(new Long[]{PoundTransTypeEnum.POUND_IN.getDefaultId(), PoundTransTypeEnum.POUND_OUT.getDefaultId(), PoundTransTypeEnum.POUND_IN_THEN_OUT.getDefaultId()})); + } + + param.getListFilterParameter().getQFilters().add(numberFilter); + } + + private void beforeUnitProjectSelect(BeforeF7SelectEvent e, ListShowParameter param) { + DynamicObject project = (DynamicObject) this.getModel().getValue("project"); + DynamicObject org = (DynamicObject) this.getModel().getValue("org"); + String orgId = org.getString("id"); + if (project != null) { + QFilter qFilter = new QFilter("parent", "=", project.getPkValue()); + DynamicObject ecProject = BusinessDataServiceHelper.loadSingle(project.getPkValue(), "ec_project"); + DynamicObject proOrg = ecProject.getDynamicObject("org"); + if (proOrg != null && !orgId.equals(proOrg.getString("id"))) { + qFilter.and(new QFilter("responsibleorg", "=", Long.parseLong(orgId))); + } + + param.getListFilterParameter().getQFilters().add(qFilter); + } + + } + + private void addF7FilterOfProject(BeforeF7SelectEvent e, ListShowParameter formShowParameter, DynamicObject project) { + if (project == null) { + this.getView().showTipNotification(ResManager.loadKDString("必须选择工程项目。", "MaterialInBillEditPlugin_6", "ec-ecma-formplugin", new Object[0])); + e.setCancel(true); + } else { + QFilter qFilter = new QFilter("project", "=", project.getPkValue()); + qFilter.and(new QFilter("isleaf", "=", true)); + DynamicObject unitProject = (DynamicObject) this.getModel().getValue("unitprojectpro"); + if (unitProject != null) { + qFilter.and(new QFilter("unitproject", "=", unitProject.getPkValue())); + formShowParameter.getTreeFilterParameter().getQFilters().add(new QFilter("unitproject", "=", unitProject.getPkValue())); + } else { + qFilter.and(new QFilter("project", "=", project.getPkValue())); + } + + formShowParameter.getListFilterParameter().getQFilters().add(qFilter); + formShowParameter.getTreeFilterParameter().getQFilters().add(new QFilter("project", "=", project.getPkValue())); + } + } + + private BigDecimal getTaxRateNum() { + DynamicObject rateObj = (DynamicObject) this.getModel().getValue("mataxrate"); + BigDecimal taxrateNum = BigDecimal.ZERO; + if (rateObj != null) { + taxrateNum = BigDecimal.valueOf((long) rateObj.getInt("taxrate")); + } + + return taxrateNum; + } + + public String getOrgViewType() { + return "02"; + } + + // protected void doFetchPoundData(BeforeDoOperationEventArgs args) { +// (new PoundAutoFetchBiz(this)).doFetchPound(args, this.getView()); +// }//系统默认 + protected void doFetchPoundData(BeforeDoOperationEventArgs args) { + (new PoundAutoFetchBizExt(this)).doFetchPound(args, this.getView()); + }//二开替代 + + 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/PoundAutoFetchBizExt.java b/code/zcdev/zcgj-zcdev-zcdev-pr/src/main/java/zcgj/zcdev/zcdev/pr/plugin/form/PoundAutoFetchBizExt.java new file mode 100644 index 0000000..50aa259 --- /dev/null +++ b/code/zcdev/zcgj-zcdev-zcdev-pr/src/main/java/zcgj/zcdev/zcdev/pr/plugin/form/PoundAutoFetchBizExt.java @@ -0,0 +1,375 @@ +// +// 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 com.google.common.collect.Sets; +import java.math.BigDecimal; +import java.util.Map; +import java.util.Optional; +import java.util.Set; +import java.util.function.Function; +import java.util.stream.Collectors; +import java.util.stream.Stream; +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.form.IFormView; +import kd.bos.form.events.BeforeDoOperationEventArgs; +import kd.bos.orm.query.QFilter; +import kd.bos.servicehelper.BusinessDataServiceHelper; +import kd.ec.basedata.business.model.cont.OutTreeListingConstant; +import kd.ec.material.common.enums.PoundTransTypeEnum; +import kd.ec.material.formplugin.MaterialInBillEditPlugin; + +public class PoundAutoFetchBizExt { + private final MaterialInBillEditPluginExt plugin; + + public PoundAutoFetchBizExt(MaterialInBillEditPluginExt plugin) { + this.plugin = plugin; + } + + public void doFetchPound(BeforeDoOperationEventArgs args, IFormView formView) { + String matInSource = (String)formView.getModel().getValue("matinsource"); + if (!StringUtils.isEmpty(matInSource)) { + switch (matInSource) { + case "1": + this.doFetchForContract(args, formView); + break; + case "2": + this.doFetchForPurchase(args, formView); + break; + case "4": + this.doFetchForResource(args, formView); + } + + } + } + + protected void doFetchForContract(BeforeDoOperationEventArgs args, IFormView formView) { + DynamicObject transType = (DynamicObject)formView.getModel().getValue("transtype"); + if (transType == null) { + args.setCancel(true); + formView.showTipNotification(ResManager.loadKDString("请先选择事务类型", "PoundAutoFetchBiz_3", "ec-ecma-formplugin", new Object[0])); + } else { + DynamicObject contract = (DynamicObject)formView.getModel().getValue("contract"); + if (contract == null) { + args.setCancel(true); + formView.showTipNotification(ResManager.loadKDString("请先选择合同。", "PoundAutoFetchBiz_0", "ec-ecma-formplugin", new Object[0])); + } else { + int rowCount = formView.getModel().getEntryRowCount("entryentity"); + if (rowCount > 0) { + formView.getModel().deleteEntryData("entryentity"); + formView.updateView("entryentity"); + } + + boolean editUnit = false; + DynamicObject project = (DynamicObject)formView.getModel().getValue("project"); + DynamicObject unitProject = (DynamicObject)formView.getModel().getValue("unitprojectpro"); + if (project != null) { + editUnit = project.getBoolean("editonunit"); + } + + Long contId = contract.getLong("id"); + QFilter contFilter = new QFilter("contractid", "=", contId); + QFilter resourceFilter = new QFilter("resourceitem", "!=", 0); + if (editUnit && unitProject != null) { + resourceFilter = resourceFilter.and(new QFilter("listunitproject", "in", new Object[]{unitProject.getPkValue(), 0})); + } + + String selectProperties = "resourceitem,measureunit,totalqty,curtaxprice,currentprice,lstoftaxamount,rateobj,cbsnumber,boqnumber"; + DynamicObject[] treeListingEntities = BusinessDataServiceHelper.load("ec_outtreelisting", selectProperties, new QFilter[]{contFilter, resourceFilter}); + if (!ArrayUtils.isEmpty(treeListingEntities)) { + Map resourceGroup = (Map)Stream.of(treeListingEntities).filter((dynamicObject) -> { + return Optional.ofNullable(dynamicObject.getDynamicObject("resourceitem")).isPresent(); + }).collect(Collectors.toMap((dynamicObject) -> { + DynamicObject resourceItem = dynamicObject.getDynamicObject("resourceitem"); + return resourceItem.getLong("id"); + }, Function.identity(), (k1, k2) -> { + return k1; + })); + Set resourceIds = resourceGroup.keySet(); + DynamicObject org = (DynamicObject)formView.getModel().getValue("org"); + QFilter orgFilter = new QFilter("org", "=", org.getPkValue()); + if (project != null) { + orgFilter = orgFilter.and(new QFilter("project", "=", project.getPkValue())); + } + + Long transTypeId = transType.getLong("id"); + QFilter transTypeFilter = null; + if (transTypeId.equals(PoundTransTypeEnum.POUND_IN.getDefaultId())) { + transTypeFilter = new QFilter("transtype", "in", Sets.newHashSet(new Long[]{PoundTransTypeEnum.POUND_IN.getDefaultId()})); + } else if (transTypeId.equals(PoundTransTypeEnum.POUND_IN_THEN_OUT.getDefaultId())) { + transTypeFilter = new QFilter("transtype", "in", Sets.newHashSet(new Long[]{PoundTransTypeEnum.POUND_IN_THEN_OUT.getDefaultId()})); + } + + QFilter depotStatusFilter = new QFilter("depotstatus", "=", Boolean.FALSE); + QFilter optTypeFilter = new QFilter("opt_type", "!=", "2"); + QFilter poundResourceFilter = new QFilter("material", "in", resourceIds); + DynamicObject[] poundEntities = BusinessDataServiceHelper.load("ecma_poundbill", "id ,billno ,material ,actualweight", new QFilter[]{orgFilter, transTypeFilter, depotStatusFilter, optTypeFilter, poundResourceFilter}); + DynamicObject[] var24 = poundEntities; + int var25 = poundEntities.length; + + for(int var26 = 0; var26 < var25; ++var26) { + DynamicObject poundEntity = var24[var26]; + DynamicObject resource = poundEntity.getDynamicObject("material"); + DynamicObject resourceListEntity = (DynamicObject)resourceGroup.get((Long)resource.getPkValue()); + if (resourceListEntity != null) { + Map poundDataMap = Maps.newHashMap(); + poundDataMap.put("poundid", poundEntity.getPkValue()); + poundDataMap.put("poundno", poundEntity.getString("billno")); + poundDataMap.put("qty", poundEntity.getString("actualweight")); + this.fillEntryByContListing(new DynamicObject[]{resourceListEntity}, formView, poundDataMap); + } + } + + this.plugin.fieldLockLogic(); + } + } + } + } + + private void fillEntryByContListing(DynamicObject[] listings, IFormView formView, Map poundDataMap) { + for(int i = 0; i < listings.length; ++i) { + int curIndex = formView.getModel().createNewEntryRow("entryentity"); + formView.getModel().updateCache(); + formView.setEnable(false, curIndex, new String[]{"material", "measureunit", "contprice"}); + DynamicObject resourceItem = listings[i].getDynamicObject("resourceitem"); + if (resourceItem != null && resourceItem.get("model") != null && StringUtils.isNotBlank(resourceItem.get("model"))) { + formView.setEnable(false, curIndex, new String[]{"modelnum"}); + } + + formView.getModel().setValue("material", resourceItem, curIndex); + formView.getModel().setValue("measureunit", listings[i].get("measureunit"), curIndex); + formView.getModel().beginInit(); + formView.getModel().setValue("qty", poundDataMap.get("qty"), curIndex); + formView.getModel().setValue("price", listings[i].get("currentprice"), curIndex); + formView.getModel().setValue("contprice", listings[i].get("curtaxprice"), curIndex); + formView.getModel().endInit(); + formView.getModel().setValue("entrytaxrate", listings[i].get("rateobj"), curIndex); + formView.updateView("qty", curIndex); + formView.updateView("price", curIndex); + formView.updateView("contprice", curIndex); + formView.updateView("entrytaxrate", curIndex); + formView.getModel().setValue("poundid", poundDataMap.get("poundid"), curIndex); + formView.getModel().setValue("poundno", poundDataMap.get("poundno"), curIndex); + DynamicObject mattaxrateObj = ((DynamicObject)formView.getModel().getEntryEntity("entryentity").get(curIndex)).getDynamicObject("entrytaxrate"); + BigDecimal taxrate = new BigDecimal(0); + if (mattaxrateObj != null) { + taxrate = mattaxrateObj.getBigDecimal("taxrate"); + } + + this.plugin.initContAndOrderData(curIndex, taxrate); + formView.getModel().setValue("listingid", listings[i].get(OutTreeListingConstant.ID_ENTITY_PK), curIndex); + formView.getModel().setValue("procbs", listings[i].get("cbsnumber"), curIndex); + formView.getModel().setValue("proboq", listings[i].get("boqnumber"), curIndex); + } + + } + + protected void doFetchForPurchase(BeforeDoOperationEventArgs args, IFormView formView) { + DynamicObject transType = (DynamicObject)formView.getModel().getValue("transtype"); + if (transType == null) { + args.setCancel(true); + formView.showTipNotification(ResManager.loadKDString("请先选择事务类型", "PoundAutoFetchBiz_3", "ec-ecma-formplugin", new Object[0])); + } else { + DynamicObject order = (DynamicObject)formView.getModel().getValue("purchaseorder"); + if (order == null) { + args.setCancel(true); + formView.showTipNotification(ResManager.loadKDString("请选择采购订单。", "PoundAutoFetchBiz_1", "ec-ecma-formplugin", new Object[0])); + } else { + int rowCount = formView.getModel().getEntryRowCount("entryentity"); + if (rowCount > 0) { + formView.getModel().deleteEntryData("entryentity"); + formView.updateView("entryentity"); + } + + Long orderId = order.getLong("id"); + QFilter orderEntryIdFilter = new QFilter("orderentryid", "=", orderId); + QFilter orderQtyFilter = new QFilter("surplusqty", ">", 0); + String purchaseOrderProperties = "material,surplusqty,modelnum,measureunit,oftaxprice,price,entrytaxrate"; + DynamicObject[] purchaseOrderEntities = BusinessDataServiceHelper.load("ecma_purchaseorderentry", purchaseOrderProperties, new QFilter[]{orderEntryIdFilter, orderQtyFilter}); + if (!ArrayUtils.isEmpty(purchaseOrderEntities)) { + Map resourceGroup = (Map)Stream.of(purchaseOrderEntities).filter((dynamicObject) -> { + return Optional.ofNullable(dynamicObject.getDynamicObject("material")).isPresent(); + }).collect(Collectors.toMap((dynamicObject) -> { + return dynamicObject.getDynamicObject("material").getLong("id"); + }, Function.identity(), (k1, k2) -> { + return k1; + })); + Set resourceIds = resourceGroup.keySet(); + DynamicObject org = (DynamicObject)formView.getModel().getValue("org"); + QFilter orgFilter = new QFilter("org", "=", org.getPkValue()); + DynamicObject project = (DynamicObject)formView.getModel().getValue("project"); + if (project != null) { + orgFilter = orgFilter.and(new QFilter("project", "=", project.getPkValue())); + } + + Long transTypeId = transType.getLong("id"); + QFilter transTypeFilter = null; + if (transTypeId.equals(PoundTransTypeEnum.POUND_IN.getDefaultId())) { + transTypeFilter = new QFilter("transtype", "in", Sets.newHashSet(new Long[]{PoundTransTypeEnum.POUND_IN.getDefaultId()})); + } else if (transTypeId.equals(PoundTransTypeEnum.POUND_IN_THEN_OUT.getDefaultId())) { + transTypeFilter = new QFilter("transtype", "in", Sets.newHashSet(new Long[]{PoundTransTypeEnum.POUND_IN_THEN_OUT.getDefaultId()})); + } + + QFilter depotStatusFilter = new QFilter("depotstatus", "=", Boolean.FALSE); + QFilter optTypeFilter = new QFilter("opt_type", "!=", "2"); + QFilter poundResourceFilter = new QFilter("material", "in", resourceIds); + DynamicObject[] poundEntities = BusinessDataServiceHelper.load("ecma_poundbill", "id ,billno ,material ,actualweight", new QFilter[]{orgFilter, transTypeFilter, depotStatusFilter, optTypeFilter, poundResourceFilter}); + DynamicObject[] var22 = poundEntities; + int var23 = poundEntities.length; + + for(int var24 = 0; var24 < var23; ++var24) { + DynamicObject poundEntity = var22[var24]; + DynamicObject resource = poundEntity.getDynamicObject("material"); + DynamicObject resourceListEntity = (DynamicObject)resourceGroup.get((Long)resource.getPkValue()); + if (resourceListEntity != null) { + Map poundDataMap = Maps.newHashMap(); + poundDataMap.put("poundid", poundEntity.getPkValue()); + poundDataMap.put("poundno", poundEntity.getString("billno")); + poundDataMap.put("qty", poundEntity.getBigDecimal("actualweight")); + this.fillEntryByOrderListing(new DynamicObject[]{resourceListEntity}, formView, poundDataMap); + } + } + + } + } + } + } + + private void fillEntryByOrderListing(DynamicObject[] orderEntries, IFormView formView, Map poundDataMap) { + this.plugin.getPageCache().put("entrysourcecache", "purChaseOrderSource"); + DynamicObject[] var4 = orderEntries; + int var5 = orderEntries.length; + + for(int var6 = 0; var6 < var5; ++var6) { + DynamicObject o = var4[var6]; + if (o.getBigDecimal("surplusqty").compareTo(BigDecimal.ZERO) > 0) { + int row = formView.getModel().createNewEntryRow("entryentity"); + formView.getModel().updateCache(); + if (o.getDynamicObject("material") != null) { + this.plugin.getView().getModel().setValue("material", o.getDynamicObject("material").getPkValue(), row); + } + + formView.getModel().setValue("modelnum", o.get("modelnum"), row); + if (o.getDynamicObject("measureunit") != null) { + formView.getModel().setValue("measureunit", o.getDynamicObject("measureunit").getPkValue(), row); + } else { + formView.getModel().setValue("measureunit", (Object)null, row); + } + + formView.getModel().beginInit(); + formView.getModel().setValue("qty", poundDataMap.get("qty"), row); + formView.getModel().setValue("contprice", o.get("price"), row); + formView.getModel().setValue("price", o.get("oftaxprice"), row); + formView.getModel().endInit(); + formView.getModel().setValue("entrytaxrate", o.get("entrytaxrate"), row); + formView.updateView("qty", row); + formView.updateView("price", row); + formView.updateView("contprice", row); + formView.updateView("entrytaxrate", row); + formView.getModel().setValue("poundid", poundDataMap.get("poundid"), row); + formView.getModel().setValue("poundno", poundDataMap.get("poundno"), row); + DynamicObject mattaxrateObj = ((DynamicObject)formView.getModel().getEntryEntity("entryentity").get(row)).getDynamicObject("entrytaxrate"); + BigDecimal taxrate = new BigDecimal(0); + if (mattaxrateObj != null) { + taxrate = mattaxrateObj.getBigDecimal("taxrate"); + } + + this.plugin.initContAndOrderData(row, taxrate); + formView.getModel().setValue("orderentryid", o.getPkValue(), row); + } + } + + } + + protected void doFetchForResource(BeforeDoOperationEventArgs args, IFormView formView) { + int rowCount = formView.getModel().getEntryRowCount("entryentity"); + if (rowCount > 0) { + formView.getModel().deleteEntryData("entryentity"); + formView.updateView("entryentity"); + } + + DynamicObject transType = (DynamicObject)formView.getModel().getValue("transtype"); + if (transType == null) { + args.setCancel(true); + formView.showTipNotification(ResManager.loadKDString("请先选择事务类型", "PoundAutoFetchBiz_3", "ec-ecma-formplugin", new Object[0])); + } else { + DynamicObject org = (DynamicObject)formView.getModel().getValue("org"); + QFilter orgFilter = new QFilter("org", "=", org.getPkValue()); + DynamicObject project = (DynamicObject)formView.getModel().getValue("project"); + if (project != null) { + orgFilter = orgFilter.and(new QFilter("project", "=", project.getPkValue())); + } + + DynamicObject supplier = (DynamicObject)formView.getModel().getValue("supplier"); + if (supplier != null) { + orgFilter = orgFilter.and(new QFilter("supplier", "=", supplier.getPkValue())); + } + + DynamicObject warehouse = (DynamicObject)formView.getModel().getValue("warehouse"); + if (warehouse != null) { + orgFilter = orgFilter.and(new QFilter("in_depot", "in", Sets.newHashSet(new Object[]{0L, warehouse.getPkValue()}))); + } + + Long transTypeId = transType.getLong("id"); + QFilter transTypeFilter = null; + if (transTypeId.equals(PoundTransTypeEnum.POUND_IN.getDefaultId())) { + transTypeFilter = new QFilter("transtype", "in", Sets.newHashSet(new Long[]{PoundTransTypeEnum.POUND_IN.getDefaultId()})); + } else if (transTypeId.equals(PoundTransTypeEnum.POUND_IN_THEN_OUT.getDefaultId())) { + transTypeFilter = new QFilter("transtype", "in", Sets.newHashSet(new Long[]{PoundTransTypeEnum.POUND_IN_THEN_OUT.getDefaultId()})); + } + + QFilter depotStatusFilter = new QFilter("depotstatus", "=", Boolean.FALSE); + QFilter optTypeFilter = new QFilter("opt_type", "!=", "2"); + DynamicObject[] poundEntities = BusinessDataServiceHelper.load("ecma_poundbill", "id ,billno ,material ,actualweight", new QFilter[]{orgFilter, transTypeFilter, depotStatusFilter, optTypeFilter}); + if (!ArrayUtils.isEmpty(poundEntities)) { + DynamicObject defaultTaxRate = (DynamicObject)formView.getModel().getValue("mataxrate"); + BigDecimal taxRate = new BigDecimal(0); + if (defaultTaxRate != null) { + taxRate = defaultTaxRate.getBigDecimal("taxrate"); + } + + DynamicObjectCollection entryEntity = formView.getModel().getEntryEntity("entryentity"); + DynamicObject[] var18 = poundEntities; + int var19 = poundEntities.length; + + for(int var20 = 0; var20 < var19; ++var20) { + DynamicObject poundEntity = var18[var20]; + DynamicObject row = entryEntity.addNew(); + row.set("poundid", poundEntity.getPkValue()); + row.set("poundno", poundEntity.getString("billno")); + row.set("qty", poundEntity.getBigDecimal("actualweight")); + DynamicObject material = poundEntity.getDynamicObject("material"); + if (material != null) { + row.set("material", material); + if (defaultTaxRate != null) { + row.set("entrytaxrate", defaultTaxRate); + } + + BigDecimal price = material.getBigDecimal("price"); + row.set("price", price); + row.set("measureunit", material.get("measureunit")); + BigDecimal taxPrice = price.multiply(BigDecimal.ONE.add(taxRate.divide(BigDecimal.valueOf(100L)))); + row.set("taxprice", taxPrice); + BigDecimal ofTaxAmount = poundEntity.getBigDecimal("actualweight").multiply(taxPrice); + row.set("oftaxamount", ofTaxAmount); + BigDecimal noTaxAmount = poundEntity.getBigDecimal("actualweight").multiply(price); + row.set("notaxamount", noTaxAmount); + row.set("taxamount", ofTaxAmount.subtract(noTaxAmount)); + } + } + + formView.getModel().updateEntryCache(entryEntity); + formView.updateView("entryentity"); + this.plugin.fieldLockLogic(); + } + } + } +}