scottlaurent/accounting

Deleting a transaction ?

Closed this issue · 1 comments

azrul commented

In my use-case, i periodically import a data file into the system. I wanted to be able to override older import if the new import has some new data.

Is there a way to search and delete an old transaction in order for me to replace it with a new one?

yes. but in order to do that you would need to do a few things based on your scenario:

  1. If you are wanting to simply to just "overwrite" an older transaction, you could add a field to the journal table called "system_x_transaction_id" and do a JournalTransaction ::where('system_x_transaction_id',$system_x_transaction_id)->first() -- and if that exists, change the value and use save() so that the balances "reset" correctly. If the transaction doesn't exists, create a new one as needed and just set the system_x_transaction_id on that new transaction.

  2. If you are going to be doing some kind of double entry system, you could consider creating a separate transaction table for your other system and using the references() feature to handle the imports.

Finally, as a clarification as to why this doesn't exist: normally, an action like this is a nightmare scenario for an accountant. Basically, the rule is "never overwrite. add an adjusting entry" -- simply to leave an audit trail. That being said, in the real world of non-audited projects (probably a majority of them), this thinking might be "paranoia" and can safely be ignored though with the understanding that auditing would never be possible. In other words, you couldn't come back 2 years from now and say "well the report on date X said $Y and now it says $Z. How did the numbers change"