黄千龙
2023-02-02 389da49a4cf18d0971cc72a34c639b4b22ccd257
VMPage与controller
3个文件已修改
2294 ■■■■■ 已修改文件
force-app/main/default/classes/SelectAssetEstimateVMController.cls 1107 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
force-app/main/default/pages/SelectAssetEstimateVM.page 1185 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
sfdx-project.json 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
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;}
@@ -116,6 +116,25 @@
    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; }
    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,8 +158,6 @@
        cond1ForSort = cond1;
        val1ForSort = val1;
        currPage = 1;
        totalPage = (totalRecords / selctRecordNum) + (Math.mod(totalRecords, selctRecordNum) > 0 ? 1 : 0);
        return null;
    }
@@ -149,6 +166,9 @@
    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 +180,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,18 +270,27 @@
        }
        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; }
            if (markUpUnCheckMap.containsKey(asset.Id) == false) {
                //unCheckedInfoList.add(unCheckMap.get(asset.Id));
                unCheckedAssets.add(new AssetInfo(unCheckedAssets.size(), asset));
                unCheckedAssets.add(new AssetInfo(unCheckedAssets.size(), asset,assNewRepMap));
            }
        }
    }
    
    //检索验证
    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 +325,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 +340,32 @@
            }
        }
        //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,'
                      //多年保设备续签计算逻辑调整 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 +381,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 +453,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 +519,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 +568,46 @@
        }
        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() {
        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) {
@@ -454,6 +630,9 @@
        if (String.isBlank(this.estimate.Process_Status__c) == false
            && this.estimate.Process_Status__c != '草案中'
            //&& this.estimate.Process_Status__c != '不批准'
            //上限合同 LY 20230113 start
            && this.estimate.Process_Status__c != '申请中'
            //上限合同 LY 20230113 start
            ) {
            return true;
        }
@@ -565,7 +744,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 +766,38 @@
                         , Sales_incidental__c, Consumption_rate_Forecast__c, AgencyHos_Price__c
                         // 申请报价金额 和 相对标准价格范围的折扣率
                         , Request_quotation_Amount__c, Service_discount_Rate__c, ContractPriceType__c
                         //上限合同 20230103 LY start
                         ,Limit_Price_Amount__c
                         //上限合同 20230103 LY 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 //过去合同结束日
                        //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;
        //故障品加费 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 +815,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,8 +832,14 @@
        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;
@@ -641,6 +854,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) {
@@ -717,7 +939,7 @@
        // 何もなければ、念のため
        else {
            throw new ControllerUtil.myException('无法显示维修合同报价');
            //return;
            // return;
        }
        //HWAG-B399Q8 2018/08/20  检验是否显示'请提交待审批' start
        IS_Clone_After_Decide = false;
@@ -731,28 +953,49 @@
        // 納入機器の情報を取得
        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
                            //多年保设备续签计算逻辑调整 2023/1/17 start
                            ,CurrentContract_F_asset__r.Asset_Consumption_Rate__c
                            ,Product2.Asset_Model_No__c
                            ,Product2.Category4__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>();
@@ -773,13 +1016,40 @@
                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.Product2.Asset_Model_No__c,
                Asset__r.Product2.Category4__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 +1073,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
@@ -847,9 +1149,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,
@@ -875,6 +1190,11 @@
                                                                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
                                                                Comment__c,
                                                                Asset__r.Posting_Date__c,
                                                                EquipmentGuaranteeFlgTxt__c,
@@ -884,8 +1204,13 @@
                                                                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
                                                                //市场多年保修价格开发 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,6 +1255,8 @@
        // ③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();
        for (Asset ast : this.assetRecords) {
            Boolean isNew = false;
@@ -987,13 +1314,13 @@
                //
                //
                //
                checkedAssets.add(new AssetInfo(checkedAssets.size(), ast, isNew, listPrice, selectedLocal));
                checkedAssets.add(new AssetInfo(checkedAssets.size(), ast, isNew, listPrice, selectedLocal,estimate,assNewRepMap));
            } else {
                //update by rentongxiao 2020-09-23 start
                if (ast.AssetMark__c == '主机') {
                    totalRecords++;
                    if (unCheckedAssets.size() < selctRecordNum) {
                        unCheckedAssets.add(new AssetInfo(unCheckedAssets.size(), ast));
                        unCheckedAssets.add(new AssetInfo(unCheckedAssets.size(), ast,assNewRepMap));
                    }
                }
                //update by rentongxiao 2020-09-23 end
@@ -1008,7 +1335,6 @@
               }
             */
        }
        totalPage = (totalRecords / selctRecordNum) + (Math.mod(totalRecords, selctRecordNum) > 0 ? 1 : 0);
    
        system.debug('顺序检测' + checkedAssets);
@@ -1066,13 +1392,17 @@
    
    // 取得分页数据
    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 +1412,32 @@
            }
            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,'
                            + 'Product2.Asset_Model_No__c,'
                            + 'Product2.Category4__c,'
                            //市场多年保价格开发 start 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 +1455,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 +1475,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,Asset__r.Product2.Asset_Model_No__c,Asset__r.Product2.Category4__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 +1520,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,8 +1542,10 @@
            }
        }
        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));
            this.unCheckedAssets.add(new AssetInfo(unCheckedAssets.size(), ast,assNewRepMap));
        }
        listCut(unCheckedAssets);
        // 根据合同开始日重新计算维修合同价格
@@ -1246,6 +1615,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 +1641,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>();
@@ -1308,7 +1684,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,
@@ -1332,7 +1708,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,
@@ -1357,7 +1733,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,
@@ -1382,7 +1758,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,
@@ -1465,9 +1841,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>();
@@ -1516,7 +1899,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,
@@ -1540,7 +1923,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,
@@ -1565,7 +1948,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,
@@ -1590,7 +1973,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,
@@ -1742,6 +2125,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 +2436,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 +2461,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 +2589,6 @@
     * 申請メソッド、最後必ず承認プロセスに載せる
     */
    public PageReference approvalProcess() {
        Id vmMaintenance_Contract = Schema.SObjectType.Maintenance_Contract_Estimate__c.getRecordTypeInfosByDeveloperName().get('NewMaintenance_Quote').getRecordTypeId();
        estimate.recordtypeid = vmMaintenance_Contract;
    
@@ -2196,7 +2612,7 @@
        //            }
        //        }
        // }
        NextMaintenanceContract();
        if (changedSubmitPrice) {
            priceChangeReset();
            return null;
@@ -2232,6 +2648,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 +2827,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 +2873,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 +2924,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 +2966,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 +3017,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 +3050,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 +3145,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 +3172,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 +3181,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 +3218,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 +3238,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 +3303,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,17 +3314,57 @@
                    //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]) {
@@ -2693,6 +3378,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,6 +3386,12 @@
                                                                      // 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]) {
    
@@ -2718,6 +3410,12 @@
                        // 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
                        LastMContract__c = target.Last_MContract__r.RecordType_DeveloperName__c == 'VM_Contract' ? null : target.Last_MContract__c
                        );
                    newValue.add(newVal);
@@ -2765,6 +3463,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 +3564,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 +3612,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 +3677,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 +3692,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 +3704,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,8 +3797,10 @@
                //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;
                    // 可开始报价的月数限制
@@ -3050,21 +3815,49 @@
                        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') {
        // 多年保判断
        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;
            // 可开始报价的月数限制
            //变更多年保续签开始日 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 + ') -- 没有续签报价权限,或者还没到续签时间。');
                }
                //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 +3868,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 +3961,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,11 +3993,14 @@
    public class AssetInfo {
    // 新合同备品确保提供 当前标记
    public Boolean etGFlg {get; set;}
    public Transient Integer lineNo {get; private 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;}
    // add by fxk 2021/9/9 控制点检对象是否可选 Star
@@ -3202,7 +4023,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 +4036,6 @@
    public void setRecId(Id value) {
        // なにもしない
    }
    // Manual専用
    public AssetInfo(Integer lineNo) {
        this.lineNo = lineNo;
@@ -3234,9 +4056,28 @@
        // 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, Map<String,repair__c> assNewRepMap) {
        this.lineNo = lineNo;
        this.rec = record;
        this.estimate = new Maintenance_Contract_Estimate__c();
        this.estimate.IS_Reduced_price_approval__c = estimate.IS_Reduced_price_approval__c;
        //   (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 +4088,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,
@@ -3257,9 +4099,19 @@
            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.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;
            }
        }
        this.isManual = false;
        this.rec_checkBox_c = true;
        this.orgPrice = record.Maintenance_Price_Month__c;
@@ -3275,6 +4127,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 +4153,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 +4166,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 +4185,54 @@
        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.Agreed_Date__c!=null) {
        //     this.Agreed_Date = '不为空';
        // }else{
        //     this.Agreed_Date = '为空';
        // }
        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;
    }
    public AssetInfo(Integer lineNo, Asset record, Map<String,repair__c> assNewRepMap) {
        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;
@@ -3374,6 +4277,7 @@
            rs = 'Undecide失败';
        }
        return rs;
    }
    
    
@@ -3466,7 +4370,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 +4491,4 @@
    // return returnValue;
    // 2021-09-10 tcm 排序逻辑调整 end
    }
    }
}
force-app/main/default/pages/SelectAssetEstimateVM.page
@@ -1,4 +1,4 @@
<apex:page controller="SelectAssetEstimateVMController" tabStyle="Maintenance_Contract_Estimate__c" sidebar="false" showHeader="true" id="allPage" action="{!init}">
<apex:page controller="SelectAssetEstimateVMController" tabStyle="Maintenance_Contract_Estimate__c" lightningStylesheets="true" sidebar="false" showHeader="true" id="allPage" action="{!init}">
<head>
 <!-- <meta http-equiv="x-ua-compatible" content="ie=edge" /> -->
 <!-- <meta name="viewport" content="width=device-width, initial-scale=1" /> -->
@@ -7,8 +7,8 @@
    <apex:stylesheet value="{!URLFOR($Resource.blockUIcss)}"/>
    <apex:includeScript value="{!URLFOR($Resource.jquery183minjs)}"/>
    <apex:includeScript value="{!URLFOR($Resource.PleaseWaitDialog)}"/>
    <apex:includeScript value="/soap/ajax/29.0/connection.js"/>
    <apex:includeScript value="/soap/ajax/29.0/apex.js"/>
    <apex:includeScript value="{!URLFOR($Resource.connection20)}"/>
    <apex:includeScript value="{!URLFOR($Resource.apex20)}"/>
<style type="text/css">
    table { border-collapse: collapse; }
    
