Skip to main content

Notifications

Microsoft Dynamics AX (Archived)

Vendor Settlement

Posted on by 1,450

Hello everyone!

I need to get all vendor invoiced transactions and all vendor honored transactions related to each transaction.

I can't find any good relation between this type of transactions (invoiced to honored). My aim is get the invoiced date and the settlement date to get how many days have passed.

I attach my code and thank you in advance.

static void JRA_VendSettlements(Args _args)
{
    TmpDueDateCompliance_ES_INL TmpDueDateCompliance_ES_INL;
    VendSettlement              VendSettlement;
    VendInvoiceJour             VendInvoiceJour;
    VendInvoiceTrans            VendInvoiceTrans;
    VendTrans                   VendTrans, offsetVendTrans;
    str                         text;
    boolean                     isFreshDelivery;

    void findSettlement(VendTrans _vendtrans, vendSettlement _vendSettlement)
    {
        VendSettlement vendSettlementNew;

        if (!_vendtrans || !_vendSettlement) return;

        select firstonly offsetVendTrans
            order by recid desc
            where offsetVendTrans.Voucher       == _vendSettlement.OffsetTransVoucher
               && offsetVendTrans.AccountNum    == _vendSettlement.AccountNum
               && offsetVendTrans.RecId         != _vendtrans.RecId;

        if (offsetVendTrans.PromissoryNoteStatus != CustVendNegInstStatus::Honored)
        {
            select firstOnly vendSettlementNew
                where   vendSettlementNew.TransRecId    == offsetVendTrans.RecId;
                    /*&&  vendSettlementNew.TransDate     == offsetVendTrans.TransDate
                    &&  vendSettlementNew.TransCompany  == offsetVendTrans.dataAreaId;*/
            findsettlement(offsetVendTrans, vendSettlementNew);
        }
    }

    ttsBegin;

    while select VendSettlement
        where VendSettlement.AccountNum == '1002'
            join    VendTrans
            where   VendTrans.RecId                 == VendSettlement.TransRecId
                &&  VendTrans.PromissoryNoteStatus  == CustVendNegInstStatus::Invoiced
    {
        //VendTrans       = VendTrans::find(VendSettlement.TransRecId);
        offsetVendTrans.clear();
        VendInvoiceJour = VendInvoiceJour::findFromVendTrans(VendTrans.Invoice, VendTrans.TransDate, VendTrans.AccountNum);

        findSettlement(VendTrans, VendSettlement);

        isFreshDelivery = PurchTable::find(VendInvoiceJour.PurchId).FreshDelivery;

        TmpDueDateCompliance_ES_INL.clear();
        TmpDueDateCompliance_ES_INL.AccountNum          = VendSettlement.AccountNum;
        TmpDueDateCompliance_ES_INL.AmountMST           = VendSettlement.SettleAmountMST;
        TmpDueDateCompliance_ES_INL.LedgerVoucher       = VendTrans.Voucher;
        TmpDueDateCompliance_ES_INL.OffsetTransVoucher  = VendSettlement.OffsetTransVoucher;
        TmpDueDateCompliance_ES_INL.DueDate             = VendSettlement.DueDate;
        TmpDueDateCompliance_ES_INL.InvoiceDate         = VendTrans.TransDate;
        TmpDueDateCompliance_ES_INL.InvoiceId           = VendTrans.Invoice;
        TmpDueDateCompliance_ES_INL.PaymDate            = offsetVendTrans.TransDate;
        TmpDueDateCompliance_ES_INL.SettlementVoucher   = offsetVendTrans.Voucher;
        TmpDueDateCompliance_ES_INL.AmountMSTSettle     = offsetVendTrans.AmountMST;
        TmpDueDateCompliance_ES_INL.Status              = offsetVendTrans.PromissoryNoteStatus;
        TmpDueDateCompliance_ES_INL.DaysReal            = TmpDueDateCompliance_ES_INL.PaymDate  - TmpDueDateCompliance_ES_INL.InvoiceDate;
        TmpDueDateCompliance_ES_INL.DaysTheory          = isFreshDelivery ? 30 : 60;
        TmpDueDateCompliance_ES_INL.DaysDifference      = TmpDueDateCompliance_ES_INL.DaysReal  - TmpDueDateCompliance_ES_INL.DaysTheory;

        
        if (TmpDueDateCompliance_ES_INL.Status == CustVendNegInstStatus::Invoiced || TmpDueDateCompliance_ES_INL.Status == CustVendNegInstStatus::Honored)
            TmpDueDateCompliance_ES_INL.insert();
    }

    ttsCommit;

}


*This post is locked for comments

  • Suggested answer
    Ludwig Reinhard Profile Picture
    Ludwig Reinhard Microsoft Employee on at
    RE: Vendor Settlement

    Hello Jesus,

    Probably have a look at the VendStatistics form and related methods that already does a similar calculation for a single vendor. I believe that you can take out the one or the other peace from there for your purpose.

    Best regards,

    Ludwig

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,253 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,188 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans