mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-05-24 02:14:21 -04:00
Fixes for calculations
This commit is contained in:
parent
1f1ce3431d
commit
232ec6364a
@ -353,7 +353,7 @@ class InvoiceItemSumInclusive
|
||||
if ($this->sub_total == 0) {
|
||||
$amount = $this->item->line_total;
|
||||
} else {
|
||||
$amount = ($this->sub_total > 0) ? $this->item->line_total - ($this->invoice->discount * ($this->item->line_total / $this->sub_total)) : 0;
|
||||
$amount = $this->item->line_total - ($this->invoice->discount * ($this->item->line_total / $this->sub_total));
|
||||
// $amount = $this->item->line_total - ($this->item->line_total * ($this->invoice->discount / $this->sub_total));
|
||||
}
|
||||
|
||||
|
@ -35,6 +35,64 @@ class InvoiceItemTest extends TestCase
|
||||
$this->makeTestData();
|
||||
}
|
||||
|
||||
|
||||
public function testDiscountsWithInclusiveTaxes()
|
||||
{
|
||||
$invoice = InvoiceFactory::create($this->company->id, $this->user->id);
|
||||
$invoice->client_id = $this->client->id;
|
||||
$invoice->uses_inclusive_taxes = true;
|
||||
$invoice->is_amount_discount =true;
|
||||
$invoice->discount = 10;
|
||||
|
||||
$line_items = [];
|
||||
|
||||
$line_item = new InvoiceItem;
|
||||
$line_item->quantity = 1;
|
||||
$line_item->cost = 100;
|
||||
$line_item->tax_rate1 = 10;
|
||||
$line_item->tax_name1 = 'GST';
|
||||
$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(90, $invoice->amount);
|
||||
$this->assertEquals(8.18, $invoice->total_taxes);
|
||||
}
|
||||
|
||||
|
||||
public function testDiscountsWithInclusiveTaxesNegativeInvoice()
|
||||
{
|
||||
$invoice = InvoiceFactory::create($this->company->id, $this->user->id);
|
||||
$invoice->client_id = $this->client->id;
|
||||
$invoice->uses_inclusive_taxes = true;
|
||||
$invoice->is_amount_discount =true;
|
||||
$invoice->discount = -10;
|
||||
|
||||
$line_items = [];
|
||||
|
||||
$line_item = new InvoiceItem;
|
||||
$line_item->quantity = -1;
|
||||
$line_item->cost = 100;
|
||||
$line_item->tax_rate1 = 10;
|
||||
$line_item->tax_name1 = 'GST';
|
||||
$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(-90, $invoice->amount);
|
||||
$this->assertEquals(-8.18, $invoice->total_taxes);
|
||||
}
|
||||
|
||||
public function testDicountsWithTaxes()
|
||||
{
|
||||
$invoice = InvoiceFactory::create($this->company->id, $this->user->id);
|
||||
@ -92,7 +150,7 @@ class InvoiceItemTest extends TestCase
|
||||
$this->assertEquals(-9, $invoice->total_taxes);
|
||||
}
|
||||
|
||||
public function testDicountsWithTaxesPercentage()
|
||||
public function testDicountsWithTaxesPercentage()
|
||||
{
|
||||
$invoice = InvoiceFactory::create($this->company->id, $this->user->id);
|
||||
$invoice->client_id = $this->client->id;
|
||||
|
Loading…
x
Reference in New Issue
Block a user