高章伟
2022-02-18 8b5f4c6c281cfa548f92de52c8021e37aa81901e
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
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
public with sharing class NewPaymentPlanLoadController {
    public String idl {get; set;}
    public Maintenance_Contract__c PageMCEElement {get; set;}
    public Datetime testDateTime {set; get;}
    public String statusSave {get; set;}
    public Boolean printContract { get; private set; }
    public Boolean printTripartite { get; private set; }
    public Boolean printAgent { get; private set; }
    //HWAG-BHT7XX 2019/11/26 START
    public Boolean agreeUpperLimit { get; private set; }
    //HWAG-BHT7XX 2019/11/26 END
    // fxk 2021/8/31 点检次数必须填 Star
    // public boolean saveErrorflag { get; private set; }
    // fxk 2021/8/31 点检次数必须填 end
    // 新增点检总次数(只在页面中显示)fxk 2021/9/2 Star
    public Integer Contract_validMonth {get; set;}
    // 新增点检总次数(只在页面中显示)fxk 2021/9/2 End
 
    public NewPaymentPlanLoadController() {
        idl = ApexPages.currentPage().getParameters().get('id');
    }
    public void init() {
        statusSave = 'Fin';
        testDateTime = system.now();
        //
        List<Maintenance_Contract__c> PageMCE = [select
                                                id,
                                                Name,
                                                Service_Contract_Staff__c,
                                                Payment_Plan_Sum_First__c,
                                                Payment_Plan_Date_First__c,
                                                Payment_Plan_Sum_Fifth__c,
                                                Payment_Plan_Date_Fifth__c,
                                                Payment_Plan_Sum_Third__c,
                                                Payment_Plan_Date_Third__c,
                                                Payment_Plan_Sum_Forth__c,
                                                Payment_Plan_Date_Forth__c,
                                                Payment_Plan_Sum_Second__c,
                                                Payment_Plan_Date_Second__c,
                                                Payment_Plan_Sum_Sixth__c,
                                                Payment_Plan_Date_Sixth__c,
                                                MainLeaderManager__c,
                                                Service_Contract_Staff__r.JingliApprovalManager__c,
                                                User_Salesdepartment__c,
                                                User_Salesdepartment_Sec__c,
                                                Service_Contract_Staff__r.Salesdepartment__c,
                                                Is_Standard_Contract__c,
                                                Small_Repair_Time__c,
                                                Big_Repair_Time__c,
                                                Live_Technical_Support_Time__c,
                                                Engineer_Name__c,
                                                Phone_Number__c,
                                                Tour_Check__c,
                                                Inspection_Time__c,
                                                Dedust__c,
                                                // fxk
                                                Contract_End_Date__c,
                                                Contract_Start_Date__c,
                                                Contract_Range__c,
                                                Contract_Limit_Times__c,
                                                Service_contract_target_number__c,
                                                // fxk
                                                Negotiate_Mean__c,
                                                First_Party_Contract_Number__c,
                                                Second_Party_Contract_Number__c,
                                                Term_Of_Payment__c,
                                                one_off_payment_agreed_period__c,
                                                Contract_Amount__c,
                                                Total_Contract_Amount_In_Words__c,
                                                Service_Contract_Staff__r.Name,
                                                Total_Payment_Time__c,
                                                Payment_Plan_Sum_First_in_Word__c,
                                                Payment_Plan_Sum_Second_in_Word__c,
                                                Payment_Plan_Sum_Third_in_Word__c,
                                                Payment_Plan_Sum_Forth_in_Word__c,
                                                Payment_Plan_Sum_Fifth_in_Word__c,
                                                Payment_Plan_Sum_Sixth_in_Word__c,
                                                Estimation_Id__c,
                                                Estimation_Id__r.Estimate_Target__c,
                                                Estimate_Target__c,
                                                Status__c,
                                                //HWAG-BHT7XX 2019/11/26 START
                                                agree_Upper_limit__c,
                                                Amount_Warranty_Coverage__c,
                                                Amount_Warranty_Coverage_In_Word__c,
                                                //HWAG-BHT7XX 2019/11/26 END
                                                Decided_Estimation__c
                                                from
                                                Maintenance_Contract__c
                                                where
                                                id = :idl];
        //权限管理-Denid
        if (PageMCE.size() == 1) {
            //if(PageMCE[0].Service_Contract_Staff__c != UserInfo.getUserId() && UserInfo.getProfileId() != System.Label.ProfileId_SystemAdmin && UserInfo.getProfileId() != System.Label.ProfileId_IThelp){
            //    ApexPages.addmessage(new ApexPages.message(ApexPages.severity.WARNING, '没有付款计划的编辑权限'));
            //    PageMCEElement = new Maintenance_Contract__c();
            //}else{
 
            PageMCEElement = PageMCE[0];
            //HWAG-BHT7XX 2019/11/26 START
            agreeUpperLimit = PageMCE[0].agree_Upper_limit__c ;
            //HWAG-BHT7XX 2019/11/26 END
            // fxk 2021/8/31 点检次数必须选 Star
            // if (PageMCEElement.Inspection_Time__c == null || ''.equals(PageMCEElement.Inspection_Time__c) || '0'.equals(PageMCEElement.Inspection_Time__c)) {
            //     PageMCEElement.Inspection_Time__c = '1';
            // }
            // fxk 2021/8/31 点检次数必须选 end
            if (PageMCEElement.Small_Repair_Time__c == null) {
                PageMCEElement.Small_Repair_Time__c = '48';
 
            }
            if (PageMCEElement.Big_Repair_Time__c == null) {
                PageMCEElement.Big_Repair_Time__c = '15';
 
            }
            if (PageMCEElement.Live_Technical_Support_Time__c == null) {
                PageMCEElement.Live_Technical_Support_Time__c = '48';
 
            }
            if (PageMCEElement.Engineer_Name__c == null && PageMCEElement.Service_Contract_Staff__r.Name != null ) {
                PageMCEElement.Engineer_Name__c = PageMCEElement.Service_Contract_Staff__r.Name.replaceAll(' ', '');
            }
            if (PageMCEElement.First_Party_Contract_Number__c == null) {
                PageMCEElement.First_Party_Contract_Number__c = '2';
            }
            if (PageMCEElement.Second_Party_Contract_Number__c == null) {
                PageMCEElement.Second_Party_Contract_Number__c = '1';
            }
 
            //}
 
        } else {
            ApexPages.addmessage(new ApexPages.message(ApexPages.severity.WARNING, '找不到对应的维修合同'));
            statusSave = 'Denied';
        }
        //fxk 新加点检总次数 2021.9.2 Star
        if (PageMCEElement.Contract_End_Date__c != null || PageMCEElement.Contract_Start_Date__c != null) {
            Contract_validMonth = Integer.valueOf(PageMCEElement.Contract_Range__c);
            // Contract_validMonth = PageMCEElement.Contract_Start_Date__c.monthsBetween(PageMCEElement.Contract_End_Date__c);
            System.debug('Contract_validMonth:'+Contract_validMonth);
        }
        //fxk 新加点检总次数 2021.9.2 End
    }
 
    public List<SelectOption> getSmall_Repair_Time() {
        List<SelectOption> options = new List<SelectOption>();
        options.add(new SelectOption('24', '24'));
        options.add(new SelectOption('48', '48'));
        options.add(new SelectOption('72', '72'));
 
        return options;
    }
 
    public List<SelectOption> getTour_Check() {
        List<SelectOption> options = new List<SelectOption>();
        options.add(new SelectOption('0', '0'));
        options.add(new SelectOption('1', '1'));
        options.add(new SelectOption('2', '2'));
        options.add(new SelectOption('3', '3'));
        options.add(new SelectOption('4', '4'));
        // del fxk 2021.9.2 删除多余的点检次数 Star
        return options;
    }
    public List<SelectOption> getTotal_Payment_Time() {
        List<SelectOption> options = new List<SelectOption>();
        options.add(new SelectOption('1', '1'));
        options.add(new SelectOption('2', '2'));
        options.add(new SelectOption('3', '3'));
        options.add(new SelectOption('4', '4'));
        options.add(new SelectOption('5', '5'));
        options.add(new SelectOption('6', '6'));
        return options;
    }
 
 
    public List<SelectOption> getTerm_Of_Payment() {
        List<SelectOption> options = new List<SelectOption>();
        options.add(new SelectOption('一次性付款', '一次性付款'));
        options.add(new SelectOption('多次付款', '多次付款'));
        return options;
    }
 
    public List<SelectOption> getFirst_Party_Contract_Number() {
        List<SelectOption> options = new List<SelectOption>();
        options.add(new SelectOption('1', '1'));
        options.add(new SelectOption('2', '2'));
        options.add(new SelectOption('3', '3'));
        options.add(new SelectOption('4', '4'));
        options.add(new SelectOption('5', '5'));
        options.add(new SelectOption('6', '6'));
        options.add(new SelectOption('7', '7'));
        options.add(new SelectOption('8', '8'));
        options.add(new SelectOption('9', '9'));
        options.add(new SelectOption('10', '10'));
        return options;
    }
 
    public boolean getCheck_Of_Payment() {
        boolean Check_Of_Payment = true;
        if (PageMCEElement.Term_Of_Payment__c != null && '多次付款'.equals(PageMCEElement.Term_Of_Payment__c)) {
            Check_Of_Payment = false;
        }
        return Check_Of_Payment;
    }
 
    public List<SelectOption> getDedust() {
        List<SelectOption> options = new List<SelectOption>();
        options.add(new SelectOption('0', '0'));
        options.add(new SelectOption('1', '1'));
        options.add(new SelectOption('2', '2'));
        return options;
    }
    public List<SelectOption> getNegotiate_Mean() {
        List<SelectOption> options = new List<SelectOption>();
        options.add(new SelectOption('1', '1'));
        options.add(new SelectOption('2', '2'));
        options.add(new SelectOption('3', '3'));
        return options;
    }
 
 
 
    public List<SelectOption> getBig_Repair_Time() {
        List<SelectOption> options = new List<SelectOption>();
        options.add(new SelectOption('7', '7'));
        options.add(new SelectOption('10', '10'));
        options.add(new SelectOption('15', '15'));
        options.add(new SelectOption('20', '20'));
        options.add(new SelectOption('25', '25'));
        options.add(new SelectOption('30', '30'));
        return options;
    }
    public List<SelectOption> getone_off_payment_agreed_period() {
 
        //LJPH-BT535P 《委托》 付款计划的字段更新 精琢技术 wql 2020/09/04 start
        map<string, list<pickerWrapper>> pickerFields = new map<string, list<pickerWrapper>>();
 
        // 维修合同 一次性付款约定期限 选项值获取
        list<pickerWrapper> taskStatusOptions = new list<pickerWrapper>();
        Schema.DescribeFieldResult taskStatusfieldResult = Maintenance_Contract__c.one_off_payment_agreed_period__c.getDescribe();
        List<Schema.PicklistEntry> taskStatusple = taskStatusfieldResult.getPicklistValues();
        for ( Schema.PicklistEntry pickListVal : taskStatusple) {
            pickerWrapper temppickerWrapper =
                new pickerWrapper(pickListVal.getLabel(), pickListVal.getValue());
            taskStatusOptions.add(temppickerWrapper);
        }
        pickerFields.put('taskStatusOptions', taskStatusOptions);
 
        List<pickerWrapper> pickerWrapperList = pickerFields.get('taskStatusOptions');
        List<SelectOption> options = new List<SelectOption>();
        List<String> filedList = new List<String>();
        List<String> selectOptionList = new List<String>();
        for (pickerWrapper pw : pickerWrapperList) {
 
            // options.add(new SelectOption(pw.label, pw.value));
            filedList.add(pw.value);
        }
        system.debug('PageMCEElement:' + PageMCEElement);
        system.debug('Estimate_Target__c:' + PageMCEElement.Estimate_Target__c);
 
        //LJPH-BV8ABG 《委托》当报价提交对象为医院时,付款天数增加【90】日内。 2020/11/11  start
        if (PageMCEElement.Estimate_Target__c != null && PageMCEElement.Estimate_Target__c == '医院') {
            filedList.add('90');
        }
        //LJPH-BV8ABG 《委托》当报价提交对象为医院时,付款天数增加【90】日内。 2020/11/11  end
        System.debug('PageMCEElement111:' + PageMCEElement);
        if (PageMCEElement.one_off_payment_agreed_period__c != null) {
            if (!filedList.contains(PageMCEElement.one_off_payment_agreed_period__c)) {
                filedList.add(PageMCEElement.one_off_payment_agreed_period__c);
 
                // options.add(new SelectOption(PageMCEElement.one_off_payment_agreed_period__c, PageMCEElement.one_off_payment_agreed_period__c));
            }
        }
        system.debug('filedList:' + filedList);
        //冒泡排序
        selectOptionList = BubbleSort(filedList);
        system.debug('selectOptionList :' + selectOptionList);
        for (String sol : selectOptionList) {
            options.add(new SelectOption(sol, sol));
        }
 
        return options;
 
        //LJPH-BT535P 《委托》 付款计划的字段更新 精琢技术 wql 2020/09/04 end
    }
 
 
    public PageReference save() {
        /*验证是否输入付款计划
        *多次付款至少输入付款计划1和付款计划1金额
        *一次性付款需要输入一次性付款约定期限
        */
        if (PageMCEElement.Is_Standard_Contract__c == null  ) {
            ApexPages.addmessage(new ApexPages.message(ApexPages.severity.WARNING, '请选择是否标准合同!'));
            statusSave = 'Denied';
            return null;
        }
        if (PageMCEElement.Term_Of_Payment__c != null &&
                '多次付款'.equals(PageMCEElement.Term_Of_Payment__c)) {
            if (PageMCEElement.Payment_Plan_Sum_First__c == null || PageMCEElement.Payment_Plan_Date_First__c == null || PageMCEElement.Payment_Plan_Sum_First__c == 0) {
                ApexPages.addmessage(new ApexPages.message(ApexPages.severity.WARNING, '请输入至少一个付款计划!'));
                statusSave = 'Denied';
                return null;
            }
 
        } else if (PageMCEElement.Term_Of_Payment__c != null
                   && '一次性付款'.equals(PageMCEElement.Term_Of_Payment__c)
                   && PageMCEElement.one_off_payment_agreed_period__c == null ) {
            ApexPages.addmessage(new ApexPages.message(ApexPages.severity.WARNING, '请输入付款计划!'));
            statusSave = 'Denied';
            return null;
        }
        // gzw fix 验证设置为全局
        if (PageMCEElement.Inspection_Time__c == null || ''.equals(PageMCEElement.Inspection_Time__c) || '0'.equals(PageMCEElement.Inspection_Time__c)) {
            System.debug('11111111111' + PageMCEElement.Inspection_Time__c);
            // ApexPages.addmessage(new ApexPages.message(ApexPages.severity.WARNING,
            // '非标合同不需要打印合同文本!'));
            PageMCEElement.Inspection_Time__c.adderror('点检次数必选项');
            statusSave = 'Denied';
            return null;
        }
 
 
        // fxk 2021/8/31 点检次数必须填 Star
        // saveErrorflag = false;
        if (PageMCEElement.Is_Standard_Contract__c == '是') {
            // gzw fix 验证设置为全局 注释
            // if (PageMCEElement.Inspection_Time__c == null || ''.equals(PageMCEElement.Inspection_Time__c) || '0'.equals(PageMCEElement.Inspection_Time__c)) {
            //     System.debug('11111111111' + PageMCEElement.Inspection_Time__c);
            //     // ApexPages.addmessage(new ApexPages.message(ApexPages.severity.WARNING,
            //     // '非标合同不需要打印合同文本!'));
            //     PageMCEElement.Inspection_Time__c.adderror('点检次数必选项');
            //     statusSave = 'Denied';
            //     return null;
            // }
            if (PageMCEElement.Contract_End_Date__c == null || PageMCEElement.Contract_Start_Date__c == null) {
                ApexPages.addmessage(new ApexPages.message(ApexPages.severity.WARNING, '请审批报价并decide'));
                statusSave = 'Denied';
                return null;
            }
        }
 
        // fxk 2021/8/31 点检次数必须填 end
        // fxk 为维修合同点检总次数赋值 star
        if (PageMCEElement.Inspection_Time__c != null) {
            if (PageMCEElement.Contract_End_Date__c != null || PageMCEElement.Contract_Start_Date__c != null) {
                System.debug('PageMCEElement.Contract_End_Date__c.year():' + PageMCEElement.Contract_End_Date__c.year());
                // 总年数
                //合同总月数
                // Integer Contract_validMonth = PageMCEElement.Contract_Start_Date__c.monthsBetween(PageMCEElement.Contract_End_Date__c);
                Integer Contract_validMonth = Integer.valueOf(PageMCEElement.Contract_Range__c);
                // Integer Allyear = Integer.valueOf(PageMCEElement.Contract_End_Date__c.year() - PageMCEElement.Contract_Start_Date__c.year());
                // System.debug('Zongnianshu' + Allyear);
                // // 剩余月数
                // Integer RestMonth = Integer.valueOf(PageMCEElement.Contract_End_Date__c.month() - PageMCEElement.Contract_Start_Date__c.month());
                // // 剩余月应该点检的次数
                // Integer RestMonth_check = RestMonth / (12 / Integer.valueOf(PageMCEElement.Inspection_Time__c));
                // // 合同点检总次数 8 +
                // Integer All_check = Allyear * Integer.valueOf(PageMCEElement.Inspection_Time__c) + RestMonth_check;
                // add 一年内点检区间不够生成一次点检计划,默认生成一个点检计划,计划区间为合同开始日-结束日 2021/10/25 fxk Star
                if((Integer.valueOf(PageMCEElement.Inspection_Time__c) == 1 && Contract_validMonth < 9) 
                    || (Integer.valueOf(PageMCEElement.Inspection_Time__c) == 2 && Contract_validMonth < 6) 
                    || (Integer.valueOf(PageMCEElement.Inspection_Time__c) == 3 && Contract_validMonth < 4)
                    || (Integer.valueOf(PageMCEElement.Inspection_Time__c) == 4 && Contract_validMonth < 3)){
                    PageMCEElement.Service_contract_target_number__c = 1;
                }else{
                // add 一年内点检区间不够生成一次点检计划,默认生成一个点检计划,计划区间为合同开始日-结束日 2021/10/25 fxk End
                    Integer All_check;
                    if (Contract_validMonth - Integer.valueOf(Contract_validMonth / 12) * 12 >= 6
                            && Integer.valueOf(PageMCEElement.Inspection_Time__c) == 1) {
                        All_check = (Contract_validMonth * Integer.valueOf(PageMCEElement.Inspection_Time__c)) / 12 + 1;
                    } else {
                        All_check = (Contract_validMonth * Integer.valueOf(PageMCEElement.Inspection_Time__c)) / 12;
                    }
                    // Integer All_check = (Contract_validMonth * Integer.valueOf(PageMCEElement.Inspection_Time__c)) / 12;
                    PageMCEElement.Service_contract_target_number__c = All_check;
                }
            }
        }
        // fxk 为维修合同点检总次数赋值 end
 
        Savepoint sp = Database.setSavepoint();
        try {
            if (PageMCEElement.Service_Contract_Staff__r.Salesdepartment__c == '1.华北') {
                PageMCEElement.User_Salesdepartment__c = System.Label.Payment_Block_Leader_HB;
                PageMCEElement.User_Salesdepartment_Sec__c = System.Label.Payment_Block_Leader_SD;
            } else if (PageMCEElement.Service_Contract_Staff__r.Salesdepartment__c == '2.东北') {
                PageMCEElement.User_Salesdepartment__c = System.Label.Payment_Block_Leader_DB;
            } else if (PageMCEElement.Service_Contract_Staff__r.Salesdepartment__c == '3.西北') {
                PageMCEElement.User_Salesdepartment__c = System.Label.Payment_Block_Leader_XB;
            } else if (PageMCEElement.Service_Contract_Staff__r.Salesdepartment__c == '4.西南') {
                PageMCEElement.User_Salesdepartment__c = System.Label.Payment_Block_Leader_XN;
            } else if (PageMCEElement.Service_Contract_Staff__r.Salesdepartment__c == '5.华东') {
                PageMCEElement.User_Salesdepartment__c = System.Label.Payment_Block_Leader_HD;
            } else if (PageMCEElement.Service_Contract_Staff__r.Salesdepartment__c == '6.华南') {
                PageMCEElement.User_Salesdepartment__c = System.Label.Payment_Block_Leader_HN;
                PageMCEElement.User_Salesdepartment_Sec__c = System.Label.Payment_Block_Leader_HNVice;
            } else if (PageMCEElement.Service_Contract_Staff__r.Salesdepartment__c == '7.能量') {
 
            }
            // 对于标准合同进行验证必填项
            string requiredInput = '';
            if (PageMCEElement.Is_Standard_Contract__c.equals('是')) {
                if (PageMCEElement.Engineer_Name__c == null || ''.equals(PageMCEElement.Engineer_Name__c)) {
                    requiredInput += '工程师姓名';
                }
                if (PageMCEElement.Phone_Number__c == null || ''.equals(PageMCEElement.Phone_Number__c)) {
                    if (!''.equals(requiredInput)) {
                        requiredInput += '、';
                    }
                    requiredInput += '手机号码';
                }
                if (PageMCEElement.Small_Repair_Time__c == null || ''.equals(PageMCEElement.Small_Repair_Time__c)) {
                    if (!''.equals(requiredInput)) {
                        requiredInput += '、';
                    }
                    requiredInput += '小修理时限';
                }
                if (PageMCEElement.Big_Repair_Time__c == null || ''.equals(PageMCEElement.Big_Repair_Time__c)) {
                    if (!''.equals(requiredInput)) {
                        requiredInput += '、';
                    }
                    requiredInput += '大修理时限';
                }
                if (PageMCEElement.Live_Technical_Support_Time__c == null || ''.equals(PageMCEElement.Live_Technical_Support_Time__c)) {
                    if (!''.equals(requiredInput)) {
                        requiredInput += '、';
                    }
                    requiredInput += '现场技术支持时限';
                }
                if (PageMCEElement.Tour_Check__c == null || ''.equals(PageMCEElement.Tour_Check__c)) {
                    if (!''.equals(requiredInput)) {
                        requiredInput += '、';
                    }
                    requiredInput += '巡回';
                }
                if (PageMCEElement.Inspection_Time__c == null || ''.equals(PageMCEElement.Inspection_Time__c)) {
                    if (!''.equals(requiredInput)) {
                        requiredInput += '、';
                    }
                    requiredInput += '点检';
                }
                if (PageMCEElement.Dedust__c == null || ''.equals(PageMCEElement.Dedust__c)) {
                    if (!''.equals(requiredInput)) {
                        requiredInput += '、';
                    }
                    requiredInput += '除尘';
                }
 
                if (PageMCEElement.First_Party_Contract_Number__c == null || ''.equals(PageMCEElement.First_Party_Contract_Number__c)) {
                    if (!''.equals(requiredInput)) {
                        requiredInput += '、';
                    }
                    requiredInput += '合同份数:甲方:';
                }
                if (PageMCEElement.Second_Party_Contract_Number__c == null || ''.equals(PageMCEElement.Second_Party_Contract_Number__c)) {
                    if (!''.equals(requiredInput)) {
                        requiredInput += '、';
                    }
                    requiredInput += '合同份数:乙方:';
                }
                if (!''.equals(requiredInput)) {
                    statusSave = 'Denied';
                    ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, '该合同是标准合同,请输入:' + requiredInput));
                    return null;
                }
            } else {
                if (PageMCEElement.Term_Of_Payment__c != null &&
                        '多次付款'.equals(PageMCEElement.Term_Of_Payment__c)) {
                    decimal PriceSum =  (PageMCEElement.Payment_Plan_Sum_First__c == null ? 0 : PageMCEElement.Payment_Plan_Sum_First__c) +
                                        (PageMCEElement.Payment_Plan_Sum_Second__c == null ? 0 : PageMCEElement.Payment_Plan_Sum_Second__c) +
                                        (PageMCEElement.Payment_Plan_Sum_Third__c == null ? 0 : PageMCEElement.Payment_Plan_Sum_Third__c) +
                                        (PageMCEElement.Payment_Plan_Sum_Forth__c == null ? 0 : PageMCEElement.Payment_Plan_Sum_Forth__c) +
                                        (PageMCEElement.Payment_Plan_Sum_Fifth__c == null ? 0 : PageMCEElement.Payment_Plan_Sum_Fifth__c) +
                                        (PageMCEElement.Payment_Plan_Sum_Sixth__c == null ? 0 : PageMCEElement.Payment_Plan_Sum_Sixth__c);
                    if (PriceSum != PageMCEElement.Contract_Amount__c ) {
                        ApexPages.addmessage(new ApexPages.message(ApexPages.severity.WARNING,
                                             '付款总金额与合同金额不符。'));
                        statusSave = 'Denied';
                    }
 
                }
            }
 
            if (PageMCEElement.Term_Of_Payment__c != null
                    && '一次性付款'.equals(PageMCEElement.Term_Of_Payment__c)) {
                PageMCEElement.Payment_Plan_Sum_First__c     = PageMCEElement.Contract_Amount__c;
                PageMCEElement.Payment_Plan_Sum_Second__c   = null;
                PageMCEElement.Payment_Plan_Sum_Third__c    = null;
                PageMCEElement.Payment_Plan_Sum_Forth__c    = null;
                PageMCEElement.Payment_Plan_Sum_Fifth__c    = null;
                PageMCEElement.Payment_Plan_Sum_Sixth__c    = null;
 
                PageMCEElement.Payment_Plan_Date_First__c   = null;
                PageMCEElement.Payment_Plan_Date_Second__c  = null;
                PageMCEElement.Payment_Plan_Date_Third__c   = null;
                PageMCEElement.Payment_Plan_Date_Forth__c   = null;
                PageMCEElement.Payment_Plan_Date_Fifth__c   = null;
                PageMCEElement.Payment_Plan_Date_Sixth__c   = null;
                PageMCEElement.Total_Payment_Time__c        = null;
            } else {
                PageMCEElement.one_off_payment_agreed_period__c        = null;
 
            }
            if (PageMCEElement.Is_Standard_Contract__c != null && PageMCEElement.Is_Standard_Contract__c.equals('否')) {
                System.debug('-------1-------'+PageMCEElement.Is_Standard_Contract__c);
                PageMCEElement.Engineer_Name__c = null;
                PageMCEElement.Phone_Number__c = null;
                PageMCEElement.Small_Repair_Time__c = null;
                PageMCEElement.Big_Repair_Time__c = null;
                PageMCEElement.Live_Technical_Support_Time__c = null;
                PageMCEElement.Tour_Check__c = null;
                // gzw fix 20210929 追加非标准合同点检次数
                // PageMCEElement.Inspection_Time__c = null;
                PageMCEElement.Dedust__c = null;
                PageMCEElement.First_Party_Contract_Number__c = null;
                PageMCEElement.Second_Party_Contract_Number__c = null;
                // gzw fix 20210929 追加非标准合同点检次数
                // PageMCEElement.Service_contract_target_number__c = null;
 
            }
            // System.debug('22222222222222'+PageMCEElement.Inspection_Time__c);
 
            PageMCEElement.MainLeaderManager__c = PageMCEElement.Service_Contract_Staff__r.JingliApprovalManager__c;
            update PageMCEElement;
            statusSave = 'Fin';
            return null;
        } catch (exception ex) {
            statusSave = 'Denied';
            Database.rollback(sp);
            ApexPages.addmessages(ex);
            return null;
        }
    }
    public void print() {
        System.debug('print start');
        save();
 
        if (PageMCEElement.Decided_Estimation__c == null) {
            ApexPages.addmessage(new ApexPages.message(ApexPages.severity.WARNING,
                                 '报价单没有决定之前不能打印合同文本!'));
            statusSave = 'Denied';
            //return;
        }
 
        if (PageMCEElement.Estimation_Id__r.Estimate_Target__c == null) {
            ApexPages.addmessage(new ApexPages.message(ApexPages.severity.WARNING,
                                 '请确定提交对象'));
            statusSave = 'Denied';
            //return;
        }
 
 
        if (PageMCEElement.Is_Standard_Contract__c != null && PageMCEElement.Is_Standard_Contract__c.equals('否')) {
            ApexPages.addmessage(new ApexPages.message(ApexPages.severity.WARNING,
                                 '非标合同不需要打印合同文本!'));
            statusSave = 'Denied';
            //return;
        }
 
 
        if (PageMCEElement.Term_Of_Payment__c != null &&
                '多次付款'.equals(PageMCEElement.Term_Of_Payment__c)) {
            decimal PriceSum =  (PageMCEElement.Payment_Plan_Sum_First__c == null ? 0 : PageMCEElement.Payment_Plan_Sum_First__c) +
                                (PageMCEElement.Payment_Plan_Sum_Second__c == null ? 0 : PageMCEElement.Payment_Plan_Sum_Second__c) +
                                (PageMCEElement.Payment_Plan_Sum_Third__c == null ? 0 : PageMCEElement.Payment_Plan_Sum_Third__c) +
                                (PageMCEElement.Payment_Plan_Sum_Forth__c == null ? 0 : PageMCEElement.Payment_Plan_Sum_Forth__c) +
                                (PageMCEElement.Payment_Plan_Sum_Fifth__c == null ? 0 : PageMCEElement.Payment_Plan_Sum_Fifth__c) +
                                (PageMCEElement.Payment_Plan_Sum_Sixth__c == null ? 0 : PageMCEElement.Payment_Plan_Sum_Sixth__c);
            if (PriceSum != PageMCEElement.Contract_Amount__c ) {
                ApexPages.addmessage(new ApexPages.message(ApexPages.severity.WARNING,
                                     '付款总金额与合同金额不符。'));
                statusSave = 'Denied';
                //return;
            }
 
            // HWAG-BHT7XX 2019-12-09 by vivek start
            Integer payTimeSum = 0;
            if (PageMCEElement.Payment_Plan_Sum_First__c != null) {
                payTimeSum++;
            }
            if (PageMCEElement.Payment_Plan_Sum_Second__c != null) {
                payTimeSum++;
            }
            if (PageMCEElement.Payment_Plan_Sum_Third__c != null) {
                payTimeSum++;
            }
            if (PageMCEElement.Payment_Plan_Sum_Forth__c != null) {
                payTimeSum++;
            }
            if (PageMCEElement.Payment_Plan_Sum_Fifth__c != null) {
                payTimeSum++;
            }
            if (PageMCEElement.Payment_Plan_Sum_Sixth__c != null) {
                payTimeSum++;
            }
            if (PageMCEElement.Total_Payment_Time__c != null) {
                system.debug(payTimeSum + '======' + Integer.valueOf(PageMCEElement.Total_Payment_Time__c));
                if (Integer.valueOf(PageMCEElement.Total_Payment_Time__c) != payTimeSum) {
                    System.debug(Integer.valueOf(PageMCEElement.Total_Payment_Time__c) + '======');
                    ApexPages.addmessage(new ApexPages.message(ApexPages.severity.WARNING,
                                         '付款期数和付款计划数目不符。'));
                    statusSave = 'Denied';
                }
            }
 
            // HWAG-BHT7XX 2019-12-09 by vivek end
        }
 
 
 
 
        if (statusSave.equals('Fin') && PageMCEElement.Estimation_Id__r.Estimate_Target__c.equals('医院')) {
            printContract = true;
            printAgent = false;
        } else if (statusSave.equals('Fin')) {
            printContract = false;
            printAgent = true;
        }
 
 
 
 
 
        System.debug('print end');
    }
 
    public void dummy() {
    }
 
//LJPH-BT535P 《委托》 付款计划的字段更新 精琢技术 wql 2020/09/04 start
    public class pickerWrapper {
        @AuraEnabled
        public string label;
        @AuraEnabled
        public string value;
        public pickerWrapper(string label, string value) {
            this.label = label;
            this.value = value;
        }
 
    }
 
    //冒泡排序
    public List<String> BubbleSort(List<String> arrayList) {
        //外层循环控制排序趟数
        for (Integer i = 1; i < arrayList.size(); i++) {
 
            //内层循环控制每一趟排序多少次 。 每次最后面的值都是最大值了 。 所以后面的都可以不用排序了。
            for (Integer j = 0; j < arrayList.size() - 1; j++) {
                if (arrayList[j] > arrayList[i]) {
                    String temp = arrayList[j];
                    arrayList[j] = arrayList[i];
                    arrayList[i] = temp;
                }
            }
        }
        return arrayList;
    }
//LJPH-BT535P 《委托》 付款计划的字段更新 精琢技术 wql 2020/09/04 end
}