游畅
2023-04-29 cc266a1e4080bb3ecc47ea4a202dd549545111e1
force-app/main/default/classes/SelectAssetEstimateVMController.cls
@@ -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; }
@@ -121,8 +126,9 @@
    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
@@ -131,7 +137,7 @@
    public Decimal Denominator {get; set; }
    public Decimal Accrued {get; set; }
    public String ProductModel{get;set;}
    public String Category{get;set;}
    // public String Category{get;set;}
    public Decimal Consumption_rate_Gurante{get;set;}
@@ -161,7 +167,35 @@
        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
@@ -362,8 +396,10 @@
                      + '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
                      // +'Guarantee_period_for_products__c,'
                      //多年保设备续签计算逻辑调整 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 + '\' ';
@@ -597,6 +633,17 @@
    //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;
@@ -627,12 +674,17 @@
        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 != '不批准'
            //上限合同 LY 20230113 start
            // && this.estimate.Process_Status__c != '申请中'
            //上限合同 LY 20230113 start
            ) {
            return true;
        }
@@ -715,6 +767,7 @@
    public Boolean isSaveOrApproval {get; set;}
    public String OldContractStartDate {get; set;}
    public String OldMaintenancePrice { get; set; }
    public Decimal OldLimitPrice { get; set; }
    
    /**
     * コンストラクタ
@@ -766,9 +819,9 @@
                         , Sales_incidental__c, Consumption_rate_Forecast__c, AgencyHos_Price__c
                         // 申请报价金额 和 相对标准价格范围的折扣率
                         , Request_quotation_Amount__c, Service_discount_Rate__c, ContractPriceType__c
                         //上限合同 20230103 LY start
                         // ,Limit_Price_Amount__c
                         //上限合同 20230103 LY end
                         //上限合同 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
@@ -779,7 +832,10 @@
                         , 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
@@ -792,11 +848,17 @@
                        ,Hospital_Salesdepartment__c
                        ,Send_Email_To_RC__c
                        //故障品加费  2022/12/16 end
                        //贸易合规 you start
                        ,Maintenance_Contract__r.AccDealerBlacklist__c
                        ,Maintenance_Contract__r.Hospital__r.Name
                        ,Maintenance_Contract__r.Dealer__r.Name
                        ,CreatedById
                        //贸易合规 you 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) +
@@ -845,7 +907,7 @@
        isSaveOrApproval = false;
        OldContractStartDate = null;
        OldMaintenancePrice = null;
        OldLimitPrice = null;
        inDicideFlag = false;
    
        isSoft = false;
@@ -903,6 +965,7 @@
            }
            this.targetMaintenanceContractId = ApexPages.currentPage().getParameters().get('mcid');
        }
        // 編集から
        if (String.isBlank(this.targetEstimateId) == false) {
            setThisEstimate();
@@ -980,11 +1043,19 @@
                            , URF_Maintenance_Contract__r.Management_Code__c
                            , URF_Maintenance_Contract__r.Contract_End_Date__c
                            //URF限次合同2期 LY 20220811 end
                            // //多年保设备续签计算逻辑调整 2022/12/14 start
                            // ,Maintenance_Price_Year__c
                            // //多年保设备续签计算逻辑调整 2022/12/14 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_Service__c,Reson_Can_not_Warranty__c,
@@ -1002,7 +1073,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>();
@@ -1015,9 +1103,14 @@
                Asset__r.EquipmentGuaranteeFlg__c,
                Asset__r.CurrentContract_F_asset__r.Estimate_Cost_Month_formula__c,
                Asset__r.CurrentContract_F_asset__r.endDateGurantee_Text__c,
                //多年保设备续签计算逻辑调整 2022/12/14 start
                // Asset__r.CurrentContract_F_asset__r.startDateGurantee__c,
                //多年保设备续签计算逻辑调整 2022/12/14 end
                //多年保设备续签计算逻辑调整 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,
@@ -1097,7 +1190,10 @@
                // 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;
@@ -1133,6 +1229,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,
@@ -1155,8 +1252,8 @@
                                                                LastMContract_Price__c,
                                                                Asset__r.CurrentContract_F_asset__r.Estimate_Cost_Month_formula__c,
                                                                Asset__r.CurrentContract_F_asset__r.endDateGurantee_Text__c,
                                                                //多年保设备续签计算逻辑调整 2022/12/14 start
                                                                // Asset__r.CurrentContract_F_asset__r.startDateGurantee__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,
@@ -1181,6 +1278,9 @@
                                                                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,
@@ -1189,6 +1289,9 @@
                                                                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,
@@ -1198,6 +1301,15 @@
                                                                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
                                                                FROM Maintenance_Contract_Asset_Estimate__c
                                                                WHERE Maintenance_Contract_Estimate__c = :this.targetEstimateId
@@ -1246,6 +1358,7 @@
        // 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;
@@ -1302,7 +1415,9 @@
                //
                //
                //
                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 == '主机') {
@@ -1323,6 +1438,8 @@
               }
             */
        }
            System.debug(LoggingLevel.INFO, '*** checkedAssets: ' + checkedAssets);
        totalPage = (totalRecords / selctRecordNum) + (Math.mod(totalRecords, selctRecordNum) > 0 ? 1 : 0);
    
        system.debug('顺序检测' + checkedAssets);
