cancel
Showing results for 
Search instead for 
Did you mean: 

How to reverse a manual Journal Entry Voucher created via Custom BO

former_member187149
Participant
0 Kudos

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

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hello Navin,

There is an action "Cancel" in the Accounting Entry BO. Try calling that action from ABSL whenever the CI is canceled. But to do that you should have the reference of the created JEV through code.

Hope this helps.

Thanks & Regards,

Meghna

kostadin_terziev
Participant
0 Kudos

Hello!

I have tried with cancel, and when debugging the status of the JEV is cancelled, but after that when i check in the UI, the JEV is still with status Posted. Here is the code i use:

import ABSL;
import AP.Common.GDT;
import AP.CustomerInvoicing.Global;
import AP.FinancialAccounting.Global;
import AP.DueItemManagement.Global;

var invoice = CustomerInvoice.Retrieve(this.invoiceUUID);
var isInvoiceCancelled = false;
if (invoice.IsSet()) {
	var releaseCancelled = invoice.Status.ReleaseStatusCode.Matches("5");
	if (releaseCancelled && !invoice.CancellationDocumentIndicator) {
		isInvoiceCancelled = true;
	}
}

// DP INVOICE CANCELLATION HANDLER:
if (this.invoiceCancelled || isInvoiceCancelled) {
	// check if the invoice is cancelled and then reverse the journal entry
	var key : AccountingEntryKey;
	key.ID = this.jevID;
	key.CompanyUUID = invoice.BillFromParty.PartyUUID;
	var jev = AccountingEntry.Retrieve(key);
	jev.Cancel();
	// raise message that jev has been cancelled
	if (jev.Status.PostingStatusCode.Matches("4")) {
		raise MsgJEVCancelled.Create("S", jev.ID);
	}
}

Answers (1)

Answers (1)

former_member187149
Participant
0 Kudos

Hi Meghna ,

Thanks for your prompt response.

I will try the above mentioned process and get back to you..

Regards,

Navin Kandasamy