diff --git a/code/zcdev/zcgj-zcdev-zcdev-pr/src/main/java/kd/ec/contr/KsRepAmountServiceImpl.java b/code/zcdev/zcgj-zcdev-zcdev-pr/src/main/java/kd/ec/contr/KsRepAmountServiceImpl.java index ccc5e6b..41fc3f6 100644 --- a/code/zcdev/zcgj-zcdev-zcdev-pr/src/main/java/kd/ec/contr/KsRepAmountServiceImpl.java +++ b/code/zcdev/zcgj-zcdev-zcdev-pr/src/main/java/kd/ec/contr/KsRepAmountServiceImpl.java @@ -1,8 +1,11 @@ package kd.ec.contr; +import kd.bos.coderule.api.CodeRuleInfo; +import kd.bos.context.RequestContext; import kd.bos.dataentity.OperateOption; import kd.bos.dataentity.entity.DynamicObject; import kd.bos.dataentity.entity.DynamicObjectCollection; +import kd.bos.dataentity.metadata.dynamicobject.DynamicObjectType; import kd.bos.dataentity.resource.ResManager; import kd.bos.dataentity.utils.StringUtils; import kd.bos.db.tx.TX; @@ -15,6 +18,8 @@ import kd.bos.logging.Log; import kd.bos.logging.LogFactory; import kd.bos.orm.query.QFilter; import kd.bos.servicehelper.BusinessDataServiceHelper; +import kd.bos.servicehelper.QueryServiceHelper; +import kd.bos.servicehelper.coderule.CodeRuleServiceHelper; import kd.bos.servicehelper.operation.DeleteServiceHelper; import kd.bos.servicehelper.operation.OperationServiceHelper; import kd.bos.servicehelper.operation.SaveServiceHelper; @@ -23,6 +28,7 @@ import kd.ec.basedata.common.enums.PayDirectionEnum; import kd.ec.contract.mservice.bill.RepAmountServiceImpl; import java.math.BigDecimal; +import java.math.RoundingMode; import java.util.*; public class KsRepAmountServiceImpl extends RepAmountServiceImpl implements KsRepAmountService { @@ -49,8 +55,8 @@ public class KsRepAmountServiceImpl extends RepAmountServiceImpl implements KsRe Map> fiBillIdEntryAmtMap = new HashMap(16); Map> fiBillIdEcApplyIdMap = new HashMap(16); boolean isCancel = false; - boolean isincomeapply = true; //是否来源与收款申请单 - + boolean isincomeapply = false; //是否来源与收款申请单 + boolean isnocontractpay=false; //无合同付款 for(Map entryData : dataList) { Long reqBillId = (Long)entryData.get("sourcepk"); String operation = String.valueOf(entryData.get("operation")); @@ -87,7 +93,10 @@ public class KsRepAmountServiceImpl extends RepAmountServiceImpl implements KsRe String zcgjEcPaymentapplyenid = casRecbill.getString("zcgj_ec_paymentapplyenid"); //收款处理关联付款申请费用明细id if(StringUtils.isNotBlank(zcgjEcPaymentapplyid) && StringUtils.isNotBlank(zcgjEcPaymentapplyenid)) { - isincomeapply = false; + isincomeapply = true; + if(amount.compareTo(BigDecimal.ZERO) > 0) { + amount = amount.multiply(BigDecimal.valueOf(-1)); + } if (StringUtils.equals(operation, "receive")) { Map entryAmtMap = (Map)fiBillIdEntryAmtMap.get(fiBillId);//收款处理单id @@ -100,8 +109,9 @@ public class KsRepAmountServiceImpl extends RepAmountServiceImpl implements KsRe } } - if (StringUtils.equals(operation, "cancelreceive")) { + if (StringUtils.equals(operation, "cancelreceive")) {//取消 isCancel = true; + } Set ecBillIds = (Set)fiBillIdEcApplyIdMap.getOrDefault(fiBillId, new HashSet(16));//收款处理单-付款申请单关联map @@ -110,26 +120,37 @@ public class KsRepAmountServiceImpl extends RepAmountServiceImpl implements KsRe //工程付款申请单 DynamicObject ecPaymentapply = BusinessDataServiceHelper.loadSingle("ec_paymentapply", - "billcompletepay,sumamount," + + "billcompletepay,sumamount,realpayamt," + "entryentity.id," + "entryentity.completepay," + - "entryentity.thisapplyoftax", + "entryentity.thisapplyoftax,"+ + "entryentity.thisrealpayamt", new QFilter[]{new QFilter("id", "=", zcgjEcPaymentapplyid)}); ecPaymentapply.set("billcompletepay",!isCancel);//付款完成 ecPaymentapply.set("sumamount",amount);//本次申请金额(单头汇总) + if(!isCancel){ + ecPaymentapply.set("realpayamt",amount);//实付金额(单头汇总) + }else{ + ecPaymentapply.set("realpayamt", BigDecimal.ZERO); //实付金额 + } DynamicObjectCollection dynamicObjectCollection = ecPaymentapply.getDynamicObjectCollection("entryentity"); for (DynamicObject dynamicObject : dynamicObjectCollection) { long pkValue = dynamicObject.getLong("id"); if(Long.parseLong(zcgjEcPaymentapplyenid) == pkValue) { dynamicObject.set("completepay", !isCancel); dynamicObject.set("thisapplyoftax", amount); //本次申请金额 + if(!isCancel){ + dynamicObject.set("thisrealpayamt", amount); //本次实付金额 + }else{ + dynamicObject.set("thisrealpayamt", BigDecimal.ZERO); //本次实付金额 + } } } SaveServiceHelper.save(new DynamicObject[]{ecPaymentapply}); } } - if(isincomeapply){ //如果是来源付款申请单,则不进行校验 + if(!isincomeapply){ //如果是来源付款申请单,则不进行校验 DynamicObject incomeBill = BusinessDataServiceHelper.loadSingle(reqBillId, "ec_incomeapply"); if (null == incomeBill) { throw new KDBizException(ResManager.loadKDString("源申请单不存在,反写失败!", "RepAmountServiceImpl_3", "ec-contract-mservice", new Object[0])); @@ -152,11 +173,21 @@ public class KsRepAmountServiceImpl extends RepAmountServiceImpl implements KsRe Set ecBillIds = (Set)fiBillIdEcApplyIdMap.getOrDefault(fiBillId, new HashSet(16)); ecBillIds.add(reqBillId); fiBillIdEcApplyIdMap.put(fiBillId, ecBillIds); + if("01".equals(incomeBill.getString("sourcetype"))){//无合同 + if(!isCancel){ + incomeBill.set("realreceiptamt",amount); + incomeBill.set("billcompletereceipt",true); + }else{ + incomeBill.set("realreceiptamt",BigDecimal.ZERO); + incomeBill.set("billcompletereceipt",false); + } + isnocontractpay= true; + SaveServiceHelper.save(new DynamicObject[]{incomeBill}); + } } - } - if(isincomeapply){ + if(!isincomeapply){// if (isCancel) { Set longs = fiBillIdEcApplyIdMap.keySet(); Set longIdStringSet = new HashSet(16); @@ -181,18 +212,25 @@ public class KsRepAmountServiceImpl extends RepAmountServiceImpl implements KsRe DeleteServiceHelper.delete("ec_income_register", new QFilter[]{new QFilter("id", "=", register.getPkValue())}); } } + } else { - this.generateInRegisterBill(fiBillIdEntryAmtMap, fiBillIdEcApplyIdMap); + if(isnocontractpay) {//无合同收款登记单 + this.generateInRegisterBillNoContract(fiBillIdEntryAmtMap, fiBillIdEcApplyIdMap); + }else{ + this.generateInRegisterBill(fiBillIdEntryAmtMap, fiBillIdEcApplyIdMap); + + } } }else{ + Set longs = fiBillIdEcApplyIdMap.keySet(); + Set longIdStringSet = new HashSet(16); + + for(Long id : longs) { + longIdStringSet.add(id.toString()); + } + + if (isCancel) { - Set longs = fiBillIdEcApplyIdMap.keySet(); - Set longIdStringSet = new HashSet(16); - - for(Long id : longs) { - longIdStringSet.add(id.toString()); - } - DynamicObject[] referRegisterArr = BusinessDataServiceHelper.load("ec_payment_register", "entryentity,contract,thispaymentoftaxamount,thispaymentamount", new QFilter[]{new QFilter("referregisterid", "in", longIdStringSet)}); for(DynamicObject register : referRegisterArr) { @@ -216,6 +254,7 @@ public class KsRepAmountServiceImpl extends RepAmountServiceImpl implements KsRe } } else { this.generatePayRegisterBill(fiBillIdEntryAmtMap, fiBillIdEcApplyIdMap); + } } @@ -223,147 +262,91 @@ public class KsRepAmountServiceImpl extends RepAmountServiceImpl implements KsRe log.error("接口传递参数为空"); } } + } - //log.info("KsRepAmountServiceImpl:incomeRepAmount"); - //boolean isCancel = false; - //Map> fiBillIdEcApplyIdMap = new HashMap(16); - //Map> fiBillIdEntryAmtMap = new HashMap(16);//收款处理单数据 - //try (TXHandle txType = TX.requiresNew("ksincomeRepAmount")) { + /** + * 非合同收款生成收款登记单 + * @param billEntryAmtMap + * @param fiBillIdEcApplyIdMap + */ + protected void generateInRegisterBillNoContract(Map> billEntryAmtMap, Map> fiBillIdEcApplyIdMap) { - // for(Map entryData : dataList) { - /*Long reqBillId = (Long)entryData.get("sourcepk"); //工程收款申请单id - String operation = String.valueOf(entryData.get("operation")); //操作类型 - String srcEntryId = String.valueOf(entryData.get("sourceentrypk")); //出纳收款处理-收款明细分录id - BigDecimal amount = (BigDecimal)entryData.get("amount"); //实付金额 - Long fiBillId = (Long)entryData.get("targetpk");//出纳收款处理单id - if (StringUtils.isBlank(operation)) { - throw new KDBizException(ResManager.loadKDString("操作类型为空,反写失败!", "RepAmountServiceImpl_0", "ec-contract-mservice", new Object[0])); - }*/ + for(Map.Entry> entry : billEntryAmtMap.entrySet()) { + Long fiBillId = (Long)entry.getKey(); - //出纳收款处理 zcgj_ec_paymentapplyid - /*DynamicObject casRecbill = BusinessDataServiceHelper.loadSingle("cas_recbill", - "zcgj_ec_paymentapplyid,zcgj_ec_paymentapplyenid", - new QFilter[]{new QFilter("id", "=", fiBillId)});*/ - - /*if(casRecbill!=null){ - String zcgjEcPaymentapplyid = casRecbill.getString("zcgj_ec_paymentapplyid");//收款处理关联付款申请id - String zcgjEcPaymentapplyenid = casRecbill.getString("zcgj_ec_paymentapplyenid"); //收款处理关联付款申请费用明细id - *//*Map entryAmtMap = (Map)fiBillIdEntryAmtMap.get(fiBillId); - if (entryAmtMap != null) { - entryAmtMap.put(srcEntryId, amount); - } else { - Map newEntryAmtMap = new HashMap(16); - newEntryAmtMap.put(srcEntryId, amount); - fiBillIdEntryAmtMap.put(fiBillId, newEntryAmtMap); - }*/ - - /* - if (StringUtils.equals(operation, "receive")) { - Map entryAmtMap = (Map)fiBillIdEntryAmtMap.get(fiBillId);//收款处理单id - if (entryAmtMap != null) { - entryAmtMap.put(srcEntryId, amount);//收款处理单费用明细id,收款金额 - } else { - Map newEntryAmtMap = new HashMap(16); - newEntryAmtMap.put(srcEntryId, amount);//收款处理单费用明细id,收款金额 - fiBillIdEntryAmtMap.put(fiBillId, newEntryAmtMap);//收款处理单id - } - } - - if (StringUtils.equals(operation, "cancelreceive")) { - isCancel = true; - } - - - - if(org.apache.commons.lang3.StringUtils.isNotBlank(zcgjEcPaymentapplyid) && - org.apache.commons.lang3.StringUtils.isNotBlank(zcgjEcPaymentapplyenid) ){ - //工程付款申请单 - DynamicObject ecPaymentapply = BusinessDataServiceHelper.loadSingle("ec_paymentapply", - "billcompletepay,sumamount," + - "entryentity.id," + - "entryentity.completepay," + - "entryentity.thisapplyoftax", - new QFilter[]{new QFilter("id", "=", zcgjEcPaymentapplyid)}); - ecPaymentapply.set("billcompletepay",!isCancel);//付款完成 - ecPaymentapply.set("sumamount",amount);//本次申请金额(单头汇总) - DynamicObjectCollection dynamicObjectCollection = ecPaymentapply.getDynamicObjectCollection("entryentity"); - for (DynamicObject dynamicObject : dynamicObjectCollection) { - long pkValue = dynamicObject.getLong("id"); - if(Long.parseLong(zcgjEcPaymentapplyenid) == pkValue) { - dynamicObject.set("completepay", !isCancel); - dynamicObject.set("thisapplyoftax", amount); //本次申请金额 - } - } - SaveServiceHelper.save(new DynamicObject[]{ecPaymentapply}); - } - - - Set ecBillIds = (Set)fiBillIdEcApplyIdMap.getOrDefault(fiBillId, new HashSet(16));//收款处理单-付款申请单关联map - ecBillIds.add(Long.parseLong(zcgjEcPaymentapplyid));//付款申请单 - fiBillIdEcApplyIdMap.put(fiBillId, ecBillIds); - - if (isCancel) { - Set longs = fiBillIdEcApplyIdMap.keySet(); - Set longIdStringSet = new HashSet(16); - - for(Long id : longs) { - longIdStringSet.add(id.toString()); - } - - DynamicObject[] referRegisterArr = BusinessDataServiceHelper.load("ec_payment_register", "entryentity,contract,thispaymentoftaxamount,thispaymentamount", new QFilter[]{new QFilter("referregisterid", "in", longIdStringSet)}); - - for(DynamicObject register : referRegisterArr) { - log.info("开始执行之前生成的付款登记单的反审核逻辑:" + register.getPkValue()); - OperateOption operateOption = OperateOption.create(); - operateOption.setVariableValue("ishasright", String.valueOf(true)); - OperationResult operationResult = OperationServiceHelper.executeOperate("unaudit", "ec_payment_register", new Object[]{register.getPkValue()}, operateOption); - log.info("完成执行之前生成的付款登记单的反审核逻辑:" + register.getPkValue()); - log.info("开始删除之前生成的付款登记单:" + register.getPkValue()); - if (operationResult != null) { - boolean success = operationResult.isSuccess(); - if (!success) { - log.error(operationResult.getAllErrorOrValidateInfo().toString()); - throw new KDBizException(operationResult.getMessage()); - } - - DeleteServiceHelper.delete("ec_payment_register", new QFilter[]{new QFilter("id", "=", register.getPkValue())}); - } - - log.info("完成删除之前生成的付款登记单:" + register.getPkValue()); - } - } else { - this.generatePayRegisterBill(fiBillIdEntryAmtMap, fiBillIdEcApplyIdMap); - } - }*/ - - //工程收款申请单 - /*DynamicObject contractBillCols = BusinessDataServiceHelper.loadSingle("ec_incomeapply", - "billname,billno", - new QFilter[]{new QFilter("id", "=", reqBillId)});*/ - - - - /*if (StringUtils.equals(operation, "receive")) { - Map entryAmtMap = (Map)fiBillIdEntryAmtMap.get(fiBillId); - if (entryAmtMap != null) { - entryAmtMap.put(srcEntryId, amount); - } else { - Map newEntryAmtMap = new HashMap(16); - newEntryAmtMap.put(srcEntryId, amount); - fiBillIdEntryAmtMap.put(fiBillId, newEntryAmtMap); - } + for(Object ecApplyId : (Set)fiBillIdEcApplyIdMap.get(fiBillId)) { + QFilter fiBillIdFilter = new QFilter("referregisterid", "=", fiBillId.toString()); + fiBillIdFilter.and("entryentity.incomeapply", "=", ecApplyId); + boolean exists = QueryServiceHelper.exists("ec_income_register", new QFilter[]{fiBillIdFilter}); + if (exists) { + log.info("该财务单据和请款单已生成登记单(无合同):" + fiBillId.toString() + "/" + ecApplyId.toString()); + return; } - if (StringUtils.equals(operation, "cancelreceive")) { - isCancel = true; + DynamicObject inComeApply = BusinessDataServiceHelper.loadSingle(ecApplyId, "ec_incomeapply"); + MainEntityType incomeRegisterDt = EntityMetadataCache.getDataEntityType("ec_income_register"); + DynamicObject newInComeRegisterObj = new DynamicObject(incomeRegisterDt); + DynamicObject currentPeriod = getCurrentPeriod(); + this.generateInRegisterNoContract(inComeApply, newInComeRegisterObj, (Map)entry.getValue(), currentPeriod); + newInComeRegisterObj.set("referregisterid", fiBillId); + Object[] objects = SaveServiceHelper.save(new DynamicObject[]{newInComeRegisterObj}); + OperateOption operateOption = OperateOption.create(); + operateOption.setVariableValue("ishasright", String.valueOf(true)); + OperationResult audit = OperationServiceHelper.executeOperate("audit", "ec_income_register", new Object[]{((DynamicObject)objects[0]).getPkValue()}, operateOption); + if (audit != null) { + boolean success = audit.isSuccess(); + if (!success) { + throw new KDBizException(audit.getAllErrorOrValidateInfo().toString()); + } } - - Set ecBillIds = (Set)fiBillIdEcApplyIdMap.getOrDefault(fiBillId, new HashSet(16)); - ecBillIds.add(reqBillId); - fiBillIdEcApplyIdMap.put(fiBillId, ecBillIds);*/ - // } - - // } + } + } } + + protected void generateInRegisterNoContract(DynamicObject inComeApply, DynamicObject inComeRegister, Map entryAmtMap, DynamicObject currentPeriod) { + DynamicObject[] funditem = BusinessDataServiceHelper.load("ec_funditem", + "id,number", new QFilter[]{new QFilter("number", "=", "ZJKX-001")}); + inComeRegister.set("billstatus", BillStatusEnum.SUBMIT.getValue()); + inComeRegister.set("org", inComeApply.get("org")); + inComeRegister.set("bizdate", new Date()); + inComeRegister.set("period", currentPeriod); + inComeRegister.set("project", inComeApply.get("project")); + inComeRegister.set("currency", inComeApply.get("currency")); + inComeRegister.set("sourcetype", inComeApply.get("sourcetype")); + inComeRegister.set("bizaccountorg", inComeApply.get("bizaccountorg")); + inComeRegister.set("fiaccountorg", inComeApply.get("fiaccountorg")); + inComeRegister.set("creator", RequestContext.get().getCurrUserId()); + inComeRegister.set("modifier", RequestContext.get().getCurrUserId()); + inComeRegister.set("auditor", RequestContext.get().getCurrUserId()); + inComeRegister.set("createtime", new Date()); + inComeRegister.set("modifytime", new Date()); + BigDecimal sumamount = inComeApply.getBigDecimal("sumamount");//请款金额 + DynamicObjectCollection entryCol = inComeRegister.getDynamicObjectCollection("itementry");//非合同请款分录 + DynamicObjectType entryDt = entryCol.getDynamicObjectType(); + DynamicObject newEntry = new DynamicObject(entryDt); + if(funditem!=null){ + newEntry.set("funditem",funditem[0]); + } + newEntry.set("preapplyoftaxamt",sumamount); + newEntry.set("applyoftaxamt",sumamount); + entryCol.add(newEntry); + //DynamicObjectCollection inComeEntryCol = inComeApply.getDynamicObjectCollection("entryentity"); + int beginIndex = 1; + /*for(DynamicObject inComeEntry : inComeEntryCol) { + String entryId = inComeEntry.getString("id"); + if (entryAmtMap.get(entryId) != null) { + } + }*/ + + CodeRuleInfo codeRuleInfo = CodeRuleServiceHelper.getCodeRule("ec_income_register", inComeRegister, String.valueOf(RequestContext.get().getOrgId())); + if (null != codeRuleInfo) { + inComeRegister.set("billno", CodeRuleServiceHelper.getNumber(codeRuleInfo, inComeRegister)); + } else { + long currentTimeMillis = System.currentTimeMillis(); + inComeRegister.set("billno", "CWFX-" + currentTimeMillis); + } + + inComeRegister.set("billname", inComeRegister.getString("billno")); + } }