diff --git a/code/zcdev/zcgj-zcdev-zcdev-pr/src/main/java/zcgj/zcdev/zcdev/pr/plugin/operate/PeriodAimcostcbsbillEditPluginExt.java b/code/zcdev/zcgj-zcdev-zcdev-pr/src/main/java/zcgj/zcdev/zcdev/pr/plugin/operate/PeriodAimcostcbsbillEditPluginExt.java new file mode 100644 index 0000000..9b813c0 --- /dev/null +++ b/code/zcdev/zcgj-zcdev-zcdev-pr/src/main/java/zcgj/zcdev/zcdev/pr/plugin/operate/PeriodAimcostcbsbillEditPluginExt.java @@ -0,0 +1,1377 @@ +// +// Source code recreated from a .class file by IntelliJ IDEA +// (powered by FernFlower decompiler) +// + +package zcgj.zcdev.zcdev.pr.plugin.operate; + +import java.math.BigDecimal; +import java.util.ArrayList; +import java.util.Calendar; +import java.util.EventObject; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.stream.Collectors; +import kd.bos.bill.OperationStatus; +import kd.bos.dataentity.entity.DynamicObject; +import kd.bos.dataentity.entity.DynamicObjectCollection; +import kd.bos.dataentity.metadata.dynamicobject.DynamicObjectType; +import kd.bos.dataentity.resource.ResManager; +import kd.bos.dataentity.utils.StringUtils; +import kd.bos.entity.EntityMetadataCache; +import kd.bos.entity.MainEntityType; +import kd.bos.entity.datamodel.events.ChangeData; +import kd.bos.entity.datamodel.events.PropertyChangedArgs; +import kd.bos.form.CloseCallBack; +import kd.bos.form.ConfirmCallBackListener; +import kd.bos.form.ConfirmTypes; +import kd.bos.form.FormShowParameter; +import kd.bos.form.MessageBoxOptions; +import kd.bos.form.MessageBoxResult; +import kd.bos.form.ShowType; +import kd.bos.form.control.Button; +import kd.bos.form.control.Control; +import kd.bos.form.control.EntryGrid; +import kd.bos.form.control.SubEntryGrid; +import kd.bos.form.control.TreeEntryGrid; +import kd.bos.form.control.events.RowClickEvent; +import kd.bos.form.control.events.RowClickEventListener; +import kd.bos.form.control.events.UploadEvent; +import kd.bos.form.control.events.UploadListener; +import kd.bos.form.events.AfterDoOperationEventArgs; +import kd.bos.form.events.BeforeDoOperationEventArgs; +import kd.bos.form.events.ClosedCallBackEvent; +import kd.bos.form.events.MessageBoxClosedEvent; +import kd.bos.form.field.BasedataEdit; +import kd.bos.form.field.events.BeforeF7SelectEvent; +import kd.bos.form.field.events.BeforeF7SelectListener; +import kd.bos.form.operate.FormOperate; +import kd.bos.list.ListShowParameter; +import kd.bos.orm.ORM; +import kd.bos.orm.query.QFilter; +import kd.bos.servicehelper.BusinessDataServiceHelper; +import kd.bos.servicehelper.QueryServiceHelper; +import kd.bos.servicehelper.user.UserServiceHelper; +import kd.bos.upload.UploadOption; +import kd.ec.basedata.business.model.ecco.BaseConstant; +import kd.ec.basedata.business.utils.EcCommonUtils; +import kd.ec.basedata.common.hierarchy.DynamicObjectTreeNode; +import kd.ec.basedata.common.utils.EcSerializeHelper; +import kd.ec.contract.common.utils.CurrencyHelper; +import kd.ec.contract.common.utils.EcConstant; +import kd.ec.contract.common.utils.EcNumberHelper; +import kd.ec.contract.common.utils.TypeUtils; +import kd.ec.cost.formplugin.AbstractEccoBillPlugin; +import kd.ec.cost.utils.AimCostCbsPoiHelper; +import kd.ec.cost.utils.CostTypeUtils; +import kd.ec.cost.utils.CurrencyFormatUtil; + +public class PeriodAimcostcbsbillEditPluginExt extends AbstractEccoBillPlugin implements BeforeF7SelectListener, RowClickEventListener, UploadListener { + private static final String PROJECT_ID = "projectId"; + private static final String IS_CANCEL = "isCancel"; + private static final String FALSE = "false"; + private static final String ISLEAF = "isleaf"; + private static final String IS_PDAMOUNT_CHANGE = "isPdamountChange"; + private static final String ISDELETESUBENTRY = "isdeletesubentry"; + private static final String ISIMPORT = "isimport"; + private static final String ISDELETE = "isdelete"; + private static final String EDITONUNIT = "editonunit"; + private static final String UPLOADCBS = "uploadcbs"; + private static final String COLOR_BLUE = "#B6E5FF"; + private static final String COLOR_GRAY = "#9D9D9D"; + private static final String COLOR_WRITE = "#FFFFFF"; + private static final String TREEENTRYENTITY = "treeentryentity"; + private static final String PROJECTPARAM = "projectId"; + private double versionNum = 1.0; + + public PeriodAimcostcbsbillEditPluginExt() { + } + + public void registerListener(EventObject e) { + super.registerListener(e); + BasedataEdit unitproject = (BasedataEdit)this.getControl("unitproject"); + unitproject.addBeforeF7SelectListener(this); + BasedataEdit project = (BasedataEdit)this.getControl("project"); + project.addBeforeF7SelectListener(this); + BasedataEdit boqEdit = (BasedataEdit)this.getControl("projectboq"); + boqEdit.addBeforeF7SelectListener(this); + TreeEntryGrid grid = (TreeEntryGrid)this.getControl("treeentryentity"); + grid.addRowClickListener(this); + Button uploadBtn = (Button)this.getControl("uploadcbs"); + uploadBtn.addUploadListener(this); + } + + public void entryRowClick(RowClickEvent rowclickevent) { +// super.entryRowClick(rowclickevent);//二开注释 + this.setsubEntryColor(); + this.setSubEntrySumAmount(); + } + + protected void setsubEntryColor() { + if (this.isAdjust()) { + SubEntryGrid subentryGrid = (SubEntryGrid)this.getView().getControl("subentryentity"); + int rowcount = this.getModel().getEntryRowCount("subentryentity"); + + for(int i = 0; i < rowcount; ++i) { + String oldentryid = TypeUtils.nullToString(this.getModel().getValue("oldentryid", i)); + if (!"".equals(oldentryid) && !"0".equals(oldentryid)) { + BigDecimal oldAdjuAmount = (BigDecimal)this.getModel().getValue("oldamountre", i); + BigDecimal amountnew = (BigDecimal)this.getModel().getValue("amount", i); + BigDecimal price = (BigDecimal)this.getModel().getValue("price", i); + BigDecimal qty = (BigDecimal)this.getModel().getValue("qty", i); + if (amountnew.compareTo(EcNumberHelper.ZERO) == 0 && price.compareTo(EcNumberHelper.ZERO) == 0 && qty.compareTo(EcNumberHelper.ZERO) == 0) { + subentryGrid.setRowBackcolor("#9D9D9D", new int[]{i}); + } else if (oldAdjuAmount.compareTo(amountnew) != 0) { + subentryGrid.setRowBackcolor("#B6E5FF", new int[]{i}); + } else { + subentryGrid.setRowBackcolor("#FFFFFF", new int[]{i}); + } + } else { + subentryGrid.setRowBackcolor("#B6E5FF", new int[]{i}); + } + } + } + + } + + public void beforeF7Select(BeforeF7SelectEvent beforef7selectevent) { + String name = beforef7selectevent.getProperty().getName(); + if ("unitproject".equals(name)) { + this.beforeUnitprojectSelected(beforef7selectevent); + } else if ("projectboq".equals(name)) { + this.beforeProjectBoqSelected(beforef7selectevent); + } else if ("project".equals(name)) { + this.beforeProjectSelected(beforef7selectevent); + } + + } + + protected void beforeProjectSelected(BeforeF7SelectEvent ent) { + ListShowParameter parameter = (ListShowParameter)ent.getFormShowParameter(); + List projectIds = new ArrayList(); + DynamicObject period = this.getView().getModel().getDataEntity().getDynamicObject("period"); + if (period != null) { + QFilter filter = new QFilter("period", "=", period.getPkValue()); + filter.and(new QFilter("id", "!=", this.getModel().getDataEntity().getPkValue())); + DynamicObject[] costbills = BusinessDataServiceHelper.load("ecco_periodcostbillcbs", "id,billno,billstatus,creator,modifier,auditor,auditdate,modifytime,createtime,org,name,project,unitproject,totalamount,versionno,remark,oldid,treeentryentity.id,treeentryentity.pid,treeentryentity.isGroupNode,treeentryentity.cbs,treeentryentity.oldamount,treeentryentity.pdamount,treeentryentity.description,treeentryentity.isgua,treeentryentity.isleaf,treeentryentity.oldcbsentryid,treeentryentity.isdelete,treeentryentity.pdpercent,treeentryentity.totalpdamount,period,isenable,currency,aimcostversion,editonunit,fiaccountorg,billhead_lk.id,billhead_lk.billhead_lk_stableid,billhead_lk.billhead_lk_sbillid,billhead_lk.billhead_lk_sid", new QFilter[]{filter}); + DynamicObject[] var7 = costbills; + int var8 = costbills.length; + + for(int var9 = 0; var9 < var8; ++var9) { + DynamicObject costbill = var7[var9]; + DynamicObject project = costbill.getDynamicObject("project"); + if (!project.getBoolean("editonunit")) { + projectIds.add((Long)project.getPkValue()); + } + } + + QFilter qFilter = new QFilter("id", "not in", projectIds); + parameter.getListFilterParameter().getQFilters().add(qFilter); + } + } + + protected void beforeProjectBoqSelected(BeforeF7SelectEvent beforef7selectevent) { + boolean editOnUnit = (Boolean)this.getModel().getValue("editonunit"); + DynamicObject unitproject = (DynamicObject)this.getModel().getValue("unitproject"); + ListShowParameter parameter = (ListShowParameter)beforef7selectevent.getFormShowParameter(); + if (editOnUnit && unitproject == null) { + this.getView().showTipNotification(ResManager.loadKDString("请填写“单位工程”字段。", "PeriodAimcostcbsbillEditPlugin_0", "ec-ecco-formplugin", new Object[0])); + beforef7selectevent.setCancel(true); + } else { + if (editOnUnit) { + QFilter qFilter = new QFilter("unitproject", "=", unitproject.getPkValue()); + parameter.getListFilterParameter().getQFilters().add(qFilter); + } + + DynamicObject project = (DynamicObject)this.getModel().getValue("project"); + if (project != null) { + QFilter qFilter = new QFilter("project", "=", project.getPkValue()); + parameter.getListFilterParameter().getQFilters().add(qFilter); + } + + parameter.setFormId("bos_listf7"); + } + } + + protected void beforeUnitprojectSelected(BeforeF7SelectEvent beforef7selectevent) { + ListShowParameter parameter = (ListShowParameter)beforef7selectevent.getFormShowParameter(); + DynamicObject project = (DynamicObject)this.getModel().getValue("project"); + QFilter qFilter = new QFilter("parent", "=", project != null ? project.getPkValue() : 0L); + List unitprojectIds = new ArrayList(); + QFilter filter = new QFilter("project", "=", project != null ? project.getPkValue() : 0L); + DynamicObject period = this.getView().getModel().getDataEntity().getDynamicObject("period"); + if (period != null) { + filter.and(new QFilter("period", "=", period.getPkValue())); + filter.and(new QFilter("id", "!=", this.getModel().getDataEntity().getPkValue())); + DynamicObject[] costbills = BusinessDataServiceHelper.load("ecco_periodcostbillcbs", "id,billno,billstatus,creator,modifier,auditor,auditdate,modifytime,createtime,org,name,project,unitproject,totalamount,versionno,remark,oldid,treeentryentity.id,treeentryentity.pid,treeentryentity.isGroupNode,treeentryentity.cbs,treeentryentity.oldamount,treeentryentity.pdamount,treeentryentity.description,treeentryentity.isgua,treeentryentity.isleaf,treeentryentity.oldcbsentryid,treeentryentity.isdelete,treeentryentity.pdpercent,treeentryentity.totalpdamount,period,isenable,currency,aimcostversion,editonunit,fiaccountorg,billhead_lk.id,billhead_lk.billhead_lk_stableid,billhead_lk.billhead_lk_sbillid,billhead_lk.billhead_lk_sid", new QFilter[]{filter}); + DynamicObject[] var9 = costbills; + int var10 = costbills.length; + + for(int var11 = 0; var11 < var10; ++var11) { + DynamicObject costbill = var9[var11]; + DynamicObject unitproject = costbill.getDynamicObject("unitproject"); + unitprojectIds.add((Long)unitproject.getPkValue()); + } + + qFilter.and(new QFilter("id", "not in", unitprojectIds)); + parameter.setCaption(ResManager.loadKDString("单位工程/标段", "PeriodAimcostcbsbillEditPlugin_1", "ec-ecco-formplugin", new Object[0])); + parameter.getListFilterParameter().getQFilters().add(qFilter); + } + } + + protected int findrowindex(String cbsid) { + int rowindex = -1; + + for(int i = 0; i < this.getModel().getEntryRowCount("treeentryentity"); ++i) { + DynamicObject cbsInfo = (DynamicObject)this.getModel().getValue("cbs", i); + if (cbsInfo != null && cbsid.equals(TypeUtils.nullToString(cbsInfo.getPkValue()))) { + rowindex = i; + } + } + + return rowindex; + } + + public void closedCallBack(ClosedCallBackEvent closedcallbackevent) { + super.closedCallBack(closedcallbackevent); + String actionID = closedcallbackevent.getActionId(); + if ("batchsetup".equals(actionID) && closedcallbackevent.getReturnData() != null) { + this.batchSetup(closedcallbackevent); + } + + } + + protected void batchSetup(ClosedCallBackEvent closedcallbackevent) { + Map map = (Map)closedcallbackevent.getReturnData(); + BigDecimal pdPercent = (BigDecimal)map.get("periodpercent"); + TreeEntryGrid treeEntry = (TreeEntryGrid)this.getControl("treeentryentity"); + int[] selRows = treeEntry.getSelectRows(); + + for(int i = 0; i < selRows.length; ++i) { + int curIndex = selRows[i]; + boolean isleaf = (Boolean)this.getModel().getValue("isleaf", curIndex); + BigDecimal totalPdAmount = (BigDecimal)this.getModel().getValue("totalpdamount", curIndex); + if (isleaf && BigDecimal.ZERO.compareTo(totalPdAmount) != 0) { + this.getModel().setValue("pdpercent", pdPercent, curIndex); + BigDecimal pdAmount = (BigDecimal)this.getModel().getValue("pdamount", curIndex); + pdPercent = pdAmount.divide(totalPdAmount, 10, 4).multiply(BigDecimal.valueOf(100L)); + this.getModel().beginInit(); + this.getModel().setValue("pdpercent", pdPercent, curIndex); + this.getModel().endInit(); + this.getView().updateView("pdpercent", curIndex); + } + } + + if (selRows.length > 0) { + treeEntry.selectRows(selRows[0]); + } + + } + + protected DynamicObjectTreeNode dynamicObjectToTreeNode(DynamicObject cbsEntryinfo, DynamicObject cbsInfo) { + DynamicObjectTreeNode child = new DynamicObjectTreeNode(); + child.setId((Long)cbsEntryinfo.getPkValue()); + if (cbsEntryinfo.get("pid") != null && cbsEntryinfo.getLong("pid") != 0L) { + child.setParentId(cbsEntryinfo.getLong("pid")); + } else { + child.setParentId(1L); + } + + child.setName(cbsInfo.getString("name")); + child.setValue(cbsEntryinfo); + child.setNumber(cbsInfo.getString("number")); + return child; + } + + public void afterCreateNewData(EventObject e) { + super.afterCreateNewData(e); + Calendar cal = Calendar.getInstance(); + int year = cal.get(1); + int month = cal.get(2) + 1; + QFilter yearFilter = new QFilter("periodyear", "=", year); + QFilter monthFilter = new QFilter("periodnumber", "=", month); + DynamicObject[] peridoArr = BusinessDataServiceHelper.load("bd_period", "number,name,periodyear,periodnumber", new QFilter[]{yearFilter, monthFilter}); + if (peridoArr != null && peridoArr.length > 0) { + DynamicObject period = peridoArr[0]; + this.getModel().setValue("period", period); + } + + FormShowParameter parameter = this.getView().getFormShowParameter(); + ORM orm = ORM.create(); + DynamicObject project; + DynamicObjectCollection entryColl; + if (!this.isAdjust()) { + Object projectId = parameter.getCustomParam("projectId"); + if (projectId != null) { + project = BusinessDataServiceHelper.loadSingle(projectId, "ec_project"); + this.getModel().setValue("project", project); + this.getModel().setValue("editonunit", project.getBoolean("editonunit")); + this.getModel().setValue("fiaccountorg", project.get("fiaccountorg_id")); + QFilter procbsfilter = new QFilter("project", "=", Long.valueOf(projectId.toString())); + QFilter enbaleFilter = new QFilter("isenable", "=", true); + DynamicObject aimCostCbs = BusinessDataServiceHelper.loadSingle("ecco_aimcostbillcbs", "versionno,treeentryentity.cbs,treeentryentity.pdamount,treeentryentity.isgua,treeentryentity.isleaf,treeentryentity.pid,subentryentity.resourceitem,subentryentity.measureunit,subentryentity.qty,subentryentity.price,subentryentity.amount,subentryentity.cbsre,subentryentity.costaccount,subentryentity.projectboq,subentryentity.costitem", new QFilter[]{procbsfilter, enbaleFilter}); + if (aimCostCbs != null) { + this.getModel().setValue("aimcostversion", aimCostCbs.get("versionno")); + entryColl = aimCostCbs.getDynamicObjectCollection("treeentryentity"); + if (!entryColl.isEmpty()) { + this.fillProCbsTreeList(entryColl); + } + } + } + + this.getModel().setValue("creator", BusinessDataServiceHelper.loadSingle(UserServiceHelper.getCurrentUserId(), "bos_user")); + this.getModel().setValue("versionno", this.versionNum); + } else { + MainEntityType dt = EntityMetadataCache.getDataEntityType("ecco_periodcostbillcbs"); + project = BusinessDataServiceHelper.loadSingle(parameter.getCustomParam("oldInfoid"), dt); + DynamicObject newInfo = this.getModel().getDataEntity(); + newInfo.set("id", orm.genLongId(dt)); + newInfo.set("oldid", project.getPkValue()); + newInfo.set("billno", project.get("billno")); + newInfo.set("name", project.get("name")); + newInfo.set("project", project.get("project")); + newInfo.set("unitproject", project.get("unitproject")); + newInfo.set("period", project.get("period")); + newInfo.set("totalamount", project.get("totalamount")); + newInfo.set("remark", project.get("remark")); + newInfo.set("org", project.get("org")); + newInfo.set("editonunit", project.get("editonunit")); + this.versionNum = TypeUtils.string2Double(project.getString("versionno")) + 1.0; + newInfo.set("versionno", this.versionNum); + newInfo.set("aimcostversion", project.get("aimcostversion")); + newInfo.set("fiaccountorg", project.get("fiaccountorg")); + this.getView().updateView("oldid"); + this.getView().updateView("billno"); + this.getView().updateView("name"); + this.getView().updateView("project"); + this.getView().updateView("unitproject"); + this.getView().updateView("period"); + this.getView().updateView("totalamount"); + this.getView().updateView("remark"); + this.getView().updateView("org"); + this.getView().updateView("versionno"); + Map cbsEntryIdMap = new HashMap(); + DynamicObjectCollection cbsEntryColl = project.getDynamicObjectCollection("treeentryentity"); + entryColl = new DynamicObjectCollection(EcCommonUtils.getEntryDynamicObjectType("ecco_periodcostbillcbs", "treeentryentity"), newInfo); + int seq = 0; + + for(int i = 0; i < cbsEntryColl.size(); ++i) { + DynamicObject oldValue = (DynamicObject)cbsEntryColl.get(i); + if (!oldValue.getBoolean("isdelete")) { + DynamicObject newValue = new DynamicObject(oldValue.getDynamicObjectType()); + newValue.set("id", orm.genLongId(EcCommonUtils.getEntryDynamicObjectType("ecco_periodcostbillcbs", "treeentryentity"))); + if (oldValue.get("pid") != null) { + newValue.set("pid", cbsEntryIdMap.get((Long)oldValue.get("pid"))); + } + + newValue.set("seq", seq++); + newValue.set("cbs", oldValue.get("cbs")); + newValue.set("oldamount", oldValue.get("pdamount")); + newValue.set("pdamount", oldValue.get("pdamount")); + newValue.set("description", oldValue.get("description")); + newValue.set("isgua", oldValue.get("isgua")); + newValue.set("isleaf", oldValue.get("isleaf")); + newValue.set("oldcbsentryid", oldValue.getPkValue()); + newValue.set("pdpercent", oldValue.get("pdpercent")); + newValue.set("totalpdamount", oldValue.get("totalpdamount")); + cbsEntryIdMap.put((Long)oldValue.getPkValue(), (Long)newValue.getPkValue()); + DynamicObjectCollection oldSubEntries = (DynamicObjectCollection)oldValue.get("subentryentity"); + if (!oldSubEntries.isEmpty()) { + DynamicObjectCollection newSubEntries = new DynamicObjectCollection(oldSubEntries.getDynamicObjectType(), newValue); + int subseq = 0; + + for(int j = 0; j < oldSubEntries.size(); ++j) { + DynamicObject oldreValue = (DynamicObject)oldSubEntries.get(j); + if (oldreValue.getBigDecimal("amount").compareTo(EcNumberHelper.ZERO) != 0 || oldreValue.getBigDecimal("price").compareTo(EcNumberHelper.ZERO) != 0 || oldreValue.getBigDecimal("qty").compareTo(EcNumberHelper.ZERO) != 0) { + DynamicObject newreValue = new DynamicObject(oldreValue.getDynamicObjectType()); + newreValue.set("seq", subseq++); + newreValue.set("oldentryid", oldreValue.getPkValue()); + newreValue.set("id", orm.genLongId(oldSubEntries.getDynamicObjectType())); + newreValue.set("resourceitem", oldreValue.get("resourceitem")); + newreValue.set("measureunit", oldreValue.get("measureunit")); + newreValue.set("oldprice", oldreValue.get("price")); + newreValue.set("oldqty", oldreValue.get("qty")); + newreValue.set("oldamountre", oldreValue.get("amount")); + newreValue.set("price", oldreValue.get("price")); + newreValue.set("qty", oldreValue.get("qty")); + newreValue.set("amount", oldreValue.get("amount")); + newreValue.set("cbsre", oldreValue.get("cbsre")); + newreValue.set("costaccount", oldreValue.get("costaccount")); + newreValue.set("projectboq", oldreValue.get("projectboq")); + newreValue.set("reamrkre", oldreValue.get("reamrkre")); + newreValue.set("originalamt", oldreValue.get("originalamt")); + newSubEntries.add(newreValue); + } + } + + newValue.set("subentryentity", newSubEntries); + } + + entryColl.add(newValue); + } + } + + newInfo.set("treeentryentity", entryColl); + this.getView().setEnable(false, new String[]{"editonunit"}); + this.getView().updateView("treeentryentity"); + } + + } + + public void beforeBindData(EventObject e) { + super.beforeBindData(e); + if (this.isAdjust()) { + this.getView().setVisible(true, new String[]{"oldamount"}); + this.getView().setVisible(true, new String[]{"oldprice"}); + this.getView().setVisible(true, new String[]{"oldqty"}); + this.getView().setVisible(true, new String[]{"oldamountre"}); + this.getView().setEnable(false, new String[]{"project", "period", "org"}); + this.getView().updateView("treeentryentity"); + this.getView().updateView("subentryentity"); + } else { + this.getView().setVisible(false, new String[]{"oldamount"}); + this.getView().setVisible(false, new String[]{"oldprice"}); + this.getView().setVisible(false, new String[]{"oldqty"}); + this.getView().setVisible(false, new String[]{"oldamountre"}); + this.getView().updateView("treeentryentity"); + this.getView().updateView("subentryentity"); + } + + } + + public void afterBindData(EventObject eventobject) { + super.afterBindData(eventobject); + this.setUnitProjectMustinput(); + this.refershTreeEnable(); + this.setSumToRow("treeentryentity", new String[]{"oldamount", "pdamount", "totalpdamount"}); + TreeEntryGrid treeEntry = (TreeEntryGrid)this.getView().getControl("treeentryentity"); + treeEntry.setCollapse(false); + if (!"A".equals(this.getModel().getValue("billstatus"))) { + this.getView().setEnable(false, new String[]{"advconbaritemap2"}); + } + + } + + protected void setUnitProjectMustinput() { + boolean editOnUnit = (Boolean)this.getModel().getValue("editonunit"); + BasedataEdit unitProjectEdit = (BasedataEdit)this.getView().getControl("unitproject"); + unitProjectEdit.setMustInput(editOnUnit); + } + + protected boolean isAdjust() { + if (!OperationStatus.ADDNEW.equals(this.getView().getFormShowParameter().getStatus())) { + this.versionNum = TypeUtils.string2Double(this.getModel().getDataEntity().getString("versionno")); + if (this.versionNum != 1.0) { + return true; + } + } + + return this.getView().getFormShowParameter().getCustomParam("isadjust") == null ? false : (Boolean)this.getView().getFormShowParameter().getCustomParam("isadjust"); + } + + protected void refershTreeEnable() { + int rowcount = this.getModel().getEntryRowCount("treeentryentity"); + TreeEntryGrid grid = (TreeEntryGrid)this.getView().getControl("treeentryentity"); + + for(int i = 0; i < rowcount; ++i) { + if (this.isAdjust() && this.getModel().getValue("oldcbsentryid", i) != null && !"0".equals(TypeUtils.nullToString(this.getModel().getValue("oldcbsentryid", i)))) { + BigDecimal oldAmount = EcNumberHelper.toBigDecimal(this.getModel().getValue("oldamount", i)); + BigDecimal newAmount = EcNumberHelper.toBigDecimal(this.getModel().getValue("pdamount", i)); + boolean isdelete = "true".equals(TypeUtils.nullToString(this.getModel().getValue("isdelete", i))); + if (isdelete) { + grid.setRowBackcolor("#9D9D9D", new int[]{i}); + } else if (oldAmount.compareTo(newAmount) != 0) { + grid.setRowBackcolor("#B6E5FF", new int[]{i}); + } else { + grid.setRowBackcolor("#FFFFFF", new int[]{i}); + } + } + } + + } + + public void propertyChanged(PropertyChangedArgs e) { + super.propertyChanged(e); + ChangeData chgData = e.getChangeSet()[0]; + Object oldValue = chgData.getOldValue(); + Object newValue = chgData.getNewValue(); + int rowIndex = chgData.getRowIndex(); + String propName = e.getProperty().getName(); + if (propName.equals("pdamount")) { + this.pdamountChanged(oldValue, newValue, rowIndex); + } else if (propName.equals("resourceitem")) { + this.resourceItemChanged(newValue, rowIndex); + } else if (propName.equals("price")) { + this.priceChanged(newValue, rowIndex); + } else if (propName.equals("qty")) { + this.qtyChanged(newValue, rowIndex); + } else if (propName.equals("amount")) { + this.amountChanged(chgData); + } else if (propName.equals("unitproject")) { + this.unitProjectChanged(oldValue); + } else if (propName.equals("project")) { + this.projectChanged(newValue); + } else if (propName.equals("pdpercent")) { + this.pdpercentChanged(newValue, rowIndex); + } else if (propName.equals("editonunit")) { + this.setUnitProjectMustinput(); + } else if (propName.equals("fiaccountorg")) { + this.fiaccountOrgChanged(newValue); + } else if (propName.equals("period")) { + this.periodChange(newValue, oldValue); + } + + } + + protected void periodChange(Object newValue, Object oldValue) { + DynamicObject project = this.getModel().getDataEntity().getDynamicObject("project"); + DynamicObject period = (DynamicObject)newValue; + if (project != null && period != null) { + QFilter projectFilter = new QFilter("project", "=", project.getPkValue()); + QFilter periodFilter = new QFilter("period", "=", period.getPkValue()); + boolean editOnUnit = this.getModel().getDataEntity().getBoolean("editonunit"); + if (!editOnUnit) { + DynamicObject[] costbills = BusinessDataServiceHelper.load("ecco_periodcostbillcbs", "id,billno,billstatus,creator,modifier,auditor,auditdate,modifytime,createtime,org,name,project,unitproject,totalamount,versionno,remark,oldid,treeentryentity.id,treeentryentity.pid,treeentryentity.isGroupNode,treeentryentity.cbs,treeentryentity.oldamount,treeentryentity.pdamount,treeentryentity.description,treeentryentity.isgua,treeentryentity.isleaf,treeentryentity.oldcbsentryid,treeentryentity.isdelete,treeentryentity.pdpercent,treeentryentity.totalpdamount,period,isenable,currency,aimcostversion,editonunit,fiaccountorg,billhead_lk.id,billhead_lk.billhead_lk_stableid,billhead_lk.billhead_lk_sbillid,billhead_lk.billhead_lk_sid", new QFilter[]{periodFilter, projectFilter}); + if (costbills.length > 0) { + this.getView().showTipNotification(ResManager.loadKDString("当前项目在所选期间已存在期间CBS成本预算。", "PeriodAimcostcbsbillEditPlugin_2", "ec-ecco-formplugin", new Object[0])); + this.getView().getModel().setValue("period", (DynamicObject)oldValue); + return; + } + } else { + DynamicObject unitproject = this.getView().getModel().getDataEntity().getDynamicObject("unitproject"); + if (unitproject == null) { + return; + } + + QFilter unitprojectFilter = new QFilter("unitproject", "=", unitproject.getPkValue()); + DynamicObject[] costbills = BusinessDataServiceHelper.load("ecco_periodcostbillcbs", "id,billno,billstatus,creator,modifier,auditor,auditdate,modifytime,createtime,org,name,project,unitproject,totalamount,versionno,remark,oldid,treeentryentity.id,treeentryentity.pid,treeentryentity.isGroupNode,treeentryentity.cbs,treeentryentity.oldamount,treeentryentity.pdamount,treeentryentity.description,treeentryentity.isgua,treeentryentity.isleaf,treeentryentity.oldcbsentryid,treeentryentity.isdelete,treeentryentity.pdpercent,treeentryentity.totalpdamount,period,isenable,currency,aimcostversion,editonunit,fiaccountorg,billhead_lk.id,billhead_lk.billhead_lk_stableid,billhead_lk.billhead_lk_sbillid,billhead_lk.billhead_lk_sid", new QFilter[]{periodFilter, projectFilter, unitprojectFilter}); + if (costbills.length > 0) { + this.getView().showTipNotification(ResManager.loadKDString("当前单位工程在所选期间已存在期间CBS成本预算。", "PeriodAimcostcbsbillEditPlugin_3", "ec-ecco-formplugin", new Object[0])); + this.getView().getModel().setValue("period", (DynamicObject)oldValue); + return; + } + } + + } + } + + private void fiaccountOrgChanged(Object newValue) { + DynamicObject org; + DynamicObject currency; + if (newValue != null) { + org = (DynamicObject)newValue; + currency = CurrencyHelper.getCurrency((Long)org.getPkValue()); + if (currency != null) { + this.getModel().setValue("currency", currency); + } + } else { + org = this.getModel().getDataEntity().getDynamicObject("org"); + if (org != null) { + currency = CurrencyHelper.getCurrency((Long)org.getPkValue()); + if (currency != null) { + this.getModel().setValue("currency", currency); + } + } + } + + } + + protected void pdpercentChanged(Object newValue, int rowIndex) { + BigDecimal percent = EcNumberHelper.toBigDecimal(newValue).divide(BigDecimal.valueOf(100L)); + BigDecimal totalPdAmount = EcNumberHelper.toBigDecimal(this.getModel().getValue("totalpdamount", rowIndex)); + BigDecimal pdAmount = totalPdAmount.multiply(percent); + DynamicObject treeEntryRowObj = this.getModel().getEntryRowEntity("treeentryentity", rowIndex); + DynamicObjectCollection subEntryRowColllection = treeEntryRowObj.getDynamicObjectCollection("subentryentity"); + if (subEntryRowColllection != null && !subEntryRowColllection.isEmpty()) { + pdAmount = BigDecimal.ZERO; + + for(int i = 0; i < subEntryRowColllection.size(); ++i) { + DynamicObject subEntryRowObj = (DynamicObject)subEntryRowColllection.get(i); + BigDecimal originalAmt = subEntryRowObj.getBigDecimal("originalamt"); + BigDecimal subAmount = originalAmt.multiply(percent); + if (subAmount.compareTo(BigDecimal.ZERO) != 0) { + BigDecimal subPrice = subEntryRowObj.getBigDecimal("price"); + BigDecimal subQty = subAmount.divide(subPrice, 10, 4); + subEntryRowObj.set("amount", subAmount); + subEntryRowObj.set("qty", subQty); + pdAmount = pdAmount.add(subAmount); + } else { + pdAmount = pdAmount.add(subEntryRowObj.getBigDecimal("amount")); + } + } + } + + this.getModel().setValue("pdamount", pdAmount, rowIndex); + } + + protected void projectChanged(Object newValue) { + this.getView().getFormShowParameter().setCustomParam("isCancel", "true"); + this.getModel().setValue("unitproject", (Object)null); + if (newValue == null) { + this.getModel().setValue("totalamount", (Object)null); + this.getModel().setValue("aimcostversion", (Object)null); + this.getModel().deleteEntryData("treeentryentity"); + } else { + this.reloadFromTotalAimCost(); + } + } + + protected void reloadFromTotalAimCost() { + this.getModel().deleteEntryData("treeentryentity"); + DynamicObject aimCostCbs = this.getEnabledTotalAimCost(); + if (aimCostCbs != null) { + this.getModel().setValue("aimcostversion", aimCostCbs.get("versionno")); + DynamicObjectCollection procbsEntry = aimCostCbs.getDynamicObjectCollection("treeentryentity"); + if (!procbsEntry.isEmpty()) { + this.fillProCbsTreeList(procbsEntry); + } + } + + this.getModel().setValue("creator", BusinessDataServiceHelper.loadSingle(UserServiceHelper.getCurrentUserId(), "bos_user")); + } + + protected DynamicObject getEnabledTotalAimCost() { + DynamicObject project = (DynamicObject)this.getModel().getValue("project"); + DynamicObject unitProject = (DynamicObject)this.getModel().getValue("unitproject"); + boolean editOnUnit = (Boolean)this.getModel().getValue("editonunit"); + if (project != null && (!editOnUnit || unitProject != null)) { + QFilter filter = new QFilter("isenable", "=", true); + filter.and(new QFilter("project", "=", project.getPkValue())); + if (editOnUnit) { + filter.and(new QFilter("unitproject", "=", unitProject.getPkValue())); + } + + return BusinessDataServiceHelper.loadSingle("ecco_aimcostbillcbs", "versionno,treeentryentity.cbs,treeentryentity.pdamount,treeentryentity.isgua,treeentryentity.isleaf,treeentryentity.pid,subentryentity.resourceitem,subentryentity.measureunit,subentryentity.qty,subentryentity.price,subentryentity.amount,subentryentity.cbsre,subentryentity.costaccount,subentryentity.projectboq,subentryentity.costitem", new QFilter[]{filter}); + } else { + return null; + } + } + + protected void unitProjectChanged(Object oldValue) { + boolean isCancel = "true".equals(TypeUtils.nullToString((String)this.getView().getFormShowParameter().getCustomParam("isCancel"))); + if (isCancel) { + this.getView().getFormShowParameter().setCustomParam("isCancel", "false"); + } else { + DynamicObjectCollection entryEntity = this.getModel().getEntryEntity("treeentryentity"); + if (entryEntity != null && !entryEntity.isEmpty()) { + ConfirmCallBackListener confirmCallBack = new ConfirmCallBackListener("unitprojectchange_callback", this); + String unitPk = oldValue == null ? "0" : ((DynamicObject)oldValue).getPkValue().toString(); + this.getPageCache().put("oldunitproject", unitPk); + this.getView().showConfirm(ResManager.loadKDString("该操作会重新加载分录数据,是否继续?", "PeriodAimcostcbsbillEditPlugin_4", "ec-ecco-formplugin", new Object[0]), MessageBoxOptions.OKCancel, ConfirmTypes.Delete, confirmCallBack); + } else { + this.reloadFromTotalAimCost(); + } + } + + } + + protected void amountChanged(ChangeData changeData) { + boolean isimport = "true".equals(TypeUtils.nullToString((String)this.getView().getFormShowParameter().getCustomParam("isdeletesubentry"))); + if (!isimport) { + int parentRowIndex = changeData.getParentRowIndex(); + EntryGrid treeEntry = (EntryGrid)this.getView().getControl("treeentryentity"); + int[] selectrows = treeEntry.getSelectRows(); + if (parentRowIndex >= 0) { + DynamicObject treeEntryRowObj = this.getModel().getEntryRowEntity("treeentryentity", parentRowIndex); + DynamicObjectCollection subentryentity = treeEntryRowObj.getDynamicObjectCollection("subentryentity"); + BigDecimal pdAmount = (BigDecimal)subentryentity.stream().map((o) -> { + return o.getBigDecimal("amount"); + }).reduce(BigDecimal.ZERO, BigDecimal::add); + BigDecimal totalPdAmount = (BigDecimal)this.getModel().getValue("totalpdamount"); + BigDecimal pdpercent = BigDecimal.ZERO; + if (BigDecimal.ZERO.compareTo(totalPdAmount) != 0) { + pdpercent = pdAmount.divide(totalPdAmount, 10, 4).multiply(BigDecimal.valueOf(100L)); + } + + treeEntryRowObj.set("pdpercent", pdpercent); + this.getView().updateView("treeentryentity"); + this.getModel().setValue("pdamount", pdAmount, parentRowIndex); + this.refershTreeEnable(); + if (selectrows.length > 0) { + treeEntry.selectRows(selectrows[0]); + } + } + + this.setsubEntryColor(); + this.setSubEntrySumAmount(); + } + } + + protected void qtyChanged(Object newValue, int rowIndex) { + BigDecimal newQty = (BigDecimal)newValue; + newQty = newQty == null ? BigDecimal.ZERO : newQty; + BigDecimal price = (BigDecimal)this.getModel().getValue("price", rowIndex); + this.getModel().setValue("amount", newQty.multiply(price), rowIndex); + } + + protected void priceChanged(Object newValue, int rowIndex) { + BigDecimal newPrice = (BigDecimal)newValue; + newPrice = newPrice == null ? BigDecimal.ZERO : newPrice; + BigDecimal qty = (BigDecimal)this.getModel().getValue("qty", rowIndex); + this.getModel().setValue("amount", newPrice.multiply(qty), rowIndex); + } + + protected void resourceItemChanged(Object newValue, int rowIndex) { + if (newValue != null) { + DynamicObject resourceItem = (DynamicObject)newValue; + String costType = CostTypeUtils.getCostType(resourceItem); + this.getModel().setValue("costitem", costType, rowIndex); + } + + } + + protected void pdamountChanged(Object oldValue, Object newValue, int rowIndex) { + boolean isimport = "true".equals(TypeUtils.nullToString((String)this.getView().getFormShowParameter().getCustomParam("isimport"))); + boolean isdeletesubentry = "true".equals(TypeUtils.nullToString((String)this.getView().getFormShowParameter().getCustomParam("isdeletesubentry"))); + boolean isPdamountChange = "true".equals(TypeUtils.nullToString((String)this.getView().getFormShowParameter().getCustomParam("isPdamountChange"))); + if (!isimport && !isdeletesubentry && !isPdamountChange) { + this.getView().getFormShowParameter().setCustomParam("isPdamountChange", "true"); + DynamicObject row = this.getModel().getEntryRowEntity("treeentryentity", rowIndex); + BigDecimal pdTotalAmount = (BigDecimal)this.getModel().getValue("totalpdamount", rowIndex); + BigDecimal pdAmount = (BigDecimal)this.getModel().getValue("pdamount", rowIndex); + BigDecimal oldAmount; + if (BigDecimal.ZERO.compareTo(pdTotalAmount) != 0) { + oldAmount = pdAmount.divide(pdTotalAmount, 10, 4).multiply(BigDecimal.valueOf(100L)); + row.set("pdpercent", oldAmount); + this.getModel().updateCache(); + this.getView().updateView("treeentryentity"); + } + + if (row.get("pid") != null) { + oldAmount = new BigDecimal(oldValue == null ? "0" : oldValue.toString()); + BigDecimal newAmount = new BigDecimal(newValue == null ? "0" : newValue.toString()); + String parentId = row.get("pid").toString(); + this.setParentAmount("treeentryentity", "pdamount", rowIndex, parentId, oldAmount, newAmount); + Map mapSum = this.sumTable("treeentryentity", new String[]{"pdamount"}); + this.getModel().setValue("totalamount", EcNumberHelper.toBigDecimal(mapSum.get("pdamount"))); + } + + this.getView().updateView("totalamount"); + this.refershTreeEnable(); + this.setSumToRow("treeentryentity", new String[]{"oldamount", "pdamount", "totalpdamount"}); + this.getView().getFormShowParameter().setCustomParam("isPdamountChange", "false"); + } + } + + protected void fillProCbsTreeList(DynamicObjectCollection oldProcbsEntryCol) { + DynamicObjectCollection curProCbsentryCol = this.getModel().getEntryEntity("treeentryentity"); + curProCbsentryCol.clear(); + DynamicObjectType cbsProEntryDt = curProCbsentryCol.getDynamicObjectType(); + ORM orm = ORM.create(); + Map idMap = new HashMap(16); + Iterator var6 = oldProcbsEntryCol.iterator(); + + DynamicObject newProcbsEntryInfo; + while(var6.hasNext()) { + DynamicObject oldProcbsEntryInfo = (DynamicObject)var6.next(); + newProcbsEntryInfo = new DynamicObject(cbsProEntryDt); + long oldId = oldProcbsEntryInfo.getLong("id"); + long newId = orm.genLongId(cbsProEntryDt); + newProcbsEntryInfo.set("id", newId); + idMap.put(oldId, newId); + DynamicObjectCollection newSubEntryCol = newProcbsEntryInfo.getDynamicObjectCollection("subentryentity"); + this.setProcbsEntryInfo(newProcbsEntryInfo, oldProcbsEntryInfo, idMap); + DynamicObjectCollection oldSubEntryCol = oldProcbsEntryInfo.getDynamicObjectCollection("subentryentity"); + if (!oldSubEntryCol.isEmpty()) { + Iterator var15 = oldSubEntryCol.iterator(); + + while(var15.hasNext()) { + DynamicObject oldSubEntryInfo = (DynamicObject)var15.next(); + DynamicObject newSubEntryInfo = new DynamicObject(newSubEntryCol.getDynamicObjectType()); + this.setSubEntryInfo(newSubEntryInfo, oldSubEntryInfo); + newSubEntryCol.add(newSubEntryInfo); + } + } + + newProcbsEntryInfo.set("subentryentity", newSubEntryCol); + BigDecimal subTotalpdAmount = BigDecimal.ZERO; + if (!newProcbsEntryInfo.getBoolean("isgua") && newProcbsEntryInfo.getBoolean("isleaf")) { + subTotalpdAmount = newProcbsEntryInfo.getBigDecimal("totalpdamount"); + } else if (!newSubEntryCol.isEmpty()) { + subTotalpdAmount = BigDecimal.valueOf((Double)newSubEntryCol.stream().collect(Collectors.summingDouble((subEntryObj) -> { + BigDecimal subPdamount = subEntryObj.getBigDecimal("amount"); + return subPdamount != null && BigDecimal.ZERO.compareTo(subPdamount) != 0 ? subPdamount.doubleValue() : 0.0; + }))); + } + + newProcbsEntryInfo.set("pdamount", subTotalpdAmount); + newProcbsEntryInfo.set("pdpercent", BigDecimal.valueOf(100L)); + curProCbsentryCol.add(newProcbsEntryInfo); + } + + this.getModel().updateEntryCache(curProCbsentryCol); + this.getView().updateView("treeentryentity"); + int rowCount = this.getModel().getEntryRowCount("treeentryentity"); + + for(int i = 0; i < rowCount; ++i) { + newProcbsEntryInfo = this.getModel().getEntryRowEntity("treeentryentity", i); + String parentId = newProcbsEntryInfo.get("pid").toString(); + BigDecimal pdAmount = (BigDecimal)this.getModel().getValue("pdamount", i); + this.setParentAmount("treeentryentity", "pdamount", i, parentId, BigDecimal.ZERO, pdAmount); + } + + TreeEntryGrid treeEntry = (TreeEntryGrid)this.getControl("treeentryentity"); + treeEntry.setCollapse(false); + this.setSumToRow("treeentryentity", new String[]{"oldamount", "pdamount", "totalpdamount"}); + Map mapSum = this.sumTable("treeentryentity", new String[]{"pdamount"}); + this.getModel().setValue("totalamount", EcNumberHelper.toBigDecimal(mapSum.get("pdamount"))); + } + + protected void setSubEntryInfo(DynamicObject newSubEntryInfo, DynamicObject oldSubEntryInfo) { + newSubEntryInfo.set("resourceitem", oldSubEntryInfo.get("resourceitem")); + newSubEntryInfo.set("measureunit", oldSubEntryInfo.get("measureunit")); + newSubEntryInfo.set("qty", oldSubEntryInfo.get("qty")); + newSubEntryInfo.set("price", oldSubEntryInfo.get("price")); + newSubEntryInfo.set("amount", oldSubEntryInfo.get("amount")); + newSubEntryInfo.set("originalamt", oldSubEntryInfo.get("amount")); + newSubEntryInfo.set("cbsre", oldSubEntryInfo.get("cbsre")); + newSubEntryInfo.set("costaccount", oldSubEntryInfo.get("costaccount")); + newSubEntryInfo.set("projectboq", oldSubEntryInfo.get("projectboq")); + newSubEntryInfo.set("costitem", oldSubEntryInfo.get("costitem")); + } + + protected void setProcbsEntryInfo(DynamicObject newProcbsEntryInfo, DynamicObject oldProcbsEntryInfo, Map idMap) { + newProcbsEntryInfo.set("cbs", oldProcbsEntryInfo.getDynamicObject("cbs")); + newProcbsEntryInfo.set("totalpdamount", oldProcbsEntryInfo.get("pdamount")); + newProcbsEntryInfo.set("isgua", oldProcbsEntryInfo.get("isgua")); + newProcbsEntryInfo.set("isleaf", oldProcbsEntryInfo.get("isleaf")); + Long oldPid = oldProcbsEntryInfo.getLong("pid"); + if (idMap.get(oldPid) != null) { + newProcbsEntryInfo.set("pid", idMap.get(oldPid)); + } + + } + + protected void setSubEntrySumAmount() { + SubEntryGrid subentryGrid = (SubEntryGrid)this.getView().getControl("subentryentity"); + int rowcount = this.getModel().getEntryRowCount("subentryentity"); + BigDecimal totalSubAmount = BigDecimal.ZERO; + + for(int i = 0; i < rowcount; ++i) { + BigDecimal subEntryAmount = (BigDecimal)this.getModel().getValue("amount", i); + totalSubAmount = EcNumberHelper.add(totalSubAmount, subEntryAmount); + } + + Map floatButtomData = new HashMap(16); + DynamicObject currency = this.getModel().getDataEntity().getDynamicObject("currency"); + floatButtomData.put("amount", CurrencyFormatUtil.getAfterFormatString(currency, totalSubAmount)); + subentryGrid.setFloatButtomData(floatButtomData); + this.setSumToRow("treeentryentity", new String[]{"oldamount", "pdamount", "totalpdamount"}); + } + + protected void setSumToRow(String tbl, String[] cols) { + if (null != tbl && !"".equals(tbl)) { + EntryGrid treeEntry = (EntryGrid)this.getView().getControl(tbl); + Map floatButtomData = new HashMap(16); + treeEntry.setFloatButtomData(floatButtomData); + + for(int i = 0; i < cols.length; ++i) { +// floatButtomData.put(cols[i], (Object)null);//已被下面二开替代 + floatButtomData.put(cols[i], (String) null); + } + + Map mapSum = this.sumTable(tbl, cols); + Set setKey = mapSum.keySet(); + Iterator iter = setKey.iterator(); + + while(iter.hasNext()) { + String str = (String)iter.next(); + DynamicObject currency = this.getModel().getDataEntity().getDynamicObject("currency"); + floatButtomData.put(str, CurrencyFormatUtil.getAfterFormatString(currency, mapSum.get(str))); + } + + treeEntry.setFloatButtomData(floatButtomData); + } + } + + protected Map sumTable(String tbl, String[] cols) { + Map mapSum = new HashMap(); + if (tbl != null && !"".equals(tbl)) { + int tblLength = this.getModel().getEntryRowCount(tbl); + int colLength = cols.length; + + for(int i = 0; i < tblLength; ++i) { + DynamicObject row = this.getModel().getEntryRowEntity(tbl, i); + if (row.get("isleaf") != null && Boolean.valueOf(row.get("isleaf").toString())) { + for(int j = 0; j < colLength; ++j) { + if (row.get(cols[j]) != null) { + Object obj = EcNumberHelper.toBigDecimal(mapSum.get(cols[j])); + Object dec = EcNumberHelper.toBigDecimal(row.get(cols[j])); + mapSum.put(cols[j], EcNumberHelper.add(obj, dec)); + } + } + } + } + + return mapSum; + } else { + mapSum.clear(); + return mapSum; + } + } + + public void beforeDoOperation(BeforeDoOperationEventArgs beforedooperationeventargs) { + super.beforeDoOperation(beforedooperationeventargs); + FormOperate formOperate = (FormOperate)beforedooperationeventargs.getSource(); + switch (formOperate.getOperateKey()) { + case "newsubentry": + this.doNewSubEntry(beforedooperationeventargs); + break; + case "deletesubentry": + this.doDeleteSubentry(); + break; + case "new": + case "submitandnew": + DynamicObject project = (DynamicObject)this.getModel().getValue("project"); + if (project != null) { + this.getView().getFormShowParameter().setCustomParam("projectId", project.getPkValue()); + } + break; + case "save": + case "submit": + this.doBeforeSaveAndSubmit(beforedooperationeventargs); +// if ("submit".equals(key) && !this.checkIsSameVersion()) {//已被下面二开替代 + if ("submit".equals(formOperate.getOperateKey()) && !this.checkIsSameVersion()) { + this.getView().showConfirm(ResManager.loadKDString("当前项目(单位工程)的总体预算版本跟最新版本不一致,是否更新?", "PeriodAimcostcbsbillEditPlugin_5", "ec-ecco-formplugin", new Object[0]), MessageBoxOptions.OKCancel, new ConfirmCallBackListener("version_callback")); + beforedooperationeventargs.setCancel(true); + } + } + + } + + protected boolean checkIsSameVersion() { + BigDecimal aimcostversion = (BigDecimal)this.getModel().getValue("aimcostversion"); + DynamicObject aimCostCbs = this.getEnabledTotalAimCost(); + if (aimCostCbs != null) { + BigDecimal newestAimCostVersion = aimCostCbs.getBigDecimal("versionno"); + return newestAimCostVersion.compareTo(aimcostversion) == 0; + } else { + return true; + } + } + + protected void doNewSubEntry(BeforeDoOperationEventArgs beforedooperationeventargs) { + TreeEntryGrid grid = (TreeEntryGrid)this.getControl("treeentryentity"); + int[] selectrow = grid.getSelectRows(); + if (selectrow.length > 0) { + boolean isdelete = "true".equals(TypeUtils.nullToString(this.getModel().getValue("isdelete", selectrow[0]))); + if (isdelete) { + this.getView().showTipNotification(ResManager.loadKDString("已删除行无法进行新增行操作,请先添加。", "PeriodAimcostcbsbillEditPlugin_6", "ec-ecco-formplugin", new Object[0])); + beforedooperationeventargs.setCancel(true); + } else if (!"true".equals(TypeUtils.nullToString(this.getModel().getValue("isleaf", selectrow[0])))) { + this.getView().showTipNotification(ResManager.loadKDString("请在成本分解结构明细节点下进行新增行操作。", "PeriodAimcostcbsbillEditPlugin_7", "ec-ecco-formplugin", new Object[0])); + beforedooperationeventargs.setCancel(true); + } + } else { + this.getView().showTipNotification(ResManager.loadKDString("请在成本分解结构明细节点下进行新增行操作", "PeriodAimcostcbsbillEditPlugin_8", "ec-ecco-formplugin", new Object[0])); + beforedooperationeventargs.setCancel(true); + } + + } + + protected void doBeforeSaveAndSubmit(BeforeDoOperationEventArgs beforedooperationeventargs) { + String number = TypeUtils.nullToString(this.getModel().getValue("billno")); + if ("".equals(number.trim())) { + this.getView().showTipNotification(ResManager.loadKDString("编码不能为空。", "PeriodAimcostcbsbillEditPlugin_9", "ec-ecco-formplugin", new Object[0])); + beforedooperationeventargs.setCancel(true); + } else { + DynamicObject period = (DynamicObject)this.getModel().getValue("period"); + if (period == null) { + this.getView().showTipNotification(ResManager.loadKDString("期间不能为空。", "PeriodAimcostcbsbillEditPlugin_10", "ec-ecco-formplugin", new Object[0])); + beforedooperationeventargs.setCancel(true); + } else { + DynamicObject project = (DynamicObject)this.getModel().getValue("project"); + boolean editOnUnit = (Boolean)this.getModel().getValue("editonunit"); + DynamicObject unitProject = (DynamicObject)this.getModel().getValue("unitproject"); + if (editOnUnit && unitProject == null) { + this.getView().showTipNotification(ResManager.loadKDString("请填写“单位工程”字段。", "PeriodAimcostcbsbillEditPlugin_0", "ec-ecco-formplugin", new Object[0])); + beforedooperationeventargs.setCancel(true); + } else if (!editOnUnit && project == null) { + this.getView().showTipNotification(ResManager.loadKDString("请填写“项目”字段。", "PeriodAimcostcbsbillEditPlugin_11", "ec-ecco-formplugin", new Object[0])); + beforedooperationeventargs.setCancel(true); + } else { + Object id = this.getModel().getDataEntity().getPkValue(); + QFilter filter = new QFilter("project", "=", project.getPkValue()); + if (id != null && TypeUtils.nullToInt(id) != 0) { + filter.and(new QFilter(BaseConstant.ID_ENTITY_PK, "!=", id)); + } + + if (editOnUnit) { + filter.and(new QFilter("unitproject", "=", unitProject.getPkValue())); + } + + filter.and(new QFilter("period", "=", period.getPkValue())); + filter.and(new QFilter("versionno", "=", this.getModel().getValue("versionno"))); + boolean exists = QueryServiceHelper.exists("ecco_periodcostbillcbs", new QFilter[]{filter}); + if (exists) { + this.getView().showTipNotification(ResManager.loadKDString("本项目(单位工程)在本期间已编制预算,如需修改,请使用调整功能。", "PeriodAimcostcbsbillEditPlugin_12", "ec-ecco-formplugin", new Object[0])); + beforedooperationeventargs.setCancel(true); + } + + List graySubEntryIds = (List)EcSerializeHelper.unserialize(this.getPageCache().get("subentry_grayids")); + if (graySubEntryIds != null && !graySubEntryIds.isEmpty()) { + DynamicObjectCollection entryEntity = this.getModel().getEntryEntity("treeentryentity"); + int entryRow = 0; + + for(Iterator var13 = entryEntity.iterator(); var13.hasNext(); ++entryRow) { + DynamicObject entry = (DynamicObject)var13.next(); + Iterator var15 = entry.getDynamicObjectCollection("subentryentity").iterator(); + + while(var15.hasNext()) { + DynamicObject subEntry = (DynamicObject)var15.next(); + if (!graySubEntryIds.contains(subEntry.getPkValue())) { + boolean isCancel = false; + StringBuilder errorMessage = new StringBuilder(String.format(ResManager.loadKDString("请填写第%s行项目CBS对应预算成本清单分录的非灰色行。", "PeriodAimcostcbsbillEditPlugin_13", "ec-ecco-formplugin", new Object[0]), entryRow + 1)); + BigDecimal amount = subEntry.getBigDecimal("amount"); + BigDecimal price = subEntry.getBigDecimal("price"); + BigDecimal qty = subEntry.getBigDecimal("qty"); + if (price.compareTo(BigDecimal.ZERO) == 0) { + errorMessage.append(ResManager.loadKDString("“单价”", "PeriodAimcostcbsbillEditPlugin_14", "ec-ecco-formplugin", new Object[0])); + isCancel = true; + } + + if (qty.compareTo(BigDecimal.ZERO) == 0) { + errorMessage.append(ResManager.loadKDString("“数量”", "PeriodAimcostcbsbillEditPlugin_15", "ec-ecco-formplugin", new Object[0])); + isCancel = true; + } + + if (amount.compareTo(BigDecimal.ZERO) == 0) { + errorMessage.append(ResManager.loadKDString("“金额”", "PeriodAimcostcbsbillEditPlugin_16", "ec-ecco-formplugin", new Object[0])); + isCancel = true; + } + + errorMessage.append(ResManager.loadKDString("字段!", "PeriodAimcostcbsbillEditPlugin_17", "ec-ecco-formplugin", new Object[0])); + if (isCancel) { + beforedooperationeventargs.setCancel(true); + this.getView().showMessage(errorMessage.toString()); + return; + } + } + } + } + } + + } + } + } + } + + protected void doDeleteSubentry() { + List graySubEntryIds = (List)EcSerializeHelper.unserialize(this.getPageCache().get("subentry_grayids")); + if (graySubEntryIds == null) { + graySubEntryIds = new ArrayList(10); + } + + SubEntryGrid subentryGrid = (SubEntryGrid)this.getView().getControl("subentryentity"); + int[] selectrows = subentryGrid.getSelectRows(); + if (selectrows.length > 0) { + int i; + if (this.isAdjust()) { + this.getView().getFormShowParameter().setCustomParam("isdeletesubentry", "true"); + List shijideleterows = new ArrayList(10); + BigDecimal subAmount = EcNumberHelper.ZERO; + + for(i = 0; i < selectrows.length; ++i) { + if (this.getModel().getValue("amount", selectrows[i]) != null) { + subAmount = EcNumberHelper.add(subAmount, this.getModel().getValue("amount", selectrows[i])); + } + + if (this.getModel().getValue("oldentryid", selectrows[i]) != null && !"0".equals(TypeUtils.nullToString(this.getModel().getValue("oldentryid", selectrows[i])))) { + this.getModel().setValue("price", EcNumberHelper.ZERO, selectrows[i]); + this.getModel().setValue("qty", EcNumberHelper.ZERO, selectrows[i]); + this.getModel().setValue("amount", EcNumberHelper.ZERO, selectrows[i]); + ((List)graySubEntryIds).add(this.getModel().getEntryRowEntity("subentryentity", selectrows[i]).getPkValue()); + } else { + shijideleterows.add(selectrows[i]); + } + } + + this.getView().updateView("subentryentity"); + int[] deleteRows = new int[shijideleterows.size()]; + + for(int j = shijideleterows.size() - 1; j >= 0; --j) { + deleteRows[j] = (Integer)shijideleterows.get(j); + } + + this.getModel().deleteEntryRows("subentryentity", deleteRows); + this.getView().updateView("subentryentity"); + this.setsubEntryColor(); + EntryGrid treeEntry = (EntryGrid)this.getView().getControl("treeentryentity"); + int entryCurrentRowIndex = this.getModel().getEntryCurrentRowIndex("treeentryentity"); + this.getView().updateView("treeentryentity"); + BigDecimal cbsOldAmount = EcNumberHelper.toBigDecimal(this.getModel().getValue("pdamount", entryCurrentRowIndex)); + BigDecimal totalPdAmount = EcNumberHelper.toBigDecimal(this.getModel().getValue("totalpdamount", entryCurrentRowIndex)); + BigDecimal newPdamount = EcNumberHelper.subtract(cbsOldAmount, subAmount); + this.getModel().setValue("pdamount", newPdamount, entryCurrentRowIndex); + this.getModel().setValue("pdpercent", newPdamount.divide(totalPdAmount, 10, 4).multiply(BigDecimal.valueOf(100L)), entryCurrentRowIndex); + DynamicObject row = this.getModel().getEntryRowEntity("treeentryentity", entryCurrentRowIndex); + String parentId = TypeUtils.nullToString(row.get("pid")); + if (!"".equals(parentId) && !"0".equals(parentId)) { + this.setParentAmount("treeentryentity", "pdamount", entryCurrentRowIndex, parentId, cbsOldAmount, EcNumberHelper.subtract(cbsOldAmount, subAmount)); + Map mapSum = this.sumTable("treeentryentity", new String[]{"pdamount"}); + this.getModel().setValue("totalamount", EcNumberHelper.toBigDecimal(mapSum.get("pdamount"))); + } + + this.getView().updateView("treeentryentity"); + this.refershTreeEnable(); + treeEntry.selectRows(entryCurrentRowIndex); + this.getView().getFormShowParameter().setCustomParam("isdeletesubentry", "false"); + } else { + BigDecimal subAmount = EcNumberHelper.ZERO; + +// for(int i = 0; i < selectrows.length; ++i) { +// if (this.getModel().getValue("amount", selectrows[i]) != null) { +// subAmount = EcNumberHelper.add(subAmount, this.getModel().getValue("amount", selectrows[i])); +// } +// }//已被下面二开替代 + for (int selectrow : selectrows) { + if (this.getModel().getValue("amount", selectrow) != null) { + subAmount = EcNumberHelper.add(subAmount, this.getModel().getValue("amount", selectrow)); + } + } + + EntryGrid treeEntry = (EntryGrid)this.getView().getControl("treeentryentity"); + i = this.getModel().getEntryCurrentRowIndex("treeentryentity"); + BigDecimal cbsOldAmount = EcNumberHelper.toBigDecimal(this.getModel().getValue("pdamount", i)); + this.getModel().setValue("pdamount", EcNumberHelper.subtract(cbsOldAmount, subAmount), i); + this.getView().updateView("treeentryentity"); + this.refershTreeEnable(); + treeEntry.selectRows(i); + this.getModel().deleteEntryRows("subentryentity", selectrows); + } + } + + } + + public void upload(UploadEvent evt) { +// super.upload(evt);//二开注释掉的 + String key = ((Control)evt.getSource()).getKey(); + Object[] urls = evt.getUrls(); + String url = (String)((Map)urls[0]).get("url"); + if (StringUtils.equals(key, "uploadcbs")) { + AimCostCbsPoiHelper.importCbsAndResources(this.getView(), url); + Map mapSum = this.sumTable("treeentryentity", new String[]{"pdamount"}); + this.getModel().setValue("totalamount", EcNumberHelper.toBigDecimal(mapSum.get("pdamount"))); + this.setSumToRow("treeentryentity", new String[]{"oldamount", "pdamount", "totalpdamount"}); + this.updatePdPercent(); + if (this.isAdjust()) { + this.refershTreeEnable(); + this.setsubEntryColor(); + } + } + + } + + protected void updatePdPercent() { + DynamicObjectCollection entryEntity = this.getModel().getEntryEntity("treeentryentity"); + + DynamicObject entry; + BigDecimal percent; + for(Iterator var2 = entryEntity.iterator(); var2.hasNext(); entry.set("pdpercent", percent)) { + entry = (DynamicObject)var2.next(); + percent = BigDecimal.valueOf(100L); + BigDecimal pdAmount = this.getDefaultZeroBigDecimal(entry.getBigDecimal("pdamount")); + BigDecimal totalPdAmount = this.getDefaultZeroBigDecimal(entry.getBigDecimal("totalpdamount")); + if (totalPdAmount.compareTo(BigDecimal.ZERO) != 0) { + percent = pdAmount.divide(totalPdAmount, 10, 4).multiply(BigDecimal.valueOf(100L)); + } + } + + this.getModel().updateEntryCache(entryEntity); + this.getView().updateView("treeentryentity"); + } + + protected BigDecimal getDefaultZeroBigDecimal(BigDecimal value) { + return value == null ? BigDecimal.ZERO : value; + } + + public void afterDoOperation(AfterDoOperationEventArgs afterDoOperationEventArgs) { + super.afterDoOperation(afterDoOperationEventArgs); + FormOperate formOperate = (FormOperate)afterDoOperationEventArgs.getSource(); + switch (formOperate.getOperateKey()) { + case "newsubentry": + this.doAfterNewSubEntry(); + break; + case "deletesubentry": + this.doAfterDeleteSubEntry(); + break; + case "batchsetting": + this.doBatchSetting(); + break; + case "exportcbs": + AimCostCbsPoiHelper.exportCbsAndResources(this.getView()); + break; + case "importcbs": + this.doImportCbs(); + break; + case "expandall": + this.doFoldAll(false); + break; + case "foldall": + this.doFoldAll(true); + break; + case "submit": + this.getView().setEnable(false, new String[]{"advconbaritemap2"}); + case "unsubmit": + this.getView().setEnable(true, new String[]{"advconbaritemap2"}); + } + + } + + protected void doFoldAll(boolean isFold) { + TreeEntryGrid treeGrid = (TreeEntryGrid)this.getControl("treeentryentity"); + treeGrid.setCollapse(isFold); + } + + protected void doImportCbs() { + Object project = this.getModel().getValue("project"); + Object unitProject = this.getModel().getValue("unitproject"); + boolean editOnUnit = (Boolean)this.getModel().getValue("editonunit"); + if (project == null) { + this.getView().showTipNotification(ResManager.loadKDString("请先选择项目。", "PeriodAimcostcbsbillEditPlugin_18", "ec-ecco-formplugin", new Object[0]), 3000); + } else if (editOnUnit && unitProject == null) { + this.getView().showTipNotification(ResManager.loadKDString("请先选择单位工程。", "PeriodAimcostcbsbillEditPlugin_19", "ec-ecco-formplugin", new Object[0]), 3000); + } else { + this.openImportDialog(); + } + + } + + protected void openImportDialog() { + UploadOption uo = new UploadOption(); + uo.setTitle(ResManager.loadKDString("导入CBS", "PeriodAimcostcbsbillEditPlugin_20", "ec-ecco-formplugin", new Object[0])); + uo.setSuffix(".xls"); + this.getView().showUpload(uo, "uploadcbs"); + } + + protected void doAfterNewSubEntry() { + ORM orm = ORM.create(); + TreeEntryGrid grid = (TreeEntryGrid)this.getControl("treeentryentity"); + int[] selectrow = grid.getSelectRows(); + if (selectrow.length > 0) { + boolean isGua = "true".equals(TypeUtils.nullToString(this.getModel().getValue("isgua", selectrow[0]))); + if (!isGua) { + this.getModel().setValue("isgua", true, selectrow[0]); + this.getModel().setValue("pdamount", 0, selectrow[0]); + SubEntryGrid subentryGrid = (SubEntryGrid)this.getView().getControl("subentryentity"); + int[] subselectrows = subentryGrid.getSelectRows(); + if (subselectrows.length > 0) { + DynamicObject parentCBSInfo = (DynamicObject)this.getModel().getValue("cbs", selectrow[0]); + this.getModel().setValue("cbsre", parentCBSInfo, subselectrows[0]); + } + + this.getView().updateView("treeentryentity"); + this.refershTreeEnable(); + grid.selectRows(selectrow[0]); + } + } + + int rowcount = this.getModel().getEntryRowCount("subentryentity"); + + for(int i = 0; i < rowcount; ++i) { + DynamicObject subEntity = this.getModel().getEntryRowEntity("subentryentity", i); + if (subEntity.get("id") == null || subEntity.getLong("id") == 0L) { + subEntity.set("id", orm.genLongId(subEntity.getDataEntityType())); + } + } + + this.setSubEntrySumAmount(); + } + + protected void doAfterDeleteSubEntry() { + int subRowcount = this.getModel().getEntryRowCount("subentryentity"); + if (subRowcount == 0) { + TreeEntryGrid grid = (TreeEntryGrid)this.getControl("treeentryentity"); + int[] selectrow = grid.getSelectRows(); + if (selectrow.length > 0) { + this.getModel().setValue("isgua", false, selectrow[0]); + this.refershTreeEnable(); + grid.selectRows(selectrow[0]); + } + } + + this.setSubEntrySumAmount(); + } + + protected void doBatchSetting() { + TreeEntryGrid treeEntry = (TreeEntryGrid)this.getControl("treeentryentity"); + int[] selRows = treeEntry.getSelectRows(); + if (selRows.length <= 0) { + this.getView().showTipNotification(ResManager.loadKDString("请选择项目CBS。", "PeriodAimcostcbsbillEditPlugin_21", "ec-ecco-formplugin", new Object[0]), 3000); + } else { + Map paraMap = new HashMap(16); + paraMap.put("formId", "ecco_batchsetup"); + FormShowParameter param = FormShowParameter.createFormShowParameter(paraMap); + param.getOpenStyle().setShowType(ShowType.Modal); + param.setCloseCallBack(new CloseCallBack(this, "batchsetup")); + this.getView().showForm(param); + } + } + + public void confirmCallBack(MessageBoxClosedEvent messageBoxClosedEvent) { + super.confirmCallBack(messageBoxClosedEvent); + if (messageBoxClosedEvent.getCallBackId().equals("unitprojectchange_callback")) { + this.updateUnitProjectConfirm(messageBoxClosedEvent); + } else if ("version_callback".equals(messageBoxClosedEvent.getCallBackId()) && messageBoxClosedEvent.getResult().equals(MessageBoxResult.Yes)) { + this.reloadFromTotalAimCost(); + } + + } + + protected void updateUnitProjectConfirm(MessageBoxClosedEvent messageBoxClosedEvent) { + if (messageBoxClosedEvent.getResult().equals(MessageBoxResult.Yes)) { + this.reloadFromTotalAimCost(); + } else if (messageBoxClosedEvent.getResult().equals(MessageBoxResult.Cancel)) { + this.getView().getFormShowParameter().setCustomParam("isCancel", "true"); + String oldvalue = this.getPageCache().get("oldunitproject"); + this.getModel().setValue("unitproject", oldvalue.equals("0") ? null : oldvalue); + this.getView().updateView("unitproject"); + } + + } + + protected void setParentAmount(String table, String colname, int rowIndex, String parentId, BigDecimal oldAmount, BigDecimal newAmount) { + for(int i = rowIndex - 1; i >= 0; --i) { + String parent = this.getModel().getEntryRowEntity(table, i).get("id").toString(); + if (parent.equals(parentId)) { + if (oldAmount == null) { + oldAmount = EcConstant.ZERO; + } + + if (newAmount == null) { + newAmount = EcConstant.ZERO; + } + + BigDecimal parentOldAmount = EcNumberHelper.toBigDecimal(this.getModel().getEntryRowEntity(table, i).get(colname)); + BigDecimal parentNewAmount = null; + if (parentOldAmount == null) { + parentOldAmount = EcConstant.ZERO; + parentNewAmount = newAmount; + } else { + parentNewAmount = parentOldAmount.subtract(oldAmount).add(newAmount); + } + + DynamicObject treeEntryRowObj = this.getModel().getEntryRowEntity("treeentryentity", i); + treeEntryRowObj.set("pdamount", parentNewAmount); + BigDecimal rowTotalPdAmount = (BigDecimal)this.getModel().getValue("totalpdamount", i); + BigDecimal pdPercent = BigDecimal.ZERO; + if (BigDecimal.ZERO.compareTo(rowTotalPdAmount) != 0) { + pdPercent = parentNewAmount.divide(rowTotalPdAmount, 10, 4).multiply(BigDecimal.valueOf(100L)); + } + + DynamicObject treeRow = this.getModel().getEntryRowEntity("treeentryentity", i); + treeRow.set("pdpercent", pdPercent); + this.getView().updateView("treeentryentity"); + if (treeEntryRowObj.getString("pid") != null) { + parentId = treeEntryRowObj.getString("pid"); + this.setParentAmount(table, "pdamount", i, parentId, parentOldAmount, parentNewAmount); + } + break; + } + } + + } +}