Hi All,
I have created a custom BO for triggering a Journal Entry Voucher for each and every Customer Invoice created in the system.Normally all Customer Invoice will be having a corresponding Journal Entry document ,apart from the default JE document I have created an additional Journal Entry for each CI through a Custom BO because of the Business requirement.I am using the default JE as the source document for the newly created JE for the same CI.
If a custom invoice gets cancelled only the default JE will get reversed.How to reverse the newly created JE too.I there a way to carry out this reversal process through PDI using ABSL.
Please find below the code for details.
Custom BO contains these lines.
import ABSL;
import AP.FinancialAccounting.Global;
import AP.CustomerInvoicing.Global;
var query;
var selparam;
var resultset;
var query1;
var selparam1;
var resultset1;
var query2;
var selparam2;
var resultset2;
query = AccountingDocument.QueryByElements;
selparam = query.CreateSelectionParams();
selparam.Add(query.UUID.content, "I", "EQ", this.ZJEUUID.content);
resultset = query.Execute(selparam).GetFirst();
selparam.Clear();
if (resultset.IsSet())
{
var CI_ID = resultset.OriginalEntryDocumentContainingObjectReference.FormattedID;
if (!CI_ID.IsInitial())
{
query1 = CustomerInvoice.QueryByElements;
selparam1 = query1.CreateSelectionParams();
selparam1.Add(query1.ID.content, "I", "EQ", CI_ID);
resultset1 = query1.Execute(selparam1).GetFirst();
selparam1.Clear();
}
if (resultset1.IsSet())
{
foreach (var itemIns in resultset1.Item)
{
var qty = itemIns.Quantity.content;
var pid = itemIns.ItemProduct.ProductKey.ProductID.content;
query2 = ZProductTax.QueryByElements;
selparam2 = query2.CreateSelectionParams();
selparam2.Add(query2.ZprdID.content, "I", "EQ", pid);
resultset2 = query2.Execute(selparam2).GetFirst();
selparam2.Clear();
if(resultset2.IsSet())
{
this.ZEnvTax.content = this.ZEnvTax.content + (qty * resultset2.ZtaxPrice.content);
this.ZEnvTax.currencyCode = resultset2.ZtaxPrice.currencyCode;
this.InvID = resultset.OriginalEntryDocumentContainingObjectReference.FormattedID;
}
}
}
}
//Manual creating of Journal Voucher //
var newJV = AccountingEntry.Create();
newJV.CompanyID = resultset.Company.ID;
newJV.Note.content = resultset.Note.content;
newJV.AccountingDocumentTypeCode = "00047";
newJV.BusinessTransactionTypeCode = "601";
newJV.TransactionCurrencyCode = resultset.Item.GetFirst().BusinessTransactionCurrencyAmount.currencyCode;
newJV.AccountingClosingStepCode = resultset.AccountingClosingStepCode;
newJV.ZcustomerID.content = resultset1.BuyerParty.PartyKey.PartyID.content;
newJV.PostingDate = resultset.PostingDate;
var sob = newJV.SetOfBooks.Create();
sob.SetOfBooksID.content = resultset.SetOfBooksID.content;
//Making the Credit account of Original JE as Debit account in this JV//
var debitAccIns = resultset.Item.Where(c => c.DebitCreditCode == "2").GetFirst();
var debitAcc = debitAccIns.ChartOfAccountsItemCode;
var newJVGL = newJV.Item.Create();
newJVGL.DebitCreditCode = "1";
newJVGL.ChartOfAccountsItemCode.content = debitAcc.content;
newJVGL.TransactionCurrencyAmount.content = this.ZEnvTax.content;
newJVGL.TransactionCurrencyAmount.currencyCode = this.ZEnvTax.currencyCode;
// Posting the debited account to a new GL account//
var newJVGL1 = newJV.Item.Create();
newJVGL1.DebitCreditCode = "2";
newJVGL1.ChartOfAccountsItemCode.content = "101000";
newJVGL1.TransactionCurrencyAmount.content = this.ZEnvTax.content;
newJVGL1.TransactionCurrencyAmount.currencyCode = this.ZEnvTax.currencyCode;
Please respond ASAP
Regards,
Navin Kandasamy