|  | @@ -1,18 +1,28 @@
 | 
	
		
			
				|  |  |  package fi.gl.formplugin;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  import kd.bos.bill.AbstractBillPlugIn;
 | 
	
		
			
				|  |  | -import kd.bos.dataentity.OperateOption;
 | 
	
		
			
				|  |  | +import kd.bos.bill.BillShowParameter;
 | 
	
		
			
				|  |  | +import kd.bos.context.RequestContext;
 | 
	
		
			
				|  |  |  import kd.bos.dataentity.entity.DynamicObject;
 | 
	
		
			
				|  |  |  import kd.bos.dataentity.entity.DynamicObjectCollection;
 | 
	
		
			
				|  |  | +import kd.bos.form.CloseCallBack;
 | 
	
		
			
				|  |  | +import kd.bos.form.FormShowParameter;
 | 
	
		
			
				|  |  | +import kd.bos.form.ShowType;
 | 
	
		
			
				|  |  |  import kd.bos.form.control.Control;
 | 
	
		
			
				|  |  | +import kd.bos.form.control.EntryGrid;
 | 
	
		
			
				|  |  | +import kd.bos.form.control.events.CellClickEvent;
 | 
	
		
			
				|  |  | +import kd.bos.form.control.events.CellClickListener;
 | 
	
		
			
				|  |  |  import kd.bos.orm.query.QCP;
 | 
	
		
			
				|  |  |  import kd.bos.orm.query.QFilter;
 | 
	
		
			
				|  |  |  import kd.bos.servicehelper.BusinessDataServiceHelper;
 | 
	
		
			
				|  |  | -import kd.bos.servicehelper.operation.OperationServiceHelper;
 | 
	
		
			
				|  |  | +import kd.bos.servicehelper.operation.DeleteServiceHelper;
 | 
	
		
			
				|  |  | +import kd.bos.servicehelper.operation.SaveServiceHelper;
 | 
	
		
			
				|  |  |  import org.apache.commons.lang3.StringUtils;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  import java.util.Date;
 | 
	
		
			
				|  |  |  import java.util.EventObject;
 | 
	
		
			
				|  |  | +import java.util.HashMap;
 | 
	
		
			
				|  |  | +import java.util.Map;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  /**
 | 
	
		
			
				|  |  |   * 动态表单操作
 | 
	
	
		
			
				|  | @@ -20,90 +30,162 @@ import java.util.EventObject;
 | 
	
		
			
				|  |  |   * 2024-06-28 wangj
 | 
	
		
			
				|  |  |   * 主要功能:日结执行按钮逻辑
 | 
	
		
			
				|  |  |   */
 | 
	
		
			
				|  |  | -public class DailyexcuteFormPlugin extends AbstractBillPlugIn {
 | 
	
		
			
				|  |  | +public class DailyexcuteFormPlugin extends AbstractBillPlugIn implements CellClickListener
 | 
	
		
			
				|  |  | +{
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      private final static String KEY_DAILY = "nckd_daily";
 | 
	
		
			
				|  |  |      //页面取消按钮标识
 | 
	
		
			
				|  |  |      private final static String KEY_UNDAILY = "nckd_undaily";
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -//    @Override
 | 
	
		
			
				|  |  | -//    public void registerListener(EventObject e) {
 | 
	
		
			
				|  |  | -//        super.registerListener(e);
 | 
	
		
			
				|  |  | -//        this.addClickListeners(KEY_DAILY, KEY_UNDAILY);
 | 
	
		
			
				|  |  | -//    }
 | 
	
		
			
				|  |  | -//
 | 
	
		
			
				|  |  | -//    @Override
 | 
	
		
			
				|  |  | -//    public void click(EventObject evt) {
 | 
	
		
			
				|  |  | -//        super.click(evt);
 | 
	
		
			
				|  |  | -//        //获取被点击的控件对象
 | 
	
		
			
				|  |  | -//        Control source = (Control) evt.getSource();
 | 
	
		
			
				|  |  | -//        if (StringUtils.equals(source.getKey(), KEY_DAILY)) {
 | 
	
		
			
				|  |  | -//            DynamicObjectCollection orgCol = (DynamicObjectCollection) this.getModel().getValue("nckd_org");
 | 
	
		
			
				|  |  | -//            if(orgCol==null || orgCol.size()==0){
 | 
	
		
			
				|  |  | -//                this.getView().showMessage("请先选择组织");
 | 
	
		
			
				|  |  | -//                return;
 | 
	
		
			
				|  |  | -//            }
 | 
	
		
			
				|  |  | -//
 | 
	
		
			
				|  |  | -//            Date dailydate = (Date) this.getModel().getValue("nckd_dailydate");
 | 
	
		
			
				|  |  | -//            if(dailydate==null || "".equals(dailydate)){
 | 
	
		
			
				|  |  | -//                this.getView().showMessage("请先选择日期");
 | 
	
		
			
				|  |  | -//                return;
 | 
	
		
			
				|  |  | -//            }
 | 
	
		
			
				|  |  | -//
 | 
	
		
			
				|  |  | -//            String message = dailyData(orgCol,dailydate);
 | 
	
		
			
				|  |  | -//            this.getView().showMessage(message);
 | 
	
		
			
				|  |  | -//        }else if (StringUtils.equals(source.getKey(), KEY_UNDAILY)) {
 | 
	
		
			
				|  |  | -//            this.getView().showMessage("反日结成功");
 | 
	
		
			
				|  |  | -//        }
 | 
	
		
			
				|  |  | -//    }
 | 
	
		
			
				|  |  | -//
 | 
	
		
			
				|  |  | -//    /*
 | 
	
		
			
				|  |  | -//    * 查询凭证,符合条件的组织插入日结记录,不符合条件的显示在表格中
 | 
	
		
			
				|  |  | -//     */
 | 
	
		
			
				|  |  | -//    private String dailyData(DynamicObjectCollection orgCol, Date dailydate) {
 | 
	
		
			
				|  |  | -//        String returnMessage = "";
 | 
	
		
			
				|  |  | -//        for(DynamicObject orgObj : orgCol){
 | 
	
		
			
				|  |  | -//            boolean isCan = true;
 | 
	
		
			
				|  |  | -//            QFilter qFilter_org = new QFilter("org", QCP.equals,orgObj.getPkValue());
 | 
	
		
			
				|  |  | -//            QFilter qFilter_bizdate = new QFilter("bizdate",QCP.equals,dailydate);
 | 
	
		
			
				|  |  | -//            DynamicObject[] voucherCol = BusinessDataServiceHelper.load("gl_voucher","id,ispost,billno,bizdate,org,billstatus",
 | 
	
		
			
				|  |  | -//                    new QFilter[]{qFilter_org,qFilter_bizdate});
 | 
	
		
			
				|  |  | -//            for(DynamicObject voucherObj : voucherCol){
 | 
	
		
			
				|  |  | -//                boolean ispost = voucherObj.getBoolean("ispost");
 | 
	
		
			
				|  |  | -//                if(ispost!=true){//是否过账等于否
 | 
	
		
			
				|  |  | -//                    isCan = false;
 | 
	
		
			
				|  |  | -//                    int rowid = this.getModel().createNewEntryRow("nckd_entryentity");
 | 
	
		
			
				|  |  | -//
 | 
	
		
			
				|  |  | -//                    this.getModel().setValue("nckd_voucherorg",orgObj,rowid);//设置组织
 | 
	
		
			
				|  |  | -//
 | 
	
		
			
				|  |  | -//                    String voucherid = voucherObj.getString("id");
 | 
	
		
			
				|  |  | -//                    this.getModel().setValue("nckd_vouherid",voucherid,rowid);//设置凭证id
 | 
	
		
			
				|  |  | -//
 | 
	
		
			
				|  |  | -//                    String billno = voucherObj.getString("billno");
 | 
	
		
			
				|  |  | -//                    this.getModel().setValue("nckd_vouhernumber",billno,rowid);//设置凭证号
 | 
	
		
			
				|  |  | -//
 | 
	
		
			
				|  |  | -//                    Date bizdate = voucherObj.getDate("bizdate");
 | 
	
		
			
				|  |  | -//                    this.getModel().setValue("nckd_voucherdate",bizdate,rowid);//设置凭证日期
 | 
	
		
			
				|  |  | -//
 | 
	
		
			
				|  |  | -//                    String billstatus = voucherObj.getString("billstatus");
 | 
	
		
			
				|  |  | -//                    this.getModel().setValue("nckd_voucherstatus",billstatus,rowid);//设置凭证状态
 | 
	
		
			
				|  |  | -//                }
 | 
	
		
			
				|  |  | -//            }
 | 
	
		
			
				|  |  | -//
 | 
	
		
			
				|  |  | -//            //写入日结记录
 | 
	
		
			
				|  |  | -//            writeDailybill(isCan,orgObj,dailydate);
 | 
	
		
			
				|  |  | -//        }
 | 
	
		
			
				|  |  | -//
 | 
	
		
			
				|  |  | -//        return returnMessage;
 | 
	
		
			
				|  |  | -//    }
 | 
	
		
			
				|  |  | -//
 | 
	
		
			
				|  |  | -//    private void writeDailybill(boolean isCan, DynamicObject orgObj, Date dailydate) {
 | 
	
		
			
				|  |  | -//        if(isCan==true){
 | 
	
		
			
				|  |  | -//            DynamicObject dailybillObj = BusinessDataServiceHelper.newDynamicObject("nckd_gl_dailybill");
 | 
	
		
			
				|  |  | -//            dailybillObj.set("nckd_org",orgObj);
 | 
	
		
			
				|  |  | -//            dailybillObj.set("nckd_dailydate",dailydate);
 | 
	
		
			
				|  |  | -//            DynamicObject[] datalist = new DynamicObject[]{dailybillObj};
 | 
	
		
			
				|  |  | -//            OperationServiceHelper.executeOperate("save","nckd_gl_dailybill",datalist, OperateOption.create());
 | 
	
		
			
				|  |  | -//        }
 | 
	
		
			
				|  |  | -//    }
 | 
	
		
			
				|  |  | +    @Override
 | 
	
		
			
				|  |  | +    public void registerListener(EventObject e) {
 | 
	
		
			
				|  |  | +        super.registerListener(e);
 | 
	
		
			
				|  |  | +        this.addClickListeners(KEY_DAILY, KEY_UNDAILY);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        EntryGrid entryGrid = this.getView().getControl("nckd_entryentity");
 | 
	
		
			
				|  |  | +        entryGrid.addCellClickListener(this);
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    @Override
 | 
	
		
			
				|  |  | +    public void click(EventObject evt) {
 | 
	
		
			
				|  |  | +        super.click(evt);
 | 
	
		
			
				|  |  | +        //获取被点击的控件对象
 | 
	
		
			
				|  |  | +        Control source = (Control) evt.getSource();
 | 
	
		
			
				|  |  | +        if (StringUtils.equals(source.getKey(), KEY_DAILY)) {
 | 
	
		
			
				|  |  | +            DynamicObjectCollection orgCol = (DynamicObjectCollection) this.getModel().getValue("nckd_org");
 | 
	
		
			
				|  |  | +            if(orgCol==null || orgCol.size()==0){
 | 
	
		
			
				|  |  | +                this.getView().showMessage("请先选择组织");
 | 
	
		
			
				|  |  | +                return;
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            Date dailydate = (Date) this.getModel().getValue("nckd_dailydate");
 | 
	
		
			
				|  |  | +            if(dailydate==null || "".equals(dailydate)){
 | 
	
		
			
				|  |  | +                this.getView().showMessage("请先选择日期");
 | 
	
		
			
				|  |  | +                return;
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            String message = dailyData(orgCol,dailydate);
 | 
	
		
			
				|  |  | +            this.getView().showMessage(message);
 | 
	
		
			
				|  |  | +        }else if (StringUtils.equals(source.getKey(), KEY_UNDAILY)) {
 | 
	
		
			
				|  |  | +            DynamicObjectCollection orgCol = (DynamicObjectCollection) this.getModel().getValue("nckd_org");
 | 
	
		
			
				|  |  | +            if(orgCol==null || orgCol.size()==0){
 | 
	
		
			
				|  |  | +                this.getView().showMessage("请先选择组织");
 | 
	
		
			
				|  |  | +                return;
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            Date dailydate = (Date) this.getModel().getValue("nckd_dailydate");
 | 
	
		
			
				|  |  | +            if(dailydate==null || "".equals(dailydate)){
 | 
	
		
			
				|  |  | +                this.getView().showMessage("请先选择日期");
 | 
	
		
			
				|  |  | +                return;
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            String message = unDailyData(orgCol,dailydate);
 | 
	
		
			
				|  |  | +            this.getView().showMessage(message);
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    /*
 | 
	
		
			
				|  |  | +     * 反日结操作
 | 
	
		
			
				|  |  | +     */
 | 
	
		
			
				|  |  | +    private String unDailyData(DynamicObjectCollection orgCol, Date dailydate) {
 | 
	
		
			
				|  |  | +        String returnMessage = "";
 | 
	
		
			
				|  |  | +        for(DynamicObject orgObj : orgCol){
 | 
	
		
			
				|  |  | +            DynamicObject orgObjReal = orgObj.getDynamicObject("fbasedataid");
 | 
	
		
			
				|  |  | +            QFilter qFilter_org = new QFilter("nckd_org", QCP.equals,orgObjReal.getPkValue());
 | 
	
		
			
				|  |  | +            QFilter qFilter_bizdate = new QFilter("nckd_dailydate",QCP.equals,dailydate);
 | 
	
		
			
				|  |  | +            DynamicObject[] dailybillCol = BusinessDataServiceHelper.load("nckd_gl_dailybill","id",
 | 
	
		
			
				|  |  | +                    new QFilter[]{qFilter_org,qFilter_bizdate});
 | 
	
		
			
				|  |  | +            if(dailybillCol!=null && dailybillCol.length>0){
 | 
	
		
			
				|  |  | +                DynamicObject dailybilloObj = dailybillCol[0];
 | 
	
		
			
				|  |  | +                DeleteServiceHelper.delete("nckd_gl_dailybill",
 | 
	
		
			
				|  |  | +                        new QFilter("id", QCP.equals, dailybilloObj.getPkValue()).toArray());
 | 
	
		
			
				|  |  | +                returnMessage = returnMessage + orgObjReal.getString("name") + "反日结成功;";;
 | 
	
		
			
				|  |  | +            }else{
 | 
	
		
			
				|  |  | +                returnMessage = returnMessage + orgObjReal.getString("name") + "日结失败,所选日期未存在日结记录;\r\n";
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        return returnMessage;
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    /*
 | 
	
		
			
				|  |  | +    * 查询凭证,符合条件的组织插入日结记录,不符合条件的显示在表格中
 | 
	
		
			
				|  |  | +     */
 | 
	
		
			
				|  |  | +    private String dailyData(DynamicObjectCollection orgCol, Date dailydate) {
 | 
	
		
			
				|  |  | +        String returnMessage = "";
 | 
	
		
			
				|  |  | +        for(DynamicObject orgObj : orgCol){
 | 
	
		
			
				|  |  | +            boolean isCan = true;
 | 
	
		
			
				|  |  | +            DynamicObject orgObjReal = orgObj.getDynamicObject("fbasedataid");
 | 
	
		
			
				|  |  | +            QFilter qFilter_org = new QFilter("org", QCP.equals,orgObjReal.getPkValue());
 | 
	
		
			
				|  |  | +            QFilter qFilter_bizdate = new QFilter("bizdate",QCP.equals,dailydate);
 | 
	
		
			
				|  |  | +            DynamicObject[] voucherCol = BusinessDataServiceHelper.load("gl_voucher","id,ispost,billno,bizdate,org,billstatus",
 | 
	
		
			
				|  |  | +                    new QFilter[]{qFilter_org,qFilter_bizdate});
 | 
	
		
			
				|  |  | +            for(DynamicObject voucherObj : voucherCol){
 | 
	
		
			
				|  |  | +                boolean ispost = voucherObj.getBoolean("ispost");
 | 
	
		
			
				|  |  | +                if(ispost!=true){//是否过账等于否
 | 
	
		
			
				|  |  | +                    isCan = false;
 | 
	
		
			
				|  |  | +                    int rowid = this.getModel().createNewEntryRow("nckd_entryentity");
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +                    this.getModel().setValue("nckd_voucherorg",orgObj,rowid);//设置组织
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +                    String voucherid = voucherObj.getString("id");
 | 
	
		
			
				|  |  | +                    this.getModel().setValue("nckd_vouherid",voucherid,rowid);//设置凭证id
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +                    String billno = voucherObj.getString("billno");
 | 
	
		
			
				|  |  | +                    this.getModel().setValue("nckd_vouhernumber",billno,rowid);//设置凭证号
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +                    Date bizdate = voucherObj.getDate("bizdate");
 | 
	
		
			
				|  |  | +                    this.getModel().setValue("nckd_voucherdate",bizdate,rowid);//设置凭证日期
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +                    String billstatus = voucherObj.getString("billstatus");
 | 
	
		
			
				|  |  | +                    this.getModel().setValue("nckd_voucherstatus",billstatus,rowid);//设置凭证状态
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            //写入日结记录
 | 
	
		
			
				|  |  | +            String messageInfo = writeDailybill(isCan,orgObjReal,dailydate);
 | 
	
		
			
				|  |  | +            returnMessage = returnMessage + messageInfo + "\r\n";
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        return returnMessage;
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    private String writeDailybill(boolean isCan, DynamicObject orgObjReal, Date dailydate) {
 | 
	
		
			
				|  |  | +        String messageInfo = "";
 | 
	
		
			
				|  |  | +        try {
 | 
	
		
			
				|  |  | +            if (isCan == true) {
 | 
	
		
			
				|  |  | +                DynamicObject dailybillObj = BusinessDataServiceHelper.newDynamicObject("nckd_gl_dailybill");
 | 
	
		
			
				|  |  | +                dailybillObj.set("nckd_org", orgObjReal);
 | 
	
		
			
				|  |  | +                dailybillObj.set("nckd_dailydate", dailydate);
 | 
	
		
			
				|  |  | +                dailybillObj.set("status", "A");
 | 
	
		
			
				|  |  | +                dailybillObj.set("enable", "1");
 | 
	
		
			
				|  |  | +                RequestContext rc = RequestContext.get();
 | 
	
		
			
				|  |  | +                dailybillObj.set("creator", rc.getUid());
 | 
	
		
			
				|  |  | +                DynamicObject[] datalist = new DynamicObject[]{dailybillObj};
 | 
	
		
			
				|  |  | +                SaveServiceHelper.save(datalist);
 | 
	
		
			
				|  |  | +                messageInfo = orgObjReal.getString("name") + "日结成功;";
 | 
	
		
			
				|  |  | +            } else {
 | 
	
		
			
				|  |  | +                messageInfo = orgObjReal.getString("name") + "日结失败,所选日期存在未过账凭证;";
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +        }catch(Exception e){
 | 
	
		
			
				|  |  | +            messageInfo = orgObjReal.getString("name") + "日结失败,"+e.getMessage()+";";
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        return messageInfo;
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    @Override
 | 
	
		
			
				|  |  | +    public void cellClick(CellClickEvent cellClickEvent) {
 | 
	
		
			
				|  |  | +        BillShowParameter billShowParameter = new BillShowParameter();
 | 
	
		
			
				|  |  | +        billShowParameter.getOpenStyle().setShowType(ShowType.Modal);
 | 
	
		
			
				|  |  | +        billShowParameter.setFormId("gl_voucher");
 | 
	
		
			
				|  |  | +        int row = this.getModel().getEntryCurrentRowIndex("nckd_entryentity");
 | 
	
		
			
				|  |  | +        String voucherid = this.getModel().getValue("nckd_vouherid",row).toString();
 | 
	
		
			
				|  |  | +        billShowParameter.setPkId(voucherid);
 | 
	
		
			
				|  |  | +        getView().showForm(billShowParameter);
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    @Override
 | 
	
		
			
				|  |  | +    public void cellDoubleClick(CellClickEvent cellClickEvent) {
 | 
	
		
			
				|  |  | +        //
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  |  }
 |