GWY
2022-05-21 a3460549533111815e7f73d6cef601a58031525d
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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
public with sharing class AllAssetController {
    
    public String assECcode { get; set; }
    public String assName { get; set; }
    public Asset rec { get; set; }
    public String setId { get; set; }
 
    public List<EquipmentSetInfo> equipmentSetRecords { get; set; }
    public List<EquipmentSetInfo> loanerSetRecords { get; set; }
 
    private Integer dayCount = 0;
 
 
    private Integer Select_Limit = 200;
 
 
 
    public AllAssetController() {
         equipmentSetRecords = new List<EquipmentSetInfo>();
    }
 
    public Integer loanerSetNo {
        get {
            return loanerSetRecords == null ? 0 : loanerSetRecords.size();
        }
    }
 
    public Integer pageRecordNo { 
        get {
            return equipmentSetRecords == null ? 0 : equipmentSetRecords.size();
        }
    }
 
    public void init() {
        List<Asset> assList = [select Id,Name, SerialNumber, Internal_Asset_number__c, OT_Code__c,EC_Code__c, Name__c,ProductName__c,
                            AssetType__c,status,Count_can_allocate_F__c,RecordTypeId,loaner_place__c,Remarks2__c,
                            Rental_Customer__r.Name,Rental_End_Date__c,Description,Rental_Start_Date__c 
                            from Asset 
                            WHERE Id != null AND Equipment_Type__c = 'BS'];
           
           for(Integer i = 0 ;i<assList.size();i++){
               if (i == Select_Limit ){
                   break;
               }
 
               equipmentSetRecords.add(new EquipmentSetInfo(assList[i]));
           }
           this.getLoanerSet();
           rec = new Asset();
           rec.Equipment_Type__c = 'BS';
    }
 
    public void getLoanerSet() {
        // 所有样机Set
        loanerSetRecords = new List<EquipmentSetInfo>();
        List<loaner_Set__c> loanerSetSearch = [select Id, Name, Equipment_Type__c,Remarks__c,SerialNumber__c,Internal_Asset_number__c,Status__c,loaner_place__c,Reservation_information__c
                                                 from  Loaner_Set__c
                                                 WHERE Equipment_Type__c = 'BS'
                                                 order by Name];
        Integer line = 0;
        for(loaner_Set__c ls : loanerSetSearch){
            EquipmentSetInfo li = new EquipmentSetInfo(line, ls);
            loanerSetRecords.add(li);
            line += 1;
        }
        //ApexPages.addmessage(new ApexPages.message(ApexPages.severity.WARNING, 'loanerSetRecords' + loanerSetRecords));
    }
 
     public void getLoanerSetdet() {
        
       
        // 样机set中所有样机
        List<String> loanerSetDetIDList = new List<String>();
        equipmentSetRecords = new List<EquipmentSetInfo>();
        for(Loaner_Set_Detail__c lSD : [SELECT Id,Asset__c FROM Loaner_Set_Detail__c WHERE Loaner_Set__c = :setId]){
            loanerSetDetIDList.add(lSD.Asset__c);
        }
 
        List<Asset> queryList = [select Id,Name, SerialNumber, Internal_Asset_number__c,Name__c,AssetType__c,
                                        OT_Code__c, EC_Code__c, status,Count_can_allocate_F__c,
                                        RecordTypeId,loaner_place__c,Remarks2__c,Rental_Customer__r.Name,Rental_End_Date__c,ProductName__c
                                        ,Description,Rental_Start_Date__c 
                                    from Asset
                                    where Id in :loanerSetDetIDList];
                                   
        // 新明细行做成  
        for (Integer i = 0;  i < queryList.size(); i++) {
            if (i == Select_Limit) {
                break;
            }
                equipmentSetRecords.add(new EquipmentSetInfo(queryList[i]));
             
        }
       
    }
 
      public void searchLoanerApp() {
        //已选择个体管理样机
        List<String> loanerindividualList = new List<String>();
        equipmentSetRecords = new List<EquipmentSetInfo>();
       
        String soql = 'select Id,Name, SerialNumber, Loaner__c,Internal_Asset_number__c, OT_Code__c,EC_Code__c, Name__c,ProductName__c,AssetType__c,';
              soql += ' status,Count_can_allocate_F__c,RecordTypeId,loaner_place__c,Remarks2__c,Rental_Customer__r.Name,Rental_End_Date__c ,Description,Rental_Start_Date__c from Asset WHERE Id != null ';
 
 
        if (!String.isBlank(assName)) {
            soql += ' and Name like \'%' + String.escapeSingleQuotes(assName.trim().replaceAll('%', '\\%')) + '%\'';
        }
        if (!String.isBlank(rec.OT_Code__c)) {
            soql += ' and OT_Code__c like \'%' + String.escapeSingleQuotes(rec.OT_Code__c.trim().replaceAll('%', '\\%')) + '%\'';
        }
        if (!String.isBlank(assECcode)) {
            soql += ' and EC_Code__c like \'%' + String.escapeSingleQuotes(assECcode.trim().replaceAll('%', '\\%')) + '%\'';
        }
       
            soql += ' and Equipment_Type__c = \'BS\'';
       
        if (!String.isBlank(rec.loaner_place__c)) {
            soql += ' and loaner_place__c = \'' + String.escapeSingleQuotes(rec.loaner_place__c) + '\'';
        }
        if (!String.isBlank(rec.Status)) {
            soql += ' and status = \'' + String.escapeSingleQuotes(rec.Status) + '\'';
        }
         if (!String.isBlank(rec.SerialNumber)) {
            soql += ' and SerialNumber like \'%' + String.escapeSingleQuotes(rec.SerialNumber.trim().replaceAll('%', '\\%')) + '%\'';
        }
        if (!String.isBlank(rec.Internal_Asset_number__c)) {
            soql += ' and Internal_Asset_number__c like \'%' + String.escapeSingleQuotes(rec.Internal_Asset_number__c.trim().replaceAll('%', '\\%')) + '%\'';
        }
 
 
 
 
        List<Asset> queryList = Database.query(soql);
        System.debug(soql);
        System.debug(queryList);
        // 新明细行做成
        for (Integer i = 0;  i < queryList.size(); i++) {
            if (i == Select_Limit) {
                break;
            }
                equipmentSetRecords.add(new EquipmentSetInfo(queryList[i]));
             
        }
        System.debug(equipmentSetRecords);
 
    }
 
 
    /* private void makeMessage() {
        if (Over_Limit) {
            ApexPages.addmessage(new ApexPages.message(ApexPages.severity.INFO, '数据超过' + Select_Limit + '件,只显示前' + Select_Limit + '件'));
            Over_Limit = false;
        }
    }*/
 
 
    class EquipmentSetInfo implements Comparable {
         public Boolean check { get; set; }
        public Boolean oldcheck { get; set; }
        public loaner_application_detail__c lad { get; set; }
        public Asset aset { get; set; }
        public Loaner_Set__c lSet { get; set; }
        public Date Rental_Start_Date { get; set; }
        public Date Rental_End_Date { get; set; }
        //最早可借出时间
        public Date earliest_Lend_Date { get; set; }
        public Integer SEdayCount { get; set; }
        public Integer deatilNo { get; set; }
        public Boolean canInput { get; set; }
        public Boolean showNo { get; set; }
        public String remark { get; set; }
        //public Date endDate {get; set; }
        //转借元申请明细标记
        public Boolean firstDet { get; set; }
 
        // 已存产品明细
        public EquipmentSetInfo(loaner_application_detail__c e) {
            check = true;
            oldcheck= true;
            lad = e;
            aset = e.LOANER__r;
            //endDate = aset.Rental_End_Date__c;
            if(String.isNotBlank(lad.Remark__c)){
                remark = lad.Remark__c;
            }else{
                remark = aset.Remarks2__c;
            }
            deatilNo = 1;
            canInput = false;
            firstDet = false;
            if(String.valueOf(aset.RecordTypeId).subString(0,15) == System.label.Asset_Record_Type2){
                showNo = true;
            }else{
                showNo = false;
            }
        }
 
        public EquipmentSetInfo(Integer in_line, Loaner_Set__c e) {
            deatilNo = in_line;
            lSet = e;
 
        }
 
        public EquipmentSetInfo(Asset e) {
            check = false;
            oldcheck = false;
            lad = new loaner_application_detail__c();
            aset = e;
            remark = aset.Remarks2__c;
            firstDet = false;
            if(String.valueOf(aset.RecordTypeId).subString(0,15) == System.label.Asset_Record_Type2){
                canInput = true;
                showNo = true;
            }else{
                //lad.loaner_ApplyNo__c = 1;
                deatilNo = 1;
                canInput = false;
                showNo = false;
            }
        }
        // 排序
        public Integer compareTo(Object compareTo) {
            return null;
        }
    }
}