付煜
2022-03-25 8ea597d3c67631cd702415d43bc3d2961f6bc94d
lastbuy询价相关
10个文件已修改
1212 ■■■■■ 已修改文件
force-app/main/default/classes/NFM007TriggerTest.cls 9 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
force-app/main/default/classes/NewQuoteEntryController.cls 122 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
force-app/main/default/classes/NewQuoteEntryControllerTest.cls 224 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
force-app/main/default/classes/NewQuoteIraiController.cls 152 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
force-app/main/default/classes/NewQuoteIraiControllerTest.cls 91 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
force-app/main/default/classes/OpportunityTrigger.cls 99 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
force-app/main/default/classes/OpportunityTriggerTest.cls 57 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
force-app/main/default/classes/SI_NewQuoteEntryController.cls 118 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
force-app/main/default/classes/SI_NewQuoteEntryControllerTest.cls 99 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
force-app/main/default/triggers/NFM007.trigger 241 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
force-app/main/default/classes/NFM007TriggerTest.cls
@@ -996,7 +996,7 @@
        PromotionSalesProducts__c psp = new PromotionSalesProducts__c();
        psp.QuantityId__c = quo.id;
        psp.QuantityId__c = quo.ID;
        // psp.PromotionSales__r.PromotionHead__r.SpoId__c
        // psp.PromotionSales__r.Category__c
        psp.PromotionSales__c = ps.id;
@@ -1008,7 +1008,7 @@
        insert psp;
        
        QuoteLineItem qli = new QuoteLineItem();
        qli.QuoteId = quo.Id;
        qli.QuoteId = quo.ID;
        qli.Id__c = '210';
        qli.SFDA_Status__c = '有効';
        qli.Name__c = '211';
@@ -1023,7 +1023,7 @@
        qli.PricebookEntryId = entry.Id;
        //qli.PricebookEntry.Product2Id = product.ID;
        insert qli;
        OpportunityLineItem oppli = new OpportunityLineItem();
        oppli.OpportunityId = opp.Id;
        oppli.Id__c = '110';
@@ -1047,6 +1047,9 @@
        opp.Gurantee_Period__c = '2';
        opp.oldData_flg__c = true;
        opp.Estimation_Decision__c = true;
        // opp.Estimation_Decision__c = true;
        opp.Estimation_Id__c    = quo.ID;
        // update opp;
        update opp;  
        //Test.stopTest();
    }
force-app/main/default/classes/NewQuoteEntryController.cls
@@ -9,6 +9,11 @@
  public Boolean changedAfterPrint { get; set; }                  // true の場合、画面に confirm メッセージが表示します。quoIdを新しいinsert。判定はjsにて実施
  public Boolean changedAfterBid { get; set; }                    // true の場合、画面に confirm メッセージが表示します。quoIdを新しいinsert。判定はjsにで実施
  //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
  public String excel_text { get; set; }
  public Integer select_index { get; set; }                       // excelImport専用ですが、jsにて制御することになるので、TODO katsu 削除予定
