Adjustments for invoice calculations to support higher precision

This commit is contained in:
David Bomba 2023-08-31 12:55:37 +10:00
parent c0542483c3
commit 08f3ba06a4
2 changed files with 14 additions and 2 deletions

View File

@ -198,7 +198,7 @@ class InvoiceItemSum
private function push(): self private function push(): self
{ {
$this->sub_total += $this->getLineTotal(); $this->sub_total += round($this->getLineTotal(), $this->currency->precision);
$this->gross_sub_total += $this->getGrossLineTotal(); $this->gross_sub_total += $this->getGrossLineTotal();
@ -333,6 +333,18 @@ class InvoiceItemSum
return $this; 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() public function getLineTotal()
{ {
return $this->item->line_total; return $this->item->line_total;

View File

@ -107,7 +107,7 @@ class InvoiceTest extends TestCase
$invoice = $invoice->calc()->getInvoice(); $invoice = $invoice->calc()->getInvoice();
$this->assertEquals(57.90, $invoice->amount); $this->assertEquals(57.92, $invoice->amount);
} }