diff --git a/code/zcdev/zcgj-zcdev-zcdev-fs/src/main/java/zcgj/zcdev/zcdev/fs/plugin/form/ContractBillListExt.java b/code/zcdev/zcgj-zcdev-zcdev-fs/src/main/java/zcgj/zcdev/zcdev/fs/plugin/form/ContractBillListExt.java new file mode 100644 index 0000000..11206ee --- /dev/null +++ b/code/zcdev/zcgj-zcdev-zcdev-fs/src/main/java/zcgj/zcdev/zcdev/fs/plugin/form/ContractBillListExt.java @@ -0,0 +1,488 @@ +// +// Source code recreated from a .class file by IntelliJ IDEA +// (powered by FernFlower decompiler) +// + +package zcgj.zcdev.zcdev.fs.plugin.form; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Date; +import java.util.EventObject; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.stream.Collectors; + +import kd.bos.dataentity.entity.DynamicObject; +import kd.bos.dataentity.entity.DynamicObjectCollection; +import kd.bos.dataentity.resource.ResManager; +import kd.bos.entity.datamodel.IDataModel; +import kd.bos.entity.datamodel.ListSelectedRow; +import kd.bos.entity.datamodel.ListSelectedRowCollection; +import kd.bos.entity.operate.IOperationResult; +import kd.bos.form.CloseCallBack; +import kd.bos.form.FormShowParameter; +import kd.bos.form.IFormView; +import kd.bos.form.ShowType; +import kd.bos.form.control.events.BeforeItemClickEvent; +import kd.bos.form.control.events.ItemClickEvent; +import kd.bos.form.events.AfterDoOperationEventArgs; +import kd.bos.form.events.BeforeDoOperationEventArgs; +import kd.bos.form.events.ClosedCallBackEvent; +import kd.bos.form.events.MessageBoxClosedEvent; +import kd.bos.form.operate.FormOperate; +import kd.bos.list.IListView; +import kd.bos.list.plugin.AbstractListPlugin; +import kd.bos.logging.Log; +import kd.bos.logging.LogFactory; +import kd.bos.mvc.list.ListView; +import kd.bos.orm.query.QFilter; +import kd.bos.servicehelper.QueryServiceHelper; +import kd.fi.er.business.isc.IscHelper; +import kd.fi.er.business.pub.ContractUtil; +import kd.fi.er.business.trip.util.TripCommonUtil; +import kd.fi.er.business.utils.ErStdConfig; +import kd.fi.er.formplugin.publicbiz.bill.contract.ContractBillList; +import kd.fi.er.model.EntityInfo; +import org.apache.commons.lang.StringUtils; + +public class ContractBillListExt extends AbstractListPlugin { + private static final String BAR_CHANGEA = "bar_changea"; + private static final String BAR_CHANGEB = "bar_changeb"; + private static final String BAR_CHANGEC = "bar_changec"; + private static final String BAR_CHANGED = "bar_changed"; + private static final String BAR_CHANGED_FRAME = "bar_changed_frame"; + private static final String EXPENSEENTRYENTITY_SOURCEBILLNO = "expenseentryentity.wbsrcbillno"; + private static final String EXPENSEENTRYENTITY_WBSRCBILLTYPE = "expenseentryentity.wbsrcbilltype"; + private static final Log logger = LogFactory.getLog(ContractBillList.class); + private static String[] opkey = new String[]{"submit", "docontractsign", "updateconsign", "frozen", "unfrozen", "closebill", "pushtocontractstop"}; + + public ContractBillListExt() { + } + + public void registerListener(EventObject e) { + super.registerListener(e); + this.addItemClickListeners(new String[]{"bar_changea", "bar_changeb", "bar_changec", "bar_changed", "bar_changed_frame", "barstopbill"}); + } + + public void beforeItemClick(BeforeItemClickEvent evt) { + switch (evt.getItemKey()) { + case "bar_changea": + this.checkChangePush(evt, "bar_changea", ResManager.loadKDString("变更金额", "ContractBillList_90", "fi-er-formplugin", new Object[0])); + break; + case "bar_changeb": + this.checkChangePush(evt, "bar_changeb", ResManager.loadKDString("变更税率", "ContractBillList_91", "fi-er-formplugin", new Object[0])); + break; + case "bar_changec": + this.checkChangePush(evt, "bar_changec", ResManager.loadKDString("补充明细", "ContractBillList_92", "fi-er-formplugin", new Object[0])); + break; + case "bar_changed": + this.checkChangePush(evt, "bar_changed", ResManager.loadKDString("变更其他", "ContractBillList_93", "fi-er-formplugin", new Object[0])); + break; + case "bar_changed_frame": + this.checkChangePush(evt, "bar_changed_frame", ResManager.loadKDString("变更框架合同", "ContractBillList_94", "fi-er-formplugin", new Object[0])); + break; + case "barstopbill": + Set ids = (Set) this.getSelectedRows().stream().map(ListSelectedRow::getPrimaryKeyValue).collect(Collectors.toSet()); + if (ids.size() != 1) { + this.getView().showTipNotification(ResManager.loadKDString("请选择一行数据操作。", "ContractBillList_1", "fi-er-formplugin", new Object[0])); + evt.setCancel(true); + } + } + + } + + private void checkChangePush(BeforeItemClickEvent evt, String changeoOpType, String itemTitle) { + Set ids = (Set) this.getSelectedRows().stream().map(ListSelectedRow::getPrimaryKeyValue).collect(Collectors.toSet()); + if (ids.size() != 1) { + this.getView().showTipNotification(ResManager.loadKDString("请选择一行数据操作。", "ContractBillList_1", "fi-er-formplugin", new Object[0])); + evt.setCancel(true); + } else { + IListView listView = (IListView) this.getView(); + String entityName = listView.getListModel().getEntityId(); + ListSelectedRowCollection selectedRows = ((IListView) this.getView()).getSelectedRows(); + Iterator var8 = selectedRows.iterator(); + + DynamicObject dynamicObject; + do { + do { + do { + do { + if (!var8.hasNext()) { + String OnWayCondition = "A,B,C,D"; + String selectedProperties = String.join(",", "id", "billstatus"); + DynamicObjectCollection prepayBills = QueryServiceHelper.query("er_contractbill", selectedProperties, new QFilter[]{new QFilter("srcsourceid", "in", ids)}); + long count = prepayBills.stream().filter((prepayBillOnWay) -> { + return OnWayCondition.contains(prepayBillOnWay.getString("billstatus")); + }).count(); + if (count > 0L) { + this.getView().showTipNotification(String.format(String.format(ResManager.loadKDString("已存在未完成的下游单据,请完成流程后再发起%1$s。", "ContractBillList_9", "fi-er-formplugin", new Object[0]), ResManager.loadKDString("变更", "ContractBillList_96", "fi-er-formplugin", new Object[0])))); + evt.setCancel(true); + return; + } + + List onwayids = ContractUtil.checkHasOnWayBills(selectedRows, OnWayCondition); + if (onwayids.size() > 0) { + this.getView().showTipNotification(String.format(String.format(ResManager.loadKDString("已存在未完成的下游单据,请完成流程后再发起%1$s。", "ContractBillList_9", "fi-er-formplugin", new Object[0]), ResManager.loadKDString("变更", "ContractBillList_96", "fi-er-formplugin", new Object[0])))); + evt.setCancel(true); + return; + } + + this.getView().getPageCache().put("changeoOpType", changeoOpType); + return; + } + + ListSelectedRow selectedRow = (ListSelectedRow) var8.next(); + Object primaryKeyValues = selectedRow.getPrimaryKeyValue(); + QFilter qFilter = new QFilter("id", "=", primaryKeyValues); + dynamicObject = QueryServiceHelper.queryOne(entityName, "frameworkcontract,billno,paybyrata,stdbilltype,detailtype,sbilltype", new QFilter[]{qFilter}); + if ("1".equals(dynamicObject.get("sbilltype"))) { + this.getView().showTipNotification(String.format(String.format(ResManager.loadKDString("单据编号:%1$s 为集成单据,不能进行此操作,请重新选择。", "ContractBillList_28", "fi-er-formplugin", new Object[0]), dynamicObject.getString("billno")))); + evt.setCancel(true); + return; + } + } while ("bar_changed_frame".equals(changeoOpType)); + + if (dynamicObject.getBoolean("frameworkcontract")) { + this.getView().showTipNotification(String.format(ResManager.loadKDString("框架合同不支持%1$s。", "ContractBillList_95", "fi-er-formplugin", new Object[0]), itemTitle)); + evt.setCancel(true); + return; + } + } while (!"biztype_applybill".equals(dynamicObject.getString("detailtype"))); + } while (!dynamicObject.getBoolean("paybyrata")); + } while (!"bar_changea".equals(changeoOpType) && !"bar_changec".equals(changeoOpType)); + + this.getView().showTipNotification(String.format(ResManager.loadKDString("按比例支付合同暂时不支持%1$s。", "ContractBillList_97", "fi-er-formplugin", new Object[0]), itemTitle)); + evt.setCancel(true); + } + } + + public void afterDoOperation(AfterDoOperationEventArgs e) { + super.afterDoOperation(e); + String key = e.getOperateKey(); + IOperationResult result = e.getOperationResult(); + IDataModel dataModel = this.getModel(); + ListView listView = (ListView) this.getView(); + ListSelectedRowCollection selectedRowCollection = listView.getSelectedRows(); + List pks = (List) selectedRowCollection.stream().map(ListSelectedRow::getPrimaryKeyValue).collect(Collectors.toList()); + switch (key) { + case "audit": + default: + break; + case "unfrozen": + if (result.isSuccess()) { + this.getView().showSuccessNotification(ResManager.loadKDString("解冻成功。", "ContractBillList_7", "fi-er-formplugin", new Object[0])); + } + break; + case "frozen": + if (result.isSuccess()) { + this.getView().showSuccessNotification(ResManager.loadKDString("冻结成功。", "ContractBillList_8", "fi-er-formplugin", new Object[0])); + } + } + + } + + public void beforeDoOperation(BeforeDoOperationEventArgs args) { + super.beforeDoOperation(args); + String operateKey = ((FormOperate) args.getSource()).getOperateKey(); + List lists = (List) args.getListSelectedData().stream().map((v) -> { + return (Long) v.getPrimaryKeyValue(); + }).collect(Collectors.toList()); + String opName = ((FormOperate) args.getSource()).getOperateName().toString(); + String OnWayStatus = "A,B,C,D"; + if (ContractUtil.isFrozen((List) args.getListSelectedData().stream().map(ListSelectedRow::getBillStatus).collect(Collectors.toList())) && ContractUtil.isFrozenOp(operateKey)) { + args.setCancel(true); + this.getView().showTipNotification(String.format(ResManager.loadKDString("冻结状态的单据不允许%1$s。", "ContractBillList_4", "fi-er-formplugin", new Object[0]), opName)); + } else { + if (Arrays.stream(opkey).anyMatch((v) -> { + return operateKey.equals(v); + })) { + DynamicObjectCollection selectedBills = QueryServiceHelper.query("er_contractbill", "id,billno,detailtype,billstatus,sbilltype", new QFilter[]{new QFilter("id", "in", lists)}); + Set collect = (Set) selectedBills.stream().filter((o) -> { + return o.get("sbilltype").equals("1"); + }).map((o) -> { + return o.getString("billno"); + }).collect(Collectors.toSet()); + if (collect.size() > 0) { + this.getView().showTipNotification(String.format(String.format(ResManager.loadKDString("单据编号:%1$s 为集成单据,不能进行此操作,请重新选择。", "ContractBillList_28", "fi-er-formplugin", new Object[0]), collect.toString()))); + args.setCancel(true); + return; + } + } + + ListSelectedRowCollection rows = args.getListSelectedData(); + String OnWayCondition; + Iterator var25; + ListSelectedRow row; + switch (operateKey) { + case "changedprojectower": + QFilter qFilter = new QFilter("id", "in", lists); + OnWayCondition = "H,I,J"; + DynamicObjectCollection selectedBills = QueryServiceHelper.query("er_contractbill", "id,detailtype,billstatus", new QFilter[]{qFilter}); + Set billstatusSet = (Set) selectedBills.stream().filter((v) -> { + return OnWayCondition.contains(v.getString("billstatus")); + }).collect(Collectors.toSet()); + if (billstatusSet.size() > 0) { + this.getView().showTipNotification(ResManager.loadKDString("选择单据的单据状态不支持变更干系人,请重新选择单据。", "ContractBillList_2", "fi-er-formplugin", new Object[0])); + args.setCancel(true); + return; + } + + Set detailtypeSet = (Set) selectedBills.stream().filter((v) -> { + return "biztype_stopbill".equals(v.get("detailtype")) || "biztype_changebill".equals(v.get("detailtype")); + }).collect(Collectors.toSet()); + if (detailtypeSet.size() > 0) { + this.getView().showTipNotification(ResManager.loadKDString("合同变更单/合同终止单不支持变更干系人,请重新选择单据。", "ContractBillList_3", "fi-er-formplugin", new Object[0])); + args.setCancel(true); + return; + } + break; + case "frozen": + var25 = rows.iterator(); + + while (var25.hasNext()) { + row = (ListSelectedRow) var25.next(); + if (!ContractUtil.froze((Long) row.getPrimaryKeyValue(), this.getView())) { + args.setCancel(true); + } + } + + return; + case "unfrozen": + var25 = rows.iterator(); + + while (var25.hasNext()) { + row = (ListSelectedRow) var25.next(); + if (!ContractUtil.unFroze((Long) row.getPrimaryKeyValue(), this.getView())) { + args.setCancel(true); + } + } + + return; + case "publicreimburse": + if (!ContractUtil.checkRelationContract(this.getView(), rows, ResManager.loadKDString("对公报销单", "ApplyPayMobEdit_1", "fi-er-formplugin", new Object[0]))) { + args.setCancel(true); + return; + } + + OnWayStatus = OnWayStatus + ",F"; + List listpub = ContractUtil.checkDownBills(rows, operateKey); + if (listpub.size() > 0) { + this.getView().showTipNotification(String.format(String.format(ResManager.loadKDString("已存在未完成的下游单据,请完成流程后再发起%1$s。", "ContractBillList_9", "fi-er-formplugin", new Object[0]), opName))); + args.setCancel(true); + } + + if (!ContractUtil.checkMultiPublicReim(rows, this.getView())) { + args.setCancel(true); + } + break; + case "pushtoprepay": + if (!ContractUtil.checkRelationContract(this.getView(), rows, ResManager.loadKDString("预付单", "ErHomeAddNewDialogPlugin_5", "fi-er-formplugin", new Object[0]))) { + args.setCancel(true); + } else { + OnWayStatus = OnWayStatus + ",F"; + List listpre = ContractUtil.checkDownBills(rows, operateKey); + if (listpre.size() > 0) { + this.getView().showTipNotification(String.format(String.format(ResManager.loadKDString("已存在未完成的下游单据,请完成流程后再发起%1$s。", "ContractBillList_9", "fi-er-formplugin", new Object[0]), opName))); + args.setCancel(true); + } + } + break; + case "pushtocontractstop": + List list = ContractUtil.checkDownBills(rows, operateKey); + if (list.size() > 0) { + this.getView().showTipNotification(String.format(String.format(ResManager.loadKDString("已存在未完成的下游单据,请完成流程后再发起%1$s。", "ContractBillList_9", "fi-er-formplugin", new Object[0]), opName))); + args.setCancel(true); + } + + OnWayCondition = "A,B,C,D"; + String selectedProperties = String.join(",", "id", "billstatus"); + DynamicObjectCollection prepayBills = QueryServiceHelper.query("er_contractbill", selectedProperties, new QFilter[]{new QFilter("srcsourceid", "in", lists)}); + long count = prepayBills.stream().filter((prepayBillOnWay) -> { + return OnWayCondition.contains(prepayBillOnWay.getString("billstatus")); + }).count(); + if (count > 0L) { + this.getView().showTipNotification(String.format(String.format(ResManager.loadKDString("已存在未完成的下游单据,请完成流程后再发起%1$s。", "ContractBillList_9", "fi-er-formplugin", new Object[0]), opName))); + args.setCancel(true); + return; + } + break; + case "pushcontractchange": + List onwaylist = ContractUtil.checkDownBills(rows, operateKey); + if (onwaylist.size() > 0) { + this.getView().showTipNotification(String.format(String.format(ResManager.loadKDString("已存在未完成的下游单据,请完成流程后再发起%1$s。", "ContractBillList_9", "fi-er-formplugin", new Object[0]), opName))); + args.setCancel(true); + } + break; + case "pushcostestimatebill": + boolean b = this.checkCostestimatebill(args, this.getView(), rows); + if (!b) { + return; + } + + List listContract = ContractUtil.checkDownBills(rows, operateKey); + if (listContract.size() > 0) { + this.getView().showTipNotification(String.format(String.format(ResManager.loadKDString("已存在未完成的下游单据,请完成流程后再发起%1$s。", "ContractBillList_9", "fi-er-formplugin", new Object[0]), opName))); + args.setCancel(true); + } + break; + case "docontractsign": + this.docontractsign(args, this.getView(), rows, operateKey); + break; + case "updateconsign": + this.docontractsign(args, this.getView(), rows, operateKey); + } + + } + } + + public void itemClick(ItemClickEvent evt) { + super.itemClick(evt); + switch (evt.getItemKey()) { + case "importdts": + try { + IscHelper.checkExistBefore(this.getView(), true); + } catch (Exception var6) { + logger.error("ContractBillList>>>>>itemClick>:失败,原因如下:", var6); + } + default: + } + } + + public void confirmCallBack(MessageBoxClosedEvent evt) { + super.confirmCallBack(evt); + + try { + IscHelper.importConfirmCallBack(evt, this.getView()); + } catch (IOException var3) { + logger.error("ErAbstractReportList>>>confirmCallBack:失败,失败原因如下:", var3); + } + + } + + private boolean checkCostestimatebill(BeforeDoOperationEventArgs args, IFormView view, ListSelectedRowCollection selectedRows) { + if (selectedRows.size() <= 0) { + view.showTipNotification(ResManager.loadKDString("请选择一条数据进行操作。", "ContractBillList_10", "fi-er-formplugin", new Object[0])); + args.setCancel(true); + return false; + } else { + Object[] primaryKeyValue = selectedRows.getPrimaryKeyValues(); + QFilter filter = new QFilter("id", "in", primaryKeyValue); + String selectFields = "company,id,frameworkcontract,enddate,billno"; + DynamicObjectCollection contractDy = QueryServiceHelper.query("er_contractbill", selectFields, new QFilter[]{filter}); + long frameworkcontract = contractDy.stream().filter((it) -> { + return !it.getBoolean("frameworkcontract"); + }).count(); + if (frameworkcontract > 0L) { + args.setCancel(true); + view.showTipNotification(ResManager.loadKDString("仅框架合同可下推费用暂估单。", "ContractBillList_15", "fi-er-formplugin", new Object[0])); + return false; + } else { + Boolean contractdeadlinecontrol = ErStdConfig.getContractDeadlineControl(); + logger.info(">>>>>>>>>>>>>>>>>contractdeadlinecontrol:" + contractdeadlinecontrol); + if (!contractdeadlinecontrol) { + Date now = TripCommonUtil.strToDate(TripCommonUtil.DateToStr(new Date()), "yyyy-MM-dd"); + StringBuilder errorbillno = new StringBuilder(); + contractDy.stream().forEach((row) -> { + Date enddate = TripCommonUtil.strToDate(TripCommonUtil.DateToStr((Date) row.get("enddate")), "yyyy-MM-dd"); + if (now.after(enddate)) { + errorbillno.append(" ").append(row.get("billno")); + } + + }); + logger.info(">>>>>>>>>>>>>>>>>contractdeadlinecontrol>>>>errorbillno:" + errorbillno); + if (errorbillno.length() > 0) { + view.showTipNotification(String.format(ResManager.loadKDString("单据编号:%1$s,已超过合同截止日期,不能下推。", "ContractBillList_24", "fi-er-formplugin", new Object[0]), errorbillno)); + args.setCancel(true); + return false; + } + } + + String OnWayConditionStatus = "A,B,C,D"; + String selectedProperties = String.join(",", "id", "billstatus"); + DynamicObjectCollection prepayBills = QueryServiceHelper.query("er_contractbill", selectedProperties, new QFilter[]{new QFilter("srcsourceid", "in", primaryKeyValue)}); + long count = prepayBills.stream().filter((prepayBillOnWay) -> { + return OnWayConditionStatus.contains(prepayBillOnWay.getString("billstatus")); + }).count(); + if (count > 0L) { + this.getView().showTipNotification(ResManager.loadKDString("已存在未完成的下游单据,不允许再推暂估单。", "ContractBillList_6", "fi-er-formplugin", new Object[0])); + args.setCancel(true); + return false; + } else { + EntityInfo reimburseInfo = (new EntityInfo.Builder()).entityName("er_publicreimbursebill").entryName("contractentry").sourceName("contractsid").build(); + List OnWayCondition = new ArrayList(); + OnWayCondition.add("H"); + if (ContractUtil.getCostestimateHasOnWayBills(primaryKeyValue, reimburseInfo, OnWayCondition) > 0) { + args.setCancel(true); + view.showTipNotification(ResManager.loadKDString("下游已存在对公报销单,不允许再推暂估单。", "ContractBillList_17", "fi-er-formplugin", new Object[0])); + return false; + } else { + EntityInfo prepayInfo = (new EntityInfo.Builder()).entityName("er_prepaybill").entryName("expenseentryentity").sourceName("wbsrcbillid").build(); + if (ContractUtil.getCostestimateHasOnWayBills(primaryKeyValue, prepayInfo, OnWayCondition) > 0) { + args.setCancel(true); + view.showTipNotification(ResManager.loadKDString("下游已存在预付单,不允许再推暂估单。", "ContractBillList_18", "fi-er-formplugin", new Object[0])); + return false; + } else { + return true; + } + } + } + } + } + } + + private void docontractsign(BeforeDoOperationEventArgs args, IFormView view, ListSelectedRowCollection selectedRows, String operateKey) { + Set collect = (Set) selectedRows.stream().map((b) -> { + return (Long) b.getPrimaryKeyValue(); + }).collect(Collectors.toSet()); + if (collect.size() <= 1 && collect.size() > 0) { + Object[] primaryKeyValue = selectedRows.getPrimaryKeyValues(); + QFilter filter = new QFilter("id", "=", primaryKeyValue[0]); + String selectFields = "id,billno,billstatus,detailtype"; + DynamicObject contractDy = QueryServiceHelper.queryOne("er_contractbill", selectFields, new QFilter[]{filter}); + String formname = ResManager.loadKDString("确认签约信息", "ContractBillList_12", "fi-er-formplugin", new Object[0]); + if ("updateconsign".equals(operateKey)) { + if (!"F".equals(contractDy.get("billstatus")) || !"biztype_applybill".equals(contractDy.getString("detailtype"))) { + view.showTipNotification(ResManager.loadKDString("单据类型为“合同台账”,合同状态为“执行中”时才能执行此操作。", "ContractBillList_14", "fi-er-formplugin", new Object[0])); + args.setCancel(true); + return; + } + + formname = ResManager.loadKDString("更新签约信息", "ContractBillList_13", "fi-er-formplugin", new Object[0]); + } else if ("docontractsign".equals(operateKey) && (!"E".equals(contractDy.get("billstatus")) || !"biztype_applybill".equals(contractDy.getString("detailtype")))) { + view.showTipNotification(ResManager.loadKDString("单据类型为“合同台账”,合同状态为“审核通过”时才能执行此操作。", "ContractBillList_11", "fi-er-formplugin", new Object[0])); + args.setCancel(true); + return; + } + + FormShowParameter showParameter = new FormShowParameter(); + Map customParam = new HashMap(); + customParam.put("contractId", primaryKeyValue[0]); + showParameter.setFormId("er_contractsign"); + showParameter.setCustomParams(customParam); + showParameter.setCaption(formname); + showParameter.setCloseCallBack(new CloseCallBack(this, "er_contractsign")); + showParameter.getOpenStyle().setShowType(ShowType.Modal); + this.getView().showForm(showParameter); + } else { + view.showTipNotification(ResManager.loadKDString("请选择一条数据进行操作。", "ContractBillList_10", "fi-er-formplugin", new Object[0])); + args.setCancel(true); + } + } + + public void closedCallBack(ClosedCallBackEvent evt) { + super.closedCallBack(evt); + String actionId = evt.getActionId(); + if (StringUtils.equalsIgnoreCase("er_contractsign", actionId)) { + Map returnData = (Map) evt.getReturnData(); + if (returnData != null && returnData.containsKey("ok") && returnData.containsKey("attachmentData")) { + ContractUtil.synAttachment(this.getView(), returnData); + } + } + + } +} diff --git a/code/zcdev/zcgj-zcdev-zcdev-fs/src/main/java/zcgj/zcdev/zcdev/fs/plugin/form/ContractUtilExt.java b/code/zcdev/zcgj-zcdev-zcdev-fs/src/main/java/zcgj/zcdev/zcdev/fs/plugin/form/ContractUtilExt.java new file mode 100644 index 0000000..ef181bf --- /dev/null +++ b/code/zcdev/zcgj-zcdev-zcdev-fs/src/main/java/zcgj/zcdev/zcdev/fs/plugin/form/ContractUtilExt.java @@ -0,0 +1,2311 @@ +// +// Source code recreated from a .class file by IntelliJ IDEA +// (powered by FernFlower decompiler) +// + +package zcgj.zcdev.zcdev.fs.plugin.form; + +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; +import com.google.common.collect.Lists; +import com.google.common.collect.Sets; + +import java.math.BigDecimal; +import java.math.RoundingMode; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.time.LocalDate; +import java.util.ArrayList; +import java.util.Arrays; +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.Objects; +import java.util.Set; +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import java.util.stream.Collectors; + +import kd.bos.bill.MobileFormPosition; +import kd.bos.context.RequestContext; +import kd.bos.dataentity.entity.DynamicObject; +import kd.bos.dataentity.entity.DynamicObjectCollection; +import kd.bos.dataentity.entity.OrmLocaleValue; +import kd.bos.dataentity.metadata.IDataEntityProperty; +import kd.bos.dataentity.metadata.clr.DataEntityPropertyCollection; +import kd.bos.dataentity.metadata.dynamicobject.DynamicObjectType; +import kd.bos.dataentity.resource.ResManager; +import kd.bos.entity.BillEntityType; +import kd.bos.entity.botp.runtime.ConvertOperationResult; +import kd.bos.entity.botp.runtime.DrawArgs; +import kd.bos.entity.datamodel.IBillModel; +import kd.bos.entity.datamodel.IDataModel; +import kd.bos.entity.datamodel.ListSelectedRow; +import kd.bos.entity.datamodel.ListSelectedRowCollection; +import kd.bos.exception.KDBizException; +import kd.bos.form.CloseCallBack; +import kd.bos.form.FormConfig; +import kd.bos.form.FormMetadataCache; +import kd.bos.form.FormShowParameter; +import kd.bos.form.IFormView; +import kd.bos.form.ShowType; +import kd.bos.form.cardentry.CardEntry; +import kd.bos.form.container.AdvContainer; +import kd.bos.form.control.EntryGrid; +import kd.bos.form.control.Label; +import kd.bos.form.events.BeforeDoOperationEventArgs; +import kd.bos.form.events.ClosedCallBackEvent; +import kd.bos.form.field.BasedataEdit; +import kd.bos.form.field.DateEdit; +import kd.bos.form.field.FieldEdit; +import kd.bos.form.field.events.BeforeF7SelectEvent; +import kd.bos.form.field.events.BeforeF7SelectListener; +import kd.bos.form.plugin.AbstractFormPlugin; +import kd.bos.form.plugin.IFormPlugin; +import kd.bos.list.BillList; +import kd.bos.list.IMobileListView; +import kd.bos.list.ListShowParameter; +import kd.bos.list.MobileListShowParameter; +import kd.bos.logging.Log; +import kd.bos.logging.LogFactory; +import kd.bos.orm.ORM; +import kd.bos.orm.query.QFilter; +import kd.bos.servicehelper.AttachmentServiceHelper; +import kd.bos.servicehelper.BusinessDataServiceHelper; +import kd.bos.servicehelper.QueryServiceHelper; +import kd.bos.servicehelper.basedata.BaseDataServiceHelper; +import kd.bos.servicehelper.botp.ConvertServiceHelper; +import kd.bos.servicehelper.operation.SaveServiceHelper; +import kd.bos.servicehelper.user.UserServiceHelper; +import kd.fi.er.business.daily.reimburse.WriteOffTypeEnum; +import kd.fi.er.business.dao.impl.ErDaoOrmImpl; +import kd.fi.er.business.pub.ContractUtil; +import kd.fi.er.business.servicehelper.CommonServiceHelper; +import kd.fi.er.business.servicehelper.ExpenseItemServiceHelper; +import kd.fi.er.business.trip.util.TripCommonUtil; +import kd.fi.er.business.utils.AmountChangeUtil; +import kd.fi.er.business.utils.AmountUtils; +import kd.fi.er.business.utils.AttachmentUtils; +import kd.fi.er.business.utils.BotpDrawServiceUtil; +import kd.fi.er.business.utils.ErCommonUtils; +import kd.fi.er.business.utils.ErStdConfig; +import kd.fi.er.business.utils.SystemParamterUtil; +import kd.fi.er.common.PayerTypeEnum; +import kd.fi.er.common.ShowPageUtils; +import kd.fi.er.common.field.writeoffmoney.ContractProjectWriteOffFields; +import kd.fi.er.common.field.writeoffmoney.WriteOffFields; +import kd.fi.er.formplugin.util.EntryCopyUtil; +import kd.fi.er.model.EntityInfo; +import kd.fi.er.opplugin.daily.web.importplugin.utils.ImportUtils; +import org.apache.commons.lang.StringUtils; +import org.apache.commons.lang3.ObjectUtils; + +public class ContractUtilExt { + private static Log logger = LogFactory.getLog(ContractUtilExt.class); + private static ErDaoOrmImpl dao; + public static final String CONTACT_SELECT_FIELD = "id,entry_linkman.contactperson,entry_linkman.phone"; + public static final String CONTRACT_HEAD_FIELD = "applier,costcompany,iscurrency,partbtype,partb"; + private static final String EXPENSEITEM_ID = "expenseitem.id"; + public static final String UID_PREFIX_CONTRACT = "contract"; + private static Set frozenOPs = new HashSet() { + { + this.add("^push"); + this.add("^invalid"); + } + }; + public static final int PRECISION = 4; + public static final long DIVISIOR = 100L; + + public ContractUtilExt() { + } + + public static void refreshExpTaxAmount(IDataModel model, IFormView view, int rowIndex, Boolean needRecalculate) { + int precision = 4; + DynamicObject expenseCurrencyDO = (DynamicObject) model.getValue("entrycurrency", rowIndex); + if (expenseCurrencyDO != null) { + precision = expenseCurrencyDO.getInt("amtprecision"); + } + + BigDecimal expAmount = (BigDecimal) model.getValue("expenseamount", rowIndex); + BigDecimal taxRate = (BigDecimal) model.getValue("taxrate", rowIndex); + taxRate = taxRate.divide(BigDecimal.valueOf(100L), 4, RoundingMode.HALF_EVEN); + BigDecimal expTaxAmount; + if (needRecalculate) { + expTaxAmount = expAmount.divide(BigDecimal.ONE.add(taxRate), precision, RoundingMode.HALF_EVEN).multiply(taxRate); + } else { + expTaxAmount = (BigDecimal) model.getValue("taxamount", rowIndex); + } + + model.setValue("actaxamount", expTaxAmount, rowIndex); + model.setValue("taxamount", expTaxAmount, rowIndex); + model.setValue("orientryamount", expAmount.subtract(expTaxAmount), rowIndex); + model.setValue("acorientryamount", expAmount.subtract(expTaxAmount), rowIndex); + } + + public static void setFrameworkcontractChange(IDataModel model, IFormView view, Boolean newValueBoolean) { + AdvContainer advconap311 = (AdvContainer) view.getControl("advconap311"); + AdvContainer advconap3 = (AdvContainer) view.getControl("advconap3"); + if (!newValueBoolean) { + view.setVisible(true, new String[]{"advconap3"}); + view.setVisible(true, new String[]{"advconap311"}); + advconap311.setCollapse(false); + advconap3.setCollapse(false); + view.setVisible(true, new String[]{"projecttype"}); + ((BasedataEdit) view.getControl("projecttype")).setMustInput(true); + ((FieldEdit) view.getControl("payterms")).setMustInput(true); + ((FieldEdit) view.getControl("contractcurrency")).setMustInput(true); + ((FieldEdit) view.getControl("changerate")).setMustInput(true); + ((EntryGrid) view.getControl("expenseentryentity")).setMustInput("expenseentryentity", true); + } else { + DynamicObjectCollection expenseentryentity = model.getEntryEntity("expenseentryentity"); + int[] indexArr = new int[expenseentryentity.size()]; + + for (int i = 0; i < expenseentryentity.size(); ++i) { + indexArr[i] = ((DynamicObject) expenseentryentity.get(i)).getInt("seq") - 1; + } + + model.deleteEntryRows("expenseentryentity", indexArr); + view.updateView("expenseentryentity"); + model.beginInit(); + model.setValue("contractamount", (Object) null); + model.setValue("oriapplyamount", (Object) null); + model.setValue("originalamount", (Object) null); + model.setValue("orinotpayamount", (Object) null); + model.setValue("changeamount", (Object) null); + model.setValue("billtaxrate", (Object) null); + model.setValue("projecttype", (Object) null); + model.endInit(); + view.updateView("advconap311"); + view.updateView("projecttype"); + view.setVisible(false, new String[]{"advconap3"}); + view.setVisible(false, new String[]{"advconap311"}); + advconap311.setCollapse(true); + advconap3.setCollapse(true); + ((BasedataEdit) view.getControl("projecttype")).setMustInput(false); + view.setVisible(false, new String[]{"projecttype"}); + model.setValue("projecttype", (Object) null); + ((FieldEdit) view.getControl("payterms")).setMustInput(false); + ((FieldEdit) view.getControl("contractcurrency")).setMustInput(false); + ((FieldEdit) view.getControl("changerate")).setMustInput(false); + } + } + + public static void refreshExpCurrAmount(IDataModel model, IFormView view, int rowIndex, Boolean iscalculate) { + DynamicObject expCurrency = (DynamicObject) model.getValue("contractcurrency"); + DynamicObject currency = (DynamicObject) model.getValue("currency"); + Map changeMap = AmountChangeUtil.refreshEnrtyExchangeRate(model, view, expCurrency); + String quoteType = (String) ObjectUtils.defaultIfNull((String) changeMap.get("quoteType"), "0"); + BigDecimal exchangeRate = (BigDecimal) ObjectUtils.defaultIfNull((BigDecimal) model.getValue("exchangerate", rowIndex), BigDecimal.ONE); + int precision = AmountUtils.getCurrencyPrecision(ErCommonUtils.getPk(currency)); + boolean ispaybyrata = (Boolean) model.getValue("paybyrata"); + BigDecimal expAmount; + BigDecimal currencyAmount; + if (ispaybyrata && iscalculate) { + currencyAmount = (BigDecimal) model.getValue("prorataamount"); + expAmount = currencyAmount.multiply((BigDecimal) model.getValue("paypercent", rowIndex)).setScale(precision, RoundingMode.HALF_UP).divide(BigDecimal.valueOf(100L)); + BigDecimal taxamount = (BigDecimal) model.getValue("taxamount", rowIndex); + model.beginInit(); + model.setValue("expenseamount", expAmount, rowIndex); + model.setValue("orgiexpebalanceamount", expAmount, rowIndex); + model.setValue("canloanamount", expAmount, rowIndex); + model.setValue("oriexpnotpayamount", expAmount, rowIndex); + model.setValue("orientryamount", expAmount.subtract(taxamount), rowIndex); + model.setValue("acexpeapproveamount", expAmount, rowIndex); + model.endInit(); + view.updateView("expenseamount", rowIndex); + view.updateView("orgiexpebalanceamount", rowIndex); + view.updateView("canloanamount", rowIndex); + view.updateView("oriexpnotpayamount", rowIndex); + view.updateView("orientryamount", rowIndex); + view.updateView("acexpeapproveamount", rowIndex); + } else { + expAmount = (BigDecimal) model.getValue("expenseamount", rowIndex); + } + + currencyAmount = AmountUtils.getCurrencyAmount(expAmount, exchangeRate, precision, quoteType); + model.setValue("currexpenseamount", currencyAmount, rowIndex); + model.setValue("acexpeapprovecurramount", currencyAmount, rowIndex); + } + + public static void refreshEntryValue(IDataModel model, Object value, String propName) { + int entryCount = model.getEntryRowCount("expenseentryentity"); + IDataEntityProperty prop = model.getProperty(propName); + if (prop != null) { + for (int index = 0; index < entryCount; ++index) { + model.setValue(propName, value, index); + } + + } + } + + public static void refreshExchangeRate(IDataModel model, IFormView view, DynamicObject currency, String changeRateProp, String quoteTypeProp) { + Map changeMap = AmountChangeUtil.refreshEnrtyExchangeRate(model, view, currency); + String quoteType = (String) ObjectUtils.defaultIfNull((String) changeMap.get("quoteType"), "0"); + model.setValue(quoteTypeProp, quoteType); + BigDecimal exchangeRate = (BigDecimal) ObjectUtils.defaultIfNull((BigDecimal) changeMap.get("exchangeRate"), BigDecimal.ONE); + model.setValue(changeRateProp, exchangeRate); + } + + public static void refreshOriEntryAmount(IDataModel model, IFormView view, int rowIndex) { + BigDecimal expAmount = (BigDecimal) model.getValue("expenseamount", rowIndex); + BigDecimal expTaxAmount = (BigDecimal) model.getValue("taxamount", rowIndex); + BigDecimal oriEntryAmount = expAmount.subtract(expTaxAmount); + model.setValue("orientryamount", oriEntryAmount, rowIndex); + model.setValue("acorientryamount", oriEntryAmount, rowIndex); + } + + public static void refreshExpPriceWithTax(IDataModel model, IFormView view, int rowIndex) { + BigDecimal expAmount = (BigDecimal) model.getValue("expenseamount", rowIndex); + Integer num = (Integer) model.getValue("num", rowIndex); + int precision = AmountUtils.getCurrencyPrecision(model, "currency"); + if (num != null && num > 0) { + BigDecimal priceWithTax = expAmount.divide(BigDecimal.valueOf((long) num), precision, RoundingMode.HALF_EVEN); + model.setValue("exppricewithtax", priceWithTax, rowIndex); + } + + } + + public static void refreshHeadAmountByExpense(IDataModel model, IFormView view) { + DynamicObjectCollection entries = model.getEntryEntity("expenseentryentity"); + BigDecimal headAmount; + if (entries != null && !entries.isEmpty()) { + headAmount = (BigDecimal) entries.stream().map((d) -> { + return d.get("expenseamount") == null ? BigDecimal.ZERO : (BigDecimal) d.get("expenseamount"); + }).reduce(BigDecimal.ZERO, BigDecimal::add); + } else { + headAmount = BigDecimal.ZERO; + } + + model.setValue("oriapplyamount", headAmount); + if (model.getValue("detailtype").equals("biztype_applybill")) { + model.setValue("contractamount", headAmount); + } + + } + + public static void refreshBillTaxAmountByExpense(IDataModel model, IFormView view) { + DynamicObjectCollection entries = model.getEntryEntity("expenseentryentity"); + if (entries != null && !entries.isEmpty()) { + BigDecimal billTaxAmount = (BigDecimal) entries.stream().map((d) -> { + return d.get("taxamount") == null ? BigDecimal.ZERO : (BigDecimal) d.get("taxamount"); + }).reduce(BigDecimal.ZERO, BigDecimal::add); + model.setValue("billtaxamount", billTaxAmount); + } + } + + public static void refreshOriginalAmount(IDataModel model, IFormView view) { + BigDecimal originalAmount = BigDecimal.ZERO; + DynamicObjectCollection exps = model.getEntryEntity("expenseentryentity"); + + for (int index = 0; index < exps.size(); ++index) { + BigDecimal orientryAmount = (BigDecimal) model.getValue("orientryamount", index); + originalAmount = originalAmount.add(orientryAmount); + } + + model.setValue("originalamount", originalAmount); + } + + public static void refreshBillTaxAmount(IDataModel model, IFormView view) { + BigDecimal applyAmount = (BigDecimal) model.getValue("oriapplyamount"); + BigDecimal billTaxRate = (BigDecimal) model.getValue("billtaxrate"); + billTaxRate = billTaxRate.divide(BigDecimal.valueOf(100L), 4, RoundingMode.HALF_EVEN); + BigDecimal taxAmount = applyAmount.divide(BigDecimal.ONE.add(billTaxRate), 4, RoundingMode.HALF_EVEN).multiply(billTaxRate); + if (billTaxRate.compareTo(BigDecimal.ZERO) != 0) { + model.setValue("billtaxamount", taxAmount); + } + + if (taxAmount.compareTo(BigDecimal.ZERO) == 0) { + model.setValue("originalamount", applyAmount); + } + + } + + public static void setHeadPart(IDataModel model, int rowIndex, Object newPart) { + DynamicObject part = (DynamicObject) newPart; + if (rowIndex == 0) { + String partatypenew = (String) model.getValue("partytype", rowIndex); + model.setValue("partatypenew", partatypenew); + model.setValue("partanew", part); + if ("bos_org".equals(partatypenew)) { + model.setValue("parta", part); + } else { + model.setValue("parta", (Object) null); + } + } else if (rowIndex == 1) { + model.setValue("partbtype", model.getValue("partytype", rowIndex)); + model.setValue("partb", part); + } else { + DynamicObjectCollection parties = model.getEntryEntity("contractpartyentry"); + if (parties == null || parties.size() <= 2) { + return; + } + + if (parties.get(2) != null) { + DynamicObject partOther = (DynamicObject) parties.get(2); + if ((DynamicObject) partOther.get("contractparty") == null) { + return; + } + + OrmLocaleValue partNameORM = (OrmLocaleValue) ((DynamicObject) partOther.get("contractparty")).get("name"); + String partName = partNameORM.getLocaleValue(); + + for (int index = 3; index < parties.size(); ++index) { + DynamicObject partI = (DynamicObject) parties.get(index); + DynamicObject contract = (DynamicObject) partI.get("contractparty"); + if (contract != null) { + partName = String.format("%1$s%2$s%3$s", partName, ";", ((OrmLocaleValue) contract.get("name")).getLocaleValue()); + } + } + + model.setValue("partother", partName); + } + } + + } + + public static void setHeadConnContracts(IDataModel model) { + DynamicObjectCollection contracts = model.getEntryEntity("contractrelation"); + StringBuffer contractsFiled = new StringBuffer(); + if (contracts != null) { + Iterator var3 = contracts.iterator(); + + while (var3.hasNext()) { + DynamicObject contract = (DynamicObject) var3.next(); + String billNo = contract.getString("basedatabillno"); + contractsFiled.append(billNo); + } + } + + model.setValue("contractsconn", contractsFiled); + } + + public static void setDefaultParty(IFormView view) { + IDataModel model = view.getModel(); + DynamicObjectCollection parties = model.getEntryEntity("contractpartyentry"); + setPartyEntry(view); + model.setValue("partytype", "bos_org", 0); + model.setValue("signcontract", "0", 0); + model.setValue("partytype", "bd_supplier", 1); + model.setValue("signcontract", "1", 1); + } + + public static void setPartyEntry(IFormView view) { + DynamicObjectCollection parties = view.getModel().getEntryEntity("contractpartyentry"); + if (parties == null || parties.size() <= 1) { + int currSize; + if (parties == null) { + currSize = 0; + } else { + currSize = parties.size(); + } + + view.getModel().batchCreateNewEntryRow("contractpartyentry", 2 - currSize); + } + } + + public static void resolvePushChange(EventObject e, IFormView view) { + IDataModel model = view.getModel(); + if (model.getDataEntity().getDataEntityState().isPushChanged()) { + } + + } + + public static void refreshHeadContacts(IFormView view, EventObject e) { + IDataModel model = view.getModel(); + DynamicObjectCollection contracts = model.getEntryEntity("contractrelation"); + if (contracts != null && contracts.size() != 0) { + DynamicObject contractF = (DynamicObject) contracts.get(0); + String billNos = contractF.getString("basedatabillno"); + + for (int index = 1; index < contracts.size(); ++index) { + DynamicObject contract = (DynamicObject) contracts.get(index); + billNos = String.format("%1$s%2$s%3$s", billNos, ";", contract.getString("basedatabillno")); + } + + model.setValue("contractsconn", billNos); + } else { + model.setValue("contractsconn", (Object) null); + } + } + + public static void setTel(IDataModel model, int rowIndex) { + DynamicObject part = (DynamicObject) model.getValue("contractparty", rowIndex); + if (part == null) { + clearTel(model, rowIndex); + } else { + Long partId = part != null ? (Long) part.getPkValue() : 0L; + String entityName = part.getDataEntityType().getName(); + if ("bos_org".equals(entityName) || "bos_adminorg".equals(entityName)) { + return; + } + + QFilter defQ = new QFilter("entry_linkman.isdefault_linkman", "=", Boolean.TRUE); + DynamicObjectCollection parts = QueryServiceHelper.query(entityName, "id,entry_linkman.contactperson,entry_linkman.phone", new QFilter[]{new QFilter("id", "=", partId), defQ}); + if (parts == null || parts.size() <= 0) { + return; + } + + DynamicObject contact = (DynamicObject) parts.get(0); + model.setValue("contactperson", contact.get("entry_linkman.contactperson"), rowIndex); + model.setValue("signtel", contact.get("entry_linkman.phone"), rowIndex); + } + + } + + public static void clearTel(IDataModel model, int rowIndex) { + model.setValue("contactperson", (Object) null, rowIndex); + model.setValue("signtel", (Object) null, rowIndex); + } + + public static void refreshWriteOffAmount(IDataModel model, WriteOffFields fields) { + String writeOffType = (String) model.getValue("writeofftype"); + if (writeOffType.equals("1")) { + writeOffOri(model, fields.entryKey, fields.approveAmtOriKey, fields.entryCurrencyKey, fields.checkAmtOriKey, fields.checkAmtKey); + } else { + writeOffCurr(model, fields.entryKey, fields.approveAmtKey, fields.approveAmtOriKey, fields.checkAmtOriKey, fields.checkAmtKey, fields.entryQuoteTypeKey, fields.entryExchangerateKey, fields.expAmountKey); + } + + } + + private static void writeOffCurr(IDataModel dataModel, String writeOffEntryProp, String canAmountProp, String oriCanAmountProp, String writeAmountProp, String currWriteAmountProp, String quoteTypeProp, String changeRateProp, String expAmountKey) { + BigDecimal currReimburseAmount = AmountUtils.getEntryAmount(dataModel, "expenseentryentity", expAmountKey); + DynamicObjectCollection woEntrys = dataModel.getEntryEntity(writeOffEntryProp); + + for (int i = 0; i < woEntrys.size(); ++i) { + DynamicObject woEntry = (DynamicObject) woEntrys.get(i); + BigDecimal woCurrAmount; + if (currReimburseAmount.compareTo(BigDecimal.ZERO) > 0) { + woCurrAmount = woEntry.getBigDecimal(canAmountProp); + if (woCurrAmount.compareTo(currReimburseAmount) > 0) { + dataModel.setValue(currWriteAmountProp, currReimburseAmount, i); + } else { + dataModel.setValue(currWriteAmountProp, woCurrAmount, i); + } + + currReimburseAmount = currReimburseAmount.subtract(woCurrAmount); + } else { + dataModel.setValue(currWriteAmountProp, BigDecimal.ZERO, i); + } + + woCurrAmount = woEntry.getBigDecimal(currWriteAmountProp); + if (woCurrAmount.compareTo(woEntry.getBigDecimal(canAmountProp)) == 0) { + dataModel.setValue(writeAmountProp, woEntry.getBigDecimal(oriCanAmountProp), i); + } else { + BigDecimal woExchageRate = woEntry.getBigDecimal(changeRateProp); + if (woExchageRate == null || woExchageRate.compareTo(BigDecimal.ZERO) == 0) { + woExchageRate = BigDecimal.ONE; + } + + String quoteType = dataModel.getProperty(quoteTypeProp) == null ? "0" : (String) woEntry.get(quoteTypeProp); + int precision = AmountUtils.getAmountFieldPrecision(woEntry, writeAmountProp); + BigDecimal accloanamount; + if ("0".equals(quoteType)) { + accloanamount = woCurrAmount.divide(woExchageRate, precision, RoundingMode.HALF_UP); + } else { + accloanamount = woCurrAmount.multiply(woExchageRate).setScale(precision, RoundingMode.HALF_UP); + } + + dataModel.setValue(writeAmountProp, accloanamount, i); + } + } + + } + + private static void writeOffOri(IDataModel dataModel, String writeOffEntryProp, String canAmountProp, String writeCurrency, String writeAmountProp, String currWriteAmountProp) { + Set expeIds = AmountUtils.getCurrencyIdSet(dataModel, "expenseentryentity", "entrycurrency"); + Set woIds = AmountUtils.getCurrencyIdSet(dataModel, writeOffEntryProp, writeCurrency); + Set totalIds = Sets.newHashSet(); + totalIds.addAll(woIds); + totalIds.addAll(expeIds); + int len = expeIds.size() + woIds.size(); + DynamicObjectCollection woColl; + if (totalIds.size() == len) { + woColl = dataModel.getEntryEntity(writeOffEntryProp); + + for (int i = 0; i < woColl.size(); ++i) { + dataModel.setValue(writeAmountProp, BigDecimal.ZERO, i); + dataModel.setValue(currWriteAmountProp, BigDecimal.ZERO, i); + } + + } else { + woColl = dataModel.getEntryEntity("expenseentryentity"); +// DynamicObjectCollection woColl = dataModel.getEntryEntity(writeOffEntryProp);//二开注释掉的 + woColl = dataModel.getEntryEntity(writeOffEntryProp);//二开添加的 + Map expeCurrcyAmount = null; + if ("projectentryentity".equals(writeOffEntryProp)) { + expeCurrcyAmount = AmountUtils.groupByCurrency(woColl, "entrycurrency", "expenseamount"); + } else { + expeCurrcyAmount = AmountUtils.groupByCurrency(woColl, "entrycurrency", "expeapproveamount"); + } + + Iterator var13 = expeCurrcyAmount.entrySet().iterator(); + + while (true) { + Map.Entry entry; + do { + if (!var13.hasNext()) { + return; + } + + entry = (Map.Entry) var13.next(); + } while (((BigDecimal) entry.getValue()).compareTo(BigDecimal.ZERO) < 0); + + for (int i = 0; i < woColl.size(); ++i) { + DynamicObject woDynamicObject = (DynamicObject) woColl.get(i); + String currcyId = ""; + if (woDynamicObject != null && woDynamicObject.get(writeCurrency) != null) { + currcyId = ((DynamicObject) woDynamicObject.get(writeCurrency)).getPkValue().toString(); + } + + if (((String) entry.getKey()).equals(currcyId)) { + if (woDynamicObject != null && ((BigDecimal) entry.getValue()).compareTo(woDynamicObject.getBigDecimal(canAmountProp)) > 0) { + dataModel.setValue(writeAmountProp, woDynamicObject.getBigDecimal(canAmountProp), i); + entry.setValue(((BigDecimal) entry.getValue()).subtract(woDynamicObject.getBigDecimal(canAmountProp))); + } else { + dataModel.setValue(writeAmountProp, entry.getValue(), i); + entry.setValue(BigDecimal.ZERO); + } + } + + if (!expeCurrcyAmount.containsKey(currcyId)) { + dataModel.setValue(writeAmountProp, BigDecimal.ZERO, i); + } + } + } + } + } + + public static void refreshWriteOffCurrAmount(IDataModel model, int index, IFormView view) { + String writeOffType = (String) model.getValue("writeofftype"); + BigDecimal expAmount = (BigDecimal) model.getValue("oriprojectwriteoffamount", index); + BigDecimal projAmount = (BigDecimal) model.getValue("oriprojectcanamount", index); + if (writeOffType.equals(WriteOffTypeEnum.ORGI_WO.getValue()) && !currencyValidate(model, index, "entrycurrency", "projectcurrency") && expAmount.compareTo(BigDecimal.ZERO) > 0) { + view.showTipNotification(ResManager.loadKDString("该币别不在费用明细中,不能冲销。", "ContractUtil_20", "fi-er-business", new Object[0])); + model.setValue("oriprojectwriteoffamount", BigDecimal.ZERO, index); + } else { + if (expAmount.compareTo(projAmount) > 0) { + model.setValue("oriprojectwriteoffamount", projAmount, index); + expAmount = projAmount; + } + + BigDecimal exchangeRate = model.getValue("projectchangerate", index) == null ? BigDecimal.ZERO : (BigDecimal) model.getValue("projectchangerate", index); + String quoteType = (String) ObjectUtils.defaultIfNull((String) model.getValue("projectquotetype", index), "0"); + DynamicObject currency = (DynamicObject) model.getValue("currency", index); + if (null != currency) { + int precision = AmountUtils.getCurrencyPrecision(ErCommonUtils.getPk(currency)); + BigDecimal currencyAmount = AmountUtils.getCurrencyAmount(expAmount, exchangeRate, precision, quoteType); + model.setValue("projectwriteoffamount", currencyAmount, index); + } + } + } + + public static boolean currencyValidate(IDataModel dataModel, int index, String entryCurrency, String projectCurrency) { + Set currencyIds = AmountUtils.getCurrencyIdSet(dataModel, "expenseentryentity", entryCurrency); + DynamicObject writeOffCurrency = (DynamicObject) dataModel.getValue(projectCurrency, index); + return writeOffCurrency == null || currencyIds.contains(writeOffCurrency.getPkValue()); + } + + public static boolean froze(Long billId, IFormView view) { + dao = new ErDaoOrmImpl("er_contractbill"); + DynamicObject[] collection = dao.query(new QFilter("id", "=", billId)); + if (collection.length > 0) { + DynamicObject bill = collection[0]; + String billStatus = bill.getString("billstatus"); + if (!billStatus.equals("E") && !billStatus.equals("F")) { + view.showTipNotification(ResManager.loadKDString("仅审核通过或执行中的单据允许冻结。", "ContractUtil_0", "fi-er-business", new Object[0])); + return false; + } else { + bill.set("billstatus", "J"); + bill.set("beforefrozenstatu", billStatus); + SaveServiceHelper.save(new DynamicObject[]{bill}); + view.invokeOperation("refresh"); + return true; + } + } else { + return false; + } + } + + public static boolean isFrozen(List status) { + Iterator var1 = status.iterator(); + + String st; + do { + if (!var1.hasNext()) { + return false; + } + + st = (String) var1.next(); + } while (!st.equals("J")); + + return true; + } + + public static boolean unFroze(Long billId, IFormView view) { + dao = new ErDaoOrmImpl("er_contractbill"); + DynamicObject[] collection = dao.query(new QFilter("id", "=", billId)); + if (collection.length > 0) { + DynamicObject bill = collection[0]; + String billStatus = bill.getString("billstatus"); + if (!billStatus.equals("J")) { + view.showTipNotification(ResManager.loadKDString("仅冻结的单据允许解冻。", "ContractUtil_35", "fi-er-business", new Object[0])); + return false; + } else { + String beforeStatus = bill.getString("beforefrozenstatu"); + bill.set("billstatus", beforeStatus); + SaveServiceHelper.save(new DynamicObject[]{bill}); + view.invokeOperation("refresh"); + return true; + } + } else { + return false; + } + } + + public static boolean isFrozenOp(String opKey) { + return frozenOPs.stream().anyMatch((s) -> { + Pattern p = Pattern.compile(s); + Matcher m = p.matcher(opKey); + return m.find(); + }); + } + + public static void setCurrency(IDataModel model) { + DynamicObject headCurrency = (DynamicObject) model.getValue("currency"); + if (headCurrency != null) { + model.setValue("contractcurrency", headCurrency); + } + } + + public static void clearExpAmount(IDataModel model, IFormView view) { + DynamicObjectCollection expcoll = model.getDataEntity(true).getDynamicObjectCollection("expenseentryentity"); + + for (int i = 0; i < expcoll.size(); ++i) { + model.setValue("expenseamount", BigDecimal.ZERO, i); + model.setValue("currexpenseamount", BigDecimal.ZERO, i); + model.setValue("taxamount", BigDecimal.ZERO, i); + model.setValue("orientryamount", BigDecimal.ZERO, i); + view.updateView("expenseamount", i); + } + + } + + public static void changeBillHeadContractsconn(IDataModel model, String entry) { + if (entry == null || "expenseentryentity".equals(entry)) { + DataEntityPropertyCollection properties = model.getDataEntityType().getProperties(); + IDataEntityProperty contractsconn = (IDataEntityProperty) properties.get("contractsconn"); + if (contractsconn != null) { + String contractno = (String) model.getEntryEntity("expenseentryentity").stream().map((it) -> { + return it.getString("entrycontractno"); + }).filter(StringUtils::isNotBlank).distinct().collect(Collectors.joining(",")); + model.setValue("contractsconn", contractno); + } + + } + } + + public static boolean checkMultiPublicReim(ListSelectedRowCollection rows, IFormView view) { + Set errFields = new HashSet(5); + if (rows.size() == 1) { + return true; + } else { + ListSelectedRow baseRow = rows.get(0); + DynamicObject base = QueryServiceHelper.queryOne("er_contractbill", "applier,costcompany,iscurrency,partbtype,partb", new QFilter[]{new QFilter("id", "=", baseRow.getPrimaryKeyValue())}); + + for (int index = 1; index < rows.size(); ++index) { + ListSelectedRow itemRow = rows.get(index); + DynamicObject item = QueryServiceHelper.queryOne("er_contractbill", "applier,costcompany,iscurrency,partbtype,partb", new QFilter[]{new QFilter("id", "=", itemRow.getPrimaryKeyValue())}); + if (item.getLong("applier") != base.getLong("applier")) { + errFields.add(ResManager.loadKDString("经办人", "ContractUtil_2", "fi-er-business", new Object[0])); + } + + if (item.getLong("costcompany") != base.getLong("costcompany")) { + errFields.add(ResManager.loadKDString("核算组织", "ContractUtil_3", "fi-er-business", new Object[0])); + } + + if (item.getBoolean("iscurrency") ^ base.getBoolean("iscurrency")) { + errFields.add(ResManager.loadKDString("多币别", "ContractUtil_4", "fi-er-business", new Object[0])); + } + + if (!item.getString("partbtype").equals(base.getString("partbtype"))) { + errFields.add(ResManager.loadKDString("乙方类型", "ContractUtil_5", "fi-er-business", new Object[0])); + } + + if (item.getLong("partb") != base.getLong("partb")) { + errFields.add(ResManager.loadKDString("乙方", "ContractUtil_6", "fi-er-business", new Object[0])); + } + } + + if (errFields.size() > 0) { + String msg = String.join(",", errFields); + view.showTipNotification(String.format(ResManager.loadKDString("已选单据%1$s不一致,请检查。", "ContractUtil_1", "fi-er-business", new Object[0]), msg)); + return false; + } else { + return true; + } + } + } + + public static void controlEndDate(IDataModel model, Object newValue, DateEdit endDateControl) { + if (newValue != null) { + Date beginDate = (Date) newValue; + endDateControl.setMinDate((Date) newValue); + Date endDate = (Date) model.getValue("enddate"); + if (endDate != null) { + if (endDate.before(beginDate)) { + model.setValue("enddate", beginDate); + } + + } + } + } + + public static String handleHeadDataForContractBill(Map dataMap) { + new Date(); + String formatType; + if (dataMap.get("enddate") != null) { + formatType = (String) dataMap.get("enddate"); + new Date(); + if (checkBizdate(formatType) || checkBizdate((String) dataMap.get("startdate")) || checkBizdate((String) dataMap.get("signdate"))) { + throw new KDBizException(ResManager.loadKDString("签约日期、起始日期、截止日期中存在错误的日期格式", "ContractUtil_34", "fi-er-business", new Object[0])); + } + + Date stardate; + Date enddate; + try { + stardate = (new SimpleDateFormat("yyyy-MM-dd")).parse((String) dataMap.get("startdate")); + enddate = (new SimpleDateFormat("yyyy-MM-dd")).parse(formatType); + } catch (ParseException var14) { + throw new RuntimeException(var14); + } + + if (enddate.before(stardate)) { + throw new KDBizException(ResManager.loadKDString("截止日期不能早于起始日期。", "ContractUtil_7", "fi-er-business", new Object[0])); + } + } + + formatType = (String) dataMap.get("contractcode"); + DynamicObjectCollection exists = QueryServiceHelper.query("er_contractbill", "billno,stdbilltype", new QFilter[]{new QFilter("contractcode", "=", formatType)}); + if (exists.size() > 0) { + throw new KDBizException(ResManager.loadKDString("合同号已存在,请修改后提交。", "ContractUtil_26", "fi-er-business", new Object[0])); + } else { + JSONObject contractcurrency = (JSONObject) dataMap.get("contractcurrency"); + String contractcurrencyNumber = contractcurrency.getString("number"); + Map exchangeRateAndQuoteMap = getExchangerate(dataMap, contractcurrencyNumber); + BigDecimal exchangerate = (BigDecimal) exchangeRateAndQuoteMap.get("exchangeRate"); + String expquotetype = (String) ObjectUtils.defaultIfNull((String) exchangeRateAndQuoteMap.get("quoteType"), "0"); + Object changerate = dataMap.get("changerate"); +// BigDecimal changerate;//二开注释掉的 + if (changerate != null) { + try { + changerate = new BigDecimal(String.valueOf(changerate)); + dataMap.put("changerate", changerate); + } catch (Exception var13) { + throw new KDBizException(ResManager.loadKDString("汇率格式不正确。", "ErBillBaseImportHandle_10", "fi-er-opplugin", new Object[0])); + } + } else { + changerate = exchangerate; + } + + if (changerate == null) { + throw new KDBizException(ResManager.loadKDString("该币别在汇率表中没有对应的汇率,请联系管理员进行设置或手工填写汇率。", "ErPubBillInitImportBaseHandle_27", "fi-er-opplugin", new Object[0])); + } else { + dataMap.put("changerate", changerate); + dataMap.put("quotetype", expquotetype); + if (!contractcurrencyNumber.equals(((JSONObject) dataMap.get("currency")).getString("number"))) { + dataMap.put("iscurrency", Boolean.TRUE); + } else { + dataMap.put("iscurrency", Boolean.FALSE); + } + + JSONArray expenseEntry = (JSONArray) dataMap.get("expenseentryentity"); + + for (int i = 0; i < expenseEntry.size(); ++i) { + Map row = (Map) expenseEntry.get(i); + row.put("entrycurrency", contractcurrency); + row.put("exchangerate", changerate); + row.put("expquotetype", expquotetype); + } + + return null; + } + } + } + + private static Map getExchangerate(Map data, String entrycurrencyNumber) { + DynamicObject dynamicObject = BusinessDataServiceHelper.loadSingleFromCache("bd_currency", new QFilter[]{new QFilter("number", "=", entrycurrencyNumber), new QFilter("enable", "=", "1")}); + if (dynamicObject == null) { + String msg = String.format(ResManager.loadKDString("编码为%s的币别不存在。", "ContractUtil_8", "fi-er-business", new Object[0]), entrycurrencyNumber); + throw new KDBizException(msg); + } else { + Date curr = null; + + try { + int exchangeRateFrom = SystemParamterUtil.getExchangeRateFrom(((JSONObject) data.get("company")).getLong("id")); + if (0 == exchangeRateFrom) { + curr = new Date(); + } else { + SimpleDateFormat siDateFormat = new SimpleDateFormat("yyyy-MM-dd"); + curr = siDateFormat.parse(data.get("signdate").toString()); + } + } catch (ParseException var6) { + throw new RuntimeException(var6); + } + + Map exchangeRateAndQuoteMap = CommonServiceHelper.getExchangeRateAndQuoteTypeNoDefault(((JSONObject) data.get("company")).getLong("id"), ((JSONObject) data.get("costcompany")).getLong("id"), (Long) dynamicObject.getPkValue(), ((JSONObject) data.get("currency")).getLong("id"), curr); + return exchangeRateAndQuoteMap; + } + } + + public static String handleExpEntryDataForContractBill(Map dataMap) { + JSONArray expenseEntry = (JSONArray) dataMap.get("expenseentryentity"); + BigDecimal originalamount = BigDecimal.ZERO; + BigDecimal oriapplyamount = BigDecimal.ZERO; + BigDecimal applyamount = BigDecimal.ZERO; + BigDecimal balanceamount = BigDecimal.ZERO; + BigDecimal oribalanceamount = BigDecimal.ZERO; + BigDecimal usedamount = BigDecimal.ZERO; + BigDecimal oriusedamount = BigDecimal.ZERO; + BigDecimal billcanloanamount = BigDecimal.ZERO; + BigDecimal oricanloanamount = BigDecimal.ZERO; + BigDecimal loanedamount = BigDecimal.ZERO; + BigDecimal oriloanedamount = BigDecimal.ZERO; + BigDecimal notpayamount = BigDecimal.ZERO; + BigDecimal orinotpayamount = BigDecimal.ZERO; + BigDecimal payedamount = BigDecimal.ZERO; + BigDecimal oripayedamount = BigDecimal.ZERO; + BigDecimal billtaxamount = BigDecimal.ZERO; + BigDecimal tolpaypercent = BigDecimal.ZERO; + BigDecimal prorataamount = BigDecimal.ZERO; + BigDecimal proratataxamount = BigDecimal.ZERO; + boolean paybyrata = Boolean.FALSE; + if (dataMap.get("paybyrata") != null) { + paybyrata = (Boolean) dataMap.get("paybyrata"); + } + + if (paybyrata && dataMap.get("prorataamount") != null) { + prorataamount = new BigDecimal((String) dataMap.get("prorataamount")); + } + + if (paybyrata && dataMap.get("proratataxamount") != null) { + proratataxamount = new BigDecimal((String) dataMap.get("proratataxamount")); + } + + JSONObject contractcurrencyjson = (JSONObject) dataMap.get("contractcurrency"); + DynamicObject contractcurrency = ImportUtils.getCurrencyIdByNumber(contractcurrencyjson.getString("number")); + BigDecimal diff = ErStdConfig.getAccentryDiffRange(); + JSONObject currencyjson = (JSONObject) dataMap.get("currency"); + DynamicObject currency = ImportUtils.getCurrencyIdByNumber(currencyjson.getString("number")); + Object projectTypeExpItemNumbers = dataMap.get("projectTypeExpItemNumbers"); + + for (int i = 0; i < expenseEntry.size(); ++i) { + Map row = (Map) expenseEntry.get(i); + row.put("entrycurrency", contractcurrency); + row.put("expquotetype", dataMap.get("quotetype")); + row.put("exchangerate", dataMap.get("changerate")); + if (projectTypeExpItemNumbers != null) { + String expenseitemnumber = ((JSONObject) row.get("expenseitem")).getString("number"); + List ptExpItemNumbers = (List) projectTypeExpItemNumbers; + if (!ptExpItemNumbers.contains(expenseitemnumber)) { + return ResManager.loadKDString(String.format("编码为%s的费用项目与业务分类所关联的费用项目不匹配。", expenseitemnumber), "ContractUtil_9", "fi-er-business", new Object[0]); + } + } + + if (checkBizdate((String) row.get("happendate"))) { + throw new KDBizException(ResManager.loadKDString("预计付款日期格式错误", "ContractUtil_33", "fi-er-business", new Object[0])); + } + + if (paybyrata && prorataamount.compareTo(BigDecimal.ZERO) == 0) { + return ResManager.loadKDString("按比例付款必须填写:合同金额(prorataamount)。", "ContractUtil_22", "fi-er-business", new Object[0]); + } + + if (paybyrata && row.get("paypercent") == null) { + return ResManager.loadKDString("按比例付款必须填写付款计划分录的付款比例。", "ContractUtil_24", "fi-er-business", new Object[0]); + } + + if (!paybyrata && row.get("expenseamount") == null) { + return ResManager.loadKDString("合同不按比例付款时,必须填写含税金额。", "ContractUtil_25", "fi-er-business", new Object[0]); + } + + BigDecimal paypercent = BigDecimal.ZERO; + BigDecimal expenseamount; + if (paybyrata) { + DynamicObject entrycurrency = (DynamicObject) row.get("entrycurrency"); + paypercent = row.get("paypercent") == null ? BigDecimal.ZERO : new BigDecimal((String) row.get("paypercent")); + expenseamount = prorataamount.multiply(paypercent).divide(BigDecimal.valueOf(100L), entrycurrency.getInt("amtprecision"), RoundingMode.HALF_EVEN); + row.put("expenseamount", expenseamount); + } else { + expenseamount = new BigDecimal((String) row.get("expenseamount")); + } + + int amtprecision = currency.getInt("amtprecision"); + BigDecimal exchangerate = (BigDecimal) row.get("exchangerate"); + String expquotetype = (String) row.get("expquotetype"); + oriapplyamount = oriapplyamount.add(expenseamount); + tolpaypercent = tolpaypercent.add(paypercent); + BigDecimal currexpenseamount; + if (i == expenseEntry.size() - 1 && paybyrata) { + if (paybyrata && tolpaypercent.compareTo(new BigDecimal(100L)) != 0) { + return ResManager.loadKDString("付款比例合计必须等于百分之100,请先修改付款比例。", "ContractUtil_23", "fi-er-business", new Object[0]); + } + + currexpenseamount = oriapplyamount.subtract(prorataamount); + if (oriapplyamount.compareTo(prorataamount) != 0) { + if (currexpenseamount.compareTo(diff) > 0 || currexpenseamount.compareTo(diff.multiply(BigDecimal.valueOf(-1L))) < 0) { + String msg = String.format(ResManager.loadKDString("含税金额合计和合同金额差异为%s,超过全局参数accentryDiffRange设置的范围,若继续引入请修改参数accentryDiffRange范围。", "ContractUtil_27", "fi-er-business", new Object[0]), currexpenseamount); + return msg; + } + + expenseamount = expenseamount.add(currexpenseamount.multiply(BigDecimal.valueOf(-1L))); + oriapplyamount = oriapplyamount.add(currexpenseamount.multiply(BigDecimal.valueOf(-1L))); + row.put("expenseamount", expenseamount); + } + } + + logger.info(i + ">>>>>>>>>>>>>expenseentryentity 计算本位币>>>>>exchangerate " + exchangerate + "&& amtprecision " + amtprecision + "&& expquotetype " + expquotetype); + currexpenseamount = AmountUtils.getCurrencyAmount(expenseamount, exchangerate, amtprecision, expquotetype); + row.put("currexpenseamount", currexpenseamount); + row.put("acexpeapprovecurramount", currexpenseamount); + row.put("acexpeapproveamount", expenseamount); + BigDecimal reimbursedamount = BigDecimal.ZERO; + Object reimbursedamountobj = row.get("reimbursedamount"); + if (reimbursedamountobj != null) { + reimbursedamount = new BigDecimal((String) reimbursedamountobj); + if (reimbursedamount.compareTo(expenseamount) > 0) { + return ResManager.loadKDString("已报销金额不能大于含税金额。", "ContractUtil_10", "fi-er-business", new Object[0]); + } + } + + BigDecimal orgiexpebalanceamount = expenseamount.subtract(reimbursedamount); + row.put("orgiexpebalanceamount", orgiexpebalanceamount); + BigDecimal pushedamount = BigDecimal.ZERO; + Object pushedamountobj = row.get("pushedamount"); + if (pushedamountobj != null) { + pushedamount = new BigDecimal((String) pushedamountobj); + if (pushedamount.compareTo(expenseamount) > 0) { + return ResManager.loadKDString("已预付金额不能大于含税金额。", "ContractUtil_11", "fi-er-business", new Object[0]); + } + } + + BigDecimal canloanamount = expenseamount.subtract(pushedamount); + row.put("canloanamount", expenseamount.subtract(pushedamount)); + BigDecimal oriexppayedamount = BigDecimal.ZERO; + BigDecimal exppayedamount = BigDecimal.ZERO; + Object oriexppayedamountobj = row.get("oriexppayedamount"); + if (oriexppayedamountobj != null) { + oriexppayedamount = new BigDecimal((String) row.get("oriexppayedamount")); + if (oriexppayedamount.compareTo(expenseamount) > 0) { + return ResManager.loadKDString("已付金额不能大于含税金额。", "ContractUtil_28", "fi-er-business", new Object[0]); + } + } + + BigDecimal oriexpnotpayamount = BigDecimal.ZERO; + Object oriexpnotpayamountobj = row.get("oriexpnotpayamount"); + if (oriexpnotpayamountobj != null) { + oriexpnotpayamount = new BigDecimal((String) oriexpnotpayamountobj); + if (oriexpnotpayamount.compareTo(expenseamount) > 0) { + return ResManager.loadKDString("未付金额不能大于含税金额。", "ContractUtil_12", "fi-er-business", new Object[0]); + } + } + + oriexpnotpayamount = expenseamount.subtract(oriexppayedamount); + row.put("oriexpnotpayamount", oriexpnotpayamount); + JSONObject entryCostCenter = (JSONObject) row.get("std_entrycostcenter"); + if (entryCostCenter != null) { + String entryCostCenterNumber = entryCostCenter.getString("number"); + if (entryCostCenterNumber != null) { + DynamicObject costCenter = ImportUtils.getCostCenterByNumber(entryCostCenterNumber); + if (costCenter == null) { + return ResManager.loadKDString(String.format("编码为%s的成本中心不存在。", entryCostCenterNumber), "ContractUtil_13", "fi-er-business", new Object[0]); + } + } + } + + int conamtprecision = contractcurrency.getInt("amtprecision"); + Object taxamountobj = row.get("taxamount"); + BigDecimal taxamount = BigDecimal.ZERO; + BigDecimal expnotpayamount; + if (taxamountobj == null) { + Object taxrate = row.get("taxrate"); + if (taxrate != null) { + expnotpayamount = (new BigDecimal((String) taxrate)).divide(new BigDecimal("100")); + taxamount = expenseamount.divide(BigDecimal.ONE.add(expnotpayamount), conamtprecision, 4).multiply(expnotpayamount).setScale(conamtprecision, 4); + } + } else { + taxamount = new BigDecimal((String) taxamountobj); + } + + billtaxamount = billtaxamount.add(taxamount); + BigDecimal tailDiff; + if (i == expenseEntry.size() - 1 && paybyrata && proratataxamount.compareTo(BigDecimal.ZERO) > 0) { + if (paybyrata && tolpaypercent.compareTo(new BigDecimal(100L)) != 0) { + return ResManager.loadKDString("付款比例合计必须等于百分之100,请先修改付款比例。", "ContractUtil_23", "fi-er-business", new Object[0]); + } + + tailDiff = billtaxamount.subtract(proratataxamount); + if (billtaxamount.compareTo(proratataxamount) != 0) { + if (tailDiff.compareTo(diff) > 0 || tailDiff.compareTo(diff.multiply(BigDecimal.valueOf(-1L))) < 0) { + String msg = String.format(ResManager.loadKDString("税额分录合计和合同税额差异为%s,超过全局参数accentryDiffRange设置的范围,若继续引入请修改参数accentryDiffRange范围。", "ContractUtil_30", "fi-er-business", new Object[0]), tailDiff); + return msg; + } + + taxamount = taxamount.add(tailDiff.multiply(BigDecimal.valueOf(-1L))); + billtaxamount = proratataxamount; + } + } + + row.put("taxamount", taxamount); + row.put("actaxamount", taxamount); + tailDiff = expenseamount.subtract(taxamount); + row.put("orientryamount", tailDiff); + row.put("acorientryamount", tailDiff); + exppayedamount = AmountUtils.getCurrencyAmount(oriexppayedamount, exchangerate, amtprecision, expquotetype); + row.put("exppayedamount", exppayedamount); + expnotpayamount = currexpenseamount.subtract(exppayedamount); + row.put("expnotpayamount", expnotpayamount); + BigDecimal reimbursedcurramount = AmountUtils.getCurrencyAmount(reimbursedamount, exchangerate, amtprecision, expquotetype); + row.put("reimbursedcurramount", reimbursedcurramount); + BigDecimal expebalanceamount = currexpenseamount.subtract(reimbursedcurramount); + row.put("expebalanceamount", expebalanceamount); + BigDecimal pushedcurramount = AmountUtils.getCurrencyAmount(pushedamount, exchangerate, amtprecision, expquotetype); + row.put("pushedcurramount", pushedcurramount); + BigDecimal canloancurramount = currexpenseamount.subtract(pushedcurramount); + row.put("canloancurramount", canloancurramount); + BigDecimal num = row.get("num") == null ? BigDecimal.ZERO : new BigDecimal((String) row.get("num")); + if (BigDecimal.ZERO.compareTo(num) != 0) { + row.put("exppricewithtax", expenseamount.divide(num, amtprecision, RoundingMode.HALF_UP)); + } + + applyamount = applyamount.add(currexpenseamount); + originalamount = originalamount.add(tailDiff); + balanceamount = balanceamount.add(expebalanceamount); + oribalanceamount = oribalanceamount.add(orgiexpebalanceamount); + billcanloanamount = billcanloanamount.add(canloancurramount); + oricanloanamount = oricanloanamount.add(canloanamount); + orinotpayamount = orinotpayamount.add(oriexpnotpayamount); + notpayamount = notpayamount.add(expnotpayamount); + usedamount = usedamount.add(reimbursedcurramount); + oriusedamount = oriusedamount.add(reimbursedamount); + payedamount = payedamount.add(exppayedamount); + oripayedamount = oripayedamount.add(oriexppayedamount); + loanedamount = loanedamount.add(pushedcurramount); + oriloanedamount = oriloanedamount.add(pushedamount); + } + + dataMap.put("originalamount", originalamount); + dataMap.put("contractamount", oriapplyamount); + dataMap.put("oriapplyamount", oriapplyamount); + dataMap.put("applyamount", applyamount); + dataMap.put("balanceamount", balanceamount); + dataMap.put("oribalanceamount", oribalanceamount); + dataMap.put("usedamount", usedamount); + dataMap.put("oriusedamount", oriusedamount); + dataMap.put("billcanloanamount", billcanloanamount); + dataMap.put("oricanloanamount", oricanloanamount); + dataMap.put("loanedamount", loanedamount); + dataMap.put("oriloanedamount", oriloanedamount); + dataMap.put("notpayamount", notpayamount); + dataMap.put("orinotpayamount", orinotpayamount); + dataMap.put("availableamount", notpayamount); + dataMap.put("oriavailableamount", orinotpayamount); + dataMap.put("payedamount", payedamount); + dataMap.put("oripayedamount", oripayedamount); + dataMap.put("invoiceamountremain", applyamount); + dataMap.put("billtaxamount", billtaxamount); + return null; + } + + public static String handlepartyEntryDataForContractBill(Map dataMap) { + JSONArray partyentry = (JSONArray) dataMap.get("contractpartyentry"); + if (partyentry.size() < 2) { + return ResManager.loadKDString("签约方分录,要有一条甲方与一条乙方。", "ContractUtil_14", "fi-er-business", new Object[0]); + } else { + int partA = 0; + int partB = 0; + String partName = ""; + + for (int i = 0; i < partyentry.size(); ++i) { + Map row = (Map) partyentry.get(i); + String signcontract = (String) row.get("signcontract"); + JSONObject contractparty = (JSONObject) row.get("contractparty"); + if ("0".equals(signcontract)) { + dataMap.put("partanew", contractparty); + dataMap.put("partatypenew", row.get("partytype")); + ++partA; + if ("bos_org".equals(row.get("partytype"))) { + dataMap.put("parta", contractparty); + } + } else if ("1".equals(signcontract)) { + dataMap.put("partb", contractparty); + dataMap.put("partbtype", row.get("partytype")); + ++partB; + } + + if (partA > 1) { + return ResManager.loadKDString("签约方分录,只能有一条甲方信息。", "ContractUtil_15", "fi-er-business", new Object[0]); + } + + if (partB > 1) { + return ResManager.loadKDString("签约方分录,只能有一条乙方信息。", "ContractUtil_16", "fi-er-business", new Object[0]); + } + } + + if (partA != 0 && partB != 0) { + Set orgset = (Set) partyentry.stream().filter((v) -> { + return ((String) ((Map) v).get("partytype")).equals("bos_org"); + }).map((rowx) -> { + return ((JSONObject) ((Map) rowx).get("contractparty")).get("number"); + }).collect(Collectors.toSet()); + Set cusset = (Set) partyentry.stream().filter((v) -> { + return ((String) ((Map) v).get("partytype")).equals("bd_customer"); + }).map((rowx) -> { + return ((JSONObject) ((Map) rowx).get("contractparty")).get("number"); + }).collect(Collectors.toSet()); + Set supset = (Set) partyentry.stream().filter((v) -> { + return ((String) ((Map) v).get("partytype")).equals("bd_supplier"); + }).map((rowx) -> { + return ((JSONObject) ((Map) rowx).get("contractparty")).get("number"); + }).collect(Collectors.toSet()); + Set adminorgset = (Set) partyentry.stream().filter((v) -> { + return ((String) ((Map) v).get("partytype")).equals("bos_adminorg"); + }).map((rowx) -> { + return ((JSONObject) ((Map) rowx).get("contractparty")).get("number"); + }).collect(Collectors.toSet()); + DynamicObjectCollection orgColl = QueryServiceHelper.query("bos_org", "id,name,number", new QFilter[]{new QFilter("number", "in", orgset), new QFilter("orgpattern.patterntype", "in", new String[]{"1", "2"})}); + DynamicObjectCollection adminorgColl = QueryServiceHelper.query("bos_adminorg", "id,name,number", new QFilter[]{new QFilter("number", "in", adminorgset), new QFilter("orgpattern.patterntype", "in", new String[]{"1", "2"})}); + JSONObject company = (JSONObject) dataMap.get("costcompany"); + Long companyId = company.getLong("id"); + QFilter baseDataFilter = BaseDataServiceHelper.getBaseDataFilter("bd_customer", companyId); + Map cusColl = BusinessDataServiceHelper.loadFromCache("bd_customer", "id, name,number, enable", new QFilter[]{(new QFilter("number", "in", cusset)).and(baseDataFilter)}); + QFilter sbaseDataFilter = BaseDataServiceHelper.getBaseDataFilter("bd_supplier", companyId); + Map supColl = BusinessDataServiceHelper.loadFromCache("bd_supplier", "id, name,number, enable", new QFilter[]{(new QFilter("number", "in", supset)).and(sbaseDataFilter)}); + + for (int i = 0; i < partyentry.size(); ++i) { + Map row = (Map) partyentry.get(i); + String partytype = (String) row.get("partytype"); + DynamicObject[] accountBanks = null; + PayerTypeEnum partyEnum = PayerTypeEnum.getValue(partytype); + JSONObject contractparty = (JSONObject) row.get("contractparty"); + String signcontract = (String) row.get("signcontract"); + List collect; + if ("bos_org".equals(partytype)) { + collect = (List) orgColl.stream().filter((v) -> { + return v.get("number").equals(contractparty.getString("number")); + }).collect(Collectors.toList()); + if (collect.size() == 0) { + return ResManager.loadKDString(String.format("签约方类型为公司,编码为%s的签约方不存在。", contractparty.getString("number")), "ContractUtil_17", "fi-er-business", new Object[0]); + } + + if ("2".equals(signcontract)) { + partName = String.format("%1$s%2$s%3$s", partName, ";", ((DynamicObject) collect.get(0)).get("name")); + } + } else if (PayerTypeEnum.SUPPLIER == partyEnum) { + collect = (List) supColl.values().stream().filter((v) -> { + return v.get("number").equals(contractparty.getString("number")); + }).collect(Collectors.toList()); + if (collect.size() == 0) { + return ResManager.loadKDString(String.format("签约方类型为%1$s,编码为%2$s的签约方不存在。", partyEnum.getTypeName(), contractparty.getString("number")), "ContractUtil_21", "fi-er-business", new Object[0]); + } + + if ("2".equals(signcontract)) { + partName = String.format("%1$s%2$s%3$s", partName, ";", ((DynamicObject) collect.get(0)).get("name")); + } + } else if (PayerTypeEnum.CUSTOMER == partyEnum) { + collect = (List) cusColl.values().stream().filter((v) -> { + return v.get("number").equals(contractparty.getString("number")); + }).collect(Collectors.toList()); + if (collect.size() == 0) { + return ResManager.loadKDString(String.format("签约方类型为%1$s,编码为%2$s的签约方不存在。", partyEnum.getTypeName(), contractparty.getString("number")), "ContractUtil_21", "fi-er-business", new Object[0]); + } + + if ("2".equals(signcontract)) { + partName = String.format("%1$s%2$s%3$s", partName, ";", ((DynamicObject) collect.get(0)).get("name")); + } + } else if ("bos_adminorg".equals(partytype)) { + collect = (List) adminorgColl.stream().filter((v) -> { + return v.get("number").equals(contractparty.getString("number")); + }).collect(Collectors.toList()); + if (collect.size() == 0) { + return ResManager.loadKDString(String.format("签约方类型为公司,编码为%s的签约方不存在。", contractparty.getString("number")), "ContractUtil_37", "fi-er-business", new Object[0]); + } + + if ("2".equals(signcontract)) { + partName = String.format("%1$s%2$s%3$s", partName, ";", ((DynamicObject) collect.get(0)).get("name")); + } + } + } + + if (partName != null && partName.startsWith(";")) { + partName = partName.substring(1); + } + + dataMap.put("partother", partName); + return null; + } else { + return ResManager.loadKDString("签约方分录,要有一条甲方与一条乙方。", "ContractUtil_14", "fi-er-business", new Object[0]); + } + } + } + + public static void setLinkman(Map row, List cucollect, String partytype) { + if (row.get("contactperson") == null) { + QFilter defQ = new QFilter("entry_linkman.isdefault_linkman", "=", Boolean.TRUE); + DynamicObjectCollection parts = QueryServiceHelper.query(partytype, "id,entry_linkman.contactperson,entry_linkman.phone", new QFilter[]{new QFilter("id", "=", ((DynamicObject) cucollect.get(0)).getPkValue()), defQ}); + if (parts != null && parts.size() != 0) { + DynamicObject contact = (DynamicObject) parts.get(0); + row.put("contactperson", contact.get("entry_linkman.contactperson")); + row.put("signtel", contact.get("entry_linkman.phone")); + } + + } + } + + public static boolean isFilterBySup(IDataModel model) { + Long company = ErCommonUtils.getPk(model.getValue("company")); + return SystemParamterUtil.getIsPublicUpFilterBySupplier(company); + } + + public static boolean checkRelationContract(IFormView view, ListSelectedRowCollection rows, String bill) { + boolean res = true; + Set hashSet = Sets.newHashSetWithExpectedSize(2); + Set billnoSet = Sets.newHashSetWithExpectedSize(1); + new StringBuilder(); + + for (int index = 0; index < rows.size(); ++index) { + ListSelectedRow row = rows.get(index); + DynamicObject curr = QueryServiceHelper.queryOne("er_contractbill", "company,frameworkcontract,enddate,billno", new QFilter[]{new QFilter("id", "=", row.getPrimaryKeyValue())}); + String contractType = SystemParamterUtil.getRelationContract((Long) curr.get("company")); + hashSet.add(curr.getString("frameworkcontract")); + if (contractType.equals("0")) { + view.showTipNotification(String.format(ResManager.loadKDString("第%1$s行单据,集成设置关联合同为项目云合同,合同台账不允许下推对公单据。", "ContractBillList_5", "fi-er-formplugin", new Object[0]), row.getRowKey() + 1)); + res = false; + } + + Boolean contractdeadlinecontrol = ErStdConfig.getContractDeadlineControl(); + if (!contractdeadlinecontrol) { + Date enddate = TripCommonUtil.strToDate(TripCommonUtil.DateToStr((Date) curr.get("enddate")), "yyyy-MM-dd"); + Date now = TripCommonUtil.strToDate(TripCommonUtil.DateToStr(new Date()), "yyyy-MM-dd"); + LocalDate localDate = LocalDate.now(); + if (now.after(enddate) && res) { + view.showTipNotification(String.format(ResManager.loadKDString("单据编号:%1$s,已超过合同截止日期,不能下推%2$s。", "ContractBillList_5", "fi-er-formplugin", new Object[0]), curr.get("billno"), bill)); + res = false; + } + } + + Boolean frameworkcontract = curr.getBoolean("frameworkcontract"); + if (frameworkcontract) { + billnoSet.add(curr.getString("billno")); + } + } + + if (hashSet.size() > 1 && res) { + res = false; + view.showTipNotification(String.format(ResManager.loadKDString("不允许同时选择框架合同与非框架合同下推%1$s。", "ContractBillList_5", "fi-er-formplugin", new Object[0]), bill)); + } + + if (billnoSet.size() > 1 && res) { + res = false; + view.showTipNotification(String.format(ResManager.loadKDString("框架合同不允许多对一生成%1$s。", "ContractBillList_22", "fi-er-formplugin", new Object[0]), bill)); + } + + if (res) { + List collect = (List) rows.stream().map(ListSelectedRow::getPrimaryKeyValue).collect(Collectors.toList()); + DynamicObjectCollection ids = QueryServiceHelper.query("er_costestimatebill", "id", new QFilter[]{new QFilter("expenseentryentity.wbsrcbillid", "in", collect), new QFilter("billstatus", "not in", "H")}); + if (ids.size() > 0) { + res = false; + view.showTipNotification(String.format(ResManager.loadKDString("下游已存在暂估单,不允许再推%1$s。", "ContractBillList_19", "fi-er-formplugin", new Object[0]), bill)); + } + } + + return res; + } + + public static String checkContractCode(DynamicObject stdbilltype, String code, String billNo) { + String errorMsg = ""; + if (!StringUtils.isBlank(code)) { + DynamicObjectCollection exists = QueryServiceHelper.query("er_contractbill", "billno,stdbilltype", new QFilter[]{new QFilter("contractcode", "=", code)}); + QFilter stdF = new QFilter("billformid", "=", "er_contractbill"); + stdF.and(new QFilter("isdefault", "=", "0")); + DynamicObjectCollection stdTypes = QueryServiceHelper.query("bos_billtype", "id,number,isdefault", new QFilter[]{stdF}); + Set types = (Set) stdTypes.stream().map((stdType) -> { + return (Long) stdType.get("id"); + }).collect(Collectors.toSet()); + if (!types.contains(stdbilltype.getPkValue())) { + Boolean valid = true; + if (exists.size() > 1) { + valid = false; + } + + if (exists.size() == 1) { + DynamicObject existOne = (DynamicObject) exists.get(0); + String eBillNo = existOne.getString("billno"); + if (!eBillNo.equals(billNo)) { + valid = false; + } + } + + if (!valid) { + errorMsg = ResManager.loadKDString("合同号已存在,请修改后提交。", "ErContractCodeValidator_0", "fi-er-opplugin", new Object[0]); + } + } + } + + return errorMsg; + } + + public static boolean checkBillType(ListSelectedRowCollection rows, IFormView view) { + boolean res = true; + + for (int index = 0; index < rows.size(); ++index) { + ListSelectedRow row = rows.get(index); + DynamicObject curr = QueryServiceHelper.queryOne("er_contractbill", "detailtype", new QFilter[]{new QFilter("id", "=", row.getPrimaryKeyValue())}); + String detailType = curr.getString("detailtype"); + if (!detailType.equals("biztype_applybill")) { + view.showTipNotification(String.format(ResManager.loadKDString("第%1$s行单据,非合同申请单据。", "ContractUtil_19", "fi-er-business", new Object[0]), row.getRowKey() + 1)); + res = false; + } + } + + return res; + } + + public static void handleProjectHyperLink(IDataModel model, IFormView view, int row) { + String projectNo = (String) model.getValue("projectbillno", row); + QFilter projectNoFilter = new QFilter("billno", "=", projectNo); + DynamicObject project = BusinessDataServiceHelper.loadSingle("er_applyprojectbill", "id", new QFilter[]{projectNoFilter}); + if (ObjectUtils.isEmpty(project)) { + view.showTipNotification(ResManager.loadKDString("该立项单不存在,请确认。", "ContractUtil_18", "fi-er-business", new Object[0])); + } else { + ShowPageUtils.openLinkedForm(project.getPkValue().toString(), "er_applyprojectbill", view); + } + } + + public static void handlePurContractHyperLink(IDataModel model, IFormView view, int row) { + String contractNo = (String) model.getValue("wbsrcbillno", row); + QFilter contractNoFilter = new QFilter("billno", "=", contractNo); + DynamicObject purcontract = BusinessDataServiceHelper.loadSingle("conm_purcontract", "id", new QFilter[]{contractNoFilter}); + if (ObjectUtils.isEmpty(purcontract)) { + view.showTipNotification(ResManager.loadKDString("该采购合同单不存在,请确认。", "ContractUtil_36", "fi-er-business", new Object[0])); + } else { + ShowPageUtils.openLinkedForm(purcontract.getPkValue().toString(), "conm_purcontract", view); + } + } + + public static List checkHasOnWayBills(ListSelectedRowCollection selectedRows, String OnWayCondition) { + List billTypes = new ArrayList(4); + Long[] billsId = (Long[]) selectedRows.stream().map((b) -> { + return (Long) b.getPrimaryKeyValue(); + }).toArray((x$0) -> { + return new Long[x$0]; + }); + EntityInfo prepayInfo; + EntityInfo reimburseInfo; + if (!"2".equals(ErStdConfig.getApplyprojectbillRelated())) { + prepayInfo = (new EntityInfo.Builder()).entityName("er_prepaybill").entryName("expenseentryentity").sourceName("wbsrcbillid").build(); + OnWayCondition = "B,C,E,F"; + if (getProjectHasOnWayBills(billsId, prepayInfo, OnWayCondition).size() > 0) { + billTypes.add("er_prepaybill"); + } + + prepayInfo = (new EntityInfo.Builder()).entityName("er_prepaybill").entryName("contractentry").sourceName("contractsid").build(); + if (getProjectHasOnWayBills(billsId, prepayInfo, OnWayCondition).size() > 0) { + billTypes.add("er_prepaybill"); + } + + reimburseInfo = (new EntityInfo.Builder()).entityName("er_publicreimbursebill").entryName("contractentry").sourceName("contractsid").build(); + if (getProjectHasOnWayBills(billsId, reimburseInfo, OnWayCondition).size() > 0) { + billTypes.add("er_publicreimbursebill"); + } + + reimburseInfo = (new EntityInfo.Builder()).entityName("er_publicreimbursebill").entryName("expenseentryentity").sourceName("wbsrcbillid").build(); + if (getProjectHasOnWayBills(billsId, reimburseInfo, OnWayCondition).size() > 0) { + billTypes.add("er_publicreimbursebill"); + } + } + + OnWayCondition = "A,B,C,D"; + prepayInfo = (new EntityInfo.Builder()).entityName("er_contractbill").entryName("expenseentryentity").sourceName("wbsrcbillid").build(); + if (getProjectHasOnWayBills(billsId, prepayInfo, OnWayCondition).size() > 0) { + billTypes.add("er_contractbill"); + } + + OnWayCondition = "A,B,C,D"; + reimburseInfo = (new EntityInfo.Builder()).entityName("er_costestimatebill").entryName("expenseentryentity").sourceName("wbsrcbillid").build(); + if (getProjectHasOnWayBills(billsId, reimburseInfo, OnWayCondition).size() > 0) { + billTypes.add("er_costestimatebill"); + } + + return billTypes; + } + + public static List getProjectHasOnWayBills(Long[] billsId, EntityInfo info, String OnWayCondition) { + String selectedProperties = String.join(",", "id", "billstatus", info.entryName + ".id", info.entryName + "." + info.sourceName); + DynamicObject[] prepayBills = BusinessDataServiceHelper.load(info.entityName, selectedProperties, new QFilter[]{new QFilter(info.entryName + "." + info.sourceName, "in", billsId)}); + List collect = (List) Arrays.stream(prepayBills).filter((prepayBillOnWay) -> { + return OnWayCondition.contains(prepayBillOnWay.getString("billstatus")); + }).flatMap((onWayBill) -> { + return onWayBill.getDynamicObjectCollection(info.entryName).stream().map((OnWayBillEntry) -> { + return OnWayBillEntry.getLong(info.sourceName); + }); + }).collect(Collectors.toList()); + return collect; + } + + public static int getCostestimateHasOnWayBills(Object[] billsId, EntityInfo info, List autuStatus) { + String selectedProperties = String.join(",", "id", "billstatus", info.entryName + ".id", info.entryName + "." + info.sourceName); + DynamicObject[] prepayBills = BusinessDataServiceHelper.load(info.entityName, selectedProperties, new QFilter[]{new QFilter(info.entryName + "." + info.sourceName, "in", billsId), new QFilter("billstatus", "not in", autuStatus)}); + return prepayBills.length; + } + + public static boolean checkExpenseItem(IDataModel model, IFormView view, int rowIndex) { + Long expItemId = ErCommonUtils.getPk(model.getValue("expenseitem", rowIndex)); + if (expItemId == null) { + return true; + } else { + QFilter qFilter = new QFilter("isleaf", "=", Boolean.TRUE); + qFilter.and("id", "=", expItemId); + QFilter filter = BaseDataServiceHelper.getBaseDataFilter("er_expenseitemedit", ErCommonUtils.getPk(model.getValue("entrycostcompany", rowIndex))); + qFilter.and(filter); + qFilter.and(ExpenseItemServiceHelper.getRelExpItemsFilter(view.getEntityId(), ErCommonUtils.getPk(model.getValue("entrycostdept", rowIndex)))); + List upBillExpitemIds = ExpenseItemServiceHelper.getUpBillExpItemId(model.getDataEntity(true)); + qFilter.or("id", "in", upBillExpitemIds); + return QueryServiceHelper.exists("er_expenseitemedit", new QFilter[]{qFilter}); + } + } + + public static boolean checkExpenseItemByProjecttype(DynamicObject projecttype, DynamicObject expenseitem) { + if (projecttype != null && expenseitem != null) { + List numbers = (List) projecttype.getDynamicObjectCollection("entryentity").stream().map((a) -> { + return a.getLong("expenseitem.id"); + }).collect(Collectors.toList()); + if (!numbers.isEmpty()) { + return numbers.contains(expenseitem.getPkValue()); + } + } + + return true; + } + + public static void changeOriWriteOffAmount(BigDecimal currAmount, int rowIndex, IDataModel model) { + BigDecimal exchangeRate = (BigDecimal) ObjectUtils.defaultIfNull((BigDecimal) model.getValue("projectchangerate", rowIndex), BigDecimal.ONE); + String quoteType = (String) ObjectUtils.defaultIfNull((String) model.getValue("projectquotetype", rowIndex), "0"); + BigDecimal orgiAmount; + if (org.apache.commons.lang3.StringUtils.equals("0", quoteType)) { + exchangeRate = exchangeRate.compareTo(BigDecimal.ZERO) == 0 ? BigDecimal.ONE : exchangeRate; + orgiAmount = currAmount.divide(exchangeRate, AmountUtils.getCurrencyPrecision(model, "projectcurrency"), RoundingMode.HALF_UP); + } else { + orgiAmount = currAmount.multiply(exchangeRate).setScale(AmountUtils.getCurrencyPrecision(model, "projectcurrency"), RoundingMode.HALF_UP); + } + + model.setValue("oriprojectwriteoffamount", orgiAmount, rowIndex); + } + + public static void deleteProjectEntry(Object oldValue, IDataModel model) { + if (oldValue != null) { + model.deleteEntryData("projectentryentity"); + } + + } + + public static List checkDownBills(ListSelectedRowCollection rows, String operateKey) { + String onWayStatus = "A,B,C,F"; + List downBills = checkHasOnWayBills(rows, onWayStatus); + if (operateKey.equals("publicreimburse")) { + downBills.remove("er_publicreimbursebill"); + } else if (operateKey.equals("er_prepaybill")) { + downBills.remove("er_prepaybill"); + } + + return downBills; + } + + public static List loadErContract(IDataModel model, Set entrybillno) { + List deleteIndex = Lists.newArrayList(); + DynamicObjectCollection dynamicObjectCollection = model.getDataEntity(true).getDynamicObjectCollection("expenseentryentity"); + String selectPropties = "billno,changerate,quotetype,contractcode,description,signdate,contractcurrency,oribalanceamount,oriusedamount,contractname,oriapplyamount"; + DynamicObject[] contractDynamicObjts = (DynamicObject[]) QueryServiceHelper.query("er_contractbill", selectPropties, new QFilter[]{new QFilter("contractcode", "in", entrybillno)}).toArray(new DynamicObject[0]); + Set entrycontractFordel = new HashSet(); + + for (int i = 0; i < dynamicObjectCollection.size(); ++i) { + if (entrycontractFordel.contains(((DynamicObject) dynamicObjectCollection.get(i)).get("entrycontractno"))) { + deleteIndex.add(i); + } else { + for (int j = 0; j < contractDynamicObjts.length; ++j) { + if (((DynamicObject) dynamicObjectCollection.get(i)).get("entrycontractno").equals(contractDynamicObjts[j].get("contractcode"))) { + entrycontractFordel.add((String) ((DynamicObject) dynamicObjectCollection.get(i)).get("entrycontractno")); + model.setValue("entrycontractname", contractDynamicObjts[j].get("contractname"), i); + model.setValue("totalamount", contractDynamicObjts[j].get("oriapplyamount"), i); + model.setValue("expusedamount", contractDynamicObjts[j].get("oriusedamount"), i); + model.setValue("expreimbursableamount", contractDynamicObjts[j].get("oribalanceamount"), i); + model.setValue("entrycurrency", contractDynamicObjts[j].get("contractcurrency"), i); + model.setValue("expquotetype", contractDynamicObjts[j].get("quotetype"), i); + model.setValue("exchangerate", contractDynamicObjts[j].get("changerate"), i); + model.setValue("expusedamount", contractDynamicObjts[j].get("oriusedamount"), i); + model.setValue("signingdate", contractDynamicObjts[j].get("signdate"), i); + } + } + } + } + + return deleteIndex; + } + + public static void refreshWriteOffAmount(IDataModel model, WriteOffFields fields, String writeOffType) { + if (writeOffType.equals("1")) { + writeOffOri(model, fields.entryKey, fields.approveAmtOriKey, fields.entryCurrencyKey, fields.checkAmtOriKey, fields.checkAmtKey); + } else { + writeOffCurr(model, fields.entryKey, fields.approveAmtKey, fields.approveAmtOriKey, fields.checkAmtOriKey, fields.checkAmtKey, fields.entryQuoteTypeKey, fields.entryExchangerateKey, fields.expAmountKey); + } + + } + + public static void synAttachment(IFormView view, Map returnData) { + BillList billList = (BillList) view.getControl("billlistap"); + ListSelectedRowCollection selectedRows = billList.getSelectedRows(); + List> attachmentData = (List) returnData.get("attachmentData"); + Iterator var5; + ListSelectedRow listSelectedRow; + List billAttachmentList; + Map billAttachment; + if (attachmentData != null && attachmentData.size() > 0) { + var5 = attachmentData.iterator(); + + while (var5.hasNext()) { + Map map = (Map) var5.next(); + String url = (String) map.get("url"); + String name = (String) map.get("name"); + if (url.contains("configKey=redis.serversForCache&id=tempfile")) { + url = AttachmentUtils.uploadTempfile(url, name); + map.put("url", url); + List> needAddData = new ArrayList(); + needAddData.add(map); + Iterator var20 = selectedRows.iterator(); + + while (var20.hasNext()) { +/* ListSelectedRow listSelectedRow = (ListSelectedRow)var20.next(); + AttachmentServiceHelper.upload(billList.getBillFormId(), listSelectedRow.getPrimaryKeyValue(), "attachmentpanel", needAddData);*///系统源码 + listSelectedRow = (ListSelectedRow) var20.next(); + AttachmentServiceHelper.upload(billList.getBillFormId(), listSelectedRow.getPrimaryKeyValue(), "attachmentpanel", needAddData);//二开系统代码 + } + } + + map.put("creator", UserServiceHelper.getCurrentUserId()); + map.put("modifytime", (new Date()).getTime()); + } + + var5 = selectedRows.iterator(); + + while (true) { + do { + do { + if (!var5.hasNext()) { + return; + } + + listSelectedRow = (ListSelectedRow) var5.next(); + billAttachmentList = AttachmentServiceHelper.getAttachments(billList.getBillFormId(), listSelectedRow.getPrimaryKeyValue(), "attachmentpanel"); + } while (billAttachmentList == null); + } while (billAttachmentList.size() <= 0); + + for (int i = 0; i < billAttachmentList.size(); ++i) { + billAttachment = (Map) billAttachmentList.get(i); + + for (int j = 0; j < attachmentData.size(); ++j) { + Map attachment = (Map) attachmentData.get(j); + String uid = (String) billAttachment.get("uid"); + if (!uid.contains("contract") || attachment.get("uid").equals(uid)) { + if (uid.contains("contract") && attachment.get("uid").equals(uid)) { + String name = (String) attachment.get("name"); + String billAttachname = (String) billAttachment.get("name"); + if (!billAttachname.equals(name)) { + AttachmentServiceHelper.rename(uid, name); + } + } + break; + } + + if (uid.contains("contract") && j == attachmentData.size() - 1) { + AttachmentServiceHelper.remove(billList.getBillFormId(), listSelectedRow.getPrimaryKeyValue(), billAttachment.get("uid")); + logger.info("----删除附件----" + billList.getBillFormId() + "-----单据id-----" + listSelectedRow.getPrimaryKeyValue() + "-----附件id-----" + billAttachment.get("uid")); + } + } + } + } + } else { + var5 = selectedRows.iterator(); + + while (true) { + do { + do { + if (!var5.hasNext()) { + return; + } + + listSelectedRow = (ListSelectedRow) var5.next(); + billAttachmentList = AttachmentServiceHelper.getAttachments(billList.getBillFormId(), listSelectedRow.getPrimaryKeyValue(), "attachmentpanel"); + } while (billAttachmentList == null); + } while (billAttachmentList.size() <= 0); + + Iterator var8 = billAttachmentList.iterator(); + + while (var8.hasNext()) { + billAttachment = (Map) var8.next(); + String uid = (String) billAttachment.get("uid"); + if (uid.contains("contract")) { + AttachmentServiceHelper.remove(billList.getBillFormId(), listSelectedRow.getPrimaryKeyValue(), uid); + logger.info("----删除附件----" + billList.getBillFormId() + "-----单据id-----" + listSelectedRow.getPrimaryKeyValue() + "-----附件id-----" + uid); + } + } + } + } + } + + public static void contractPageRules(IDataModel model, IFormView view, String entryName, Boolean delete) { + int entrySize = model.getEntryRowCount(entryName); + CardEntry cardEntry; + int rowIndex; + switch (entryName) { + case "contractpartyentry": + if (entrySize == 0) { + view.setVisible(false, new String[]{"signflex", entryName}); + break; + } else { + view.setVisible(true, new String[]{"signflex", entryName}); + if (delete) { + view.setVisible(true, new String[]{"label_sign_done"}); + view.setVisible(false, new String[]{"label_sign_delete"}); + } else { + view.setVisible(true, new String[]{"label_sign_delete"}); + view.setVisible(false, new String[]{"label_sign_done"}); + } + + cardEntry = (CardEntry) view.getControl(entryName); + + for (rowIndex = 0; rowIndex < entrySize; ++rowIndex) { + if (rowIndex < 2) { + cardEntry.setChildVisible(false, rowIndex, new String[]{"image_sign_delete"}); + } else { + cardEntry.setChildVisible(delete, rowIndex, new String[]{"image_sign_delete"}); + } + } + + return; + } + case "termentry": + if (entrySize == 0) { + view.setVisible(false, new String[]{"contractitemflex", entryName}); + break; + } else { + view.setVisible(true, new String[]{"contractitemflex", entryName}); + if (delete) { + view.setVisible(true, new String[]{"label_item_done"}); + view.setVisible(false, new String[]{"label_item_delete"}); + } else { + view.setVisible(true, new String[]{"label_item_delete"}); + view.setVisible(false, new String[]{"label_item_done"}); + } + + cardEntry = (CardEntry) view.getControl(entryName); + + for (rowIndex = 0; rowIndex < entrySize; ++rowIndex) { + cardEntry.setChildVisible(delete, rowIndex, new String[]{"image_item_delete"}); + } + + return; + } + case "projectentryentity": + if (entrySize == 0) { + view.setVisible(false, new String[]{"contractprojectflex", entryName}); + break; + } else { + view.setVisible(true, new String[]{"contractprojectflex", entryName}); + if (delete) { + view.setVisible(true, new String[]{"label_project_done"}); + view.setVisible(false, new String[]{"label_project_delete"}); + } else { + view.setVisible(true, new String[]{"label_project_delete"}); + view.setVisible(false, new String[]{"label_project_done"}); + } + + cardEntry = (CardEntry) view.getControl(entryName); + + for (rowIndex = 0; rowIndex < entrySize; ++rowIndex) { + cardEntry.setChildVisible(delete, rowIndex, new String[]{"image_project_delete"}); + } + + return; + } + case "expenseentryentity": + if ((Boolean) model.getValue("frameworkcontract")) { + view.setVisible(false, new String[]{"expflex", entryName, "btn_plan_add"}); + } else { + view.setVisible(true, new String[]{"btn_plan_add"}); + if (entrySize == 0) { + view.setVisible(false, new String[]{"expflex", entryName}); + } else { + view.setVisible(true, new String[]{"expflex", entryName}); + if (delete) { + view.setVisible(true, new String[]{"label_exp_done"}); + view.setVisible(false, new String[]{"label_exp_delete"}); + } else { + view.setVisible(true, new String[]{"label_exp_delete"}); + view.setVisible(false, new String[]{"label_exp_done"}); + } + + cardEntry = (CardEntry) view.getControl(entryName); + + for (rowIndex = 0; rowIndex < entrySize; ++rowIndex) { + cardEntry.setChildVisible(delete, rowIndex, new String[]{"image_exp_delete"}); + } + } + } + } + + } + + public static void setWriteOffType(IDataModel model) { + DynamicObject company = (DynamicObject) model.getValue("company"); + String writeType = (String) ErCommonUtils.getEMParameter(ErCommonUtils.getPk(company), "er010"); + model.setValue("writeofftype", writeType); + } + + public static void addContractPartByHand(IDataModel model, IFormView view, AbstractFormPlugin formPlugin, int rowIndex, String formid) { + Map param = new HashMap(); + Map paramMap = new HashMap(); + paramMap.put("formType", "6"); + paramMap.put("formId", formid); + paramMap.put("writeofftype", model.getValue("writeofftype")); + param.put("isquerybudget", (Boolean) model.getValue("isquerybudget")); + param.put("billstatus", model.getValue("billstatus")); + param.put("std_costcenter", model.getValue("std_costcenter")); + if (rowIndex != -1) { + param.put("index", rowIndex); + } else { + param.put("index", -1); + } + + ShowPageUtils.setFormStatusToCustomParam(param, view); + paramMap.put("customParam", param); + paramMap.put("needCallBack", Boolean.TRUE); + ShowPageUtils.showPage(paramMap, formPlugin); + } + + public static void saveContractPartOrItemByHand(IDataModel model, IFormView view, String entryName) { + DynamicObjectCollection contractPartEntry = (DynamicObjectCollection) model.getDataEntity(true).get(entryName); + IFormView parentView = view.getParentView(); + IDataModel parentModel = parentView.getModel(); + DynamicObjectCollection parentContractPartEntry = (DynamicObjectCollection) parentModel.getDataEntity(true).get(entryName); + FormShowParameter param = view.getFormShowParameter(); + Map returnData = new HashMap(); + if (param.getCustomParam("index") != null && (Integer) param.getCustomParam("index") != -1) { + int index = (Integer) param.getCustomParam("index"); + EntryCopyUtil.updateColl2TargetColl(parentContractPartEntry, contractPartEntry, index); + returnData.put("index", index); + } else { + EntryCopyUtil.copyColl2TargetColl(parentContractPartEntry, contractPartEntry); + returnData.put("index", -1); + } + + view.returnDataToParent(returnData); + view.sendFormAction(parentView); + view.close(); + } + + public static void setAndGetSelectedRowEntryId(IDataModel model, IFormView formView, String entryName) { + DynamicObjectCollection entryList = model.getEntryEntity(entryName); + long[] ids = ORM.create().genLongIds(formView.getEntityId(), entryList.size()); + + for (int i = 0; i < entryList.size(); ++i) { + DynamicObject entryEntity = (DynamicObject) entryList.get(i); + Long entryId = (Long) entryEntity.getPkValue(); + if (Objects.equals(entryId, 0L)) { + entryEntity.set("id", ids[i]); + } + } + + } + + public static void setContractPartF7Filter(final IDataModel model, IFormView formView) { + BasedataEdit realCardF7 = (BasedataEdit) formView.getControl("contractparty"); + realCardF7.addBeforeF7SelectListener(new BeforeF7SelectListener() { + public void beforeF7Select(BeforeF7SelectEvent evt) { + int entryCurrentRowIndex = model.getEntryCurrentRowIndex("contractpartyentry"); + String partytype = (String) model.getValue("partytype", entryCurrentRowIndex); + if ("bos_org".equals(partytype) || "bos_adminorg".equals(partytype)) { + ListShowParameter cardF7Param = (ListShowParameter) evt.getFormShowParameter(); + QFilter orgPatternFilter = new QFilter("orgpattern.patterntype", "in", new String[]{"1", "2"}); + cardF7Param.getListFilterParameter().getQFilters().add(orgPatternFilter); + if ("bos_org".equals(partytype)) { + evt.getFormShowParameter().setCustomParam("initOrgFuncId", "10"); + } + } + + } + }); + } + + public static void setMobFrameworkcontractChange(IDataModel model, IFormView view, Boolean newValueBoolean) { + int rowIndex; + if (newValueBoolean) { + DynamicObjectCollection expenseentryentity = model.getEntryEntity("expenseentryentity"); + int[] indexArr = new int[expenseentryentity.size()]; + + for (rowIndex = 0; rowIndex < expenseentryentity.size(); indexArr[rowIndex] = rowIndex++) { + } + + model.deleteEntryRows("expenseentryentity", indexArr); + model.beginInit(); + model.setValue("contractamount", (Object) null); + model.setValue("oriapplyamount", (Object) null); + model.setValue("originalamount", (Object) null); + model.setValue("orinotpayamount", (Object) null); + model.setValue("changeamount", (Object) null); + model.setValue("billtaxrate", (Object) null); + model.setValue("projecttype", (Object) null); + model.endInit(); + view.updateView("projecttype"); + view.setVisible(false, new String[]{"projecttype", "expflex", "expenseentryentity", "btn_plan_add", "flexpanelap6"}); + ((BasedataEdit) view.getControl("projecttype")).setMustInput(false); + ((FieldEdit) view.getControl("payterms")).setMustInput(false); + ((FieldEdit) view.getControl("contractcurrency")).setMustInput(false); + ((FieldEdit) view.getControl("changerate")).setMustInput(false); + } else { + view.setVisible(true, new String[]{"projecttype", "btn_plan_add", "flexpanelap6"}); + int entrySize = model.getEntryRowCount("expenseentryentity"); + if (entrySize == 0) { + view.setVisible(false, new String[]{"expflex", "expenseentryentity"}); + } else { + view.setVisible(true, new String[]{"label_exp_delete"}); + view.setVisible(false, new String[]{"label_exp_done"}); + CardEntry cardEntry = (CardEntry) view.getControl("expenseentryentity"); + + for (rowIndex = 0; rowIndex < entrySize; ++rowIndex) { + cardEntry.setChildVisible(false, rowIndex, new String[]{"image_exp_delete"}); + } + } + + ((BasedataEdit) view.getControl("projecttype")).setMustInput(true); + ((FieldEdit) view.getControl("payterms")).setMustInput(true); + ((FieldEdit) view.getControl("contractcurrency")).setMustInput(true); + ((FieldEdit) view.getControl("changerate")).setMustInput(true); + ((EntryGrid) view.getControl("expenseentryentity")).setMustInput("expenseentryentity", true); + } + + } + + public static void setMobHeadPart(IDataModel model, IFormView view, ClosedCallBackEvent closedCallBackEvent) { + int index = -1; + DynamicObject part = null; + Map returnData = (Map) closedCallBackEvent.getReturnData(); + if (returnData != null) { + index = (Integer) returnData.get("index"); + } + + if (index == 0) { + part = (DynamicObject) model.getValue("contractparty", 0); + } else if (index == 1) { + part = (DynamicObject) model.getValue("contractparty", 1); + if (model.getEntryRowCount("projectentryentity") > 0) { + DynamicObject wlunit = (DynamicObject) model.getValue("projectwunit", 0); + if (part == null || wlunit != null && (Long) wlunit.getPkValue() != (Long) part.getPkValue()) { + model.deleteEntryData("projectentryentity"); + } + } + } + + setHeadPart(model, index, part); + } + + public static void callRleAfterClosedCallBack(IDataModel model, IFormView formView, ListSelectedRowCollection selectBill, String entityNumber, String RuleId, String actionId) { + if (selectBill != null && !selectBill.isEmpty()) { + DrawArgs args = BotpDrawServiceUtil.buildDrawArgs(entityNumber, model.getDataEntityType().getName(), formView, selectBill, RuleId); + List resultList = Lists.newArrayListWithExpectedSize(4); + ConvertOperationResult result = ConvertServiceHelper.draw(args); + if (result.isSuccess()) { + BotpDrawServiceUtil.dealResult(result, resultList, (BillEntityType) model.getDataEntityType()); + Iterator var9 = resultList.iterator(); + + while (var9.hasNext()) { + DynamicObject bill = (DynamicObject) var9.next(); + ((IBillModel) model).push(bill); + } + + if ("er_projectfromcontract_mb".equals(actionId)) { + refreshWriteOffAmount(model, ContractProjectWriteOffFields.getInstance()); + String writeOffType = (String) model.getValue("writeofftype"); + int size = model.getEntryRowCount("projectentryentity"); + int i; + if ("1".equals(writeOffType)) { + for (i = 0; i < size; ++i) { + refreshWriteOffCurrAmount(model, i, formView); + } + } else { + for (i = 0; i < size; ++i) { + changeOriWriteOffAmount((BigDecimal) model.getValue("projectwriteoffamount", i), i, model); + } + } + + DynamicObject currency = (DynamicObject) model.getValue("currency"); + setAmountToLabel(model, formView, "projectentryentity", "projectwriteoffamount", "label_project_amount", currency); + contractPageRules(model, formView, "projectentryentity", false); + formView.updateView("projectentryentity"); + if (size > 0) { + Object unit = model.getValue("projectwunit", 0); + if (unit != null && model.getEntryRowCount("contractpartyentry") > 1) { + model.setValue("contractparty", unit, 1); + } + } + } else if ("er_draw_concontract_mb".equals(actionId)) { + refreshHeadContacts(formView, (EventObject) null); + formView.updateView("contractsconn"); + } + + } + } + } + + public static void refreshSecondWriteOffCurrAmount(IDataModel model, IDataModel parentModel, int index, IFormView view) { + String writeOffType = (String) parentModel.getValue("writeofftype"); + BigDecimal expAmount = (BigDecimal) model.getValue("oriprojectwriteoffamount", index); + BigDecimal projAmount = (BigDecimal) model.getValue("oriprojectcanamount", index); + if (writeOffType.equals(WriteOffTypeEnum.ORGI_WO.getValue()) && !currencyValidate(model, parentModel, index, "entrycurrency", "projectcurrency") && expAmount.compareTo(BigDecimal.ZERO) > 0) { + view.showTipNotification(ResManager.loadKDString("该币别不在费用明细中,不能冲销。", "ContractUtil_20", "fi-er-business", new Object[0])); + model.setValue("oriprojectwriteoffamount", BigDecimal.ZERO, index); + } else { + if (expAmount.compareTo(projAmount) > 0) { + model.setValue("oriprojectwriteoffamount", projAmount, index); + expAmount = projAmount; + } + + BigDecimal exchangeRate = model.getValue("projectchangerate", index) == null ? BigDecimal.ZERO : (BigDecimal) model.getValue("projectchangerate", index); + String quoteType = (String) ObjectUtils.defaultIfNull((String) model.getValue("projectquotetype", index), "0"); + DynamicObject currency = (DynamicObject) parentModel.getValue("currency"); + if (null != currency) { + int precision = AmountUtils.getCurrencyPrecision(ErCommonUtils.getPk(currency)); + BigDecimal currencyAmount = AmountUtils.getCurrencyAmount(expAmount, exchangeRate, precision, quoteType); + model.setValue("projectwriteoffamount", currencyAmount, index); + } + } + } + + public static boolean currencyValidate(IDataModel dataModel, IDataModel parentModel, int index, String entryCurrency, String projectCurrency) { + Set currencyIds = AmountUtils.getCurrencyIdSet(parentModel, "expenseentryentity", entryCurrency); + DynamicObject writeOffCurrency = (DynamicObject) dataModel.getValue(projectCurrency, index); + return writeOffCurrency == null || currencyIds.contains(writeOffCurrency.getPkValue()); + } + + public static void calBillSumAmount(IDataModel model, IFormView formView) { + BigDecimal expenseamount = AmountUtils.getEntryAmount(model, "expenseentryentity", "expenseamount"); + model.setValue("oribalanceamount", expenseamount); + model.setValue("oricanloanamount", expenseamount); + model.setValue("orinotpayamount", AmountUtils.getEntryAmount(model, "expenseentryentity", "oriexpnotpayamount")); + model.setValue("oriapplyamount", expenseamount); + if (model.getValue("detailtype").equals("biztype_applybill")) { + model.setValue("contractamount", expenseamount); + } + + BigDecimal currexpenseamount = AmountUtils.getEntryAmount(model, "expenseentryentity", "currexpenseamount"); + model.setValue("applyamount", currexpenseamount); + model.setValue("balanceamount", currexpenseamount); + model.setValue("billcanloanamount", currexpenseamount); + if (model.getProperty("cancontractamount") != null) { + model.setValue("cancontractamount", currexpenseamount); + } + + if (model.getProperty("invoiceamountremain") != null) { + model.setValue("invoiceamountremain", currexpenseamount); + } + + model.setValue("notpayamount", AmountUtils.getEntryAmount(model, "expenseentryentity", "expnotpayamount")); + model.setValue("availableamount", currexpenseamount.subtract((BigDecimal) model.getValue("nonpayamount"))); + model.setValue("oriavailableamount", expenseamount.subtract((BigDecimal) model.getValue("orinonpayamount"))); + refreshBillTaxAmountByExpense(model, formView); + refreshOriginalAmount(model, formView); + } + + public static void setAmountToLabel(IDataModel model, IFormView formView, String entryName, String amtFieldName, String labelName, DynamicObject currency) { + BigDecimal loanAmount = AmountUtils.getEntryAmount(model, entryName, amtFieldName); + String currencySign = ""; + int amountPrecition = 4; + if (currency != null) { + currencySign = currency.getString("sign"); + amountPrecition = currency.getInt("amtprecision"); + loanAmount = loanAmount.setScale(amountPrecition, RoundingMode.HALF_UP); + } + + String formatMoneyByUser = AmountUtils.formatMoneyByUser(Long.valueOf(RequestContext.get().getUserId()), currencySign, amountPrecition, loanAmount); + Label expenseAmount = (Label) formView.getControl(labelName); + if (expenseAmount != null) { + expenseAmount.setText(formatMoneyByUser); + formView.updateView(labelName); + } + + } + + public static void setBudgetShow(IDataModel model, IFormView formView, boolean isShowBudget, String budgeMsgValue, int index) { + if (index == -1) { + for (int i = 0; i < model.getEntryRowCount("expenseentryentity"); ++i) { + setBudgetVisible(formView, "expenseentryentity", budgeMsgValue, isShowBudget, i); + } + } else { + setBudgetVisible(formView, "expenseentryentity", budgeMsgValue, isShowBudget, index); + } + + } + + public static void setBudgetVisible(IFormView formView, String entryName, String budgeMsgValue, boolean isQueryBudgetFlag, int index) { + CardEntry cardEntry = (CardEntry) formView.getControl(entryName); + if (isQueryBudgetFlag) { + if ("0".equals(budgeMsgValue)) { + cardEntry.setChildVisible(true, index, new String[]{"budgetamount"}); + cardEntry.setChildVisible(false, index, new String[]{"budgetmsg"}); + } else { + cardEntry.setChildVisible(false, index, new String[]{"budgetamount"}); + cardEntry.setChildVisible(true, index, new String[]{"budgetmsg"}); + } + } else { + cardEntry.setChildVisible(false, index, new String[]{"budgetamount"}); + cardEntry.setChildVisible(false, index, new String[]{"budgetmsg"}); + } + + } + + public static DynamicObject getSelectBillProjectOwer(IMobileListView view, String entityId) { + Long pkId = (Long) view.getCurrentSelectedRowInfo().getPrimaryKeyValue(); + return BusinessDataServiceHelper.loadSingle(pkId, entityId); + } + + public static Map getUserInSelectedBillsProjectOwer(IMobileListView mobileListView, String entityId) { + return (Map) getSelectBillProjectOwer(mobileListView, entityId).getDynamicObjectCollection("projectower").stream().collect(Collectors.toMap((k) -> { + return k.getLong("FBASEDATAID_id"); + }, (k) -> { + return k.getDynamicObject("fbasedataid"); + }, (k, v) -> { + return v; + })); + } + + public static void setUsersToSelectedBillProjectOwer(Set ids, IMobileListView mobileListView, String entityId) { + DynamicObject selectBill = getSelectBillProjectOwer(mobileListView, entityId); + DynamicObjectCollection projectowers = selectBill.getDynamicObjectCollection("projectower"); + if (projectowers.size() == 0) { + projectowers.addNew(); + } + + DynamicObjectType projectOwersType = (DynamicObjectType) ((DynamicObject) projectowers.get(0)).getDataEntityType(); + projectowers.clear(); + selectBill.set("projectower", projectowers); + SaveServiceHelper.save(new DynamicObject[]{selectBill}); + Iterator var6 = ids.iterator(); + + while (var6.hasNext()) { + Long r = (Long) var6.next(); + DynamicObject tmpDynamicObject = new DynamicObject(projectOwersType); + tmpDynamicObject.set("fbasedataid", r); + tmpDynamicObject.set("FBASEDATAID_id", r); + projectowers.add(tmpDynamicObject); + } + + selectBill.set("projectower", projectowers); + SaveServiceHelper.save(new DynamicObject[]{selectBill}); + } + + public static void createShowMobileF7ListForm(String formId, boolean isMultiSelect, IMobileListView view, IFormPlugin plugin) { + MobileListShowParameter listShowParameter = new MobileListShowParameter(); + FormConfig formConfig = FormMetadataCache.getMobListFormConfig(formId); + listShowParameter.setCaption(formConfig.getCaption().toString()); + listShowParameter.setLookUp(true); + listShowParameter.setBillFormId(formId); + ShowType showType; + if (formConfig.getShowType() == ShowType.MainNewTabPage) { + showType = ShowType.Floating; + } else { + showType = ShowType.Modal; + listShowParameter.setPosition(MobileFormPosition.Bottom); + } + + listShowParameter.getOpenStyle().setShowType(showType); + listShowParameter.setMultiSelect(isMultiSelect); + String f7ListFormId = formConfig.getF7ListFormId(); + if (StringUtils.isNotBlank(f7ListFormId)) { + listShowParameter.setFormId(f7ListFormId); + } + + listShowParameter.setCaption(ResManager.loadKDString("变更干系人", "ProjectOwerListPlugin_0", "fi-er-formplugin", new Object[0])); + listShowParameter.setShowUsed(true); + listShowParameter.setShowApproved(true); + listShowParameter.setShowQuickFilter(true); + listShowParameter.setShowFilter(true); + listShowParameter.setMustInput(true); + listShowParameter.setSelectedRows(getUserInSelectedBillsProjectOwer(view, "er_contractbill").keySet().toArray()); + listShowParameter.setCloseCallBack(new CloseCallBack(plugin, "projectower")); + view.showForm(listShowParameter); + } + + public static boolean checkChangeProjectOwer(ListSelectedRowCollection listSelectedRows, IMobileListView view) { + boolean res = Boolean.FALSE; + if (listSelectedRows != null && listSelectedRows.size() == 1) { + QFilter qFilter = new QFilter("id", "in", listSelectedRows.stream().map((v) -> { + return (Long) v.getPrimaryKeyValue(); + }).collect(Collectors.toList())); + String OnWayCondition = "H,I,J"; + DynamicObjectCollection selectedBills = QueryServiceHelper.query("er_contractbill", "id,detailtype,billstatus,company", new QFilter[]{qFilter}); + Set billstatusSet = (Set) selectedBills.stream().filter((v) -> { + return OnWayCondition.contains(v.getString("billstatus")); + }).collect(Collectors.toSet()); + if (billstatusSet.size() > 0) { + view.showTipNotification(ResManager.loadKDString("选择单据的单据状态不支持变更干系人,请重新选择单据。", "ContractBillList_2", "fi-er-formplugin", new Object[0])); + return Boolean.TRUE; + } else { + Set detailtypeSet = (Set) selectedBills.stream().filter((v) -> { + return "biztype_stopbill".equals(v.get("detailtype")) || "biztype_changebill".equals(v.get("detailtype")); + }).collect(Collectors.toSet()); + if (detailtypeSet.size() > 0) { + view.showTipNotification(ResManager.loadKDString("合同变更单/合同终止单不支持变更干系人,请重新选择单据。", "ContractBillList_3", "fi-er-formplugin", new Object[0])); + return Boolean.TRUE; + } else { + if ("1".equals(ErCommonUtils.getEMParameter(RequestContext.get().getOrgId(), "stakeholderschange"))) { + view.showTipNotification(ResManager.loadKDString("移动端暂不支持需要流程审批的干系人变更。", "ContractBillList_23", "fi-er-formplugin", new Object[0])); + } + + return res; + } + } + } else { + view.showTipNotification(ResManager.loadKDString("请选择一行数据进行变更干系人操作。", "ProjectOwerListPlugin_1", "fi-er-formplugin", new Object[0])); + return Boolean.TRUE; + } + } + + public static void setSecondFiledLockAndVisible(String detaiType, String changeType, IDataModel dataModel, IFormView formView, String entryName) { + if ("biztype_stopbill".equals(detaiType)) { + if ("projectentryentity".equals(entryName)) { + formView.setEnable(Boolean.FALSE, new String[]{"flexpanelap"}); + formView.setVisible(Boolean.FALSE, new String[]{"btn_save"}); + } else if ("contractpartyentry".equals(entryName)) { + formView.setEnable(Boolean.FALSE, new String[]{"flexpanelap"}); + formView.setVisible(Boolean.FALSE, new String[]{"addcontractpart", "btn_save"}); + } else if ("termentry".equals(entryName)) { + formView.setEnable(Boolean.FALSE, new String[]{"flexpanelap"}); + formView.setVisible(Boolean.FALSE, new String[]{"addcontractitem", "btn_save"}); + } else if ("expenseentryentity".equals(entryName)) { + formView.setEnable(Boolean.FALSE, new String[]{"flexpanelap"}); + formView.setVisible(Boolean.FALSE, new String[]{"addcontractplan", "btn_save"}); + } + } else if ("biztype_changebill".equals(detaiType)) { + if ("projectentryentity".equals(entryName)) { + formView.setEnable(Boolean.FALSE, new String[]{"flexpanelap"}); + formView.setVisible(Boolean.FALSE, new String[]{"btn_save"}); + } else if ("contractpartyentry".equals(entryName)) { + formView.setEnable(Boolean.FALSE, new String[]{"flexpanelap"}); + formView.setVisible(Boolean.FALSE, new String[]{"addcontractpart", "btn_save"}); + } else if ("termentry".equals(entryName)) { + if (!"D".equals(changeType)) { + formView.setEnable(Boolean.FALSE, new String[]{"flexpanelap"}); + formView.setVisible(Boolean.FALSE, new String[]{"addcontractitem", "btn_save"}); + } + } else if ("expenseentryentity".equals(entryName)) { + if ("A".equals(changeType)) { + formView.setVisible(Boolean.FALSE, new String[]{"addcontractplan"}); + formView.setEnable(Boolean.FALSE, 0, new String[]{"paymenttypeid", "happendate", "taxrate", "orientryamount", "invoicetype", "entrycostcenter", "expenseitem", "std_project", "entryproducttype", "assetunit", "num", "exppricewithtax", "entryremark", "payterms", "entrycostdept", "entrycostcompany"}); + } else if ("B".equals(changeType)) { + formView.setVisible(Boolean.FALSE, new String[]{"addcontractplan"}); + formView.setEnable(Boolean.FALSE, 0, new String[]{"paymenttypeid", "happendate", "expenseamount", "orientryamount", "invoicetype", "entrycostcenter", "expenseitem", "std_project", "entryproducttype", "assetunit", "num", "exppricewithtax", "entryremark", "payterms", "entrycostdept", "entrycostcompany"}); + } else if ("C".equals(changeType)) { + FormShowParameter formShowParameter = formView.getFormShowParameter(); + int index = (Integer) formShowParameter.getCustomParam("index"); + if (index != -1 && "1".equals(dataModel.getValue("itemfrom", 0))) { + formView.setEnable(Boolean.FALSE, 0, new String[]{"paymenttypeid", "happendate", "expenseamount", "taxrate", "taxamount", "orientryamount", "invoicetype", "entrycostcenter", "expenseitem", "std_project", "entryproducttype", "assetunit", "num", "exppricewithtax", "entryremark", "payterms", "entrycostdept", "entrycostcompany"}); + } + } else if ("D".equals(changeType)) { + formView.setVisible(Boolean.FALSE, new String[]{"addcontractplan"}); + formView.setEnable(Boolean.FALSE, 0, new String[]{"expenseamount", "taxamount", "taxrate", "entrycostdept", "entrycostcenter", "entrycostcompany"}); + } + } + } + + } + + public static void setFirstFiledLockAndVisible(String detaiType, String changeType, IDataModel dataModel, IFormView formView) { + if ("biztype_stopbill".equals(detaiType)) { + formView.setEnable(Boolean.FALSE, new String[]{"alltipsflex", "costcompanyflexpanel", "contractflexpanel", "flexpanelap6", "projectower", "projecttype"}); + formView.setVisible(Boolean.FALSE, new String[]{"label_sign_delete", "label_sign_done", "label_exp_delete", "label_exp_done", "flex_addcontractpart", "btn_plan_add", "btn_contractitem_add", "btn_contractproject_add", "label_item_delete", "label_item_done", "label_project_delete", "label_project_done", "changedate", "lb_change"}); + } else if ("biztype_changebill".equals(detaiType)) { + formView.setEnable(Boolean.FALSE, new String[]{"costcompanyflexpanel", "contracttype", "contractcode", "contractname", "signdate", "relationconpanelapl", "frameworkcontract", "projecttype"}); + formView.setVisible(Boolean.FALSE, new String[]{"flexcontractpanelap", "label_sign_delete", "label_sign_delete", "flex_addcontractpart", "flexpanelap6", "lb_change"}); + if ("A".equals(changeType)) { + formView.setVisible(Boolean.FALSE, new String[]{"label_exp_delete", "label_exp_done", "btn_plan_add", "btn_contractitem_add", "label_item_delete", "label_item_done"}); + } else if ("B".equals(changeType)) { + formView.setVisible(Boolean.FALSE, new String[]{"label_exp_delete", "label_exp_done", "btn_plan_add", "btn_contractitem_add", "label_item_delete", "label_item_done"}); + } else if ("C".equals(changeType)) { + formView.setVisible(Boolean.FALSE, new String[]{"btn_contractitem_add", "label_item_delete", "label_item_done"}); + } else if ("D".equals(changeType)) { + formView.setVisible(Boolean.FALSE, new String[]{"label_exp_delete", "label_exp_done", "btn_plan_add"}); + } + } else { + formView.setVisible(Boolean.FALSE, new String[]{"changedate"}); + } + + } + + public static void contractPaybyrataCheckAmount(BeforeDoOperationEventArgs e, IDataModel dataModel, IFormView formView) { + Boolean ispaybyrata = (Boolean) dataModel.getValue("paybyrata"); + if (ispaybyrata) { + BigDecimal prorataamount = (BigDecimal) dataModel.getValue("prorataamount"); + BigDecimal proratataxamount = (BigDecimal) dataModel.getValue("proratataxamount"); + DynamicObjectCollection expcoll = dataModel.getEntryEntity("expenseentryentity"); + BigDecimal paypercent = (BigDecimal) expcoll.stream().map((n) -> { + return n.getBigDecimal("paypercent"); + }).reduce(BigDecimal.ZERO, BigDecimal::add); + if (ispaybyrata && paypercent.compareTo(new BigDecimal(100L)) == 0) { + BigDecimal diff = ErStdConfig.getAccentryDiffRange(); + if (prorataamount.compareTo(BigDecimal.ZERO) != 0) { + BigDecimal expenseamounttol = (BigDecimal) expcoll.stream().map((n) -> { + return n.getBigDecimal("expenseamount"); + }).reduce(BigDecimal.ZERO, BigDecimal::add); + BigDecimal tailDiff = prorataamount.subtract(expenseamounttol); + BigDecimal taxamounttol; + if (expenseamounttol.compareTo(prorataamount) != 0) { + if (tailDiff.compareTo(diff) <= 0 && tailDiff.compareTo(diff.multiply(BigDecimal.valueOf(-1L))) >= 0) { + taxamounttol = (BigDecimal) dataModel.getValue("expenseamount", expcoll.size() - 1); + dataModel.setValue("expenseamount", taxamounttol.add(tailDiff), expcoll.size() - 1); + } else { + e.setCancel(true); + formView.showTipNotification(String.format(ResManager.loadKDString("温馨提示:合同金额不等于“付款计划”分录含税金额合计,请修改。", "ContractUtil_31", "fi-er-business", new Object[0]))); + } + } + + if (proratataxamount.compareTo(BigDecimal.ZERO) != 0) { + taxamounttol = (BigDecimal) expcoll.stream().map((n) -> { + return n.getBigDecimal("taxamount"); + }).reduce(BigDecimal.ZERO, BigDecimal::add); + BigDecimal taxDiff = proratataxamount.subtract(taxamounttol); + if (proratataxamount.compareTo(taxamounttol) != 0) { + if (taxDiff.compareTo(diff) <= 0 && taxDiff.compareTo(diff.multiply(BigDecimal.valueOf(-1L))) >= 0) { + BigDecimal taxamount = (BigDecimal) dataModel.getValue("taxamount", expcoll.size() - 1); + dataModel.setValue("taxamount", taxamount.add(taxDiff), expcoll.size() - 1); + } else { + e.setCancel(true); + formView.showTipNotification(String.format(ResManager.loadKDString("温馨提示:合同税额不等于“付款计划”分录税额合计,请修改。", "ContractUtil_32", "fi-er-business", new Object[0]))); + } + } + } + } + } + } + + } + + private static boolean checkBizdate(String dateStr) { + if (dateStr != null) { + Matcher matcher = Pattern.compile("\\d{4}-\\d{2}-\\d{2}").matcher(dateStr); + return !matcher.matches(); + } else { + return false; + } + } +}