Thursday, January 2, 2014

Import Vendor Invoices with AIF LedgerGeneralJournalService

One way of posting vendor invoices is simply posting credit to a vendor via a General Journal. From a business process point of view you might want to do this if you do not have Purchase Order Documents to post the invoice. Usually this happens in case of expense bills...such as office materials.

If you choose the AIF LedgerGeneralJournalService be aware of the following Problem:

Certain fields in the table LedgerJournalTrans do not get populated when using the Account Type "Vendor"
EG:
- the vendors posting profile is missing
- no Terms of Payments
- the due date does not get calculated


This happens because code on the form is triggered when you select the vendor account manually. The above described fields usually get populated by the LedgerJournalEngine Class.

Fix:
To fix this problem you have to modify the service axd Class. But caution! If you simply call the Standard LedgerJournalEngine Class, the AIF produces an Error. Here is my first approach:

AxdLedgerGeneralJournal
public void updateNow()
{
    (.. std code ..)
    
    // -->
    LedgerJournalTrans      ledgerJournalTrans;
    LedgerJournalEngine_DailyAif   ledgerJournalEngine = new LedgerJournalEngine_DailyAif();
    // <-- data-blogger-escaped---="" data-blogger-escaped-..="" data-blogger-escaped-code="" data-blogger-escaped-std="">
    ledgerJournalTrans = axLedgerJournalTrans.ledgerJournalTrans();
    switch (ledgerJournalTrans.AccountType)
    {
        case LedgerJournalACType::Vend:
            ledgerJournalEngine.accountModified(ledgerJournalTrans);
            ledgerJournalEngine.initFromVendTable(ledgerJournalTrans);
            break;
    }
    ledgerJournalTrans.update();

    (.. std code ..)
}

any inbound message will now result into the following Error: The request failed with the following error:
Exception of type 'Microsoft.Dynamics.Ax.Xpp.InvalidRemoteCallException' was thrown

Debugging with VS surfaced that the use of the FormRun parameter in the constructor resulted into an error. You need to create a couple of new classes based on LedgerJournalEngine and LedgerJournalEngine_Daily. Simply get rid of the parameter in method new().

I finally got everything to work with the following code:

AxdLedgerGeneralJournal
public void updateNow()
{
    #macrolib.LedgerAIF
    SysGlobalCache          cache = classfactory.globalCache();
    LedgerJournalTable      ledgerJournalTable;
    LedgerJournalInclTax    ledgerJournalInclTax;
    // -->
    LedgerJournalTrans      ledgerJournalTrans;
    //  LedgerJournalEngine_DailyAif is a new class based on LedgerJournalEngine
    LedgerJournalEngine_DailyAif   ledgerJournalEngine = new LedgerJournalEngine_DailyAif();
    // <--

    super();

    ledgerJournalTable = axLedgerJournalTable.ledgerJournalTable();
    ledgerJournalInclTax = LedgerJournalTable::find(ledgerJournalTable.JournalNum).LedgerJournalInclTax;
    [ledgerJournalTable.JournalTotalDebit,
        ledgerJournalTable.JournalTotalCredit,
        ledgerJournalTable.JournalTotalOffsetBalance] = LedgerJournalTable::journalBalanceMST(ledgerJournalTable.JournalNum,
                                                            false,
                                                            ledgerJournalInclTax,
                                                            false);
    ledgerJournalTable.JournalBalance = ledgerJournalTable.JournalTotalDebit - ledgerJournalTable.JournalTotalCredit;
    ledgerJournalTable.update();

    // -->
    ledgerJournalTrans = axLedgerJournalTrans.ledgerJournalTrans();
    switch (ledgerJournalTrans.AccountType)
    {
        case LedgerJournalACType::Vend:
            ledgerJournalEngine.accountModified(ledgerJournalTrans);
            ledgerJournalEngine.initFromVendTable(ledgerJournalTrans);
            break;
    }
    ledgerJournalTrans.update();
    // <--

   (.. std code ..)
}

If you want to reproduce this scenario:
- get the latest AX2012 vm (refresh 4 with CU7)
- create a new inbound port for the AIF service (simply use the file system adapter...)
- use the following xml



  
ussi http://schemas.microsoft.com/dynamics/2008/01/services/GeneralJournalService/create
ussi Detail GenJrn General Journal Vend 1007.00 ussi USD US_SI_000007 US_SI_000007 1.0000000000 Ledger ussi 500110-003-022-00000001-Application Development 500110 BusinessUnit 003 Department 022 Project 00000001 ServiceLine Application Development 2013-12-26 No Po Invoice

Further thoughts:

- Alternatively you could use the service LedgerPurchaseInvoiceService, this will create an Invoice Register (but in my experience they are less frequently used than the Ledger Journals / Invoice Journals)
- In order to submit a invoice number with the GeneralJournalService you need to add the field invoice!


hope this helps
-k

8 comments:

  1. this would be a great solution for all invoicing issues. I started using a invoicing and billing tool when I had issues with bills and invoice management.fetchflow provides an online service for small businesses and contractors who need to make invoicing quick and user friendly. You can view real-time account summaries at any time.simply sinup http://www.fetchflow.com/Signup/PayPal . fetchflow.com allow to Send invoices as PDF, e-mail or have clients access them online. They have forever free plan

    ReplyDelete
  2. what did you mean by "You need to create a couple of new classes based on LedgerJournalEngine and LedgerJournalEngine_Daily."? are you creating a copy of them or extending from them

    ReplyDelete
  3. Just to expand on this question. We created the LedgerJournalEngine_DailyAIF class which is a duplicate of LedgerJournalEngine_Daily which we renamed to be LedgerJournalEngine_DailyAIF with the new params removed. Where we are unclear is where the new LedgerJournalEngine class comes in?

    ReplyDelete
  4. Thank you for sharing this. Is it possible to share the new class you created in a bit more detail? I dont get the vendor information in the journal, even though I did exactly as what was described in your post. Adding the field invoice was fairly simple and works fine. Thanks in advance.

    ReplyDelete
  5. Hi I am Facing Same issue in Creating Customer Invoice and Customer Payment Through using AIF - GeneralJournalService in C#. LedgerJournalTrans(Line) is not updating with our TRANSDATE and DUE date, DOCUMENTDATE which we are sending from C# to Service class. Its Taking Default value(TODAY)for TRANSDATE and Rest DUE and DOCUMENT Date is not taking any Value so its showing as Empty. How do i get TRANS and DUE date.

    Please help Me as its Required for Live project.
    Regards
    Sachin

    ReplyDelete
  6. Use this online converter for file converting to other formats like these;

    Unique Converter

    ReplyDelete
  7. This can transfer your one file to other formats like these;

    Wmv to Gif

    Gif to Mov

    Png to Bmp

    M4p to Wav

    M4r to M4a

    ReplyDelete
  8. Great insights! Your deep knowledge of AIF registration is truly impressive. You've explained the complexities in a way that's easy to understand, making the process much clearer for readers. The step-by-step breakdown and regulatory insights are particularly helpful. Looking forward to more such informative posts!

    ReplyDelete

feel free to leave a comment or ask questions!