Advertisement
Guest User

Untitled

a guest
Mar 22nd, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 18.85 KB | None | 0 0
  1. /**
  2.     This class contains Opportunity button actions
  3.     12.10.2018 - CR 00042620 - Circuit ID within manual creation cross connect details - DEPLOYED 12.10.2018
  4.     18.08.2015 - CR 00010393 - COF Changes - Manage default value for Stage/Sub-Stage - DEPLOYED 29.09.2015
  5.     12.08.2015 - CR 00009832 - Sales Support Workshop - 1.2 MSA defaults - DEPLOYED 23.09.2015
  6.     24.07.2015 - CR 00010389 - Opportunity date defaults - UK - DEPLOYED 27.07.2015
  7.     07.07.2015 - CR 00009845 - Change opp naming protocol - DEPLOYED 27.07.2015
  8.     02.06.2015 - CR 00009982 - Update Effective Contract Date and Close Date - upon creation UK - DEPLOYED
  9.     17.04.2015 - CR 00009276 - Default Opportunity Currency - DEPLOYED 27.07.2015
  10.     20.11.2014 - CR 00008191 - Generate Opportunity URL with default value. - DEPLOYED
  11.     02.06.2015 - CR 00009982 - Update Effective Contract Date and Close Date - upon creation UK - DEPLOYED
  12.    
  13.  
  14. **/
  15.  
  16.      public with sharing class OpportunityButtonActionsController{
  17.      
  18.         public Account acc {get;private set;}
  19.         public Opportunity opp {get;set;}
  20.         //Pull out Opportunity Record type info
  21.         public static Map<Id,Schema.RecordTypeInfo> rtInfoMapById = Schema.SObjectType.Opportunity.getRecordTypeInfosById();
  22.         public List<RecordType> availableRTs{get;private set;}
  23.         public static Id cCRecTypeId = cache.RecordTypeId('Opportunity.Cross Connect Opportunity');
  24.         public static Id cOFRecTypeId = cache.RecordTypeId('Opportunity.Customer Order Form Opportunity');
  25.         public static Map<String,String> countryIsoCodeMapping = new Map<String,String>{'UK' => 'UK',
  26.                                                                                         'Austria' => 'AT',
  27.                                                                                         'Belgium' => 'BE',
  28.                                                                                         'Denmark' => 'DK',
  29.                                                                                         'France' => 'FR',
  30.                                                                                         'Germany' => 'DE',
  31.                                                                                         'Ireland' => 'IE',
  32.                                                                                         'Netherlands' => 'NL',
  33.                                                                                         'Spain' => 'ES',
  34.                                                                                         'Sweden' => 'SE',
  35.                                                                                         'Switzerland' => 'CH',
  36.                                                                                         'UK' => 'UK',
  37.                                                                                         'Science Park' => 'NL'};
  38.                                                                                                                                                                                    
  39.         /**Getters**/
  40.        
  41.        
  42.         public static String getDefaultSubStage(){
  43.             return 'Qualify';
  44.         }
  45.        
  46.         public static String getDefaultStageName(){
  47.             return 'Qualification';
  48.         }
  49.         public static String getDefaultCampaignId(){
  50.             return '701D00000004XQp';
  51.         }
  52.        
  53.         public static String getRecordTypeParamURL(){
  54.             return 'RecordType';
  55.         }
  56.         public static String getIXCountryParamURL(){
  57.             return 'CF00ND0000003Cjyk';
  58.         }
  59.         public static String getSubStageParamURL(){
  60.             return '00ND0000003CjzQ';
  61.         }
  62.         public static String getSvCountryParamURL(){
  63.             return '00ND0000003CjzE';
  64.         }
  65.        
  66.         public static String getSvSite(){
  67.             return '00ND0000003CjzD';
  68.         }
  69.         public static String getOppCurrencyParamURL(){
  70.             return 'opp16';
  71.         }
  72.        
  73.         public static String getSvCampusParamURL(){
  74.             return '00ND0000003CjzB';
  75.         }
  76.         public static String getOppNameParamURL(){
  77.             return 'opp3';
  78.         }
  79.         public static String getOppClosedDateParamURL(){
  80.             return 'opp9';
  81.         }
  82.         public static String getOppEffContractDateParamURL(){
  83.             return '00ND00000042k4j';
  84.         }
  85.  
  86.         public static String getCommencementDateParamURL(){
  87.             return '00ND0000003CjyR';
  88.         }
  89.        
  90.         public static String getSafetyDepositParamURL(){
  91.             return '00ND00000041CeR';
  92.         }
  93.        
  94.         public static String getCPIClauseParamURL (){
  95.             return '00ND00000041CeS';
  96.         }  
  97.        
  98.         public static String getPowerUsagePriceClauseParamURL (){
  99.             return '00ND00000041CeT';
  100.         }
  101.        
  102.         public static String getServiceCreditLimitationParamURL (){
  103.             return '00ND00000041CeU';
  104.         }
  105.         public static String getPaymentTermParamURL(){    
  106.             return '00ND00000041CeV';
  107.         }
  108.         //CR 00042620
  109.         public static String getAccountCountryCode(){
  110.             return '00N5700000686IG';
  111.         }
  112.        
  113.         public OpportunityButtonActionsController(){
  114.              this.opp =  new Opportunity();
  115.              this.opp.AccountId = ApexPages.currentPage().getParameters().get('accId');
  116.              this.availableRTs = new List<RecordType>();
  117.              
  118.         }
  119.         //Redirect users to the Opportunity creation page
  120.         public PageReference goToNextPage(){
  121.            
  122.             if(this.opp.RecordTypeId !=null ){
  123.                 try{              
  124.                     PageReference pageRef = new Pagereference('/006/e');
  125.                     pageRef.getParameters().put('retURL','/'+this.opp.AccountId);
  126.                     pageRef.getParameters().put('campid', getDefaultCampaignId());
  127.                     pageRef.getParameters().put('opp11',getDefaultStageName());
  128.  
  129.                     pageRef.getParameters().put('save_new_url','/006/e?retURL='+this.opp.AccountId);
  130.                     pageRef.getParameters().put('ent','Opportunity');
  131.  
  132.                     pageRef.getParameters().put(getRecordTypeParamURL(),this.opp.RecordTypeId);
  133.  
  134.                     pageRef.getParameters().put(getSubStageParamURL(),getDefaultSubStage());
  135.                     //Start - CR 00010393 - default sub-stage
  136.                     if(Cache.RecordTypeId('Opportunity.Cross Connect Opportunity').contains(this.opp.RecordTypeId)
  137.                        || Cache.RecordTypeId('Opportunity.Customer Order Form Opportunity').contains(this.opp.RecordTypeId))
  138.                         pageRef.getParameters().put(getSubStageParamURL(),'Create Product Items');
  139.                     else
  140.                         pageRef.getParameters().put(getSubStageParamURL(),getDefaultSubStage());
  141.                     //End - CR 00010393 - default sub-stage
  142.                     List<Account> currentAccount = [SELECT Id,
  143.                                                            Name,
  144.                                                            Industry,
  145.                                                            Account_Country__c,
  146.                                                            ParentId, // CR 00009832
  147.                                                            CurrencyIsoCode
  148.                                                            FROM Account
  149.                                                            WHERE Id =:this.opp.AccountId LIMIT 1 ];
  150.                     //Start 00009832 G.B
  151.                     if(!currentAccount.isEmpty() && currentAccount.get(0).ParentId !=null){
  152.                         List<Apttus__APTS_Agreement__c> mSAAgreement = [Select Id,
  153.                                                                                Finance_Security_Clause__c,
  154.                                                                                CPI_Clause__c,
  155.                                                                                Power_Usage_Price_Clause__c,
  156.                                                                                Service_Credit_Limitation__c,
  157.                                                                                Payment_Term__c
  158.                                                                                FROM Apttus__APTS_Agreement__c
  159.                                                                                WHERE Apttus__Status_Category__c = 'In Effect'
  160.                                                                                AND Apttus__Account__c =:currentAccount.get(0).ParentId
  161.                                                                                AND RecordTypeId =: Cache.RecordTypeId('Apttus__APTS_Agreement__c.Master Services Agreement')  
  162.                                                                                LIMIT 1];
  163.                         //Default Commercial Matrix
  164.                         if(!mSAAgreement.isEmpty()){
  165.                             //pageRef.getParameters().put('AgrmtId',mSAAgreement.get(0).Id);
  166.                             pageRef.getParameters().put(getSafetyDepositParamURL(),mSAAgreement.get(0).Finance_Security_Clause__c);
  167.                             pageRef.getParameters().put(getCPIClauseParamURL(),mSAAgreement.get(0).CPI_Clause__c);
  168.                             pageRef.getParameters().put(getPowerUsagePriceClauseParamURL (),mSAAgreement.get(0).Power_Usage_Price_Clause__c);
  169.                             pageRef.getParameters().put(getServiceCreditLimitationParamURL (),mSAAgreement.get(0).Service_Credit_Limitation__c);
  170.                             pageRef.getParameters().put(getPaymentTermParamURL(),mSAAgreement.get(0).Payment_Term__c);
  171.                         }
  172.                    
  173.                     }
  174.                     //End 00009832 G.B
  175.                    
  176.                     String accName = !currentAccount.isEmpty() ? currentAccount.get(0).Name:'';
  177.                     //Set account name
  178.                     pageRef.getParameters().put('opp4',accName);
  179.                     //Set account Id
  180.                     pageRef.getParameters().put('opp4_lkid',this.opp.AccountId);
  181.                    
  182.                     //Set Opportunity Currency  - Start CR 00009276
  183.                     pageRef.getParameters().put(getOppCurrencyParamURL(),currentAccount.get(0).CurrencyIsoCode);
  184.                     // End CR 00009276
  185.                                        
  186.                     //Pulls out current user IX country
  187.                     List<User> currentUser = [SELECT Country_IX__c,Profile.Name FROM User WHERE Id =:UserInfo.getUserId() LIMIT 1];
  188.                    
  189.                     String currentCountry = 'Netherlands';
  190.                     if(!currentAccount.isEmpty() && currentAccount.get(0).Account_Country__c != null && currentAccount.get(0).Account_Country__c != 'Unknown')
  191.                         currentCountry = currentAccount.get(0).Account_Country__c;
  192.                     else if(!currentUser.isEmpty() && currentUser.get(0).Country_IX__c != null && currentUser.get(0).Country_IX__c != 'HQ'){
  193.                         currentCountry = currentUser.get(0).Country_IX__c;
  194.                     }
  195.                    
  196.                    
  197.                     //Pull out Interxion entity details
  198.                     List<Account> interxionEntitySub = [SELECT Id,
  199.                                                                Name,
  200.                                                                Default_Service_Campus__c,
  201.                                                                Subsidiary_country__c,
  202.                                                                Default_Service_Site__c
  203.                                                                FROM Account
  204.                                                                WHERE Subsidiary_country__c =: currentCountry
  205.                                                                OR Default_IX_Subsidiary__c = true
  206.                                                                order by Default_IX_Subsidiary__c asc LIMIT 2];
  207.                                                
  208.                     //Default Opportunity Name
  209.                     String oppName = '';
  210.                     //Pulls out the country 2 characters iso code
  211.                     String countryIsoCode = (currentCountry !=null && countryIsoCodeMapping.containsKey(currentCountry))?
  212.                                              countryIsoCodeMapping.get(currentCountry): 'NL';  
  213.                    
  214.                     // Account Country Code - CR 00042620
  215.                     pageRef.getParameters().put(getAccountCountryCode(),countryIsoCode);
  216.                    
  217.                     //Set Opp Commencement Date
  218.                     pageRef.getParameters().put(getCommencementDateParamURL(),Date.today().addMonths(1).format());
  219.                    
  220.                     //Set CC Opps
  221.                     if(String.valueOf(this.opp.RecordTypeId).contains(cCRecTypeId)){
  222.                         oppName = 'CC-'+ countryIsoCode + '-' + accName;
  223.                         //Set UK CC Commencement Date
  224.                         if(currentCountry == 'UK')
  225.                             // Start - CR 00009982 - G.B
  226.                             //pageRef.getParameters().put(getCommencementDateParamURL(),Date.today().addMonths(3).format());
  227.                             // End - CR 00009982 - G.B
  228.                             // Start - CR 00010389 - G.B
  229.                             pageRef.getParameters().put(getCommencementDateParamURL(),getCommencementDate('UK').format());
  230.                             // End - CR 00010389 - G.B
  231.                     }
  232.                     // Set COF Opps
  233.                     else if(String.valueOf(this.opp.RecordTypeId).contains(cOFRecTypeId)){
  234.                         oppName = 'COF-'+ countryIsoCode + '-' + accName;
  235.                          //Set UK COF Commencement Date
  236.                          if(currentCountry == 'UK')
  237.                              // Start - CR 00009982 - G.B
  238.                             //pageRef.getParameters().put(getCommencementDateParamURL(),Date.today().addMonths(3).format());
  239.                             // End - CR 00009982 - G.B
  240.                              // Start - CR 00010389 - G.B
  241.                             pageRef.getParameters().put(getCommencementDateParamURL(),Date.today().addMonths(1).format());
  242.                             // End - CR 00010389 - G.B
  243.                            
  244.                     }
  245.  
  246.                     if(!interxionEntitySub.isEmpty()){
  247.                         //Set Opp Interxion Contracting Entity
  248.                         pageRef.getParameters().put(getIXCountryParamURL(),interxionEntitySub.get(0).Name);
  249.                         //Set Opp Service Country
  250.                         pageRef.getParameters().put(getSvCountryParamURL(),interxionEntitySub.get(0).Subsidiary_country__c);
  251.                         //Set Opp Service Campus
  252.                         pageRef.getParameters().put(getSvCampusParamURL(),interxionEntitySub.get(0).Default_Service_Campus__c);
  253.                         //Set Default name
  254.                         //CR 00009845 - G.B - 07.07.2015
  255.                         oppName = oppName == ''?accName +' - '+ interxionEntitySub.get(0).Default_Service_Site__c:oppName;
  256.                         //CR 00009845 - G.B - 07.07.2015
  257.                         //Set Opp Service Site
  258.                         pageRef.getParameters().put(getSvSite(),interxionEntitySub.get(0).Default_Service_Site__c);
  259.                     }
  260.                    
  261.                     //Start - CR 00009982 - G.B
  262.                     //Set Opp Closed Date
  263.                     if(currentCountry == 'UK'
  264.                        && String.valueOf(this.opp.RecordTypeId).contains(cOFRecTypeId)){
  265.                         // Start - CR 00010389
  266.                         pageRef.getParameters().put(getOppClosedDateParamURL(),Date.today().addMonths(1).format());
  267.                         //Set Opp Effective Contract Date
  268.                         pageRef.getParameters().put(getOppEffContractDateParamURL(),Date.today().addMonths(1).format());
  269.                         //End - CR 00010389
  270.                     }else if(currentCountry == 'UK'
  271.                             && String.valueOf(this.opp.RecordTypeId).contains(cCRecTypeId)){
  272.                         // Start - CR 00010389
  273.                         pageRef.getParameters().put(getOppClosedDateParamURL(),Date.today().format());
  274.                         //Set Opp Effective Contract Date
  275.                         pageRef.getParameters().put(getOppEffContractDateParamURL(),Date.today().format());
  276.                         //End - CR 00010389
  277.                     }else{
  278.                          pageRef.getParameters().put(getOppClosedDateParamURL(),Date.today().format());
  279.                          //Set Opp Effective Contract Date
  280.                          pageRef.getParameters().put(getOppEffContractDateParamURL(),Date.today().format());
  281.                     }    
  282.                     //End - CR 00009982 - G.B
  283.                    
  284.                     if(oppName!=null && oppName!='')
  285.                         //Set Opp Name
  286.                         pageRef.getParameters().put(getOppNameParamURL(),oppName);
  287.  
  288.  
  289.                     return pageRef.setRedirect(true);
  290.                    
  291.                     }catch (Exception e){
  292.                           ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR,e.getMessage()));
  293.                           return null;
  294.                     }
  295.                
  296.             }else{
  297.                 ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR,'Missing URL Parameter'));
  298.                 return null;
  299.             }
  300.             return null;
  301.         }
  302.         //Go back to the related account
  303.         public PageReference goToCancel(){
  304.             return new PageReference ('/'+this.opp.AccountId);
  305.         }
  306.         //Load list of RT
  307.         public PageReference loadOppAvailableRTTypes(){
  308.             //Populate available Recordt Type info based on user access
  309.             for(RecordType rt:[SELECT Id,Name,Description FROM RecordType WHERE SobjectType = 'Opportunity']){
  310.               if(rtInfoMapById !=null && rtInfoMapById.containsKey(rt.Id) && rtInfoMapById.get(rt.Id).isAvailable())
  311.                  availableRTs.add(rt);  
  312.             }
  313.             //User has acces to only one RT
  314.             if(availableRTs.size() == 1){
  315.                 this.opp.RecordTypeId = availableRTs.get(0).Id;
  316.                 return goToNextPage();
  317.             }
  318.            
  319.             return null;      
  320.         }
  321.        
  322.        //Calcluate Commencement Date(today + SLA (10 working days))
  323.         private Date getCommencementDate(String country){
  324.             return Utility.getBusinessEndDate(Date.today(),3,country);
  325.         }      
  326.      
  327.      
  328.      }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement