Thhto
2022-11-17 ea6a4eec81a6a74e214aefc5971d701242c3e7d3
force-app/main/default/classes/NewQuoteEntryController.cls
@@ -11,8 +11,12 @@
  //public Id qlistId { get; set; }
  //lastbuy  2022/2/9 fy start
  public Boolean filg { get; set; }
  public Integer flglastbuy { get; set; }
  public String errorProductmodel { get; set; }
  //lastbuy  2022/2/9 fy end
  //SWAG-CC6AFQ【委托】又有询价跳过了报价计算 fy start
  public Boolean SkipQuotefilg { get; set; }
  //SWAG-CC6AFQ【委托】又有询价跳过了报价计算 fy end
  public String excel_text { get; set; }
  public Integer select_index { get; set; }                       // excelImport専用ですが、jsにて制御することになるので、TODO katsu 削除予定
  public String Product_text { get; set; }
@@ -125,7 +129,9 @@
  }
  public PageReference init() {
    //SWAG-CC6AFQ【委托】又有询价跳过了报价计算 fy start
    SkipQuotefilg = false;
    //SWAG-CC6AFQ【委托】又有询价跳过了报价计算 fy end
    system.debug('============start init==============');
    boolean quoteflg = true;
    WinOrDecideAlert = false;
@@ -155,6 +161,7 @@
        }
      } else {
        quoId = System.currentPageReference().getParameters().get('copyid');
        system.debug('copyid++++++++++++'+quoId);
        if (quoId != null) {
          // コピーのデータが後で作成する
        } else {
@@ -213,6 +220,12 @@
               //【是否需要价格申请】 thh start
               If_Need_PriceApply__c
               //【是否需要价格申请】 thh end
               // Celon询价修改 2022-04-24 ssm start
               ,CelonOpportunity__c
               // Celon询价修改 2022-04-24 ssm end
               // lastbuy判断变更用户询价 start
               , If_Account_Change__c
               // lastbuy判断变更用户询价 end
               FROM Opportunity Where Id = :oppId];
    // 多年保修 start
    trade = '外貿';
@@ -355,8 +368,8 @@
      }
    } else {
      //添加行
      List<Quote> quoList =
        [ SELECT Id, Name, Cancel_Decide__c, CreatedDate, PriceRefreshDate__c, Quote_Print_Date__c,
      List<Quote> quoList =//SWAG-CKDATG 【委托】【OBSAP-报价委托】报价委托项目改善1 fy start QuotationChange__c,MainEngineWithoutMonitor__c,Interdepartmental__c,
        [ SELECT Id, Name, Cancel_Decide__c, CreatedDate, PriceRefreshDate__c, Quote_Print_Date__c,QuotationChange__c,MainEngineWithoutMonitor__c,Interdepartmental__c,
          Dealer_Final_Price__c, TotalPrice__c, Estimation_List_Price__c, QuoteNumber,
          QuoteToName, Quote_Expiration_Date__c, Quote_Comment__c, Stocking_Price__c, Unit_Price__c,
          Offer_Amount__c, TOTAL__c, Discount__c, Pricing__c, Preferential_Trading_Price__c, Contract__c,
@@ -405,6 +418,8 @@
         ,PricebookEntry.Product2.Intra_Trade_Foreign_RMB__c
         //NoDiscount 金额(USD)
         ,PricebookEntry.Product2.NoDiscount_Foreign__c 
         //fy 预留产品标识
         ,PricebookEntry.Product2.LastbuyProductFLG__c
         ,Quote.Opportunity.Trade__c 
         //外贸多年保 2021/01/04 精琢技术 wql end
@@ -414,12 +429,17 @@
         From QuoteLineItem where Quoteid = :quoId Order by Item_Order__c, Id];
      String copyQuoId = System.currentPageReference().getParameters().get('copyid');
      system.debug('copyid2++++++++++++'+copyQuoId);
      CheckItem = items;
      if (copyQuoId == null) {
      } else {
        // copyの場合、quoIdをnullに戻す
        system.debug('id空6:');
        quoId = null;
        //SWAG-CC6AFQ【委托】又有询价跳过了报价计算 fy start
        SkipQuotefilg = true;
        //SWAG-CC6AFQ【委托】又有询价跳过了报价计算 fy end
      }
      if (quoList.size() > 0) {
        //添加行
@@ -428,6 +448,7 @@
        }
        if (copyQuoId == null) {
          quo = quoList[0];
          quo.QuoteName__c = quo.Name;
          // 多年保修 start
          quoteGurantee_Period = quo.Gurantee_Period__c;
@@ -799,10 +820,13 @@
    // CHAN-AVG3PW 询价报价画面规则变更
    Datetime cDate = quo.CreatedDate;
    over3month = cDate != null && cDate.date().addMonths(3) < Date.today();
//SWAG-CKDATG 【委托】【OBSAP-报价委托】报价委托项目改善1 fy start
quo.Offer_Amount__c = true;
quo.TOTAL__c = true;
quo.Preferential_Gurantee_Period__c = true;
//SWAG-CKDATG 【委托】【OBSAP-报价委托】报价委托项目改善1 fy end
    return null;
  }
  //Search Events============================================================
  // TODO ManualEntryと同様、jsにて解決できる、ここでwebserviceだけを実装、今後 by katsu
@@ -900,6 +924,8 @@
                               //外贸多年保 2021/01/04 精琢技术 wql start
                               //维修合同报价(USD)
                               ,Repair_Contract_USD__c
                               //fy 预留产品标识
                               ,LastbuyProductFLG__c
                               //计提金额(不含税,USD)
                               ,Intra_Trade_Foreign_RMB__c
                               //NoDiscount 金额(USD)
@@ -1238,6 +1264,8 @@
    for (QELine t : tmpactivities) {
      if (i == j) {
        Map<String, Product2> mpProduct2 = new Map<String, Product2>();                     // keyがProductCodeです。
        // Celon询价修改 20220513 ssm start
        String celon_type = String.isNotBlank(oppInfo.CelonOpportunity) ? oppInfo.CelonOpportunity : null;
        List<Product2> items = [select Id, Name, ProductCode,
                                Foreign_Trade_Cost_US__c, Foreign_Trade_List_US__c, Intra_Trade_Cost_RMB__c, Intra_Trade_List_RMB__c,
                                //CHAN-BKU3XH 检查是否存在不是同一个供销商名称 精琢技术 2020/02/17 Start 增加字段
@@ -1270,6 +1298,9 @@
                              //SFDC停止预警 lt 20211009 end
                                FROM Product2 Where ProductCode In :codelist
                                // Celon询价
                                And Celon_Product__c = :celon_type
                                // Celon询价
                                And Manual_Entry__c = false];
        for (Product2 prd : items) {
          system.debug('prd.ProductCode:::::' + prd.ProductCode);
@@ -1526,6 +1557,22 @@
      errorMessagechack = null;
      Savepoint sp = Database.setSavepoint();
      try {
        // 2022-04-19 营业部门需求 没有行项目不能保存 ssm start
        if (activities != null && activities.size() > 0) {
          QELine line1 = activities[0];
          // System.debug('Save() line1: ' + line1);
          // System.debug('line1 != null: ' + (line1 != null));
          // System.debug('line1.pageObject.PricebookEntryId != null: ' + (line1.pageObject.PricebookEntryId != null));
          // System.debug('isNotBlank(line1.pageObject.PricebookEntryId): ' + (String.isNotBlank(line1.pageObject.PricebookEntryId)));
          // System.debug('Save() line1 flag: ' + (!(line1 != null && String.isNotBlank(line1.pageObject.PricebookEntryId))));
          if (!(line1 != null && String.isNotBlank(line1.pageObject.PricebookEntryId))) {
            errorflg = true;
            errorMessage = '不允许保存空的报价单,请选择产品';
            return null;
          }
        }
        // 2022-04-19 ssm end
        // CHAN-AVG3PW 询价报价画面规则变更
        // 报价创建日超过三个月时,点保存时强制更新
        // CHAN-AZG864 不管在不在报价有效期内,CFDA不可销售的时候,都是报错的,其中不可销售产品显示红字,不应该保存。
@@ -1539,7 +1586,6 @@
          errormessage = '请更新不可销售的产品。';
          return null;
        }
        System.debug('checkSFDAStatus1 finished at: ' + System.currentTimeMillis());
        //データチェック
@@ -1721,6 +1767,22 @@
      // 报价创建日超过三个月时,点保存时强制更新
      // CHAN-AZG864 不管在不在报价有效期内,CFDA不可销售的时候,都是报错的,其中不可销售产品显示红字,不应该保存。
      // 2022-04-19 XYOU-CDLCMM 没有行项目不能保存 ssm start
      if (activities != null && activities.size() > 0) {
        QELine line1 = activities[0];
        // System.debug('Save() line1: ' + line1);
        // System.debug('line1 != null: ' + (line1 != null));
        // System.debug('line1.pageObject.PricebookEntryId != null: ' + (line1.pageObject.PricebookEntryId != null));
        // System.debug('isNotBlank(line1.pageObject.PricebookEntryId): ' + (String.isNotBlank(line1.pageObject.PricebookEntryId)));
        // System.debug('Save() line1 flag: ' + (!(line1 != null && String.isNotBlank(line1.pageObject.PricebookEntryId))));
        if (!(line1 != null && String.isNotBlank(line1.pageObject.PricebookEntryId))) {
          errorflg = true;
          errorMessage = '不允许保存空的报价单,请选择产品';
          return null;
        }
      }
      // 2022-04-19 ssm end
      if (WinOrDecideAlert && (!productStatusUpdated)) {
        errorflg = true;
        errorMessage = '产品状态发生变化,请更新';
@@ -1778,10 +1840,23 @@
      errorflg = false;
      errormessage = null;
      //20220214 fy lastbuy start 
      if(!ReservedProductVerification()){
        errorflg = true;
        errormessage =  '产品数量不可超过产品预留数量' ;
        return null;
      if (!oppInfo.is_changed_opp) {
        if(!ReservedProductVerification()){
          system.debug('flglastbuy++++'+flglastbuy);
          if(flglastbuy==1){
            errorflg = true;
            errormessage =  '预留产品表中没有该询价,请通过本部窗口联系营业管理课' ;
            return null;
          }else if(flglastbuy==2){
            errorflg = true;
            errormessage =  errorProductmodel+'产品数量不可超过产品预留数量' ;
            return null;
          }else if(flglastbuy==3){
            errorflg = true;
            errormessage =  '预留产品'+errorProductmodel+'未录入预留产品表';
            return null;
          }
        }
      }
      //20220214 fy lastbuy end
      // 2022-01-12 ssm 报价计算check
@@ -1808,60 +1883,77 @@
      if (dataCheck() == false) {
        return null;
      }
      // 2022-04-06 SWAG-CC6AFQ【委托】又有询价跳过了报价计算 ssm start
      // 判断条件修改
      // 1.如果保存方法返回false,return
      // 2.如果保存通过但创建了新报价,return
      // 3.继续做decide
      if (dataEntry() == false) {
        return null;
      } else {
        //引合に見積決定をオン
        if (oppId == null) {
          system.debug('Error is Opportunityid null!!!');
        } else {
          List<Opportunity> opps = [Select Id, Estimation_Decision__c From Opportunity Where Id = : oppId];
          if (opps.size() > 0) {
            opps[0].Estimation_Decision__c = true;
            /*↓↓↓見積同期↓↓↓2012/11/28 未使用
            opps[0].SyncedQuoteId = quoId;
            ↑↑↑    ↑↑↑*/
            ControllerUtil.updOpp(opps[0]);
          }
          errorflg = true;
          errorMessage = System.Label.Message_002;
          // cic 134906 start
          Quote q = [select Id from Quote where Id = :quoId];
          q.Quote_Decision_Date__c = date.Today();
          update q;
          // cic 134906 end
          QuoteDecision = true;
          enableContract = true;
          //--Savebutton
          Save_button = true;
          //--Decisionbutton判定
          if (verified == true) {
            Decision_button = false;
          } else if (QuoteCorrect == false) {
            Decision_button = true;
          } else if (QuoteDecision == true) {
            Decision_button = true;
          } else {
            Decision_button = false;
          }
          //--SAPButton
          if (QuoteDecision == false) {
            sap_button = true;
          } else if (specialAuthority == false) {
            sap_button = true;
          } else {
            sap_button = false;
          }
          //--決定ボタン使えないようにする
          Decision_button = true;
          pageArrange();
        }
      }
      //SWAG-CC6AFQ【委托】又有询价跳过了报价计算 fy start
      if(SkipQuotefilg){
        errorflg = true;
        errormessage =  '产品配置或者经销商信息发生变化,已经生成新的报价单,请重新操作报价计算';
        quo.IsQuoteTrial__c = false;
        return null;
      }
      //SWAG-CC6AFQ【委托】又有询价跳过了报价计算 fy end
      //引合に見積決定をオン
      if (oppId == null) {
        system.debug('Error is Opportunityid null!!!');
      } else {
        List<Opportunity> opps = [Select Id, Estimation_Decision__c From Opportunity Where Id = : oppId];
        if (opps.size() > 0) {
          opps[0].Estimation_Decision__c = true;
          /*↓↓↓見積同期↓↓↓2012/11/28 未使用
          opps[0].SyncedQuoteId = quoId;
          ↑↑↑    ↑↑↑*/
          // SWAG-CER5R4 优化保存速度 start
          // ControllerUtil.updOpp(opps[0]);
          StaticParameter.EscapeOppandStaTrigger = true;
          update opps[0];
          StaticParameter.EscapeOppandStaTrigger = false;
          // SWAG-CER5R4 优化保存速度 end
        }
        errorflg = true;
        errorMessage = System.Label.Message_002;
        // cic 134906 start
        Quote q = [select Id from Quote where Id = :quoId];
        q.Quote_Decision_Date__c = date.Today();
        update q;
        // cic 134906 end
        QuoteDecision = true;
        enableContract = true;
        //--Savebutton
        Save_button = true;
        //--Decisionbutton判定
        if (verified == true) {
          Decision_button = false;
        } else if (QuoteCorrect == false) {
          Decision_button = true;
        } else if (QuoteDecision == true) {
          Decision_button = true;
        } else {
          Decision_button = false;
        }
        //--SAPButton
        if (QuoteDecision == false) {
          sap_button = true;
        } else if (specialAuthority == false) {
          sap_button = true;
        } else {
          sap_button = false;
        }
        //--決定ボタン使えないようにする
        Decision_button = true;
        pageArrange();
      }
      // 2022-04-06 SWAG-CC6AFQ【委托】又有询价跳过了报价计算 ssm end
    } catch (DmlException de) {
      Database.rollback(sp);
      errorflg = true;
@@ -1957,7 +2049,12 @@
              if (quos[0].Quote_Date__c == null) {
                quos[0].Quote_Date__c = date.Today();
                opps[0].Estimation_Proposal_Date__c = date.Today();
                ControllerUtil.updOpp(opps[0]);
                // SWAG-CER5R4 优化保存速度 start
                // ControllerUtil.updOpp(opps[0]);
                StaticParameter.EscapeOppandStaTrigger = true;
                update opps[0];
                StaticParameter.EscapeOppandStaTrigger = false;
                // SWAG-CER5R4 优化保存速度 end
              }
              quos[0].Quote_Print_Date__c = date.Today();
              ControllerUtil.updQuote(quos[0]);
@@ -2082,7 +2179,9 @@
      // ここを修正したら、NFM007.triggerも要確認
      prd2LatestValMap = new Map<Id, Product2>();
      integer cntPrd2 = 0;
      for (Product2 prd2 : [Select Id, Estimation_Entry_Possibility__c, SFDA_Status__c, Packing_list_manual__c
      for (Product2 prd2 : [Select Id, Estimation_Entry_Possibility__c, SFDA_Status__c, Packing_list_manual__c,
      //fy 预留产品标识
      LastbuyProductFLG__c
                            From Product2 Where Id IN :product2Ids]) {
        cntPrd2 = cntPrd2   +   1;
        if (prd2.Estimation_Entry_Possibility__c != '○') {
@@ -2104,7 +2203,11 @@
      }
    }
    //SWAG-CER5R4 【委托】报价合同金额增加限制 fy start
    if(ContractAmountLimitJudge()){
      return false;
    }
    //SWAG-CER5R4 【委托】报价合同金额增加限制 fy end
    if (error == true && WinOrDecideAlert == false) {
      PageArrange();
      errorflg = true;
@@ -2172,7 +2275,13 @@
    Boolean error = false;
    errorflg = false;
    errormessage = null;
    //obsap 最终用户合同金额验证 fy start
    if (quo.Dealer_Final_Price_Page__c == null) {
      quo.Dealer_Final_Price__c.addError(System.Label.Error_Message3);
      error = true;
      errormessage = System.Label.Error_Message3;
    }
    //obsap 最终用户合同金额验证 fy end
    if (checkAgentsDeleteFlag() == false) {
      return false;
    }
@@ -2535,8 +2644,57 @@
    return false;
  }
  //SWAG-C9JCS8 【委托】【紧急】询价GZ-SP-GD0757135报价单问题 fy end
  //SWAG-CER5R4 【委托】报价合同金额增加限制 fy start
  private boolean ContractAmountLimitJudge(){
    system.debug('oppInfo.Sales_Root+++='+oppInfo.Sales_Root);
    if(oppInfo.Sales_Root =='OCM直接销售'){
      return false;
    }
    Boolean error = false;
    // List<QuoteLineItem> act = new List<QuoteLineItem>();
    // List<QuoteLineItem> act2 = new List<QuoteLineItem>();
    Double AccrualTotal=0;
    Double sumContractAmount =0;
    for(QELine aaa :activities){
      // 2022-06-14 紧急修复 ssm
      if (String.isBlank(aaa.Asset_Model)) {
        continue;
      }
      if(aaa.pageObject.PricebookEntry.Product2Id!=null){
        if(aaa.GuranteePrice==null){
          aaa.GuranteePrice=0;
        }
        AccrualTotal += aaa.pageObject.Quantity__c*aaa.GuranteePrice;
        // act.add(aaa.pageObject);
      }
    }
    // act2=act.deepClone();
    // Double AccrualTotal=0;
    // Double sumContractAmount =0;
    // for(QuoteLineItem pspsc :act2){
    //   AccrualTotal += pspsc.Quantity__c*pspsc.GuranteePrice__c;
    // }
    if(quo.MultiYearWarrantyTotalPrice__c==null){
      quo.MultiYearWarrantyTotalPrice__c=0;
    }
    sumContractAmount = AccrualTotal+quo.MultiYearWarrantyTotalPrice__c;
    if(quo.OCM_Agent1_Price_Page__c<=sumContractAmount){
      error = true;
      errorflg = true;
      errormessage = '预测金额为负数,请正确填写合同金额。';
    }
    if(quo.multiYearWarranty__c){
      if(quo.OCM_Agent1_Price_Page__c<=0){
        error = true;
        errorflg = true;
        errormessage = '预测金额为负数,请正确填写合同金额。';
      }
    }
    return error;
  }
  //SWAG-CER5R4 【委托】报价合同金额增加限制 fy end
  public boolean dataEntry() {
    system.debug('activities++++----****3'+activities);
    //SWAG-C9JCS8 【委托】【紧急】询价GZ-SP-GD0757135报价单问题 fy start
    // Boolean ifdecide=false;
    // List<Opportunity> oppsde = [Select Id, Estimation_Decision__c From Opportunity Where Id = : oppId];
@@ -2560,11 +2718,11 @@
        error = true;
        errormessage = System.Label.Error_Message3;
      }
      if (quo.Dealer_Final_Price_Page__c == null) {
        quo.Dealer_Final_Price__c.addError(System.Label.Error_Message3);
        error = true;
        errormessage = System.Label.Error_Message3;
      }
      // if (quo.Dealer_Final_Price_Page__c == null) {
      //   quo.Dealer_Final_Price__c.addError(System.Label.Error_Message3);
      //   error = true;
      //   errormessage = System.Label.Error_Message3;
      // }
      if (qb.Quote_Adjust_Calculate == null) {
        quo.Quote_Adjust_Calculate__c.addError(System.Label.Error_Message3);
        error = true;
@@ -2581,6 +2739,7 @@
        errormessage = System.Label.Error_Message3;
      }
      //decimal temSalesAmount1 = 0; // 2018/09/28 CHAN-B4YAB8 经销商小计合计 end
      system.debug('activities++++----****2'+activities);
      for (QELine a : activities) {
        if ((a.Asset_Model != null) && (a.Asset_Model != '')) {
          if (a.PageObject.Quantity__c == null || a.PageObject.Quantity__c == 0) {
@@ -2646,10 +2805,10 @@
      }
      if (DisCalculation >= 1000 || DisCalculation <= -1000) {
        error = true;
        errormessage = System.Label.Error_Message38;
      }
      // if (DisCalculation >= 1000 || DisCalculation <= -1000) {
      //   error = true;
      //   errormessage = System.Label.Error_Message38;
      // }
      if (qb.SalesCalculation1 >= 1000 || qb.SalesCalculation1 <= -1000) {
        error = true;
        errormessage = System.Label.Error_Message38;
@@ -2692,22 +2851,43 @@
      oppNo = oppNo.substring(oppNo.length() - 2);
      Quote q = New Quote();
      System.debug('quoId: ' + quoId);
      System.debug('changedAfterPrint: ' + changedAfterPrint);
      if (changedAfterPrint) {
        system.debug('id空1:');
        quoId = null;
        //SWAG-CC6AFQ【委托】又有询价跳过了报价计算 fy start
        SkipQuotefilg = true;
        //SWAG-CC6AFQ【委托】又有询价跳过了报价计算 fy end
      }
      // false伝票から新規作成
      System.debug('changedAfterBid: ' + changedAfterBid);
      if (changedAfterBid) {
        system.debug('id空2:');
        quoId = null;
        //SWAG-CC6AFQ【委托】又有询价跳过了报价计算 fy start
        SkipQuotefilg = true;
        //SWAG-CC6AFQ【委托】又有询价跳过了报价计算 fy end
      }
      // CHAN-AVG3PW 询价报价画面规则变更
      System.debug('newQuoteFlag: ' + newQuoteFlag);
      if (newQuoteFlag) {
        system.debug('id空3:');
        quoId = null;
        //SWAG-CC6AFQ【委托】又有询价跳过了报价计算 fy start
        SkipQuotefilg = true;
        //SWAG-CC6AFQ【委托】又有询价跳过了报价计算 fy end
      }
      // 多年保修 start
      //报价试算 增加经销商前后对比 精琢技术 wql 20210508 start
      System.debug('quoteGurantee_Period: ' + quoteGurantee_Period);
      System.debug('quo.Gurantee_Period__c: ' + quo.Gurantee_Period__c);
      System.debug('quotemultiYearWarranty: ' + quotemultiYearWarranty);
      System.debug('quo.multiYearWarranty__c: ' + quo.multiYearWarranty__c);
      System.debug('agency1Name: ' + agency1Name);
      System.debug('quo.Agency1__c: ' + quo.Agency1__c);
      System.debug('agency2Name: ' + agency2Name);
      System.debug('quo.Agency2__c: ' + quo.Agency2__c);
      if ((quoteGurantee_Period != null &&
          !quoteGurantee_Period.equals(quo.Gurantee_Period__c))
          ||
@@ -2718,7 +2898,11 @@
          ||
          (agency2Name !=null &&!agency2Name.equals(quo.Agency2__c))
        ) {
          system.debug('id空8:');
        quoId = null;
        //SWAG-CC6AFQ【委托】又有询价跳过了报价计算 fy start
        SkipQuotefilg = true;
        //SWAG-CC6AFQ【委托】又有询价跳过了报价计算 fy end
      }
      agency1Name = quo.Agency1__c;
      agency2Name = quo.Agency2__c;
@@ -2741,8 +2925,8 @@
        }
      } else {
        List<Quote> qs = New List<Quote>();
        qs = [select Id, OpportunityId, CreatedDate, Pricebook2Id, Name, Estimation_List_Price__c, Dealer_Final_Price__c,
        List<Quote> qs = New List<Quote>();//SWAG-CKDATG 【委托】【OBSAP-报价委托】报价委托项目改善1 fy start QuotationChange__c,MainEngineWithoutMonitor__c,Interdepartmental__c,
        qs = [select Id, OpportunityId, CreatedDate, Pricebook2Id, Name, Estimation_List_Price__c, Dealer_Final_Price__c,QuotationChange__c,MainEngineWithoutMonitor__c,Interdepartmental__c,
              Stocking_Price__c, Discount_Amount__c, Discount_Amount_Calculate__c, Quote_Adjust_Amount__c, Quote_Adjust_Calculate__c,
              Agency1__c, OCM_Agent1_Price__c, Agency1_Profit__c, Agency1_Profit_Rate__c, Quote_No__c,
              Agency2__c, Agent1_Agent2_Price__c, Agency2_Profit__c, Agency2_Profit_Rate__c,
@@ -2782,6 +2966,7 @@
      // 20150302 jo 見積の主机安装地点を設定
      List<String> pIds = new List<String>();
      system.debug('activities++++----****1'+activities);
      for (QELine s : activities) {
        if (String.isBlank(s.PageObject.Id__c) == false) {
          pIds.add(s.PageObject.Id__c);
@@ -2827,18 +3012,29 @@
      q.Quote_Comment__c = quo.Quote_Comment__c;
      q.Installation_location__c = quo.Installation_location__c;
      //SWAG-CKDATG 【委托】【OBSAP-报价委托】报价委托项目改善1 fy start
      q.QuotationChange__c = quo.QuotationChange__c;
      q.MainEngineWithoutMonitor__c = quo.MainEngineWithoutMonitor__c;
      q.Interdepartmental__c = quo.Interdepartmental__c;
      //SWAG-CKDATG 【委托】【OBSAP-报价委托】报价委托项目改善1 fy end
      /*
      if (hasType3Machine) {
          q.Installation_location__c = '';
      }
      */
      System.debug('start save quote at: ' + System.currentTimeMillis());
      System.debug('q.QuotationChange__c+++'+q.QuotationChange__c);
      System.debug('quo.QuotationChange__c++' + quo.QuotationChange__c);
      System.debug('quo.MainEngineWithoutMonitor__c++' + quo.MainEngineWithoutMonitor__c);
      if (quoId == null) {
        insert q;
        quo.Quote_No__c = q.Quote_No__c;
      } else {
        update q;
      }
      System.debug('q.QuotationChange__c2+++'+q.QuotationChange__c);
      System.debug('quo.QuotationChange__c2++' + quo.QuotationChange__c);
      System.debug('quo.MainEngineWithoutMonitor__c2++' + quo.MainEngineWithoutMonitor__c);
      System.debug('finished save quote at: ' + System.currentTimeMillis());
      system.debug('○○○○○Save1○○○○○');
@@ -2858,6 +3054,7 @@
      //Sap送信,Printに合わせて1~
      Integer i = 1;
      if (activities.size() > 0) {
        system.debug('activities++++----****'+activities);
        for (QELine s : activities) {
          if (s.Asset_Model != null && s.Asset_Model != '') {
            if (s.pageObject.PricebookEntryId != null) {
@@ -2903,6 +3100,7 @@
          }
        }
        System.debug('start save quote lines at: ' + System.currentTimeMillis());
        system.debug('qlist+++---+++'+qlist);
        insert qlist;
        System.debug('finished save quote lines at: ' + System.currentTimeMillis());
@@ -2920,6 +3118,9 @@
      os = [select Id, Estimation_List_Price__c, Dealer_Final_Price__c, Estimation_List_Price_Without_Tax__c,
            Agency1__c, OCM_Agent1_Price__c, Agency1_Profit__c, Agency1_Profit_Rate__c, Stocking_Price__c,
            Agency2__c, Agent1_Agent2_Price__c, Agency2_Profit__c, Agency2_Profit_Rate__c, Quote_Update_Sum__c , Hospital__c,Is_Corrosion__c 
            // lt 20221008 SWAG-CHL5XA【FY23询价改善】-统计主机台数 start
            ,StageName ,OlyNumberHosts__c
            // lt 20221008 SWAG-CHL5XA【FY23询价改善】-统计主机台数 end
            From Opportunity Where Id = :oppid];
      if (os.size() > 0) {
        o = os[0];
@@ -2939,7 +3140,7 @@
        o.Stocking_Price__c = quo.Stocking_Price__c;
        o.Estimation_No__c = quo.Quote_No__c;
        o.Estimation_No__c = q.Quote_No__c; // quo.Quote_No__c;
        //o.Estimation_Name__c = quo.Name;
        o.Estimation_Name__c = q.Name;
        o.Estimation_Id__c = q.Id;
@@ -2955,6 +3156,40 @@
        o.quoteSavedDate__c = Date.today();
        // 多年保修 end
        // lt 20221008 SWAG-CHL5XA【FY23询价改善】-统计主机台数 start
        System.debug('lt123询价状态(阶段): ' + o.StageName);
        System.debug('lt123activities: ' + activities);
        o.OlyNumberHosts__c = 0;
        System.debug('lt123主机数: ' + o.OlyNumberHosts__c);
        List<String> oppIds = New List<String>();
        List<String> product2Ids = New List<String>();
        Map<String,Decimal> product2IdsMap = new Map<String,Decimal>();
        if (activities.size() > 0) {
          for (QELine a : activities) {
            if (String.isBlank(a.PageObject.Id__c) == false) {
              product2Ids.add(a.PageObject.Id__c);
              product2IdsMap.put(a.PageObject.Id__c,a.PageObject.Quantity__c);
            }
          }
          for (Product2 prod : [Select Id,ProductClass__c
                                From Product2 Where Id IN :product2Ids]) {
            System.debug('lt123产品市场类别: ' + prod.ProductClass__c);
                if(o.StageName == '引合' || o.StageName == '注残' || o.StageName == '出荷' || o.StageName == '完了'){
                  if(prod.ProductClass__c == '主机'){
                    if(product2IdsMap.containsKey(prod.Id)){
                      o.OlyNumberHosts__c += product2IdsMap.get(prod.Id);
                      oppIds.add(o.Id);
                      ControllerUtil.UpdateBiddingFlag(oppIds);
                    }
                  }else{
                    o.OlyNumberHosts__c += 0;
                  }
                }
          }
        }
        // lt 20221008 SWAG-CHL5XA【FY23询价改善】-统计主机台数 end
        if (o.Quote_Update_Sum__c == null) {
          o.Quote_Update_Sum__c = 1;
@@ -2962,7 +3197,11 @@
          o.Quote_Update_Sum__c = o.Quote_Update_Sum__c + 1;
        }
        System.debug('start 1st save Opportunity at: ' + System.currentTimeMillis());
        ControllerUtil.updOpp(o);
        // SWAG-CER5R4 优化保存速度 start
        // ControllerUtil.updOpp(o);
        StaticParameter.EscapeOppandStaTrigger = true;
        update o;
        // SWAG-CER5R4 优化保存速度 end
        System.debug('finished 1st save Opportunity at: ' + System.currentTimeMillis());
        system.debug('○○○○○Save3○○○○○');
@@ -2972,7 +3211,10 @@
        //価格、単位、小計、OCM売上予測金額(税抜)、価格表
        List<OpportunityLineItem> ols = New List<OpportunityLineItem>();
        OpportunityLineItem ol = New OpportunityLineItem();
        ols = [select Id from OpportunityLineItem Where OpportunityId = :oppid];
        // lt 20221008 SWAG-CHL5XA【FY23询价改善】-统计主机台数 end
        ols = [select Id, Quantity from OpportunityLineItem Where OpportunityId = :oppid];  //update
        System.debug('lt123询价产品: ' + ols);
        // lt 20221008 SWAG-CHL5XA【FY23询价改善】-统计主机台数 end
        if (ols.size() > 0) {
          //delete
          ControllerUtil.delOppLine(ols);
@@ -2986,6 +3228,7 @@
            if (s.Asset_Model != null && s.Asset_Model != '') {
              if (s.PageObject.PricebookEntryId != null) {
                ol = New OpportunityLineItem();
                System.debug('lt123询价产品数量: ' + ol.Quantity);   //lt CHL5XA【FY23询价改善】
                ol.OpportunityId = oppid;
                ol.Id__c = s.PageObject.Id__c;
                // CHAN-AVG3PW 询价报价画面规则变更
@@ -3115,28 +3358,82 @@
  }
  //lastbuy  2022/2/9 fy start
  public boolean ReservedProductVerification() {
    filg=true;
    Map<string,QuoteLineItem> quotlinitMap = new Map<string,QuoteLineItem>();
    List<Id> lastProductFLGList = new List<Id>();
    for(QELine qli : activities){
      lastProductFLGList.add(qli.pageObject.PricebookEntry.Product2Id);
      quotlinitMap.put(qli.pageObject.PricebookEntry.Product2Id,qli.pageObject);
    List<Id> lastProductFLGListId = new List<Id>();
    List<QuoteLineItem> lastProductFLGList = new List<QuoteLineItem>();
    List<QuoteLineItem> act = new List<QuoteLineItem>();
    List<QuoteLineItem> act2 = new List<QuoteLineItem>();
    for(QELine aaa :activities){
      if(aaa.pageObject.PricebookEntry.Product2Id!=null){
        act.add(aaa.pageObject);
      }
    }
    if(lastProductFLGList!=null){
        List<LastbuyProduct__c> LastbuyObjList=[select id,LastbuyQuantity__c,InquiryCode__c,ProductName__c from LastbuyProduct__c where InquiryCode__c= : oppId and ProductName__c in :lastProductFLGList];
        if(LastbuyObjList!=null){
            for(LastbuyProduct__c lastbuypr :LastbuyObjList){
              Decimal quoteLItemNum=0;
              if(quotlinitMap.containsKey(lastbuypr.ProductName__c)){
                  quoteLItemNum=quotlinitMap.get(lastbuypr.ProductName__c).Quantity__c;
              }else{
                  continue;
              }
              if(lastbuypr.LastbuyQuantity__c<quoteLItemNum){
                filg=false;
                break;
              }
    act2=act.deepClone();
    Map<String,QuoteLineItem> map1 = new Map<String,QuoteLineItem>();
    System.debug('activities1111111111112为所当为多多!!!'+activities);
    integer i =0;
    for(QuoteLineItem pspsc :act2){
      if(pspsc.PricebookEntry.Product2Id!=null){
        if(map1.containsKey(pspsc.PricebookEntry.Product2Id)){
          QuoteLineItem quoteLine = map1.get(pspsc.PricebookEntry.Product2Id);
          quoteLine.Quantity__c =quoteLine.Quantity__c+pspsc.Quantity__c;
          map1.put(pspsc.PricebookEntry.Product2Id,quoteLine);
        }else{
          map1.put(pspsc.PricebookEntry.Product2Id,pspsc);
        }
        System.debug('34499879!!!'+activities);
      }
    }
    System.debug('3434343!!!'+activities);
    System.debug('5656565!!!'+map1);
    for (QuoteLineItem value : map1.values()) {
      if(value.PricebookEntry.Product2.LastbuyProductFLG__c){
        lastProductFLGListId.add(value.PricebookEntry.Product2Id);
        quotlinitMap.put(value.PricebookEntry.Product2Id,value);
        lastProductFLGList.add(value);
      }
    }
    System.debug('activities++++!!!'+activities);
    System.debug('activities!!!'+map1.values());
    System.debug('oppId!!!'+oppId);
    System.debug('lastProductFLGList!!!'+lastProductFLGListId);
    if(lastProductFLGListId!=null&&lastProductFLGListId.size()!=0){
        List<LastbuyProduct__c> LastbuyObjList=[select id,LastbuyQuantity__c,InquiryCode__c,ProductName__c,effectiveFLG__c from LastbuyProduct__c where InquiryCode__c= : oppId and ProductName__c in :lastProductFLGListId and effectiveFLG__c = true];
        Map<string,LastbuyProduct__c> LastbuyObjMap = new Map<string,LastbuyProduct__c>();
        System.debug('LastbuyObjList+++++!!!'+LastbuyObjList);
        if(LastbuyObjList!=null&&LastbuyObjList.size()!=0){
          for(LastbuyProduct__c lastbuypr :LastbuyObjList){
            LastbuyObjMap.put(lastbuypr.ProductName__c,lastbuypr);
          }
        }else{
          flglastbuy=1;
          filg=false;
          return filg;
        }
        System.debug('LastbuyObjMap!!!'+LastbuyObjMap);
        System.debug('lastProductFLGList+++++++!!!'+lastProductFLGList);
        if(lastProductFLGList!=null&&lastProductFLGList.size()!=0){
          for(QuoteLineItem lastbuypr :lastProductFLGList){
            Decimal quoteLItemNum=0;
            if(LastbuyObjMap.containsKey(lastbuypr.PricebookEntry.Product2Id)){
                quoteLItemNum=LastbuyObjMap.get(lastbuypr.PricebookEntry.Product2Id).LastbuyQuantity__c;
                System.debug('quoteLItemNum!!!'+quoteLItemNum);
                System.debug('lastbuypr.pageObject.Quantity__c+++!!!'+lastbuypr.Quantity__c);
                if(lastbuypr.Quantity__c>quoteLItemNum){
                  errorProductmodel=lastbuypr.Asset_Model_No__c;
                  flglastbuy=2;
                  filg=false;
                  break;
                }
            }else{
              errorProductmodel=lastbuypr.Asset_Model_No__c;
              flglastbuy=3;
              filg=false;
              break;
            }
          }
        }
    }
    system.debug('filg====='+filg);
@@ -3164,6 +3461,13 @@
    public String Authorized_DB_No { get; set; }
    // LHJ End
    // Celon询价修改 2022-04-24 ssm start
    public String CelonOpportunity { get; set; }
    // Celon询价修改 2022-04-24 ssm end
    // lastbuy判断变更用户询价 start
    public Boolean is_changed_opp { get; set; }
    // lastbuy判断变更用户询价 end
    public OppInfo(Opportunity opp) {
      Account_RecordType_DeveloperName = opp.Account.RecordType.DeveloperName;
      Direct_Separate = opp.Direct_Separate__c;
@@ -3177,6 +3481,12 @@
      If_Need_Authorize = opp.If_Need_Authorize__c;
      Authorized_DB_No = opp.Authorized_DB_No__c;
      // LHJ End
      // Celon询价修改 2022-04-24 ssm start
      CelonOpportunity = opp.CelonOpportunity__c;
      // Celon询价修改 2022-04-24 ssm end
      // lastbuy判断变更用户询价 start
      is_changed_opp = opp.If_Account_Change__c != null ? opp.If_Account_Change__c : false;
      // lastbuy判断变更用户询价 end
    }
  }
  //TODO 1.Quoteオブジェクト追加