From bfd8bcb346c35f9356ed49a71f343bad35eb1b38 Mon Sep 17 00:00:00 2001 From: xuhaihui <2098865055@qq.com> Date: Fri, 5 Sep 2025 10:58:51 +0800 Subject: [PATCH] =?UTF-8?q?=E6=A0=87=E8=AE=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ContractSettleCommonEditPluginExt.java | 2014 +++++++++++++++++ 1 file changed, 2014 insertions(+) create mode 100644 code/zcdev/zcgj-zcdev-zcdev-pr/src/main/java/zcgj/zcdev/zcdev/pr/plugin/form/ContractSettleCommonEditPluginExt.java diff --git a/code/zcdev/zcgj-zcdev-zcdev-pr/src/main/java/zcgj/zcdev/zcdev/pr/plugin/form/ContractSettleCommonEditPluginExt.java b/code/zcdev/zcgj-zcdev-zcdev-pr/src/main/java/zcgj/zcdev/zcdev/pr/plugin/form/ContractSettleCommonEditPluginExt.java new file mode 100644 index 0000000..816cb90 --- /dev/null +++ b/code/zcdev/zcgj-zcdev-zcdev-pr/src/main/java/zcgj/zcdev/zcdev/pr/plugin/form/ContractSettleCommonEditPluginExt.java @@ -0,0 +1,2014 @@ +// +// Source code recreated from a .class file by IntelliJ IDEA +// (powered by FernFlower decompiler) +// + +package zcgj.zcdev.zcdev.pr.plugin.form; + +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 java.util.function.Function; +import java.util.stream.Collectors; +import kd.bos.bill.OperationStatus; +import kd.bos.dataentity.entity.DataEntityBase; +import kd.bos.dataentity.entity.DynamicObject; +import kd.bos.dataentity.entity.DynamicObjectCollection; +import kd.bos.dataentity.metadata.dynamicobject.DynamicObjectType; +import kd.bos.dataentity.resource.ResManager; +import kd.bos.dataentity.serialization.SerializationUtils; +import kd.bos.dataentity.utils.StringUtils; +import kd.bos.entity.datamodel.ListSelectedRow; +import kd.bos.entity.datamodel.ListSelectedRowCollection; +import kd.bos.entity.datamodel.events.ChangeData; +import kd.bos.entity.datamodel.events.PropertyChangedArgs; +import kd.bos.form.CloseCallBack; +import kd.bos.form.ConfirmCallBackListener; +import kd.bos.form.FormShowParameter; +import kd.bos.form.IPageCache; +import kd.bos.form.MessageBoxOptions; +import kd.bos.form.MessageBoxResult; +import kd.bos.form.ShowFormHelper; +import kd.bos.form.ShowType; +import kd.bos.form.control.EntryGrid; +import kd.bos.form.events.AfterDoOperationEventArgs; +import kd.bos.form.events.BeforeDoOperationEventArgs; +import kd.bos.form.events.ClosedCallBackEvent; +import kd.bos.form.events.HyperLinkClickEvent; +import kd.bos.form.events.HyperLinkClickListener; +import kd.bos.form.events.MessageBoxClosedEvent; +import kd.bos.form.field.BasedataEdit; +import kd.bos.form.field.DateEdit; +import kd.bos.form.field.events.BeforeF7SelectEvent; +import kd.bos.form.field.events.BeforeF7SelectListener; +import kd.bos.form.operate.FormOperate; +import kd.bos.list.ListShowParameter; +import kd.bos.orm.query.QFilter; +import kd.bos.servicehelper.BusinessDataServiceHelper; +import kd.ec.basedata.business.model.cont.ContractSettleTplConstant; +import kd.ec.basedata.business.model.cont.PayItemConstant; +import kd.ec.basedata.common.enums.BillStatusEnum; +import kd.ec.basedata.common.enums.PayDirectionEnum; +import kd.ec.basedata.common.enums.ReferBillTypeEnum; +import kd.ec.basedata.common.utils.OpenPageUtils; +import kd.ec.contract.common.enums.DirectionEnum; +import kd.ec.contract.common.enums.PayItemTypeEnum; +import kd.ec.contract.common.utils.ContractHelper; +import kd.ec.contract.formplugin.AbstractContBillPlugin; +import kd.ec.contract.utils.SettleUpdateAmtUtils; +import org.jetbrains.annotations.NotNull; + +public class ContractSettleCommonEditPluginExt extends AbstractContBillPlugin implements BeforeF7SelectListener, HyperLinkClickListener { + private static final String BILLNO_BILLNAME_CONTRACT_PERIOD = "billno,billname,contract,period,"; + private static final String MEASUREITEM_ID = "506427748873442304"; + private static final long SUPPLIER_ITEM_ID = 1204312316120741888L; + + public ContractSettleCommonEditPluginExt() { + } + + public void beforeBindData(EventObject e) { + super.beforeBindData(e); + this.setHasDetailValue(false); + } + + protected void setHasDetailValue(boolean isDataChange) { + DynamicObjectCollection payItemDetailEntries = this.getModel().getEntryEntity("payitemdetailentry"); + Set detailItemIds = new HashSet(); + if (payItemDetailEntries != null && !payItemDetailEntries.isEmpty()) { + Iterator var4 = payItemDetailEntries.iterator(); + + DynamicObject payItem; + while(var4.hasNext()) { + DynamicObject entry = (DynamicObject)var4.next(); + payItem = entry.getDynamicObject("detailpayitem"); + if (payItem != null) { + detailItemIds.add(payItem.getPkValue()); + } + } + + int rowCount = this.getModel().getEntryRowCount("itementry"); + + for(int i = 0; i < rowCount; ++i) { + payItem = (DynamicObject)this.getModel().getValue("payitem", i); + if (payItem != null && detailItemIds.contains(payItem.getPkValue())) { + this.getModel().setValue("hasdetail", true, i); + if (!isDataChange) { + this.getModel().setDataChanged(false); + } + } else if (payItem != null) { + this.getModel().setValue("hasdetail", false, i); + } + } + } + + } + + public void afterCreateNewData(EventObject e) { + super.afterCreateNewData(e); + this.carryCurrentPeriodAndDate(); + } + + protected void carryCurrentPeriodAndDate() { + 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 bdPeriod = BusinessDataServiceHelper.loadSingle("bd_period", "id,name,begindate,enddate", new QFilter[]{yearFilter, monthFilter}); + if (bdPeriod != null) { + this.getModel().setValue("period", bdPeriod.getPkValue()); + this.getModel().setValue("begindate", bdPeriod.get("begindate")); + this.getModel().setValue("enddate", bdPeriod.get("enddate")); + } + + } + + public void afterBindData(EventObject e) { + super.afterBindData(e); + SettleUpdateAmtUtils.setItemEntrySumAmt(this.getView()); + } + + public void registerListener(EventObject e) { + super.registerListener(e); + BasedataEdit contract = (BasedataEdit)this.getControl("contract"); + if (contract != null) { + contract.addBeforeF7SelectListener(this); + contract.addBeforeF7ViewDetailListener((beforeF7ViewDetailEvent) -> { + beforeF7ViewDetailEvent.setCancel(true); + this.getView().showForm(OpenPageUtils.buildBillShowParam(beforeF7ViewDetailEvent.getPkId(), this.getContractFormId())); + }); + } + + BasedataEdit project = (BasedataEdit)this.getView().getControl("project"); + if (project != null) { + project.addBeforeF7ViewDetailListener((beforeF7ViewDetailEvent) -> { + beforeF7ViewDetailEvent.setCancel(true); + this.getView().showForm(OpenPageUtils.buildBillShowParam(beforeF7ViewDetailEvent.getPkId(), "ec_project")); + }); + } + + EntryGrid payItemDetailEntry = (EntryGrid)this.getControl("payitemdetailentry"); + payItemDetailEntry.addHyperClickListener(this); + } + + public void beforeF7Select(BeforeF7SelectEvent beforeF7SelectEvent) { + String propName = beforeF7SelectEvent.getProperty().getName(); + ListShowParameter showParameter = (ListShowParameter)beforeF7SelectEvent.getFormShowParameter(); + if (StringUtils.equals(propName, "contract")) { + this.beforeContractSelect(showParameter); + } + + } + + protected void beforeContractSelect(ListShowParameter showParameter) { + ContractHelper.getContractByStatus(this.getCurrentFormBillId(), showParameter, this.getPayDirection()); + } + + public void beforeDoOperation(BeforeDoOperationEventArgs args) { + super.beforeDoOperation(args); + FormOperate operate = (FormOperate)args.getSource(); + String operateKey = operate.getOperateKey(); + if (StringUtils.equals(operateKey, "addentry")) { + this.addItemEntry(args); + } else if (StringUtils.equals(operateKey, "deleteitementry")) { + this.beforeDeleteItemEntry(args); + } else if (StringUtils.equals(operateKey, "adddetailentry")) { + this.addDetailEntry(args); + } else if (StringUtils.equals(operateKey, "deleteitemdetail")) { + this.beforeDeleteDetail(args); + } + + } + + protected void beforeDeleteDetail(BeforeDoOperationEventArgs args) { + EntryGrid payItemDetailEntryGrid = (EntryGrid)this.getControl("payitemdetailentry"); + int[] selectRows = payItemDetailEntryGrid.getSelectRows(); + boolean flag = false; + Set deleteReferBillIds = new HashSet(); + List list = new ArrayList(); + + String referBillType; + for(int i = 0; i < selectRows.length; ++i) { + Long referBillNumber = (Long)this.getModel().getValue("referbillid", selectRows[i]); + referBillType = (String)this.getModel().getValue("referbilltype", selectRows[i]); + if (StringUtils.equals("perform", referBillType)) { + deleteReferBillIds.add(referBillNumber); + flag = true; + } else { + list.add(selectRows[i]); + } + } + + if (!deleteReferBillIds.isEmpty()) { + DynamicObjectCollection payItemEntry = this.getModel().getEntryEntity("payitemdetailentry"); + + for(int i = 0; i < payItemEntry.size(); ++i) { + referBillType = ((DynamicObject)payItemEntry.get(i)).getString("referbilltype"); + if (StringUtils.equals("perform", referBillType)) { + long referBillNumber = ((DynamicObject)payItemEntry.get(i)).getLong("referbillid"); + if (deleteReferBillIds.contains(referBillNumber)) { + list.add(i); + } + } + } + } + + if (flag) { + args.setCancel(true); + IPageCache pageCache = this.getPageCache(); + pageCache.put("selectPayItem", SerializationUtils.toJsonString(list)); + this.getView().showConfirm(ResManager.loadKDString("删除履约事务将删除所选择履约事务相同单据的所有履约事务,确认删除吗?", "ContractSettleCommonEditPlugin_4", "ec-contract-formplugin", new Object[0]), MessageBoxOptions.OKCancel, new ConfirmCallBackListener("deletePerform", this)); + } else { + if (this.getPayDirection().equals(PayDirectionEnum.OUT.getValue())) { + this.updateItemEntryWhenDelItemDetail(selectRows); + } else { + this.updateItemEntryWhenDelItemDetailIn(selectRows); + } + + SettleUpdateAmtUtils.calAllTypeAmount(this.getModel()); + } + + } + + public void confirmCallBack(MessageBoxClosedEvent messageBoxClosedEvent) { + super.confirmCallBack(messageBoxClosedEvent); + String callBackId = messageBoxClosedEvent.getCallBackId(); + if (messageBoxClosedEvent.getResult().equals(MessageBoxResult.Yes)) { + if (StringUtils.equals(callBackId, "deletePerform")) { + this.deletePerform(); + } + + } + } + + private void deletePerform() { + String selectPayItem = this.getPageCache().get("selectPayItem"); + List selectPerform = (List)SerializationUtils.fromJsonString(selectPayItem, List.class); + int[] selectRows = new int[selectPerform.size()]; + + for(int i = 0; i < selectPerform.size(); ++i) { + selectRows[i] = (Integer)selectPerform.get(i); + } + + if (this.getPayDirection().equals(PayDirectionEnum.OUT.getValue())) { + this.updateItemEntryWhenDelItemDetail(selectRows); + } else { + this.updateItemEntryWhenDelItemDetailIn(selectRows); + } + + SettleUpdateAmtUtils.calAllTypeAmount(this.getModel()); + this.getModel().deleteEntryRows("payitemdetailentry", selectRows); + this.setHasDetailValue(true); + } + + protected void updateItemEntryWhenDelItemDetailIn(@NotNull int[] selectRows) { + Map ofTaxMap = new HashMap(selectRows.length); + Map amountMap = new HashMap(selectRows.length); + Map taxMap = new HashMap(selectRows.length); + int[] var5 = selectRows; + int var6 = selectRows.length; + + DynamicObject itemPayItem; + DynamicObject detailunitproject; + BigDecimal itemOfTaxAmt; + BigDecimal ofTax; + BigDecimal amount; + for(int var7 = 0; var7 < var6; ++var7) { + int rowIndex = var5[var7]; + itemPayItem = this.getModel().getEntryRowEntity("payitemdetailentry", rowIndex); + detailunitproject = itemPayItem.getDynamicObject("detailpayitem"); + if (detailunitproject != null) { +// DynamicObject detailunitproject = (DynamicObject)itemPayItem.get("detailunitproject");//系统标准 + detailunitproject = (DynamicObject) itemPayItem.get("detailunitproject");//二开修改 + String mapKey = detailunitproject.getString("id") + "," + (detailunitproject != null ? detailunitproject.getString("id") : ""); + itemOfTaxAmt = (BigDecimal)ofTaxMap.getOrDefault(mapKey, BigDecimal.ZERO); + itemOfTaxAmt = itemOfTaxAmt.add(itemPayItem.getBigDecimal("detailoftaxamt") == null ? BigDecimal.ZERO : itemPayItem.getBigDecimal("detailoftaxamt")); + ofTaxMap.put(mapKey, itemOfTaxAmt); + ofTax = (BigDecimal)amountMap.getOrDefault(mapKey, BigDecimal.ZERO); + ofTax = ofTax.add(itemPayItem.getBigDecimal("detailamt") == null ? BigDecimal.ZERO : itemPayItem.getBigDecimal("detailamt")); + amountMap.put(mapKey, ofTax); + amount = (BigDecimal)taxMap.getOrDefault(mapKey, BigDecimal.ZERO); + amount = amount.add(itemPayItem.getBigDecimal("detailtaxamt") == null ? BigDecimal.ZERO : itemPayItem.getBigDecimal("detailtaxamt")); + taxMap.put(mapKey, amount); + } + } + + boolean multiRate = this.isMultiRate(); + DynamicObjectCollection itemEntryCol = this.getModel().getEntryEntity("itementry"); + Iterator iterator = itemEntryCol.iterator(); + + while(true) { + while(true) { + DynamicObject itemEntry; + String uniquekey; + do { + if (!iterator.hasNext()) { + this.getModel().updateEntryCache(itemEntryCol); + this.getView().updateView("itementry"); + return; + } + + itemEntry = (DynamicObject)iterator.next(); + itemPayItem = itemEntry.getDynamicObject("payitem"); + detailunitproject = (DynamicObject)itemEntry.get("itemunitproject"); + uniquekey = itemPayItem.getString("id") + "," + (detailunitproject != null ? detailunitproject.getString("id") : ""); + } while(!ofTaxMap.containsKey(uniquekey)); + + BigDecimal itemDetailOfTaxAmt = (BigDecimal)ofTaxMap.getOrDefault(uniquekey, BigDecimal.ZERO); + itemOfTaxAmt = itemEntry.getBigDecimal("oftaxamount"); + if (itemDetailOfTaxAmt.compareTo(itemOfTaxAmt) == 0 && !StringUtils.equals(itemPayItem.getString("paymentitemtype"), PayItemTypeEnum.FIXED.getValue())) { + iterator.remove(); + } else { + ofTax = itemEntry.getBigDecimal("oftaxamount").subtract(itemDetailOfTaxAmt); + itemEntry.set("oftaxamount", ofTax); + amount = itemEntry.getBigDecimal("amount").subtract((BigDecimal)amountMap.getOrDefault(uniquekey, BigDecimal.ZERO)); + itemEntry.set("amount", amount); + BigDecimal tax = itemEntry.getBigDecimal("taxamt").subtract((BigDecimal)taxMap.getOrDefault(uniquekey, BigDecimal.ZERO)); + itemEntry.set("taxamt", tax); + if (amount != null && amount.compareTo(BigDecimal.ZERO) != 0 && tax != null && multiRate) { + itemEntry.set("rate", tax.multiply(new BigDecimal(100)).divide(amount, 2).setScale(0, RoundingMode.HALF_UP)); + } + + if (itemEntry.getBigDecimal("amount").compareTo(BigDecimal.ZERO) == 0) { + iterator.remove(); + } + } + } + } + } + + protected void updateItemEntryWhenDelItemDetail(@NotNull int[] selectRows) { + Map ofTaxMap = new HashMap(selectRows.length); + Map amountMap = new HashMap(selectRows.length); + Map taxMap = new HashMap(selectRows.length); + int[] var5 = selectRows; + int var6 = selectRows.length; + + DynamicObject itemPayItem; + BigDecimal itemOfTaxAmt; + BigDecimal ofTax; + BigDecimal amount; + BigDecimal tax; + for(int var7 = 0; var7 < var6; ++var7) { + int rowIndex = var5[var7]; + itemPayItem = this.getModel().getEntryRowEntity("payitemdetailentry", rowIndex); + DynamicObject payItem = itemPayItem.getDynamicObject("detailpayitem"); + if (payItem != null) { + itemOfTaxAmt = (BigDecimal)ofTaxMap.getOrDefault(payItem.getPkValue(), BigDecimal.ZERO); + itemOfTaxAmt = itemOfTaxAmt.add(itemPayItem.getBigDecimal("detailoftaxamt") == null ? BigDecimal.ZERO : itemPayItem.getBigDecimal("detailoftaxamt")); + ofTaxMap.put(payItem.getPkValue(), itemOfTaxAmt); + ofTax = (BigDecimal)amountMap.getOrDefault(payItem.getPkValue(), BigDecimal.ZERO); + ofTax = ofTax.add(itemPayItem.getBigDecimal("detailamt") == null ? BigDecimal.ZERO : itemPayItem.getBigDecimal("detailamt")); + amountMap.put(payItem.getPkValue(), ofTax); + amount = (BigDecimal)taxMap.getOrDefault(payItem.getPkValue(), BigDecimal.ZERO); + amount = amount.add(itemPayItem.getBigDecimal("detailtaxamt") == null ? BigDecimal.ZERO : itemPayItem.getBigDecimal("detailtaxamt")); + taxMap.put(payItem.getPkValue(), amount); + if (StringUtils.equals(PayDirectionEnum.OUT.getValue(), this.getPayDirection()) && itemPayItem.getBoolean("ismeasurebymatin")) { + tax = (BigDecimal)ofTaxMap.getOrDefault("760004250343646208", BigDecimal.ZERO); + tax = tax.add(itemPayItem.getBigDecimal("measuretransoftax") == null ? BigDecimal.ZERO : itemPayItem.getBigDecimal("measuretransoftax")); + ofTaxMap.put(Long.valueOf("760004250343646208"), tax); + BigDecimal transAmount = (BigDecimal)amountMap.getOrDefault("760004250343646208", BigDecimal.ZERO); + transAmount = transAmount.add(itemPayItem.getBigDecimal("measuretransamt") == null ? BigDecimal.ZERO : itemPayItem.getBigDecimal("measuretransamt")); + amountMap.put(Long.valueOf("760004250343646208"), transAmount); + BigDecimal transTax = tax.subtract(transAmount); + taxMap.put(Long.valueOf("760004250343646208"), transTax); + } + } + } + + boolean multiRate = this.isMultiRate(); + DynamicObjectCollection itemEntryCol = this.getModel().getEntryEntity("itementry"); + Iterator iterator = itemEntryCol.iterator(); + + while(true) { + while(true) { + DynamicObject itemEntry; + do { + if (!iterator.hasNext()) { + this.getModel().updateEntryCache(itemEntryCol); + this.getView().updateView("itementry"); + return; + } + + itemEntry = (DynamicObject)iterator.next(); + itemPayItem = itemEntry.getDynamicObject("payitem"); + } while(!ofTaxMap.containsKey(itemPayItem.getPkValue())); + + BigDecimal itemDetailOfTaxAmt = (BigDecimal)ofTaxMap.getOrDefault(itemPayItem.getPkValue(), BigDecimal.ZERO); + itemOfTaxAmt = itemEntry.getBigDecimal("oftaxamount"); + if (itemDetailOfTaxAmt.compareTo(itemOfTaxAmt) == 0 && !StringUtils.equals(itemPayItem.getString("paymentitemtype"), PayItemTypeEnum.FIXED.getValue())) { + iterator.remove(); + } else { + ofTax = itemEntry.getBigDecimal("oftaxamount").subtract(itemDetailOfTaxAmt); + itemEntry.set("oftaxamount", ofTax); + amount = itemEntry.getBigDecimal("amount").subtract((BigDecimal)amountMap.getOrDefault(itemPayItem.getPkValue(), BigDecimal.ZERO)); + itemEntry.set("amount", amount); + tax = itemEntry.getBigDecimal("taxamt").subtract((BigDecimal)taxMap.getOrDefault(itemPayItem.getPkValue(), BigDecimal.ZERO)); + itemEntry.set("taxamt", tax); + if (amount != null && amount.compareTo(BigDecimal.ZERO) != 0 && tax != null && multiRate) { + itemEntry.set("rate", tax.multiply(new BigDecimal(100)).divide(amount, 2).setScale(0, RoundingMode.HALF_UP)); + } + } + } + } + } + + protected void addDetailEntry(BeforeDoOperationEventArgs args) { + DynamicObject contract = this.getModel().getDataEntity().getDynamicObject("contract"); + if (contract == null) { + this.getView().showTipNotification(ResManager.loadKDString("请选择合同。", "ContractSettleCommonEditPlugin_5", "ec-contract-formplugin", new Object[0])); + args.setCancel(true); + } else { + FormShowParameter showParameter = new FormShowParameter(); + showParameter.setFormId("ec_itemdetail_f7"); + showParameter.getOpenStyle().setShowType(ShowType.Modal); + showParameter.setCloseCallBack(new CloseCallBack(this, "adddetail")); + this.getView().showForm(showParameter); + } + } + + protected void beforeDeleteItemEntry(BeforeDoOperationEventArgs args) { + EntryGrid control = (EntryGrid)this.getView().getControl("itementry"); + int[] selectRows = control.getSelectRows(); + if (!this.deleteItemEntryValidate(args, selectRows)) { + DynamicObjectCollection payItemDetailEntryCol = this.getModel().getEntryEntity("payitemdetailentry"); + Set deletePayItemSet = new HashSet(selectRows.length); + int[] var6 = selectRows; + int i = selectRows.length; + + for(int var8 = 0; var8 < i; ++var8) { + int rowIndex = var6[var8]; + DynamicObject itemEntryObj = this.getModel().getEntryRowEntity("itementry", rowIndex); + DynamicObject payItem = itemEntryObj.getDynamicObject("payitem"); + if (payItem != null && !payItem.getString("paymentitemtype").equals(PayItemTypeEnum.FIXED.value)) { + deletePayItemSet.add(payItem.getPkValue()); + } + } + + List deleteList = new ArrayList(payItemDetailEntryCol.size()); + + for(i = 0; i < payItemDetailEntryCol.size(); ++i) { + DynamicObject payItemDetailEntryObj = (DynamicObject)payItemDetailEntryCol.get(i); + DynamicObject detailPatItem = payItemDetailEntryObj.getDynamicObject("detailpayitem"); + if (detailPatItem != null && deletePayItemSet.contains(detailPatItem.getPkValue())) { + deleteList.add(i); + } + } + + if (!deleteList.isEmpty()) { + this.getModel().deleteEntryRows("payitemdetailentry", deleteList.stream().mapToInt(Integer::intValue).toArray()); + } + + } + } + + protected boolean deleteItemEntryValidate(BeforeDoOperationEventArgs args, @NotNull int[] selectRows) { + List deleteRows = new ArrayList(); + DynamicObjectCollection itemEntry = this.getModel().getEntryEntity("itementry"); + int[] var5 = selectRows; + int var6 = selectRows.length; + + for(int var7 = 0; var7 < var6; ++var7) { + int rowIndex = var5[var7]; + deleteRows.add(itemEntry.get(rowIndex)); + } + + StringBuilder message = new StringBuilder(" "); + boolean isCancel = false; + boolean isTrans = false; + Iterator var14 = deleteRows.iterator(); + + while(true) { + while(var14.hasNext()) { + DynamicObject row = (DynamicObject)var14.next(); + DynamicObject payItem = (DynamicObject)row.get("payitem"); + if (payItem != null && payItem.getString("paymentitemtype").equals(PayItemTypeEnum.FIXED.value)) { + message.append("“").append(payItem.getString("number")).append("”"); + isCancel = true; + } else if (payItem != null && StringUtils.equals("YFJS", payItem.getString("number"))) { + isTrans = true; + } + } + + if (isCancel) { + this.getView().showTipNotification(String.format(ResManager.loadKDString("不能删除固定项:%s。", "ContractSettleCommonEditPlugin_6", "ec-contract-formplugin", new Object[0]), message)); + args.setCancel(true); + } + + if (isTrans) { + this.getView().showTipNotification(ResManager.loadKDString("不能删除当前运费结算款。", "ContractSettleCommonEditPlugin_7", "ec-contract-formplugin", new Object[0])); + args.setCancel(true); + } + + return isCancel || isTrans; + } + } + + protected void addItemEntry(BeforeDoOperationEventArgs args) { + DynamicObject contract = (DynamicObject)this.getModel().getValue("contract"); + if (contract == null) { + this.getView().showTipNotification(ResManager.loadKDString("请先选择合同。", "ContractSettleCommonEditPlugin_8", "ec-contract-formplugin", new Object[0])); + args.setCancel(true); + } else { + ListShowParameter parameter = ShowFormHelper.createShowListForm("ec_payitem", true, 2); + parameter.setShowUsed(true); + parameter.setShowApproved(true); + int rowCount = this.getModel().getEntryRowCount("itementry"); + List originValue = new ArrayList(); + + for(int index = 0; index < rowCount; ++index) { + DynamicObject payItem = (DynamicObject)this.getModel().getValue("payitem", index); + if (payItem.getString("paymentitemtype").equals(PayItemTypeEnum.CHANGED.value)) { + originValue.add(payItem.getPkValue()); + } + } + + Long contAttrPk = (Long)BusinessDataServiceHelper.loadSingle(contract.getPkValue(), this.getContractFormId()).getDynamicObject("contracttype").getDynamicObject("contattr").getPkValue(); + QFilter notPreFilter = new QFilter("contattr", "=", 0L); + notPreFilter.and(new QFilter("ispreitem", "=", "0")); + notPreFilter.and(new QFilter("status", "=", BillStatusEnum.AUDIT.getValue())); + QFilter preFilter = new QFilter("ispreitem", "=", "1"); + if (!this.isOutSubContract()) { + preFilter.and(PayItemConstant.ID_ENTITY_PK, "!=", 1204312316120741888L); + } + + parameter.getListFilterParameter().getQFilters().add((new QFilter("contattr", "=", contAttrPk)).or(preFilter).or(notPreFilter)); + parameter.getListFilterParameter().getQFilters().add(new QFilter("paymentitemtype", "=", PayItemTypeEnum.CHANGED.value)); + parameter.getListFilterParameter().getQFilters().add(new QFilter("number", "!=", "YFJS")); + parameter.getListFilterParameter().getQFilters().add(new QFilter(PayItemConstant.ID_ENTITY_PK, "not in", originValue)); + CloseCallBack callBack = new CloseCallBack(this, "ec_payitem"); + parameter.setCloseCallBack(callBack); + this.getView().showForm(parameter); + } + } + + protected boolean isOutSubContract() { + if (StringUtils.equals(this.getPayDirection(), PayDirectionEnum.IN.getValue())) { + return false; + } else { + DynamicObject contractAttr = (DynamicObject)this.getModel().getValue("contattr"); + if (contractAttr != null) { + String basicType = contractAttr.getString("basictype"); + return StringUtils.equals("03", basicType); + } else { + return false; + } + } + } + + public void afterDoOperation(AfterDoOperationEventArgs args) { + super.afterDoOperation(args); + String operateKey = args.getOperateKey(); + if (StringUtils.equals(operateKey, "deleteitementry")) { + this.afterDeleteItemEntry(); + } else if (StringUtils.equals(operateKey, "deleteitemdetail")) { + this.setHasDetailValue(true); + } + + } + + protected void afterDeleteItemEntry() { + SettleUpdateAmtUtils.setItemEntrySumAmt(this.getView()); + SettleUpdateAmtUtils.calAllTypeAmount(this.getModel()); + } + + public void closedCallBack(ClosedCallBackEvent closedCallBackEvent) { + super.closedCallBack(closedCallBackEvent); + Object returnData = closedCallBackEvent.getReturnData(); + String actionId = closedCallBackEvent.getActionId(); + if (actionId.equals("ec_payitem") && returnData != null) { + this.payItemCallBack((ListSelectedRowCollection)returnData); + } else if (StringUtils.equals("adddetail", actionId) && returnData != null) { + this.itemDetailCallBack((DynamicObjectCollection)returnData); + } + + } + + protected void itemDetailCallBack(DynamicObjectCollection returnData) { + DynamicObjectCollection payItemDetailCol = this.getModel().getEntryEntity("payitemdetailentry"); + DynamicObjectCollection addItemDetailCol = new DynamicObjectCollection(); + DynamicObjectType payItemDetailType = payItemDetailCol.getDynamicObjectType(); + boolean isOut = StringUtils.equals(PayDirectionEnum.OUT.getValue(), this.getPayDirection()); + boolean isMultiRate = (Boolean)this.getModel().getValue("ismultirate"); + BigDecimal taxRate = BigDecimal.ZERO; + if (!isMultiRate) { + DynamicObject rate = (DynamicObject)this.getModel().getValue("taxrate"); + taxRate = rate == null ? taxRate : rate.getBigDecimal("taxrate").divide(new BigDecimal(100), 10, 4); + } + + if (returnData.size() > 0) { + Iterator var14 = returnData.iterator(); + + while(var14.hasNext()) { + DynamicObject dynamicObject = (DynamicObject)var14.next(); + DynamicObject payItemDetail = new DynamicObject(payItemDetailType); + BigDecimal amount = dynamicObject.getBigDecimal("detailamt"); + BigDecimal ofTax = amount.multiply(BigDecimal.ONE.add(taxRate)); + payItemDetail.set("detailitem", dynamicObject.getString("detailitem")); + payItemDetail.set("detailpayitem", dynamicObject.getDynamicObject("detailpayitem")); + String billType = dynamicObject.getString("referbilltype"); + payItemDetail.set("referbilltype", billType); + if (StringUtils.equals(billType, ReferBillTypeEnum.MATERIAL_OUT.getValue())) { + payItemDetail.set("detailoftaxamt", ofTax); + payItemDetail.set("detailtaxamt", ofTax.subtract(amount)); + } else { + payItemDetail.set("detailoftaxamt", dynamicObject.getBigDecimal("detailoftaxamt")); + payItemDetail.set("detailtaxamt", dynamicObject.getBigDecimal("detailtaxamt")); + } + + payItemDetail.set("detailamt", amount); + payItemDetail.set("referbillnumber", dynamicObject.getString("billnumber")); + payItemDetail.set("referbillid", dynamicObject.get("referbillid")); + payItemDetail.set("referentryid", dynamicObject.get("referentryid")); + if (isOut) { + payItemDetail.set("ismeasurebymatin", dynamicObject.get("ismeasurebymatin")); + payItemDetail.set("measuretransamt", dynamicObject.get("measuretransamt")); + payItemDetail.set("measuretransoftax", dynamicObject.get("measuretransoftax")); + } else { + payItemDetail.set("detailunitproject", dynamicObject.get("unitproject")); + } + + payItemDetailCol.add(payItemDetail); + addItemDetailCol.add(payItemDetail); + } + + this.getModel().updateEntryCache(payItemDetailCol); + this.getView().updateView("payitemdetailentry"); + this.mergeToItemEntry(addItemDetailCol); + } + + SettleUpdateAmtUtils.setItemEntrySumAmt(this.getView()); + } + + protected void mergeToItemEntry(DynamicObjectCollection payItemDetailEntryCol) { + if (payItemDetailEntryCol != null && !payItemDetailEntryCol.isEmpty()) { + DynamicObjectCollection itemEntryCol = this.getModel().getEntryEntity("itementry"); + DynamicObjectType itemEntryType = itemEntryCol.getDynamicObjectType(); + Map> itemAmtMap = new HashMap(); + boolean isOut = StringUtils.equals(PayDirectionEnum.OUT.getValue(), this.getPayDirection()); + boolean isIn = StringUtils.equals(PayDirectionEnum.IN.getValue(), this.getPayDirection()); + DynamicObject contact = (DynamicObject)this.getModel().getValue("contract"); + contact = BusinessDataServiceHelper.loadSingle(contact.getPkValue(), "ec_out_contract"); + DynamicObject taxRate = contact.getDynamicObject("taxrate"); + String mapkey = ""; + Iterator var10 = payItemDetailEntryCol.iterator(); + + while(true) { + DynamicObject payItemDetail; + DynamicObject item; + DynamicObject unitproject; + Long detailupId; + do { + do { + if (!var10.hasNext()) { + boolean multiRate = this.isMultiRate(); + DynamicObject newItemEntry; + DynamicObject payitem; + Iterator var22; + Map.Entry mapEntry; + String key; + if (isOut) { + var22 = itemAmtMap.entrySet().iterator(); + + label157: + while(var22.hasNext()) { + mapEntry = (Map.Entry)var22.next(); + key = (String)mapEntry.getKey(); + Map amtMap = (Map)mapEntry.getValue(); + boolean isExist = false; + Iterator var32 = itemEntryCol.iterator(); + + while(true) { + do { + if (!var32.hasNext()) { + if (!isExist) { +// DynamicObject newItemEntry = new DynamicObject(itemEntryType);//系统标准 + newItemEntry = new DynamicObject(itemEntryType);//二开修改 + newItemEntry.set("payitem", BusinessDataServiceHelper.loadSingle(key, "ec_payitem", "id")); + newItemEntry.set("oftaxamount", amtMap.get("oftaxamt")); + newItemEntry.set("amount", amtMap.get("amt")); + newItemEntry.set("taxamt", amtMap.get("tax")); + if (amtMap.get("amt") != null && BigDecimal.ZERO.compareTo((BigDecimal)amtMap.get("amt")) != 0) { + newItemEntry.set("rate", ((BigDecimal)amtMap.get("tax")).multiply(new BigDecimal(100)).divide((BigDecimal)amtMap.get("amt"), 2).setScale(0, RoundingMode.HALF_UP)); + } + + newItemEntry.set("hasdetail", true); + if (StringUtils.equals("760004250343646208", key)) { + itemEntryCol.add(1, newItemEntry); + } else { + itemEntryCol.add(newItemEntry); + } + } + continue label157; + } + + newItemEntry = (DynamicObject)var32.next(); + payitem = newItemEntry.getDynamicObject("payitem"); + } while(payitem != null && !StringUtils.equals(payitem.getString("id"), String.valueOf(key))); + + isExist = true; + newItemEntry.set("oftaxamount", newItemEntry.getBigDecimal("oftaxamount").add((BigDecimal)amtMap.get("oftaxamt"))); + newItemEntry.set("amount", newItemEntry.getBigDecimal("amount").add((BigDecimal)amtMap.get("amt"))); + newItemEntry.set("taxamt", newItemEntry.getBigDecimal("taxamt").add((BigDecimal)amtMap.get("tax"))); + if (amtMap.get("amt") != null && BigDecimal.ZERO.compareTo((BigDecimal)amtMap.get("amt")) != 0 && (multiRate || StringUtils.equals("760004250343646208", (CharSequence)mapEntry.getKey()))) { + newItemEntry.set("rate", ((BigDecimal)amtMap.get("tax")).multiply(new BigDecimal(100)).divide((BigDecimal)amtMap.get("amt"), 2).setScale(0, RoundingMode.HALF_UP)); + } + + newItemEntry.set("hasdetail", true); + } + } + } else { + var22 = itemAmtMap.entrySet().iterator(); + + label131: + while(true) { + while(true) { + if (!var22.hasNext()) { + break label131; + } + + mapEntry = (Map.Entry)var22.next(); + key = (String)mapEntry.getKey(); + String itemId = key.split(",")[0]; + String unitprojctId = ""; + if (key.split(",").length > 1) { + unitprojctId = key.split(",")[1]; + } + + Map amtMap = (Map)mapEntry.getValue(); + if (itemId.equals("506427748873442304")) { + newItemEntry = new DynamicObject(itemEntryType); + payitem = BusinessDataServiceHelper.loadSingle(Long.valueOf(itemId), "ec_payitem"); + newItemEntry.set("payitem", payitem); + newItemEntry.set("oftaxamount", amtMap.get("oftaxamt")); + newItemEntry.set("amount", amtMap.get("amt")); + newItemEntry.set("taxamt", amtMap.get("tax")); + if (StringUtils.isNotBlank(unitprojctId)) { + newItemEntry.set("itemunitproject", BusinessDataServiceHelper.loadSingle(Long.valueOf(unitprojctId), "ec_ecbd_unitproject")); + } + + if (!this.isMultiRate()) { + newItemEntry.set("rate", taxRate.getBigDecimal("taxrate")); + } + + newItemEntry.set("remark", payitem.getString("description")); + if (amtMap.get("amt") != null && BigDecimal.ZERO.compareTo((BigDecimal)amtMap.get("amt")) != 0 && (multiRate || StringUtils.equals("760004250343646208", (CharSequence)mapEntry.getKey()))) { + newItemEntry.set("rate", ((BigDecimal)amtMap.get("tax")).multiply(new BigDecimal(100)).divide((BigDecimal)amtMap.get("amt"), 2).setScale(0, RoundingMode.HALF_UP)); + } + + newItemEntry.set("hasdetail", true); + Long insertIndex = itemEntryCol.stream().filter((row) -> { + return row.getString("payitem.id").equals("506427748873442304"); + }).count(); + itemEntryCol.add(insertIndex.intValue(), newItemEntry); + } else { + newItemEntry = new DynamicObject(itemEntryType); + newItemEntry.set("payitem", BusinessDataServiceHelper.loadSingle(Long.valueOf(itemId), "ec_payitem", "id")); + newItemEntry.set("oftaxamount", amtMap.get("oftaxamt")); + newItemEntry.set("amount", amtMap.get("amt")); + newItemEntry.set("taxamt", amtMap.get("tax")); + if (amtMap.get("amt") != null && BigDecimal.ZERO.compareTo((BigDecimal)amtMap.get("amt")) != 0) { + newItemEntry.set("rate", ((BigDecimal)amtMap.get("tax")).multiply(new BigDecimal(100)).divide((BigDecimal)amtMap.get("amt"), 2).setScale(0, RoundingMode.HALF_UP)); + } + + newItemEntry.set("hasdetail", true); + if (this.getPayDirection().equals(PayDirectionEnum.IN.getValue())) { + String[] split = key.split(","); + DynamicObject up = null; + if (split.length > 1) { + String uid = split[1]; + if (StringUtils.isNotBlank(uid)) { + up = BusinessDataServiceHelper.loadSingle(Long.valueOf(uid), "ec_ecbd_unitproject"); + } + } + + newItemEntry.set("itemunitproject", up); + } + + if (StringUtils.equals("760004250343646208", key)) { + itemEntryCol.add(1, newItemEntry); + } else { + itemEntryCol.add(newItemEntry); + } + } + } + } + } + + this.getModel().updateEntryCache(itemEntryCol); + this.getView().updateView("itementry"); + SettleUpdateAmtUtils.calAllTypeAmount(this.getModel()); + return; + } + + payItemDetail = (DynamicObject)var10.next(); + item = payItemDetail.getDynamicObject("detailpayitem"); + } while(item == null); + + mapkey = item.getString("id"); + if (!this.getPayDirection().equals(PayDirectionEnum.IN.getValue())) { + break; + } + + DynamicObject detailunitproject = payItemDetail.getDynamicObject("detailunitproject"); + mapkey = item.getString("id") + "," + (detailunitproject == null ? "" : detailunitproject.getString("id")); + unitproject = (DynamicObject)this.getModel().getValue("unitproject"); + detailupId = detailunitproject != null ? detailunitproject.getLong("id") : 0L; + } while(unitproject != null && detailupId != unitproject.getLong("id")); + + BigDecimal tax; + Map amtAmp; + BigDecimal ofTax; + BigDecimal amount; + if (!itemAmtMap.containsKey(mapkey)) { + Map amtMap = new HashMap(); + amtMap.put("oftaxamt", payItemDetail.getBigDecimal("detailoftaxamt")); + amtMap.put("tax", payItemDetail.getBigDecimal("detailtaxamt")); + amtMap.put("amt", payItemDetail.getBigDecimal("detailamt")); + itemAmtMap.put(mapkey, amtMap); + } else { + amtAmp = (Map)itemAmtMap.get(mapkey); + ofTax = ((BigDecimal)amtAmp.get("oftaxamt")).add(payItemDetail.getBigDecimal("detailoftaxamt")); + amount = ((BigDecimal)amtAmp.get("tax")).add(payItemDetail.getBigDecimal("detailtaxamt")); + tax = ((BigDecimal)amtAmp.get("amt")).add(payItemDetail.getBigDecimal("detailamt")); + amtAmp.put("oftaxamt", ofTax); + amtAmp.put("tax", amount); + amtAmp.put("amt", tax); + itemAmtMap.put(mapkey, amtAmp); + } + + if (StringUtils.equals(item.getString("id"), "506427748873442304") && isOut && payItemDetail.getBoolean("ismeasurebymatin")) { + amtAmp = (Map)itemAmtMap.getOrDefault("760004250343646208", new HashMap(3)); + ofTax = (BigDecimal)amtAmp.getOrDefault("oftaxamt", BigDecimal.ZERO); + amount = (BigDecimal)amtAmp.getOrDefault("amt", BigDecimal.ZERO); + ofTax = ofTax.add(payItemDetail.getBigDecimal("measuretransoftax")); + amount = amount.add(payItemDetail.getBigDecimal("measuretransamt")); + tax = ofTax.subtract(amount); + if (ofTax.compareTo(BigDecimal.ZERO) != 0 && amount.compareTo(BigDecimal.ZERO) != 0) { + amtAmp.put("oftaxamt", ofTax); + amtAmp.put("amt", amount); + amtAmp.put("tax", tax); + itemAmtMap.put("760004250343646208", amtAmp); + } + } + } + } + } + + protected void payItemCallBack(ListSelectedRowCollection returnData) { + List selectedIds = new ArrayList(); + List originalIds = new ArrayList(); + Iterator var4 = returnData.iterator(); + + while(var4.hasNext()) { + ListSelectedRow row = (ListSelectedRow)var4.next(); + selectedIds.add(row.getPrimaryKeyValue()); + } + + DynamicObjectCollection entries = this.getModel().getEntryEntity("itementry"); + Iterator var13 = entries.iterator(); + + DynamicObject taxRateObject; + while(var13.hasNext()) { + taxRateObject = (DynamicObject)var13.next(); + DynamicObject payItem = taxRateObject.getDynamicObject("payitem"); + if (payItem.getString("paymentitemtype").equals(PayItemTypeEnum.CHANGED.value)) { + originalIds.add(payItem.getPkValue()); + } + } + + selectedIds.removeAll(originalIds); + boolean isMultiRate = (Boolean)this.getModel().getValue("ismultirate"); + taxRateObject = (DynamicObject)this.getModel().getValue("taxrate"); + if (!selectedIds.isEmpty()) { + int[] indexArray = this.getModel().batchCreateNewEntryRow("itementry", selectedIds.size()); + + for(int i = 0; i < selectedIds.size(); ++i) { + Object pk = selectedIds.get(i); + int row = indexArray[i]; + this.getModel().setValue("payitem", pk, row); + DynamicObject payItem = (DynamicObject)this.getModel().getValue("payitem", row); + this.getModel().setValue("remark", payItem.getString("description"), row); + if (!isMultiRate) { + this.getModel().setValue("rate", taxRateObject.getBigDecimal("taxrate"), row); + } + + this.fillItemEntryCbs(row); + if (payItem.getBoolean("iscompute")) { + this.reComputePayItem(row, row); + } + } + + SettleUpdateAmtUtils.setItemEntrySumAmt(this.getView()); + SettleUpdateAmtUtils.calAllTypeAmount(this.getModel()); + } + + } + + protected void reComputePayItem(int rowIndex, int rowCount) { + DynamicObject payItem = (DynamicObject)this.getModel().getValue("payitem", rowIndex); + BigDecimal amount = BigDecimal.ZERO; + BigDecimal ofTaxAmount = BigDecimal.ZERO; + BigDecimal taxAmt = BigDecimal.ZERO; + DynamicObjectCollection formulas = BusinessDataServiceHelper.loadSingle(payItem.getPkValue(), "ec_payitem").getDynamicObjectCollection("entryentity"); + if (formulas != null && !formulas.isEmpty()) { + Iterator var8 = formulas.iterator(); + + while(true) { + DynamicObject formula; + DynamicObject item; + do { + if (!var8.hasNext()) { + this.getModel().setValue("oftaxamount", ofTaxAmount, rowIndex); + this.getModel().setValue("amount", amount, rowIndex); + this.getModel().setValue("taxamt", taxAmt, rowIndex); + return; + } + + formula = (DynamicObject)var8.next(); + item = formula.getDynamicObject("item"); + } while(item == null); + + Object formulaItemPk = item.getPkValue(); + BigDecimal formulaPercent = formula.getBigDecimal("percent"); + String operation = formula.getString("operation"); + + for(int index = 0; index < rowCount; ++index) { + Object sourcePk = ((DynamicObject)this.getModel().getValue("payitem", index)).getPkValue(); + if (formulaItemPk.equals(sourcePk)) { + BigDecimal sourceAmount = (BigDecimal)this.getModel().getValue("amount", index); + BigDecimal sourceOfTaxAmount = (BigDecimal)this.getModel().getValue("oftaxamount", index); + BigDecimal sourceTaxAmt = (BigDecimal)this.getModel().getValue("taxamt", index); + if (operation.equals("01")) { + amount = amount.add(sourceAmount.multiply(formulaPercent)); + ofTaxAmount = ofTaxAmount.add(sourceOfTaxAmount.multiply(formulaPercent)); + taxAmt = taxAmt.add(sourceTaxAmt.multiply(formulaPercent)); + } else { + amount = amount.subtract(sourceAmount.multiply(formulaPercent)); + ofTaxAmount = ofTaxAmount.subtract(sourceOfTaxAmount.multiply(formulaPercent)); + taxAmt = taxAmt.subtract(sourceTaxAmt.multiply(formulaPercent)); + } + } + } + } + } + } + + protected void fillItemEntryCbs(int row) { + DynamicObject cbs = this.getNeedFillCbs(); + if (cbs != null && !(Boolean)this.getModel().getValue("isonlist")) { + this.getModel().setValue("itemcbs", cbs.getPkValue(), row); + } + + } + + protected DynamicObject getNeedFillCbs() { + String formId = this.getView().getFormShowParameter().getFormId(); + if (StringUtils.equals("ec_in_contract_settle", formId)) { + return null; + } else { + DynamicObject project = this.getModel().getDataEntity().getDynamicObject("project"); + DynamicObject contract = this.getModel().getDataEntity().getDynamicObject("contract"); + if (project != null && contract != null) { + boolean isBudgetControl = project.getBoolean("budgetcontrol"); + String controlModel = project.getString("costcontrolmodel"); + if (isBudgetControl && controlModel.contains("1")) { + return contract.getDynamicObject("cbs"); + } + } + + return null; + } + } + + public void propertyChanged(PropertyChangedArgs e) { + String name = e.getProperty().getName(); + ChangeData changeData = e.getChangeSet()[0]; + DynamicObject contract; + if (StringUtils.equals(name, "contract")) { + contract = (DynamicObject)changeData.getNewValue(); + this.clearUnitproject(); + this.contractChanged(contract); + } else if (StringUtils.equals(name, "period")) { + this.periodChanged(changeData); + } else if (!StringUtils.equals(name, "begindate") && !StringUtils.equals(name, "enddate")) { + if (StringUtils.equals(name, "issettlebymatin")) { + this.isSettleByMaterialInChanged(changeData); + } else if (StringUtils.equals(name, "issettlebyreconc")) { + this.isSettleByReconciliationChanged(changeData); + } else if (StringUtils.equals(name, "oftaxamount")) { + this.ofTaxAmountChanged(changeData); + } else if (StringUtils.equals(name, "amount")) { + this.amountChanged(changeData); + } else if (StringUtils.equals(name, "rate")) { + this.rateChanged(changeData); + } else if (StringUtils.equals("unitproject", name)) { + contract = (DynamicObject)this.getModel().getValue("contract"); + this.contractChanged(contract); + } + } else { + this.setDateEditMinAndMaxDate(); + } + + } + + protected void rateChanged(ChangeData changeData) { + int rowIndex = changeData.getRowIndex(); + boolean isMultiRate = (Boolean)this.getModel().getValue("ismultirate"); + BigDecimal ofTaxAmount = (BigDecimal)this.getModel().getValue("oftaxamount", rowIndex); + BigDecimal amount = (BigDecimal)this.getModel().getValue("amount", rowIndex); + BigDecimal taxRate = (BigDecimal)changeData.getNewValue(); + String ignoreRateChanged = this.getPageCache().get("ignoreRateChanged"); + if (ignoreRateChanged != null) { + this.getPageCache().remove("ignoreRateChanged"); + } else { + if (isMultiRate) { + BigDecimal rate = BigDecimal.ONE.add(taxRate.divide(BigDecimal.valueOf(100L), 10, RoundingMode.HALF_UP)); + BigDecimal taxAmount; + if (ofTaxAmount.compareTo(BigDecimal.ZERO) != 0) { + amount = ofTaxAmount.divide(rate, 6, 4); + taxAmount = ofTaxAmount.subtract(amount); + this.getModel().setValue("taxamt", taxAmount, rowIndex); + this.getModel().setValue("amount", amount, rowIndex); + } else { + ofTaxAmount = amount.multiply(rate); + taxAmount = ofTaxAmount.subtract(amount); + this.getModel().setValue("taxamt", taxAmount, rowIndex); + this.getModel().setValue("oftaxamount", ofTaxAmount, rowIndex); + } + } + + } + } + + protected void amountChanged(ChangeData changeData) { + int rowIndex = changeData.getRowIndex(); + if (this.isNotNonDirection(rowIndex)) { + boolean isMultiRate = (Boolean)this.getModel().getValue("ismultirate"); + BigDecimal ofTaxAmount = (BigDecimal)this.getModel().getValue("oftaxamount", rowIndex); + BigDecimal amount = (BigDecimal)this.getModel().getValue("amount", rowIndex); + if (isMultiRate && (BigDecimal.ZERO.compareTo(ofTaxAmount) == 0 || BigDecimal.ZERO.compareTo(amount) == 0)) { + this.getModel().setValue("rate", 0, rowIndex); + this.getModel().setValue("taxamt", BigDecimal.ZERO, rowIndex); + this.getModel().setValue("oftaxamount", amount, rowIndex); + return; + } + + BigDecimal taxAmt = ofTaxAmount.subtract(amount); + if (BigDecimal.ZERO.compareTo(amount) != 0 && isMultiRate) { + BigDecimal taxRate = taxAmt.multiply(BigDecimal.valueOf(100L)).divide(amount, 4, 4); + this.getModel().setValue("rate", taxRate, rowIndex); + } + + this.getModel().setValue("taxamt", taxAmt, rowIndex); + this.checkNeedReComputeItem(rowIndex); + SettleUpdateAmtUtils.setItemEntrySumAmt(this.getView()); + SettleUpdateAmtUtils.calAllTypeAmount(this.getModel()); + } + + } + + protected void ofTaxAmountChanged(ChangeData changeData) { + int rowIndex = changeData.getRowIndex(); + if (this.isNotNonDirection(rowIndex)) { + BigDecimal ofTaxAmount = (BigDecimal)this.getModel().getValue("oftaxamount", rowIndex); + BigDecimal rate = (BigDecimal)this.getModel().getValue("rate", rowIndex); + BigDecimal amount = ofTaxAmount.divide(BigDecimal.ONE.add(rate.divide(BigDecimal.valueOf(100L), 10, RoundingMode.HALF_UP)), 10, 4); + BigDecimal taxAmount = ofTaxAmount.subtract(amount); + this.getModel().setValue("taxamt", taxAmount, rowIndex); + this.getModel().setValue("amount", amount, rowIndex); + this.checkNeedReComputeItem(rowIndex); + SettleUpdateAmtUtils.setItemEntrySumAmt(this.getView()); + SettleUpdateAmtUtils.calAllTypeAmount(this.getModel()); + } + + } + + public void checkNeedReComputeItem(int rowIndex) { + Object changedPayItemPk = ((DynamicObject)this.getModel().getValue("payitem", rowIndex)).getPkValue(); + int rowCount = this.getModel().getEntryRowCount("itementry"); + + for(int index = 0; index < rowCount; ++index) { + DynamicObject payItem = (DynamicObject)this.getModel().getValue("payitem", index); + if (payItem != null && payItem.getBoolean("iscompute")) { + DynamicObjectCollection formulas = BusinessDataServiceHelper.loadSingle(payItem.getPkValue(), "ec_payitem").getDynamicObjectCollection("entryentity"); + Iterator var7 = formulas.iterator(); + + while(var7.hasNext()) { + DynamicObject formula = (DynamicObject)var7.next(); + Object pk = formula.getDynamicObject("item").getPkValue(); + if (changedPayItemPk.equals(pk)) { + this.reComputePayItem(index, rowCount); + break; + } + } + } + } + + } + + protected boolean isNotNonDirection(int rowIndex) { + DynamicObject itemEntry = this.getModel().getEntryRowEntity("itementry", rowIndex); + if (itemEntry == null) { + return false; + } else { + DynamicObject payItem = itemEntry.getDynamicObject("payitem"); + if (payItem == null) { + return false; + } else { + String direction = payItem.getString("direction"); + return !StringUtils.equals(direction, DirectionEnum.NON.getValue()); + } + } + } + + protected void isSettleByMaterialInChanged(ChangeData changeData) { + if ((Boolean)changeData.getNewValue()) { + this.deleteDetailsByReferBillType(false, ReferBillTypeEnum.MEASURE.getValue()); + } else { + this.reloadMeasureDetails(); + } + + } + + protected void isSettleByReconciliationChanged(ChangeData changeData) { + int entryRowCount = this.getModel().getEntryRowCount("itementry"); + DynamicObject rate = (DynamicObject)this.getModel().getValue("taxrate"); + if (entryRowCount > 0) { + this.getModel().setValue("amount", 0, 0); + this.getModel().setValue("oftaxamount", 0, 0); + this.getModel().setValue("taxamt", 0, 0); + if (rate != null) { + this.getModel().setValue("rate", rate.getBigDecimal("taxrate"), 0); + } + } + + if ((Boolean)changeData.getNewValue()) { + this.deleteDetailsByReferBillType(false, ReferBillTypeEnum.MEASURE.getValue()); + } else { + this.reloadMeasureDetails(); + } + + } + + protected void setDateEditMinAndMaxDate() { + DynamicObject period = (DynamicObject)this.getModel().getValue("period"); + DateEdit beginDateEdit = (DateEdit)this.getControl("begindate"); + if (period != null) { + beginDateEdit.setMinDate(period.getDate("begindate")); + beginDateEdit.setMaxDate(period.getDate("enddate")); + } + + Date endDate = (Date)this.getModel().getValue("enddate"); + if (endDate != null) { + beginDateEdit.setMaxDate(endDate); + } + + DateEdit endDateEdit = (DateEdit)this.getControl("enddate"); + if (period != null) { + endDateEdit.setMinDate(period.getDate("begindate")); + endDateEdit.setMaxDate(period.getDate("enddate")); + } + + Date beginDate = (Date)this.getModel().getValue("begindate"); + if (beginDate != null) { + endDateEdit.setMinDate(beginDate); + } + + } + + protected void periodChanged(ChangeData changeData) { + DynamicObject period = (DynamicObject)changeData.getNewValue(); + this.getModel().setValue("begindate", period == null ? null : period.getDate("begindate")); + this.getModel().setValue("enddate", period == null ? null : period.getDate("enddate")); + this.reloadMeasureDetails(); + this.reloadMaterialOutDetails(); + } + + protected void reloadMaterialOutDetails() { + DynamicObjectCollection addEntry = this.updateMaterialOutDetails(); + if (addEntry != null) { + this.mergeToItemEntry(addEntry); + } + + SettleUpdateAmtUtils.setItemEntrySumAmt(this.getView()); + } + + protected void reloadMeasureDetails() { + DynamicObjectCollection addEntry = this.updateContractMeasureDetails(); + if (addEntry != null) { + this.mergeToItemEntry(addEntry); + } + + SettleUpdateAmtUtils.setItemEntrySumAmt(this.getView()); + } + + protected void contractChanged(DynamicObject contract) { + contract = contract == null ? null : BusinessDataServiceHelper.loadSingle(contract.getPkValue(), "ec_out_contract"); + this.initBasicInfoByContract(contract); + this.initPayItemEntryByContract(contract); + this.initPayItemDetailEntry(); + } + + private void clearUnitproject() { + if (this.getPayDirection().equals(PayDirectionEnum.IN.getValue())) { + this.getModel().setValue("unitproject", (Object)null); + } + + } + + protected void initPayItemDetailEntry() { + this.updateItemDetailEntry(); + this.updateContractMeasureDetails(); + this.updateMaterialOutDetails(); + DynamicObjectCollection entryCollection = this.getModel().getEntryEntity("payitemdetailentry"); + this.mergeToItemEntry(entryCollection); + this.fixedNeedReComputeItem(); + SettleUpdateAmtUtils.setItemEntrySumAmt(this.getView()); + } + + protected DynamicObjectCollection updateMaterialOutDetails() { + if (!this.isOutSubContract()) { + return null; + } else { + DynamicObject settleBill = this.getModel().getDataEntity(); + DynamicObject contract = settleBill.getDynamicObject("contract"); + DynamicObject period = settleBill.getDynamicObject("period"); + if (contract != null && period != null) { + QFilter contractFilter = new QFilter("contract", "=", contract.getPkValue()); + QFilter billStatusFilter = new QFilter("billstatus", "=", BillStatusEnum.AUDIT.getValue()); + QFilter periodFilter = new QFilter("period.number", "=", period.getString("number")); + QFilter costTypeFilter = new QFilter("costtype", "=", "b"); + QFilter isNotSettleFilter = new QFilter("issettled", "=", "0"); + QFilter typeFilter = new QFilter("matbilltype", "=", "materialout"); + QFilter notUseFilter = this.getNotUseMaterialOutFilter(contract, period); + QFilter[] materialOutFilters = new QFilter[]{typeFilter, contractFilter, billStatusFilter, periodFilter, costTypeFilter, isNotSettleFilter, notUseFilter}; + DynamicObject[] materialOutBills = BusinessDataServiceHelper.load("ecma_materialoutbill", "id,billname,settleamt,auditdate,billno", materialOutFilters); + return this.updateMaterialOutBillDataToEntry(materialOutBills); + } else { + return null; + } + } + } + + protected DynamicObjectCollection updateMaterialOutBillDataToEntry(DynamicObject[] materialOutBills) { + this.deleteDetailsByReferBillType(true, ReferBillTypeEnum.MATERIAL_OUT.getValue()); + if (materialOutBills != null && materialOutBills.length != 0) { + DynamicObjectCollection entryCollection = this.getModel().getEntryEntity("payitemdetailentry"); + DynamicObjectType entryType = entryCollection.getDynamicObjectType(); + DynamicObjectCollection addEntry = new DynamicObjectCollection(); + DynamicObject materialOutItem = BusinessDataServiceHelper.loadSingle(1204312316120741888L, "ec_payitem"); + boolean isMultiRate = (Boolean)this.getModel().getValue("ismultirate"); + BigDecimal taxRate = BigDecimal.ZERO; + if (!isMultiRate) { + DynamicObject rate = (DynamicObject)this.getModel().getValue("taxrate"); + taxRate = rate == null ? taxRate : rate.getBigDecimal("taxrate").divide(new BigDecimal(100), 10, 4); + } + + DynamicObject[] var15 = materialOutBills; + int var9 = materialOutBills.length; + + for(int var10 = 0; var10 < var9; ++var10) { + DynamicObject materialOutBill = var15[var10]; + DynamicObject entryObj = new DynamicObject(entryType); + BigDecimal amount = materialOutBill.getBigDecimal("settleamt"); + BigDecimal ofTax = amount.multiply(BigDecimal.ONE.add(taxRate)); + entryObj.set("detailitem", materialOutBill.getString("billname")); + entryObj.set("detailpayitem", materialOutItem); + entryObj.set("detailoftaxamt", ofTax); + entryObj.set("detailtaxamt", ofTax.subtract(amount)); + entryObj.set("detailamt", amount); + entryObj.set("detailauditdate", materialOutBill.getDate("auditdate")); + entryObj.set("referbillnumber", materialOutBill.getString("billno")); + entryObj.set("referbilltype", ReferBillTypeEnum.MATERIAL_OUT.getValue()); + entryObj.set("referbillid", materialOutBill.getPkValue()); + entryCollection.add(entryObj); + addEntry.add(entryObj); + } + + this.sortDetailEntry(entryCollection); + this.getModel().updateEntryCache(entryCollection); + this.getView().updateView("payitemdetailentry"); + return addEntry; + } else { + return null; + } + } + + protected void deleteDetailsByReferBillType(boolean isRecountToItemEntry, String referBillType) { + List deleteRows = new ArrayList(); + int rowCount = this.getModel().getEntryRowCount("payitemdetailentry"); + + for(int i = 0; i < rowCount; ++i) { + DynamicObject entry = this.getModel().getEntryRowEntity("payitemdetailentry", i); + if (StringUtils.equals(referBillType, entry.getString("referbilltype"))) { + deleteRows.add(i); + } + } + + if (isRecountToItemEntry) { + this.updateItemEntryWhenDelItemDetail(deleteRows.stream().mapToInt(Integer::intValue).toArray()); + SettleUpdateAmtUtils.calAllTypeAmount(this.getModel()); + SettleUpdateAmtUtils.setItemEntrySumAmt(this.getView()); + } + + this.getModel().deleteEntryRows("payitemdetailentry", deleteRows.stream().mapToInt(Integer::intValue).toArray()); + this.getModel().updateCache(); + } + + protected QFilter getNotUseMaterialOutFilter(DynamicObject period, DynamicObject contract) { + QFilter qFilter = new QFilter("contract", "=", contract.getPkValue()); + qFilter.and(new QFilter("billstatus", "!=", BillStatusEnum.AUDIT.getValue())); + qFilter.and(new QFilter("period.number", "=", period.getString("number"))); + qFilter.and(new QFilter(ContractSettleTplConstant.ID_ENTITY_PK, "!=", this.getModel().getDataEntity().getPkValue())); + DynamicObject[] settleBills = BusinessDataServiceHelper.load("ec_out_contract_settle", "id", new QFilter[]{qFilter}); + Set materialOutBillIds = new HashSet(); + DynamicObject[] var6 = settleBills; + int var7 = settleBills.length; + + for(int var8 = 0; var8 < var7; ++var8) { + DynamicObject settleBill = var6[var8]; + settleBill = BusinessDataServiceHelper.loadSingle(settleBill.getPkValue(), "ec_out_contract_settle"); + DynamicObjectCollection entries = settleBill.getDynamicObjectCollection("payitemdetailentry"); + Iterator var11 = entries.iterator(); + + while(var11.hasNext()) { + DynamicObject entry = (DynamicObject)var11.next(); + if (StringUtils.equals(entry.getString("referbilltype"), ReferBillTypeEnum.MATERIAL_OUT.getValue())) { + materialOutBillIds.add(entry.getLong("referbillid")); + } + } + } + + if (materialOutBillIds.isEmpty()) { + return new QFilter("id", "!=", 0L); + } else { + return new QFilter("id", "not in", materialOutBillIds); + } + } + + protected void fixedNeedReComputeItem() { + DynamicObjectCollection itementry = this.getModel().getEntryEntity("itementry"); + + for(int i = 0; i < itementry.size(); ++i) { + if (this.isNotNonDirection(i)) { + this.checkNeedReComputeItem(i); + } + } + + this.getView().updateView("itementry"); + } + + protected DynamicObjectCollection updateContractMeasureDetails() { + DynamicObject settleBill = this.getModel().getDataEntity(); + DynamicObject contract = settleBill.getDynamicObject("contract"); + DynamicObject period = settleBill.getDynamicObject("period"); + boolean isOutContract = StringUtils.equals(PayDirectionEnum.OUT.getValue(), this.getPayDirection()); + if (contract == null || period == null || !isOutContract && !contract.getBoolean("isonlist") || isOutContract && settleBill.getBoolean("issettlebymatin") || isOutContract && settleBill.getBoolean("issettlebyreconc")) { + return null; + } else { + QFilter contractFilter = new QFilter("contract", "=", contract.getPkValue()); + QFilter billStatusFilter = new QFilter("billstatus", "=", BillStatusEnum.AUDIT.getValue()); + QFilter periodFilter = new QFilter("period.enddate", "<=", period.getDate("enddate")); + QFilter isNotSettleFilter = new QFilter("issettled", "=", "0"); + QFilter notUseFilter = this.getNotUseFilter(contract, ReferBillTypeEnum.MEASURE.getValue()); + String paydirection = (String)this.getModel().getValue("paydirection"); + String formId = "ec_outcontractmeasure"; + String others = ""; + if (PayDirectionEnum.IN.getValue().equals(paydirection)) { + formId = "ec_incontractmeasure"; + others = ",unitproject,listmodelentry,listentry,entryunitproject,thisamount,thistax,thisoftaxmount"; + } + + QFilter[] measureFilters = new QFilter[]{contractFilter, billStatusFilter, periodFilter, isNotSettleFilter, notUseFilter}; + DynamicObject[] measureBills = BusinessDataServiceHelper.load(formId, "billno,billname,contract,period,ismeasurebymatin,materialinentry,materialinentry.transtaxamount,materialinentry.transnotaxamount,materialinentry.istranssettle,measureoftax,measureamount,measuretax,creator,createtime,auditor,auditdate" + others, measureFilters); + return this.updateMeasureBillDataToEntry(measureBills); + } + } + + protected QFilter getNotUseFilter(DynamicObject contract, String billType) { + String formId = this.getSettleFormId(); + QFilter qFilter = new QFilter("contract", "=", contract.getPkValue()); + qFilter.and(new QFilter(ContractSettleTplConstant.ID_ENTITY_PK, "!=", this.getModel().getDataEntity().getPkValue())); + DynamicObject[] settleBills = BusinessDataServiceHelper.load(formId, "id", new QFilter[]{qFilter}); + Set measureBillSet = new HashSet(); + Map> ret = new HashMap(); + DynamicObject[] var8 = settleBills; + int var9 = settleBills.length; + + label67: + for(int var10 = 0; var10 < var9; ++var10) { + DynamicObject settleBill = var8[var10]; + settleBill = BusinessDataServiceHelper.loadSingle(settleBill.getPkValue(), formId); + DynamicObjectCollection entries = settleBill.getDynamicObjectCollection("payitemdetailentry"); + Iterator var13 = entries.iterator(); + + while(true) { + while(true) { + DynamicObject entry; + do { + do { + if (!var13.hasNext()) { + continue label67; + } + + entry = (DynamicObject)var13.next(); + } while(!StringUtils.equals(entry.getString("referbilltype"), billType)); + + if (!StringUtils.equals(ReferBillTypeEnum.MEASURE.getValue(), billType) && !StringUtils.equals(ReferBillTypeEnum.PERFORM.getValue(), billType)) { + measureBillSet.add(entry.getLong("referbillid")); + } + + if (StringUtils.equals(ReferBillTypeEnum.PERFORM.getValue(), billType)) { + measureBillSet.add(entry.getLong("referentryid")); + } + } while(!StringUtils.equals(ReferBillTypeEnum.MEASURE.getValue(), billType)); + + if (this.getPayDirection().equals(PayDirectionEnum.IN.getValue())) { + Long measureId = entry.getLong("referbillid"); + Long eUnitId = entry.getLong("detailunitproject_id"); + Set orDefault = (Set)ret.getOrDefault(measureId, new HashSet()); + orDefault.add(eUnitId); + ret.put(measureId, orDefault); + DynamicObject measureBill = BusinessDataServiceHelper.loadSingle(measureId, "ec_incontractmeasure"); + DynamicObjectCollection listmodelentry = measureBill.getDynamicObjectCollection("listmodelentry"); + Set curUnitProIds = new HashSet(); + Iterator var21 = listmodelentry.iterator(); + + while(var21.hasNext()) { + DynamicObject model = (DynamicObject)var21.next(); + DynamicObjectCollection listentry = model.getDynamicObjectCollection("listentry"); + List ids = (List)listentry.stream().map((o) -> { + return o.getLong("entryunitproject_id"); + }).collect(Collectors.toList()); + curUnitProIds.addAll(ids); + } + + if (((Set)ret.get(measureId)).containsAll(curUnitProIds)) { + measureBillSet.add(entry.getLong("referbillid")); + } + } else { + measureBillSet.add(entry.getLong("referbillid")); + } + } + } + } + + if (measureBillSet.isEmpty()) { + return new QFilter("id", "!=", 0L); + } else if (!StringUtils.equals(ReferBillTypeEnum.PERFORM.getValue(), billType)) { + return new QFilter("id", "not in", measureBillSet); + } else { + return new QFilter("entryentity.id", "not in", measureBillSet); + } + } + + protected Map> getUsedMeasureEntryMap() { + String formId = this.getSettleFormId(); + DynamicObject contract = (DynamicObject)this.getModel().getValue("contract"); + QFilter qFilter = new QFilter("contract", "=", contract.getPkValue()); + qFilter.and(new QFilter(ContractSettleTplConstant.ID_ENTITY_PK, "!=", this.getModel().getDataEntity().getPkValue())); + Map> ret = new HashMap(); + DynamicObject[] settleBills = BusinessDataServiceHelper.load(formId, "id", new QFilter[]{qFilter}); + DynamicObject[] var6 = settleBills; + int var7 = settleBills.length; + + for(int var8 = 0; var8 < var7; ++var8) { + DynamicObject settleBill = var6[var8]; + settleBill = BusinessDataServiceHelper.loadSingle(settleBill.getPkValue(), formId); + DynamicObjectCollection entries = settleBill.getDynamicObjectCollection("payitemdetailentry"); + Iterator var11 = entries.iterator(); + + while(var11.hasNext()) { + DynamicObject entry = (DynamicObject)var11.next(); + if (entry.getString("referbilltype").equals(ReferBillTypeEnum.MEASURE.getValue()) && this.getPayDirection().equals(PayDirectionEnum.IN.getValue())) { + long referbillid = entry.getLong("referbillid"); + Long eUnitId = entry.getLong("detailunitproject_id"); + Set orDefault = (Set)ret.getOrDefault(referbillid, new HashSet()); + orDefault.add(eUnitId); + ret.put(referbillid, orDefault); + } + } + } + + return ret; + } + + protected DynamicObjectCollection updateMeasureBillDataToEntry(DynamicObject[] measureBills) { + this.deleteDetailsByReferBillType(true, ReferBillTypeEnum.MEASURE.getValue()); + if (measureBills != null && measureBills.length != 0) { + DynamicObjectCollection entryCollection = this.getModel().getEntryEntity("payitemdetailentry"); + DynamicObjectType entryType = entryCollection.getDynamicObjectType(); + DynamicObjectCollection addEntry = new DynamicObjectCollection(); + DynamicObject measureItem = BusinessDataServiceHelper.loadSingle(Long.parseLong("506427748873442304"), "ec_payitem"); + boolean isOut = StringUtils.equals(PayDirectionEnum.OUT.getValue(), this.getPayDirection()); + if (isOut) { + DynamicObject[] var7 = measureBills; + int var8 = measureBills.length; + + for(int var9 = 0; var9 < var8; ++var9) { + DynamicObject measureBill = var7[var9]; + DynamicObject entryObj = new DynamicObject(entryType); + entryObj.set("detailitem", measureBill.getString("billname")); + entryObj.set("detailpayitem", measureItem); + entryObj.set("detailoftaxamt", measureBill.getBigDecimal("measureoftax")); + entryObj.set("detailtaxamt", measureBill.getBigDecimal("measuretax")); + entryObj.set("detailamt", measureBill.getBigDecimal("measureamount")); + entryObj.set("detailauditdate", measureBill.getDate("auditdate")); + entryObj.set("referbillnumber", measureBill.getString("billno")); + entryObj.set("referbilltype", ReferBillTypeEnum.MEASURE.getValue()); + entryObj.set("referbillid", measureBill.getPkValue()); + if (isOut && measureBill.getBoolean("ismeasurebymatin")) { + entryObj.set("ismeasurebymatin", "1"); + DynamicObjectCollection materialInEntries = measureBill.getDynamicObjectCollection("materialinentry"); + if (materialInEntries != null && !materialInEntries.isEmpty()) { + BigDecimal amount = BigDecimal.ZERO; + BigDecimal ofTax = BigDecimal.ZERO; + Iterator var15 = materialInEntries.iterator(); + + while(var15.hasNext()) { + DynamicObject materialInEntry = (DynamicObject)var15.next(); + if (materialInEntry.getBoolean("istranssettle")) { + amount = amount.add(materialInEntry.getBigDecimal("transnotaxamount")); + ofTax = ofTax.add(materialInEntry.getBigDecimal("transtaxamount")); + } + } + + entryObj.set("measuretransamt", amount); + entryObj.set("measuretransoftax", ofTax); + } + } + + entryCollection.add(entryObj); + addEntry.add(entryObj); + } + } else { + Map amountMap = new HashMap(); + Map taxMap = new HashMap(); + Map taxOfAmountMap = new HashMap(); + Map entryIdsMap = new HashMap(); + Map> usedMeasureEntryMap = this.getUsedMeasureEntryMap(); + Map measurebillMap = (Map)Arrays.stream(measureBills).collect(Collectors.toMap(DataEntityBase::getPkValue, Function.identity())); + DynamicObject project = (DynamicObject)this.getModel().getValue("project"); + DynamicObject[] var43 = measureBills; + int var45 = measureBills.length; + + DynamicObject entryObj; + for(int var47 = 0; var47 < var45; ++var47) { + DynamicObject measureBill = var43[var47]; + Long measurebillId = measureBill.getLong("id"); + DynamicObjectCollection listmodelentry = measureBill.getDynamicObjectCollection("listmodelentry"); + Iterator var20 = listmodelentry.iterator(); + + label115: + while(var20.hasNext()) { + entryObj = (DynamicObject)var20.next(); + DynamicObjectCollection listentry = entryObj.getDynamicObjectCollection("listentry"); + Iterator var23 = listentry.iterator(); + + while(true) { + DynamicObject measureEntry; + DynamicObject unitproject; + long entryUnitId; + do { + DynamicObject proOrg; + long orgId; + do { + DynamicObject headunitproject; + long unitProjectId; + do { + if (!var23.hasNext()) { + continue label115; + } + + measureEntry = (DynamicObject)var23.next(); + unitproject = measureEntry.getDynamicObject("entryunitproject"); + headunitproject = (DynamicObject)this.getModel().getValue("unitproject"); + unitProjectId = unitproject == null ? 0L : unitproject.getLong("id"); + } while(null != headunitproject && unitProjectId != headunitproject.getLong("id")); + + if (null != headunitproject || unitproject == null || project == null) { + break; + } + + proOrg = project.getDynamicObject("projectorg"); + DynamicObject orgObj = this.getModel().getDataEntity().getDynamicObject("org"); + orgId = orgObj == null ? 0L : orgObj.getLong("id"); + } while(proOrg != null && orgId != proOrg.getLong("id") && unitproject.getLong("responsibleorg.id") != orgId); + + entryUnitId = measureEntry.getLong("entryunitproject_id"); + } while(usedMeasureEntryMap.containsKey(measurebillId) && ((Set)usedMeasureEntryMap.get(measurebillId)).contains(entryUnitId)); + + String key = unitproject == null ? "0," + measurebillId : unitproject.getString("id") + "," + measurebillId; + BigDecimal thisamount = measureEntry.getBigDecimal("thisamount"); + BigDecimal thistax = measureEntry.getBigDecimal("thistax"); + BigDecimal thisoftaxmount = measureEntry.getBigDecimal("thisoftaxmount"); + amountMap.put(key, ((BigDecimal)amountMap.getOrDefault(key, BigDecimal.ZERO)).add(thisamount)); + taxMap.put(key, ((BigDecimal)taxMap.getOrDefault(key, BigDecimal.ZERO)).add(thistax)); + taxOfAmountMap.put(key, ((BigDecimal)taxOfAmountMap.getOrDefault(key, BigDecimal.ZERO)).add(thisoftaxmount)); + String str = entryIdsMap.get(key) == null ? measureEntry.getString("id") : ((String)entryIdsMap.get(key)).concat(",").concat(measureEntry.getString("id")); + entryIdsMap.put(key, str); + } + } + } + + Iterator iterator = amountMap.keySet().iterator(); + + while(iterator.hasNext()) { + String key = (String)iterator.next(); + String[] split = key.split(","); + String unitprojectId = split[0]; + DynamicObject up = null; + if (!"0".equals(unitprojectId)) { + up = BusinessDataServiceHelper.loadSingle(Long.valueOf(unitprojectId), "ec_ecbd_unitproject"); + } + + String billId = split[1]; + DynamicObject measureBill = (DynamicObject)measurebillMap.get(Long.valueOf(billId)); + entryObj = new DynamicObject(entryType); + entryObj.set("detailitem", measureBill.getString("billname")); + entryObj.set("detailpayitem", measureItem); + entryObj.set("detailoftaxamt", taxOfAmountMap.get(key)); + entryObj.set("detailtaxamt", taxMap.get(key)); + entryObj.set("detailamt", amountMap.get(key)); + entryObj.set("detailauditdate", measureBill.getDate("auditdate")); + entryObj.set("referbillnumber", measureBill.getString("billno")); + entryObj.set("referbilltype", ReferBillTypeEnum.MEASURE.getValue()); + entryObj.set("referbillid", measureBill.getPkValue()); + entryObj.set("detailunitproject", up); + entryCollection.add(entryObj); + addEntry.add(entryObj); + } + } + + this.sortDetailEntry(entryCollection); + this.getModel().updateEntryCache(entryCollection); + this.getView().updateView("payitemdetailentry"); + return addEntry; + } else { + return null; + } + } + + protected void updateItemDetailEntry() { + this.getModel().deleteEntryData("payitemdetailentry"); + DynamicObject dataEntity = this.getModel().getDataEntity(); + DynamicObject contract = dataEntity.getDynamicObject("contract"); + if (contract != null) { + QFilter contractFilter = new QFilter("contract", "=", contract.getPkValue()); + QFilter billStatusFilter = new QFilter("billstatus", "=", BillStatusEnum.AUDIT.getValue()); + QFilter payDirectionFilter = new QFilter("paydirection", "=", this.getPayDirection()); + QFilter isNeedSettleFilter = new QFilter("isneedsettle", "=", "1"); + QFilter isNotSettleFilter = new QFilter("issettle", "=", "0"); + String paydirection = (String)this.getModel().getValue("paydirection"); + if (PayDirectionEnum.IN.getValue().equals(paydirection)) { + DynamicObject unitproject = (DynamicObject)this.getModel().getValue("unitproject"); + if (null != unitproject) { + contractFilter.and(new QFilter("unitproject", "=", unitproject.getPkValue())); + } else { + DynamicObject project = this.getModel().getDataEntity().getDynamicObject("project"); + if (project != null) { + DynamicObject proOrg = project.getDynamicObject("projectorg"); + DynamicObject orgObj = (DynamicObject)this.getModel().getValue("org"); + long orgId = orgObj == null ? 0L : orgObj.getLong("id"); + if (proOrg != null && orgId != proOrg.getLong("id")) { + contractFilter.and(new QFilter("unitproject.responsibleorg.id", "=", orgId)); + } + } + } + } + + QFilter[] claimFilters = new QFilter[]{contractFilter, billStatusFilter, payDirectionFilter, isNeedSettleFilter, isNotSettleFilter, this.getNotUseFilter(contract, ReferBillTypeEnum.CLAIM.getValue())}; + QFilter[] performRecordFilters = new QFilter[]{contractFilter, billStatusFilter, payDirectionFilter, this.getNotUseFilter(contract, ReferBillTypeEnum.PERFORM.getValue())}; + QFilter[] visaFilters = new QFilter[]{contractFilter, billStatusFilter, payDirectionFilter, isNeedSettleFilter, isNotSettleFilter, this.getNotUseFilter(contract, ReferBillTypeEnum.VISA.getValue())}; + String unitpro = ""; + if (this.getPayDirection().equals(PayDirectionEnum.IN.getValue())) { + unitpro = ",unitproject"; + } + + DynamicObject[] claimArr = BusinessDataServiceHelper.load(this.getClaimFormId(), "billno,billname,contract,period,contpayitem,claimoftaxamount,taxamount,taxrate,claimamount,creator,createtime,auditor,auditdate,isneedsettle,issettle" + unitpro, claimFilters); + DynamicObject[] performRecordArr = BusinessDataServiceHelper.load(this.getPerformFormId(), "billno,name,contract,entryentity,entryentity.record,entryentity.tax,entryentity.amount,entryentity.notaxamount,entryentity.contpayitem,creator,createtime,auditor,auditdate,entryentity.isneedsettle,entryentity.issettle" + unitpro, performRecordFilters); + DynamicObject[] visaBillArr = BusinessDataServiceHelper.load(this.getVisaFormId(), "billno,billname,contract,period,contpayitem,visaoftaxamount,taxamount,visaamount,taxrate,creator,createtime,auditor,auditdate,,isneedsettle,issettle" + unitpro, visaFilters); + DynamicObjectCollection entryCollection = this.getModel().getEntryEntity("payitemdetailentry"); + this.setClaimArrDataToEntry(entryCollection, claimArr); + this.setPerformRecordArrToEntry(entryCollection, performRecordArr); + this.setVisaBillArrDataToEntry(entryCollection, visaBillArr); + this.sortDetailEntry(entryCollection); + this.getModel().updateEntryCache(entryCollection); + this.getView().updateView("payitemdetailentry"); + } + } + + protected void sortDetailEntry(DynamicObjectCollection entryCollection) { + entryCollection.sort((o1, o2) -> { + DynamicObject detailPayItem1 = o1.getDynamicObject("detailpayitem"); + DynamicObject detailPayItem2 = o2.getDynamicObject("detailpayitem"); + String referBillType1 = o1.getString("referbilltype"); + String referBillType2 = o2.getString("referbilltype"); + Date detailAuditDate1 = o1.getDate("detailauditdate"); + Date detailAuditDate2 = o2.getDate("detailauditdate"); + if (detailPayItem1 != null && detailPayItem2 != null) { + if (detailPayItem1.getPkValue().equals(detailPayItem2.getPkValue())) { + return StringUtils.equals(referBillType1, referBillType2) ? detailAuditDate1.compareTo(detailAuditDate2) : referBillType1.compareTo(referBillType2); + } else { + return -detailPayItem1.getString("number").compareTo(detailPayItem2.getString("number")); + } + } else { + return 0; + } + }); + } + + protected void setVisaBillArrDataToEntry(DynamicObjectCollection entryCollection, DynamicObject[] visaBillArr) { + if (visaBillArr != null && visaBillArr.length != 0) { + DynamicObjectType entryType = entryCollection.getDynamicObjectType(); + DynamicObject[] var4 = visaBillArr; + int var5 = visaBillArr.length; + + for(int var6 = 0; var6 < var5; ++var6) { + DynamicObject visaBill = var4[var6]; + DynamicObject entryObj = new DynamicObject(entryType); + entryObj.set("detailitem", visaBill.getString("billname")); + entryObj.set("detailpayitem", visaBill.getDynamicObject("contpayitem")); + entryObj.set("detailoftaxamt", visaBill.getBigDecimal("visaoftaxamount")); + entryObj.set("detailtaxamt", visaBill.getBigDecimal("taxamount")); + entryObj.set("detailamt", visaBill.getBigDecimal("visaamount")); + entryObj.set("detailauditdate", visaBill.getDate("auditdate")); + entryObj.set("referbillnumber", visaBill.getString("billno")); + entryObj.set("referbilltype", ReferBillTypeEnum.VISA.getValue()); + entryObj.set("referbillid", visaBill.getPkValue()); + if (this.getPayDirection().equals(PayDirectionEnum.IN.getValue())) { + entryObj.set("detailunitproject", visaBill.get("unitproject")); + } + + entryCollection.add(entryObj); + } + + } + } + + protected void setPerformRecordArrToEntry(DynamicObjectCollection entryCollection, DynamicObject[] performRecordArr) { + if (performRecordArr != null && performRecordArr.length != 0) { + DynamicObjectType entryType = entryCollection.getDynamicObjectType(); + DynamicObject[] var4 = performRecordArr; + int var5 = performRecordArr.length; + + for(int var6 = 0; var6 < var5; ++var6) { + DynamicObject performRecord = var4[var6]; + DynamicObjectCollection performRecordEntryCol = performRecord.getDynamicObjectCollection("entryentity"); + Iterator var9 = performRecordEntryCol.iterator(); + + while(var9.hasNext()) { + DynamicObject performRecordEntry = (DynamicObject)var9.next(); + boolean isSettle = performRecordEntry.getBoolean("issettle"); + boolean isNeedSettle = performRecordEntry.getBoolean("isneedsettle"); + if (isNeedSettle && !isSettle) { + DynamicObject entryObj = this.newEntry(performRecord, performRecordEntry, entryType); + entryCollection.add(entryObj); + } + } + } + + } + } + + protected DynamicObject newEntry(DynamicObject performRecord, DynamicObject performRecordEntry, DynamicObjectType entryType) { + DynamicObject entryObj = new DynamicObject(entryType); + entryObj.set("detailitem", performRecordEntry.getString("record")); + entryObj.set("detailpayitem", performRecordEntry.getDynamicObject("contpayitem")); + entryObj.set("detailoftaxamt", performRecordEntry.getBigDecimal("amount")); + entryObj.set("detailtaxamt", performRecordEntry.getBigDecimal("tax")); + entryObj.set("detailamt", performRecordEntry.getBigDecimal("notaxamount")); + entryObj.set("referbillnumber", performRecord.getString("billno")); + entryObj.set("referbilltype", ReferBillTypeEnum.PERFORM.getValue()); + entryObj.set("detailauditdate", performRecord.getDate("auditdate")); + entryObj.set("referbillid", performRecord.getPkValue()); + entryObj.set("referentryid", performRecordEntry.getPkValue()); + if (this.getPayDirection().equals(PayDirectionEnum.IN.getValue())) { + entryObj.set("detailunitproject", performRecord.get("unitproject")); + } + + return entryObj; + } + + protected void setClaimArrDataToEntry(DynamicObjectCollection entryCollection, DynamicObject[] claimArr) { + if (claimArr != null && claimArr.length != 0) { + DynamicObjectType entryType = entryCollection.getDynamicObjectType(); + DynamicObject[] var4 = claimArr; + int var5 = claimArr.length; + + for(int var6 = 0; var6 < var5; ++var6) { + DynamicObject claim = var4[var6]; + DynamicObject entryObj = new DynamicObject(entryType); + entryObj.set("detailitem", claim.getString("billname")); + entryObj.set("detailpayitem", claim.getDynamicObject("contpayitem")); + entryObj.set("detailoftaxamt", claim.getBigDecimal("claimoftaxamount")); + entryObj.set("detailtaxamt", claim.getBigDecimal("taxamount")); + entryObj.set("detailamt", claim.getBigDecimal("claimamount")); + entryObj.set("detailauditdate", claim.getDate("auditdate")); + entryObj.set("referbillnumber", claim.getString("billno")); + entryObj.set("referbilltype", ReferBillTypeEnum.CLAIM.getValue()); + entryObj.set("referbillid", claim.getPkValue()); + if (this.getPayDirection().equals(PayDirectionEnum.IN.getValue())) { + entryObj.set("detailunitproject", claim.get("unitproject")); + } + + entryCollection.add(entryObj); + } + + } + } + + protected void initPayItemEntryByContract(DynamicObject contract) { + this.getModel().deleteEntryData("itementry"); + if (contract != null) { + Object contAttrPk = contract.getDynamicObject("contracttype").getDynamicObject("contattr").getPkValue(); + QFilter commonFilter = (new QFilter("enable", "=", "1")).and("status", "=", "C").and("paymentitemtype", "=", PayItemTypeEnum.FIXED.getValue()); + QFilter preFilter = (new QFilter("ispreitem", "=", true)).and(commonFilter); + QFilter attrFilter = (new QFilter("contattr", "=", contAttrPk)).and(commonFilter); + QFilter noAttrFilter = (new QFilter("contattr", "=", 0L)).and("ispreitem", "=", false).and(commonFilter); + boolean isMultiRate = contract.getBoolean("ismultirate"); + DynamicObject taxRate = contract.getDynamicObject("taxrate"); + DynamicObject[] payItems = BusinessDataServiceHelper.load("ec_payitem", "id,isupdateamount,computesource,ispreitem,iscompute,description", new QFilter[]{preFilter.or(attrFilter).or(noAttrFilter)}, "ispreitem desc,number asc"); + int initEntrylen = payItems.length; + if (this.getPayDirection().equals(PayDirectionEnum.IN.getValue()) && contract.getBoolean("isonlist")) { + initEntrylen = (int)Arrays.stream(payItems).filter((obj) -> { + return !obj.getString("id").equals("506427748873442304"); + }).count(); + } + + if (initEntrylen != 0) { + int index = 0; + int[] indexArray = this.getModel().batchCreateNewEntryRow("itementry", initEntrylen); + DynamicObject[] var13 = payItems; + int var14 = payItems.length; + + for(int var15 = 0; var15 < var14; ++var15) { + DynamicObject payItem = var13[var15]; + if (!this.getPayDirection().equals(PayDirectionEnum.IN.getValue()) || !payItem.getString("id").equals("506427748873442304") || !contract.getBoolean("isonlist")) { + int row = indexArray[index]; + this.getModel().setValue("payitem", payItem.getPkValue(), row); + if (payItem.getBoolean("ispreitem") && !isMultiRate && taxRate != null) { + this.getModel().setValue("rate", taxRate.getBigDecimal("taxrate"), 0); + } else if (!payItem.getBoolean("ispreitem")) { + this.getModel().setValue("remark", payItem.getString("description"), row); + if (!isMultiRate && !payItem.getBoolean("iscompute") && taxRate != null) { + this.getModel().setValue("rate", taxRate.getBigDecimal("taxrate"), row); + } + } + + this.fillItemEntryCbs(row); + ++index; + } + } + + } + } + } + + protected void initBasicInfoByContract(DynamicObject contract) { + this.getModel().setValue("settleoftaxamount", (Object)null); + this.getModel().setValue("taxamount", (Object)null); + this.getModel().setValue("settleamount", (Object)null); + if (contract == null) { + this.getModel().setValue("project", (Object)null); + this.getModel().setValue("taxrate", (Object)null); + this.getModel().setValue("ismultirate", false); + this.getModel().setValue("ismulticurrency", false); + this.getModel().setValue("isonlist", false); + this.getModel().setValue("contattr", (Object)null); + this.clearAllAmtWhenDelContract(); + } else { + this.getModel().setValue("conttotaloftaxamount", contract.getBigDecimal("totaloftaxamount")); + this.getModel().setValue("totalsettleoftaxamount", contract.getBigDecimal("totalsettleoftaxamount")); + this.getModel().setValue("ismulticurrency", contract.getBoolean("ismulticurrency")); + this.getModel().setValue("ismultirate", contract.getBoolean("ismultirate")); + this.getModel().setValue("isonlist", contract.getBoolean("isonlist")); + this.getModel().setValue("contattr", contract.getDynamicObject("contracttype").getDynamicObject("contattr").getPkValue()); + DynamicObject project = contract.getDynamicObject("project"); + if (project != null) { + this.getModel().setValue("project", project.getPkValue()); + } else { + this.getModel().setValue("project", (Object)null); + } + + DynamicObject taxRate = contract.getDynamicObject("taxrate"); + if (taxRate != null) { + this.getModel().setValue("taxrate", taxRate.getPkValue()); + } + + this.getModel().setValue("showcurrency", "A"); + } + } + + protected void clearAllAmtWhenDelContract() { + this.getModel().setValue("caloftaxamt", BigDecimal.ZERO); + this.getModel().setValue("notcaloftaxamt", BigDecimal.ZERO); + this.getModel().setValue("settleoftaxamount", BigDecimal.ZERO); + this.getModel().setValue("totalcaloftaxamt", BigDecimal.ZERO); + this.getModel().setValue("totalnotcaloftaxamt", BigDecimal.ZERO); + this.getModel().setValue("totalsettleoftaxamount", BigDecimal.ZERO); + this.getModel().setValue("totalplanpayoftaxamt", BigDecimal.ZERO); + this.getModel().setValue("totalrealpayoftaxamt", BigDecimal.ZERO); + this.getModel().setValue("calofamt", BigDecimal.ZERO); + this.getModel().setValue("notcalofamt", BigDecimal.ZERO); + this.getModel().setValue("settleamount", BigDecimal.ZERO); + this.getModel().setValue("totalcalofamt", BigDecimal.ZERO); + this.getModel().setValue("totalnotcalofamt", BigDecimal.ZERO); + this.getModel().setValue("totalsettleofamount", BigDecimal.ZERO); + this.getModel().setValue("totalplanpayofamt", BigDecimal.ZERO); + this.getModel().setValue("totalrealpayofamt", BigDecimal.ZERO); + this.getModel().setValue("caltaxamt", BigDecimal.ZERO); + this.getModel().setValue("notcaltaxamt", BigDecimal.ZERO); + this.getModel().setValue("taxamount", BigDecimal.ZERO); + this.getModel().setValue("totalcaltaxamt", BigDecimal.ZERO); + this.getModel().setValue("totalnotcaltaxamt", BigDecimal.ZERO); + this.getModel().setValue("totalsettletaxamount", BigDecimal.ZERO); + this.getModel().setValue("totalplanpaytaxamt", BigDecimal.ZERO); + this.getModel().setValue("totalrealpaytaxamt", BigDecimal.ZERO); + this.getModel().setValue("conttotaloftaxamount", BigDecimal.ZERO); + } + + public void hyperLinkClick(HyperLinkClickEvent paramHyperLinkClickEvent) { + String fieldName = paramHyperLinkClickEvent.getFieldName(); + int rowIndex = paramHyperLinkClickEvent.getRowIndex(); + if (StringUtils.equals(fieldName, "referbillnumber")) { + this.referBillHyperLinkClick(rowIndex); + } + + } + + protected void referBillHyperLinkClick(int rowIndex) { + DynamicObject detailEntry = this.getModel().getEntryRowEntity("payitemdetailentry", rowIndex); + String referBillType = detailEntry.getString("referbilltype"); + Long referBillId = detailEntry.getLong("referbillid"); + if (StringUtils.equals(referBillType, ReferBillTypeEnum.CLAIM.getValue())) { + this.showBillDetailForm(referBillId, this.getClaimFormId()); + } else if (StringUtils.equals(referBillType, ReferBillTypeEnum.PERFORM.getValue())) { + this.showBillDetailForm(referBillId, this.getPerformFormId()); + } else if (StringUtils.equals(referBillType, ReferBillTypeEnum.VISA.getValue())) { + this.showBillDetailForm(referBillId, this.getVisaFormId()); + } else if (StringUtils.equals(referBillType, ReferBillTypeEnum.MEASURE.getValue())) { + this.showBillDetailForm(referBillId, this.getMeasureFormId()); + } else if (StringUtils.equals(referBillType, ReferBillTypeEnum.MATERIAL_OUT.getValue())) { + this.showBillDetailForm(referBillId, "ecma_materialoutbill"); + } + + } + + protected void showBillDetailForm(Long pkId, String billFormId) { + Map paramMap = new HashMap(); + paramMap.put("formId", billFormId); + paramMap.put("pkId", String.valueOf(pkId)); + FormShowParameter showParameter = FormShowParameter.createFormShowParameter(paramMap); + showParameter.setStatus(OperationStatus.VIEW); + showParameter.getOpenStyle().setShowType(ShowType.MainNewTabPage); + this.getView().showForm(showParameter); + } + + protected String getContractFormId() { + return StringUtils.equals(this.getPayDirection(), PayDirectionEnum.OUT.getValue()) ? "ec_out_contract" : "ec_in_contract"; + } + + protected String getMeasureFormId() { + return StringUtils.equals(this.getPayDirection(), PayDirectionEnum.OUT.getValue()) ? "ec_outcontractmeasure" : "ec_incontractmeasure"; + } + + protected String getSettleFormId() { + return StringUtils.equals(this.getPayDirection(), PayDirectionEnum.OUT.getValue()) ? "ec_out_contract_settle" : "ec_in_contract_settle"; + } + + protected String getClaimFormId() { + return StringUtils.equals(this.getPayDirection(), PayDirectionEnum.OUT.getValue()) ? "ec_outclaimbill" : "ec_inclaimbill"; + } + + protected String getVisaFormId() { + return StringUtils.equals(this.getPayDirection(), PayDirectionEnum.OUT.getValue()) ? "ec_outvisabill" : "ec_invisabill"; + } + + protected String getPerformFormId() { + return StringUtils.equals(this.getPayDirection(), PayDirectionEnum.OUT.getValue()) ? "ec_out_performrecords" : "ec_in_performrecords"; + } + + protected String getPayDirection() { + return (String)this.getModel().getValue("paydirection"); + } + + protected String getCurrentFormBillId() { + return this.getView().getFormShowParameter().getFormId(); + } + + protected boolean isMultiRate() { + return (Boolean)this.getModel().getValue("ismultirate"); + } +}