通过 SQL 在 axapta 中获取当前账户余额

Getting current account balances in axapta via SQL

我正在尝试弄清楚如何通过 SQL 从 Axapta 2012 表中获取我的主要帐户的当前余额。

有人知道怎么做吗?

table MainAccount 的方法 getBalance 似乎是一个不错的起点。不幸的是,这种方法使用 class LedgerBalanceMainAccountAmounts 来计算余额。我认为在 SQL 中重新创建 class 的逻辑即使不是不可能也是非常困难的。

根据您的要求,一种替代方法是在 x++ 中编写一个函数,将 getBalance 方法的结果写入新的 table,然后您可以使用 SQL 来查询新 table.

但我建议您查看 out-of-the-box 选项来分析主要账户数据,例如管理报告者或 BI。

谢谢。不过我想出了一个解决办法。

这是我在另一个论坛上的帖子和解决方案。

https://community.dynamics.com/ax/f/33/p/268863/762367#762367

Basically what I wanted is the main account ids with the structure defined via -> "traditional finance report" -> "Rowdefinition" -> "Structure designer".

With these account ids I go into the [DIMENSIONATTRIBUTEVALUECOMBINATION] then into [GENERALJOURNALACCOUNTENTRY] and into [GENERALJOURNALENTRY] to get the "transactions" for a specified timeframe.

Then I sum those transactions up to get the accounts balance.

WITH mainaccs(recid, PARENTRECID,[Name]) AS (
  SELECT RecId,
         PARENTRECID,
         [Name]
  FROM   [LEDGERROWDEFLINE]
    where PARENTRECID = 0
  UNION ALL
  SELECT cur.RecId,
         cur.PARENTRECID,
         cur.[Name]
  FROM   [LEDGERROWDEFLINE] cur, mainaccs
  WHERE  cur.PARENTRECID = mainaccs.recid
)
SELECT 
    ma.MAINACCOUNTID,
    Sum(gjae.TRANSACTIONCURRENCYAMOUNT) amount
FROM  mainaccs maccs
    inner join [MAINACCOUNT] ma on ma.MainaccountId = maccs.Name
    inner join [DIMENSIONATTRIBUTEVALUECOMBINATION] davc on ma.RECID = davc.MAINACCOUNT
    inner join [GENERALJOURNALACCOUNTENTRY] gjae on gjae.LEDGERACCOUNT = davc.DISPLAYVALUE
    inner join [GENERALJOURNALENTRY] gje on gje.RecId = gjae.GENERALJOURNALENTRY
where YEAR(gje.ACCOUNTINGDATE) = 2017
group by ma.MAINACCOUNTID
order by ma.MAINACCOUNTID