package nckd.jimin.jyyy.fi.plugin.form.botp;

import kd.bos.dataentity.entity.DynamicObject;
import kd.bos.entity.datamodel.IDataModel;
import kd.bos.form.IFormView;
import kd.bos.form.events.SetFilterEvent;
import kd.bos.orm.query.QCP;
import kd.bos.orm.query.QFilter;
import kd.fi.er.business.utils.ErEntityTypeUtils;
import kd.fi.er.formplugin.publicbiz.botp.up.UpDrawContract;
import java.util.List;

/**
 * PC关联合同台账：nckd_er_contract_draw_ext
 * @author wanghaiwu_kd
 * @date 2025/09/30
 */
public class UpDrawContractExtListPlugin extends UpDrawContract{
    @Override
    public void setFilter(SetFilterEvent e) {
        super.setFilter(e);
        IFormView parentView = this.getView().getParentView();
        if (parentView != null) {
            IDataModel pModel = parentView.getModel();
            String formId = parentView.getEntityId();

            if (ErEntityTypeUtils.isPublicReimburseBill(formId) || ErEntityTypeUtils.isPrePayBill(formId)) {
                List<QFilter> qFilters = e.getCustomQFilters();
                if (qFilters != null && qFilters.size() > 0) {
                    QFilter qFilter = qFilters.get(0);

                    DynamicObject project = (DynamicObject) pModel.getValue("nckd_project");

                    if(project != null){
                        String projectNumber = project.getString("number");
                        if(projectNumber.indexOf(".") > 0) {
                            projectNumber = projectNumber.substring(0, projectNumber.indexOf("."));
                        }

//                        qFilter.and(new QFilter("expenseentryentity.std_project.number", QCP.like, projectNumber +"%"));
                        //增加表头的项目过滤
                        qFilter.and(new QFilter("nckd_project.number", QCP.like, projectNumber +"%"));
                    }
                }
            }
        }

    }
}
