Showing posts with label Invoice Journal. Show all posts
Showing posts with label Invoice Journal. Show all posts

Sunday, June 29, 2025

Code to get customer and vendor posted and unposted invoice journals in D365F&O X++

   public void clicked()

        {

            VendInvoiceInfoLine         vendInvoiceInfoLine;

            ACCOUNTINGDISTRIBUTION      accoutingDistribution;

            LedgerAccount               ledgerAccount;

            VendInvoiceInfoTable        vendInvoiceInfoTable;

            Amount                      totalAmount;

            container                   con;

            VendInvoiceJour             vendInvoiceJour;

            VendInvoiceTrans            vendInvoiceTrans;

            LedgerJournalTable          ledgerJournalTable;

            LedgerJournalTrans          ledgerJournalTrans;

            RecId                       dynamicVendorAccount;

            GeneralJournalAccountEntry  generalJournalAccountEntry;

            GeneralJournalEntry         generalJournalEntry;

            CustInvoiceTable            custInvoiceTable;

            CustInvoiceLine             custInvoiceLine;

            CustInvoiceJour             custInvoiceJour;

            CustInvoiceTrans            custInvoiceTrans;

            MainAccount                 mainaccount;


            super();


            RPTLines.GLAccount =  GLAccount.valueStr();

            

            if(RPTLines.PartyType == PwC_PartyType::Vendor)

            {

                con =str2con(RPTLines.GLAccount,";",false);


                for(int c=1; c<=conLen(con);c++)

                {

                    Amount  unpostedTotal,postedTotal,transTotal;


                    //for unposted vendor invoices

                    while select vendInvoiceInfoLine

                        join vendInvoiceInfoTable

                            where vendInvoiceInfoTable.TableRefId == vendInvoiceInfoLine.TableRefId

                        join  accoutingDistribution

                             where accoutingDistribution.SourceDocumentLine ==  vendInvoiceInfoLine.SourceDocumentLine

                            && vendInvoiceInfoTable.ParmId  ==  vendInvoiceInfoLine.ParmId

                            && vendInvoiceInfoTable.DocumentDate >= RPTLines.FromDate

                            && vendInvoiceInfoTable.DocumentDate <= RPTLines.ToDate

                            &&  vendInvoiceInfoTable.ParmJobStatus != ParmJobStatus::Executed

                    {

                        ledgerAccount = MainAccount::findByLedgerDimension(accoutingDistribution.LedgerDimension).MainAccountId;


                        if(ledgerAccount == conPeek(con, c))

                        {

                            unpostedTotal += vendInvoiceInfoLine.LineAmount;

                        }

                    }


                    //posted vendor invoices

                    while select generalJournalAccountEntry

                            join generalJournalEntry

                                where generalJournalEntry.RecId == generalJournalAccountEntry.GeneralJournalEntry

                            join vendInvoiceJour

                                where vendInvoiceJour.LedgerVoucher == generalJournalEntry.SubledgerVoucher

                                &&  vendInvoiceJour.InvoiceDate >= RPTLines.FromDate

                                &&  vendInvoiceJour.InvoiceDate <= RPTLines.ToDate

                    {

                        ledgerAccount = MainAccount::findByLedgerDimension(generalJournalAccountEntry.LedgerDimension).MainAccountId;


                        if(ledgerAccount == conPeek(con, c))

                        {

                            postedTotal += generalJournalAccountEntry.AccountingCurrencyAmount;

                        }

                    }


                    dynamicVendorAccount = LedgerDynamicAccountHelper::getDynamicAccountFromAccountNumber(RPTLines.PartyNumber,LedgerJournalACType::Vend);


                    //GL entries for vendor

                    while select ledgerJournalTrans

                            join ledgerJournalTable

                            where ledgerJournalTable.JournalNum == ledgerJournalTrans.JournalNum

                            && ledgerJournalTrans.DocumentDate >= RPTLines.FromDate

                            &&  ledgerJournalTrans.DocumentDate <=  RPTLines.ToDate

                            && ledgerJournalTrans.LedgerDimension == dynamicVendorAccount

                            && ledgerJournalTrans.Invoice !=''

                            && ledgerJournalTable.Posted == NoYes::No

                    {

                        ledgerAccount = MainAccount::findByLedgerDimension(ledgerJournalTrans.OffsetLedgerDimension).MainAccountId;


                        if(ledgerAccount == conPeek(con, c))

                        {

                            if(ledgerJournalTrans.AmountCurDebit)

                            {

                                transTotal += ledgerJournalTrans.AmountCurDebit;

                            }

                            else if(ledgerJournalTrans.AmountCurCredit)

                            {

                                transTotal += ledgerJournalTrans.AmountCurCredit;

                            }

                        }

                    }

                            

                    totalAmount +=  unpostedTotal + postedTotal + transTotal;

                }


                RPTLines.TransactionAmount =  totalAmount;

                

            }


            else  if(RPTLines.PartyType == PwC_PartyType::Customer)

            {

                con =str2con(RPTLines.GLAccount,";",false);

                Amount custTotalAmount;

                for(int c=1; c<=conLen(con);c++)

                {

                    Amount  unposted,GLAmount;

                    mainaccount = MainAccount::findByMainAccountId(conPeek(con,c));


                    RecId  mainaccountValue = LedgerDefaultAccountHelper::getDefaultAccountFromMainAccountRecId(mainaccount.RecId);


                    //posted and unposted invoices

                    while select custInvoiceLine

                       join  custInvoiceTable

                        where custInvoiceTable.RecId == custInvoiceLine.ParentRecId

                        && custInvoiceTable.DocumentDate >= RPTLines.FromDate

                        &&  custInvoiceTable.DocumentDate <=  RPTLines.ToDate

                        && custInvoiceLine.LedgerDimension == mainaccountValue

                    {

                        unposted += custInvoiceLine.AmountCur;

                    }


                    dynamicVendorAccount = LedgerDynamicAccountHelper::getDynamicAccountFromAccountNumber(RPTLines.PartyNumber,LedgerJournalACType::Cust);


                    //GL entries for customer

                    while select ledgerJournalTrans

                            join ledgerJournalTable

                            where ledgerJournalTable.JournalNum == ledgerJournalTrans.JournalNum

                            && ledgerJournalTrans.DocumentDate >= RPTLines.FromDate

                            &&  ledgerJournalTrans.DocumentDate <=  RPTLines.ToDate

                            && ledgerJournalTrans.LedgerDimension == dynamicVendorAccount

                            && ledgerJournalTrans.Invoice !=''

                    {

                        ledgerAccount = MainAccount::findByLedgerDimension(ledgerJournalTrans.OffsetLedgerDimension).MainAccountId;


                        if(ledgerAccount == conPeek(con, c))

                        {

                            if(ledgerJournalTrans.AmountCurDebit)

                            {

                                GLAmount += ledgerJournalTrans.AmountCurDebit;

                            }

                            else if(ledgerJournalTrans.AmountCurCredit)

                            {

                                GLAmount += ledgerJournalTrans.AmountCurCredit;

                            }

                        }

                    }

                    custTotalAmount +=  unposted + GLAmount;

                }

                RPTLines.TransactionAmount =  custTotalAmount;

            }

            GLAccount.text('');

        }

