X++ code to get Ledger period start date / End date And calculate main account balance from trail balances

 public AmountMst openingbalance()

    {

        LedgerBalanceMainAccountAmounts ledgerBalance;

        GeneralJournalAccountEntry      generalJournalAccountEntry;

        GeneralJournalEntry              generaljournalentry;

        FiscalCalendarPeriod             fiscalCalendarPeriod;

        AmountMst  opSum;

        LedgerPeriodCode ledgerPeriodCode;

        InventPosting     inventposting;

// To get period start date

       periodstart periodStartDate = FiscalCalendarYear::findYearByCalendarDate(Ledger::fiscalCalendar(), fromDate).StartDate;

       

        select * from inventposting 

            where inventposting.InventAccountType == InventAccountType::PurchPackingSlipPurchaseOffsetAccount;

        /// select statement to get sum of Main account balances

        select sum(AccountingCurrencyAmount) from generalJournalAccountEntry 

            where generalJournalAccountEntry.MainAccount == MainAccount::findByMainAccountId(inventposting.ledgerAccountName()).RecId

                join generaljournalentry where generalJournalAccountEntry.GeneralJournalEntry == generaljournalentry.RecId

                    && generaljournalentry.AccountingDate >= periodStartDate 

                    && generaljournalentry.AccountingDate<= fromDate

                        join fiscalCalendarPeriod where fiscalCalendarPeriod.RecId == generaljournalentry.FiscalCalendarPeriod

                            && (fiscalCalendarPeriod.Type == FiscalPeriodType::Opening

                            || fiscalCalendarPeriod.Type == FiscalPeriodType::Operating);


        return generalJournalAccountEntry.AccountingCurrencyAmount;

No comments:

Post a Comment