mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-07 18:14:32 -04:00
Minor fixes
This commit is contained in:
parent
a1cb4ce00b
commit
31bfb83875
@ -161,12 +161,20 @@ class InvoiceItemSum
|
||||
->sumLineItem()
|
||||
->setDiscount()
|
||||
->calcTaxes()
|
||||
->roundLineItem()
|
||||
->push();
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
private function roundLineItem(): self
|
||||
{
|
||||
$this->item->line_total = round($this->item->line_total, $this->currency->precision);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
private function shouldCalculateTax(): self
|
||||
{
|
||||
|
||||
|
@ -297,9 +297,12 @@ class ProfitLoss
|
||||
|
||||
$amount_payment_paid += $pivot->amount - $pivot->refunded;
|
||||
$amount_payment_paid_converted += $amount_payment_paid / ($payment->exchange_rate ?: 1);
|
||||
|
||||
$tax_amount += ($amount_payment_paid / $invoice->amount) * $invoice->total_taxes;
|
||||
$tax_amount_converted += (($amount_payment_paid / $invoice->amount) * $invoice->total_taxes) / $payment->exchange_rate;
|
||||
|
||||
if ($invoice->amount > 0) {
|
||||
$tax_amount += ($amount_payment_paid / $invoice->amount) * $invoice->total_taxes;
|
||||
$tax_amount_converted += (($amount_payment_paid / $invoice->amount) * $invoice->total_taxes) / $payment->exchange_rate;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if ($pivot->paymentable_type == 'credits') {
|
||||
|
@ -49,6 +49,68 @@ class InvoiceTest extends TestCase
|
||||
$this->invoice_calc = new InvoiceSum($this->invoice);
|
||||
}
|
||||
|
||||
public function testTaskRoundingPrecisionThree()
|
||||
{
|
||||
$invoice = InvoiceFactory::create($this->company->id, $this->user->id);
|
||||
$invoice->client_id = $this->client->id;
|
||||
$invoice->uses_inclusive_taxes = false;
|
||||
|
||||
$line_items = [];
|
||||
|
||||
$line_item = new InvoiceItem;
|
||||
$line_item->quantity = 25;
|
||||
$line_item->cost = 0.333;
|
||||
$line_item->tax_rate1 = 0;
|
||||
$line_item->tax_name1 = '';
|
||||
$line_item->product_key = 'Test';
|
||||
$line_item->notes = 'Test';
|
||||
$line_items[] = $line_item;
|
||||
|
||||
$line_item = new InvoiceItem;
|
||||
$line_item->quantity = 25;
|
||||
$line_item->cost = 0.333;
|
||||
$line_item->tax_rate1 = 0;
|
||||
$line_item->tax_name1 = '';
|
||||
$line_item->product_key = 'Test';
|
||||
$line_item->notes = 'Test';
|
||||
$line_items[] = $line_item;
|
||||
|
||||
$line_item = new InvoiceItem;
|
||||
$line_item->quantity = 25;
|
||||
$line_item->cost = 1.333;
|
||||
$line_item->tax_rate1 = 0;
|
||||
$line_item->tax_name1 = '';
|
||||
$line_item->product_key = 'Test';
|
||||
$line_item->notes = 'Test';
|
||||
$line_items[] = $line_item;
|
||||
|
||||
$line_item = new InvoiceItem;
|
||||
$line_item->quantity = 25;
|
||||
$line_item->cost = 0.267;
|
||||
$line_item->tax_rate1 = 0;
|
||||
$line_item->tax_name1 = '';
|
||||
$line_item->product_key = 'Test';
|
||||
$line_item->notes = 'Test';
|
||||
$line_items[] = $line_item;
|
||||
|
||||
$line_item = new InvoiceItem;
|
||||
$line_item->quantity = 25;
|
||||
$line_item->cost = 0.05;
|
||||
$line_item->tax_rate1 = 0;
|
||||
$line_item->tax_name1 = '';
|
||||
$line_item->product_key = 'Test';
|
||||
$line_item->notes = 'Test';
|
||||
$line_items[] = $line_item;
|
||||
|
||||
$invoice->line_items = $line_items;
|
||||
$invoice->save();
|
||||
|
||||
$invoice = $invoice->calc()->getInvoice();
|
||||
|
||||
$this->assertEquals(57.92, $invoice->amount);
|
||||
|
||||
}
|
||||
|
||||
public function testRoundingWithLargeUnitCostPrecision()
|
||||
{
|
||||
$invoice = InvoiceFactory::create($this->company->id, $this->user->id);
|
||||
|
Loading…
x
Reference in New Issue
Block a user