关于Acumatica中GL Account汇总信息计算对象的技术问询
Hey there! I’ve worked with Acumatica’s GL APIs quite a bit, so let me walk you through the best way to calculate those period summary values (beginning balance, net change, ending balance) and build your export tool.
The Key Acumatica Object You Need
Acumatica has a dedicated business logic graph called GLHistoryEnq that’s designed exactly for this kind of GL account period summary calculation. It handles all the heavy lifting—like aggregating transactions, accounting for beginning balances, and respecting financial period boundaries—so you don’t have to reinvent the wheel.
Step-by-Step Implementation
Here’s how to use it in your custom code:
Initialize the GL History Inquiry Graph
Start by creating an instance of theGLHistoryEnqgraph, which lives in thePX.Objects.GLnamespace.Configure Your Filters
Set the necessary parameters to target your specific financial period, branch, and any account filters you need:BranchID: The company branch you’re queryingFinPeriodID: The target financial period ID (e.g., "2024-03")- Optional filters: Account masks, subaccount masks, or ledger type if you need to narrow results
Retrieve the Summary Data
Use theFillTable()method to populate the graph’sHistoryview with calculated summary values. Each row in this view is aGLHistoryResultDAC, which includes all the fields you need out of the box.
Example Code Snippet
using PX.Data; using PX.Objects.GL; // Create instance of the GL History Inquiry graph GLHistoryEnq glHistoryGraph = PXGraph.CreateInstance<GLHistoryEnq>(); // Set up filter parameters glHistoryGraph.Filter.Current.BranchID = 1; // Replace with your Branch ID glHistoryGraph.Filter.Current.FinPeriodID = "2024-Q2"; // Replace with your target period // Add optional filters if needed, e.g., account mask: // glHistoryGraph.Filter.Current.AccountMask = "100000-"; // Populate the summary data glHistoryGraph.FillTable(); // Iterate through results and prepare for export foreach (GLHistoryResult summary in glHistoryGraph.History.Select()) { string accountCode = summary.AccountCD; decimal beginningBalance = summary.BeginningBalance; decimal netChange = summary.PeriodDebit - summary.PeriodCredit; decimal endingBalance = summary.EndingBalance; // Already calculated for you! // Write these values to your text file here // Example: $"{accountCode},{beginningBalance},{netChange},{endingBalance}" }
Additional Notes
GLHistoryResultDAC Fields: This class includes pre-calculated values likeBeginningBalance,PeriodDebit,PeriodCredit, andEndingBalance—so you don’t have to manually compute ending balance unless you have custom logic.- Permissions: Make sure the user account running your custom program has the appropriate GL inquiry permissions in Acumatica (e.g., the "GL Inquiry" role) to access this data.
- Alternative for Custom Logic: If you need more control (like including unposted transactions or custom calculations), you can query the
GLTrantable directly and join withFinPeriodto aggregate totals—butGLHistoryEnqis the recommended approach since it encapsulates Acumatica’s native financial logic.
内容的提问来源于stack exchange,提问作者David Eichner