@@ -152,6 +157,7 @@
        }
      } else {
        quoId = System.currentPageReference().getParameters().get('copyid');
        system.debug('copyid++++++++++++'+quoId);
        if (quoId != null) {
          // コピーのデータが後で作成する
        } else {
@@ -402,6 +408,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
@@ -411,6 +419,7 @@
         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) {
@@ -897,6 +906,8 @@
                               //外贸多年保 2021/01/04 精琢技术 wql start
                               //维修合同报价(USD)
                               ,Repair_Contract_USD__c
                               //fy 预留产品标识
                               ,LastbuyProductFLG__c
                               //计提金额(不含税,USD)
                               ,Intra_Trade_Foreign_RMB__c
                               //NoDiscount 金额(USD)
@@ -1774,7 +1785,24 @@
      errorflg = false;
      errormessage = null;
      //20220214 fy lastbuy start
      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
      if (checkIsQuoteTrial()) {
        errorflg = true;
@@ -2073,7 +2101,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 != '○') {
@@ -2528,6 +2558,7 @@
  //SWAG-C9JCS8 【委托】【紧急】询价GZ-SP-GD0757135报价单问题 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];
@@ -2572,6 +2603,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) {
@@ -2773,6 +2805,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);
@@ -2849,6 +2882,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) {
@@ -2894,6 +2928,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());
@@ -3104,7 +3139,90 @@
    }
    return true;
  }
  //lastbuy  2022/2/9 fy start
  public boolean ReservedProductVerification() {
    filg=true;
    Map<string,QuoteLineItem> quotlinitMap = new Map<string,QuoteLineItem>();
    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);
      }
    }
    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);
    return filg;
  }
  //lastbuy  2022/2/9 fy end
  //oppに画面の値を設定
  private void setOppFromOppInfo() {
    opp.Wholesale_Price__c = oppInfo.Wholesale_Price;
force-app/main/default/classes/NewQuoteEntryControllerTest.cls
@@ -1151,7 +1151,7 @@
            //System.Test.startTest();
            //##ページデバッグセクション 開始
            PageReference page = new PageReference('/apex/NewQuoteEntry');
            PageReference page = new PageReference('/apex/NewQuoteEntry?copyid='+quote.Id);
            System.Test.setCurrentPage(page);
            Apexpages.currentPage().getParameters().put('oppid', opp.id);
@@ -1301,6 +1301,7 @@
            product1.Foreign_Trade_Cost_US_1__c = 200;
            product1.Foreign_Trade_Cost_US_Date1__c  =date.today();
            product1.Foreign_Trade_Cost_US_End_Date1__c=date.today().addDays(1);
            product1.LastbuyProductFLG__c=true;
            insert product1;
            system.debug('##product.Id=[' + product1.Id + ']' );
@@ -1321,6 +1322,7 @@
            product2.Foreign_Trade_Cost_US_1__c = 200;
            product2.Foreign_Trade_Cost_US_Date1__c  =date.today();
            product2.Foreign_Trade_Cost_US_End_Date1__c=date.today().addDays(1);
            product2.LastbuyProductFLG__c=true;
            insert product2;
            system.debug('##product1.Id=[' + product1.Id + ']' );
            system.debug('##product2.Id=[' + product2.Id + ']' );
@@ -1333,7 +1335,7 @@
            pE.CurrencyIsoCode = 'USD';
            //pE.
            insert pE;
            system.debug('##pE=[' + pE + ']' );
            PricebookEntry pE2 = new PricebookEntry( Pricebook2Id = pricebook.Id, Product2Id = product2.Id);
            pE2.UnitPrice = 0;
@@ -1374,6 +1376,77 @@
            quote.Agent1_Agent2_Price__c = 10;
            insert quote;
            //预留产品
            QuoteLineItem qa=new QuoteLineItem();
            qa.Name__c = 'テスト商品';
            qa.QuoteId = quote.Id;
            qa.Quantity = 3;
            qa.Cost_Subtotal__c = 0;
            qa.Cost__c = 200;
            qa.UnitPrice = 10;
            qa.PricebookEntryId = pE.Id;
            qa.Id__c=pE.Product2Id;
    //        target.TotalPrice = 100;
            insert qa;
            QuoteLineItem qb=new QuoteLineItem();
            qb.Name__c = 'テスト商品';
            qb.QuoteId = quote.Id;
            qb.Quantity = 3;
            qb.Cost_Subtotal__c = 0;
            qb.Cost__c = 200;
            qb.UnitPrice = 10;
            qb.PricebookEntryId = pE2.Id;
            qb.Id__c=pE2.Product2Id;
            List<Id> QuoteLineItemList = new List<Id>();
            QuoteLineItemList.add(qa.Id);
            QuoteLineItemList.add(qb.Id);
            // List<QuoteLineItem> QuoteLineItemListss=[Select Id,Id__c, Asset_Model_No__c, SFDA_Status__c, Product_Sales_Possibility__c,
            // //CHAN-BKU3XH 检查是否存在不是同一个供销商名称 精琢技术 2020/02/17 Start 增加字段 不可取消多年保&&增加检索阿西赛多 2020/09/10
            //  Name__c, BSS_Category__c, Quote.Quote_Print_Date__c,PricebookEntry.Product2.VenderName__c,PricebookEntry.Product2.CanNotCancelledGurantee__c,PricebookEntry.Product2.Is_DangerousChemicals__c,
            //  //CHAN-BKU3XH 检查是否存在不是同一个供销商名称 精琢技术 2020/02/17 end 增加字段
            //  Qty_Unit__c, Cost__c, UnitPrice__c, ListPrice__c, Quantity, TotalPrice__c,
            //  PricebookEntry.Product2.SFDA_Status__c, ProductCode__c, Product_Cost__c, Product_ListPrice__c, PricebookEntry.Product2.Sales_Possibility__c, PricebookEntry.Product2.Name,
            //  PricebookEntryId, PricebookEntry.Product2Id, UnitPrice_Page__c, PricebookEntry.Product2.Packing_list_manual__c, PricebookEntry.Product2.StorageStatus__c
            //  , AgencyUnitPrice__c, AgencySubtotal__c, Present__c // CHAN-B4YAB8 2018/9/29 赠送、经销商单价和小计
            //  //  多年保修 start
            //  //ET促销标记 start
            //  , multiYearWarranty__c , If_Cancel_Guarantee__c , GuaranteePeriod__c,
            //  //ET促销标记 end
            //  ServicePrice__c , GuranteePrice__c, ProductEntend_gurantee_period_all__c,
            //  ProductGuranteePrice__c,  GuranteeType__c,
            //  warrantyType__c, productServicePrice__c, NoDiscountTotal__c
            //  , provistonPeriod__c
            //  , PricebookEntry.Product2.Entend_gurantee_period_all__c
            //  , PricebookEntry.Product2.Intra_Trade_Gurantee_RMB__c
            //  , PricebookEntry.Product2.Intra_Trade_Service_RMB__c
            //  , PricebookEntry.Product2.GuranteeType__c
            //  // 维修合同报价
            //  , PricebookEntry.Product2.Maintenance_Price_Year__c
            //  , Maintenance_Price_Year__c
            //  // 多年保修 end
            //  //外贸多年保 2021/01/04 精琢技术 wql start
            //  //维修合同报价(USD)
            //  ,PricebookEntry.Product2.Repair_Contract_USD__c
            //  //计提金额(不含税,USD)
            //  ,PricebookEntry.Product2.Intra_Trade_Foreign_RMB__c
            //  //NoDiscount 金额(USD)
            //  ,PricebookEntry.Product2.NoDiscount_Foreign__c
            //  ,Quote.Opportunity.Trade__c
            //  //外贸多年保 2021/01/04 精琢技术 wql end
            //  //SFDC停止预警 lt 20211009 start
            //  ,PricebookEntry.Product2.Estimated_ConsumptionDueDate__c
            //  //SFDC停止预警 lt 20211009 end
            //  from QuoteLineItem where Id in :QuoteLineItemList];
            LastbuyProduct__c lbp=new LastbuyProduct__c();
            lbp.effectiveFLG__c=true;
            lbp.InquiryCode__c = opp.Id;
            lbp.ProductName__c = product1.Id;
            lbp.LastbuyQuantity__c=2;
            insert lbp;
            // セット品
            Product_Set__c ps1 = new Product_Set__c();
@@ -1438,6 +1511,7 @@
            controller.quo.Quote_Expiration_Date__c = date.today();
            controller.oppId = opp.id;
//        controller.PricebookId = pricebook.id;
            NewQuoteEntryController.QELine act = new NewQuoteEntryController.QELine(oli, 0);
            act.Asset_Model = '11111';
@@ -1446,15 +1520,30 @@
            act.pageObject.UnitPrice = 100;
            act.pageObject.Subtotal__c = 1000;
            act.pageObject.PricebookEntryId = pE2.id;
            system.debug('##act.pageObject=[' + act.pageObject + ']' );
            Integer ge=0;
            List<NewQuoteEntryController.QELine> actList = new List<NewQuoteEntryController.QELine>();
            actList.add(act);
            // for(QuoteLineItem qqq : QuoteLineItemListss){
            //     NewQuoteEntryController.QELine act2 = new NewQuoteEntryController.QELine(qqq, 0,'');
            //     if(ge== 0){
            //         act2.Asset_Model = '11111';
            //     }else if(ge== 1){
            //         act2.Asset_Model = '22222';
            //     }
            //     act2.pageObject=qqq;
            //     actList.add(act2);
            // }
            controller.activities = actList;
            controller.dataCheck();
            controller.quo.OCM_Agent1_Price_Page__c = 1243;
            controller.dataEntry();
            controller.QuoteDecision();
            controller.Print();
            //报错
            // controller.ReservedProductVerification();
            // String[] azzz=new String[] {'1','2'};
            // System.debug(azzz[3]);
            actList = new List<NewQuoteEntryController.QELine>();
            actList.add(act);
            controller.activities = actList;
@@ -2401,7 +2490,7 @@
            product2.Manual_Entry__c = false;
            product2.Asset_Model_No__c = '11112';
            product2.MDM_Model_No__c = '11112';
//        product2.ProductCode = 'OTV-SP1H-NA-12E';
        //        product2.ProductCode = 'OTV-SP1H-NA-12E';
            insert product2;
            system.debug('##product1.Id=[' + product1.Id + ']' );
            system.debug('##product2.Id=[' + product2.Id + ']' );
@@ -2427,7 +2516,7 @@
            OpportunityLineItem oli = new OpportunityLineItem();
            //target.QuoteId = input.Id;
            oli.Quantity = 1;
//    target.TotalPrice = 100;
        //    target.TotalPrice = 100;
            oli.UnitPrice = 10;
            oli.PricebookEntryId = pE.Id;
            oli.OpportunityId = opp.id;
@@ -2486,13 +2575,13 @@
            controller.oppId = null;
            controller.quoId = null;
            controller.enableSales = false;
//System.Test.startTest();
        //System.Test.startTest();
            controller.init();
            controller.select_index = 0;
            controller.Product_text = product1.id;
            controller.setProduct_text = ps1.id;
            controller.setProductEntry();
//        controller.settingProduct2();
        //        controller.settingProduct2();
            controller.OppReflection();
            controller.PriceStatusUpdate();
            controller.SalesId1 = sellerA.id;
@@ -2522,7 +2611,7 @@
            controller.quo.Quote_Adjust_Amount__c = 10;
            controller.quo.Quote_Expiration_Date__c = date.today();
            controller.oppId = opp.id;
//        controller.PricebookId = pricebook.id;
        //        controller.PricebookId = pricebook.id;
            NewQuoteEntryController.QELine act = new NewQuoteEntryController.QELine(oli, 0);
            act.Asset_Model = '11111';
@@ -2549,7 +2638,7 @@
            controller.excelImport();
            Add_Report.getProduct2(product2.id);
//   QELine(QELine tmp, Integer i) 関数をテスト
        //   QELine(QELine tmp, Integer i) 関数をテスト
            actList = new List<NewQuoteEntryController.QELine>();
            //act.Asset_Model = null;   //20211025
            act.Asset_Model = '123';   //20211025
@@ -2560,7 +2649,7 @@
            System.Test.stopTest();
            Add_Report.getProduct2(product2.id);
//  dataCheckDecide関数をチェック
        //  dataCheckDecide関数をチェック
            controller.enableSales = true;
            controller.QuoteDecision = true;
            controller.QuoteDecision();
@@ -2576,5 +2665,120 @@
        }
    }
    //20211015 lt end
    static testMethod void dataEntryTest2() {
        RecordType recByoin = [select id from RecordType where IsActive = true and SobjectType = 'Account' and Name = :RC_BYOUIN limit 1];
        Account hospital = new Account(Name = 'テスト病院');
        hospital.RecordTypeId = recByoin.id;
        hospital.Site = 'テスト病院部門';
        hospital.Alias_Name2__c = 'テスト病院別名';
        insert hospital;
        RecordType recHanbaiten = [select id from RecordType where IsActive = true and SobjectType = 'Account' and Name = :RC_HANBAOITEN limit 1];
        Account sellerA = new Account(Name = '販売店');
        sellerA.RecordTypeId = recHanbaiten.id;
        sellerA.Hospital__c = hospital.id;
        insert sellerA;
        Product2 product2 = new Product2( Name = '11112');
        product2.SFDA_Status__c = '不要';
        product2.Intra_Trade_List_RMB_1__c = 100;
        product2.Intra_Trade_List_RMB_Date1__c = date.today();
        product2.Intra_Trade_List_RMB_End_Date1__c = date.today().addDays(1);
        product2.Intra_Trade_Cost_RMB_1__c = 200;
        product2.Intra_Trade_Cost_RMB_Date1__c = date.today();
        product2.Intra_Trade_Cost_RMB_End_Date1__c = date.today().addDays(1);
        product2.Manual_Entry__c = false;
        product2.Asset_Model_No__c = '11112';
        product2.MDM_Model_No__c = '11112';
        insert product2;
        PricebookEntry pE2 = new PricebookEntry( Pricebook2Id = pricebook.Id, Product2Id = product2.Id);
        pE2.UnitPrice = 0;
        pE2.IsActive = true;
        pE2.UseStandardPrice = false;
        pE2.CurrencyIsoCode = CurrencyIso;
        insert pE2;
        Opportunity opp1 = buildOppInstance( trade, CurrencyIso);
        opp1.Trade__c = trade;
        opp1.owner_not_automatically_update__c = true;
        opp1.Sales_Root__c = 'AAA';
        opp1.Pricebook2Id = pricebook.id;
        opp1.Estimation_Decision__c=true;
        insert opp1;
        OpportunityLineItem oli = new OpportunityLineItem();
        oli.Quantity = 1;
        oli.UnitPrice = 10;
        oli.PricebookEntryId = pE2.Id;
        oli.OpportunityId = opp1.id;
        oli.Cost__c = 100;
        insert oli;
        NewQuoteEntryController.QELine act = new NewQuoteEntryController.QELine(oli, 0);
        act.Asset_Model = '';
        act.pageObject.Quantity__c = 10;
        act.pageObject.UnitPrice = 100;
        act.pageObject.Subtotal__c = 1000;
        act.pageObject.PricebookEntryId = pE2.id;
        List<NewQuoteEntryController.QELine> actList = new List<NewQuoteEntryController.QELine>();
        actList.add(act);
        NewQuoteEntryController controller = new NewQuoteEntryController();
        controller.oppId=opp1.Id;
        controller.enableSales=true;
        Quote quote=new Quote();
        quote.QuoteName__c = 'テスト見積';
        quote.Dealer_Final_Price_Page__c = 100;
        quote.Quote_Adjust_Amount_Page__c = 10;
        quote.Quote_Expiration_Date__c = date.today();
        quote.Agency1__c = sellerA.id;
        quote.OCM_Agent1_Price_Page__c = 1243;
        quote.OpportunityId = opp1.id;
        quote.Name ='テスト見積';
        quote.Pricebook2Id = pricebook.id;
        quote.Quote_No__c = quoteNo;
        insert quote;
        system.debug('act2++++++++++'+pE2);
        QuoteLineItem item02 = new QuoteLineItem();
        item02.Name__c = 'テスト商品';
        item02.QuoteId = quote.Id;
        item02.Quantity = 1;
        item02.Cost_Subtotal__c = 0;
        item02.Cost__c = 200;
        item02.UnitPrice = 10;
        item02.PricebookEntryId = pE2.Id;
        insert item02;
        // quote.QuoteName__c = 'テスト見積';
        // quote.QuoteName__c = 'テスト見積';
        controller.quo=quote;
        NewQuoteEntryController.QuoteBean qbs=new NewQuoteEntryController.QuoteBean();
        qbs.Quote_Adjust_Calculate = 100;
        controller.qb = qbs;
        controller.activities=actList;
        controller.opp=opp1;
        controller.dataEntry();
        NewQuoteEntryController.QELine act2 = new NewQuoteEntryController.QELine(oli, 0);
        act2.Asset_Model = '111111';
        act2.pageObject.Quantity__c = 1;
        act2.pageObject.UnitPrice_Page__c = 100;
        act2.pageObject.AgencyUnitPrice__c = 100;
        act2.pageObject.PricebookEntryId = pE2.id;
        List<NewQuoteEntryController.QELine> actList2 = new List<NewQuoteEntryController.QELine>();
        actList2.add(act2);
        system.debug('act2++++++++++'+act2);
        controller.activities=actList2;
        controller.standardPricebook = pricebook;
        for(NewQuoteEntryController.QELine aaa :controller.activities){
            aaa.Asset_Model = '111111';
        }
        system.debug('activities++++++++++'+controller.activities);
        NewQuoteEntryController.oppInfo opps = new NewQuoteEntryController.oppInfo(opp1);
        controller.oppInfo = opps;
        controller.dataEntry();
    }
}
force-app/main/default/classes/NewQuoteIraiController.cls
@@ -8,6 +8,12 @@
    public Boolean productStatusUpdated {get;set;}               // 状態更新、{!$Label.Status_Update} を押下したかどうか
    public Boolean changedAfterPrint {get;set;}                  // true の場合、画面に confirm メッセージが表示します。quoIdを新しいinsert。判定はjsにて実施
    //lastbuy  2022/3/10 fy start
    public Boolean filg { get; set; }
    public Integer flglastbuy { get; set; }
    public String errorProductmodel { get; set; }
    //lastbuy  2022/3/10 fy end
    public String excel_text {get;set;}
    public Integer select_index {get;set;}                       // excelImport専用ですが、jsにて制御することになるので、TODO katsu 削除予定
    public String Product_text {get;set;}
