308 lines
		
	
	
		
			16 KiB
		
	
	
	
		
			Java
		
	
	
	
			
		
		
	
	
			308 lines
		
	
	
		
			16 KiB
		
	
	
	
		
			Java
		
	
	
	
| package tqq9.lc123.cloud.app.plugin.form.pm;
 | |
| 
 | |
| import com.alibaba.fastjson.JSONArray;
 | |
| import com.alibaba.fastjson.JSONObject;
 | |
| import kd.bos.bill.AbstractBillPlugIn;
 | |
| import kd.bos.bill.BillShowParameter;
 | |
| import kd.bos.bill.OperationStatus;
 | |
| import kd.bos.dataentity.entity.DynamicObject;
 | |
| import kd.bos.dataentity.entity.DynamicObjectCollection;
 | |
| import kd.bos.dataentity.utils.ObjectUtils;
 | |
| import kd.bos.dataentity.utils.StringUtils;
 | |
| import kd.bos.entity.datamodel.IDataModel;
 | |
| import kd.bos.entity.datamodel.ListSelectedRow;
 | |
| import kd.bos.entity.datamodel.ListSelectedRowCollection;
 | |
| import kd.bos.form.*;
 | |
| import kd.bos.form.control.Control;
 | |
| import kd.bos.form.control.EntryGrid;
 | |
| import kd.bos.form.control.events.BeforeClickEvent;
 | |
| import kd.bos.form.events.ClosedCallBackEvent;
 | |
| import kd.bos.form.events.HyperLinkClickEvent;
 | |
| import kd.bos.form.events.HyperLinkClickListener;
 | |
| import kd.bos.list.ListFilterParameter;
 | |
| import kd.bos.list.ListShowParameter;
 | |
| import kd.bos.logging.Log;
 | |
| import kd.bos.logging.LogFactory;
 | |
| import kd.bos.orm.query.QCP;
 | |
| import kd.bos.orm.query.QFilter;
 | |
| import kd.bos.servicehelper.BusinessDataServiceHelper;
 | |
| import kd.bos.servicehelper.user.UserServiceHelper;
 | |
| 
 | |
| import java.math.BigDecimal;
 | |
| import java.util.ArrayList;
 | |
| import java.util.Date;
 | |
| import java.util.EventObject;
 | |
| import java.util.List;
 | |
| 
 | |
| /**
 | |
|  * 采购订单界面插件
 | |
|  * 点击付款计划分录付款单,弹出与预付款选择界面进行预付
 | |
|  */
 | |
