unknown
2023-04-18 b5f156c53c77becbfc0f8e5f0a1a4be20655f087
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
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
/*
 * @Description: 
 * @version: 
 * @Author: chen jing wu
 * @Date: 2023-04-12 11:16:07
 * @LastEditors: chen jing wu
 * @LastEditTime: 2023-04-14 17:24:54
 */
public with sharing class OpportunityLightingButtonController {
    @AuraEnabled
    public static InitData initForPredictedDateChangeButton(String recordId){
        InitData res = new InitData();
        try {
            Opportunity opportunity = [
            select 
            DirectLossFLG__c,
            Created_Day__c
            from Opportunity where Id =: recordId];
            res.createdDay = opportunity.Created_Day__c;
            res.directLossFLG = opportunity.DirectLossFLG__c;
        } catch (Exception e) {
            System.debug('e:****' + e);
        }
        return res;
    }
    @AuraEnabled
    public static InitData initForAgencyAuthorizeButton(String recordId){
        InitData res = new InitData();
        try {
            Opportunity opportunity = [
                select 
                Agency1_ID_18__c,
                StageName,
                SAP_Send_OK__c,
                Opp_order_Type__c,
                If_Have_170__c,
                If_Have_AH__c,
                Cnt_Lost_cancel_Draft__c,
                Cnt_Lost_cancel_report__c,
                Estimation_Id__c,
                DetailNum__c,
                Estimation_Decision__c,
                Sales_Root__c,
                AcecideCntCheck__c,
                IF_Submit__c ,
                Trade__c,
                Is_Corrosion__c,
                If_Authorizing_Lock__c 
                from Opportunity where Id =: recordId 
            ];
            res.agency1Id = opportunity.Agency1_ID_18__c;
            res.stageName = opportunity.StageName;
            res.sapSendOK = opportunity.SAP_Send_OK__c;
            res.oppOrderType = opportunity.Opp_order_Type__c;
            res.ifHave170 = opportunity.If_Have_170__c;
            res.ifHaveAH = opportunity.If_Have_AH__c;
            res.cntLostCancelDraft = opportunity.Cnt_Lost_cancel_Draft__c;
            res.cntLostCancelReport = opportunity.Cnt_Lost_cancel_report__c;
            res.estimationId = opportunity.Estimation_Id__c;
            res.detailNum = opportunity.DetailNum__c;
            res.estimationDecision = opportunity.Estimation_Decision__c;
            res.salesRoot = opportunity.Sales_Root__c;
            res.acecideCntCheck = opportunity.AcecideCntCheck__c;
            res.ifSubmit = opportunity.IF_Submit__c;
            res.trade = opportunity.Trade__c;
            res.isCorrosion = opportunity.Is_Corrosion__c;
            res.ifAuthorizingLock = opportunity.If_Authorizing_Lock__c;
            String profile18 = UserInfo.getProfileId();
            res.profileId = profile18.substring(0,profile18.length() - 3);
        } catch (Exception e) {
            System.debug('e:****' + e);
        }
        return res;
    }
    @AuraEnabled
    public static InitData initForLoseBidButton(String recordId){
        InitData res = new InitData();
        try {
            Opportunity opportunity = [
                select
                ifOpenBid__c
                from Opportunity where Id =: recordId
            ];
            res.ifOpenBid = opportunity.ifOpenBid__c;
        } catch (Exception e) {
            System.debug('e:****' + e);
        }
        return res;
    }
    @AuraEnabled
    public static InitData initForOLYwinBidButton(String recordId){
        InitData res = new InitData();
        try {
            Opportunity opportunity = [
                select
                ifOpenBid__c
                from Opportunity where Id =: recordId
            ];
            res.ifOpenBid = opportunity.ifOpenBid__c;
        } catch (Exception e) {
            System.debug('e:****' + e);
        }
        return res;
    }
    @AuraEnabled
    public static InitData initForCreateEventButton(String recordId){
        InitData res = new InitData();
        try {
            Opportunity opportunity = [
                select 
                AccountId 
                from Opportunity where Id =: recordId];
            res.accountId = opportunity.AccountId;
        } catch (Exception e) {
            System.debug('e:****' + e);
        }
        return res;
    }
    @AuraEnabled
    public static InitData initFoBeforeOPDPDFBtnButton(String recordId){
        InitData res = new InitData();
        try {
            Opportunity opportunity = [
                select
                AccountId
                from Opportunity where Id =: recordId
            ];
            res.accountId = opportunity.AccountId;
            res.userId = UserInfo.getUserId();
        } catch (Exception e) {
            System.debug('e:****' + e);
        }
        return res;
    }
    @AuraEnabled
    public static InitData initFoBeforeOPDPDFBtnSISButton(String recordId){
        InitData res = new InitData();
        try {
            Opportunity opportunity = [
                select
                AccountId
                from Opportunity where Id =: recordId
            ];
            res.accountId = opportunity.AccountId;
            res.userId = UserInfo.getUserId();
        } catch (Exception e) {
            System.debug('e:****' + e);
        }
        return res;
    }
    @AuraEnabled
    public static InitData initForRequestDBButton(String recordId){
        InitData res = new InitData();
        try {
            Opportunity opportunity = [
                select
                StageName,
                SAP_Send_OK__c,
                Cnt_Lost_cancel_report__c,
                Cnt_Lost_cancel_Draft__c,
                Agency1__c,
                Agency1_ID_18__c,
                Name,
                Bid_Planned_Date__c,
                Sales_assistant_name__c,
                Sales_assistant_ID__c
                from Opportunity where Id =: recordId
            ];
            res.stageName = opportunity.StageName;
            res.sapSendOK = opportunity.SAP_Send_OK__c;
            res.cntLostCancelReport = opportunity.Cnt_Lost_cancel_report__c;
            res.cntLostCancelDraft = opportunity.Cnt_Lost_cancel_Draft__c;
            res.agency1 = opportunity.Agency1__c;
            res.agency1Id = opportunity.Agency1_ID_18__c;
            res.name = opportunity.Name;
            res.bidPlannedDate = opportunity.Bid_Planned_Date__c;
            res.salesAssistantName = opportunity.Sales_assistant_name__c;
            res.salesAssistantID = opportunity.Sales_assistant_ID__c;
            String profileId18 = UserInfo.getProfileId();
            res.profileId = profileId18.substring(0, profileId18.length() - 3);
        } catch (Exception e) {
            System.debug('e:****' + e);
        }
        return res;
    }
    @AuraEnabled
    public static InitData initForCancelReportButton(String recordId){
        InitData res = new InitData();
        try {
        Opportunity opportunity = [
            select
            StageName,
            SAP_Send_OK__c,
            Cnt_Lost_cancel_report__c,
            Cnt_Lost_cancel_Draft__c,
            Job_category__c,
            Bidding_Project_Name_Bid__c,
            Name,
            Sales_assistant_name__c,
            Sales_assistant_ID__c,
            Manager_name__c,
            Sales_manager_departmentID__c,
            Sales_owner_buchang__c,
            Sales_owner_buchangID__c
            from Opportunity where Id =: recordId
        ];
        res.stageName = opportunity.StageName;
        res.sapSendOK = opportunity.SAP_Send_OK__c;
        res.cntLostCancelReport = opportunity.Cnt_Lost_cancel_report__c;
        res.cntLostCancelDraft = opportunity.Cnt_Lost_cancel_Draft__c;
        res.jobCategory = opportunity.Job_category__c;
        res.biddingProjectNameBid = opportunity.Bidding_Project_Name_Bid__c;
        res.name = opportunity.Name;
        res.salesAssistantName = opportunity.Sales_assistant_name__c;
        res.salesAssistantID = opportunity.Sales_assistant_ID__c;
        res.managerName = opportunity.Manager_name__c;
        res.salesManagerDepartmentID = opportunity.Sales_manager_departmentID__c;
        res.salesOwnerBuchang = opportunity.Sales_owner_buchang__c;
        res.salesOwnerBuchangID = opportunity.Sales_owner_buchangID__c;
        } catch (Exception e) {
            throw new AuraHandledException(e.getMessage());
        }
        return res;
    }
    @AuraEnabled
    public static InitData initForLostReportButton(String recordId){
        InitData res = new InitData();
        try {
            Opportunity opportunity = [
                select
                StageName,
                SAP_Send_OK__c,
                Cnt_Lost_cancel_report__c,
                Name,
                Sales_assistant_name__c,
                Sales_assistant_ID__c,
                Manager_name__c,
                Sales_manager_departmentID__c,
                Sales_owner_buchang__c,
                Sales_owner_buchangID__c
                from Opportunity where Id =: recordId
            ];
            res.stageName = opportunity.StageName;
            res.sapSendOK = opportunity.SAP_Send_OK__c;
            res.cntLostCancelReport = opportunity.Cnt_Lost_cancel_report__c;
            res.name = opportunity.Name;
            res.salesAssistantName = opportunity.Sales_assistant_name__c;
            res.salesAssistantID = opportunity.Sales_assistant_ID__c;
            res.managerName = opportunity.Manager_name__c;
            res.salesManagerDepartmentID = opportunity.Sales_manager_departmentID__c;
            res.salesOwnerBuchang = opportunity.Sales_owner_buchang__c;
            res.salesOwnerBuchangID = opportunity.Sales_owner_buchangID__c;
        } catch (Exception e) {
            throw new AuraHandledException(e.getMessage());
        }
        return res;
    }
    @AuraEnabled
    public static InitData initForQuotationRequestButton(String recordId){
        InitData res = new InitData();
        try {
            Opportunity opportunity = [
                select
                Bidding_Project_Name_Bid__r.Id,
                Estimation_Id__c
                from Opportunity where Id =: recordId
            ];
            res.biddingProjectNameBidId = opportunity.Bidding_Project_Name_Bid__r.Id;
            res.estimationId = opportunity.Estimation_Id__c;
        } catch (Exception e) {
            throw new AuraHandledException(e.getMessage());
        }
        return res;
    }
    @AuraEnabled
    public static InitData initForStockApplyButton(String recordId){
        InitData res = new InitData();
        try {
            Opportunity opportunity = [
                select
                Stock_apply_status__c,
                Last_opportunity_file__r.Id
                from Opportunity where Id =: recordId
            ];
            res.stockApplyStatus = opportunity.Stock_apply_status__c;
            res.lastOpportunityFileId = opportunity.Last_opportunity_file__r.Id;
        } catch (Exception e) {
            throw new AuraHandledException(e.getMessage());
        }
        return res;
    }
    @AuraEnabled
    public static InitData initForQuotationProductNewButton(String recordId){
        InitData res = new InitData();
        try {
            Opportunity opportunity = [
                select
                CurrencyIsoCode
                from Opportunity where Id =: recordId
            ];
            res.currencyIsoCode = opportunity.CurrencyIsoCode;
        } catch (Exception e) {
            throw new AuraHandledException(e.getMessage());
        }
        return res;
    }
    @AuraEnabled
    public static string updateForAgencyAuthorizeButton(String recordId){
        try {
            Opportunity opp = new Opportunity();
            opp.Id = recordId;
            opp.If_Authorizing__c = true;
            opp.if_Interface_Lock__c = true;
            opp.IF_Submit__c = true;
            update opp;
            return null;
        } catch (Exception e) {
            String eMessage = e.getMessage();
            Integer left  = eMessage.indexOf(',') + 1;
            Integer right = eMessage.length();
            return eMessage.substring(left,right);
        }
    }
    @AuraEnabled
    public static string updateForLoseBidButton(String recordId){
        try {
            Opportunity opp = new Opportunity();
            opp.Id = recordId;
            opp.ConfirmationofAward__c = LightingButtonConstant.OPPORTUNITY_CONFIRMATION_OF_AWARD_LOSE_BID;
            update opp;
            return null;
        } catch (Exception e) {
            String eMessage = e.getMessage();
            Integer left = eMessage.indexOf(',') + 1;
            Integer right = eMessage.length();
            return eMessage.substring(left,right);
        }
    }
    @AuraEnabled
    public static string updateForOLYwinBidButton(String recordId){
        try {
            Opportunity opp = [select ConfirmationofAward__c,Closing_Bid_Date__c from Opportunity where Id =: recordId];
            opp.ConfirmationofAward__c = LightingButtonConstant.OPPORTUNITY_CONFIRMATION_OF_AWARD_OLY_WIN_BID;
            if (opp.Closing_Bid_Date__c == null) {
                opp.Closing_Bid_Date__c = Date.today();
            }
            update opp;
            return null;
        } catch (Exception e) {
            String eMessage = e.getMessage();
            Integer left = eMessage.indexOf(',') + 1;
            Integer right = eMessage.length();
            return eMessage.substring(left,right);
        }
    }
    @AuraEnabled
    public static string updateForStockApplyButton(String recordId,Boolean flag){
        try {
            Opportunity opp = new Opportunity();
            opp.Id = recordId;
            if(flag){
                opp.Stock_apply_status__c  = '填写完毕';
            }else {
                opp.Stock_apply_status__c = '草案中';
            }
            update opp;
            return null;
        } catch (Exception e) {
            String eMessage = e.getMessage();
            Integer left = eMessage.indexOf(',') + 1;
            Integer right = eMessage.length();
            return eMessage.substring(left,right);
        }
    }
    @AuraEnabled
    public static List<InquiryPredictsDateChange__c> queryForPredictedDateChangeButton(String recordId){
        List<InquiryPredictsDateChange__c> rac = null;
        try {
            rac = [
                select 
                id 
                from InquiryPredictsDateChange__c where Predicted_Date_Status__c = :LightingButtonConstant.PREDICTED_DATE_STATUS and Opportunity__c =:recordId];
        } catch (Exception e) {
            System.debug('e:****' + e);
        }
        return rac;
    }
    @AuraEnabled
    public static List<task__c> queryForLoseBidButton(String recordId){
        List<task__c> tasks = null;
        try {
            String obscureName = '%' + LightingButtonConstant.TASK_NAME_BY_CONFIRMATION_OF_WINNING_BID + '%';
            tasks = [
                select
                taskStatus__c
                from task__c where OpportunityId__c =: recordId and name like :obscureName];
        } catch (Exception e) {
            System.debug('e:****' + e);
        }
        return tasks;
    }
    @AuraEnabled
    public static List<task__c> queryForOLYwinBidButton(String recordId){
        List<task__c> tasks = null;
        try {
            String obscureName = '%' + LightingButtonConstant.TASK_NAME_BY_CONFIRMATION_OF_WINNING_BID + '%';
            tasks = [
                select
                taskStatus__c
                from task__c where OpportunityId__c =: recordId and name like :obscureName];
        } catch (Exception e) {
            System.debug('e:****' + e);
        }
        return tasks;
    }
    @AuraEnabled
    public static List<Tender_Opportunity_Link__c> queryForCancelReportButton(String recordId){
        List<Tender_Opportunity_Link__c> links = null;
        try {
            links = [
                select id,
                Tender_information__r.subInfoType__c
                from Tender_Opportunity_Link__c 
                where (Tender_information__r.subInfoType__c = '3-1:废标公告' OR Tender_information__r.subInfoType__c ='3-2:流标公告') and Opportunity__c =: recordId
            ];
        } catch (Exception e) {
            System.debug('e:****' + e);
        }
        return links;
    }
    @AuraEnabled
    public static List<QuoteIrai__c > queryForQuotationRequestButton(String recordId){
        List<QuoteIrai__c> quotes = null;
        try {
            String opportunityId = '%' + recordId + '%';
            quotes = [
                select 
                id 
                from QuoteIrai__c where Note__c like :opportunityId and QuoteIrai_Status__c = '草案中'
            ];
        } catch (Exception e) {
            System.debug('e:****' + e);
        }
        return quotes;
    }
    public class InitData{
        @AuraEnabled
        public Boolean directLossFLG;
        @AuraEnabled
        public Date createdDay;
        @AuraEnabled
        public String agency1Id;
        @AuraEnabled
        public String agency1;
        @AuraEnabled
        public String stageName;
        @AuraEnabled
        public Boolean sapSendOK;
        @AuraEnabled
        public String oppOrderType;
        @AuraEnabled
        public Boolean ifHave170;
        @AuraEnabled
        public Boolean ifHaveAH;
        @AuraEnabled
        public Decimal cntLostCancelDraft;
        @AuraEnabled
        public Decimal cntLostCancelReport;
        @AuraEnabled
        public String estimationId;
        @AuraEnabled
        public Decimal detailNum;
        @AuraEnabled
        public Boolean estimationDecision;
        @AuraEnabled
        public String salesRoot;
        @AuraEnabled
        public Boolean acecideCntCheck;
        @AuraEnabled
        public Boolean ifSubmit;
        @AuraEnabled
        public String trade;
        @AuraEnabled
        public Boolean isCorrosion;
        @AuraEnabled
        public Boolean ifAuthorizingLock;
        @AuraEnabled
        public String profileId;
        @AuraEnabled
        public String ifOpenBid;
        @AuraEnabled
        public String accountId;
        @AuraEnabled
        public String userId;
        @AuraEnabled
        public String name;
        @AuraEnabled
        public Date bidPlannedDate;
        @AuraEnabled
        public String salesAssistantName;
        @AuraEnabled
        public String salesAssistantID;
        @AuraEnabled
        public String jobCategory;
        @AuraEnabled
        public String biddingProjectNameBid;
        @AuraEnabled
        public String managerName;
        @AuraEnabled
        public String salesManagerDepartmentID;
        @AuraEnabled
        public String salesOwnerBuchang;
        @AuraEnabled
        public String salesOwnerBuchangID;
        @AuraEnabled
        public String biddingProjectNameBidId;
        @AuraEnabled
        public String stockApplyStatus;
        @AuraEnabled
        public String lastOpportunityFileId;
        @AuraEnabled
        public String currencyIsoCode;
    }
}