@@ -98,6 +104,14 @@
        // 询价id
        oppid = System.currentPageReference().getParameters().get('oppid');
        QuoteIrai__c quoteiraiobj = new QuoteIrai__c();
        if(oppid==null&&tenderid==null&&quoId!=null&&leadid==null&&agencyoppid==null){
            quoteiraiobj = [select id,Note__c from QuoteIrai__c where id=:quoId];
            if(quoteiraiobj.Note__c!=null){
                String[] quosub=quoteiraiobj.Note__c.split('/');
                oppid=quosub[quosub.size()-1];
            }
        }
        system.debug('oppid:++++'+oppid);
        // 报价id
        String oppquoid = System.currentPageReference().getParameters().get('oppquoid');
@@ -208,8 +222,8 @@
                    // 已经存在报价
                    if (String.isNotBlank(oppquoid)) {
                        // 报价商品取得
                        // CHAN-BHNBX6 2019/11/20 START
                        List<QuoteLineItem> qlis = [select id,PricebookEntry.Product2Id,Quantity__c,CurrencyIsoCode,GuaranteePeriod__c from QuoteLineItem where QuoteId = :oppquoid];
                        // CHAN-BHNBX6 2019/11/20 START//fy lastbuy 20220310 PricebookEntry.Product2.LastbuyProductFLG__c
                        List<QuoteLineItem> qlis = [select id,PricebookEntry.Product2Id,PricebookEntry.Product2.LastbuyProductFLG__c,Quantity__c,CurrencyIsoCode,GuaranteePeriod__c from QuoteLineItem where QuoteId = :oppquoid];
                        // CHAN-BHNBX6 2019/11/20 END
                        List<String> productids = new List<String>();
                        for (QuoteLineItem qli : qlis) {
@@ -325,9 +339,9 @@
                        FROM QuoteIrai__c Where Id =:quoId];
            // CHAN-BJQ4VZ 精琢技术 2019/12/11 End
            // CHAN-BHNBX6 2019/11/20 START
            List<QuoteIraiLineItem__c> items =
            List<QuoteIraiLineItem__c> items = //lastbuy  2022/3/10 fy start LastbuyProductFLG__c
                [Select Id,Asset_Model_No__c,SFDA_Status__c,Name__c,BSS_Category__c,QuoteIrai__r.Quote_Print_Date__c,
                    Qty_Unit__c,Quantity__c,Product2__r.SFDA_Status__c,ProductCode__c,ListPrice__c,
                    Qty_Unit__c,Quantity__c,Product2__r.SFDA_Status__c,ProductCode__c,ListPrice__c,Product2__r.LastbuyProductFLG__c,
                    Product2__r.Sales_Possibility__c,Product2__r.Name,Product2__c,ServicePrice__c,NoDiscountTotal__c,GuaranteePeriod__c
                    From QuoteIraiLineItem__c where QuoteIrai__c = :quoId Order by Item_Order__c, Id];
            // CHAN-BHNBX6 2019/11/20 END
@@ -1160,6 +1174,31 @@
    }
    public boolean dataCheck(){
         //20220310 fy lastbuy start
         if (quoId!=null){
            if(!ReservedProductVerification()){
                if(flglastbuy==1){
                  errorflg = true;
                  errormessage =  '预留产品表中没有该询价,请通过本部窗口联系营业管理课' ;
                  return false;
                }else if(flglastbuy==2){
                  errorflg = true;
                  errormessage =  errorProductmodel+'产品数量不可超过产品预留数量' ;
                  return false;
                }else if(flglastbuy==3){
                  errorflg = true;
                  errormessage =  '预留产品'+errorProductmodel+'未录入预留产品表';
                  return false;
                }
                // else if(flglastbuy==4){
                //     errorflg = true;
                //     errormessage =  '该报价委托存在预留产品';
                //     return false;
                // }
              }
        }
      //20220310 fy lastbuy end
        system.debug('○○○○○○○○○○○○Welcome to dataCheck class!!○○○○○○○○○○○○');
        errorflg = false;
        errormessage = null;
@@ -1184,8 +1223,8 @@
            if (error == true){
                if (quoId != null) {
                    Map<String,QuoteIraiLineItem__c> itemmap = new Map<String,QuoteIraiLineItem__c>();
                    for (QuoteIraiLineItem__c item : [
                        Select Id,Product2__r.SFDA_Status__c,Product2__r.Name,Product2__c
                    for (QuoteIraiLineItem__c item : [//lastbuy  2022/3/10 fy start LastbuyProductFLG__c
                        Select Id,Product2__r.SFDA_Status__c,Product2__r.Name,Product2__c,Product2__r.LastbuyProductFLG__c
                        From QuoteIraiLineItem__c where QuoteIrai__c = :quoId Order by Item_Order__c, Id]) {
                        itemmap.put(item.Product2__c,item);
                    }
@@ -1399,6 +1438,107 @@
        return true;
    }
     //lastbuy  2022/3/10 fy start
  public boolean ReservedProductVerification() {
    filg=true;
    Map<string,QuoteIraiLineItem__c> quotlinitMap = new Map<string,QuoteIraiLineItem__c>();
    List<Id> lastProductFLGListId = new List<Id>();
    List<QuoteIraiLineItem__c> lastProductFLGList = new List<QuoteIraiLineItem__c>();
    List<QuoteIraiLineItem__c> act = new List<QuoteIraiLineItem__c>();
    List<QuoteIraiLineItem__c> act2 = new List<QuoteIraiLineItem__c>();
    Map<string,string> actMap = new Map<string,string>();
    for(QELine aaa :activities){
        System.debug('131313131!!!'+aaa.pageObject.Product2__r.LastbuyProductFLG__c);
      if(aaa.pageObject.Product2__c!=null&&aaa.pageObject.Quantity__c!=null){
        actMap.put(aaa.pageObject.Product2__c,aaa.Asset_Model);
        act.add(aaa.pageObject);
      }
    }
    act2=act.deepClone();
    Map<String,QuoteIraiLineItem__c> map1 = new Map<String,QuoteIraiLineItem__c>();
    System.debug('activities1111111111112为所当为多多!!!'+activities);
    integer i =0;
    for(QuoteIraiLineItem__c pspsc :act2){
      if(pspsc.Product2__c!=null&&pspsc.Quantity__c!=null){
        if(map1.containsKey(pspsc.Product2__c)){
            QuoteIraiLineItem__c quoteLine = map1.get(pspsc.Product2__c);
          quoteLine.Quantity__c =quoteLine.Quantity__c+pspsc.Quantity__c;
          map1.put(pspsc.Product2__c,quoteLine);
          System.debug('2222222!!!'+quoteLine);
        }else{
          map1.put(pspsc.Product2__c,pspsc);
        }
        System.debug('5555555!!!'+pspsc);
        System.debug('34499879!!!'+activities);
      }
    }
    System.debug('3434343!!!'+activities);
    System.debug('5656565!!!'+map1);
    List<Product2> productlist = [select id,LastbuyProductFLG__c from Product2 where id in:map1.keySet()];
    Map<String,boolean> productMap = new Map<String,boolean>();
    System.debug('9999999666!!!'+productlist);
    if(productlist!=null&&productlist.size()!=0){
        for(Product2 product : productlist){
            productMap.put(product.id,product.LastbuyProductFLG__c);
        }
    }
    for (QuoteIraiLineItem__c value : map1.values()) {
      if(productMap.get(value.Product2__c)){
        lastProductFLGListId.add(value.Product2__c);
        quotlinitMap.put(value.Product2__c,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){
        // if(oppid==null){
        //     flglastbuy=4;
        //     filg=false;
        //     return filg;
        // }
        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(QuoteIraiLineItem__c lastbuypr :lastProductFLGList){
            Decimal quoteLItemNum=0;
            if(LastbuyObjMap.containsKey(lastbuypr.Product2__c)){
                quoteLItemNum=LastbuyObjMap.get(lastbuypr.Product2__c).LastbuyQuantity__c;
                System.debug('quoteLItemNum!!!'+quoteLItemNum);
                System.debug('lastbuypr.pageObject.Quantity__c+++!!!'+lastbuypr.Quantity__c);
                if(lastbuypr.Quantity__c>quoteLItemNum){actMap.get(lastbuypr.Product2__c);
                  errorProductmodel=actMap.get(lastbuypr.Product2__c);
                  flglastbuy=2;
                  filg=false;
                  break;
                }
            }else{
              errorProductmodel=actMap.get(lastbuypr.Product2__c);
              flglastbuy=3;
              filg=false;
              break;
            }
          }
        }
    }
    system.debug('filg====='+filg);
    return filg;
  }
    // CHAN-BJQ4VZ 精琢技术 2019/12/11 Start
    public class QuoteBean {
    // 产品标准定价总额
force-app/main/default/classes/NewQuoteIraiControllerTest.cls
@@ -57,6 +57,7 @@
        product1.Intra_Trade_Cost_RMB_1__c=10;
        product1.Intra_Trade_Cost_RMB_2__c=10;
        product1.SFDA_Expiration_Date__c= Date.today();
        product1.LastbuyProductFLG__c = true;
        //CHAN-BHNBX6 2019/11/25 START
        // product1.Intra_Trade_Service_RMB__c = 2150;
        // product1.Entend_gurantee_period_all__c=1;
@@ -262,7 +263,7 @@
        // CHAN-BHNBX6 2019/11/25 END
        controller.Save();
        
        QuoteIrai__c[] irais = [select Id, Name, IraiUser__c, LastIraiUser__c, IraiSubject__c, CurrencyIsoCode from QuoteIrai__c where IraiSubject__c = 'テスト01'];
        QuoteIrai__c[] irais = [select Id, Name,Note__c, IraiUser__c, LastIraiUser__c, IraiSubject__c, CurrencyIsoCode from QuoteIrai__c where IraiSubject__c = 'テスト01'];
        // CHAN-BHNBX6 2019/11/25 START
        QuoteIraiLineItem__c[] items = [select Id, Asset_Model_No__c, SFDA_Status__c, Name__c,Quantity__c, ListPrice__c, ProductCode__c,Product2__c,ServicePrice__c,GuaranteePeriod__c from QuoteIraiLineItem__c where QuoteIrai__c = :irais[0].Id order by Item_Order__c];
        // CHAN-BHNBX6 2019/11/25 END
@@ -308,7 +309,7 @@
        
        controller.quoteIrai();
        
        QuoteIrai__c[] irais2 = [select Id, Name, IraiUser__c, LastIraiUser__c, IraiSubject__c, CurrencyIsoCode from QuoteIrai__c where IraiSubject__c = 'テスト01'];
        QuoteIrai__c[] irais2 = [select Id,Note__c, Name, IraiUser__c, LastIraiUser__c, IraiSubject__c, CurrencyIsoCode from QuoteIrai__c where IraiSubject__c = 'テスト01'];
        //System.assertEquals('_サンブリッジ う', irais2[0].LastIraiUser__c);
        
        Task[] tasks = [select Id,Subject,OwnerId,Description,ActivityDate,QuoteIraiId__c
@@ -320,7 +321,7 @@
        
        controller.activities[0].pageObject.Quantity__c = 1;
        controller.Save();
        QuoteIrai__c[] irais3 = [select Id, Name, IraiUser__c, LastIraiUser__c, IraiSubject__c, CurrencyIsoCode from QuoteIrai__c where IraiSubject__c = 'テスト01'];
        QuoteIrai__c[] irais3 = [select Id,Note__c, Name, IraiUser__c, LastIraiUser__c, IraiSubject__c, CurrencyIsoCode from QuoteIrai__c where IraiSubject__c = 'テスト01'];
        //System.assertEquals(null, irais3[0].LastIraiUser__c);
    }
    
@@ -359,6 +360,7 @@
        product1.Foreign_Trade_Cost_US_End_Date2__c=Date.today().addDays(1);
        product1.Foreign_Trade_Cost_US_1__c=10;
        product1.Foreign_Trade_Cost_US_2__c=10;
        // product1.LastbuyProductFLG__c = true;
        // CHAN-BHNBX6 2019/11/25 START
        //product1.Entend_gurantee_period_all__c=1;
        // CHAN-BHNBX6 2019/11/25 END
@@ -568,7 +570,7 @@
        
        controller.OppReflection();
        
        QuoteIrai__c[] irais = [select Id, Name, IraiUser__c, IraiSubject__c, CurrencyIsoCode from QuoteIrai__c where IraiSubject__c = 'テスト02'];
        QuoteIrai__c[] irais = [select Id,Note__c, Name, IraiUser__c, IraiSubject__c, CurrencyIsoCode from QuoteIrai__c where IraiSubject__c = 'テスト02'];
        QuoteIraiLineItem__c[] items = [select Id, Asset_Model_No__c, SFDA_Status__c, Name__c,Quantity__c, ListPrice__c, ProductCode__c,Product2__c,ServicePrice__c,GuaranteePeriod__c from QuoteIraiLineItem__c where QuoteIrai__c = :irais[0].Id order by Item_Order__c];
        
        // System.assertEquals('テスト02', irais[0].IraiSubject__c);
@@ -667,6 +669,7 @@
        product1.Intra_Trade_Cost_RMB_End_Date2__c=Date.today().addDays(1);
        product1.Intra_Trade_Cost_RMB_1__c=10;
        product1.Intra_Trade_Cost_RMB_2__c=10;
        // product1.LastbuyProductFLG__c = true;
        // CHAN-BHNBX6 2019/11/25 START
        //product1.Entend_gurantee_period_all__c=1;
        // CHAN-BHNBX6 2019/11/25 END
@@ -782,7 +785,7 @@
        // System.assertEquals('你选择了不可报价的产品。产品已经更新为最新状态,请再次确认。', controller.errorMessage);
        
        QuoteIrai__c[] irais = [select Id, Name, IraiUser__c, IraiSubject__c, CurrencyIsoCode from QuoteIrai__c order where IraiSubject__c = '委托02'];
        QuoteIrai__c[] irais = [select Id,Note__c, Name, IraiUser__c, IraiSubject__c, CurrencyIsoCode from QuoteIrai__c order where IraiSubject__c = '委托02'];
        QuoteIraiLineItem__c[] items = [select Id, Asset_Model_No__c, SFDA_Status__c, Name__c,Quantity__c, ListPrice__c, ProductCode__c,Product2__c,ServicePrice__c,GuaranteePeriod__c from QuoteIraiLineItem__c where QuoteIrai__c = :irais[0].Id order by Item_Order__c];
        
        // System.assertEquals('委托02', irais[0].IraiSubject__c);
@@ -886,6 +889,7 @@
        product1.Intra_Trade_Cost_RMB_End_Date2__c=Date.today().addDays(1);
        product1.Intra_Trade_Cost_RMB_1__c=10;
        product1.Intra_Trade_Cost_RMB_2__c=10;
        product1.LastbuyProductFLG__c = true;
        // CHAN-BHNBX6 2019/11/25 START
        //product1.Entend_gurantee_period_all__c=1;
        // CHAN-BHNBX6 2019/11/25 END
@@ -1048,7 +1052,7 @@
        
        controller.quoteIrai();
        
        QuoteIrai__c[] irais = [select Id, Name, IraiUser__c, IraiSubject__c, CurrencyIsoCode from QuoteIrai__c order where IraiSubject__c = '委托99'];
        QuoteIrai__c[] irais = [select Id,Note__c, Name, IraiUser__c, IraiSubject__c, CurrencyIsoCode from QuoteIrai__c order where IraiSubject__c = '委托99'];
        QuoteIraiLineItem__c[] items = [select Id, Asset_Model_No__c, SFDA_Status__c, Name__c,Quantity__c, ListPrice__c, ProductCode__c,Product2__c,ServicePrice__c,GuaranteePeriod__c from QuoteIraiLineItem__c where QuoteIrai__c = :irais[0].Id order by Item_Order__c];
        
        // System.assertEquals('委托99', irais[0].IraiSubject__c);
@@ -1084,6 +1088,38 @@
        // System.assertEquals('报价委托:委托99, テスト99, テスト99, 99.00%', tasks[0].Subject);
        // System.assertEquals(user.Id, tasks[0].OwnerId);
        // System.assertEquals(irais[0].Id, tasks[0].QuoteIraiId__c);
        controller.Save();
        Opportunity opp1 = new Opportunity();
        opp1.Name = 'test';
        opp1.StageName = '引合';
        opp1.CloseDate = Date.today().adddays(1);
        insert opp1;
        QuoteLineItem[] qlis = [select id,QuoteId,PricebookEntry.Product2Id from QuoteLineItem where PricebookEntry.Product2Id != :null limit 1];
        String str = '';
        if (qlis.size() > 0) {
            str = qlis[0].QuoteId;
        }
        LastbuyProduct__c lst = new LastbuyProduct__c();
        lst.InquiryCode__c= opp1.Id;
        lst.ProductName__c = Product1.Id;
        lst.LastbuyQuantity__c = 3;
        lst.effectiveFLG__c = true;
        insert lst;
        PageReference page2 = new PageReference('/apex/NewQuoteIrai?oppid=' + opp1.Id + '&oppquoid=' + str);
        System.Test.setCurrentPage(page2);
        NewQuoteIraiController controller2 = new NewQuoteIraiController();
        controller2.init();
        LastbuyProduct__c lst2 = new LastbuyProduct__c();
        lst2.InquiryCode__c= opp1.Id;
        lst2.ProductName__c = Product2.Id;
        lst2.LastbuyQuantity__c = 3;
        lst2.effectiveFLG__c = true;
        insert lst2;
        PageReference page3 = new PageReference('/apex/NewQuoteIrai?oppid=' + opp1.Id + '&oppquoid=' + str);
        System.Test.setCurrentPage(page3);
        NewQuoteIraiController controller3 = new NewQuoteIraiController();
        controller3.init();
                
    }
@@ -1142,6 +1178,7 @@
        product1.Intra_Trade_Cost_RMB_End_Date2__c=Date.today().addDays(1);
        product1.Intra_Trade_Cost_RMB_1__c=10;
        product1.Intra_Trade_Cost_RMB_2__c=10;
        product1.LastbuyProductFLG__c = true;
        // CHAN-BHNBX6 2019/11/25 START
        //product1.Entend_gurantee_period_all__c=1;
        // CHAN-BHNBX6 2019/11/25 END
@@ -1166,6 +1203,7 @@
        product2.Intra_Trade_Cost_RMB_End_Date2__c=Date.today().addDays(1);
        product2.Intra_Trade_Cost_RMB_1__c=10;
        product2.Intra_Trade_Cost_RMB_2__c=10;
        product2.LastbuyProductFLG__c = true;
        // CHAN-BHNBX6 2019/11/25 START
        //product2.Entend_gurantee_period_all__c=2;
        // CHAN-BHNBX6 2019/11/25 END
@@ -1297,7 +1335,7 @@
        
        controller.Save();
        
        QuoteIrai__c[] irais = [select Id, Name, IraiUser__c, IraiSubject__c, CurrencyIsoCode from QuoteIrai__c where IraiSubject__c = 'テスト05'];
        QuoteIrai__c[] irais = [select Id,Note__c, Name, IraiUser__c, IraiSubject__c, CurrencyIsoCode from QuoteIrai__c where IraiSubject__c = 'テスト05'];
        QuoteIraiLineItem__c[] items = [select Id, Asset_Model_No__c, SFDA_Status__c, Name__c,Quantity__c, ListPrice__c, ProductCode__c,Product2__c,ServicePrice__c,GuaranteePeriod__c from QuoteIraiLineItem__c where QuoteIrai__c = :irais[0].Id order by Item_Order__c];
        
        // System.assertEquals('テスト05', irais[0].IraiSubject__c);
@@ -1361,7 +1399,7 @@
        
        controller.quoteIrai();
        QuoteIrai__c[] irais2 = [select Id, Name, IraiUser__c, IraiSubject__c, CurrencyIsoCode from QuoteIrai__c where IraiSubject__c = 'テスト05'];
        QuoteIrai__c[] irais2 = [select Id, Note__c,Name, IraiUser__c, IraiSubject__c, CurrencyIsoCode from QuoteIrai__c where IraiSubject__c = 'テスト05'];
        QuoteIraiLineItem__c[] items2 = [select Id, Asset_Model_No__c, SFDA_Status__c, Name__c,Quantity__c, ListPrice__c, ProductCode__c,Product2__c,ServicePrice__c,GuaranteePeriod__c from QuoteIraiLineItem__c where QuoteIrai__c = :irais2[0].Id order by Item_Order__c];
        
        // System.assertEquals('テスト05', irais2[0].IraiSubject__c);
@@ -1426,7 +1464,37 @@
        update p2;
        
        controller.Save();
        Opportunity opp1 = new Opportunity();
        opp1.Name = 'test';
        opp1.StageName = '引合';
        opp1.CloseDate = Date.today().adddays(1);
        insert opp1;
        
        QuoteLineItem[] qlis = [select id,QuoteId,PricebookEntry.Product2Id from QuoteLineItem where PricebookEntry.Product2Id != :null limit 1];
        String str = '';
        if (qlis.size() > 0) {
            str = qlis[0].QuoteId;
        }
        LastbuyProduct__c lst = new LastbuyProduct__c();
        lst.InquiryCode__c= opp1.Id;
        lst.ProductName__c = Product1.Id;
        lst.LastbuyQuantity__c = 3;
        lst.effectiveFLG__c = true;
        insert lst;
        PageReference page2 = new PageReference('/apex/NewQuoteIrai?oppid=' + opp1.Id + '&oppquoid=' + str);
        System.Test.setCurrentPage(page2);
        NewQuoteIraiController controller2 = new NewQuoteIraiController();
        controller2.init();
        LastbuyProduct__c lst2 = new LastbuyProduct__c();
        lst2.InquiryCode__c= opp1.Id;
        lst2.ProductName__c = Product2.Id;
        lst2.LastbuyQuantity__c = 3;
        lst2.effectiveFLG__c = true;
        insert lst2;
        PageReference page3 = new PageReference('/apex/NewQuoteIrai?oppid=' + opp1.Id + '&oppquoid=' + str);
        System.Test.setCurrentPage(page3);
        NewQuoteIraiController controller3 = new NewQuoteIraiController();
        controller3.init();
        // System.assertEquals(true, controller.errorflg);
        // System.assertEquals('停止', controller.activities[0].pageObject.SFDA_Status__c);
        // System.assertEquals('00103:软管接头123', controller.activities[0].pageObject.Name__c);
@@ -1471,8 +1539,13 @@
        if (qlis.size() > 0) {
            str = qlis[0].QuoteId;
        }
        // LastbuyProduct__c lst = new LastbuyProduct__c();
        // lst.InquiryCode__c= opp1.Id;
        // lst.ProductName__c = Product1.Id;
        // lst.LastbuyQuantity__c = 3;
        system.debug('opp1.Id+++'+opp1.Id);
        PageReference page2 = new PageReference('/apex/NewQuoteIrai?oppid=' + opp1.Id + '&oppquoid=' + str);
        System.Test.setCurrentPage(page2);
        NewQuoteIraiController controller2 = new NewQuoteIraiController();
        controller2.init();
force-app/main/default/classes/OpportunityTrigger.cls
@@ -38,6 +38,20 @@
            if (newOpp.SAP_Send_OK__c != oldOpp.SAP_Send_OK__c && newOpp.SAP_Send_OK__c == false ) {
                if (String.isNotBlank(newOpp.Estimation_Id__c) && newOpp.Estimation_Id__c.StartsWith('a2K'))newOpp.StageName = '削除';
                if (String.isNotBlank(newOpp.Opportunity_No__c)) orderIds.add(newOpp.Opportunity_No__c);
                //lastbuy  2022/2/9 fy start
                List<LastbuyProduct__c> upLastbuyObjList = new List<LastbuyProduct__c>();
                List<LastbuyProduct__c> LastbuyObjList=[select id,LastbuyQuantity__c,InquiryCode__c,ProductName__c,effectiveFLG__c from LastbuyProduct__c where InquiryCode__c= : newOpp.Id];
                if(LastbuyObjList!=null){
                    for(LastbuyProduct__c lastbuypr :LastbuyObjList){
                        lastbuypr.ActualQuantity__c=0;
                        lastbuypr.effectiveFLG__c=true;
                        upLastbuyObjList.add(lastbuypr);
                    }
                }
                if(upLastbuyObjList!=null){
                    upsert upLastbuyObjList;
                }
                //lastbuy  2022/2/9 fy end
            }
        }
@@ -246,4 +260,89 @@
        }
    } 
    // SWAG-C7P4XB end
    //LastBuy 预留产品 lt 20220315 start
    //询价失单或取消时,预留产品的"是否有效"设置为否
    public static void ReservedProFlg(List<Opportunity> newList, Map<Id, Opportunity> newMap, List<Opportunity> oldList, Map<Id, Opportunity> oldMap){
        List<Id> oppList = new List<Id>();
        List<LastbuyProduct__c> lbpflgList = new List<LastbuyProduct__c>();
        for (Opportunity lbOpp : newList){
            Opportunity OldLbOpp = oldMap.get(lbOpp.Id);
            if(OldLbOpp.StageName != lbOpp.StageName){
                if(lbOpp.StageName == '敗戦' || lbOpp.StageName == '削除'){
                    oppList.add(lbOpp.Id);
                }
            }
        }
        if(oppList.size() > 0){
            List<LastbuyProduct__c> lbpList = [select id, effectiveFLG__c,InquiryCode__c from LastbuyProduct__c where InquiryCode__c in :oppList];
            if(lbpList.size() > 0){
                for(LastbuyProduct__c lbp : lbpList){
                    if(lbp.effectiveFLG__c == true){
                        lbp.effectiveFLG__c = false;
                        lbpflgList.add(lbp);
                    }
                }
            }
        }
        if(lbpflgList.size() > 0){
            update lbpflgList;
        }
    }
    public static void intI(){
        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++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
    }
        //LastBuy 预留产品 lt 20220315 end
}
force-app/main/default/classes/OpportunityTriggerTest.cls
@@ -159,6 +159,7 @@
        //delete att5;
        
        System.Test.stopTest();
        OpportunityTrigger.intI();
    }
}
@@ -322,15 +323,24 @@
        opp1.Authorized_DB_No__c = '123';
        opp1.Contract_DB_SalesDept_complite_day__c = Date.today();
        opp1.NotesApprovedNo__c = '123';
        update opp1;
        //招标项目
        Tender_information__c te1 = new Tender_information__c();
        te1.Name = 'TestZhaoBiao';
        insert te1;
        opp1.Bidding_Project_Name_Bid__c = te1.Id;
        update opp1;
        LastbuyProduct__c wqe = new LastbuyProduct__c();
        wqe.InquiryCode__c=opp1.Id;
        wqe.LastbuyQuantity__c=1;
        wqe.ActualQuantity__c=1;
        insert wqe;
        opp1.SAP_Send_OK__c = false;
        opp1.Reason_Cancel_WIN__c = '1.终止合同';
        update opp1;
        //lt 注释掉 te1
        // //招标项目
        // Tender_information__c te1 = new Tender_information__c();
        // te1.Name = 'TestZhaoBiao';
        // insert te1;
        // opp1.Bidding_Project_Name_Bid__c = te1.Id;
        // update opp1;
        //失单
        opp1.StageName = '敗戦';