| public class    PurorderEntryIntroPaybillPlugin extends AbstractBillPlugIn implements HyperLinkClickListener {
 | |
|     private final static Log logger = LogFactory.getLog(PurorderEntryIntroPaybillPlugin.class);
 | |
|     private static DynamicObject BILLTYPE;
 | |
|     private static DynamicObject BIZTYPE;
 | |
|     private static DynamicObject LINETYPE;
 | |
| 
 | |
|     static {
 | |
|         //订单
 | |
|         DynamicObject billtype = BusinessDataServiceHelper.loadSingle("bos_billtype", new QFilter[]{new QFilter("number", QCP.equals, "pm_PurOrderBill_STD_BT_S")});
 | |
|         BILLTYPE = billtype;
 | |
| 
 | |
|         DynamicObject biztype = BusinessDataServiceHelper.loadSingle("bd_biztype", new QFilter[]{new QFilter("number", QCP.equals, "110")});
 | |
|         BIZTYPE = biztype;
 | |
|         DynamicObject linetype = BusinessDataServiceHelper.loadSingle("bd_linetype", new QFilter[]{new QFilter("number", QCP.equals, "010")});
 | |
|         LINETYPE = linetype;
 | |
|     }
 | |
| 
 | |
|     @Override
 | |
|     public void registerListener(EventObject e) {
 | |
|         super.registerListener(e);
 | |
|         this.addClickListeners(new String[]{"tqq9_paybillno"});
 | |
|         EntryGrid preEntry = (EntryGrid) this.getView().getControl("purbillentry_pay");
 | |
|         preEntry.addHyperClickListener(this);
 | |
|     }
 | |
| 
 | |
|     /**
 | |
|      * 点击付款单反写本次结算金额
 | |
|      */
 | |
|     @Override
 | |
|     public void closedCallBack(ClosedCallBackEvent closedCallBackEvent) {
 | |
|         super.closedCallBack(closedCallBackEvent);
 | |
|         IDataModel model = this.getModel();
 | |
|         IFormView view = this.getView();
 | |
|         String actionId = closedCallBackEvent.getActionId();
 | |
|         Object returnData = closedCallBackEvent.getReturnData();
 | |
|         if (returnData != null) {
 | |
|             if ("paybill".equals(actionId)) {
 | |
|                 DynamicObjectCollection purbillentry_pay = this.getModel().getDataEntity(true).getDynamicObjectCollection("purbillentry_pay");
 | |
|                 int seq = 0;
 | |
|                 for (DynamicObject dynamicObject : purbillentry_pay) {
 | |
|                     boolean isprepay = dynamicObject.getBoolean("isprepay");
 | |
|                     if (isprepay) {
 | |
|                         seq = dynamicObject.getInt("seq") - 1;
 | |
|                     }
 | |
|                 }
 | |
|                 ListSelectedRow listSelectedRow = ((ListSelectedRowCollection) returnData).get(0);
 | |
|                 DynamicObject dynamicObject = BusinessDataServiceHelper.loadSingle(listSelectedRow.toString(), "cas_paybill");
 | |
|                 BigDecimal unsettleamount = dynamicObject.getBigDecimal("unsettleamount");
 | |
| 
 | |
|                 model.setValue("tqq9_paybillno", dynamicObject.getString("billno"));//付款单
 | |
|                 model.setValue("joinpayamount", unsettleamount, seq);//关联付款金额
 | |
|                 model.setValue("paidamount", unsettleamount, seq);//已付金额
 | |
|                 model.setValue("tqq9_settleamount", unsettleamount, seq);//本次结算金额
 | |
|                 view.setVisible(true, "paidpreallamount,paidallamount,joinpayamount,paidamount,tqq9_settleamount");
 | |
|             }
 | |
|         }
 | |
|         this.getView().updateView();
 | |
|     }
 | |
| 
 | |
|     /**
 | |
|      * 选择付款单前置条件校验:订货供应商不能为空,勾选是否预付,价税合计不能为空
 | |
|      */
 | |
|     @Override
 | |
|     public void beforeClick(BeforeClickEvent evt) {
 | |
|         super.beforeClick(evt);
 | |
|         IDataModel model = this.getModel();
 | |
|         Control c = (Control) evt.getSource();
 | |
|         String key = c.getKey().toLowerCase();
 | |
|         if ("tqq9_paybillno".equals(key)) {
 | |
|             EntryGrid entryGrid = this.getControl("purbillentry_pay");
 | |
|             int length = entryGrid.getSelectRows()[0];//获取点击分录序号从0开始
 | |
|             DynamicObject pm_purorderbill = model.getDataEntity(true);//采购订单
 | |
|             BigDecimal totalallamount = pm_purorderbill.getBigDecimal("totalallamount");//价税合计
 | |
|             if (totalallamount.compareTo(BigDecimal.ZERO) < 0) {
 | |
|                 this.getView().showMessage("价税合计不能为空");
 | |
|                 evt.setCancel(true);
 | |
|             }
 | |
|             DynamicObjectCollection entries = pm_purorderbill.getDynamicObjectCollection("purbillentry_pay");//付款计划分录
 | |
|             DynamicObject supplier = pm_purorderbill.getDynamicObject("supplier");//订货供应商
 | |
|             DynamicObject dynamicObject = entries.get(length);
 | |
|             Boolean isprepay = dynamicObject.getBoolean("isprepay");
 | |
|             if (supplier == null) {
 | |
|                 this.getView().showMessage("订货供应商不能为空");
 | |
|                 evt.setCancel(true);
 | |
|             }
 | |
|             if (isprepay.equals(false)) {
 | |
|                 this.getView().showMessage("请勾选是否预付");
 | |
|                 evt.setCancel(true);
 | |
|             }
 | |
|         }
 | |
|     }
 | |
| 
 | |
|     /**
 | |
|      * 点击付款单字段选择付款单
 | |
|      */
 | |
|     @Override
 | |
|     public void click(EventObject evt) {
 | |
|         super.click(evt);
 | |
|         Control c = (Control) evt.getSource();
 | |
|         String key = c.getKey().toLowerCase();
 | |
| 
 | |
|         if ("tqq9_paybillno".equals(key)) {
 | |
|             IDataModel model = this.getModel();
 | |
|             int entryRowCount = model.getEntryRowCount("purbillentry_pay");
 | |
|             List<String> selectedNos = new ArrayList(entryRowCount);
 | |
|             DynamicObject pm_purorderbill = model.getDataEntity(true);//采购订单
 | |
|             DynamicObjectCollection entries = pm_purorderbill.getDynamicObjectCollection("purbillentry_pay");//付款计划分录
 | |
|             DynamicObject supplier = pm_purorderbill.getDynamicObject("supplier");//订货供应商
 | |
|             if (entries != null) {
 | |
|                 for (DynamicObject entry : entries) {
 | |
|                     String tqq9_paybillno = entry.getString("tqq9_paybillno");
 | |
|                     if (tqq9_paybillno != null) {
 | |
|                         selectedNos.add(tqq9_paybillno);
 | |
|                     }
 | |
|                 }
 | |
|             }
 | |
|             QFilter filter = new QFilter("billstatus", "=", "D");//已付款
 | |
|             if (!ObjectUtils.isEmpty(selectedNos)) {
 | |
|                 filter.and(new QFilter("billno", "not in", selectedNos));
 | |
|             }
 | |
|             filter.and(new QFilter("itempayeetype", "=", "bd_supplier"));//收款人类型为供应商
 | |
|             filter.and(new QFilter("itempayee", "=", supplier.getLong("id")));//收款人为采购订单供应商
 | |
|             filter.and(new QFilter("paymenttype.number", "=", "202"));
 | |
|             filter.and("unsettleamount", QCP.large_than, BigDecimal.ZERO);
 | |
|             //组织一致
 | |
|             DynamicObject org = (DynamicObject) model.getValue("org");
 | |
|             filter.and(new QFilter("entry.settleorg", "=", org.getLong("id")));
 | |
|             DynamicObject dynamicObject = BusinessDataServiceHelper.loadSingle("cas_paybill", new QFilter[]{filter});
 | |
|             showZbBillF7(this.getView(), this.getPluginName(), filter);
 | |
|         }
 | |
| 
 | |
|     }
 | |
| 
 | |
| 
 | |
|     /**
 | |
|      * 点击付款单字段跳转至付款单
 | |
|      */
 | |
|     @Override
 | |
|     public void hyperLinkClick(HyperLinkClickEvent hyperLinkClickEvent) {
 | |
|         int rowIndex = hyperLinkClickEvent.getRowIndex();
 | |
|         String tqq9_paybillno = (String) this.getModel().getValue("tqq9_paybillno", rowIndex);
 | |
|         DynamicObject paybill = BusinessDataServiceHelper.loadSingle("cas_paybill", new QFilter[]{new QFilter("billno", QCP.equals, tqq9_paybillno)});
 | |
|         Long id = paybill.getLong("id");
 | |
|         if (id != null) {
 | |
|             BillShowParameter formshowParameter = new BillShowParameter();
 | |
|             formshowParameter.setFormId("cas_paybill");
 | |
|             formshowParameter.getOpenStyle().setInlineStyleCss(new StyleCss());
 | |
|             formshowParameter.setPkId(id);
 | |
|             formshowParameter.getOpenStyle().setShowType(ShowType.Modal);
 | |
|             formshowParameter.setStatus(OperationStatus.VIEW);
 | |
|             this.getView().showForm(formshowParameter);
 | |
|         }
 | |
|     }
 | |
| 
 | |
|     public static void showZbBillF7(IFormView view, String pluginName, QFilter filter) {
 | |
|         ListShowParameter lsp = ShowFormHelper.createShowListForm("cas_paybill", true, 2);
 | |
|         ListFilterParameter lfp = new ListFilterParameter();
 | |
|         lfp.setFilter(filter);
 | |
|         lsp.setCustomParam("ismergerows", Boolean.FALSE);
 | |
|         lsp.setListFilterParameter(lfp);
 | |
|         CloseCallBack closeCallBack = new CloseCallBack(pluginName, "paybill");
 | |
|         lsp.setCloseCallBack(closeCallBack);
 | |
|         view.showForm(lsp);
 | |
|     }
 | |
| 
 | |
| 
 | |
|     /**
 | |
|      * 点击下推付款申请单跳转至付款申请单
 | |
|      */
 | |
|     @Override
 | |
|     public void afterCreateNewData(EventObject e) {
 | |
|         super.afterCreateNewData(e);
 | |
|         FormShowParameter formShowParameter = this.getView().getFormShowParameter();
 | |
|         JSONObject tqq9_pursuggestrpt = (JSONObject) formShowParameter.getCustomParam("pm_purorderbill");
 | |
|         if (tqq9_pursuggestrpt != null) {
 | |
|             IDataModel model = this.getModel();
 | |
|             DynamicObjectCollection billentry = model.getDataEntity(true).getDynamicObjectCollection("billentry");
 | |
|             billentry.clear();
 | |
|             //采购建议报表
 | |
|             JSONArray tqq9_pursuggestrptentry = tqq9_pursuggestrpt.getJSONArray("tqq9_pursuggestrptentry");
 | |
| 
 | |
|             long currentUserId = UserServiceHelper.getCurrentUserId();
 | |
|             DynamicObject user = BusinessDataServiceHelper.loadSingle("bos_user", new QFilter[]{new QFilter("id", QCP.equals, currentUserId)});
 | |
|             DynamicObjectCollection entryentity = user.getDynamicObjectCollection("entryentity");
 | |
|             DynamicObject dept = null;//部门
 | |
|             for (DynamicObject dynamicObject : entryentity) {
 | |
|                 boolean ispartjob = dynamicObject.getBoolean("ispartjob");
 | |
|                 if (!ispartjob) {
 | |
|                     dept = dynamicObject.getDynamicObject("dpt");
 | |
|                 }
 | |
|             }
 | |
| 
 | |
|             DynamicObject currency = BusinessDataServiceHelper.loadSingle("bd_currency",
 | |
|                     new QFilter[]{new QFilter("number", QCP.equals, "CNY")});//币别
 | |
|             DynamicObject taxrate = BusinessDataServiceHelper.loadSingle("bd_taxrate",
 | |
|                     new QFilter[]{new QFilter("number", QCP.equals, "V13")});//税率
 | |
|             Date date = new Date();
 | |
|             DynamicObject org = null;//组织
 | |
|             int i = 0;
 | |
|             for (Object dynamicObject : tqq9_pursuggestrptentry) {
 | |
|                 JSONObject entry = (JSONObject) dynamicObject;
 | |
|                 if (entry.getBoolean("tqq9_ischange")) {
 | |
|                     billentry.addNew();
 | |
|                     if (i == 0) {
 | |
|                         JSONObject tqq9_org = entry.getJSONObject("tqq9_org");
 | |
|                         org = BusinessDataServiceHelper.loadSingle(tqq9_org.getLong("id"), "bos_org");//组织
 | |
|                         model.setValue("org", org);//申请组织
 | |
|                         model.setValue("dept", dept);//申请部门
 | |
|                         model.setValue("creator", user);//创建人
 | |
|                         model.setValue("lastupdateuser", user);//修改人
 | |
|                         model.setValue("currency", currency);//币别
 | |
|                         model.setValue("lastupdatetime", date);//修改时间
 | |
|                         model.setValue("billtype", BILLTYPE);//单据类型
 | |
|                         model.setValue("biztype", BIZTYPE);//业务类型
 | |
|                         model.setValue("biztime", date);//申请日期
 | |
|                         model.setValue("billstatus", "A");//单据状态
 | |
|                         model.setValue("closestatus", "A");//关闭状态
 | |
|                         model.setValue("cancelstatus", "A");//作废状态
 | |
|                         model.setValue("changestatus", "A");//变更状态
 | |
|                         model.setValue("subversion", "1");//子版本号
 | |
|                         model.setValue("version", "1");//版本号
 | |
|                         model.setValue("tqq9_sfsyhf", "false");//是否使用货返
 | |
|                         model.setValue("tqq9_hshfsysl", taxrate);//含税货返使用税率
 | |
|                         model.setValue("tqq9_hshfsygs", "A");//含税货返使用归属
 | |
|                         model.setValue("tqq9_sfsyxf", "false");//是否使用现返
 | |
|                         model.setValue("tqq9_hsxfsysl", taxrate);//含税现返使用税率
 | |
|                         model.setValue("tqq9_hsxfsygs", "A");//含税现返使用归属
 | |
|                     }
 | |
|                     JSONObject material = entry.getJSONObject("tqq9_material");//物料
 | |
|                     DynamicObject tqq9_material = BusinessDataServiceHelper.loadSingle(material.getLong("id"), "bd_material");//物料
 | |
|                     DynamicObject materialpurchaseinfo = BusinessDataServiceHelper.loadSingle("bd_materialpurchaseinfo", new QFilter[]{new QFilter("masterid", QCP.equals, tqq9_material.getLong("id"))});//物料采购信息
 | |
|                     BigDecimal tqq9_saledates = entry.getBigDecimal("tqq9_saledates");
 | |
|                     model.setValue("material", materialpurchaseinfo, i);//物料
 | |
|                     model.setValue("materialname", tqq9_material.getString("name"), i);//物料名称
 | |
|                     model.setValue("unit", tqq9_material.getDynamicObject("baseunit"), i);//计量单位
 | |
|                     model.setValue("baseunit", tqq9_material.getDynamicObject("baseunit"), i);//基本单位
 | |
|                     model.setValue("tqq9_brand", tqq9_material.getDynamicObject("tqq9_brand"), i);//品牌
 | |
|                     model.setValue("entrycreator", user, i);//创建人
 | |
|                     model.setValue("rowclosestatus", "A", i);//行关闭状态
 | |
|                     model.setValue("rowterminatestatus", "A", i);//行终止状态
 | |
|                     model.setValue("entrychangetype", "B",i);//变更方式
 | |
|                     model.setValue("entryrecorg", org, i);//收货组织
 | |
|                     model.setValue("entryreqorg", org, i);//需求组织
 | |
|                     model.setValue("entryreqdept", dept, i);//需求部门
 | |
|                     model.setValue("entryrecdept", org, i);//收货部门
 | |
|                     model.setValue("entrysettleorg", org, i);//结算组织
 | |
|                     model.setValue("entrypayorg", org, i);//付款组织
 | |
|                     model.setValue("deliverdate", date, i);//交货日期
 | |
|                     model.setValue("linetype", LINETYPE, i);//行类型
 | |
|                     model.setValue("entryrecdept", org, i);//收货部门
 | |
|                     model.setValue("discounttype", "C", i);//折扣方式
 | |
|                     model.setValue("tqq9_expectsaletime", tqq9_saledates, i);//预计销售时间(月)
 | |
|                     if (StringUtils.equals(org.getString("number"), "SHLC")) {
 | |
|                         model.setValue("tqq9_zgcgxj", tqq9_material.getBigDecimal("tqq9_maxprice_sh"), i);//最高采购限价
 | |
|                         model.setValue("priceandtax", tqq9_material.getBigDecimal("tqq9_maxprice_sh"), i);//含税单价
 | |
|                     } else if (StringUtils.equals(org.getString("number"), "BJLC")) {
 | |
|                         model.setValue("tqq9_zgcgxj", tqq9_material.getBigDecimal("tqq9_maxprice_bj"), i);//最高采购限价
 | |
|                         model.setValue("priceandtax", tqq9_material.getBigDecimal("tqq9_maxprice_bj"), i);//含税单价
 | |
|                     } else if (StringUtils.equals(org.getString("number"), "GZLC")) {
 | |
|                         model.setValue("tqq9_zgcgxj", tqq9_material.getBigDecimal("tqq9_maxprice_gz"), i);//最高采购限价
 | |
|                         model.setValue("priceandtax", tqq9_material.getBigDecimal("tqq9_maxprice_gz"), i);//含税单价
 | |
|                     }
 | |
|                     i++;
 | |
|                 }
 | |
|             }
 | |
|         }
 | |
|     }
 | |
| } |