@@ -1349,7 +1466,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);
@@ -1374,6 +1491,7 @@
        }
        checkedAssets=NumberSort;
        //2021-11-30 fy add LJPH-C8W8FV 置顶 end
    System.debug(LoggingLevel.INFO, '*** checkedAssetsEND: ' + checkedAssets);
    }
    
    //
@@ -1421,6 +1539,14 @@
                            //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
@@ -1477,7 +1603,15 @@
            //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
@@ -1679,6 +1813,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 = [
@@ -1703,6 +1840,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年间修理实绩
@@ -1728,6 +1868,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年修理实绩
@@ -1753,6 +1896,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
        ];
    
@@ -1894,6 +2040,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 = [
@@ -1918,6 +2067,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年间修理实绩
@@ -1943,6 +2095,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年修理实绩
@@ -1968,6 +2123,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年间
@@ -2835,6 +2993,30 @@
        return new PageReference('/' + this.targetEstimateId + '/e?completion=4');
    
    }
    //贸易合规 you start
    public PageReference interceptsend(){
        //String BuchangApprovalManager = this.estimate.BuchangApprovalManager__c;
        //String JingliApprovalManager = this.estimate.JingliApprovalManager__c;
        String fseid = this.estimate.CreatedById;
        String AccDealerBlacklist = this.estimate.Maintenance_Contract__r.AccDealerBlacklist__c;
        String accname = this.estimate.Maintenance_Contract__r.Hospital__r.Name;
        String deaname = this.estimate.Maintenance_Contract__r.Dealer__r.Name;
        //FSE领导
        String[] FSEStr = new String[] {};
        //if(String.isNotBlank(BuchangApprovalManager)){
        //    FSEStr.add(BuchangApprovalManager);
        //}
        //if(String.isNotBlank(JingliApprovalManager)){
        //    FSEStr.add(JingliApprovalManager);
        //}
        FSEStr.add(fseid);
        system.debug('==jinlaile====='+FSEStr);
        Boolean reflag = OpportunityWebService.accSendEmailFW(AccDealerBlacklist,accname,deaname,this.targetEstimateId,'decide_con',FSEStr);
        system.debug('==fawanle====='+FSEStr);
        return null;
    }
    //贸易合规 you end
    
    /**
     * Process用のユーザー情報をセット、新規見積もり時用
@@ -3345,6 +3527,26 @@
                                                                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>();
@@ -3369,7 +3571,8 @@
                                                                      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,
@@ -3391,13 +3594,22 @@
                        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;
@@ -3649,7 +3861,8 @@
    
    // 2021-02-07  gzw add  LJPH-BWY5QB start
    private void setEndUserType(String id) {
        this.contract = [SELECT Id, Name, Status__c, Decided_Estimation__c, Service_Contract_Staff__c,
        //贸易合规 you 20230414 加查询AccDealerBlacklist__c
        this.contract = [SELECT Id, Name,AccDealerBlacklist__c, 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, VM_Contract_Check__c,Open_RenewalQuotation__c
@@ -3662,7 +3875,8 @@
    // 2021-02-07  gzw add  LJPH-BWY5QB end
    
    private void setContractInfo(String id) {
        this.contract = [SELECT Id, Name, Status__c, Decided_Estimation__c, Service_Contract_Staff__c,
        //贸易合规 you 20230414 加查询AccDealerBlacklist__c
        this.contract = [SELECT Id, Name,AccDealerBlacklist__c, Status__c, Decided_Estimation__c, Service_Contract_Staff__c,
                         Estimate_Num__c, Management_Code__c, Hospital__c,
                         //2021-01-18  mzy add  LJPH-BWY5QB   客户上的 维修合同用户类型 为true /false,报价 用户类型为 既有用户 / 新用户
                         // Hospital__r.MaintenanceContractUserType__c,
@@ -3797,21 +4011,41 @@
            // modify by lc 20220607 多年保续签和实绩连动状态对应 start
            Integer noOfDays = today.daysBetween(input.rec.CurrentContract_F_asset__r.endDateGurantee_Text__c);
            Decimal monthCon = (Decimal)noOfDays/365*12;
            //市场多年保修价格开发 DC 2023/02/02 Start  结束日空白期大于6个月 报错提示 新的合同报价开始日期和上一期合同
            Date endDate6Month = input.rec.CurrentContract_F_asset__r.endDateGurantee_Text__c.addMonths(6);
            Date cotractEndDay = input.rec.CurrentContract_F__r.endDateGurantee__c;
            System.debug(LoggingLevel.INFO, '*** endDate6Month: ' + endDate6Month);
            System.debug(LoggingLevel.INFO, '*** cotractEndDay: ' + cotractEndDay);
            System.debug(LoggingLevel.INFO, '*** this.estimate.Contract_Esti_Start_Date__c: ' + this.estimate.Contract_Esti_Start_Date__c);
            if(this.estimate.Contract_Esti_Start_Date__c >endDate6Month && cotractEndDay < this.estimate.Contract_Esti_Start_Date__c){
                System.debug(LoggingLevel.INFO, '*** meet error: ' );
                input.rec.Name.addError(input.rec.Name + '(' + input.rec.SerialNumber + ') -- 市场多年保结束已超过6个月,由于空白期过长,请先联系服务管理部评估。');
                rtn = false;
            }
            //市场多年保修价格开发 DC 2023/02/02 end
            // 可开始报价的月数限制
            //变更多年保续签开始日 thh 20220315 start
            //if (input.rec.CurrentContract_F__r.Gurantee_Estimate_startDate__c > Date.today()) {
            // gzw 20220630 开通续签报价权限后,超过6个月也可以续签
            // 续签情况 ① 上期合同 Open_RenewalQuotation__c & 6个月以内  ② VM_Contract_Check__c Open_RenewalQuotation__c 2个都打钩
            // ① 2个开关都打开 ②VM_Contract_Check__c打开 小于6个月
            if (!((this.contract.Open_RenewalQuotation__c && input.rec.CurrentContract_F__r.VM_Contract_Check__c) || (input.rec.CurrentContract_F__r.VM_Contract_Check__c && monthCon < 6))) {
                if(monthCon < 6){
                    input.rec.Name.addError(input.rec.Name + '(' + input.rec.SerialNumber + ') -- 可以加入服务合同,加入价格请联系服务管理部。');
                }else{
                    input.rec.Name.addError(input.rec.Name + '(' + input.rec.SerialNumber + ') -- 没有续签报价权限,或者还没到续签时间。');
                }
                //input.rec.Name.addError(input.rec.Name + '(' + input.rec.SerialNumber + ') -- 没有续签报价权限,或者还没到续签时间。');
                rtn = false;
            }
            // 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;
@@ -3968,6 +4202,7 @@
    public class AssetInfo {
    // 新合同备品确保提供 当前标记
    public Boolean etGFlg {get; 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;}
@@ -3978,6 +4213,7 @@
    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
@@ -3998,7 +4234,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) {
@@ -4032,8 +4270,16 @@
    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 = '不为空';
@@ -4062,6 +4308,9 @@
            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,
@@ -4085,6 +4334,17 @@
                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;
@@ -4100,6 +4360,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;
@@ -4153,6 +4418,10 @@
        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
    }
    
    // 選択されなかった用
@@ -4160,11 +4429,6 @@
        this.lineNo = lineNo;
        this.rec = record;
        //   (2022年12月上线)故障品加费 start
        // if (record.Return_Without_Repair__r.Agreed_Date__c!=null) {
        //     this.Agreed_Date = '不为空';
        // }else{
        //     this.Agreed_Date = '为空';
        // }
        if (record.Return_Without_Repair__r.Repair_List_Price_formula__c!=null) {
            this.Repair_Price_Auto = record.Return_Without_Repair__r.Repair_List_Price_formula__c;
        }
@@ -4177,7 +4441,7 @@
        this.proSerialName = record.Name;
        this.proSerialNumber = record.SerialNumber;
    }
    // public AssetInfo(Integer lineNo, Asset record, Map<String,repair__c> assNewRepMap) {
    // public AssetInfo(Integer lineNo, Asset record) {
    //     this.lineNo = lineNo;
    //     this.rec = record;
    //     //   (2022年12月上线)故障品加费 start