Central transaction table (=single transactions table) #7460
Replies: 3 comments 1 reply
-
I should note that there was some push back on the merging of AR/AP tables, mainly due to the fact that AR and AP might diverge in the future as they have different meaning and might be likely to not have the same structures in the future leading to one table where some rows require certain columns to be filled in while others require a different set of columns with a few columns in common. This in turn would mean that the application needs to know which columns to leave empty or fill in as one cannot put these restraints on the table. So maybe one should remove that part. |
Beta Was this translation helpful? Give feedback.
-
There was also a fair bit of discussion between @ehuelsmann and @freelock after I summarized this, and I realized it after posting, so it may be that my summary is completely outdated 🙈 |
Beta Was this translation helpful? Give feedback.
-
@christian-eriksson hope you don't mind my edits to the original description! Creating a new discussion item felt like red tape... |
Beta Was this translation helpful? Give feedback.
-
Definition: a transaction is the accounting representation of an atomic business event, such as a sale, or transfer of money.
At the moment there are 4 tables playing a role in recording transactions:
transactions
,GL
,AR
andAP
(with transaction lines recorded inacc_trans
, requiring the lines associated with a record in ar/ap/gl being balanced).The role of the
transactions
table is to prevent the sameid
value being shared betweenar
,ap
andgl
by adding the IDs being inserted into those tables to thetransactions
immediately, preventing the same value being inserted in any of the other tables. This behaviour is implemented using a trigger. Leading to this schema:Attempt to put this in an ERD:
The three tables (ar/ap/gl) record data that could be interpreted as a "transaction header": information such as a description, posting date, notes, transaction reference number, etc.
Using the transaction definition stated above, the GL table is indeed the header of a transaction: once the header data is inserted in
gl
and the lines inacc_trans
, nothing changes to the database records anymore. However, the AR and AP table cannot be classified the same way: after the AR and AP records have been created and theacc_trans
lines posted, the AR and AP data is modified in the sense thatacc_trans
lines are added to the AR/AP data when a payment is recorded. This also leads to the AR/AP data no longer being atomic or single-point-in-time.An example could be:
ar
table:acc_trans
table:Let's assume Erik pays the full amount on Jan 31st to the bank account, the data for the AR item in
acc_trans
looks like:As you can see: the data in
acc_trans
is not atomic and immutable when considering all data in the "AR" item.Problem statement 1
The above has several problems:
There are 2 invoices, with IDs
1
and2
, where2
voids1
:Ideally, these would be closed against each other automatically as part of the voiding procedure like this:
This, however, is impossible, because it leaves both transactions unbalanced. To work around this, a zero-amount payment is created by the end-user, resulting in the following lines:
While this works technically, it's functionally confusing because it creates a payment and two transactions on the bank account (which did not really happen). Users strict about their reconciliations are finding this conflicting with their desire to match the bank statement exactly in the reconciliation report.
Desired outcome
Instead of the above, I'd like the outcome to be close to this, where "trans_id"==3 is a transaction triggered by the posting of the voiding invoice:
This result nicely tracks the various business events, each of which should be balanced.
Problem statement 2
Payments can be part of payment batches, which can exist in unapproved state, meaning the payment lines will have an unapproved status while the transaction itself has a status of approved. The transaction is therefore inconsistent with its lines, even though the state is functionally correct.
Returning back to the example above where Erik pays an AR item, but this time two partial payments are applied on the day the item is created, the
acc_trans
items look like this:Here, all lines are all referencing the same
ar
record. Due to the way the schema is structured, none of them reference the GL table and they all reference the sametransactions
record by definition.Conclusion
The current schema is - with respect to the
acc_trans
records linked to thear
andap
tables - not complying to the definition of atomicity of accounting transactions and even loosing information to the effect of being able to distinguish (multiple) payments from the original transaction. There definitely is a role for the AR and AP table information, but it's not as the header of a transaction as defined above.Way forward (proposal)
A replacement schema proposal that satisfies the atomicity changes the meaning of the AR and AP tables.
Summary of differences:
approved
andtransdate
fields onacc_trans
(only ontransactions
level)vouchers
table, becauseacc_trans
lines allocated to the batch may not be a subset of lines within a transaction (which used to be allowed in case of payments and receipts)gl
table, because it's assimilated with thetransactions
tablepayment
andpayment_link
tables (which have been generalized into theopen_item
andopen_item_link
tables)open_item
throughopen_item_link
-s relating the payment lines to the AR/AP open itemsopen_item
instead of specialized paymentopen_item
; not the transaction, because that does not uniquely identify the account and the amount of the open item (with this schema, it's possible to mix regular payments and overpayments in a single bank receipt/payment)<--
In this schema, there's no need for a GL table, because it's completely assimilated into the transactions table. The role of the payments table is to be reconsidered, because the payment can be registered as a single transaction (where the role of the payments table currently is to track all payment related
acc_trans
records acrossar
andap
), with allocation to the various AR and AP items through thear_links
andap_links
tables. This is especially true if transactions posted on an account that is a bank account, allow storing additional data that currently goes into the payment table. [Note to self: overpayments still do need some kind of tracking, because they can't be directly allocated to invoices...]Along the same lines, there shouldn't be a need for vouchers anymore, because vouchers group acc_trans lines into batches across transactions, which is most important for payment/receipt batches in the existing schema, but this is no longer important in the new schema, because approval moves to the transaction level only.
-->
rest of the original text:
this leads to some weirdness in the backend like:
AR
andAP
with a lot of unions between them, instead of a singleAA
.To solve this issue, change the roles of the AR/AP/GL tables. The GL table will contain a header for every transaction (even the ones for which AR and AP used to be the source). This also means that every group of lines inserted in the
acc_trans
table will be linked to a GL record.The AR and AP tables would become a single AA table and hold journal headers instead of transaction headers and reference the transactions in the GL table. So the AR/AP will have all lines associated with the transaction which relate to the creation and closing of the AR/AP position.
In essence the GL table would be the "single source of truth" when it comes to what transactions have taken place in the system. This would also align with the current design for payments, where a payment is linked to its lines through the
payment_links
table.A single transaction table would allow for a reference to both the voided and voiding invoice on a single transaction that can close out the balance of both.
This would also simplify the transaction handling and make it easier to implement payments, overpayments and more.
Beta Was this translation helpful? Give feedback.
All reactions