diff --git a/code/zcdev/zcgj-zcdev-zcdev-pr/src/main/java/zcgj/zcdev/zcdev/pr/plugin/form/ContractCostSplitBillPluginExt.java b/code/zcdev/zcgj-zcdev-zcdev-pr/src/main/java/zcgj/zcdev/zcdev/pr/plugin/form/ContractCostSplitBillPluginExt.java new file mode 100644 index 0000000..7dc50fc --- /dev/null +++ b/code/zcdev/zcgj-zcdev-zcdev-pr/src/main/java/zcgj/zcdev/zcdev/pr/plugin/form/ContractCostSplitBillPluginExt.java @@ -0,0 +1,1660 @@ +// +// Source code recreated from a .class file by IntelliJ IDEA +// (powered by FernFlower decompiler) +// + +package zcgj.zcdev.zcdev.pr.plugin.form; + +import java.awt.Color; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.math.BigDecimal; +import java.math.RoundingMode; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Calendar; +import java.util.Date; +import java.util.EventObject; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import kd.bos.bill.OperationStatus; +import kd.bos.cache.CacheFactory; +import kd.bos.dataentity.entity.DynamicObject; +import kd.bos.dataentity.entity.DynamicObjectCollection; +import kd.bos.dataentity.entity.LocaleString; +import kd.bos.dataentity.metadata.dynamicobject.DynamicObjectType; +import kd.bos.dataentity.resource.ResManager; +import kd.bos.dataentity.utils.StringUtils; +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.entity.property.ComboProp; +import kd.bos.form.CloseCallBack; +import kd.bos.form.FormShowParameter; +import kd.bos.form.ShowType; +import kd.bos.form.control.Control; +import kd.bos.form.control.EntryGrid; +import kd.bos.form.events.AfterDoOperationEventArgs; +import kd.bos.form.events.BeforeDoOperationEventArgs; +import kd.bos.form.events.ClosedCallBackEvent; +import kd.bos.form.events.HyperLinkClickEvent; +import kd.bos.form.events.HyperLinkClickListener; +import kd.bos.form.field.AmountEdit; +import kd.bos.form.field.BasedataEdit; +import kd.bos.form.field.FieldEdit; +import kd.bos.form.field.TextEdit; +import kd.bos.form.field.events.BeforeF7SelectEvent; +import kd.bos.form.field.events.BeforeF7SelectListener; +import kd.bos.form.operate.FormOperate; +import kd.bos.list.ListFilterParameter; +import kd.bos.list.ListShowParameter; +import kd.bos.orm.query.QFilter; +import kd.bos.servicehelper.BusinessDataServiceHelper; +import kd.bos.servicehelper.QueryServiceHelper; +import kd.ec.basedata.business.model.cont.OutContractMeasureConstant; +import kd.ec.basedata.common.enums.PayDirectionEnum; +import kd.ec.basedata.common.enums.ReferBillTypeEnum; +import kd.ec.basedata.common.enums.SplitBillTypeEnum; +import kd.ec.basedata.common.utils.EcPeriodUtils; +import kd.ec.basedata.common.utils.OpenPageUtils; +import kd.ec.contract.common.enums.DirectionEnum; +import kd.ec.contract.common.utils.CurrencyHelper; +import kd.ec.contract.utils.BudgetCBSUtils; +import kd.ec.cost.common.enums.BillStatusEnum; +import kd.ec.cost.formplugin.AbstractEccoBillPlugin; +import org.apache.poi.ss.usermodel.FillPatternType; +import org.apache.poi.ss.usermodel.HorizontalAlignment; +import org.apache.poi.xssf.usermodel.DefaultIndexedColorMap; +import org.apache.poi.xssf.usermodel.XSSFCell; +import org.apache.poi.xssf.usermodel.XSSFCellStyle; +import org.apache.poi.xssf.usermodel.XSSFColor; +import org.apache.poi.xssf.usermodel.XSSFRow; +import org.apache.poi.xssf.usermodel.XSSFSheet; +import org.apache.poi.xssf.usermodel.XSSFWorkbook; +import org.jetbrains.annotations.NotNull; + +public class ContractCostSplitBillPluginExt extends AbstractEccoBillPlugin implements BeforeF7SelectListener, HyperLinkClickListener { + private static final String UNITPROJECT = "unitproject"; + private static final String DIRECTION = "direction"; + public static final String AUTO_GET_DATA = "autogetdata"; + public static final String NEWSUBENTRY = "newsubentry"; + public static final String DELETESUBENTRY = "deletesubentry"; + private static final String EXPORTSETTLEDETAIL = "exportsettledetail"; + private static final String PROJECT = "project"; + private static final String EC_PROJECT = "ec_project"; + + public ContractCostSplitBillPluginExt() { + } + + public void registerListener(EventObject e) { + super.registerListener(e); + BasedataEdit project = (BasedataEdit) this.getControl("project"); + BasedataEdit period = (BasedataEdit) this.getControl("period"); + BasedataEdit proBOQ = (BasedataEdit) this.getControl("proboq"); + BasedataEdit proCBS = (BasedataEdit) this.getControl("procbs"); + BasedataEdit rsItem = (BasedataEdit) this.getControl("resource"); + BasedataEdit unitPro = (BasedataEdit) this.getControl("unitproject"); + project.addBeforeF7SelectListener(this); + period.addBeforeF7SelectListener(this); + proBOQ.addBeforeF7SelectListener(this); + proCBS.addBeforeF7SelectListener(this); + rsItem.addBeforeF7SelectListener(this); + unitPro.addBeforeF7SelectListener(this); + EntryGrid grid = (EntryGrid) this.getControl("entryentity"); + grid.addHyperClickListener(this); + BasedataEdit proj = (BasedataEdit) this.getView().getControl("project"); + if (proj != null) { + proj.addBeforeF7ViewDetailListener((beforeF7ViewDetailEvent) -> { + beforeF7ViewDetailEvent.setCancel(true); + this.getView().showForm(OpenPageUtils.buildBillShowParam(beforeF7ViewDetailEvent.getPkId(), "ec_project")); + }); + } + + TextEdit listingName = (TextEdit) this.getControl("listingname"); + listingName.addClickListener(this); + } + + public void beforeF7Select(BeforeF7SelectEvent event) { + String key = event.getProperty().getName(); + ListShowParameter listShowParameter = (ListShowParameter) event.getFormShowParameter(); + if (StringUtils.equals(key, "proboq")) { + this.beforeProjectBoqSelect(event, listShowParameter); + } else if (StringUtils.equals(key, "procbs")) { + this.beforeProjectCbsSelect(event, listShowParameter); + } else if (StringUtils.equals(key, "unitproject")) { + this.beforeUnitProjectSelect(event, listShowParameter); + } + + } + + public void afterAddRow(AfterAddRowEventArgs e) { + super.afterAddRow(e); + String entryName = e.getEntryProp().getName(); + if (StringUtils.equals(entryName, "subentryentity")) { + RowDataEntity[] rowDataEntities = e.getRowDataEntities(); + + for (int i = 0; i < rowDataEntities.length; ++i) { + int parentRowIndex = rowDataEntities[i].getParentRowIndex(); + int rowIndex = rowDataEntities[i].getRowIndex(); + this.getModel().setValue("isaddrow", true, rowIndex); + Object settleNumber = this.getModel().getValue("settlenumber", parentRowIndex); + this.getModel().setValue("subsettlenumber", settleNumber, rowIndex); + } + } + + } + + public void click(EventObject evt) { + super.click(evt); + Control c = (Control) evt.getSource(); + String key = c.getKey().toLowerCase(); + if (StringUtils.equals(key, "listingname")) { + this.listingNameClick(); + } + + } + + protected void listingNameClick() { + Map paramMap = new HashMap(); + paramMap.put("formId", "ecco_contlisting"); + FormShowParameter showParameter = FormShowParameter.createFormShowParameter(paramMap); + int entryCurrentRowIndex = this.getModel().getEntryCurrentRowIndex("entryentity"); + String billType = (String) this.getModel().getValue("splitbilltype", entryCurrentRowIndex); + Long billId = (Long) this.getModel().getValue("settleid", entryCurrentRowIndex); + Map map = new HashMap(); + map.put("billtype", billType); + map.put("billid", billId); + showParameter.setCustomParams(map); + showParameter.getOpenStyle().setShowType(ShowType.Modal); + CloseCallBack closeCallBack = new CloseCallBack(this, "subListingNameCallBack"); + showParameter.setCloseCallBack(closeCallBack); + this.getView().showForm(showParameter); + } + + public void closedCallBack(ClosedCallBackEvent closedCallBackEvent) { + super.closedCallBack(closedCallBackEvent); + String actionId = closedCallBackEvent.getActionId(); + if (StringUtils.equals(actionId, "subListingNameCallBack")) { + this.listNameClosedCallBack(closedCallBackEvent); + } + + } + + private void listNameClosedCallBack(ClosedCallBackEvent closedCallBackEvent) { + Map returnData = (Map) closedCallBackEvent.getReturnData(); + if (returnData != null) { + int entryCurrentRowIndex = this.getModel().getEntryCurrentRowIndex("subentryentity"); + this.getModel().setValue("listingname", returnData.get("listingname"), entryCurrentRowIndex); + this.getModel().setValue("resource", returnData.get("resource"), entryCurrentRowIndex); + } + + } + + protected void beforeUnitProjectSelect(BeforeF7SelectEvent event, ListShowParameter listShowParameter) { + DynamicObject project = (DynamicObject) this.getModel().getValue("project"); + DynamicObject entryRowEntity = this.getModel().getEntryRowEntity("subentryentity", event.getRow()); + DynamicObject parent = (DynamicObject) entryRowEntity.getParent(); + DynamicObject contract = parent.getDynamicObject("contract"); + if (project != null) { + List unitProIds = this.getContUnitProIds(contract); + if (unitProIds.isEmpty()) { + unitProIds = this.getProUnitProIds(project); + } + + listShowParameter.getListFilterParameter().getQFilters().add(new QFilter("id", "in", unitProIds)); + } else { + this.getView().showTipNotification(ResManager.loadKDString("请先选择项目。", "ContractCostSplitBillPlugin_0", "ec-ecco-formplugin", new Object[0])); + event.setCancel(true); + } + } + + protected void beforeProjectCbsSelect(BeforeF7SelectEvent event, ListShowParameter listShowParameter) { + DynamicObject project = (DynamicObject) this.getModel().getValue("project"); + if (null != project) { + listShowParameter.setFormId("bos_listf7"); + ListFilterParameter listFilterParameter = listShowParameter.getListFilterParameter(); + listFilterParameter.getQFilters().add(new QFilter("project", "=", project.getPkValue())); + } else { + this.getView().showTipNotification(ResManager.loadKDString("请先选择项目。", "ContractCostSplitBillPlugin_0", "ec-ecco-formplugin", new Object[0])); + event.setCancel(true); + } + + } + + protected void beforeProjectBoqSelect(BeforeF7SelectEvent event, ListShowParameter listShowParameter) { + DynamicObject project = (DynamicObject) this.getModel().getValue("project"); + DynamicObject entryRowEntity = this.getModel().getEntryRowEntity("subentryentity", event.getRow()); + DynamicObject parent = (DynamicObject) entryRowEntity.getParent(); + DynamicObject contract = parent.getDynamicObject("contract"); + if (project == null) { + this.getView().showTipNotification(ResManager.loadKDString("请先选择项目。", "ContractCostSplitBillPlugin_0", "ec-ecco-formplugin", new Object[0])); + event.setCancel(true); + } else { + DynamicObject unitPro = (DynamicObject) this.getModel().getValue("unitproject", event.getRow()); + ListFilterParameter listFilterParameter = listShowParameter.getListFilterParameter(); + if (unitPro != null) { + listFilterParameter.getQFilters().add(new QFilter("unitproject", "=", unitPro.getPkValue())); + } else { + List unitProIds = this.getContUnitProIds(contract); + if (!unitProIds.isEmpty()) { + listFilterParameter.getQFilters().add(new QFilter("unitproject", "in", unitProIds)); + } else { + listFilterParameter.getQFilters().add(new QFilter("project", "=", project.getPkValue())); + } + } + + listShowParameter.setFormId("bos_listf7"); + } + } + + protected List getProUnitProIds(DynamicObject project) { + List unitProIds = new ArrayList(); + if (project != null) { + project = BusinessDataServiceHelper.loadSingle(project.getPkValue(), "ec_project"); + DynamicObjectCollection proUnitPros = project.getDynamicObjectCollection("unitproject"); + Iterator var4 = proUnitPros.iterator(); + + while (var4.hasNext()) { + DynamicObject entry = (DynamicObject) var4.next(); + unitProIds.add(entry.getPkValue()); + } + } + + return unitProIds; + } + + protected List getContUnitProIds(DynamicObject contract) { + List unitProIds = new ArrayList(); + if (contract != null) { + contract = BusinessDataServiceHelper.loadSingle(contract.getPkValue(), "ec_out_contract"); + DynamicObject contUnitPro = contract.getDynamicObject("unitproject"); + if (contUnitPro != null) { + unitProIds.add(contUnitPro.getPkValue()); + } + + if (contract.getBoolean("isonlist")) { + DynamicObjectCollection listmodelentry = contract.getDynamicObjectCollection("listmodelentry"); + Iterator var5 = listmodelentry.iterator(); + + while (var5.hasNext()) { + DynamicObject listEntry = (DynamicObject) var5.next(); + DynamicObjectCollection sublistentry = listEntry.getDynamicObjectCollection("sublistentry"); + Iterator var8 = sublistentry.iterator(); + + while (var8.hasNext()) { + DynamicObject entry = (DynamicObject) var8.next(); + DynamicObject contListUnitPro = entry.getDynamicObject("listunitproject"); + if (contListUnitPro != null) { + unitProIds.add(contListUnitPro.getPkValue()); + } + } + } + } + } + + return unitProIds; + } + + public void afterCreateNewData(EventObject e) { + super.afterCreateNewData(e); + FormShowParameter formShowParameter = this.getView().getFormShowParameter(); + Map customParams = formShowParameter.getCustomParams(); + Object projectId = customParams.get("projectId"); + if (null != projectId) { + this.getModel().setValue("project", projectId); + } + + 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); + } + + } + + public void beforeDoOperation(BeforeDoOperationEventArgs args) { + super.beforeDoOperation(args); + FormOperate formOperate = (FormOperate) args.getSource(); + String key = formOperate.getOperateKey(); + if (StringUtils.equals(key, "autogetdata")) { + if (this.judgeCondition()) { + this.loadSettleInfo(); + this.setCostAmt(); + } + } else if (StringUtils.equals(key, "newsubentry")) { + this.beforeNewSubEntry(args); + } else if (StringUtils.equals(key, "deletesubentry")) { + this.beforeDeleteSubEntry(); + } else if (StringUtils.equals(key, "exportsettledetail")) { + this.exportSettleDetail(); + } + + } + + public void afterDoOperation(AfterDoOperationEventArgs args) { + super.afterDoOperation(args); + FormOperate formOperate = (FormOperate) args.getSource(); + String key = formOperate.getOperateKey(); + if (StringUtils.equals(key, "deleteentry")) { + this.setCostAmt(); + } + + } + + protected void beforeDeleteSubEntry() { + int rowCount = this.getModel().getEntryRowCount("subentryentity"); + if (rowCount > 0) { + int subEntryIndex = this.getModel().getEntryCurrentRowIndex("subentryentity"); + if (subEntryIndex >= 0) { + int parentRowIndex = this.getModel().getEntryCurrentRowIndex("entryentity"); + BigDecimal totalAmt = this.sumAmount("subentryentity", "amount"); + BigDecimal deleteAmt = (BigDecimal) this.getModel().getValue("amount", subEntryIndex); + totalAmt = totalAmt.subtract(deleteAmt); + this.getModel().setValue("splitamount", totalAmt, parentRowIndex); + } + + } + } + + protected void beforeNewSubEntry(BeforeDoOperationEventArgs args) { + int rowIndex = this.getModel().getEntryCurrentRowIndex("entryentity"); + int rowCount = this.getModel().getEntryRowCount("entryentity"); + if (rowCount <= 0 || rowIndex < 0) { + this.getView().showTipNotification(ResManager.loadKDString("请先选中1行合同结算明细。", "ContractCostSplitBillPlugin_1", "ec-ecco-formplugin", new Object[0])); + args.setCancel(true); + } + + } + + protected void exportSettleDetail() { + int rowCount = this.getModel().getEntryRowCount("entryentity"); + if (rowCount <= 0) { + this.getView().showTipNotification(ResManager.loadKDString("当前分录没有数据。", "ContractCostSplitBillPlugin_2", "ec-ecco-formplugin", new Object[0])); + } else { + XSSFWorkbook wb = new XSSFWorkbook(); + EntryGrid grid = (EntryGrid) this.getView().getControl("entryentity"); + List items = grid.getItems(); + int size = items.size() - 3; + String[] title = new String[size]; + String[] numbers = new String[size]; + int index = 0; + Iterator var9 = items.iterator(); + + while (var9.hasNext()) { + Control item = (Control) var9.next(); + FieldEdit column = (FieldEdit) item; + if (!StringUtils.equals(column.getKey(), "settleid") && !StringUtils.equals(column.getKey(), "measureamount") && !StringUtils.equals(column.getKey(), "settlesplitamount")) { + numbers[index] = column.getKey(); + title[index] = column.getProperty().getDisplayName().getLocaleValue(); + ++index; + } + } + + XSSFSheet sheet = wb.createSheet(ResManager.loadKDString("合同结算明细", "ContractCostSplitBillPlugin_3", "ec-ecco-formplugin", new Object[0])); + XSSFCellStyle style = wb.createCellStyle(); + style.setFillPattern(FillPatternType.SOLID_FOREGROUND); + style.setFillForegroundColor(new XSSFColor(new Color(255, 245, 0), new DefaultIndexedColorMap())); + style.setAlignment(HorizontalAlignment.CENTER_SELECTION); + XSSFCellStyle dataStyle = wb.createCellStyle(); + dataStyle.setAlignment(HorizontalAlignment.RIGHT); + XSSFRow row = sheet.createRow(0); + + int i; + for (i = 0; i < size; ++i) { + XSSFCell cell = row.createCell(i); + cell.setCellValue(title[i]); + cell.setCellStyle(style); + sheet.setColumnWidth(i, 4024); + } + + String number; + for (i = 0; i < rowCount; ++i) { + XSSFRow cur = sheet.createRow(i + 1); + + XSSFCell dataCell; + String cellValue; + for (int count = 0; count < numbers.length; dataCell.setCellValue(cellValue)) { + number = numbers[count]; + dataCell = cur.createCell(count++); + Object value = this.getModel().getValue(number, i); + if (value == null) { + cellValue = ""; + } else if (value instanceof DynamicObject) { + Object name = ((DynamicObject) value).get("name"); + if (name instanceof LocaleString) { + cellValue = ((LocaleString) name).getLocaleValue(); + } else { + cellValue = name.toString(); + } + } else if (!(value instanceof BigDecimal)) { + if (StringUtils.equals("splitbilltype", number)) { + ComboProp property = (ComboProp) this.getModel().getDataEntityType().findProperty(number); + cellValue = property.getItemByName(value.toString()); + } else { + cellValue = value.toString(); + } + } else { + DynamicObject currency = (DynamicObject) this.getModel().getValue(this.getCurrency()); + Control control = this.getControl(number); + if (currency != null && control instanceof AmountEdit) { + int precision = currency.getInt("amtprecision"); + cellValue = ((BigDecimal) value).setScale(precision).toPlainString(); + } else { + cellValue = ((BigDecimal) value).toPlainString(); + } + + if ("0E-10".equals(cellValue)) { + cellValue = "0.00"; + } + + dataCell.setCellStyle(dataStyle); + } + } + } + + ByteArrayOutputStream os = new ByteArrayOutputStream(); + + try { + wb.write(os); + } catch (IOException var25) { + var25.printStackTrace(); + } + + byte[] content = os.toByteArray(); + InputStream in = new ByteArrayInputStream(content); + number = CacheFactory.getCommonCacheFactory().getTempFileCache().saveAsUrl(this.getFileName(), in, 5000); + this.getView().download(number); + if (wb != null) { + try { + wb.close(); + } catch (IOException var24) { + var24.printStackTrace(); + } + } + + } + } + + protected String getFileName() { + Object billNumber = this.getModel().getValue("billno"); + return billNumber != null ? String.format(ResManager.loadKDString("%s合同成本分摊-合同结算明细.xlsx", "ContractCostSplitBillPlugin_4", "ec-ecco-formplugin", new Object[0]), billNumber.toString()) : ResManager.loadKDString("合同成本分摊-合同结算明细.xlsx", "ContractCostSplitBillPlugin_5", "ec-ecco-formplugin", new Object[0]); + } + + protected void onPeriodChange() { + this.getModel().deleteEntryData("entryentity"); + this.getModel().deleteEntryData("subentryentity"); + this.setCostAmt(); + } + + protected void onProjectChange(ChangeData changeData) { + DynamicObject project = (DynamicObject) changeData.getNewValue(); + this.getModel().deleteEntryData("entryentity"); + this.getModel().deleteEntryData("subentryentity"); + this.setCostAmt(); + this.setUnitProjectMustInput(project); + } + + private void setUnitProjectMustInput(DynamicObject project) { + boolean isUnit = BudgetCBSUtils.projectIsUnit(project); + BasedataEdit unitProject = (BasedataEdit) this.getView().getControl("unitproject"); + unitProject.setMustInput(isUnit); + } + + public void beforeBindData(EventObject e) { + super.beforeBindData(e); + this.setUnitProjectMustInput((DynamicObject) this.getModel().getValue("project")); + } + + public void propertyChanged(PropertyChangedArgs e) { + String key = e.getProperty().getName(); + ChangeData changeData = e.getChangeSet()[0]; + int rowIndex = changeData.getRowIndex(); + if (StringUtils.equals(key, "project")) { + this.onProjectChange(changeData); + } else if (StringUtils.equals(key, "period")) { + this.onPeriodChange(); + } else if (StringUtils.equals(key, "splitamount")) { + int index = changeData.getRowIndex(); + this.calUnSplitAmt(index); + this.setCostAmt(); + } else if (StringUtils.equals(key, "amount")) { + BigDecimal totalAmt = this.sumAmount("subentryentity", "amount"); + this.getModel().setValue("splitamount", totalAmt, changeData.getParentRowIndex()); + } else if (StringUtils.equals(key, "resource")) { + this.onResourceChange(changeData, rowIndex); + } else if (StringUtils.equals(key, "unitproject")) { + this.getModel().setValue("proboq", (Object) null, rowIndex); + } else if (StringUtils.equals(key, "proboq")) { + this.onBoqChange(changeData, rowIndex); + } + + } + + protected void onBoqChange(ChangeData changeData, int rowIndex) { + DynamicObject proBoq = (DynamicObject) changeData.getNewValue(); + if (rowIndex >= 0) { + DynamicObject unitPro = (DynamicObject) this.getModel().getValue("unitproject", rowIndex); + if (proBoq != null && unitPro == null) { + DynamicObject unitproject = proBoq.getDynamicObject("unitproject"); + if (unitproject != null) { + this.getModel().beginInit(); + this.getModel().setValue("unitproject", unitproject.getPkValue(), rowIndex); + this.getModel().endInit(); + this.getView().updateView("unitproject", rowIndex); + } + } + + } + } + + protected void onResourceChange(ChangeData changeData, int rowIndex) { + this.getModel().setValue("procbs", (Object) null, rowIndex); + this.getModel().setValue("costaccount", (Object) null, rowIndex); + DynamicObject resourceItem = (DynamicObject) changeData.getNewValue(); + if (null != resourceItem) { + DynamicObject cbs = resourceItem.getDynamicObject("cbs"); + if (null != cbs) { + Long cbsId = (Long) cbs.getPkValue(); + DynamicObject project = (DynamicObject) this.getModel().getValue("project"); + Long projectId = (Long) project.getPkValue(); + QFilter qFilter = new QFilter("project", "=", projectId); + qFilter.and(new QFilter("enterprisecbs", "=", cbsId)); + DynamicObject[] proCbs = BusinessDataServiceHelper.load("ec_ecbd_pro_cbs", "id", new QFilter[]{qFilter}); + if (null != proCbs && proCbs.length > 0) { + this.getModel().setValue("procbs", proCbs[0], rowIndex); + } + } + + this.getModel().setValue("costaccount", resourceItem.getDynamicObject("ca"), rowIndex); + } + + } + + protected boolean judgeCondition() { + DynamicObject project = (DynamicObject) this.getModel().getValue("project"); + DynamicObject period = (DynamicObject) this.getModel().getValue("period"); + if (project == null) { + this.getView().showTipNotification(ResManager.loadKDString("工程项目不能为空。", "ContractCostSplitBillPlugin_6", "ec-ecco-formplugin", new Object[0])); + return false; + } else if (period == null) { + this.getView().showTipNotification(ResManager.loadKDString("期间不能为空。", "ContractCostSplitBillPlugin_7", "ec-ecco-formplugin", new Object[0])); + return false; + } else { + return true; + } + } + + protected void loadSettleInfo() { + this.getModel().deleteEntryData("entryentity"); + this.getView().updateView("entryentity"); + HashMap settleSplitAmountMap = this.getHistorySplitAmount(false); + DynamicObject project = (DynamicObject) this.getModel().getValue("project"); + DynamicObject period = (DynamicObject) this.getModel().getValue("period"); + QFilter projectFilter = new QFilter("project", "=", project.getPkValue()); + QFilter periodFilter = new QFilter("enddate", "<=", this.getLastTimeOfDay(period.getDate("enddate"))); + QFilter typeFilter = new QFilter("contattr.basictype", "!=", "02"); + QFilter commonFilter = new QFilter("billstatus", "=", BillStatusEnum.AUDIT.getValue()); + QFilter payDirectionFilter = new QFilter("paydirection", "=", PayDirectionEnum.OUT.getValue()); + QFilter isInCostFilter = new QFilter("contract.isincost", "=", true); + QFilter splitCompletedFilter = new QFilter("isincost", "=", "0"); + Map onWayFilter = this.getOnWayFilter(); + DynamicObject[] settleBills = BusinessDataServiceHelper.load("ec_out_contract_settle", "id", new QFilter[]{projectFilter, periodFilter, commonFilter, payDirectionFilter, typeFilter, isInCostFilter, splitCompletedFilter, (QFilter) onWayFilter.get(SplitBillTypeEnum.SETTLE.getValue())}); + Set splitMeasureIds = new HashSet(16); + DynamicObjectCollection entries = this.getModel().getEntryEntity("entryentity"); + DynamicObjectType entryDT = entries.getDynamicObjectType(); + int precision = this.getAmountPrecision(); + DynamicObject[] var17 = settleBills; + int var18 = settleBills.length; + + BigDecimal unSplitAmt; + BigDecimal measureBillAmount; + DynamicObject finalSettle; + DynamicObject detailEntry; + DynamicObject itemEntry; + for (int var19 = 0; var19 < var18; ++var19) { + DynamicObject settleBill = var17[var19]; + settleBill = BusinessDataServiceHelper.loadSingle(settleBill.getPkValue(), "ec_out_contract_settle"); + BigDecimal historySplitAmount = (BigDecimal) settleSplitAmountMap.get(settleBill.getLong("id")); + historySplitAmount = historySplitAmount == null ? BigDecimal.ZERO : historySplitAmount; + BigDecimal exchangeRate = this.getBillExchangeRate(settleBill); + BigDecimal settleAmount = settleBill.getBigDecimal("settleamount"); + BigDecimal splitAmount = BigDecimal.ZERO; + measureBillAmount = BigDecimal.ZERO; + settleAmount = settleAmount.multiply(exchangeRate); + boolean autoSplit = true; + if (historySplitAmount.compareTo(settleAmount.multiply(exchangeRate)) == 0) { + DynamicObjectCollection payDetailEntries = settleBill.getDynamicObjectCollection("payitemdetailentry"); + Iterator var29 = payDetailEntries.iterator(); + + while (var29.hasNext()) { + finalSettle = (DynamicObject) var29.next(); + String billType = finalSettle.getString("referbilltype"); + if (StringUtils.equals(billType, ReferBillTypeEnum.MEASURE.getValue())) { + splitMeasureIds.add(finalSettle.getLong("referbillid")); + } + } + } else { + if (historySplitAmount.compareTo(BigDecimal.ZERO) > 0) { + autoSplit = false; + } + + DynamicObject entry = new DynamicObject(entryDT); + entry.set("contract", settleBill.get("contract")); + entry.set("contractnumber", settleBill.get("contract.number")); + entry.set("settlenumber", settleBill.get("billno")); + entry.set("settleid", settleBill.getPkValue()); + entry.set("settleperiod", settleBill.get("period")); + entry.set("settleamount", this.valueOfPrecision(settleAmount, precision)); + entry.set("settlesplitamount", this.valueOfPrecision(historySplitAmount, precision)); + entry.set("entrycomment", settleBill.get("description")); + entry.set("splitbilltype", SplitBillTypeEnum.SETTLE.getValue()); + String settleNumber = settleBill.getString("billno"); + Set itemList = new HashSet(); + DynamicObjectCollection detailEntries = settleBill.getDynamicObjectCollection("payitemdetailentry"); + if (detailEntries != null && !detailEntries.isEmpty()) { + Iterator var32 = detailEntries.iterator(); + + while (var32.hasNext()) { + detailEntry = (DynamicObject) var32.next(); + DynamicObject item = detailEntry.getDynamicObject("detailpayitem"); + if (item != null) { + itemList.add(item.getPkValue()); + } + + String billType = detailEntry.getString("referbilltype"); + long billId = detailEntry.getLong("referbillid"); + if (StringUtils.equals(billType, ReferBillTypeEnum.CLAIM.getValue())) { + splitAmount = this.newSplitDetailByClaim(billId, splitAmount, exchangeRate, settleNumber, autoSplit, item, entry); + } else if (StringUtils.equals(billType, ReferBillTypeEnum.VISA.getValue())) { + splitAmount = this.newSplitDetailByVisa(billId, splitAmount, exchangeRate, settleNumber, autoSplit, item, entry); + } else if (StringUtils.equals(billType, ReferBillTypeEnum.PERFORM.getValue())) { + long entryId = detailEntry.getLong("referentryid"); + splitAmount = this.newSplitDetailByPerformEntry(billId, entryId, splitAmount, exchangeRate, settleNumber, autoSplit, item, entry); + } + } + } + + DynamicObjectCollection itemEntries = settleBill.getDynamicObjectCollection("itementry"); + if (itemEntries != null && !itemEntries.isEmpty()) { + DynamicObjectCollection subEntries = entry.getDynamicObjectCollection("subentryentity"); + DynamicObjectType subEntryDT = subEntries.getDynamicObjectType(); + int size = subEntries.size(); + + for (int j = 0; j < itemEntries.size(); ++j) { + itemEntry = (DynamicObject) itemEntries.get(j); + DynamicObject item = itemEntry.getDynamicObject("payitem"); + if (item != null && !itemList.contains(item.getPkValue())) { + String direction = item.getString("direction"); + if (!DirectionEnum.NON.getValue().equals(direction)) { + DynamicObject subEntry = new DynamicObject(subEntryDT); + subEntry.set("subsettlenumber", settleBill.getString("billno")); + subEntry.set("listingname", item.getString("name")); + BigDecimal amount = itemEntry.getBigDecimal("amount").multiply(exchangeRate); + if (DirectionEnum.SUB.getValue().equals(direction)) { + amount = amount.negate(); + } + + subEntry.set("procbs", itemEntry.get("itemcbs")); + subEntry.set("costaccount", itemEntry.get("itemca")); + subEntry.set("proboq", itemEntry.get("itemboq")); + if (autoSplit) { + subEntry.set("amount", this.valueOfPrecision(amount, precision)); + splitAmount = splitAmount.add(this.valueOfPrecision(amount, precision)); + } + + ++size; + subEntry.set("seq", size); + subEntries.add(subEntry); + } + } else if (item != null && itemList.contains(item.getPkValue()) && j == 0) { + measureBillAmount = this.valueOfPrecision(itemEntry.getBigDecimal("amount").multiply(exchangeRate), precision); + } + } + } + + entry.set("splitamount", this.valueOfPrecision(splitAmount, precision)); + entry.set("measureamount", this.valueOfPrecision(measureBillAmount, precision)); + entry.set("tosplitamount", this.valueOfPrecision(settleAmount.subtract(measureBillAmount), precision)); + unSplitAmt = this.valueOfPrecision(settleAmount, precision).subtract(this.valueOfPrecision(historySplitAmount, precision)).subtract(this.valueOfPrecision(splitAmount, precision)).subtract(this.valueOfPrecision(measureBillAmount, precision)); + entry.set("unsplitamount", this.valueOfPrecision(unSplitAmt, precision)); + entries.add(entry); + } + } + + HashMap measureSplitedAmountMap = this.getHistorySplitAmount(true); + QFilter splitMeasureFilter = new QFilter(OutContractMeasureConstant.ID_ENTITY_PK, "not in", splitMeasureIds); + QFilter[] measureFilters = new QFilter[]{projectFilter, periodFilter, commonFilter, payDirectionFilter, typeFilter, isInCostFilter, splitMeasureFilter, splitCompletedFilter, (QFilter) onWayFilter.get(SplitBillTypeEnum.MEASURE.getValue())}; + DynamicObject[] measureBills = BusinessDataServiceHelper.load("ec_outcontractmeasure", "id", measureFilters); + List noSettleMeasureBills = new ArrayList(); + Map enterpriseCbsMap = this.getEnterpriseCbsMap(); + DynamicObject[] var62 = measureBills; + int var65 = measureBills.length; + + BigDecimal historySplitAmount; + BigDecimal splitAmount; + for (int var64 = 0; var64 < var65; ++var64) { + DynamicObject measureBill = var62[var64]; + measureBill = BusinessDataServiceHelper.loadSingle(measureBill.getPkValue(), "ec_outcontractmeasure"); + if (!measureBill.getBoolean("issettled")) { + noSettleMeasureBills.add(measureBill); + } + + historySplitAmount = (BigDecimal) measureSplitedAmountMap.get(measureBill.getLong("id")); + historySplitAmount = historySplitAmount == null ? BigDecimal.ZERO : historySplitAmount; + BigDecimal exchangeRate = this.getBillExchangeRate(measureBill); + BigDecimal measureAmount = measureBill.getBigDecimal("measureamount"); +// BigDecimal splitAmount = BigDecimal.ZERO;//系统代码 + splitAmount = BigDecimal.ZERO;//二开替代 + measureAmount = measureAmount.multiply(exchangeRate); + boolean autoSplit = true; + if (historySplitAmount.compareTo(measureAmount.multiply(exchangeRate)) != 0) { + if (historySplitAmount.compareTo(BigDecimal.ZERO) > 0) { + autoSplit = false; + } + + detailEntry = new DynamicObject(entryDT); + detailEntry.set("contract", measureBill.get("contract")); + detailEntry.set("contractnumber", measureBill.get("contract.number")); + detailEntry.set("settlenumber", measureBill.get("billno")); + detailEntry.set("settleid", measureBill.getPkValue()); + detailEntry.set("settleperiod", measureBill.get("period")); + detailEntry.set("settleamount", this.valueOfPrecision(measureAmount, precision)); + detailEntry.set("settlesplitamount", this.valueOfPrecision(historySplitAmount, precision)); + detailEntry.set("entrycomment", measureBill.get("description")); + detailEntry.set("splitbilltype", SplitBillTypeEnum.MEASURE.getValue()); + detailEntry.set("tosplitamount", this.valueOfPrecision(measureAmount, precision)); + splitAmount = this.newSplitDetailByMeasure(measureBill, splitAmount, exchangeRate, autoSplit, enterpriseCbsMap, detailEntry); + detailEntry.set("splitamount", this.valueOfPrecision(splitAmount, precision)); + splitAmount = this.valueOfPrecision(measureAmount, precision).subtract(this.valueOfPrecision(historySplitAmount, precision)).subtract(this.valueOfPrecision(splitAmount, precision)); + detailEntry.set("unsplitamount", this.valueOfPrecision(splitAmount, precision)); + entries.add(detailEntry); + } + } + + Iterator iterator = entries.iterator(); + + while (iterator.hasNext()) { + DynamicObject entry = (DynamicObject) iterator.next(); + unSplitAmt = entry.getBigDecimal("settleamount"); + measureBillAmount = entry.getBigDecimal("settlesplitamount"); + historySplitAmount = entry.getBigDecimal("measureamount"); + if (unSplitAmt.compareTo(measureBillAmount.add(historySplitAmount)) == 0) { + iterator.remove(); + } + } + + QFilter finalSettlePeriodFilter = new QFilter("bizdate", "<=", this.getLastTimeOfDay(period.getDate("enddate"))); + QFilter billStatusFilter = new QFilter("billstatus", "=", "C"); + DynamicObject[] finalSettles = BusinessDataServiceHelper.load("ec_out_finalsettle", "id", new QFilter[]{projectFilter, finalSettlePeriodFilter, splitCompletedFilter, billStatusFilter, isInCostFilter, (QFilter) onWayFilter.get("finalsettle")}); + DynamicObject[] var77 = finalSettles; + int var74 = finalSettles.length; + + for (int var79 = 0; var79 < var74; ++var79) { + finalSettle = var77[var79]; + splitAmount = BigDecimal.ZERO; + finalSettle = BusinessDataServiceHelper.loadSingle(finalSettle.getPkValue(), "ec_out_finalsettle"); + DynamicObject entry = new DynamicObject(entryDT); + BigDecimal exchangeRate = this.getBillExchangeRate(finalSettle); + entry.set("contract", finalSettle.get("contract")); + entry.set("contractnumber", finalSettle.get("contract.number")); + entry.set("settlenumber", finalSettle.get("billno")); + entry.set("settleid", finalSettle.getPkValue()); + Date date = finalSettle.getDate("bizdate"); + DynamicObject periodByDate = EcPeriodUtils.getPeriodByDate(date, 1L); + QFilter qFilter = new QFilter("id", "=", periodByDate.getLong("id")); + itemEntry = BusinessDataServiceHelper.loadSingle("bd_period", "begindate,enddate,name,number,periodtype.id,periodtype.name,periodtype.number", qFilter.toArray()); + entry.set("settleperiod", itemEntry); + QFilter isInListFilter = new QFilter("contract", "=", finalSettle.getDynamicObject("contract").getPkValue()); + isInListFilter.and(new QFilter("project", "=", finalSettle.getDynamicObject("project").getPkValue())); + isInListFilter.and(new QFilter("isincost", "=", "1")); + isInListFilter.and(new QFilter("issettled", "=", "0")); + DynamicObject[] isInCostList = BusinessDataServiceHelper.load("ec_outcontractmeasure", "listmodelentry,listentry,listentry.listing,listentry.thisamount", isInListFilter.toArray()); + QFilter onTheWayListFilter = new QFilter("contract", "=", finalSettle.getDynamicObject("contract").getPkValue()); + onTheWayListFilter.and(new QFilter("project", "=", finalSettle.getDynamicObject("project").getPkValue())); + onTheWayListFilter.and(new QFilter("isincost", "=", "0")); + onTheWayListFilter.and(new QFilter("issettled", "=", "0")); + QFilter measureOnWayF = (QFilter) onWayFilter.get("measureinfilter"); + DynamicObject[] onTheWayMeasureList = BusinessDataServiceHelper.load("ec_outcontractmeasure", "listmodelentry,listentry,listentry.listing,listentry.thisamount", new QFilter[]{measureOnWayF, onTheWayListFilter}); + noSettleMeasureBills.addAll(Arrays.asList(onTheWayMeasureList)); + splitAmount = this.newSplitDetailByFinalSettle(finalSettle, splitAmount, exchangeRate, noSettleMeasureBills, true, isInCostList, entry); + String settleNumber = finalSettle.getString("billno"); + Set itemList = new HashSet(); + DynamicObjectCollection detailEntries = finalSettle.getDynamicObjectCollection("payitemdetailentry"); + if (detailEntries != null && !detailEntries.isEmpty()) { + Iterator var46 = detailEntries.iterator(); + + while (var46.hasNext()) { +// DynamicObject detailEntry = (DynamicObject)var46.next();//系统代码 + DynamicObject detailEntry1 = (DynamicObject) var46.next();//二开替代 + DynamicObject item = detailEntry1.getDynamicObject("detailpayitem"); + if (item != null) { + itemList.add(item.getPkValue()); + } + + String billType = detailEntry1.getString("referbilltype"); + long billId = detailEntry1.getLong("referbillid"); + QFilter qf = new QFilter("id", "=", billId); + DynamicObject visa; + boolean isNeedSettle; + String settleType; + if (StringUtils.equals(billType, ReferBillTypeEnum.CLAIM.getValue())) { + visa = BusinessDataServiceHelper.loadSingle("ec_outclaimbill", "isneedsettle,issettle,billtype", qf.toArray()); + isNeedSettle = visa.getBoolean("isneedsettle"); + settleType = visa.getString("billtype"); + if (isNeedSettle && StringUtils.equals(settleType, "finalsettle")) { + splitAmount = this.newSplitDetailByClaim(billId, splitAmount, exchangeRate, settleNumber, true, item, entry); + } + } else if (StringUtils.equals(billType, ReferBillTypeEnum.VISA.getValue())) { + visa = BusinessDataServiceHelper.loadSingle("ec_outvisabill", "isneedsettle,issettle,billtype", qf.toArray()); + isNeedSettle = visa.getBoolean("isneedsettle"); + settleType = visa.getString("billtype"); + if (isNeedSettle && StringUtils.equals(settleType, "finalsettle")) { + splitAmount = this.newSplitDetailByVisa(billId, splitAmount, exchangeRate, settleNumber, true, item, entry); + } + } else if (StringUtils.equals(billType, ReferBillTypeEnum.PERFORM.getValue())) { + long entryId = detailEntry1.getLong("referentryid"); + splitAmount = this.newFinalSettleSplitDetailByPerformEntry(billId, entryId, splitAmount, exchangeRate, settleNumber, true, item, entry); + } + } + } + + BigDecimal appAmount = finalSettle.getBigDecimal("appamount"); + entry.set("settleamount", this.valueOfPrecision(appAmount, precision)); + entry.set("splitamount", this.valueOfPrecision(splitAmount, precision)); + entry.set("entrycomment", finalSettle.get("description")); +/* BigDecimal measureBillAmount = appAmount.subtract(splitAmount); + entry.set("measureamount", this.valueOfPrecision(measureBillAmount, precision));*///系统代码 + //二开替代↓ + BigDecimal measureBillAmount1 = appAmount.subtract(splitAmount); + entry.set("measureamount", this.valueOfPrecision(measureBillAmount1, precision)); + //二开替代↑ + entry.set("tosplitamount", this.valueOfPrecision(splitAmount, precision)); + entry.set("splitbilltype", "finalsettle"); + entries.add(entry); + } + + this.getModel().updateEntryCache(entries); + this.getView().updateView("entryentity"); + this.getView().updateView("subentryentity"); + if (entries.isEmpty()) { + this.getView().showTipNotification(ResManager.loadKDString("不存在未分摊的计量、结算、决算数据。", "ContractCostSplitBillPlugin_8", "ec-ecco-formplugin", new Object[0]), 3000); + } else { + this.getView().showSuccessNotification(ResManager.loadKDString("已完成取数分摊。", "ContractCostSplitBillPlugin_9", "ec-ecco-formplugin", new Object[0]), 3000); + } + + } + + @NotNull + protected Date getLastTimeOfDay(Date endDate) { + Calendar calendar = Calendar.getInstance(); + calendar.setTime(endDate); + calendar.set(11, 23); + calendar.set(12, 59); + calendar.set(13, 59); + return calendar.getTime(); + } + + protected Map getOnWayFilter() { + DynamicObject project = (DynamicObject) this.getModel().getValue("project"); + QFilter filter = new QFilter("project", "=", project.getPkValue()); + filter.and(new QFilter("billstatus", "!=", BillStatusEnum.AUDIT.getValue())); + filter.and(new QFilter("id", "!=", this.getModel().getDataEntity().getPkValue())); + String selectPro = "entryentity.settleid,entryentity.splitbilltype"; + DynamicObject[] contractCostBills = BusinessDataServiceHelper.load("ecco_contractcost", selectPro, new QFilter[]{filter}); + Set settleBillIds = new HashSet(16); + Set measureBillIds = new HashSet(16); + Set finalBillIds = new HashSet(16); + DynamicObject[] var8 = contractCostBills; + int var9 = contractCostBills.length; + + label39: + for (int var10 = 0; var10 < var9; ++var10) { + DynamicObject bill = var8[var10]; + DynamicObjectCollection entries = bill.getDynamicObjectCollection("entryentity"); + Iterator var13 = entries.iterator(); + + while (true) { + while (true) { + if (!var13.hasNext()) { + continue label39; + } + + DynamicObject entry = (DynamicObject) var13.next(); + Long settleId = entry.getLong("settleid"); + if (entry.getString("splitbilltype") != null && StringUtils.equals(entry.getString("splitbilltype"), SplitBillTypeEnum.MEASURE.getValue())) { + measureBillIds.add(settleId); + } else if (entry.getString("splitbilltype") != null && StringUtils.equals(entry.getString("splitbilltype"), SplitBillTypeEnum.SETTLE.getValue())) { + settleBillIds.add(settleId); + } else if (entry.getString("splitbilltype") != null && StringUtils.equals(entry.getString("splitbilltype"), "finalsettle")) { + finalBillIds.add(settleId); + } + } + } + } + + QFilter settleFilter = new QFilter("id", "not in", settleBillIds); + QFilter measureFilter = new QFilter("id", "not in", measureBillIds); + QFilter finalFilter = new QFilter("id", "not in", finalBillIds); + QFilter measureInFilter = new QFilter("id", "in", measureBillIds); + HashMap filterMap = new HashMap(2); + filterMap.put(SplitBillTypeEnum.MEASURE.getValue(), measureFilter); + filterMap.put(SplitBillTypeEnum.SETTLE.getValue(), settleFilter); + filterMap.put("finalsettle", finalFilter); + filterMap.put("measureinfilter", measureInFilter); + return filterMap; + } + + protected BigDecimal valueOfPrecision(BigDecimal value, int precision) { + return value == null ? BigDecimal.ZERO : value.setScale(precision, 4); + } + + protected int getAmountPrecision() { + DynamicObject currency = (DynamicObject) this.getModel().getValue("currency"); + return currency != null ? currency.getInt("amtprecision") : 10; + } + + protected BigDecimal getBillExchangeRate(DynamicObject settleBill) { + BigDecimal exchangeRate = BigDecimal.ONE; + boolean isMultiCurrency = settleBill.getBoolean("ismulticurrency"); + if (isMultiCurrency) { + DynamicObject currency = settleBill.getDynamicObject("currency"); + DynamicObject stdCurrency = settleBill.getDynamicObject("stdcurrency"); + DynamicObject exrateTable = settleBill.getDynamicObject("exratetable"); + exchangeRate = settleBill.getBigDecimal("exchangerate"); + DynamicObject thisCurrency = this.getModel().getDataEntity().getDynamicObject("currency"); + if (currency != null && thisCurrency != null) { + if (currency.getPkValue().equals(thisCurrency.getPkValue())) { + exchangeRate = BigDecimal.ONE; + } else if (!stdCurrency.getPkValue().equals(thisCurrency.getPkValue())) { + exchangeRate = CurrencyHelper.getExChangeRate(currency.getLong("id"), stdCurrency.getLong("id"), exrateTable.getLong("id"), new Date()); + } + } + } + + return exchangeRate == null ? BigDecimal.ONE : exchangeRate; + } + + protected BigDecimal newFinalSettleSplitDetailByPerformEntry(long billId, long entryId, BigDecimal splitAmount, BigDecimal exchangeRate, String settleNumber, Boolean autoSplit, DynamicObject item, DynamicObject newEntry) { + if (!QueryServiceHelper.exists("ec_out_performrecords", billId)) { + return splitAmount; + } else { + BigDecimal directionRate = this.getItemRate(item); + DynamicObject performBill = BusinessDataServiceHelper.loadSingle(billId, "ec_out_performrecords"); + DynamicObjectCollection entries = performBill.getDynamicObjectCollection("entryentity"); + if (entries != null && !entries.isEmpty()) { + DynamicObjectCollection subEntries = newEntry.getDynamicObjectCollection("subentryentity"); + int size = subEntries.size(); + DynamicObjectType subEntryDT = subEntries.getDynamicObjectType(); + String settleType = performBill.getString("billtype"); + if (performBill.getBoolean("isneedsettlehead") && StringUtils.equals(settleType, "finalsettle")) { + Iterator var18 = entries.iterator(); + + while (var18.hasNext()) { + DynamicObject entry = (DynamicObject) var18.next(); + if (entry.getLong("id") == entryId) { + int precision = this.getAmountPrecision(); + DynamicObject subEntry = new DynamicObject(subEntryDT); + subEntry.set("subsettlenumber", settleNumber); + subEntry.set("listingname", item.getString("name")); + if (entry.get("cbs") != null) { + subEntry.set("procbs", entry.get("cbs")); + } + + if (entry.get("boq") != null) { + subEntry.set("proboq", entry.get("boq")); + } + + if (entry.get("ca") != null) { + subEntry.set("costaccount", entry.get("ca")); + } + + if (entry.get("unitproject") != null) { + subEntry.set("unitproject", entry.get("unitproject")); + } + + BigDecimal thisAmt = BigDecimal.ZERO; + if (autoSplit) { + thisAmt = entry.getBigDecimal("notaxamount").multiply(exchangeRate).multiply(directionRate); + } + + subEntry.set("amount", this.valueOfPrecision(thisAmt, precision)); + splitAmount = splitAmount.add(this.valueOfPrecision(thisAmt, precision)); + ++size; + subEntry.set("seq", size); + subEntries.add(subEntry); + break; + } + } + } + + return splitAmount; + } else { + return splitAmount; + } + } + } + + protected BigDecimal newSplitDetailByPerformEntry(long billId, long entryId, BigDecimal splitAmount, BigDecimal exchangeRate, String settleNumber, Boolean autoSplit, DynamicObject item, DynamicObject newEntry) { + if (!QueryServiceHelper.exists("ec_out_performrecords", billId)) { + return splitAmount; + } else { + BigDecimal directionRate = this.getItemRate(item); + DynamicObject performBill = BusinessDataServiceHelper.loadSingle(billId, "ec_out_performrecords"); + DynamicObjectCollection entries = performBill.getDynamicObjectCollection("entryentity"); + if (entries != null && !entries.isEmpty()) { + DynamicObjectCollection subEntries = newEntry.getDynamicObjectCollection("subentryentity"); + DynamicObjectType subEntryDT = subEntries.getDynamicObjectType(); + int size = subEntries.size(); + Iterator var17 = entries.iterator(); + + while (var17.hasNext()) { + DynamicObject entry = (DynamicObject) var17.next(); + if (entry.getLong("id") == entryId) { + int precision = this.getAmountPrecision(); + DynamicObject subEntry = new DynamicObject(subEntryDT); + subEntry.set("subsettlenumber", settleNumber); + subEntry.set("listingname", item.getString("name")); + if (entry.get("cbs") != null) { + subEntry.set("procbs", entry.get("cbs")); + } + + if (entry.get("boq") != null) { + subEntry.set("proboq", entry.get("boq")); + } + + if (entry.get("ca") != null) { + subEntry.set("costaccount", entry.get("ca")); + } + + if (entry.get("unitproject") != null) { + subEntry.set("unitproject", entry.get("unitproject")); + } + + BigDecimal thisAmt = BigDecimal.ZERO; + if (autoSplit) { + thisAmt = entry.getBigDecimal("notaxamount").multiply(exchangeRate).multiply(directionRate); + } + + subEntry.set("amount", this.valueOfPrecision(thisAmt, precision)); + splitAmount = splitAmount.add(this.valueOfPrecision(thisAmt, precision)); + ++size; + subEntry.set("seq", size); + subEntries.add(subEntry); + break; + } + } + + return splitAmount; + } else { + return splitAmount; + } + } + } + + protected BigDecimal newSplitDetailByVisa(long billId, BigDecimal splitAmount, BigDecimal exchangeRate, String settleNumber, Boolean autoSplit, DynamicObject item, DynamicObject newEntry) { + if (!QueryServiceHelper.exists("ec_outvisabill", billId)) { + return splitAmount; + } else { + int precision = this.getAmountPrecision(); + BigDecimal directionRate = this.getItemRate(item); + DynamicObject claimBill = BusinessDataServiceHelper.loadSingle(billId, "ec_outvisabill"); + DynamicObjectCollection entries = claimBill.getDynamicObjectCollection("entryentity"); + DynamicObjectCollection subEntries = newEntry.getDynamicObjectCollection("subentryentity"); + DynamicObjectType subEntryDT = subEntries.getDynamicObjectType(); + int size = subEntries.size(); + if (entries != null && !entries.isEmpty()) { + Iterator var20 = entries.iterator(); + + while (var20.hasNext()) { + DynamicObject entry = (DynamicObject) var20.next(); + DynamicObject subEntry = new DynamicObject(subEntryDT); + subEntry.set("subsettlenumber", settleNumber); + subEntry.set("listingname", item.getString("name")); + if (entry.get("cbs") != null) { + subEntry.set("procbs", entry.get("cbs")); + } + + if (entry.get("boq") != null) { + subEntry.set("proboq", entry.get("boq")); + } + + if (entry.get("ca") != null) { + subEntry.set("costaccount", entry.get("ca")); + } + + if (entry.get("unitproject") != null) { + subEntry.set("unitproject", entry.get("unitproject")); + } + + BigDecimal thisAmt = BigDecimal.ZERO; + if (autoSplit) { + thisAmt = entry.getBigDecimal("unitvisaamt").multiply(exchangeRate).multiply(directionRate); + } + + subEntry.set("amount", this.valueOfPrecision(thisAmt, precision)); + splitAmount = splitAmount.add(this.valueOfPrecision(thisAmt, precision)); + ++size; + subEntry.set("seq", size); + subEntries.add(subEntry); + } + } else { + DynamicObject subEntry = new DynamicObject(subEntryDT); + subEntry.set("subsettlenumber", settleNumber); + subEntry.set("listingname", item.getString("name")); + BigDecimal thisAmt = BigDecimal.ZERO; + if (autoSplit) { + thisAmt = claimBill.getBigDecimal("visaamount").multiply(exchangeRate).multiply(directionRate); + } + + subEntry.set("amount", this.valueOfPrecision(thisAmt, precision)); + splitAmount = splitAmount.add(this.valueOfPrecision(thisAmt, precision)); + ++size; + subEntry.set("seq", size); + subEntries.add(subEntry); + } + + return splitAmount; + } + } + + protected BigDecimal newSplitDetailByFinalSettle(DynamicObject bill, BigDecimal splitAmount, BigDecimal exchangeRate, List noSettleMeasure, Boolean autoSplit, DynamicObject[] isInCostList, DynamicObject newEntry) { + int precision = this.getAmountPrecision(); + DynamicObject contract = bill.getDynamicObject("contract"); + Object unitProject = ((DynamicObject) bill.get("contract")).get("unitproject"); + if (contract != null && contract.getBoolean("isonlist")) { + DynamicObject headCbs = contract.getDynamicObject("cbs"); + DynamicObjectCollection modelEntries = bill.getDynamicObjectCollection("listmodelentry"); + if (modelEntries == null || modelEntries.isEmpty()) { + return splitAmount; + } else { + Iterator var13 = modelEntries.iterator(); + + while (true) { + BigDecimal cmpRate; + DynamicObjectCollection entries; + do { + do { + if (!var13.hasNext()) { + return splitAmount; + } + + DynamicObject modelEntry = (DynamicObject) var13.next(); + cmpRate = getCmpRate(modelEntry.getString("cmptype")); + entries = modelEntry.getDynamicObjectCollection("listentry"); + } while (entries == null); + } while (entries.isEmpty()); + + DynamicObjectCollection subEntries = newEntry.getDynamicObjectCollection("subentryentity"); + DynamicObjectType subEntryDT = subEntries.getDynamicObjectType(); + int size = subEntries.size(); + Iterator var20 = entries.iterator(); + + while (var20.hasNext()) { + DynamicObject entry = (DynamicObject) var20.next(); + DynamicObject subEntry = new DynamicObject(subEntryDT); + subEntry.set("subsettlenumber", bill.getString("billno")); + DynamicObject dy = entry.getDynamicObject("listing"); + if (dy != null) { + subEntry.set("listingname", dy.get("name")); + } + + DynamicObject resourceitem = entry.getDynamicObject("listing"); + subEntry.set("resource", dy.getDynamicObject("resourceitem")); + if (null != resourceitem) { + } + + DynamicObject listCbs = entry.getDynamicObject("listcbs"); + listCbs = listCbs == null ? headCbs : listCbs; + if (listCbs != null) { + subEntry.set("procbs", listCbs); + } + + if (entry.get("listboq") != null) { + subEntry.set("proboq", entry.get("listboq")); + } + + if (entry.get("listca") != null) { + subEntry.set("costaccount", entry.get("listca")); + } + + if (entry.get("listunitproject") != null) { + subEntry.set("unitproject", entry.get("listunitproject")); + } + + BigDecimal thisAmt = BigDecimal.ZERO; + if (autoSplit) { + thisAmt = entry.getBigDecimal("listsettlediffamt").multiply(exchangeRate).multiply(cmpRate); + } + + Iterator var27 = noSettleMeasure.iterator(); + + while (var27.hasNext()) { + DynamicObject measure = (DynamicObject) var27.next(); + Object pkValue = dy.getPkValue(); + DynamicObjectCollection listModelEntry = measure.getDynamicObjectCollection("listmodelentry"); + Iterator var31 = listModelEntry.iterator(); + + while (var31.hasNext()) { + DynamicObject listEntry = (DynamicObject) var31.next(); + DynamicObjectCollection dynamicObjectCollection = listEntry.getDynamicObjectCollection("listentry"); + Iterator var34 = dynamicObjectCollection.iterator(); + + while (var34.hasNext()) { + DynamicObject d = (DynamicObject) var34.next(); + if (StringUtils.equals(pkValue.toString(), d.getDynamicObject("listing").getPkValue().toString())) { + thisAmt = thisAmt.subtract(d.getBigDecimal("thisamount").multiply(exchangeRate).multiply(cmpRate)); + } + } + } + } + + DynamicObject[] var38 = isInCostList; + int var39 = isInCostList.length; + + for (int var40 = 0; var40 < var39; ++var40) { + DynamicObject isInCost = var38[var40]; + Object pkValue = dy.getPkValue(); + DynamicObjectCollection listModelEntry = isInCost.getDynamicObjectCollection("listmodelentry"); + Iterator var44 = listModelEntry.iterator(); + + while (var44.hasNext()) { + DynamicObject listEntry = (DynamicObject) var44.next(); + DynamicObjectCollection dynamicObjectCollection = listEntry.getDynamicObjectCollection("listentry"); + Iterator var36 = dynamicObjectCollection.iterator(); + + while (var36.hasNext()) { + DynamicObject d = (DynamicObject) var36.next(); + if (StringUtils.equals(pkValue.toString(), d.getDynamicObject("listing").getPkValue().toString())) { + thisAmt = thisAmt.subtract(d.getBigDecimal("thisamount").multiply(exchangeRate).multiply(cmpRate)); + } + } + } + } + + subEntry.set("amount", this.valueOfPrecision(thisAmt, precision)); + if (thisAmt.intValue() != 0) { + splitAmount = splitAmount.add(this.valueOfPrecision(thisAmt, precision)); + ++size; + subEntry.set("seq", size); + subEntries.add(subEntry); + } + } + } + } + } else { + return splitAmount; + } + } + + protected BigDecimal newSplitDetailByClaim(long billId, BigDecimal splitAmount, BigDecimal exchangeRate, String settleNumber, Boolean autoSplit, DynamicObject item, DynamicObject newEntry) { + if (!QueryServiceHelper.exists("ec_outclaimbill", billId)) { + return splitAmount; + } else { + int precision = this.getAmountPrecision(); + BigDecimal directionRate = this.getItemRate(item); + DynamicObject claimBill = BusinessDataServiceHelper.loadSingle(billId, "ec_outclaimbill"); + DynamicObjectCollection entries = claimBill.getDynamicObjectCollection("entryentity"); + DynamicObjectCollection subEntries = newEntry.getDynamicObjectCollection("subentryentity"); + DynamicObjectType subEntryDT = subEntries.getDynamicObjectType(); + int size = subEntries.size(); + if (entries != null && !entries.isEmpty()) { + Iterator var20 = entries.iterator(); + + while (var20.hasNext()) { + DynamicObject entry = (DynamicObject) var20.next(); + DynamicObject subEntry = new DynamicObject(subEntryDT); + subEntry.set("subsettlenumber", settleNumber); + subEntry.set("listingname", item.getString("name")); + if (entry.get("cbs") != null) { + subEntry.set("procbs", entry.get("cbs")); + } + + if (entry.get("boq") != null) { + subEntry.set("proboq", entry.get("boq")); + } + + if (entry.get("ca") != null) { + subEntry.set("costaccount", entry.get("ca")); + } + + if (entry.get("unitproject") != null) { + subEntry.set("unitproject", entry.get("unitproject")); + } + + BigDecimal thisAmt = BigDecimal.ZERO; + if (autoSplit) { + thisAmt = entry.getBigDecimal("unitclaimamt").multiply(exchangeRate).multiply(directionRate); + } + + subEntry.set("amount", this.valueOfPrecision(thisAmt, precision)); + splitAmount = splitAmount.add(this.valueOfPrecision(thisAmt, precision)); + ++size; + subEntry.set("seq", size); + subEntries.add(subEntry); + } + } else { + DynamicObject subEntry = new DynamicObject(subEntryDT); + subEntry.set("subsettlenumber", settleNumber); + subEntry.set("listingname", item.getString("name")); + BigDecimal thisAmt = BigDecimal.ZERO; + if (autoSplit) { + thisAmt = claimBill.getBigDecimal("claimamount").multiply(exchangeRate).multiply(directionRate); + } + + subEntry.set("amount", this.valueOfPrecision(thisAmt, precision)); + splitAmount = splitAmount.add(this.valueOfPrecision(thisAmt, precision)); + ++size; + subEntry.set("seq", size); + subEntries.add(subEntry); + } + + return splitAmount; + } + } + + protected BigDecimal newSplitDetailByMeasure(DynamicObject measureBill, BigDecimal splitAmount, BigDecimal exchangeRate, boolean autoSplit, Map enterpriseCbsMap, DynamicObject newEntry) { + int precision = this.getAmountPrecision(); + DynamicObject contract = measureBill.getDynamicObject("contract"); + DynamicObject taxRateObject; + if (contract != null && contract.getBoolean("isonlist")) { + DynamicObject headCbs = contract.getDynamicObject("cbs"); + DynamicObjectCollection modelEntries = measureBill.getDynamicObjectCollection("listmodelentry"); + if (modelEntries == null || modelEntries.isEmpty()) { + return splitAmount; + } + + Iterator var26 = modelEntries.iterator(); + + while (true) { + BigDecimal cmpRate; + DynamicObjectCollection entries; + do { + do { + if (!var26.hasNext()) { + return splitAmount; + } + + taxRateObject = (DynamicObject) var26.next(); + cmpRate = getCmpRate(taxRateObject.getString("cmptype")); + entries = taxRateObject.getDynamicObjectCollection("listentry"); + } while (entries == null); + } while (entries.isEmpty()); + + DynamicObjectCollection subEntries = newEntry.getDynamicObjectCollection("subentryentity"); + DynamicObjectType subEntryDT = subEntries.getDynamicObjectType(); + int size = subEntries.size(); + Iterator var33 = entries.iterator(); + + while (var33.hasNext()) { + DynamicObject entry = (DynamicObject) var33.next(); + DynamicObject subEntry = new DynamicObject(subEntryDT); + subEntry.set("subsettlenumber", measureBill.getString("billno")); + subEntry.set("listingname", entry.getString("listingname")); + DynamicObject resourceitem = entry.getDynamicObject("resourceitem"); + subEntry.set("resource", resourceitem); + DynamicObject listCbs; + if (null != resourceitem) { + subEntry.set("costaccount", resourceitem.get("ca")); + listCbs = resourceitem.getDynamicObject("cbs"); + if (null != listCbs) { + subEntry.set("procbs", enterpriseCbsMap.get(String.valueOf(listCbs.getPkValue()))); + } + } + + listCbs = entry.getDynamicObject("listcbs"); + listCbs = listCbs == null ? headCbs : listCbs; + if (listCbs != null) { + subEntry.set("procbs", listCbs); + } + + if (entry.get("listboq") != null) { + subEntry.set("proboq", entry.get("listboq")); + } + + if (entry.get("listca") != null) { + subEntry.set("costaccount", entry.get("listca")); + } + + if (entry.get("listunitproject") != null) { + subEntry.set("unitproject", entry.get("listunitproject")); + } + + BigDecimal thisAmt = BigDecimal.ZERO; + if (autoSplit) { + thisAmt = entry.getBigDecimal("thisamount").multiply(exchangeRate).multiply(cmpRate); + } + + subEntry.set("amount", this.valueOfPrecision(thisAmt, precision)); + splitAmount = splitAmount.add(this.valueOfPrecision(thisAmt, precision)); + ++size; + subEntry.set("seq", size); + subEntries.add(subEntry); + } + } + } else if (contract != null) { + DynamicObjectCollection entries = measureBill.getDynamicObjectCollection("entryentity"); + if (entries == null || entries.isEmpty()) { + return splitAmount; + } + + boolean isMultiRate = measureBill.getBoolean("ismultirate"); + BigDecimal taxRate; + if (isMultiRate) { + taxRate = contract.getBigDecimal("avgtaxrate").divide(BigDecimal.valueOf(100L), RoundingMode.HALF_UP); + } else { + taxRateObject = contract.getDynamicObject("taxrate"); + taxRateObject = BusinessDataServiceHelper.loadSingle(taxRateObject.getPkValue(), "bd_taxrate"); + taxRate = taxRateObject == null ? BigDecimal.ZERO : taxRateObject.getBigDecimal("taxrate"); + taxRate = taxRate.divide(BigDecimal.valueOf(100L), RoundingMode.HALF_UP); + } + + taxRate = taxRate.compareTo(BigDecimal.valueOf(-1L)) == 0 ? BigDecimal.ONE : taxRate.add(BigDecimal.ONE); + DynamicObjectCollection subEntries = newEntry.getDynamicObjectCollection("subentryentity"); + DynamicObjectType subEntryDT = subEntries.getDynamicObjectType(); + int size = subEntries.size(); + Iterator var15 = entries.iterator(); + + while (var15.hasNext()) { + DynamicObject entry = (DynamicObject) var15.next(); + DynamicObject subEntry = new DynamicObject(subEntryDT); + subEntry.set("subsettlenumber", measureBill.getString("billno")); + subEntry.set("listingname", ResManager.loadKDString("计量款", "ContractCostSplitBillPlugin_10", "ec-ecco-formplugin", new Object[0])); + if (entry.get("cbs") != null) { + subEntry.set("procbs", entry.get("cbs")); + } + + if (entry.get("boq") != null) { + subEntry.set("proboq", entry.get("boq")); + } + + if (entry.get("ca") != null) { + subEntry.set("costaccount", entry.get("ca")); + } + + if (entry.get("unitproject") != null) { + subEntry.set("unitproject", entry.get("unitproject")); + } + + BigDecimal thisAmt = BigDecimal.ZERO; + if (autoSplit) { + thisAmt = entry.getBigDecimal("measureoftaxamt").multiply(exchangeRate).divide(taxRate, 10, RoundingMode.HALF_UP); + } + + subEntry.set("amount", this.valueOfPrecision(thisAmt, precision)); + splitAmount = splitAmount.add(this.valueOfPrecision(thisAmt, precision)); + ++size; + subEntry.set("seq", size); + subEntries.add(subEntry); + } + } + + return splitAmount; + } + + protected BigDecimal getItemRate(DynamicObject item) { + String direction = item.getString("direction"); + BigDecimal directionRate = BigDecimal.ONE; + if (DirectionEnum.NON.getValue().equals(direction)) { + directionRate = BigDecimal.ZERO; + } else if (DirectionEnum.SUB.getValue().equals(direction)) { + directionRate = directionRate.negate(); + } + + return directionRate; + } + + protected Map getEnterpriseCbsMap() { + DynamicObject project = (DynamicObject) this.getModel().getValue("project"); + Long projectId = (Long) project.getPkValue(); + QFilter qFilter = new QFilter("project", "=", projectId); + DynamicObject[] proCbs = BusinessDataServiceHelper.load("ec_ecbd_pro_cbs", "id, enterprisecbs", new QFilter[]{qFilter}); + Map map = new HashMap(); + DynamicObject[] var6 = proCbs; + int var7 = proCbs.length; + + for (int var8 = 0; var8 < var7; ++var8) { + DynamicObject cbs = var6[var8]; + DynamicObject enterprisecbs = cbs.getDynamicObject("enterprisecbs"); + if (null != enterprisecbs) { + map.put(String.valueOf(enterprisecbs.getPkValue()), String.valueOf(cbs.getPkValue())); + } + } + + return map; + } + + private static BigDecimal getCmpRate(String cmpType) { + if (cmpType != null && !StringUtils.equals("(+)", cmpType)) { + return StringUtils.equals("(-)", cmpType) ? BigDecimal.valueOf(-1L) : BigDecimal.ZERO; + } else { + return BigDecimal.ONE; + } + } + + protected void setCostAmt() { + BigDecimal costAmt = this.sumAmount("entryentity", "splitamount"); + this.getModel().setValue("costamount", costAmt); + } + + protected BigDecimal sumAmount(String entryKey, String col) { + BigDecimal totalAmt = BigDecimal.ZERO; + int index = this.getModel().getEntryRowCount(entryKey); + + for (int i = 0; i < index; ++i) { + BigDecimal splitAmt = (BigDecimal) this.getModel().getValue(col, i); + totalAmt = totalAmt.add(splitAmt); + } + + return totalAmt; + } + + protected QFilter[] getSplitInfoFilter() { + DynamicObject project = (DynamicObject) this.getModel().getValue("project"); + DynamicObject period = (DynamicObject) this.getModel().getValue("period"); + QFilter projectFilter = new QFilter("project", "=", project.getPkValue()); + QFilter periodFilter = new QFilter("period.enddate", "<=", this.getLastTimeOfDay(period.getDate("enddate"))); + QFilter commonFilter = new QFilter("billstatus", "=", BillStatusEnum.AUDIT.getValue()); + return new QFilter[]{projectFilter, periodFilter, commonFilter}; + } + + protected HashMap getHistorySplitAmount(boolean isMeasure) { + HashMap map = new HashMap(); + QFilter[] qFilters = this.getSplitInfoFilter(); + String selectPro = "entryentity.splitamount,entryentity.settleid,entryentity.splitbilltype"; + DynamicObject[] contCostCols = BusinessDataServiceHelper.load("ecco_contractcost", selectPro, qFilters); + if (contCostCols != null && contCostCols.length > 0) { + DynamicObject[] var6 = contCostCols; + int var7 = contCostCols.length; + + for (int var8 = 0; var8 < var7; ++var8) { + DynamicObject contCost = var6[var8]; + if (!contCost.getPkValue().equals(this.getModel().getDataEntity().getPkValue())) { + DynamicObjectCollection entries = contCost.getDynamicObjectCollection("entryentity"); + if (entries != null && !entries.isEmpty()) { + Iterator var11 = entries.iterator(); + + while (var11.hasNext()) { + DynamicObject entry = (DynamicObject) var11.next(); + if (isMeasure == (entry.getString("splitbilltype") != null && StringUtils.equals(entry.getString("splitbilltype"), SplitBillTypeEnum.MEASURE.getValue()))) { + Long settleId = entry.getLong("settleid"); + BigDecimal splitAmt = entry.getBigDecimal("splitamount"); + if (map.containsKey(settleId)) { + BigDecimal rs = ((BigDecimal) map.get(settleId)).add(splitAmt); + map.put(settleId, rs); + } else { + map.put(settleId, splitAmt); + } + } + } + } + } + } + + return map; + } else { + return map; + } + } + + protected void calUnSplitAmt(int index) { + BigDecimal settleAmt = (BigDecimal) this.getModel().getValue("settleamount", index); + BigDecimal settleSplitAmt = (BigDecimal) this.getModel().getValue("settlesplitamount", index); + BigDecimal splitAmt = (BigDecimal) this.getModel().getValue("splitamount", index); + BigDecimal measureAmount = (BigDecimal) this.getModel().getValue("measureamount", index); + BigDecimal unSplitAmt = settleAmt.subtract(settleSplitAmt).subtract(splitAmt).subtract(measureAmount); + this.getModel().setValue("unsplitamount", unSplitAmt, index); + if (unSplitAmt.compareTo(BigDecimal.ZERO) < 0) { + this.getView().showErrorNotification(String.format(ResManager.loadKDString("合同明细第%s行,剩余金额不允许为负数,请修改分摊金额", "ContractCostSplitBillPlugin_11", "ec-ecco-formplugin", new Object[0]), index + 1)); + } + + } + + public void hyperLinkClick(HyperLinkClickEvent evt) { + String fieldName = evt.getFieldName(); + int rowIndex = evt.getRowIndex(); + if (StringUtils.equals("contractnumber", fieldName)) { + this.contractHyperLink(rowIndex); + } else if (StringUtils.equals("settlenumber", fieldName)) { + this.splitBillHyperLink(rowIndex); + } + + } + + protected void splitBillHyperLink(int rowIndex) { + Object billPk = this.getModel().getValue("settleid", rowIndex); + Map settleParam = new HashMap(); + settleParam.put("pkId", billPk.toString()); + String splitBillType = (String) this.getModel().getValue("splitbilltype", rowIndex); + settleParam.put("formId", StringUtils.equals(splitBillType, SplitBillTypeEnum.MEASURE.getValue()) ? "ec_outcontractmeasure" : (StringUtils.equals(splitBillType, SplitBillTypeEnum.SETTLE.getValue()) ? "ec_out_contract_settle" : "ec_out_finalsettle")); + FormShowParameter param = FormShowParameter.createFormShowParameter(settleParam); + param.getOpenStyle().setShowType(ShowType.MainNewTabPage); + param.setStatus(OperationStatus.VIEW); + this.getView().showForm(param); + } + + protected void contractHyperLink(int rowIndex) { + DynamicObject contract = (DynamicObject) this.getModel().getValue("contract", rowIndex); + Map custormMap = new HashMap(); + custormMap.put("contractId", contract.getPkValue().toString()); + custormMap.put("payDirection", contract.getString("paydirection")); + Map map = new HashMap(); + map.put("formId", "ec_dynamiccontract"); + map.put("customParams", custormMap); + FormShowParameter parameter = FormShowParameter.createFormShowParameter(map); + parameter.getOpenStyle().setShowType(ShowType.MainNewTabPage); + this.getView().showForm(parameter); + } +}