package fi.em.formPlugin; import com.alibaba.druid.util.StringUtils; import kd.bos.bill.AbstractBillPlugIn; import kd.bos.dataentity.entity.DynamicObject; import kd.bos.entity.datamodel.ListSelectedRow; import kd.bos.entity.datamodel.ListSelectedRowCollection; import kd.bos.entity.datamodel.events.ChangeData; import kd.bos.entity.datamodel.events.PropertyChangedArgs; import kd.bos.exception.KDBizException; import kd.bos.form.*; import kd.bos.form.control.Control; import kd.bos.form.events.AfterDoOperationEventArgs; import kd.bos.form.events.ClosedCallBackEvent; import kd.bos.form.field.TextEdit; import kd.bos.list.ListShowParameter; import kd.bos.list.plugin.AbstractListPlugin; import kd.bos.orm.query.QCP; import kd.bos.orm.query.QFilter; import kd.bos.servicehelper.BusinessDataServiceHelper; import kd.sdk.plugin.Plugin; import java.math.BigDecimal; import java.util.EventObject; import java.util.Map; public class BxdBankListtenerFromPlugin extends AbstractListPlugin implements Plugin { @Override public void registerListener(EventObject e) { super.registerListener(e); // 对字段(文本控件)添加点击监听 TextEdit textEdit = getControl("nckd_gysbanks"); textEdit.addClickListener(this); } @Override public void click(EventObject evt) { Control control = (Control) evt.getSource(); String key = control.getKey(); // 点击供应商11111 if (StringUtils.equalsIgnoreCase("nckd_gysbanks", key)) { String billpayertype = this.getModel().getValue("billpayertype").toString(); if("bd_supplier".equals(billpayertype)){ ListShowParameter parameter = ShowFormHelper.createShowListForm("nckd_supplierbankinfor", false); parameter.setCloseCallBack(new CloseCallBack(this, "nckd_supplierbankinfor")); DynamicObject skdata = (DynamicObject)this.getModel().getValue("billpayerid"); if(skdata ==null){ throw new KDBizException("往来单位为空!"); } long orgid = skdata.getLong("id"); QFilter nckd_skzjFilter = new QFilter("id", QCP.equals,orgid); DynamicObject dynamicObject = BusinessDataServiceHelper.loadSingle("bd_supplier", "id", new QFilter[]{nckd_skzjFilter}); QFilter filter; //给基础资料添加过滤 filter = new QFilter("nckd_id", QCP.equals, dynamicObject.getLong("id")); parameter.getListFilterParameter().setFilter(filter); getView().showForm(parameter); } else if ("bos_user".equals(billpayertype)) { ListShowParameter parameter = ShowFormHelper.createShowListForm("er_payeer", false); parameter.setCloseCallBack(new CloseCallBack(this, "er_payeer")); DynamicObject skdata = (DynamicObject)this.getModel().getValue("billpayerid"); if(skdata ==null){ throw new KDBizException("往来单位为空!"); } long orgid = skdata.getLong("id"); QFilter nckd_skzjFilter = new QFilter("id", QCP.equals,orgid); DynamicObject dynamicObject = BusinessDataServiceHelper.loadSingle("bos_user", "id", new QFilter[]{nckd_skzjFilter}); QFilter filter; //给基础资料添加过滤 filter = new QFilter("payer.id", QCP.equals, dynamicObject.getLong("id")); parameter.getListFilterParameter().setFilter(filter); getView().showForm(parameter); } else if ("bos_org".equals(billpayertype)) { ListShowParameter parameter = ShowFormHelper.createShowListForm("bos_org", false); parameter.setCloseCallBack(new CloseCallBack(this, "bos_org")); DynamicObject skdata = (DynamicObject)this.getModel().getValue("billpayerid"); if(skdata ==null){ throw new KDBizException("往来单位为空!"); } long orgid = skdata.getLong("id"); QFilter nckd_skzjFilter = new QFilter("id", QCP.equals,orgid); DynamicObject dynamicObject = BusinessDataServiceHelper.loadSingle("bos_org", "id", new QFilter[]{nckd_skzjFilter}); QFilter filter; //给基础资料添加过滤 filter = new QFilter("id", QCP.equals, dynamicObject.getLong("id")); parameter.getListFilterParameter().setFilter(filter); getView().showForm(parameter); } } super.click(evt); } @Override public void closedCallBack(ClosedCallBackEvent evt) { String key = evt.getActionId(); Object returnData = evt.getReturnData(); // 将选择的采购申请单数据回写至样例单据上的相应字段 if (StringUtils.equalsIgnoreCase("nckd_supplierbankinfor", key) && returnData != null) { ListSelectedRow row = ((ListSelectedRowCollection) returnData).get(0); DynamicObject billObj = BusinessDataServiceHelper.loadSingle(row.getPrimaryKeyValue(), "nckd_supplierbankinfor"); this.getModel().setValue("nckd_gysbanks", billObj.getString("nckd_bankaccount")); this.getModel().setValue("nckd_bankname", billObj.getString("nckd_accountname")); DynamicObject nckdBank = billObj.getDynamicObject("nckd_bank"); this.getModel().setValue("nckd_khbank",nckdBank); //设置分录 this.getModel().setValue("supplier", billObj, 0); this.getModel().setValue("payeraccount", billObj.getString("nckd_bankaccount"), 0); this.getModel().setValue("payeraccountname", billObj.getString("nckd_accountname"), 0); this.getModel().setValue("payerbank", nckdBank, 0); Object nckdPaymentmethod = this.getModel().getValue("nckd_paymentmethod"); DynamicObject nckd_paymentmethod = (DynamicObject) nckdPaymentmethod; this.getModel().setValue("paymode", nckd_paymentmethod, 0); //刷新分录 this.getView().updateView("accountentry"); } else if (StringUtils.equalsIgnoreCase("er_payeer", key) && returnData != null) { ListSelectedRow row = ((ListSelectedRowCollection) returnData).get(0); DynamicObject billObj = BusinessDataServiceHelper.loadSingle(row.getPrimaryKeyValue(), "er_payeer"); DynamicObject payerbank = billObj.getDynamicObject("payerbank"); this.getModel().setValue("nckd_gysbanks", payerbank.getString("number"));//行号 this.getModel().setValue("nckd_bankname", payerbank.getString("name"));//行名 this.getModel().setValue("nckd_khbank", payerbank); //设置分录 this.getModel().setValue("payer", payerbank, 0); this.getModel().setValue("payeraccount", payerbank.getString("number"), 0); this.getModel().setValue("payeraccountname", payerbank.getString("name"), 0); this.getModel().setValue("payerbank", payerbank, 0); Object nckdPaymentmethod = this.getModel().getValue("nckd_paymentmethod"); DynamicObject nckd_paymentmethod = (DynamicObject) nckdPaymentmethod; this.getModel().setValue("paymode", nckd_paymentmethod, 0); //刷新分录 this.getView().updateView("accountentry"); } else if (StringUtils.equalsIgnoreCase("bos_org", key) && returnData != null) { ListSelectedRow row = ((ListSelectedRowCollection) returnData).get(0); DynamicObject billObj = BusinessDataServiceHelper.loadSingle(row.getPrimaryKeyValue(), "bos_org"); this.getModel().setValue("nckd_gysbanks", billObj.getString("bankaccount")); this.getModel().setValue("nckd_bankname", billObj.getString("ffirmname")); //this.getModel().setValue("nckd_khbank", billObj.getString("depositbank")); //设置分录 this.getModel().setValue("payername", billObj.getString("name"), 0); this.getModel().setValue("payeraccount", billObj.getString("bankaccount"), 0); this.getModel().setValue("payeraccountname", billObj.getString("ffirmname"), 0); Object nckdPaymentmethod = this.getModel().getValue("nckd_paymentmethod"); DynamicObject nckd_paymentmethod = (DynamicObject) nckdPaymentmethod; this.getModel().setValue("paymode", nckd_paymentmethod, 0); //刷新分录 this.getView().updateView("accountentry"); } super.closedCallBack(evt); } @Override public void propertyChanged(PropertyChangedArgs e) { super.beforePropertyChanged(e); String name = e.getProperty().getName();//获取字段标识 if ("billpayerid".equals(name)) { ChangeData[] changeSet = e.getChangeSet();//获取值 for (ChangeData changeData : changeSet) { int rowIndex = changeData.getRowIndex(); Object newValue = changeData.getNewValue(); Object oldValue = changeData.getOldValue(); DynamicObject payeenamevs = (DynamicObject) newValue; String billpayertype = this.getModel().getValue("billpayertype").toString(); if("bd_supplier".equals(billpayertype)){ this.getModel().setValue("nckd_gysbanks",null);//行号 this.getModel().setValue("nckd_bankname",null);//行名 this.getModel().setValue("nckd_khbank",null); this.getModel().setValue("payer",null, 0); this.getModel().setValue("payeraccount",null, 0); this.getModel().setValue("payeraccountname",null, 0); this.getModel().setValue("payerbank",null, 0); //刷新分录 this.getView().updateView("accountentry"); this.getView().updateView("nckd_gysbanks"); this.getView().updateView("nckd_bankname"); this.getView().updateView("nckd_khbank"); QFilter nckd = new QFilter("id", QCP.equals,payeenamevs.getLong("id")); payeenamevs = BusinessDataServiceHelper.loadSingle("bd_supplier", new QFilter[]{nckd}); if(payeenamevs!=null){ for (DynamicObject entryentity : payeenamevs.getDynamicObjectCollection("entry_bank")) { String bankaccount = entryentity.getString("bankaccount"); String accountname = entryentity.getString("accountname"); String isdefaultBank = entryentity.getString("isdefault_bank"); DynamicObject bank = entryentity.getDynamicObject("bank"); if("true".equals(isdefaultBank)){ this.getModel().setValue("nckd_gysbanks", bankaccount); this.getModel().setValue("nckd_bankname", accountname); // DynamicObject nckdBank = billObj.getDynamicObject("nckd_bank"); this.getModel().setValue("nckd_khbank",bank); //设置分录 this.getModel().setValue("supplier", payeenamevs, 0); this.getModel().setValue("payeraccount", bankaccount, 0); this.getModel().setValue("payeraccountname", accountname, 0); this.getModel().setValue("payerbank", bank, 0); Object nckdPaymentmethod = this.getModel().getValue("nckd_paymentmethod"); DynamicObject nckd_paymentmethod = (DynamicObject) nckdPaymentmethod; this.getModel().setValue("paymode", nckd_paymentmethod, 0); //刷新分录 this.getView().updateView("accountentry"); } } } } else if ("bos_user".equals(billpayertype)) { this.getModel().setValue("nckd_gysbanks",null);//行号 this.getModel().setValue("nckd_bankname",null);//行名 this.getModel().setValue("nckd_khbank",null); this.getModel().setValue("payer",null, 0); this.getModel().setValue("payeraccount",null, 0); this.getModel().setValue("payeraccountname",null, 0); this.getModel().setValue("payerbank",null, 0); //刷新分录 this.getView().updateView("accountentry"); this.getView().updateView("nckd_gysbanks"); this.getView().updateView("nckd_bankname"); this.getView().updateView("nckd_khbank"); QFilter nckd = new QFilter("id", QCP.equals,payeenamevs.getLong("id")); payeenamevs = BusinessDataServiceHelper.loadSingle("bos_user", new QFilter[]{nckd}); if(payeenamevs!=null){ QFilter nckd_skzjFilter = new QFilter("payer.id", QCP.equals,payeenamevs.getLong("id")); nckd_skzjFilter.and("isdefault", QCP.equals, "1"); DynamicObject dynamicObject = BusinessDataServiceHelper.loadSingle("er_payeer", new QFilter[]{nckd_skzjFilter}); if(dynamicObject!=null){ DynamicObject payerbank = dynamicObject.getDynamicObject("payerbank"); this.getModel().setValue("nckd_gysbanks", payerbank.getString("number"));//行号 this.getModel().setValue("nckd_bankname", payerbank.getString("name"));//行名 this.getModel().setValue("nckd_khbank", payerbank); //设置分录 this.getModel().setValue("payer", dynamicObject, 0); this.getModel().setValue("payeraccount", payerbank.getString("number"), 0); this.getModel().setValue("payeraccountname", payerbank.getString("name"), 0); this.getModel().setValue("payerbank", payerbank, 0); Object nckdPaymentmethod = this.getModel().getValue("nckd_paymentmethod"); DynamicObject nckd_paymentmethod = (DynamicObject) nckdPaymentmethod; this.getModel().setValue("paymode", nckd_paymentmethod, 0); //刷新分录 this.getView().updateView("accountentry"); } } } else if ("bos_org".equals(billpayertype)) { this.getModel().setValue("nckd_gysbanks",null);//行号 this.getModel().setValue("nckd_bankname",null);//行名 this.getModel().setValue("nckd_khbank",null); this.getModel().setValue("payer",null, 0); this.getModel().setValue("payeraccount",null, 0); this.getModel().setValue("payeraccountname",null, 0); this.getModel().setValue("payerbank",null, 0); //刷新分录 this.getView().updateView("accountentry"); this.getView().updateView("nckd_gysbanks"); this.getView().updateView("nckd_bankname"); this.getView().updateView("nckd_khbank"); QFilter nckd = new QFilter("id", QCP.equals,payeenamevs.getLong("id")); payeenamevs = BusinessDataServiceHelper.loadSingle("bos_org", new QFilter[]{nckd}); if(payeenamevs!=null){ this.getModel().setValue("nckd_gysbanks", payeenamevs.getString("bankaccount")); this.getModel().setValue("nckd_bankname", payeenamevs.getString("ffirmname")); //this.getModel().setValue("nckd_khbank", payeenamevs.getString("depositbank")); //设置分录 this.getModel().setValue("payername", payeenamevs.getString("name"), 0); this.getModel().setValue("payeraccount", payeenamevs.getString("bankaccount"), 0); this.getModel().setValue("payeraccountname", payeenamevs.getString("ffirmname"), 0); this.getModel().setValue("casorg", payeenamevs, 0); Object nckdPaymentmethod = this.getModel().getValue("nckd_paymentmethod"); DynamicObject nckd_paymentmethod = (DynamicObject) nckdPaymentmethod; this.getModel().setValue("paymode", nckd_paymentmethod, 0); //刷新分录 this.getView().updateView("accountentry"); } } } } else if ("nckd_onaccountamount".equals(name)) { String nckd_reimburseamount = this.getModel().getValue("nckd_reimburseamount").toString();//报销金额 String nckd_onaccountamount = this.getModel().getValue("nckd_onaccountamount").toString();//挂账金额 String nckd_yufuamount = this.getModel().getValue("nckd_yufuamount").toString();//预付金额 BigDecimal reimburseamount = new BigDecimal(nckd_reimburseamount); BigDecimal onaccountamount = new BigDecimal(nckd_onaccountamount); BigDecimal yufuamount = new BigDecimal(nckd_yufuamount); reimburseamount=reimburseamount.subtract(onaccountamount); reimburseamount=reimburseamount.subtract(yufuamount); this.getModel().setValue("nckd_fukuanamountfield", reimburseamount); this.getModel().setValue("nckd_orireceiveamount", reimburseamount, 0); //刷新分录 this.getView().updateView("expenseentryentity"); }else if ("nckd_yufuamount".equals(name)) { String nckd_reimburseamount = this.getModel().getValue("nckd_reimburseamount").toString();//报销金额 String nckd_onaccountamount = this.getModel().getValue("nckd_onaccountamount").toString();//挂账金额 String nckd_yufuamount = this.getModel().getValue("nckd_yufuamount").toString();//预付金额 BigDecimal reimburseamount = new BigDecimal(nckd_reimburseamount); BigDecimal onaccountamount = new BigDecimal(nckd_onaccountamount); BigDecimal yufuamount = new BigDecimal(nckd_yufuamount); reimburseamount=reimburseamount.subtract(onaccountamount); reimburseamount=reimburseamount.subtract(yufuamount); this.getModel().setValue("nckd_fukuanamountfield", reimburseamount); this.getModel().setValue("nckd_orireceiveamount", reimburseamount, 0); //刷新分录 this.getView().updateView("expenseentryentity"); }else if ("nckd_paymentmethod".equals(name)) { ChangeData[] changeSet = e.getChangeSet();//获取值1 for (ChangeData changeData : changeSet) { int rowIndex = changeData.getRowIndex(); Object newValue = changeData.getNewValue(); Object oldValue = changeData.getOldValue(); Object nckdPaymentmethod = this.getModel().getValue("nckd_paymentmethod"); DynamicObject nckd_paymentmethod = (DynamicObject) newValue; this.getModel().setValue("paymode", nckd_paymentmethod,0); } }else if ("nckd_reimburseamount".equals(name)) { String nckd_reimburseamount = this.getModel().getValue("nckd_reimburseamount").toString();//报销金额 String nckd_onaccountamount = this.getModel().getValue("nckd_onaccountamount").toString();//挂账金额 String nckd_yufuamount = this.getModel().getValue("nckd_yufuamount").toString();//预付金额 BigDecimal reimburseamount = new BigDecimal(nckd_reimburseamount); BigDecimal onaccountamount = new BigDecimal(nckd_onaccountamount); BigDecimal yufuamount = new BigDecimal(nckd_yufuamount); reimburseamount=reimburseamount.subtract(onaccountamount); reimburseamount=reimburseamount.subtract(yufuamount); this.getModel().setValue("nckd_fukuanamountfield", reimburseamount); this.getModel().setValue("nckd_orireceiveamount", reimburseamount, 0); //刷新分录 this.getView().updateView("expenseentryentity"); } } }