diff --git a/app/Helpers/Invoice/InvoiceItemSum.php b/app/Helpers/Invoice/InvoiceItemSum.php index 3d419a66ae9d..62384287d58f 100644 --- a/app/Helpers/Invoice/InvoiceItemSum.php +++ b/app/Helpers/Invoice/InvoiceItemSum.php @@ -198,7 +198,7 @@ class InvoiceItemSum private function push(): self { - $this->sub_total += $this->getLineTotal(); + $this->sub_total += round($this->getLineTotal(), $this->currency->precision); $this->gross_sub_total += $this->getGrossLineTotal(); @@ -333,6 +333,18 @@ class InvoiceItemSum return $this; } + public function getRoundedLineTotal(): float + { + $total = 0; + + foreach($this->line_items as $item) + { + $total += round($item->line_total, $this->currency->precision); + } + + return $total; + } + public function getLineTotal() { return $this->item->line_total; diff --git a/tests/Unit/InvoiceTest.php b/tests/Unit/InvoiceTest.php index 6f189a41777a..305e1e86704d 100644 --- a/tests/Unit/InvoiceTest.php +++ b/tests/Unit/InvoiceTest.php @@ -107,7 +107,7 @@ class InvoiceTest extends TestCase $invoice = $invoice->calc()->getInvoice(); - $this->assertEquals(57.90, $invoice->amount); + $this->assertEquals(57.92, $invoice->amount); }