GWY
2022-03-17 ae3dbaacd49b295337c5c53dbf5cf732898ed6f8
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
public without sharing class NewQuoteDevideController {
    private String oid;
    private String qid;
    private String ot;
    private String cid;
    private String rturl;
 
    public NewQuoteDevideController(ApexPages.StandardController controller) {
        this();
    }
 
    public NewQuoteDevideController() {
        oid = System.currentPageReference().getParameters().get('oppid');
        qid = System.currentPageReference().getParameters().get('id');
        ot = System.currentPageReference().getParameters().get('openType');
        cid = System.currentPageReference().getParameters().get('copyid');
        rturl = System.currentPageReference().getParameters().get('retURL');
    }
 
    public PageReference init() {
        PageReference pr = null;
 
        String quoId = '';
        String oppId = '';
        if (cid != null && cid.length() > 0) {
            quoId = cid;
        } else if (qid != null && qid.length() > 0) {
            quoId = qid;
        } else if (oid != null && oid.length() > 0) {
            oppId = oid;
        }
 
        boolean isService = false;
        if (ot == 'service') {
            isService = true;
        } else {
            if (quoId != null && quoId.length() > 0) {
                List<Quote> quoList = [select Id, Quote_Type__c from Quote where Id = :quoId];
                String rt = quoList[0].Quote_Type__c;
                isService = rt == 'service';
            }
 
            if (oppId != null && oppId.length() > 0) {
                List<Opportunity> oppList = [select Id, RecordTypeId from Opportunity where Id = :oppId];
                String rt = oppList[0].RecordTypeId;
                isService = rt.substring(0, 15) == System.Label.RT_SSBD_Service;
            }
        }
 
        String cStr = '';
        if (cid != null && cid.length() > 0) {
            cStr = '&copyid=' + cid;
        }
        String rStr = '';
        if (rturl != null && rturl.length() > 0) {
            rStr = '&retURL=' + rturl;
        }
        if (oid != null && oid.length() > 0) {
            if (isService == true) {
                pr = new PageReference('/apex/NewQuoteService?oppid=' + oid + '&openType=service' + cStr + rStr);
            } else {
                pr = new PageReference('/apex/NewQuoteEntry?oppid=' + oid + cStr + rStr);
            }
        } else if (qid != null && qid.length() > 0) {
            if (isService == true) {
                pr = new PageReference('/apex/NewQuoteService?id=' + qid + '&openType=service' + rStr);
            } else {
                pr = new PageReference('/apex/NewQuoteEntry?id=' + qid + rStr);
            }
        }
 
        pr.setRedirect(true);
        return pr;
    }
}