buli
2022-05-14 ead4df22dca33a867279471821ca675f91dec760
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
public class SearchSetProductController {
    
    public List<productSet__c> cl {get;set;}
 
    public String SearchName {get;set;}
    public String SearchCode {get;set;}
 
    public Integer activitiesSize {get;set;}
    public List<QELine> activities {get;set;}
    public String setPFString {get;set;}
    public String gainQuoteSetNameAndSetQty;
    public Map<String,Decimal> setNameAndSetQtyMap;
    public Map<String,Decimal> setNameAndSetDiscountMap;
    public SearchSetProductController(){
        this.setNameAndSetQtyMap = new Map<String,Decimal>();
        this.setNameAndSetDiscountMap = new Map<String,Decimal>();
        cl = new List<productSet__c>();
        //获取从前一个页面传过来的"产品配套名称"和"产品配套数量"
        this.gainQuoteSetNameAndSetQty = Apexpages.currentPage().getParameters().get('gainQuoteSetNameAndSetQty');
        system.debug('gainQuoteSetNameAndSetQty_Test_0_' + gainQuoteSetNameAndSetQty);
        if (gainQuoteSetNameAndSetQty.length() >0) {
 
            for (String setNameAndSetQty : gainQuoteSetNameAndSetQty.split(';')) {
                setNameAndSetQtyMap.put(setNameAndSetQty.split(',')[0],Decimal.valueOf(setNameAndSetQty.split(',')[1]));
                setNameAndSetDiscountMap.put(setNameAndSetQty.split(',')[0], Decimal.valueOf(setNameAndSetQty.split(',')[2]));
            }
        }
        system.debug('setNameAndSetQtyMap_Test_0_' + setNameAndSetQtyMap);
    }
  public SearchSetProductController(ApexPages.StandardController controller){
    this();    
  }
 
  public void init(){
    system.debug('gainQuoteSetNameAndSetQty_Test' + gainQuoteSetNameAndSetQty);
    system.debug('setNameAndSetQtyMap_Test' + setNameAndSetQtyMap);
    activitiesSize = 0;
    
    searchproductSet();
    activitiesSize = activities.size();
  } 
 
    public PageReference searchproductSet() {
 
        //查找有效的"产品配套"
        cl = [Select id, Name,Code__c From productSet__c Where  IsValid__c = true order by Name];
 
        activities = new List<QELine>();
        List<QELine> selectedActivities = new List<QELine>();
        //将上个页面传过来的产品配套选中,并放到前面
        for(productSet__c psl : cl){            
            if (setNameAndSetQtyMap.containsKey(psl.Name)) {
                QELine a = new QELine(psl);
                a.Quantity =  setNameAndSetQtyMap.get(psl.Name);
                a.QuantityReference = setNameAndSetQtyMap.get(psl.Name);
                a.Discount = setNameAndSetDiscountMap.get(psl.Name);
                a.isSelected = true;
                selectedActivities.add(a);  
            } 
        
        }
        for(productSet__c psl : cl){
            
            if (!setNameAndSetQtyMap.containsKey(psl.Name)) {
                QELine a = new QELine(psl);
                a.Quantity = 0;
                a.QuantityReference = 0;
                a.Discount = 0 ;
                selectedActivities.add(a); 
            } else {
                continue;
            } 
        }
        activities = selectedActivities;
        return null;   
    } 
 
    public PageReference serContact(){
        
        String searchSql = 'Select id,Code__c,Name From productSet__c ';
        String whereStr = 'Where  IsValid__c = true ';
        String whereSql = '';
 
        if(SearchName != null && SearchName != ''){
            whereSql += ' and Name Like ' + '\'%' + SearchName + '%\' ';
        }
 
        if(SearchCode != null && SearchCode != ''){
          whereSql += 'and Code__c like ' + '\'%' + SearchCode + '%\' ';
        }
 
        searchSql = searchSql + whereStr + whereSql;
 
        searchSql += ' order by Code__c limit 500';
 
        cl = Database.query(searchSql);
 
        Map<String,QELine> selectedQELineMap = new Map<String,QELine>();
        if (activities.size() >0 ) {
            for (QELine  q :activities) {
                if (q.isSelected == true) {
                    selectedQELineMap.put(q.setProductidFull, q);
                } 
            }
        }
 
        for(productSet__c psl : cl){
            
            if (!setNameAndSetQtyMap.containsKey(psl.Name)) {
                QELine a = new QELine(psl);
                if (selectedQELineMap.containsKey(a.setProductidFull)) {
                    continue;
                } else {
                    a.Quantity = 0 ;
                    selectedQELineMap.put(a.setProductidFull, a);
                }
                
            } else {
                continue;
            }
            
            
        }
        activities = selectedQELineMap.values();
        return null;
  }
  public void SelectDone(){
    setPFString = '';
    String idAndQuantity ;
 
    for (QELine arc :activities) {
 
        if(arc.isSelected==true){
            
            if (arc.Quantity > 0) {
                idAndQuantity = arc.setProductidFull +','+ arc.Quantity +','+ arc.Discount;
                
                if(String.isblank(setPFString)||setPFString==null){
                    
                    setPFString = idAndQuantity;
                }else{
                    
                    setPFString = setPFString +';'+ idAndQuantity;
                }
            }
            
        }
    }
    
  }
 
    public class QELine {
        public Boolean isSelected {get;set;}
        public String setProductidFull { get; set; }
        public Decimal Quantity { get; set; }
        public Decimal QuantityReference { get; set; }
        public Decimal Discount { get; set; }
        public String Name { get; set; }       
        public String Code { get; set; }
 
        public QELine(productSet__c psl) {
            isSelected = false;
            setProductidFull = psl.id;
            Name = psl.Name;
            Code = psl.Code__c;
            
        }
    }
}