Create Draft Sales Invoice

Zumzum Financials Knowledge Base

    This document describes the apex metadata, which is responsible to create draft Sales Invoices:

    Class : SalesInvoicePostService

    Function : CreateSalesInvoices

    Input : List<SalesInvoiceWrapper>

    Output : List<Sales_Invoice__c>

    This function will accept the list of ‘SalesInvoiceWrapper’ as an input parameter. The below text highlighted in the box represents the attributes of the wrapper class.

    global class SalesInvoiceWrapper{
     global Id Customer {get;set;}  /* [Required : Account Id] */
     global Date InvoiceDate {get;set;} /* [Required : InvoiceDate] */
     global Id Opportunity {get;set;} /* [Optional : Opportunity Id] */ 
     global Id TransactionCurrency {get;set;} /* [Required : Sales Invoice Currency Id] */ 
     global List<SalesInvoiceLineWrapper> LineItems {get;set;}  /* [Required : List of invoice line items] */
    }
    
    
    global class SalesInvoiceLineWrapper{
     global Id Product {get;set;}  /* [Required : Product Id] */
     global Id TaxRate {get;set;} /* [Required : Tax Rate Id] */
     global decimal ForeignNetAmount {get;set;} /* [Required : Line item Foreign Net Amount for single quantity] */
     global integer Quantity {get;set;} /* [Required : line item quantity] */
    }

    Sample Code :

    /* Create draft invoices */
    SalesInvoicePostService objInvoiceHandler = new SalesInvoicePostService();
    List<SalesInvoicePostService.SalesInvoiceWrapper > lstInvData = new List<SalesInvoicePostService.SalesInvoiceWrapper >();
             
    SalesInvoicePostService.SalesInvoiceWrapper inv = new SalesInvoicePostService.SalesInvoiceWrapper( );
    inv.Customer = '001b000003n1k1I';
    inv.InvoiceDate = date.today();
    inv.TransactionCurrency = 'a0vb0000005EIAf';
    SalesInvoicePostService.SalesInvoiceLineWrapper invLine = new SalesInvoicePostService.SalesInvoiceLineWrapper();
    invLine.Product = '01tb0000005MawT';
    invLine.Quantity = 2;
    invLine.TaxRate = 'a03b000000CoYXo';
    invLine.ForeignNetAmount= 150;
    inv.LineItems = new List<SalesInvoicePostService.SalesInvoiceLineWrapper>();
    inv.LineItems.add(invLine);
    lstInvData.add(inv);
    List<Sales_Invoice__c> lstSalesInvoices = objInvoiceHandler.CreateSalesInvoices(lstInvData);
    system.debug('lstSalesInvoices::' + lstSalesInvoices);
    
    
    in Integration Tags: Create Draft Sales InvoiceIntegrationSales Invoice