@@ -40,14 +40,45 @@
var Confirm_EstimateRefresh = '已超过创建日3个月,是否更新报价?';
window.sfdcPage.appendToOnloadQueue(function() { calonLoad() });
var RCbottonChanged = 0;
// 2022故障品加费 start
// var RCButtonDisable = document.getElementById("emailSend");
// RCButtonDisable.style.display = "none";
// 2022故障品加费 end
var hasSendEmail = {!hasSendEmail};
console.log('***hasSendEmail',hasSendEmail);
// if(hasSendEmail == true){
//     j$(escapeVfId('allPage:allForm:emailSend')).attr("disabled", true);
//     j$(escapeVfId('allPage:allForm:emailSend')).attr("class", 'btnDisabled');
//     console.log('已提交RC 按钮不可见');
// }
function approvalJs() {
    approvalDate = new Date();
    var rowCnt = j$(escapeVfId('allPage:allForm:allBlock:assetSection:productCnt')).val();
    refreshAsset(rowCnt);
}
//故障品加费 RC 点击后不可见
function rcJs() {
    hasSendEmail = true;
    j$(escapeVfId('allPage:allForm:emailSend')).attr("disabled", true);
    j$(escapeVfId('allPage:allForm:emailSend')).attr("class", 'btnDisabled');
    console.log('点击RC 按钮不可见hasSendEmail' +hasSendEmail);
}
//add by gwy 2021-01-27 start 提交时的提示框
function KindsAndMonths() {
   //   故障品加费 系统检查修理减价审批完成 Start
         ISReduced = j$(escapeVfId('allPage:allForm:allBlock:ISReducedpriceapproval')).val();
        console.log('点击提交待审批时 是否审批通过='+ISReduced);
        if( ISReduced == '审批中' || ISReduced == '有八折以下待审批'){
            alert('请通过修理减价审批再提交');
            // approvalbtntop1.style.display = "none";
            return false;
        }
    //   故障品加费 系统检查修理减价审批完成 end
    var months      = localParseFloat(j$(escapeVfId('allPage:allForm:allBlock:contract:monthRange')).val());
    var contrNew    = document.getElementById("allPage:allForm:allBlock:contractInfo:Contract_TypeTXT").innerHTML;
    if(months>12 && months<60 && contrNew == '新品合同'){
@@ -57,7 +88,17 @@
            return false;  
        }
    }
        return true;
    // 先款后修-提交报价时如果是先款对象进行提示 thh 20220408 start
    var FirstParagraphEnd = j$(escapeVfId('allPage:allForm:allBlock:contract:FirstParagraphEnd'))[0].checked;
    if(FirstParagraphEnd){
        if (confirm('本次签约经销商是先款对象,请确认是否提交报价?')) {
            return true;
        }else{
            return false;
        }
    }
    // 先款后修-提交报价时如果是先款对象进行提示 thh 20220408 end
    return true;
}
//add by gwy 2021-01-27 end 提交时的提示框
@@ -79,6 +120,9 @@
    j$("#sbArea").fadeOut(500, function(){
        j$("#sbArea").remove();
    });
    console.log('发送邮件成功');
}
//<!-- HWAG-B4R3SS  START 20181026-->
function clearAndSearch() {
@@ -95,8 +139,30 @@
//<!-- HWAG-B4R3SS  END 20181026-->
// 初始化设定画面项目不可用
function pageSetDisabled(){
    // if (RCbottonChanged == 0) {
    //     console.log('test初始化');
        // 故障品加费 提交RC按钮不可见 start
        // j$(escapeVfId('allPage:allForm:emailSend')).attr("disabled", true);
        // j$(escapeVfId('allPage:allForm:emailSend')).attr("class", 'btnDisabled');
        // 故障品加费 提交RC按钮不可见 end
    // }
    // 故障品加费 start
    var hasSendEmail ={!hasSendEmail};
    console.log('page hasSendEmail',hasSendEmail);
    if(hasSendEmail == true){
        j$(escapeVfId('allPage:allForm:emailSend')).attr("disabled", true);
        j$(escapeVfId('allPage:allForm:emailSend')).attr("class", 'btnDisabled');
        console.log('已提交RC 按钮不可见 page set');
    }
    //故障品加费 end
    var isDisabled = {!PageDisabled};
    // ResonCannotWarranty = j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':ResonCannotWarranty')).value();
    // if(!ResonCannotWarranty.contains("弃修")){
    //     j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':Repair_Price_Auto')).attr("display", none);
    // }
    if (isDisabled) {
        j$(escapeVfId('allPage:allForm:allBlock:contract:depart')).attr("disabled", true);
        j$(escapeVfId('allPage:allForm:allBlock:contract:startdate')).attr("disabled", true);
        j$(escapeVfId('allPage:allForm:allBlock:contract:monthRange')).attr("disabled", true);
@@ -113,6 +179,7 @@
            j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':assetCheck')).attr("disabled", true);
            j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':repairPrice')).attr("disabled", true);
            j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':comment')).attr("disabled", true);
            j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':Third_Party_Return__c')).attr("disabled", true);
        }
        j$(escapeVfId('allPage:allForm:allBlock:appendCondition:Examination_Count')).attr("disabled", true);
        j$(escapeVfId('allPage:allForm:allBlock:contractInfo:disPercent')).attr("disabled", true);
@@ -181,6 +248,16 @@
    // 2021、8、26 合同报价页面的优化,无保有设备点检对象选择框变黑 fxk star
    // disable1();
    // 2021、8、26 合同报价页面的优化,无保有设备点检对象选择框变黑 fxk end
    console.log('ApprovalBtnDisabled=='+{!ApprovalBtnDisabled});
    //上限合同 20230103 LY start
    var mainteReal = j$(escapeVfId('allPage:allForm:allBlock:contractInfo:mainteReal')).text();
    Limit_Price_Amount = localParseFloat(mainteReal)*1.3;
    // console.log('Limit_Price_Amount'+Limit_Price_Amount);
    Limit_Price_AmountOne =  j$(escapeVfId('allPage:allForm:allBlock:contractInfo:Limit_Price_Amount')).value();
    if (Limit_Price_AmountOne*1==0) {
        j$(escapeVfId('allPage:allForm:allBlock:contractInfo:Limit_Price_Amount')).val(Limit_Price_Amount);
    }
    //上限合同 20230103 LY end
    pageSetDisabled();
    var createdDate = new Date('{!estimate.CreatedDate}');
    // 报价中设备的机身编码为空时的新品合同有效期延长 20200710 gzw
