Thhto
2022-11-17 ea6a4eec81a6a74e214aefc5971d701242c3e7d3
force-app/main/default/classes/SI_NewQuoteEntryController.cls
@@ -12,6 +12,8 @@
    //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; }
@@ -365,8 +367,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,
                        CreatedByid,Queto_Confirm_Date__c,
                        QuoteToName,Quote_Expiration_Date__c,Quote_Comment__c,Stocking_Price__c,Unit_Price__c,
@@ -418,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
@@ -430,6 +433,7 @@
            if (copyQuoId == null) {
                    quo = quoList[0];
                    quoteOwner = quo.CreatedByid;
                    //SWAG-C5DBAL  【委托】 [紧急]SI询价肖寒无法修改报价单  精琢技术  2021/07/30 start
                    //注释原逻辑
                    if(quo.Queto_Confirm_Date__c != null ||
@@ -714,6 +718,11 @@
        }
        // vivek end
        system.debug('初始化时的集合:'+activities);
         //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;
     }
@@ -817,7 +826,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
@@ -1230,7 +1240,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
@@ -1682,9 +1693,19 @@
            }
            //20220215 fy lastbuy start
            if(!ReservedProductVerification()){
                errorflg = true;
                errormessage =  '产品数量不可超过产品预留数量' ;
                return null;
                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);
@@ -2002,7 +2023,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;
        }
@@ -2274,11 +2301,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;
@@ -2455,8 +2482,8 @@
            }
        } else {
            List<Quote> qs = New List<Quote>();
            qs = [select Id,OpportunityId,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,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,
@@ -2543,6 +2570,12 @@
        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 = '';
@@ -2774,26 +2807,79 @@
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,effectiveFLG__c from LastbuyProduct__c where InquiryCode__c= : oppId and ProductName__c in :lastProductFLGList and  effectiveFLG__c= true];
        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);