feat:信保回填,合同回款金额校验

This commit is contained in:
zzs 2024-12-18 16:19:28 +08:00
parent d255d994a6
commit 1f2b2b9799

View File

@ -1,9 +1,13 @@
package com.yem.wm.es.storagetrans.dynamic;
import com.yem.rf.utils.RFUtils;
import com.yem.wm.es.Util.CreditBackFillUtils;
import com.yem.wm.es.Util.TotalUtil;
import com.yem.wm.es.shippingdetails.util.PaymentControlUtil;
import com.yem.wm.utils.CalendarUtils;
import com.yem.wm.utils.RptUtil;
import com.yem.wm.utils.YEM;
import kd.bos.algo.DataSet;
import kd.bos.dataentity.entity.DynamicObject;
import kd.bos.dataentity.entity.DynamicObjectCollection;
import kd.bos.entity.datamodel.IDataModel;
@ -13,17 +17,17 @@ import kd.bos.form.IFormView;
import kd.bos.form.control.Control;
import kd.bos.form.events.AfterDoOperationEventArgs;
import kd.bos.form.plugin.AbstractFormPlugin;
import kd.bos.orm.ORM;
import kd.bos.orm.query.QCP;
import kd.bos.orm.query.QFilter;
import kd.bos.servicehelper.BusinessDataServiceHelper;
import kd.bos.servicehelper.operation.SaveServiceHelper;
import kd.tmc.cfm.formplugin.bd.PayMentbyInstalments;
import org.apache.commons.compress.utils.Lists;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.Date;
import java.util.EventObject;
import java.util.HashMap;
import java.util.Map;
import java.util.*;
/**
* @author xwudd
@ -45,6 +49,7 @@ public class CreditBackFillEdit extends AbstractFormPlugin {
model.setValue("yem_storagetransno", parentModel.getValue("billno"));//储运托单号
model.setValue("yem_currency", parentModel.getValue("yem_creditcurr"));//信保币别
model.setValue("yem_settlementcurr", parentModel.getValue("yem_currency"));//结算币别
model.setValue("yem_currencybase", parentModel.getValue("yem_currencybase"));//本位币
model.setValue("yem_actulpreamount", parentModel.getValue("yem_actualsinkamount"));//实际收汇金额汇总
model.setValue("yem_actulpreamountbase", parentModel.getValue("yem_actualsinkamountba"));//实际收汇本位币金额汇总
@ -115,6 +120,10 @@ public class CreditBackFillEdit extends AbstractFormPlugin {
String key = control.getKey();
if ("btnok".equals(key)) {
if (!beforeOkOperationValidator()) {
return;
}
IFormView view = this.getView();
IDataModel model = this.getModel();
DynamicObject dataEntity = model.getDataEntity(true);
@ -172,6 +181,96 @@ public class CreditBackFillEdit extends AbstractFormPlugin {
}
}
private boolean beforeOkOperationValidator() {
IDataModel model = this.getModel();
IFormView view = this.getView();
IFormView parentView = view.getParentView();
IDataModel parentModel = parentView.getModel();
DynamicObject dataEntity = model.getDataEntity(true);
StringBuilder sb = new StringBuilder();
DynamicObjectCollection collection = dataEntity.getDynamicObjectCollection("yem_creditentry");
// 当前订舱合同回款金额
Map<String, BigDecimal> contractPayAmtMap = new HashMap<>();
for (DynamicObject d : collection) {
int idx = collection.indexOf(d);
BigDecimal contractpayamt = d.getBigDecimal("yem_contractpayamt");
String salecontractno = d.getString("yem_salecontractno");
if (contractPayAmtMap.containsKey(salecontractno)) {
BigDecimal decimal = contractPayAmtMap.get(salecontractno);
decimal = decimal.add(contractpayamt);
contractPayAmtMap.put(salecontractno, decimal);
} else {
contractPayAmtMap.put(salecontractno, contractpayamt);
}
if (contractpayamt.compareTo(BigDecimal.ZERO) <= 0) {
sb.append(String.format("请填写明细信息第 %s 行,合同回款金额!!", idx + 1)).append("\n\r");
}
}
if (sb.length() > 0) {
view.showErrorNotification(sb.toString());
return false;
}
QFilter qFilter = RFUtils.getBaseQFilter();
// 当前单涉及需要校验的合同
Set<String> salesorder = new HashSet<>();
for (DynamicObject d : collection) {
salesorder.add(d.getString("yem_salecontractno"));
}
qFilter.and("yem_creditdetail.yem_salecontractno.billno", "in", salesorder);
qFilter.and("billno", "not in", parentModel.getValue("billno"));
ArrayList<String> selectfileds = Lists.newArrayList();
selectfileds.add("yem_creditdetail.yem_salecontractno.billno yem_salecontractno");//外销合同号
selectfileds.add("yem_creditdetail.yem_contractpayamt yem_contractpayamt");//合同回款金额
DataSet st = ORM.create().queryDataSet("com.yem.wm.es.storagetrans.dynamic.CreditBackFillEdit.beforeOkOperationValidator", "yem_es_storagetrans", String.join(",", selectfileds), qFilter.toArray());
st = st.groupBy(new String[]{"yem_salecontractno"}).sum("yem_contractpayamt").finish();
DynamicObjectCollection dataSetCollection = ORM.create().toPlainDynamicObjectCollection(st);
// 历史除去本单订舱合同回款金额 + 当前订舱合同回款金额
for (DynamicObject setObj : dataSetCollection) {
String salecontractno = setObj.getString("yem_salecontractno");
BigDecimal contractpayamt = setObj.getBigDecimal("yem_contractpayamt");
if (contractPayAmtMap.containsKey(salecontractno)) {
BigDecimal decimal = contractPayAmtMap.get(salecontractno);
decimal = decimal.add(contractpayamt);
contractPayAmtMap.put(salecontractno, decimal);
} else {
contractPayAmtMap.put(salecontractno, contractpayamt);
}
}
StringBuilder amtSb = new StringBuilder();
DynamicObject[] load = BusinessDataServiceHelper.load("yem_es_salesorder", "id, billno", new QFilter[]{new QFilter("billno", "in", salesorder)});
for (DynamicObject object : load) {
for (Map.Entry<String, BigDecimal> map : contractPayAmtMap.entrySet()) {
BigDecimal amt = map.getValue();
String billno = map.getKey();
if (object.getString("billno").equals(billno)) {
BigDecimal contractClimeAmt = PaymentControlUtil.getContractClimeAmt(object, "F");
if (amt.compareTo(contractClimeAmt) > 0) {
amtSb.append(String.format("合同号:%s合同回款总金额%s元尾款账期认领总金额%s元已超额请认领完成后在操作信保回款。"
, billno
, amt.setScale(4, RoundingMode.HALF_UP).toPlainString()
, contractClimeAmt.setScale(4, RoundingMode.HALF_UP).toPlainString()
)).append("\n\r");
}
}
}
}
if (amtSb.length() > 0) {
view.showErrorNotification(amtSb.toString());
return false;
}
return true;
}
/**
* 缓存分录数据
*
@ -501,6 +600,21 @@ public class CreditBackFillEdit extends AbstractFormPlugin {
this.getModel().setValue("yem_creactuallocamt", creactualamt.multiply(crerate), row);
// this.getView().updateView();
}
// 汇总子分录合同回款金额到分录
if ("yem_contractpayamt_e".equals(key)) {
DynamicObjectCollection collection = dataEntity.getDynamicObjectCollection("yem_creditentry");
for (DynamicObject entry : collection) {
int idx = collection.indexOf(entry);
DynamicObjectCollection subEntry = entry.getDynamicObjectCollection("yem_crecollection");
BigDecimal calc = BigDecimal.ZERO;
for (DynamicObject subObj : subEntry) {
BigDecimal contractpayamt_e = subObj.getBigDecimal("yem_contractpayamt_e");
calc = calc.add(contractpayamt_e);
}
model.setValue("yem_contractpayamt", calc, idx);
}
}
}
private void carryCreditInsuranceRate(int rowIndex) {