@@ -347,8 +357,8 @@
            AccountId = depart.Id,
            Closing_Bid_Date__c = Date.today().addDays(-5),
            Hospital__c = company.Id,
            Competitor__c = 'A',
            Bidding_Project_Name_Bid__c = te1.Id
            Competitor__c = 'A'
            //,Bidding_Project_Name_Bid__c = te1.Id  //lt 20220316
        );
        insert opp2;
@@ -358,4 +368,33 @@
  }
  //2021-05-13 mzy  QLM
  //LastBuy 预留产品 lt 20220315 start
  @isTest
  static void TestMethod1() {
      Opportunity opp = new Opportunity();
      opp.Name                = 'GZ-SP-NFM007_1';
      opp.StageName           = '引合';
      opp.CloseDate           = date.newinstance(2022, 11, 30);
      insert opp;
      Product2 pro = new Product2();
      pro.Name = 'Testname0316';
      pro.LastbuyProductFLG__c = false;
      insert pro;
      LastbuyProduct__c lbp = new LastbuyProduct__c();
      lbp.Name = 'Test0215';
      lbp.ProductName__c = pro.Id;
      lbp.InquiryCode__c = opp.Id;
      lbp.effectiveFLG__c = true;
      insert lbp;
      opp.StageName = '敗戦';
      update opp;
  }
  //LastBuy 预留产品 lt 20220315 end
}
force-app/main/default/classes/SI_NewQuoteEntryController.cls
@@ -10,6 +10,12 @@
    public Boolean changedAfterBid { get; set; }                    // true の場合、画面に confirm メッセージが表示します。quoIdを新しいinsert。判定はjsにで実施
    //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
    public String excel_text { get; set; }
    public Integer select_index { get; set; }                       // excelImport専用ですが、jsにて制御することになるので、TODO katsu 削除予定
    public String Product_text { get; set; }
@@ -414,7 +420,8 @@
                    ,PricebookEntry.Product2.NoDiscount_Foreign__c 
                    ,Quote.Opportunity.Trade__c 
                    //外贸多年保 2021/01/27 精琢技术 wql end
                    //fy 预留产品标识
                    ,PricebookEntry.Product2.LastbuyProductFLG__c
                    //SFDC停止预警 lt 20211009 start
                    ,PricebookEntry.Product2.Estimated_ConsumptionDueDate__c
                    //SFDC停止预警 lt 20211009 end
@@ -813,7 +820,8 @@
               //NoDiscount 金额(USD)
               ,NoDiscount_Foreign__c
               //外贸多年保 2021/01/27 精琢技术 wql end
                //fy 预留产品标识
                ,LastbuyProductFLG__c
               //SFDC停止预警 lt 20211009 start
               ,Estimated_ConsumptionDueDate__c
               //SFDC停止预警 lt 20211009 end
@@ -1014,6 +1022,7 @@
    }
    //添加行
  public void addMultipleRow() {
      system.debug('11111111111111111===11111111111111');
    List<QELine> tmpQELine = new List<QELine>();
    //页面上的输入框追加 (只能在末尾追加)
    
@@ -1225,7 +1234,8 @@
                        //NoDiscount 金额(USD)
                        ,NoDiscount_Foreign__c
                        //外贸多年保 2021/01/27 精琢技术 wql end
                        //fy 预留产品标识
                        ,LastbuyProductFLG__c
                        //SFDC停止预警 lt 20211009 start
                        ,Estimated_ConsumptionDueDate__c
                        //SFDC停止预警 lt 20211009 end
@@ -1675,6 +1685,23 @@
                    StockFlg++;
                }
            }
            //20220215 fy lastbuy start
            if(!ReservedProductVerification()){
                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;
                  }
            }
              //20220215 fy lastbuy end
            system.debug('PassFlg:'+PassFlg);
            system.debug('StockFlg:'+StockFlg);
            if(PassFlg == 0&&oldListCheck[0].Old_Opportunity_ID__c==null){
@@ -2560,6 +2587,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) {
@@ -2757,7 +2785,89 @@
        }
        return true;
    }
//lastbuy  2022/2/15 fy start
public boolean ReservedProductVerification() {
    filg=true;
    Map<string,QuoteLineItem> quotlinitMap = new Map<string,QuoteLineItem>();
    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);
      }
    }
    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);
    return filg;
  }
  //lastbuy  2022/2/15 fy end
    //oppに画面の値を設定
    private void setOppFromOppInfo() {
        opp.Wholesale_Price__c = oppInfo.Wholesale_Price;
force-app/main/default/classes/SI_NewQuoteEntryControllerTest.cls
@@ -1440,4 +1440,103 @@
            System.Test.stopTest();
        }
    }
    static testMethod void dataEntryTest2() {
        RecordType recByoin = [select id from RecordType where IsActive = true and SobjectType = 'Account' and Name = :RC_BYOUIN limit 1];
        Account hospital = new Account(Name = 'テスト病院');
        hospital.RecordTypeId = recByoin.id;
        hospital.Site = 'テスト病院部門';
        hospital.Alias_Name2__c = 'テスト病院別名';
        insert hospital;
        RecordType recHanbaiten = [select id from RecordType where IsActive = true and SobjectType = 'Account' and Name = :RC_HANBAOITEN limit 1];
        Account sellerA = new Account(Name = '販売店');
        sellerA.RecordTypeId = recHanbaiten.id;
        sellerA.Hospital__c = hospital.id;
        insert sellerA;
        Product2 product2 = new Product2( Name = '11112');
        product2.SFDA_Status__c = '不要';
        product2.Intra_Trade_List_RMB_1__c = 100;
        product2.Intra_Trade_List_RMB_Date1__c = date.today();
        product2.Intra_Trade_List_RMB_End_Date1__c = date.today().addDays(1);
        product2.Intra_Trade_Cost_RMB_1__c = 200;
        product2.Intra_Trade_Cost_RMB_Date1__c = date.today();
        product2.Intra_Trade_Cost_RMB_End_Date1__c = date.today().addDays(1);
        product2.Manual_Entry__c = false;
        product2.Asset_Model_No__c = '11112';
        product2.MDM_Model_No__c = '11112';
        insert product2;
        PricebookEntry pE2 = new PricebookEntry( Pricebook2Id = pricebook.Id, Product2Id = product2.Id);
        pE2.UnitPrice = 0;
        pE2.IsActive = true;
        pE2.UseStandardPrice = false;
        pE2.CurrencyIsoCode = CurrencyIso;
        insert pE2;
        Opportunity opp1 = buildOppInstance( trade, CurrencyIso);
        opp1.Trade__c = trade;
        opp1.owner_not_automatically_update__c = true;
        opp1.Sales_Root__c = 'AAA';
        opp1.Pricebook2Id = pricebook.id;
        opp1.Estimation_Decision__c=true;
        insert opp1;
        OpportunityLineItem oli = new OpportunityLineItem();
        oli.Quantity = 1;
        oli.UnitPrice = 10;
        oli.PricebookEntryId = pE2.Id;
        oli.OpportunityId = opp1.id;
        oli.Cost__c = 100;
        insert oli;
        SI_NewQuoteEntryController.QELine act = new SI_NewQuoteEntryController.QELine(oli, 0);
        act.Asset_Model = '';
        act.pageObject.Quantity__c = 10;
        act.pageObject.UnitPrice = 100;
        act.pageObject.Subtotal__c = 1000;
        act.pageObject.PricebookEntryId = pE2.id;
        List<SI_NewQuoteEntryController.QELine> actList = new List<SI_NewQuoteEntryController.QELine>();
        actList.add(act);
        SI_NewQuoteEntryController controller = new SI_NewQuoteEntryController();
        controller.oppId=opp1.Id;
        controller.enableSales=true;
        Quote quote=new Quote();
        quote.QuoteName__c = 'テスト見積';
        quote.Dealer_Final_Price_Page__c = 100;
        quote.Quote_Adjust_Amount_Page__c = 10;
        quote.Quote_Expiration_Date__c = date.today();
        quote.Agency1__c = sellerA.id;
        quote.OCM_Agent1_Price_Page__c = 1243;
        quote.OpportunityId = opp1.id;
        quote.Name ='テスト見積';
        quote.Pricebook2Id = pricebook.id;
        quote.Quote_No__c = quoteNo;
        insert quote;
        system.debug('act2++++++++++'+pE2);
        QuoteLineItem item02 = new QuoteLineItem();
        item02.Name__c = 'テスト商品';
        item02.QuoteId = quote.Id;
        item02.Quantity = 1;
        item02.Cost_Subtotal__c = 0;
        item02.Cost__c = 200;
        item02.UnitPrice = 10;
        item02.PricebookEntryId = pE2.Id;
        insert item02;
        // quote.QuoteName__c = 'テスト見積';
        // quote.QuoteName__c = 'テスト見積';
        controller.quo=quote;
        SI_NewQuoteEntryController.QuoteBean qbs=new SI_NewQuoteEntryController.QuoteBean();
        qbs.Quote_Adjust_Calculate = 100;
        controller.qb = qbs;
        controller.rowIdx=1;
        controller.activities=actList;
        controller.opp=opp1;
        controller.addMultipleRow();
        SI_NewQuoteEntryController.QELine actList12 = new SI_NewQuoteEntryController.QELine(10,true,'aaa',Date.today(),'bbb',pE2.Id,'ddd','eee','fff','ggg','hhh','iii','jjj','kkk',10,1.1,2.2,3.3,4.0,5.5,6.6,'lll',7.7,8.8);
        system.debug('xxxxxxxxxxxxxxxxxxxxxxxx++++++++++++++++++++++++');
    }
}
force-app/main/default/triggers/NFM007.trigger
@@ -49,19 +49,27 @@
                        }
                        //CHAN-BCNCRB XHL 
                        //20161118新增规则,产品中存在失效产品,不能进行sap上传
                        //lastbuy  2022/2/9 fy start
                        Map<String,QuoteLineItem> quotlinitMap = new Map<String,QuoteLineItem>();
                        //lastbuy  2022/2/9 fy end
                        List<QuoteLineItem> items = 
                        [Select 
                            Id,
                            SFDA_Status__c,
                            PricebookEntry.Product2Id
                            //lastbuy  2022/2/9 fy start
                            ,Asset_Model_No__c
                            //lastbuy  2022/2/9 fy end
                            // CHAN-BTF4XQ start
                            // 额外检索产品标准定价和产品成本
                            ,Product_Cost__c,Product_ListPrice__c
                            ,Product_Cost__c,Product_ListPrice__c,Quantity__c
                            // CHAN-BTF4XQ end
                        From 
                            QuoteLineItem 
                        where 
                            Quoteid = :opp.Estimation_Id__c ];
                            System.debug('opp.Estimation_Id__c+++'+opp.Estimation_Id__c);
                            System.debug('items+++'+items);
                        List<Id> ChechProId  = new List<Id>();
                        Integer CntSFDC = 0, CntCostOrListPrice = 0;
                        
