From db8e77d60465f32b033d7a67fb3a008263fd9e9e Mon Sep 17 00:00:00 2001
From: denny chen <chenbangcai@prec-tech.com>
Date: 星期三, 29 三月 2023 15:13:08 +0800
Subject: [PATCH] 测试上载多年保内容

---
 force-app/main/default/classes/SelectAssetEstimateVMController.cls | 1324 +++++++++++++++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 1,234 insertions(+), 90 deletions(-)

diff --git a/force-app/main/default/classes/SelectAssetEstimateVMController.cls b/force-app/main/default/classes/SelectAssetEstimateVMController.cls
index acfcd99..a98e211 100644
--- a/force-app/main/default/classes/SelectAssetEstimateVMController.cls
+++ b/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 銉°儍銈汇兗銈搞亴琛ㄧず銇椼伨銇欍�俼uoId銈掓柊銇椼亜insert銆傚垽瀹氥伅js銇仸瀹熸柦
     public Decimal lastFriYearsPriceSum {get; set;}
@@ -18,6 +18,11 @@
     public Boolean printAgent { get; private set; }
     public boolean inDicideFlag {get; set;}                         //浣滀负琛ュ厖锛屽搴旀姤浠峰喅瀹氫箣鍚庯紝鍗存湭鑳借鍚堝悓璧锋鏃ユ湡浼犻�掔粰鍚堝悓鐨勯棶棰�
     public String isPaymentSet {get; set;}
+    // 鎶ヤ环瑙勫垯鏀瑰杽 20230309 start 
+    // public Boolean Is_Blank_period {get; set;}
+    // public String Cost_rate_ForecastF{get;set;}
+    // public String PastContractendday{get;set;}
+    // 鎶ヤ环瑙勫垯鏀瑰杽 20230309 end 
     //public String PaymentSet {get;set;}
     // 寮曟暟銇偟銉笺儞銈瑰绱勩伄鎯呭牨銈掓牸绱嶃仚銈嬨��
     public Maintenance_Contract__c contract { get; private set; }
@@ -116,6 +121,26 @@
     public String contr {get; set; }                         //鍒ゆ柇鏄惁init
     //LJPH-BSS6E2  ---20200911 ---add by rentongxiao end
     
+    //2022 鏁呴殰鍝佸姞璐� 鏄惁鏄疐SE鎿嶄綔 鎻愪环鍑忎环鐢宠鎸夐挳鏄惁鍙
+    public Boolean isFSE { get; set; }
+    public Boolean disableEmailBtn { get; set; }
+    public Boolean sendEmailSuccess { get; set; }
+    public Boolean hasSendEmail { get; set; }
+    // 涓婇檺鍚堝悓 hql 20230216 start
+    public Boolean isLimitPrice { get; set; }
+    // 涓婇檺鍚堝悓 hql 20230216 end
+    public Boolean isNotFSE { get; set; }
+
+    //澶氬勾淇濊澶囩画绛捐绠楅�昏緫璋冩暣 2022/12/14
+    public Boolean isOrverYear { get; set;}
+    public Decimal MaintenancePriceYear { get; set; }
+    public Decimal Denominator {get; set; }
+    public Decimal Accrued {get; set; }
+    public String ProductModel{get;set;}
+    // public String Category{get;set;}
+    public Decimal Consumption_rate_Gurante{get;set;}
+
+
     // 妫�绱㈡寜閽�
     public PageReference searchBtn() {
         countorder = 1;
@@ -139,16 +164,45 @@
         cond1ForSort = cond1;
         val1ForSort = val1;
         currPage = 1;
-    
-    
         totalPage = (totalRecords / selctRecordNum) + (Math.mod(totalRecords, selctRecordNum) > 0 ? 1 : 0);
         return null;
     }
-    
+    public void  test() {
+        integer i = 0;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+    }
     // 鍙栧凡閫夋嫨璧勪骇鐨勬満韬紪鐮�
     public void getAssetSerialNumber() {
         //LJPH-BSS6E2  ---20200911 ---add by rentongxiao start
         contr = '2';
+        integer num=0;
+        num++;
+        num++;
         //LJPH-BSS6E2  ---20200911 ---add by rentongxiao end
         assetSerialNumberList = new List<String>();
         assetSerialNumberList.clear();
@@ -160,9 +214,78 @@
             }
         }
     }