@@ -212,6 +289,11 @@
            //j$(escapeVfId('allPage:allForm:decidebtn')).attr("disabled", true);
            j$(escapeVfId('allPage:allForm:savebtn')).attr("class", 'btnDisabled');
            j$(escapeVfId('allPage:allForm:approvalbtn')).attr("class", 'btnDisabled');
            //故障品加费 RC按钮
            j$(escapeVfId('allPage:allForm:emailSend')).attr("disabled", true);
            j$(escapeVfId('allPage:allForm:emailSend')).attr("class", 'btnDisabled');
            //j$(escapeVfId('allPage:allForm:decidebtn')).attr("class", 'btnDisabled');
            
            if (confirm(Confirm_EstimateRefresh)) {
@@ -244,6 +326,10 @@
            //j$(escapeVfId('allPage:allForm:decidebtn')).attr("disabled", true);
            j$(escapeVfId('allPage:allForm:savebtn')).attr("class", 'btnDisabled');
            j$(escapeVfId('allPage:allForm:approvalbtn')).attr("class", 'btnDisabled');
            //故障品加费RC按钮
            j$(escapeVfId('allPage:allForm:emailSend')).attr("disabled", true);
            j$(escapeVfId('allPage:allForm:emailSend')).attr("class", 'btnDisabled');
            //j$(escapeVfId('allPage:allForm:decidebtn')).attr("class", 'btnDisabled');
            
            if (confirm('已超过创建日6个月,是否更新报价?')) {
@@ -306,6 +392,10 @@
    //val = Math.round(val * 100) / 100;
    val = Math.round(val);
    j$(escapeVfId('allPage:allForm:allBlock:contractInfo:quotation_Amount')).val(toNumComma(val));
    //上限合同 20230117 HQL start
     console.log('上限金额填入:'+val*1.3);
    j$(escapeVfId('allPage:allForm:allBlock:contractInfo:Limit_Price_Amount')).val(val*1.3);
    //上限合同 20230117 HQL end
   makeRealPrice(1);
}
@@ -329,13 +419,23 @@
    //contractStartDateChange();
    refreshAsset(cnt);
}
function toChange1(){
    tochange();
    ISReducedpriceapproval = j$(escapeVfId('allPage:allForm:allBlock:ISReducedpriceapproval')).val();
    console.log('方法1是否审批通过=='+ISReducedpriceapproval+'====================');
}
function toChange2(){
    tochange2();
    ISReducedpriceapproval = j$(escapeVfId('allPage:allForm:allBlock:ISReducedpriceapproval')).val();
    console.log('方法2是否审批通过=='+ISReducedpriceapproval+'==============');
}
function refreshAsset(cnt) {
    //alert('1111111111');
     // alert(cnt);
    // 提交后就页面不计算了
    var isDisabled = {!PageDisabled};
    // 合同总理
    var newCount = 0;
    var isresduce = 0;
    var oyearCount = 0;
    var firstCCount = 0;
    var conCCount = 0;
@@ -345,7 +445,25 @@
    // 新品合同 判断
    var newCon = true;
    var contractStartDate = new Date(j$(escapeVfId('allPage:allForm:contractstartdate')).value());
    //上限合同 20230103 LY start
    var mainteReal = j$(escapeVfId('allPage:allForm:allBlock:contractInfo:mainteReal')).text();
    Limit_Price_Amount = localParseFloat(mainteReal)*1.3;
    Limit_Price_AmountOne =  j$(escapeVfId('allPage:allForm:allBlock:contractInfo:Limit_Price_Amount')).value();
    console.log('Limit_Price_AmountOne'+Limit_Price_AmountOne);
    if (Limit_Price_AmountOne*1==0) {
        j$(escapeVfId('allPage:allForm:allBlock:contractInfo:Limit_Price_Amount')).val(Limit_Price_Amount);
    }
    //上限合同 20230103 LY end
    //多年保续签合同数量 thh 20220316 start
    var GuranteeCount = 0;
    //多年保续签合同数量 thh 20220316 end
    //2022故障品加费 获取userInfo简档名称 是否为FSE start
    var isFSE = {!isFSE};
    // var isFSE = true;
    console.log('***isFSE',isFSE);
    //2022故障品加费 获取userInfo简档名称 end
    // 预定开始日
    var startdate = new Date(j$(escapeVfId('allPage:allForm:allBlock:contract:startdate')).value());
@@ -383,7 +501,7 @@
        var downPrice = 0;
        // 上线价格
        var upPrice = 0;
        // 12个月合同金额
        var Price_YearTXT = 0;
        
@@ -412,6 +530,7 @@
                }
                var b = j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':Contract_No')).value();
                var LastMContractRecord = j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':LastMContractRecord')).value();
                console.log('***维修合同记录类型1'+LastMContractRecord);
                if(b != ''){
                    conCCount ++;
                    // 1.合同期不满一年时,合同期超过一半才可开始续签报价。(eg:11个月的合同从6个月后才可报价。)
@@ -422,6 +541,10 @@
                    var lastContRange = 0;
                    if(LastMContractRecord == 'VM_Contract'){
                        newCount++;
                        //多年保续签合同数量,多年保续签到服务合同时视为首签设备 thh 20220316 start
                        GuranteeCount++;
                        newCon = false;
                        //多年保续签合同数量,多年保续签到服务合同时视为首签设备 thh 20220316 end
                        lastendDate = new Date(j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':endDateGurantee_Text')).value());
                        lastContRange = 36;
                    }else{
@@ -429,7 +552,7 @@
                    }
                    //最后结束日+1年
                    lastendDate.setMonth(lastendDate.getMonth() + 12);
                    if (Date.parse(contractStartDate) > Date.parse(lastendDate)) {
                    if (Date.parse(contractStartDate) > Date.parse(lastendDate) ) {
                        oyearCount ++;
                    }
                    // 取联动价格
@@ -447,10 +570,120 @@
                    var Estimate_Num = j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':Estimate_NumHidden')).val();
                    if(Estimate_Num == 0){
                        if(LastMContractRecord == 'VM_Contract'){
                            //upPrice = (strMoney) * (1 + Adjustment_ratio_Upper/100);
                            //downPrice = (strMoney) * (1 + Adjustment_ratio_Lower/100);
                            upPrice = (assetListmonth * Punish) * (1 + Adjustment_ratio_Upper/100);
                            downPrice = (assetListmonth * Punish) * (1 + Adjustment_ratio_Lower/100);
                            // gzw 20220630  实际联动6个月价格区分
                            var nowdate = new Date();
                            lastendDate = new Date(j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':endDateGurantee_Text')).value());
                            nowdate = nowdate.setMonth(nowdate.getMonth() + 6);
                            //市场多年保修价格开发 DC 2023/1/30 start
                            //消费率 展示修改为市场多年保设备消费率
                            // j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':AssetConsumptionRateNew')).attr("style", "display:block");
                            // j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':Contractrate')).attr("style", "display:none");
                            var Maxcoefficient =0;
                            var Mincoefficient =0;
                            var AssetRate = localParseFloat(j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':AssetConsumptionRateNew')).val());
                            console.log('***消费率:'+AssetRate);
                             j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':Contractrate')).text(AssetRate +'%');
                            if(AssetRate>0 &&AssetRate<=0.5){
                                Maxcoefficient = (1-0.3);
                                Mincoefficient = (1-0.4);
                            }else if(AssetRate>0.5 &&AssetRate<=0.6){
                                Maxcoefficient = (1-0.2);
                                Mincoefficient = (1-0.3);
                            }else if(AssetRate>0.6 &&AssetRate<=0.7){
                                Maxcoefficient = (1-0.15);
                                Mincoefficient = (1-0.25);
                            }else if(AssetRate>0.7 &&AssetRate<=0.8){
                                Maxcoefficient = (1-0.1);
                                Mincoefficient = (1-0.2);
                            }else if(AssetRate>0.8 &&AssetRate<=0.9){
                                Maxcoefficient = (1-0.05);
                                Mincoefficient = (1-0.15);
                            }else if(AssetRate>0.9 &&AssetRate<=1.0){
                                Maxcoefficient = 1;
                                Mincoefficient = (1-0.05);
                            }else if(AssetRate>1.0 &&AssetRate<=1.1){
                                Maxcoefficient = (1+0.05);
                                Mincoefficient = 1;
                            }else if(AssetRate>1.1 &&AssetRate<=1.2){
                                Maxcoefficient = (1+0.1);
                                Mincoefficient = 1;
                            }else if(AssetRate>1.2 &&AssetRate<=1.3){
                                Maxcoefficient = (1+0.2);
                                Mincoefficient = (1+0.1);
                            }else if(AssetRate>1.3 &&AssetRate<=1.4){
                                Maxcoefficient = (1+0.25);
                                Mincoefficient = (1+0.15);
                            }else if(AssetRate>1.4){
                                Maxcoefficient = (1+0.3);
                                Mincoefficient = (1+0.2);
                            }
                            //市场多年保修价格开发 DC 2023/1/30 end
                            console.log('***最高系数'+Maxcoefficient);
                            console.log('***最低系数'+Mincoefficient);
                        if(nowdate < Date.parse(lastendDate)){
                            //设备小于两年半
                            // upPrice = strMoney;
                            // downPrice = strMoney * 0.8;
                        console.log('***小于2年半')
                        // 市场多年保修价格开发 start DC 2023/01/19
                            //市场多年保设备小于2年半
                            var AssetModelNo = j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':Asset_Model_No__c')).value();
                            var Category4 = j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':Category4__c')).value();
                            console.log('***设备型号'+AssetModelNo);
                            console.log('***产品类型'+Category4);
                            //设备设备消费率小于1.4
                            if(AssetRate<1.4){
                                upPrice = strMoney;
                                console.log('消费率小于1.4 upPrice = strmonye'+ upPrice);
                                if(AssetModelNo.includes('290')|| Category4 =='BF'|| Category4=='BF扇扫'|| Category4=='GIF'||Category4=='CF' || Category4.includes('GF')){
                                    downPrice = upPrice;
                                    console.log('消费率小于1.4 产品无最低价 downPrice '+ downPrice);
                                }else{
                                    downPrice = upPrice * 0.8;
                                    console.log('消费率小于1.4 产品最低价 downPrice = upPrice* 0.8:'+ downPrice);
                                }
                            }else{
                                upPrice = assetListmonth * month *Maxcoefficient / 12;
                                downPrice = assetListmonth * month * Mincoefficient / 12;
                                console.log('消费率大于1.4 upPrice'+ upPrice);
                                console.log('消费率大于1.4 downPrice'+ downPrice);
                            }
                            // 市场多年保修价格开发 end DC 2023/01/19
                            }else{
                                // upPrice = (assetListmonth * Punish) * (1 + Adjustment_ratio_Upper/100);
                                // downPrice = (assetListmonth * Punish) * (1 + Adjustment_ratio_Lower/100);
                                //市场多年保修价格开发 DC 2023/1/30 start  设备大于2年半 续签价格 = 定价 *消费率对应系数 / 12 *合同月数
                                upPrice = assetListmonth * month *Maxcoefficient / 12;
                                downPrice = assetListmonth * month * Mincoefficient / 12;
                                //市场多年保修价格开发 DC 2023/1/30 end
                            }
                            // gzw 20220630  实际联动6个月价格区分
                        }else{
                            upPrice = strMoney;
                            downPrice = strMoney * 0.8;
@@ -515,8 +748,10 @@
            } else {
                strMoney = month * strMoney + month2 * strMoney;
            }
            var b = j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':Contract_No')).value();
            var b = j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':Contract_No')).value();
            var LastMContractRecord = j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':LastMContractRecord')).value();
            console.log('***维修合同记录类型2'+LastMContractRecord);
            if(b != ''){
                conCCount ++;
                // 1.合同期不满一年时,合同期超过一半才可开始续签报价。(eg:11个月的合同从6个月后才可报价。)
@@ -526,6 +761,10 @@
                var lastContRange = 0;
                if(LastMContractRecord == 'VM_Contract'){
                    newCount++;
                    //多年保续签合同数量,多年保续签到服务合同时视为首签设备 thh 20220316 start
                    GuranteeCount++;
                    newCon = false;
                    //多年保续签合同数量,多年保续签到服务合同时视为首签设备 thh 20220316 end
                    lastendDate = new Date(j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':endDateGurantee_Text')).value());
                    lastContRange = 36;
                }else{
@@ -533,6 +772,8 @@
                }
                //最后结束日+1年
                lastendDate.setMonth(lastendDate.getMonth() + 12);
                // alert('+++++++++--------' + lastendDate);
                // alert('+++++++++--------' + Date.parse(contractStartDate) + '77777' + Date.parse(lastendDate));
                if (Date.parse(contractStartDate) > Date.parse(lastendDate)) {
                    oyearCount ++;
                }
