You can split single or multiple invoice(s) into multiple invoices by calling the Apttus_Billing.BillingService.createSplitInvoices API. You have an option to choose between split by amount or split by percentage methods.

The API can handle the splitting of 10 invoices with 12 line items each during a single execution.

API

Signature

Apttus_Billing.BillingService.createSplitInvoices

static List createSplitInvoices(List splitInvoiceRequests)

The API accepts source invoice ID, split by amount or percentage, number of splits, as the required input parameters. For each SplitInvoiceRequest, a set of split invoices is generated in Draft status. You can auto-approve the split invoices by setting the Auto Approve Split Invoices to True.

Request - SplitInvoiceRequestInput

Field

Type

Required

Description

Source Invoice ID

ID

Yes

The ID of the approved Invoice to be split.

Split By Amount or Percentage.

Decimal

Yes

The split method to be used for splitting the invoice.

  • Percent: Enter “Percent” if you want to split the invoice based on the percentage for each split invoice. For example, the total invoice amount of the source invoice is $100 and you want to split it into two invoices based on percentages of 60% and 40% respectively.

  • Amount: Enter “Amount“ if you want to split the invoice based on the amount for each split invoice. For example, the total invoice amount of the source invoice is $100 and you want to split it into two invoices based on amounts of $75 and $25 respectively.

Number of Splits

Decimal

Yes

The number of splits you want for the source invoice.

Auto Approve Split Invoices

Boolean

No

If True, the split invoice is transitioned to Approved status otherwise it is created in a Draft status.

Generate Invoice Line Summary

Boolean

No

If True, the split invoices have a line summary generated for them; otherwise, they are created without any line summary.

Split Details Info

List

Yes

Information pertaining to splitting the invoices.

Request - SplitInvoiceLineItemInput

Field

Type

Required

Description

Split By Value

Decimal

Yes

The fee amount of the split invoice

Date of Split

Date

Yes

Date of split

Payment Term ID

ID

No

Payment term ID to be associated with the split invoice

Bill To ID

ID

No

The bill to ID for the split invoice.

Account Location ID

ID

No

The account location ID for the split invoice.

Response

Field

Type

Description

CustomClass.SplitInvoiceResponse

List

A result parameter is returned for each request parameter.

When you split an invoice, the status of the source invoice changes to Distributed status. The split invoices are created based on the values provided by the user. Split invoices are created with the same number of invoice line items as that of the source invoice. The amount for the split invoice is distributed based on the split percentage or split amount. Taxes are recalculated based on the split invoices and Destination Related A/R Transactions are created for each split invoice.

The API returns an error message if:

  • The source invoice ID is not valid.

  • The source invoice ID is valid but the invoice is not approved.

  • The source invoice ID is valid but the invoice has a credit memo associated with it.

  • The source invoice ID is valid but the invoice is paid from a wallet.

  • The source invoice ID is valid but the invoice is already split.

  • The number of splits is an invalid value.

  • The “Split by” is null or has an unrecognized value.

  • The number of supplied values for “Split by value” does not match the “Number of splits” mentioned.

  • The sum of the percent values of all the splits is not equal to 100.

  • The sum of the split amounts mentioned in the split lines does not equal the total value on the original invoice.

  • “Auto approve the split invoices” or “Generate Invoice Lines Summary” does not have a valid value.

  • Details like Bill To, Location, Payment Term, or Invoice Date are supplied for a few of the splits.

Code Sample to Split Single Invoice

//API Details For Split Functions
//===============================
Apttus_Billing.CustomClass.SplitInvoiceDetails details1 = new Apttus_Billing.CustomClass.SplitInvoiceDetails
(
40, // Split By value
DateTime.now(), // Date Of Split
null, // Payment Term ID
null, // Bill To ID
null // Account Location ID
);
Apttus_Billing.CustomClass.SplitInvoiceDetails details2 = new Apttus_Billing.CustomClass.SplitInvoiceDetails
(40,DateTime.now(),null,null,null);
Apttus_Billing.CustomClass.SplitInvoiceDetails details3 = new Apttus_Billing.CustomClass.SplitInvoiceDetails
(20,DateTime.now(),null,null,null);
  
