|  | @@ -0,0 +1,178 @@
 | 
	
		
			
				|  |  | +package nckd.wnq01.wnq.scm.plugin.form;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +import kd.bos.dataentity.entity.DynamicObject;
 | 
	
		
			
				|  |  | +import kd.bos.dataentity.entity.DynamicObjectCollection;
 | 
	
		
			
				|  |  | +import kd.bos.dataentity.metadata.IDataEntityProperty;
 | 
	
		
			
				|  |  | +import kd.bos.dataentity.metadata.clr.DataEntityPropertyCollection;
 | 
	
		
			
				|  |  | +import kd.bos.dataentity.resource.ResManager;
 | 
	
		
			
				|  |  | +import kd.bos.entity.datamodel.IDataModel;
 | 
	
		
			
				|  |  | +import kd.bos.form.ConfirmCallBackListener;
 | 
	
		
			
				|  |  | +import kd.bos.form.FormShowParameter;
 | 
	
		
			
				|  |  | +import kd.bos.form.IFormView;
 | 
	
		
			
				|  |  | +import kd.bos.form.MessageBoxOptions;
 | 
	
		
			
				|  |  | +import kd.bos.form.control.Control;
 | 
	
		
			
				|  |  | +import kd.bos.form.field.BasedataEdit;
 | 
	
		
			
				|  |  | +import kd.bos.form.field.FieldEdit;
 | 
	
		
			
				|  |  | +import kd.bos.form.field.MulBasedataEdit;
 | 
	
		
			
				|  |  | +import kd.bos.form.field.events.BeforeF7SelectEvent;
 | 
	
		
			
				|  |  | +import kd.bos.form.field.events.BeforeF7SelectListener;
 | 
	
		
			
				|  |  | +import kd.bos.form.plugin.AbstractFormPlugin;
 | 
	
		
			
				|  |  | +import kd.bos.list.ListShowParameter;
 | 
	
		
			
				|  |  | +import kd.bos.orm.query.QCP;
 | 
	
		
			
				|  |  | +import kd.bos.orm.query.QFilter;
 | 
	
		
			
				|  |  | +import kd.fi.er.business.servicehelper.BaseCurrencyServiceHelper;
 | 
	
		
			
				|  |  | +import kd.fi.er.business.servicehelper.CommonServiceHelper;
 | 
	
		
			
				|  |  | +import kd.fi.er.business.servicehelper.CoreBaseBillServiceHelper;
 | 
	
		
			
				|  |  | +import kd.fi.er.business.utils.ErCommonUtils;
 | 
	
		
			
				|  |  | +import kd.fi.er.business.utils.ErCostCenterUtil;
 | 
	
		
			
				|  |  | +import kd.fi.er.business.utils.ErEntityTypeUtils;
 | 
	
		
			
				|  |  | +import kd.fi.er.business.utils.SystemParamterUtil;
 | 
	
		
			
				|  |  | +import kd.fi.er.common.ControlMethodEnum;
 | 
	
		
			
				|  |  | +import org.apache.commons.lang.StringUtils;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +import java.math.BigDecimal;
 | 
	
		
			
				|  |  | +import java.util.*;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +/**
 | 
	
		
			
				|  |  | + * @Author: Boil
 | 
	
		
			
				|  |  | + * @Date: 2025/5/11 12:58
 | 
	
		
			
				|  |  | + * @Version: v1.0.0
 | 
	
		
			
				|  |  | + * @Description: TODO
 | 
	
		
			
				|  |  | + **/
 | 
	
		
			
				|  |  | +public class PtEntryEdit extends AbstractFormPlugin implements BeforeF7SelectListener {
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    public static String entryKey="nckd_putentry";
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    @Override
 | 
	
		
			
				|  |  | +    public void registerListener(EventObject e) {
 | 
	
		
			
				|  |  | +        super.registerListener(e);
 | 
	
		
			
				|  |  | +        this.addClickListeners("btnok");
 | 
	
		
			
				|  |  | +        BasedataEdit bEdit = this.getView().getControl("nckd_xqys");
 | 
	
		
			
				|  |  | +        bEdit.addBeforeF7SelectListener(this);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    public void afterCreateNewData(EventObject e) {
 | 
	
		
			
				|  |  | +        super.afterCreateNewData(e);
 | 
	
		
			
				|  |  | +        IFormView parentView = this.getView().getParentView();
 | 
	
		
			
				|  |  | +        if (parentView != null) {
 | 
	
		
			
				|  |  | +            IDataModel parentModel = parentView.getModel();
 | 
	
		
			
				|  |  | +            IDataModel model = this.getModel();
 | 
	
		
			
				|  |  | +            this.setRowIndexPageCache();
 | 
	
		
			
				|  |  | +            int tripEntryRowIndex = Integer.parseInt(this.getPageCache().get("tripEntryRowIndex"));
 | 
	
		
			
				|  |  | +            if (tripEntryRowIndex != -1) {
 | 
	
		
			
				|  |  | +                DynamicObject tripEntry = parentModel.getEntryRowEntity(entryKey, tripEntryRowIndex);
 | 
	
		
			
				|  |  | +                DataEntityPropertyCollection tripEntryProps = tripEntry.getDataEntityType().getProperties();
 | 
	
		
			
				|  |  | +                for(IDataEntityProperty property : model.getDataEntityType().getProperties()) {
 | 
	
		
			
				|  |  | +                    String propertyName = property.getName();
 | 
	
		
			
				|  |  | +                    if (tripEntryProps.get(propertyName) != null) {
 | 
	
		
			
				|  |  | +                        model.setValue(propertyName, ErCommonUtils.getObjectValue(tripEntry.get(propertyName)));
 | 
	
		
			
				|  |  | +                    }
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    private void setRowIndexPageCache() {
 | 
	
		
			
				|  |  | +        FormShowParameter formShowParameter = this.getView().getFormShowParameter();
 | 
	
		
			
				|  |  | +        Map<String, Object> customParams = formShowParameter.getCustomParams();
 | 
	
		
			
				|  |  | +        String tripRowIndex = "-1";
 | 
	
		
			
				|  |  | +        if (customParams.get("tripEntryRowIndex") != null) {
 | 
	
		
			
				|  |  | +            tripRowIndex = customParams.get("tripEntryRowIndex").toString();
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        this.getPageCache().put("tripEntryRowIndex", tripRowIndex);
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    @Override
 | 
	
		
			
				|  |  | +    public void click(EventObject evt) {
 | 
	
		
			
				|  |  | +        super.click(evt);
 | 
	
		
			
				|  |  | +        IDataModel model = this.getModel();
 | 
	
		
			
				|  |  | +        switch (((Control)evt.getSource()).getKey()) {
 | 
	
		
			
				|  |  | +            case "btnok":
 | 
	
		
			
				|  |  | +                IFormView parentView = this.getView().getParentView();
 | 
	
		
			
				|  |  | +                IDataModel parentModel = parentView.getModel();
 | 
	
		
			
				|  |  | +                //String formId = (String)parentModel.getValue("formid");
 | 
	
		
			
				|  |  | +                this.clickOk(model, parentView, parentModel, null);
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    protected void clickOk(IDataModel model, IFormView parentView, IDataModel parentModel, String formId) {
 | 
	
		
			
				|  |  | +        this.getView().setEnable(false, new String[]{"btnok"});
 | 
	
		
			
				|  |  | +        DataEntityPropertyCollection tripEntryProps = parentModel.getDataEntity(true).getDynamicObjectCollection(entryKey).getDynamicObjectType().getProperties();
 | 
	
		
			
				|  |  | +        int tripEntryRowIndex = Integer.parseInt(this.getPageCache().get("tripEntryRowIndex"));
 | 
	
		
			
				|  |  | +        DataEntityPropertyCollection properties = model.getDataEntityType().getProperties();
 | 
	
		
			
				|  |  | +        Map<String, Object> returnParam = new HashMap();
 | 
	
		
			
				|  |  | +        DynamicObjectCollection tripEntry = parentModel.getDataEntity().getDynamicObjectCollection(entryKey);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        if (tripEntryRowIndex == -1) {
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +                int rowIndex = parentModel.createNewEntryRow(entryKey);
 | 
	
		
			
				|  |  | +                parentModel.setEntryCurrentRowIndex(entryKey, rowIndex);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +                for(IDataEntityProperty property : properties) {
 | 
	
		
			
				|  |  | +                    if (tripEntry.size() > 0) {
 | 
	
		
			
				|  |  | +                        String propertyName = property.getName();
 | 
	
		
			
				|  |  | +                        if (tripEntryProps.get(propertyName) != null) {
 | 
	
		
			
				|  |  | +                            parentModel.setValue(propertyName, ErCommonUtils.getObjectValue(model.getValue(propertyName)), rowIndex);
 | 
	
		
			
				|  |  | +                        }
 | 
	
		
			
				|  |  | +                    }
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            returnParam.put("isUpdate", false);
 | 
	
		
			
				|  |  | +        } else if (parentModel.getEntryEntity(entryKey).size() > 0) {
 | 
	
		
			
				|  |  | +            //if (tripEntryRowIndex == 0) {
 | 
	
		
			
				|  |  | +                for (IDataEntityProperty property : properties) {
 | 
	
		
			
				|  |  | +                    String propertyName = property.getName();
 | 
	
		
			
				|  |  | +                    if (parentModel.getEntryEntity(entryKey).size() > 0 && tripEntryProps.get(propertyName) != null) {
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +                        parentModel.setValue(propertyName, ErCommonUtils.getObjectValue(model.getValue(propertyName)), tripEntryRowIndex);
 | 
	
		
			
				|  |  | +                    }
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +            //}
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +//            if (parentModel.getEntryEntity(entryKey).size() > 0) {
 | 
	
		
			
				|  |  | +//                int entrySize = parentModel.getEntryRowCount("entryentity");
 | 
	
		
			
				|  |  | +//                int tripDay = (Integer)parentModel.getValue("tripday", tripEntryRowIndex);
 | 
	
		
			
				|  |  | +//
 | 
	
		
			
				|  |  | +//                for(int i = 0; i < entrySize; ++i) {
 | 
	
		
			
				|  |  | +//                    parentModel.setValue("daycount", tripDay, i, parentModel.getEntryCurrentRowIndex("tripentry"));
 | 
	
		
			
				|  |  | +//                }
 | 
	
		
			
				|  |  | +//
 | 
	
		
			
				|  |  | +//                returnParam.put("isUpdate", true);
 | 
	
		
			
				|  |  | +//                returnParam.put("currentTripEntryIndex", parentModel.getEntryCurrentRowIndex("tripentry"));
 | 
	
		
			
				|  |  | +//            }
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        returnParam.put("isOK", true);
 | 
	
		
			
				|  |  | +        //returnParam.put("startDate", model.getValue("startDate"));
 | 
	
		
			
				|  |  | +        //returnParam.put("endDate", model.getValue("endDate"));
 | 
	
		
			
				|  |  | +        this.getView().returnDataToParent(returnParam);
 | 
	
		
			
				|  |  | +        this.getView().sendFormAction(parentView);
 | 
	
		
			
				|  |  | +        this.getView().close();
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    @Override
 | 
	
		
			
				|  |  | +    public void beforeF7Select(BeforeF7SelectEvent beforeF7SelectEvent) {
 | 
	
		
			
				|  |  | +        String propertyName = beforeF7SelectEvent.getProperty().getName();
 | 
	
		
			
				|  |  | +        if("nckd_xqys".equals(propertyName)) {
 | 
	
		
			
				|  |  | +            ListShowParameter formShowParameter = (ListShowParameter) beforeF7SelectEvent.getFormShowParameter();
 | 
	
		
			
				|  |  | +            List<QFilter> qFilters = new ArrayList<>();
 | 
	
		
			
				|  |  | +            if(null != this.getModel().getValue("nckd_quyus") ) {
 | 
	
		
			
				|  |  | +                DynamicObject quyus = (DynamicObject) this.getModel().getValue("nckd_quyus");
 | 
	
		
			
				|  |  | +                qFilters.add(new QFilter("nckd_qy.id", QCP.equals, quyus.getPkValue()));
 | 
	
		
			
				|  |  | +                formShowParameter.getListFilterParameter().setQFilters(qFilters);
 | 
	
		
			
				|  |  | +            }else{
 | 
	
		
			
				|  |  | +                this.getView().showErrorNotification("请先选择区域字段");
 | 
	
		
			
				|  |  | +                beforeF7SelectEvent.setCancel(true);
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +}
 |