Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

Generating a Customer Invoice through SDK

Hi Guys, hope that all of you are fine!

I've been trying to deal with this on my own for a while, but honestly.. I just can't.

I'm trying to create a Customer Invoice from the sdk, as far as I know in order to do that you need first to generate a Customer Invoice Request.. here's where it gets annoying..

I tried it.. several times, with the code in the PSM (It doesn't work.. what a surprise), consuming the CustomerInvoiceRequest web service.. and nothing..

There's a web service in the system that allows to create an Invoice.. it's called ManageCustomerInvoiceRequestIn.. but i'm not able to use it..

Thanks to all of you in advance

Tags:
Former Member replied

I have tested this code and this is working fine.

This code was written in a BeforeSave of a CustomBO.

It also contains the code for creating and releasing the Invoice after creating Request.

So, please find the syntax of creating invoice from a request(incase you missed this from studio)

I request you to use this function based on your use case.

You  might see some errors after executing this code. You can ignore them. However, both InvoiceRequest and Invoice will be created successfully.

Whatever you do, I request you NOT to change the sequence of code.

Invoice Item needs either a product or a GL account assignment. So, I have given you both examples in this code by commenting one.

Also, please make a note that you can eliminate some coding by right customer account setup.

For eg., Currency and Pricing terms can be assigned in the Sales Data of the Customer Account and so, whenever this customer along with the sales unit is used in any Customer Invoice Request, those values are picked up automatically so that you don't have to maintain them in your coding.

May be your CRM leads can help you in this setup.

import

ABSL;


import

AP.CustomerInvoicing.Global;



// define CustomerInvoiceRequest root node


var

elCustomerInvoiceRequest_Root: elementsof CustomerInvoiceRequest;


var

instCustomerInvoiceRequest;



// define CustomerInvoiceRequest BusinessProcessVariantType node


var

elCustomerInvoiceRequest_BPVT: elementsof CustomerInvoiceRequest.BusinessProcessVariantType;


var

instCustomerInvoiceRequest_BPVT;



// define CustomerInvoiceRequest buyer party node


var

elCustomerInvoiceRequest_BuyerParty: elementsof CustomerInvoiceRequest.Party;


var

instCustomerInvoiceRequest_BuyerParty;



// define CustomerInvoiceRequest sales unit party node


var

elCustomerInvoiceRequest_SalesUnitParty: elementsof CustomerInvoiceRequest.Party;


var

instCustomerInvoiceRequest_SalesUnitParty;



// define CustomerInvoiceRequest item node


var

elCustomerInvoiceRequest_Item: elementsof CustomerInvoiceRequest.Item;


var

instCustomerInvoiceRequest_Item;



var

ItemProduct : elementsof CustomerInvoiceRequest.Item.ItemProduct;



// define CustomerInvoiceRequest item accounting coding block node


var

elCustomerInvoiceRequest_ItemACBD: elementsof CustomerInvoiceRequest.Item.ItemAccountingCodingBlockDistribution;


var

instCustomerInvoiceRequest_ItemACBD;



// define CustomerInvoiceRequest item price component


var

elCustomerInvoiceRequest_Item_MainPrice: elementsof CustomerInvoiceRequest.PriceAndTaxCalculation.Item.ItemPriceComponent;


var

instCustomerInvoiceRequest_Item_MainPrice;



// InvoiceDate setting to current date for this example.


var

InvoiceDate = Context.GetCurrentUserDate();



// CustomerInvoiceRequest: create new instance




// CustomerInvoiceRequest: maintain BPVT node


// BusinessProcessVariantTypeCode = 3 describes type 'Manual Invoice'


elCustomerInvoiceRequest_BPVT

.BusinessProcessVariantTypeCode = "3";



elCustomerInvoiceRequest_Root

.CustomerInvoiceProcessingTypeCode = "CI";


instCustomerInvoiceRequest

= CustomerInvoiceRequest.Create(elCustomerInvoiceRequest_Root);


// CustomerInvoiceRequest: create new BPVT instance


// Without the BPVT node no modifications can be made to the CustomerInvoiceRequest


instCustomerInvoiceRequest_BPVT

= instCustomerInvoiceRequest.BusinessProcessVariantType.Create(elCustomerInvoiceRequest_BPVT);



// Assign currencycode


if

(!instCustomerInvoiceRequest.PricingTerms.IsSet()){


var temp = instCustomerInvoiceRequest.PricingTerms.Create();


temp.CurrencyCode = "GBP";


}


else

{


instCustomerInvoiceRequest.PricingTerms.CurrencyCode = "GBP";


}



// CustomerInvoiceRequest: maintain customer invoice processing type - mandatory


instCustomerInvoiceRequest

.CustomerInvoiceProcessingTypeCode = "CI";



// CustomerInvoiceRequest: maintain description - optional


instCustomerInvoiceRequest

.Name = "CIR From ABSL";



// CustomerInvoiceRequest:: maintain buyer party - mandatory


elCustomerInvoiceRequest_BuyerParty

.PartyKey.PartyID.content = "CP100992";



// CustomerInvoiceRequest: create new party instance


instCustomerInvoiceRequest_BuyerParty

= instCustomerInvoiceRequest.BuyerParty.Create(elCustomerInvoiceRequest_BuyerParty);



// CustomerInvoiceRequest:: maintain sales unit party - mandatory


elCustomerInvoiceRequest_SalesUnitParty

.PartyKey.PartyID.content = "P1110";



// CustomerInvoiceRequest: create new party instance


instCustomerInvoiceRequest_SalesUnitParty

= instCustomerInvoiceRequest.SalesUnitParty.Create(elCustomerInvoiceRequest_SalesUnitParty);



// Assign Cash Discount Terms


if

(!instCustomerInvoiceRequest.CashDiscountTerms.IsSet()){


var PaymentTerms = instCustomerInvoiceRequest.CashDiscountTerms.Create();


PaymentTerms.Code.content = "001";


}


else

{


instCustomerInvoiceRequest.CashDiscountTerms.Code.content = "0001";


}



// CustomerInvoiceRequest: maintain item with product



// CustomerInvoiceRequest.Item: maintain description - mandatory


elCustomerInvoiceRequest_Item

.Description.content = "Test from ABSL";



// CustomerInvoiceRequest.Item: maintain quantity - mandatory


elCustomerInvoiceRequest_Item

.Quantity.content  = 1;


elCustomerInvoiceRequest_Item

.Quantity.unitCode = "EA";



// CustomerInvoiceRequest: create item instance


instCustomerInvoiceRequest_Item

= instCustomerInvoiceRequest.Item.Create(elCustomerInvoiceRequest_Item);


if

(!instCustomerInvoiceRequest_Item.ItemProduct.IsSet()){


var instItemProduct = instCustomerInvoiceRequest_Item.ItemProduct.Create();


instItemProduct.ProductKey.ProductID.content = "P100202";


}



// CustomerInvoiceRequest.Item.ItemAccountingCodingBlockDistribution: maintain GL-account - mandatory


//elCustomerInvoiceRequest_ItemACBD.GeneralLedgerAccountAliasCode.content = "A-1500";



// CustomerInvoiceRequest.Item: create new ItemAccountingCodingBlockDistribution instance


//instCustomerInvoiceRequest_ItemACBD = instCustomerInvoiceRequest_Item.ItemAccountingCodingBlockDistribution.Create(elCustomerInvoiceRequest_ItemACBD);



// CustomerInvoiceRequest.Item.PATCItem: maintain tax code - mandatory (code 501 = Sales Tax - Standard Rate)


instCustomerInvoiceRequest_Item

.PriceAndTaxCalculationItem.TaxationCharacteristicsCode.content = "509";



// CustomerInvoiceRequest.Item.PriceAndTaxCalculationItem.ItemMainTotal: Maintain price


instCustomerInvoiceRequest_Item

.PriceAndTaxCalculationItem.ItemMainTotal.Rate.BaseDecimalValue = 150;


instCustomerInvoiceRequest_Item

.PriceAndTaxCalculationItem.ItemMainTotal.Rate.CurrencyCode     = "GBP";



// To Create Invoice from this request and to release it.


// Use the parameters of this function based on your need. Setting second parameter to "true" releases the invoice.


// Incase you miss the syntax from ByD, here you go CreateCustomerInvoices(CustomerInvoiceDate,AutomaticReleaseIndicator,BBTDBasedSeperationReqdIndicator,PDBasedSeperationReqdIndicator,InvClearingRequestedIndicator)


instCustomerInvoiceRequest

.CreateCustomerInvoices(InvoiceDate,true,false,false,false);

Message was edited by: Srivatsava Janaswamy

2 View this answer in context
Not what you were looking for? View more on this topic or Ask a question