List<Apttus_Billing.CustomClass.SplitInvoiceDetails> splitDetails = new List<Apttus_Billing.CustomClass.SplitInvoiceDetails>();
splitDetails.add(details1);
splitDetails.add(details2);
splitDetails.add(details3);
system.debug('---'+splitDetails);
  
Apttus_Billing.CustomClass.SplitMethod percentage = Apttus_Billing.CustomClass.SplitMethod.SPLIT_BY_PERCENTAGE;
//Apttus_Billing.CustomClass.SplitMethod amount = Apttus_Billing.CustomClass.SplitMethod.SPLIT_BY_AMOUNT;
Apttus_Billing.CustomClass.SplitInvoiceRequest input1 = new Apttus_Billing.CustomClass.SplitInvoiceRequest
(
'a6I7e000000l1uc', //Source Invoice ID.
percentage, //Split By. amount or percentage.
3, //No Of Splits.
true, //Auto Approve split invoices.
true, //Generate Invoice Line Summary.
splitDetails //Split Details Info.
);
List<Apttus_Billing.CustomClass.SplitInvoiceRequest> splitInvoice = new List<Apttus_Billing.CustomClass.SplitInvoiceRequest>();
splitInvoice.add(input1);
  
List<Apttus_Billing.CustomClass.SplitInvoiceResponse> splitResp = new List<Apttus_Billing.CustomClass.SplitInvoiceResponse>();
splitResp = Apttus_Billing.BillingService.createSplitInvoices(splitInvoice);
  
system.debug('Response!!!!'+splitResp);
CODE

Code Sample to Split Multiple Invoices

Apttus_Billing.CustomClass.SplitInvoiceDetails details1 =  new Apttus_Billing.CustomClass.SplitInvoiceDetails(8.33333,DateTime.now(),null,null,null);
Apttus_Billing.CustomClass.SplitInvoiceDetails details2 =  new Apttus_Billing.CustomClass.SplitInvoiceDetails(8.33334,DateTime.now(),null,null,null);
Apttus_Billing.CustomClass.SplitInvoiceDetails details3 =  new Apttus_Billing.CustomClass.SplitInvoiceDetails(8.33335,DateTime.now(),null,null,null);
Apttus_Billing.CustomClass.SplitInvoiceDetails details4 =  new Apttus_Billing.CustomClass.SplitInvoiceDetails(8.33336,DateTime.now(),null,null,null);
Apttus_Billing.CustomClass.SplitInvoiceDetails details5 =  new Apttus_Billing.CustomClass.SplitInvoiceDetails(8.33337,DateTime.now(),null,null,null);
Apttus_Billing.CustomClass.SplitInvoiceDetails details6 =  new Apttus_Billing.CustomClass.SplitInvoiceDetails(8.33338,DateTime.now(),null,null,null);
Apttus_Billing.CustomClass.SplitInvoiceDetails details7 =  new Apttus_Billing.CustomClass.SplitInvoiceDetails(8.33339,DateTime.now(),null,null,null);
Apttus_Billing.CustomClass.SplitInvoiceDetails details8 =  new Apttus_Billing.CustomClass.SplitInvoiceDetails(8.33340,DateTime.now(),null,null,null);
Apttus_Billing.CustomClass.SplitInvoiceDetails details9 =  new Apttus_Billing.CustomClass.SplitInvoiceDetails(8.33341,DateTime.now(),null,null,null);
Apttus_Billing.CustomClass.SplitInvoiceDetails details10 = new Apttus_Billing.CustomClass.SplitInvoiceDetails(8.33342,DateTime.now(),null,null,null);
Apttus_Billing.CustomClass.SplitInvoiceDetails details11 = new Apttus_Billing.CustomClass.SplitInvoiceDetails(8.33343,DateTime.now(),null,null,null);
Apttus_Billing.CustomClass.SplitInvoiceDetails details12 = new Apttus_Billing.CustomClass.SplitInvoiceDetails(8.33282,DateTime.now(),null,null,null); 
List<Apttus_Billing.CustomClass.SplitInvoiceDetails> splitDetails1 = new List<Apttus_Billing.CustomClass.SplitInvoiceDetails>();
splitDetails1.add(details1);
splitDetails1.add(details2);
splitDetails1.add(details3);
splitDetails1.add(details4);  
splitDetails1.add(details5);
splitDetails1.add(details6);
splitDetails1.add(details7);
splitDetails1.add(details8);
splitDetails1.add(details9);
splitDetails1.add(details10);  
splitDetails1.add(details11);
splitDetails1.add(details12);

