diff --git a/app/Helpers/Invoice/InvoiceSum.php b/app/Helpers/Invoice/InvoiceSum.php index f142ce0b9f..52cd745418 100644 --- a/app/Helpers/Invoice/InvoiceSum.php +++ b/app/Helpers/Invoice/InvoiceSum.php @@ -246,8 +246,6 @@ class InvoiceSum if ($this->invoice->status_id != Invoice::STATUS_DRAFT) { if ($this->invoice->amount != $this->invoice->balance) { - // $paid_to_date = $this->invoice->amount - $this->invoice->balance; - $this->invoice->balance = Number::roundValue($this->getTotal(), $this->precision) - $this->invoice->paid_to_date; //21-02-2024 cannot use the calculated $paid_to_date here as it could send the balance backward. } else { $this->invoice->balance = Number::roundValue($this->getTotal(), $this->precision); @@ -256,8 +254,10 @@ class InvoiceSum /* Set new calculated total */ $this->invoice->amount = $this->formatValue($this->getTotal(), $this->precision); - if($this->rappen_rounding) + if($this->rappen_rounding){ $this->invoice->amount = $this->roundRappen($this->invoice->amount); + $this->invoice->balance = $this->roundRappen($this->invoice->balance); + } $this->invoice->total_taxes = $this->getTotalTaxes(); diff --git a/app/Helpers/Invoice/InvoiceSumInclusive.php b/app/Helpers/Invoice/InvoiceSumInclusive.php index d7c8a75dbe..aae9c08481 100644 --- a/app/Helpers/Invoice/InvoiceSumInclusive.php +++ b/app/Helpers/Invoice/InvoiceSumInclusive.php @@ -272,11 +272,11 @@ class InvoiceSumInclusive } /* Set new calculated total */ - /** @todo - rappen rounding here */ $this->invoice->amount = $this->formatValue($this->getTotal(), $this->precision); if($this->rappen_rounding) { $this->invoice->amount = $this->roundRappen($this->invoice->amount); + $this->invoice->balance = $this->roundRappen($this->invoice->balance); } $this->invoice->total_taxes = $this->getTotalTaxes(); diff --git a/lang/en/texts.php b/lang/en/texts.php index 7fb70f97c2..d0e88abcc3 100644 --- a/lang/en/texts.php +++ b/lang/en/texts.php @@ -461,8 +461,8 @@ $lang = array( 'delete_token' => 'Delete Token', 'token' => 'Token', 'add_gateway' => 'Add Payment Gateway', - 'delete_gateway' => 'Delete Gateway', - 'edit_gateway' => 'Edit Gateway', + 'delete_gateway' => 'Delete Payment Gateway', + 'edit_gateway' => 'Edit Payment Gateway', 'updated_gateway' => 'Successfully updated gateway', 'created_gateway' => 'Successfully created gateway', 'deleted_gateway' => 'Successfully deleted gateway', @@ -5267,6 +5267,7 @@ $lang = array( 'enable_rappen_roudning' => 'Enable Rappen Rounding', 'enable_rappen_rounding_help' => 'Rounds totals to nearest 5', 'duration_words' => 'Duration in words', + 'upcoming_recurring_invoices' => 'Upcoming Recurring Invoices', ); return $lang; diff --git a/tests/Unit/InvoiceTest.php b/tests/Unit/InvoiceTest.php index d9b9cab429..3c2bb1ccea 100644 --- a/tests/Unit/InvoiceTest.php +++ b/tests/Unit/InvoiceTest.php @@ -61,6 +61,8 @@ class InvoiceTest extends TestCase 'settings' => $c_settings, ]); + $this->assertEquals(0, $c->balance); + $item = InvoiceItemFactory::create(); $item->quantity = 1; $item->cost = 10.01; @@ -88,6 +90,10 @@ class InvoiceTest extends TestCase $this->assertEquals(10, $ii->amount); + $ii->service()->markSent()->save(); + + $this->assertEquals(10, $c->fresh()->balance); + } public function testRappenRoundingUp() @@ -129,6 +135,26 @@ class InvoiceTest extends TestCase $this->assertEquals(10.10, round($ii->amount,2)); + $ii->service()->markSent()->save(); + + $this->assertEquals(10.10, $c->fresh()->balance); + + $item = InvoiceItemFactory::create(); + $item->quantity = 2; + $item->cost = 10.09; + $item->type_id = '1'; + $item->tax_id = '1'; + + $i->line_items = [$item]; + + $invoice_calc = new InvoiceSum($i); + $ii = $invoice_calc->build()->getInvoice(); + + $ii->client->service()->calculateBalance($ii); + + $this->assertEquals(20.20, round($ii->amount,2)); + $this->assertEquals(20.20, round($ii->balance,2)); + $this->assertEquals(20.20, round($c->fresh()->balance,2)); } public function testPartialDueDateCast()