diff --git a/code/zcdev/zcgj-zcdev-zcdev-pr/src/main/java/zcgj/zcdev/zcdev/pr/plugin/form/AimcostcbsbillEditUIExt.java b/code/zcdev/zcgj-zcdev-zcdev-pr/src/main/java/zcgj/zcdev/zcdev/pr/plugin/form/AimcostcbsbillEditUIExt.java new file mode 100644 index 0000000..c893ce3 --- /dev/null +++ b/code/zcdev/zcgj-zcdev-zcdev-pr/src/main/java/zcgj/zcdev/zcdev/pr/plugin/form/AimcostcbsbillEditUIExt.java @@ -0,0 +1,1152 @@ +package zcgj.zcdev.zcdev.pr.plugin.form; + +import java.math.BigDecimal; +import java.util.ArrayList; +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 kd.bos.bill.OperationStatus; +import kd.bos.dataentity.entity.DynamicObject; +import kd.bos.dataentity.entity.DynamicObjectCollection; +import kd.bos.dataentity.resource.ResManager; +import kd.bos.dataentity.utils.StringUtils; +import kd.bos.entity.EntityMetadataCache; +import kd.bos.entity.MainEntityType; +import kd.bos.entity.datamodel.IDataModel; +import kd.bos.entity.datamodel.RowDataEntity; +import kd.bos.entity.datamodel.events.AfterAddRowEventArgs; +import kd.bos.entity.datamodel.events.ChangeData; +import kd.bos.entity.datamodel.events.PropertyChangedArgs; +import kd.bos.form.FormShowParameter; +import kd.bos.form.MessageBoxResult; +import kd.bos.form.ShowType; +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.events.AfterDoOperationEventArgs; +import kd.bos.form.events.BeforeDoOperationEventArgs; +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.ec.basedata.business.model.ecco.BaseConstant; +import kd.ec.basedata.business.utils.EcCommonUtils; +import kd.ec.basedata.common.enums.BillStatusEnum; +import kd.ec.basedata.common.enums.PayDirectionEnum; +import kd.ec.basedata.common.hierarchy.DynamicObjectTreeNode; +import kd.ec.basedata.common.utils.CBSBudgetUtil; +import kd.ec.basedata.common.utils.CurrencyHelper; +import kd.ec.basedata.common.utils.EcNumberHelper; +import kd.ec.basedata.common.utils.EcSerializeHelper; +import kd.ec.basedata.common.utils.TypeUtils; +import kd.ec.cost.formplugin.AbstractEccoBillPlugin; +import kd.ec.cost.utils.CostTypeUtils; +import kd.ec.cost.utils.CurrencyFormatUtil; + +public class AimcostcbsbillEditUIExt extends AbstractEccoBillPlugin implements BeforeF7SelectListener, RowClickEventListener { + private static final String IS_CANCEL = "isCancel"; + private static final String EDITONUNIT = "editonunit"; + private static final String NUMBER = "number"; + private static final String ISDELETE = "isdelete"; + private static final String UNITPROJECTCHANGE_CALLBACK = "unitprojectchange_callback"; + private static final String SHOWLOCATION = "showlocation"; + private static final String PROJECT_ID = "projectId"; + private static final String SUBENTRY_GRAYIDS = "subentry_grayids"; + private static final String ISLEAF = "isleaf"; + private static final String ISIMPORT = "isimport"; + private static final String IS_PDAMOUNT_CHANGE = "isPdamountChange"; + private static final String TRUE = "true"; + private static final String ISDELETESUBENTRY = "isdeletesubentry"; + private static final String ID_NAME_NUMBER_LONGNUMBER_LEVEL_PARENT_ISLEAF = "id,name,number,longnumber,level,parent,isleaf,resourcehook"; + private static final String LOCATIONTREE = "locationtree"; + 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 static final String FIACCOUNTORG = "fiaccountorg"; + private double versionNum = 1.0; + + public AimcostcbsbillEditUIExt() { + } + + 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); + } + + public void entryRowClick(RowClickEvent 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(BigDecimal.ZERO) == 0 && price.compareTo(BigDecimal.ZERO) == 0 && qty.compareTo(BigDecimal.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}); + } + } + + this.getView().updateView("subentryentity"); + } + + } + + public void beforeF7Select(BeforeF7SelectEvent beforef7selectevent) { + String name = beforef7selectevent.getProperty().getName(); + if ("unitproject".equals(name)) { + this.beforeUnitProjectSelected(beforef7selectevent); + } else if ("projectboq".equals(name)) { + this.beforeBoqSelected(beforef7selectevent); + }/* else if ("project".equals(name)) { + this.beforeProjectSelected(beforef7selectevent); + }*/ + + } + + protected void beforeProjectSelected(BeforeF7SelectEvent ent) { + ListShowParameter parameter = (ListShowParameter)ent.getFormShowParameter(); + QFilter filter = new QFilter("id", "!=", this.getModel().getDataEntity().getPkValue()); + List projectIds = new ArrayList(); + DynamicObject[] aimcostbills = BusinessDataServiceHelper.load("ecco_aimcostbillcbs", "id,billno,billstatus,creator,modifier,auditor,auditdate,modifytime,createtime,org,treeentryentity.id,treeentryentity.pid,treeentryentity.isGroupNode,treeentryentity.cbs,treeentryentity.oldamount,treeentryentity.pdamount,treeentryentity.description,treeentryentity.isgua,treeentryentity.isleaf,treeentryentity.oldcbsentryid,treeentryentity.isdelete,name,project,unitproject,totalamount,remark,versionno,oldid,isenable,currency,editonunit,fiaccountorg,billhead_lk.id,billhead_lk.billhead_lk_stableid,billhead_lk.billhead_lk_sbillid,billhead_lk.billhead_lk_sid,beforeamt", new QFilter[]{filter}); + DynamicObject[] var6 = aimcostbills; + int var7 = aimcostbills.length; + + for(int var8 = 0; var8 < var7; ++var8) { + DynamicObject aimcostbill = var6[var8]; + DynamicObject project = aimcostbill.getDynamicObject("project"); + if (project != null && !project.getBoolean("editonunit")) { + projectIds.add((Long)project.getPkValue()); + } + } + + QFilter qFilter = new QFilter("id", "not in", projectIds); + parameter.getListFilterParameter().getQFilters().add(qFilter); + } + + protected void beforeBoqSelected(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("请填写“单位工程”字段。", "AimcostcbsbillEditUI_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"); + if (project != null) { + QFilter qFilter = new QFilter("parent", "=", project.getPkValue()); + List unitprojectIds = new ArrayList(); + QFilter filter = new QFilter("project", "=", project != null ? project.getPkValue() : 0L); + filter.and(new QFilter("id", "!=", this.getModel().getDataEntity().getPkValue())); + DynamicObject[] aimcostbills = BusinessDataServiceHelper.load("ecco_aimcostbillcbs", "id,billno,billstatus,creator,modifier,auditor,auditdate,modifytime,createtime,org,treeentryentity.id,treeentryentity.pid,treeentryentity.isGroupNode,treeentryentity.cbs,treeentryentity.oldamount,treeentryentity.pdamount,treeentryentity.description,treeentryentity.isgua,treeentryentity.isleaf,treeentryentity.oldcbsentryid,treeentryentity.isdelete,name,project,unitproject,totalamount,remark,versionno,oldid,isenable,currency,editonunit,fiaccountorg,billhead_lk.id,billhead_lk.billhead_lk_stableid,billhead_lk.billhead_lk_sbillid,billhead_lk.billhead_lk_sid,beforeamt", new QFilter[]{filter}); + DynamicObject[] var8 = aimcostbills; + int var9 = aimcostbills.length; + + for(int var10 = 0; var10 < var9; ++var10) { + DynamicObject aimcostbill = var8[var10]; + DynamicObject unitproject = aimcostbill.getDynamicObject("unitproject"); + unitprojectIds.add((Long)unitproject.getPkValue()); + } + + qFilter.and(new QFilter("id", "not in", unitprojectIds)); + parameter.getListFilterParameter().getQFilters().add(qFilter); + } + + parameter.setCaption(ResManager.loadKDString("单位工程/标段", "AimcostcbsbillEditUI_1", "ec-ecco-formplugin", new Object[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 arg0) { + super.afterCreateNewData(arg0); + ORM orm = ORM.create(); + FormShowParameter formShowParameter = this.getView().getFormShowParameter(); + DynamicObject project; + if (!this.isAdjust()) { + Object projectId = formShowParameter.getCustomParam("projectId"); + if (projectId != null) { + this.getModel().setValue("project", projectId); + project = BusinessDataServiceHelper.loadSingle("ec_project", "editonunit,fiaccountorg", new QFilter[]{new QFilter("id", "=", Long.valueOf(projectId.toString()))}); + if (project != null) { + this.getModel().setValue("editonunit", project.getBoolean("editonunit")); + this.getModel().setValue("fiaccountorg", project.get("fiaccountorg_id")); + BigDecimal allInContractAmt = this.getAllInContractAmt(Long.valueOf(projectId.toString())); + this.getModel().setValue("totalincontamt", allInContractAmt); + QFilter procbsfilter = new QFilter("project", "=", Long.valueOf(projectId.toString())); + procbsfilter.and(new QFilter("level", "=", 1)); + procbsfilter.and(new QFilter("enable", "=", "1")); + DynamicObject[] procbss = BusinessDataServiceHelper.load("ec_ecbd_pro_cbs", "id,name,number,longnumber,level,parent,isleaf,resourcehook", new QFilter[]{procbsfilter}, "number"); + if (procbss.length > 0) { + this.getModel().deleteEntryData("treeentryentity"); + this.getModel().updateCache(); + this.fillTreeList(this.getModel(), procbss, true, 0); + } + } + } + + this.getModel().setValue("creator", BusinessDataServiceHelper.loadSingle(UserServiceHelper.getCurrentUserId(), "bos_user")); + this.getModel().setValue("versionno", this.versionNum); + } else { + MainEntityType dt = EntityMetadataCache.getDataEntityType("ecco_aimcostbillcbs"); + project = BusinessDataServiceHelper.loadSingle(formShowParameter.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("org", project.get("org")); + project = project.getDynamicObject("project"); + if (project != null) { + BigDecimal allInContractAmt = this.getAllInContractAmt(project.getLong("id")); + this.getModel().setValue("totalincontamt", allInContractAmt); + } + + newInfo.set("unitproject", project.get("unitproject")); + newInfo.set("totalamount", project.get("totalamount")); + newInfo.set("remark", project.get("remark")); + newInfo.set("editonunit", project.get("editonunit")); + newInfo.set("fiaccountorg", project.get("fiaccountorg")); + this.versionNum = TypeUtils.string2Double(project.getString("versionno")) + 1.0; + newInfo.set("versionno", this.versionNum); + newInfo.set("currency", project.get("currency")); + this.getView().updateView("oldid"); + this.getView().updateView("billno"); + this.getView().updateView("name"); + this.getView().updateView("project"); + this.getView().updateView("unitproject"); + this.getView().updateView("totalamount"); + this.getView().updateView("remark"); + this.getView().updateView("org"); + this.getView().updateView("versionno"); + this.getView().updateView("currency"); + Map cbsEntryIdMap = new HashMap(); + Map idMap = new HashMap(16); + DynamicObjectCollection cbsEntryColl = (DynamicObjectCollection)project.get("treeentryentity"); + DynamicObjectCollection entryColl = new DynamicObjectCollection(EcCommonUtils.getEntryDynamicObjectType("ecco_aimcostbillcbs", "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()); + long entryId = orm.genLongId(EcCommonUtils.getEntryDynamicObjectType("ecco_aimcostbillcbs", "treeentryentity")); + newValue.set("id", entryId); + idMap.put(oldValue.getDynamicObject("cbs").getString("id"), String.valueOf(entryId)); + if (oldValue.get("pid") != null) { + newValue.set("pid", cbsEntryIdMap.get((Long)oldValue.get("pid"))); + } + + newValue.set("seq", seq++); + DynamicObject cbs = oldValue.getDynamicObject("cbs"); + newValue.set("cbs", 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", cbs == null ? oldValue.get("isleaf") : cbs.get("isleaf")); + newValue.set("oldcbsentryid", oldValue.getPkValue()); + cbsEntryIdMap.put((Long)oldValue.getPkValue(), (Long)newValue.getPkValue()); + DynamicObjectCollection oldResourceEntries = (DynamicObjectCollection)oldValue.get("subentryentity"); + if (!oldResourceEntries.isEmpty()) { + DynamicObjectCollection newResourceEntries = new DynamicObjectCollection(oldResourceEntries.getDynamicObjectType(), newValue); + int subseq = 0; + + for(int j = 0; j < oldResourceEntries.size(); ++j) { + DynamicObject oldreValue = (DynamicObject)oldResourceEntries.get(j); + if (oldreValue.getBigDecimal("amount").compareTo(BigDecimal.ZERO) != 0 || oldreValue.getBigDecimal("price").compareTo(BigDecimal.ZERO) != 0 || oldreValue.getBigDecimal("qty").compareTo(BigDecimal.ZERO) != 0) { + DynamicObject newreValue = new DynamicObject(oldreValue.getDynamicObjectType()); + newreValue.set("seq", subseq++); + newreValue.set("oldentryid", oldreValue.getPkValue()); + newreValue.set("id", orm.genLongId(oldResourceEntries.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("costitem", oldreValue.get("costitem")); + newreValue.set("reamrkre", oldreValue.get("reamrkre")); + newResourceEntries.add(newreValue); + } + } + + newValue.set("subentryentity", newResourceEntries); + } + + entryColl.add(newValue); + } + } + + newInfo.set("treeentryentity", entryColl); + this.adjustAddNewCbs(project, entryColl, idMap); + this.getView().setEnable(false, new String[]{"project"}); + this.getView().setEnable(false, new String[]{"editonunit"}); + this.getModel().updateEntryCache(entryColl); + this.getView().updateView("treeentryentity"); + } + + } + + protected void adjustAddNewCbs(DynamicObject project, DynamicObjectCollection entryColl, Map idMap) { + QFilter profilter = new QFilter("project", "=", project.getLong("id")); + profilter.and(new QFilter("enable", "=", "1")); + DynamicObject[] procbss = BusinessDataServiceHelper.load("ec_ecbd_pro_cbs", "id,name,number,longnumber,level,parent,isleaf,resourcehook", new QFilter[]{profilter}, "number"); + List newProCbsList = new ArrayList(); + DynamicObject[] var7 = procbss; + int i = procbss.length; + + for(int var9 = 0; var9 < i; ++var9) { + DynamicObject procbs = var7[var9]; + String procbsId = procbs.getString("id"); + i = 0; + + int entryCollSize; + for(entryCollSize = entryColl.size(); i < entryCollSize; ++i) { + DynamicObject entryCbsObj = ((DynamicObject)entryColl.get(i)).getDynamicObject("cbs"); + if (procbsId.equals(entryCbsObj.getString("id"))) { + break; + } + } + + if (i >= entryCollSize) { + newProCbsList.add(procbs); + } + } + + if (!newProCbsList.isEmpty()) { + ORM orm = ORM.create(); + + for(i = 0; i < newProCbsList.size(); ++i) { + DynamicObject newValue = new DynamicObject(entryColl.getDynamicObjectType()); + long treeEntryId = orm.genLongId(entryColl.getDynamicObjectType()); + DynamicObject newCbs = (DynamicObject)newProCbsList.get(i); + idMap.put(newCbs.getString("id"), String.valueOf(treeEntryId)); + newValue.set("cbs", newCbs); + boolean isleaf = newCbs.getBoolean("isleaf"); + newValue.set("id", treeEntryId); + newValue.set("isleaf", isleaf); + newValue.set("pid", 0); + newValue.set("isgua", newCbs.get("resourcehook")); + if (isleaf && newCbs.getDynamicObject("parent") != null) { + String parentCbsId = newCbs.getDynamicObject("parent").getString("id"); + if (idMap.get(parentCbsId) != null) { + newValue.set("pid", idMap.get(parentCbsId)); + } + } + + entryColl.add(newValue); + } + } + + } + + 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().setVisible(true, new String[]{"beforeamt"}); + this.getView().setEnable(false, new String[]{"org"}); + this.getView().updateView("treeentryentity"); + this.getView().updateView("subentryentity"); + if (OperationStatus.ADDNEW.equals(this.getView().getFormShowParameter().getStatus())) { + BigDecimal beforeAmt = (BigDecimal)this.getModel().getValue("totalamount"); + this.getModel().setValue("beforeamt", beforeAmt); + } + } 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().setVisible(false, new String[]{"beforeamt"}); + this.getView().updateView("treeentryentity"); + this.getView().updateView("subentryentity"); + } + + this.getView().setVisible(false, new String[]{"locationtree"}); + } + + public void afterBindData(EventObject eventobject) { + super.afterBindData(eventobject); + this.setUnitProjectMustinput(); + this.refershTreeEnable(); + this.setSumToRow("treeentryentity", new String[]{"oldamount", "pdamount"}); + this.setsubEntryColor(); + TreeEntryGrid treeEntry = (TreeEntryGrid)this.getView().getControl("treeentryentity"); + treeEntry.setCollapse(false); + } + + 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}); + } + } + } + + } + + protected void fillTreeList(IDataModel model, DynamicObject[] objs, boolean isRoot, int rowIndex) { + if (objs != null && objs.length != 0) { + for(int i = 0; i < objs.length; ++i) { +// int rIndex = false; + int rIndex; + if (isRoot) { + rIndex = model.createNewEntryRow("treeentryentity"); + } else { + rIndex = model.insertEntryRow("treeentryentity", rowIndex); + } + + TreeEntryGrid grid = (TreeEntryGrid)this.getView().getControl("treeentryentity"); + grid.getModel().updateCache(); + model.setValue("cbs", objs[i], rIndex); + model.setValue("isleaf", objs[i].get("isleaf"), rIndex); + model.setValue("isgua", objs[i].get("resourcehook"), rIndex); + QFilter parentId = new QFilter("parent.id", "=", objs[i].get("id")); + QFilter[] filters = new QFilter[]{parentId}; + DynamicObject[] subCbs = BusinessDataServiceHelper.load("ec_ecbd_pro_cbs", "id,name,number,longnumber,level,parent,isleaf,resourcehook", filters, "number"); + if (subCbs != null && subCbs.length > 0) { + this.fillTreeList(model, subCbs, false, rIndex); + } + } + + } + } + + 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("editonunit")) { + this.setUnitProjectMustinput(); + } else if ("fiaccountorg".equals(propName)) { + this.fiaccountOrgChanged(newValue); + } + + } + + 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 BigDecimal getAllInContractAmt(Long projectPk) { + DynamicObject[] contractBillCols = BusinessDataServiceHelper.load("ec_in_contract", "id,project,contstatus,totaloftaxamount,signamount,currency,stdcurrency,exchangedate", new QFilter[]{new QFilter("project", "=", projectPk), new QFilter("billstatus", "=", BillStatusEnum.AUDIT.getValue()), new QFilter("paydirection", "=", PayDirectionEnum.IN.getValue())}); + BigDecimal allInContAmount = BigDecimal.ZERO; + DynamicObject projectCurrencyObject = (DynamicObject)this.getModel().getValue("currency"); + Long projCurrency = 0L; + if (projectCurrencyObject != null) { + projCurrency = (Long)projectCurrencyObject.getPkValue(); + } + + for(int i = 0; i < contractBillCols.length; ++i) { + DynamicObject contractBill = contractBillCols[i]; + DynamicObject currency = (DynamicObject)contractBill.get("currency"); + DynamicObject stdCurrency = (DynamicObject)contractBill.get("stdcurrency"); + BigDecimal originaloftaxamount = contractBill.getBigDecimal("totaloftaxamount"); + BigDecimal signamount = contractBill.getBigDecimal("signamount"); + BigDecimal contAmount = null; + if (stdCurrency != null && stdCurrency.getPkValue().equals(projCurrency)) { + if (signamount.compareTo(BigDecimal.ZERO) > 0) { + contAmount = signamount; + } else { + contAmount = originaloftaxamount; + } + } else if (currency != null && projectCurrencyObject != null) { + DynamicObject org = (DynamicObject)this.getModel().getValue("org"); + BigDecimal rate = BigDecimal.ONE; + if (org != null) { + Long orgPk = org.getLong("id"); + DynamicObject rateTable = CurrencyHelper.getExRateTable(orgPk); + if (rateTable != null) { + rate = CurrencyHelper.getExChangeRate((Long)currency.getPkValue(), projCurrency, rateTable.getLong("id"), contractBill.getDate("exchangedate")); + } + } + + if (rate == null) { + rate = BigDecimal.ONE; + } + + contAmount = originaloftaxamount.multiply(rate); + } else { + contAmount = originaloftaxamount; + } + + allInContAmount = allInContAmount.add(contAmount == null ? BigDecimal.ZERO : contAmount); + } + + return allInContAmount; + } + + 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); + this.getModel().setValue("pdamount", pdAmount, parentRowIndex); + this.getView().updateView("treeentryentity"); + this.refershTreeEnable(); + if (selectrows.length > 0) { + treeEntry.selectRows(selectrows[0]); + } + } + + this.setsubEntryColor(); + this.setSubEntrySumAmount(); + } + } + + protected void qtyChanged(Object newValue, int rowIndex) { + BigDecimal qtynew = (BigDecimal)newValue; + qtynew = qtynew == null ? BigDecimal.ZERO : qtynew; + BigDecimal price = (BigDecimal)this.getModel().getValue("price", rowIndex); + this.getModel().setValue("amount", qtynew.multiply(price), rowIndex); + } + + protected void priceChanged(Object newValue, int rowIndex) { + BigDecimal pricenew = (BigDecimal)newValue; + pricenew = pricenew == null ? BigDecimal.ZERO : pricenew; + BigDecimal qty = (BigDecimal)this.getModel().getValue("qty", rowIndex); + this.getModel().setValue("amount", pricenew.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); + if (row.get("pid") != null) { + BigDecimal 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"}); + this.getView().getFormShowParameter().setCustomParam("isPdamountChange", "false"); + } + } + + 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"}); + } + + protected void setSumToRow(String tbl, String[] cols) { + if (null != tbl && !"".equals(tbl)) { + EntryGrid treeEntry = (EntryGrid)this.getView().getControl(tbl); + Map floatButtomData = new HashMap(16); + + for(int i = 0; i < cols.length; ++i) { + 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(16); + 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.TRUE.equals(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(); + String key = formOperate.getOperateKey(); + if ("newsubentry".equals(key)) { + this.beforeNewSubEntry(beforedooperationeventargs); + } else if ("deletesubentry".equals(key)) { + this.deleteSubRows(); + } else if (!"new".equals(key) && !"submitandnew".equals(key)) { + if (!"save".equals(key) && !"submit".equals(key)) { + if ("location".equals(key)) { + this.doLocation(); + } else if ("showbudget".equals(key)) { + this.doShowBudget(); + } else if ("showreourcelist".equals(key)) { + this.doShowResourceList(); + } + } else { + this.beforeSaveAndSubmit(beforedooperationeventargs); + } + } else { + this.beforeDoNew(); + } + + } + + protected void doShowResourceList() { + FormShowParameter showParameter = new FormShowParameter(); + showParameter.setFormId("ecco_resourcesum"); + showParameter.getOpenStyle().setShowType(ShowType.Modal); + this.getView().showForm(showParameter); + } + + protected void doShowBudget() { + DynamicObject project = (DynamicObject)this.getModel().getValue("project"); + boolean isUnitProject = CBSBudgetUtil.projectIsUnit(project); + if (isUnitProject && this.getModel().getValue("unitproject") == null) { + this.getView().showMessage(ResManager.loadKDString("单位工程未录入", "AimcostcbsbillEditUI_14", "ec-ecco-formplugin", new Object[0])); + } else { + FormShowParameter showParameter = new FormShowParameter(); + showParameter.setFormId("ec_cont_showbudget"); + showParameter.getOpenStyle().setShowType(ShowType.Modal); + this.getView().showForm(showParameter); + } + } + + protected void doLocation() { + boolean showlocation = "true".equals(this.getPageCache().get("showlocation")); + if (showlocation) { + this.getView().setVisible(false, new String[]{"locationtree"}); + this.getPageCache().put("showlocation", "false"); + } else { + this.getView().setVisible(true, new String[]{"locationtree"}); + this.getPageCache().put("showlocation", "true"); + } + + } + + protected void beforeSaveAndSubmit(BeforeDoOperationEventArgs beforedooperationeventargs) { + String number = TypeUtils.nullToString(this.getModel().getValue("billno")); + if ("".equals(number.trim())) { + this.getView().showTipNotification(ResManager.loadKDString("编码不能为空。", "AimcostcbsbillEditUI_3", "ec-ecco-formplugin", new Object[0])); + beforedooperationeventargs.setCancel(true); + } else { + boolean editOnUnit = (Boolean)this.getModel().getValue("editonunit"); + DynamicObject project = (DynamicObject)this.getModel().getValue("project"); + DynamicObject unitProject = (DynamicObject)this.getModel().getValue("unitproject"); + if (editOnUnit && unitProject == null) { + this.getView().showTipNotification(ResManager.loadKDString("请填写“单位工程”字段。", "AimcostcbsbillEditUI_0", "ec-ecco-formplugin", new Object[0])); + beforedooperationeventargs.setCancel(true); + } else if (!editOnUnit && project == null) { + this.getView().showTipNotification(ResManager.loadKDString("请填写“项目”字段。", "AimcostcbsbillEditUI_4", "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("versionno", "=", this.getModel().getValue("versionno"))); + boolean exists = QueryServiceHelper.exists("ecco_aimcostbillcbs", new QFilter[]{filter}); + if (exists) { + this.getView().showTipNotification(ResManager.loadKDString("本项目(单位工程)已编制预算,如需修改,请使用调整功能。", "AimcostcbsbillEditUI_5", "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 var12 = entryEntity.iterator(); var12.hasNext(); ++entryRow) { + DynamicObject entry = (DynamicObject)var12.next(); + Iterator var14 = entry.getDynamicObjectCollection("subentryentity").iterator(); + + while(var14.hasNext()) { + DynamicObject subEntry = (DynamicObject)var14.next(); + if (!graySubEntryIds.contains(subEntry.getPkValue())) { + boolean isCancel = false; + StringBuilder errorMessage = new StringBuilder(String.format(ResManager.loadKDString("请填写第%s行项目CBS对应预算成本清单分录的非灰色行", "AimcostcbsbillEditUI_6", "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("“单价”", "AimcostcbsbillEditUI_7", "ec-ecco-formplugin", new Object[0])); + isCancel = true; + } + + if (qty.compareTo(BigDecimal.ZERO) == 0) { + errorMessage.append(ResManager.loadKDString("“数量”", "AimcostcbsbillEditUI_8", "ec-ecco-formplugin", new Object[0])); + isCancel = true; + } + + if (amount.compareTo(BigDecimal.ZERO) == 0) { + errorMessage.append(ResManager.loadKDString("“金额”", "AimcostcbsbillEditUI_9", "ec-ecco-formplugin", new Object[0])); + isCancel = true; + } + + errorMessage.append(ResManager.loadKDString("字段。", "AimcostcbsbillEditUI_10", "ec-ecco-formplugin", new Object[0])); + if (isCancel) { + beforedooperationeventargs.setCancel(true); + this.getView().showMessage(errorMessage.toString()); + return; + } + } + } + } + } + + } + } + } + + protected void beforeDoNew() { + DynamicObject project = (DynamicObject)this.getModel().getValue("project"); + if (project != null) { + this.getView().getFormShowParameter().setCustomParam("projectId", project.getPkValue()); + } + + } + + protected void deleteSubRows() { + 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) { + if (this.isAdjust()) { + this.getView().getFormShowParameter().setCustomParam("isdeletesubentry", "true"); + List shijideleterows = new ArrayList(10); + BigDecimal subAmount = BigDecimal.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])); + } + + if (this.getModel().getValue("oldentryid", selectrows[i]) != null && !"0".equals(TypeUtils.nullToString(this.getModel().getValue("oldentryid", selectrows[i])))) { + this.getModel().setValue("price", BigDecimal.ZERO, selectrows[i]); + this.getModel().setValue("qty", BigDecimal.ZERO, selectrows[i]); + this.getModel().setValue("amount", BigDecimal.ZERO, selectrows[i]); + Object pkValue = this.getModel().getEntryRowEntity("subentryentity", selectrows[i]).getPkValue(); + ((List)graySubEntryIds).add(pkValue); + } 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[] treeEntrySelectedRows = treeEntry.getSelectRows(); + if (treeEntrySelectedRows.length > 0) { + this.getView().updateView("treeentryentity"); + BigDecimal cbsOldAmount = EcNumberHelper.toBigDecimal(this.getModel().getValue("pdamount", treeEntrySelectedRows[0])); + this.getModel().setValue("pdamount", EcNumberHelper.subtract(cbsOldAmount, subAmount), treeEntrySelectedRows[0]); + DynamicObject row = this.getModel().getEntryRowEntity("treeentryentity", treeEntrySelectedRows[0]); + String parentId = TypeUtils.nullToString(row.get("pid")); + if (!"".equals(parentId) && !"0".equals(parentId)) { + this.setParentAmount("treeentryentity", "pdamount", treeEntrySelectedRows[0], 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(treeEntrySelectedRows[0]); + } + + this.getPageCache().put("subentry_grayids", EcSerializeHelper.serialize(graySubEntryIds)); + this.getView().getFormShowParameter().setCustomParam("isdeletesubentry", "false"); + } else { + BigDecimal subAmount = BigDecimal.ZERO; + + int parentRowIndex; + for(parentRowIndex = 0; parentRowIndex < selectrows.length; ++parentRowIndex) { + if (this.getModel().getValue("amount", selectrows[parentRowIndex]) != null) { + subAmount = EcNumberHelper.add(subAmount, this.getModel().getValue("amount", selectrows[parentRowIndex])); + } + } + + parentRowIndex = this.getModel().getEntryCurrentRowIndex("treeentryentity"); + EntryGrid treeEntry = (EntryGrid)this.getView().getControl("treeentryentity"); + if (parentRowIndex >= 0) { + BigDecimal cbsOldAmount = EcNumberHelper.toBigDecimal(this.getModel().getValue("pdamount", parentRowIndex)); + this.getModel().setValue("pdamount", EcNumberHelper.subtract(cbsOldAmount, subAmount), parentRowIndex); + this.getView().updateView("treeentryentity"); + this.refershTreeEnable(); + treeEntry.selectRows(parentRowIndex); + } + + this.getModel().deleteEntryRows("subentryentity", selectrows); + } + } + + } + + protected void beforeNewSubEntry(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("已删除无法进行新增行操作,请先添加。", "AimcostcbsbillEditUI_11", "ec-ecco-formplugin", new Object[0])); + beforedooperationeventargs.setCancel(true); + } else { + boolean isLeaf = "true".equals(TypeUtils.nullToString(this.getModel().getValue("isleaf", selectrow[0]))); + if (!isLeaf) { + this.getView().showTipNotification(ResManager.loadKDString("请在成本分解结构明细节点下进行新增行操作。", "AimcostcbsbillEditUI_12", "ec-ecco-formplugin", new Object[0])); + beforedooperationeventargs.setCancel(true); + } + } + } else { + this.getView().showTipNotification(ResManager.loadKDString("请在成本分解结构明细节点下进行新增行操作", "AimcostcbsbillEditUI_13", "ec-ecco-formplugin", new Object[0])); + beforedooperationeventargs.setCancel(true); + } + + } + + public void afterDoOperation(AfterDoOperationEventArgs afterDoOperationEventArgs) { + super.afterDoOperation(afterDoOperationEventArgs); + FormOperate formOperate = (FormOperate)afterDoOperationEventArgs.getSource(); + String key = formOperate.getOperateKey(); + if ("newsubentry".equals(key)) { + this.afterNewSubEntry(); + } else if ("deletesubentry".equals(key)) { + this.afterDeleteSubEntry(); + } else if ("expandall".equals(key)) { + this.doFoldAll(false); + } else if ("foldall".equals(key)) { + this.doFoldAll(true); + } + + } + + protected void doFoldAll(boolean isFold) { + TreeEntryGrid treeGrid = (TreeEntryGrid)this.getControl("treeentryentity"); + treeGrid.setCollapse(isFold); + } + + protected void afterDeleteSubEntry() { + int subRowcount = this.getModel().getEntryRowCount("subentryentity"); + if (subRowcount == 0) { + TreeEntryGrid grid = (TreeEntryGrid)this.getControl("treeentryentity"); + int[] selectrow = grid.getSelectRows(); + if (selectrow.length > 0) { + DynamicObject entryRowEntity = this.getModel().getEntryRowEntity("treeentryentity", selectrow[0]); + DynamicObject proCbs = entryRowEntity.getDynamicObject("cbs"); + if (!proCbs.getBoolean("resourcehook")) { + this.getModel().setValue("isgua", false, selectrow[0]); + } + + this.refershTreeEnable(); + grid.selectRows(selectrow[0]); + } + } + + this.setSubEntrySumAmount(); + } + + public void afterAddRow(AfterAddRowEventArgs e) { + String entryName = e.getEntryProp().getName(); + if (StringUtils.equals(entryName, "subentryentity")) { + RowDataEntity[] rowDataEntities = e.getRowDataEntities(); + if (rowDataEntities == null) { + return; + } + + RowDataEntity[] var4 = rowDataEntities; + int var5 = rowDataEntities.length; + + for(int var6 = 0; var6 < var5; ++var6) { + RowDataEntity rowDataEntity = var4[var6]; + int rowIndex = rowDataEntity.getRowIndex(); + int parentRowIndex = rowDataEntity.getParentRowIndex(); + DynamicObject parentCbs = (DynamicObject)this.getModel().getValue("cbs", parentRowIndex); + this.getModel().setValue("cbsre", parentCbs, rowIndex, parentRowIndex); + } + } + + } + + protected void afterNewSubEntry() { + 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]); + 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(); + } + + public void confirmCallBack(MessageBoxClosedEvent messageBoxClosedEvent) { + super.confirmCallBack(messageBoxClosedEvent); + if (messageBoxClosedEvent.getCallBackId().equals("unitprojectchange_callback")) { + this.unitProjectChangedConfirm(messageBoxClosedEvent); + } + + } + + protected void unitProjectChangedConfirm(MessageBoxClosedEvent messageBoxClosedEvent) { + if (messageBoxClosedEvent.getResult().equals(MessageBoxResult.Yes)) { + DynamicObjectCollection subentryColl = this.getModel().getEntryEntity("subentryentity"); + + for(int i = 0; i < subentryColl.size(); ++i) { + DynamicObject subEntry = (DynamicObject)subentryColl.get(i); + if (subEntry.get("projectboq") != null) { + subEntry.set("projectboq", (Object)null); + } + } + + this.getModel().updateCache(); + this.getView().updateView("subentryentity"); + } else if (messageBoxClosedEvent.getResult().equals(MessageBoxResult.Cancel)) { + Object oldvalue = this.getView().getFormShowParameter().getCustomParam("oldunitproject"); + this.getModel().setValue("unitproject", oldvalue); + this.getView().updateView("unitproject"); + this.getView().getFormShowParameter().setCustomParam("isCancel", "true"); + } + + } + + 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 = BigDecimal.ZERO; + } + + if (newAmount == null) { + newAmount = BigDecimal.ZERO; + } + + BigDecimal parentOldAmount = EcNumberHelper.toBigDecimal(this.getModel().getEntryRowEntity(table, i).get(colname)); + BigDecimal parentNewAmount = null; + if (parentOldAmount == null) { + parentNewAmount = newAmount; + } else { + parentNewAmount = parentOldAmount.subtract(oldAmount).add(newAmount); + } + + this.getModel().setValue(colname, parentNewAmount, i); + if (this.getModel().getEntryRowEntity(table, i).get("pid") != null) { + parentId = this.getModel().getEntryRowEntity(table, i).get("pid").toString(); + } + } + } + + } +}