@@ -551,10 +792,126 @@
                var Estimate_Num = j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':Estimate_NumHidden')).val();
                if(Estimate_Num == 0){
                    if(LastMContractRecord == 'VM_Contract'){
                        //upPrice = (strMoney) * (1 + Adjustment_ratio_Upper/100);
                        //downPrice = (strMoney) * (1 + Adjustment_ratio_Lower/100);
                        upPrice = (assetListmonth * Punish) * (1 + Adjustment_ratio_Upper/100);
                        downPrice = (assetListmonth * Punish) * (1 + Adjustment_ratio_Lower/100);
                        // alert('11111');
                        // gzw 20220630  实际联动6个月价格区分
                        var nowdate = new Date();
                        lastendDate = new Date(j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':endDateGurantee_Text')).value());
                        nowdate = nowdate.setMonth(nowdate.getMonth() + 6);
                        //市场多年保修价格开发 DC 2023/1/30 start
                            //消费率 展示修改为市场多年保设备消费率
                            // j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':AssetConsumptionRateNew3')).attr("style", "display:block");
                            //  var AssetRate2 = j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':AssetConsumptionRateNew2')).value();
                            // console.log('***消费率2:'+AssetRate2);
                            //  var AssetRate3 = localParseFloat(j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':AssetConsumptionRateNew3')).value());
                            // console.log('***消费率3:'+AssetRate3);
                            var Maxcoefficient =0;
                            var Mincoefficient =0;
                            var AssetRate = localParseFloat(j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':AssetConsumptionRateNew')).val());
                            console.log('***消费率:'+AssetRate);
                             j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':Contractrate')).text(AssetRate +'%');
                            if(AssetRate>0 &&AssetRate<=0.5){
                                Maxcoefficient = (1-0.3);
                                Mincoefficient = (1-0.4);
                            }else if(AssetRate>0.5 &&AssetRate<=0.6){
                                Maxcoefficient = (1-0.2);
                                Mincoefficient = (1-0.3);
                            }else if(AssetRate>0.6 &&AssetRate<=0.7){
                                Maxcoefficient = (1-0.15);
                                Mincoefficient = (1-0.25);
                            }else if(AssetRate>0.7 &&AssetRate<=0.8){
                                Maxcoefficient = (1-0.1);
                                Mincoefficient = (1-0.2);
                            }else if(AssetRate>0.8 &&AssetRate<=0.9){
                                Maxcoefficient = (1-0.05);
                                Mincoefficient = (1-0.15);
                            }else if(AssetRate>0.9 &&AssetRate<=1.0){
                                Maxcoefficient = 1;
                                Mincoefficient = (1-0.05);
                            }else if(AssetRate>1.0 &&AssetRate<=1.1){
                                Maxcoefficient = (1+0.05);
                                Mincoefficient = 1;
                            }else if(AssetRate>1.1 &&AssetRate<=1.2){
                                Maxcoefficient = (1+0.1);
                                Mincoefficient = 1;
                            }else if(AssetRate>1.2 &&AssetRate<=1.3){
                                Maxcoefficient = (1+0.2);
                                Mincoefficient = (1+0.1);
                            }else if(AssetRate>1.3 &&AssetRate<=1.4){
                                Maxcoefficient = (1+0.25);
                                Mincoefficient = (1+0.15);
                            }else if(AssetRate>1.4){
                                Maxcoefficient = (1+0.3);
                                Mincoefficient = (1+0.2);
                            }
                            //市场多年保修价格开发 DC 2023/1/30 end
                            console.log('***最高系数'+Maxcoefficient);
                            console.log('***最低系数'+Mincoefficient);
                        if(nowdate < Date.parse(lastendDate)){
                            //设备小于两年半
                            // upPrice = strMoney;
                            // downPrice = strMoney * 0.8;
                        console.log('***小于2年半')
                        // 市场多年保修价格开发 start DC 2023/01/19
                            //市场多年保设备小于2年半
                            var AssetModelNo = j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':Asset_Model_No__c')).value();
                            var Category4 = j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':Category4__c')).value();
                            console.log('***设备型号'+AssetModelNo);
                            console.log('***产品类型'+Category4);
                            //设备设备消费率小于1.4
                            if(AssetRate<1.4){
                                upPrice = strMoney;
                                console.log('消费率小于1.4 upPrice = strmonye'+ upPrice);
                                if(AssetModelNo.includes('290')|| Category4 =='BF'|| Category4=='BF扇扫'|| Category4=='GIF'||Category4=='CF' || Category4.includes('GF')){
                                    downPrice = upPrice;
                                    console.log('消费率小于1.4 产品无最低价 downPrice '+ downPrice);
                                }else{
                                    downPrice = upPrice * 0.8;
                                    console.log('消费率小于1.4 产品最低价 downPrice = upPrice* 0.8:'+ downPrice);
                                }
                            }else{
                                upPrice = assetListmonth * month *Maxcoefficient / 12;
                                downPrice = assetListmonth * month * Mincoefficient / 12;
                                console.log('消费率大于1.4 upPrice'+ upPrice);
                                console.log('消费率大于1.4 downPrice'+ downPrice);
                            }
                        // 市场多年保修价格开发 end DC 2023/01/19
                        }else{
                            //设备大于两年半
                            // upPrice = (assetListmonth * Punish) * (1 + Adjustment_ratio_Upper/100);
                            // downPrice = (assetListmonth * Punish) * (1 + Adjustment_ratio_Lower/100);
                            //市场多年保修价格开发 DC 2023/1/30 start  设备大于2年半 续签价格 = 定价 *消费率对应系数 / 12 *合同月数
                            upPrice = assetListmonth * month *Maxcoefficient / 12;
                            downPrice = assetListmonth * month * Mincoefficient / 12;
                            //市场多年保修价格开发 DC 2023/1/30 end
                        }
                        // gzw 20220630  实际联动6个月价格区分
                    }else{
                        upPrice = strMoney;
                        downPrice = strMoney * 0.8;
@@ -589,14 +946,68 @@
            }
            //j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':assetListPrice')).text(toNumComma(strMoney));
            j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':assetListPricePageHidden')).val(strMoney);
            //
            repairMoney = j$.trim(j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':repairPrice')).value());
            //<!-- (2022年12月上线)故障品加费 start -->
            Repair_Price_AutoPrice = j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':Repair_Price_Auto'));
            Repair_Price_Auto = Repair_Price_AutoPrice.value();
            repairMoney = j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':repairPrice')).value();
            Repair_Price_pass = j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':Repair_Price_pass')).val();
            console.log((i+1)+'号repairMoney='+repairMoney);
            console.log((i+1)+'号Repair_Price_Auto='+Repair_Price_Auto);
            if ((repairMoney+1)==1) {
                j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':repairPrice')).val(Repair_Price_Auto);
                console.log('repairMoney修改成功');
            }
            if ((Repair_Price_pass+1)==1) {
                j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':Repair_Price_pass')).val(Repair_Price_Auto);
                console.log('Repair_Price_pass修改成功');
            }
            repairMoney1 = localParseFloat(repairMoney);
            ISReducedpriceapproval = j$(escapeVfId('allPage:allForm:allBlock:ISReducedpriceapproval')).val();
            console.log('ISReducedpriceapproval=='+ISReducedpriceapproval);
            if (ISReducedpriceapproval =='有八折以下待审批' || ISReducedpriceapproval =='是') {
                j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':repairPrice')).attr("disabled", true);
            }else{
                j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':repairPrice')).attr("disabled", false);
            }
            ISReducedpriceapproval1 = j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':ISReducedpriceapproval1')).val();
            ISReduced = j$(escapeVfId('allPage:allForm:allBlock:ISReducedpriceapproval')).val();
            if (repairMoney1> 0 && (repairMoney1 <Repair_Price_Auto*0.80)) {
                isresduce = isresduce+1;
            }
            console.log('初始化isresduce='+isresduce);
            ResonCannotWarranty = j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':ResonCannotWarranty')).value();
            rppa =  document.getElementById('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':Repair_Price_Auto');
            situation = j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':Asset_situation')).value();
            // Agreed_Date =  j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':Agreed_Date')).value();
            console.log('situation='+situation);
            // console.log('Agreed_Date1='+Agreed_Date);
            if(ResonCannotWarranty!=null&&!(ResonCannotWarranty.indexOf("弃修") != -1)){
                // if (!(situation.indexOf("修理中")!=-1)&& !(Agreed_Date.indexOf("为空")!=-1)) {
                    rppa.style.display = "none";
                // }
            }
            console.log('判断1'+(situation.indexOf("修理中")!=-1));
            // console.log('判断'+(Agreed_Date.indexOf("不为空")!=-1));
            // if ((situation.indexOf("修理中")!=-1)&& (Agreed_Date.indexOf("不为空")!=-1)) {
            //     console.log('开始操作2');
            //     j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':Repair_Price_Auto')).val(0);
            //     j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':repairPrice')).val(0);
            // }
        //<!-- (2022年12月上线)故障品加费 end -->
        }
        repairSum = repairSum + localParseFloat(repairMoney);
        listSum = listSum + localParseFloat(toNum(strMoney));
        downPriceSum = downPriceSum + localParseFloat(toNum(downPrice));
        upPriceSum =  upPriceSum + localParseFloat(toNum(upPrice));
    }
    j$(escapeVfId('allPage:allForm:allBlock:assetRepairSumNum')).text(toNumComma(repairSum));
    //j$(escapeVfId('allPage:allForm:allBlock:assetListSumNum')).text(toNumComma(listSum));
    
