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..607d8bc --- /dev/null +++ b/code/zcdev/zcgj-zcdev-zcdev-pr/src/main/java/zcgj/zcdev/zcdev/pr/plugin/form/MaterialInBillEditPluginExt.java @@ -0,0 +1,2102 @@ +// +// 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);//BOQ(工程量清单) + } + + 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(4); + 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]), + ResManager.loadKDString("采购申请", "MaterialInBillEditPlugin_12", "ec-ecma-formplugin", new Object[0])}; + String[] value = new String[]{"1", "2", "4","6"}; + + for (int i = 0; i < 4; ++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/MaterialInbFinaceConfirmeInvoicePlugin.java b/code/zcdev/zcgj-zcdev-zcdev-pr/src/main/java/zcgj/zcdev/zcdev/pr/plugin/form/MaterialInbFinaceConfirmeInvoicePlugin.java index 9457c97..ed9a32a 100644 --- a/code/zcdev/zcgj-zcdev-zcdev-pr/src/main/java/zcgj/zcdev/zcdev/pr/plugin/form/MaterialInbFinaceConfirmeInvoicePlugin.java +++ b/code/zcdev/zcgj-zcdev-zcdev-pr/src/main/java/zcgj/zcdev/zcdev/pr/plugin/form/MaterialInbFinaceConfirmeInvoicePlugin.java @@ -40,7 +40,7 @@ import java.util.*; import java.util.stream.Collectors; /** - * 入库单发票导入插件+事物类型默认为空+是否主材隐显 + * 入库单发票导入插件+ 事物类型默认为空(废弃+是否主材隐显(废弃 */ public class MaterialInbFinaceConfirmeInvoicePlugin extends AbstractBillPlugIn implements Plugin { private static final Log log = LogFactory.getLog(MaterialInbFinaceConfirmeInvoicePlugin.class); @@ -48,7 +48,7 @@ public class MaterialInbFinaceConfirmeInvoicePlugin extends AbstractBillPlugIn i @Override public void afterCreateNewData(EventObject e) { super.afterCreateNewData(e); - this.getModel().setValue("transtype", null);//事务类型默认为空 +// this.getModel().setValue("transtype", null);//事务类型默认为空 } @Override @@ -57,20 +57,20 @@ public class MaterialInbFinaceConfirmeInvoicePlugin extends AbstractBillPlugIn i String key = e.getProperty().getName(); if (key.equals("transtype")) { //事务类型 - ChangeData[] changeSet = e.getChangeSet(); - ChangeData changeData = changeSet[0]; - DynamicObject transtype = (DynamicObject) changeData.getNewValue();//新值 - if (transtype != null) { - String number = transtype.getString("number"); - if (number.equals("jrjc")) { - //事务类型为即入即出时隐藏是否主材 - this.getView().setVisible(false, "ismainmaterial");//是否主材 - } else { - this.getView().setVisible(true, "ismainmaterial");//是否主材 - } - } else { - this.getView().setVisible(true, "ismainmaterial");//是否主材 - } +// ChangeData[] changeSet = e.getChangeSet(); +// ChangeData changeData = changeSet[0]; +// DynamicObject transtype = (DynamicObject) changeData.getNewValue();//新值 +// if (transtype != null) { +// String number = transtype.getString("number"); +// if (number.equals("jrjc")) { +// //事务类型为即入即出时隐藏是否主材 +// this.getView().setVisible(false, "ismainmaterial");//是否主材 +// } else { +// this.getView().setVisible(true, "ismainmaterial");//是否主材 +// } +// } else { +// this.getView().setVisible(true, "ismainmaterial");//是否主材 +// } } } diff --git a/code/zcdev/zcgj-zcdev-zcdev-pr/src/main/java/zcgj/zcdev/zcdev/pr/plugin/form/MaterialInbPurchaseApplyPlugin.java b/code/zcdev/zcgj-zcdev-zcdev-pr/src/main/java/zcgj/zcdev/zcdev/pr/plugin/form/MaterialInbPurchaseApplyPlugin.java new file mode 100644 index 0000000..ef4fc02 --- /dev/null +++ b/code/zcdev/zcgj-zcdev-zcdev-pr/src/main/java/zcgj/zcdev/zcdev/pr/plugin/form/MaterialInbPurchaseApplyPlugin.java @@ -0,0 +1,124 @@ +package zcgj.zcdev.zcdev.pr.plugin.form; + +import kd.bos.algo.DataSet; +import kd.bos.algo.JoinDataSet; +import kd.bos.algo.JoinType; +import kd.bos.algo.Row; +import kd.bos.bill.AbstractBillPlugIn; +import kd.bos.dataentity.entity.DynamicObject; +import kd.bos.dataentity.entity.DynamicObjectCollection; +import kd.bos.dataentity.resource.ResManager; +import kd.bos.dataentity.utils.StringUtils; +import kd.bos.entity.EntityMetadataCache; +import kd.bos.entity.datamodel.ListSelectedRowCollection; +import kd.bos.form.*; +import kd.bos.form.events.AfterDoOperationEventArgs; +import kd.bos.form.events.BeforeDoOperationEventArgs; +import kd.bos.form.events.ClosedCallBackEvent; +import kd.bos.form.operate.FormOperate; +import kd.bos.list.ListShowParameter; +import kd.bos.orm.query.QCP; +import kd.bos.orm.query.QFilter; +import kd.bos.servicehelper.BusinessDataServiceHelper; +import kd.bos.servicehelper.QueryServiceHelper; +import kd.sdk.plugin.Plugin; + +import java.util.*; +import java.util.stream.Collectors; + +/** + * 入库单表单插件:入库单点击选择采购申请按钮后弹出对应采购申请分录内容,后通过选择弹出的采购申请分录行赋值给入库单中 + */ +public class MaterialInbPurchaseApplyPlugin extends AbstractBillPlugIn implements Plugin { + public void beforeDoOperation(BeforeDoOperationEventArgs args) { + super.beforeDoOperation(args); + FormOperate operate = (FormOperate) args.getSource(); + if ("purchaseapply".equals(operate.getOperateKey())) { + //选择采购申请单 + this.doPurchaseApply(); + } + } + + private void doPurchaseApply() { + DynamicObject purchaseApply = (DynamicObject) this.getModel().getValue("zcgj_purchaseapply");//采购申请单 + if (purchaseApply == null) { + this.getView().showTipNotification(ResManager.loadKDString("请先选择采购申请。", "MaterialInBillEditPlugin_0", "ec-ecma-formplugin", new Object[0])); + } else { + FormShowParameter formShowParameter = new FormShowParameter(); + HashMap paramters = new HashMap<>(); + DynamicObjectCollection entryEntityCollection = this.getModel().getDataEntity(true).getDynamicObjectCollection("entryentity");//入库单分录 + List entryIds = new ArrayList<>(); + List entryIds2 = new ArrayList<>(); + for (DynamicObject entryEntity : entryEntityCollection) { + Long entryEntityId = entryEntity.getLong("listingid");//合同清单id + entryIds.add(entryEntityId); + entryIds2.add(entryEntityId); + } + + long purchaseApplyId = purchaseApply.getLong("id");//采购申请单id + QFilter[] qFilte = new QFilter[]{new QFilter("zcgj_purchaseapply.id", QCP.equals, purchaseApplyId)}; + DynamicObject[] ecma_materialInBills = BusinessDataServiceHelper.load("ecma_materialinbill","entryentity,entryentity.listingid", qFilte);//入库单 + for (DynamicObject materialInBill : ecma_materialInBills) { + DynamicObjectCollection entryEntityCollection1 = materialInBill.getDynamicObjectCollection("entryentity");//入库单分录 + for (DynamicObject entryEntity : entryEntityCollection1) { + long entryEntityId = entryEntity.getLong("listingid");//入库单分录-合同清单id + if (materialInBill.get("id").equals(this.getModel().getValue("id"))){ + if (!entryIds2.contains(entryEntityId)){ + break; + } + } + entryIds.add(entryEntityId); + } + } + paramters.put("purchaseApplyId", purchaseApplyId); + paramters.put("entryIds", entryIds); + formShowParameter.setCustomParams(paramters); + formShowParameter.setCaption("采购申请分录列表"); + formShowParameter.setFormId("zcgj_purchaseapplyentry"); + formShowParameter.setCloseCallBack(new CloseCallBack(this, "zcgj_selectpurchaseapply")); + + StyleCss styleCss = new StyleCss(); + styleCss.setWidth("900"); + styleCss.setHeight("545"); + OpenStyle openStyle = formShowParameter.getOpenStyle(); + openStyle.setShowType(ShowType.Modal); + openStyle.setInlineStyleCss(styleCss); + this.getView().showForm(formShowParameter); + } + } + + public void closedCallBack(ClosedCallBackEvent closedCallBackEvent) { + super.closedCallBack(closedCallBackEvent); + String actionId = closedCallBackEvent.getActionId(); + DynamicObjectCollection returnDataCollection = (DynamicObjectCollection) closedCallBackEvent.getReturnData(); + if (returnDataCollection == null) { + return; + } + if ("zcgj_selectpurchaseapply".equals(actionId) && returnDataCollection.size() > 0) { + for (DynamicObject returnData : returnDataCollection) { + int curIndex = this.getModel().createNewEntryRow("entryentity"); + this.getModel().updateCache(); + this.getView().setEnable(false, curIndex, new String[]{"oftaxamount", "notaxamount", "taxamount", "taxprice"}); + + long zcgj_bigintfield = returnData.getLong("zcgj_bigintfield");//采购申请单id + QFilter filter = new QFilter("purchaseentry.id", QCP.equals, zcgj_bigintfield); + DynamicObjectCollection purchaseApply = QueryServiceHelper.query("ecma_purchaseapply", + "purchaseentry,purchaseentry.material,purchaseentry.purchaseqty,purchaseentry.entrytaxrate,purchaseentry.price,purchaseentry.id,purchaseentry.remarks", + new QFilter[]{filter});//采购申请单 + + long material = purchaseApply.get(0).getLong("purchaseentry.material");//采购申请分录-资源编码 + Object purchaseQty = purchaseApply.get(0).get("purchaseentry.purchaseqty");//采购申请分录-采购数量 + Object entryTaxRate = purchaseApply.get(0).get("purchaseentry.entrytaxrate");//采购申请分录-税率 + Object price = purchaseApply.get(0).get("purchaseentry.price");//采购申请分录-预估单价 + Object purchaseEntryId = purchaseApply.get(0).get("purchaseentry.id");//采购申请分录-预估单价 + Object remarks = purchaseApply.get(0).get("purchaseentry.remarks");//采购申请分录-备注 + this.getModel().setValue("material", material, curIndex);//资源编码 + this.getModel().setValue("entrytaxrate", entryTaxRate, curIndex);//税率名称 + this.getModel().setValue("qty", purchaseQty, curIndex);//数量 + this.getModel().setValue("price", price, curIndex);//入库单价 + this.getModel().setValue("listingid", purchaseEntryId, curIndex);//合同清单id + this.getModel().setValue("note", remarks, curIndex);//备注 + } + } + } +} diff --git a/code/zcdev/zcgj-zcdev-zcdev-pr/src/main/java/zcgj/zcdev/zcdev/pr/plugin/form/MaterialOutApplyPluginExt.java b/code/zcdev/zcgj-zcdev-zcdev-pr/src/main/java/zcgj/zcdev/zcdev/pr/plugin/form/MaterialOutApplyPluginExt.java index 2ad708e..81018cd 100644 --- a/code/zcdev/zcgj-zcdev-zcdev-pr/src/main/java/zcgj/zcdev/zcdev/pr/plugin/form/MaterialOutApplyPluginExt.java +++ b/code/zcdev/zcgj-zcdev-zcdev-pr/src/main/java/zcgj/zcdev/zcdev/pr/plugin/form/MaterialOutApplyPluginExt.java @@ -217,10 +217,10 @@ public class MaterialOutApplyPluginExt extends AbstractBillPlugIn implements Bef protected void carryHeadData(DynamicObject applyBill) { this.getModel().beginInit(); - DynamicObject transType = applyBill.getDynamicObject("transtype"); - if (transType != null) { - this.getModel().setValue("transtype", transType.getPkValue()); - } +// DynamicObject transType = applyBill.getDynamicObject("transtype"); +// if (transType != null) { +// this.getModel().setValue("transtype", transType.getPkValue()); +// }//二开去除:无需携带上游单据的事务类型至出库单 DynamicObject supplier = applyBill.getDynamicObject("supplier"); if (supplier != null) { 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(); + } + } + } +} diff --git a/code/zcdev/zcgj-zcdev-zcdev-pr/src/main/java/zcgj/zcdev/zcdev/pr/plugin/form/PurchaseAppBillPlugin.java b/code/zcdev/zcgj-zcdev-zcdev-pr/src/main/java/zcgj/zcdev/zcdev/pr/plugin/form/PurchaseAppBillPlugin.java new file mode 100644 index 0000000..14f75f9 --- /dev/null +++ b/code/zcdev/zcgj-zcdev-zcdev-pr/src/main/java/zcgj/zcdev/zcdev/pr/plugin/form/PurchaseAppBillPlugin.java @@ -0,0 +1,17 @@ +package zcgj.zcdev.zcdev.pr.plugin.form; + +import kd.bos.bill.AbstractBillPlugIn; + +import java.util.EventObject; + +/** + * 采购申请单表单插件:初始默认采购组织等于所属组织 + */ +public class PurchaseAppBillPlugin extends AbstractBillPlugIn { + @Override + public void afterCreateNewData(EventObject e) { + super.afterCreateNewData(e); + Object org = this.getModel().getValue("org");//所属组织 + this.getModel().setValue("purchaseorg", org);//采购组织 + } +} diff --git a/code/zcdev/zcgj-zcdev-zcdev-pr/src/main/java/zcgj/zcdev/zcdev/pr/plugin/form/PurchaseApplyEntryPlugin.java b/code/zcdev/zcgj-zcdev-zcdev-pr/src/main/java/zcgj/zcdev/zcdev/pr/plugin/form/PurchaseApplyEntryPlugin.java new file mode 100644 index 0000000..8eaa173 --- /dev/null +++ b/code/zcdev/zcgj-zcdev-zcdev-pr/src/main/java/zcgj/zcdev/zcdev/pr/plugin/form/PurchaseApplyEntryPlugin.java @@ -0,0 +1,78 @@ +package zcgj.zcdev.zcdev.pr.plugin.form; + +import com.alibaba.fastjson.JSONObject; +import kd.bos.dataentity.entity.DynamicObject; +import kd.bos.dataentity.entity.DynamicObjectCollection; +import kd.bos.form.control.Button; +import kd.bos.form.control.Control; +import kd.bos.form.control.EntryGrid; +import kd.bos.form.plugin.AbstractFormPlugin; +import kd.bos.servicehelper.BusinessDataServiceHelper; +import kd.sdk.plugin.Plugin; + +import java.util.EventObject; +import java.util.List; +import java.util.Map; + +/* + * 采购申请单物料列表插件:返回入库单点击选择采购申请信息 + */ +public class PurchaseApplyEntryPlugin extends AbstractFormPlugin implements Plugin { + @Override + public void registerListener(EventObject e) { + super.registerListener(e); + Button btnok = this.getControl("btnok");//确定 + btnok.addClickListener(this); + } + + @Override + public void click(EventObject evt) { + super.click(evt); + Control source = (Control) evt.getSource(); + if ("btnok".equals(source.getKey())) { + EntryGrid entryGrid = this.getControl("zcgj_entryentity"); + int[] selectRows = entryGrid.getSelectRows(); + int count = selectRows.length; + //分录行数只有一条的时候才能通过接下来两个if + if (count == 0) { + this.getView().showErrorNotification("请选择一条分录信息!"); + return; + } + DynamicObjectCollection qeug_entryentity = getModel().getEntryEntity("zcgj_entryentity");//分录 + DynamicObjectCollection collection = new DynamicObjectCollection(); + for (int selectRow : selectRows) { + collection.add(qeug_entryentity.get(selectRow)); + } + this.getView().returnDataToParent(collection);//返回所选数据给父级 + this.getView().close(); + } + } + + @Override + public void afterCreateNewData(EventObject e) { + super.afterCreateNewData(e); + Map customParams = this.getView().getFormShowParameter().getCustomParams(); + Long purchaseApplyId = (Long) customParams.get("purchaseApplyId");//采购申请单ID + if (purchaseApplyId != null) { + List entryIds = (List) customParams.get("entryIds"); + DynamicObject ecma_purchaseApply = BusinessDataServiceHelper.loadSingle(purchaseApplyId, "ecma_purchaseapply");//采购申请单 + DynamicObjectCollection purchaseEntryCollection = ecma_purchaseApply.getDynamicObjectCollection("purchaseentry");//采购明细单据体 + DynamicObjectCollection entryEntityCollection = this.getModel().getEntryEntity("zcgj_entryentity");//分录 + for (DynamicObject purchaseEntry : purchaseEntryCollection) { + Long id = (Long) purchaseEntry.get("id"); + if (entryIds != null && entryIds.contains(id)) { + continue; + } + DynamicObject entryEntityNew = entryEntityCollection.addNew(); + entryEntityNew.set("zcgj_bigintfield", id);//分录id + entryEntityNew.set("zcgj_material", purchaseEntry.get("material"));//物料 + entryEntityNew.set("zcgj_modelnum", purchaseEntry.getDynamicObject("material").get("model"));//规格型号 + entryEntityNew.set("zcgj_measureunit", purchaseEntry.get("unit"));//计量单位 + entryEntityNew.set("zcgj_qty", purchaseEntry.get("purchaseqty"));//数量 + entryEntityNew.set("zcgj_price", purchaseEntry.get("oftaxprice"));//合同单价(含税) + entryEntityNew.set("zcgj_oftaxamt", purchaseEntry.get("oftaxamount"));//本次订单金额(含税) + entryEntityNew.set("zcgj_description", purchaseEntry.get("remarks"));//备注 + } + } + } +} diff --git a/code/zcdev/zcgj-zcdev-zcdev-pr/src/main/java/zcgj/zcdev/zcdev/pr/plugin/operate/PeriodAimcostcbsbillEditPluginExt.java b/code/zcdev/zcgj-zcdev-zcdev-pr/src/main/java/zcgj/zcdev/zcdev/pr/plugin/operate/PeriodAimcostcbsbillEditPluginExt.java new file mode 100644 index 0000000..754941a --- /dev/null +++ b/code/zcdev/zcgj-zcdev-zcdev-pr/src/main/java/zcgj/zcdev/zcdev/pr/plugin/operate/PeriodAimcostcbsbillEditPluginExt.java @@ -0,0 +1,1380 @@ +// +// Source code recreated from a .class file by IntelliJ IDEA +// (powered by FernFlower decompiler) +// + +package zcgj.zcdev.zcdev.pr.plugin.operate; + +import java.math.BigDecimal; +import java.util.ArrayList; +import java.util.Calendar; +import java.util.EventObject; +import java.util.HashMap; +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.OperationStatus; +import kd.bos.dataentity.entity.DynamicObject; +import kd.bos.dataentity.entity.DynamicObjectCollection; +import kd.bos.dataentity.metadata.dynamicobject.DynamicObjectType; +import kd.bos.dataentity.resource.ResManager; +import kd.bos.dataentity.utils.StringUtils; +import kd.bos.entity.EntityMetadataCache; +import kd.bos.entity.MainEntityType; +import kd.bos.entity.datamodel.events.ChangeData; +import kd.bos.entity.datamodel.events.PropertyChangedArgs; +import kd.bos.form.CloseCallBack; +import kd.bos.form.ConfirmCallBackListener; +import kd.bos.form.ConfirmTypes; +import kd.bos.form.FormShowParameter; +import kd.bos.form.MessageBoxOptions; +import kd.bos.form.MessageBoxResult; +import kd.bos.form.ShowType; +import kd.bos.form.control.Button; +import kd.bos.form.control.Control; +import kd.bos.form.control.EntryGrid; +import kd.bos.form.control.SubEntryGrid; +import kd.bos.form.control.TreeEntryGrid; +import kd.bos.form.control.events.RowClickEvent; +import kd.bos.form.control.events.RowClickEventListener; +import kd.bos.form.control.events.UploadEvent; +import kd.bos.form.control.events.UploadListener; +import kd.bos.form.events.AfterDoOperationEventArgs; +import kd.bos.form.events.BeforeDoOperationEventArgs; +import kd.bos.form.events.ClosedCallBackEvent; +import kd.bos.form.events.MessageBoxClosedEvent; +import kd.bos.form.field.BasedataEdit; +import kd.bos.form.field.events.BeforeF7SelectEvent; +import kd.bos.form.field.events.BeforeF7SelectListener; +import kd.bos.form.operate.FormOperate; +import kd.bos.list.ListShowParameter; +import kd.bos.orm.ORM; +import kd.bos.orm.query.QFilter; +import kd.bos.servicehelper.BusinessDataServiceHelper; +import kd.bos.servicehelper.QueryServiceHelper; +import kd.bos.servicehelper.user.UserServiceHelper; +import kd.bos.upload.UploadOption; +import kd.ec.basedata.business.model.ecco.BaseConstant; +import kd.ec.basedata.business.utils.EcCommonUtils; +import kd.ec.basedata.common.hierarchy.DynamicObjectTreeNode; +import kd.ec.basedata.common.utils.EcSerializeHelper; +import kd.ec.contract.common.utils.CurrencyHelper; +import kd.ec.contract.common.utils.EcConstant; +import kd.ec.contract.common.utils.EcNumberHelper; +import kd.ec.contract.common.utils.TypeUtils; +import kd.ec.cost.formplugin.AbstractEccoBillPlugin; +import kd.ec.cost.utils.AimCostCbsPoiHelper; +import kd.ec.cost.utils.CostTypeUtils; +import kd.ec.cost.utils.CurrencyFormatUtil; + +/* + * 工序期间成本预算系统插件:二开去除项目过滤逻辑和校验逻辑 + */ +public class PeriodAimcostcbsbillEditPluginExt extends AbstractEccoBillPlugin implements BeforeF7SelectListener, RowClickEventListener, UploadListener { + private static final String PROJECT_ID = "projectId"; + private static final String IS_CANCEL = "isCancel"; + private static final String FALSE = "false"; + private static final String ISLEAF = "isleaf"; + private static final String IS_PDAMOUNT_CHANGE = "isPdamountChange"; + private static final String ISDELETESUBENTRY = "isdeletesubentry"; + private static final String ISIMPORT = "isimport"; + private static final String ISDELETE = "isdelete"; + private static final String EDITONUNIT = "editonunit"; + private static final String UPLOADCBS = "uploadcbs"; + private static final String COLOR_BLUE = "#B6E5FF"; + private static final String COLOR_GRAY = "#9D9D9D"; + private static final String COLOR_WRITE = "#FFFFFF"; + private static final String TREEENTRYENTITY = "treeentryentity"; + private static final String PROJECTPARAM = "projectId"; + private double versionNum = 1.0; + + public PeriodAimcostcbsbillEditPluginExt() { + } + + public void registerListener(EventObject e) { + super.registerListener(e); + BasedataEdit unitproject = (BasedataEdit)this.getControl("unitproject"); + unitproject.addBeforeF7SelectListener(this); + BasedataEdit project = (BasedataEdit)this.getControl("project"); + project.addBeforeF7SelectListener(this); + BasedataEdit boqEdit = (BasedataEdit)this.getControl("projectboq"); + boqEdit.addBeforeF7SelectListener(this); + TreeEntryGrid grid = (TreeEntryGrid)this.getControl("treeentryentity"); + grid.addRowClickListener(this); + Button uploadBtn = (Button)this.getControl("uploadcbs"); + uploadBtn.addUploadListener(this); + } + + public void entryRowClick(RowClickEvent rowclickevent) { +// super.entryRowClick(rowclickevent);//二开注释 + this.setsubEntryColor(); + this.setSubEntrySumAmount(); + } + + protected void setsubEntryColor() { + if (this.isAdjust()) { + SubEntryGrid subentryGrid = (SubEntryGrid)this.getView().getControl("subentryentity"); + int rowcount = this.getModel().getEntryRowCount("subentryentity"); + + for(int i = 0; i < rowcount; ++i) { + String oldentryid = TypeUtils.nullToString(this.getModel().getValue("oldentryid", i)); + if (!"".equals(oldentryid) && !"0".equals(oldentryid)) { + BigDecimal oldAdjuAmount = (BigDecimal)this.getModel().getValue("oldamountre", i); + BigDecimal amountnew = (BigDecimal)this.getModel().getValue("amount", i); + BigDecimal price = (BigDecimal)this.getModel().getValue("price", i); + BigDecimal qty = (BigDecimal)this.getModel().getValue("qty", i); + if (amountnew.compareTo(EcNumberHelper.ZERO) == 0 && price.compareTo(EcNumberHelper.ZERO) == 0 && qty.compareTo(EcNumberHelper.ZERO) == 0) { + subentryGrid.setRowBackcolor("#9D9D9D", new int[]{i}); + } else if (oldAdjuAmount.compareTo(amountnew) != 0) { + subentryGrid.setRowBackcolor("#B6E5FF", new int[]{i}); + } else { + subentryGrid.setRowBackcolor("#FFFFFF", new int[]{i}); + } + } else { + subentryGrid.setRowBackcolor("#B6E5FF", new int[]{i}); + } + } + } + + } + + public void beforeF7Select(BeforeF7SelectEvent beforef7selectevent) { + String name = beforef7selectevent.getProperty().getName(); + if ("unitproject".equals(name)) { + this.beforeUnitprojectSelected(beforef7selectevent); + } else if ("projectboq".equals(name)) { + this.beforeProjectBoqSelected(beforef7selectevent); + }/* else if ("project".equals(name)) { + this.beforeProjectSelected(beforef7selectevent); + }*/ //二开注释掉的 + + } + + protected void beforeProjectSelected(BeforeF7SelectEvent ent) { + ListShowParameter parameter = (ListShowParameter)ent.getFormShowParameter(); + List projectIds = new ArrayList(); + DynamicObject period = this.getView().getModel().getDataEntity().getDynamicObject("period"); + if (period != null) { + QFilter filter = new QFilter("period", "=", period.getPkValue()); + filter.and(new QFilter("id", "!=", this.getModel().getDataEntity().getPkValue())); + DynamicObject[] costbills = BusinessDataServiceHelper.load("ecco_periodcostbillcbs", "id,billno,billstatus,creator,modifier,auditor,auditdate,modifytime,createtime,org,name,project,unitproject,totalamount,versionno,remark,oldid,treeentryentity.id,treeentryentity.pid,treeentryentity.isGroupNode,treeentryentity.cbs,treeentryentity.oldamount,treeentryentity.pdamount,treeentryentity.description,treeentryentity.isgua,treeentryentity.isleaf,treeentryentity.oldcbsentryid,treeentryentity.isdelete,treeentryentity.pdpercent,treeentryentity.totalpdamount,period,isenable,currency,aimcostversion,editonunit,fiaccountorg,billhead_lk.id,billhead_lk.billhead_lk_stableid,billhead_lk.billhead_lk_sbillid,billhead_lk.billhead_lk_sid", new QFilter[]{filter}); + DynamicObject[] var7 = costbills; + int var8 = costbills.length; + + for(int var9 = 0; var9 < var8; ++var9) { + DynamicObject costbill = var7[var9]; + DynamicObject project = costbill.getDynamicObject("project"); + if (!project.getBoolean("editonunit")) { + projectIds.add((Long)project.getPkValue()); + } + } + + QFilter qFilter = new QFilter("id", "not in", projectIds); + parameter.getListFilterParameter().getQFilters().add(qFilter); + } + } + + protected void beforeProjectBoqSelected(BeforeF7SelectEvent beforef7selectevent) { + boolean editOnUnit = (Boolean)this.getModel().getValue("editonunit"); + DynamicObject unitproject = (DynamicObject)this.getModel().getValue("unitproject"); + ListShowParameter parameter = (ListShowParameter)beforef7selectevent.getFormShowParameter(); + if (editOnUnit && unitproject == null) { + this.getView().showTipNotification(ResManager.loadKDString("请填写“单位工程”字段。", "PeriodAimcostcbsbillEditPlugin_0", "ec-ecco-formplugin", new Object[0])); + beforef7selectevent.setCancel(true); + } else { + if (editOnUnit) { + QFilter qFilter = new QFilter("unitproject", "=", unitproject.getPkValue()); + parameter.getListFilterParameter().getQFilters().add(qFilter); + } + + DynamicObject project = (DynamicObject)this.getModel().getValue("project"); + if (project != null) { + QFilter qFilter = new QFilter("project", "=", project.getPkValue()); + parameter.getListFilterParameter().getQFilters().add(qFilter); + } + + parameter.setFormId("bos_listf7"); + } + } + + protected void beforeUnitprojectSelected(BeforeF7SelectEvent beforef7selectevent) { + ListShowParameter parameter = (ListShowParameter)beforef7selectevent.getFormShowParameter(); + DynamicObject project = (DynamicObject)this.getModel().getValue("project"); + QFilter qFilter = new QFilter("parent", "=", project != null ? project.getPkValue() : 0L); + List unitprojectIds = new ArrayList(); + QFilter filter = new QFilter("project", "=", project != null ? project.getPkValue() : 0L); + DynamicObject period = this.getView().getModel().getDataEntity().getDynamicObject("period"); + if (period != null) { + filter.and(new QFilter("period", "=", period.getPkValue())); + filter.and(new QFilter("id", "!=", this.getModel().getDataEntity().getPkValue())); + DynamicObject[] costbills = BusinessDataServiceHelper.load("ecco_periodcostbillcbs", "id,billno,billstatus,creator,modifier,auditor,auditdate,modifytime,createtime,org,name,project,unitproject,totalamount,versionno,remark,oldid,treeentryentity.id,treeentryentity.pid,treeentryentity.isGroupNode,treeentryentity.cbs,treeentryentity.oldamount,treeentryentity.pdamount,treeentryentity.description,treeentryentity.isgua,treeentryentity.isleaf,treeentryentity.oldcbsentryid,treeentryentity.isdelete,treeentryentity.pdpercent,treeentryentity.totalpdamount,period,isenable,currency,aimcostversion,editonunit,fiaccountorg,billhead_lk.id,billhead_lk.billhead_lk_stableid,billhead_lk.billhead_lk_sbillid,billhead_lk.billhead_lk_sid", new QFilter[]{filter}); + DynamicObject[] var9 = costbills; + int var10 = costbills.length; + + for(int var11 = 0; var11 < var10; ++var11) { + DynamicObject costbill = var9[var11]; + DynamicObject unitproject = costbill.getDynamicObject("unitproject"); + unitprojectIds.add((Long)unitproject.getPkValue()); + } + + qFilter.and(new QFilter("id", "not in", unitprojectIds)); + parameter.setCaption(ResManager.loadKDString("单位工程/标段", "PeriodAimcostcbsbillEditPlugin_1", "ec-ecco-formplugin", new Object[0])); + parameter.getListFilterParameter().getQFilters().add(qFilter); + } + } + + protected int findrowindex(String cbsid) { + int rowindex = -1; + + for(int i = 0; i < this.getModel().getEntryRowCount("treeentryentity"); ++i) { + DynamicObject cbsInfo = (DynamicObject)this.getModel().getValue("cbs", i); + if (cbsInfo != null && cbsid.equals(TypeUtils.nullToString(cbsInfo.getPkValue()))) { + rowindex = i; + } + } + + return rowindex; + } + + public void closedCallBack(ClosedCallBackEvent closedcallbackevent) { + super.closedCallBack(closedcallbackevent); + String actionID = closedcallbackevent.getActionId(); + if ("batchsetup".equals(actionID) && closedcallbackevent.getReturnData() != null) { + this.batchSetup(closedcallbackevent); + } + + } + + protected void batchSetup(ClosedCallBackEvent closedcallbackevent) { + Map map = (Map)closedcallbackevent.getReturnData(); + BigDecimal pdPercent = (BigDecimal)map.get("periodpercent"); + TreeEntryGrid treeEntry = (TreeEntryGrid)this.getControl("treeentryentity"); + int[] selRows = treeEntry.getSelectRows(); + + for(int i = 0; i < selRows.length; ++i) { + int curIndex = selRows[i]; + boolean isleaf = (Boolean)this.getModel().getValue("isleaf", curIndex); + BigDecimal totalPdAmount = (BigDecimal)this.getModel().getValue("totalpdamount", curIndex); + if (isleaf && BigDecimal.ZERO.compareTo(totalPdAmount) != 0) { + this.getModel().setValue("pdpercent", pdPercent, curIndex); + BigDecimal pdAmount = (BigDecimal)this.getModel().getValue("pdamount", curIndex); + pdPercent = pdAmount.divide(totalPdAmount, 10, 4).multiply(BigDecimal.valueOf(100L)); + this.getModel().beginInit(); + this.getModel().setValue("pdpercent", pdPercent, curIndex); + this.getModel().endInit(); + this.getView().updateView("pdpercent", curIndex); + } + } + + if (selRows.length > 0) { + treeEntry.selectRows(selRows[0]); + } + + } + + protected DynamicObjectTreeNode dynamicObjectToTreeNode(DynamicObject cbsEntryinfo, DynamicObject cbsInfo) { + DynamicObjectTreeNode child = new DynamicObjectTreeNode(); + child.setId((Long)cbsEntryinfo.getPkValue()); + if (cbsEntryinfo.get("pid") != null && cbsEntryinfo.getLong("pid") != 0L) { + child.setParentId(cbsEntryinfo.getLong("pid")); + } else { + child.setParentId(1L); + } + + child.setName(cbsInfo.getString("name")); + child.setValue(cbsEntryinfo); + child.setNumber(cbsInfo.getString("number")); + return child; + } + + public void afterCreateNewData(EventObject e) { + super.afterCreateNewData(e); + Calendar cal = Calendar.getInstance(); + int year = cal.get(1); + int month = cal.get(2) + 1; + QFilter yearFilter = new QFilter("periodyear", "=", year); + QFilter monthFilter = new QFilter("periodnumber", "=", month); + DynamicObject[] peridoArr = BusinessDataServiceHelper.load("bd_period", "number,name,periodyear,periodnumber", new QFilter[]{yearFilter, monthFilter}); + if (peridoArr != null && peridoArr.length > 0) { + DynamicObject period = peridoArr[0]; + this.getModel().setValue("period", period); + } + + FormShowParameter parameter = this.getView().getFormShowParameter(); + ORM orm = ORM.create(); + DynamicObject project; + DynamicObjectCollection entryColl; + if (!this.isAdjust()) { + Object projectId = parameter.getCustomParam("projectId"); + if (projectId != null) { + project = BusinessDataServiceHelper.loadSingle(projectId, "ec_project"); + this.getModel().setValue("project", project); + this.getModel().setValue("editonunit", project.getBoolean("editonunit")); + this.getModel().setValue("fiaccountorg", project.get("fiaccountorg_id")); + QFilter procbsfilter = new QFilter("project", "=", Long.valueOf(projectId.toString())); + QFilter enbaleFilter = new QFilter("isenable", "=", true); + DynamicObject aimCostCbs = BusinessDataServiceHelper.loadSingle("ecco_aimcostbillcbs", "versionno,treeentryentity.cbs,treeentryentity.pdamount,treeentryentity.isgua,treeentryentity.isleaf,treeentryentity.pid,subentryentity.resourceitem,subentryentity.measureunit,subentryentity.qty,subentryentity.price,subentryentity.amount,subentryentity.cbsre,subentryentity.costaccount,subentryentity.projectboq,subentryentity.costitem", new QFilter[]{procbsfilter, enbaleFilter}); + if (aimCostCbs != null) { + this.getModel().setValue("aimcostversion", aimCostCbs.get("versionno")); + entryColl = aimCostCbs.getDynamicObjectCollection("treeentryentity"); + if (!entryColl.isEmpty()) { + this.fillProCbsTreeList(entryColl); + } + } + } + + this.getModel().setValue("creator", BusinessDataServiceHelper.loadSingle(UserServiceHelper.getCurrentUserId(), "bos_user")); + this.getModel().setValue("versionno", this.versionNum); + } else { + MainEntityType dt = EntityMetadataCache.getDataEntityType("ecco_periodcostbillcbs"); + project = BusinessDataServiceHelper.loadSingle(parameter.getCustomParam("oldInfoid"), dt); + DynamicObject newInfo = this.getModel().getDataEntity(); + newInfo.set("id", orm.genLongId(dt)); + newInfo.set("oldid", project.getPkValue()); + newInfo.set("billno", project.get("billno")); + newInfo.set("name", project.get("name")); + newInfo.set("project", project.get("project")); + newInfo.set("unitproject", project.get("unitproject")); + newInfo.set("period", project.get("period")); + newInfo.set("totalamount", project.get("totalamount")); + newInfo.set("remark", project.get("remark")); + newInfo.set("org", project.get("org")); + newInfo.set("editonunit", project.get("editonunit")); + this.versionNum = TypeUtils.string2Double(project.getString("versionno")) + 1.0; + newInfo.set("versionno", this.versionNum); + newInfo.set("aimcostversion", project.get("aimcostversion")); + newInfo.set("fiaccountorg", project.get("fiaccountorg")); + this.getView().updateView("oldid"); + this.getView().updateView("billno"); + this.getView().updateView("name"); + this.getView().updateView("project"); + this.getView().updateView("unitproject"); + this.getView().updateView("period"); + this.getView().updateView("totalamount"); + this.getView().updateView("remark"); + this.getView().updateView("org"); + this.getView().updateView("versionno"); + Map cbsEntryIdMap = new HashMap(); + DynamicObjectCollection cbsEntryColl = project.getDynamicObjectCollection("treeentryentity"); + entryColl = new DynamicObjectCollection(EcCommonUtils.getEntryDynamicObjectType("ecco_periodcostbillcbs", "treeentryentity"), newInfo); + int seq = 0; + + for(int i = 0; i < cbsEntryColl.size(); ++i) { + DynamicObject oldValue = (DynamicObject)cbsEntryColl.get(i); + if (!oldValue.getBoolean("isdelete")) { + DynamicObject newValue = new DynamicObject(oldValue.getDynamicObjectType()); + newValue.set("id", orm.genLongId(EcCommonUtils.getEntryDynamicObjectType("ecco_periodcostbillcbs", "treeentryentity"))); + if (oldValue.get("pid") != null) { + newValue.set("pid", cbsEntryIdMap.get((Long)oldValue.get("pid"))); + } + + newValue.set("seq", seq++); + newValue.set("cbs", oldValue.get("cbs")); + newValue.set("oldamount", oldValue.get("pdamount")); + newValue.set("pdamount", oldValue.get("pdamount")); + newValue.set("description", oldValue.get("description")); + newValue.set("isgua", oldValue.get("isgua")); + newValue.set("isleaf", oldValue.get("isleaf")); + newValue.set("oldcbsentryid", oldValue.getPkValue()); + newValue.set("pdpercent", oldValue.get("pdpercent")); + newValue.set("totalpdamount", oldValue.get("totalpdamount")); + cbsEntryIdMap.put((Long)oldValue.getPkValue(), (Long)newValue.getPkValue()); + DynamicObjectCollection oldSubEntries = (DynamicObjectCollection)oldValue.get("subentryentity"); + if (!oldSubEntries.isEmpty()) { + DynamicObjectCollection newSubEntries = new DynamicObjectCollection(oldSubEntries.getDynamicObjectType(), newValue); + int subseq = 0; + + for(int j = 0; j < oldSubEntries.size(); ++j) { + DynamicObject oldreValue = (DynamicObject)oldSubEntries.get(j); + if (oldreValue.getBigDecimal("amount").compareTo(EcNumberHelper.ZERO) != 0 || oldreValue.getBigDecimal("price").compareTo(EcNumberHelper.ZERO) != 0 || oldreValue.getBigDecimal("qty").compareTo(EcNumberHelper.ZERO) != 0) { + DynamicObject newreValue = new DynamicObject(oldreValue.getDynamicObjectType()); + newreValue.set("seq", subseq++); + newreValue.set("oldentryid", oldreValue.getPkValue()); + newreValue.set("id", orm.genLongId(oldSubEntries.getDynamicObjectType())); + newreValue.set("resourceitem", oldreValue.get("resourceitem")); + newreValue.set("measureunit", oldreValue.get("measureunit")); + newreValue.set("oldprice", oldreValue.get("price")); + newreValue.set("oldqty", oldreValue.get("qty")); + newreValue.set("oldamountre", oldreValue.get("amount")); + newreValue.set("price", oldreValue.get("price")); + newreValue.set("qty", oldreValue.get("qty")); + newreValue.set("amount", oldreValue.get("amount")); + newreValue.set("cbsre", oldreValue.get("cbsre")); + newreValue.set("costaccount", oldreValue.get("costaccount")); + newreValue.set("projectboq", oldreValue.get("projectboq")); + newreValue.set("reamrkre", oldreValue.get("reamrkre")); + newreValue.set("originalamt", oldreValue.get("originalamt")); + newSubEntries.add(newreValue); + } + } + + newValue.set("subentryentity", newSubEntries); + } + + entryColl.add(newValue); + } + } + + newInfo.set("treeentryentity", entryColl); + this.getView().setEnable(false, new String[]{"editonunit"}); + this.getView().updateView("treeentryentity"); + } + + } + + public void beforeBindData(EventObject e) { + super.beforeBindData(e); + if (this.isAdjust()) { + this.getView().setVisible(true, new String[]{"oldamount"}); + this.getView().setVisible(true, new String[]{"oldprice"}); + this.getView().setVisible(true, new String[]{"oldqty"}); + this.getView().setVisible(true, new String[]{"oldamountre"}); + this.getView().setEnable(false, new String[]{"project", "period", "org"}); + this.getView().updateView("treeentryentity"); + this.getView().updateView("subentryentity"); + } else { + this.getView().setVisible(false, new String[]{"oldamount"}); + this.getView().setVisible(false, new String[]{"oldprice"}); + this.getView().setVisible(false, new String[]{"oldqty"}); + this.getView().setVisible(false, new String[]{"oldamountre"}); + this.getView().updateView("treeentryentity"); + this.getView().updateView("subentryentity"); + } + + } + + public void afterBindData(EventObject eventobject) { + super.afterBindData(eventobject); + this.setUnitProjectMustinput(); + this.refershTreeEnable(); + this.setSumToRow("treeentryentity", new String[]{"oldamount", "pdamount", "totalpdamount"}); + TreeEntryGrid treeEntry = (TreeEntryGrid)this.getView().getControl("treeentryentity"); + treeEntry.setCollapse(false); + if (!"A".equals(this.getModel().getValue("billstatus"))) { + this.getView().setEnable(false, new String[]{"advconbaritemap2"}); + } + + } + + protected void setUnitProjectMustinput() { + boolean editOnUnit = (Boolean)this.getModel().getValue("editonunit"); + BasedataEdit unitProjectEdit = (BasedataEdit)this.getView().getControl("unitproject"); + unitProjectEdit.setMustInput(editOnUnit); + } + + protected boolean isAdjust() { + if (!OperationStatus.ADDNEW.equals(this.getView().getFormShowParameter().getStatus())) { + this.versionNum = TypeUtils.string2Double(this.getModel().getDataEntity().getString("versionno")); + if (this.versionNum != 1.0) { + return true; + } + } + + return this.getView().getFormShowParameter().getCustomParam("isadjust") == null ? false : (Boolean)this.getView().getFormShowParameter().getCustomParam("isadjust"); + } + + protected void refershTreeEnable() { + int rowcount = this.getModel().getEntryRowCount("treeentryentity"); + TreeEntryGrid grid = (TreeEntryGrid)this.getView().getControl("treeentryentity"); + + for(int i = 0; i < rowcount; ++i) { + if (this.isAdjust() && this.getModel().getValue("oldcbsentryid", i) != null && !"0".equals(TypeUtils.nullToString(this.getModel().getValue("oldcbsentryid", i)))) { + BigDecimal oldAmount = EcNumberHelper.toBigDecimal(this.getModel().getValue("oldamount", i)); + BigDecimal newAmount = EcNumberHelper.toBigDecimal(this.getModel().getValue("pdamount", i)); + boolean isdelete = "true".equals(TypeUtils.nullToString(this.getModel().getValue("isdelete", i))); + if (isdelete) { + grid.setRowBackcolor("#9D9D9D", new int[]{i}); + } else if (oldAmount.compareTo(newAmount) != 0) { + grid.setRowBackcolor("#B6E5FF", new int[]{i}); + } else { + grid.setRowBackcolor("#FFFFFF", new int[]{i}); + } + } + } + + } + + public void propertyChanged(PropertyChangedArgs e) { + super.propertyChanged(e); + ChangeData chgData = e.getChangeSet()[0]; + Object oldValue = chgData.getOldValue(); + Object newValue = chgData.getNewValue(); + int rowIndex = chgData.getRowIndex(); + String propName = e.getProperty().getName(); + if (propName.equals("pdamount")) { + this.pdamountChanged(oldValue, newValue, rowIndex); + } else if (propName.equals("resourceitem")) { + this.resourceItemChanged(newValue, rowIndex); + } else if (propName.equals("price")) { + this.priceChanged(newValue, rowIndex); + } else if (propName.equals("qty")) { + this.qtyChanged(newValue, rowIndex); + } else if (propName.equals("amount")) { + this.amountChanged(chgData); + } else if (propName.equals("unitproject")) { + this.unitProjectChanged(oldValue); + } else if (propName.equals("project")) { + this.projectChanged(newValue); + } else if (propName.equals("pdpercent")) { + this.pdpercentChanged(newValue, rowIndex); + } else if (propName.equals("editonunit")) { + this.setUnitProjectMustinput(); + } else if (propName.equals("fiaccountorg")) { + this.fiaccountOrgChanged(newValue); + } else if (propName.equals("period")) { + this.periodChange(newValue, oldValue); + } + + } + + protected void periodChange(Object newValue, Object oldValue) { + DynamicObject project = this.getModel().getDataEntity().getDynamicObject("project"); + DynamicObject period = (DynamicObject)newValue; + if (project != null && period != null) { + QFilter projectFilter = new QFilter("project", "=", project.getPkValue()); + QFilter periodFilter = new QFilter("period", "=", period.getPkValue()); + boolean editOnUnit = this.getModel().getDataEntity().getBoolean("editonunit"); + if (!editOnUnit) { + DynamicObject[] costbills = BusinessDataServiceHelper.load("ecco_periodcostbillcbs", "id,billno,billstatus,creator,modifier,auditor,auditdate,modifytime,createtime,org,name,project,unitproject,totalamount,versionno,remark,oldid,treeentryentity.id,treeentryentity.pid,treeentryentity.isGroupNode,treeentryentity.cbs,treeentryentity.oldamount,treeentryentity.pdamount,treeentryentity.description,treeentryentity.isgua,treeentryentity.isleaf,treeentryentity.oldcbsentryid,treeentryentity.isdelete,treeentryentity.pdpercent,treeentryentity.totalpdamount,period,isenable,currency,aimcostversion,editonunit,fiaccountorg,billhead_lk.id,billhead_lk.billhead_lk_stableid,billhead_lk.billhead_lk_sbillid,billhead_lk.billhead_lk_sid", new QFilter[]{periodFilter, projectFilter}); + if (costbills.length > 0) { + this.getView().showTipNotification(ResManager.loadKDString("当前项目在所选期间已存在期间CBS成本预算。", "PeriodAimcostcbsbillEditPlugin_2", "ec-ecco-formplugin", new Object[0])); + this.getView().getModel().setValue("period", (DynamicObject)oldValue); + return; + } + } else { + DynamicObject unitproject = this.getView().getModel().getDataEntity().getDynamicObject("unitproject"); + if (unitproject == null) { + return; + } + + QFilter unitprojectFilter = new QFilter("unitproject", "=", unitproject.getPkValue()); + DynamicObject[] costbills = BusinessDataServiceHelper.load("ecco_periodcostbillcbs", "id,billno,billstatus,creator,modifier,auditor,auditdate,modifytime,createtime,org,name,project,unitproject,totalamount,versionno,remark,oldid,treeentryentity.id,treeentryentity.pid,treeentryentity.isGroupNode,treeentryentity.cbs,treeentryentity.oldamount,treeentryentity.pdamount,treeentryentity.description,treeentryentity.isgua,treeentryentity.isleaf,treeentryentity.oldcbsentryid,treeentryentity.isdelete,treeentryentity.pdpercent,treeentryentity.totalpdamount,period,isenable,currency,aimcostversion,editonunit,fiaccountorg,billhead_lk.id,billhead_lk.billhead_lk_stableid,billhead_lk.billhead_lk_sbillid,billhead_lk.billhead_lk_sid", new QFilter[]{periodFilter, projectFilter, unitprojectFilter}); + if (costbills.length > 0) { + this.getView().showTipNotification(ResManager.loadKDString("当前单位工程在所选期间已存在期间CBS成本预算。", "PeriodAimcostcbsbillEditPlugin_3", "ec-ecco-formplugin", new Object[0])); + this.getView().getModel().setValue("period", (DynamicObject)oldValue); + return; + } + } + + } + } + + private void fiaccountOrgChanged(Object newValue) { + DynamicObject org; + DynamicObject currency; + if (newValue != null) { + org = (DynamicObject)newValue; + currency = CurrencyHelper.getCurrency((Long)org.getPkValue()); + if (currency != null) { + this.getModel().setValue("currency", currency); + } + } else { + org = this.getModel().getDataEntity().getDynamicObject("org"); + if (org != null) { + currency = CurrencyHelper.getCurrency((Long)org.getPkValue()); + if (currency != null) { + this.getModel().setValue("currency", currency); + } + } + } + + } + + protected void pdpercentChanged(Object newValue, int rowIndex) { + BigDecimal percent = EcNumberHelper.toBigDecimal(newValue).divide(BigDecimal.valueOf(100L)); + BigDecimal totalPdAmount = EcNumberHelper.toBigDecimal(this.getModel().getValue("totalpdamount", rowIndex)); + BigDecimal pdAmount = totalPdAmount.multiply(percent); + DynamicObject treeEntryRowObj = this.getModel().getEntryRowEntity("treeentryentity", rowIndex); + DynamicObjectCollection subEntryRowColllection = treeEntryRowObj.getDynamicObjectCollection("subentryentity"); + if (subEntryRowColllection != null && !subEntryRowColllection.isEmpty()) { + pdAmount = BigDecimal.ZERO; + + for(int i = 0; i < subEntryRowColllection.size(); ++i) { + DynamicObject subEntryRowObj = (DynamicObject)subEntryRowColllection.get(i); + BigDecimal originalAmt = subEntryRowObj.getBigDecimal("originalamt"); + BigDecimal subAmount = originalAmt.multiply(percent); + if (subAmount.compareTo(BigDecimal.ZERO) != 0) { + BigDecimal subPrice = subEntryRowObj.getBigDecimal("price"); + BigDecimal subQty = subAmount.divide(subPrice, 10, 4); + subEntryRowObj.set("amount", subAmount); + subEntryRowObj.set("qty", subQty); + pdAmount = pdAmount.add(subAmount); + } else { + pdAmount = pdAmount.add(subEntryRowObj.getBigDecimal("amount")); + } + } + } + + this.getModel().setValue("pdamount", pdAmount, rowIndex); + } + + protected void projectChanged(Object newValue) { + this.getView().getFormShowParameter().setCustomParam("isCancel", "true"); + this.getModel().setValue("unitproject", (Object)null); + if (newValue == null) { + this.getModel().setValue("totalamount", (Object)null); + this.getModel().setValue("aimcostversion", (Object)null); + this.getModel().deleteEntryData("treeentryentity"); + } else { + this.reloadFromTotalAimCost(); + } + } + + protected void reloadFromTotalAimCost() { + this.getModel().deleteEntryData("treeentryentity"); + DynamicObject aimCostCbs = this.getEnabledTotalAimCost(); + if (aimCostCbs != null) { + this.getModel().setValue("aimcostversion", aimCostCbs.get("versionno")); + DynamicObjectCollection procbsEntry = aimCostCbs.getDynamicObjectCollection("treeentryentity"); + if (!procbsEntry.isEmpty()) { + this.fillProCbsTreeList(procbsEntry); + } + } + + this.getModel().setValue("creator", BusinessDataServiceHelper.loadSingle(UserServiceHelper.getCurrentUserId(), "bos_user")); + } + + protected DynamicObject getEnabledTotalAimCost() { + DynamicObject project = (DynamicObject)this.getModel().getValue("project"); + DynamicObject unitProject = (DynamicObject)this.getModel().getValue("unitproject"); + boolean editOnUnit = (Boolean)this.getModel().getValue("editonunit"); + if (project != null && (!editOnUnit || unitProject != null)) { + QFilter filter = new QFilter("isenable", "=", true); + filter.and(new QFilter("project", "=", project.getPkValue())); + if (editOnUnit) { + filter.and(new QFilter("unitproject", "=", unitProject.getPkValue())); + } + + return BusinessDataServiceHelper.loadSingle("ecco_aimcostbillcbs", "versionno,treeentryentity.cbs,treeentryentity.pdamount,treeentryentity.isgua,treeentryentity.isleaf,treeentryentity.pid,subentryentity.resourceitem,subentryentity.measureunit,subentryentity.qty,subentryentity.price,subentryentity.amount,subentryentity.cbsre,subentryentity.costaccount,subentryentity.projectboq,subentryentity.costitem", new QFilter[]{filter}); + } else { + return null; + } + } + + protected void unitProjectChanged(Object oldValue) { + boolean isCancel = "true".equals(TypeUtils.nullToString((String)this.getView().getFormShowParameter().getCustomParam("isCancel"))); + if (isCancel) { + this.getView().getFormShowParameter().setCustomParam("isCancel", "false"); + } else { + DynamicObjectCollection entryEntity = this.getModel().getEntryEntity("treeentryentity"); + if (entryEntity != null && !entryEntity.isEmpty()) { + ConfirmCallBackListener confirmCallBack = new ConfirmCallBackListener("unitprojectchange_callback", this); + String unitPk = oldValue == null ? "0" : ((DynamicObject)oldValue).getPkValue().toString(); + this.getPageCache().put("oldunitproject", unitPk); + this.getView().showConfirm(ResManager.loadKDString("该操作会重新加载分录数据,是否继续?", "PeriodAimcostcbsbillEditPlugin_4", "ec-ecco-formplugin", new Object[0]), MessageBoxOptions.OKCancel, ConfirmTypes.Delete, confirmCallBack); + } else { + this.reloadFromTotalAimCost(); + } + } + + } + + protected void amountChanged(ChangeData changeData) { + boolean isimport = "true".equals(TypeUtils.nullToString((String)this.getView().getFormShowParameter().getCustomParam("isdeletesubentry"))); + if (!isimport) { + int parentRowIndex = changeData.getParentRowIndex(); + EntryGrid treeEntry = (EntryGrid)this.getView().getControl("treeentryentity"); + int[] selectrows = treeEntry.getSelectRows(); + if (parentRowIndex >= 0) { + DynamicObject treeEntryRowObj = this.getModel().getEntryRowEntity("treeentryentity", parentRowIndex); + DynamicObjectCollection subentryentity = treeEntryRowObj.getDynamicObjectCollection("subentryentity"); + BigDecimal pdAmount = (BigDecimal)subentryentity.stream().map((o) -> { + return o.getBigDecimal("amount"); + }).reduce(BigDecimal.ZERO, BigDecimal::add); + BigDecimal totalPdAmount = (BigDecimal)this.getModel().getValue("totalpdamount"); + BigDecimal pdpercent = BigDecimal.ZERO; + if (BigDecimal.ZERO.compareTo(totalPdAmount) != 0) { + pdpercent = pdAmount.divide(totalPdAmount, 10, 4).multiply(BigDecimal.valueOf(100L)); + } + + treeEntryRowObj.set("pdpercent", pdpercent); + this.getView().updateView("treeentryentity"); + this.getModel().setValue("pdamount", pdAmount, parentRowIndex); + this.refershTreeEnable(); + if (selectrows.length > 0) { + treeEntry.selectRows(selectrows[0]); + } + } + + this.setsubEntryColor(); + this.setSubEntrySumAmount(); + } + } + + protected void qtyChanged(Object newValue, int rowIndex) { + BigDecimal newQty = (BigDecimal)newValue; + newQty = newQty == null ? BigDecimal.ZERO : newQty; + BigDecimal price = (BigDecimal)this.getModel().getValue("price", rowIndex); + this.getModel().setValue("amount", newQty.multiply(price), rowIndex); + } + + protected void priceChanged(Object newValue, int rowIndex) { + BigDecimal newPrice = (BigDecimal)newValue; + newPrice = newPrice == null ? BigDecimal.ZERO : newPrice; + BigDecimal qty = (BigDecimal)this.getModel().getValue("qty", rowIndex); + this.getModel().setValue("amount", newPrice.multiply(qty), rowIndex); + } + + protected void resourceItemChanged(Object newValue, int rowIndex) { + if (newValue != null) { + DynamicObject resourceItem = (DynamicObject)newValue; + String costType = CostTypeUtils.getCostType(resourceItem); + this.getModel().setValue("costitem", costType, rowIndex); + } + + } + + protected void pdamountChanged(Object oldValue, Object newValue, int rowIndex) { + boolean isimport = "true".equals(TypeUtils.nullToString((String)this.getView().getFormShowParameter().getCustomParam("isimport"))); + boolean isdeletesubentry = "true".equals(TypeUtils.nullToString((String)this.getView().getFormShowParameter().getCustomParam("isdeletesubentry"))); + boolean isPdamountChange = "true".equals(TypeUtils.nullToString((String)this.getView().getFormShowParameter().getCustomParam("isPdamountChange"))); + if (!isimport && !isdeletesubentry && !isPdamountChange) { + this.getView().getFormShowParameter().setCustomParam("isPdamountChange", "true"); + DynamicObject row = this.getModel().getEntryRowEntity("treeentryentity", rowIndex); + BigDecimal pdTotalAmount = (BigDecimal)this.getModel().getValue("totalpdamount", rowIndex); + BigDecimal pdAmount = (BigDecimal)this.getModel().getValue("pdamount", rowIndex); + BigDecimal oldAmount; + if (BigDecimal.ZERO.compareTo(pdTotalAmount) != 0) { + oldAmount = pdAmount.divide(pdTotalAmount, 10, 4).multiply(BigDecimal.valueOf(100L)); + row.set("pdpercent", oldAmount); + this.getModel().updateCache(); + this.getView().updateView("treeentryentity"); + } + + if (row.get("pid") != null) { + oldAmount = new BigDecimal(oldValue == null ? "0" : oldValue.toString()); + BigDecimal newAmount = new BigDecimal(newValue == null ? "0" : newValue.toString()); + String parentId = row.get("pid").toString(); + this.setParentAmount("treeentryentity", "pdamount", rowIndex, parentId, oldAmount, newAmount); + Map mapSum = this.sumTable("treeentryentity", new String[]{"pdamount"}); + this.getModel().setValue("totalamount", EcNumberHelper.toBigDecimal(mapSum.get("pdamount"))); + } + + this.getView().updateView("totalamount"); + this.refershTreeEnable(); + this.setSumToRow("treeentryentity", new String[]{"oldamount", "pdamount", "totalpdamount"}); + this.getView().getFormShowParameter().setCustomParam("isPdamountChange", "false"); + } + } + + protected void fillProCbsTreeList(DynamicObjectCollection oldProcbsEntryCol) { + DynamicObjectCollection curProCbsentryCol = this.getModel().getEntryEntity("treeentryentity"); + curProCbsentryCol.clear(); + DynamicObjectType cbsProEntryDt = curProCbsentryCol.getDynamicObjectType(); + ORM orm = ORM.create(); + Map idMap = new HashMap(16); + Iterator var6 = oldProcbsEntryCol.iterator(); + + DynamicObject newProcbsEntryInfo; + while(var6.hasNext()) { + DynamicObject oldProcbsEntryInfo = (DynamicObject)var6.next(); + newProcbsEntryInfo = new DynamicObject(cbsProEntryDt); + long oldId = oldProcbsEntryInfo.getLong("id"); + long newId = orm.genLongId(cbsProEntryDt); + newProcbsEntryInfo.set("id", newId); + idMap.put(oldId, newId); + DynamicObjectCollection newSubEntryCol = newProcbsEntryInfo.getDynamicObjectCollection("subentryentity"); + this.setProcbsEntryInfo(newProcbsEntryInfo, oldProcbsEntryInfo, idMap); + DynamicObjectCollection oldSubEntryCol = oldProcbsEntryInfo.getDynamicObjectCollection("subentryentity"); + if (!oldSubEntryCol.isEmpty()) { + Iterator var15 = oldSubEntryCol.iterator(); + + while(var15.hasNext()) { + DynamicObject oldSubEntryInfo = (DynamicObject)var15.next(); + DynamicObject newSubEntryInfo = new DynamicObject(newSubEntryCol.getDynamicObjectType()); + this.setSubEntryInfo(newSubEntryInfo, oldSubEntryInfo); + newSubEntryCol.add(newSubEntryInfo); + } + } + + newProcbsEntryInfo.set("subentryentity", newSubEntryCol); + BigDecimal subTotalpdAmount = BigDecimal.ZERO; + if (!newProcbsEntryInfo.getBoolean("isgua") && newProcbsEntryInfo.getBoolean("isleaf")) { + subTotalpdAmount = newProcbsEntryInfo.getBigDecimal("totalpdamount"); + } else if (!newSubEntryCol.isEmpty()) { + subTotalpdAmount = BigDecimal.valueOf((Double)newSubEntryCol.stream().collect(Collectors.summingDouble((subEntryObj) -> { + BigDecimal subPdamount = subEntryObj.getBigDecimal("amount"); + return subPdamount != null && BigDecimal.ZERO.compareTo(subPdamount) != 0 ? subPdamount.doubleValue() : 0.0; + }))); + } + + newProcbsEntryInfo.set("pdamount", subTotalpdAmount); + newProcbsEntryInfo.set("pdpercent", BigDecimal.valueOf(100L)); + curProCbsentryCol.add(newProcbsEntryInfo); + } + + this.getModel().updateEntryCache(curProCbsentryCol); + this.getView().updateView("treeentryentity"); + int rowCount = this.getModel().getEntryRowCount("treeentryentity"); + + for(int i = 0; i < rowCount; ++i) { + newProcbsEntryInfo = this.getModel().getEntryRowEntity("treeentryentity", i); + String parentId = newProcbsEntryInfo.get("pid").toString(); + BigDecimal pdAmount = (BigDecimal)this.getModel().getValue("pdamount", i); + this.setParentAmount("treeentryentity", "pdamount", i, parentId, BigDecimal.ZERO, pdAmount); + } + + TreeEntryGrid treeEntry = (TreeEntryGrid)this.getControl("treeentryentity"); + treeEntry.setCollapse(false); + this.setSumToRow("treeentryentity", new String[]{"oldamount", "pdamount", "totalpdamount"}); + Map mapSum = this.sumTable("treeentryentity", new String[]{"pdamount"}); + this.getModel().setValue("totalamount", EcNumberHelper.toBigDecimal(mapSum.get("pdamount"))); + } + + protected void setSubEntryInfo(DynamicObject newSubEntryInfo, DynamicObject oldSubEntryInfo) { + newSubEntryInfo.set("resourceitem", oldSubEntryInfo.get("resourceitem")); + newSubEntryInfo.set("measureunit", oldSubEntryInfo.get("measureunit")); + newSubEntryInfo.set("qty", oldSubEntryInfo.get("qty")); + newSubEntryInfo.set("price", oldSubEntryInfo.get("price")); + newSubEntryInfo.set("amount", oldSubEntryInfo.get("amount")); + newSubEntryInfo.set("originalamt", oldSubEntryInfo.get("amount")); + newSubEntryInfo.set("cbsre", oldSubEntryInfo.get("cbsre")); + newSubEntryInfo.set("costaccount", oldSubEntryInfo.get("costaccount")); + newSubEntryInfo.set("projectboq", oldSubEntryInfo.get("projectboq")); + newSubEntryInfo.set("costitem", oldSubEntryInfo.get("costitem")); + } + + protected void setProcbsEntryInfo(DynamicObject newProcbsEntryInfo, DynamicObject oldProcbsEntryInfo, Map idMap) { + newProcbsEntryInfo.set("cbs", oldProcbsEntryInfo.getDynamicObject("cbs")); + newProcbsEntryInfo.set("totalpdamount", oldProcbsEntryInfo.get("pdamount")); + newProcbsEntryInfo.set("isgua", oldProcbsEntryInfo.get("isgua")); + newProcbsEntryInfo.set("isleaf", oldProcbsEntryInfo.get("isleaf")); + Long oldPid = oldProcbsEntryInfo.getLong("pid"); + if (idMap.get(oldPid) != null) { + newProcbsEntryInfo.set("pid", idMap.get(oldPid)); + } + + } + + protected void setSubEntrySumAmount() { + SubEntryGrid subentryGrid = (SubEntryGrid)this.getView().getControl("subentryentity"); + int rowcount = this.getModel().getEntryRowCount("subentryentity"); + BigDecimal totalSubAmount = BigDecimal.ZERO; + + for(int i = 0; i < rowcount; ++i) { + BigDecimal subEntryAmount = (BigDecimal)this.getModel().getValue("amount", i); + totalSubAmount = EcNumberHelper.add(totalSubAmount, subEntryAmount); + } + + Map floatButtomData = new HashMap(16); + DynamicObject currency = this.getModel().getDataEntity().getDynamicObject("currency"); + floatButtomData.put("amount", CurrencyFormatUtil.getAfterFormatString(currency, totalSubAmount)); + subentryGrid.setFloatButtomData(floatButtomData); + this.setSumToRow("treeentryentity", new String[]{"oldamount", "pdamount", "totalpdamount"}); + } + + protected void setSumToRow(String tbl, String[] cols) { + if (null != tbl && !"".equals(tbl)) { + EntryGrid treeEntry = (EntryGrid)this.getView().getControl(tbl); + Map floatButtomData = new HashMap(16); + treeEntry.setFloatButtomData(floatButtomData); + + for(int i = 0; i < cols.length; ++i) { +// floatButtomData.put(cols[i], (Object)null);//已被下面二开替代 + floatButtomData.put(cols[i], (String) null); + } + + Map mapSum = this.sumTable(tbl, cols); + Set setKey = mapSum.keySet(); + Iterator iter = setKey.iterator(); + + while(iter.hasNext()) { + String str = (String)iter.next(); + DynamicObject currency = this.getModel().getDataEntity().getDynamicObject("currency"); + floatButtomData.put(str, CurrencyFormatUtil.getAfterFormatString(currency, mapSum.get(str))); + } + + treeEntry.setFloatButtomData(floatButtomData); + } + } + + protected Map sumTable(String tbl, String[] cols) { + Map mapSum = new HashMap(); + if (tbl != null && !"".equals(tbl)) { + int tblLength = this.getModel().getEntryRowCount(tbl); + int colLength = cols.length; + + for(int i = 0; i < tblLength; ++i) { + DynamicObject row = this.getModel().getEntryRowEntity(tbl, i); + if (row.get("isleaf") != null && Boolean.valueOf(row.get("isleaf").toString())) { + for(int j = 0; j < colLength; ++j) { + if (row.get(cols[j]) != null) { + Object obj = EcNumberHelper.toBigDecimal(mapSum.get(cols[j])); + Object dec = EcNumberHelper.toBigDecimal(row.get(cols[j])); + mapSum.put(cols[j], EcNumberHelper.add(obj, dec)); + } + } + } + } + + return mapSum; + } else { + mapSum.clear(); + return mapSum; + } + } + + public void beforeDoOperation(BeforeDoOperationEventArgs beforedooperationeventargs) { + super.beforeDoOperation(beforedooperationeventargs); + FormOperate formOperate = (FormOperate)beforedooperationeventargs.getSource(); + switch (formOperate.getOperateKey()) { + case "newsubentry": + this.doNewSubEntry(beforedooperationeventargs); + break; + case "deletesubentry": + this.doDeleteSubentry(); + break; + case "new": + case "submitandnew": + DynamicObject project = (DynamicObject)this.getModel().getValue("project"); + if (project != null) { + this.getView().getFormShowParameter().setCustomParam("projectId", project.getPkValue()); + } + break; + case "save": + case "submit": + this.doBeforeSaveAndSubmit(beforedooperationeventargs); +// if ("submit".equals(key) && !this.checkIsSameVersion()) {//已被下面二开替代 + if ("submit".equals(formOperate.getOperateKey()) && !this.checkIsSameVersion()) { + this.getView().showConfirm(ResManager.loadKDString("当前项目(单位工程)的总体预算版本跟最新版本不一致,是否更新?", "PeriodAimcostcbsbillEditPlugin_5", "ec-ecco-formplugin", new Object[0]), MessageBoxOptions.OKCancel, new ConfirmCallBackListener("version_callback")); + beforedooperationeventargs.setCancel(true); + } + } + + } + + protected boolean checkIsSameVersion() { + BigDecimal aimcostversion = (BigDecimal)this.getModel().getValue("aimcostversion"); + DynamicObject aimCostCbs = this.getEnabledTotalAimCost(); + if (aimCostCbs != null) { + BigDecimal newestAimCostVersion = aimCostCbs.getBigDecimal("versionno"); + return newestAimCostVersion.compareTo(aimcostversion) == 0; + } else { + return true; + } + } + + protected void doNewSubEntry(BeforeDoOperationEventArgs beforedooperationeventargs) { + TreeEntryGrid grid = (TreeEntryGrid)this.getControl("treeentryentity"); + int[] selectrow = grid.getSelectRows(); + if (selectrow.length > 0) { + boolean isdelete = "true".equals(TypeUtils.nullToString(this.getModel().getValue("isdelete", selectrow[0]))); + if (isdelete) { + this.getView().showTipNotification(ResManager.loadKDString("已删除行无法进行新增行操作,请先添加。", "PeriodAimcostcbsbillEditPlugin_6", "ec-ecco-formplugin", new Object[0])); + beforedooperationeventargs.setCancel(true); + } else if (!"true".equals(TypeUtils.nullToString(this.getModel().getValue("isleaf", selectrow[0])))) { + this.getView().showTipNotification(ResManager.loadKDString("请在成本分解结构明细节点下进行新增行操作。", "PeriodAimcostcbsbillEditPlugin_7", "ec-ecco-formplugin", new Object[0])); + beforedooperationeventargs.setCancel(true); + } + } else { + this.getView().showTipNotification(ResManager.loadKDString("请在成本分解结构明细节点下进行新增行操作", "PeriodAimcostcbsbillEditPlugin_8", "ec-ecco-formplugin", new Object[0])); + beforedooperationeventargs.setCancel(true); + } + + } + + protected void doBeforeSaveAndSubmit(BeforeDoOperationEventArgs beforedooperationeventargs) { + String number = TypeUtils.nullToString(this.getModel().getValue("billno")); + if ("".equals(number.trim())) { + this.getView().showTipNotification(ResManager.loadKDString("编码不能为空。", "PeriodAimcostcbsbillEditPlugin_9", "ec-ecco-formplugin", new Object[0])); + beforedooperationeventargs.setCancel(true); + } else { + DynamicObject period = (DynamicObject)this.getModel().getValue("period"); + if (period == null) { + this.getView().showTipNotification(ResManager.loadKDString("期间不能为空。", "PeriodAimcostcbsbillEditPlugin_10", "ec-ecco-formplugin", new Object[0])); + beforedooperationeventargs.setCancel(true); + } else { + DynamicObject project = (DynamicObject)this.getModel().getValue("project"); + boolean editOnUnit = (Boolean)this.getModel().getValue("editonunit"); + DynamicObject unitProject = (DynamicObject)this.getModel().getValue("unitproject"); + if (editOnUnit && unitProject == null) { + this.getView().showTipNotification(ResManager.loadKDString("请填写“单位工程”字段。", "PeriodAimcostcbsbillEditPlugin_0", "ec-ecco-formplugin", new Object[0])); + beforedooperationeventargs.setCancel(true); + } else if (!editOnUnit && project == null) { + this.getView().showTipNotification(ResManager.loadKDString("请填写“项目”字段。", "PeriodAimcostcbsbillEditPlugin_11", "ec-ecco-formplugin", new Object[0])); + beforedooperationeventargs.setCancel(true); + } else { + Object id = this.getModel().getDataEntity().getPkValue(); + QFilter filter = new QFilter("project", "=", project.getPkValue()); + if (id != null && TypeUtils.nullToInt(id) != 0) { + filter.and(new QFilter(BaseConstant.ID_ENTITY_PK, "!=", id)); + } + + if (editOnUnit) { + filter.and(new QFilter("unitproject", "=", unitProject.getPkValue())); + } + + filter.and(new QFilter("period", "=", period.getPkValue())); + filter.and(new QFilter("versionno", "=", this.getModel().getValue("versionno"))); + boolean exists = QueryServiceHelper.exists("ecco_periodcostbillcbs", new QFilter[]{filter}); +// if (exists) { +// this.getView().showTipNotification(ResManager.loadKDString("本项目(单位工程)在本期间已编制预算,如需修改,请使用调整功能。", "PeriodAimcostcbsbillEditPlugin_12", "ec-ecco-formplugin", new Object[0])); +// beforedooperationeventargs.setCancel(true); +// }//二开注释掉的 + + List graySubEntryIds = (List)EcSerializeHelper.unserialize(this.getPageCache().get("subentry_grayids")); + if (graySubEntryIds != null && !graySubEntryIds.isEmpty()) { + DynamicObjectCollection entryEntity = this.getModel().getEntryEntity("treeentryentity"); + int entryRow = 0; + + for(Iterator var13 = entryEntity.iterator(); var13.hasNext(); ++entryRow) { + DynamicObject entry = (DynamicObject)var13.next(); + Iterator var15 = entry.getDynamicObjectCollection("subentryentity").iterator(); + + while(var15.hasNext()) { + DynamicObject subEntry = (DynamicObject)var15.next(); + if (!graySubEntryIds.contains(subEntry.getPkValue())) { + boolean isCancel = false; + StringBuilder errorMessage = new StringBuilder(String.format(ResManager.loadKDString("请填写第%s行项目CBS对应预算成本清单分录的非灰色行。", "PeriodAimcostcbsbillEditPlugin_13", "ec-ecco-formplugin", new Object[0]), entryRow + 1)); + BigDecimal amount = subEntry.getBigDecimal("amount"); + BigDecimal price = subEntry.getBigDecimal("price"); + BigDecimal qty = subEntry.getBigDecimal("qty"); + if (price.compareTo(BigDecimal.ZERO) == 0) { + errorMessage.append(ResManager.loadKDString("“单价”", "PeriodAimcostcbsbillEditPlugin_14", "ec-ecco-formplugin", new Object[0])); + isCancel = true; + } + + if (qty.compareTo(BigDecimal.ZERO) == 0) { + errorMessage.append(ResManager.loadKDString("“数量”", "PeriodAimcostcbsbillEditPlugin_15", "ec-ecco-formplugin", new Object[0])); + isCancel = true; + } + + if (amount.compareTo(BigDecimal.ZERO) == 0) { + errorMessage.append(ResManager.loadKDString("“金额”", "PeriodAimcostcbsbillEditPlugin_16", "ec-ecco-formplugin", new Object[0])); + isCancel = true; + } + + errorMessage.append(ResManager.loadKDString("字段!", "PeriodAimcostcbsbillEditPlugin_17", "ec-ecco-formplugin", new Object[0])); + if (isCancel) { + beforedooperationeventargs.setCancel(true); + this.getView().showMessage(errorMessage.toString()); + return; + } + } + } + } + } + + } + } + } + } + + protected void doDeleteSubentry() { + List graySubEntryIds = (List)EcSerializeHelper.unserialize(this.getPageCache().get("subentry_grayids")); + if (graySubEntryIds == null) { + graySubEntryIds = new ArrayList(10); + } + + SubEntryGrid subentryGrid = (SubEntryGrid)this.getView().getControl("subentryentity"); + int[] selectrows = subentryGrid.getSelectRows(); + if (selectrows.length > 0) { + int i; + if (this.isAdjust()) { + this.getView().getFormShowParameter().setCustomParam("isdeletesubentry", "true"); + List shijideleterows = new ArrayList(10); + BigDecimal subAmount = EcNumberHelper.ZERO; + + for(i = 0; i < selectrows.length; ++i) { + if (this.getModel().getValue("amount", selectrows[i]) != null) { + subAmount = EcNumberHelper.add(subAmount, this.getModel().getValue("amount", selectrows[i])); + } + + if (this.getModel().getValue("oldentryid", selectrows[i]) != null && !"0".equals(TypeUtils.nullToString(this.getModel().getValue("oldentryid", selectrows[i])))) { + this.getModel().setValue("price", EcNumberHelper.ZERO, selectrows[i]); + this.getModel().setValue("qty", EcNumberHelper.ZERO, selectrows[i]); + this.getModel().setValue("amount", EcNumberHelper.ZERO, selectrows[i]); + ((List)graySubEntryIds).add(this.getModel().getEntryRowEntity("subentryentity", selectrows[i]).getPkValue()); + } else { + shijideleterows.add(selectrows[i]); + } + } + + this.getView().updateView("subentryentity"); + int[] deleteRows = new int[shijideleterows.size()]; + + for(int j = shijideleterows.size() - 1; j >= 0; --j) { + deleteRows[j] = (Integer)shijideleterows.get(j); + } + + this.getModel().deleteEntryRows("subentryentity", deleteRows); + this.getView().updateView("subentryentity"); + this.setsubEntryColor(); + EntryGrid treeEntry = (EntryGrid)this.getView().getControl("treeentryentity"); + int entryCurrentRowIndex = this.getModel().getEntryCurrentRowIndex("treeentryentity"); + this.getView().updateView("treeentryentity"); + BigDecimal cbsOldAmount = EcNumberHelper.toBigDecimal(this.getModel().getValue("pdamount", entryCurrentRowIndex)); + BigDecimal totalPdAmount = EcNumberHelper.toBigDecimal(this.getModel().getValue("totalpdamount", entryCurrentRowIndex)); + BigDecimal newPdamount = EcNumberHelper.subtract(cbsOldAmount, subAmount); + this.getModel().setValue("pdamount", newPdamount, entryCurrentRowIndex); + this.getModel().setValue("pdpercent", newPdamount.divide(totalPdAmount, 10, 4).multiply(BigDecimal.valueOf(100L)), entryCurrentRowIndex); + DynamicObject row = this.getModel().getEntryRowEntity("treeentryentity", entryCurrentRowIndex); + String parentId = TypeUtils.nullToString(row.get("pid")); + if (!"".equals(parentId) && !"0".equals(parentId)) { + this.setParentAmount("treeentryentity", "pdamount", entryCurrentRowIndex, parentId, cbsOldAmount, EcNumberHelper.subtract(cbsOldAmount, subAmount)); + Map mapSum = this.sumTable("treeentryentity", new String[]{"pdamount"}); + this.getModel().setValue("totalamount", EcNumberHelper.toBigDecimal(mapSum.get("pdamount"))); + } + + this.getView().updateView("treeentryentity"); + this.refershTreeEnable(); + treeEntry.selectRows(entryCurrentRowIndex); + this.getView().getFormShowParameter().setCustomParam("isdeletesubentry", "false"); + } else { + BigDecimal subAmount = EcNumberHelper.ZERO; + +// for(int i = 0; i < selectrows.length; ++i) { +// if (this.getModel().getValue("amount", selectrows[i]) != null) { +// subAmount = EcNumberHelper.add(subAmount, this.getModel().getValue("amount", selectrows[i])); +// } +// }//已被下面二开替代 + for (int selectrow : selectrows) { + if (this.getModel().getValue("amount", selectrow) != null) { + subAmount = EcNumberHelper.add(subAmount, this.getModel().getValue("amount", selectrow)); + } + } + + EntryGrid treeEntry = (EntryGrid)this.getView().getControl("treeentryentity"); + i = this.getModel().getEntryCurrentRowIndex("treeentryentity"); + BigDecimal cbsOldAmount = EcNumberHelper.toBigDecimal(this.getModel().getValue("pdamount", i)); + this.getModel().setValue("pdamount", EcNumberHelper.subtract(cbsOldAmount, subAmount), i); + this.getView().updateView("treeentryentity"); + this.refershTreeEnable(); + treeEntry.selectRows(i); + this.getModel().deleteEntryRows("subentryentity", selectrows); + } + } + + } + + public void upload(UploadEvent evt) { +// super.upload(evt);//二开注释掉的 + String key = ((Control)evt.getSource()).getKey(); + Object[] urls = evt.getUrls(); + String url = (String)((Map)urls[0]).get("url"); + if (StringUtils.equals(key, "uploadcbs")) { + AimCostCbsPoiHelper.importCbsAndResources(this.getView(), url); + Map mapSum = this.sumTable("treeentryentity", new String[]{"pdamount"}); + this.getModel().setValue("totalamount", EcNumberHelper.toBigDecimal(mapSum.get("pdamount"))); + this.setSumToRow("treeentryentity", new String[]{"oldamount", "pdamount", "totalpdamount"}); + this.updatePdPercent(); + if (this.isAdjust()) { + this.refershTreeEnable(); + this.setsubEntryColor(); + } + } + + } + + protected void updatePdPercent() { + DynamicObjectCollection entryEntity = this.getModel().getEntryEntity("treeentryentity"); + + DynamicObject entry; + BigDecimal percent; + for(Iterator var2 = entryEntity.iterator(); var2.hasNext(); entry.set("pdpercent", percent)) { + entry = (DynamicObject)var2.next(); + percent = BigDecimal.valueOf(100L); + BigDecimal pdAmount = this.getDefaultZeroBigDecimal(entry.getBigDecimal("pdamount")); + BigDecimal totalPdAmount = this.getDefaultZeroBigDecimal(entry.getBigDecimal("totalpdamount")); + if (totalPdAmount.compareTo(BigDecimal.ZERO) != 0) { + percent = pdAmount.divide(totalPdAmount, 10, 4).multiply(BigDecimal.valueOf(100L)); + } + } + + this.getModel().updateEntryCache(entryEntity); + this.getView().updateView("treeentryentity"); + } + + protected BigDecimal getDefaultZeroBigDecimal(BigDecimal value) { + return value == null ? BigDecimal.ZERO : value; + } + + public void afterDoOperation(AfterDoOperationEventArgs afterDoOperationEventArgs) { + super.afterDoOperation(afterDoOperationEventArgs); + FormOperate formOperate = (FormOperate)afterDoOperationEventArgs.getSource(); + switch (formOperate.getOperateKey()) { + case "newsubentry": + this.doAfterNewSubEntry(); + break; + case "deletesubentry": + this.doAfterDeleteSubEntry(); + break; + case "batchsetting": + this.doBatchSetting(); + break; + case "exportcbs": + AimCostCbsPoiHelper.exportCbsAndResources(this.getView()); + break; + case "importcbs": + this.doImportCbs(); + break; + case "expandall": + this.doFoldAll(false); + break; + case "foldall": + this.doFoldAll(true); + break; + case "submit": + this.getView().setEnable(false, new String[]{"advconbaritemap2"}); + case "unsubmit": + this.getView().setEnable(true, new String[]{"advconbaritemap2"}); + } + + } + + protected void doFoldAll(boolean isFold) { + TreeEntryGrid treeGrid = (TreeEntryGrid)this.getControl("treeentryentity"); + treeGrid.setCollapse(isFold); + } + + protected void doImportCbs() { + Object project = this.getModel().getValue("project"); + Object unitProject = this.getModel().getValue("unitproject"); + boolean editOnUnit = (Boolean)this.getModel().getValue("editonunit"); + if (project == null) { + this.getView().showTipNotification(ResManager.loadKDString("请先选择项目。", "PeriodAimcostcbsbillEditPlugin_18", "ec-ecco-formplugin", new Object[0]), 3000); + } else if (editOnUnit && unitProject == null) { + this.getView().showTipNotification(ResManager.loadKDString("请先选择单位工程。", "PeriodAimcostcbsbillEditPlugin_19", "ec-ecco-formplugin", new Object[0]), 3000); + } else { + this.openImportDialog(); + } + + } + + protected void openImportDialog() { + UploadOption uo = new UploadOption(); + uo.setTitle(ResManager.loadKDString("导入CBS", "PeriodAimcostcbsbillEditPlugin_20", "ec-ecco-formplugin", new Object[0])); + uo.setSuffix(".xls"); + this.getView().showUpload(uo, "uploadcbs"); + } + + protected void doAfterNewSubEntry() { + ORM orm = ORM.create(); + TreeEntryGrid grid = (TreeEntryGrid)this.getControl("treeentryentity"); + int[] selectrow = grid.getSelectRows(); + if (selectrow.length > 0) { + boolean isGua = "true".equals(TypeUtils.nullToString(this.getModel().getValue("isgua", selectrow[0]))); + if (!isGua) { + this.getModel().setValue("isgua", true, selectrow[0]); + this.getModel().setValue("pdamount", 0, selectrow[0]); + SubEntryGrid subentryGrid = (SubEntryGrid)this.getView().getControl("subentryentity"); + int[] subselectrows = subentryGrid.getSelectRows(); + if (subselectrows.length > 0) { + DynamicObject parentCBSInfo = (DynamicObject)this.getModel().getValue("cbs", selectrow[0]); + this.getModel().setValue("cbsre", parentCBSInfo, subselectrows[0]); + } + + this.getView().updateView("treeentryentity"); + this.refershTreeEnable(); + grid.selectRows(selectrow[0]); + } + } + + int rowcount = this.getModel().getEntryRowCount("subentryentity"); + + for(int i = 0; i < rowcount; ++i) { + DynamicObject subEntity = this.getModel().getEntryRowEntity("subentryentity", i); + if (subEntity.get("id") == null || subEntity.getLong("id") == 0L) { + subEntity.set("id", orm.genLongId(subEntity.getDataEntityType())); + } + } + + this.setSubEntrySumAmount(); + } + + protected void doAfterDeleteSubEntry() { + int subRowcount = this.getModel().getEntryRowCount("subentryentity"); + if (subRowcount == 0) { + TreeEntryGrid grid = (TreeEntryGrid)this.getControl("treeentryentity"); + int[] selectrow = grid.getSelectRows(); + if (selectrow.length > 0) { + this.getModel().setValue("isgua", false, selectrow[0]); + this.refershTreeEnable(); + grid.selectRows(selectrow[0]); + } + } + + this.setSubEntrySumAmount(); + } + + protected void doBatchSetting() { + TreeEntryGrid treeEntry = (TreeEntryGrid)this.getControl("treeentryentity"); + int[] selRows = treeEntry.getSelectRows(); + if (selRows.length <= 0) { + this.getView().showTipNotification(ResManager.loadKDString("请选择项目CBS。", "PeriodAimcostcbsbillEditPlugin_21", "ec-ecco-formplugin", new Object[0]), 3000); + } else { + Map paraMap = new HashMap(16); + paraMap.put("formId", "ecco_batchsetup"); + FormShowParameter param = FormShowParameter.createFormShowParameter(paraMap); + param.getOpenStyle().setShowType(ShowType.Modal); + param.setCloseCallBack(new CloseCallBack(this, "batchsetup")); + this.getView().showForm(param); + } + } + + public void confirmCallBack(MessageBoxClosedEvent messageBoxClosedEvent) { + super.confirmCallBack(messageBoxClosedEvent); + if (messageBoxClosedEvent.getCallBackId().equals("unitprojectchange_callback")) { + this.updateUnitProjectConfirm(messageBoxClosedEvent); + } else if ("version_callback".equals(messageBoxClosedEvent.getCallBackId()) && messageBoxClosedEvent.getResult().equals(MessageBoxResult.Yes)) { + this.reloadFromTotalAimCost(); + } + + } + + protected void updateUnitProjectConfirm(MessageBoxClosedEvent messageBoxClosedEvent) { + if (messageBoxClosedEvent.getResult().equals(MessageBoxResult.Yes)) { + this.reloadFromTotalAimCost(); + } else if (messageBoxClosedEvent.getResult().equals(MessageBoxResult.Cancel)) { + this.getView().getFormShowParameter().setCustomParam("isCancel", "true"); + String oldvalue = this.getPageCache().get("oldunitproject"); + this.getModel().setValue("unitproject", oldvalue.equals("0") ? null : oldvalue); + this.getView().updateView("unitproject"); + } + + } + + protected void setParentAmount(String table, String colname, int rowIndex, String parentId, BigDecimal oldAmount, BigDecimal newAmount) { + for(int i = rowIndex - 1; i >= 0; --i) { + String parent = this.getModel().getEntryRowEntity(table, i).get("id").toString(); + if (parent.equals(parentId)) { + if (oldAmount == null) { + oldAmount = EcConstant.ZERO; + } + + if (newAmount == null) { + newAmount = EcConstant.ZERO; + } + + BigDecimal parentOldAmount = EcNumberHelper.toBigDecimal(this.getModel().getEntryRowEntity(table, i).get(colname)); + BigDecimal parentNewAmount = null; + if (parentOldAmount == null) { + parentOldAmount = EcConstant.ZERO; + parentNewAmount = newAmount; + } else { + parentNewAmount = parentOldAmount.subtract(oldAmount).add(newAmount); + } + + DynamicObject treeEntryRowObj = this.getModel().getEntryRowEntity("treeentryentity", i); + treeEntryRowObj.set("pdamount", parentNewAmount); + BigDecimal rowTotalPdAmount = (BigDecimal)this.getModel().getValue("totalpdamount", i); + BigDecimal pdPercent = BigDecimal.ZERO; + if (BigDecimal.ZERO.compareTo(rowTotalPdAmount) != 0) { + pdPercent = parentNewAmount.divide(rowTotalPdAmount, 10, 4).multiply(BigDecimal.valueOf(100L)); + } + + DynamicObject treeRow = this.getModel().getEntryRowEntity("treeentryentity", i); + treeRow.set("pdpercent", pdPercent); + this.getView().updateView("treeentryentity"); + if (treeEntryRowObj.getString("pid") != null) { + parentId = treeEntryRowObj.getString("pid"); + this.setParentAmount(table, "pdamount", i, parentId, parentOldAmount, parentNewAmount); + } + break; + } + } + + } +} diff --git a/code/zcdev/zcgj-zcdev-zcdev-pr/src/main/java/zcgj/zcdev/zcdev/pr/plugin/operate/PurchaseReqBackWriteOp.java b/code/zcdev/zcgj-zcdev-zcdev-pr/src/main/java/zcgj/zcdev/zcdev/pr/plugin/operate/PurchaseReqBackWriteOp.java new file mode 100644 index 0000000..db24cab --- /dev/null +++ b/code/zcdev/zcgj-zcdev-zcdev-pr/src/main/java/zcgj/zcdev/zcdev/pr/plugin/operate/PurchaseReqBackWriteOp.java @@ -0,0 +1,68 @@ +package zcgj.zcdev.zcdev.pr.plugin.operate; + +import kd.bos.dataentity.entity.DynamicObject; +import kd.bos.dataentity.entity.DynamicObjectCollection; +import kd.bos.entity.plugin.AbstractOperationServicePlugIn; +import kd.bos.entity.plugin.args.AfterOperationArgs; +import kd.bos.orm.query.QFilter; +import kd.bos.servicehelper.BusinessDataServiceHelper; +import kd.bos.servicehelper.operation.SaveServiceHelper; + +import java.math.BigDecimal; +import java.util.ArrayList; +import java.util.List; + +/** + * 入库单保存删除插件:保存、删除时,将入库单数量反写至采购申请单 + */ +public class PurchaseReqBackWriteOp extends AbstractOperationServicePlugIn { + + @Override + public void afterExecuteOperationTransaction(AfterOperationArgs e) { + super.afterExecuteOperationTransaction(e); + + String operationKey = e.getOperationKey();//操作标识 + DynamicObject[] dataEntities = e.getDataEntities(); + List modifiedEntities = new ArrayList<>(); + + for (DynamicObject model : dataEntities) { + long id = model.getLong("id"); + QFilter f1 = new QFilter("id", "=", id); + DynamicObject ecma_MaterialInBill = BusinessDataServiceHelper.loadSingle("ecma_materialinbill", new QFilter[]{f1});//入库单 + String matInSource = ecma_MaterialInBill.getString("matinsource");//入库来源 + DynamicObject zcgj_purchaseApply = ecma_MaterialInBill.getDynamicObject("zcgj_purchaseapply");//采购申请 + if ("6".equals(matInSource) && zcgj_purchaseApply != null) { + //为采购申请单时反写数量 + DynamicObject ecma_purchaseApply = BusinessDataServiceHelper.loadSingle("ecma_purchaseapply", + new QFilter[]{new QFilter("id", "=", zcgj_purchaseApply.getLong("id"))});//采购申请单 + DynamicObjectCollection purchaseEntryCollection = ecma_purchaseApply.getDynamicObjectCollection("purchaseentry");//采购明细单据体 + DynamicObjectCollection entryEntityCollection = ecma_MaterialInBill.getDynamicObjectCollection("entryentity");//入库单分录 + for (DynamicObject entryEntity : entryEntityCollection) { + String listingId = entryEntity.getString("listingid");//入库单分录-合同清单id + + for (DynamicObject purchaseEntry : purchaseEntryCollection) { + String purchaseEntryId = purchaseEntry.getString("id");//采购明细单据体-id + if (purchaseEntryId != null && purchaseEntryId.equals(listingId)) { + BigDecimal qty = entryEntity.getBigDecimal("qty");//入库单分录-数量 + BigDecimal inCount = purchaseEntry.getBigDecimal("zcgj_incount");//采购明细单据体-已入库数量 + if ("save".equals(operationKey)) { + purchaseEntry.set("zcgj_incount", inCount.add(qty));//采购明细单据体-已入库数量 + } else { + purchaseEntry.set("zcgj_incount", inCount.subtract(qty));//采购明细单据体-已入库数量 + } + break; + } + } + } + modifiedEntities.add(ecma_purchaseApply); + } + } + if (!modifiedEntities.isEmpty()) { + try { + SaveServiceHelper.save(modifiedEntities.toArray(new DynamicObject[0])); + } catch (Exception ex) { + throw new RuntimeException(ex); + } + } + } +}