111
沙世明
2022-11-22 928399eceec50e3d37ea08669a12789a9410a9d2
force-app/main/default/classes/SelectAssetEstimateVMController.cls
@@ -116,6 +116,13 @@
    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 isNotFSE { get; set; }
    // 检索按钮
    public PageReference searchBtn() {
        countorder = 1;
@@ -239,7 +246,7 @@
        //2021-11-30 fy add LJPH-C8W8FV 置顶 start OwnershipMachine_No__c Product2.ProductURF__c
        //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, '
@@ -247,10 +254,16 @@
                      //变更多年保续签开始日 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,'
                      //   (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
                      + '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\' ';
@@ -438,6 +451,45 @@
        }
        return false;
    }
   public Boolean gettoApprovalBtnDisabled() {
        if (String.isBlank(this.estimate.IS_Reduced_price_approval__c)) {
            return true;
        }
        return false;
    }
    // 2022故障品加费 提交减价按钮
    public Boolean getSendEmailBtnDisabled() {
        String uProfileId = UserInfo.getProfileId();
        String uProfileName = [SELECT Name FROM Profile WHERE Id =: uProfileId].Name;
        // System.debug(LoggingLevel.INFO, '*** this.disableEmailBtn: ' + this.disableEmailBtn);
        System.debug(LoggingLevel.INFO, '*** this.checkedAssets: ' + this.checkedAssets);
        //简档不确定 待修改
        // Boolean lessE = false;
        // for (AssetInfo  assItemd: this.checkedAssets) {
        //     System.debug(LoggingLevel.INFO, '*** assItemd.mcae.Repair_Price__c: ' + assItemd.mcae.Repair_Price__c);
        //     System.debug(LoggingLevel.INFO, '*** assItemd.Repair_Price_Auto: ' + assItemd.mcae.Repair_Price__c);
        //     if(assItemd.mcae.Repair_Price__c < (assItemd.Repair_Price_Auto* 0.8 ) ){
        //         lessE = true;
        //     }
        // }
        // System.debug(LoggingLevel.INFO, '*** lessE: ' + lessE);
        if(uProfileName == '2F3_合同组' || uProfileName == '系统管理员'){
            return false;
            //测试为false 实际应修改为true
        }else{
            // if (String.isBlank(this.estimate.IS_Reduced_price_approval__c)) {
            //     return true;
            // }
            return false;
        }
    }
    // 20200307 不用
    // public Boolean getcontactBtnDisabled() {
    //     if (String.isBlank(this.contract.Decided_Estimation__c) == false) {
@@ -571,7 +623,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,
@@ -605,7 +657,13 @@
                        //LJPH-C9SCX7 【委托】合同无空白期的提醒  lt  20211221  start
                        //, Maintenance_Contract__r.Past_Contract_end_day__c //过去合同结束日
                        //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
                         FROM Maintenance_Contract_Estimate__c WHERE Id = :this.targetEstimateId];
        //HWAG-B399Q8 2018/08/20  添加一额外字段 IS_Clone_After_Decide__c 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) +
@@ -625,6 +683,11 @@
        }
    }
    
    public PageReference tochange() {
        estimate.IS_Reduced_price_approval__c = '审批中';
        return null;
    }
    public void init() {
        //2021-11-30 fy add LJPH-C8W8FV 置顶 start
        TopProductModel.add('CF-LV1I');
@@ -650,6 +713,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) {
@@ -741,7 +813,7 @@
        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,
            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,
@@ -749,6 +821,10 @@
                            //变更多年保续签开始日 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,
                            //   (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
@@ -758,16 +834,21 @@
                            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
                            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>();
@@ -801,6 +882,11 @@
                //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
                from Maintenance_Contract_Asset__c
                where Maintenance_Contract__c = :this.targetMaintenanceContractId
            ];
@@ -871,6 +957,11 @@
                                                                //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
                                                                LastMContract_Price__c,
                                                                Asset__r.CurrentContract_F_asset__r.Estimate_Cost_Month_formula__c,
                                                                Asset__r.CurrentContract_F_asset__r.endDateGurantee_Text__c,
