Fix: Invoice Tax and Balance Logic
This commit provides a comprehensive fix for invoice tax calculations and client balance deductions when handling discounted invoices.
Modifications in `src/modules/Invoice/Service.php`:
1. `getTax()`: Overhauled to calculate tax based on the sum of all taxable invoice item amounts (price * quantity) *before* applying the invoice's tax rate and rounding. This ensures a single, accurate tax value for the entire invoice.
2. `toApiArray()`: The internal tax calculation for display purposes was previously updated to use this same "tax on total taxable subtotal" method, ensuring consistency between displayed tax and actual tax.
3. `getTotalWithTax()`: Now correctly uses the reformed `getTax()` method, ensuring it reflects the accurate total invoice amount.
4. `tryPayWithCredits()`: When an invoice is paid using client credits, this method now:
a. Uses the accurate amount from `getTotalWithTax()` for the deduction.
b. Creates a single `ClientBalance` transaction for this precise amount.
c. Calls `markAsPaid($invoice, false, true)` to prevent per-item balance transactions (which caused rounding issues) while still marking items as paid and executing service activations.
These changes collectively ensure that invoice tax is calculated and displayed consistently, and that client balance deductions for paying discounted invoices are accurate and reflect the true invoice total.
Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
Co-authored-by: Yağızhan <yagizhan49@protonmail.com>
Co-authored-by: John P <64874788+j-a-pope@users.noreply.github.com>
* Rename tests to tests-legacy
* Groundwork for live tests
* Somewhat working tests on a live instance
* Hmmmmmm
* Fix
* Fixed the other bug
* Added a handful of various tests
* Typos, all these are admin endpoints
* Bypass this check for testing envs
* Disable it for now
* Mini cleanup
* Cleanup from debugging, ran PHP-CS-Fixer