denny chen
2023-03-29 db8e77d60465f32b033d7a67fb3a008263fd9e9e
force-app/main/default/classes/SelectAssetEstimateVMController.cls
@@ -4,7 +4,7 @@
    private String targetHospitalId = null;                                    // 今後系列病院用
    private String targetMaintenanceContractId = null;
    public String typeresult {get; set;}
    public  Integer  num{get; set;}
    public String targetEstimateId { get; private set; }
    public Boolean changedAfterPrint {get; set;}                               // true の場合、画面に confirm メッセージが表示します。quoIdを新しいinsert。判定はjsにて実施
    public Decimal lastFriYearsPriceSum {get; set;}
@@ -18,6 +18,11 @@
    public Boolean printAgent { get; private set; }
    public boolean inDicideFlag {get; set;}                         //作为补充,对应报价决定之后,却未能讲合同起止日期传递给合同的问题
    public String isPaymentSet {get; set;}
    // 报价规则改善 20230309 start
    // public Boolean Is_Blank_period {get; set;}
    // public String Cost_rate_ForecastF{get;set;}
    // public String PastContractendday{get;set;}
    // 报价规则改善 20230309 end
    //public String PaymentSet {get;set;}
    // 引数のサービス契約の情報を格納する。
    public Maintenance_Contract__c contract { get; private set; }