@@ -899,6 +990,10 @@
                                                                Last_inspection_day__c,
                                                                Check_Result__c,
                                                                Repair_Price__c,
                                                                //   (2022年12月上线)故障品加费 start
                                                                Repair_Price_Auto__c,
                                                                Third_Party_Return__c,
                                                                 //   (2022年12月上线)故障品加费 end
                                                                Comment__c,
                                                                Asset__r.Posting_Date__c,
                                                                EquipmentGuaranteeFlgTxt__c,
@@ -1107,7 +1202,7 @@
            //2021-11-30 fy add LJPH-C8W8FV 置顶 start OwnershipMachine_No__c Product2.ProductURF__c
            //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,'
@@ -1115,11 +1210,17 @@
                            //变更多年保续签开始日 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,'
                            //   (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
                            + '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
@@ -1137,7 +1238,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 {
@@ -1157,7 +1258,7 @@
            //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,';
@@ -1165,11 +1266,17 @@
            //变更多年保续签开始日 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,';
            //   (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
            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\' ) ';
@@ -1188,15 +1295,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)) {
@@ -1281,6 +1388,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) {
@@ -1343,7 +1457,7 @@
        // 20191210 Gzw 服务合同过去3年修理实绩合并
        List<AggregateResult> FriRepairList = [
            select
            sum(Discount_Price_formula__c) SumPrice,
            sum(Repair_List_Price_formula__c) SumPrice,
            //2019/1添加
            sum(Repair_Quotation_Id__r.sales_discount__c) sales_discount,
            sum(Repair_Quotation_Id__r.Contract_target__c) contract_target,
@@ -1367,7 +1481,7 @@
        ];
        List<AggregateResult> SecRepairList = [
            select
            sum(Discount_Price_formula__c) SumPrice,
            sum(Repair_List_Price_formula__c) SumPrice,
            //2019/1添加
            sum(Repair_Quotation_Id__r.sales_discount__c) sales_discount,
            sum(Repair_Quotation_Id__r.Contract_target__c) contract_target,
@@ -1392,7 +1506,7 @@
        // 过去3年间修理实绩
        List<AggregateResult> ThiRepairList = [
            select
            sum(Discount_Price_formula__c) SumPrice,
            sum(Repair_List_Price_formula__c) SumPrice,
            //2019/1添加
            sum(Repair_Quotation_Id__r.sales_discount__c) sales_discount,
            sum(Repair_Quotation_Id__r.Contract_target__c) contract_target,
@@ -1417,7 +1531,7 @@
        // 过去3年修理实绩
        List<AggregateResult> ThreeyearList = [
            select
            sum(Discount_Price_formula__c) SumPrice,
            sum(Repair_List_Price_formula__c) SumPrice,
            //2019/1添加
            sum(Repair_Quotation_Id__r.sales_discount__c) sales_discount,
            sum(Repair_Quotation_Id__r.Contract_target__c) contract_target,
@@ -1551,7 +1665,7 @@
        // 20191210 Gzw 服务合同过去3年修理实绩合并
        List<AggregateResult> FriRepairList = [
            select
            sum(Discount_Price_formula__c) SumPrice,
            sum(Repair_List_Price_formula__c) SumPrice,
            //2019/1添加
            sum(Repair_Quotation_Id__r.sales_discount__c) sales_discount,
            sum(Repair_Quotation_Id__r.Contract_target__c) contract_target,
@@ -1575,7 +1689,7 @@
        ];
        List<AggregateResult> SecRepairList = [
            select
            sum(Discount_Price_formula__c) SumPrice,
            sum(Repair_List_Price_formula__c) SumPrice,
            //2019/1添加
            sum(Repair_Quotation_Id__r.sales_discount__c) sales_discount,
            sum(Repair_Quotation_Id__r.Contract_target__c) contract_target,
@@ -1600,7 +1714,7 @@
        // 过去3年间修理实绩
        List<AggregateResult> ThiRepairList = [
            select
            sum(Discount_Price_formula__c) SumPrice,
            sum(Repair_List_Price_formula__c) SumPrice,
            //2019/1添加
            sum(Repair_Quotation_Id__r.sales_discount__c) sales_discount,
            sum(Repair_Quotation_Id__r.Contract_target__c) contract_target,
@@ -1625,7 +1739,7 @@
        // 过去3年修理实绩
        List<AggregateResult> ThreeyearList = [
            select
            sum(Discount_Price_formula__c) SumPrice,
            sum(Repair_List_Price_formula__c) SumPrice,
            //2019/1添加
            sum(Repair_Quotation_Id__r.sales_discount__c) sales_discount,
            sum(Repair_Quotation_Id__r.Contract_target__c) contract_target,
@@ -2099,7 +2213,6 @@
            return null;
        }
        //add by rentx 2020-11-13 LJPH-BV93RZ end
        NextMaintenanceContract();
    
        Id vmMaintenance_Contract = Schema.SObjectType.Maintenance_Contract_Estimate__c.getRecordTypeInfosByDeveloperName().get('NewMaintenance_Quote').getRecordTypeId();
        estimate.recordtypeid = vmMaintenance_Contract;
@@ -2109,14 +2222,30 @@
        }
         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;
            // 故障品加费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 null;
     }
    /**
     * 印刷メソッド、decide前は保有設備、decide後は合同配置
     */
@@ -2216,8 +2345,6 @@
     * 申請メソッド、最後必ず承認プロセスに載せる
     */
    public PageReference approvalProcess() {
        Id vmMaintenance_Contract = Schema.SObjectType.Maintenance_Contract_Estimate__c.getRecordTypeInfosByDeveloperName().get('NewMaintenance_Quote').getRecordTypeId();
        estimate.recordtypeid = vmMaintenance_Contract;
    
@@ -2277,6 +2404,87 @@
        }
        return null;
    }
    /**
     * FSE修理値引きメール提出 2022故障品加费
     */
    public PageReference sendEmail() {
        // System.debug(LoggingLevel.INFO, '*** in sendEmail: ');
        // // this.estimate
        // // save();
        //  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;
        // }
        // 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});
        // return null;
         System.debug(LoggingLevel.INFO, '*** in sendEmail: ');
        // this.estimate
        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: ');
        return null;
    }
    
    /**
     * 決定取消メソッド
@@ -2300,55 +2508,12 @@
        return null;
    }
    
    public PageReference dosomething() {
        System.debug('dosomething start');
        NextMaintenanceContract();
        return null;
    }
    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');
    }
    /**
     * 決定メソッド
     */
    public PageReference decide() {
        System.debug('decide start');
       NextMaintenanceContract();
        inDicideFlag = true;
        // TODO check decide 资格
        Savepoint sp = Database.setSavepoint();
@@ -2545,7 +2710,36 @@
            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
    
            // 原方法
            // List<lastMContract> lastMContractRes = getlastMContract(this.checkedAssets, this.estimate.Contract_Start_Date__c);
@@ -2857,6 +3051,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) {
@@ -2980,7 +3200,6 @@
            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;
@@ -3202,7 +3421,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;
                    }
@@ -3303,6 +3522,7 @@
    // 新合同备品确保提供 当前标记
    public Boolean etGFlg {get; set;}
    public Integer lineNo {get; private set;}
    public Decimal Repair_Price_Auto {get; set;}
    public Boolean rec_checkBox_c {get; set;}
    public Asset rec { get; set; }
    public Maintenance_Contract_Asset_Estimate__c mcae { get; set; }
@@ -3364,6 +3584,11 @@
    public AssetInfo(Integer lineNo, Asset record, Boolean isNew, Decimal listPrice, Maintenance_Contract_Asset_Estimate__c mcae) {
        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.mcae = new Maintenance_Contract_Asset_Estimate__c(
            //                id = mcae.Id,             // 本当にいらないの? セットしたら、新規権限がなくでも、更新できます。後藤さんに確認した、なくでもいいです。
            isNew__c = isNew,
@@ -3384,8 +3609,10 @@
            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
            );
        this.isManual = false;
        this.rec_checkBox_c = true;
@@ -3435,8 +3662,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;
@@ -3457,6 +3686,11 @@
    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;
@@ -3593,7 +3827,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>();