mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-13 22:54:25 +01:00
Fixes for calculations
This commit is contained in:
parent
a4c3ab58fc
commit
1f1ce3431d
@ -399,11 +399,8 @@ class InvoiceItemSum
|
||||
|
||||
$item_tax = 0;
|
||||
|
||||
// $amount = $this->item->line_total - ($this->item->line_total * ($this->invoice->discount / $this->sub_total));
|
||||
if($this->invoice->discount > 0)
|
||||
$amount = ($this->sub_total > 0) ? $this->item->line_total - ($this->invoice->discount * ($this->item->line_total / $this->sub_total)) : 0;
|
||||
else
|
||||
$amount = $this->item->line_total - ($this->item->line_total * ($this->invoice->discount / $this->sub_total));
|
||||
$amount = $this->item->line_total - ($this->item->line_total * ($this->invoice->discount / $this->sub_total));
|
||||
//$amount = ($this->sub_total > 0) ? $this->item->line_total - ($this->invoice->discount * ($this->item->line_total / $this->sub_total)) : 0;
|
||||
|
||||
$item_tax_rate1_total = $this->calcAmountLineTax($this->item->tax_rate1, $amount);
|
||||
|
||||
|
@ -11,11 +11,13 @@
|
||||
|
||||
namespace Tests\Unit;
|
||||
|
||||
use Tests\TestCase;
|
||||
use Tests\MockAccountData;
|
||||
use App\DataMapper\InvoiceItem;
|
||||
use App\Factory\InvoiceFactory;
|
||||
use App\Factory\InvoiceItemFactory;
|
||||
use App\Helpers\Invoice\InvoiceItemSum;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
use Tests\MockAccountData;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* @test
|
||||
@ -33,6 +35,154 @@ class InvoiceItemTest extends TestCase
|
||||
$this->makeTestData();
|
||||
}
|
||||
|
||||
public function testDicountsWithTaxes()
|
||||
{
|
||||
$invoice = InvoiceFactory::create($this->company->id, $this->user->id);
|
||||
$invoice->client_id = $this->client->id;
|
||||
$invoice->uses_inclusive_taxes = false;
|
||||
$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(99, $invoice->amount);
|
||||
$this->assertEquals(9, $invoice->total_taxes);
|
||||
}
|
||||
|
||||
|
||||
public function testDicountsWithTaxesNegativeInvoice()
|
||||
{
|
||||
$invoice = InvoiceFactory::create($this->company->id, $this->user->id);
|
||||
$invoice->client_id = $this->client->id;
|
||||
$invoice->uses_inclusive_taxes = false;
|
||||
$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(-99, $invoice->amount);
|
||||
$this->assertEquals(-9, $invoice->total_taxes);
|
||||
}
|
||||
|
||||
public function testDicountsWithTaxesPercentage()
|
||||
{
|
||||
$invoice = InvoiceFactory::create($this->company->id, $this->user->id);
|
||||
$invoice->client_id = $this->client->id;
|
||||
$invoice->uses_inclusive_taxes = false;
|
||||
$invoice->is_amount_discount =false;
|
||||
$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(99, $invoice->amount);
|
||||
$this->assertEquals(9, $invoice->total_taxes);
|
||||
}
|
||||
|
||||
|
||||
public function testDicountsWithTaxesNegativeInvoicePercentage()
|
||||
{
|
||||
$invoice = InvoiceFactory::create($this->company->id, $this->user->id);
|
||||
$invoice->client_id = $this->client->id;
|
||||
$invoice->uses_inclusive_taxes = false;
|
||||
$invoice->is_amount_discount =false;
|
||||
$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(-121, $invoice->amount);
|
||||
$this->assertEquals(-10, $invoice->discount);
|
||||
$this->assertEquals(-11, $invoice->total_taxes);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function testDicountPercentageWithTaxes()
|
||||
{
|
||||
$invoice = InvoiceFactory::create($this->company->id, $this->user->id);
|
||||
$invoice->client_id = $this->client->id;
|
||||
$invoice->uses_inclusive_taxes = false;
|
||||
$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(99, $invoice->amount);
|
||||
$this->assertEquals(9, $invoice->total_taxes);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public function testInvoiceItemTotalSimple()
|
||||
{
|
||||
$item = InvoiceItemFactory::create();
|
||||
|
@ -49,6 +49,8 @@ class InvoiceTest extends TestCase
|
||||
$this->invoice_calc = new InvoiceSum($this->invoice);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function testMarkPaidWithPartial()
|
||||
{
|
||||
$item = InvoiceItemFactory::create();
|
||||
|
Loading…
Reference in New Issue
Block a user