diff --git a/sys/shkd-sys-sys/src/main/java/shkd/sys/sys/plugin/list/LpzListPlugin.java b/sys/shkd-sys-sys/src/main/java/shkd/sys/sys/plugin/list/LpzListPlugin.java index 57a5d4c..8d52914 100644 --- a/sys/shkd-sys-sys/src/main/java/shkd/sys/sys/plugin/list/LpzListPlugin.java +++ b/sys/shkd-sys-sys/src/main/java/shkd/sys/sys/plugin/list/LpzListPlugin.java @@ -6,6 +6,8 @@ import kd.bos.dataentity.entity.DynamicObjectCollection; import kd.bos.entity.datamodel.ListSelectedRow; import kd.bos.entity.datamodel.ListSelectedRowCollection; import kd.bos.form.control.events.ItemClickEvent; +import kd.bos.form.events.BeforeDoOperationEventArgs; +import kd.bos.form.operate.AbstractOperate; import kd.bos.list.BillList; import kd.bos.list.plugin.AbstractListPlugin; import kd.bos.logging.Log; @@ -15,16 +17,12 @@ import kd.bos.orm.query.QFilter; import kd.bos.servicehelper.BusinessDataServiceHelper; import kd.bos.servicehelper.coderule.CodeRuleServiceHelper; import kd.bos.servicehelper.operation.SaveServiceHelper; -import kd.scmc.pm.forecast.business.helper.DateHelper; +import kd.bos.entity.operate.Delete; import kd.sdk.plugin.Plugin; import java.math.BigDecimal; import java.text.SimpleDateFormat; -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Date; +import java.util.*; /** * 标准单据列表插件 @@ -44,28 +42,38 @@ public class LpzListPlugin extends AbstractListPlugin implements Plugin { ListSelectedRowCollection selectedRows = list.getSelectedRows(); if ("shkd_combined".equals(itemKey)) { - if (selectedRows.isEmpty() || selectedRows.size() == 1) { + if (selectedRows.isEmpty() || selectedRows.size() == 2) { this.getView().showTipNotification("请至少选择两条数据"); - return; } else { + List selectedRowPKValues = new ArrayList<>(); + for (ListSelectedRow selectedRow : selectedRows) { + selectedRowPKValues.add(selectedRow.getPrimaryKeyValue()); + } + selectedRowPKValues = new ArrayList<>(new HashSet<>(selectedRowPKValues)); + //合并的凭证 List allMergeVoucher = new ArrayList<>(); //核算组织的类型 List tallycompanys = new ArrayList<>(); - for (ListSelectedRow selectedRow : selectedRows) { - Object primaryKeyValue = selectedRow.getPrimaryKeyValue(); - + for (Object primaryKeyValue : selectedRowPKValues) { //获取凭证全部数据 // DynamicObject dynamicObject = BusinessDataServiceHelper.loadSingle(primaryKeyValue, "fr_manualtallybill"); - DynamicObject[] dynamicObjects = BusinessDataServiceHelper.load("shkd_fr_manualtallybi_inh", "id,billno,tallycompany,biztype,company,currency,accountbook,applydate," + - "bizdate,bookdate,period,vouchertype,biztype,amount,shkd_combined,shkd_combinedtime,tallyentryentity,tallyentryentity.tallyabstract,tallyentryentity.loanstanamount,tallyentryentity.standardamount,tallyentryentity.shkd_hswd," + - "tallyentryentity.account,tallyentryentity.loanamount,tallyentryentity.oriamount,tallyentryentity.maincfitem,tallyentryentity.shkd_zbhswd,tallyentryentity.maincfamount,tallyentryentity.cuscurrency," + - "tallyentryentity.exrate,tallyentryentity.ratedate,tallyentryentity.tallyamount", new QFilter("id", QCP.equals, primaryKeyValue).toArray()); + DynamicObject[] dynamicObjects = BusinessDataServiceHelper.load("shkd_fr_manualtallybi_inh", + "id,billno,tallycompany,biztype,company,currency,accountbook,applydate,bizdate," + + "bookdate,period,vouchertype,biztype,amount,shkd_combined,shkd_combinedtime,shkd_bemerged," + + "shkd_bemergedtime,tallyentryentity,tallyentryentity.tallyabstract,tallyentryentity.loanstanamount," + + "tallyentryentity.standardamount,tallyentryentity.shkd_hswd,tallyentryentity.account," + + "tallyentryentity.loanamount,tallyentryentity.oriamount,tallyentryentity.maincfitem," + + "tallyentryentity.shkd_zbhswd,tallyentryentity.maincfamount,tallyentryentity.cuscurrency," + + "tallyentryentity.exrate,tallyentryentity.ratedate,tallyentryentity.tallyamount," + + "shkd_djhbjlentryentity,shkd_djhbjlentryentity.shkd_hbdj,shkd_djhbjlentryentity.shkd_djbzywlx", + new QFilter("id", QCP.equals, primaryKeyValue).toArray()); DynamicObject dynamicObject = dynamicObjects[0]; boolean shkdCombined = dynamicObject.getBoolean("shkd_combined"); - if (shkdCombined) { + boolean shkd_bemerged = dynamicObject.getBoolean("shkd_bemerged"); + if (shkdCombined || shkd_bemerged) { this.getView().showTipNotification("所选数据存在已合并凭证"); return; } @@ -81,6 +89,11 @@ public class LpzListPlugin extends AbstractListPlugin implements Plugin { // 核算组织去重 tallycompanys = new ArrayList<>(new HashSet<>(tallycompanys)); + // 币种 + DynamicObject[] bdCurrency = BusinessDataServiceHelper.load("bd_currency", "id,name", new QFilter("name", QCP.equals, "人民币").toArray()); + // 当前日期 + Date currentDate = new Date(); + for (Long tallycompany : tallycompanys) { // 根据核算组织分类后的合并凭证 List mergeVoucher = new ArrayList<>(); @@ -140,6 +153,20 @@ public class LpzListPlugin extends AbstractListPlugin implements Plugin { // 创建一个合并单据 DynamicObject frManualtallybill = BusinessDataServiceHelper.newDynamicObject("shkd_fr_manualtallybi_inh"); + // 单据合并记录分录 + DynamicObjectCollection shkdDjhbjlentryentity = frManualtallybill.getDynamicObjectCollection("shkd_djhbjlentryentity"); + for (DynamicObject consolidateDocument : consolidateDocuments) { + DynamicObject dynamicObject = shkdDjhbjlentryentity.addNew(); + + dynamicObject.set("shkd_hbdj", consolidateDocument); + dynamicObject.set("shkd_djbzywlx", consolidateDocument.getDynamicObject("biztype")); + + consolidateDocument.set("shkd_bemerged", true); + consolidateDocument.set("shkd_bemergedtime", currentDate); + SaveServiceHelper.save(new DynamicObject[]{consolidateDocument}); + } + + DynamicObject packagenoObject = mergeVoucher.get(0); // CodeRuleServiceHelper(编码规则帮助服务类) CodeRuleInfo codeRule = CodeRuleServiceHelper.getCodeRule(packagenoObject.getDataEntityType().getName(), packagenoObject, null); @@ -152,12 +179,6 @@ public class LpzListPlugin extends AbstractListPlugin implements Plugin { frManualtallybill.set("company", tallycompany); // 核算组织 frManualtallybill.set("tallycompany", tallycompany); - - // 币种 - DynamicObject[] bdCurrency = BusinessDataServiceHelper.load("bd_currency", "id,name", new QFilter("name", QCP.equals, "人民币").toArray()); - // 当前日期 - Date currentDate = new Date(); - // 本位币种 frManualtallybill.set("currency", bdCurrency[0]); // 账簿类型 @@ -411,4 +432,34 @@ public class LpzListPlugin extends AbstractListPlugin implements Plugin { } } } + @Override + public void beforeDoOperation(BeforeDoOperationEventArgs args) { + super.beforeDoOperation(args); + AbstractOperate argsSource = (AbstractOperate)args.getSource(); + String operateKey = argsSource.getOperateKey(); + if (("delete").equals(operateKey)) { + ListSelectedRowCollection listSelectedData = ((Delete) argsSource).getListSelectedData(); + List listFocusRowPKIds = new ArrayList<>(); + for (ListSelectedRow listSelectedRow : listSelectedData) { + Object primaryKeyValue = listSelectedRow.getPrimaryKeyValue(); + listFocusRowPKIds.add(primaryKeyValue); + } + listFocusRowPKIds = new ArrayList<>(new HashSet<>(listFocusRowPKIds)); + for (Object listFocusRowPKId : listFocusRowPKIds) { + DynamicObject dynamicObject = BusinessDataServiceHelper.loadSingle(listFocusRowPKId, "shkd_fr_manualtallybi_inh"); + boolean shkdCombined = dynamicObject.getBoolean("shkd_combined"); + if (shkdCombined) { + DynamicObjectCollection shkdDjhbjlentryentitys = dynamicObject.getDynamicObjectCollection("shkd_djhbjlentryentity"); + List dynamicObjects = new ArrayList<>(); + for (DynamicObject shkdDjhbjlentryentity : shkdDjhbjlentryentitys) { + DynamicObject shkdFrManualtallybiInh = BusinessDataServiceHelper.loadSingle(shkdDjhbjlentryentity.getDynamicObject("shkd_hbdj").getPkValue(), "shkd_fr_manualtallybi_inh"); + shkdFrManualtallybiInh.set("shkd_bemerged", false); + shkdFrManualtallybiInh.set("shkd_bemergedtime", null); + dynamicObjects.add(shkdFrManualtallybiInh); + } + SaveServiceHelper.save(dynamicObjects.toArray(new DynamicObject[0])); + } + } + } + } } \ No newline at end of file