Two other points:
- Instead of storing the vat with the payment I would store a foreign key to the vat entry with the payment (that said, I don't have a case where the current implementation doesn't work).
- Not a blocker, but we'll likely require some UI changes as well for the payment process.
Not related, but is this expected in here?.
Should the rate be hardcoded here?
Use ceil here as well. I would create a a function in Payment to calculate the amount (and potentially not store base_amount at all, unless necessary).
I would just call the methods instead of assembling a string.
I think we should be using ceil instead of round, so we always cover at least the tax,
How about amount_after_taxes, or taxed_amount, or wallet_amount?
I would prefer passing the $payment to credit, and then extract the correct amount there.
Rather call the actual method instead of assembling a string that is then invoked as a method, IMO.
I would prefer a string "taxed_at_source", "not_taxed" (or something like that).
As for the need for base_amount... We could get rid of it if we never support change of app.vat.mode on a working system. We could also store the mode instead. Also, having a calculated value that can be "directly" used for balance-related operations is handy. E.g. for Income chart we don't have to calculate the value in a sql query.
Fake data is here so we can produce a test output of a receipt, using template:render command
Accepting \App\Payment in these Wallet methods might be a good idea.
Instead of storing the vat with the payment I would store a foreign key to the vat entry with the payment (that said, I don't have a case where the current implementation doesn't work).
One thing that would currently be difficult is to show in the UI which tax rate was applied beyond the percentage. I think we should preserve the link to the db entry so we can e.g. show in some UI that the the tax rate from switzerland, active in 2023 was used for this payment. If we only have the percentage we loose the ability to do this (cleanly).
I think it should be fine to change the mode. We store the applied tax with the existing payment, and never change that, so changing the mode should only apply to new payments. That having it calculated for SQL reasons is handy makes sense.