|
@@ -0,0 +1,166 @@
|
|
|
+package fi.em.formPlugin;
|
|
|
+import kd.bos.exception.KDBizException;
|
|
|
+import kd.bos.form.plugin.AbstractFormPlugin;
|
|
|
+import kd.sdk.plugin.Plugin;
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import kd.bos.dataentity.entity.DynamicObject;
|
|
|
+import kd.bos.dataentity.serialization.SerializationUtils;
|
|
|
+import kd.bos.form.control.Control;
|
|
|
+import kd.bos.form.control.EntryGrid;
|
|
|
+import kd.bos.orm.query.QCP;
|
|
|
+import kd.bos.orm.query.QFilter;
|
|
|
+import kd.bos.servicehelper.BusinessDataServiceHelper;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.util.*;
|
|
|
+
|
|
|
+
|
|
|
+/**
|
|
|
+ * @author cjz
|
|
|
+ * @date 2024/7/25 15:13
|
|
|
+ * @description:报销单初始化表单
|
|
|
+ */
|
|
|
+
|
|
|
+public class ReimbursementFormPlugin extends AbstractFormPlugin implements Plugin {
|
|
|
+ private final static String KEY_OK = "btnok";//确定按钮标识
|
|
|
+ private final static String KEY_CANCEL = "btncancel";//页面取消按钮标识
|
|
|
+ private final static String KEY_SEARCH = "search";//动态表单查询按钮操作
|
|
|
+ private final static String FORMID_ENTRY = "nckd_entryentity";//动态表单单据体标识
|
|
|
+ private static String er_prepaybill = "er_prepaybill";//预付单标识
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 页面点击事件
|
|
|
+ *
|
|
|
+ * @param evt
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public void click(EventObject evt) {
|
|
|
+ super.click(evt);
|
|
|
+ //获取被点击的控件对象
|
|
|
+ Control source = (Control) evt.getSource();
|
|
|
+ String pageId = this.getView().getPageId();
|
|
|
+ //点击确定后
|
|
|
+ if (StringUtils.equals(source.getKey(), KEY_OK)) {
|
|
|
+ String listStr = this.getPageCache().get(pageId);
|
|
|
+ if (StringUtils.isNotBlank(listStr)) {
|
|
|
+ JSONArray reJa = new JSONArray();
|
|
|
+ //获取单据控件模型
|
|
|
+ EntryGrid entryGrid = this.getView().getControl(FORMID_ENTRY);
|
|
|
+ //获取选择的行号
|
|
|
+ int[] selectRows = entryGrid.getSelectRows();
|
|
|
+
|
|
|
+ //判断数据是否存在
|
|
|
+ if (selectRows.length <= 0) {
|
|
|
+ this.getView().showMessage("请先选择一条数据!");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ JSONArray infoJa = SerializationUtils.fromJsonString(listStr, JSONArray.class);
|
|
|
+ for (int i = 0; i < selectRows.length; i++) {
|
|
|
+ JSONObject reJo = infoJa.getJSONObject(selectRows[i]);
|
|
|
+ reJa.add(reJo);
|
|
|
+ }
|
|
|
+ HashMap<String, String> map = new HashMap<>();
|
|
|
+ map.put("reJaStr", reJa.toJSONString());
|
|
|
+
|
|
|
+ //将获取的json数据返回到界面view中
|
|
|
+ this.getView().returnDataToParent(map);
|
|
|
+ }
|
|
|
+ this.getView().close();
|
|
|
+ } else if (StringUtils.equals(source.getKey(), KEY_CANCEL)) {
|
|
|
+ //被点击控件为取消则设置返回值为空并关闭页面(在页面关闭回调方法中必须验证返回值不为空,否则会报空指针)
|
|
|
+ this.getView().returnDataToParent(null);
|
|
|
+ this.getView().close();
|
|
|
+ } else {
|
|
|
+ this.getView().returnDataToParent(null);
|
|
|
+ this.getView().close();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //监听接口
|
|
|
+ @Override
|
|
|
+ public void registerListener(EventObject e) {
|
|
|
+ super.registerListener(e);
|
|
|
+ //页面确认按钮和取消按钮添加监听
|
|
|
+ this.addClickListeners(KEY_OK, KEY_CANCEL);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void afterCreateNewData(EventObject e) {
|
|
|
+ super.afterBindData(e);
|
|
|
+ //DynamicObject period = (DynamicObject) this.getModel().getValue("nckd_basedatafield");
|
|
|
+ //获取父页面传入数据
|
|
|
+ Map<String, Object> customParams = this.getView().getFormShowParameter().getCustomParams();
|
|
|
+ String orgnumber = (String) customParams.get("orgnumber");
|
|
|
+ String orgid = (String) customParams.get("orgid");
|
|
|
+ if (orgnumber == null) {
|
|
|
+ throw new KDBizException("付费承担公司为空!");
|
|
|
+ }
|
|
|
+ List<JSONObject> resdate = new ArrayList<>();
|
|
|
+ //历史数据清除
|
|
|
+ this.getModel().deleteEntryData(FORMID_ENTRY);
|
|
|
+ //构建查费用分摊动因参数基础资料参数
|
|
|
+ QFilter nckd_orgamountFilter = new QFilter("costcompany.number", QCP.equals, orgnumber);
|
|
|
+ //单据状态
|
|
|
+ nckd_orgamountFilter.and("billstatus", QCP.equals, "E");
|
|
|
+ DynamicObject[] nckd_orgamountaccount = BusinessDataServiceHelper.
|
|
|
+ load(er_prepaybill, "id,number", new QFilter[]{nckd_orgamountFilter});
|
|
|
+
|
|
|
+ for (int c=0;c<nckd_orgamountaccount.length;c++){
|
|
|
+ //当前循环动因基础资料单头
|
|
|
+ DynamicObject dynamicObject = BusinessDataServiceHelper.loadSingle(nckd_orgamountaccount[c].getPkValue(), nckd_orgamountaccount[c].getDynamicObjectType().getName());
|
|
|
+
|
|
|
+ String billno= dynamicObject.getString("billno");
|
|
|
+ //循环分录
|
|
|
+ for (DynamicObject entryentity : dynamicObject.getDynamicObjectCollection("expenseentryentity")) {
|
|
|
+
|
|
|
+ //获取费用承担部门
|
|
|
+ DynamicObject entrycostdept = entryentity.getDynamicObject("entrycostdept");
|
|
|
+
|
|
|
+ //获取费用项目
|
|
|
+ DynamicObject expenseitem=entryentity.getDynamicObject("expenseitem");
|
|
|
+
|
|
|
+ //申请金额
|
|
|
+ BigDecimal expenseamount=entryentity.getBigDecimal("expenseamount");
|
|
|
+
|
|
|
+ //结算金额
|
|
|
+ BigDecimal exporiusedamount=entryentity.getBigDecimal("exporiusedamount");
|
|
|
+
|
|
|
+ //未结算金额
|
|
|
+ BigDecimal orgiexpebalanceamount=entryentity.getBigDecimal("orgiexpebalanceamount");
|
|
|
+
|
|
|
+ //备注
|
|
|
+ String remark=entryentity.getString("remark");
|
|
|
+
|
|
|
+ //新增动态单据分录
|
|
|
+ int rowIndex = this.getModel().createNewEntryRow(FORMID_ENTRY);
|
|
|
+ //赋值给新增分录
|
|
|
+ this.getModel().setValue("nckd_billno",billno,rowIndex);
|
|
|
+ this.getModel().setValue("nckd_entrycostdept",entrycostdept,rowIndex);
|
|
|
+ this.getModel().setValue("nckd_expenseitem",expenseitem,rowIndex);
|
|
|
+ this.getModel().setValue("nckd_expenseamount",expenseamount,rowIndex);
|
|
|
+ this.getModel().setValue("nckd_exporiusedamount",exporiusedamount,rowIndex);
|
|
|
+ this.getModel().setValue("nckd_unexporiusedamount",orgiexpebalanceamount,rowIndex);
|
|
|
+ this.getModel().setValue("nckd_remarke",remark,rowIndex);
|
|
|
+ //将选中的数据放到缓存中
|
|
|
+ JSONObject obj = new JSONObject();
|
|
|
+ //放入缓存
|
|
|
+ obj.put("nckd_billno",billno);
|
|
|
+ obj.put("nckd_entrycostdept",entrycostdept.getString("number"));
|
|
|
+ obj.put("nckd_expenseitem",expenseitem.getString("number"));
|
|
|
+ obj.put("nckd_expenseamount",expenseamount);
|
|
|
+ obj.put("nckd_exporiusedamount",exporiusedamount);
|
|
|
+ obj.put("nckd_unexporiusedamount",orgiexpebalanceamount);
|
|
|
+ obj.put("nckd_remark",remark);
|
|
|
+ resdate.add(obj);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ String pageId = this.getView().getPageId();
|
|
|
+ String listStr = SerializationUtils.toJsonString(resdate);
|
|
|
+ this.getPageCache().put(pageId, listStr);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+}
|