Thursday, January 4, 2024

Remove marked for settlement open transactions through X++ code

 AP>Invoices>Invoice Journal>Lines>Settele Transcations



View Marked Transcations.





Other Way:

http://daxdude.blogspot.com/2013/02/remove-marked-for-settlement-open.html



Friday, October 20, 2023

Code to create a AP invoice journal in D365F&O X++

public static void main(Args _args)

   {

       MCRLedgerJournal        journalTable;

       LedgerJournalTable      ledgerJournalTable;

       Counter                 recordsInserted;

        ttsbegin;

       //Creates the journal header table

       journalTable = new MCRLedgerJournal_VendInvoiceRegister(LedgerJournalType::VendInvoiceRegister,"APInvoice");

       ledgerJournalTable = journalTable.createLedgerJournalTable();

       journalTable.parmLedgerJournalTable(ledgerJournalTable);

       journalTable.parmMCRCCGeneralLedgerId();

       journalTable.parmCurrencyCode(CompanyInfoHelper::standardCurrency());

 

       // creates a new line in general journal

       journalTable.parmLineNum();

       journalTable.parmLedgerAccountType(LedgerJournalACType::Vend);

       journalTable.parmLedgerAccount(LedgerDynamicAccountHelper::getDynamicAccountFromAccountNumber("1001",LedgerJournalACType::Vend)); //You need to use the vendor account as per your environment's data.

       journalTable.parmTransDate(today());

       journalTable.parmTransTxt("Acquisition");

       journalTable.parmInvoice("123");

       journalTable.parmExchRate(0.00);

       journalTable.createLedgerJournalTrans(abs(0),abs(100),LedgerJournalACType::Vend);

       recordsInserted++;

       ttscommit;

       info(strFmt("Journal number %1 is created", ledgerJournalTable.JournalNum));

   }

 ...............


AP>Invoices>Invoice Journal