rendered paste bodypublic without sharing class QuoteDetailController {
private static final Set<String> EDITABLE_STATUS_VALUES =
new Set<String>{'draft',
'sent quote inquiry',
'sent for credit check',
'ee sent for credit check',
'credit approval received',
'held for customer',
'credit check failed',
'rejected to sales',
'client declined',
'sent agreement, waiting acceptance'};
/* new Set<String>{'credit check failed', // 'customer signed agreement in person',
'provisioning complete', 'provisioning in progress','replaced agreement','ee sent for credit check','credit approval received',
'held for customer','rejected to sales', 'order entry complete'}; */
public QuoteVO quote {get; private set;}
public Web_Account__c account {get; private set;}
public List<QuoteLineVO> products {get; private set;}
public List<ContactVO> contacts {get; private set;}
public String quoteDetailLink {get; private set;}
public Boolean multiSite {get; private set;}
public Address__c installLocation {get; private set;}
public Boolean sendAgreementDisabled {get{return isSendAgreementDisabled();}}
public Boolean creditCheckDisabled {get{return isCreditCheckDisabled();}}
public Boolean dealerUser {get{return QuotePortalUtils.isUserDealer();}}
public PicklistValuesOptionModel preferredInstallationTime {get; private set;}
public PicklistValuesOptionModel quoteStatusOptions {get; private set;}
public PicklistValuesOptionModel assignedAccountOrder {get; private set;}
public Boolean sendEmailDisabled {get{return isSendEmailDisabled();}}
public Boolean quoteHasMissingInformation {get{return quoteHasMissingInformation();}}
private String returnURL;
private Boolean detailView = true;
public transient SBQQ__Quote__c quoteRec {get; set;}
public QuoteDetailController() {
Id quoteId = ApexPages.currentPage().getParameters().get('qid');
returnURL = ApexPages.currentPage().getParameters().get('retURL');
detailView = (ApexPages.currentPage().getParameters().get('pd') == '1');
init(quoteId);
preferredInstallationTime = new PicklistValuesOptionModel(SBQQ__Quote__c.Preferred_Installation_Time__c);
assignedAccountOrder = new PicklistValuesOptionModel(SBQQ__Quote__c.Assigned_Account_Order__c);
initQuoteStatusOptions();
}
/**
* Constructor used by component that generates fullfillment emails
*/
public QuoteDetailController(Id quoteId) {
init(quoteId);
}
private void initQuoteStatusOptions() {
quoteStatusOptions = new PicklistValuesOptionModel(SBQQ__Quote__c.SBQQ__Status__c);
for (SelectOption opt : quoteStatusOptions.getOptions()) {
if (QuotePortalUtils.isExperienceExcellenceUser() && EDITABLE_STATUS_VALUES.contains(opt.getValue().toLowerCase())) {
opt.setDisabled(false);
/* Begin Traction Change 2/8/12 for Case TC1049 */
// } else if (opt.getValue().equalsIgnoreCase('Client Declined') || opt.getValue().equalsIgnoreCase('Replaced Agreement')) {
} else if (opt.getValue().equalsIgnoreCase('Client Declined') || opt.getValue().equalsIgnoreCase('Replaced Agreement') || (opt.getValue().equalsIgnoreCase('customer signed agreement in person') && dealerUser != false) ) {
/* End Traction Change 2/8/12 for Case TC1049 */
opt.setDisabled(false);
} else {
opt.setDisabled(true);
}
}
}
public Boolean isSendAgreementDisabled() {
return (quote.agreementExists && !QuotePortalUtils.isExperienceExcellenceUser()) ||
(quote.status == 'Customer Signed Agreement in Person') ||
(quote.status == 'Client Declined') ||
(account.Credit_Reference__c == null) ||
((account.Credit_Check_Status__c != 'Approved') && (account.Credit_Check_Status__c != 'Pre-Approved Credit'));
}
public Boolean isCreditCheckDisabled() {
return quote.creditCheckRequested ||
(quote.status == 'Client Declined') ||
((account.Credit_Reference__c != null) &&
((account.Credit_Check_Status__c == 'Approved') || (account.Credit_Check_Status__c == 'Pre-Approved Credit')));
}
public Boolean isSendEmailDisabled() {
return quote.record.Email_Enabled__c.equalsIgnoreCase('no') || (quote.status == 'Client Declined');
}
public String getDetailPageURL() {
PageReference pref = Page.QuoteDetail;
pref.getParameters().put('qid', quote.id);
if (multiSite) {
pref.getParameters().put('ms','1');
}
pref.getParameters().put('step', ApexPages.currentPage().getParameters().get('step'));
pref.getParameters().put('addon', ApexPages.currentPage().getParameters().get('addon'));
pref.setRedirect(true);
return pref.getUrl();
}
public String getSummaryPageURL() {
PageReference pref = Page.QuoteSummary;
pref.getParameters().put('qid', quote.id);
if (multiSite) {
pref.getParameters().put('ms','1');
}
pref.getParameters().put('step', ApexPages.currentPage().getParameters().get('step'));
pref.getParameters().put('addon', ApexPages.currentPage().getParameters().get('addon'));
pref.setRedirect(true);
return pref.getUrl();
}
public Boolean quoteHasMissingInformation() {
Id[] qids = new Id[]{quote.id};
return QuotePortalUtils.quotesHaveDevicesWithMissingInformation(qids).get(quote.id);
}
private void init(Id quoteId) {
quote = new QuoteVO(QuotePortalUtils.loadQuoteById(quoteId));
products = new List<QuoteLineVO>();
for (SBQQ__QuoteLine__c line : QuotePortalUtils.loadQuoteLines(quoteId, detailView)) {
products.add(new QuoteLineVO(line));
}
products = QuotePortalUtils.sortLines(products);
Id accountId = quote.record.SBQQ__Opportunity__r.Web_Account__c;
account = QuotePortalUtils.loadAccountById(accountId);
multiSite = quote.record.Group__c != null;
if (quote.record.Install_Location__c != null) {
installLocation = [SELECT Special_Location__c, Street__c, City__c, State_Province__c, BAN__c, CAN__c, Rate_Band__c, Postal_Code__c FROM Address__c WHERE Id = :quote.record.Install_Location__c];
}
}
public PageReference onClone() {
PageReference pref = Page.SBQQ__SiteCloneQuote;
pref.getParameters().put('qid', quote.id);
QuotePortalUtils.addReturnURLParam(pref, Page.QuoteCloneConfirmation);
//pref.getParameters().put('retURL', getSummaryPageURL());
return pref;
}
private Boolean isAgreementAcceptedStatus(String status) {
return status == 'Customer Accepted Agreement' || status == 'Customer Accepted Agreement, Awaiting Provisioning';
}
public PageReference onSave() {
System.Savepoint sp = Database.setSavepoint();
try {
update installLocation;
Boolean sendProvision = false;
Map<Id, Boolean> quoteHasPendingDealerInfo = QuotePortalUtils.quotesHaveDevicesWithMissingInformation(new Id[]{quote.record.Id});
if(quoteHasPendingDealerInfo.get(quote.record.Id) && isAgreementAcceptedStatus(quote.record.SBQQ__Status__c)) {
quote.record.SBQQ__Status__c = 'Customer Accepted Agreement, Pending Dealer Input';
update quote.record;
QuotePortalUtils.sendCompleteInformationEmail(quote.record);
} else {
Boolean priorProvisioningSendFlag = quote.record.Provisioning_Requested__c;
update quote.record;
SBQQ__Quote__c q = [SELECT Provisioning_Requested__c FROM SBQQ__Quote__c WHERE Id = :quote.record.Id];
sendProvision = (priorProvisioningSendFlag == false) && q.Provisioning_Requested__c;
if (sendProvision) {
sendProvisioningEmail(quote.record);
}
}
if (quote.record.Group__c != null) {
SBQQ__Quote__c changedQuote = [SELECT Kana_Queue__c FROM SBQQ__Quote__c WHERE Id = :quote.record.Id];
SBQQ__Quote__c[] otherQuotes =
[SELECT Name, SBQQ__Status__c, Order_Complete__c, Client_In_Store__c, Assigned_Account_Order__c, CreatedById FROM SBQQ__Quote__c
WHERE Id != :quote.record.Id AND Group__c = :quote.record.Group__c];
for (SBQQ__Quote__c other : otherQuotes) {
other.SBQQ__Status__c = quote.record.SBQQ__Status__c;
other.Order_Complete__c = quote.record.Order_Complete__c;
other.Client_In_Store__c = quote.record.Client_In_Store__c;
other.Assigned_Account_Order__c = quote.record.Assigned_Account_Order__c;
if (quoteHasPendingDealerInfo.get(quote.record.Id)) {
QuotePortalUtils.sendCompleteInformationEmail(other);
} else if (sendProvision) {
sendProvisioningEmail(other);
}
}
update otherQuotes;
Quote_Group__c grp = new Quote_Group__c(Id=quote.record.Group__c);
grp.Status__c = quote.record.SBQQ__Status__c;
grp.Order_Complete__c = quote.record.Order_Complete__c;
grp.Client_In_Store__c = quote.record.Client_In_Store__c;
grp.Kana_Queue__c = changedQuote.Kana_Queue__c;
update grp;
}
PageReference pref = new PageReference(returnURL);
pref.setRedirect(true);
return pref;
} catch (Exception e) {
ApexPages.addMessages(e);
Database.rollback(sp);
}
return null;
}
private void sendProvisioningEmail(SBQQ__Quote__c quote) {
PageReference pref = Page.QuoteProvisionRequest;
pref.setRedirect(true);
pref.getParameters().put('qid', quote.Id);
pref.getParameters().put('pd', '1');
String body = pref.getContent().toString();
QuotePortalUtils.sendProvisioningEmail(quote, body);
}
public PageReference onCancel() {
PageReference pref = new PageReference(returnURL);
pref.setRedirect(true);
return pref;
}
public PageReference onPrint() {
PageReference pref = Page.PrintQuote;
pref.getParameters().put('qids', quote.id);
pref.getParameters().put('retURL', getSummaryPageURL());
pref.setRedirect(true);
return pref;
}
public PageReference onEmail() {
PageReference pref = Page.SendQuoteEmail;
pref.getParameters().put('qids', quote.id);
pref.getParameters().put('aid', account.Id);
pref.getParameters().put('retURL', getSummaryPageURL());
pref.setRedirect(true);
return pref;
}
public PageReference onSendAgreement() {
PageReference pref = Page.SendQuoteAgreement;
pref.getParameters().put('qids', quote.id);
pref.getParameters().put('aid', account.Id);
pref.getParameters().put('retURL', getSummaryPageURL());
pref.setRedirect(true);
Boolean requiredInformationFilled = QuoteCustomConfigurationService.isRequiredAdditionalInformationFilled(quote.Id, QuoteStatus.SENT_AGREEMENT);
if(!requiredInformationFilled){
ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.INFO,
'There is required data that needs to be filled before you can send the agreement. Click <a href="QuoteCompleteInformation?qid='
+ quote.id + '&stage=' + EncodingUtil.urlEncode(QuoteStatus.SENT_AGREEMENT, 'UTF-8')
+ '&retUrl=' + EncodingUtil.urlEncode(pref.getUrl(), 'UTF-8') + '">here </a> to complete the data.'));
return null;
}
return pref;
}
public PageReference onLoad() {
String link = ApexPages.currentPage().getParameters().get('link');
if (link == '1') {
QuoteCustomConfigurationController.linkUnassignedAdditionalInformation(quote.record.Id);
}
return null;
}
public PageReference onCheckCredit() {
PageReference submitCreditPageRef = Page.SubmitCreditCheck;
submitCreditPageRef.getParameters().put('summaryUrl', getSummaryPageURL());
submitCreditPageRef.getParameters().put('qid', quote.id);
Boolean requiredInformationFilled = QuoteCustomConfigurationService.isRequiredAdditionalInformationFilled(quote.Id, QuoteStatus.SENT_FOR_CREDIT_CHECK);
if(!requiredInformationFilled){
ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.INFO,
'There is required data that needs to be filled before you can send the quote for credit check. Click <a href="QuoteCompleteInformation?qid='
+ quote.id + '&stage=' + EncodingUtil.urlEncode(QuoteStatus.SENT_FOR_CREDIT_CHECK, 'UTF-8')
+ '&retUrl=' + EncodingUtil.urlEncode(submitCreditPageRef.getUrl(), 'UTF-8')
+ '">here </a> to complete the data.'));
return null;
}
// Traction addition for QTR5 Req 10 + 11
// Allowing Account & Contact fields to be optional until later in the quote process
/* Pseudocode Account Information Checking :) - this should probably become a class with a 2 param method... quote Id and status
@map of all account fields that should be displayed, and when they should be mandatory...
@method
*/
Boolean requiredAccountInformationFilled;
requiredAccountInformationFilled = true;
if (account.Type_of_customer__c == '') {
requiredAccountInformationFilled = false;
}
if(account.BAN_type__c == '') {
requiredAccountInformationFilled = false;
}
if (account.Billing_Address__c == '' ||
account.Billing_City__c == '' ||
account.Billing_State__c == '' ||
account.Billing_Country__c == '' ||
account.Billing_PostalCode__c == '' ||
account.Billing_Province__c == '') {
requiredAccountInformationFilled = false;
}
if (account.Shipping_Address__c == '' ||
account.Shipping_City__c == '' ||
account.Shipping_State__c == '' ||
account.Shipping_Country__c == '' ||
account.Shipping_PostalCode__c == '' ||
account.Shipping_Province__c == '') {
requiredAccountInformationFilled = false;
}
if (!requiredAccountInformationFilled) {
ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.INFO,
'Additional Account information must be filled before you can send the quote for credit check.'
+ ' Click <a href="QuoteCompleteInformation?qid='
+ quote.id + '&stage=' + EncodingUtil.urlEncode(QuoteStatus.SENT_FOR_CREDIT_CHECK, 'UTF-8')
+ '&retUrl=' + EncodingUtil.urlEncode(submitCreditPageRef.getUrl(), 'UTF-8')
+ '">here </a> to complete the data.'));
return null;
}
return submitCreditPageRef;
}
public String getQuoteRefresh() {
String id = ApexPages.currentPage().getParameters().get('qid');
if ((quote != null) && (quote.record.Id != id)) {
init(id);
}
return '';
}
}