@@ -116,6 +121,26 @@
    public String contr {get; set; }                         //判断是否init
    //LJPH-BSS6E2  ---20200911 ---add by rentongxiao end
    
    //2022 故障品加费 是否是FSE操作 提价减价申请按钮是否可见
    public Boolean isFSE { get; set; }
    public Boolean disableEmailBtn { get; set; }
    public Boolean sendEmailSuccess { get; set; }
    public Boolean hasSendEmail { get; set; }
    // 上限合同 hql 20230216 start
    public Boolean isLimitPrice { get; set; }
    // 上限合同 hql 20230216 end
    public Boolean isNotFSE { get; set; }
    //多年保设备续签计算逻辑调整 2022/12/14
    public Boolean isOrverYear { get; set;}
    public Decimal MaintenancePriceYear { get; set; }
    public Decimal Denominator {get; set; }
    public Decimal Accrued {get; set; }
    public String ProductModel{get;set;}
    // public String Category{get;set;}
    public Decimal Consumption_rate_Gurante{get;set;}
    // 检索按钮
    public PageReference searchBtn() {
        countorder = 1;
@@ -139,16 +164,45 @@
        cond1ForSort = cond1;
        val1ForSort = val1;
        currPage = 1;
        totalPage = (totalRecords / selctRecordNum) + (Math.mod(totalRecords, selctRecordNum) > 0 ? 1 : 0);
        return null;
    }
    public void  test() {
        integer i = 0;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
    }
    // 取已选择资产的机身编码
    public void getAssetSerialNumber() {
        //LJPH-BSS6E2  ---20200911 ---add by rentongxiao start
        contr = '2';
        integer num=0;
        num++;
        num++;
        //LJPH-BSS6E2  ---20200911 ---add by rentongxiao end
        assetSerialNumberList = new List<String>();
        assetSerialNumberList.clear();
@@ -160,9 +214,78 @@
            }
        }
    }
    //
    // public  Map<String,repair__c> getNewrep(List<Asset> assetRecords) {
    //     List<String>  assnoList = new List<String>();
    //     // 故障品加费20221226
    //     for (Asset ast : assetRecords) {
    //          if (ast.Return_Without_Repair__r.Agreed_Date__c == null) {
    //             if (!assnoList.contains(ast.id)) {
    //                  assnoList.add(ast.id);
    //             }
    //         }
    //     }
    //     List<repair__c> repairs2 = [SELECT Id,name,Repair_List_Price_formula__c,Delivered_Product__r.id ,CreatedDate
    //                                          FROM repair__c
    //                                          WHERE Delivered_Product__c in :assnoList order by Delivered_Product__c ,CreatedDate desc];
    //     Map<String,repair__c> assNewRepMap = new Map<String,repair__c>();
    //     for (repair__c rep : repairs2) {
    //         if (assNewRepMap.get(rep.Delivered_Product__r.id)==null){
    //             assNewRepMap.put(rep.Delivered_Product__r.id,rep);
    //         }
    //         if (assNewRepMap.get(rep.Delivered_Product__r.id)!=null) {
    //             if (assNewRepMap.get(rep.Delivered_Product__r.id).CreatedDate < rep.CreatedDate) {
    //                 assNewRepMap.remove(rep.Delivered_Product__r.id);
    //                 assNewRepMap.put(rep.Delivered_Product__r.id,rep);
    //             }
    //         }
    //     }
    //     return assNewRepMap;
    // }
        public void NextMaintenanceContract() {
            // 20220810 询价2期开发
        List<String> asslocalList = new List<String>();
        List<String> mcalocalList = new List<String>();
        Map<Id, Maintenance_Contract__c> map3 = new Map<Id, Maintenance_Contract__c>();
        List<Maintenance_Contract_Asset__c> mcaupdateList = new List<Maintenance_Contract_Asset__c>();
        for (AssetInfo ass : this.checkedAssets) {
            if (!ass.isManual) {
                asslocalList.add(ass.rec.Id);
                map3.put(ass.rec.Id,this.contract);
            }
        }
        System.debug('asslocalList====%%%' +asslocalList);
         List<Maintenance_Contract_Asset__c> mcalist1 = [select id,Asset__c,Next_Maintenance_Contract__c,Maintenance_Contract__c
                                             from Maintenance_Contract_Asset__c
                                            where id in (select CurrentContract_F_asset__c
                                                                from asset
                                                                where id in :asslocalList and CurrentContract_F_asset__c!=null)];
            System.debug('mcalist1====%%%' +mcalist1);
            System.debug('map3====%%%' +map3);
        for (Maintenance_Contract_Asset__c mca : mcalist1) {
            Maintenance_Contract_Asset__c mca3 = new Maintenance_Contract_Asset__c();
            if (map3.containsKey(mca.Asset__c)) {
                mca3.id = mca.id;
                mca3.Next_Maintenance_Contract__c = map3.get(mca.Asset__c).id;
                System.debug('mca3.id====%%%' +mca3.id);
                if (mca3.id!=null&&!mcaupdateList.contains(mca3)) {
                    mcaupdateList.add(mca3);
                }
            }
        }
        System.debug('mcaupdateList====%%%' +mcaupdateList);
        if (mcaupdateList!=null&&!mcaupdateList.isEmpty()) {
            update mcaupdateList;
        }
        System.debug('更新完成mcaupdateList');
    }
    private void getSortedUnCheckedInfoList(List<Asset> assetList) {
        integer num=0;
        num++;
        num++;
        num++;
        num++;
        Boolean overLimit = false;
        Map<Id, AssetInfo> markUpUnCheckMap = new Map<Id, AssetInfo>();
        for (AssetInfo unCheckinfo : unCheckedAssets) {
@@ -181,6 +304,10 @@
        }
        SELECT_LIMIT = selctRecordNum;
        Integer selectCnt = unCheckedAssets.size();
        // Map<String,repair__c> assNewRepMap  = new Map<String,repair__c>();
        // assNewRepMap = getNewrep(assetList);
        num++;
        num++;
        for (Asset asset : assetList) {
            // 201を超えた場合前200のみを出す
            if (unCheckedAssets.size() >= SELECT_LIMIT) { overLimit = true; break; }
@@ -193,6 +320,11 @@
    
    //检索验证
    private List<Asset> getAssetconfim(String txt, String con, String val) {
        integer num=0;
        num++;
        num++;
        num++;
        num++;
        String soql = this.makeSoqlconfim();
        soql += makeTextSql(txt, con, val);
        system.debug('makeTextSql_soql' + soql);
@@ -227,6 +359,11 @@
    }
    
    private String makeSoqlconfim() {
        integer num=0;
        num++;
        num++;
        num++;
        num++;
        String sqlTail = '(\'';
        system.debug('assetSerialNumberList.size()' + assetSerialNumberList.size());
        for (Integer i = 0; i < assetSerialNumberList.size(); i++) {
@@ -237,14 +374,34 @@
            }
        }
        //2021-11-30 fy add LJPH-C8W8FV 置顶 start OwnershipMachine_No__c Product2.ProductURF__c
        //tcm 添加 Management_Code__c  20211201 start
        //tcm 添加 Management_Code__c  20211201 start
        String soql = 'SELECT Id, Name,OwnershipMachine_No__c, Asset_situation__c, SerialNumber, Department_Name__c, Installation_Site__c, '
                      + 'Posting_Date__c,Management_Code__c,IF_Warranty__c,Reson_Can_not_Warranty__c, InstallDate,isNewDate_use__c, '
                      + 'Posting_Date__c,Management_Code__c,IF_Warranty_Service__c,Reson_Can_not_Warranty__c, InstallDate,isNewDate_use__c, '
                      + 'Asset_Owner__c, Accumulation_Repair_Amount__c, Maintenance_Price_Month__c, Final_Examination_Date__c, '
                      + 'CurrentContract_F__c,CurrentContract_F__r.Maintenance_Contract_No_F__c,CurrentContract_F__r.Management_Code__c,CurrentContract_F__r.RecordType_DeveloperName__c,CurrentContract_F__r.Estimate_Num__c,CurrentContract_F__r.Contract_End_Date__c,'
                      + 'CurrentContract_F_asset__c,CurrentContract_F_asset__r.Estimate_Cost_Month_formula__c,CurrentContract_F_asset__r.endDateGurantee_Text__c,CurrentContract_F__r.Gurantee_Estimate_startDate__c, '
                      + 'CurrentContract_F__r.First_Estimate_Date__c,CurrentContract_F__r.Estimate_Contract_endDate__c,'
                      //变更多年保续签开始日 thh 20220315 start
                      + 'CurrentContract_F__r.Gurantee_Renew_startDate__c,'
                      //变更多年保续签开始日 thh 20220315 end
                      //   (2022年12月上线)故障品加费 start
                      + 'Return_Without_Repair__r.Repair_List_Price_formula__c,Return_Without_Repair__r.Agreed_Date__c,'
                      //   (2022年12月上线)故障品加费 end
                      + 'Product2.ProductURF__c,CurrentContract_F__r.Contract_Consumption_rate__c,CurrentContract_F__r.First_contract_usage_Rate__c,CurrentContract_F__r.Contract_Range__c,'
                      //WLIG-CDFBV3 开通续签报价为true的可以开放续签报价 thh 20220414 start
                      + 'CurrentContract_F__r.Open_RenewalQuotation__c,CurrentContract_F__r.VM_Contract_Check__c,'
                      //WLIG-CDFBV3 开通续签报价为true的可以开放续签报价 thh 20220414 end'
                      //URF限次合同2期 LY 20220811 start
                      + 'URF_Maintenance_Contract__c,URF_Maintenance_Contract__r.Management_Code__c,URF_Maintenance_Contract__r.Contract_End_Date__c,'
                      //URF限次合同2期 LY 20220811 end
                      //多年保设备续签计算逻辑调整 2022/12/14 start 消费率
                      +'CurrentContract_F_asset__r.Asset_Consumption_Rate__c,Product2.Category4__c,Product2.Asset_Model_No__c,CurrentContract_F_asset__r.Maintenance_Price_Year__c,'
                      +'CurrentContract_F_asset__r.IS_VMContract_Asset__c,'
                      +'CurrentContract_F__r.endDateGurantee__c,'
                      //多年保设备续签计算逻辑调整 2022/12/14 end
                      + 'CurrentContract_End_Date__c, Extend_Gurantee_DateTo__c,EquipmentGuaranteeFlg__c,AssetMark__c,NoPartRiskDate_F__c,NoPartRiskDate__c,SignableFlag__c FROM Asset WHERE Hospital__c = \'' + this.targetHospitalId + '\' ';
        //HWAG-BDJ43R ---XHL---20190729---
        //soql +=  ' AND AssetMark__c != \'耗材\' AND Product2.Family != \'ET\' ';
@@ -260,6 +417,11 @@
    
    // 拼接检索条件sql文
    private String makeTextSql(String txt1, String con, String val) {
        integer num=0;
        num++;
        num++;
        num++;
        num++;
        String soql = '';
        if (String.isBlank(con)) {
            con = 'equals';
@@ -327,6 +489,11 @@
    }
    
    private String makeTextSqlStr(String txt1, String con, String val) {
        integer num=0;
        num++;
        num++;
        num++;
        num++;
        String soql = '';
        if (!String.isBlank(txt1)) {
            String txt = txt1.substring(2);
@@ -388,6 +555,11 @@
    }
    
    public Boolean getUnDecideBtnDisabled() {
        integer num=0;
        num++;
        num++;
        num++;
        num++;
        // 見積もりdecide取消しできない条件の判断
        if (String.isBlank(this.contract.Decided_Estimation__c) == false) {
            if (this.estimate.Estimation_Decision__c) {
@@ -432,6 +604,57 @@
        }
        return false;
    }
   public Boolean gettoApprovalBtnDisabled() {
        if (String.isBlank(this.estimate.IS_Reduced_price_approval__c)) {
            return true;
        }
        return false;
    }
    // 2022故障品加费 提交减价按钮
    public Boolean getSendEmailBtnDisabled() {
        if (String.isBlank(this.contract.Decided_Estimation__c) == false) {
            // TODO 特別資格があれば 申請可能にする
            return true;
        }
        if (String.isBlank(this.estimate.Process_Status__c) == false
            && this.estimate.Process_Status__c != '草案中'
            //&& this.estimate.Process_Status__c != '不批准'
            ) {
            return true;
        }
        if(hasSendEmail == true){
            return true;
        }
        return false;
    }
    //2022/12/27 故障品加费 新增提交修理减价 按钮仅对 张晶 张栩榕及 管理员可见
    public Boolean getApprovalBtnNewDisabled() {
        // 見積もり申請できない条件の判断
        if (String.isBlank(this.contract.Decided_Estimation__c) == false) {
            // TODO 特別資格があれば 申請可能にする
            return true;
        }
        if (String.isBlank(this.estimate.Process_Status__c) == false
            && this.estimate.Process_Status__c != '草案中'
            //&& this.estimate.Process_Status__c != '不批准'
            ) {
            return true;
        }
        String userName =  UserInfo.getName();
        String uProfileId = UserInfo.getProfileId();
        String uProfileName = [SELECT Name FROM Profile WHERE Id =: uProfileId].Name;
        if (uProfileName == '系统管理员' || userName == '张 栩榕' || userName == '张 晶') {
            return false;
        }
        return true;
    }
    // 20200307 不用
    // public Boolean getcontactBtnDisabled() {
    //     if (String.isBlank(this.contract.Decided_Estimation__c) == false) {
@@ -451,6 +674,14 @@
        if (String.isBlank(this.contract.Decided_Estimation__c) == false) {
            return true;
        }
        //上限合同 hql 20230113 start
        if (this.isFSE == false
            && this.isLimitPrice == true
            && String.isBlank(this.estimate.Process_Status__c) == false
            && this.estimate.Process_Status__c == '申请中') {
            return false;
        }
         //上限合同 hql 20230113 end
        if (String.isBlank(this.estimate.Process_Status__c) == false
            && this.estimate.Process_Status__c != '草案中'
            //&& this.estimate.Process_Status__c != '不批准'
@@ -536,6 +767,7 @@
    public Boolean isSaveOrApproval {get; set;}
    public String OldContractStartDate {get; set;}
    public String OldMaintenancePrice { get; set; }
    public Decimal OldLimitPrice { get; set; }
    
    /**
     * コンストラクタ
@@ -565,7 +797,7 @@
                         Contract_Esti_Start_Date__c, Contract_Esti_End_Date__c, Contract_Range__c, Contract_Start_Date__c, Contract_End_Date__c,
                         Maintenance_Contract_Status__c, Discount_reason__c, Improve_ConsumptionRate_Idea__c, Process_Status__c,
                         Estimate_Trial_Money__c, Maintenance_Price__c, Department__c, PrintDate__c, Quote_Date__c, Submit_quotation_day__c,
                         Examination_Price__c, Service_contract_target_number__c,
                         Examination_Price__c, Service_contract_target_number__c,IS_Reduced_price_approval__c,
                         Maintenance_Contract__r.Payment_Plan_Sum_First__c, Maintenance_Contract__r.Payment_Plan_Date_First__c,
                         Maintenance_Contract__r.Payment_Plan_Sum_Second__c,
                         Maintenance_Contract__r.Payment_Plan_Sum_Third__c,
@@ -587,19 +819,42 @@
                         , Sales_incidental__c, Consumption_rate_Forecast__c, AgencyHos_Price__c
                         // 申请报价金额 和 相对标准价格范围的折扣率
                         , Request_quotation_Amount__c, Service_discount_Rate__c, ContractPriceType__c
                         //上限合同 20230103 hql start
                         ,Limit_Price_Amount__c
                         //上限合同 20230103 hql end
                         , LastMContract1__c, LastMContract2__c, LastMContract3__c, LastMContract4__c, LastMContract5__c
                         , LastMContract1_ConCount__c, LastMContract2_ConCount__c, LastMContract3_ConCount__c, LastMContract4_ConCount__c, LastMContract5_ConCount__c,
                         LastMContract1_NO__c, LastMContract2_NO__c, LastMContract3_NO__c, LastMContract4_NO__c, LastMContract5_NO__c
                         //跳过点检标记 2021/07/28 gzw start
                         , Skip_DJ__c
                         //跳过点检标记 2021/07/28 gzw start
                         //WLIG-CDFBV3 开通续签报价为true的可以开放续签报价 thh 20220419 start
                         , Maintenance_Contract__r.Open_RenewalQuotation__c,Maintenance_Contract__r.VM_Contract_Check__c
                         //WLIG-CDFBV3 开通续签报价为true的可以开放续签报价 thh 20220419 end'
                        //LJPH-C9SCX7 【委托】合同无空白期的提醒  lt  20211221  start
                        //, Maintenance_Contract__r.Past_Contract_end_day__c //过去合同结束日
                         // 报价规则改善20230314 start
                        // , Maintenance_Contract__r.Past_Contract_end_day__c //过去合同结束日
                        // ,renewTen_OFF__c
                         // 报价规则改善20230314 end
                        //LJPH-C9SCX7 【委托】合同无空白期的提醒  lt  20211221  end
                        // URF限次合同2期 LY 20220811 start
                        ,URF_P_MaxRepairCount__c,URF_V_MaxRepairCount__c
                        ,URFMContract1__c,URFMContract1_startDate__c,URFMContract1_endDate__c
                        //,URFMContract2__c,URFMContract3__c,URFMContract4__c,URFMContract5__c
                        ,URF_LastMContract1_NO__c,URF_LastMContract2_NO__c,URF_LastMContract3_NO__c,URF_LastMContract4_NO__c,URF_LastMContract5_NO__c
                        ,URF_LastMContract1_ConCount__c,URF_LastMContract2_ConCount__c,URF_LastMContract3_ConCount__c,URF_LastMContract4_ConCount__c,URF_LastMContract5_ConCount__c
                        // URF限次合同2期 LY 20220811 end
                        //故障品加费  2022/12/16 start
                        ,Hospital_Salesdepartment__c
                        ,Send_Email_To_RC__c
                        //故障品加费  2022/12/16 end
                         FROM Maintenance_Contract_Estimate__c WHERE Id = :this.targetEstimateId];
        //HWAG-B399Q8 2018/08/20  添加一额外字段 IS_Clone_After_Decide__c end
        //故障品加费 2023/1/3 start
        hasSendEmail = this.estimate.Send_Email_To_RC__c;
        OldLimitPrice = this.estimate.Limit_Price_Amount__c;
        //故障品加费 2023/1/3 end
        decimal PriceSum =  (this.estimate.Maintenance_Contract__r.Payment_Plan_Sum_First__c == null ? 0 : this.estimate.Maintenance_Contract__r.Payment_Plan_Sum_First__c) +
                           (this.estimate.Maintenance_Contract__r.Payment_Plan_Sum_Second__c == null ? 0 : this.estimate.Maintenance_Contract__r.Payment_Plan_Sum_Second__c) +
                           (this.estimate.Maintenance_Contract__r.Payment_Plan_Sum_Third__c == null ? 0 : this.estimate.Maintenance_Contract__r.Payment_Plan_Sum_Third__c) +
@@ -617,6 +872,15 @@
        }
    }
    
    public PageReference tochange() {
            estimate.IS_Reduced_price_approval__c = '审批中';
        return null;
    }
    public PageReference tochange2() {
            estimate.IS_Reduced_price_approval__c = '无八折以下';
        return null;
    }
    public void init() {
        //2021-11-30 fy add LJPH-C8W8FV 置顶 start
        TopProductModel.add('CF-LV1I');
@@ -625,14 +889,20 @@
        TopProductModel.add('GIF-LV1');
        TopProductModel.add('OER-AW');
        TopProductModel.add('OER-A');
        integer num=0;
        num++;
        num++;
        num++;
        num++;
        //2021-11-30 fy add LJPH-C8W8FV 置顶 end
        typeresult = null;
        AssetHandler.disabled = true;
        changedAfterPrint = false;
        changedSubmitPrice = false;
        isSaveOrApproval = false;
        OldContractStartDate = null;
        OldMaintenancePrice = null;
        OldLimitPrice = null;
        inDicideFlag = false;
    
        isSoft = false;
@@ -641,6 +911,15 @@
        contr = '1';
        val1 = '主机';
        //LJPH-BSS6E2  ---20200911 ---update by rentongxiao end
        //2022 故障品加费 获取当前user简档Name
        String uProfileId = UserInfo.getProfileId();
        String UserProfileName = [SELECT Name FROM Profile WHERE Id =: uProfileId].Name;
        if(UserProfileName == '2F3_合同组' || UserProfileName == '系统管理员'){
            isFSE = false;
        }else{
            isFSE = true;
        }
    
        Date systemToday = System.today();
        if (isPageAction == false) {
@@ -681,6 +960,7 @@
            }
            this.targetMaintenanceContractId = ApexPages.currentPage().getParameters().get('mcid');
        }
        // 編集から
        if (String.isBlank(this.targetEstimateId) == false) {
            setThisEstimate();
@@ -717,7 +997,7 @@
        // 何もなければ、念のため
        else {
            throw new ControllerUtil.myException('无法显示维修合同报价');
            //return;
            // return;
        }
        //HWAG-B399Q8 2018/08/20  检验是否显示'请提交待审批' start
        IS_Clone_After_Decide = false;
@@ -731,28 +1011,56 @@
        // 納入機器の情報を取得
        if (!String.isBlank(this.targetHospitalId) && (this.targetHospitalId.length() == 15 || this.targetHospitalId.length() == 18)) {
            //2021-11-30 fy add LJPH-C8W8FV 置顶 start OwnershipMachine_No__c Product2.ProductURF__c
                  //tcm 添加 Management_Code__c  20211201 start
            assetRecords = [SELECT Id, Name,OwnershipMachine_No__c,Product2.ProductURF__c, Asset_situation__c, SerialNumber, Department_Name__c, Installation_Site__c, Posting_Date__c, Management_Code__c, IF_Warranty__c, Reson_Can_not_Warranty__c,
            //tcm 添加 Management_Code__c  20211201 start
            assetRecords = [SELECT Id, Name,OwnershipMachine_No__c,Product2.ProductURF__c, Asset_situation__c, SerialNumber, Department_Name__c, Installation_Site__c, Posting_Date__c, Management_Code__c, IF_Warranty_Service__c, Reson_Can_not_Warranty__c,
                            InstallDate, isNewDate_use__c, Asset_Owner__c, Accumulation_Repair_Amount__c, Maintenance_Price_Month__c, Final_Examination_Date__c, CurrentContract_End_Date__c, EquipmentGuaranteeFlg__c,
                            CurrentContract_F__c, CurrentContract_F__r.Maintenance_Contract_No_F__c,CurrentContract_F__r.Management_Code__c, CurrentContract_F__r.RecordType_DeveloperName__c, CurrentContract_F__r.Estimate_Num__c, CurrentContract_F__r.Contract_End_Date__c, CurrentContract_F__r.Estimate_Contract_endDate__c,
                            CurrentContract_F_asset__c, CurrentContract_F_asset__r.Estimate_Cost_Month_formula__c, CurrentContract_F_asset__r.endDateGurantee_Text__c, CurrentContract_F__r.Gurantee_Estimate_startDate__c,
                            CurrentContract_F__r.First_Estimate_Date__c,
                            //变更多年保续签开始日 thh 20220315 start
                            CurrentContract_F__r.Gurantee_Renew_startDate__c,
                            //变更多年保续签开始日 thh 20220315 end
                            //   (2022年12月上线)故障品加费 start
                            Return_Without_Repair__r.Repair_List_Price_formula__c,
                            Return_Without_Repair__r.Agreed_Date__c,
                            //   (2022年12月上线)故障品加费 end
                            CurrentContract_F__r.Contract_Consumption_rate__c, CurrentContract_F__r.First_contract_usage_Rate__c,
                            CurrentContract_F__r.Contract_Range__c, AssetMark__c,
                            //WLIG-CDFBV3 开通续签报价为true的可以开放续签报价 thh 20220414 start
                            CurrentContract_F__r.Open_RenewalQuotation__c,CurrentContract_F__r.VM_Contract_Check__c,
                            //WLIG-CDFBV3 开通续签报价为true的可以开放续签报价 thh 20220414 end
                            // 2021-01-29 LJPH-BX9CVX mzy   add  合同报价时判断零件风险
                            NoPartRiskDate_F__c, NoPartRiskDate__c, SignableFlag__c,
                            Product2.PartSupplyFinishDate__c, Product2.PartSupplyFinishDateExp__c
                            // 2021-01-29 LJPH-BX9CVX mzy   add  合同报价时判断零件风险
                            FROM Asset WHERE Hospital__c = :this.targetHospitalId AND ( AssetMark__c != '耗材' OR Product2.Family != 'ET' ) ORDER BY ID, IF_Warranty__c asc];
                            //URF限次合同2期 LY 20220811 start
                            , URF_Maintenance_Contract__c
                            , URF_Maintenance_Contract__r.Management_Code__c
                            , URF_Maintenance_Contract__r.Contract_End_Date__c
                            //URF限次合同2期 LY 20220811 end
                            // 报价规则改善 20230315 start
                            // ,IS_StandardPricing__c
                            // 报价规则改善 20230315 end
                            //多年保设备续签计算逻辑调整 2023/1/17 start
                            ,CurrentContract_F_asset__r.Asset_Consumption_Rate__c
                            ,CurrentContract_F_asset__r.Maintenance_Price_Year__c
                            ,CurrentContract_F_asset__r.IS_VMContract_Asset__c
                            ,Product2.Asset_Model_No__c
                            ,Product2.Category4__c
                            ,CurrentContract_F__r.endDateGurantee__c
                            //添加是否服务多年保修,多年保维修期至
                            ,IS_Extend_Gurantee__c,Extend_Gurantee_DateTo__c
                             //多年保设备续签计算逻辑调整 2023/1/17 end
                            FROM Asset WHERE Hospital__c = :this.targetHospitalId AND ( AssetMark__c != '耗材' OR Product2.Family != 'ET' ) ORDER BY ID, IF_Warranty_Service__c asc];
            //JZHG-BSDUT4 ---20200825---update By rentongxiao---Start
            // assetRecords = [SELECT Id, Name, Asset_situation__c, SerialNumber, Department_Name__c, Installation_Site__c, Posting_Date__c,Management_Code__c,IF_Warranty__c,Reson_Can_not_Warranty__c,
            // assetRecords = [SELECT Id, Name, Asset_situation__c, SerialNumber, Department_Name__c, Installation_Site__c, Posting_Date__c,Management_Code__c,IF_Warranty_Service__c,Reson_Can_not_Warranty__c,
            //                      InstallDate,isNewDate_use__c, Asset_Owner__c, Accumulation_Repair_Amount__c, Maintenance_Price_Month__c, Final_Examination_Date__c,CurrentContract_End_Date__c,EquipmentGuaranteeFlg__c,
            //                      CurrentContract_F__c,CurrentContract_F__r.Maintenance_Contract_No_F__c,CurrentContract_F__r.RecordType_DeveloperName__c,CurrentContract_F__r.Estimate_Num__c,CurrentContract_F__r.Contract_End_Date__c,CurrentContract_F__r.Estimate_Contract_endDate__c,
            //                      CurrentContract_F_asset__c,CurrentContract_F_asset__r.Estimate_Cost_Month_formula__c,CurrentContract_F_asset__r.endDateGurantee_Text__c,CurrentContract_F__r.Gurantee_Estimate_startDate__c,
            //                      CurrentContract_F__r.First_Estimate_Date__c,
            //                     CurrentContract_F__r.Contract_Consumption_rate__c,CurrentContract_F__r.First_contract_usage_Rate__c,
            //                     CurrentContract_F__r.Contract_Range__c ,AssetMark__c
            //                      FROM Asset WHERE Hospital__c = :this.targetHospitalId AND AssetMark__c = '主机' ORDER BY ID,IF_Warranty__c asc];
            //                      FROM Asset WHERE Hospital__c = :this.targetHospitalId AND AssetMark__c = '主机' ORDER BY ID,IF_Warranty_Service__c asc];
            //JZHG-BSDUT4 ---20200825---update By rentongxiao---End
        } else {
            assetRecords = new List<Asset>();
@@ -760,7 +1068,24 @@
        //sqlStr += ' AND AssetMark__c != \'耗材\' AND Product2.Family != \'ET\' ';
        this.checkedAssets = new List<AssetInfo>();
        this.unCheckedAssets = new List<AssetInfo>();
        // 上限合同 hql 20230216 start
            Boolean isLimitPriceOne = [SELECT id,Limit_Price__c FROM Maintenance_Contract__c  WHERE Id =: this.targetMaintenanceContractId].Limit_Price__c;
            if(isLimitPriceOne){
                this.isLimitPrice = true;
            }else{
                this.isLimitPrice = false;
            }
        // 上限合同 hql 20230216 end
        // 报价规则改善 20230309 start
            // Maintenance_Contract__c mc1 = [SELECT id,Is_Blank_period__c,Cost_rate_ForecastF__c FROM Maintenance_Contract__c  WHERE Id =: this.targetMaintenanceContractId];
            // Boolean IsBlankperiod = mc1.Is_Blank_period__c;
            // this.Cost_rate_ForecastF = mc1.Cost_rate_ForecastF__c;
            // if(IsBlankperiod){
            //     this.Is_Blank_period = true;
            // }else{
            //     this.Is_Blank_period = false;
            // }
        // 报价规则改善 20230309 end
        // 選択済みの納入機器情報を取得
        Map<Id, Integer> selectedAssetIds = new Map<Id, Integer>();
        List<Maintenance_Contract_Asset_Estimate__c> selectedMcaes = new List<Maintenance_Contract_Asset_Estimate__c>();
@@ -773,13 +1098,43 @@
                Asset__r.EquipmentGuaranteeFlg__c,
                Asset__r.CurrentContract_F_asset__r.Estimate_Cost_Month_formula__c,
                Asset__r.CurrentContract_F_asset__r.endDateGurantee_Text__c,
                //多年保设备续签计算逻辑调整 2023/1/18 start 设备消费率
                Asset__r.CurrentContract_F_asset__r.Asset_Consumption_Rate__c,
                Asset__r.CurrentContract_F_asset__r.IS_VMContract_Asset__c,
                Asset__r.CurrentContract_F_asset__r.Maintenance_Price_Year__c,
                Asset__r.Product2.Asset_Model_No__c,
                Asset__r.Product2.Category4__c,
                Asset__r.CurrentContract_F__r.endDateGurantee__c,
                //多年保设备续签计算逻辑调整 2022/1/18 end
                Asset__r.CurrentContract_F__r.First_Estimate_Date__c,
                Asset__r.CurrentContract_F__r.Contract_Consumption_rate__c,
                Asset__r.CurrentContract_F__r.First_contract_usage_Rate__c,
                Asset__r.CurrentContract_F__r.Estimate_Contract_endDate__c,
                Asset__r.CurrentContract_F__r.Contract_Range__c,
                Asset__r.CurrentContract_F__r.Contract_End_Date__c,
                Asset__r.CurrentContract_F__r.Gurantee_Estimate_startDate__c
                Asset__r.CurrentContract_F__r.Gurantee_Estimate_startDate__c,
                //变更多年保续签开始日 thh 20220315 start
                Asset__r.CurrentContract_F__r.Gurantee_Renew_startDate__c,
                //变更多年保续签开始日 thh 20220315 end
                //WLIG-CDFBV3 开通续签报价为true的可以开放续签报价 thh 20220414 start
                Asset__r.CurrentContract_F__r.Open_RenewalQuotation__c,Asset__r.CurrentContract_F__r.VM_Contract_Check__c
                //WLIG-CDFBV3 开通续签报价为true的可以开放续签报价 thh 20220414 end
                //URF限次合同2期 LY 20220811 start
                , Asset__r.URF_Maintenance_Contract__c
                , Asset__r.URF_Maintenance_Contract__r.Management_Code__c
                , Asset__r.URF_Maintenance_Contract__r.Contract_End_Date__c
                //URF限次合同2期 LY 20220811 end
                // //多年保设备续签计算逻辑调整 2022/12/14 start
                // , Asset__r.Guarantee_period_for_products__c
                // ,Asset__r.Maintenance_Price_Year__c
                // ,Maintenance_Contract__r.FM__c
                // ,Asset__r.Product2.Intra_Trade_Gurantee_RMB__c
                // ,Asset__r.Product2.Asset_Model_No__c
                // ,Asset__r.Product2.Category4__c
                // ,Maintenance_Contract__r.Consumption_rate_Gurante__c
                // //多年保设备续签计算逻辑调整 2022/12/14 end
                from Maintenance_Contract_Asset__c
                where Maintenance_Contract__c = :this.targetMaintenanceContractId
            ];
@@ -803,6 +1158,38 @@
                // 2.提交后不再变化
                //Date createdDate = (estimate.CreatedDate == null || !String.isBlank(copyid)) ? systemToday : estimate.CreatedDate.date();
                Date createdDate = systemToday;
                //多年保设备续签计算逻辑调整 2022/12/14 start
                // if(createdDate.daysBetween(mca.Asset__r.CurrentContract_F_asset__r.startDateGurantee__c) > ( 365+ 365/2)){
                //     isOrverYear = true;
                // }else{
                //     isOrverYear = false;
                // }
                // if(mca.Asset__r.Maintenance_Price_Year__c >0){
                //     MaintenancePriceYear = mca.Asset__r.Maintenance_Price_Year__c;
                // }
                // if(mca.Maintenance_Contract__r.FM__c>0){
                //     Denominator = mca.Maintenance_Contract__r.FM__c;
                // }
                // if (mca.Asset__r.Product2.Intra_Trade_Gurantee_RMB__c >0) {
                //     Accrued = mca.Asset__r.Product2.Intra_Trade_Gurantee_RMB__c;
                // }
                // if (mca.Asset__r.Product2.Asset_Model_No__c != null ) {
                //     ProductModel = mca.Asset__r.Product2.Asset_Model_No__c;
                // }
                // if (mca.Asset__r.Product2.Category4__c != null) {
                //    Category = mca.Asset__r.Product2.Category4__c;
                // }
                // if (mca.Maintenance_Contract__r.Consumption_rate_Gurante__c != null) {
                //     Consumption_rate_Gurante = mca.Maintenance_Contract__r.Consumption_rate_Gurante__c;
                // }
                // if(mca.Asset_Consumption_Rate__c!=null){
                //     Consumption_rate_Gurante = mca.Asset_Consumption_Rate__c;
                // }
                //多年保设备续签计算逻辑调整 2022/12/14 end
                if (createdDate.addMonths(isNewAddMonth) < mca.Asset__r.isNewDate_use__c) {
                    isNew = true;
                    // add点检改善:新增一个点检对象复选框字段,默认为true 2021.6.8 fxk Star
@@ -837,6 +1224,7 @@
                                                                Asset__r.EquipmentGuaranteeFlg__c,
                                                                //2021-11-30 fy add LJPH-C8W8FV 置顶 start
                                                                Asset__r.OwnershipMachine_No__c,
                                                                Product_Manual__r.Category4__c,
                                                                //2021-11-30 fy add LJPH-C8W8FV 置顶 end
                                                                Asset_Consumption_rate__c,
                                                                Asset__r.CurrentContract_F__c,
@@ -847,9 +1235,22 @@
                                                                Asset__r.CurrentContract_F__r.Contract_Range__c,
                                                                Asset__r.CurrentContract_F__r.Contract_End_Date__c,
                                                                Asset__r.CurrentContract_F__r.Gurantee_Estimate_startDate__c,
                                                                //WLIG-CDFBV3 开通续签报价为true的可以开放续签报价 thh 20220414 start
                                                                Asset__r.CurrentContract_F__r.Open_RenewalQuotation__c,Asset__r.CurrentContract_F__r.VM_Contract_Check__c,
                                                                //WLIG-CDFBV3 开通续签报价为true的可以开放续签报价 thh 20220414 end
                                                                //URF限次合同2期 LY 20220811 start
                                                                Asset__r.URF_Maintenance_Contract__c,
                                                                IS_Reduced_price_approval__c,
                                                                Asset__r.URF_Maintenance_Contract__r.Management_Code__c,
                                                                Asset__r.URF_Maintenance_Contract__r.Contract_End_Date__c,
                                                                //URF限次合同2期 LY 20220811 end
                                                                LastMContract_Price__c,
                                                                Asset__r.CurrentContract_F_asset__r.Estimate_Cost_Month_formula__c,
                                                                Asset__r.CurrentContract_F_asset__r.endDateGurantee_Text__c,
                                                                //多年保设备续签计算逻辑调整 2023/1/18 start  设备消费率
                                                                // Asset__r.CurrentContract_F_asset__r.Asset_Consumption_Rate__c,
                                                                // Asset__r.Product2.Intra_Trade_Gurantee_RMB__c,
                                                                //多年保设备续签计算逻辑调整 2022/12/14 end
                                                                Product_Manual__c,
                                                                Product_Manual__r.EquipmentGuaranteeFlg__c,
                                                                Product_Manual__r.Maintenance_Price_Month__c,
@@ -872,9 +1273,20 @@
                                                                Adjustment_ratio_Lower__c,
                                                                Adjustment_Lower_price__c,
                                                                Adjustment_Upper_price__c,
                                                                // 服务合同报价规则改善 20230227 start
                                                                // IS_StandardPricing__c,
                                                                // 服务合同报价规则改善 20230227 end
                                                                Last_inspection_day__c,
                                                                Check_Result__c,
                                                                Repair_Price__c,
                                                                //   (2022年12月上线)故障品加费 start
                                                                Repair_Price_pass__c,
                                                                Repair_Price_Auto__c,
                                                                Third_Party_Return__c,
                                                                 //   (2022年12月上线)故障品加费 end
                                                                // 报价规则改善 20230308 start
                                                                 // Blank_period__c,
                                                                // 报价规则改善 20230308 end
                                                                Comment__c,
                                                                Asset__r.Posting_Date__c,
                                                                EquipmentGuaranteeFlgTxt__c,
@@ -884,8 +1296,16 @@
                                                                Last_MContract__c
                                                                // Gzw 20200807 五个去年合同相关,所以报价产品,获取上期合同 eng
                                                                // LJPH-C9GD34 gzw fix start
                                                                //市场多年保修价格开发 2023/01/28 start
                                                                ,Asset__r.Product2.Asset_Model_No__c
                                                                ,Asset__r.Product2.Category4__c
                                                                ,Asset__r.CurrentContract_F_asset__r.Asset_Consumption_Rate__c
                                                                ,Asset__r.CurrentContract_F_asset__r.Maintenance_Price_Year__c
                                                                ,Asset__r.CurrentContract_F_asset__r.IS_VMContract_Asset__c
                                                                ,Asset__r.CurrentContract_F__r.endDateGurantee__c
                                                                //市场多年保修价格开发 2023/01/28 end
                                                                ,Estimate_List_Price_Page__c
                                                                // LJPH-C9GD34 gzw fix end
                                                                FROM Maintenance_Contract_Asset_Estimate__c
                                                                WHERE Maintenance_Contract_Estimate__c = :this.targetEstimateId
                                                                                                         ORDER BY
@@ -930,7 +1350,10 @@
        // ③Assetを元にデータをマッピングする時、明細マップからAssetAを取得できない?一覧に明細Aが出ない
        // 次回、Assetの検索条件が大きく変更する時、対応必要
        List<Data> datatemp = new List<Data>();
        // Map<String,repair__c> assNewRepMap  = new Map<String,repair__c>();
        // assNewRepMap = getNewrep(this.assetRecords);
        datatemp = getChartData();
        System.debug(LoggingLevel.INFO, '*** this.assetRecords: ' + this.assetRecords);
        for (Asset ast : this.assetRecords) {
            Boolean isNew = false;
            Decimal listPrice = ast.Maintenance_Price_Month__c;
@@ -987,7 +1410,9 @@
                //
                //
                //
                checkedAssets.add(new AssetInfo(checkedAssets.size(), ast, isNew, listPrice, selectedLocal));
                ast.CurrentContract_End_Date__c = ast.CurrentContract_F_asset__r.IS_VMContract_Asset__c ? ast.Extend_Gurantee_DateTo__c : ast.CurrentContract_End_Date__c;
                checkedAssets.add(new AssetInfo(checkedAssets.size(), ast, isNew, listPrice, selectedLocal,estimate));
            } else {
                //update by rentongxiao 2020-09-23 start
                if (ast.AssetMark__c == '主机') {
@@ -1008,7 +1433,8 @@
               }
             */
        }
            System.debug(LoggingLevel.INFO, '*** checkedAssets: ' + checkedAssets);
        totalPage = (totalRecords / selctRecordNum) + (Math.mod(totalRecords, selctRecordNum) > 0 ? 1 : 0);
    
        system.debug('顺序检测' + checkedAssets);
@@ -1035,7 +1461,7 @@
        //2021-11-30 fy add LJPH-C8W8FV 置顶 start
        List<AssetInfo> topAsset =new List<AssetInfo>();
        List<AssetInfo> otherAsset =new List<AssetInfo>();
        System.debug(LoggingLevel.INFO, '*** 顺序: ' + checkedAssets);
        for(AssetInfo ched : checkedAssets){
            system.debug('顺序检测2' + ched.ProductModelNoc);
            system.debug('顺序检测3' + ched.AssetModelNoc);
@@ -1060,19 +1486,24 @@
        }
        checkedAssets=NumberSort;
        //2021-11-30 fy add LJPH-C8W8FV 置顶 end
    System.debug(LoggingLevel.INFO, '*** checkedAssetsEND: ' + checkedAssets);
    }
    
    //
    
    // 取得分页数据
    private void setPageRecord() {
        integer num=0;
        num++;
        num++;
        num++;
        num++;
        checkIdList = new List<String> ();
        for (AssetInfo ass : this.checkedAssets) {
            if (!ass.isManual) {
                checkIdList.add(ass.rec.Id);
            }
        }
        if ((currPage * selctRecordNum) <= 2000) {
            String notInId = '(\'';
            if (checkIdList.size() > 0) {
@@ -1082,15 +1513,35 @@
            }
            notInId += '\')';
            //2021-11-30 fy add LJPH-C8W8FV 置顶 start OwnershipMachine_No__c Product2.ProductURF__c
                //tcm 添加 Management_Code__c  20211201 start
            //tcm 添加 Management_Code__c  20211201 start
            String sqlStr = 'SELECT Id, Name,OwnershipMachine_No__c, Asset_situation__c, SerialNumber, Department_Name__c, Installation_Site__c, '
                            + 'Posting_Date__c,Management_Code__c,IF_Warranty__c,Reson_Can_not_Warranty__c, InstallDate,isNewDate_use__c, '
                            + 'Posting_Date__c,Management_Code__c,IF_Warranty_Service__c,Reson_Can_not_Warranty__c, InstallDate,isNewDate_use__c, '
                            + 'Asset_Owner__c, Accumulation_Repair_Amount__c, Maintenance_Price_Month__c, Final_Examination_Date__c, '
                            + 'CurrentContract_End_Date__c, Extend_Gurantee_DateTo__c,EquipmentGuaranteeFlg__c, '
                            + 'CurrentContract_F__c,CurrentContract_F__r.Maintenance_Contract_No_F__c,CurrentContract_F__r.Management_Code__c,CurrentContract_F__r.RecordType_DeveloperName__c,CurrentContract_F__r.Estimate_Num__c,CurrentContract_F__r.Contract_End_Date__c,'
                            + 'CurrentContract_F__c,CurrentContract_F__r.Maintenance_Contract_No_F__c,CurrentContract_F__r.Management_Code__c,CurrentContract_F__r.RecordType_DeveloperName__c, CurrentContract_F__r.Estimate_Num__c,CurrentContract_F__r.Contract_End_Date__c,'
                            + 'CurrentContract_F_asset__c,CurrentContract_F_asset__r.Estimate_Cost_Month_formula__c,CurrentContract_F_asset__r.endDateGurantee_Text__c,CurrentContract_F__r.Gurantee_Estimate_startDate__c, '
                            //变更多年保续签开始日 thh 20220315 start
                            + 'CurrentContract_F__r.Gurantee_Renew_startDate__c,'
                            //变更多年保续签开始日 thh 20220315 end
                            //   (2022年12月上线)故障品加费 start
                            + 'Return_Without_Repair__r.Repair_List_Price_formula__c,Return_Without_Repair__r.Agreed_Date__c,'
                            //   (2022年12月上线)故障品加费 end
                            + 'CurrentContract_F__r.First_Estimate_Date__c,CurrentContract_F__r.Estimate_Contract_endDate__c,'
                            + 'CurrentContract_F__r.Contract_Consumption_rate__c,CurrentContract_F__r.First_contract_usage_Rate__c,'
                            //WLIG-CDFBV3 开通续签报价为true的可以开放续签报价 thh 20220414 start
                            + 'CurrentContract_F__r.Open_RenewalQuotation__c,CurrentContract_F__r.VM_Contract_Check__c,'
                            //WLIG-CDFBV3 开通续签报价为true的可以开放续签报价 thh 20220414 end
                            //URF限次合同2期 LY 20220811 start
                            + 'URF_Maintenance_Contract__c,URF_Maintenance_Contract__r.Management_Code__c,URF_Maintenance_Contract__r.Contract_End_Date__c,'
                            //URF限次合同2期 LY 20220811 end
                            //市场多年保价格开发 start DC 2023/01/17 设备消费率 产品型号 第四分类 是否为多年保设备
                            + 'CurrentContract_F_asset__r.Asset_Consumption_Rate__c,'
                            + 'CurrentContract_F_asset__r.Maintenance_Price_Year__c,'
                            + 'CurrentContract_F_asset__r.IS_VMContract_Asset__c,'
                            + 'Product2.Asset_Model_No__c,'
                            + 'Product2.Category4__c,'
                            + 'CurrentContract_F__r.endDateGurantee__c,'
                            //市场多年保价格开发 end DC 2023/01/17
                            + 'Product2.ProductURF__c,CurrentContract_F__r.Contract_Range__c,AssetMark__c,NoPartRiskDate__c,NoPartRiskDate_F__c,Product2.PartSupplyFinishDate__c,SignableFlag__c FROM Asset WHERE Hospital__c = \'' + this.targetHospitalId + '\' '
                            + 'AND Id NOT IN ' + notInId;
            //HWAG-B4R3SS  START 20181026
@@ -1108,7 +1559,7 @@
            //HWAG-BDJ43R---XHL---20190729---
            sqlStr += ' AND ( AssetMark__c != \'耗材\' OR Product2.Family != \'ET\' )';
            //HWAG-BDJ43R---XHL---20190729---
            sqlStr += ' ORDER BY ID,IF_Warranty__c asc ';
            sqlStr += ' ORDER BY ID,IF_Warranty_Service__c asc ';
            if (currPage == 1) {
                sqlStr += 'limit ' + selRecordOption;
            } else {
@@ -1128,14 +1579,34 @@
            //2021-11-30 fy add LJPH-C8W8FV 置顶 start OwnershipMachine_No__c Product2.ProductURF__c
            //tcm 添加 Management_Code__c  20211201 start
            sqlStr  = 'SELECT Id, Name,OwnershipMachine_No__c, Asset_situation__c, SerialNumber, Department_Name__c, Installation_Site__c,';
            sqlStr += 'Posting_Date__c,Management_Code__c,IF_Warranty__c,Reson_Can_not_Warranty__c,InstallDate,isNewDate_use__c,';
            sqlStr += 'Posting_Date__c,Management_Code__c,IF_Warranty_Service__c,Reson_Can_not_Warranty__c,InstallDate,isNewDate_use__c,';
            sqlStr += 'Asset_Owner__c, Accumulation_Repair_Amount__c, Maintenance_Price_Month__c, Final_Examination_Date__c,';
            sqlStr += 'CurrentContract_End_Date__c,Extend_Gurantee_DateTo__c,EquipmentGuaranteeFlg__c,';
            sqlStr += 'CurrentContract_F__c,CurrentContract_F__r.Maintenance_Contract_No_F__c,CurrentContract_F__r.Management_Code__c,CurrentContract_F__r.RecordType_DeveloperName__c,CurrentContract_F__r.Estimate_Num__c,CurrentContract_F__r.Contract_End_Date__c,';
            sqlStr += 'CurrentContract_F_asset__c,CurrentContract_F_asset__r.Estimate_Cost_Month_formula__c,CurrentContract_F_asset__r.endDateGurantee_Text__c,CurrentContract_F__r.Gurantee_Estimate_startDate__c,';
            //变更多年保续签开始日 thh 20220315 start
            sqlStr += 'CurrentContract_F__r.Gurantee_Renew_startDate__c,';
            //变更多年保续签开始日 thh 20220315 end
            //   (2022年12月上线)故障品加费 start
            sqlStr += 'Return_Without_Repair__r.Repair_List_Price_formula__c,Return_Without_Repair__r.Agreed_Date__c,';
            //   (2022年12月上线)故障品加费 end
            sqlStr += 'CurrentContract_F__r.First_Estimate_Date__c,CurrentContract_F__r.Estimate_Contract_endDate__c,';
            sqlStr += 'Product2.ProductURF__c,CurrentContract_F__r.Contract_Consumption_rate__c,CurrentContract_F__r.First_contract_usage_Rate__c,';
            //WLIG-CDFBV3 开通续签报价为true的可以开放续签报价 thh 20220414 start
            sqlStr += 'CurrentContract_F__r.Open_RenewalQuotation__c,CurrentContract_F__r.VM_Contract_Check__c,';
            //WLIG-CDFBV3 开通续签报价为true的可以开放续签报价 thh 20220414 end
            //URF限次合同2期 LY 20220811 start
            sqlStr += 'URF_Maintenance_Contract__c,URF_Maintenance_Contract__r.Management_Code__c,URF_Maintenance_Contract__r.Contract_End_Date__c,';
            //URF限次合同2期 LY 20220811 end
            //市场多年保价格开发 start DC 2023/01/17 设备消费率
            sqlStr += 'CurrentContract_F_asset__r.Asset_Consumption_Rate__c,CurrentContract_F_asset__r.IS_VMContract_Asset__c,CurrentContract_F_asset__r.Maintenance_Price_Year__c,Product2.Asset_Model_No__c,Product2.Category4__c,CurrentContract_F__r.endDateGurantee__c,';
            //市场多年保价格开发 start DC 2023/01/17
            sqlStr += ' CurrentContract_F__r.Contract_Range__c,AssetMark__c,NoPartRiskDate__c,NoPartRiskDate_F__c,Product2.PartSupplyFinishDate__c,SignableFlag__c FROM Asset WHERE Hospital__c = \'' + this.targetHospitalId + '\'';
            //JZHG-BSDUT4 ---20200825---update By rentongxiao---Start
            // sqlStr += '  AND ( AssetMark__c != \'耗材\' OR Product2.Family != \'ET\' ) ';
            //JZHG-BSDUT4 ---20200825---update By rentongxiao---End
@@ -1153,15 +1624,15 @@
            //HWAG-B4R3SS  END 20181026
            if (checkIdList.size() > 0) {
                sqlStr += '  AND Id NOT IN ' + checkIdList;
                //temAsset = [SELECT Id, Name, Asset_situation__c, SerialNumber, Department_Name__c, Installation_Site__c, Posting_Date__c,Management_Code__c,IF_Warranty__c,Reson_Can_not_Warranty__c,
                //temAsset = [SELECT Id, Name, Asset_situation__c, SerialNumber, Department_Name__c, Installation_Site__c, Posting_Date__c,Management_Code__c,IF_Warranty_Service__c,Reson_Can_not_Warranty__c,
                //            InstallDate, Asset_Owner__c, Accumulation_Repair_Amount__c, Maintenance_Price_Month__c, Final_Examination_Date__c,CurrentContract_End_Date__c,Extend_Gurantee_DateTo__c
                //            FROM Asset WHERE Hospital__c = :this.targetHospitalId AND Id NOT IN : checkIdList AND AssetMark__c != '耗材' AND Product2.Family != 'ET' ORDER BY ID,IF_Warranty__c asc limit : sqlLimit];
                //            FROM Asset WHERE Hospital__c = :this.targetHospitalId AND Id NOT IN : checkIdList AND AssetMark__c != '耗材' AND Product2.Family != 'ET' ORDER BY ID,IF_Warranty_Service__c asc limit : sqlLimit];
            } else {
                //temAsset = [SELECT Id, Name, Asset_situation__c, SerialNumber, Department_Name__c, Installation_Site__c, Posting_Date__c,Management_Code__c,IF_Warranty__c,Reson_Can_not_Warranty__c,
                //temAsset = [SELECT Id, Name, Asset_situation__c, SerialNumber, Department_Name__c, Installation_Site__c, Posting_Date__c,Management_Code__c,IF_Warranty_Service__c,Reson_Can_not_Warranty__c,
                //            InstallDate, Asset_Owner__c, Accumulation_Repair_Amount__c, Maintenance_Price_Month__c, Final_Examination_Date__c,CurrentContract_End_Date__c,Extend_Gurantee_DateTo__c
                //            FROM Asset WHERE Hospital__c = :this.targetHospitalId AND AssetMark__c != '耗材' AND Product2.Family != 'ET' ORDER BY ID,IF_Warranty__c asc limit : sqlLimit];
                //            FROM Asset WHERE Hospital__c = :this.targetHospitalId AND AssetMark__c != '耗材' AND Product2.Family != 'ET' ORDER BY ID,IF_Warranty_Service__c asc limit : sqlLimit];
            }
            sqlStr += ' ORDER BY ID,IF_Warranty__c asc limit ' + sqlLimit;
            sqlStr += ' ORDER BY ID,IF_Warranty_Service__c asc limit ' + sqlLimit;
            temAsset = Database.query(sqlStr);
            //HWAG-BDJ43R ---XHL---20190729---
            if (temAsset.size() >= (currPage * selctRecordNum)) {
@@ -1175,6 +1646,8 @@
            }
        }
        this.unCheckedAssets = new List<AssetInfo>();
        // Map<String,repair__c> assNewRepMap  = new Map<String,repair__c>();
        // assNewRepMap = getNewrep(this.assetRecords);
        for (Asset ast : assetRecords) {
            this.unCheckedAssets.add(new AssetInfo(unCheckedAssets.size(), ast));
        }
@@ -1246,6 +1719,13 @@
        totalPage = (totalRecords / selctRecordNum) + (Math.mod(totalRecords, selctRecordNum) > 0 ? 1 : 0);
        this.setPageRecord();
    }
     //2022 故障品加费 判断修理金额是否低于8折以下
    public PageReference  judgePrice(Boolean islessPrice){
        disableEmailBtn = islessPrice;
        System.debug(LoggingLevel.INFO, '*** disableEmailBtn: ' + disableEmailBtn);
        return null;
    }
    
    //list分割 集合大小超过1000对应
    private void listCut(List<AssetInfo> records) {
@@ -1265,7 +1745,7 @@
    public static void ComputeLTYRepair(String targetHospitalId) {
        system.debug('ComputeLTYRepair=====Start');
        List<Maintenance_Contract_Asset_Estimate__c> McaeList = new List<Maintenance_Contract_Asset_Estimate__c>();
        McaeList = [select id, asset__c, Lastyear_Repair_Cost_Text__c, Last_Second_Years_Repair_Cost_Text__c, Last_Third_Years_Repair_Cost_Text__c, Three_Years_Repair_Cost_Text__c
        McaeList = [select id, asset__c, Lastyear_Repair_Cost_Text__c, Last_Second_Years_Repair_Cost_Text__c, Last_Third_Years_Repair_Cost_Text__c, Three_Years_Repair_Cost_Text__c,IS_Reduced_price_approval__c
                    from Maintenance_Contract_Asset_Estimate__c
                    where Maintenance_Contract_Estimate__c = :targetHospitalId];
        List<id> AsList = new List<id>();
@@ -1328,6 +1808,9 @@
            and Agreed_Date__c != null
            and Agreed_Date__c > :LastYearDate
            and Agreed_Date__c <= :today
            // DB202302544421 LHJ add
            and Status2__c !='00.删除'
            and Status2__c !='00.取消'
            group by Delivered_Product__c
        ];
        List<AggregateResult> SecRepairList = [
@@ -1352,6 +1835,9 @@
            and Agreed_Date__c != null
            and Agreed_Date__c <= :LastYearDate
            and Agreed_Date__c > :LastSecondYearDate
            // DB202302544421 LHJ add
            and Status2__c !='00.删除'
            and Status2__c !='00.取消'
            group by Delivered_Product__c
        ];
        // 过去3年间修理实绩
@@ -1377,6 +1863,9 @@
            and Agreed_Date__c != null
            and Agreed_Date__c <= :LastSecondYearDate
            and Agreed_Date__c > :LastThirdYearDate
            // DB202302544421 LHJ add
            and Status2__c !='00.删除'
            and Status2__c !='00.取消'
            group by Delivered_Product__c
        ];
        // 过去3年修理实绩
@@ -1402,6 +1891,9 @@
            and Agreed_Date__c != null
            and Agreed_Date__c <= :today
            and Agreed_Date__c > :LastThirdYearDate
            // DB202302544421 LHJ add
            and Status2__c !='00.删除'
            and Status2__c !='00.取消'
            group by Delivered_Product__c
        ];
    
@@ -1465,9 +1957,16 @@
    
    
    public void ComputeLTYRepair() {
        integer num=0;
        num++;
        num++;
        num++;
        num++;
        num++;
        num++;
        system.debug('ComputeLTYRepair=====Start');
        List<Maintenance_Contract_Asset_Estimate__c> McaeList = new List<Maintenance_Contract_Asset_Estimate__c>();
        McaeList = [select id, asset__c, Lastyear_Repair_Cost_Text__c, Last_Second_Years_Repair_Cost_Text__c, Last_Third_Years_Repair_Cost_Text__c, Three_Years_Repair_Cost_Text__c
        McaeList = [select id, asset__c, Lastyear_Repair_Cost_Text__c, Last_Second_Years_Repair_Cost_Text__c, Last_Third_Years_Repair_Cost_Text__c, Three_Years_Repair_Cost_Text__c,IS_Reduced_price_approval__c
                    from Maintenance_Contract_Asset_Estimate__c
                    where Maintenance_Contract_Estimate__c = :targetEstimateId];
        List<id> AsList = new List<id>();
@@ -1536,6 +2035,9 @@
            and Agreed_Date__c != null
            and Agreed_Date__c > :LastYearDate
            and Agreed_Date__c <= :today
            // DB202302544421 LHJ add
            and Status2__c !='00.删除'
            and Status2__c !='00.取消'
            group by Delivered_Product__c
        ];
        List<AggregateResult> SecRepairList = [
@@ -1560,6 +2062,9 @@
            and Agreed_Date__c != null
            and Agreed_Date__c <= :LastYearDate
            and Agreed_Date__c > :LastSecondYearDate
            // DB202302544421 LHJ add
            and Status2__c !='00.删除'
            and Status2__c !='00.取消'
            group by Delivered_Product__c
        ];
        // 过去3年间修理实绩
@@ -1585,6 +2090,9 @@
            and Agreed_Date__c != null
            and Agreed_Date__c <= :LastSecondYearDate
            and Agreed_Date__c > :LastThirdYearDate
            // DB202302544421 LHJ add
            and Status2__c !='00.删除'
            and Status2__c !='00.取消'
            group by Delivered_Product__c
        ];
        // 过去3年修理实绩
@@ -1610,6 +2118,9 @@
            and Agreed_Date__c != null
            and Agreed_Date__c <= :today
            and Agreed_Date__c > :LastThirdYearDate
            // DB202302544421 LHJ add
            and Status2__c !='00.删除'
            and Status2__c !='00.取消'
            group by Delivered_Product__c
        ];
        // 过去1年间
@@ -1742,6 +2253,11 @@
    public void refreshProductData() {
        System.debug('1535.......................进入refreshProductData方法');
        System.debug('1536.......................进入refreshProductData方法');
        integer num=0;
        num++;
        num++;
        num++;
        num++;
        for (Integer i = 0; i < checkedAssets.size(); i++) {
            if (i == productIdx) {
                AssetInfo ai = checkedAssets[i];
@@ -2048,15 +2564,24 @@
    /**
     * 保存メソッド
     */
    public PageReference save() {
        System.debug('save start');
        Oly_TriggerHandler.bypass('Maintenance_Contract_Asset__c');
        Oly_TriggerHandler.bypass('AssetHandler');
        // Oly_TriggerHandler.bypass('AssetTrigger');
        Oly_TriggerHandler.bypass('AssetHandlerCheck');
        Oly_TriggerHandler.bypass('SetContractEstimatePriceHandler');
        StaticParameter.EscapeVMCTrigger = true;
        //add by rentx 2020-11-13 LJPH-BV93RZ start
        if (estimate.Contract_Range__c == null) {
            this.estimate.Contract_Range__c.addError('必须输入合同月数!');
            return null;
        }
        NextMaintenanceContract();
        //add by rentx 2020-11-13 LJPH-BV93RZ end
    
        Id vmMaintenance_Contract = Schema.SObjectType.Maintenance_Contract_Estimate__c.getRecordTypeInfosByDeveloperName().get('NewMaintenance_Quote').getRecordTypeId();
        estimate.recordtypeid = vmMaintenance_Contract;
@@ -2064,14 +2589,35 @@
            priceChangeReset();
            return null;
        }
         AssetHandler.disabled = true;
        if (syncEstimate(false, false)) {
            // 故障品加费2022/11/18
            // if (estimate.IS_Reduced_price_approval__c=='否' || estimate.IS_Reduced_price_approval__c=='审批中') {
            //  Approval.ProcessSubmitRequest psr = new Approval.ProcessSubmitRequest();
            // psr.setObjectId(this.estimate.id);
            // Approval.ProcessResult submitResult = Approval.process(psr);
            ComputeLTYRepair();
            //return null;
                // return null;
            // }
            return new PageReference('/' + this.targetEstimateId + '/e?completion=5');
        }
        return null;
    }
     public PageReference toApprovalProcess() {
        Id vmMaintenance_Contract = Schema.SObjectType.Maintenance_Contract_Estimate__c.getRecordTypeInfosByDeveloperName().get('NewMaintenance_Quote').getRecordTypeId();
        estimate.recordtypeid = vmMaintenance_Contract;
        if (syncEstimate(false, false)) {
            // 故障品加费2022/11/18
             if (estimate.IS_Reduced_price_approval__c=='否' || estimate.IS_Reduced_price_approval__c=='审批中') {
                Approval.ProcessSubmitRequest psr = new Approval.ProcessSubmitRequest();
                psr.setObjectId(this.estimate.id);
                Approval.ProcessResult submitResult = Approval.process(psr);
             }
          return new PageReference('/' + this.targetEstimateId + '/e?completion=5');
        }
        return null;
     }
    /**
     * 印刷メソッド、decide前は保有設備、decide後は合同配置
     */
@@ -2171,8 +2717,6 @@
     * 申請メソッド、最後必ず承認プロセスに載せる
     */
    public PageReference approvalProcess() {
        Id vmMaintenance_Contract = Schema.SObjectType.Maintenance_Contract_Estimate__c.getRecordTypeInfosByDeveloperName().get('NewMaintenance_Quote').getRecordTypeId();
        estimate.recordtypeid = vmMaintenance_Contract;
    
@@ -2196,7 +2740,7 @@
        //            }
        //        }
        // }
        NextMaintenanceContract();
        if (changedSubmitPrice) {
            priceChangeReset();
            return null;
@@ -2232,6 +2776,162 @@
        }
        return null;
    }
    /**
     * FSE修理値引きメール提出 2022故障品加费
     */
    public PageReference sendEmail() {
        System.debug(LoggingLevel.INFO, '*** in sendEmail: ');
        this.estimate.Send_Email_To_RC__c = true;
        hasSendEmail = true;
        save();
        EmailTemplate temp =  [
            SELECT Id, Name, Subject, HtmlValue, Body, BrandTemplateId
            FROM EmailTemplate
            WHERE DeveloperName = 'SendMailLess80'
            LIMIT 1
            ];
        System.debug(LoggingLevel.INFO, '*** temp: '+ temp);
      //   //简档不确定 待修改
      //   List<String> sendEaddress = new List<String>();
      //   // for (User u  : [SELECT Email FROM User WHERE Profile.Name ='2F3_合同组' AND IsActive=true]) {
      //   //     sendEaddress.add(u.Email);
      //   // }
      //   for (User u  : [SELECT Email FROM User WHERE Profile.Name ='ATEST_故障品' AND IsActive=true]) {
      //       sendEaddress.add(u.Email);
      //   }
      //   System.debug(LoggingLevel.INFO, '*** sendEaddress: ' + sendEaddress);
      //   System.debug(LoggingLevel.INFO, '*** this.estimate: ' + this.estimate);
      //   Messaging.SingleEmailMessage email = Messaging.renderStoredEmailTemplate(temp.Id,null, this.estimate.Id);
      //   email.setSaveAsActivity(false);
      //   email.setToAddresses(sendEaddress);
      //   Messaging.sendEmail(new List<Messaging.SingleEmailMessage>{email});
      //   System.debug(LoggingLevel.INFO, '*** sendEmail end: ');
      //   Messaging.SendEmailResult[] results = messaging.sendEmail(new List<Messaging.SingleEmailMessage>{email});
      //   for (Integer i = 0; i < results.size(); i++) {
      //   if (results[i].success == true) {
      //     System.debug(LoggingLevel.INFO, '*** sendEmail true: ');
      //   }
      // }
        // 数据验证
        // 验证 开始日期,最早允许制定日之前半年
            Date createdDate = this.estimate.CreatedDate == null ? System.today() : this.estimate.CreatedDate.date();
            createdDate = createdDate.addMonths(isNewAddMonth);
            // if (estimate.Contract_Start_Date__c < createdDate) {
            //     this.estimate.Contract_Start_Date__c.addError('合同开始日最早允许追溯制定日之前半年');
            //     return false;
            // }
            // 验证 用户类型,必填
            if (String.isBlank(estimate.EndUserType__c) ) {
                this.estimate.EndUserType__c.addError('请选择用户类型!');
                return null;
            }
            // 验证 申请报价金额,需要大于0
            if (estimate.Request_quotation_Amount__c <= 0 || estimate.Request_quotation_Amount__c == null) {
                this.estimate.Request_quotation_Amount__c.addError('申请报价金额必需大于0');
                return null;
            }
            // fxk 改报错位置 2021、9、9 Star
            if (estimate.Request_quotation_Amount__c > estimate.GuidePrice_Up__c || estimate.Request_quotation_Amount__c < estimate.GuidePrice_Down__c) {
                if (!(this.estimate.mainTalksTime__c > 0)) {
                    this.estimate.mainTalksTime__c.addError('主要谈判次数必填');
                    return null;
                }
                if (this.estimate.talksStartDate__c == null) {
                    this.estimate.talksStartDate__c.addError('谈判的开始时间必填');
                    return null;
                }
                if (String.isBlank(this.estimate.Discount_reason__c)) {
                    this.estimate.Discount_reason__c.addError('价格申请理由必填');
                    return null;
                }
                if (String.isBlank(this.estimate.Improve_ConsumptionRate_Idea__c)) {
                    this.estimate.Improve_ConsumptionRate_Idea__c.addError('消费率改善方案必填');
                    return null;
                }
            }
            if (estimate.Contract_Range__c == null) {
                 this.estimate.Contract_Range__c.addError('必须输入合同月数!');
                 return null;
            }
        //抄送人 张禄杰、张晶、张栩榕 setCcAddresses
        List<String> ccAddress = new List<String>();
        for (User u : [Select Email,Id,Alias__c from User where IsActive =true  and (Alias__c='张禄杰' OR Alias__c='张晶' OR Alias__c='张栩榕') ]) {
            ccAddress.add(u.Email);
        }
        System.debug(LoggingLevel.INFO, '*** ccAddress: ' + ccAddress);
        //华北 西北 张禄杰
        //东北 张禄杰  张森
        //华东 刘海峰
        //华南 西南 刘海峰 张颖华
        List<Messaging.SingleEmailMessage> emails = new List<Messaging.SingleEmailMessage>();
        for (User u : [Select Email,Id,Alias__c from User where (Alias__c='张禄杰' OR Alias__c='张森' OR Alias__c='刘海峰' OR Alias__c='张颖华') and IsActive =true ]) {
            Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
            email = Messaging.renderStoredEmailTemplate(temp.Id, u.Id, this.estimate.Id);
            // email = Messaging.renderStoredEmailTemplate(temp.Id, null, this.estimate.Id);
            email.setTemplateId(temp.Id);
            email.setSaveAsActivity(false);
            email.setCcAddresses(ccAddress);
            System.debug(LoggingLevel.INFO, '*** this.estimate.Hospital_Salesdepartment__c: ' + this.estimate.Hospital_Salesdepartment__c);
            if(u.Alias__c=='张禄杰' && (this.estimate.Hospital_Salesdepartment__c =='1.华北' || this.estimate.Hospital_Salesdepartment__c =='3.西北' ||  this.estimate.Hospital_Salesdepartment__c =='2.东北')){
                email.setTargetObjectId(u.Id);
                emails.add(email);
            }else if(u.Alias__c=='张森' && (this.estimate.Hospital_Salesdepartment__c =='2.东北')){
                email.setTargetObjectId(u.Id);
                emails.add(email);
            }else if(u.Alias__c=='刘海峰' &&(this.estimate.Hospital_Salesdepartment__c =='5.华东' ||this.estimate.Hospital_Salesdepartment__c =='6.华南' || this.estimate.Hospital_Salesdepartment__c =='4.西南')){
                email.setTargetObjectId(u.Id);
                emails.add(email);
            }else if(u.Alias__c=='张颖华' &&( this.estimate.Hospital_Salesdepartment__c =='6.华南' || this.estimate.Hospital_Salesdepartment__c =='4.西南')){
                email.setTargetObjectId(u.Id);
                emails.add(email);
            }
            // }else if(u.Alias__c=='故障品Test2Test' && (this.estimate.Hospital_Salesdepartment__c =='5.华东')){
            //     email.setTargetObjectId(u.Id);
            //     emails.add(email);
            //     System.debug(LoggingLevel.INFO, '*** test setTargetObjectId: ' + email);
            // }
        // email.setTargetObjectId(u.Id);
        System.debug(LoggingLevel.INFO, '*** email: ' + email);
        }
        if(emails.size()>0){
            try{
                Messaging.sendEmail(emails);
                sendEmailSuccess = true;
                System.debug(LoggingLevel.INFO, '*** sendEmail hasSendEmail: ' + hasSendEmail);
                System.debug(LoggingLevel.INFO, '*** sendEmailSuccess: ' + sendEmailSuccess);
                ApexPages.addMessage(new ApexPages.Message(ApexPages.severity.INFO,'邮件发送成功!'));
            }catch(Exception e){
                System.debug(e.getMessage());
                sendEmailSuccess = false;
                // hasSendEmail = false;
                ApexPages.addMessage(new ApexPages.Message(ApexPages.severity.WARNING,'邮件发送失败,请联系管理员!'));
            }
        }
        return null;
    }
    
    /**
     * 決定取消メソッド
@@ -2255,12 +2955,14 @@
        return null;
    }
    
    /**
     * 決定メソッド
     */
    public PageReference decide() {
        System.debug('decide start');
        inDicideFlag = true;
        NextMaintenanceContract();
        // TODO check decide 资格
        Savepoint sp = Database.setSavepoint();
        // gzw cputimeout 报错添加 20210729 start
@@ -2299,6 +3001,19 @@
        this.estimate.ZongjianApprovalManager__c = loginUser.ZongjianApprovalManager__c == null ? loginUser.Id : loginUser.ZongjianApprovalManager__c;
        this.estimate.Service_Contract_Staff__c = this.contract.Service_Contract_Staff__c;
        this.estimate.TKZongjianApprovalManager__c = loginUser.TongkuoZongjian__c == null ? loginUser.Id : loginUser.TongkuoZongjian__c;
        integer num=0;
        num++;
        num++;
        num++;
        num++;
        num++;
        num++;
        num++;
        num++;
        num++;
        num++;
        num++;
        num++;
    }
    
    /**
@@ -2337,7 +3052,10 @@
        System.debug('syncEstimate start');
        Boolean hasDatabaseError = false;
        Savepoint sp = Database.setSavepoint();
        integer i =0;
        i++;
        i++;
        //bug修复
        //提交 报价决定日期
        // this.estimate.Quotation_Determines_Time__c = date.today();
@@ -2376,7 +3094,8 @@
                    this.estimate.mainTalksTime__c.addError('主要谈判次数必填');
                    return false;
                }
                i++;
                i++;
                if (this.estimate.talksStartDate__c == null) {
                    this.estimate.talksStartDate__c.addError('谈判的开始时间必填');
                    return false;
@@ -2426,7 +3145,10 @@
                ApexPages.addMessage(new ApexPages.message(ApexPages.severity.INFO, '已经是Decide过的合同 或 不是批准的报价,不能Decide'));
                return false;
            }
            i++;
            i++;
            i++;
            i++;
            // 追加上期合同信息 start
            // 2021-09-10 tcm 排序逻辑调整 start
            List<lastMContract> lastMContractRes;
@@ -2456,8 +3178,40 @@
            this.estimate.LastMContract5__c = lastMContractRes[4].contractId;
            this.estimate.LastMContract5_NO__c = lastMContractRes[4].contractNo;
            this.estimate.LastMContract5_ConCount__c = lastMContractRes[4].count;
            //URF限次合同2期 LY 20220908 start
            List<lastMContract> urfMContractRes;
            if (isDecide) {
                system.debug('执行了tcm isDecide');
                urfMContractRes = getURFMContract(this.checkedAssets,this.estimate.Contract_Start_Date__c);
            } else{
                system.debug('执行了tcm NODecide');
                urfMContractRes = getURFMContract(this.checkedAssets,this.estimate.Contract_Esti_Start_Date__c);
            }
            this.estimate.URFMContract1__c = urfMContractRes[0].contractId;
            this.estimate.URF_LastMContract1_NO__c = urfMContractRes[0].contractNo;
            this.estimate.URF_LastMContract1_ConCount__c = urfMContractRes[0].count;
    
            //this.estimate.URFMContract2__c = urfMContractRes[1].contractId;
            this.estimate.URF_LastMContract2_NO__c = urfMContractRes[1].contractNo;
            this.estimate.URF_LastMContract2_ConCount__c = urfMContractRes[1].count;
    
            //this.estimate.URFMContract3__c = urfMContractRes[2].contractId;
            this.estimate.URF_LastMContract3_NO__c = urfMContractRes[2].contractNo;
            this.estimate.URF_LastMContract3_ConCount__c = urfMContractRes[2].count;
            //this.estimate.URFMContract4__c = urfMContractRes[3].contractId;
            this.estimate.URF_LastMContract4_NO__c = urfMContractRes[3].contractNo;
            this.estimate.URF_LastMContract4_ConCount__c = urfMContractRes[3].count;
            //this.estimate.URFMContract5__c = urfMContractRes[4].contractId;
            this.estimate.URF_LastMContract5_NO__c = urfMContractRes[4].contractNo;
            this.estimate.URF_LastMContract5_ConCount__c = urfMContractRes[4].count;
            //URF限次合同2期 LY 20220908 end
            i++;
            i++;
            i++;
            i++;
            // 原方法
            // List<lastMContract> lastMContractRes = getlastMContract(this.checkedAssets, this.estimate.Contract_Start_Date__c);
            // // ApexPages.addMessage(new ApexPages.message(ApexPages.severity.INFO, 'lastMContractRes +++++!' + lastMContractRes));
@@ -2519,7 +3273,10 @@
                }
                ControllerUtil.updateMaintenance_Contract_Estimate(otherEstimates);
            }
            i++;
            i++;
            i++;
            i++;
            // 合同结束预定日を算出
            Date t = this.estimate.Contract_Esti_Start_Date__c.addMonths(Integer.valueOf(this.estimate.Contract_Range__c));
            // 20151217 xudan 维修合同报价SH-RS-JS0046560-01 期间显示问题
@@ -2543,6 +3300,7 @@
            t = this.estimate.Contract_Start_Date__c.addMonths(Integer.valueOf(this.estimate.Contract_Range__c));
            t = t.addDays(-1);
            this.estimate.Contract_End_Date__c = t;
            //提交之后decide之前,经销商变更的话,先款信息以变更后的经销商先款信息执行 thh 20220418 start
            //add      wangweipeng                   2021/12/26                     start
            if(String.isNotBlank(this.estimate.Dealer__c)){
                checkDealerId = this.estimate.Dealer__c;
@@ -2551,6 +3309,7 @@
                this.estimate.Is_RecognitionModel__c = false;
            }
            //add      wangweipeng                   2021/12/26                     end
            //提交之后decide之前,经销商变更的话,先款信息以变更后的经销商先款信息执行 thh 20220418 end
            System.debug('---------345----'+this.estimate.Dealer__c+'-------'+this.estimate.Dealer__r.FirstParagraphEnd__c);
            // 位置调整 在1951 line
            // Date createdDate = this.estimate.CreatedDate == null ? System.today() : this.estimate.CreatedDate.date();
@@ -2587,6 +3346,7 @@
                setApprovalManager();
                System.debug('Process_Status__c=' + this.estimate.Process_Status__c);
                insert this.estimate;
                System.debug(LoggingLevel.INFO, '*** insertthis.estimate: ');
                this.targetEstimateId = this.estimate.Id;
                setThisEstimate();
            } else {
@@ -2606,9 +3366,19 @@
            //
            //  因为月初计算消费率,所以结束日在上月或以前,可以取到完整消费率,否则保存首次报价日
            Date toDate = Date.today();
            integer num=0;
            num++;
            num++;
            num++;
            num++;
            Date mon1stDate = Date.newInstance(toDate.year(), toDate.month(), 1);
            // list 修改 map
            Map<id, Maintenance_Contract__c> mcList = new Map<id, Maintenance_Contract__c>();
            //故障品加费 第三方回归 故障品标识
            Boolean hasThirdPartyReturnc = false;
            Boolean hasSurchargeDefective = false;
            for (AssetInfo input : this.checkedAssets) {
                if (!input.isManual || input.isManual && !String.isBlank(input.mcae.Product_Manual__c)) {
                    //Maintenance_Contract_Asset_Estimate__c mcae = new Maintenance_Contract_Asset_Estimate__c();
@@ -2661,7 +3431,10 @@
                    }
                    //songxiaoqi end
    
                    num++;
                    num++;
                    num++;
                    num++;
                    // Gzw 20200807 五个去年合同相关,所以报价产品,获取上期合同 end
                    //mcae.Estimate_List_Price__c = input.mcae.Estimate_List_Price__c;
                    //mcae.IsNew__c = input.mcae.isNew__c;
@@ -2669,22 +3442,82 @@
                    //mcae.Repair_Price__c = input.mcae.Repair_Price__c;
                    //mcae.Comment__c = input.mcae.Comment__c;
                    insertTarget.add(input.mcae);
                    //故障品加费 第三方回归 、故障品标识 start 2022/12/30
                    if(input.mcae.Third_Party_Return__c == true){
                        hasThirdPartyReturnc = true;
                    }
                    System.debug(LoggingLevel.INFO, '*** input.mcae: ' + input.mcae);
                    // System.debug(LoggingLevel.INFO, '*** input.mcae.Surcharge_Defective_Contract__c: ' + input.mcae.Surcharge_Defective_Contract__c);
                    if(input.mcae.Repair_Price__c>0 && input.mcae.Third_Party_Return__c == false){
                        hasSurchargeDefective = true;
                    }
                    //故障品加费 第三方回归 、故障品标识 end 2022/12/30
                }
            }
            //故障品加费 维修合同、报价  第三方回归 、故障品标识 start 2022/12/30
            System.debug(LoggingLevel.INFO, '*** hasThirdPartyReturnc: ' + hasThirdPartyReturnc);
            System.debug(LoggingLevel.INFO, '*** hasThirdPartyReturnc: ' + hasSurchargeDefective);
            if(hasThirdPartyReturnc == true){
                //报价
                this.estimate.Third_Party_Return__c = true;
                this.estimate.Surcharge_Defective_Contract__c = false;
                //维修合同
                this.contract.Third_Party_Return_Contract__c = this.estimate.Third_Party_Return__c;
                this.contract.Surcharge_Defective_Contract__c = this.estimate.Surcharge_Defective_Contract__c;
            }else if(hasThirdPartyReturnc == false && hasSurchargeDefective == true){
                //报价
                this.estimate.Surcharge_Defective_Contract__c = true;
                this.estimate.Third_Party_Return__c = false;
                //维修合同
                this.contract.Third_Party_Return_Contract__c = this.estimate.Third_Party_Return__c;
                this.contract.Surcharge_Defective_Contract__c = this.estimate.Surcharge_Defective_Contract__c;
            }else if(hasThirdPartyReturnc == false && hasSurchargeDefective == false){
                //报价
                this.estimate.Surcharge_Defective_Contract__c = false;
                this.estimate.Third_Party_Return__c = false;
                //维修合同
                this.contract.Third_Party_Return_Contract__c = this.estimate.Third_Party_Return__c;
                this.contract.Surcharge_Defective_Contract__c = this.estimate.Surcharge_Defective_Contract__c;
            }
            //故障品加费 维修合同、报价  第三方回归 、故障品标识 end 2022/12/30
            // 本当に保存した納入機器があれば削除
            List<Maintenance_Contract_Asset_Estimate__c> selectedAsset = [SELECT Id, Name, Maintenance_Contract_Estimate__c, Asset__c, IsNew__c FROM Maintenance_Contract_Asset_Estimate__c WHERE Maintenance_Contract_Estimate__c = :this.targetEstimateId];
            // AssetHandler.disabled = true;
            List<Maintenance_Contract_Asset_Estimate__c> selectedAsset = [SELECT Id, Name,IS_Reduced_price_approval__c, Maintenance_Contract_Estimate__c, Asset__c, IsNew__c FROM Maintenance_Contract_Asset_Estimate__c WHERE Maintenance_Contract_Estimate__c = :this.targetEstimateId];
            if (selectedAsset.size() > 0) {
                ControllerUtil.deleteMaintenance_Contract_Asset_Estimate(selectedAsset);
            }
            if (insertTarget.size() > 0) {
                ControllerUtil.insertMaintenance_Contract_Asset_Estimate(insertTarget);
            }
            // ① start
            for (List<Maintenance_Contract_Asset__c> oldList : [select Id from Maintenance_Contract_Asset__c
                                                                where Maintenance_Contract__c = :this.estimate.Maintenance_Contract__c]) {
                delete oldList;
            }
            //市场多年保价格开发 DC 2023/02/08 start
            // Map<String,Decimal> contractAssetFZ = new Map<String,Decimal>();
            // List<Maintenance_Contract_Asset__c> oldListMA = new List<Maintenance_Contract_Asset__c>();
            // for (Maintenance_Contract_Asset__c oldmc : [select Id
            //                                                     // ,Summary_FM_Year__c
            //                                                     // ,Asset_Consumption_Rate__c
            //                                                     ,Summary_FZ__c
            //                                                     ,Asset__c
            //                                                     // ,Over_FM_Year__c
            //                                                     // ,Summary_FM_Months__c
            //                                                     from Maintenance_Contract_Asset__c
            //                                                     where Maintenance_Contract__c = :this.estimate.Maintenance_Contract__c]) {
            //     oldListMA.add(oldmc);
            //     contractAssetFZ.put(oldmc.Asset__c, oldmc.Summary_FZ__c);
            // }
            // delete oldListMA;
            //市场多年保价格开发 DC 2023/02/08 end
            // ② start
            {
                List<Maintenance_Contract_Asset__c> newValue = new List<Maintenance_Contract_Asset__c>();
@@ -2693,6 +3526,7 @@
                                                                      Check_Object__c,
                                                                      //add 点检改善:合同保有设备下的点检对象与报价保有设备下的点检对象同步 2021.6.9 fxk end
                                                                      IsNew__c, EquipmentGuaranteeFlgTxt__c,
                                                                      IS_Reduced_price_approval__c,
                                                                      // Gzw 20200807 五个去年合同相关,所以报价产品,获取上期合同 start
                                                                      Last_MContract__c
                                                                      // Gzw 20200807 五个去年合同相关,所以报价产品,获取上期合同 eng
@@ -2700,9 +3534,16 @@
                                                                      // LJPH-C9GD34 gzw fix start
                                                                      ,Estimate_List_Price_Page__c
                                                                      // LJPH-C9GD34 gzw fix end
                                                                      // 故障品加费 2022/12/30 start
                                                                      ,Third_Party_Return__c
                                                                      ,Surcharge_Defective_Contract__c
                                                                      // 故障品加费 2022/12/30 end
                                                                      from Maintenance_Contract_Asset_Estimate__c
                                                                      where Maintenance_Contract_Estimate__c = :this.estimate.Id and Asset__c <> null]) {
                    Maintenance_Contract_Asset__c newVal = new Maintenance_Contract_Asset__c(
                        Maintenance_Contract__c = this.estimate.Maintenance_Contract__c,
                        Asset__c = target.Asset__c,
@@ -2718,13 +3559,28 @@
                        // LastMContract__c = target.Last_MContract__c
                        // Gzw 20200807 五个去年合同相关,所以报价产品,获取上期合同 end
                        //如果是多年保修合同,不更新上期维修合同信息 LJPH-BUU3E3 update by rentx  2020-11-03
                        //故障品加费  第三方回归、故障品加费 标识start
                        Third_Party_Return__c = target.Third_Party_Return__c,
                        Surcharge_Defective_Contract__c = target.Surcharge_Defective_Contract__c,
                        //故障品加费  第三方回归、故障品加费 标识end
                        //市场多年保价格开发 start DC 2023/02/09
                        // Summary_FZ__c = contractAssetFZ.get(target.Asset__c),
                        //市场多年保价格开发 end DC 2023/02/09
                        LastMContract__c = target.Last_MContract__r.RecordType_DeveloperName__c == 'VM_Contract' ? null : target.Last_MContract__c
                        );
                    // System.debug(LoggingLevel.INFO, '*** contractAssetFZ.get(target.Asset__c): ' + contractAssetFZ.get(target.Asset__c));
                    newValue.add(newVal);
                }
                if (newValue.size() > 0) insert newValue;
            }
            // ④ start
            // 报价规则改善 20230309 start
            // this.contract.Is_Blank_period__c = this.Is_Blank_period;
            // 报价规则改善 20230309 end
            this.contract.Estimation_Id__c = this.targetEstimateId;     
            this.contract.Contract_Esti_Start_Date__c = this.estimate.Contract_Esti_Start_Date__c;
            this.contract.Contract_Range__c = this.estimate.Contract_Range__c;
@@ -2765,6 +3621,32 @@
            this.contract.LastMContract5_NO__c = this.estimate.LastMContract5_NO__c;
            this.contract.LastMContract5_ConCount__c =  this.estimate.LastMContract5_ConCount__c;
            // 追加上期合同信息 end
            //URF限次合同2期 LY 20220908 start
            //追加上期限次合同信息 start
            this.contract.URF_LastMContract1__c = this.estimate.URFMContract1__c;
            this.contract.URF_LastMContract1_startDate__c = this.estimate.URFMContract1_startDate__c;
            this.contract.URF_LastMContract1_endDate__c = this.estimate.URFMContract1_endDate__c;
            this.contract.URF_LastMContract1_NO__c = this.estimate.URF_LastMContract1_NO__c;
            this.contract.URF_LastMContract1_ConCount__c =  this.estimate.URF_LastMContract1_ConCount__c;
            //this.contract.URF_LastMContract2__c =  this.estimate.URFMContract2__c;
            this.contract.URF_LastMContract2_NO__c = this.estimate.URF_LastMContract2_NO__c;
            this.contract.URF_LastMContract2_ConCount__c =  this.estimate.URF_LastMContract2_ConCount__c;
            //this.contract.URF_LastMContract3__c =  this.estimate.URFMContract3__c;
            this.contract.URF_LastMContract3_NO__c = this.estimate.URF_LastMContract3_NO__c;
            this.contract.URF_LastMContract3_ConCount__c =  this.estimate.URF_LastMContract3_ConCount__c;
            //this.contract.URF_LastMContract4__c =  this.estimate.URFMContract4__c;
            this.contract.URF_LastMContract4_NO__c = this.estimate.URF_LastMContract4_NO__c;
            this.contract.URF_LastMContract4_ConCount__c =  this.estimate.URF_LastMContract4_ConCount__c;
            //this.contract.URF_LastMContract5__c =  this.estimate.URFMContract5__c;
            this.contract.URF_LastMContract5_NO__c = this.estimate.URF_LastMContract5_NO__c;
            this.contract.URF_LastMContract5_ConCount__c =  this.estimate.URF_LastMContract5_ConCount__c;
            // 追加上期限次合同信息 end
            //URF限次合同2期 LY 20220908 end
    
            system.debug('测算isDecide的结果_1::::::::' + isDecide);
            if (isDecide == true) {
@@ -2840,6 +3722,15 @@
     */
    @TestVisible
    private Boolean checkChangedAfterPrint() {
        integer num=0;
        num++;
        num++;
        num++;
        num++;
        num++;
        num++;
        num++;
        num++;
        System.debug('checkChangedAfterPrint start');
        if (changedAfterPrint) {
            this.targetEstimateId = null;
@@ -2879,11 +3770,16 @@
    
    /** 保存返回 **/
    public PageReference saveAndCancel () {
        AssetHandler.disabled = true;
        Oly_TriggerHandler.bypass('Maintenance_Contract_Asset__c');
        Oly_TriggerHandler.bypass('AssetHandler');
         Oly_TriggerHandler.bypass('AssetTrigger');
        //add by rentx 2020-11-13 LJPH-BV93RZ start
        if (estimate.Contract_Range__c == null) {
            this.estimate.Contract_Range__c.addError('必须输入合同月数!');
            return null;
        }
        NextMaintenanceContract();
        //add by rentx 2020-11-13 LJPH-BV93RZ end
        if (syncEstimate(false, false)) {
            PageReference ret = null;
@@ -2939,7 +3835,7 @@
        this.contract = [SELECT Id, Name, Status__c, Decided_Estimation__c, Service_Contract_Staff__c,
                         Estimate_Num__c, Management_Code__c, Hospital__c,
                         Hospital__r.MaintenanceContractUserType__c,
                         Contract_Start_Date__c, Contract_End_Date__c
                         Contract_Start_Date__c, Contract_End_Date__c, VM_Contract_Check__c,Open_RenewalQuotation__c
                         FROM Maintenance_Contract__c WHERE Id = :id];
        if (this.estimate.Process_Status__c == '草案中' || String.IsBlank(this.estimate.Process_Status__c)) {
    
@@ -2954,7 +3850,7 @@
                         //2021-01-18  mzy add  LJPH-BWY5QB   客户上的 维修合同用户类型 为true /false,报价 用户类型为 既有用户 / 新用户
                         // Hospital__r.MaintenanceContractUserType__c,
                         //2021-01-18  mzy add  LJPH-BWY5QB   客户上的 维修合同用户类型 为true /false,报价 用户类型为 既有用户 / 新用户
                         Contract_Start_Date__c, Contract_End_Date__c
                         Contract_Start_Date__c, Contract_End_Date__c, VM_Contract_Check__c,Open_RenewalQuotation__c
                         FROM Maintenance_Contract__c WHERE Id = :id];
        this.targetHospitalId = this.contract.Hospital__c;
        // 2021-01-18  mzy  add LJPH-BWY5QB   客户上的 维修合同用户类型 为true /false,报价 用户类型为 既有用户 / 新用户
@@ -2966,6 +3862,31 @@
    }
    
    private Boolean checkValidate() {
        integer i =0;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        Boolean rtn = true;
        Date today = Date.today();
        if (getPageDisabled()) {
@@ -3034,37 +3955,87 @@
                //1.合同期不满一年时,合同期超过一半才可开始续签报价。(eg:11个月的合同从6个月后才可报价。)
                //2.一年以上的合同,在结束前6个月开始可以开放续签报价。
                //3.管理员跳过,
                if (UserInfo.getProfileId() != System.Label.ProfileId_SystemAdmin && String.isNotBlank(input.rec.CurrentContract_F__c) && input.rec.CurrentContract_F__r.RecordType_DeveloperName__c != 'VM_Contract') {
                //WLIG-CDFBV3 开通续签报价为true的可以开放续签报价 thh 20220413
                // if (input.rec.CurrentContract_F__r.Open_RenewalQuotation__c == false && UserInfo.getProfileId() != System.Label.ProfileId_SystemAdmin &&
                //         String.isNotBlank(input.rec.CurrentContract_F__c) && input.rec.CurrentContract_F__r.RecordType_DeveloperName__c != 'VM_Contract') {
                //     Integer noOfDays = today.daysBetween(input.rec.CurrentContract_F__r.Contract_End_Date__c);
                //     Decimal monthCon = (Decimal)noOfDays / 365 * 12;
                //     // 可开始报价的月数限制
                //     if (input.rec.CurrentContract_F__r.Contract_Range__c >= 12 && monthCon > 6) {
                //         input.rec.Name.addError(input.rec.Name + '(' + input.rec.SerialNumber + ') -- 合同结束前6个月开始可以制作报价。');
                //         rtn = false;
                //     }
                //     //ApexPages.addMessage(new ApexPages.message(ApexPages.severity.INFO, '---' + monthCon  + ' +++ ' + Math.floor(input.rec.CurrentContract_F__r.Contract_Range__c/2)));
                //     //rtn = false;
                //     if (input.rec.CurrentContract_F__r.Contract_Range__c < 12 && monthCon > Math.floor(input.rec.CurrentContract_F__r.Contract_Range__c / 2)) {
                //         input.rec.Name.addError(input.rec.Name + '(' + input.rec.SerialNumber + ') -- 经历月数过半方可制作报价');
                //         rtn = false;
                //     }
                // }
        // 多年保判断
        if ( String.isNotBlank(input.rec.CurrentContract_F__c) && input.rec.CurrentContract_F__r.RecordType_DeveloperName__c == 'VM_Contract') {
            //if (UserInfo.getProfileId() != System.Label.ProfileId_SystemAdmin && String.isNotBlank(input.rec.CurrentContract_F__c) && input.rec.CurrentContract_F__r.RecordType_DeveloperName__c == 'VM_Contract') {
    
                    Integer noOfDays = today.daysBetween(input.rec.CurrentContract_F__r.Contract_End_Date__c);
                    Decimal monthCon = (Decimal)noOfDays / 365 * 12;
                    // 可开始报价的月数限制
                    if (input.rec.CurrentContract_F__r.Contract_Range__c >= 12 && monthCon > 6) {
                        input.rec.Name.addError(input.rec.Name + '(' + input.rec.SerialNumber + ') -- 合同结束前6个月开始可以制作报价。');
                        rtn = false;
                    }
                    //ApexPages.addMessage(new ApexPages.message(ApexPages.severity.INFO, '---' + monthCon  + ' +++ ' + Math.floor(input.rec.CurrentContract_F__r.Contract_Range__c/2)));
                    //rtn = false;
                    if (input.rec.CurrentContract_F__r.Contract_Range__c < 12 && monthCon > Math.floor(input.rec.CurrentContract_F__r.Contract_Range__c / 2)) {
                        input.rec.Name.addError(input.rec.Name + '(' + input.rec.SerialNumber + ') -- 经历月数过半方可制作报价');
                        rtn = false;
                    }
                }
                // 多年保判断
                if ( String.isNotBlank(input.rec.CurrentContract_F__c) && input.rec.CurrentContract_F__r.RecordType_DeveloperName__c == 'VM_Contract') {
                    //if (UserInfo.getProfileId() != System.Label.ProfileId_SystemAdmin && String.isNotBlank(input.rec.CurrentContract_F__c) && input.rec.CurrentContract_F__r.RecordType_DeveloperName__c == 'VM_Contract') {
                    //Integer noOfDays = today.daysBetween(input.rec.CurrentContract_F_asset__r.endDateGurantee_Text__c);
                    //Decimal monthCon = (Decimal)noOfDays/365*12;
                    // 可开始报价的月数限制
                    if (input.rec.CurrentContract_F__r.Gurantee_Estimate_startDate__c > Date.today()) {
                        input.rec.Name.addError(input.rec.Name + '(' + input.rec.SerialNumber + ') -- 合同结束前6个月开始可以制作报价。');
                        rtn = false;
                    }
                }
            // modify by lc 20220607 多年保续签和实绩连动状态对应 start
            Integer noOfDays = today.daysBetween(input.rec.CurrentContract_F_asset__r.endDateGurantee_Text__c);
            Decimal monthCon = (Decimal)noOfDays/365*12;
            //市场多年保修价格开发 DC 2023/02/02 Start  结束日空白期大于6个月 报错提示 新的合同报价开始日期和上一期合同
            Date endDate6Month = input.rec.CurrentContract_F_asset__r.endDateGurantee_Text__c.addMonths(6);
            Date cotractEndDay = input.rec.CurrentContract_F__r.endDateGurantee__c;
            System.debug(LoggingLevel.INFO, '*** endDate6Month: ' + endDate6Month);
            System.debug(LoggingLevel.INFO, '*** cotractEndDay: ' + cotractEndDay);
            System.debug(LoggingLevel.INFO, '*** this.estimate.Contract_Esti_Start_Date__c: ' + this.estimate.Contract_Esti_Start_Date__c);
            if(this.estimate.Contract_Esti_Start_Date__c >endDate6Month && cotractEndDay < this.estimate.Contract_Esti_Start_Date__c){
                System.debug(LoggingLevel.INFO, '*** meet error: ' );
                input.rec.Name.addError(input.rec.Name + '(' + input.rec.SerialNumber + ') -- 市场多年保结束已超过6个月,由于空白期过长,请先联系服务管理部评估。');
                rtn = false;
            }
            //市场多年保修价格开发 DC 2023/02/02 end
            // 可开始报价的月数限制
            //变更多年保续签开始日 thh 20220315 start
            //if (input.rec.CurrentContract_F__r.Gurantee_Estimate_startDate__c > Date.today()) {
            // gzw 20220630 开通续签报价权限后,超过6个月也可以续签
            // 续签情况 ① 上期合同 Open_RenewalQuotation__c & 6个月以内  ② VM_Contract_Check__c Open_RenewalQuotation__c 2个都打钩
            // ① 2个开关都打开 ②VM_Contract_Check__c打开 小于6个月
            // if (!((this.contract.Open_RenewalQuotation__c && input.rec.CurrentContract_F__r.VM_Contract_Check__c) || (input.rec.CurrentContract_F__r.VM_Contract_Check__c && monthCon < 6))) {
            //     if(monthCon < 6){
            //         input.rec.Name.addError(input.rec.Name + '(' + input.rec.SerialNumber + ') -- 可以加入服务合同,加入价格请联系服务管理部。');
            //     }else{
            //         input.rec.Name.addError(input.rec.Name + '(' + input.rec.SerialNumber + ') -- 没有续签报价权限,或者还没到续签时间。');
            //     }
            //     System.debug(LoggingLevel.INFO, '*** this.contract.Open_RenewalQuotation__c: ' + this.contract.Open_RenewalQuotation__c);
            //     System.debug(LoggingLevel.INFO, '*** : input.rec.CurrentContract_F__r.VM_Contract_Check__c' + input.rec.CurrentContract_F__r.VM_Contract_Check__c);
            //     System.debug(LoggingLevel.INFO, '*** monthCon: ' + monthCon);
            //     //input.rec.Name.addError(input.rec.Name + '(' + input.rec.SerialNumber + ') -- 没有续签报价权限,或者还没到续签时间。');
            //     rtn = false;
            // }
            /*if (input.rec.CurrentContract_F__r.Gurantee_Renew_startDate__c > Date.today()) {
                input.rec.Name.addError(input.rec.Name + '(' + input.rec.SerialNumber + ') -- 第一个设备结束后可以制作报价。');
                rtn = false;
            }*/
            //变更多年保续签开始日 thh 20220315 end
            // modify by lc 20220607 多年保续签和实绩连动状态对应 end
        }
                //ApexPages.addMessage(new ApexPages.message(ApexPages.severity.INFO, '---' + input.rec.CurrentContract_F__r.Contract_End_Date__c));
                if (inDicideFlag && String.isNotBlank(input.rec.CurrentContract_F__c) && estimate.Skip_DJ__c == false ) {
                    //ApexPages.addMessage(new ApexPages.message(ApexPages.severity.INFO, '+++' + input.rec.CurrentContract_F__r.Contract_End_Date__c));
                    //多年保结束日到续签开始日之间的空白期大于30日,且在合同开始日前三个月内没有点检记录,报错 20220429 thh start
                    if(input.rec.CurrentContract_F__r.RecordType_DeveloperName__c == 'VM_Contract' &&
                        input.rec.CurrentContract_F__r.Contract_End_Date__c > input.rec.CurrentContract_F__r.Gurantee_Renew_startDate__c.addDays(30)
                        && (input.rec.Final_Examination_Date__c == null
                            || input.rec.Final_Examination_Date__c < estimate.Contract_Start_Date__c.addMonths(-3))){
                        input.rec.Name.addError(input.rec.Name + '(' + input.rec.SerialNumber + ') -- 没有最新的点检记录');
                        rtn = false;
                    }
                    //多年保结束日到续签开始日之间的空白期大于30日,且在合同开始日前三个月内没有点检记录,报错 20220429 thh end
                    // 合同开始日大于上期合同结束日加一个月,且没有点检日期或者最近一次点检日期是3个月前  报错
                    if (estimate.Contract_Start_Date__c > input.rec.CurrentContract_F__r.Contract_End_Date__c.addMonths(1)
                        && (input.rec.Final_Examination_Date__c == null
@@ -3075,7 +4046,7 @@
                }
    
                if (isSaveOrApproval) {
                    if (input.rec.IF_Warranty__c == '否') {
                    if (input.rec.IF_Warranty_Service__c == '否') {
                        input.rec.Name.addError(input.rec.Name + '(' + input.rec.SerialNumber + ') -- 不能选择不可参保设备');
                        rtn = false;
                    }
@@ -3168,6 +4139,31 @@
                }
            }
        }
        integer i =0;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        //contractStartDateChange();
    }
    
@@ -3175,13 +4171,18 @@
    public class AssetInfo {
    // 新合同备品确保提供 当前标记
    public Boolean etGFlg {get; set;}
    public Transient Integer lineNo {get; private set;}
    public String ISStandardPricing{get; set;}
    public Integer lineNo {get; private set;}
    public Decimal Repair_Price_Auto {get; set;}
    public String Agreed_Date{get; set;}
    public Boolean rec_checkBox_c {get; set;}
    public Asset rec { get; set; }
    public Maintenance_Contract_Asset_Estimate__c mcae { get; set; }
    public Boolean isManual { get; set; }
    public Maintenance_Contract_Estimate__c estimate {get; set;}
    public Transient Decimal orgPrice {get; private set;}
    public Transient Decimal orgPrice12 {get; private set;}
    public String Blank_period {get;  set;}
    // add by fxk 2021/9/9 控制点检对象是否可选 Star
    public Boolean CheckRows {get; private set;}
    // add by fxk 2021/9/9 控制点检对象是否可选 End
@@ -3202,7 +4203,9 @@
    public String AssetModelNoc;
    public String MDMModelNoc;
    //2021-11-30 fy add LJPH-C8W8FV 置顶 end
    //市场多年保 价格开发 start 2023/01/17
    public String Category;
    //市场多年保 价格开发 end 2023/01/17
    public Id getRecId() {
        Id rtn = null;
        if (rec != null) {
@@ -3213,7 +4216,6 @@
    public void setRecId(Id value) {
        // なにもしない
    }
    // Manual専用
    public AssetInfo(Integer lineNo) {
        this.lineNo = lineNo;
@@ -3234,9 +4236,36 @@
        // add by fxk 2021/9/9 控制点检对象是否可选 End
    }
    // 選択された用(非Manual)
    public AssetInfo(Integer lineNo, Asset record, Boolean isNew, Decimal listPrice, Maintenance_Contract_Asset_Estimate__c mcae) {
    public AssetInfo(Integer lineNo, Asset record, Boolean isNew, Decimal listPrice, Maintenance_Contract_Asset_Estimate__c mcae,Maintenance_Contract_Estimate__c estimate) {
        this.lineNo = lineNo;
        this.rec = record;
        this.rec.CurrentContract_End_Date__c = record.CurrentContract_End_Date__c;
        // this.rec.CurrentContract_End_Date__c = record.IS_Extend_Gurantee__c ? record.Extend_Gurantee_DateTo__c : record.CurrentContract_End_Date__c;
        // this.ISStandardPricing = record.IS_StandardPricing__c;
        this.estimate = new Maintenance_Contract_Estimate__c();
        this.estimate.IS_Reduced_price_approval__c = estimate.IS_Reduced_price_approval__c;
         // 报价规则改善 20230308 start
        // this.estimate.Contract_Esti_Start_Date__c = estimate.Contract_Esti_Start_Date__c;
        // this.estimate.renewTen_OFF__c = estimate.renewTen_OFF__c;
         // 报价规则改善 20230308 end
        //   (2022年12月上线)故障品加费 start
        // if (record.Asset_situation__c == '修理中' && record.Return_Without_Repair__r.Agreed_Date__c!=null) {
        //     this.Agreed_Date = '不为空';
        // }
        // if (record.Asset_situation__c == '修理中' && record.Return_Without_Repair__r.Agreed_Date__c==null) {
        //     this.Agreed_Date = '为空';
        //     if (assNewRepMap.get(record.id)!=null) {
        //          this.Repair_Price_Auto = assNewRepMap.get(record.id).Repair_List_Price_formula__c;
        //     }
        // }
        // if (record.Return_Without_Repair__r.Repair_List_Price_formula__c!=null&&record.Asset_situation__c != '修理中') {
        //     this.Repair_Price_Auto = record.Return_Without_Repair__r.Repair_List_Price_formula__c;
        // }
        if (record.Return_Without_Repair__r.Repair_List_Price_formula__c!=null) {
            this.Repair_Price_Auto = record.Return_Without_Repair__r.Repair_List_Price_formula__c;
        }
        //   (2022年12月上线)故障品加费 end
        this.mcae = new Maintenance_Contract_Asset_Estimate__c(
            //                id = mcae.Id,             // 本当にいらないの? セットしたら、新規権限がなくでも、更新できます。後藤さんに確認した、なくでもいいです。
            isNew__c = isNew,
@@ -3247,6 +4276,10 @@
            //Maintenance_Price_YearTXT__c = mcae.Maintenance_Price_YearTXT__c,
            Check_Result__c = mcae.Check_Result__c,
            Repair_Price__c = mcae.Repair_Price__c,
            Repair_Price_pass__c = mcae.Repair_Price_pass__c,
            // 报价规则改善 20230308 start
            // Blank_period__c = mcae.Blank_period__c,
            // 报价规则改善 20230308 end
            Comment__c = mcae.Comment__c,
            EquipmentGuaranteeFlgTxt__c = mcae.EquipmentGuaranteeFlgTxt__c,
            Estimate_Cost__c = mcae.Estimate_Cost__c,
@@ -3257,9 +4290,30 @@
            Adjustment_Lower_price__c = mcae.Adjustment_Lower_price__c,
            Asset_Consumption_rate__c = mcae.Asset_Consumption_rate__c
            // LJPH-C9GD34 gzw fix start
            ,Estimate_List_Price_Page__c = mcae.Estimate_List_Price_Page__c
            ,Estimate_List_Price_Page__c = mcae.Estimate_List_Price_Page__c,
            // LJPH-C9GD34 gzw fix end
            //(2022年12月上线)故障品加费 第三方回归
            Third_Party_Return__c = mcae.Third_Party_Return__c
            );
         if ((this.mcae.Repair_Price__c==null&&this.Repair_Price_Auto!=null&&this.rec.Reson_Can_not_Warranty__c!=null&&this.rec.Reson_Can_not_Warranty__c.indexof('弃修')!=-1)||(this.estimate.IS_Reduced_price_approval__c == '否')) {
            this.mcae.Repair_Price__c = this.Repair_Price_Auto;
        }
        if (this.estimate.IS_Reduced_price_approval__c=='是'||this.estimate.IS_Reduced_price_approval__c==null) {
            if (this.mcae.Repair_Price__c!=null) {
                this.mcae.Repair_Price_pass__c = this.mcae.Repair_Price__c;
            }
        }
         // 报价规则改善 20230308 start
            // if (this.estimate.Contract_Esti_Start_Date__c!=null  && this.rec.CurrentContract_End_Date__c != null) {
            //        this.mcae.Blank_period__c = String.valueof(this.rec.CurrentContract_End_Date__c.daysbetween(this.estimate.Contract_Esti_Start_Date__c));
            // }
            // if (this.estimate.Contract_Esti_Start_Date__c==null && this.rec.CurrentContract_End_Date__c != null) {
            //        this.mcae.Blank_period__c = String.valueof(this.rec.CurrentContract_End_Date__c.daysbetween(system.today()));
            // }
            // if (this.mcae.Blank_period__c!=null&&integer.valueOf(this.mcae.Blank_period__c)<15 ) {
            //         this.mcae.Blank_period__c = '无缝续签';
            // }
        // 报价规则改善 20230308 end
        this.isManual = false;
        this.rec_checkBox_c = true;
        this.orgPrice = record.Maintenance_Price_Month__c;
@@ -3275,6 +4329,11 @@
        //2021-11-30 fy add LJPH-C8W8FV 置顶 end
    
        //add by rentx 2020-11-12 LJPH-BV93RZ end
        //市场多年保 价格开发 start 2023/01/17
        this.Category = mcae.Product_Manual__r.Category4__c;
        //市场多年保 价格开发 end 2023/01/17
        //add by mzy 2021-02-07 start
        //this.NoPartRiskDate = mcae.Product_Manual__r.NoPartRiskDate_F__c;
        //this.proName2 = mcae.Product_Manual__r.Name;
@@ -3296,6 +4355,7 @@
            //Maintenance_Price_YearTXT__c = mcae.Maintenance_Price_YearTXT__c,
            Check_Result__c = mcae.Check_Result__c,
            Repair_Price__c = mcae.Repair_Price__c,
            Repair_Price_pass__c = mcae.Repair_Price_pass__c,
            Comment__c = mcae.Comment__c,
            EquipmentGuaranteeFlgTxt__c = mcae.EquipmentGuaranteeFlgTxt__c,
            Estimate_Cost__c = mcae.Estimate_Cost__c,
@@ -3308,8 +4368,10 @@
            Contract_Esti_Start_Date__c = mcae.Maintenance_Contract_Estimate__r.Contract_Esti_Start_Date__c
                                          // Contract_Esti_Start_Date__c=mcae.Contract_Esti_Start_Date__c
            // LJPH-C9GD34 gzw fix start
            ,Estimate_List_Price_Page__c = mcae.Estimate_List_Price_Page__c
            ,Estimate_List_Price_Page__c = mcae.Estimate_List_Price_Page__c,
            // LJPH-C9GD34 gzw fix end
            //(2022年12月上线)故障品加费 第三方回归
            Third_Party_Return__c = mcae.Third_Party_Return__c
            );
        this.isManual = true;
        this.rec_checkBox_c = false;
@@ -3325,11 +4387,21 @@
        this.ProductModelNoc = mcae.Product_Manual__r.Asset_Model_No__c;
        this.AssetModelNoc = mcae.Asset__r.OwnershipMachine_No__c;
        //2021-11-30 fy add LJPH-C8W8FV 置顶 end
        //市场多年保 价格开发 start 2023/01/17
        this.Category = mcae.Product_Manual__r.Category4__c;
        //市场多年保 价格开发 end 2023/01/17
    }
    // 選択されなかった用
    public AssetInfo(Integer lineNo, Asset record) {
        this.lineNo = lineNo;
        this.rec = record;
        //   (2022年12月上线)故障品加费 start
        if (record.Return_Without_Repair__r.Repair_List_Price_formula__c!=null) {
            this.Repair_Price_Auto = record.Return_Without_Repair__r.Repair_List_Price_formula__c;
        }
        //   (2022年12月上线)故障品加费 end
        this.isManual = false;
        this.rec_checkBox_c = false;
        this.orgPrice = record.Maintenance_Price_Month__c;
@@ -3338,6 +4410,34 @@
        this.proSerialName = record.Name;
        this.proSerialNumber = record.SerialNumber;
    }
    // public AssetInfo(Integer lineNo, Asset record) {
    //     this.lineNo = lineNo;
    //     this.rec = record;
    //     //   (2022年12月上线)故障品加费 start
    //     // if (record.Asset_situation__c == '修理中' && record.Return_Without_Repair__r.Agreed_Date__c!=null) {
    //     //     this.Agreed_Date = '不为空';
    //     // }
    //     // if (record.Asset_situation__c == '修理中' && record.Return_Without_Repair__r.Agreed_Date__c==null) {
    //     //     this.Agreed_Date = '为空';
    //     //     if (assNewRepMap.get(record.id)!=null) {
    //     //          this.Repair_Price_Auto = assNewRepMap.get(record.id).Repair_List_Price_formula__c;
    //     //     }
    //     // }
    //     // if (record.Return_Without_Repair__r.Repair_List_Price_formula__c!=null&&record.Asset_situation__c != '修理中') {
    //     //     this.Repair_Price_Auto = record.Return_Without_Repair__r.Repair_List_Price_formula__c;
    //     // }
    //     if (record.Return_Without_Repair__r.Repair_List_Price_formula__c!=null) {
    //         this.Repair_Price_Auto = record.Return_Without_Repair__r.Repair_List_Price_formula__c;
    //     }
    //     //   (2022年12月上线)故障品加费 end
    //     this.isManual = false;
    //     this.rec_checkBox_c = false;
    //     this.orgPrice = record.Maintenance_Price_Month__c;
    //     this.orgPrice12 = this.orgPrice * 12;
    //     this.etGFlg = record.EquipmentGuaranteeFlg__c;
    //     this.proSerialName = record.Name;
    //     this.proSerialNumber = record.SerialNumber;
    // }
    }
    
    WebService static String pageDecide(String strId) {
@@ -3374,6 +4474,7 @@
            rs = 'Undecide失败';
        }
        return rs;
    }
    
    
@@ -3466,7 +4567,50 @@
        //List<lastMContract> listResult = new List<lastMContract>();
        return listResult;
    }
    //URF限次合同2期 LY 20220908 start
    //对限次合同进行排序
    public static List<lastMContract> getURFMContract(List<AssetInfo> checkedAssets, Date startDate) {
        Map<String, lastMContract> urfMContractMap = new Map<String, lastMContract>();
        Map<String, lastMContract> lastMContractMap1 = new Map<String, lastMContract>();
        for (AssetInfo ai : checkedAssets) {
            lastMContract urfMC = new lastMContract(ai.rec.URF_Maintenance_Contract__c, ai.rec.URF_Maintenance_Contract__r.Management_Code__c, ai.rec.URF_Maintenance_Contract__r.Contract_End_Date__c, 1);
            if (String.isNotBlank(ai.rec.URF_Maintenance_Contract__c)) {
                if (urfMContractMap.containsKey(ai.rec.URF_Maintenance_Contract__c)) {
                    urfMContractMap.get(ai.rec.URF_Maintenance_Contract__c).count++;
                } else {
                    urfMContractMap.put(ai.rec.URF_Maintenance_Contract__c, urfMC);
                }
            }
        }
        List<lastMContract> listResulttemp = new List<lastMContract>();
        List<lastMContract> listResult = new List<lastMContract>();
        for ( lastMContract ll : urfMContractMap.values()) {
            listResulttemp.add(ll);
        }
        listResulttemp.sort();
        if (listResulttemp.size() >= 5){
            for (Integer i = 0; i < listResulttemp.size(); i++) {
                if (listResulttemp.size() >= i + 1) {
                    listResult.add(listResulttemp[i]);
                }
            }
        }else {
            for (Integer i = 0; i < listResulttemp.size(); i++) {
                if (listResulttemp.size() >= i + 1) {
                    listResult.add(listResulttemp[i]);
                }
            }
            for (Integer i = listResulttemp.size(); i < 5; i++) {
                listResult.add(new lastMContract(null, null, null, null));
            }
        }
        return listResult;
    }
    //URF限次合同2期 LY 20220908 end
    
    public static List<Data> getChartData() {
        List<Data> data = new List<Data>();
@@ -3544,4 +4688,4 @@
    // return returnValue;
    // 2021-09-10 tcm 排序逻辑调整 end
    }
    }
}