|
@@ -0,0 +1,73 @@
|
|
|
+package fi.em.formPlugin;
|
|
|
+
|
|
|
+import kd.bos.dataentity.entity.DynamicObject;
|
|
|
+import kd.bos.dataentity.entity.DynamicObjectCollection;
|
|
|
+import kd.bos.form.events.AfterDoOperationEventArgs;
|
|
|
+import kd.bos.form.events.BeforeDoOperationEventArgs;
|
|
|
+import kd.bos.form.operate.AbstractOperate;
|
|
|
+import kd.bos.form.plugin.AbstractFormPlugin;
|
|
|
+
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.Iterator;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @author cjz
|
|
|
+ * @date 2024/11/7 15:45
|
|
|
+ * @description:差旅汇总分录计算
|
|
|
+ */
|
|
|
+public class TravelTotalPlugin extends AbstractFormPlugin {
|
|
|
+
|
|
|
+ private static String bar_save="save";//保存标识
|
|
|
+ private static String entryentity="nckd_entryentity";//差旅汇总标识
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void beforeDoOperation(BeforeDoOperationEventArgs args) {
|
|
|
+ super.beforeDoOperation(args);
|
|
|
+ AbstractOperate op = (AbstractOperate)args.getSource();
|
|
|
+ String operateKey = op.getOperateKey();
|
|
|
+ //获取当前单据
|
|
|
+ DynamicObject dynamicObject=this.getModel().getDataEntity(true);
|
|
|
+ //差旅汇总分录
|
|
|
+ DynamicObjectCollection nckd_entryentity=dynamicObject.getDynamicObjectCollection(entryentity);
|
|
|
+ //汇总map
|
|
|
+ Map<DynamicObject,BigDecimal> allMap=new HashMap<>();
|
|
|
+ if (bar_save.equals(operateKey)) {
|
|
|
+ //获取行程信息
|
|
|
+ DynamicObjectCollection dynamicObjectCollection=dynamicObject.getDynamicObjectCollection("tripentry");
|
|
|
+ //子卡片分录信息
|
|
|
+ for (DynamicObject item:dynamicObjectCollection) {
|
|
|
+ for (DynamicObject entry:item.getDynamicObjectCollection("entryentity")) {
|
|
|
+ //差旅项目获取
|
|
|
+ DynamicObject expenseitem=entry.getDynamicObject("expenseitem");
|
|
|
+ //报销金额获取
|
|
|
+ BigDecimal orientryamount=entry.getBigDecimal("orientryamount");
|
|
|
+ //差旅项目不存在则加进map
|
|
|
+ if (!allMap.containsKey(expenseitem)) {
|
|
|
+ allMap.put(expenseitem,orientryamount);
|
|
|
+ }else {
|
|
|
+ //存在则对该项目进行累加
|
|
|
+ BigDecimal account = allMap.get(expenseitem);
|
|
|
+ account=account.add(orientryamount);
|
|
|
+ allMap.put(expenseitem,account);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ Iterator<Map.Entry<DynamicObject, BigDecimal>> iter = allMap.entrySet().iterator();
|
|
|
+ //清空分录
|
|
|
+ this.getModel().deleteEntryData(entryentity);
|
|
|
+ //遍历汇总map
|
|
|
+ while (iter.hasNext()) {
|
|
|
+ Map.Entry<DynamicObject, BigDecimal> entry = iter.next();
|
|
|
+ //新增动态单据分录行
|
|
|
+ int rowIndex = this.getModel().createNewEntryRow(entryentity);
|
|
|
+ this.getModel().setValue("nckd_travelitem",entry.getKey(),rowIndex);
|
|
|
+ this.getModel().setValue("nckd_oriamount",entry.getValue(),rowIndex);
|
|
|
+ this.getModel().setValue("nckd_triamount",entry.getValue(),rowIndex);
|
|
|
+ }
|
|
|
+ //刷新分录
|
|
|
+ this.getView().updateView("nckd_entryentity");
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|