支出财务确认单关联冲销
This commit is contained in:
parent
b2f0702195
commit
a646532296
|
@ -0,0 +1,100 @@
|
||||||
|
package zcgj.zcdev.zcdev.pr.plugin.operate;
|
||||||
|
|
||||||
|
import kd.bos.dataentity.entity.DynamicObject;
|
||||||
|
import kd.bos.dataentity.entity.DynamicObjectCollection;
|
||||||
|
import kd.bos.db.tx.TX;
|
||||||
|
import kd.bos.db.tx.TXHandle;
|
||||||
|
import kd.bos.entity.ExtendedDataEntity;
|
||||||
|
import kd.bos.entity.plugin.AbstractOperationServicePlugIn;
|
||||||
|
import kd.bos.entity.plugin.AddValidatorsEventArgs;
|
||||||
|
import kd.bos.entity.plugin.PreparePropertysEventArgs;
|
||||||
|
import kd.bos.entity.plugin.args.EndOperationTransactionArgs;
|
||||||
|
import kd.bos.entity.validate.AbstractValidator;
|
||||||
|
import kd.bos.logging.Log;
|
||||||
|
import kd.bos.logging.LogFactory;
|
||||||
|
import kd.bos.servicehelper.BusinessDataServiceHelper;
|
||||||
|
import kd.bos.servicehelper.operation.SaveServiceHelper;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 支出财务确认单提交时冲销金额校验插件
|
||||||
|
*/
|
||||||
|
public class OutFinaceconfirmReversalamountCkOp extends AbstractOperationServicePlugIn {
|
||||||
|
|
||||||
|
private static final Log log = LogFactory.getLog(OutFinaceconfirmReversalamountCkOp.class);
|
||||||
|
|
||||||
|
public void onPreparePropertys(PreparePropertysEventArgs e) {
|
||||||
|
e.getFieldKeys().add("zcgj_prepayentry");
|
||||||
|
e.getFieldKeys().add("zcgj_prepayentry.zcgj_sourceapplybillid");
|
||||||
|
e.getFieldKeys().add("zcgj_prepayentry.zcgj_sourceapplyentryid");
|
||||||
|
e.getFieldKeys().add("zcgj_prepayentry.zcgj_boltamount");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onAddValidators(AddValidatorsEventArgs e) {
|
||||||
|
super.onAddValidators(e);
|
||||||
|
e.getValidators().add(new ValidatorExt());
|
||||||
|
}
|
||||||
|
|
||||||
|
class ValidatorExt extends AbstractValidator {
|
||||||
|
@Override
|
||||||
|
public void validate() {
|
||||||
|
ExtendedDataEntity[] extendedDataEntities = this.getDataEntities();
|
||||||
|
for (ExtendedDataEntity extendedDataEntity : extendedDataEntities) {
|
||||||
|
DynamicObject dataEntity = extendedDataEntity.getDataEntity();//支出财务确认单
|
||||||
|
DynamicObjectCollection entryEntityCollection = dataEntity.getDynamicObjectCollection("zcgj_prepayentry");//付款信息分录
|
||||||
|
for (int i = 0; i < entryEntityCollection.size(); i++) {
|
||||||
|
DynamicObject entryEntity = entryEntityCollection.get(i);
|
||||||
|
DynamicObjectCollection prepayentryCollection = dataEntity.getDynamicObjectCollection("zcgj_prepayentry");//冲销预付分录
|
||||||
|
int seq = 0;
|
||||||
|
for (DynamicObject prepay : prepayentryCollection) {
|
||||||
|
seq++;
|
||||||
|
long sourceapplybillid = prepay.getLong("zcgj_sourceapplybillid");
|
||||||
|
long sourceapplyentryid = prepay.getLong("zcgj_sourceapplyentryid");
|
||||||
|
BigDecimal boltamount = prepay.getBigDecimal("zcgj_boltamount");//支出财务确认单冲销金额
|
||||||
|
DynamicObject paymentapply = BusinessDataServiceHelper.loadSingle(sourceapplybillid, "ec_paymentapply");//工程资金付款申请单
|
||||||
|
if (paymentapply != null) {
|
||||||
|
DynamicObjectCollection entryentityCollection = paymentapply.getDynamicObjectCollection("entryentity");
|
||||||
|
|
||||||
|
for (DynamicObject dynamicObject : entryentityCollection) {
|
||||||
|
BigDecimal thisrealpayamt = dynamicObject.getBigDecimal("thisrealpayamt");//付款申请单本次实付金额
|
||||||
|
long pkValue = (long)dynamicObject.getPkValue();
|
||||||
|
if(pkValue==sourceapplyentryid){
|
||||||
|
BigDecimal zcgjYreversalamount = dynamicObject.getBigDecimal("zcgj_yreversalamount");
|
||||||
|
zcgjYreversalamount = zcgjYreversalamount.add(boltamount);
|
||||||
|
if(thisrealpayamt.subtract(zcgjYreversalamount).compareTo(BigDecimal.ZERO) < 0){
|
||||||
|
this.addFatalErrorMessage(extendedDataEntity, String.format("冲销预付分录第%d行,冲销金额超限!",seq));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/*DynamicObject contract = entryEntity.getDynamicObject("contract");//合同名称
|
||||||
|
String contractNumber = null;
|
||||||
|
if (contract != null) {
|
||||||
|
contractNumber = contract.getString("number");//合同编号
|
||||||
|
}
|
||||||
|
String paymentType = entryEntity.getString("paymenttype");//支付类型
|
||||||
|
DynamicObject settleType = entryEntity.getDynamicObject("settletype");//结算方式
|
||||||
|
String settleTypeName = null;
|
||||||
|
if (settleType != null) {
|
||||||
|
settleTypeName = settleType.getString("name");//结算方式编码
|
||||||
|
}
|
||||||
|
String combinationKey = contractNumber + "|" + paymentType + "|" + settleTypeName;
|
||||||
|
if (combinationIndices.containsKey(combinationKey)) {
|
||||||
|
this.addFatalErrorMessage(extendedDataEntity, "付款信息中一个合同不能填写多行相同的支付类型+结算方式");
|
||||||
|
} else {
|
||||||
|
List<Integer> indices = new ArrayList<>();
|
||||||
|
indices.add(i);
|
||||||
|
combinationIndices.put(combinationKey, indices);
|
||||||
|
}*/
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,145 @@
|
||||||
|
package zcgj.zcdev.zcdev.pr.plugin.operate;
|
||||||
|
|
||||||
|
import kd.bos.dataentity.entity.DynamicObject;
|
||||||
|
import kd.bos.dataentity.entity.DynamicObjectCollection;
|
||||||
|
import kd.bos.db.tx.TX;
|
||||||
|
import kd.bos.db.tx.TXHandle;
|
||||||
|
import kd.bos.entity.ExtendedDataEntity;
|
||||||
|
import kd.bos.entity.plugin.AbstractOperationServicePlugIn;
|
||||||
|
import kd.bos.entity.plugin.AddValidatorsEventArgs;
|
||||||
|
import kd.bos.entity.plugin.PreparePropertysEventArgs;
|
||||||
|
import kd.bos.entity.plugin.args.EndOperationTransactionArgs;
|
||||||
|
import kd.bos.entity.validate.AbstractValidator;
|
||||||
|
import kd.bos.logging.Log;
|
||||||
|
import kd.bos.logging.LogFactory;
|
||||||
|
import kd.bos.servicehelper.BusinessDataServiceHelper;
|
||||||
|
import kd.bos.servicehelper.botp.BFTrackerServiceHelper;
|
||||||
|
import kd.bos.servicehelper.operation.SaveServiceHelper;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 支出财务确认单提交时反写付款申请单付款分录冲销金额
|
||||||
|
*/
|
||||||
|
public class OutFinaceconfirmReversalamountOp extends AbstractOperationServicePlugIn {
|
||||||
|
|
||||||
|
private static final Log log = LogFactory.getLog(OutFinaceconfirmReversalamountOp.class);
|
||||||
|
|
||||||
|
public void onPreparePropertys(PreparePropertysEventArgs e) {
|
||||||
|
e.getFieldKeys().add("zcgj_prepayentry");
|
||||||
|
e.getFieldKeys().add("zcgj_prepayentry.zcgj_sourceapplybillid");
|
||||||
|
e.getFieldKeys().add("zcgj_prepayentry.zcgj_sourceapplyentryid");
|
||||||
|
e.getFieldKeys().add("zcgj_prepayentry.zcgj_boltamount");
|
||||||
|
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public void endOperationTransaction(EndOperationTransactionArgs e) {
|
||||||
|
String operationKey = e.getOperationKey();
|
||||||
|
DynamicObject[] dataEntities = e.getDataEntities();
|
||||||
|
switch (operationKey) {
|
||||||
|
case "submit"://提交
|
||||||
|
log.info("执行OutFinaceconfirmReversalamountOp的提交操作,开始更新付款申请单付款信息分录冲销金额");
|
||||||
|
updateInApplyReversaAmt(dataEntities, true);
|
||||||
|
break;
|
||||||
|
case "unsubmit"://撤销
|
||||||
|
log.info("执行OutFinaceconfirmReversalamountOp的撤销操作,开始更新付款申请单付款信息分录冲销金额");
|
||||||
|
updateInApplyReversaAmt(dataEntities, false);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/*public void endOperationTransaction(EndOperationTransactionArgs e) {
|
||||||
|
}*/
|
||||||
|
|
||||||
|
protected void updateInApplyReversaAmt(DynamicObject[] dataEntities, boolean isSubmit){
|
||||||
|
List<DynamicObject> updateData = new ArrayList<>();
|
||||||
|
for (DynamicObject dataEntity : dataEntities) {
|
||||||
|
long id = dataEntity.getLong("id");
|
||||||
|
DynamicObjectCollection prepayentryCollection = dataEntity.getDynamicObjectCollection("zcgj_prepayentry");//冲销预付分录
|
||||||
|
for (DynamicObject prepay : prepayentryCollection) {
|
||||||
|
long sourceapplybillid = prepay.getLong("zcgj_sourceapplybillid");
|
||||||
|
long sourceapplyentryid = prepay.getLong("zcgj_sourceapplyentryid");
|
||||||
|
BigDecimal boltamount = prepay.getBigDecimal("zcgj_boltamount");//支出财务确认单冲销金额
|
||||||
|
DynamicObject paymentapply = BusinessDataServiceHelper.loadSingle(sourceapplybillid, "ec_paymentapply");//工程资金付款申请单
|
||||||
|
if (paymentapply != null) {
|
||||||
|
DynamicObjectCollection entryentityCollection = paymentapply.getDynamicObjectCollection("entryentity");
|
||||||
|
for (DynamicObject dynamicObject : entryentityCollection) {
|
||||||
|
BigDecimal thisrealpayamt = dynamicObject.getBigDecimal("thisrealpayamt");//付款申请单本次实付金额
|
||||||
|
long pkValue = (long)dynamicObject.getPkValue();
|
||||||
|
if(pkValue==sourceapplyentryid){
|
||||||
|
BigDecimal zcgjYreversalamount = dynamicObject.getBigDecimal("zcgj_yreversalamount");
|
||||||
|
if(!isSubmit){
|
||||||
|
boltamount = boltamount.multiply(BigDecimal.ZERO.subtract(BigDecimal.ONE));//取相反数
|
||||||
|
}
|
||||||
|
zcgjYreversalamount = zcgjYreversalamount.add(boltamount);
|
||||||
|
dynamicObject.set("zcgj_yreversalamount",zcgjYreversalamount);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
updateData.add(paymentapply);
|
||||||
|
}
|
||||||
|
if(!updateData.isEmpty()){
|
||||||
|
try (TXHandle txType = TX.requiresNew("updateAmt")) {
|
||||||
|
SaveServiceHelper.save(updateData.toArray(new DynamicObject[0]));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// idList.add(id);
|
||||||
|
/*Map<String, HashSet<Long>> sourceBills = BFTrackerServiceHelper.findSourceBills("cas_paybill", new Long[]{id});
|
||||||
|
HashSet<Long> zcgjEcFundingplanapply = sourceBills.get("zcgj_ec_fundingplanapply");
|
||||||
|
if(zcgjEcFundingplanapply != null && !zcgjEcFundingplanapply.isEmpty()) {
|
||||||
|
Long dataId = (Long)zcgjEcFundingplanapply.toArray()[0];
|
||||||
|
|
||||||
|
//计算实际付款金额
|
||||||
|
DynamicObject paybill = BusinessDataServiceHelper.loadSingle(id, "cas_paybill");
|
||||||
|
DynamicObject settletype = paybill.getDynamicObject("settletype");
|
||||||
|
String typeString = "";
|
||||||
|
|
||||||
|
DynamicObjectCollection entryCpllection = paybill.getDynamicObjectCollection("entry");
|
||||||
|
BigDecimal allActamt = BigDecimal.ZERO;
|
||||||
|
for (DynamicObject entry : entryCpllection) {
|
||||||
|
BigDecimal val = entry.getBigDecimal("e_actamt");
|
||||||
|
BigDecimal eActamt = val !=null ?val:BigDecimal.ZERO;//获取实付金额
|
||||||
|
allActamt = allActamt.add(eActamt);
|
||||||
|
}
|
||||||
|
|
||||||
|
//读取资金计划申请
|
||||||
|
DynamicObject fundingplanapply = BusinessDataServiceHelper.loadSingle(dataId, "zcgj_ec_fundingplanapply");
|
||||||
|
DynamicObjectCollection zcgjFinApprovedAmount = fundingplanapply.getDynamicObjectCollection("zcgj_fin_approved_amount");
|
||||||
|
for (DynamicObject dynamicObject : zcgjFinApprovedAmount) {
|
||||||
|
String zcgjSetttype = dynamicObject.getString("zcgj_setttype");
|
||||||
|
if(typeString.equals(zcgjSetttype)){
|
||||||
|
BigDecimal zcgjAmountpaid = dynamicObject.getBigDecimal("zcgj_amountpaid");
|
||||||
|
BigDecimal zcgjAmountRecommended = zcgjAmountpaid !=null ? zcgjAmountpaid:BigDecimal.ZERO;//实际付款金额
|
||||||
|
BigDecimal amountrecommended = BigDecimal.ZERO;
|
||||||
|
if(!isSubmit){
|
||||||
|
amountrecommended = allActamt;
|
||||||
|
allActamt = allActamt.multiply(BigDecimal.ZERO.subtract(BigDecimal.ONE));//取相反数
|
||||||
|
}
|
||||||
|
allActamt = allActamt.add(zcgjAmountRecommended);
|
||||||
|
dynamicObject.set("zcgj_amountpaid", allActamt);//实付金额
|
||||||
|
dynamicObject.set("zcgj_amount_inpayment",amountrecommended);//
|
||||||
|
|
||||||
|
//zcgj_amount_remaining = zcgj_hdamount - zcgj_amount_inpayment - zcgj_amountpaid
|
||||||
|
//剩余待拨付金额 = 财务核定金额 - 付款处理中金额 - 实付金额
|
||||||
|
BigDecimal hdamount = dynamicObject.getBigDecimal("zcgj_hdamount");
|
||||||
|
if(hdamount !=null && isSubmit){
|
||||||
|
BigDecimal subtract = hdamount.subtract(amountrecommended).subtract(allActamt);
|
||||||
|
dynamicObject.set("zcgj_amount_remaining",subtract);
|
||||||
|
}else if(hdamount != null){
|
||||||
|
BigDecimal subtract = hdamount.add(amountrecommended).subtract(allActamt);//实付金额已经成为相反数
|
||||||
|
dynamicObject.set("zcgj_amount_remaining",subtract);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
updateData.add(fundingplanapply);
|
||||||
|
}*/
|
||||||
|
}
|
||||||
|
/*if(!updateData.isEmpty()){
|
||||||
|
try (TXHandle txType = TX.requiresNew("updateAmt")) {
|
||||||
|
SaveServiceHelper.save(updateData.toArray(new DynamicObject[0]));
|
||||||
|
}
|
||||||
|
}*/
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,41 @@
|
||||||
|
package zcgj.zcdev.zcdev.pr.plugin.other;
|
||||||
|
|
||||||
|
import kd.bos.dataentity.entity.DynamicObject;
|
||||||
|
import kd.bos.dataentity.entity.DynamicObjectCollection;
|
||||||
|
import kd.bos.entity.botp.plugin.AbstractConvertPlugIn;
|
||||||
|
import kd.bos.entity.botp.plugin.args.AfterBuildDrawFilterEventArgs;
|
||||||
|
import kd.bos.orm.query.QCP;
|
||||||
|
import kd.bos.orm.query.QFilter;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 支出财务确认单上拉付款申请单botp插件
|
||||||
|
*/
|
||||||
|
public class OutFinaceconfirmBotpPlugin extends AbstractConvertPlugIn {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void afterBuildDrawFilter(AfterBuildDrawFilterEventArgs e) {
|
||||||
|
//选单过滤
|
||||||
|
super.afterBuildDrawFilter(e);
|
||||||
|
System.out.println("afterBuildDrawFilter——>");
|
||||||
|
QFilter plugFilter = e.getPlugFilter();//插件追加的选单条件
|
||||||
|
String sourceLayout = e.getSourceLayout();//获取插件设置的选单时打开的源单列表布局
|
||||||
|
DynamicObject targetDataEntity = e.getTargetDataEntity();//当前数据包
|
||||||
|
DynamicObjectCollection prepayentryCollection = targetDataEntity.getDynamicObjectCollection("zcgj_prepayentry");
|
||||||
|
List<Long> ids = new ArrayList<>();
|
||||||
|
for (DynamicObject dynamicObject : prepayentryCollection) {
|
||||||
|
long aLong = dynamicObject.getLong("zcgj_sourceapplybillid");
|
||||||
|
ids.add(aLong);
|
||||||
|
}
|
||||||
|
QFilter filter = new QFilter("id", QCP.not_in, ids);
|
||||||
|
DynamicObject contract = targetDataEntity.getDynamicObject("zcgj_contract");
|
||||||
|
if(contract != null) {
|
||||||
|
long contractId = contract.getLong("id");
|
||||||
|
filter = filter.and(new QFilter("entryentity.contract", QCP.equals, contractId));
|
||||||
|
}
|
||||||
|
filter = filter.and(new QFilter("entryentity.paymenttype", QCP.equals, "PREPAYMENT"));
|
||||||
|
e.setPlugFilter(filter);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue