|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //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; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | 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 | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //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),请更新报价'); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | 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++; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|