The configuration file should be kept in your application's load path. The accounts, and permitted transfers between those accounts. ConfigurationĪ configuration file should be used to define a set of accounts, optional scopes on Transfer metadata is stored in a json(b) column on both the source and destination lines of the transfer. The current balance for an account, we find the most recent lines table entryĪccountBalance records cache the current balance for each Account, and are used Lines table entries also store the running balance for the account. As this is aĭouble-entry accounting system, each transfer generates two lines tableĮntries: one for the source account, and one for the destination. ImplementationĪll transfers and balances are stored in the lines table. See DoubleEntry::Validation for more info. perform! ( fixer: DoubleEntry:: Validation:: AccountFixer. perform! # Check & fix accounts (results will also be written to the table) DoubleEntry:: Validation:: LineCheck. # Check all accounts & write the results to the double_entry_line_checks table DoubleEntry:: Validation:: LineCheck. Here are examples that could go in your scheduled job, depending on your needs:
Keep in mind that this process locks accounts as it inspects their balances, so it will prevent new transactions from being written for a short time. If you want to make use of them then it's recommended to run them in a scheduled job, somewhere on the order of hourly to daily, depending on transaction volume.
Using these classes is optional and both are provided for additional safety checks. This gem provides the DoubleEntry::Validation::AccountFixer class which will correct the balance if it's out of sync. You can alternatively pass a fixer to the DoubleEntry::Validation::LineCheck.perform method which will try and correct the balances. If either one of these turn out to be incorrect then it will write an entry into the double_entry_line_checks table reporting on the differences. The DoubleEntry::Validation::LineCheck will check the double_entry_lines table to make sure that the balance column correctly reflects the calculated running balance, and that the double_entry_account_balances table has the correct value in the balance column. Account Checker/FixerĭoubleEntry tries really hard to make sure that stored account balances reflect the running balances from the double_entry_lines table, but there is always the unlikely possibility that something will go wrong and the calculated balance might get out of sync with the actual running balance of the lines.ĭoubleEntry therefore provides a couple of tools to give you some confidence that things are working as expected. The lock_accounts call generates a database transaction, which must be the new ( 20_00 ), from: account_a, to: account_b, code: :purchase ) # Perform other tasks that should be commited atomically with the transfer of funds. lock_accounts ( account_a, account_b ) do # Perhaps transfer some money DoubleEntry.