116 lines
		
	
	
		
			4.8 KiB
		
	
	
	
		
			Java
		
	
	
	
			
		
		
	
	
			116 lines
		
	
	
		
			4.8 KiB
		
	
	
	
		
			Java
		
	
	
	
| package tqq9.lc123.cloud.app.plugin.form.ap;
 | |
| 
 | |
| import kd.bos.algo.DataSet;
 | |
| import kd.bos.bill.AbstractBillPlugIn;
 | |
| import kd.bos.dataentity.entity.DynamicObject;
 | |
| import kd.bos.dataentity.entity.DynamicObjectCollection;
 | |
| import kd.bos.dataentity.utils.StringUtils;
 | |
| import kd.bos.db.DB;
 | |
| import kd.bos.db.DBRoute;
 | |
| import kd.bos.entity.datamodel.IDataModel;
 | |
| import kd.bos.entity.datamodel.events.PropertyChangedArgs;
 | |
| import kd.bos.form.CloseCallBack;
 | |
| import kd.bos.form.FormShowParameter;
 | |
| import kd.bos.form.ShowType;
 | |
| import kd.bos.form.control.events.ItemClickEvent;
 | |
| import kd.bos.logging.Log;
 | |
| import kd.bos.logging.LogFactory;
 | |
| import kd.bos.orm.ORM;
 | |
| import kd.sdk.plugin.Plugin;
 | |
| 
 | |
| import java.math.BigDecimal;
 | |
| import java.util.EventObject;
 | |
| 
 | |
| /**
 | |
|  * 付款申请新增抵扣订单按钮
 | |
|  */
 | |
| public class PayApplyFormPlugin extends AbstractBillPlugIn implements Plugin {
 | |
|     private final static Log logger = LogFactory.getLog(PayApplyFormPlugin.class);
 | |
| 
 | |
|     @Override
 | |
|     public void registerListener(EventObject e) {
 | |
|         super.registerListener(e);
 | |
|         this.addItemClickListeners("tbmain");
 | |
|     }
 | |
| 
 | |
| 
 | |
|     /**
 | |
|      * 付款申请点击抵扣订单弹出手工结算
 | |
|      */
 | |
|     @Override
 | |
|     public void itemClick(ItemClickEvent evt) {
 | |
|         super.itemClick(evt);
 | |
|         String itemKey = evt.getItemKey();
 | |
|         if (StringUtils.equals("tqq9_deductorder", itemKey)) {
 | |
|             DynamicObjectCollection entry = this.getModel().getDataEntity(true).getDynamicObjectCollection("entry");
 | |
|             if (entry.isEmpty()) {
 | |
|                 getView().showMessage("请先维护供应商");
 | |
|                 return;
 | |
|             } else {
 | |
|                 DynamicObject e_asstact = entry.get(0).getDynamicObject("e_asstact");//往来户
 | |
|                 DynamicObject settleorg = (DynamicObject) this.getModel().getValue("settleorg");//结算组织
 | |
|                 if (e_asstact == null) {
 | |
|                     getView().showMessage("请先维护供应商");
 | |
|                     return;
 | |
|                 } else {
 | |
|                     FormShowParameter param = new FormShowParameter();
 | |
|                     param.setFormId("ap_handsettle");
 | |
|                     param.setCustomParam("e_asstact", e_asstact);
 | |
|                     param.setCustomParam("settleorg", settleorg);
 | |
|                     param.setCloseCallBack(new CloseCallBack(this, "tqq9_deductorder"));
 | |
|                     param.getOpenStyle().setShowType(ShowType.Modal);
 | |
|                     this.getView().showForm(param);
 | |
|                 }
 | |
|             }
 | |
|         }
 | |
|     }
 | |
| 
 | |
|     /**
 | |
|      * 付款申请供应商可抵扣金额
 | |
|      */
 | |
|     @Override
 | |
|     public void afterCreateNewData(EventObject e) {
 | |
|         super.afterCreateNewData(e);
 | |
|         IDataModel model = this.getModel();
 | |
|         DynamicObject e_asstact = (DynamicObject) model.getValue("e_asstact", 0);
 | |
|         if (e_asstact != null) {
 | |
|             long id = e_asstact.getLong("id");
 | |
|             String sql = "/*dialect*/select  fasstactid,sum(funsettleamount) qty from t_ap_finapbill WHERE fsettlestatus in ('unsettle','partsettle') " +
 | |
|                     "and fiswrittenoff='0' and fbillstatus ='C' and funsettleamount<0 AND fasstactid=" + id + " group by fasstactid";
 | |
|             DataSet dataSet = DB.queryDataSet(this.getClass().getName(), DBRoute.of("cas"), sql);
 | |
|             DataSet copy = dataSet.copy();
 | |
|             DynamicObjectCollection dynamicObjects = ORM.create().toPlainDynamicObjectCollection(copy);
 | |
|             BigDecimal qty = dynamicObjects.get(0).getBigDecimal("qty");
 | |
|             model.setValue("tqq9_gyskdkzje", qty);
 | |
|             getView().updateView();
 | |
|         }
 | |
|     }
 | |
| 
 | |
|     /**
 | |
|      * 付款申请供应商可抵扣金额
 | |
|      */
 | |
|     @Override
 | |
|     public void propertyChanged(PropertyChangedArgs e) {
 | |
|         super.propertyChanged(e);
 | |
|         String name = e.getProperty().getName();
 | |
|         if (StringUtils.equals("e_asstact", name)) {
 | |
|             IDataModel model = this.getModel();
 | |
|             DynamicObject e_asstact = (DynamicObject) model.getValue("e_asstact", 0);
 | |
|             if (e_asstact != null) {
 | |
|                 long id = e_asstact.getLong("id");
 | |
|                 String sql =  "/*dialect*/select  fasstactid,sum(funsettleamount) qty from t_ap_finapbill WHERE fsettlestatus in ('unsettle','partsettle') " +
 | |
|                         "and fiswrittenoff='0' and fbillstatus ='C' and funsettleamount<0 AND fasstactid=" + id + " group by fasstactid";
 | |
|                 DataSet dataSet = DB.queryDataSet(this.getClass().getName(), DBRoute.of("cas"), sql);
 | |
|                 DataSet copy = dataSet.copy();
 | |
|                 DynamicObjectCollection dynamicObjects = ORM.create().toPlainDynamicObjectCollection(copy);
 | |
|                 BigDecimal qty=BigDecimal.ZERO;
 | |
|                 if(dynamicObjects.size()>0){
 | |
|                      qty = dynamicObjects.get(0).getBigDecimal("qty");
 | |
|                 }
 | |
|                 model.setValue("tqq9_gyskdkzje", qty);
 | |
|                 getView().updateView();
 | |
|             }
 | |
|         }
 | |
| 
 | |
|     }
 | |
| } |