@@ -615,26 +1026,649 @@
    var result = '';
    if (allcount == 0) {
        result = null;
    }else
    if (newCount > 0 && newCount == allcount && newCon == true) {
    //如果所有设备的上期合同都是多年保合同,则合同种类为市场多年保续签合同 thh 20220315 start
    }else if(GuranteeCount > 0 && GuranteeCount == allcount){
        result = '市场多年保续签合同';
    //如果所有设备的上期合同都是多年保合同,则合同种类为市场多年保续签合同 thh 20220315 end
    }else if (newCount > 0 && newCount == allcount && newCon == true) {
        result = '新品合同';
    }else if (((newCount > 0 && newCount == allcount) ||(newCount + firstCCount == allcount)) && newCon == false) {
        result = '首签合同';
    }else if(firstCCount > 0 && firstCCount == allcount){
        result = '首签合同';
    }else if(oyearCount > 0 && oyearCount == conCCount){
    // 20220328 ljh update  LJPH-C8FB4P【委托】配合PBI设备覆盖率的数据准备 start
    // }else if(oyearCount > 0 && oyearCount == conCCount){
    }else if(oyearCount > 0 && oyearCount == conCCount && allcount == oyearCount ){
    // 20220328 ljh update  LJPH-C8FB4P【委托】配合PBI设备覆盖率的数据准备 start
        result = '非续签合同(空白期一年以上)';
    }else{
        result = '续签合同';
    }
    console.log(result);
    document.getElementById("allPage:allForm:allBlock:contractInfo:Contract_TypeTXT").innerHTML = result;
    document.getElementById("allPage:allForm:allBlock:contractInfo:Contract_TypeTXTHidden").value = result;
    // 取消酸化水
    //NotUseOxygenatedWaterAmount(1);
    examinationPriceCal(cnt);
    getLastContractRate();
}
function changeAsset(cnt) {
    // alert(cnt);
    // 提交后就页面不计算了
    var isDisabled = {!PageDisabled};
    // 合同总理
    var newCount = 0;
    var isresduce = 0;
    var oyearCount = 0;
    var firstCCount = 0;
    var conCCount = 0;
    // row金額合計
    var repairSum = 0;
    var listSum = 0;
    // 新品合同 判断
    var newCon = true;
    var contractStartDate = new Date(j$(escapeVfId('allPage:allForm:contractstartdate')).value());
    //多年保续签合同数量 thh 20220316 start
    var GuranteeCount = 0;
    //多年保续签合同数量 thh 20220316 end
    //2022故障品加费 获取userInfo简档名称 是否为FSE start
    var isFSE = {!isFSE};
    // var hasSendEmail = {!hasSendEmail};
    // var isFSE = true;
    console.log('***isFSE',isFSE);
    // console.log('***hasSendEmail',hasSendEmail);
    // if(hasSendEmail == true){
    //     j$(escapeVfId('allPage:allForm:emailSend')).attr("disabled", true);
    //     j$(escapeVfId('allPage:allForm:emailSend')).attr("class", 'btnDisabled');
    //     console.log('8折以下提交RC可见 ');
    // }
    //2022故障品加费 获取userInfo简档名称 end
    // 预定开始日
    var startdate = new Date(j$(escapeVfId('allPage:allForm:allBlock:contract:startdate')).value());
    // 预定开始日-6个月
    startdate.setMonth(startdate.getMonth() - 6);
    // 申请日 当前日期
    if(approvalDate != ''){
        //申请日
        approvalDate = new Date(approvalDate.toLocaleDateString());
        if (Date.parse(approvalDate) < Date.parse(startdate)) {
            newCon = false;
        }
    }
    // 最高、最低价格合计
    var downPriceSum = 0;
    var upPriceSum = 0;
    // 合同月数乗算
    var month = localParseFloat(j$(escapeVfId('allPage:allForm:allBlock:contract:monthRange')).val());
    if (month == undefined || month == "") {
        month = 1;
    }
    var month2 = 0;
    if (month > 12) {
        month2 = month - 12;
        month = 12;
    }
    for (var i = 0; i < cnt; i++) {
        var strMoney = 0;
        var repairMoney = 0;
        // 行项目 最高、最低价格合计
        // 续签价格取联动价格页面计算,首签或产品取 实际价格
        // 下线价格
        var downPrice = 0;
        // 上线价格
        var upPrice = 0;
        // 12个月合同金额
        var Price_YearTXT = 0;
        var isManual = j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':IsManual')).text();
        var isnew = j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':assetNewHidden')).val();
        var assetListmonth = j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':assetListPriceHidden')).val();
        if (isManual == 'true') {
            var a = j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':Assert')).value();
            if (a != '') {
                // 所有设备按安装日、发货日(最早的),距离合同开始日6个月内都是新品合同
                //var isNewDate = new Date(j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':isNewDate')).value());
                //isNewDate.setMonth(isNewDate.getMonth() + 6);
                //if (Date.parse(contractStartDate) > Date.parse(isNewDate)) {
                //    newCon = false;
                //}
                strMoney = j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':assetListPriceHidden')).val();
                //市场多年保修价格开发 DC 2023/1/30 start
                var LastMContractRecord = j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':LastMContractRecord')).value();
                // alert(strMoney);
                console.log('***维修合同记录类型3'+LastMContractRecord);
                Price_YearTXT = strMoney * 12;
                if (isnew == 'true') {
                    newCount ++;
                    strMoney = month * strMoney + month2 * strMoney / {!isNewPriceAdj};
                } else {
                    newCon = false;
                    strMoney = month * strMoney + month2 * strMoney;
                }
                var b = j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':Contract_No')).value();
                // var LastMContractRecord = j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':LastMContractRecord')).value();
                if(b != ''){
                    conCCount ++;
                    // 1.合同期不满一年时,合同期超过一半才可开始续签报价。(eg:11个月的合同从6个月后才可报价。)
                    // 2.一年以上的合同,在结束前6个月开始可以开放续签报价。
                    var lastendDate = new Date(j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':End_Date')).value());
                    var lastContRange = 0;
                    if(LastMContractRecord == 'VM_Contract'){
                        newCount++;
                        //多年保续签合同数量,多年保续签到服务合同时视为首签设备 thh 20220316 start
                        GuranteeCount++;
                        newCon = false;
                        //多年保续签合同数量,多年保续签到服务合同时视为首签设备 thh 20220316 end
                        lastendDate = new Date(j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':endDateGurantee_Text')).value());
                        lastContRange = 36;
                    }else{
                        lastContRange = j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':lastContRange')).value();
                    }
                    //最后结束日+1年
                    lastendDate.setMonth(lastendDate.getMonth() + 12);
                    if (Date.parse(contractStartDate) > Date.parse(lastendDate) ) {
                        oyearCount ++;
                    }
                    // 取联动价格
                    // 上一期合同实际报价月额
                    //
                    var LastMContract_Price = localParseFloat(j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':LastMContract_Price')).val());
                    var Adjustment_ratio_Lower = localParseFloat(j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':Adjustment_ratio_Lower')).val());
                    var Adjustment_ratio_Upper = localParseFloat(j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':Adjustment_ratio_Upper')).val());
                    //计算惩罚率
                    var Punish = calculateNtoMRatio( lastContRange,(month + month2));
                    if(Punish == 0){
                        return;
                    }
                    // 判断有无报价:没有按照标准价格实际联动
                    var Estimate_Num = j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':Estimate_NumHidden')).val();
                    if(Estimate_Num == 0){
                        if(LastMContractRecord == 'VM_Contract'){
                            // gzw 20220630  实际联动6个月价格区分
                            var nowdate = new Date();
                            lastendDate = new Date(j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':endDateGurantee_Text')).value());
                            nowdate = nowdate.setMonth(nowdate.getMonth() + 6);
                            //市场多年保修价格开发 DC 2023/1/30 start
                            var Maxcoefficient =0;
                            var Mincoefficient =0;
                            var AssetRate = localParseFloat(j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':AssetConsumptionRateNew')).val());
                            console.log('***消费率:'+AssetRate);
                             j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':Contractrate')).text(AssetRate +'%');
                            if(AssetRate>0 &&AssetRate<=0.5){
                                Maxcoefficient = (1-0.3);
                                Mincoefficient = (1-0.4);
                            }else if(AssetRate>0.5 &&AssetRate<=0.6){
                                Maxcoefficient = (1-0.2);
                                Mincoefficient = (1-0.3);
                            }else if(AssetRate>0.6 &&AssetRate<=0.7){
                                Maxcoefficient = (1-0.15);
                                Mincoefficient = (1-0.25);
                            }else if(AssetRate>0.7 &&AssetRate<=0.8){
                                Maxcoefficient = (1-0.1);
                                Mincoefficient = (1-0.2);
                            }else if(AssetRate>0.8 &&AssetRate<=0.9){
                                Maxcoefficient = (1-0.05);
                                Mincoefficient = (1-0.15);
                            }else if(AssetRate>0.9 &&AssetRate<=1.0){
                                Maxcoefficient = 1;
                                Mincoefficient = (1-0.05);
                            }else if(AssetRate>1.0 &&AssetRate<=1.1){
                                Maxcoefficient = (1+0.05);
                                Mincoefficient = 1;
                            }else if(AssetRate>1.1 &&AssetRate<=1.2){
                                Maxcoefficient = (1+0.1);
                                Mincoefficient = 1;
                            }else if(AssetRate>1.2 &&AssetRate<=1.3){
                                Maxcoefficient = (1+0.2);
                                Mincoefficient = (1+0.1);
                            }else if(AssetRate>1.3 &&AssetRate<=1.4){
                                Maxcoefficient = (1+0.25);
                                Mincoefficient = (1+0.15);
                            }else if(AssetRate>1.4){
                                Maxcoefficient = (1+0.3);
                                Mincoefficient = (1+0.2);
                            }
                            //市场多年保修价格开发 DC 2023/1/30 end
                            console.log('***最高系数'+Maxcoefficient);
                            console.log('***最低系数'+Mincoefficient);
                        if(nowdate < Date.parse(lastendDate)){
                            //设备小于两年半
                            // upPrice = strMoney;
                            // downPrice = strMoney * 0.8;
                        console.log('***小于2年半')
                        // 市场多年保修价格开发 start DC 2023/01/19
                            //市场多年保设备小于2年半
                            var AssetModelNo = j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':Asset_Model_No__c')).value();
                            var Category4 = j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':Category4__c')).value();
                            console.log('***设备型号'+AssetModelNo);
                            console.log('***产品类型'+Category4);
                            //设备设备消费率小于1.4
                            if(AssetRate<1.4){
                                upPrice = strMoney;
                                console.log('消费率小于1.4 upPrice = strmonye'+ upPrice);
                                if(AssetModelNo.includes('290')|| Category4 =='BF'|| Category4=='BF扇扫'|| Category4=='GIF'||Category4=='CF' || Category4.includes('GF')){
                                    downPrice = upPrice;
                                    console.log('消费率小于1.4 产品无最低价 downPrice '+ downPrice);
                                }else{
                                    downPrice = upPrice * 0.8;
                                    console.log('消费率小于1.4 产品最低价 downPrice = upPrice* 0.8:'+ downPrice);
                                }
                            }else{
                                upPrice = assetListmonth * month *Maxcoefficient / 12;
                                downPrice = assetListmonth * month * Mincoefficient / 12;
                                console.log('消费率大于1.4 upPrice'+ upPrice);
                                console.log('消费率大于1.4 downPrice'+ downPrice);
                            }
                            // 市场多年保修价格开发 end DC 2023/01/19
                            }else{
                                // upPrice = (assetListmonth * Punish) * (1 + Adjustment_ratio_Upper/100);
                                // downPrice = (assetListmonth * Punish) * (1 + Adjustment_ratio_Lower/100);
                                //市场多年保修价格开发 DC 2023/1/30 start  设备大于2年半 续签价格 =定价*消费率对应系数 / 12 *合同月数
                                upPrice = assetListmonth * month *Maxcoefficient / 12;
                                downPrice = assetListmonth * month * Mincoefficient / 12;
                                //市场多年保修价格开发 DC 2023/1/30 end
                            }
                            // gzw 20220630  实际联动6个月价格区分
                        }else{
                            upPrice = strMoney;
                            downPrice = strMoney * 0.8;
                        }
                    }else{
                        upPrice = (LastMContract_Price * Punish) * (1 + Adjustment_ratio_Upper/100);
                        downPrice = (LastMContract_Price * Punish) * (1 + Adjustment_ratio_Lower/100);
                    }
                }else{
                    //firstCCount ++;
                    upPrice = strMoney;
                    downPrice = strMoney * 0.8;
                }
                // 上下限四舍五入
                upPrice = upPrice.toFixed(2);
                downPrice = downPrice.toFixed(2);
                // 12个月合同金额
                //j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':assetListPriceTXT')).text(toNumComma(Price_YearTXT));
                //j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':assetListPriceTXTHidden')).val(Price_YearTXT);
                if (!isDisabled) {
                    // 实际联动价格 start
                    j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':Adjustment_Lower_price')).text(toNumComma(downPrice));
                    j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':Adjustment_Lower_priceHidden')).val(downPrice);
                    j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':Adjustment_Upper_price')).text(toNumComma(upPrice));
                    j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':Adjustment_Upper_priceHidden')).val(upPrice);
                    // 实际联动价格 end
                }
                //j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':assetListPrice')).text(toNumComma(strMoney));
                j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':assetListPricePageHidden')).val(strMoney);
                repairMoney = j$.trim(j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':repairPrice')).value());
            } else {
                // TODO 一時的な対応、なんで別行の金額リフレッシュされた?
                //j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':assetListPrice')).text("");
                j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':assetListPricePageHidden')).val();
                // 12个月合同金额
                //j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':assetListPriceTXT')).text("");
                //j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':assetListPriceTXTHidden')).val();
                if (!isDisabled) {
                    // 实际联动价格 start
                    j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':Adjustment_Lower_price')).text("");
                    j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':Adjustment_Lower_priceHidden')).val();
                    j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':Adjustment_Upper_price')).text("");
                    j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':Adjustment_Upper_priceHidden')).val();
                    // 实际联动价格 end
                 }
            }
        }
        else {
            // 所有设备按安装日、发货日(最早的),距离合同开始日6个月内都是新品合同
            var isNewDate = new Date(j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':isNewDate')).value());
            isNewDate.setMonth(isNewDate.getMonth() + 6);
            if (Date.parse(contractStartDate) > Date.parse(isNewDate)) {
                newCon = false;
            }
            strMoney = j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':assetListPriceHidden')).val();
            Price_YearTXT = strMoney * 12;
            if (isnew == 'true') {
                strMoney = month * strMoney + month2 * strMoney / {!isNewPriceAdj};
            } else {
                strMoney = month * strMoney + month2 * strMoney;
            }
            var b = j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':Contract_No')).value();
            var LastMContractRecord = j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':LastMContractRecord')).value();
            console.log('***维修合同记录类型4'+LastMContractRecord);
            if(b != ''){
                conCCount ++;
                // 1.合同期不满一年时,合同期超过一半才可开始续签报价。(eg:11个月的合同从6个月后才可报价。)
                // 2.一年以上的合同,在结束前6个月开始可以开放续签报价。
                var lastendDate = new Date(j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':End_Date')).value());
                var lastContRange = 0;
                if(LastMContractRecord == 'VM_Contract'){
                    newCount++;
                    //多年保续签合同数量,多年保续签到服务合同时视为首签设备 thh 20220316 start
                    GuranteeCount++;
                    newCon = false;
                    //多年保续签合同数量,多年保续签到服务合同时视为首签设备 thh 20220316 end
                    lastendDate = new Date(j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':endDateGurantee_Text')).value());
                    lastContRange = 36;
                }else{
                    lastContRange = j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':lastContRange')).value();
                }
                //最后结束日+1年
                lastendDate.setMonth(lastendDate.getMonth() + 12);
                // alert('+++++++++--------' + lastendDate);
                // alert('+++++++++--------' + Date.parse(contractStartDate) + '77777' + Date.parse(lastendDate));
                if (Date.parse(contractStartDate) > Date.parse(lastendDate)) {
                    oyearCount ++;
                }
                // 取联动价格
                // 上一期合同实际报价月额
                //
                var LastMContract_Price = localParseFloat(j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':LastMContract_Price')).val());
                var Adjustment_ratio_Lower = localParseFloat(j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':Adjustment_ratio_Lower')).val());
                var Adjustment_ratio_Upper = localParseFloat(j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':Adjustment_ratio_Upper')).val());
                //计算惩罚率
                var Punish = calculateNtoMRatio( lastContRange,(month + month2));
                if(Punish == 0){
                    return;
                }
                // 判断有无报价:没有按照标准价格实际联动
                var Estimate_Num = j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':Estimate_NumHidden')).val();
                if(Estimate_Num == 0){
                    if(LastMContractRecord == 'VM_Contract'){
                        // alert('11111');
                        // gzw 20220630  实际联动6个月价格区分
                        var nowdate = new Date();
                        lastendDate = new Date(j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':endDateGurantee_Text')).value());
                        nowdate = nowdate.setMonth(nowdate.getMonth() + 6);
                         //市场多年保修价格开发 DC 2023/1/30 start
                            var Maxcoefficient =0;
                            var Mincoefficient =0;
                            var AssetRate = localParseFloat(j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':AssetConsumptionRateNew')).val());
                            console.log('***消费率:'+AssetRate);
                             j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':Contractrate')).text(AssetRate +'%');
                            if(AssetRate>0 &&AssetRate<=0.5){
                                Maxcoefficient = (1-0.3);
                                Mincoefficient = (1-0.4);
                            }else if(AssetRate>0.5 &&AssetRate<=0.6){
                                Maxcoefficient = (1-0.2);
                                Mincoefficient = (1-0.3);
                            }else if(AssetRate>0.6 &&AssetRate<=0.7){
                                Maxcoefficient = (1-0.15);
                                Mincoefficient = (1-0.25);
                            }else if(AssetRate>0.7 &&AssetRate<=0.8){
                                Maxcoefficient = (1-0.1);
                                Mincoefficient = (1-0.2);
                            }else if(AssetRate>0.8 &&AssetRate<=0.9){
                                Maxcoefficient = (1-0.05);
                                Mincoefficient = (1-0.15);
                            }else if(AssetRate>0.9 &&AssetRate<=1.0){
                                Maxcoefficient = 1;
                                Mincoefficient = (1-0.05);
                            }else if(AssetRate>1.0 &&AssetRate<=1.1){
                                Maxcoefficient = (1+0.05);
                                Mincoefficient = 1;
                            }else if(AssetRate>1.1 &&AssetRate<=1.2){
                                Maxcoefficient = (1+0.1);
                                Mincoefficient = 1;
                            }else if(AssetRate>1.2 &&AssetRate<=1.3){
                                Maxcoefficient = (1+0.2);
                                Mincoefficient = (1+0.1);
                            }else if(AssetRate>1.3 &&AssetRate<=1.4){
                                Maxcoefficient = (1+0.25);
                                Mincoefficient = (1+0.15);
                            }else if(AssetRate>1.4){
                                Maxcoefficient = (1+0.3);
                                Mincoefficient = (1+0.2);
                            }
                            //市场多年保修价格开发 DC 2023/1/30 end
                            console.log('***最高系数'+Maxcoefficient);
                            console.log('***最低系数'+Mincoefficient);
                        if(nowdate < Date.parse(lastendDate)){
                            //设备小于两年半
                            // upPrice = strMoney;
                            // downPrice = strMoney * 0.8;
                        console.log('***小于2年半')
                        // 市场多年保修价格开发 start DC 2023/01/19
                            //市场多年保设备小于2年半
                            var AssetModelNo = j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':Asset_Model_No__c')).value();
                            var Category4 = j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':Category4__c')).value();
                            console.log('***设备型号'+AssetModelNo);
                            console.log('***产品类型'+Category4);
                            //设备设备消费率小于1.4
                            if(AssetRate<1.4){
                                upPrice = strMoney;
                                console.log('消费率小于1.4 upPrice = strmonye'+ upPrice);
                                if(AssetModelNo.includes('290')|| Category4 =='BF'|| Category4=='BF扇扫'|| Category4=='GIF'||Category4=='CF' || Category4.includes('GF')){
                                    downPrice = upPrice;
                                    console.log('消费率小于1.4 产品无最低价 downPrice '+ downPrice);
                                }else{
                                    downPrice = upPrice * 0.8;
                                    console.log('消费率小于1.4 产品最低价 downPrice = upPrice* 0.8:'+ downPrice);
                                }
                            }else{
                                upPrice = assetListmonth * month *Maxcoefficient / 12;
                                downPrice = assetListmonth * month * Mincoefficient / 12;
                                console.log('消费率大于1.4 upPrice'+ upPrice);
                                console.log('消费率大于1.4 downPrice'+ downPrice);
                            }
                            // 市场多年保修价格开发 end DC 2023/01/19
                        }else{
                            // upPrice = (assetListmonth * Punish) * (1 + Adjustment_ratio_Upper/100);
                            // downPrice = (assetListmonth * Punish) * (1 + Adjustment_ratio_Lower/100);
                            //市场多年保修价格开发 DC 2023/1/30 start  设备大于2年半 续签价格 = 定价 *消费率对应系数 / 12 *合同月数
                            upPrice = assetListmonth * month *Maxcoefficient / 12;
                            downPrice = assetListmonth * month * Mincoefficient / 12;
                            //市场多年保修价格开发 DC 2023/1/30 end
                        }
                        // gzw 20220630  实际联动6个月价格区分
                    }else{
                        upPrice = strMoney;
                        downPrice = strMoney * 0.8;
                    }
                }else{
                    upPrice = (LastMContract_Price * Punish) * (1 + Adjustment_ratio_Upper/100);
                    downPrice = (LastMContract_Price * Punish) * (1 + Adjustment_ratio_Lower/100);
                }
            }else{
                if (isnew == 'true') {
                    newCount ++;
                } else {
                    newCon = false;
                    firstCCount ++;
                }
                upPrice = strMoney;
                downPrice = strMoney * 0.8;
            }
            // 上下限四舍五入
            upPrice = upPrice.toFixed(2);
            downPrice = downPrice.toFixed(2);
            // 12个月合同金额
            //j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':assetListPriceTXT')).text(toNumComma(Price_YearTXT));
            //j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':assetListPriceTXTHidden')).val(Price_YearTXT);
            if (!isDisabled) {
                // 实际联动价格 start
                j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':Adjustment_Lower_price')).text(toNumComma(downPrice));
                j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':Adjustment_Lower_priceHidden')).val(downPrice);
                j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':Adjustment_Upper_price')).text(toNumComma(upPrice));
                j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':Adjustment_Upper_priceHidden')).val(upPrice);
                // 实际联动价格 end
            }
            //j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':assetListPrice')).text(toNumComma(strMoney));
            j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':assetListPricePageHidden')).val(strMoney);
            //<!-- (2022年12月上线)故障品加费 start -->
            Repair_Price_AutoPrice = j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':Repair_Price_Auto'));
            Repair_Price_Auto = Repair_Price_AutoPrice.value();
            repairMoney = j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':repairPrice')).value();
            // console.log('repairMoney='+repairMoney);
            repairMoney1 = localParseFloat(repairMoney);
            ISReducedpriceapproval1 = j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':ISReducedpriceapproval1')).val();
            ISReduced = j$(escapeVfId('allPage:allForm:allBlock:ISReducedpriceapproval')).val();
            console.log('ISReduced='+ISReduced);
            console.log('Repair_Price_Auto='+Repair_Price_Auto);
            console.log('第'+(i+1)+'个设备ISReducedpriceapproval1='+ISReducedpriceapproval1);
            console.log('repairMoney1='+repairMoney1);
            Repair_Price_pass1 = j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':Repair_Price_pass')).val();
            Repair_Price_pass2 = localParseFloat(Repair_Price_pass1);
            console.log('结果='+(repairMoney1<Repair_Price_pass2));
            console.log('Repair_Price_pass2='+Repair_Price_pass2);
            if (repairMoney1> 0 && repairMoney1<(Repair_Price_Auto*0.80) && Repair_Price_Auto != null && isFSE == true) {
                 if (Repair_Price_pass1!=null && repairMoney1<Repair_Price_pass2) {
                    alert('由于存在折扣率超过20%以上的修理加费减价申请,请先点击“提交RC评估”按钮,待RC评估后服务管理部会推进审批');
                        // j$(escapeVfId('allPage:allForm:emailSend')).attr("disabled", false);
                        // j$(escapeVfId('allPage:allForm:emailSend')).attr("class", 'btn');
                    // RCbottonChanged = 1;
                    // var change_cancel = document.getElementById("emailSend");
                    // change_cancel.style.display = "block";
                    repairMoney = Repair_Price_pass2;
                    j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':repairPrice')).val(Repair_Price_pass2);
                 }
            }
             repairMoney2 = j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':repairPrice')).value();
            // console.log('repairMoney='+repairMoney);
            repairMoney3 = localParseFloat(repairMoney2);
             if (repairMoney3> 0 && (repairMoney3 <Repair_Price_Auto*0.80)) {
                if (Repair_Price_pass1!=null && repairMoney3<Repair_Price_pass2) {
                         isresduce = isresduce+1;
                }
            }
            ResonCannotWarranty = j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':ResonCannotWarranty')).value();
            rppa =  document.getElementById('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':Repair_Price_Auto');
            situation = j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':Asset_situation')).value();
            // Agreed_Date =  j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':Agreed_Date')).value();
            console.log('situation='+situation);
            // console.log('Agreed_Date1='+Agreed_Date);
            if(ResonCannotWarranty!=null&&!(ResonCannotWarranty.indexOf("弃修") != -1)){
                // if (!(situation.indexOf("修理中")!=-1)&& !(Agreed_Date.indexOf("为空")!=-1)) {
                    rppa.style.display = "none";
                // }
            }
            // if ((situation.indexOf("修理中")!=-1)&& (Agreed_Date.indexOf("为空")!=-1)) {
            //     console.log('开始操作1');
            //     rppa.style.display = "none";
            // }
            // if ((situation.indexOf("修理中")!=-1)&& (Agreed_Date.indexOf("不为空")!=-1)) {
            //     console.log('开始操作2');
            //     j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':Repair_Price_Auto')).val(0);
            //     j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':repairPrice')).val(0);
            // }
        //<!-- (2022年12月上线)故障品加费 end -->
        }
        repairSum = repairSum + localParseFloat(repairMoney);
        listSum = listSum + localParseFloat(toNum(strMoney));
        downPriceSum = downPriceSum + localParseFloat(toNum(downPrice));
        upPriceSum =  upPriceSum + localParseFloat(toNum(upPrice));
    }
    console.log('改变金额isresduce='+isresduce);
     if (isresduce!=0) {
                toChange1();
        }else{
            if(ISReduced !='' ){
                 toChange2();
            }
        }
    j$(escapeVfId('allPage:allForm:allBlock:assetRepairSumNum')).text(toNumComma(repairSum));
    if (!isDisabled) {
        j$(escapeVfId('allPage:allForm:allBlock:contractInfo:GuidePriceUp')).text(toNumComma(Math.round(upPriceSum)));
        j$(escapeVfId('allPage:allForm:allBlock:contractInfo:GuidePriceUpHidden')).val(toNum(Math.round(upPriceSum)));
        j$(escapeVfId('allPage:allForm:allBlock:contractInfo:GuidePriceDown')).text(toNumComma(Math.round(downPriceSum)));
        j$(escapeVfId('allPage:allForm:allBlock:contractInfo:GuidePriceDownHidden')).val(toNum(Math.round(downPriceSum)));
    }
    j$(escapeVfId('allPage:allForm:allBlock:contractInfo:assetRepairSumPrice')).text(toNumComma(repairSum));
    j$(escapeVfId('allPage:allForm:allBlock:contractInfo:assetRepairSumPriceHidden')).val(toNum(repairSum));
    var allcount = j$(escapeVfId('allPage:allForm:allBlock:productCount3')).value();
    var result = '';
    if (allcount == 0) {
        result = null;
    //如果所有设备的上期合同都是多年保合同,则合同种类为市场多年保续签合同 thh 20220315 start
    }else if(GuranteeCount > 0 && GuranteeCount == allcount){
        result = '市场多年保续签合同';
    //如果所有设备的上期合同都是多年保合同,则合同种类为市场多年保续签合同 thh 20220315 end
    }else if (newCount > 0 && newCount == allcount && newCon == true) {
        result = '新品合同';
    }else if (((newCount > 0 && newCount == allcount) ||(newCount + firstCCount == allcount)) && newCon == false) {
        result = '首签合同';
    }else if(firstCCount > 0 && firstCCount == allcount){
        result = '首签合同';
    // 20220328 ljh update  LJPH-C8FB4P【委托】配合PBI设备覆盖率的数据准备 start
    // }else if(oyearCount > 0 && oyearCount == conCCount){
    }else if(oyearCount > 0 && oyearCount == conCCount && allcount == oyearCount ){
    // 20220328 ljh update  LJPH-C8FB4P【委托】配合PBI设备覆盖率的数据准备 start
        result = '非续签合同(空白期一年以上)';
    }else{
        result = '续签合同';
    }
    document.getElementById("allPage:allForm:allBlock:contractInfo:Contract_TypeTXT").innerHTML = result;
    document.getElementById("allPage:allForm:allBlock:contractInfo:Contract_TypeTXTHidden").value = result;
    // 取消酸化水
    //NotUseOxygenatedWaterAmount(1);
    examinationPriceCal(cnt);
    getLastContractRate();
}
function examinationPriceCal(cntWithKara) {
@@ -958,8 +1992,10 @@
function ComputeLTY() {
    var  urlNameJs = j$(escapeVfId('allPage:allForm:urlName')).val();
    urlNameJs = '{!$Label.ID_of_SelectAssetEstimate}'+urlNameJs ;
    var w = window.open(encodeURI(urlNameJs),'过去两年修理实绩','menubar=no,height=720,width=986');
    w.focus();
    //URF限次合同2期 LY 20220920 start
    // var w = window.open(encodeURI(urlNameJs),'过去两年修理实绩','menubar=no,height=720,width=986');
    // w.focus();
    //URF限次合同2期 LY 20220920 end
}
function recordNumChangeJs() {
    recordNumChangeAction();
@@ -1241,6 +2277,10 @@
    <!-- HWAG-B4R3SS  START 20181026-->
    <apex:actionFunction name="searchfunc" action="{!searchBtn}" rerender="Form,Block,assetSection2,pageMessages,allBlock" onComplete="unblockUI();"></apex:actionFunction>
    <apex:actionfunction action="{!tochange}" name="tochange" rerender="ISReducedpriceapproval" oncomplete="unblockUI();">
        </apex:actionfunction>
        <apex:actionfunction action="{!tochange2}" name="tochange2" rerender="ISReducedpriceapproval" oncomplete="unblockUI();">
        </apex:actionfunction>
    <!-- HWAG-B4R3SS  END 20181026-->
    <apex:actionFunction name="ComputeLTYRepair" action="{!ComputeLTYRepair}" rerender="pageMessages" oncomplete="unblockUI();ComputeLTY();"/>
    <apex:actionFunction name="ShowLTYRepair" action="{!ShowLTYRepair}"  oncomplete="unblockUI();ComputeLTY();"/>
@@ -1461,6 +2501,11 @@
                        
                        <th style="width:70px" class="headerRow  booleanColumn">{!$ObjectType.Asset.fields.Management_Code__c.label}</th>
                        <th style="width:70px" class="headerRow  booleanColumn">{!$ObjectType.Maintenance_Contract_Asset_Estimate__c.fields.Asset_Consumption_rate__c.label}</th>
                        <!-- 市场多年保修价格开发 DC 2023/1/30 start -->
                        <th style="width:70px" class="headerRow  booleanColumn">{!$ObjectType.Maintenance_Contract_Asset_Estimate__c.fields.Asset_Consumption_rate__c.label}</th>
                        <!-- 市场多年保修价格开发 DC 2023/1/30 end -->
                        <th style="width:70px" class="headerRow  booleanColumn">{!$ObjectType.Asset.fields.CurrentContract_End_Date__c.label}</th>
                        <!-- 实绩联动价格计算 start -->
                        <th style="width:35px" class="headerRow  booleanColumn">{!$ObjectType.Maintenance_Contract_Asset_Estimate__c.fields.Adjustment_Upper_price__c.label}</th>
@@ -1481,7 +2526,15 @@
                        <th style="width:90px" class="headerRow  booleanColumn">{!$ObjectType.Maintenance_Contract_Asset_Estimate__c.fields.Estimate_List_Price_All__c.label}</th>
                        <th style="width:90px" class="headerRow  booleanColumn">{!$ObjectType.Maintenance_Contract_Asset_Estimate__c.fields.Maintenance_Price_YearTXT__c.label}</th>-->
                        <th style="width:70px" class="headerRow  booleanColumn">{!$ObjectType.Maintenance_Contract_Asset_Estimate__c.fields.Repair_Price__c.label}</th>
                        <!-- (2022年12月上线)故障品加费 start -->
                        <th style="width:70px" class="headerRow ">{!$ObjectType.Maintenance_Contract_Asset_Estimate__c.fields.Repair_Price_Auto__c.label}</th>
                       <!-- (2022年12月上线)故障品加费 end -->
                        <th style="width:70px" class="headerRow  booleanColumn">{!$ObjectType.Maintenance_Contract_Asset_Estimate__c.fields.Comment__c.label}</th>
                        <!-- (2022年12月上线)故障品加费 第三方回归 -->
                        <th style="width:70px" class="headerRow  booleanColumn">{!$ObjectType.Maintenance_Contract_Asset_Estimate__c.fields.Third_Party_Return__c.label}</th>
                    </tr>
                    
                    <apex:variable value="{!1}" var="cnt" />
@@ -1499,8 +2552,13 @@
                                    <apex:inputField value="{!ar.mcae.Product_Manual__c}" id="Assert" style="width:90%;" rendered="{!ar.IsManual}" onchange="blockme();refreshProductData({!ar.lineNo});"/>
                                    <apex:inputText id="ProductId" value="{!ar.mcae.Product_Manual__c}" style="display:none;" disabled="true"/>
                                </td>
                                <!-- URF限次合同2期 LY 20220811 start -->
                                    <apex:inputHidden value="{!ar.rec.URF_Maintenance_Contract__r.Management_Code__c}" rendered="{!Not(ar.IsManual)}" id="URF_Contract_No"/>
                                <!-- URF限次合同2期 LY 20220811 end -->
                                <td class="dataCell" width="70px">
                                    <apex:outputField value="{!ar.rec.Asset_situation__c}" rendered="{!Not(ar.IsManual)}" />
                                    <apex:outputField value="{!ar.rec.Asset_situation__c}" rendered="{!Not(ar.IsManual)}" id="Asset_situation"/>
                                </td>
                                <td class="dataCell" width="70px">
                                    <apex:outputLink value="/{!ar.recId}" rendered="{!Not(ar.IsManual)}" >{!ar.rec.SerialNumber}</apex:outputLink>
@@ -1539,6 +2597,19 @@
                                    <apex:inputHidden value="{!ar.rec.CurrentContract_F__r.RecordType_DeveloperName__c}" id="LastMContractRecord"/>
                                    <apex:inputField value="{!ar.rec.CurrentContract_F_asset__r.endDateGurantee_Text__c}" id="endDateGurantee_Text" style="display: none" showDatePicker="false"/>
                                    <apex:inputHidden value="{!ar.rec.CurrentContract_F__c}" id="LastMContractID"/>
                                    <!-- 市场多年保价格开发 start 20223/01/17 维修合同/保有设备 设备消费率 -->
                                    <apex:inputHidden value="{!ar.rec.CurrentContract_F_asset__r.Asset_Consumption_Rate__c}" id="AssetConsumptionRateNew"/>
                                 <!--    <apex:inputField value="{!ar.rec.CurrentContract_F_asset__r.Asset_Consumption_Rate__c}" id="AssetConsumptionRateNew2" style="display: none" showDatePicker="false" />
                                    <apex:outputText value="{!ar.rec.CurrentContract_F_asset__r.Asset_Consumption_Rate__c}" id="AssetConsumptionRateNew3" rendered="{!Not(ar.IsManual)}" style="display: none"/> -->
                                    <apex:inputField value="{!ar.rec.Product2.Asset_Model_No__c}" id="Asset_Model_No__c" style="display: none" showDatePicker="false"/>
                                    <apex:inputField value="{!ar.rec.Product2.Category4__c}" id="Category4__c" style="display: none" showDatePicker="false"/>
                                    <!-- 市场多年保价格开发 end 20223/01/17 设备消费率 -->
                                </td>
                                <td class="dataCell" width="90px" style="text-align:right" >
                                    <apex:outputField value="{!ar.mcae.Asset_Consumption_rate__c}" rendered="{!Not(ar.IsManual)}" id="Contractrate"/>
@@ -1562,6 +2633,7 @@
                                        <apex:inputHidden value="{!ar.mcae.Estimate_List_Price__c}" id="assetListPriceHidden"/>
                                        <apex:inputHidden value="{!ar.mcae.Estimate_List_Price_Page__c}" id="assetListPricePageHidden" />
                                        <apex:inputHidden value="{!ar.rec.CurrentContract_F__r.Estimate_Num__c}" id="Estimate_NumHidden" />
                                    </apex:outputPanel>
                                    
                                    <apex:outputPanel layout="none" rendered="{!Not($ObjectType.Maintenance_Contract_Asset_Estimate__c.createable)}" >
@@ -1573,11 +2645,26 @@
                                    <!-- 20200103 Gzw 计算实际报价金额 end -->
                                </td>
                                <td class="dataCell" width="70px" style="text-align:right" >
                                    <apex:inputField value="{!ar.mcae.Repair_Price__c}" id="repairPrice" style="ime-mode: disabled; width:95%; text-align:right;" onchange="refreshAsset({!productCount});"/>
                                <td class="dataCell" width="35px" style="text-align:right" >
                                    <apex:inputField value="{!ar.mcae.Repair_Price__c}" id="repairPrice" style="ime-mode: disabled; width:95%; text-align:right;" onchange="refreshAsset({!productCount});changeAsset({!productCount})"/>
                                </td>
                               <!-- (2022年12月上线)故障品加费 start -->
                                <td class="dataCell" width="35px" style="text-align:right" >
                                    <apex:outputText value="{!ar.Repair_Price_Auto}" id="Repair_Price_Auto" style="width:95%; disabled:disabled;"/>
                                    <!-- <apex:inputHiddenalue="{!ar.rec.Reson_Can_not_Warranty__c}" id="ResonCannotWarranty"/> -->
                                    <!-- <apex:outputText value="{!ar.Agreed_Date}" id="Agreed_Date" style="width:95%;display: none;"/> -->
                                    <apex:inputField value="{!ar.mcae.Repair_Price_pass__c}" id="Repair_Price_pass" style="width:95%;display: none;"/>
                                    <apex:inputHidden value="{!ar.mcae.IS_Reduced_price_approval__c}" id="ISReducedpriceapproval1"/>
                                     <apex:outputText value="{!ar.rec.Reson_Can_not_Warranty__c}" id="ResonCannotWarranty" style="display:none;" rendered="{!Not(ar.IsManual)}" />
                                </td>
                                <!-- (2022年12月上线)故障品加费 end -->
                                <td class="dataCell" width="70px" style="text-align:right" >
                                    <apex:inputField value="{!ar.mcae.Comment__c}" id="comment" style="width:95%;"/>
                                </td>
                                <!--(2022年12月上线)故障品加费 第三方回归  -->
                                <td class="dataCell" width="40px" style="text-align:center;" >
                                    <apex:inputCheckbox value="{!ar.mcae.Third_Party_Return__c}" id="Third_Party_Return__c"/>
                                </td>
                            </tr>
@@ -1634,9 +2721,12 @@
                    <th width="90px" style="text-align:right">设备数量</th>
                    <td width="90px" style="text-align:right"><apex:outputtext value="{!productCount3}" id="productCount3"/></td>
                    <td width="25px">&nbsp;</td>
                    <th width="90px" style="text-align:right">
                        <apex:inputField value="{!estimate.IS_Reduced_price_approval__c}" id="ISReducedpriceapproval" style="display:none"/></th>
                         <!-- <apex:inputField value="{!estimate.IS_Reduced_price_approval__c}" id="ISReducedpriceapproval"/></th> -->
                    <td width="25px">&nbsp;</td>
                    <!--<th width="90px" style="text-align:right">报价总额</th>
                    <th width="90px" style="text-align:right"><span id="allPage:allForm:allBlock:assetListSumNum" ></span></th>-->
                    <td width="25px">&nbsp;</td>
                    <th width="90px" style="text-align:right">修理总额</th>
                    <th width="90px" style="text-align:right"><span id="allPage:allForm:allBlock:assetRepairSumNum" ></span></th>
                    <td width="95px">&nbsp;</td>
@@ -1657,7 +2747,7 @@
                        <th style="width:70px" class="headerRow  booleanColumn">{!$ObjectType.Asset.fields.SerialNumber.label}</th>
                        <th class="headerRow  booleanColumn">{!$ObjectType.Asset.fields.Department_Name__c.label}</th>
                        <!-- <th style="width:90px" class="headerRow  booleanColumn">{!$ObjectType.Asset.fields.Installation_Site__c.label}</th> -->
                        <th style="width:90px" class="headerRow  booleanColumn">{!$ObjectType.Asset.fields.IF_Warranty__c.label}</th>
                        <th style="width:90px" class="headerRow  booleanColumn">{!$ObjectType.Asset.fields.IF_Warranty_Service__c.label}</th>
                         <!-- //JZHG-BSDUT4 ---20200825---update By rentongxiao---Start -->
                        <th style="width:90px" class="headerRow  booleanColumn">主机/耗材</th>
                         <!-- //JZHG-BSDUT4 ---20200825---update By rentongxiao---End -->
@@ -1675,7 +2765,7 @@
                        <apex:repeat value="{!assetsView}" var="ar" id="assetTable2">
                            <tr class="dataRow {!IF(MOD(cnt, 2)==0, 'odd', 'even')} {!IF(cnt==1, 'first', '')}" onmouseover="if (window.hiOn){hiOn(this);} " onmouseout="if (window.hiOff){hiOff(this);} " onblur="if (window.hiOff){hiOff(this);}" onfocus="if (window.hiOn){hiOn(this);}">
                                <td class="dataCell" width="25px">
                                    <apex:inputCheckbox value="{!ar.rec_checkBox_c}" id="assetRowCheckbox2" disabled="{!IF(ar.rec.Maintenance_Price_Month__c == 0 || ar.rec.IF_Warranty__c = '否', 'true', 'false')}"/>
                                    <apex:inputCheckbox value="{!ar.rec_checkBox_c}" id="assetRowCheckbox2" disabled="{!IF(ar.rec.Maintenance_Price_Month__c == 0 || ar.rec.IF_Warranty_Service__c = '否', 'true', 'false')}"/>
                                </td>
                                <td class="dataCell" width="25%">
                                    <apex:outputField value="{!ar.rec.name}" id="assetName"/>
@@ -1693,7 +2783,7 @@
                                    <apex:outputField value="{!ar.rec.Installation_Site__c}"/>
                                </td> -->
                                <td class="dataCell" width="90px" style="text-align:center">
                                    <apex:outputField value="{!ar.rec.IF_Warranty__c}"/>
                                    <apex:outputField value="{!ar.rec.IF_Warranty_Service__c}"/>
                                </td>
                                 <!-- //JZHG-BSDUT4 ---20200825---update By rentongxiao---Start -->
                                <td class="dataCell" width="90px" style="text-align:center">
@@ -1778,6 +2868,9 @@
                        <th style="text-align: center">申请报价金额</th>
                        <th style="text-align: center">合同设备修理总额</th>
                        <th style="text-align: center">合同总金额</th>
                        <!-- 上限合同 20230103 LY start -->
                        <th style="text-align: center">上限金额</th>
                        <!-- 上限合同 20230103 LY end -->
                    </tr>
                    <tr>
                        <td style="text-align: center">
@@ -1788,6 +2881,7 @@
                            <apex:outputField value="{!estimate.GuidePrice_Up__c}" id="GuidePriceUp" />
                            <apex:inputHidden value="{!estimate.GuidePrice_Up__c}" id="GuidePriceUpHidden" />
                        </td>
                        <td style="text-align: center">
                            <!--<apex:inputField value="{!estimate.Request_quotation_Amount__c}" id="quotation_Amount" />-->
                            <apex:inputField value="{!estimate.Request_quotation_Amount__c}" style="ime-mode: disabled; text-align: right; width:100px" id="quotation_Amount" onchange="checkDiscount(this.value);"/>
@@ -1797,10 +2891,15 @@
                            <apex:inputHidden value="{!estimate.Asset_Repair_Sum_Price__c}" id="assetRepairSumPriceHidden" />
                        </td>
                        <td style="text-align: center">
                            <apex:outputField value="{!estimate.Maintenance_Price__c}" id="mainteReal" />
                            <apex:outputField value="{!estimate.Maintenance_Price__c}" id="mainteReal"/>
                            <apex:inputHidden value="{!estimate.Maintenance_Price__c}" id="mainteRealHidden"/>
                            <apex:inputHidden value="{!OldMaintenancePrice}" id="oldMainteReal"/>
                        </td>
                        <!-- 上限合同 20230103 LY start -->
                        <td style="text-align: center">
                            <apex:inputField value="{!estimate.Limit_Price_Amount__c}" style="ime-mode: disabled; text-align: right; width:100px" id="Limit_Price_Amount" />
                        </td>
                        <!-- 上限合同 20230103 LY end -->
                    </tr>
                    <tr>
                        <th style="text-align: center">{!$ObjectType.Maintenance_Contract_Estimate__c.fields.Service_discount_Rate__c.label}</th>
@@ -1970,9 +3069,12 @@
                        <td>&nbsp;</td>
                        <td width="30px">&nbsp;</td>
                        <!-- <td><apex:commandButton id="savebtn" action="{!save}" value="{!$Label.Save_Button}" disabled="{!SaveBtnDisabled}" rerender="allForm" onclick="if (!onclickCheckchangedAfterPrint('true','true')) return false;" oncomplete="unblockUI();"/></td> -->
                        <td><apex:commandButton id="savebtn" action="{!save}" value="{!$Label.Save_Button}" disabled="{!SaveBtnDisabled}" rerender="allForm" onclick="if (!EGFlgconfim()) return false;" oncomplete="unblockUI();"/></td>
                        <td width="200px"><apex:commandButton id="approvalbtn" action="{!approvalProcess}" value="提交待审批" disabled="{!ApprovalBtnDisabled}" rerender="allForm" onclick="if (!KindsAndMonths()) return false;if (!EGFlgconfim()) return false;approvalJs();" oncomplete="unblockUI();"/>
                        <!-- 故障修理费  添加提交修理减价按钮  disabled="true" -->
                        <td><apex:commandButton id="emailSend" action="{!sendEmail}" value="提交RC评估" rerender="allForm" disabled="{!SendEmailBtnDisabled}" onclick="if (!EGFlgconfim()) return false;" oncomplete="unblockUI();"/></td>
                        <td>
                            <apex:commandButton id="approvalbtn1" action="{!toApprovalProcess}" value="提交修理减价审批" disabled="{!ApprovalBtnNewDisabled}" />
                        </td>
                        <td width="200px"><apex:commandButton id="approvalbtn" action="{!approvalProcess}" value="提交待审批" disabled="{!ApprovalBtnDisabled}" rerender="allForm" onclick="if (!KindsAndMonths()) return false;if (!EGFlgconfim()) return false;approvalJs();" oncomplete="unblockUI();toApprovalProcess();"/>
                        <!-- HWAG-B399Q8 2018/08/20 新增请提交待审批 提示字段 start-->
                        &nbsp; <apex:outputText style="color:red;font-size:20px;" value="请提交待审批" rendered="{!IS_Clone_After_Decide}"/>
                        <!-- HWAG-B399Q8 2018/08/20 新增请提交待审批 提示字段 end-->
@@ -1986,6 +3088,9 @@
                        <td><apex:outputField value="{!estimate.Contract_End_Date__c}" id="contractenddate"/></td>
                        <td>&nbsp;</td>
                        <td><apex:commandButton id="decidebtn" value="{!$Label.QuoteDecision_Button}" disabled="{!DecideBtnDisabled}" onclick="decideJs(); return false;"/></td>
                           <td>  <apex:commandButton id="savebtn" action="{!save}" value="{!$Label.Save_Button}" disabled="{!SaveBtnDisabled}" rerender="allForm" onclick="if (!EGFlgconfim()) return false;" oncomplete="unblockUI();"/>
                        </td>
                        <!-- <td><apex:commandButton id="decidebtn1" value="{!$Label.QuoteDecision_Button}" action="{!dosomething}"/></td> -->
                        <td style="text-align:right"><apex:commandButton id="undecidebtn" action="{!undecide}" value="取消{!$Label.QuoteDecision_Button}" disabled="{!UnDecideBtnDisabled}" rerender="allForm" onclick="blockme();" oncomplete="unblockUI();"/></td>
                    </tr>
                </table>
@@ -2140,7 +3245,7 @@
        // xud 20140529 ここは明細変更判断
        // xudan 20150729 ソート項目にIdを追加
        var sql = "SELECT Id, Asset__c, Asset__r.SerialNumber, Check_Result__c, Product_Manual__c,"
                + " Repair_Price__c, Comment__c, Maintenance_Contract_Estimate__r.Maintenance_Price__c"
                + " Repair_Price__c, Comment__c, Maintenance_Contract_Estimate__r.Maintenance_Price__c,Third_Party_Return__c"
                + "  FROM Maintenance_Contract_Asset_Estimate__c"
                + " WHERE Maintenance_Contract_Estimate__c = '{!targetEstimateId}'"
                + " ORDER BY id,Asset__c,Product_Manual__c, Asset__r.SerialNumber, Asset__r.Name, Asset__r.Department_Name__c, Asset__r.InstallDate";
sfdx-project.json
@@ -7,6 +7,6 @@
  ],
  "name": "Stagefull_olympus",
  "namespace": "",
  "sfdcLoginUrl": "https://login.salesforce.com",
  "sfdcLoginUrl": "https://test.salesforce.com",
  "sourceApiVersion": "52.0"
}