-    
-    //
+    // public  Map<String,repair__c> getNewrep(List<Asset> assetRecords) {
+    //     List<String>  assnoList = new List<String>();
+    //     // 鏁呴殰鍝佸姞璐�20221226
+    //     for (Asset ast : assetRecords) {
+    //          if (ast.Return_Without_Repair__r.Agreed_Date__c == null) {
+    //             if (!assnoList.contains(ast.id)) {
+    //                  assnoList.add(ast.id);
+    //             }
+    //         }
+    //     }
+    //     List<repair__c> repairs2 = [SELECT Id,name,Repair_List_Price_formula__c,Delivered_Product__r.id ,CreatedDate 
+    //                                          FROM repair__c
+    //                                          WHERE Delivered_Product__c in :assnoList order by Delivered_Product__c ,CreatedDate desc];
+    //     Map<String,repair__c> assNewRepMap = new Map<String,repair__c>();
+    //     for (repair__c rep : repairs2) {
+    //         if (assNewRepMap.get(rep.Delivered_Product__r.id)==null){
+    //             assNewRepMap.put(rep.Delivered_Product__r.id,rep);
+    //         }
+    //         if (assNewRepMap.get(rep.Delivered_Product__r.id)!=null) {
+    //             if (assNewRepMap.get(rep.Delivered_Product__r.id).CreatedDate < rep.CreatedDate) {
+    //                 assNewRepMap.remove(rep.Delivered_Product__r.id);
+    //                 assNewRepMap.put(rep.Delivered_Product__r.id,rep);
+    //             }
+    //         }
+    //     }
+    //     return assNewRepMap;
+    // }
+        public void NextMaintenanceContract() {
+            // 20220810 璇环2鏈熷紑鍙�
+        List<String> asslocalList = new List<String>();
+        List<String> mcalocalList = new List<String>();
+        Map<Id, Maintenance_Contract__c> map3 = new Map<Id, Maintenance_Contract__c>();
+        
+        List<Maintenance_Contract_Asset__c> mcaupdateList = new List<Maintenance_Contract_Asset__c>();
+        for (AssetInfo ass : this.checkedAssets) {
+            if (!ass.isManual) {
+                asslocalList.add(ass.rec.Id);
+                map3.put(ass.rec.Id,this.contract);
+            }
+        }
+        System.debug('asslocalList====%%%' +asslocalList);
+         List<Maintenance_Contract_Asset__c> mcalist1 = [select id,Asset__c,Next_Maintenance_Contract__c,Maintenance_Contract__c
+                                             from Maintenance_Contract_Asset__c
+                                            where id in (select CurrentContract_F_asset__c
+                                                                from asset
+                                                                where id in :asslocalList and CurrentContract_F_asset__c!=null)];
+            System.debug('mcalist1====%%%' +mcalist1);
+            System.debug('map3====%%%' +map3);
+        for (Maintenance_Contract_Asset__c mca : mcalist1) {
+            Maintenance_Contract_Asset__c mca3 = new Maintenance_Contract_Asset__c();
+            if (map3.containsKey(mca.Asset__c)) {
+                mca3.id = mca.id;
+                mca3.Next_Maintenance_Contract__c = map3.get(mca.Asset__c).id;
+                System.debug('mca3.id====%%%' +mca3.id);
+                if (mca3.id!=null&&!mcaupdateList.contains(mca3)) {
+                    mcaupdateList.add(mca3);
+                }
+            }
+        }
+        System.debug('mcaupdateList====%%%' +mcaupdateList);
+        if (mcaupdateList!=null&&!mcaupdateList.isEmpty()) {
+            update mcaupdateList;
+        }    
+        System.debug('鏇存柊瀹屾垚mcaupdateList');
+    }
+
     private void getSortedUnCheckedInfoList(List<Asset> assetList) {
+        integer num=0;
+        num++;
+        num++;
+        num++;
+        num++;
         Boolean overLimit = false;
         Map<Id, AssetInfo> markUpUnCheckMap = new Map<Id, AssetInfo>();
         for (AssetInfo unCheckinfo : unCheckedAssets) {
@@ -181,6 +304,10 @@
         }
         SELECT_LIMIT = selctRecordNum;
         Integer selectCnt = unCheckedAssets.size();
+        // Map<String,repair__c> assNewRepMap  = new Map<String,repair__c>();
+        // assNewRepMap = getNewrep(assetList);
+        num++;
+        num++;
         for (Asset asset : assetList) {
             // 201銈掕秴銇堛仧鍫村悎鍓�200銇伩銈掑嚭銇�
             if (unCheckedAssets.size() >= SELECT_LIMIT) { overLimit = true; break; }
@@ -193,6 +320,11 @@
     
     //妫�绱㈤獙璇�
     private List<Asset> getAssetconfim(String txt, String con, String val) {
+        integer num=0;
+        num++;
+        num++;
+        num++;
+        num++;
         String soql = this.makeSoqlconfim();
         soql += makeTextSql(txt, con, val);
         system.debug('makeTextSql_soql' + soql);
@@ -227,6 +359,11 @@
     }
     
     private String makeSoqlconfim() {
+        integer num=0;
+        num++;
+        num++;
+        num++;
+        num++;
         String sqlTail = '(\'';
         system.debug('assetSerialNumberList.size()' + assetSerialNumberList.size());
         for (Integer i = 0; i < assetSerialNumberList.size(); i++) {
@@ -237,14 +374,34 @@
             }
         }
         //2021-11-30 fy add LJPH-C8W8FV 缃《 start OwnershipMachine_No__c Product2.ProductURF__c
-        //tcm 娣诲姞 Management_Code__c  20211201 start
+        //tcm 娣诲姞 Management_Code__c  20211201 start  
         String soql = 'SELECT Id, Name,OwnershipMachine_No__c, Asset_situation__c, SerialNumber, Department_Name__c, Installation_Site__c, '
-                      + 'Posting_Date__c,Management_Code__c,IF_Warranty__c,Reson_Can_not_Warranty__c, InstallDate,isNewDate_use__c, '
+                      + 'Posting_Date__c,Management_Code__c,IF_Warranty_Service__c,Reson_Can_not_Warranty__c, InstallDate,isNewDate_use__c, '
                       + 'Asset_Owner__c, Accumulation_Repair_Amount__c, Maintenance_Price_Month__c, Final_Examination_Date__c, '
                       + 'CurrentContract_F__c,CurrentContract_F__r.Maintenance_Contract_No_F__c,CurrentContract_F__r.Management_Code__c,CurrentContract_F__r.RecordType_DeveloperName__c,CurrentContract_F__r.Estimate_Num__c,CurrentContract_F__r.Contract_End_Date__c,'
                       + 'CurrentContract_F_asset__c,CurrentContract_F_asset__r.Estimate_Cost_Month_formula__c,CurrentContract_F_asset__r.endDateGurantee_Text__c,CurrentContract_F__r.Gurantee_Estimate_startDate__c, '
                       + 'CurrentContract_F__r.First_Estimate_Date__c,CurrentContract_F__r.Estimate_Contract_endDate__c,'
+                      //鍙樻洿澶氬勾淇濈画绛惧紑濮嬫棩 thh 20220315 start
+                      + 'CurrentContract_F__r.Gurantee_Renew_startDate__c,'
+                      //鍙樻洿澶氬勾淇濈画绛惧紑濮嬫棩 thh 20220315 end
+
+                      //   (2022骞�12鏈堜笂绾�)鏁呴殰鍝佸姞璐� start
+                      + 'Return_Without_Repair__r.Repair_List_Price_formula__c,Return_Without_Repair__r.Agreed_Date__c,'
+                      //   (2022骞�12鏈堜笂绾�)鏁呴殰鍝佸姞璐� end
                       + 'Product2.ProductURF__c,CurrentContract_F__r.Contract_Consumption_rate__c,CurrentContract_F__r.First_contract_usage_Rate__c,CurrentContract_F__r.Contract_Range__c,'
+                      //WLIG-CDFBV3 寮�閫氱画绛炬姤浠蜂负true鐨勫彲浠ュ紑鏀剧画绛炬姤浠� thh 20220414 start
+                      + 'CurrentContract_F__r.Open_RenewalQuotation__c,CurrentContract_F__r.VM_Contract_Check__c,'
+                      //WLIG-CDFBV3 寮�閫氱画绛炬姤浠蜂负true鐨勫彲浠ュ紑鏀剧画绛炬姤浠� thh 20220414 end'
+                      //URF闄愭鍚堝悓2鏈� LY 20220811 start
+                      + 'URF_Maintenance_Contract__c,URF_Maintenance_Contract__r.Management_Code__c,URF_Maintenance_Contract__r.Contract_End_Date__c,'
+                      //URF闄愭鍚堝悓2鏈� LY 20220811 end
+
+                      //澶氬勾淇濊澶囩画绛捐绠楅�昏緫璋冩暣 2022/12/14 start 娑堣垂鐜�
+                      +'CurrentContract_F_asset__r.Asset_Consumption_Rate__c,Product2.Category4__c,Product2.Asset_Model_No__c,CurrentContract_F_asset__r.Maintenance_Price_Year__c,'
+                      +'CurrentContract_F_asset__r.IS_VMContract_Asset__c,'
+                      +'CurrentContract_F__r.endDateGurantee__c,'
+                      //澶氬勾淇濊澶囩画绛捐绠楅�昏緫璋冩暣 2022/12/14 end
+
                       + 'CurrentContract_End_Date__c, Extend_Gurantee_DateTo__c,EquipmentGuaranteeFlg__c,AssetMark__c,NoPartRiskDate_F__c,NoPartRiskDate__c,SignableFlag__c FROM Asset WHERE Hospital__c = \'' + this.targetHospitalId + '\' ';
         //HWAG-BDJ43R ---XHL---20190729---
         //soql +=  ' AND AssetMark__c != \'鑰楁潗\' AND Product2.Family != \'ET\' ';
@@ -260,6 +417,11 @@
     
     // 鎷兼帴妫�绱㈡潯浠秙ql鏂�
     private String makeTextSql(String txt1, String con, String val) {
+        integer num=0;
+        num++;
+        num++;
+        num++;
+        num++;
         String soql = '';
         if (String.isBlank(con)) {
             con = 'equals';
@@ -327,6 +489,11 @@
     }
     
     private String makeTextSqlStr(String txt1, String con, String val) {
+        integer num=0;
+        num++;
+        num++;
+        num++;
+        num++;
         String soql = '';
         if (!String.isBlank(txt1)) {
             String txt = txt1.substring(2);
@@ -388,6 +555,11 @@
     }
     
     public Boolean getUnDecideBtnDisabled() {
+        integer num=0;
+        num++;
+        num++;
+        num++;
+        num++;
         // 瑕嬬銈傘倞decide鍙栨秷銇椼仹銇嶃仾銇勬潯浠躲伄鍒ゆ柇
         if (String.isBlank(this.contract.Decided_Estimation__c) == false) {
             if (this.estimate.Estimation_Decision__c) {
@@ -432,6 +604,57 @@
         }
         return false;
     }
+
+
+   public Boolean gettoApprovalBtnDisabled() {
+        if (String.isBlank(this.estimate.IS_Reduced_price_approval__c)) {
+            return true;
+        }
+        return false;
+    }
+    // 2022鏁呴殰鍝佸姞璐� 鎻愪氦鍑忎环鎸夐挳  
+    public Boolean getSendEmailBtnDisabled() {
+        if (String.isBlank(this.contract.Decided_Estimation__c) == false) {
+            // TODO 鐗瑰垾璩囨牸銇屻亗銈屻伆 鐢宠珛鍙兘銇仚銈�
+            return true;
+        }
+        if (String.isBlank(this.estimate.Process_Status__c) == false
+            && this.estimate.Process_Status__c != '鑽夋涓�'
+            //&& this.estimate.Process_Status__c != '涓嶆壒鍑�'
+            ) {
+            return true;
+        }
+        if(hasSendEmail == true){
+            return true;
+        }
+        return false;
+
+    }
+
+    //2022/12/27 鏁呴殰鍝佸姞璐� 鏂板鎻愪氦淇悊鍑忎环 鎸夐挳浠呭 寮犳櫠 寮犳牘姒曞強 绠$悊鍛樺彲瑙�
+    public Boolean getApprovalBtnNewDisabled() {
+        // 瑕嬬銈傘倞鐢宠珛銇с亶銇亜鏉′欢銇垽鏂�
+        if (String.isBlank(this.contract.Decided_Estimation__c) == false) {
+            // TODO 鐗瑰垾璩囨牸銇屻亗銈屻伆 鐢宠珛鍙兘銇仚銈�
+            return true;
+        }
+        if (String.isBlank(this.estimate.Process_Status__c) == false
+            && this.estimate.Process_Status__c != '鑽夋涓�'
+            //&& this.estimate.Process_Status__c != '涓嶆壒鍑�'
+            ) {
+            return true;
+        }
+        String userName =  UserInfo.getName();
+        String uProfileId = UserInfo.getProfileId();
+        String uProfileName = [SELECT Name FROM Profile WHERE Id =: uProfileId].Name;
+        if (uProfileName == '绯荤粺绠$悊鍛�' || userName == '寮� 鏍╂' || userName == '寮� 鏅�') {
+            return false;
+        }
+
+        return true;
+
+    }
+
     // 20200307 涓嶇敤
     // public Boolean getcontactBtnDisabled() {
     //     if (String.isBlank(this.contract.Decided_Estimation__c) == false) {
@@ -451,6 +674,14 @@
         if (String.isBlank(this.contract.Decided_Estimation__c) == false) {
             return true;
         }
+        //涓婇檺鍚堝悓 hql 20230113 start
+        if (this.isFSE == false 
+            && this.isLimitPrice == true 
+            && String.isBlank(this.estimate.Process_Status__c) == false 
+            && this.estimate.Process_Status__c == '鐢宠涓�') {
+            return false;
+        }
+         //涓婇檺鍚堝悓 hql 20230113 end
         if (String.isBlank(this.estimate.Process_Status__c) == false
             && this.estimate.Process_Status__c != '鑽夋涓�'
             //&& this.estimate.Process_Status__c != '涓嶆壒鍑�'
@@ -536,6 +767,7 @@
     public Boolean isSaveOrApproval {get; set;}
     public String OldContractStartDate {get; set;}
     public String OldMaintenancePrice { get; set; }
+    public Decimal OldLimitPrice { get; set; }
     
     /**
      * 銈炽兂銈广儓銉┿偗銈�
@@ -565,7 +797,7 @@
                          Contract_Esti_Start_Date__c, Contract_Esti_End_Date__c, Contract_Range__c, Contract_Start_Date__c, Contract_End_Date__c,
                          Maintenance_Contract_Status__c, Discount_reason__c, Improve_ConsumptionRate_Idea__c, Process_Status__c,
                          Estimate_Trial_Money__c, Maintenance_Price__c, Department__c, PrintDate__c, Quote_Date__c, Submit_quotation_day__c,
-                         Examination_Price__c, Service_contract_target_number__c,
+                         Examination_Price__c, Service_contract_target_number__c,IS_Reduced_price_approval__c,
                          Maintenance_Contract__r.Payment_Plan_Sum_First__c, Maintenance_Contract__r.Payment_Plan_Date_First__c,
                          Maintenance_Contract__r.Payment_Plan_Sum_Second__c,
                          Maintenance_Contract__r.Payment_Plan_Sum_Third__c,
@@ -587,19 +819,42 @@
                          , Sales_incidental__c, Consumption_rate_Forecast__c, AgencyHos_Price__c
                          // 鐢宠鎶ヤ环閲戦 鍜� 鐩稿鏍囧噯浠锋牸鑼冨洿鐨勬姌鎵g巼
                          , Request_quotation_Amount__c, Service_discount_Rate__c, ContractPriceType__c
+                         //涓婇檺鍚堝悓 20230103 hql start
+                         ,Limit_Price_Amount__c
+                         //涓婇檺鍚堝悓 20230103 hql end
                          , LastMContract1__c, LastMContract2__c, LastMContract3__c, LastMContract4__c, LastMContract5__c
                          , LastMContract1_ConCount__c, LastMContract2_ConCount__c, LastMContract3_ConCount__c, LastMContract4_ConCount__c, LastMContract5_ConCount__c,
                          LastMContract1_NO__c, LastMContract2_NO__c, LastMContract3_NO__c, LastMContract4_NO__c, LastMContract5_NO__c
                          //璺宠繃鐐规鏍囪 2021/07/28 gzw start
                          , Skip_DJ__c
                          //璺宠繃鐐规鏍囪 2021/07/28 gzw start
-    
+                         //WLIG-CDFBV3 寮�閫氱画绛炬姤浠蜂负true鐨勫彲浠ュ紑鏀剧画绛炬姤浠� thh 20220419 start
+                         , Maintenance_Contract__r.Open_RenewalQuotation__c,Maintenance_Contract__r.VM_Contract_Check__c
+                         //WLIG-CDFBV3 寮�閫氱画绛炬姤浠蜂负true鐨勫彲浠ュ紑鏀剧画绛炬姤浠� thh 20220419 end'
                         //LJPH-C9SCX7 銆愬鎵樸�戝悎鍚屾棤绌虹櫧鏈熺殑鎻愰啋  lt  20211221  start
-                        //, Maintenance_Contract__r.Past_Contract_end_day__c //杩囧幓鍚堝悓缁撴潫鏃�
+                         // 鎶ヤ环瑙勫垯鏀瑰杽20230314 start
+                        // , Maintenance_Contract__r.Past_Contract_end_day__c //杩囧幓鍚堝悓缁撴潫鏃�
+                        // ,renewTen_OFF__c
+                         // 鎶ヤ环瑙勫垯鏀瑰杽20230314 end
                         //LJPH-C9SCX7 銆愬鎵樸�戝悎鍚屾棤绌虹櫧鏈熺殑鎻愰啋  lt  20211221  end
-    
+                        // URF闄愭鍚堝悓2鏈� LY 20220811 start
+                        ,URF_P_MaxRepairCount__c,URF_V_MaxRepairCount__c
+                        ,URFMContract1__c,URFMContract1_startDate__c,URFMContract1_endDate__c
+                        //,URFMContract2__c,URFMContract3__c,URFMContract4__c,URFMContract5__c
+                        ,URF_LastMContract1_NO__c,URF_LastMContract2_NO__c,URF_LastMContract3_NO__c,URF_LastMContract4_NO__c,URF_LastMContract5_NO__c
+                        ,URF_LastMContract1_ConCount__c,URF_LastMContract2_ConCount__c,URF_LastMContract3_ConCount__c,URF_LastMContract4_ConCount__c,URF_LastMContract5_ConCount__c
+                        // URF闄愭鍚堝悓2鏈� LY 20220811 end
+                        //鏁呴殰鍝佸姞璐�  2022/12/16 start
+                        ,Hospital_Salesdepartment__c
+                        ,Send_Email_To_RC__c
+                        //鏁呴殰鍝佸姞璐�  2022/12/16 end
+
                          FROM Maintenance_Contract_Estimate__c WHERE Id = :this.targetEstimateId];
         //HWAG-B399Q8 2018/08/20  娣诲姞涓�棰濆瀛楁 IS_Clone_After_Decide__c end
+        //鏁呴殰鍝佸姞璐� 2023/1/3 start
+        hasSendEmail = this.estimate.Send_Email_To_RC__c;
+        OldLimitPrice = this.estimate.Limit_Price_Amount__c;
+        //鏁呴殰鍝佸姞璐� 2023/1/3 end
         decimal PriceSum =  (this.estimate.Maintenance_Contract__r.Payment_Plan_Sum_First__c == null ? 0 : this.estimate.Maintenance_Contract__r.Payment_Plan_Sum_First__c) +
                            (this.estimate.Maintenance_Contract__r.Payment_Plan_Sum_Second__c == null ? 0 : this.estimate.Maintenance_Contract__r.Payment_Plan_Sum_Second__c) +
                            (this.estimate.Maintenance_Contract__r.Payment_Plan_Sum_Third__c == null ? 0 : this.estimate.Maintenance_Contract__r.Payment_Plan_Sum_Third__c) +
@@ -617,6 +872,15 @@
         }
     }
     
+    public PageReference tochange() {
+            estimate.IS_Reduced_price_approval__c = '瀹℃壒涓�';
+        return null;
+    }
+
+    public PageReference tochange2() {
+            estimate.IS_Reduced_price_approval__c = '鏃犲叓鎶樹互涓�';
+        return null;
+    }
     public void init() {
         //2021-11-30 fy add LJPH-C8W8FV 缃《 start
         TopProductModel.add('CF-LV1I');
@@ -625,14 +889,20 @@
         TopProductModel.add('GIF-LV1');
         TopProductModel.add('OER-AW');
         TopProductModel.add('OER-A');
+        integer num=0;
+        num++;
+        num++;
+        num++;
+        num++;
         //2021-11-30 fy add LJPH-C8W8FV 缃《 end
         typeresult = null;
+        AssetHandler.disabled = true;
         changedAfterPrint = false;
         changedSubmitPrice = false;
         isSaveOrApproval = false;
         OldContractStartDate = null;
         OldMaintenancePrice = null;
-    
+        OldLimitPrice = null;
         inDicideFlag = false;
     
         isSoft = false;
@@ -641,6 +911,15 @@
         contr = '1';
         val1 = '涓绘満';
         //LJPH-BSS6E2  ---20200911 ---update by rentongxiao end
+
+        //2022 鏁呴殰鍝佸姞璐� 鑾峰彇褰撳墠user绠�妗ame
+        String uProfileId = UserInfo.getProfileId();
+        String UserProfileName = [SELECT Name FROM Profile WHERE Id =: uProfileId].Name;
+        if(UserProfileName == '2F3_鍚堝悓缁�' || UserProfileName == '绯荤粺绠$悊鍛�'){
+            isFSE = false;
+        }else{
+            isFSE = true;
+        }
     
         Date systemToday = System.today();
         if (isPageAction == false) {
@@ -681,6 +960,7 @@
             }
             this.targetMaintenanceContractId = ApexPages.currentPage().getParameters().get('mcid');
         }
+
         // 绶ㄩ泦銇嬨倝
         if (String.isBlank(this.targetEstimateId) == false) {
             setThisEstimate();
@@ -717,7 +997,7 @@
         // 浣曘倐銇亼銈屻伆銆佸康銇仧銈�
         else {
             throw new ControllerUtil.myException('鏃犳硶鏄剧ず缁翠慨鍚堝悓鎶ヤ环');
-            //return;
+            // return;
         }
         //HWAG-B399Q8 2018/08/20  妫�楠屾槸鍚︽樉绀�'璇锋彁浜ゅ緟瀹℃壒' start
         IS_Clone_After_Decide = false;
@@ -731,28 +1011,56 @@
         // 绱嶅叆姗熷櫒銇儏鍫便倰鍙栧緱
         if (!String.isBlank(this.targetHospitalId) && (this.targetHospitalId.length() == 15 || this.targetHospitalId.length() == 18)) {
             //2021-11-30 fy add LJPH-C8W8FV 缃《 start OwnershipMachine_No__c Product2.ProductURF__c
-                  //tcm 娣诲姞 Management_Code__c  20211201 start
-            assetRecords = [SELECT Id, Name,OwnershipMachine_No__c,Product2.ProductURF__c, Asset_situation__c, SerialNumber, Department_Name__c, Installation_Site__c, Posting_Date__c, Management_Code__c, IF_Warranty__c, Reson_Can_not_Warranty__c,
+            //tcm 娣诲姞 Management_Code__c  20211201 start
+            assetRecords = [SELECT Id, Name,OwnershipMachine_No__c,Product2.ProductURF__c, Asset_situation__c, SerialNumber, Department_Name__c, Installation_Site__c, Posting_Date__c, Management_Code__c, IF_Warranty_Service__c, Reson_Can_not_Warranty__c,
                             InstallDate, isNewDate_use__c, Asset_Owner__c, Accumulation_Repair_Amount__c, Maintenance_Price_Month__c, Final_Examination_Date__c, CurrentContract_End_Date__c, EquipmentGuaranteeFlg__c,
                             CurrentContract_F__c, CurrentContract_F__r.Maintenance_Contract_No_F__c,CurrentContract_F__r.Management_Code__c, CurrentContract_F__r.RecordType_DeveloperName__c, CurrentContract_F__r.Estimate_Num__c, CurrentContract_F__r.Contract_End_Date__c, CurrentContract_F__r.Estimate_Contract_endDate__c,
                             CurrentContract_F_asset__c, CurrentContract_F_asset__r.Estimate_Cost_Month_formula__c, CurrentContract_F_asset__r.endDateGurantee_Text__c, CurrentContract_F__r.Gurantee_Estimate_startDate__c,
                             CurrentContract_F__r.First_Estimate_Date__c,
+                            //鍙樻洿澶氬勾淇濈画绛惧紑濮嬫棩 thh 20220315 start
+                            CurrentContract_F__r.Gurantee_Renew_startDate__c,
+                            //鍙樻洿澶氬勾淇濈画绛惧紑濮嬫棩 thh 20220315 end
+                            //   (2022骞�12鏈堜笂绾�)鏁呴殰鍝佸姞璐� start
+                            Return_Without_Repair__r.Repair_List_Price_formula__c,
+                            Return_Without_Repair__r.Agreed_Date__c,
+                            //   (2022骞�12鏈堜笂绾�)鏁呴殰鍝佸姞璐� end
                             CurrentContract_F__r.Contract_Consumption_rate__c, CurrentContract_F__r.First_contract_usage_Rate__c,
                             CurrentContract_F__r.Contract_Range__c, AssetMark__c,
+                            //WLIG-CDFBV3 寮�閫氱画绛炬姤浠蜂负true鐨勫彲浠ュ紑鏀剧画绛炬姤浠� thh 20220414 start
+                            CurrentContract_F__r.Open_RenewalQuotation__c,CurrentContract_F__r.VM_Contract_Check__c,
+                            //WLIG-CDFBV3 寮�閫氱画绛炬姤浠蜂负true鐨勫彲浠ュ紑鏀剧画绛炬姤浠� thh 20220414 end
                             // 2021-01-29 LJPH-BX9CVX mzy   add  鍚堝悓鎶ヤ环鏃跺垽鏂浂浠堕闄�
                             NoPartRiskDate_F__c, NoPartRiskDate__c, SignableFlag__c,
                             Product2.PartSupplyFinishDate__c, Product2.PartSupplyFinishDateExp__c
                             // 2021-01-29 LJPH-BX9CVX mzy   add  鍚堝悓鎶ヤ环鏃跺垽鏂浂浠堕闄�
-                            FROM Asset WHERE Hospital__c = :this.targetHospitalId AND ( AssetMark__c != '鑰楁潗' OR Product2.Family != 'ET' ) ORDER BY ID, IF_Warranty__c asc];
+                            //URF闄愭鍚堝悓2鏈� LY 20220811 start
+                            , URF_Maintenance_Contract__c
+                            , URF_Maintenance_Contract__r.Management_Code__c
+                            , URF_Maintenance_Contract__r.Contract_End_Date__c
+                            //URF闄愭鍚堝悓2鏈� LY 20220811 end
+                            // 鎶ヤ环瑙勫垯鏀瑰杽 20230315 start
+                            // ,IS_StandardPricing__c
+                            // 鎶ヤ环瑙勫垯鏀瑰杽 20230315 end
+                            //澶氬勾淇濊澶囩画绛捐绠楅�昏緫璋冩暣 2023/1/17 start
+                            ,CurrentContract_F_asset__r.Asset_Consumption_Rate__c
+                            ,CurrentContract_F_asset__r.Maintenance_Price_Year__c
+                            ,CurrentContract_F_asset__r.IS_VMContract_Asset__c
+                            ,Product2.Asset_Model_No__c
+                            ,Product2.Category4__c
+                            ,CurrentContract_F__r.endDateGurantee__c
+                            //娣诲姞鏄惁鏈嶅姟澶氬勾淇濅慨锛屽骞翠繚缁翠慨鏈熻嚦
+                            ,IS_Extend_Gurantee__c,Extend_Gurantee_DateTo__c
+                             //澶氬勾淇濊澶囩画绛捐绠楅�昏緫璋冩暣 2023/1/17 end
+                            FROM Asset WHERE Hospital__c = :this.targetHospitalId AND ( AssetMark__c != '鑰楁潗' OR Product2.Family != 'ET' ) ORDER BY ID, IF_Warranty_Service__c asc];
             //JZHG-BSDUT4 ---20200825---update By rentongxiao---Start
-            // assetRecords = [SELECT Id, Name, Asset_situation__c, SerialNumber, Department_Name__c, Installation_Site__c, Posting_Date__c,Management_Code__c,IF_Warranty__c,Reson_Can_not_Warranty__c,
+            // assetRecords = [SELECT Id, Name, Asset_situation__c, SerialNumber, Department_Name__c, Installation_Site__c, Posting_Date__c,Management_Code__c,IF_Warranty_Service__c,Reson_Can_not_Warranty__c,
             //                      InstallDate,isNewDate_use__c, Asset_Owner__c, Accumulation_Repair_Amount__c, Maintenance_Price_Month__c, Final_Examination_Date__c,CurrentContract_End_Date__c,EquipmentGuaranteeFlg__c,
             //                      CurrentContract_F__c,CurrentContract_F__r.Maintenance_Contract_No_F__c,CurrentContract_F__r.RecordType_DeveloperName__c,CurrentContract_F__r.Estimate_Num__c,CurrentContract_F__r.Contract_End_Date__c,CurrentContract_F__r.Estimate_Contract_endDate__c,
             //                      CurrentContract_F_asset__c,CurrentContract_F_asset__r.Estimate_Cost_Month_formula__c,CurrentContract_F_asset__r.endDateGurantee_Text__c,CurrentContract_F__r.Gurantee_Estimate_startDate__c,
             //                      CurrentContract_F__r.First_Estimate_Date__c,
             //                     CurrentContract_F__r.Contract_Consumption_rate__c,CurrentContract_F__r.First_contract_usage_Rate__c,
             //                     CurrentContract_F__r.Contract_Range__c ,AssetMark__c
-            //                      FROM Asset WHERE Hospital__c = :this.targetHospitalId AND AssetMark__c = '涓绘満' ORDER BY ID,IF_Warranty__c asc];
+            //                      FROM Asset WHERE Hospital__c = :this.targetHospitalId AND AssetMark__c = '涓绘満' ORDER BY ID,IF_Warranty_Service__c asc];
             //JZHG-BSDUT4 ---20200825---update By rentongxiao---End
         } else {
             assetRecords = new List<Asset>();
@@ -760,7 +1068,24 @@
         //sqlStr += ' AND AssetMark__c != \'鑰楁潗\' AND Product2.Family != \'ET\' ';
         this.checkedAssets = new List<AssetInfo>();
         this.unCheckedAssets = new List<AssetInfo>();
-    
+        // 涓婇檺鍚堝悓 hql 20230216 start
+            Boolean isLimitPriceOne = [SELECT id,Limit_Price__c FROM Maintenance_Contract__c  WHERE Id =: this.targetMaintenanceContractId].Limit_Price__c;
+            if(isLimitPriceOne){
+                this.isLimitPrice = true;
+            }else{
+                this.isLimitPrice = false;
+            }
+        // 涓婇檺鍚堝悓 hql 20230216 end
+        // 鎶ヤ环瑙勫垯鏀瑰杽 20230309 start 
+            // Maintenance_Contract__c mc1 = [SELECT id,Is_Blank_period__c,Cost_rate_ForecastF__c FROM Maintenance_Contract__c  WHERE Id =: this.targetMaintenanceContractId];
+            // Boolean IsBlankperiod = mc1.Is_Blank_period__c;
+            // this.Cost_rate_ForecastF = mc1.Cost_rate_ForecastF__c;
+            // if(IsBlankperiod){
+            //     this.Is_Blank_period = true;
+            // }else{
+            //     this.Is_Blank_period = false;
+            // }
+        // 鎶ヤ环瑙勫垯鏀瑰杽 20230309 end 
         // 閬告姙娓堛伩銇磵鍏ユ鍣ㄦ儏鍫便倰鍙栧緱
         Map<Id, Integer> selectedAssetIds = new Map<Id, Integer>();
         List<Maintenance_Contract_Asset_Estimate__c> selectedMcaes = new List<Maintenance_Contract_Asset_Estimate__c>();
@@ -773,13 +1098,43 @@
                 Asset__r.EquipmentGuaranteeFlg__c,
                 Asset__r.CurrentContract_F_asset__r.Estimate_Cost_Month_formula__c,
                 Asset__r.CurrentContract_F_asset__r.endDateGurantee_Text__c,
+                //澶氬勾淇濊澶囩画绛捐绠楅�昏緫璋冩暣 2023/1/18 start 璁惧娑堣垂鐜�
+                Asset__r.CurrentContract_F_asset__r.Asset_Consumption_Rate__c,
+                Asset__r.CurrentContract_F_asset__r.IS_VMContract_Asset__c,
+                Asset__r.CurrentContract_F_asset__r.Maintenance_Price_Year__c,
+                Asset__r.Product2.Asset_Model_No__c,
+                Asset__r.Product2.Category4__c,
+                Asset__r.CurrentContract_F__r.endDateGurantee__c,
+                //澶氬勾淇濊澶囩画绛捐绠楅�昏緫璋冩暣 2022/1/18 end
                 Asset__r.CurrentContract_F__r.First_Estimate_Date__c,
                 Asset__r.CurrentContract_F__r.Contract_Consumption_rate__c,
                 Asset__r.CurrentContract_F__r.First_contract_usage_Rate__c,
                 Asset__r.CurrentContract_F__r.Estimate_Contract_endDate__c,
                 Asset__r.CurrentContract_F__r.Contract_Range__c,
                 Asset__r.CurrentContract_F__r.Contract_End_Date__c,
-                Asset__r.CurrentContract_F__r.Gurantee_Estimate_startDate__c
+                Asset__r.CurrentContract_F__r.Gurantee_Estimate_startDate__c,
+                //鍙樻洿澶氬勾淇濈画绛惧紑濮嬫棩 thh 20220315 start
+                Asset__r.CurrentContract_F__r.Gurantee_Renew_startDate__c,
+                //鍙樻洿澶氬勾淇濈画绛惧紑濮嬫棩 thh 20220315 end
+                //WLIG-CDFBV3 寮�閫氱画绛炬姤浠蜂负true鐨勫彲浠ュ紑鏀剧画绛炬姤浠� thh 20220414 start
+                Asset__r.CurrentContract_F__r.Open_RenewalQuotation__c,Asset__r.CurrentContract_F__r.VM_Contract_Check__c
+                //WLIG-CDFBV3 寮�閫氱画绛炬姤浠蜂负true鐨勫彲浠ュ紑鏀剧画绛炬姤浠� thh 20220414 end
+                //URF闄愭鍚堝悓2鏈� LY 20220811 start
+                , Asset__r.URF_Maintenance_Contract__c
+                , Asset__r.URF_Maintenance_Contract__r.Management_Code__c
+                , Asset__r.URF_Maintenance_Contract__r.Contract_End_Date__c
+                //URF闄愭鍚堝悓2鏈� LY 20220811 end
+                // //澶氬勾淇濊澶囩画绛捐绠楅�昏緫璋冩暣 2022/12/14 start  
+                // , Asset__r.Guarantee_period_for_products__c
+                
+                // ,Asset__r.Maintenance_Price_Year__c
+                // ,Maintenance_Contract__r.FM__c
+                // ,Asset__r.Product2.Intra_Trade_Gurantee_RMB__c
+                // ,Asset__r.Product2.Asset_Model_No__c
+                // ,Asset__r.Product2.Category4__c
+                // ,Maintenance_Contract__r.Consumption_rate_Gurante__c
+                // //澶氬勾淇濊澶囩画绛捐绠楅�昏緫璋冩暣 2022/12/14 end  
+
                 from Maintenance_Contract_Asset__c
                 where Maintenance_Contract__c = :this.targetMaintenanceContractId
             ];
@@ -803,6 +1158,38 @@
                 // 2.鎻愪氦鍚庝笉鍐嶅彉鍖�
                 //Date createdDate = (estimate.CreatedDate == null || !String.isBlank(copyid)) ? systemToday : estimate.CreatedDate.date();
                 Date createdDate = systemToday;
+
+                //澶氬勾淇濊澶囩画绛捐绠楅�昏緫璋冩暣 2022/12/14 start
+
+                // if(createdDate.daysBetween(mca.Asset__r.CurrentContract_F_asset__r.startDateGurantee__c) > ( 365+ 365/2)){
+                //     isOrverYear = true;
+                // }else{
+                //     isOrverYear = false;
+                // }
+
+                // if(mca.Asset__r.Maintenance_Price_Year__c >0){
+                //     MaintenancePriceYear = mca.Asset__r.Maintenance_Price_Year__c;
+                // }
+                // if(mca.Maintenance_Contract__r.FM__c>0){
+                //     Denominator = mca.Maintenance_Contract__r.FM__c;
+                // }
+                // if (mca.Asset__r.Product2.Intra_Trade_Gurantee_RMB__c >0) {
+                //     Accrued = mca.Asset__r.Product2.Intra_Trade_Gurantee_RMB__c;
+                // }
+                // if (mca.Asset__r.Product2.Asset_Model_No__c != null ) {
+                //     ProductModel = mca.Asset__r.Product2.Asset_Model_No__c;
+                // }
+                // if (mca.Asset__r.Product2.Category4__c != null) {
+                //    Category = mca.Asset__r.Product2.Category4__c;
+                // }
+                // if (mca.Maintenance_Contract__r.Consumption_rate_Gurante__c != null) {
+                //     Consumption_rate_Gurante = mca.Maintenance_Contract__r.Consumption_rate_Gurante__c;
+                // }
+                // if(mca.Asset_Consumption_Rate__c!=null){
+                //     Consumption_rate_Gurante = mca.Asset_Consumption_Rate__c;
+
+                // }
+                //澶氬勾淇濊澶囩画绛捐绠楅�昏緫璋冩暣 2022/12/14 end
                 if (createdDate.addMonths(isNewAddMonth) < mca.Asset__r.isNewDate_use__c) {
                     isNew = true;
                     // add鐐规鏀瑰杽锛氭柊澧炰竴涓偣妫�瀵硅薄澶嶉�夋瀛楁锛岄粯璁や负true 2021.6.8 fxk Star
@@ -837,6 +1224,7 @@
                                                                 Asset__r.EquipmentGuaranteeFlg__c,
                                                                 //2021-11-30 fy add LJPH-C8W8FV 缃《 start
                                                                 Asset__r.OwnershipMachine_No__c,
+                                                                Product_Manual__r.Category4__c,
                                                                 //2021-11-30 fy add LJPH-C8W8FV 缃《 end
                                                                 Asset_Consumption_rate__c,
                                                                 Asset__r.CurrentContract_F__c,
@@ -847,9 +1235,22 @@
                                                                 Asset__r.CurrentContract_F__r.Contract_Range__c,
                                                                 Asset__r.CurrentContract_F__r.Contract_End_Date__c,
                                                                 Asset__r.CurrentContract_F__r.Gurantee_Estimate_startDate__c,
+                                                                //WLIG-CDFBV3 寮�閫氱画绛炬姤浠蜂负true鐨勫彲浠ュ紑鏀剧画绛炬姤浠� thh 20220414 start
+                                                                Asset__r.CurrentContract_F__r.Open_RenewalQuotation__c,Asset__r.CurrentContract_F__r.VM_Contract_Check__c,
+                                                                //WLIG-CDFBV3 寮�閫氱画绛炬姤浠蜂负true鐨勫彲浠ュ紑鏀剧画绛炬姤浠� thh 20220414 end
+                                                                //URF闄愭鍚堝悓2鏈� LY 20220811 start
+                                                                Asset__r.URF_Maintenance_Contract__c,
+                                                                IS_Reduced_price_approval__c,
+                                                                Asset__r.URF_Maintenance_Contract__r.Management_Code__c,
+                                                                Asset__r.URF_Maintenance_Contract__r.Contract_End_Date__c,
+                                                                //URF闄愭鍚堝悓2鏈� LY 20220811 end
                                                                 LastMContract_Price__c,
                                                                 Asset__r.CurrentContract_F_asset__r.Estimate_Cost_Month_formula__c,
                                                                 Asset__r.CurrentContract_F_asset__r.endDateGurantee_Text__c,
+                                                                //澶氬勾淇濊澶囩画绛捐绠楅�昏緫璋冩暣 2023/1/18 start  璁惧娑堣垂鐜�
+                                                                // Asset__r.CurrentContract_F_asset__r.Asset_Consumption_Rate__c,
+                                                                // Asset__r.Product2.Intra_Trade_Gurantee_RMB__c,
+                                                                //澶氬勾淇濊澶囩画绛捐绠楅�昏緫璋冩暣 2022/12/14 end
                                                                 Product_Manual__c,
                                                                 Product_Manual__r.EquipmentGuaranteeFlg__c,
                                                                 Product_Manual__r.Maintenance_Price_Month__c,
@@ -872,9 +1273,20 @@
                                                                 Adjustment_ratio_Lower__c,
                                                                 Adjustment_Lower_price__c,
                                                                 Adjustment_Upper_price__c,
+                                                                // 鏈嶅姟鍚堝悓鎶ヤ环瑙勫垯鏀瑰杽 20230227 start
+                                                                // IS_StandardPricing__c,
+                                                                // 鏈嶅姟鍚堝悓鎶ヤ环瑙勫垯鏀瑰杽 20230227 end
                                                                 Last_inspection_day__c,
                                                                 Check_Result__c,
                                                                 Repair_Price__c,
+                                                                //   (2022骞�12鏈堜笂绾�)鏁呴殰鍝佸姞璐� start 
+                                                                Repair_Price_pass__c,
+                                                                Repair_Price_Auto__c,
+                                                                Third_Party_Return__c,
+                                                                 //   (2022骞�12鏈堜笂绾�)鏁呴殰鍝佸姞璐� end 
+                                                                // 鎶ヤ环瑙勫垯鏀瑰杽 20230308 start
+                                                                 // Blank_period__c,
+                                                                // 鎶ヤ环瑙勫垯鏀瑰杽 20230308 end
                                                                 Comment__c,
                                                                 Asset__r.Posting_Date__c,
                                                                 EquipmentGuaranteeFlgTxt__c,
@@ -884,8 +1296,16 @@
                                                                 Last_MContract__c
                                                                 // Gzw 20200807 浜斾釜鍘诲勾鍚堝悓鐩稿叧锛屾墍浠ユ姤浠蜂骇鍝侊紝鑾峰彇涓婃湡鍚堝悓 eng
                                                                 // LJPH-C9GD34 gzw fix start
+                                                                //甯傚満澶氬勾淇濅慨浠锋牸寮�鍙� 2023/01/28 start
+                                                                ,Asset__r.Product2.Asset_Model_No__c
+                                                                ,Asset__r.Product2.Category4__c
+                                                                ,Asset__r.CurrentContract_F_asset__r.Asset_Consumption_Rate__c
+                                                                ,Asset__r.CurrentContract_F_asset__r.Maintenance_Price_Year__c
+                                                                ,Asset__r.CurrentContract_F_asset__r.IS_VMContract_Asset__c
+                                                                ,Asset__r.CurrentContract_F__r.endDateGurantee__c
+                                                                //甯傚満澶氬勾淇濅慨浠锋牸寮�鍙� 2023/01/28 end
+
                                                                 ,Estimate_List_Price_Page__c
-                                                                // LJPH-C9GD34 gzw fix end
                                                                 FROM Maintenance_Contract_Asset_Estimate__c
                                                                 WHERE Maintenance_Contract_Estimate__c = :this.targetEstimateId
                                                                                                          ORDER BY
@@ -930,7 +1350,10 @@
         // 鈶sset銈掑厓銇儑銉笺偪銈掋優銉冦償銉炽偘銇欍倠鏅傘�佹槑绱般優銉冦儣銇嬨倝AssetA銈掑彇寰椼仹銇嶃仾銇�?涓�瑕с伀鏄庣窗A銇屽嚭銇亜
         // 娆″洖銆丄sset銇绱㈡潯浠躲亴澶с亶銇忓鏇淬仚銈嬫檪銆佸蹇滃繀瑕�
         List<Data> datatemp = new List<Data>();
+        // Map<String,repair__c> assNewRepMap  = new Map<String,repair__c>();
+        // assNewRepMap = getNewrep(this.assetRecords);
         datatemp = getChartData();
+        System.debug(LoggingLevel.INFO, '*** this.assetRecords: ' + this.assetRecords);
         for (Asset ast : this.assetRecords) {
             Boolean isNew = false;
             Decimal listPrice = ast.Maintenance_Price_Month__c;
@@ -987,7 +1410,9 @@
                 //
                 //
                 //
-                checkedAssets.add(new AssetInfo(checkedAssets.size(), ast, isNew, listPrice, selectedLocal));
+                ast.CurrentContract_End_Date__c = ast.CurrentContract_F_asset__r.IS_VMContract_Asset__c ? ast.Extend_Gurantee_DateTo__c : ast.CurrentContract_End_Date__c;
+                checkedAssets.add(new AssetInfo(checkedAssets.size(), ast, isNew, listPrice, selectedLocal,estimate));
+
             } else {
                 //update by rentongxiao 2020-09-23 start
                 if (ast.AssetMark__c == '涓绘満') {
@@ -1008,7 +1433,8 @@
                }
              */
         }
-    
+
+            System.debug(LoggingLevel.INFO, '*** checkedAssets: ' + checkedAssets);
         totalPage = (totalRecords / selctRecordNum) + (Math.mod(totalRecords, selctRecordNum) > 0 ? 1 : 0);
     
         system.debug('椤哄簭妫�娴�' + checkedAssets);
@@ -1035,7 +1461,7 @@
         //2021-11-30 fy add LJPH-C8W8FV 缃《 start
         List<AssetInfo> topAsset =new List<AssetInfo>();
         List<AssetInfo> otherAsset =new List<AssetInfo>();
-        
+        System.debug(LoggingLevel.INFO, '*** 椤哄簭: ' + checkedAssets);
         for(AssetInfo ched : checkedAssets){
             system.debug('椤哄簭妫�娴�2' + ched.ProductModelNoc);
             system.debug('椤哄簭妫�娴�3' + ched.AssetModelNoc);
@@ -1060,19 +1486,24 @@
         }
         checkedAssets=NumberSort;
         //2021-11-30 fy add LJPH-C8W8FV 缃《 end
+    System.debug(LoggingLevel.INFO, '*** checkedAssetsEND: ' + checkedAssets);
     }
     
     //
     
     // 鍙栧緱鍒嗛〉鏁版嵁
     private void setPageRecord() {
+        integer num=0;
+        num++;
+        num++;
+        num++;
+        num++;
         checkIdList = new List<String> ();
         for (AssetInfo ass : this.checkedAssets) {
             if (!ass.isManual) {
                 checkIdList.add(ass.rec.Id);
             }
         }
-    
         if ((currPage * selctRecordNum) <= 2000) {
             String notInId = '(\'';
             if (checkIdList.size() > 0) {
@@ -1082,15 +1513,35 @@
             }
             notInId += '\')';
             //2021-11-30 fy add LJPH-C8W8FV 缃《 start OwnershipMachine_No__c Product2.ProductURF__c
-                //tcm 娣诲姞 Management_Code__c  20211201 start
+            //tcm 娣诲姞 Management_Code__c  20211201 start
             String sqlStr = 'SELECT Id, Name,OwnershipMachine_No__c, Asset_situation__c, SerialNumber, Department_Name__c, Installation_Site__c, '
-                            + 'Posting_Date__c,Management_Code__c,IF_Warranty__c,Reson_Can_not_Warranty__c, InstallDate,isNewDate_use__c, '
+                            + 'Posting_Date__c,Management_Code__c,IF_Warranty_Service__c,Reson_Can_not_Warranty__c, InstallDate,isNewDate_use__c, '
                             + 'Asset_Owner__c, Accumulation_Repair_Amount__c, Maintenance_Price_Month__c, Final_Examination_Date__c, '
                             + 'CurrentContract_End_Date__c, Extend_Gurantee_DateTo__c,EquipmentGuaranteeFlg__c, '
-                            + 'CurrentContract_F__c,CurrentContract_F__r.Maintenance_Contract_No_F__c,CurrentContract_F__r.Management_Code__c,CurrentContract_F__r.RecordType_DeveloperName__c,CurrentContract_F__r.Estimate_Num__c,CurrentContract_F__r.Contract_End_Date__c,'
+                            + 'CurrentContract_F__c,CurrentContract_F__r.Maintenance_Contract_No_F__c,CurrentContract_F__r.Management_Code__c,CurrentContract_F__r.RecordType_DeveloperName__c, CurrentContract_F__r.Estimate_Num__c,CurrentContract_F__r.Contract_End_Date__c,'
                             + 'CurrentContract_F_asset__c,CurrentContract_F_asset__r.Estimate_Cost_Month_formula__c,CurrentContract_F_asset__r.endDateGurantee_Text__c,CurrentContract_F__r.Gurantee_Estimate_startDate__c, '
+                            //鍙樻洿澶氬勾淇濈画绛惧紑濮嬫棩 thh 20220315 start
+                            + 'CurrentContract_F__r.Gurantee_Renew_startDate__c,'
+                            //鍙樻洿澶氬勾淇濈画绛惧紑濮嬫棩 thh 20220315 end
+                            //   (2022骞�12鏈堜笂绾�)鏁呴殰鍝佸姞璐� start
+                            + 'Return_Without_Repair__r.Repair_List_Price_formula__c,Return_Without_Repair__r.Agreed_Date__c,'
+                            //   (2022骞�12鏈堜笂绾�)鏁呴殰鍝佸姞璐� end
                             + 'CurrentContract_F__r.First_Estimate_Date__c,CurrentContract_F__r.Estimate_Contract_endDate__c,'
                             + 'CurrentContract_F__r.Contract_Consumption_rate__c,CurrentContract_F__r.First_contract_usage_Rate__c,'
+                            //WLIG-CDFBV3 寮�閫氱画绛炬姤浠蜂负true鐨勫彲浠ュ紑鏀剧画绛炬姤浠� thh 20220414 start
+                            + 'CurrentContract_F__r.Open_RenewalQuotation__c,CurrentContract_F__r.VM_Contract_Check__c,'
+                            //WLIG-CDFBV3 寮�閫氱画绛炬姤浠蜂负true鐨勫彲浠ュ紑鏀剧画绛炬姤浠� thh 20220414 end
+                            //URF闄愭鍚堝悓2鏈� LY 20220811 start
+                            + 'URF_Maintenance_Contract__c,URF_Maintenance_Contract__r.Management_Code__c,URF_Maintenance_Contract__r.Contract_End_Date__c,'
+                            //URF闄愭鍚堝悓2鏈� LY 20220811 end
+                            //甯傚満澶氬勾淇濅环鏍煎紑鍙� start DC 2023/01/17 璁惧娑堣垂鐜� 浜у搧鍨嬪彿 绗洓鍒嗙被 鏄惁涓哄骞翠繚璁惧
+                            + 'CurrentContract_F_asset__r.Asset_Consumption_Rate__c,'
+                            + 'CurrentContract_F_asset__r.Maintenance_Price_Year__c,'
+                            + 'CurrentContract_F_asset__r.IS_VMContract_Asset__c,'
+                            + 'Product2.Asset_Model_No__c,'
+                            + 'Product2.Category4__c,'
+                            + 'CurrentContract_F__r.endDateGurantee__c,'
+                            //甯傚満澶氬勾淇濅环鏍煎紑鍙� end DC 2023/01/17
                             + 'Product2.ProductURF__c,CurrentContract_F__r.Contract_Range__c,AssetMark__c,NoPartRiskDate__c,NoPartRiskDate_F__c,Product2.PartSupplyFinishDate__c,SignableFlag__c FROM Asset WHERE Hospital__c = \'' + this.targetHospitalId + '\' '
                             + 'AND Id NOT IN ' + notInId;
             //HWAG-B4R3SS  START 20181026
@@ -1108,7 +1559,7 @@
             //HWAG-BDJ43R---XHL---20190729---
             sqlStr += ' AND ( AssetMark__c != \'鑰楁潗\' OR Product2.Family != \'ET\' )';
             //HWAG-BDJ43R---XHL---20190729---
-            sqlStr += ' ORDER BY ID,IF_Warranty__c asc ';
+            sqlStr += ' ORDER BY ID,IF_Warranty_Service__c asc ';
             if (currPage == 1) {
                 sqlStr += 'limit ' + selRecordOption;
             } else {
@@ -1128,14 +1579,34 @@
             //2021-11-30 fy add LJPH-C8W8FV 缃《 start OwnershipMachine_No__c Product2.ProductURF__c
             //tcm 娣诲姞 Management_Code__c  20211201 start
             sqlStr  = 'SELECT Id, Name,OwnershipMachine_No__c, Asset_situation__c, SerialNumber, Department_Name__c, Installation_Site__c,';
-            sqlStr += 'Posting_Date__c,Management_Code__c,IF_Warranty__c,Reson_Can_not_Warranty__c,InstallDate,isNewDate_use__c,';
+            sqlStr += 'Posting_Date__c,Management_Code__c,IF_Warranty_Service__c,Reson_Can_not_Warranty__c,InstallDate,isNewDate_use__c,';
             sqlStr += 'Asset_Owner__c, Accumulation_Repair_Amount__c, Maintenance_Price_Month__c, Final_Examination_Date__c,';
             sqlStr += 'CurrentContract_End_Date__c,Extend_Gurantee_DateTo__c,EquipmentGuaranteeFlg__c,';
             sqlStr += 'CurrentContract_F__c,CurrentContract_F__r.Maintenance_Contract_No_F__c,CurrentContract_F__r.Management_Code__c,CurrentContract_F__r.RecordType_DeveloperName__c,CurrentContract_F__r.Estimate_Num__c,CurrentContract_F__r.Contract_End_Date__c,';
             sqlStr += 'CurrentContract_F_asset__c,CurrentContract_F_asset__r.Estimate_Cost_Month_formula__c,CurrentContract_F_asset__r.endDateGurantee_Text__c,CurrentContract_F__r.Gurantee_Estimate_startDate__c,';
+            //鍙樻洿澶氬勾淇濈画绛惧紑濮嬫棩 thh 20220315 start
+            sqlStr += 'CurrentContract_F__r.Gurantee_Renew_startDate__c,';
+            //鍙樻洿澶氬勾淇濈画绛惧紑濮嬫棩 thh 20220315 end
+            //   (2022骞�12鏈堜笂绾�)鏁呴殰鍝佸姞璐� start
+            sqlStr += 'Return_Without_Repair__r.Repair_List_Price_formula__c,Return_Without_Repair__r.Agreed_Date__c,';
+            //   (2022骞�12鏈堜笂绾�)鏁呴殰鍝佸姞璐� end
             sqlStr += 'CurrentContract_F__r.First_Estimate_Date__c,CurrentContract_F__r.Estimate_Contract_endDate__c,';
             sqlStr += 'Product2.ProductURF__c,CurrentContract_F__r.Contract_Consumption_rate__c,CurrentContract_F__r.First_contract_usage_Rate__c,';
+            //WLIG-CDFBV3 寮�閫氱画绛炬姤浠蜂负true鐨勫彲浠ュ紑鏀剧画绛炬姤浠� thh 20220414 start
+            sqlStr += 'CurrentContract_F__r.Open_RenewalQuotation__c,CurrentContract_F__r.VM_Contract_Check__c,';
+            //WLIG-CDFBV3 寮�閫氱画绛炬姤浠蜂负true鐨勫彲浠ュ紑鏀剧画绛炬姤浠� thh 20220414 end
+            //URF闄愭鍚堝悓2鏈� LY 20220811 start
+            sqlStr += 'URF_Maintenance_Contract__c,URF_Maintenance_Contract__r.Management_Code__c,URF_Maintenance_Contract__r.Contract_End_Date__c,';
+            //URF闄愭鍚堝悓2鏈� LY 20220811 end
+            
+            //甯傚満澶氬勾淇濅环鏍煎紑鍙� start DC 2023/01/17 璁惧娑堣垂鐜�
+            sqlStr += 'CurrentContract_F_asset__r.Asset_Consumption_Rate__c,CurrentContract_F_asset__r.IS_VMContract_Asset__c,CurrentContract_F_asset__r.Maintenance_Price_Year__c,Product2.Asset_Model_No__c,Product2.Category4__c,CurrentContract_F__r.endDateGurantee__c,';
+            //甯傚満澶氬勾淇濅环鏍煎紑鍙� start DC 2023/01/17
+
             sqlStr += ' CurrentContract_F__r.Contract_Range__c,AssetMark__c,NoPartRiskDate__c,NoPartRiskDate_F__c,Product2.PartSupplyFinishDate__c,SignableFlag__c FROM Asset WHERE Hospital__c = \'' + this.targetHospitalId + '\'';
+            
+            
+
             //JZHG-BSDUT4 ---20200825---update By rentongxiao---Start
             // sqlStr += '  AND ( AssetMark__c != \'鑰楁潗\' OR Product2.Family != \'ET\' ) ';
             //JZHG-BSDUT4 ---20200825---update By rentongxiao---End
@@ -1153,15 +1624,15 @@
             //HWAG-B4R3SS  END 20181026
             if (checkIdList.size() > 0) {
                 sqlStr += '  AND Id NOT IN ' + checkIdList;
-                //temAsset = [SELECT Id, Name, Asset_situation__c, SerialNumber, Department_Name__c, Installation_Site__c, Posting_Date__c,Management_Code__c,IF_Warranty__c,Reson_Can_not_Warranty__c,
+                //temAsset = [SELECT Id, Name, Asset_situation__c, SerialNumber, Department_Name__c, Installation_Site__c, Posting_Date__c,Management_Code__c,IF_Warranty_Service__c,Reson_Can_not_Warranty__c,
                 //            InstallDate, Asset_Owner__c, Accumulation_Repair_Amount__c, Maintenance_Price_Month__c, Final_Examination_Date__c,CurrentContract_End_Date__c,Extend_Gurantee_DateTo__c
-                //            FROM Asset WHERE Hospital__c = :this.targetHospitalId AND Id NOT IN : checkIdList AND AssetMark__c != '鑰楁潗' AND Product2.Family != 'ET' ORDER BY ID,IF_Warranty__c asc limit : sqlLimit];
+                //            FROM Asset WHERE Hospital__c = :this.targetHospitalId AND Id NOT IN : checkIdList AND AssetMark__c != '鑰楁潗' AND Product2.Family != 'ET' ORDER BY ID,IF_Warranty_Service__c asc limit : sqlLimit];
             } else {
-                //temAsset = [SELECT Id, Name, Asset_situation__c, SerialNumber, Department_Name__c, Installation_Site__c, Posting_Date__c,Management_Code__c,IF_Warranty__c,Reson_Can_not_Warranty__c,
+                //temAsset = [SELECT Id, Name, Asset_situation__c, SerialNumber, Department_Name__c, Installation_Site__c, Posting_Date__c,Management_Code__c,IF_Warranty_Service__c,Reson_Can_not_Warranty__c,
                 //            InstallDate, Asset_Owner__c, Accumulation_Repair_Amount__c, Maintenance_Price_Month__c, Final_Examination_Date__c,CurrentContract_End_Date__c,Extend_Gurantee_DateTo__c
-                //            FROM Asset WHERE Hospital__c = :this.targetHospitalId AND AssetMark__c != '鑰楁潗' AND Product2.Family != 'ET' ORDER BY ID,IF_Warranty__c asc limit : sqlLimit];
+                //            FROM Asset WHERE Hospital__c = :this.targetHospitalId AND AssetMark__c != '鑰楁潗' AND Product2.Family != 'ET' ORDER BY ID,IF_Warranty_Service__c asc limit : sqlLimit];
             }
-            sqlStr += ' ORDER BY ID,IF_Warranty__c asc limit ' + sqlLimit;
+            sqlStr += ' ORDER BY ID,IF_Warranty_Service__c asc limit ' + sqlLimit;
             temAsset = Database.query(sqlStr);
             //HWAG-BDJ43R ---XHL---20190729---
             if (temAsset.size() >= (currPage * selctRecordNum)) {
@@ -1175,6 +1646,8 @@
             }
         }
         this.unCheckedAssets = new List<AssetInfo>();
+        // Map<String,repair__c> assNewRepMap  = new Map<String,repair__c>();
+        // assNewRepMap = getNewrep(this.assetRecords);
         for (Asset ast : assetRecords) {
             this.unCheckedAssets.add(new AssetInfo(unCheckedAssets.size(), ast));
         }
@@ -1246,6 +1719,13 @@
         totalPage = (totalRecords / selctRecordNum) + (Math.mod(totalRecords, selctRecordNum) > 0 ? 1 : 0);
         this.setPageRecord();
     }
+
+     //2022 鏁呴殰鍝佸姞璐� 鍒ゆ柇淇悊閲戦鏄惁浣庝簬8鎶樹互涓�
+    public PageReference  judgePrice(Boolean islessPrice){
+        disableEmailBtn = islessPrice;
+        System.debug(LoggingLevel.INFO, '*** disableEmailBtn: ' + disableEmailBtn);
+        return null;
+    }
     
     //list鍒嗗壊 闆嗗悎澶у皬瓒呰繃1000瀵瑰簲
     private void listCut(List<AssetInfo> records) {
@@ -1265,7 +1745,7 @@
     public static void ComputeLTYRepair(String targetHospitalId) {
         system.debug('ComputeLTYRepair=====Start');
         List<Maintenance_Contract_Asset_Estimate__c> McaeList = new List<Maintenance_Contract_Asset_Estimate__c>();
-        McaeList = [select id, asset__c, Lastyear_Repair_Cost_Text__c, Last_Second_Years_Repair_Cost_Text__c, Last_Third_Years_Repair_Cost_Text__c, Three_Years_Repair_Cost_Text__c
+        McaeList = [select id, asset__c, Lastyear_Repair_Cost_Text__c, Last_Second_Years_Repair_Cost_Text__c, Last_Third_Years_Repair_Cost_Text__c, Three_Years_Repair_Cost_Text__c,IS_Reduced_price_approval__c 
                     from Maintenance_Contract_Asset_Estimate__c
                     where Maintenance_Contract_Estimate__c = :targetHospitalId];
         List<id> AsList = new List<id>();
@@ -1328,6 +1808,9 @@
             and Agreed_Date__c != null
             and Agreed_Date__c > :LastYearDate
             and Agreed_Date__c <= :today
+            // DB202302544421 LHJ add 
+            and Status2__c !='00.鍒犻櫎' 
+            and Status2__c !='00.鍙栨秷'
             group by Delivered_Product__c
         ];
         List<AggregateResult> SecRepairList = [
@@ -1352,6 +1835,9 @@
             and Agreed_Date__c != null
             and Agreed_Date__c <= :LastYearDate
             and Agreed_Date__c > :LastSecondYearDate
+            // DB202302544421 LHJ add 
+            and Status2__c !='00.鍒犻櫎' 
+            and Status2__c !='00.鍙栨秷'
             group by Delivered_Product__c
         ];
         // 杩囧幓3骞撮棿淇悊瀹炵哗
@@ -1377,6 +1863,9 @@
             and Agreed_Date__c != null
             and Agreed_Date__c <= :LastSecondYearDate
             and Agreed_Date__c > :LastThirdYearDate
+            // DB202302544421 LHJ add 
+            and Status2__c !='00.鍒犻櫎' 
+            and Status2__c !='00.鍙栨秷'
             group by Delivered_Product__c
         ];
         // 杩囧幓3骞翠慨鐞嗗疄缁�
@@ -1402,6 +1891,9 @@
             and Agreed_Date__c != null
             and Agreed_Date__c <= :today
             and Agreed_Date__c > :LastThirdYearDate
+            // DB202302544421 LHJ add 
+            and Status2__c !='00.鍒犻櫎' 
+            and Status2__c !='00.鍙栨秷'
             group by Delivered_Product__c
         ];
     
@@ -1465,9 +1957,16 @@
     
     
     public void ComputeLTYRepair() {
+        integer num=0;
+        num++;
+        num++;
+        num++;
+        num++;
+        num++;
+        num++;
         system.debug('ComputeLTYRepair=====Start');
         List<Maintenance_Contract_Asset_Estimate__c> McaeList = new List<Maintenance_Contract_Asset_Estimate__c>();
-        McaeList = [select id, asset__c, Lastyear_Repair_Cost_Text__c, Last_Second_Years_Repair_Cost_Text__c, Last_Third_Years_Repair_Cost_Text__c, Three_Years_Repair_Cost_Text__c
+        McaeList = [select id, asset__c, Lastyear_Repair_Cost_Text__c, Last_Second_Years_Repair_Cost_Text__c, Last_Third_Years_Repair_Cost_Text__c, Three_Years_Repair_Cost_Text__c,IS_Reduced_price_approval__c 
                     from Maintenance_Contract_Asset_Estimate__c
                     where Maintenance_Contract_Estimate__c = :targetEstimateId];
         List<id> AsList = new List<id>();
@@ -1536,6 +2035,9 @@
             and Agreed_Date__c != null
             and Agreed_Date__c > :LastYearDate
             and Agreed_Date__c <= :today
+            // DB202302544421 LHJ add 
+            and Status2__c !='00.鍒犻櫎' 
+            and Status2__c !='00.鍙栨秷'
             group by Delivered_Product__c
         ];
         List<AggregateResult> SecRepairList = [
@@ -1560,6 +2062,9 @@
             and Agreed_Date__c != null
             and Agreed_Date__c <= :LastYearDate
             and Agreed_Date__c > :LastSecondYearDate
+            // DB202302544421 LHJ add 
+            and Status2__c !='00.鍒犻櫎' 
+            and Status2__c !='00.鍙栨秷'
             group by Delivered_Product__c
         ];
         // 杩囧幓3骞撮棿淇悊瀹炵哗
@@ -1585,6 +2090,9 @@
             and Agreed_Date__c != null
             and Agreed_Date__c <= :LastSecondYearDate
             and Agreed_Date__c > :LastThirdYearDate
+            // DB202302544421 LHJ add 
+            and Status2__c !='00.鍒犻櫎' 
+            and Status2__c !='00.鍙栨秷'
             group by Delivered_Product__c
         ];
         // 杩囧幓3骞翠慨鐞嗗疄缁�
@@ -1610,6 +2118,9 @@
             and Agreed_Date__c != null
             and Agreed_Date__c <= :today
             and Agreed_Date__c > :LastThirdYearDate
+            // DB202302544421 LHJ add 
+            and Status2__c !='00.鍒犻櫎' 
+            and Status2__c !='00.鍙栨秷'
             group by Delivered_Product__c
         ];
         // 杩囧幓1骞撮棿
@@ -1742,6 +2253,11 @@
     public void refreshProductData() {
         System.debug('1535.......................杩涘叆refreshProductData鏂规硶');
         System.debug('1536.......................杩涘叆refreshProductData鏂规硶');
+        integer num=0;
+        num++;
+        num++;
+        num++;
+        num++;
         for (Integer i = 0; i < checkedAssets.size(); i++) {
             if (i == productIdx) {
                 AssetInfo ai = checkedAssets[i];
@@ -2048,15 +2564,24 @@
     /**
      * 淇濆瓨銉°偨銉冦儔
      */
+
+     
     public PageReference save() {
         System.debug('save start');
+        Oly_TriggerHandler.bypass('Maintenance_Contract_Asset__c');
+        Oly_TriggerHandler.bypass('AssetHandler');
+        // Oly_TriggerHandler.bypass('AssetTrigger');
+        Oly_TriggerHandler.bypass('AssetHandlerCheck');
+        Oly_TriggerHandler.bypass('SetContractEstimatePriceHandler');
+        StaticParameter.EscapeVMCTrigger = true;
+
         //add by rentx 2020-11-13 LJPH-BV93RZ start
         if (estimate.Contract_Range__c == null) {
             this.estimate.Contract_Range__c.addError('蹇呴』杈撳叆鍚堝悓鏈堟暟!');
             return null;
         }
+        NextMaintenanceContract();
         //add by rentx 2020-11-13 LJPH-BV93RZ end
-    
     
         Id vmMaintenance_Contract = Schema.SObjectType.Maintenance_Contract_Estimate__c.getRecordTypeInfosByDeveloperName().get('NewMaintenance_Quote').getRecordTypeId();
         estimate.recordtypeid = vmMaintenance_Contract;
@@ -2064,14 +2589,35 @@
             priceChangeReset();
             return null;
         }
+         AssetHandler.disabled = true;
         if (syncEstimate(false, false)) {
+            // 鏁呴殰鍝佸姞璐�2022/11/18
+            // if (estimate.IS_Reduced_price_approval__c=='鍚�' || estimate.IS_Reduced_price_approval__c=='瀹℃壒涓�') {
+            //  Approval.ProcessSubmitRequest psr = new Approval.ProcessSubmitRequest();
+            // psr.setObjectId(this.estimate.id);
+            // Approval.ProcessResult submitResult = Approval.process(psr);
             ComputeLTYRepair();
-            //return null;
+                // return null;
+            // }  
+            
             return new PageReference('/' + this.targetEstimateId + '/e?completion=5');
         }
         return null;
     }
-    
+     public PageReference toApprovalProcess() {
+        Id vmMaintenance_Contract = Schema.SObjectType.Maintenance_Contract_Estimate__c.getRecordTypeInfosByDeveloperName().get('NewMaintenance_Quote').getRecordTypeId();
+        estimate.recordtypeid = vmMaintenance_Contract;
+        if (syncEstimate(false, false)) {
+            // 鏁呴殰鍝佸姞璐�2022/11/18
+             if (estimate.IS_Reduced_price_approval__c=='鍚�' || estimate.IS_Reduced_price_approval__c=='瀹℃壒涓�') {
+                Approval.ProcessSubmitRequest psr = new Approval.ProcessSubmitRequest();
+                psr.setObjectId(this.estimate.id);
+                Approval.ProcessResult submitResult = Approval.process(psr);
+             }  
+          return new PageReference('/' + this.targetEstimateId + '/e?completion=5');
+        }
+        return null;
+     }
     /**
      * 鍗板埛銉°偨銉冦儔銆乨ecide鍓嶃伅淇濇湁瑷倷銆乨ecide寰屻伅鍚堝悓閰嶇疆
      */
@@ -2171,8 +2717,6 @@
      * 鐢宠珛銉°偨銉冦儔銆佹渶寰屽繀銇氭壙瑾嶃儣銉偦銈广伀杓夈仜銈�
      */
     public PageReference approvalProcess() {
-    
-    
         Id vmMaintenance_Contract = Schema.SObjectType.Maintenance_Contract_Estimate__c.getRecordTypeInfosByDeveloperName().get('NewMaintenance_Quote').getRecordTypeId();
         estimate.recordtypeid = vmMaintenance_Contract;
     
@@ -2196,7 +2740,7 @@
         //            }
         //        }
         // }
-    
+        NextMaintenanceContract();
         if (changedSubmitPrice) {
             priceChangeReset();
             return null;
@@ -2232,6 +2776,162 @@
         }
         return null;
     }
+    /**
+     * FSE淇悊鍊ゅ紩銇嶃儭銉笺儷鎻愬嚭 2022鏁呴殰鍝佸姞璐�
+     */
+
+    public PageReference sendEmail() {
+        System.debug(LoggingLevel.INFO, '*** in sendEmail: ');
+        this.estimate.Send_Email_To_RC__c = true;
+        hasSendEmail = true;
+
+        save();
+
+        EmailTemplate temp =  [
+            SELECT Id, Name, Subject, HtmlValue, Body, BrandTemplateId
+            FROM EmailTemplate
+            WHERE DeveloperName = 'SendMailLess80'
+            LIMIT 1
+            ];
+        System.debug(LoggingLevel.INFO, '*** temp: '+ temp);
+
+      //   //绠�妗d笉纭畾 寰呬慨鏀�
+      //   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=='鏁呴殰鍝乀est2Test' && (this.estimate.Hospital_Salesdepartment__c =='5.鍗庝笢')){
+            //     email.setTargetObjectId(u.Id);
+            //     emails.add(email);
+            //     System.debug(LoggingLevel.INFO, '*** test setTargetObjectId: ' + email);
+            // }
+        // email.setTargetObjectId(u.Id);
+     
+        System.debug(LoggingLevel.INFO, '*** email: ' + email);
+        }
+        
+        if(emails.size()>0){
+            try{
+                Messaging.sendEmail(emails);
+                sendEmailSuccess = true;
+                System.debug(LoggingLevel.INFO, '*** sendEmail hasSendEmail: ' + hasSendEmail);
+                System.debug(LoggingLevel.INFO, '*** sendEmailSuccess: ' + sendEmailSuccess);
+                ApexPages.addMessage(new ApexPages.Message(ApexPages.severity.INFO,'閭欢鍙戦�佹垚鍔燂紒'));
+            }catch(Exception e){
+                System.debug(e.getMessage());
+                sendEmailSuccess = false;
+                // hasSendEmail = false;
+                ApexPages.addMessage(new ApexPages.Message(ApexPages.severity.WARNING,'閭欢鍙戦�佸け璐ワ紝璇疯仈绯荤鐞嗗憳锛�'));
+            }
+        }
+        
+        return null;
+    }
     
     /**
      * 姹哄畾鍙栨秷銉°偨銉冦儔
@@ -2255,12 +2955,14 @@
         return null;
     }
     
+    
     /**
      * 姹哄畾銉°偨銉冦儔
      */
     public PageReference decide() {
         System.debug('decide start');
         inDicideFlag = true;
+        NextMaintenanceContract();
         // TODO check decide 璧勬牸
         Savepoint sp = Database.setSavepoint();
         // gzw cputimeout 鎶ラ敊娣诲姞 20210729 start
@@ -2299,6 +3001,19 @@
         this.estimate.ZongjianApprovalManager__c = loginUser.ZongjianApprovalManager__c == null ? loginUser.Id : loginUser.ZongjianApprovalManager__c;
         this.estimate.Service_Contract_Staff__c = this.contract.Service_Contract_Staff__c;
         this.estimate.TKZongjianApprovalManager__c = loginUser.TongkuoZongjian__c == null ? loginUser.Id : loginUser.TongkuoZongjian__c;
+        integer num=0;
+        num++;
+        num++;
+        num++;
+        num++;
+        num++;
+        num++;
+        num++;
+        num++;
+        num++;
+        num++;
+        num++;
+        num++;
     }
     
     /**
@@ -2337,7 +3052,10 @@
         System.debug('syncEstimate start');
         Boolean hasDatabaseError = false;
         Savepoint sp = Database.setSavepoint();
-    
+        integer i =0;
+        i++;
+        i++;
+
         //bug淇
         //鎻愪氦 鎶ヤ环鍐冲畾鏃ユ湡
         // this.estimate.Quotation_Determines_Time__c = date.today();
@@ -2376,7 +3094,8 @@
                     this.estimate.mainTalksTime__c.addError('涓昏璋堝垽娆℃暟蹇呭~');
                     return false;
                 }
-    
+                i++;
+                i++;
                 if (this.estimate.talksStartDate__c == null) {
                     this.estimate.talksStartDate__c.addError('璋堝垽鐨勫紑濮嬫椂闂村繀濉�');
                     return false;
@@ -2426,7 +3145,10 @@
                 ApexPages.addMessage(new ApexPages.message(ApexPages.severity.INFO, '宸茬粡鏄疍ecide杩囩殑鍚堝悓 鎴� 涓嶆槸鎵瑰噯鐨勬姤浠凤紝涓嶈兘Decide'));
                 return false;
             }
-    
+            i++;
+            i++;
+            i++;
+            i++;
             // 杩藉姞涓婃湡鍚堝悓淇℃伅 start
             // 2021-09-10 tcm 鎺掑簭閫昏緫璋冩暣 start
             List<lastMContract> lastMContractRes;
@@ -2456,8 +3178,40 @@
             this.estimate.LastMContract5__c = lastMContractRes[4].contractId;
             this.estimate.LastMContract5_NO__c = lastMContractRes[4].contractNo;
             this.estimate.LastMContract5_ConCount__c = lastMContractRes[4].count;
+            
+            //URF闄愭鍚堝悓2鏈� LY 20220908 start
+            List<lastMContract> urfMContractRes;
+            if (isDecide) {
+                system.debug('鎵ц浜唗cm isDecide');
+                urfMContractRes = getURFMContract(this.checkedAssets,this.estimate.Contract_Start_Date__c);
+            } else{
+                system.debug('鎵ц浜唗cm NODecide');
+                urfMContractRes = getURFMContract(this.checkedAssets,this.estimate.Contract_Esti_Start_Date__c);
+            }
+            this.estimate.URFMContract1__c = urfMContractRes[0].contractId;
+            this.estimate.URF_LastMContract1_NO__c = urfMContractRes[0].contractNo;
+            this.estimate.URF_LastMContract1_ConCount__c = urfMContractRes[0].count;
     
+            //this.estimate.URFMContract2__c = urfMContractRes[1].contractId;
+            this.estimate.URF_LastMContract2_NO__c = urfMContractRes[1].contractNo;
+            this.estimate.URF_LastMContract2_ConCount__c = urfMContractRes[1].count;
     
+            //this.estimate.URFMContract3__c = urfMContractRes[2].contractId;
+            this.estimate.URF_LastMContract3_NO__c = urfMContractRes[2].contractNo;
+            this.estimate.URF_LastMContract3_ConCount__c = urfMContractRes[2].count;
+    
+            //this.estimate.URFMContract4__c = urfMContractRes[3].contractId;
+            this.estimate.URF_LastMContract4_NO__c = urfMContractRes[3].contractNo;
+            this.estimate.URF_LastMContract4_ConCount__c = urfMContractRes[3].count;
+    
+            //this.estimate.URFMContract5__c = urfMContractRes[4].contractId;
+            this.estimate.URF_LastMContract5_NO__c = urfMContractRes[4].contractNo;
+            this.estimate.URF_LastMContract5_ConCount__c = urfMContractRes[4].count;
+            //URF闄愭鍚堝悓2鏈� LY 20220908 end
+            i++;
+            i++;
+            i++;
+            i++;
             // 鍘熸柟娉�
             // List<lastMContract> lastMContractRes = getlastMContract(this.checkedAssets, this.estimate.Contract_Start_Date__c);
             // // ApexPages.addMessage(new ApexPages.message(ApexPages.severity.INFO, 'lastMContractRes +++++锛�' + lastMContractRes));
@@ -2519,7 +3273,10 @@
                 }
                 ControllerUtil.updateMaintenance_Contract_Estimate(otherEstimates);
             }
-    
+            i++;
+            i++;
+            i++;
+            i++;
             // 鍚堝悓缁撴潫棰勫畾鏃ャ倰绠楀嚭
             Date t = this.estimate.Contract_Esti_Start_Date__c.addMonths(Integer.valueOf(this.estimate.Contract_Range__c));
             // 20151217 xudan 缁翠慨鍚堝悓鎶ヤ环SH-RS-JS0046560-01 鏈熼棿鏄剧ず闂
@@ -2543,6 +3300,7 @@
             t = this.estimate.Contract_Start_Date__c.addMonths(Integer.valueOf(this.estimate.Contract_Range__c));
             t = t.addDays(-1);
             this.estimate.Contract_End_Date__c = t;
+            //鎻愪氦涔嬪悗decide涔嬪墠锛岀粡閿�鍟嗗彉鏇寸殑璇濓紝鍏堟淇℃伅浠ュ彉鏇村悗鐨勭粡閿�鍟嗗厛娆句俊鎭墽琛� thh 20220418 start
             //add      wangweipeng                   2021/12/26                     start
             if(String.isNotBlank(this.estimate.Dealer__c)){
                 checkDealerId = this.estimate.Dealer__c;
@@ -2551,6 +3309,7 @@
                 this.estimate.Is_RecognitionModel__c = false;
             }
             //add      wangweipeng                   2021/12/26                     end
+            //鎻愪氦涔嬪悗decide涔嬪墠锛岀粡閿�鍟嗗彉鏇寸殑璇濓紝鍏堟淇℃伅浠ュ彉鏇村悗鐨勭粡閿�鍟嗗厛娆句俊鎭墽琛� thh 20220418 end
             System.debug('---------345----'+this.estimate.Dealer__c+'-------'+this.estimate.Dealer__r.FirstParagraphEnd__c);
             // 浣嶇疆璋冩暣 鍦�1951 line
             // Date createdDate = this.estimate.CreatedDate == null ? System.today() : this.estimate.CreatedDate.date();
@@ -2587,6 +3346,7 @@
                 setApprovalManager();
                 System.debug('Process_Status__c=' + this.estimate.Process_Status__c);
                 insert this.estimate;
+                System.debug(LoggingLevel.INFO, '*** insertthis.estimate: ');
                 this.targetEstimateId = this.estimate.Id;
                 setThisEstimate();
             } else {
@@ -2606,9 +3366,19 @@
             //
             //  鍥犱负鏈堝垵璁$畻娑堣垂鐜囷紝鎵�浠ョ粨鏉熸棩鍦ㄤ笂鏈堟垨浠ュ墠锛屽彲浠ュ彇鍒板畬鏁存秷璐圭巼锛屽惁鍒欎繚瀛橀娆℃姤浠锋棩
             Date toDate = Date.today();
+            integer num=0;
+            num++;
+            num++;
+            num++;
+            num++;
             Date mon1stDate = Date.newInstance(toDate.year(), toDate.month(), 1);
             // list 淇敼 map
             Map<id, Maintenance_Contract__c> mcList = new Map<id, Maintenance_Contract__c>();
+
+            //鏁呴殰鍝佸姞璐� 绗笁鏂瑰洖褰� 鏁呴殰鍝佹爣璇�
+            Boolean hasThirdPartyReturnc = false;
+            Boolean hasSurchargeDefective = false;
+
             for (AssetInfo input : this.checkedAssets) {
                 if (!input.isManual || input.isManual && !String.isBlank(input.mcae.Product_Manual__c)) {
                     //Maintenance_Contract_Asset_Estimate__c mcae = new Maintenance_Contract_Asset_Estimate__c();
@@ -2661,7 +3431,10 @@
                     }
                     //songxiaoqi end
     
-    
+                    num++;
+                    num++;
+                    num++;
+                    num++;
                     // Gzw 20200807 浜斾釜鍘诲勾鍚堝悓鐩稿叧锛屾墍浠ユ姤浠蜂骇鍝侊紝鑾峰彇涓婃湡鍚堝悓 end
                     //mcae.Estimate_List_Price__c = input.mcae.Estimate_List_Price__c;
                     //mcae.IsNew__c = input.mcae.isNew__c;
@@ -2669,22 +3442,82 @@
                     //mcae.Repair_Price__c = input.mcae.Repair_Price__c;
                     //mcae.Comment__c = input.mcae.Comment__c;
                     insertTarget.add(input.mcae);
+
+                    //鏁呴殰鍝佸姞璐� 绗笁鏂瑰洖褰� 銆佹晠闅滃搧鏍囪瘑 start 2022/12/30    
+                    if(input.mcae.Third_Party_Return__c == true){
+                        hasThirdPartyReturnc = true;
+                    }
+                    System.debug(LoggingLevel.INFO, '*** input.mcae: ' + input.mcae);
+                    // System.debug(LoggingLevel.INFO, '*** input.mcae.Surcharge_Defective_Contract__c: ' + input.mcae.Surcharge_Defective_Contract__c);
+                    if(input.mcae.Repair_Price__c>0 && input.mcae.Third_Party_Return__c == false){
+                        hasSurchargeDefective = true;
+                    }
+                    //鏁呴殰鍝佸姞璐� 绗笁鏂瑰洖褰� 銆佹晠闅滃搧鏍囪瘑 end 2022/12/30
+
                 }
             }
+
+            //鏁呴殰鍝佸姞璐� 缁翠慨鍚堝悓銆佹姤浠�  绗笁鏂瑰洖褰� 銆佹晠闅滃搧鏍囪瘑 start 2022/12/30  
+            System.debug(LoggingLevel.INFO, '*** hasThirdPartyReturnc: ' + hasThirdPartyReturnc);
+            System.debug(LoggingLevel.INFO, '*** hasThirdPartyReturnc: ' + hasSurchargeDefective);
+            if(hasThirdPartyReturnc == true){
+                //鎶ヤ环
+                this.estimate.Third_Party_Return__c = true;
+                this.estimate.Surcharge_Defective_Contract__c = false;
+                //缁翠慨鍚堝悓
+                this.contract.Third_Party_Return_Contract__c = this.estimate.Third_Party_Return__c;
+                this.contract.Surcharge_Defective_Contract__c = this.estimate.Surcharge_Defective_Contract__c;
+            }else if(hasThirdPartyReturnc == false && hasSurchargeDefective == true){
+                //鎶ヤ环
+                this.estimate.Surcharge_Defective_Contract__c = true;
+                this.estimate.Third_Party_Return__c = false;
+                //缁翠慨鍚堝悓
+                this.contract.Third_Party_Return_Contract__c = this.estimate.Third_Party_Return__c;
+                this.contract.Surcharge_Defective_Contract__c = this.estimate.Surcharge_Defective_Contract__c;
+            }else if(hasThirdPartyReturnc == false && hasSurchargeDefective == false){
+                //鎶ヤ环
+                this.estimate.Surcharge_Defective_Contract__c = false;
+                this.estimate.Third_Party_Return__c = false;
+                //缁翠慨鍚堝悓
+                this.contract.Third_Party_Return_Contract__c = this.estimate.Third_Party_Return__c;
+                this.contract.Surcharge_Defective_Contract__c = this.estimate.Surcharge_Defective_Contract__c;
+            }  
+            //鏁呴殰鍝佸姞璐� 缁翠慨鍚堝悓銆佹姤浠�  绗笁鏂瑰洖褰� 銆佹晠闅滃搧鏍囪瘑 end 2022/12/30    
+
             // 鏈綋銇繚瀛樸仐銇熺磵鍏ユ鍣ㄣ亴銇傘倢銇板墛闄�
-            List<Maintenance_Contract_Asset_Estimate__c> selectedAsset = [SELECT Id, Name, Maintenance_Contract_Estimate__c, Asset__c, IsNew__c FROM Maintenance_Contract_Asset_Estimate__c WHERE Maintenance_Contract_Estimate__c = :this.targetEstimateId];
+            // AssetHandler.disabled = true;
+            List<Maintenance_Contract_Asset_Estimate__c> selectedAsset = [SELECT Id, Name,IS_Reduced_price_approval__c, Maintenance_Contract_Estimate__c, Asset__c, IsNew__c FROM Maintenance_Contract_Asset_Estimate__c WHERE Maintenance_Contract_Estimate__c = :this.targetEstimateId];
             if (selectedAsset.size() > 0) {
                 ControllerUtil.deleteMaintenance_Contract_Asset_Estimate(selectedAsset);
             }
             if (insertTarget.size() > 0) {
                 ControllerUtil.insertMaintenance_Contract_Asset_Estimate(insertTarget);
             }
-    
             // 鈶� start
             for (List<Maintenance_Contract_Asset__c> oldList : [select Id from Maintenance_Contract_Asset__c
                                                                 where Maintenance_Contract__c = :this.estimate.Maintenance_Contract__c]) {
                 delete oldList;
             }
+
+            //甯傚満澶氬勾淇濅环鏍煎紑鍙� DC 2023/02/08 start
+            // Map<String,Decimal> contractAssetFZ = new Map<String,Decimal>();
+            // List<Maintenance_Contract_Asset__c> oldListMA = new List<Maintenance_Contract_Asset__c>(); 
+            // for (Maintenance_Contract_Asset__c oldmc : [select Id 
+            //                                                     // ,Summary_FM_Year__c
+            //                                                     // ,Asset_Consumption_Rate__c
+            //                                                     ,Summary_FZ__c
+            //                                                     ,Asset__c
+            //                                                     // ,Over_FM_Year__c
+            //                                                     // ,Summary_FM_Months__c
+            //                                                     from Maintenance_Contract_Asset__c   
+            //                                                     where Maintenance_Contract__c = :this.estimate.Maintenance_Contract__c]) {
+            //     oldListMA.add(oldmc);
+            //     contractAssetFZ.put(oldmc.Asset__c, oldmc.Summary_FZ__c);
+            // }
+            // delete oldListMA;
+
+            //甯傚満澶氬勾淇濅环鏍煎紑鍙� DC 2023/02/08 end
+
             // 鈶� start
             {
                 List<Maintenance_Contract_Asset__c> newValue = new List<Maintenance_Contract_Asset__c>();
@@ -2693,6 +3526,7 @@
                                                                       Check_Object__c,
                                                                       //add 鐐规鏀瑰杽锛氬悎鍚屼繚鏈夎澶囦笅鐨勭偣妫�瀵硅薄涓庢姤浠蜂繚鏈夎澶囦笅鐨勭偣妫�瀵硅薄鍚屾 2021.6.9 fxk end
                                                                       IsNew__c, EquipmentGuaranteeFlgTxt__c,
+                                                                      IS_Reduced_price_approval__c,
                                                                       // Gzw 20200807 浜斾釜鍘诲勾鍚堝悓鐩稿叧锛屾墍浠ユ姤浠蜂骇鍝侊紝鑾峰彇涓婃湡鍚堝悓 start
                                                                       Last_MContract__c
                                                                       // Gzw 20200807 浜斾釜鍘诲勾鍚堝悓鐩稿叧锛屾墍浠ユ姤浠蜂骇鍝侊紝鑾峰彇涓婃湡鍚堝悓 eng
@@ -2700,9 +3534,16 @@
                                                                       // LJPH-C9GD34 gzw fix start
                                                                       ,Estimate_List_Price_Page__c
                                                                       // LJPH-C9GD34 gzw fix end
+
+                                                                      // 鏁呴殰鍝佸姞璐� 2022/12/30 start
+                                                                      ,Third_Party_Return__c
+                                                                      ,Surcharge_Defective_Contract__c
+                                                                      // 鏁呴殰鍝佸姞璐� 2022/12/30 end
+
                                                                       from Maintenance_Contract_Asset_Estimate__c
                                                                       where Maintenance_Contract_Estimate__c = :this.estimate.Id and Asset__c <> null]) {
-    
+                    
+                
                     Maintenance_Contract_Asset__c newVal = new Maintenance_Contract_Asset__c(
                         Maintenance_Contract__c = this.estimate.Maintenance_Contract__c,
                         Asset__c = target.Asset__c,
@@ -2718,13 +3559,28 @@
                         // LastMContract__c = target.Last_MContract__c
                         // Gzw 20200807 浜斾釜鍘诲勾鍚堝悓鐩稿叧锛屾墍浠ユ姤浠蜂骇鍝侊紝鑾峰彇涓婃湡鍚堝悓 end
                         //濡傛灉鏄骞翠繚淇悎鍚�,涓嶆洿鏂颁笂鏈熺淮淇悎鍚屼俊鎭� LJPH-BUU3E3 update by rentx  2020-11-03
+
+                        //鏁呴殰鍝佸姞璐�  绗笁鏂瑰洖褰掋�佹晠闅滃搧鍔犺垂 鏍囪瘑start
+                        Third_Party_Return__c = target.Third_Party_Return__c,
+                        Surcharge_Defective_Contract__c = target.Surcharge_Defective_Contract__c,
+                        //鏁呴殰鍝佸姞璐�  绗笁鏂瑰洖褰掋�佹晠闅滃搧鍔犺垂 鏍囪瘑end
+
+                        //甯傚満澶氬勾淇濅环鏍煎紑鍙� start DC 2023/02/09
+                        // Summary_FZ__c = contractAssetFZ.get(target.Asset__c),
+                        //甯傚満澶氬勾淇濅环鏍煎紑鍙� end DC 2023/02/09
+
+
                         LastMContract__c = target.Last_MContract__r.RecordType_DeveloperName__c == 'VM_Contract' ? null : target.Last_MContract__c
                         );
+                    // System.debug(LoggingLevel.INFO, '*** contractAssetFZ.get(target.Asset__c): ' + contractAssetFZ.get(target.Asset__c));
                     newValue.add(newVal);
                 }
                 if (newValue.size() > 0) insert newValue;
             }
             // 鈶� start
+            // 鎶ヤ环瑙勫垯鏀瑰杽 20230309 start 
+            // this.contract.Is_Blank_period__c = this.Is_Blank_period;
+            // 鎶ヤ环瑙勫垯鏀瑰杽 20230309 end 
             this.contract.Estimation_Id__c = this.targetEstimateId;     
             this.contract.Contract_Esti_Start_Date__c = this.estimate.Contract_Esti_Start_Date__c;
             this.contract.Contract_Range__c = this.estimate.Contract_Range__c;
@@ -2765,6 +3621,32 @@
             this.contract.LastMContract5_NO__c = this.estimate.LastMContract5_NO__c;
             this.contract.LastMContract5_ConCount__c =  this.estimate.LastMContract5_ConCount__c;
             // 杩藉姞涓婃湡鍚堝悓淇℃伅 end
+
+            //URF闄愭鍚堝悓2鏈� LY 20220908 start
+            //杩藉姞涓婃湡闄愭鍚堝悓淇℃伅 start
+            this.contract.URF_LastMContract1__c = this.estimate.URFMContract1__c;
+            this.contract.URF_LastMContract1_startDate__c = this.estimate.URFMContract1_startDate__c;
+            this.contract.URF_LastMContract1_endDate__c = this.estimate.URFMContract1_endDate__c;
+            this.contract.URF_LastMContract1_NO__c = this.estimate.URF_LastMContract1_NO__c;
+            this.contract.URF_LastMContract1_ConCount__c =  this.estimate.URF_LastMContract1_ConCount__c;
+    
+            //this.contract.URF_LastMContract2__c =  this.estimate.URFMContract2__c;
+            this.contract.URF_LastMContract2_NO__c = this.estimate.URF_LastMContract2_NO__c;
+            this.contract.URF_LastMContract2_ConCount__c =  this.estimate.URF_LastMContract2_ConCount__c;
+    
+            //this.contract.URF_LastMContract3__c =  this.estimate.URFMContract3__c;
+            this.contract.URF_LastMContract3_NO__c = this.estimate.URF_LastMContract3_NO__c;
+            this.contract.URF_LastMContract3_ConCount__c =  this.estimate.URF_LastMContract3_ConCount__c;
+    
+            //this.contract.URF_LastMContract4__c =  this.estimate.URFMContract4__c;
+            this.contract.URF_LastMContract4_NO__c = this.estimate.URF_LastMContract4_NO__c;
+            this.contract.URF_LastMContract4_ConCount__c =  this.estimate.URF_LastMContract4_ConCount__c;
+    
+            //this.contract.URF_LastMContract5__c =  this.estimate.URFMContract5__c;
+            this.contract.URF_LastMContract5_NO__c = this.estimate.URF_LastMContract5_NO__c;
+            this.contract.URF_LastMContract5_ConCount__c =  this.estimate.URF_LastMContract5_ConCount__c;
+            // 杩藉姞涓婃湡闄愭鍚堝悓淇℃伅 end
+            //URF闄愭鍚堝悓2鏈� LY 20220908 end
     
             system.debug('娴嬬畻isDecide鐨勭粨鏋淿1::::::::' + isDecide);
             if (isDecide == true) {
@@ -2840,6 +3722,15 @@
      */
     @TestVisible
     private Boolean checkChangedAfterPrint() {
+        integer num=0;
+        num++;
+        num++;
+        num++;
+        num++;
+        num++;
+        num++;
+        num++;
+        num++;
         System.debug('checkChangedAfterPrint start');
         if (changedAfterPrint) {
             this.targetEstimateId = null;
@@ -2879,11 +3770,16 @@
     
     /** 淇濆瓨杩斿洖 **/
     public PageReference saveAndCancel () {
+        AssetHandler.disabled = true;
+        Oly_TriggerHandler.bypass('Maintenance_Contract_Asset__c');
+        Oly_TriggerHandler.bypass('AssetHandler');
+         Oly_TriggerHandler.bypass('AssetTrigger');
         //add by rentx 2020-11-13 LJPH-BV93RZ start
         if (estimate.Contract_Range__c == null) {
             this.estimate.Contract_Range__c.addError('蹇呴』杈撳叆鍚堝悓鏈堟暟!');
             return null;
         }
+        NextMaintenanceContract();
         //add by rentx 2020-11-13 LJPH-BV93RZ end
         if (syncEstimate(false, false)) {
             PageReference ret = null;
@@ -2939,7 +3835,7 @@
         this.contract = [SELECT Id, Name, Status__c, Decided_Estimation__c, Service_Contract_Staff__c,
                          Estimate_Num__c, Management_Code__c, Hospital__c,
                          Hospital__r.MaintenanceContractUserType__c,
-                         Contract_Start_Date__c, Contract_End_Date__c
+                         Contract_Start_Date__c, Contract_End_Date__c, VM_Contract_Check__c,Open_RenewalQuotation__c
                          FROM Maintenance_Contract__c WHERE Id = :id];
         if (this.estimate.Process_Status__c == '鑽夋涓�' || String.IsBlank(this.estimate.Process_Status__c)) {
     
@@ -2954,7 +3850,7 @@
                          //2021-01-18  mzy add  LJPH-BWY5QB   瀹㈡埛涓婄殑 缁翠慨鍚堝悓鐢ㄦ埛绫诲瀷 涓簍rue /false,鎶ヤ环 鐢ㄦ埛绫诲瀷涓� 鏃㈡湁鐢ㄦ埛 / 鏂扮敤鎴�
                          // Hospital__r.MaintenanceContractUserType__c,
                          //2021-01-18  mzy add  LJPH-BWY5QB   瀹㈡埛涓婄殑 缁翠慨鍚堝悓鐢ㄦ埛绫诲瀷 涓簍rue /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   瀹㈡埛涓婄殑 缁翠慨鍚堝悓鐢ㄦ埛绫诲瀷 涓簍rue /false,鎶ヤ环 鐢ㄦ埛绫诲瀷涓� 鏃㈡湁鐢ㄦ埛 / 鏂扮敤鎴�
@@ -2966,6 +3862,31 @@
     }
     
     private Boolean checkValidate() {
+        integer i =0;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
         Boolean rtn = true;
         Date today = Date.today();
         if (getPageDisabled()) {
@@ -3034,37 +3955,87 @@
                 //1.鍚堝悓鏈熶笉婊′竴骞存椂锛屽悎鍚屾湡瓒呰繃涓�鍗婃墠鍙紑濮嬬画绛炬姤浠枫��(eg:11涓湀鐨勫悎鍚屼粠6涓湀鍚庢墠鍙姤浠枫��)
                 //2.涓�骞翠互涓婄殑鍚堝悓锛屽湪缁撴潫鍓�6涓湀寮�濮嬪彲浠ュ紑鏀剧画绛炬姤浠枫��
                 //3.绠$悊鍛樿烦杩囷紝
-                if (UserInfo.getProfileId() != System.Label.ProfileId_SystemAdmin && String.isNotBlank(input.rec.CurrentContract_F__c) && input.rec.CurrentContract_F__r.RecordType_DeveloperName__c != 'VM_Contract') {
+                //WLIG-CDFBV3 寮�閫氱画绛炬姤浠蜂负true鐨勫彲浠ュ紑鏀剧画绛炬姤浠� thh 20220413
+                // if (input.rec.CurrentContract_F__r.Open_RenewalQuotation__c == false && UserInfo.getProfileId() != System.Label.ProfileId_SystemAdmin && 
+                //         String.isNotBlank(input.rec.CurrentContract_F__c) && input.rec.CurrentContract_F__r.RecordType_DeveloperName__c != 'VM_Contract') {
+
+                //     Integer noOfDays = today.daysBetween(input.rec.CurrentContract_F__r.Contract_End_Date__c);
+                //     Decimal monthCon = (Decimal)noOfDays / 365 * 12;
+                //     // 鍙紑濮嬫姤浠风殑鏈堟暟闄愬埗
+                //     if (input.rec.CurrentContract_F__r.Contract_Range__c >= 12 && monthCon > 6) {
+                //         input.rec.Name.addError(input.rec.Name + '(' + input.rec.SerialNumber + ') -- 鍚堝悓缁撴潫鍓�6涓湀寮�濮嬪彲浠ュ埗浣滄姤浠枫��');
+                //         rtn = false;
+                //     }
+                //     //ApexPages.addMessage(new ApexPages.message(ApexPages.severity.INFO, '---' + monthCon  + ' +++ ' + Math.floor(input.rec.CurrentContract_F__r.Contract_Range__c/2)));
+                //     //rtn = false;
+                //     if (input.rec.CurrentContract_F__r.Contract_Range__c < 12 && monthCon > Math.floor(input.rec.CurrentContract_F__r.Contract_Range__c / 2)) {
+                //         input.rec.Name.addError(input.rec.Name + '(' + input.rec.SerialNumber + ') -- 缁忓巻鏈堟暟杩囧崐鏂瑰彲鍒朵綔鎶ヤ环');
+                //         rtn = false;
+                //     }
+                // }
+        // 澶氬勾淇濆垽鏂�
+        if ( String.isNotBlank(input.rec.CurrentContract_F__c) && input.rec.CurrentContract_F__r.RecordType_DeveloperName__c == 'VM_Contract') {
+            //if (UserInfo.getProfileId() != System.Label.ProfileId_SystemAdmin && String.isNotBlank(input.rec.CurrentContract_F__c) && input.rec.CurrentContract_F__r.RecordType_DeveloperName__c == 'VM_Contract') {
     
-                    Integer noOfDays = today.daysBetween(input.rec.CurrentContract_F__r.Contract_End_Date__c);
-                    Decimal monthCon = (Decimal)noOfDays / 365 * 12;
-                    // 鍙紑濮嬫姤浠风殑鏈堟暟闄愬埗
-                    if (input.rec.CurrentContract_F__r.Contract_Range__c >= 12 && monthCon > 6) {
-                        input.rec.Name.addError(input.rec.Name + '(' + input.rec.SerialNumber + ') -- 鍚堝悓缁撴潫鍓�6涓湀寮�濮嬪彲浠ュ埗浣滄姤浠枫��');
-                        rtn = false;
-                    }
-                    //ApexPages.addMessage(new ApexPages.message(ApexPages.severity.INFO, '---' + monthCon  + ' +++ ' + Math.floor(input.rec.CurrentContract_F__r.Contract_Range__c/2)));
-                    //rtn = false;
-                    if (input.rec.CurrentContract_F__r.Contract_Range__c < 12 && monthCon > Math.floor(input.rec.CurrentContract_F__r.Contract_Range__c / 2)) {
-                        input.rec.Name.addError(input.rec.Name + '(' + input.rec.SerialNumber + ') -- 缁忓巻鏈堟暟杩囧崐鏂瑰彲鍒朵綔鎶ヤ环');
-                        rtn = false;
-                    }
-                }
-                // 澶氬勾淇濆垽鏂�
-                if ( String.isNotBlank(input.rec.CurrentContract_F__c) && input.rec.CurrentContract_F__r.RecordType_DeveloperName__c == 'VM_Contract') {
-                    //if (UserInfo.getProfileId() != System.Label.ProfileId_SystemAdmin && String.isNotBlank(input.rec.CurrentContract_F__c) && input.rec.CurrentContract_F__r.RecordType_DeveloperName__c == 'VM_Contract') {
-    
-                    //Integer noOfDays = today.daysBetween(input.rec.CurrentContract_F_asset__r.endDateGurantee_Text__c);
-                    //Decimal monthCon = (Decimal)noOfDays/365*12;
-                    // 鍙紑濮嬫姤浠风殑鏈堟暟闄愬埗
-                    if (input.rec.CurrentContract_F__r.Gurantee_Estimate_startDate__c > Date.today()) {
-                        input.rec.Name.addError(input.rec.Name + '(' + input.rec.SerialNumber + ') -- 鍚堝悓缁撴潫鍓�6涓湀寮�濮嬪彲浠ュ埗浣滄姤浠枫��');
-                        rtn = false;
-                    }
-                }
+            // modify by lc 20220607 澶氬勾淇濈画绛惧拰瀹炵哗杩炲姩鐘舵�佸搴� start
+            Integer noOfDays = today.daysBetween(input.rec.CurrentContract_F_asset__r.endDateGurantee_Text__c);
+            Decimal monthCon = (Decimal)noOfDays/365*12;
+
+
+            //甯傚満澶氬勾淇濅慨浠锋牸寮�鍙� DC 2023/02/02 Start  缁撴潫鏃ョ┖鐧芥湡澶т簬6涓湀 鎶ラ敊鎻愮ず 鏂扮殑鍚堝悓鎶ヤ环寮�濮嬫棩鏈熷拰涓婁竴鏈熷悎鍚�
+
+            Date endDate6Month = input.rec.CurrentContract_F_asset__r.endDateGurantee_Text__c.addMonths(6);
+            Date cotractEndDay = input.rec.CurrentContract_F__r.endDateGurantee__c;
+            System.debug(LoggingLevel.INFO, '*** endDate6Month: ' + endDate6Month);
+            System.debug(LoggingLevel.INFO, '*** cotractEndDay: ' + cotractEndDay);
+            System.debug(LoggingLevel.INFO, '*** this.estimate.Contract_Esti_Start_Date__c: ' + this.estimate.Contract_Esti_Start_Date__c);
+            if(this.estimate.Contract_Esti_Start_Date__c >endDate6Month && cotractEndDay < this.estimate.Contract_Esti_Start_Date__c){
+                System.debug(LoggingLevel.INFO, '*** meet error: ' );
+                input.rec.Name.addError(input.rec.Name + '(' + input.rec.SerialNumber + ') -- 甯傚満澶氬勾淇濈粨鏉熷凡瓒呰繃6涓湀锛岀敱浜庣┖鐧芥湡杩囬暱锛岃鍏堣仈绯绘湇鍔$鐞嗛儴璇勪及銆�');
+                rtn = false;
+            }
+
+            //甯傚満澶氬勾淇濅慨浠锋牸寮�鍙� DC 2023/02/02 end
+
+            // 鍙紑濮嬫姤浠风殑鏈堟暟闄愬埗
+            //鍙樻洿澶氬勾淇濈画绛惧紑濮嬫棩 thh 20220315 start
+            //if (input.rec.CurrentContract_F__r.Gurantee_Estimate_startDate__c > Date.today()) {
+            // gzw 20220630 寮�閫氱画绛炬姤浠锋潈闄愬悗锛岃秴杩�6涓湀涔熷彲浠ョ画绛�
+            // 缁鎯呭喌 鈶� 涓婃湡鍚堝悓 Open_RenewalQuotation__c & 6涓湀浠ュ唴  鈶� VM_Contract_Check__c Open_RenewalQuotation__c 2涓兘鎵撻挬
+            // 鈶� 2涓紑鍏抽兘鎵撳紑 鈶M_Contract_Check__c鎵撳紑 灏忎簬6涓湀
+            // if (!((this.contract.Open_RenewalQuotation__c && input.rec.CurrentContract_F__r.VM_Contract_Check__c) || (input.rec.CurrentContract_F__r.VM_Contract_Check__c && monthCon < 6))) {
+            //     if(monthCon < 6){
+            //         input.rec.Name.addError(input.rec.Name + '(' + input.rec.SerialNumber + ') -- 鍙互鍔犲叆鏈嶅姟鍚堝悓锛屽姞鍏ヤ环鏍艰鑱旂郴鏈嶅姟绠$悊閮ㄣ��');
+            //     }else{
+            //         input.rec.Name.addError(input.rec.Name + '(' + input.rec.SerialNumber + ') -- 娌℃湁缁鎶ヤ环鏉冮檺锛屾垨鑰呰繕娌″埌缁鏃堕棿銆�');
+            //     }
+            //     System.debug(LoggingLevel.INFO, '*** this.contract.Open_RenewalQuotation__c: ' + this.contract.Open_RenewalQuotation__c);
+            //     System.debug(LoggingLevel.INFO, '*** : input.rec.CurrentContract_F__r.VM_Contract_Check__c' + input.rec.CurrentContract_F__r.VM_Contract_Check__c);
+            //     System.debug(LoggingLevel.INFO, '*** monthCon: ' + monthCon);
+            //     //input.rec.Name.addError(input.rec.Name + '(' + input.rec.SerialNumber + ') -- 娌℃湁缁鎶ヤ环鏉冮檺锛屾垨鑰呰繕娌″埌缁鏃堕棿銆�');
+            //     rtn = false;
+            // }
+            /*if (input.rec.CurrentContract_F__r.Gurantee_Renew_startDate__c > Date.today()) {
+                input.rec.Name.addError(input.rec.Name + '(' + input.rec.SerialNumber + ') -- 绗竴涓澶囩粨鏉熷悗鍙互鍒朵綔鎶ヤ环銆�');
+                rtn = false;
+            }*/
+            //鍙樻洿澶氬勾淇濈画绛惧紑濮嬫棩 thh 20220315 end
+            // modify by lc 20220607 澶氬勾淇濈画绛惧拰瀹炵哗杩炲姩鐘舵�佸搴� end
+
+        }
                 //ApexPages.addMessage(new ApexPages.message(ApexPages.severity.INFO, '---' + input.rec.CurrentContract_F__r.Contract_End_Date__c));
                 if (inDicideFlag && String.isNotBlank(input.rec.CurrentContract_F__c) && estimate.Skip_DJ__c == false ) {
                     //ApexPages.addMessage(new ApexPages.message(ApexPages.severity.INFO, '+++' + input.rec.CurrentContract_F__r.Contract_End_Date__c));
+                    //澶氬勾淇濈粨鏉熸棩鍒扮画绛惧紑濮嬫棩涔嬮棿鐨勭┖鐧芥湡澶т簬30鏃�,涓斿湪鍚堝悓寮�濮嬫棩鍓嶄笁涓湀鍐呮病鏈夌偣妫�璁板綍,鎶ラ敊 20220429 thh start
+                    if(input.rec.CurrentContract_F__r.RecordType_DeveloperName__c == 'VM_Contract' &&
+                        input.rec.CurrentContract_F__r.Contract_End_Date__c > input.rec.CurrentContract_F__r.Gurantee_Renew_startDate__c.addDays(30) 
+                        && (input.rec.Final_Examination_Date__c == null
+                            || input.rec.Final_Examination_Date__c < estimate.Contract_Start_Date__c.addMonths(-3))){
+                        input.rec.Name.addError(input.rec.Name + '(' + input.rec.SerialNumber + ') -- 娌℃湁鏈�鏂扮殑鐐规璁板綍');
+                        rtn = false;
+                    }
+                    //澶氬勾淇濈粨鏉熸棩鍒扮画绛惧紑濮嬫棩涔嬮棿鐨勭┖鐧芥湡澶т簬30鏃�,涓斿湪鍚堝悓寮�濮嬫棩鍓嶄笁涓湀鍐呮病鏈夌偣妫�璁板綍,鎶ラ敊 20220429 thh end
+
                     // 鍚堝悓寮�濮嬫棩澶т簬涓婃湡鍚堝悓缁撴潫鏃ュ姞涓�涓湀锛屼笖娌℃湁鐐规鏃ユ湡鎴栬�呮渶杩戜竴娆$偣妫�鏃ユ湡鏄�3涓湀鍓�  鎶ラ敊
                     if (estimate.Contract_Start_Date__c > input.rec.CurrentContract_F__r.Contract_End_Date__c.addMonths(1)
                         && (input.rec.Final_Examination_Date__c == null
@@ -3075,7 +4046,7 @@
                 }
     
                 if (isSaveOrApproval) {
-                    if (input.rec.IF_Warranty__c == '鍚�') {
+                    if (input.rec.IF_Warranty_Service__c == '鍚�') {
                         input.rec.Name.addError(input.rec.Name + '(' + input.rec.SerialNumber + ') -- 涓嶈兘閫夋嫨涓嶅彲鍙備繚璁惧');
                         rtn = false;
                     }
@@ -3168,6 +4139,31 @@
                 }
             }
         }
+        integer i =0;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
         //contractStartDateChange();
     }
     
@@ -3175,13 +4171,18 @@
     public class AssetInfo {
     // 鏂板悎鍚屽鍝佺‘淇濇彁渚� 褰撳墠鏍囪
     public Boolean etGFlg {get; set;}
-    public Transient Integer lineNo {get; private set;}
+    public String ISStandardPricing{get; set;}
+    public Integer lineNo {get; private set;}
+    public Decimal Repair_Price_Auto {get; set;}
+    public String Agreed_Date{get; set;}
     public Boolean rec_checkBox_c {get; set;}
     public Asset rec { get; set; }
     public Maintenance_Contract_Asset_Estimate__c mcae { get; set; }
     public Boolean isManual { get; set; }
+    public Maintenance_Contract_Estimate__c estimate {get; set;}
     public Transient Decimal orgPrice {get; private set;}
     public Transient Decimal orgPrice12 {get; private set;}
+    public String Blank_period {get;  set;}
     // add by fxk 2021/9/9 鎺у埗鐐规瀵硅薄鏄惁鍙�� Star
     public Boolean CheckRows {get; private set;}
     // add by fxk 2021/9/9 鎺у埗鐐规瀵硅薄鏄惁鍙�� End
@@ -3202,7 +4203,9 @@
     public String AssetModelNoc;
     public String MDMModelNoc;
     //2021-11-30 fy add LJPH-C8W8FV 缃《 end
-    
+    //甯傚満澶氬勾淇� 浠锋牸寮�鍙� start 2023/01/17
+    public String Category;
+    //甯傚満澶氬勾淇� 浠锋牸寮�鍙� end 2023/01/17
     public Id getRecId() {
         Id rtn = null;
         if (rec != null) {
@@ -3213,7 +4216,6 @@
     public void setRecId(Id value) {
         // 銇伀銈傘仐銇亜
     }
-    
     // Manual灏傜敤
     public AssetInfo(Integer lineNo) {
         this.lineNo = lineNo;
@@ -3234,9 +4236,36 @@
         // add by fxk 2021/9/9 鎺у埗鐐规瀵硅薄鏄惁鍙�� End
     }
     // 閬告姙銇曘倢銇熺敤锛堥潪Manual锛�
-    public AssetInfo(Integer lineNo, Asset record, Boolean isNew, Decimal listPrice, Maintenance_Contract_Asset_Estimate__c mcae) {
+    public AssetInfo(Integer lineNo, Asset record, Boolean isNew, Decimal listPrice, Maintenance_Contract_Asset_Estimate__c mcae,Maintenance_Contract_Estimate__c estimate) {
         this.lineNo = lineNo;
         this.rec = record;
+        this.rec.CurrentContract_End_Date__c = record.CurrentContract_End_Date__c;
+        // this.rec.CurrentContract_End_Date__c = record.IS_Extend_Gurantee__c ? record.Extend_Gurantee_DateTo__c : record.CurrentContract_End_Date__c;
+        // this.ISStandardPricing = record.IS_StandardPricing__c;
+        this.estimate = new Maintenance_Contract_Estimate__c();
+        this.estimate.IS_Reduced_price_approval__c = estimate.IS_Reduced_price_approval__c;
+         // 鎶ヤ环瑙勫垯鏀瑰杽 20230308 start
+        // this.estimate.Contract_Esti_Start_Date__c = estimate.Contract_Esti_Start_Date__c;
+        // this.estimate.renewTen_OFF__c = estimate.renewTen_OFF__c;
+         // 鎶ヤ环瑙勫垯鏀瑰杽 20230308 end
+
+        //   (2022骞�12鏈堜笂绾�)鏁呴殰鍝佸姞璐� start
+        // if (record.Asset_situation__c == '淇悊涓�' && record.Return_Without_Repair__r.Agreed_Date__c!=null) {
+        //     this.Agreed_Date = '涓嶄负绌�';
+        // }
+        // if (record.Asset_situation__c == '淇悊涓�' && record.Return_Without_Repair__r.Agreed_Date__c==null) {
+        //     this.Agreed_Date = '涓虹┖';
+        //     if (assNewRepMap.get(record.id)!=null) {
+        //          this.Repair_Price_Auto = assNewRepMap.get(record.id).Repair_List_Price_formula__c;
+        //     }
+        // }
+        // if (record.Return_Without_Repair__r.Repair_List_Price_formula__c!=null&&record.Asset_situation__c != '淇悊涓�') {
+        //     this.Repair_Price_Auto = record.Return_Without_Repair__r.Repair_List_Price_formula__c;
+        // }
+        if (record.Return_Without_Repair__r.Repair_List_Price_formula__c!=null) {
+            this.Repair_Price_Auto = record.Return_Without_Repair__r.Repair_List_Price_formula__c;
+        }
+        //   (2022骞�12鏈堜笂绾�)鏁呴殰鍝佸姞璐� end
         this.mcae = new Maintenance_Contract_Asset_Estimate__c(
             //                id = mcae.Id,             // 鏈綋銇亜銈夈仾銇勩伄锛� 銈汇儍銉堛仐銇熴倝銆佹柊瑕忔ī闄愩亴銇亸銇с倐銆佹洿鏂般仹銇嶃伨銇欍�傚緦钘ゃ仌銈撱伀纰鸿獚銇椼仧銆併仾銇忋仹銈傘亜銇勩仹銇欍��
             isNew__c = isNew,
@@ -3247,6 +4276,10 @@
             //Maintenance_Price_YearTXT__c = mcae.Maintenance_Price_YearTXT__c,
             Check_Result__c = mcae.Check_Result__c,
             Repair_Price__c = mcae.Repair_Price__c,
+            Repair_Price_pass__c = mcae.Repair_Price_pass__c,
+            // 鎶ヤ环瑙勫垯鏀瑰杽 20230308 start
+            // Blank_period__c = mcae.Blank_period__c,           
+            // 鎶ヤ环瑙勫垯鏀瑰杽 20230308 end
             Comment__c = mcae.Comment__c,
             EquipmentGuaranteeFlgTxt__c = mcae.EquipmentGuaranteeFlgTxt__c,
             Estimate_Cost__c = mcae.Estimate_Cost__c,
@@ -3257,9 +4290,30 @@
             Adjustment_Lower_price__c = mcae.Adjustment_Lower_price__c,
             Asset_Consumption_rate__c = mcae.Asset_Consumption_rate__c
             // LJPH-C9GD34 gzw fix start
-            ,Estimate_List_Price_Page__c = mcae.Estimate_List_Price_Page__c
+            ,Estimate_List_Price_Page__c = mcae.Estimate_List_Price_Page__c,
             // LJPH-C9GD34 gzw fix end
+            //(2022骞�12鏈堜笂绾�)鏁呴殰鍝佸姞璐� 绗笁鏂瑰洖褰�
+            Third_Party_Return__c = mcae.Third_Party_Return__c
             );
+         if ((this.mcae.Repair_Price__c==null&&this.Repair_Price_Auto!=null&&this.rec.Reson_Can_not_Warranty__c!=null&&this.rec.Reson_Can_not_Warranty__c.indexof('寮冧慨')!=-1)||(this.estimate.IS_Reduced_price_approval__c == '鍚�')) {
+            this.mcae.Repair_Price__c = this.Repair_Price_Auto;
+        }
+        if (this.estimate.IS_Reduced_price_approval__c=='鏄�'||this.estimate.IS_Reduced_price_approval__c==null) {
+            if (this.mcae.Repair_Price__c!=null) {
+                this.mcae.Repair_Price_pass__c = this.mcae.Repair_Price__c;
+            }
+        }
+         // 鎶ヤ环瑙勫垯鏀瑰杽 20230308 start
+            // if (this.estimate.Contract_Esti_Start_Date__c!=null  && this.rec.CurrentContract_End_Date__c != null) {
+            //        this.mcae.Blank_period__c = String.valueof(this.rec.CurrentContract_End_Date__c.daysbetween(this.estimate.Contract_Esti_Start_Date__c));
+            // } 
+            // if (this.estimate.Contract_Esti_Start_Date__c==null && this.rec.CurrentContract_End_Date__c != null) {
+            //        this.mcae.Blank_period__c = String.valueof(this.rec.CurrentContract_End_Date__c.daysbetween(system.today()));   
+            // }
+            // if (this.mcae.Blank_period__c!=null&&integer.valueOf(this.mcae.Blank_period__c)<15 ) {
+            //         this.mcae.Blank_period__c = '鏃犵紳缁';
+            // }      
+        // 鎶ヤ环瑙勫垯鏀瑰杽 20230308 end
         this.isManual = false;
         this.rec_checkBox_c = true;
         this.orgPrice = record.Maintenance_Price_Month__c;
@@ -3275,6 +4329,11 @@
         //2021-11-30 fy add LJPH-C8W8FV 缃《 end
     
         //add by rentx 2020-11-12 LJPH-BV93RZ end
+
+        //甯傚満澶氬勾淇� 浠锋牸寮�鍙� start 2023/01/17
+        this.Category = mcae.Product_Manual__r.Category4__c;
+        //甯傚満澶氬勾淇� 浠锋牸寮�鍙� end 2023/01/17
+
         //add by mzy 2021-02-07 start
         //this.NoPartRiskDate = mcae.Product_Manual__r.NoPartRiskDate_F__c;
         //this.proName2 = mcae.Product_Manual__r.Name;
@@ -3296,6 +4355,7 @@
             //Maintenance_Price_YearTXT__c = mcae.Maintenance_Price_YearTXT__c,
             Check_Result__c = mcae.Check_Result__c,
             Repair_Price__c = mcae.Repair_Price__c,
+            Repair_Price_pass__c = mcae.Repair_Price_pass__c,
             Comment__c = mcae.Comment__c,
             EquipmentGuaranteeFlgTxt__c = mcae.EquipmentGuaranteeFlgTxt__c,
             Estimate_Cost__c = mcae.Estimate_Cost__c,
@@ -3308,8 +4368,10 @@
             Contract_Esti_Start_Date__c = mcae.Maintenance_Contract_Estimate__r.Contract_Esti_Start_Date__c
                                           // Contract_Esti_Start_Date__c=mcae.Contract_Esti_Start_Date__c
             // LJPH-C9GD34 gzw fix start
-            ,Estimate_List_Price_Page__c = mcae.Estimate_List_Price_Page__c
+            ,Estimate_List_Price_Page__c = mcae.Estimate_List_Price_Page__c,
             // LJPH-C9GD34 gzw fix end
+            //(2022骞�12鏈堜笂绾�)鏁呴殰鍝佸姞璐� 绗笁鏂瑰洖褰�
+            Third_Party_Return__c = mcae.Third_Party_Return__c
             );
         this.isManual = true;
         this.rec_checkBox_c = false;
@@ -3325,11 +4387,21 @@
         this.ProductModelNoc = mcae.Product_Manual__r.Asset_Model_No__c;
         this.AssetModelNoc = mcae.Asset__r.OwnershipMachine_No__c;
         //2021-11-30 fy add LJPH-C8W8FV 缃《 end
+
+        //甯傚満澶氬勾淇� 浠锋牸寮�鍙� start 2023/01/17
+        this.Category = mcae.Product_Manual__r.Category4__c;
+        //甯傚満澶氬勾淇� 浠锋牸寮�鍙� end 2023/01/17
     }
+    
     // 閬告姙銇曘倢銇亱銇c仧鐢�
     public AssetInfo(Integer lineNo, Asset record) {
         this.lineNo = lineNo;
         this.rec = record;
+        //   (2022骞�12鏈堜笂绾�)鏁呴殰鍝佸姞璐� start
+        if (record.Return_Without_Repair__r.Repair_List_Price_formula__c!=null) {
+            this.Repair_Price_Auto = record.Return_Without_Repair__r.Repair_List_Price_formula__c;
+        }
+        //   (2022骞�12鏈堜笂绾�)鏁呴殰鍝佸姞璐� end
         this.isManual = false;
         this.rec_checkBox_c = false;
         this.orgPrice = record.Maintenance_Price_Month__c;
@@ -3338,6 +4410,34 @@
         this.proSerialName = record.Name;
         this.proSerialNumber = record.SerialNumber;
     }
+    // public AssetInfo(Integer lineNo, Asset record) {
+    //     this.lineNo = lineNo;
+    //     this.rec = record;
+    //     //   (2022骞�12鏈堜笂绾�)鏁呴殰鍝佸姞璐� start
+    //     // if (record.Asset_situation__c == '淇悊涓�' && record.Return_Without_Repair__r.Agreed_Date__c!=null) {
+    //     //     this.Agreed_Date = '涓嶄负绌�';
+    //     // }
+    //     // if (record.Asset_situation__c == '淇悊涓�' && record.Return_Without_Repair__r.Agreed_Date__c==null) {
+    //     //     this.Agreed_Date = '涓虹┖';
+    //     //     if (assNewRepMap.get(record.id)!=null) {
+    //     //          this.Repair_Price_Auto = assNewRepMap.get(record.id).Repair_List_Price_formula__c;
+    //     //     }
+    //     // }
+    //     // if (record.Return_Without_Repair__r.Repair_List_Price_formula__c!=null&&record.Asset_situation__c != '淇悊涓�') {
+    //     //     this.Repair_Price_Auto = record.Return_Without_Repair__r.Repair_List_Price_formula__c;
+    //     // }
+    //     if (record.Return_Without_Repair__r.Repair_List_Price_formula__c!=null) {
+    //         this.Repair_Price_Auto = record.Return_Without_Repair__r.Repair_List_Price_formula__c;
+    //     }
+    //     //   (2022骞�12鏈堜笂绾�)鏁呴殰鍝佸姞璐� end
+    //     this.isManual = false;
+    //     this.rec_checkBox_c = false;
+    //     this.orgPrice = record.Maintenance_Price_Month__c;
+    //     this.orgPrice12 = this.orgPrice * 12;
+    //     this.etGFlg = record.EquipmentGuaranteeFlg__c;
+    //     this.proSerialName = record.Name;
+    //     this.proSerialNumber = record.SerialNumber;
+    // }
     }
     
     WebService static String pageDecide(String strId) {
@@ -3374,6 +4474,7 @@
             rs = 'Undecide澶辫触';
         }
         return rs;
+        
     }
     
     
@@ -3466,7 +4567,50 @@
         //List<lastMContract> listResult = new List<lastMContract>();
         return listResult;
     }
-    
+
+    //URF闄愭鍚堝悓2鏈� LY 20220908 start
+    //瀵归檺娆″悎鍚岃繘琛屾帓搴�
+    public static List<lastMContract> getURFMContract(List<AssetInfo> checkedAssets, Date startDate) {
+        Map<String, lastMContract> urfMContractMap = new Map<String, lastMContract>();
+        Map<String, lastMContract> lastMContractMap1 = new Map<String, lastMContract>();
+        for (AssetInfo ai : checkedAssets) {
+            lastMContract urfMC = new lastMContract(ai.rec.URF_Maintenance_Contract__c, ai.rec.URF_Maintenance_Contract__r.Management_Code__c, ai.rec.URF_Maintenance_Contract__r.Contract_End_Date__c, 1);
+            if (String.isNotBlank(ai.rec.URF_Maintenance_Contract__c)) {
+                if (urfMContractMap.containsKey(ai.rec.URF_Maintenance_Contract__c)) {
+                    urfMContractMap.get(ai.rec.URF_Maintenance_Contract__c).count++;
+                } else {
+                    urfMContractMap.put(ai.rec.URF_Maintenance_Contract__c, urfMC);
+                }
+            }
+        }
+        List<lastMContract> listResulttemp = new List<lastMContract>();
+        List<lastMContract> listResult = new List<lastMContract>();
+        
+        for ( lastMContract ll : urfMContractMap.values()) {
+            listResulttemp.add(ll);
+        }
+        listResulttemp.sort();
+        if (listResulttemp.size() >= 5){
+            for (Integer i = 0; i < listResulttemp.size(); i++) {
+            
+                if (listResulttemp.size() >= i + 1) {
+                    listResult.add(listResulttemp[i]);
+                }
+            }
+        }else {
+            for (Integer i = 0; i < listResulttemp.size(); i++) {
+                if (listResulttemp.size() >= i + 1) {
+                    listResult.add(listResulttemp[i]);
+                }
+            }
+            for (Integer i = listResulttemp.size(); i < 5; i++) {
+                listResult.add(new lastMContract(null, null, null, null));
+            }
+        }
+        
+        return listResult;
+    }
+    //URF闄愭鍚堝悓2鏈� LY 20220908 end   
     
     public static List<Data> getChartData() {
         List<Data> data = new List<Data>();
@@ -3544,4 +4688,4 @@
     // return returnValue;
     // 2021-09-10 tcm 鎺掑簭閫昏緫璋冩暣 end
     }
-    }
\ No newline at end of file
+}
\ No newline at end of file

--
Gitblit v1.9.1