Happy Business Starts Here

Highlighted
New Student

Subscription end date problem when upselling.

Hi community!

I encounter a problem while making an upsell amendment on an existing (and already billed) quote.

I used many of sample codes and all kind of things i found on doing it, buut still have a deal.

First let me introduce what i have/want:

I made a subscription starting on  may the 10th of 2019 for a 1 year product using the zQuoteUtil class in apex.

I want to make an addon (in quantity) to the subscription from  august the 1st 2019 to the end of the subscription (still using zquoteUtil class in an apex). 

When i send the quote to Zuora, and make a billing preview, end dates are not what expected.
I get the first invoice first with initial quantity and total billed, then a preview on the upsell start date from 08/01/2019 to 04/30/2020 where i expected a preview from 08/01//2019 to 05/09/2020.

 

As we cannot set decimal in zqu__InitialTerm__c i use salesforce monthsBetween function to calculate it.

Here is the code i use to make the amendment. Mayby someone can tell me what i'm doing wrong?


	        zqu__Quote__c quoteSObject = new zqu__Quote__c();
            
	        //First, create the quote
            quoteSObject.UNY_ClientEndUserId__c = chain.customerId__c;
            quoteSObject.UNY_CustomerName__c = chain.customerName__c;
            quoteSObject.Name = nam;
            quoteSObject.zqu__Description__c = 'test description';
            quoteSObject.zqu__Opportunity__c = opportunity.Id;
            quoteSObject.zqu__ValidUntil__c = opportunity.startDate__c;
            quoteSObject.zqu__Customer_Acceptance_Date__c = prevQuoteSObject.zqu__Customer_Acceptance_Date__c;
            quoteSObject.zqu__Service_Activation_Date__c = prevQuoteSObject.zqu__Service_Activation_Date__c;
            quoteSObject.zqu__Customer_Acceptance_Date__c = opportunity.startDate__c;
            quoteSObject.zqu__Service_Activation_Date__c = opportunity.startDate__c;

            double ratio = Double.valueOf(opportunity.startDate__c.daysBetween(prevOpportunity.endDate__c)) / Double.valueOf(prevOpportunity.startDate__c.daysBetween(prevOpportunity.endDate__c));
            double duration = Double.valueOf(prevOpportunity.duration__c) * ratio;

            quoteSObject.zqu__Subscription_Term_Type__c = prevQuoteSObject.zqu__Subscription_Term_Type__c;
            quoteSObject.zqu__SubscriptionTermStartDate__c = prevQuoteSObject.zqu__SubscriptionTermStartDate__c;
            quoteSObject.zqu__SubscriptionTermEndDate__c = prevQuoteSObject.zqu__SubscriptionTermEndDate__c;
            quoteSObject.zqu__QuoteBusinessType__c = 'Upsell';
            quoteSObject.zqu__Amendment_Name__c = 'Addon ' + opportunity.quantity__c;
            
            quoteSObject.zqu__SubscriptionType__c = 'Amend Subscription';
            quoteSObject.zqu__ZuoraAccountId__c = prevQuoteSObject.zqu__ZuoraAccountID__c;
            quoteSObject.zqu__StartDate__c = prevQuoteSObject.zqu__StartDate__c;
            quoteSObject.zqu__Account__c = prevQuoteSObject.zqu__Account__c;
            quoteSObject.zqu__BillToContact__c = prevQuoteSObject.zqu__BillToContact__c;
            quoteSObject.zqu__SoldToContact__c = prevQuoteSObject.zqu__SoldToContact__c;
            quoteSObject.zqu__BillingBatch__c = 'Batch1';
            
            quoteSObject.zqu__ExistSubscriptionID__c = prevQuoteSObject.zqu__ZuoraSubscriptionID__c;
            quoteSObject.zqu__GenerateInvoice__c = true;
            quoteSObject.zqu__Currency__c = prevQuoteSObject.zqu__Currency__c;
            quoteSObject.zqu__SubscriptionName__c = 'test name';
            quoteSObject.zqu__RenewalTerm__c = prevQuoteSObject.zqu__RenewalTerm__c;
            quoteSObject.zqu__InitialTerm__c = duration.intValue();
            quoteSObject.zqu__TermStartDate__c = opportunity.startDate__c;
            quoteSObject.zqu__PaymentTerm__c = paymentTerm;
            quoteSObject.zqu__ValidUntil__c = validUntil;
            quoteSObject.zqu__PaymentMethod__c = 'Wire Transfer';     // choice in Check, Wire Transfer, Credit Card, ACH, Cash, Other
            quoteSObject.zqu__RenewalSetting__c = 'RENEW_WITH_SPECIFIC_TERM';
            quoteSObject.zqu__ApprovalStatus__c = 'Approved';
            
            // Save the quote for the next step            
            newQuote = zqu.Quote.createNewInstance(quoteSObject);
            newQuote.buildAndSave();

(then, preview and sen to zbilling of course)

1 REPLY 1
Highlighted
Support SME

Re: Subscription end date problem when upselling.

@gquinet I would need to check the data as with which you are testing since this is very specific to dates. Could you please direct message me your Zuora Tenant ID and SF ORG ID alongwith the sample record. I will then check the details accordingly.






If you found my answer helpful, please give me a kudo ↑
Help others find answers faster by accepting my post as a solution √