费用项目过滤插件

This commit is contained in:
zengweihai 2024-06-05 18:28:03 +08:00
parent bff7f48d66
commit b5736b4254
1 changed files with 85 additions and 0 deletions

View File

@ -0,0 +1,85 @@
package shkd.fi.er.plugin.formplugin;
import kd.bos.bill.AbstractBillPlugIn;
import kd.bos.dataentity.entity.DynamicObject;
import kd.bos.dataentity.entity.DynamicObjectCollection;
import kd.bos.form.field.BasedataEdit;
import kd.bos.form.field.events.BeforeF7SelectEvent;
import kd.bos.form.field.events.BeforeF7SelectListener;
import kd.bos.list.ListShowParameter;
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.util.StringUtils;
import kd.sdk.plugin.Plugin;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.EventObject;
import java.util.List;
/**
* 单据界面插件
*/
public class CommonExpenseItemBillFormPlugin extends AbstractBillPlugIn implements BeforeF7SelectListener,Plugin {
String entityId;
List<String> paymentList = new ArrayList<String>(Arrays.asList("er_publicreimbursebill","er_prepaybill","er_dailyreimbursebill"));//对公报销单预付单费用报销单
List<String> paymentItemList = new ArrayList<String>(Arrays.asList("er_dailyloanbill"));//员工借款单
@Override
public void initialize() {
super.initialize();
entityId = this.getView().getEntityId();//获取当前页面标识
}
@Override
public void registerListener(EventObject e) {
super.registerListener(e);
BasedataEdit edit = this.getView().getControl("expenseitem");
if (edit != null){
edit.addBeforeF7SelectListener(this);
}
}
@Override
public void beforeF7Select(BeforeF7SelectEvent beforeF7SelectEvent) {
String name = beforeF7SelectEvent.getProperty().getName();
DynamicObject dataEntity = this.getModel().getDataEntity();//获取单据实体
DynamicObject payment = null;
if ("expenseitem".equals(name)){
if (paymentList.contains(entityId)){
payment = dataEntity.getDynamicObject("shkd_payment");
}else if (paymentItemList.contains(entityId)){
payment = dataEntity.getDynamicObject("shkd_paymentitem");
}
if (payment != null){
String paymentNumber = payment.getString("number");
if (StringUtils.isNotEmpty(paymentNumber)){//付款事项编码不为空
ArrayList<Object> paymentIds = new ArrayList<>();
QFilter qFilter = new QFilter("shkd_paymatterinfo.number", QCP.equals, paymentNumber);
DynamicObject[] loads = BusinessDataServiceHelper.load("shkd_accountlinkmatter","id,shkd_expenseitem.id",qFilter.toArray());
for (DynamicObject load : loads) {
long aLong = load.getLong("shkd_expenseitem.id");
paymentIds.add(aLong);
}
if (!paymentIds.isEmpty()){
QFilter qF = new QFilter("id", QCP.in,paymentIds);
ListShowParameter formShowParameter = (ListShowParameter) beforeF7SelectEvent.getFormShowParameter();
formShowParameter.getListFilterParameter().setFilter(qF);
}else {
beforeF7SelectEvent.setCancel(true);
this.getView().showTipNotification("该付款事项未关联费用项目");
}
}
}else {
beforeF7SelectEvent.setCancel(true);
this.getView().showTipNotification("请先选择付款事项");
}
}
}
}