buli
2022-05-13 2f4492ee18f90274582fcc2bb06f5e9bf64136e8
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
public without sharing class QuoteTriggerHandler {
 
    public static void setDealerGroup(List<Quote> newList, Map<Id, Quote> newMap, List<Quote> oldList, Map<Id, Quote> oldMap) {
        List<String> oppIdList = new List<String>();
        for (Quote newQuote : newList) {
            oppIdList.add(newQuote.OpportunityId);
        }
 
        if (oppIdList.size() > 0) {
            List<OpportunityTeamMember> otmList = [select Id, UserId, User.ProfileId from OpportunityTeamMember where opportunityId = :oppIdList];
            List<OpportunityTeamMember> delList = new List<OpportunityTeamMember>();
            for (OpportunityTeamMember otm : otmList) {
                String profileId = otm.User.ProfileId;
                if (profileId.substring(0, 15) == System.Label.RT_BS_No_Price ||
                    profileId.substring(0, 15) == System.Label.RT_BS_No_Price_Email) {
                    delList.add(otm);
                }
            }
 
            if (delList.size() > 0) delete delList;
    }
 
       
    }
 
    public static void setPaymetTerms(List<Quote> newList, Map<Id, Quote> newMap, List<Quote> oldList, Map<Id, Quote> oldMap){
        System.debug('1111');
        Map<String,Quote> oppMap = new Map<String,Quote>();
        //String quoId = '';
        for (Quote newQuote : newList) {
            Quote old = oldMap.get(newQuote.Id);
            System.debug(newQuote.PaymentTerms__c);
            System.debug(old.PaymentTerms__c);
            if(newQuote.PaymentTerms__c != old.PaymentTerms__c){
                oppMap.put(newQuote.OpportunityId, newQuote);
            }
           /* if(newQuote.ProductSegment__c == 'BS' && newQuote.Is_Decided__c != oldMap.get(newQuote.iD).Is_Decided__c){
                quoId = newQuote.Id;
            }*/
        }
        System.debug(oppMap.keySet().size());
        if(oppMap.keySet().size()>0){
            System.debug(oppMap.keySet());
            List<Order> orderList = [select Id,OpportunityId from Order where Status__c = 'Active' and OpportunityId = :oppMap.keySet()];
            System.debug(orderList);
            if(orderList.size() > 0){
                System.debug('22222222222');
                for(Order odr : orderList){
                    odr.PaymentTerms__c = oppMap.get(odr.OpportunityId).PaymentTerms__c;
                }
                System.debug(orderList);
                update orderList;
            }
        }
 
        /*if(quoId != '' && quoId != null){
            List<QuoteLineItem> qliList = [select id,DontSingleProduct__c from QuoteLineItem where QuoteId = :quoId];
            String temp = '';
            for(QuoteLineItem qli : qliList){
                if(qli.DontSingleProduct__c != '1'){
                    temp+=(' '+qli.DontSingleProduct__c);
                }
            }
            Quote quo = new Quote();
            quo.id = quoId;
            quo.DontSingleProductCode__c = temp;
 
            if(temp.length() >0) update quo;
        }*/
    }
 
    public static void setDontSingleProductCode(List<Quote> newList, Map<Id, Quote> newMap, List<Quote> oldList, Map<Id, Quote> oldMap){ 
        //String quoId = '';
 
        Quote quo = newList[0];
        // Opportunity opp = [select Id,Dealer__c from Opportunity where Id = :quo.OpportunityId];
        // if(opp.Dealer__c != '0012800001HoORb' && opp.Dealer__c != '0012800001HoPY4' && opp.Dealer__c != '0012800001HoPaz'){
        // WLIG-BVP4L2 触发101 新建一个公式字段OppDealer__c,去掉上面的检索
        if(quo.OppDealer__c != '0012800001HoORb' && quo.OppDealer__c != '0012800001HoPY4' && quo.OppDealer__c != '0012800001HoPaz'){
 
            //if(quo.ProductSegment__c == 'BS' && quo.Is_Decided__c != oldMap.get(quo.Id).Is_Decided__c && quo.Is_Decided__c == true){
                List<QuoteLineItem> qliList = [select id,DontSingleProduct__c from QuoteLineItem where QuoteId = :quo.Id];
                String temp = '';
                for(QuoteLineItem qli : qliList){
                    if(qli.DontSingleProduct__c != '1'){
                        temp+=(' '+qli.DontSingleProduct__c);
                    }
                }
                quo.DontSingleProductCode__c = temp;
           // }
        }
 
    }
 
    public static void check(List<Quote> newList, Map<Id, Quote> newMap, List<Quote> oldList, Map<Id, Quote> oldMap){
        //if(newList[0].Is_Decided__c == true){
            String quoid =  newList[0].id;
            List<QuoteLineItem> qliList= [select id,Product2.NMPAStatus__c,Product2.ProductCode,Product2.ProductStatusFormula__c,QuoLiOrderIsChange__c,quoLiVerifyProductValid__c from QuoteLineItem where QuoteId = :quoid];
            String str = '';
            Boolean isok = true;
            for(QuoteLineItem qli : qliList){
                // WLIG-BTA8C2 XHL 20200925 -Start
                // 合同变更 并且 报价产品的 验证产品有效性 为 false 时跳过验证
                if (qli.QuoLiOrderIsChange__c && qli.quoLiVerifyProductValid__c == false) {
                // WLIG-BTA8C2 XHL 20200925 -End
                } else {
                    if(qli.Product2.ProductStatusFormula__c == '0' ){
                        if(newList[0].Is_Decided__c == true && oldList[0].Is_Decided__c == false){
                            str += (' '+qli.Product2.ProductCode);
                            isok = false;
                        }else{
                            
                        }
                    }   
                }
                
            }
            if(isok == false){
                newList[0].addError(str + '产品状态不正确。');
            }
        //}
 
   } 
 
}