1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-09-20 08:21:34 +02:00

Rappen Rounding

This commit is contained in:
David Bomba 2024-03-21 19:26:11 +11:00
parent 65a356c99f
commit c0ffaca0eb
4 changed files with 33 additions and 6 deletions

View File

@ -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();

View File

@ -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();

View File

@ -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;

View File

@ -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()