1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-06 03:02:34 +01:00
invoiceninja/tests/Unit/InvoiceTest.php

224 lines
6.6 KiB
PHP
Raw Normal View History

2019-04-10 11:09:57 +02:00
<?php
2020-09-14 13:11:46 +02:00
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
2020-09-14 13:11:46 +02:00
*
* @license https://opensource.org/licenses/AAL
*/
2019-04-10 11:09:57 +02:00
namespace Tests\Unit;
use App\Factory\InvoiceItemFactory;
use App\Helpers\Invoice\InvoiceSum;
2019-04-24 12:01:40 +02:00
use Illuminate\Foundation\Testing\DatabaseTransactions;
2019-10-07 11:56:10 +02:00
use Tests\MockAccountData;
2019-04-10 11:09:57 +02:00
use Tests\TestCase;
/**
* @test
* @covers App\Helpers\Invoice\InvoiceSum
2019-04-10 11:09:57 +02:00
*/
class InvoiceTest extends TestCase
{
use MockAccountData;
use DatabaseTransactions;
2019-04-10 11:42:19 +02:00
public $invoice;
2019-04-10 11:42:19 +02:00
public $invoice_calc;
2019-04-10 11:42:19 +02:00
public $settings;
2019-04-10 11:42:19 +02:00
2019-04-24 12:01:40 +02:00
public function setUp() :void
2019-04-10 11:09:57 +02:00
{
parent::setUp();
$this->makeTestData();
2019-10-07 11:39:22 +02:00
$this->invoice->line_items = $this->buildLineItems();
2019-04-10 11:42:19 +02:00
$this->invoice->usesinclusive_taxes = true;
2019-04-10 11:42:19 +02:00
$this->invoice_calc = new InvoiceSum($this->invoice);
}
2019-04-24 12:01:40 +02:00
private function buildLineItems()
{
$line_items = [];
2019-04-11 02:57:06 +02:00
$item = InvoiceItemFactory::create();
$item->quantity = 1;
$item->cost = 10;
2019-04-11 02:57:06 +02:00
$line_items[] = $item;
2019-04-11 06:40:36 +02:00
$item = InvoiceItemFactory::create();
$item->quantity = 1;
$item->cost = 10;
2019-04-11 06:40:36 +02:00
$line_items[] = $item;
2019-04-11 06:40:36 +02:00
return $line_items;
}
2019-04-11 06:40:36 +02:00
public function testInvoiceTotals()
{
$this->invoice_calc->build();
2019-04-11 06:40:36 +02:00
$this->assertEquals($this->invoice_calc->getSubTotal(), 20);
$this->assertEquals($this->invoice_calc->getTotal(), 20);
}
2019-04-11 06:40:36 +02:00
public function testInvoiceTotalsWithDiscount()
{
$this->invoice->discount = 5;
$this->invoice_calc->build();
2019-04-11 06:40:36 +02:00
$this->assertEquals($this->invoice_calc->getSubTotal(), 20);
//$this->assertEquals($this->invoice_calc->getTotal(), 15);
//$this->assertEquals($this->invoice_calc->getBalance(), 15);
}
2019-04-11 06:40:36 +02:00
public function testInvoiceTotalsWithDiscountWithSurcharge()
{
$this->invoice->discount = 5;
$this->invoice->custom_value1 = 5;
$this->invoice_calc->build();
2019-04-11 06:40:36 +02:00
$this->assertEquals($this->invoice_calc->getSubTotal(), 20);
//$this->assertEquals($this->invoice_calc->getTotal(), 20);
//$this->assertEquals($this->invoice_calc->getBalance(), 20);
}
public function testInvoiceTotalsWithDiscountWithSurchargeWithInclusiveTax()
{
$this->invoice->discount = 5;
$this->invoice->custom_value1 = 5;
$this->invoice->tax_name1 = 'GST';
$this->invoice->tax_rate1 = 10;
2019-04-11 06:40:36 +02:00
$this->invoice_calc->build();
2019-04-11 06:40:36 +02:00
$this->assertEquals($this->invoice_calc->getSubTotal(), 20);
//$this->assertEquals($this->invoice_calc->getTotal(), 20);
//$this->assertEquals($this->invoice_calc->getBalance(), 20);
}
2019-04-11 06:40:36 +02:00
public function testInvoiceTotalsWithDiscountWithSurchargeWithExclusiveTax()
{
$this->invoice->discount = 5;
$this->invoice->custom_value1 = 5;
$this->invoice->tax_name1 = 'GST';
$this->invoice->tax_rate1 = 10;
$this->invoice->uses_inclusive_taxes = false;
$this->invoice->is_amount_discount = true;
2019-04-11 06:40:36 +02:00
//$this->invoice_calc = new InvoiceSum($this->invoice, $this->settings);
2019-04-11 06:40:36 +02:00
$this->invoice_calc->build();
2019-04-11 06:40:36 +02:00
$this->assertEquals($this->invoice_calc->getSubTotal(), 20);
//$this->assertEquals($this->invoice_calc->getTotal(), 21.5);
//$this->assertEquals($this->invoice_calc->getBalance(), 21.5);
//$this->assertEquals($this->invoice_calc->getTotalTaxes(), 1.5);
}
2019-04-11 06:40:36 +02:00
public function testInvoiceTotalsWithDiscountWithSurchargeWithDoubleExclusiveTax()
{
$this->invoice_calc = new InvoiceSum($this->invoice);
2019-04-11 06:40:36 +02:00
$this->invoice->discount = 5;
$this->invoice->custom_value1 = 5;
$this->invoice->tax_name1 = 'GST';
$this->invoice->tax_rate1 = 10;
$this->invoice->tax_name2 = 'GST';
$this->invoice->tax_rate2 = 10;
$this->invoice->uses_inclusive_taxes = false;
$this->invoice_calc->build();
$this->assertEquals($this->invoice_calc->getSubTotal(), 20);
//$this->assertEquals($this->invoice_calc->getTotal(), 23);
//$this->assertEquals($this->invoice_calc->getBalance(), 23);
//$this->assertEquals($this->invoice_calc->getTotalTaxes(), 3);
}
public function testLineItemTaxRatesInclusiveTaxes()
{
$line_items = [];
$item = InvoiceItemFactory::create();
$item->quantity = 1;
$item->cost = 10;
$item->tax_rate1 = 10;
$item->tax_name1 = 10;
$line_items[] = $item;
$item = InvoiceItemFactory::create();
$item->quantity = 1;
$item->cost = 10;
$item->tax_rate1 = 10;
$item->tax_name1 = 10;
$line_items[] = $item;
$this->invoice->line_items = $line_items;
$this->invoice->uses_inclusive_taxes = true;
$this->invoice->discount = 0;
$this->invoice->custom_value1 = 0;
$this->invoice_calc = new InvoiceSum($this->invoice);
$this->invoice_calc->build();
2019-04-11 06:40:36 +02:00
$this->assertEquals($this->invoice_calc->getSubTotal(), 20);
//$this->assertEquals($this->invoice_calc->getTotal(), 20);
//$this->assertEquals($this->invoice_calc->getBalance(), 20);
//$this->assertEquals($this->invoice_calc->getTotalTaxes(), 1.82);
$this->assertEquals(count($this->invoice_calc->getTaxMap()), 1);
}
2019-04-11 06:40:36 +02:00
public function testLineItemTaxRatesExclusiveTaxes()
{
$line_items = [];
$item = InvoiceItemFactory::create();
$item->quantity = 1;
$item->cost = 10;
$item->tax_rate1 = 10;
$item->tax_name1 = 10;
$line_items[] = $item;
$item = InvoiceItemFactory::create();
$item->quantity = 1;
$item->cost = 10;
$item->tax_rate1 = 10;
$item->tax_name1 = 10;
$line_items[] = $item;
$this->invoice->line_items = $line_items;
$this->invoice->discount = 0;
$this->invoice->tax_name1 = 'GST';
$this->invoice->tax_rate1 = 10;
$this->invoice->tax_name2 = 'GST';
$this->invoice->tax_rate2 = 10;
$this->invoice->uses_inclusive_taxes = false;
$this->invoice_calc = new InvoiceSum($this->invoice);
$this->invoice_calc->build();
$this->assertEquals($this->invoice_calc->getSubTotal(), 20);
//$this->assertEquals($this->invoice_calc->getTotal(), 26);
//$this->assertEquals($this->invoice_calc->getBalance(), 26);
//$this->assertEquals($this->invoice_calc->getTotalTaxes(), 4);
//$this->assertEquals(count($this->invoice_calc->getTaxMap()), 1);
}
}