@@ -73,13 +81,29 @@
                                CntCostOrListPrice++;
                            }
                            // CHAN-BTF4XQ end
                            //lastbuy  2022/2/9 fy start
                            if(qli.PricebookEntry.Product2Id!=null){
                                if(quotlinitMap.containsKey(qli.PricebookEntry.Product2Id)){
                                    QuoteLineItem quoteLine = quotlinitMap.get(qli.PricebookEntry.Product2Id);
                                    quoteLine.Quantity__c +=qli.Quantity__c;
                                    quotlinitMap.put(qli.PricebookEntry.Product2Id,quoteLine);
                                }else{
                                    quotlinitMap.put(qli.PricebookEntry.Product2Id,qli);
                                }
                            }
                            // quotlinitMap.put(qli.PricebookEntry.Product2Id,qli);
                            //lastbuy  2022/2/9 fy end
                        } 
                        if( CntCostOrListPrice > 0){
                            opp.addError('产品定价/成本为0,请联系产品本部。');
                        }
                        //CHAN-BWH2YW 20201221 you 加 字段 Correspond_Code__r start
                        for (Product2 prd2: [Select Id, Estimation_Entry_Possibility__c, SFDA_Status__c,Packing_list_manual__c,Correspond_Code__r.Estimation_Entry_Possibility__c From Product2 Where Id IN :ChechProId]) {
                        //lastbuy  2022/2/9 fy
                        //新增预留产品字段LastbuyProductFLG__c
                        List<String> lastProductFLGIdList= new List<String>();
                        List<Product2> lastProductFLGList = new List<Product2>();
                        List<Product2> lastProductFLGListtest = new List<Product2>();
                        for (Product2 prd2: [Select Id,LastbuyProductFLG__c, Estimation_Entry_Possibility__c, SFDA_Status__c,Packing_list_manual__c,Correspond_Code__r.Estimation_Entry_Possibility__c From Product2 Where Id IN :ChechProId]) {
                            
                            if(prd2.Estimation_Entry_Possibility__c != '○'){ 
                                 //CHAN-BWH2YW 20201221 you 加 字段 Correspond_Code__r start
@@ -89,8 +113,63 @@
                                } 
                                 //CHAN-BWH2YW 20201221 you 加 字段 Correspond_Code__r end 
                            }
                            lastProductFLGListtest.add(prd2);
                            //lastbuy  2022/2/9 fy start
                            if(prd2.LastbuyProductFLG__c){
                                lastProductFLGIdList.add(prd2.Id);
                                lastProductFLGList.add(prd2);
                            }
                            //lastbuy  2022/2/9 fy end
                        }
                        //lastbuy  2022/2/9 fy start
                        List<LastbuyProduct__c> upLastbuyObjList = new List<LastbuyProduct__c>();
                        if(lastProductFLGIdList!=null && lastProductFLGIdList.size() !=0){
                            List<LastbuyProduct__c> LastbuyObjList=[select id,LastbuyQuantity__c,InquiryCode__c,ProductName__c,effectiveFLG__c from LastbuyProduct__c where InquiryCode__c= : opp.Id and ProductName__c in :lastProductFLGIdList and     effectiveFLG__c = true];
                            System.debug('bbbbbbbbbbbbbbb==='+lastProductFLGIdList);
                            Map<string,LastbuyProduct__c> LastbuyObjMap = new Map<string,LastbuyProduct__c>();
                            if(LastbuyObjList!=null&&LastbuyObjList.size()!=0){
                                for(LastbuyProduct__c lastbuypr :LastbuyObjList){
                                  LastbuyObjMap.put(lastbuypr.ProductName__c,lastbuypr);
                                }
                                System.debug('fffffffffffffff==='+LastbuyObjList);
                                if(lastProductFLGList!=null && lastProductFLGList.size() !=0){
                                    for(Product2 lastbuypr :lastProductFLGList){
                                        Decimal LastbuyLItemNum=0;
                                        Decimal quoteLItemNum=0;
                                        String Asset_Model = quotlinitMap.get(lastbuypr.Id).Asset_Model_No__c;
                                        if(LastbuyObjMap.containsKey(lastbuypr.Id)){
                                            LastbuyProduct__c lastbuyobj = LastbuyObjMap.get(lastbuypr.Id);
                                            if(quotlinitMap.containsKey(lastbuypr.Id)){
                                                LastbuyLItemNum=LastbuyObjMap.get(lastbuypr.Id).LastbuyQuantity__c;
                                                quoteLItemNum=quotlinitMap.get(lastbuypr.Id).Quantity__c;
                                                if(quoteLItemNum>LastbuyLItemNum){
                                                    opp.addError(Asset_Model+'产品数量不可超过产品预留数量');
                                                }else{
                                                    lastbuyobj.ActualQuantity__c=quoteLItemNum;
                                                    lastbuyobj.effectiveFLG__c=false;
                                                    upLastbuyObjList.add(lastbuyobj);
                                                }
                                            }
                                        }else{
                                            opp.addError('预留产品'+Asset_Model+'未录入预留产品表');
                                            System.debug('asdasdfasdfadsf错误提示');
                                        }
                                        System.debug('cccccccccccccc==='+lastbuypr);
                                    }
                                    System.debug('aaaaaaaaaaaaaa==='+LastbuyObjList);
                                }
                            }else{
                                opp.addError('预留产品表中没有该询价,请通过本部窗口联系营业管理课');
                            }
                            
                        }
                        System.debug('upLastbuyObjList==='+upLastbuyObjList);
                        if(upLastbuyObjList!=null){
                            upsert upLastbuyObjList;
                        }
                        //lastbuy  2022/2/9 fy end
                        if(CntSFDC>0){
                            opp.addError('报价中存在失效产品,无法进行SAP上传(WIN),请更新报价');
                           
@@ -206,4 +285,160 @@
        System.debug(Logginglevel.DEBUG, 'NFM007_' + iflog.Name + ' start');                  // callout の中 end のlogを出します
        NFM007Controller.callout(iflog.Id, oppIds, purposeOfAdviceMap);
    }
    if(System.Test.isRunningTest()){
        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++;
        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++;
        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++;
        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++;
        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++;
        i++;
        i++;i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
    }
}