|
@@ -9,6 +9,7 @@ import kd.bos.entity.plugin.args.BeginOperationTransactionArgs;
|
|
|
import kd.bos.orm.query.QCP;
|
|
|
import kd.bos.orm.query.QFilter;
|
|
|
import kd.bos.servicehelper.BusinessDataServiceHelper;
|
|
|
+import kd.bos.servicehelper.QueryServiceHelper;
|
|
|
import kd.bos.servicehelper.operation.SaveServiceHelper;
|
|
|
import java.math.BigDecimal;
|
|
|
import java.util.Arrays;
|
|
@@ -66,8 +67,12 @@ public class PublicreimburOpPlugin extends AbstractOperationServicePlugIn {
|
|
|
|
|
|
//反写预付借款单
|
|
|
DynamicObjectCollection writeoffmoneys = info.getDynamicObjectCollection("writeoffmoney");
|
|
|
- DynamicObject saveInfo = BusinessDataServiceHelper.loadSingle(info.getPkValue(), info.getDynamicObjectType().getName());
|
|
|
- if (saveInfo != null) {
|
|
|
+ Boolean exist = QueryServiceHelper.exists(info.getDynamicObjectType().getName(), info.getPkValue());
|
|
|
+ if (!exist) {
|
|
|
+ // 如果没有保存的信息,直接反写
|
|
|
+ writeBackFinarbill(writeoffmoneys);
|
|
|
+ }else {
|
|
|
+ DynamicObject saveInfo = BusinessDataServiceHelper.loadSingle(info.getPkValue(), info.getDynamicObjectType().getName());
|
|
|
DynamicObjectCollection saveWriteoffmoneys = saveInfo.getDynamicObjectCollection("writeoffmoney");
|
|
|
// 处理在 saveWriteoffmoneys 中但不在 writeoffmoneys 中的元素
|
|
|
DynamicObjectCollection toDelete = getDifference(saveWriteoffmoneys, writeoffmoneys);
|
|
@@ -79,9 +84,11 @@ public class PublicreimburOpPlugin extends AbstractOperationServicePlugIn {
|
|
|
if (toWriteBack.size() != 0) {
|
|
|
writeBackFinarbill(toWriteBack);
|
|
|
}
|
|
|
- } else {
|
|
|
- // 如果没有保存的信息,直接反写
|
|
|
- writeBackFinarbill(writeoffmoneys);
|
|
|
+ // 获取在 writeoffmoneys 和 saveWriteoffmoneys 中都有的元素并执行反写
|
|
|
+ DynamicObjectCollection commonItems = getCommonItems(writeoffmoneys, saveWriteoffmoneys);
|
|
|
+ if (commonItems.size() != 0) {
|
|
|
+ commonBackFinarbill(commonItems);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -167,6 +174,46 @@ public class PublicreimburOpPlugin extends AbstractOperationServicePlugIn {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ public void commonBackFinarbill(DynamicObjectCollection writeoffmoneys) {
|
|
|
+ //报销单冲预付借款分录
|
|
|
+ for (DynamicObject writeoffmoney : writeoffmoneys) {
|
|
|
+ //预付借款单id
|
|
|
+ String sourcebillid = writeoffmoney.getString("sourcebillid");
|
|
|
+ //预付借款单预付借款信息分录id
|
|
|
+ Long srcofsrcentryid = writeoffmoney.getLong("srcofsrcentryid");
|
|
|
+ //冲销金额
|
|
|
+ BigDecimal nckd_amountfield13 = writeoffmoney.getBigDecimal("nckd_amountfield13");
|
|
|
+ //查询应收挂账单
|
|
|
+ QFilter filter = new QFilter("sourcebillid", QCP.equals, sourcebillid);
|
|
|
+ DynamicObject[] finarbills = BusinessDataServiceHelper.load("ar_finarbill","id",new QFilter[] {filter});
|
|
|
+ for (DynamicObject finarbill : finarbills) {
|
|
|
+ DynamicObject finarbillInfo = BusinessDataServiceHelper.loadSingle(finarbill.getPkValue(), finarbill.getDynamicObjectType().getName());
|
|
|
+ //应收挂账单明细分录
|
|
|
+ DynamicObjectCollection entrys = finarbillInfo.getDynamicObjectCollection("entry");
|
|
|
+ for (DynamicObject entry : entrys) {
|
|
|
+ //预付借款单预付借款信息分录id
|
|
|
+ Long e_srcentryid = entry.getLong("e_srcentryid");
|
|
|
+ //销账金额
|
|
|
+ BigDecimal nckd_e_settledamt = entry.getBigDecimal("nckd_e_settledamt");
|
|
|
+ //已结算金额
|
|
|
+ BigDecimal e_settledamt = entry.getBigDecimal("e_settledamt");
|
|
|
+ //未结算金额
|
|
|
+ BigDecimal e_unsettleamt = entry.getBigDecimal("e_unsettleamt");
|
|
|
+ //已结算金额(本位币)
|
|
|
+ BigDecimal e_settledlocalamt = entry.getBigDecimal("e_settledlocalamt");
|
|
|
+ //未结算金额(本位币)
|
|
|
+ BigDecimal e_unsettlelocalamt = entry.getBigDecimal("e_unsettlelocalamt");
|
|
|
+ if (e_srcentryid != 0 && e_srcentryid.equals(srcofsrcentryid)) {
|
|
|
+ entry.set("nckd_e_settledamt", nckd_e_settledamt.add(nckd_amountfield13));
|
|
|
+ entry.set("e_settledamt", e_settledamt.add(nckd_amountfield13));
|
|
|
+ entry.set("e_unsettleamt", e_unsettleamt.subtract(nckd_amountfield13));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ SaveServiceHelper.save(new DynamicObject[]{finarbillInfo});
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
// 获取在 source 中但不在 target 中的元素集合
|
|
|
private DynamicObjectCollection getDifference(DynamicObjectCollection source, DynamicObjectCollection target) {
|
|
|
DynamicObjectCollection difference = new DynamicObjectCollection();
|
|
@@ -185,4 +232,25 @@ public class PublicreimburOpPlugin extends AbstractOperationServicePlugIn {
|
|
|
}
|
|
|
return difference;
|
|
|
}
|
|
|
+
|
|
|
+ // 获取在 source 和 target 中都有的元素集合
|
|
|
+ private DynamicObjectCollection getCommonItems(DynamicObjectCollection source, DynamicObjectCollection target) {
|
|
|
+ DynamicObjectCollection commonItems = new DynamicObjectCollection();
|
|
|
+ for (DynamicObject sourceItem : source) {
|
|
|
+ for (DynamicObject targetItem : target) {
|
|
|
+ // 根据某个唯一标识符判断是否存在
|
|
|
+ if (sourceItem.getPkValue().equals(targetItem.getPkValue())) {
|
|
|
+ BigDecimal sourceAmount = sourceItem.getBigDecimal("accloanamount");
|
|
|
+ BigDecimal targetAmount = targetItem.getBigDecimal("accloanamount");
|
|
|
+ BigDecimal nckd_amountfield13 = sourceAmount.subtract(targetAmount);
|
|
|
+ if (nckd_amountfield13.compareTo(BigDecimal.ZERO) != 0) {
|
|
|
+ sourceItem.set("nckd_amountfield13", nckd_amountfield13);
|
|
|
+ commonItems.add(sourceItem);
|
|
|
+ break; // 找到共同项后跳出内层循环
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return commonItems;
|
|
|
+ }
|
|
|
}
|