//Apttus_Billing.CustomClass.SplitMethod percentage = Apttus_Billing.CustomClass.SplitMethod.SPLIT_BY_PERCENTAGE;
Apttus_Billing.CustomClass.SplitMethod amount = Apttus_Billing.CustomClass.SplitMethod.SPLIT_BY_AMOUNT;

//a5T040000001ANF - invalid id. 
Apttus_Billing.CustomClass.SplitInvoiceRequest input1 = new Apttus_Billing.CustomClass.SplitInvoiceRequest('a5T040000001ANf',amount,12,false,true,splitDetails1);
//a5T040000001ANK - in draft mode.
Apttus_Billing.CustomClass.SplitInvoiceRequest input2 = new Apttus_Billing.CustomClass.SplitInvoiceRequest('a5T040000001ANK',amount,12,false,true,splitDetails1);
//a5T040000001ANP- with Distributed status
Apttus_Billing.CustomClass.SplitInvoiceRequest input3 = new Apttus_Billing.CustomClass.SplitInvoiceRequest('a5T040000001ANP',amount,12,false,true,splitDetails1);
//Auto Approve option is set to null.
Apttus_Billing.CustomClass.SplitInvoiceRequest input4 = new Apttus_Billing.CustomClass.SplitInvoiceRequest('a5T040000001ANU',amount,12,null,true,splitDetails1);
//Number of split details =12, but provided value=10.
Apttus_Billing.CustomClass.SplitInvoiceRequest input5 = new Apttus_Billing.CustomClass.SplitInvoiceRequest('a5T040000001ANZ',amount,10,false,true,splitDetails1);
//split by is not valid
Apttus_Billing.CustomClass.SplitInvoiceRequest input6 = new Apttus_Billing.CustomClass.SplitInvoiceRequest('a5T040000001ANe',amount,12,false,true,splitDetails1);
Apttus_Billing.CustomClass.SplitInvoiceRequest input7 = new Apttus_Billing.CustomClass.SplitInvoiceRequest('a5T040000001ANj',amount,12,false,true,splitDetails1);
Apttus_Billing.CustomClass.SplitInvoiceRequest input8 = new Apttus_Billing.CustomClass.SplitInvoiceRequest('a5T040000001ANo',amount,12,false,true,splitDetails1);
Apttus_Billing.CustomClass.SplitInvoiceRequest input9 = new Apttus_Billing.CustomClass.SplitInvoiceRequest('a5T040000001ANt',amount,12,false,true,splitDetails1);
Apttus_Billing.CustomClass.SplitInvoiceRequest input10 = new Apttus_Billing.CustomClass.SplitInvoiceRequest('a5T040000001ANy',amount,12,false,true,splitDetails1);

List<Apttus_Billing.CustomClass.SplitInvoiceRequest> splitInvoice = new List<Apttus_Billing.CustomClass.SplitInvoiceRequest>();
splitInvoice.add(input1);
splitInvoice.add(input2);
splitInvoice.add(input3);
splitInvoice.add(input4);
splitInvoice.add(input5);
splitInvoice.add(input6);
splitInvoice.add(input7);
splitInvoice.add(input8);
splitInvoice.add(input9);
splitInvoice.add(input10);
//=======================================================================
 
List<Apttus_Billing.CustomClass.SplitInvoiceResponse>  splitResp = new List<Apttus_Billing.CustomClass.SplitInvoiceResponse>();
splitResp = Apttus_Billing.BillingService.createSplitInvoices(splitInvoice);
system.debug('Response!!!!'+splitResp);

CODE