diff --git a/code/zcdev/zcgj-zcdev-zcdev-pr/src/main/java/zcgj/zcdev/zcdev/pr/plugin/form/AimCostBoqEditPluginExt.java b/code/zcdev/zcgj-zcdev-zcdev-pr/src/main/java/zcgj/zcdev/zcdev/pr/plugin/form/AimCostBoqEditPluginExt.java new file mode 100644 index 0000000..a391940 --- /dev/null +++ b/code/zcdev/zcgj-zcdev-zcdev-pr/src/main/java/zcgj/zcdev/zcdev/pr/plugin/form/AimCostBoqEditPluginExt.java @@ -0,0 +1,2693 @@ +package zcgj.zcdev.zcdev.pr.plugin.form; + +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; +import java.math.BigDecimal; +import java.math.RoundingMode; +import java.util.ArrayList; +import java.util.Arrays; +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.TreeMap; +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.ListSelectedRowCollection; +import kd.bos.entity.datamodel.events.ChangeData; +import kd.bos.entity.datamodel.events.PropertyChangedArgs; +import kd.bos.entity.report.CellStyle; +import kd.bos.exception.KDBizException; +import kd.bos.form.CloseCallBack; +import kd.bos.form.ConfirmCallBackListener; +import kd.bos.form.MessageBoxOptions; +import kd.bos.form.MessageBoxResult; +import kd.bos.form.MessageTypes; +import kd.bos.form.ShowFormHelper; +import kd.bos.form.control.Button; +import kd.bos.form.control.Control; +import kd.bos.form.control.EntryGrid; +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.upload.UploadOption; +import kd.ec.basedata.business.model.ecco.AimCostBoqSplitModelConstant; +import kd.ec.basedata.common.utils.AimCostBoqPoiHelper; +import kd.ec.basedata.common.utils.OpenPageUtils; +import kd.ec.basedata.common.utils.POIHelperFast; +import kd.ec.basedata.formplugin.base.AbstractEcBillPlugin; +import kd.ec.cost.common.enums.AimCostTypeEnum; +import kd.ec.cost.utils.AimCostBoqCalculateHelper; +import kd.ec.cost.utils.CurrencyFormatUtil; +import org.apache.commons.beanutils.ConversionException; +import org.jetbrains.annotations.NotNull; + +public class AimCostBoqEditPluginExt extends AbstractEcBillPlugin implements BeforeF7SelectListener, RowClickEventListener, UploadListener { + private static final String ID_NUMBER_NAME = "id,number,name"; + private static final String BD_MEASUREUNITS = "bd_measureunits"; + private static final String PROJECTBOQID = "ec_ecbd_pro_boq"; + private static final String ISLEAF = "isleaf"; + private static final String PARENT = "parent"; + private static final String ADDBOQENTRY = "addboqentry"; + private static final String NEWENTRY = "newentry"; + private static final String DELETEENTRY = "deleteentry"; + private static final String DELETEBOQENTRY = "deleteboqentry"; + private static final String SHOWCOMPOSITEPRICE = "showcompositeprice"; + private static final String SHOWALLPRICE = "showallprice"; + private static final String SUBEXPORT = "subexport"; + private static final String SYSRESOURCEIMPORT = "sysresourceimport"; + private static final String EXTERNALRESIMPORT = "externalresimport"; + private static final String EXCELCOLUMNKEY = "columnKey"; + private static final String EXCELVALUE = "value"; + private static final String EXCELNAME = "name"; + private static final String RESOURCEMATCH = "resourcematch"; + private static final String PROJECT = "project"; + private static final String EC_PROJECT = "ec_project"; + private static final String[] COLUMNKEYA = new String[]{"unitproject", "boqnumber", "boqitemnumber", "boqname", "entryrate", "entryprice", "compositeprice", "artificialprice", "mainmaterialprice", "secondarymaterialprice", "machineprice", "subcontractprice", "managementprice", "profitprice", "taxprice", "otherprice"}; + private static final String[] COLUMNKEYB = new String[]{"unitproject", "boqnumber", "boqitemnumber", "boqname", "resourcetype", "resource", "resourcenumber", "resourcename", "model", "measureunit", "resourceprice", "unitcostqty", "resourceqty", "ca", "caname", "cbs", "cbsname", "costtype", "remark"}; + private static final List COLUMNKEYS = new ArrayList(2); + private static final List COLUMNKEYHASHCODES = new ArrayList(2); + public static final String COPY_ROW_INDEX = "copyRowIndex"; + + public AimCostBoqEditPluginExt() { + } + + private List getSheetname() { + List SHEETNAME = new ArrayList(2); + SHEETNAME.add(ResManager.loadKDString("工程量清单单价拆分模板", "AimCostBoqEditPlugin_0", "ec-ecco-formplugin", new Object[0])); + SHEETNAME.add(ResManager.loadKDString("综合单价分析模板", "AimCostBoqEditPlugin_1", "ec-ecco-formplugin", new Object[0])); + return SHEETNAME; + } + + private String[] getHeadera() { + return new String[]{ResManager.loadKDString("单位工程", "AimCostBoqEditPlugin_2", "ec-ecco-formplugin", new Object[0]), ResManager.loadKDString("系统编码", "AimCostBoqEditPlugin_3", "ec-ecco-formplugin", new Object[0]), ResManager.loadKDString("清单编码", "AimCostBoqEditPlugin_4", "ec-ecco-formplugin", new Object[0]), ResManager.loadKDString("清单名称", "AimCostBoqEditPlugin_5", "ec-ecco-formplugin", new Object[0]), ResManager.loadKDString("税率", "AimCostBoqEditPlugin_6", "ec-ecco-formplugin", new Object[0]), ResManager.loadKDString("控制单价", "AimCostBoqEditPlugin_7", "ec-ecco-formplugin", new Object[0]), ResManager.loadKDString("综合单价", "AimCostBoqEditPlugin_8", "ec-ecco-formplugin", new Object[0]), ResManager.loadKDString("人工单价", "AimCostBoqEditPlugin_9", "ec-ecco-formplugin", new Object[0]), ResManager.loadKDString("主材费单价", "AimCostBoqEditPlugin_10", "ec-ecco-formplugin", new Object[0]), ResManager.loadKDString("辅材费单价", "AimCostBoqEditPlugin_11", "ec-ecco-formplugin", new Object[0]), ResManager.loadKDString("机械单价", "AimCostBoqEditPlugin_12", "ec-ecco-formplugin", new Object[0]), ResManager.loadKDString("分包单价", "AimCostBoqEditPlugin_13", "ec-ecco-formplugin", new Object[0]), ResManager.loadKDString("管理费单价", "AimCostBoqEditPlugin_14", "ec-ecco-formplugin", new Object[0]), ResManager.loadKDString("利润单价", "AimCostBoqEditPlugin_15", "ec-ecco-formplugin", new Object[0]), ResManager.loadKDString("税费单价", "AimCostBoqEditPlugin_16", "ec-ecco-formplugin", new Object[0]), ResManager.loadKDString("其他费单价", "AimCostBoqEditPlugin_17", "ec-ecco-formplugin", new Object[0])}; + } + + private String[] getHeaderb() { + return new String[]{ResManager.loadKDString("单位工程", "AimCostBoqEditPlugin_2", "ec-ecco-formplugin", new Object[0]), ResManager.loadKDString("系统编码", "AimCostBoqEditPlugin_3", "ec-ecco-formplugin", new Object[0]), ResManager.loadKDString("清单编码", "AimCostBoqEditPlugin_4", "ec-ecco-formplugin", new Object[0]), ResManager.loadKDString("清单名称", "AimCostBoqEditPlugin_5", "ec-ecco-formplugin", new Object[0]), ResManager.loadKDString("清单性质", "AimCostBoqEditPlugin_18", "ec-ecco-formplugin", new Object[0]), ResManager.loadKDString("清单分类", "AimCostBoqEditPlugin_19", "ec-ecco-formplugin", new Object[0]), ResManager.loadKDString("资源编码", "AimCostBoqEditPlugin_20", "ec-ecco-formplugin", new Object[0]), ResManager.loadKDString("资源名称", "AimCostBoqEditPlugin_21", "ec-ecco-formplugin", new Object[0]), ResManager.loadKDString("规格型号", "AimCostBoqEditPlugin_22", "ec-ecco-formplugin", new Object[0]), ResManager.loadKDString("计量单位", "AimCostBoqEditPlugin_23", "ec-ecco-formplugin", new Object[0]), ResManager.loadKDString("资源单价", "AimCostBoqEditPlugin_24", "ec-ecco-formplugin", new Object[0]), ResManager.loadKDString("单位消耗量", "AimCostBoqEditPlugin_25", "ec-ecco-formplugin", new Object[0]), ResManager.loadKDString("资源数量", "AimCostBoqEditPlugin_26", "ec-ecco-formplugin", new Object[0]), ResManager.loadKDString("企业成本科目(CA)编码", "AimCostBoqEditPlugin_27", "ec-ecco-formplugin", new Object[0]), ResManager.loadKDString("企业成本科目(CA)名称", "AimCostBoqEditPlugin_28", "ec-ecco-formplugin", new Object[0]), ResManager.loadKDString("项目成本结构(CBS)编码", "AimCostBoqEditPlugin_29", "ec-ecco-formplugin", new Object[0]), ResManager.loadKDString("项目成本结构(CBS)名称", "AimCostBoqEditPlugin_30", "ec-ecco-formplugin", new Object[0]), ResManager.loadKDString("预算类型", "AimCostBoqEditPlugin_31", "ec-ecco-formplugin", new Object[0]), ResManager.loadKDString("备注", "AimCostBoqEditPlugin_32", "ec-ecco-formplugin", new Object[0])}; + } + + private List> getMustFillColumns() { + List> mustFillColumns = new ArrayList(2); + mustFillColumns.add(this.getMustFillColumnA()); + mustFillColumns.add(this.getMustFillColumnB()); + return mustFillColumns; + } + + private List getMustFillColumnA() { + List mustFillColumna = new ArrayList(4); + mustFillColumna.add(ResManager.loadKDString("系统编码", "AimCostBoqEditPlugin_3", "ec-ecco-formplugin", new Object[0])); + mustFillColumna.add(ResManager.loadKDString("清单编码", "AimCostBoqEditPlugin_4", "ec-ecco-formplugin", new Object[0])); + mustFillColumna.add(ResManager.loadKDString("清单名称", "AimCostBoqEditPlugin_5", "ec-ecco-formplugin", new Object[0])); + return mustFillColumna; + } + + private List getMustFillColumnB() { + List mustFillColumnb = new ArrayList(4); + mustFillColumnb.add(ResManager.loadKDString("系统编码", "AimCostBoqEditPlugin_3", "ec-ecco-formplugin", new Object[0])); + mustFillColumnb.add(ResManager.loadKDString("清单编码", "AimCostBoqEditPlugin_4", "ec-ecco-formplugin", new Object[0])); + mustFillColumnb.add(ResManager.loadKDString("清单名称", "AimCostBoqEditPlugin_5", "ec-ecco-formplugin", new Object[0])); + mustFillColumnb.add(ResManager.loadKDString("资源编码", "AimCostBoqEditPlugin_20", "ec-ecco-formplugin", new Object[0])); + mustFillColumnb.add(ResManager.loadKDString("资源名称", "AimCostBoqEditPlugin_21", "ec-ecco-formplugin", new Object[0])); + mustFillColumnb.add(ResManager.loadKDString("资源单价", "AimCostBoqEditPlugin_24", "ec-ecco-formplugin", new Object[0])); + return mustFillColumnb; + } + + private List getHeaders() { + List headers = new ArrayList(2); + headers.add(this.getHeadera()); + headers.add(this.getHeaderb()); + return headers; + } + + public void registerListener(EventObject e) { + super.registerListener(e); + BasedataEdit unitProject = (BasedataEdit)this.getView().getControl("unitproject"); + unitProject.addBeforeF7SelectListener(this); + BasedataEdit cbs = (BasedataEdit)this.getView().getControl("projectcbs"); + cbs.addBeforeF7SelectListener(this); + BasedataEdit ca = (BasedataEdit)this.getView().getControl("enterpriseca"); + ca.addBeforeF7SelectListener(this); + EntryGrid grid = (EntryGrid)this.getControl("treeentryentity"); + grid.addRowClickListener(this); + Button sysUploadBtn = (Button)this.getControl("sysresourceimport"); + sysUploadBtn.addUploadListener(this); + Button externalUploadBtn = (Button)this.getControl("externalresimport"); + externalUploadBtn.addUploadListener(this); + Button listingUploadBtn = (Button)this.getControl("listingimport"); + listingUploadBtn.addUploadListener(this); + BasedataEdit proj = (BasedataEdit)this.getView().getControl("project"); + if (proj != null) { + proj.addBeforeF7ViewDetailListener((beforeF7ViewDetailEvent) -> { + beforeF7ViewDetailEvent.setCancel(true); + this.getView().showForm(OpenPageUtils.buildBillShowParam(beforeF7ViewDetailEvent.getPkId(), "ec_project")); + }); + proj.addBeforeF7SelectListener(this); + } + + } + + public void entryRowClick(RowClickEvent rowclickevent) { + Control control = (Control)rowclickevent.getSource(); + if (StringUtils.equals("treeentryentity", control.getKey())) { + this.setSubEntryOperateEnable(); + } + + } + + private void setSubEntryOperateEnable() { + int rowIndex = this.getModel().getEntryCurrentRowIndex("treeentryentity"); + if (rowIndex >= 0) { + DynamicObject rowEntity = this.getModel().getEntryRowEntity("treeentryentity", rowIndex); + this.getView().setEnable(rowEntity.getBoolean("isleaf"), new String[]{"addsubentry", "deletesubentry"}); + } + + } + + public void afterBindData(EventObject arg0) { + super.afterBindData(arg0); + Object isAdjust = this.getView().getFormShowParameter().getCustomParam("isadjust"); + if (isAdjust != null) { + BigDecimal vision = (BigDecimal)this.getModel().getValue("vision"); + this.getModel().setValue("vision", vision.add(BigDecimal.ONE)); + this.getModel().setValue("iseffective", false); + this.getModel().setValue("isadjust", true); + this.getModel().setValue("lastversionamt", this.getModel().getValue("totalamount")); + this.getView().setEnable(false, new String[]{"multicurrency"}); + this.adjustAddNewBoqData(); + } + + EntryGrid grid = (EntryGrid)this.getControl("treeentryentity"); + grid.setCollapse(false); + this.setButtomAmount(); + this.updateTreeEntryCellStyle(grid, (Integer)null); + } + + protected void adjustAddNewBoqData() { + List filters = new ArrayList(4); + DynamicObject project = (DynamicObject)this.getModel().getValue("project"); + boolean isEditOnUnit = (Boolean)this.getModel().getValue("editonunit"); + Set boqIdSet = this.getBoqIds(); + filters.add(new QFilter("id", "not in", boqIdSet)); + filters.add(new QFilter("project", "=", project.getPkValue())); + if (isEditOnUnit) { + DynamicObject unitproject = (DynamicObject)this.getView().getModel().getValue("unitproject"); + filters.add(new QFilter("unitproject", "=", unitproject.getPkValue())); + } + + filters.add(new QFilter("isleaf", "=", "1")); + filters.add(new QFilter("qtytotal", "!=", 0)); + filters.add(new QFilter("enable", "=", "1")); + this.autoAddBoq(filters); + } + + public void beforeF7Select(BeforeF7SelectEvent arg0) { + String name = arg0.getProperty().getName(); + if (StringUtils.equals("unitproject", name)) { + this.beforeUnitProjectSelected(arg0); + } else if (StringUtils.equals("projectcbs", name)) { + this.beforeCbsSelected(arg0); + } else if (StringUtils.equals("enterpriseca", name)) { + this.beforeCaSelected(arg0); + } else if (StringUtils.equals("project", name)) { + this.beforeProjectSelected(arg0); + } + + } + + protected void beforeProjectSelected(BeforeF7SelectEvent arg0) { + QFilter existFilter = new QFilter("project", "!=", 0L); + existFilter.and("id", "!=", this.getModel().getDataEntity().getPkValue()); + DynamicObjectCollection query = QueryServiceHelper.query("ecco_aimcostboqsplitmodel", "project", new QFilter[]{existFilter}); + if (query != null && !query.isEmpty()) { + Set projectIds = new HashSet(query.size()); + Iterator var5 = query.iterator(); + + while(var5.hasNext()) { + DynamicObject bill = (DynamicObject)var5.next(); + projectIds.add(bill.getLong("project")); + } + + ListShowParameter parameter = (ListShowParameter)arg0.getFormShowParameter(); + QFilter projectFilter = new QFilter("id", "not in", projectIds); + projectFilter.or("boqmode", "=", "unitproject"); + parameter.getListFilterParameter().getQFilters().add(projectFilter); + } + + } + + protected void beforeCaSelected(BeforeF7SelectEvent arg0) { + ListShowParameter parameter = (ListShowParameter)arg0.getFormShowParameter(); + parameter.getListFilterParameter().getQFilters().add(new QFilter("isleaf", "=", "1")); + } + + protected void beforeCbsSelected(BeforeF7SelectEvent arg0) { + ListShowParameter parameter = (ListShowParameter)arg0.getFormShowParameter(); + DynamicObject project = this.getModel().getDataEntity().getDynamicObject("project"); + if (project != null) { + QFilter qFilter = new QFilter("project", "=", project.getPkValue()); + parameter.getListFilterParameter().getQFilters().add(qFilter); + parameter.getListFilterParameter().getQFilters().add(new QFilter("isleaf", "=", "1")); + parameter.setFormId("bos_listf7"); + } else { + this.getView().showTipNotification(ResManager.loadKDString("请先选择项目", "AimCostBoqEditPlugin_33", "ec-ecco-formplugin", new Object[0])); + arg0.setCancel(true); + } + + } + + protected void beforeUnitProjectSelected(BeforeF7SelectEvent arg0) { + ListShowParameter parameter = (ListShowParameter)arg0.getFormShowParameter(); + List unitProjectFilter = this.getUnitProjectFilter(); + parameter.getListFilterParameter().getQFilters().addAll(unitProjectFilter); + } + + public void beforeDoOperation(BeforeDoOperationEventArgs args) { + super.beforeDoOperation(args); + FormOperate source = (FormOperate)args.getSource(); + switch (source.getOperateKey()) { + case "addboqentry": + this.doAddBoqEntry(); + break; + case "deleteboqentry": + this.doDeleteBoqEntry(); + break; + case "subexport": + this.doSubExport(); + break; + case "sysresourceimport": + case "externalresimport": + case "importlisting": + this.doImportResource(args, source.getOperateKey()); + break; + case "resourcematch": + this.doResourceMatch(); + break; + case "newentry": + this.doNewEntry(); + break; + case "exportlisting": + this.doExportListing(); + break; + case "copyprice": + this.doCopyPrice(); + break; + case "pasteprice": + this.doPastePrice(); + } + + } + + protected void doPastePrice() { + EntryGrid treeGrid = (EntryGrid)this.getControl("treeentryentity"); + int[] selectRows = treeGrid.getSelectRows(); + if (selectRows != null && selectRows.length != 0) { + if (this.getPageCache().get("copyRowIndex") == null) { + this.getView().showTipNotification(ResManager.loadKDString("请先进行复制操作。", "AimCostBoqEditPlugin_35", "ec-ecco-formplugin", new Object[0])); + } else { + boolean isResourceMode = (Boolean)this.getModel().getValue("resourcemode"); + if (isResourceMode) { + this.getView().showConfirm(ResManager.loadKDString("粘贴数据将清空选中行原有的资源明细数据,是否继续?", "AimCostBoqEditPlugin_36", "ec-ecco-formplugin", new Object[0]), MessageBoxOptions.OKCancel, new ConfirmCallBackListener("pastePrice", this)); + } else { + this.pastePrice(selectRows); + } + } + } else { + this.getView().showTipNotification(ResManager.loadKDString("请选中要操作的分录数据。", "AimCostBoqEditPlugin_34", "ec-ecco-formplugin", new Object[0])); + } + } + + protected void pastePrice(int[] selectRows) { + boolean isResourceMode = (Boolean)this.getModel().getValue("resourcemode"); + int copyRowIndex = Integer.parseInt(this.getPageCache().get("copyRowIndex")); + DynamicObject copyEntry = this.getModel().getEntryRowEntity("treeentryentity", copyRowIndex); + DynamicObjectCollection entries = this.getModel().getEntryEntity("treeentryentity"); + int[] var6 = selectRows; + int var7 = selectRows.length; + + for(int var8 = 0; var8 < var7; ++var8) { + int selectRow = var6[var8]; + if (selectRow != copyRowIndex) { + DynamicObject entry = (DynamicObject)entries.get(selectRow); + if (entry.getBoolean("isleaf")) { + entry.set("entryprice", copyEntry.get("entryprice")); + entry.set("compositeprice", copyEntry.get("compositeprice")); + entry.set("artificialprice", copyEntry.get("artificialprice")); + entry.set("mainmaterialprice", copyEntry.get("mainmaterialprice")); + entry.set("secondarymaterialprice", copyEntry.get("secondarymaterialprice")); + entry.set("machineprice", copyEntry.get("machineprice")); + entry.set("subcontractprice", copyEntry.get("subcontractprice")); + entry.set("managementprice", copyEntry.get("managementprice")); + entry.set("profitprice", copyEntry.get("profitprice")); + entry.set("taxprice", copyEntry.get("taxprice")); + entry.set("otherprice", copyEntry.get("otherprice")); + entry.set("hasresource", copyEntry.get("hasresource")); + BigDecimal compositePrice = entry.getBigDecimal("compositeprice"); + compositePrice = compositePrice == null ? BigDecimal.ZERO : compositePrice; + BigDecimal qty = entry.getBigDecimal("entryqty"); + qty = qty == null ? BigDecimal.ZERO : qty; + BigDecimal aimCostAmount = compositePrice.multiply(qty); + entry.set("aimcostamount", aimCostAmount); + BigDecimal ofTax = aimCostAmount; + DynamicObject rateObject = entry.getDynamicObject("entryrate"); + BigDecimal entryPrice; + BigDecimal entryAmount; + if (rateObject != null) { + entryPrice = rateObject.getBigDecimal("taxrate").divide(new BigDecimal(100), 10, 4); + entryAmount = aimCostAmount.multiply(entryPrice); + entry.set("entrytax", entryAmount); + ofTax = aimCostAmount.multiply(BigDecimal.ONE.add(entryPrice)); + } + + entry.set("oftaxamount", ofTax); + entryPrice = entry.getBigDecimal("entryprice"); + entryPrice = entryPrice == null ? BigDecimal.ZERO : entryPrice; + entryAmount = entryPrice.multiply(qty); + entry.set("entryamount", entryAmount); + entry.set("aimprofit", entryAmount.subtract(aimCostAmount)); + if (isResourceMode) { + DynamicObjectCollection subEntries = entry.getDynamicObjectCollection("subentryentity"); + subEntries.clear(); + DynamicObjectCollection copySubEntries = copyEntry.getDynamicObjectCollection("subentryentity"); + if (!copySubEntries.isEmpty()) { + Iterator var20 = copySubEntries.iterator(); + + while(var20.hasNext()) { + DynamicObject copySubEntry = (DynamicObject)var20.next(); + DynamicObject subEntry = subEntries.addNew(); + subEntry.set("resourceitem", copySubEntry.get("resourceitem")); + subEntry.set("externalnumber", copySubEntry.get("externalnumber")); + subEntry.set("externalname", copySubEntry.get("externalname")); + subEntry.set("resourcemodel", copySubEntry.get("resourcemodel")); + subEntry.set("resourceunit", copySubEntry.get("resourceunit")); + subEntry.set("resourceitem", copySubEntry.get("resourceitem")); + BigDecimal resourcePrice = copySubEntry.getBigDecimal("resourceprice"); + resourcePrice = resourcePrice == null ? BigDecimal.ZERO : resourcePrice; + subEntry.set("resourceprice", resourcePrice); + BigDecimal unitQty = copySubEntry.getBigDecimal("unitcostqty"); + unitQty = unitQty == null ? BigDecimal.ZERO : unitQty; + subEntry.set("unitcostqty", unitQty); + subEntry.set("unitamount", copySubEntry.get("unitamount")); + subEntry.set("enterpriseca", copySubEntry.get("enterpriseca")); + subEntry.set("projectcbs", copySubEntry.get("projectcbs")); + subEntry.set("costtype", copySubEntry.get("costtype")); + subEntry.set("subremark", copySubEntry.get("subremark")); + BigDecimal resourceQty = unitQty.multiply(qty); + subEntry.set("resourceqty", resourceQty); + subEntry.set("resourceamount", resourceQty.multiply(resourcePrice)); + } + } + } + } + } + } + + EntryGrid grid = (EntryGrid)this.getControl("treeentryentity"); + this.summaryAmount(entries, grid); + this.getModel().updateEntryCache(entries); + this.getView().updateView("treeentryentity"); + this.summaryAmount(entries, grid); + } + + protected void doCopyPrice() { + EntryGrid treeGrid = (EntryGrid)this.getControl("treeentryentity"); + int[] selectRows = treeGrid.getSelectRows(); + if (selectRows != null && selectRows.length != 0 && selectRows.length <= 1) { + if (!(Boolean)this.getModel().getValue("isleaf", selectRows[0])) { + this.getView().showTipNotification(ResManager.loadKDString("请选中叶子节点数据进行复制。", "AimCostBoqEditPlugin_38", "ec-ecco-formplugin", new Object[0])); + } else { + this.getPageCache().put("copyRowIndex", selectRows[0] + ""); + } + } else { + this.getView().showTipNotification(ResManager.loadKDString("请选中一行分录数据进行复制。", "AimCostBoqEditPlugin_37", "ec-ecco-formplugin", new Object[0])); + } + } + + protected void doExportListing() { + DynamicObjectCollection entryEntity = this.getModel().getEntryEntity("treeentryentity"); + JSONArray boqData = new JSONArray(); + Iterator var3 = entryEntity.iterator(); + + while(true) { + DynamicObject entry; + do { + if (!var3.hasNext()) { + String url = AimCostBoqPoiHelper.newOutPutExcel(ResManager.loadKDString("BOQ成本预算模板", "AimCostBoqEditPlugin_39", "ec-ecco-formplugin", new Object[0]), ResManager.loadKDString("工程量清单单价拆分模板", "AimCostBoqEditPlugin_0", "ec-ecco-formplugin", new Object[0]), this.getHeadera(), COLUMNKEYA, this.getMustFillColumnA(), boqData, this.isSplitModel()); + this.getView().download(url); + this.getView().showSuccessNotification(ResManager.loadKDString("导出成功。", "AimCostBoqEditPlugin_40", "ec-ecco-formplugin", new Object[0]), 2000); + return; + } + + entry = (DynamicObject)var3.next(); + } while(!entry.getBoolean("isleaf")); + + DynamicObject boq = entry.getDynamicObject("boq"); + DynamicObject unitProject = boq.getDynamicObject("unitproject"); + JSONObject boqObj = new JSONObject(); + if (unitProject != null) { + boqObj.put(COLUMNKEYA[0], unitProject.getString("name")); + } + + boqObj.put(COLUMNKEYA[1], boq.getString("number")); + boqObj.put(COLUMNKEYA[2], boq.getString("itemnumber")); + boqObj.put(COLUMNKEYA[3], boq.getString("name")); + DynamicObject rateObject = entry.getDynamicObject("entryrate"); + if (rateObject != null) { + boqObj.put(COLUMNKEYA[4], rateObject.getString("name")); + } + + for(int i = 5; i < COLUMNKEYA.length; ++i) { + boqObj.put(COLUMNKEYA[i], "0E-10".equals(entry.getBigDecimal(COLUMNKEYA[i]).toString()) ? BigDecimal.ZERO : entry.getBigDecimal(COLUMNKEYA[i])); + } + + boqData.add(boqObj); + } + } + + protected void doResourceMatch() { + int rowCount = this.getModel().getEntryRowCount("treeentryentity"); + DynamicObject[] resources = BusinessDataServiceHelper.load("ecbd_resourceitem", "id,number,name,resourcetype,rousourceattribute,resource,model,measureunit,price", (QFilter[])null); + Map resourceMap1 = this.exchangeToResourceMap(resources, true, true); + Map resourceMap2 = this.exchangeToResourceMap(resources, true, false); + Map resourceMap3 = this.exchangeToResourceMap(resources, false, true); + Map resourceMap4 = this.exchangeToResourceMap(resources, false, false); + int matchCount = 0; + + int i; + label83: + for(i = 0; i < rowCount; ++i) { + DynamicObject treeEntryRow = this.getModel().getEntryRowEntity("treeentryentity", i); + DynamicObjectCollection subEntryEntity = treeEntryRow.getDynamicObjectCollection("subentryentity"); + if (subEntryEntity != null && !subEntryEntity.isEmpty()) { + Iterator var11 = subEntryEntity.iterator(); + + while(true) { + DynamicObject subEntry; + DynamicObject matchResource; + do { + String resourceNumber; + String resourceName; + String resourceModel; + do { + while(true) { + if (!var11.hasNext()) { + continue label83; + } + + subEntry = (DynamicObject)var11.next(); + DynamicObject resource = subEntry.getDynamicObject("resourceitem"); + if (resource == null) { + resourceNumber = subEntry.getString("externalnumber"); + resourceName = subEntry.getString("externalname"); + resourceModel = subEntry.getString("resourcemodel"); + break; + } + + ++matchCount; + } + } while(StringUtils.isEmpty(resourceName)); + + String key = this.concatKey(resourceNumber, resourceName, resourceModel); + matchResource = (DynamicObject)resourceMap1.get(key); + matchResource = matchResource == null ? (DynamicObject)resourceMap2.get(key) : matchResource; + matchResource = matchResource == null ? (DynamicObject)resourceMap3.get(key) : matchResource; + matchResource = matchResource == null ? (DynamicObject)resourceMap4.get(key) : matchResource; + } while(matchResource == null); + + subEntry.set("resourceitem", matchResource); + String costType = AimCostBoqCalculateHelper.getCostTypeByResource(matchResource); + if (this.isSplitModel() && StringUtils.equals(AimCostTypeEnum.OTHERPRICE.getValue(), costType) || !this.isSplitModel() && StringUtils.equals(AimCostTypeEnum.TAXPRICE.getValue(), costType)) { + costType = null; + } + + subEntry.set("resourcemodel", matchResource.get("model")); + subEntry.set("resourceunit", matchResource.get("measureunit")); + subEntry.set("costtype", costType); + ++matchCount; + } + } + } + + this.getModel().updateCache(); + this.getView().updateView("subentryentity"); + + for(i = 0; i < rowCount; ++i) { + this.updatePrice(i, false); + } + + this.getView().showSuccessNotification(String.format(ResManager.loadKDString("共%s行资源匹配成功。", "AimCostBoqEditPlugin_41", "ec-ecco-formplugin", new Object[0]), matchCount)); + } + + private Map exchangeToResourceMap(DynamicObject[] resources, boolean withModel, boolean withNumber) { + Map resourceMap = new HashMap(); + if (resources != null && resources.length > 0) { + DynamicObject[] var5 = resources; + int var6 = resources.length; + + for(int var7 = 0; var7 < var6; ++var7) { + DynamicObject resource = var5[var7]; + resourceMap.put(this.concatKey(withNumber ? resource.getString("number") : "", resource.getString("name"), withModel ? resource.getString("model") : ""), resource); + } + } + + return resourceMap; + } + + protected String concatKey(String number, String name, String model) { + StringBuilder key = new StringBuilder(); + key.append(number); + key.append("$$$"); + key.append(name); + key.append("$$$"); + key.append(model); + return key.toString(); + } + + protected void doImportResource(BeforeDoOperationEventArgs args, String operateKey) { + DynamicObject project = (DynamicObject)this.getModel().getValue("project"); + DynamicObject unitProject = (DynamicObject)this.getModel().getValue("unitproject"); + boolean editOnUnit = (Boolean)this.getModel().getValue("editonunit"); + if (project == null) { + this.getView().showTipNotification(ResManager.loadKDString("请选择项目。", "AimCostBoqEditPlugin_42", "ec-ecco-formplugin", new Object[0])); + args.setCancel(true); + } else if (editOnUnit && unitProject == null) { + this.getView().showTipNotification(ResManager.loadKDString("请选择单位工程。", "AimCostBoqEditPlugin_43", "ec-ecco-formplugin", new Object[0])); + args.setCancel(true); + } else { + this.getView().showConfirm(ResManager.loadKDString("导入数据将清空原有工料机,请确认。", "AimCostBoqEditPlugin_44", "ec-ecco-formplugin", new Object[0]), MessageBoxOptions.OKCancel, new ConfirmCallBackListener(operateKey, this)); + } + } + + protected void doSubExport() { + DynamicObjectCollection entryEntity = this.getModel().getEntryEntity("treeentryentity"); + List datas = new ArrayList(); + JSONArray boqData = new JSONArray(); + JSONArray resourceData = new JSONArray(); + Iterator var5 = entryEntity.iterator(); + + while(true) { + DynamicObjectCollection subEntryEntity; + DynamicObject boq; + DynamicObject unitProject; + do { + do { + DynamicObject entry; + do { + if (!var5.hasNext()) { + datas.add(boqData); + datas.add(resourceData); + String url = AimCostBoqPoiHelper.newOutPutExcelWithMultisheet(ResManager.loadKDString("BOQ成本预算模板", "AimCostBoqEditPlugin_39", "ec-ecco-formplugin", new Object[0]), this.getSheetname(), this.getHeaders(), COLUMNKEYS, this.getMustFillColumns(), datas, 2, this.isSplitModel()); + this.getView().download(url); + this.getView().showSuccessNotification(ResManager.loadKDString("导出成功。", "AimCostBoqEditPlugin_40", "ec-ecco-formplugin", new Object[0]), 2000); + return; + } + + entry = (DynamicObject)var5.next(); + } while(!entry.getBoolean("isleaf")); + + subEntryEntity = entry.getDynamicObjectCollection("subentryentity"); + boq = entry.getDynamicObject("boq"); + unitProject = boq.getDynamicObject("unitproject"); + JSONObject boqObj = new JSONObject(); + if (unitProject != null) { + boqObj.put(COLUMNKEYA[0], unitProject.getString("name")); + } + + boqObj.put(COLUMNKEYA[1], boq.getString("number")); + boqObj.put(COLUMNKEYA[2], boq.getString("itemnumber")); + boqObj.put(COLUMNKEYA[3], boq.getString("name")); + DynamicObject rateObject = entry.getDynamicObject("entryrate"); + if (rateObject != null) { + boqObj.put(COLUMNKEYA[4], rateObject.getString("name")); + } + + for(int i = 5; i < COLUMNKEYA.length; ++i) { + boqObj.put(COLUMNKEYA[i], "0E-10".equals(entry.getBigDecimal(COLUMNKEYA[i]).toString()) ? BigDecimal.ZERO : entry.getBigDecimal(COLUMNKEYA[i])); + } + + boqData.add(boqObj); + } while(subEntryEntity == null); + } while(subEntryEntity.isEmpty()); + + Iterator var23 = subEntryEntity.iterator(); + + while(var23.hasNext()) { + DynamicObject subEntry = (DynamicObject)var23.next(); + JSONObject jsonObj = new JSONObject(); + if (unitProject != null) { + jsonObj.put(COLUMNKEYB[0], unitProject.getString("name")); + } + + jsonObj.put(COLUMNKEYB[1], boq.getString("number")); + jsonObj.put(COLUMNKEYB[2], boq.getString("itemnumber")); + jsonObj.put(COLUMNKEYB[3], boq.getString("name")); + DynamicObject resourceItem = subEntry.getDynamicObject("resourceitem"); + if (resourceItem != null) { + String resourceType = resourceItem.getString("resourcetype"); + jsonObj.put(COLUMNKEYB[4], this.getResourceTypeName(resourceType)); + DynamicObject resource = resourceItem.getDynamicObject("resource"); + if (resource != null) { + jsonObj.put(COLUMNKEYB[5], resource.getString("name")); + } + } + + jsonObj.put(COLUMNKEYB[6], subEntry.getString("externalnumber")); + jsonObj.put(COLUMNKEYB[7], subEntry.getString("externalname")); + jsonObj.put(COLUMNKEYB[8], subEntry.getString("resourcemodel")); + DynamicObject unit = subEntry.getDynamicObject("resourceunit"); + if (unit != null) { + jsonObj.put(COLUMNKEYB[9], unit.getString("name")); + } + + BigDecimal price = subEntry.getBigDecimal("resourceprice"); + if (price.compareTo(BigDecimal.ZERO) != 0) { + jsonObj.put(COLUMNKEYB[10], price); + } + + BigDecimal unitcostqty = subEntry.getBigDecimal("unitcostqty"); + if (unitcostqty.compareTo(BigDecimal.ZERO) != 0) { + jsonObj.put(COLUMNKEYB[11], unitcostqty); + } + + BigDecimal qty = subEntry.getBigDecimal("resourceqty"); + if (qty.compareTo(BigDecimal.ZERO) != 0) { + jsonObj.put(COLUMNKEYB[12], qty); + } + + DynamicObject ca = subEntry.getDynamicObject("enterpriseca"); + if (ca != null) { + jsonObj.put(COLUMNKEYB[13], ca.getString("number")); + jsonObj.put(COLUMNKEYB[14], ca.getString("name")); + } + + DynamicObject cbs = subEntry.getDynamicObject("projectcbs"); + if (cbs != null) { + jsonObj.put(COLUMNKEYB[15], cbs.getString("number")); + jsonObj.put(COLUMNKEYB[16], cbs.getString("name")); + } + + jsonObj.put(COLUMNKEYB[17], this.getCostTypeName(subEntry.getString("costtype"))); + jsonObj.put(COLUMNKEYB[18], subEntry.getString("subremark")); + resourceData.add(jsonObj); + } + } + } + + protected String getCostTypeName(String costType) { + AimCostTypeEnum costTypeEnum = AimCostTypeEnum.getEnumByValue(costType); + return costTypeEnum == null ? "" : costTypeEnum.getName(); + } + + protected String getCostTypeValue(String costTypeName) { + if (costTypeName == null) { + return ""; + } else if (StringUtils.equals(AimCostTypeEnum.ARTIFICIALPRICE.getName(), costTypeName)) { + return AimCostTypeEnum.ARTIFICIALPRICE.getValue(); + } else if (StringUtils.equals(AimCostTypeEnum.MAINMATERIALPRICE.getName(), costTypeName)) { + return AimCostTypeEnum.MAINMATERIALPRICE.getValue(); + } else if (StringUtils.equals(AimCostTypeEnum.SECONDARYMATERIALPRICE.getName(), costTypeName)) { + return AimCostTypeEnum.SECONDARYMATERIALPRICE.getValue(); + } else if (StringUtils.equals(AimCostTypeEnum.SUBCONTRACTPRICE.getName(), costTypeName)) { + return AimCostTypeEnum.SUBCONTRACTPRICE.getValue(); + } else if (StringUtils.equals(AimCostTypeEnum.MACHINEPRICE.getName(), costTypeName)) { + return AimCostTypeEnum.MACHINEPRICE.getValue(); + } else if (StringUtils.equals(AimCostTypeEnum.MANAGEMENTPRICE.getName(), costTypeName)) { + return AimCostTypeEnum.MANAGEMENTPRICE.getValue(); + } else if (StringUtils.equals(AimCostTypeEnum.PROFITPRICE.getName(), costTypeName)) { + return AimCostTypeEnum.PROFITPRICE.getValue(); + } else if (StringUtils.equals(AimCostTypeEnum.TAXPRICE.getName(), costTypeName)) { + return AimCostTypeEnum.TAXPRICE.getValue(); + } else { + return StringUtils.equals(AimCostTypeEnum.OTHERPRICE.getName(), costTypeName) ? AimCostTypeEnum.OTHERPRICE.getValue() : ""; + } + } + + protected String getResourceTypeName(String resourceType) { + switch (resourceType) { + case "01": + return ResManager.loadKDString("分包协作清单", "AimCostBoqEditPlugin_45", "ec-ecco-formplugin", new Object[0]); + case "02": + return ResManager.loadKDString("劳务协作清单", "AimCostBoqEditPlugin_46", "ec-ecco-formplugin", new Object[0]); + case "03": + return ResManager.loadKDString("物资清单", "AimCostBoqEditPlugin_47", "ec-ecco-formplugin", new Object[0]); + case "04": + return ResManager.loadKDString("设备清单", "AimCostBoqEditPlugin_48", "ec-ecco-formplugin", new Object[0]); + case "05": + return ResManager.loadKDString("周材清单", "AimCostBoqEditPlugin_49", "ec-ecco-formplugin", new Object[0]); + case "06": + return ResManager.loadKDString("其它类清单", "AimCostBoqEditPlugin_50", "ec-ecco-formplugin", new Object[0]); + default: + return ""; + } + } + + protected String getResourceType(String resourceTypeName) { + switch (resourceTypeName) { + case "分包协作清单": + return "01"; + case "劳务协作清单": + return "02"; + case "物资清单": + return "03"; + case "设备清单": + return "04"; + case "周材清单": + return "05"; + case "其它类清单": + return "06"; + default: + return ""; + } + } + + protected void doDeleteBoqEntry() { + EntryGrid grid = (EntryGrid)this.getView().getControl("treeentryentity"); + int[] selectRows = grid.getSelectRows(); + int[] var3 = selectRows; + int var4 = selectRows.length; + + for(int var5 = 0; var5 < var4; ++var5) { + int i = var3[var5]; + boolean isLeaf = (Boolean)this.getModel().getValue("isleaf", i); + if (!isLeaf) { + this.getView().showConfirm(ResManager.loadKDString("父节点删除时,子节点也将被删除,请确认。", "AimCostBoqEditPlugin_51", "ec-ecco-formplugin", new Object[0]), MessageBoxOptions.OKCancel, new ConfirmCallBackListener("deleteboqentry", this)); + return; + } + } + + this.getModel().deleteEntryRows("treeentryentity", selectRows); + this.getModel().updateCache(); + DynamicObjectCollection entryEntity = this.getModel().getEntryEntity("treeentryentity"); + this.summaryAmount(entryEntity, (EntryGrid)this.getControl("treeentryentity")); + this.getModel().updateEntryCache(entryEntity); + this.getView().updateView("treeentryentity"); + if (!entryEntity.isEmpty()) { + EntryGrid entryGrid = (EntryGrid)this.getView().getControl("treeentryentity"); + this.getModel().setEntryCurrentRowIndex("treeentryentity", 0); + entryGrid.entryRowClick(0); + entryGrid.selectRows(0); + } + + } + + protected void doNewEntry() { + int rowIndex = this.getModel().getEntryCurrentRowIndex("treeentryentity"); + DynamicObject entry = this.getModel().getEntryRowEntity("treeentryentity", rowIndex); + if (entry != null) { + DynamicObjectCollection subEntryEntity = entry.getDynamicObjectCollection("subentryentity"); + if (subEntryEntity == null || subEntryEntity.isEmpty()) { + this.getModel().setValue("hasresource", true, rowIndex); + } + + } + } + + protected void doAddBoqEntry() { + DynamicObject project = (DynamicObject)this.getModel().getValue("project"); + List filters = new ArrayList(4); + if (project == null) { + this.getView().showTipNotification(ResManager.loadKDString("请先选择项目。", "AimCostBoqEditPlugin_52", "ec-ecco-formplugin", new Object[0])); + } else { + filters.add(new QFilter("project", "=", project.getPkValue())); + ListShowParameter formShowParameter = ShowFormHelper.createShowListForm("ec_ecbd_pro_boq", true); + boolean isEditOnUnit = (Boolean)this.getModel().getValue("editonunit"); + if (isEditOnUnit) { + DynamicObject unitProject = (DynamicObject)this.getModel().getValue("unitproject"); + if (unitProject == null) { + this.getView().showTipNotification(ResManager.loadKDString("请先选择单位工程。", "AimCostBoqEditPlugin_53", "ec-ecco-formplugin", new Object[0])); + return; + } + + filters.add(new QFilter("unitproject", "=", unitProject.getPkValue())); + formShowParameter.setCustomParam("treecontrolunitproject", unitProject.getPkValue()); + } + + Set boqIdSet = this.getBoqIds(); + filters.add(new QFilter("id", "not in", boqIdSet)); + filters.add(new QFilter("isleaf", "=", "1")); + filters.add(new QFilter("enable", "=", "1")); + formShowParameter.getTreeFilterParameter().getQFilters().add(new QFilter("id", "not in", boqIdSet)); + formShowParameter.setCustomParam("treecontrolproject", project.getPkValue()); + formShowParameter.getListFilterParameter().getQFilters().addAll(filters); + formShowParameter.setCloseCallBack(new CloseCallBack(this, "addboqentry")); + this.getView().showForm(formShowParameter); + } + } + + public void afterDoOperation(AfterDoOperationEventArgs afterdooperationeventargs) { + super.afterDoOperation(afterdooperationeventargs); + String operateKey = afterdooperationeventargs.getOperateKey(); + if (StringUtils.equals(operateKey, "deleteentry")) { + this.afterDeleteRow(); + } else if (StringUtils.equals(operateKey, "showcompositeprice")) { + this.getModel().setValue("isshowallprice", false); + } else if (StringUtils.equals(operateKey, "showallprice")) { + this.getModel().setValue("isshowallprice", true); + } else if (StringUtils.equals(operateKey, "audit")) { + this.getView().updateView("iseffective"); + } else if (StringUtils.equals(operateKey, "newentry")) { + this.carryPreData(); + } + + } + + protected void carryPreData() { + int rowIndex = this.getModel().getEntryCurrentRowIndex("subentryentity"); + int rowCount = this.getModel().getEntryRowCount("subentryentity"); + if (rowIndex > 0 && rowIndex < rowCount) { + this.getModel().setValue("projectcbs", this.getModel().getValue("projectcbs", rowIndex - 1), rowIndex); + this.getModel().setValue("enterpriseca", this.getModel().getValue("enterpriseca", rowIndex - 1), rowIndex); + } + + } + + protected void afterDeleteRow() { + int rowIndex = this.getModel().getEntryCurrentRowIndex("treeentryentity"); + int entryRowCount = this.getModel().getEntryRowCount("treeentryentity"); + int subEntryRowCount = this.getModel().getEntryRowCount("subentryentity"); + if (subEntryRowCount == 0 && entryRowCount != 0 && rowIndex >= 0) { + this.getModel().setValue("hasresource", false, rowIndex); + } + + if (entryRowCount != 0 && rowIndex >= 0) { + this.updatePrice(rowIndex, true); + } + + } + + public void closedCallBack(ClosedCallBackEvent closedCallBackEvent) { + super.closedCallBack(closedCallBackEvent); + String actionId = closedCallBackEvent.getActionId(); + Object returnData = closedCallBackEvent.getReturnData(); + if (StringUtils.equals(actionId, "addboqentry")) { + this.addBoqEntryCallBack(returnData); + } + + } + + protected void addBoqEntryCallBack(Object returnData) { + ListSelectedRowCollection selectedRows = (ListSelectedRowCollection)returnData; + if (selectedRows != null && !selectedRows.isEmpty()) { + Object[] selectedIds = selectedRows.getPrimaryKeyValues(); + Long[] ids = new Long[selectedIds.length]; + + for(int i = 0; i < selectedIds.length; ++i) { + ids[i] = Long.valueOf(selectedIds[i].toString()); + } + + Map boqEntryIdMap = this.getBoqEntryIdMap(); + DynamicObjectCollection entryEntity = this.getModel().getEntryEntity("treeentryentity"); + this.addBoqToEntryEntity(ids, boqEntryIdMap, entryEntity); + this.updateEntryEntity(entryEntity); + } + } + + protected void updateEntryEntity(DynamicObjectCollection entryEntity) { + EntryGrid grid = (EntryGrid)this.getControl("treeentryentity"); + this.summaryAmount(entryEntity, grid); + this.sortEntry(entryEntity); + this.getModel().updateCache(); + this.getModel().updateEntryCache(entryEntity); + this.getView().updateView("treeentryentity"); + this.summaryAmount(entryEntity, grid); + grid.setCollapse(false); + if (!entryEntity.isEmpty()) { + this.getModel().setEntryCurrentRowIndex("treeentryentity", 0); + grid.entryRowClick(0); + this.setSubEntryOperateEnable(); + } + + } + + protected void addBoqToEntryEntity(Long[] ids, Map boqEntryIdMap, DynamicObjectCollection entryEntity) { + Set boqIds = new HashSet(16); + boqIds.addAll(boqEntryIdMap.keySet()); + Set addBoqs = new HashSet(16); + this.completeBoqConstruction(ids, boqIds, addBoqs); + boolean isSplitModel = this.isSplitModel(); + DynamicObjectType dt = entryEntity.getDynamicObjectType(); + ORM orm = ORM.create(); + long[] newIds = orm.genLongIds(dt, addBoqs.size()); + int index = 0; + Iterator var11 = addBoqs.iterator(); + + while(var11.hasNext()) { + DynamicObject addBoq = (DynamicObject)var11.next(); + boqEntryIdMap.put(addBoq.getLong("id"), newIds[index++]); + } + + DynamicObject taxrate = (DynamicObject)this.getView().getModel().getValue("taxrate"); + + DynamicObject newEntry; + for(Iterator var17 = addBoqs.iterator(); var17.hasNext(); entryEntity.add(newEntry)) { + DynamicObject addBoq = (DynamicObject)var17.next(); + newEntry = new DynamicObject(dt); + newEntry.set("id", boqEntryIdMap.get(addBoq.getLong("id"))); + DynamicObject parent = addBoq.getDynamicObject("parent"); + if (parent != null) { + newEntry.set("pid", boqEntryIdMap.get(parent.getLong("id"))); + } + + newEntry.set("boq", addBoq); + newEntry.set("entrymeasureunit", addBoq.get("unit")); + newEntry.set("isleaf", addBoq.get("isleaf")); + if (addBoq.getBoolean("isleaf")) { + newEntry.set("entryqty", addBoq.get("qtytotal")); + newEntry.set("entryprice", addBoq.get("priceavg")); + newEntry.set("boqnature", addBoq.get("boqnature")); + if (isSplitModel) { + newEntry.set("compositeprice", addBoq.get("priceavg")); + newEntry.set("otherprice", addBoq.get("priceavg")); + newEntry.set("aimcostamount", addBoq.get("amounttotal")); + } else { + newEntry.set("entryrate", taxrate); + } + + newEntry.set("entryamount", addBoq.get("amounttotal")); + } + } + + } + + private boolean isSplitModel() { + return StringUtils.equals("01", (String)this.getModel().getValue("editmodel")); + } + + protected DynamicObjectCollection sortEntry(DynamicObjectCollection entryEntity) { + Map entryBoqNumberMap = new TreeMap(); + Iterator var3 = entryEntity.iterator(); + + while(var3.hasNext()) { + DynamicObject entry = (DynamicObject)var3.next(); + DynamicObject boq = entry.getDynamicObject("boq"); + if (boq != null) { + entryBoqNumberMap.put(boq.getString("number"), entry); + } + } + + entryEntity.clear(); + var3 = entryBoqNumberMap.entrySet().iterator(); + + while(var3.hasNext()) { + Map.Entry entry = (Map.Entry)var3.next(); + entryEntity.add(entry.getValue()); + } + + return entryEntity; + } + + protected void summaryAmount(DynamicObjectCollection entryEntity, EntryGrid entryGrid) { + DynamicObject currency = (DynamicObject)this.getModel().getValue("currency"); + BigDecimal costControlAmount = AimCostBoqCalculateHelper.summaryTreeEntryAmount(entryEntity, "entryamount"); + BigDecimal totalAimAmount = AimCostBoqCalculateHelper.summaryTreeEntryAmount(entryEntity, "aimcostamount"); + Map floatButtomData = new HashMap(); + floatButtomData.put("aimcostamount", CurrencyFormatUtil.getAfterFormatString(currency, totalAimAmount)); + floatButtomData.put("entryamount", CurrencyFormatUtil.getAfterFormatString(currency, costControlAmount)); + this.setTotalAmount(totalAimAmount, costControlAmount); + BigDecimal totalProfit = AimCostBoqCalculateHelper.summaryTreeEntryAmount(entryEntity, "aimprofit"); + floatButtomData.put("aimprofit", CurrencyFormatUtil.getAfterFormatString(currency, totalProfit)); + BigDecimal totalEntryTax = AimCostBoqCalculateHelper.summaryTreeEntryAmount(entryEntity, "entrytax"); + floatButtomData.put("entrytax", CurrencyFormatUtil.getAfterFormatString(currency, totalEntryTax)); + BigDecimal totalOftaxamount = AimCostBoqCalculateHelper.summaryTreeEntryAmount(entryEntity, "oftaxamount"); + floatButtomData.put("oftaxamount", CurrencyFormatUtil.getAfterFormatString(currency, totalOftaxamount)); + this.setTotaloftaxamount(totalOftaxamount); + entryGrid.setFloatButtomData(floatButtomData); + } + + protected void completeBoqConstruction(Long[] selectedIds, Set boqIds, Set addBoqs) { + DynamicObject[] boqs = BusinessDataServiceHelper.load(selectedIds, EntityMetadataCache.getDataEntityType("ec_ecbd_pro_boq")); + addBoqs.addAll(Arrays.asList(boqs)); + boqIds.addAll(Arrays.asList(selectedIds)); + Set parentIds = new HashSet(16); + DynamicObject[] var6 = boqs; + int var7 = boqs.length; + + for(int var8 = 0; var8 < var7; ++var8) { + DynamicObject boq = var6[var8]; + DynamicObject parent = boq.getDynamicObject("parent"); + if (parent != null && !boqIds.contains(parent.getLong("id"))) { + parentIds.add(parent.getLong("id")); + } + } + + if (!parentIds.isEmpty()) { + this.completeBoqConstruction((Long[])parentIds.toArray(new Long[0]), boqIds, addBoqs); + } + + } + + public void confirmCallBack(MessageBoxClosedEvent messageboxclosedevent) { + super.confirmCallBack(messageboxclosedevent); + String callBackId = messageboxclosedevent.getCallBackId(); + if (StringUtils.equals(callBackId, "resourceModeChanged")) { + this.resourceModeChangedCallBack(messageboxclosedevent); + } + + if (messageboxclosedevent.getResult().equals(MessageBoxResult.Yes)) { + if (StringUtils.equals(callBackId, "deleteboqentry")) { + this.confirmDelteBoqEntrys(); + } else if (StringUtils.equals(callBackId, "sysresourceimport")) { + this.showUpload(ResManager.loadKDString("导入清单与资源", "AimCostBoqEditPlugin_54", "ec-ecco-formplugin", new Object[0]), "sysresourceimport"); + } else if (StringUtils.equals(callBackId, "externalresimport")) { + this.showUpload(ResManager.loadKDString("导入外部资源", "AimCostBoqEditPlugin_55", "ec-ecco-formplugin", new Object[0]), "externalresimport"); + } else if (StringUtils.equals(callBackId, "importlisting")) { + this.showUpload(ResManager.loadKDString("导入预算清单", "AimCostBoqEditPlugin_56", "ec-ecco-formplugin", new Object[0]), "listingimport"); + } else if (StringUtils.equals(callBackId, "pastePrice")) { + this.pastePriceConfirm(); + } + + } + } + + protected void pastePriceConfirm() { + EntryGrid treeGrid = (EntryGrid)this.getControl("treeentryentity"); + int[] selectRows = treeGrid.getSelectRows(); + this.pastePrice(selectRows); + } + + protected void showUpload(String title, String btnKey) { + UploadOption uo = new UploadOption(); + uo.setTitle(title); + uo.setSuffix(".xls"); + this.getView().showUpload(uo, btnKey); + } + + protected void resourceModeChangedCallBack(MessageBoxClosedEvent messageboxclosedevent) { + if (messageboxclosedevent.getResult().equals(MessageBoxResult.Yes)) { + DynamicObjectCollection entries = this.getModel().getEntryEntity("treeentryentity"); + Iterator var3 = entries.iterator(); + + while(var3.hasNext()) { + DynamicObject entry = (DynamicObject)var3.next(); + DynamicObjectCollection subEntries = entry.getDynamicObjectCollection("subentryentity"); + subEntries.clear(); + } + + this.getModel().updateEntryCache(entries); + this.getView().updateView("subentryentity"); + } else { + this.getPageCache().put("recoverResourceMode", "1"); + this.getModel().setValue("resourcemode", true); + } + + } + + protected void confirmDelteBoqEntrys() { + EntryGrid grid = (EntryGrid)this.getView().getControl("treeentryentity"); + int[] selectRows = grid.getSelectRows(); + Set deleteRows = new HashSet(); + Map idIndexMap = new HashMap(); + Map> childMap = new HashMap(); + int rowCount = this.getModel().getEntryRowCount("treeentryentity"); + + for(int i = 0; i < rowCount; ++i) { + DynamicObject rowEntity = this.getModel().getEntryRowEntity("treeentryentity", i); + idIndexMap.put(rowEntity.getLong("id"), i); + long pid = rowEntity.getLong("pid"); + Set childSet = (Set)childMap.get(pid); + if (childSet == null) { + childSet = new HashSet(); + } + + ((Set)childSet).add(rowEntity.getLong("id")); + childMap.put(pid, childSet); + } + + int[] deleteRowIndexArr = selectRows; + int index = selectRows.length; + + int i; + for(int var14 = 0; var14 < index; ++var14) { + i = deleteRowIndexArr[var14]; + deleteRows.add(i); + DynamicObject rowEntity = this.getModel().getEntryRowEntity("treeentryentity", i); + this.addAllChildIndex(deleteRows, idIndexMap, childMap, rowEntity.getLong("id")); + } + + deleteRowIndexArr = new int[deleteRows.size()]; + index = 0; + + for(Iterator var15 = deleteRows.iterator(); var15.hasNext(); deleteRowIndexArr[index++] = i) { + i = (Integer)var15.next(); + } + + this.getModel().deleteEntryRows("treeentryentity", deleteRowIndexArr); + this.getModel().updateCache(); + DynamicObjectCollection entryEntity = this.getModel().getEntryEntity("treeentryentity"); + this.summaryAmount(entryEntity, (EntryGrid)this.getControl("treeentryentity")); + this.getModel().updateEntryCache(entryEntity); + this.getView().updateView("treeentryentity"); + if (!entryEntity.isEmpty()) { + EntryGrid entryGrid = (EntryGrid)this.getView().getControl("treeentryentity"); + this.getModel().setEntryCurrentRowIndex("treeentryentity", 0); + entryGrid.entryRowClick(0); + entryGrid.selectRows(0); + } + + } + + protected void addAllChildIndex(Set deleteRows, Map idIndexMap, Map> childMap, long rowId) { + Set childSet = (Set)childMap.get(rowId); + if (childSet != null) { + Iterator var7 = childSet.iterator(); + + while(var7.hasNext()) { + Long childId = (Long)var7.next(); + deleteRows.add(idIndexMap.get(childId)); + this.addAllChildIndex(deleteRows, idIndexMap, childMap, childId); + } + } + + } + + public void upload(UploadEvent uploadevent) { + String key = ((Control)uploadevent.getSource()).getKey(); + Object[] urls = uploadevent.getUrls(); + String url = (String)((Map)urls[0]).get("url"); + if (StringUtils.equals(key, "sysresourceimport")) { + this.importResource(url, true); + } else if (StringUtils.equals(key, "externalresimport")) { + this.importResource(url, false); + } else if (StringUtils.equals(key, "listingimport")) { + this.importListing(url); + } + + } + + protected void importListing(String url) { + JSONArray excel = POIHelperFast.newInputExcel(url, POIHelperFast.stringArrayToHash(COLUMNKEYA)); + if (excel != null && !excel.isEmpty()) { + String formId = this.getView().getFormShowParameter().getFormId(); + MainEntityType dataEntityType = EntityMetadataCache.getDataEntityType(formId); + DynamicObjectType treeEntryDt = (new DynamicObject(dataEntityType)).getDynamicObjectCollection("treeentryentity").getDynamicObjectType(); + DynamicObject project = (DynamicObject)this.getModel().getValue("project"); + DynamicObject unitProject = (DynamicObject)this.getModel().getValue("unitproject"); + boolean editOnUnit = (Boolean)this.getModel().getValue("editonunit"); + if (project != null) { + QFilter projectFilter = new QFilter("project", "=", project.getPkValue()); + if (editOnUnit && unitProject != null) { + projectFilter.and(new QFilter("unitproject", "=", unitProject.getPkValue())); + } + + projectFilter.and(new QFilter("isleaf", "=", "1")); + Map boqMap = this.getBoqMap(projectFilter); + Map rateMap = this.getRateMap(); + Map boqTreeEntryMap = new HashMap(); + List errorMessages = new ArrayList(10); + int index = 1; + + DynamicObject entry; + label132: + for(Iterator var15 = excel.iterator(); var15.hasNext(); ++index) { + Object excelRowJson = var15.next(); + if (excelRowJson != null) { + entry = new DynamicObject(treeEntryDt); + StringBuilder errorMessage = new StringBuilder(String.format(ResManager.loadKDString("工程量清单单价拆分模板.第%s行:", "AimCostBoqEditPlugin_58", "ec-ecco-formplugin", new Object[0]), index)); + boolean isError = false; + JSONArray row = JSONArray.parseArray(excelRowJson.toString()); + StringBuilder boqKey = new StringBuilder(); + Iterator var22 = row.iterator(); + + while(true) { + while(true) { + String columnKey; + Object value; + do { + do { + Object cellObject; + do { + if (!var22.hasNext()) { + if (StringUtils.isNotEmpty(boqKey.toString())) { + DynamicObject boq = (DynamicObject)boqMap.get(boqKey.toString()); + if (boq == null) { + errorMessage.append(ResManager.loadKDString("工程量清单(BOQ)不存在或不是明细清单,", "AimCostBoqEditPlugin_59", "ec-ecco-formplugin", new Object[0])); + isError = true; + } else { + entry.set("boq", boq.getLong("id")); + boqTreeEntryMap.put(boq.getLong("id"), entry); + } + } + + if (isError) { + errorMessages.add(errorMessage.substring(0, errorMessage.length() - 1)); + } + continue label132; + } + + cellObject = var22.next(); + } while(cellObject == null); + + JSONObject cell = JSONObject.parseObject(cellObject.toString()); + String name = cell.getString("name"); + columnKey = cell.getString("columnKey"); + value = cell.get("value"); + isError = isError || this.validateMustinput(errorMessage, name, value, this.getMustFillColumnA()); + } while(value == null); + } while(!StringUtils.isNotEmpty(value.toString())); + + if (!StringUtils.equals(columnKey, COLUMNKEYA[0]) && !StringUtils.equals(columnKey, COLUMNKEYA[1]) && !StringUtils.equals(columnKey, COLUMNKEYA[2]) && !StringUtils.equals(columnKey, COLUMNKEYA[3])) { + if (StringUtils.equals(columnKey, COLUMNKEYA[4])) { + entry.set(columnKey, rateMap.get(value)); + } else { + entry.set(columnKey, value); + } + } else { + boqKey.append(value.toString()); + } + } + } + } + } + + Iterator var30; + if (errorMessages.isEmpty()) { + DynamicObjectCollection treeEntryEntity = this.getModel().getEntryEntity("treeentryentity"); + var30 = treeEntryEntity.iterator(); + + while(true) { + DynamicObject treeEntry; + do { + DynamicObject boq; + do { + boolean isLeaf; + do { + if (!var30.hasNext()) { + this.updatePrice(treeEntryEntity); + this.updateEntryEntity(treeEntryEntity); + return; + } + + entry = (DynamicObject)var30.next(); + isLeaf = entry.getBoolean("isleaf"); + } while(!isLeaf); + + boq = entry.getDynamicObject("boq"); + } while(boq == null); + + treeEntry = (DynamicObject)boqTreeEntryMap.get(boq.getLong("id")); + } while(treeEntry == null); + + for(int i = 4; i < COLUMNKEYA.length; ++i) { + entry.set(COLUMNKEYA[i], treeEntry.get(COLUMNKEYA[i])); + } + } + } else { + StringBuilder message = new StringBuilder(); + var30 = errorMessages.iterator(); + + while(var30.hasNext()) { + String errorMessage = (String)var30.next(); + message.append(errorMessage).append("\r\n"); + } + + this.getView().showMessage(ResManager.loadKDString("导入失败", "AimCostBoqEditPlugin_60", "ec-ecco-formplugin", new Object[0]), message.toString(), MessageTypes.Default); + } + } + } else { + this.getView().showErrorNotification(ResManager.loadKDString("导入内容为空或导入模板错误。", "AimCostBoqEditPlugin_57", "ec-ecco-formplugin", new Object[0])); + } + } + + protected void importResource(String url, boolean isSysResource) { + List excel = POIHelperFast.newInputExcel(url, COLUMNKEYHASHCODES, 2); + boolean isEmpty = true; + Iterator var5 = excel.iterator(); + + JSONArray resourceArray; + while(var5.hasNext()) { + resourceArray = (JSONArray)var5.next(); + if (!resourceArray.isEmpty()) { + isEmpty = false; + break; + } + } + + if (isEmpty) { + this.getView().showErrorNotification(ResManager.loadKDString("导入内容为空或导入模板错误。", "AimCostBoqEditPlugin_57", "ec-ecco-formplugin", new Object[0])); + } else { + JSONArray boqArray = (JSONArray)excel.get(0); + resourceArray = (JSONArray)excel.get(1); + String formId = this.getView().getFormShowParameter().getFormId(); + MainEntityType dataEntityType = EntityMetadataCache.getDataEntityType(formId); + DynamicObjectType treeEntryDt = (new DynamicObject(dataEntityType)).getDynamicObjectCollection("treeentryentity").getDynamicObjectType(); + DynamicObjectType subEntryDt = (new DynamicObject(treeEntryDt)).getDynamicObjectCollection("subentryentity").getDynamicObjectType(); + DynamicObject project = (DynamicObject)this.getModel().getValue("project"); + DynamicObject unitProject = (DynamicObject)this.getModel().getValue("unitproject"); + boolean editOnUnit = (Boolean)this.getModel().getValue("editonunit"); + if (project != null) { + QFilter projectFilter = new QFilter("project", "=", project.getPkValue()); + if (editOnUnit && unitProject != null) { + projectFilter.and(new QFilter("unitproject", "=", unitProject.getPkValue())); + } + + projectFilter.and(new QFilter("isleaf", "=", "1")); + Map> dataMap = this.getDataMap(project, projectFilter); + Map boqMap = (Map)dataMap.get("boq"); + Map resourceMap = (Map)dataMap.get("resource"); + Map unitMap = (Map)dataMap.get("unit"); + Map caMap = (Map)dataMap.get("ca"); + Map cbsMap = (Map)dataMap.get("cbs"); + Map rateMap = this.getRateMap(); + Map> boqSubentryMap = new HashMap(); + Map boqTreeEntryMap = new HashMap(); + List errorMessages = new ArrayList(10); + boolean isSplitModel = this.isSplitModel(); + int index = 1; + + Iterator var27; + Object excelRowJson; + DynamicObject subEntry; + StringBuilder errorMessage; + boolean isError; + JSONArray row; + StringBuilder boqKey; + Object value; + label355: + for(var27 = boqArray.iterator(); var27.hasNext(); ++index) { + excelRowJson = var27.next(); + if (excelRowJson != null) { + subEntry = new DynamicObject(treeEntryDt); + errorMessage = new StringBuilder(String.format(ResManager.loadKDString("工程量清单单价拆分模板.第%s行:", "AimCostBoqEditPlugin_58", "ec-ecco-formplugin", new Object[0]), index)); + isError = false; + row = JSONArray.parseArray(excelRowJson.toString()); + boqKey = new StringBuilder(); + Iterator var34 = row.iterator(); + + while(true) { + while(true) { + String columnKey; + do { + do { + Object cellObject; + do { + if (!var34.hasNext()) { + if (StringUtils.isNotEmpty(boqKey.toString())) { + DynamicObject boq = (DynamicObject)boqMap.get(boqKey.toString()); + if (boq == null) { + errorMessage.append(ResManager.loadKDString("工程量清单(BOQ)不存在或不是明细清单,", "AimCostBoqEditPlugin_59", "ec-ecco-formplugin", new Object[0])); + isError = true; + } else { + subEntry.set("boq", boq.getLong("id")); + boqTreeEntryMap.put(boq.getLong("id"), subEntry); + } + } + + if (isError) { + errorMessages.add(errorMessage.substring(0, errorMessage.length() - 1)); + } + continue label355; + } + + cellObject = var34.next(); + } while(cellObject == null); + + JSONObject cell = JSONObject.parseObject(cellObject.toString()); + String name = cell.getString("name"); + columnKey = cell.getString("columnKey"); + value = cell.get("value"); + isError = isError || this.validateMustinput(errorMessage, name, value, this.getMustFillColumnA()); + } while(value == null); + } while(!StringUtils.isNotEmpty(value.toString())); + + if (!StringUtils.equals(columnKey, COLUMNKEYA[0]) && !StringUtils.equals(columnKey, COLUMNKEYA[1]) && !StringUtils.equals(columnKey, COLUMNKEYA[2]) && !StringUtils.equals(columnKey, COLUMNKEYA[3])) { + if (StringUtils.equals(columnKey, COLUMNKEYA[4])) { + subEntry.set(columnKey, rateMap.get(value)); + } else { + subEntry.set(columnKey, value); + } + } else { + boqKey.append(value.toString()); + } + } + } + } + } + + index = 1; + var27 = resourceArray.iterator(); + + while(true) { + label316: + while(true) { + if (!var27.hasNext()) { + Iterator var47; + if (errorMessages.isEmpty()) { + DynamicObjectCollection treeEntryEntity = this.getModel().getEntryEntity("treeentryentity"); + var47 = treeEntryEntity.iterator(); + + while(true) { + List subEntryList; + do { + do { + DynamicObject boq; + do { + boolean isLeaf; + do { + if (!var47.hasNext()) { + this.updatePrice(treeEntryEntity); + this.updateEntryEntity(treeEntryEntity); + return; + } + + subEntry = (DynamicObject)var47.next(); + isLeaf = subEntry.getBoolean("isleaf"); + } while(!isLeaf); + + boq = subEntry.getDynamicObject("boq"); + } while(boq == null); + + DynamicObject treeEntry = (DynamicObject)boqTreeEntryMap.get(boq.getLong("id")); + if (treeEntry != null) { + for(int i = 4; i < COLUMNKEYA.length; ++i) { + subEntry.set(COLUMNKEYA[i], treeEntry.get(COLUMNKEYA[i])); + } + } + + subEntryList = (List)boqSubentryMap.get(boq.getLong("id")); + } while(subEntryList == null); + } while(subEntryList.isEmpty()); + + DynamicObjectCollection boqSubEntryEntity = new DynamicObjectCollection(subEntryDt, subEntry, subEntryList); + subEntry.set("hasresource", true); + subEntry.set("subentryentity", boqSubEntryEntity); + BigDecimal qty = subEntry.getBigDecimal("entryqty"); + qty = qty == null ? BigDecimal.ZERO : qty; + DynamicObject unit = subEntry.getDynamicObject("entrymeasureunit"); + if (unit != null) { + BigDecimal precision = unit.getBigDecimal("precision"); + qty = qty.setScale(precision.intValue(), RoundingMode.DOWN); + } + + BigDecimal resourceQty; + BigDecimal resourcePrice; + for(Iterator var63 = boqSubEntryEntity.iterator(); var63.hasNext(); subEntry.set("resourceamount", resourceQty.multiply(resourcePrice))) { + subEntry = (DynamicObject)var63.next(); + resourceQty = subEntry.getBigDecimal("resourceqty"); + resourcePrice = subEntry.getBigDecimal("resourceprice"); + BigDecimal unitCostQty = subEntry.getBigDecimal("unitcostqty"); + resourceQty = resourceQty == null ? BigDecimal.ZERO : resourceQty; + resourcePrice = resourcePrice == null ? BigDecimal.ZERO : resourcePrice; + unitCostQty = unitCostQty == null ? BigDecimal.ZERO : unitCostQty; + if (qty.compareTo(BigDecimal.ZERO) != 0) { + if (resourceQty.compareTo(BigDecimal.ZERO) != 0) { + unitCostQty = resourceQty.setScale(10, RoundingMode.DOWN).divide(qty, RoundingMode.HALF_UP); + } else { + resourceQty = unitCostQty.setScale(10, RoundingMode.DOWN).multiply(qty); + subEntry.set("resourceqty", resourceQty); + } + + subEntry.set("unitcostqty", unitCostQty); + subEntry.set("unitamount", unitCostQty.multiply(resourcePrice)); + } + } + } + } else { + StringBuilder message = new StringBuilder(); + var47 = errorMessages.iterator(); + + while(var47.hasNext()) { + String errorMessage1 = (String)var47.next(); + message.append(errorMessage1).append("\r\n"); + } + + this.getView().showMessage(ResManager.loadKDString("导入失败", "AimCostBoqEditPlugin_60", "ec-ecco-formplugin", new Object[0]), message.toString(), MessageTypes.Default); + return; + } + } + + excelRowJson = var27.next(); + if (excelRowJson == null) { + break; + } + + subEntry = new DynamicObject(subEntryDt); + errorMessage = new StringBuilder(String.format(ResManager.loadKDString("综合单价分析模板.第%s行:", "AimCostBoqEditPlugin_61", "ec-ecco-formplugin", new Object[0]), index)); + isError = false; + row = JSONArray.parseArray(excelRowJson.toString()); + boqKey = new StringBuilder(); + StringBuilder resourceKey = new StringBuilder(); + StringBuilder unitKey = new StringBuilder(); + StringBuilder caKey = new StringBuilder(); + StringBuilder cbsKey = new StringBuilder(); + Iterator var64 = row.iterator(); + + while(true) { + while(true) { + String columnKey; + do { + do { + String costType; + do { + if (!var64.hasNext()) { + boolean isOtherCostType = false; + boolean isTaxCostType = false; + DynamicObject cbs; + if (isSysResource) { + cbs = (DynamicObject)resourceMap.get(resourceKey.toString()); + if (cbs != null) { + subEntry.set("resourceitem", cbs); + if (StringUtils.isEmpty(subEntry.getString("costtype"))) { + costType = AimCostBoqCalculateHelper.getCostTypeByResource(cbs); + isOtherCostType = StringUtils.equals(costType, AimCostTypeEnum.OTHERPRICE.getValue()); + isTaxCostType = StringUtils.equals(costType, AimCostTypeEnum.TAXPRICE.getValue()); + subEntry.set("costtype", costType); + } + } + } + + if (isOtherCostType && isSplitModel || isTaxCostType && !isSplitModel) { + continue label316; + } + + if (StringUtils.isNotEmpty(boqKey.toString())) { + cbs = (DynamicObject)boqMap.get(boqKey.toString()); + if (cbs == null) { + errorMessage.append(ResManager.loadKDString("工程量清单(BOQ)不存在或不是明细清单,", "AimCostBoqEditPlugin_59", "ec-ecco-formplugin", new Object[0])); + isError = true; + } else { + List boqSubEntryEntity = (List)boqSubentryMap.get(cbs.getLong("id")); + boqSubEntryEntity = boqSubEntryEntity == null ? new ArrayList() : boqSubEntryEntity; + if (!this.isResourceEmpty(subEntry)) { + ((List)boqSubEntryEntity).add(subEntry); + } + + boqSubentryMap.put(cbs.getLong("id"), boqSubEntryEntity); + } + } + + if (StringUtils.isNotEmpty(unitKey.toString())) { + cbs = (DynamicObject)unitMap.get(unitKey.toString()); + if (cbs == null) { + errorMessage.append(ResManager.loadKDString("计量单位不存在,", "AimCostBoqEditPlugin_62", "ec-ecco-formplugin", new Object[0])); + isError = true; + } else { + subEntry.set("resourceunit", cbs); + } + } + + if (StringUtils.isNotEmpty(caKey.toString())) { + cbs = (DynamicObject)caMap.get(caKey.toString()); + if (caKey.length() > 0 && cbs == null) { + errorMessage.append(ResManager.loadKDString("企业成本科目(CA)不存在,", "AimCostBoqEditPlugin_63", "ec-ecco-formplugin", new Object[0])); + isError = true; + } else if (cbs != null) { + subEntry.set("enterpriseca", cbs); + } + } + + if (StringUtils.isNotEmpty(cbsKey.toString())) { + cbs = (DynamicObject)cbsMap.get(cbsKey.toString()); + if (cbsKey.length() > 0 && cbs == null) { + errorMessage.append(ResManager.loadKDString("项目成本结构(CBS)不存在,", "AimCostBoqEditPlugin_64", "ec-ecco-formplugin", new Object[0])); + isError = true; + } else if (cbs != null) { + subEntry.set("projectcbs", cbs); + } + } + + if (isError) { + errorMessages.add(errorMessage.substring(0, errorMessage.length() - 1)); + } + break label316; + } + + value = var64.next(); + } while(value == null); + + JSONObject cell = JSONObject.parseObject(value.toString()); + costType = cell.getString("name"); + columnKey = cell.getString("columnKey"); + value = cell.get("value"); + isError = isError || this.validateMustinput(errorMessage, costType, value, this.getMustFillColumnB()); + } while(value == null); + } while(!StringUtils.isNotEmpty(value.toString())); + + if (!StringUtils.equals(columnKey, COLUMNKEYB[0]) && !StringUtils.equals(columnKey, COLUMNKEYB[1]) && !StringUtils.equals(columnKey, COLUMNKEYB[2]) && !StringUtils.equals(columnKey, COLUMNKEYB[3])) { + if (StringUtils.equals(columnKey, COLUMNKEYB[4])) { + resourceKey.append(this.getResourceType(value.toString())); + } else if (StringUtils.equals(columnKey, COLUMNKEYB[5])) { + resourceKey.append(value.toString()); + } else if (StringUtils.equals(columnKey, COLUMNKEYB[6])) { + subEntry.set("externalnumber", value); + resourceKey.append(value.toString()); + } else if (StringUtils.equals(columnKey, COLUMNKEYB[7])) { + subEntry.set("externalname", value); + resourceKey.append(value.toString()); + } else if (StringUtils.equals(columnKey, COLUMNKEYB[8])) { + resourceKey.append(value.toString()); + subEntry.set("resourcemodel", value); + } else if (StringUtils.equals(columnKey, COLUMNKEYB[9])) { + resourceKey.append(value.toString()); + unitKey.append(value.toString()); + } else if (StringUtils.equals(columnKey, COLUMNKEYB[10])) { + this.setValueWithValidate(subEntry, value, "resourceprice", ResManager.loadKDString("资源单价", "AimCostBoqEditPlugin_24", "ec-ecco-formplugin", new Object[0]), index); + } else if (StringUtils.equals(columnKey, COLUMNKEYB[11])) { + this.setValueWithValidate(subEntry, value, "unitcostqty", ResManager.loadKDString("单位消耗量", "AimCostBoqEditPlugin_25", "ec-ecco-formplugin", new Object[0]), index); + } else if (StringUtils.equals(columnKey, COLUMNKEYB[12])) { + this.setValueWithValidate(subEntry, value, "resourceqty", ResManager.loadKDString("资源数量", "AimCostBoqEditPlugin_26", "ec-ecco-formplugin", new Object[0]), index); + } else if (StringUtils.equals(columnKey, COLUMNKEYB[13])) { + caKey.append(value.toString()); + } else if (StringUtils.equals(columnKey, COLUMNKEYB[15])) { + cbsKey.append(value.toString()); + } else if (StringUtils.equals(columnKey, COLUMNKEYB[17])) { + subEntry.set("costtype", this.getCostTypeValue(value.toString())); + } else if (StringUtils.equals(columnKey, COLUMNKEYB[18])) { + subEntry.set("subremark", value); + } + } else { + boqKey.append(value.toString()); + } + } + } + } + + ++index; + } + } + } + } + + protected void updatePrice(DynamicObjectCollection treeEntryEntity) { + if (treeEntryEntity != null && !treeEntryEntity.isEmpty()) { + boolean splitModel = this.isSplitModel(); + Iterator var3 = treeEntryEntity.iterator(); + + while(var3.hasNext()) { + DynamicObject treeEntryRow = (DynamicObject)var3.next(); + BigDecimal qty = treeEntryRow.getBigDecimal("entryqty"); + DynamicObject unit = treeEntryRow.getDynamicObject("entrymeasureunit"); + if (unit != null) { + BigDecimal precision = unit.getBigDecimal("precision"); + qty = qty.setScale(precision.intValue(), RoundingMode.DOWN); + } + + DynamicObjectCollection subEntryEntity = treeEntryRow.getDynamicObjectCollection("subentryentity"); + BigDecimal compositePrice = BigDecimal.ZERO; + BigDecimal aimCostAmount; + BigDecimal amount; + BigDecimal subcontractPrice; + BigDecimal secondaryMaterialPrice; + BigDecimal mainMaterialPrice; + BigDecimal managementPrice; + BigDecimal otherPrice; + if (subEntryEntity != null && !subEntryEntity.isEmpty()) { + Map costTypePriceMap = new HashMap(); + Iterator var22 = subEntryEntity.iterator(); + + while(var22.hasNext()) { + DynamicObject entry = (DynamicObject)var22.next(); + String costType = entry.getString("costtype"); + if (!StringUtils.isEmpty(costType)) { + secondaryMaterialPrice = (BigDecimal)costTypePriceMap.get(costType); + secondaryMaterialPrice = secondaryMaterialPrice == null ? BigDecimal.ZERO : secondaryMaterialPrice; + mainMaterialPrice = entry.getBigDecimal("resourceamount"); + if (qty != null && qty.compareTo(BigDecimal.ZERO) != 0) { + secondaryMaterialPrice = secondaryMaterialPrice.add(mainMaterialPrice.setScale(10, RoundingMode.DOWN).divide(qty, RoundingMode.HALF_UP)); + } + + costTypePriceMap.put(costType, secondaryMaterialPrice); + } + } + + Map.Entry entry; + for(var22 = costTypePriceMap.entrySet().iterator(); var22.hasNext(); compositePrice = compositePrice.add((BigDecimal)entry.getValue())) { + entry = (Map.Entry)var22.next(); + treeEntryRow.set(AimCostBoqCalculateHelper.getPriceIdByCostType((String)entry.getKey()), entry.getValue()); + } + + treeEntryRow.set("compositeprice", compositePrice); + } else if (!splitModel) { + aimCostAmount = treeEntryRow.getBigDecimal("profitprice"); + if (aimCostAmount != null) { + compositePrice = compositePrice.add(aimCostAmount); + } + + BigDecimal artificialPrice = treeEntryRow.getBigDecimal("artificialprice"); + if (artificialPrice != null) { + compositePrice = compositePrice.add(artificialPrice); + } + + amount = treeEntryRow.getBigDecimal("machineprice"); + if (amount != null) { + compositePrice = compositePrice.add(amount); + } + + subcontractPrice = treeEntryRow.getBigDecimal("subcontractprice"); + if (subcontractPrice != null) { + compositePrice = compositePrice.add(subcontractPrice); + } + + secondaryMaterialPrice = treeEntryRow.getBigDecimal("secondarymaterialprice"); + if (secondaryMaterialPrice != null) { + compositePrice = compositePrice.add(secondaryMaterialPrice); + } + + mainMaterialPrice = treeEntryRow.getBigDecimal("mainmaterialprice"); + if (mainMaterialPrice != null) { + compositePrice = compositePrice.add(mainMaterialPrice); + } + + managementPrice = treeEntryRow.getBigDecimal("managementprice"); + if (managementPrice != null) { + compositePrice = compositePrice.add(managementPrice); + } + + otherPrice = treeEntryRow.getBigDecimal("otherprice"); + if (otherPrice != null) { + compositePrice = compositePrice.add(otherPrice); + } + + if (compositePrice.compareTo(BigDecimal.ZERO) != 0) { + treeEntryRow.set("compositeprice", compositePrice); + } else { + compositePrice = treeEntryRow.getBigDecimal("compositeprice"); + } + } else { + compositePrice = treeEntryRow.getBigDecimal("compositeprice"); + } + + if (qty != null && qty.compareTo(BigDecimal.ZERO) != 0) { + aimCostAmount = compositePrice.multiply(qty); + treeEntryRow.set("aimcostamount", aimCostAmount); + treeEntryRow.set("entryamount", treeEntryRow.getBigDecimal("entryprice").multiply(qty)); + DynamicObject rate = treeEntryRow.getDynamicObject("entryrate"); + if (rate != null) { + amount = rate.getBigDecimal("taxrate").divide(new BigDecimal(100), 10, 4).add(BigDecimal.ONE); + subcontractPrice = aimCostAmount.multiply(amount); + treeEntryRow.set("oftaxamount", subcontractPrice); + treeEntryRow.set("entrytax", subcontractPrice.subtract(aimCostAmount)); + } + + if (!splitModel) { + amount = treeEntryRow.getBigDecimal("entryamount"); + amount = amount == null ? BigDecimal.ZERO : amount; + treeEntryRow.set("aimprofit", amount.subtract(aimCostAmount)); + } else { + amount = treeEntryRow.getBigDecimal("artificialprice"); + subcontractPrice = treeEntryRow.getBigDecimal("machineprice"); + secondaryMaterialPrice = treeEntryRow.getBigDecimal("mainmaterialprice"); + mainMaterialPrice = treeEntryRow.getBigDecimal("managementprice"); + managementPrice = treeEntryRow.getBigDecimal("profitprice"); + otherPrice = treeEntryRow.getBigDecimal("secondarymaterialprice"); + subcontractPrice = treeEntryRow.getBigDecimal("subcontractprice"); + BigDecimal taxPrice = treeEntryRow.getBigDecimal("taxprice"); + otherPrice = compositePrice.subtract(amount).subtract(subcontractPrice).subtract(secondaryMaterialPrice).subtract(mainMaterialPrice).subtract(managementPrice).subtract(otherPrice).subtract(subcontractPrice).subtract(taxPrice); + treeEntryRow.set("otherprice", otherPrice); + } + } + } + + } + } + + protected void setValueWithValidate(DynamicObject object, Object value, String columnID, String columnName, int index) { + try { + object.set(columnID, value); + } catch (ConversionException var8) { + String message = String.format(ResManager.loadKDString("综合单价分析模板.第%1$s行:[%2$s]字段类型不匹配,请检查。", "AimCostBoqEditPlugin_65", "ec-ecco-formplugin", new Object[0]), index, columnName); + throw new KDBizException(message); + } + } + + protected boolean isResourceEmpty(DynamicObject subEntry) { + return (subEntry.get("externalname") == null || StringUtils.isEmpty(subEntry.getString("externalname"))) && (subEntry.get("externalnumber") == null || StringUtils.isEmpty(subEntry.getString("externalnumber"))); + } + + protected boolean validateMustinput(StringBuilder errorMessage, String name, Object value, List mustFillColumn) { + boolean isEmpty = value == null || value instanceof String && StringUtils.isEmpty(value.toString()) || value instanceof BigDecimal && BigDecimal.ZERO.compareTo((BigDecimal)value) == 0; + if (mustFillColumn.contains(name.replace("*", "")) && isEmpty) { + errorMessage.append(String.format(ResManager.loadKDString("%s未录入,", "AimCostBoqEditPlugin_66", "ec-ecco-formplugin", new Object[0]), name)); + return true; + } else { + return false; + } + } + + protected Map> getDataMap(DynamicObject project, QFilter projectFilter) { + Map> validateDataMap = new HashMap(); + Map validateBoqMap = this.getBoqMap(projectFilter); + validateDataMap.put("boq", validateBoqMap); + Map validateResourceMap = new HashMap(); + DynamicObject[] resources = BusinessDataServiceHelper.load("ecbd_resourceitem", "id,number,name,resourcetype,rousourceattribute,resource,model,measureunit,price", new QFilter[0]); + DynamicObject[] var7 = resources; + int var8 = resources.length; + + for(int var9 = 0; var9 < var8; ++var9) { + DynamicObject object = var7[var9]; + String key = (object.getString("resourcetype") == null ? "" : object.getString("resourcetype")) + (object.getString("resource.name") == null ? "" : object.getString("resource.name")) + (object.getString("number") == null ? "" : object.getString("number")) + (object.getString("name") == null ? "" : object.getString("name")) + (object.getString("model") == null ? "" : object.getString("model")) + (object.getString("measureunit.name") == null ? "" : object.getString("measureunit.name")); + validateResourceMap.put(key, object); + } + + validateDataMap.put("resource", validateResourceMap); + Map validateUnitMap = new HashMap(); + DynamicObject[] units = BusinessDataServiceHelper.load("bd_measureunits", "id,number,name", new QFilter[0]); + DynamicObject[] var20 = units; + int var22 = units.length; + + for(int var24 = 0; var24 < var22; ++var24) { + DynamicObject object = var20[var24]; + validateUnitMap.put(object.getString("name"), object); + } + + validateDataMap.put("unit", validateUnitMap); + Map validateCaMap = new HashMap(); + DynamicObject[] cas = BusinessDataServiceHelper.load("ec_ecbd_costaccount", "id,number,name", new QFilter[0]); + DynamicObject[] var25 = cas; + int var26 = cas.length; + + for(int var13 = 0; var13 < var26; ++var13) { + DynamicObject object = var25[var13]; + validateCaMap.put(object.getString("number"), object); + } + + validateDataMap.put("ca", validateCaMap); + Map validateCbsMap = new HashMap(); + QFilter cbsProjectFilter = new QFilter("project", "=", project.getPkValue()); + DynamicObject[] cbs = BusinessDataServiceHelper.load("ec_ecbd_pro_cbs", "id,number,name", new QFilter[]{cbsProjectFilter}); + DynamicObject[] var30 = cbs; + int var15 = cbs.length; + + for(int var16 = 0; var16 < var15; ++var16) { + DynamicObject object = var30[var16]; + validateCbsMap.put(object.getString("number"), object); + } + + validateDataMap.put("cbs", validateCbsMap); + return validateDataMap; + } + + protected Map getRateMap() { + QFilter filter = new QFilter("status", "=", "C"); + DynamicObject[] rates = BusinessDataServiceHelper.load("bd_taxrate", "number,name,taxrate", new QFilter[]{filter}); + Map rateMap = new HashMap(); + DynamicObject[] var4 = rates; + int var5 = rates.length; + + for(int var6 = 0; var6 < var5; ++var6) { + DynamicObject rate = var4[var6]; + rateMap.put(rate.getString("name"), rate); + } + + return rateMap; + } + + @NotNull + protected Map getBoqMap(QFilter projectFilter) { + Map validateBoqMap = new HashMap(); + DynamicObject[] boqs = BusinessDataServiceHelper.load("ec_ecbd_pro_boq", "id,number,name,itemnumber,unit,project,unitproject,priceavg,qtytotal,amounttotal,isleaf", new QFilter[]{projectFilter}); + DynamicObject[] var4 = boqs; + int var5 = boqs.length; + + for(int var6 = 0; var6 < var5; ++var6) { + DynamicObject object = var4[var6]; + StringBuilder key = new StringBuilder(); + DynamicObject unitProject = object.getDynamicObject("unitproject"); + if (unitProject != null) { + key.append(unitProject.getString("name") == null ? "" : unitProject.getString("name")); + } + + key.append(object.getString("number") == null ? "" : object.getString("number")); + key.append(object.getString("itemnumber") == null ? "" : object.getString("itemnumber")); + key.append(object.getString("name") == null ? "" : object.getString("name")); + validateBoqMap.put(key.toString(), object); + } + + return validateBoqMap; + } + + public void propertyChanged(PropertyChangedArgs e) { + super.propertyChanged(e); + String name = e.getProperty().getName(); + int rowIndex = e.getChangeSet()[0].getRowIndex(); + EntryGrid entryGrid = (EntryGrid)this.getControl("treeentryentity"); + switch (name) { + case "taxrate": + this.taxrateChange(); + break; + case "entryrate": + this.summaryTreeEntryAmount("oftaxamount", rowIndex); + this.setButtomAmount(); + this.updateTreeEntryCellStyle(entryGrid, rowIndex); + break; + case "project": + this.projectChanged(); + break; + case "unitproject": + this.unitProjectChanged(); + break; + case "resourceitem": + this.resourceChanged(e); + break; + case "hasresource": + this.updatePrice(rowIndex, true); + break; + case "resourceamount": + this.resourceAmountChanged(e); + break; + case "costtype": + this.costTypeChanged(e); + break; + case "resourceqty": + this.resourceQtyChanged(e); + break; + case "resourceprice": + this.resourcePriceChanged(e); + break; + case "unitcostqty": + this.unitCostQtyChanged(e); + break; + case "entryamount": + this.summaryTreeEntryAmount("entryamount", rowIndex); + break; + case "aimcostamount": + this.summaryTreeEntryAmount("aimcostamount", rowIndex); + this.setButtomAmount(); + this.updateTreeEntryCellStyle(entryGrid, rowIndex); + break; + case "aimprofit": + this.summaryTreeEntryAmount("aimprofit", rowIndex); + this.setButtomAmount(); + this.updateTreeEntryCellStyle(entryGrid, rowIndex); + break; + case "oftaxamount": + this.summaryTreeEntryAmount("oftaxamount", rowIndex); + this.setButtomAmount(); + this.updateTreeEntryCellStyle(entryGrid, rowIndex); + break; + case "pricecontaintax": + this.summaryTotalAmount(); + break; + case "resourcemode": + this.resourceModeChanged(e.getChangeSet()[0]); + } + + } + + protected void resourceModeChanged(ChangeData changeData) { + boolean resourceMode = (Boolean)changeData.getNewValue(); + if (!resourceMode) { + this.getView().showConfirm(ResManager.loadKDString("关闭资源模式,将会清空“综合单价资源明细分析”分录数据,是否继续?", "AimCostBoqEditPlugin_67", "ec-ecco-formplugin", new Object[0]), MessageBoxOptions.YesNo, new ConfirmCallBackListener("resourceModeChanged", this)); + } else if (this.getPageCache().get("recoverResourceMode") != null) { + this.getPageCache().remove("recoverResourceMode"); + } else { + int rowCount = this.getModel().getEntryRowCount("treeentryentity"); + + for(int i = 0; i < rowCount; ++i) { + this.clearPrice(i); + } + } + + } + + protected void taxrateChange() { + boolean isSplitModel = this.isSplitModel(); + if (!isSplitModel) { + DynamicObject taxrate = (DynamicObject)this.getView().getModel().getValue("taxrate"); + DynamicObjectCollection entrys = this.getView().getModel().getEntryEntity("treeentryentity"); + + for(int i = 0; i < entrys.size(); ++i) { + if (((DynamicObject)entrys.get(i)).getBoolean("isleaf")) { + this.getView().getModel().setValue("entryrate", taxrate, i); + } + } + + } + } + + private void updateTreeEntryCellStyle(EntryGrid entryGrid, Integer currentIndex) { + List cellStyles = new ArrayList(); + DynamicObjectCollection entryEntity = this.getModel().getEntryEntity("treeentryentity"); + if (entryEntity != null && !entryEntity.isEmpty()) { + BigDecimal aimOftaxamount; + if (currentIndex == null) { + for(int index = 0; index < entryEntity.size(); ++index) { + DynamicObject row = (DynamicObject)entryEntity.get(index); + BigDecimal aimCost = row.getBigDecimal("aimcostamount"); + BigDecimal aimProfit = row.getBigDecimal("aimprofit"); + aimOftaxamount = row.getBigDecimal("oftaxamount"); + cellStyles.add(this.createCellStyle(index, aimCost, "aimcostamount")); + cellStyles.add(this.createCellStyle(index, aimProfit, "aimprofit")); + cellStyles.add(this.createCellStyle(index, aimOftaxamount, "oftaxamount")); + } + } else { + List superRowIndex = this.getSuperRowIndex(entryEntity, currentIndex); + Iterator var13 = superRowIndex.iterator(); + + while(var13.hasNext()) { + Integer rowIndex = (Integer)var13.next(); + DynamicObject row = (DynamicObject)entryEntity.get(rowIndex); + aimOftaxamount = row.getBigDecimal("aimcostamount"); + BigDecimal aimProfit = row.getBigDecimal("aimprofit"); + aimOftaxamount = row.getBigDecimal("oftaxamount"); + cellStyles.add(this.createCellStyle(rowIndex, aimOftaxamount, "aimcostamount")); + cellStyles.add(this.createCellStyle(rowIndex, aimProfit, "aimprofit")); + cellStyles.add(this.createCellStyle(rowIndex, aimOftaxamount, "oftaxamount")); + } + } + } + + entryGrid.setCellStyle(cellStyles); + } + + private CellStyle createCellStyle(int index, BigDecimal value, String fieldKey) { + CellStyle cellStyle = new CellStyle(); + cellStyle.setRow(index); + cellStyle.setFieldKey(fieldKey); + if (value != null && value.compareTo(BigDecimal.ZERO) >= 0) { + cellStyle.setForeColor("#000000"); + } else { + cellStyle.setForeColor("#FF0000"); + } + + return cellStyle; + } + + protected void setButtomAmount() { + EntryGrid entryGrid = (EntryGrid)this.getView().getControl("treeentryentity"); + DynamicObject currency = (DynamicObject)this.getModel().getValue("currency"); + Map floatButtomData = new HashMap(); + DynamicObjectCollection entries = this.getModel().getEntryEntity("treeentryentity"); + BigDecimal totalAimCostAmount = BigDecimal.ZERO; + BigDecimal costControlAmount = BigDecimal.ZERO; + BigDecimal totalTax = BigDecimal.ZERO; + BigDecimal totalOfTax = BigDecimal.ZERO; + BigDecimal totalProfit = BigDecimal.ZERO; + Iterator var10 = entries.iterator(); + + while(var10.hasNext()) { + DynamicObject entry = (DynamicObject)var10.next(); + if (entry.getBoolean("isleaf")) { + totalAimCostAmount = totalAimCostAmount.add(entry.getBigDecimal("aimcostamount")); + costControlAmount = costControlAmount.add(entry.getBigDecimal("entryamount")); + totalTax = totalTax.add(entry.getBigDecimal("entrytax")); + totalOfTax = totalOfTax.add(entry.getBigDecimal("oftaxamount")); + totalProfit = totalProfit.add(entry.getBigDecimal("aimprofit")); + } + } + + this.setTotalAmount(totalAimCostAmount, costControlAmount); + floatButtomData.put("aimcostamount", CurrencyFormatUtil.getAfterFormatString(currency, totalAimCostAmount)); + floatButtomData.put("aimprofit", CurrencyFormatUtil.getAfterFormatString(currency, totalProfit)); + floatButtomData.put("entrytax", CurrencyFormatUtil.getAfterFormatString(currency, totalTax)); + floatButtomData.put("entryamount", CurrencyFormatUtil.getAfterFormatString(currency, costControlAmount)); + floatButtomData.put("oftaxamount", CurrencyFormatUtil.getAfterFormatString(currency, totalOfTax)); + this.setTotaloftaxamount(totalOfTax); + entryGrid.setFloatButtomData(floatButtomData); + } + + protected void unitProjectChanged() { + this.getPageCache().remove("copyRowIndex"); + this.setTotalAmount(BigDecimal.ZERO, BigDecimal.ZERO); + this.getModel().setValue("totaloftaxamount", (Object)null); + this.getModel().setValue("taxrate", (Object)null); + this.getModel().setValue("tax", (Object)null); + this.getModel().deleteEntryData("treeentryentity"); + DynamicObject project = (DynamicObject)this.getView().getModel().getValue("project"); + DynamicObject unitproject = (DynamicObject)this.getView().getModel().getValue("unitproject"); + if (unitproject != null) { + if (!this.validateExistBill()) { + List filters = new ArrayList(4); + filters.add(new QFilter("project", "=", project.getPkValue())); + filters.add(new QFilter("unitproject", "=", unitproject.getPkValue())); + filters.add(new QFilter("isleaf", "=", "1")); + filters.add(new QFilter("qtytotal", "!=", 0)); + filters.add(new QFilter("enable", "=", "1")); + this.autoAddBoq(filters); + } + + } + } + + protected void costTypeChanged(PropertyChangedArgs e) { + String newCostType = (String)e.getChangeSet()[0].getNewValue(); + String oldCostType = (String)e.getChangeSet()[0].getOldValue(); + int parentRowIndex = e.getChangeSet()[0].getParentRowIndex(); + int rowIndex = e.getChangeSet()[0].getRowIndex(); + DynamicObject parentRow = null; + DynamicObjectCollection currentSubRows = null; + if (parentRowIndex >= 0 && rowIndex >= 0) { + parentRow = this.getModel().getEntryRowEntity("treeentryentity", parentRowIndex); + if (parentRow != null) { + currentSubRows = parentRow.getDynamicObjectCollection("subentryentity"); + } + } + + if (currentSubRows != null) { + BigDecimal qty = parentRow.getBigDecimal("entryqty"); + DynamicObject unit = parentRow.getDynamicObject("entrymeasureunit"); + BigDecimal newTotalAmont; + if (unit != null) { + newTotalAmont = unit.getBigDecimal("precision"); + qty = qty.setScale(newTotalAmont.intValue(), RoundingMode.DOWN); + } + + if (qty.compareTo(BigDecimal.ZERO) != 0) { + newTotalAmont = BigDecimal.ZERO; + BigDecimal oldTotalAmont = BigDecimal.ZERO; + Iterator var12 = currentSubRows.iterator(); + + while(var12.hasNext()) { + DynamicObject row = (DynamicObject)var12.next(); + BigDecimal amount; + if (StringUtils.equals(newCostType, row.getString("costtype"))) { + amount = row.getBigDecimal("resourceamount"); + newTotalAmont = newTotalAmont.add(amount); + } else if (StringUtils.equals(oldCostType, row.getString("costtype"))) { + amount = row.getBigDecimal("resourceamount"); + oldTotalAmont = oldTotalAmont.add(amount); + } + } + + BigDecimal newPrice = newTotalAmont.setScale(10, RoundingMode.DOWN).divide(qty, RoundingMode.HALF_UP); + BigDecimal oldPrice = oldTotalAmont.setScale(10, RoundingMode.DOWN).divide(qty, RoundingMode.HALF_UP); + String newPriceId = AimCostBoqCalculateHelper.getPriceIdByCostType(newCostType); + String oldPriceId = AimCostBoqCalculateHelper.getPriceIdByCostType(oldCostType); + if (newPriceId != null) { + this.getModel().setValue(newPriceId, newPrice, parentRowIndex); + } + + if (oldPriceId != null) { + this.getModel().setValue(oldPriceId, oldPrice, parentRowIndex); + } + } + } + + } + + protected void resourceAmountChanged(PropertyChangedArgs e) { + int parentRowIndex = e.getChangeSet()[0].getParentRowIndex(); + int rowIndex = e.getChangeSet()[0].getRowIndex(); + if (parentRowIndex >= 0 && rowIndex >= 0) { + DynamicObject parentRow = this.getModel().getEntryRowEntity("treeentryentity", parentRowIndex); + DynamicObjectCollection currentSubRows = parentRow.getDynamicObjectCollection("subentryentity"); + DynamicObject currentRow = (DynamicObject)currentSubRows.get(rowIndex); + BigDecimal newAmount = (BigDecimal)e.getChangeSet()[0].getNewValue(); + BigDecimal qty = parentRow.getBigDecimal("entryqty"); + DynamicObject unit = parentRow.getDynamicObject("entrymeasureunit"); + BigDecimal price; + if (unit != null) { + price = unit.getBigDecimal("precision"); + qty = qty.setScale(price.intValue(), RoundingMode.DOWN); + } + + BigDecimal resourceQty; + BigDecimal unitCostQty; + if (qty.compareTo(BigDecimal.ZERO) != 0) { + String costType = currentRow.getString("costtype"); + resourceQty = BigDecimal.ZERO; + Iterator var12 = currentSubRows.iterator(); + + while(var12.hasNext()) { + DynamicObject row = (DynamicObject)var12.next(); + if (StringUtils.equals(costType, row.getString("costtype"))) { + BigDecimal amount = row.getBigDecimal("resourceamount"); + resourceQty = resourceQty.add(amount); + } + } + + unitCostQty = resourceQty.setScale(10, RoundingMode.DOWN).divide(qty, RoundingMode.HALF_UP); + String priceId = AimCostBoqCalculateHelper.getPriceIdByCostType(costType); + if (priceId != null) { + this.getModel().setValue(priceId, unitCostQty, parentRowIndex); + } + } + + this.getModel().beginInit(); + price = currentRow.getBigDecimal("resourceprice"); + if (price != null && price.compareTo(BigDecimal.ZERO) != 0) { + resourceQty = newAmount.setScale(10, RoundingMode.DOWN).divide(price, RoundingMode.HALF_UP); + this.getModel().setValue("resourceqty", resourceQty, rowIndex, parentRowIndex); + if (qty.compareTo(BigDecimal.ZERO) != 0) { + unitCostQty = resourceQty.setScale(10, RoundingMode.DOWN).divide(qty, RoundingMode.HALF_UP); + BigDecimal unitAmount = unitCostQty.multiply(price); + this.getModel().setValue("unitcostqty", unitCostQty, rowIndex, parentRowIndex); + this.getModel().setValue("unitamount", unitAmount, rowIndex, parentRowIndex); + } + } + + this.getModel().endInit(); + this.getView().updateView("subentryentity"); + } + } + + protected void resourceQtyChanged(PropertyChangedArgs e) { + int parentRowIndex = e.getChangeSet()[0].getParentRowIndex(); + int rowIndex = e.getChangeSet()[0].getRowIndex(); + if (parentRowIndex >= 0 && rowIndex >= 0) { + DynamicObject parentRow = this.getModel().getEntryRowEntity("treeentryentity", parentRowIndex); + DynamicObject currentRow = (DynamicObject)parentRow.getDynamicObjectCollection("subentryentity").get(rowIndex); + BigDecimal newQty = (BigDecimal)e.getChangeSet()[0].getNewValue(); + BigDecimal boqQty = parentRow.getBigDecimal("entryqty"); + DynamicObject unit = parentRow.getDynamicObject("entrymeasureunit"); + BigDecimal price; + if (unit != null) { + price = unit.getBigDecimal("precision"); + boqQty = boqQty.setScale(price.intValue(), RoundingMode.DOWN); + } + + price = currentRow.getBigDecimal("resourceprice"); + BigDecimal unitCostQty; + if (price != null && price.compareTo(BigDecimal.ZERO) != 0) { + unitCostQty = newQty.multiply(price); + this.getModel().setValue("resourceamount", unitCostQty, rowIndex, parentRowIndex); + } + + this.getModel().beginInit(); + if (boqQty.compareTo(BigDecimal.ZERO) != 0) { + unitCostQty = newQty.setScale(10, RoundingMode.DOWN).divide(boqQty, RoundingMode.HALF_UP); + BigDecimal unitAmount = unitCostQty.multiply(price); + this.getModel().setValue("unitcostqty", unitCostQty, rowIndex, parentRowIndex); + this.getModel().setValue("unitamount", unitAmount, rowIndex, parentRowIndex); + } + + this.getModel().endInit(); + this.getView().updateView("subentryentity"); + } + } + + protected void resourcePriceChanged(PropertyChangedArgs e) { + int parentRowIndex = e.getChangeSet()[0].getParentRowIndex(); + int rowIndex = e.getChangeSet()[0].getRowIndex(); + if (parentRowIndex >= 0 && rowIndex >= 0) { + DynamicObject parentRow = this.getModel().getEntryRowEntity("treeentryentity", parentRowIndex); + DynamicObject currentRow = (DynamicObject)parentRow.getDynamicObjectCollection("subentryentity").get(rowIndex); + BigDecimal newPrice = (BigDecimal)e.getChangeSet()[0].getNewValue(); + BigDecimal resourceQty = currentRow.getBigDecimal("resourceqty"); + BigDecimal resourceAmount = newPrice.multiply(resourceQty); + BigDecimal unitQty = currentRow.getBigDecimal("unitcostqty"); + BigDecimal unitAmount = newPrice.multiply(unitQty); + this.getModel().setValue("resourceamount", resourceAmount, rowIndex, parentRowIndex); + this.getModel().setValue("unitamount", unitAmount, rowIndex, parentRowIndex); + } + } + + protected void unitCostQtyChanged(PropertyChangedArgs e) { + int parentRowIndex = e.getChangeSet()[0].getParentRowIndex(); + int rowIndex = e.getChangeSet()[0].getRowIndex(); + if (parentRowIndex >= 0 && rowIndex >= 0) { + DynamicObject parentRow = this.getModel().getEntryRowEntity("treeentryentity", parentRowIndex); + DynamicObject currentRow = (DynamicObject)parentRow.getDynamicObjectCollection("subentryentity").get(rowIndex); + BigDecimal newUnitCostQty = (BigDecimal)e.getChangeSet()[0].getNewValue(); + BigDecimal boqQty = parentRow.getBigDecimal("entryqty"); + DynamicObject unit = parentRow.getDynamicObject("entrymeasureunit"); + BigDecimal resourcePrice; + if (unit != null) { + resourcePrice = unit.getBigDecimal("precision"); + boqQty = boqQty.setScale(resourcePrice.intValue(), RoundingMode.DOWN); + } + + resourcePrice = currentRow.getBigDecimal("resourceprice"); + BigDecimal resourceQty = newUnitCostQty.multiply(boqQty); + BigDecimal unitAmount = newUnitCostQty.multiply(resourcePrice); + this.getModel().setValue("resourceqty", resourceQty, rowIndex, parentRowIndex); + this.getModel().setValue("unitamount", unitAmount, rowIndex, parentRowIndex); + } + } + + protected void resourceChanged(PropertyChangedArgs e) { + int rowIndex = e.getChangeSet()[0].getRowIndex(); + int parentRowIndex = e.getChangeSet()[0].getParentRowIndex(); + DynamicObject resource = (DynamicObject)e.getChangeSet()[0].getNewValue(); + if (resource != null) { + String costType = AimCostBoqCalculateHelper.getCostTypeByResource(resource); + if (this.isSplitModel() && StringUtils.equals(AimCostTypeEnum.OTHERPRICE.getValue(), costType) || !this.isSplitModel() && StringUtils.equals(AimCostTypeEnum.TAXPRICE.getValue(), costType)) { + costType = null; + } + + this.getModel().setValue("costtype", costType, rowIndex, parentRowIndex); + this.getModel().setValue("enterpriseca", resource.get("ca"), rowIndex, parentRowIndex); + } + + } + + protected void projectChanged() { + this.getPageCache().remove("copyRowIndex"); + this.getModel().setValue("unitproject", (Object)null); + this.setTotalAmount(BigDecimal.ZERO, BigDecimal.ZERO); + this.getModel().setValue("totaloftaxamount", (Object)null); + this.getModel().setValue("taxrate", (Object)null); + this.getModel().setValue("tax", (Object)null); + this.getModel().deleteEntryData("treeentryentity"); + DynamicObject project = (DynamicObject)this.getModel().getValue("project"); + boolean isEditOnUnit = (Boolean)this.getModel().getValue("editonunit"); + if (project != null) { + if (isEditOnUnit) { + List unitProjectFilter = this.getUnitProjectFilter(); + DynamicObject[] unitProjects = BusinessDataServiceHelper.load("ec_ecbd_unitproject", "id", (QFilter[])unitProjectFilter.toArray(new QFilter[0])); + if (unitProjects != null && unitProjects.length > 0) { + this.getModel().setValue("unitproject", unitProjects[0].getPkValue()); + } + } else if (!this.validateExistBill()) { + List filters = new ArrayList(4); + filters.add(new QFilter("project", "=", project.getPkValue())); + filters.add(new QFilter("isleaf", "=", "1")); + filters.add(new QFilter("qtytotal", "!=", 0)); + filters.add(new QFilter("enable", "=", "1")); + this.autoAddBoq(filters); + } + } + + } + + private void autoAddBoq(List filters) { + DynamicObject[] boqIds = BusinessDataServiceHelper.load("ec_ecbd_pro_boq", "id", (QFilter[])filters.toArray(new QFilter[0])); + Long[] ids = new Long[boqIds.length]; + + for(int i = 0; i < boqIds.length; ++i) { + ids[i] = Long.valueOf(boqIds[i].getPkValue().toString()); + } + + Map boqEntryIdMap = this.getBoqEntryIdMap(); + DynamicObjectCollection entryEntity = this.getModel().getEntryEntity("treeentryentity"); + this.addBoqToEntryEntity(ids, boqEntryIdMap, entryEntity); + this.updateBoqQty(entryEntity); + this.updateEntryEntity(entryEntity); + } + + protected void updateBoqQty(DynamicObjectCollection entryEntity) { + Iterator var2 = entryEntity.iterator(); + + while(var2.hasNext()) { + DynamicObject entry = (DynamicObject)var2.next(); + DynamicObject boq = entry.getDynamicObject("boq"); + if (boq != null && entry.getBoolean("isleaf")) { + BigDecimal entryQty = entry.getBigDecimal("entryqty"); + BigDecimal boqQty = boq.getBigDecimal("qtytotal"); + if (entryQty.compareTo(boqQty) != 0) { + entry.set("entryqty", boqQty); + BigDecimal price = entry.getBigDecimal("entryprice"); + BigDecimal amount = price.multiply(boqQty); + entry.set("entryamount", amount); + BigDecimal aimPrice = entry.getBigDecimal("compositeprice"); + BigDecimal aimAmount = aimPrice.multiply(boqQty); + entry.set("aimcostamount", aimAmount); + entry.set("aimprofit", amount.subtract(aimAmount)); + DynamicObject rate = entry.getDynamicObject("entryrate"); + BigDecimal oneAddRate = rate == null ? BigDecimal.ONE : BigDecimal.ONE.add(rate.getBigDecimal("taxrate").divide(new BigDecimal(100), 10, 4)); + BigDecimal aimOfTax = aimAmount.multiply(oneAddRate); + entry.set("oftaxamount", aimOfTax); + entry.set("entrytax", aimOfTax.subtract(aimAmount)); + } + + entry.set("boqnature", boq.get("boqnature")); + DynamicObject entryUnit = entry.getDynamicObject("entrymeasureunit"); + long entryUnitId = entryUnit == null ? 0L : entryUnit.getLong("id"); + DynamicObject boqUnit = boq.getDynamicObject("unit"); + long boqUnitId = boqUnit == null ? 0L : boqUnit.getLong("id"); + if (entryUnitId != boqUnitId) { + entry.set("entrymeasureunit", boqUnit); + } + } + } + + } + + protected BigDecimal summaryTotalAmount() { + DynamicObjectCollection entryEntity = this.getModel().getEntryEntity("treeentryentity"); + BigDecimal totalAmount = AimCostBoqCalculateHelper.summaryTreeEntryAmount(entryEntity, "aimcostamount"); + BigDecimal costControlAmount = AimCostBoqCalculateHelper.summaryTreeEntryAmount(entryEntity, "entryamount"); + this.setTotalAmount(totalAmount, costControlAmount); + return totalAmount; + } + + protected void setTotalAmount(BigDecimal totalAmount, BigDecimal costControlAmount) { +// this.getModel().setValue("totalamount", totalAmount);//出去的系统逻辑 + this.getModel().setValue("costcontrolamt", costControlAmount); + this.getModel().setValue("totalprofit", costControlAmount.subtract(totalAmount)); + } + + protected void setTotaloftaxamount(BigDecimal totalAmount) { + this.getModel().setValue("totaloftaxamount", totalAmount); + } + + protected BigDecimal summaryTreeEntryAmount(String amountId, int currentRowIndex) { + DynamicObjectCollection entryEntity = this.getModel().getEntryEntity("treeentryentity"); + BigDecimal totalAmount = AimCostBoqCalculateHelper.summaryTreeEntryAmount(entryEntity, amountId); + List updateIndexList = this.getSuperRowIndex(entryEntity, currentRowIndex); + Iterator var6 = updateIndexList.iterator(); + + while(var6.hasNext()) { + Integer i = (Integer)var6.next(); + this.getView().updateView(amountId, i); + } + + return totalAmount; + } + + @NotNull + private List getSuperRowIndex(DynamicObjectCollection entryEntity, Integer currentRowIndex) { + Set idSet = new HashSet(16); + idSet.add(((DynamicObject)entryEntity.get(currentRowIndex)).getPkValue()); + List updateIndexList = new ArrayList(10); + + for(int i = currentRowIndex; i >= 0; --i) { + DynamicObject entry = (DynamicObject)entryEntity.get(i); + Object pkValue = entry.getPkValue(); + Object pid = entry.get("pid"); + if (idSet.contains(pkValue)) { + updateIndexList.add(i); + idSet.add(pid); + } + } + + return updateIndexList; + } + + protected List getUnitProjectFilter() { + List filters = new ArrayList(2); + DynamicObject org = (DynamicObject)this.getModel().getValue("org"); + DynamicObject project = (DynamicObject)this.getModel().getValue("project"); + if (project != null) { + DynamicObject projectOrg = project.getDynamicObject("projectorg"); + filters.add(new QFilter("parent", "=", project.getPkValue())); + if (org != null && !org.getPkValue().equals(projectOrg.getPkValue())) { + filters.add(new QFilter("responsibleorg", "=", org.getPkValue())); + } + + QFilter existFilter = new QFilter("project", "=", project.getPkValue()); + existFilter.and("unitproject", "!=", 0L); + existFilter.and("id", "!=", this.getModel().getDataEntity().getPkValue()); + DynamicObjectCollection query = QueryServiceHelper.query("ecco_aimcostboqsplitmodel", "unitproject", new QFilter[]{existFilter}); + if (query != null && !query.isEmpty()) { + List unitProjectIds = new ArrayList(query.size()); + Iterator var8 = query.iterator(); + + while(var8.hasNext()) { + DynamicObject bill = (DynamicObject)var8.next(); + unitProjectIds.add(bill.getLong("unitproject")); + } + + filters.add(new QFilter("id", "not in", unitProjectIds)); + } + } + + return filters; + } + + protected void updatePrice(int rowIndex, boolean clearPrice) { + DynamicObject treeEntryRow = this.getModel().getEntryRowEntity("treeentryentity", rowIndex); + BigDecimal qty = treeEntryRow.getBigDecimal("entryqty"); + DynamicObject unit = treeEntryRow.getDynamicObject("entrymeasureunit"); + if (unit != null) { + BigDecimal precision = unit.getBigDecimal("precision"); + qty = qty.setScale(precision.intValue(), RoundingMode.DOWN); + } + + DynamicObjectCollection subEntryEntity = treeEntryRow.getDynamicObjectCollection("subentryentity"); + BigDecimal compositePrice; + BigDecimal subcontractPrice; + BigDecimal secondaryMaterialPrice; + if (subEntryEntity != null && !subEntryEntity.isEmpty()) { + if (qty != null && qty.compareTo(BigDecimal.ZERO) != 0) { + Map costTypePriceMap = new HashMap(); + Iterator var17 = subEntryEntity.iterator(); + + while(var17.hasNext()) { + DynamicObject entry = (DynamicObject)var17.next(); + String costType = entry.getString("costtype"); + if (!StringUtils.isEmpty(costType)) { + subcontractPrice = (BigDecimal)costTypePriceMap.get(costType); + subcontractPrice = subcontractPrice == null ? BigDecimal.ZERO : subcontractPrice; + secondaryMaterialPrice = entry.getBigDecimal("resourceamount"); + subcontractPrice = subcontractPrice.add(secondaryMaterialPrice.setScale(10, RoundingMode.DOWN).divide(qty, RoundingMode.HALF_UP)); + costTypePriceMap.put(costType, subcontractPrice); + } + } + + this.clearPrice(rowIndex); + compositePrice = BigDecimal.ZERO; + + Map.Entry entry; + for(Iterator var19 = costTypePriceMap.entrySet().iterator(); var19.hasNext(); compositePrice = compositePrice.add((BigDecimal)entry.getValue())) { + entry = (Map.Entry)var19.next(); + this.getModel().setValue(AimCostBoqCalculateHelper.getPriceIdByCostType((String)entry.getKey()), entry.getValue(), rowIndex); + } + + this.getModel().setValue("compositeprice", compositePrice, rowIndex); + } + + } else { + if (clearPrice) { + this.clearPrice(rowIndex); + } + + if (!this.isSplitModel()) { + compositePrice = BigDecimal.ZERO; + compositePrice = treeEntryRow.getBigDecimal("profitprice"); + if (compositePrice != null) { + compositePrice = compositePrice.add(compositePrice); + } + + BigDecimal artificialPrice = treeEntryRow.getBigDecimal("artificialprice"); + if (artificialPrice != null) { + compositePrice = compositePrice.add(artificialPrice); + } + + BigDecimal machinePrice = treeEntryRow.getBigDecimal("machineprice"); + if (machinePrice != null) { + compositePrice = compositePrice.add(machinePrice); + } + + subcontractPrice = treeEntryRow.getBigDecimal("subcontractprice"); + if (subcontractPrice != null) { + compositePrice = compositePrice.add(subcontractPrice); + } + + secondaryMaterialPrice = treeEntryRow.getBigDecimal("secondarymaterialprice"); + if (secondaryMaterialPrice != null) { + compositePrice = compositePrice.add(secondaryMaterialPrice); + } + + BigDecimal mainMaterialPrice = treeEntryRow.getBigDecimal("mainmaterialprice"); + if (mainMaterialPrice != null) { + compositePrice = compositePrice.add(mainMaterialPrice); + } + + BigDecimal managementPrice = treeEntryRow.getBigDecimal("managementprice"); + if (managementPrice != null) { + compositePrice = compositePrice.add(managementPrice); + } + + BigDecimal otherPrice = treeEntryRow.getBigDecimal("otherprice"); + if (otherPrice != null) { + compositePrice = compositePrice.add(otherPrice); + } + + this.getModel().setValue("compositeprice", compositePrice, rowIndex); + } + + } + } + + private void clearPrice(int rowIndex) { + this.getModel().setValue("profitprice", 0, rowIndex); + this.getModel().setValue("artificialprice", 0, rowIndex); + this.getModel().setValue("machineprice", 0, rowIndex); + this.getModel().setValue("taxprice", 0, rowIndex); + this.getModel().setValue("subcontractprice", 0, rowIndex); + this.getModel().setValue("secondarymaterialprice", 0, rowIndex); + this.getModel().setValue("mainmaterialprice", 0, rowIndex); + this.getModel().setValue("managementprice", 0, rowIndex); + this.getModel().setValue("otherprice", 0, rowIndex); + this.getModel().setValue("compositeprice", 0, rowIndex); + } + + protected Set getBoqIds() { + DynamicObjectCollection entryEntity = this.getModel().getEntryEntity("treeentryentity"); + Set boqIds = new HashSet(16); + Iterator var3 = entryEntity.iterator(); + + while(var3.hasNext()) { + DynamicObject entry = (DynamicObject)var3.next(); + DynamicObject boq = entry.getDynamicObject("boq"); + if (boq != null) { + boqIds.add(boq.getLong("id")); + } + } + + return boqIds; + } + + protected Map getBoqEntryIdMap() { + DynamicObjectCollection entryEntity = this.getModel().getEntryEntity("treeentryentity"); + Map boqEntryIdMap = new HashMap(16); + Iterator var3 = entryEntity.iterator(); + + while(var3.hasNext()) { + DynamicObject entry = (DynamicObject)var3.next(); + DynamicObject boq = entry.getDynamicObject("boq"); + if (boq != null) { + boqEntryIdMap.put(boq.getLong("id"), entry.getLong("id")); + } + } + + return boqEntryIdMap; + } + + protected boolean validateExistBill() { + DynamicObject bill = this.getModel().getDataEntity(); + DynamicObject project = bill.getDynamicObject("project"); + if (project == null) { + return true; + } else { + DynamicObject unitProject = bill.getDynamicObject("unitproject"); + BigDecimal vision = bill.getBigDecimal("vision"); + Object pkValue = bill.getPkValue(); + QFilter filter = new QFilter("project", "=", project.getPkValue()); + if (unitProject != null) { + filter.and(new QFilter("unitproject", "=", unitProject.getPkValue())); + } + + if (pkValue != null) { + filter.and(new QFilter(AimCostBoqSplitModelConstant.ID_ENTITY_PK, "!=", pkValue)); + } + + filter.and(new QFilter("vision", "=", vision)); + boolean isExist = QueryServiceHelper.exists("ecco_aimcostboqsplitmodel", new QFilter[]{filter}); + if (isExist && vision.compareTo(BigDecimal.ONE) == 0) { + if (unitProject != null) { + this.getView().showTipNotification(ResManager.loadKDString("该单位工程已存在BOQ预算。", "AimCostBoqEditPlugin_68", "ec-ecco-formplugin", new Object[0])); + } else { + this.getView().showTipNotification(ResManager.loadKDString("该项目已存在BOQ预算。", "AimCostBoqEditPlugin_69", "ec-ecco-formplugin", new Object[0])); + } + } else if (isExist) { + if (unitProject != null) { + this.getView().showTipNotification(ResManager.loadKDString("该单位工程已存在相同版本的BOQ预算。", "AimCostBoqEditPlugin_70", "ec-ecco-formplugin", new Object[0])); + } else { + this.getView().showTipNotification(ResManager.loadKDString("该项目已存在相同版本的BOQ预算。", "AimCostBoqEditPlugin_71", "ec-ecco-formplugin", new Object[0])); + } + } + + return isExist; + } + } + + static { + COLUMNKEYS.add(COLUMNKEYA); + COLUMNKEYS.add(COLUMNKEYB); + COLUMNKEYHASHCODES.add(POIHelperFast.stringArrayToHash(COLUMNKEYA)); + COLUMNKEYHASHCODES.add(POIHelperFast.stringArrayToHash(COLUMNKEYB)); + } +} diff --git a/code/zcdev/zcgj-zcdev-zcdev-pr/src/main/java/zcgj/zcdev/zcdev/pr/plugin/form/PaymentapplyCopyPlugin.java b/code/zcdev/zcgj-zcdev-zcdev-pr/src/main/java/zcgj/zcdev/zcdev/pr/plugin/form/PaymentapplyCopyPlugin.java index 06b1295..51aa730 100644 --- a/code/zcdev/zcgj-zcdev-zcdev-pr/src/main/java/zcgj/zcdev/zcdev/pr/plugin/form/PaymentapplyCopyPlugin.java +++ b/code/zcdev/zcgj-zcdev-zcdev-pr/src/main/java/zcgj/zcdev/zcdev/pr/plugin/form/PaymentapplyCopyPlugin.java @@ -109,7 +109,7 @@ public class PaymentapplyCopyPlugin extends AbstractBillPlugIn implements Plugin srcBillNo = this.getView().getParentView().getPageCache().get("srcBillNo");//列表获取的缓存信息 } QFilter f2 = new QFilter("billno", QCP.equals, srcBillNo); - DynamicObject ec_paymentapply = BusinessDataServiceHelper.loadSingle("ec_paymentapply", "id,entryentity,entryentity.bankaccount", new QFilter[]{f2}); + DynamicObject ec_paymentapply = BusinessDataServiceHelper.loadSingle("ec_paymentapply", "id,billname,entryentity,entryentity.bankaccount", new QFilter[]{f2}); if (ec_paymentapply != null) { DynamicObjectCollection entryEntityCollection = ec_paymentapply.getDynamicObjectCollection("entryentity");//合同付款信息分录 for (int i = 0; i < entryEntityCollection.size(); i++) { @@ -117,6 +117,12 @@ public class PaymentapplyCopyPlugin extends AbstractBillPlugIn implements Plugin String bankAccount = entryEntity.getString("bankaccount");//收款账号 this.getModel().setValue("bankaccount", bankAccount, i); } + String billName = ec_paymentapply.getString("billname");//单位名称 + if (billName != null) { + this.getModel().setValue("billname", billName + "-复制"); + } else { + this.getModel().setValue("billname", "-复制"); + } } } }