2019-10-22 04:07:00 +02:00
|
|
|
<?php
|
2020-09-14 13:11:46 +02:00
|
|
|
/**
|
|
|
|
* Invoice Ninja (https://invoiceninja.com).
|
|
|
|
*
|
|
|
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
|
|
|
*
|
2021-01-03 22:54:54 +01:00
|
|
|
* @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-10-22 04:07:00 +02:00
|
|
|
namespace Tests\Unit;
|
|
|
|
|
|
|
|
use App\Factory\InvoiceItemFactory;
|
|
|
|
use App\Helpers\Invoice\InvoiceItemSumInclusive;
|
|
|
|
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
|
|
|
use Tests\MockAccountData;
|
|
|
|
use Tests\TestCase;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
* @covers App\Helpers\Invoice\InvoiceItemSumInclusive
|
|
|
|
*/
|
|
|
|
class InvoiceItemInclusiveTest extends TestCase
|
|
|
|
{
|
2020-03-21 06:37:30 +01:00
|
|
|
use MockAccountData;
|
2019-10-22 04:07:00 +02:00
|
|
|
use DatabaseTransactions;
|
|
|
|
|
|
|
|
public function setUp() :void
|
|
|
|
{
|
2020-03-21 06:37:30 +01:00
|
|
|
parent::setUp();
|
2020-09-06 11:38:10 +02:00
|
|
|
|
2020-03-21 06:37:30 +01:00
|
|
|
$this->makeTestData();
|
|
|
|
}
|
2019-10-22 04:07:00 +02:00
|
|
|
|
2020-03-21 06:37:30 +01:00
|
|
|
public function testInvoiceItemTotalSimpleX()
|
|
|
|
{
|
|
|
|
$item = InvoiceItemFactory::create();
|
|
|
|
$item->quantity = 1;
|
2020-09-06 11:38:10 +02:00
|
|
|
$item->cost = 10;
|
2020-03-21 06:37:30 +01:00
|
|
|
$item->is_amount_discount = true;
|
2019-10-22 04:07:00 +02:00
|
|
|
|
2020-03-21 06:37:30 +01:00
|
|
|
$settings = new \stdClass;
|
|
|
|
$settings->inclusive_taxes = true;
|
|
|
|
$settings->precision = 2;
|
2019-10-22 04:07:00 +02:00
|
|
|
|
2020-03-21 06:37:30 +01:00
|
|
|
$this->invoice->line_items = [$item];
|
2019-10-22 04:07:00 +02:00
|
|
|
|
2020-03-21 06:37:30 +01:00
|
|
|
$item_calc = new InvoiceItemSumInclusive($this->invoice);
|
|
|
|
$item_calc->process();
|
2019-10-22 04:07:00 +02:00
|
|
|
|
2020-03-21 06:37:30 +01:00
|
|
|
$this->assertEquals($item_calc->getLineTotal(), 10);
|
|
|
|
}
|
2019-10-22 04:07:00 +02:00
|
|
|
|
2020-03-21 06:37:30 +01:00
|
|
|
public function testInvoiceItemTotalSimpleWithDiscount()
|
|
|
|
{
|
|
|
|
$item = InvoiceItemFactory::create();
|
|
|
|
$item->quantity = 1;
|
2020-09-06 11:38:10 +02:00
|
|
|
$item->cost = 10;
|
2020-03-21 06:37:30 +01:00
|
|
|
$item->is_amount_discount = true;
|
|
|
|
$item->discount = 2;
|
2019-10-22 04:07:00 +02:00
|
|
|
|
2020-03-21 06:37:30 +01:00
|
|
|
$this->invoice->line_items = [$item];
|
2019-10-22 04:07:00 +02:00
|
|
|
|
2020-03-21 06:37:30 +01:00
|
|
|
$settings = new \stdClass;
|
|
|
|
$settings->inclusive_taxes = true;
|
|
|
|
$settings->precision = 2;
|
|
|
|
|
|
|
|
$item_calc = new InvoiceItemSumInclusive($this->invoice);
|
|
|
|
$item_calc->process();
|
|
|
|
|
|
|
|
$this->assertEquals($item_calc->getLineTotal(), 8);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testInvoiceItemTotalSimpleWithDiscountWithPrecision()
|
|
|
|
{
|
|
|
|
$item = InvoiceItemFactory::create();
|
|
|
|
$item->quantity = 1;
|
2020-09-06 11:38:10 +02:00
|
|
|
$item->cost = 10;
|
2020-03-21 06:37:30 +01:00
|
|
|
$item->is_amount_discount = true;
|
|
|
|
$item->discount = 2.521254522145214511;
|
|
|
|
|
|
|
|
$this->invoice->line_items = [$item];
|
|
|
|
|
|
|
|
$settings = new \stdClass;
|
|
|
|
$settings->inclusive_taxes = true;
|
|
|
|
$settings->precision = 2;
|
|
|
|
|
|
|
|
$item_calc = new InvoiceItemSumInclusive($this->invoice);
|
|
|
|
$item_calc->process();
|
|
|
|
|
|
|
|
$this->assertEquals($item_calc->getLineTotal(), 7.48);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testInvoiceItemTotalSimpleWithDiscountWithPrecisionWithSingleInclusiveTax()
|
|
|
|
{
|
|
|
|
$item = InvoiceItemFactory::create();
|
|
|
|
$item->quantity = 1;
|
2020-09-06 11:38:10 +02:00
|
|
|
$item->cost = 10;
|
2020-03-21 06:37:30 +01:00
|
|
|
$item->is_amount_discount = true;
|
|
|
|
$item->discount = 0;
|
|
|
|
$item->tax_rate1 = 10;
|
|
|
|
|
|
|
|
$settings = new \stdClass;
|
|
|
|
$settings->inclusive_taxes = false;
|
|
|
|
$settings->precision = 2;
|
|
|
|
|
|
|
|
$this->invoice->line_items = [$item];
|
|
|
|
|
|
|
|
$item_calc = new InvoiceItemSumInclusive($this->invoice);
|
|
|
|
$item_calc->process();
|
|
|
|
|
|
|
|
$this->assertEquals($item_calc->getTotalTaxes(), 0.91);
|
|
|
|
$this->assertEquals($item_calc->getSubTotal(), 10);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testInvoiceItemTotalSimpleWithDiscountWithPrecisionWithSingleInclusiveTax2()
|
|
|
|
{
|
|
|
|
$item = InvoiceItemFactory::create();
|
|
|
|
$item->quantity = 1;
|
2020-09-06 11:38:10 +02:00
|
|
|
$item->cost = 10;
|
2020-03-21 06:37:30 +01:00
|
|
|
$item->is_amount_discount = true;
|
|
|
|
$item->discount = 2;
|
|
|
|
$item->tax_rate1 = 10;
|
|
|
|
|
|
|
|
$settings = new \stdClass;
|
|
|
|
$settings->inclusive_taxes = false;
|
|
|
|
$settings->precision = 2;
|
|
|
|
|
|
|
|
$this->invoice->line_items = [$item];
|
2019-10-22 04:07:00 +02:00
|
|
|
|
2020-03-21 06:37:30 +01:00
|
|
|
$item_calc = new InvoiceItemSumInclusive($this->invoice);
|
|
|
|
$item_calc->process();
|
|
|
|
|
|
|
|
$this->assertEquals($item_calc->getTotalTaxes(), 0.73);
|
|
|
|
$this->assertEquals($item_calc->getSubTotal(), 8);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testInvoiceItemTotalSimpleWithDiscountWithPrecisionWithDoubleInclusiveTax()
|
|
|
|
{
|
|
|
|
$item = InvoiceItemFactory::create();
|
|
|
|
$item->quantity = 1;
|
|
|
|
$item->cost = 10;
|
|
|
|
$item->is_amount_discount = true;
|
|
|
|
$item->discount = 0;
|
|
|
|
$item->tax_rate1 = 10;
|
|
|
|
$item->tax_rate2 = 17.5;
|
|
|
|
|
|
|
|
$this->invoice->line_items = [$item];
|
|
|
|
|
|
|
|
$settings = new \stdClass;
|
|
|
|
$settings->inclusive_taxes = true;
|
|
|
|
$settings->precision = 2;
|
|
|
|
|
|
|
|
$item_calc = new InvoiceItemSumInclusive($this->invoice);
|
|
|
|
$item_calc->process();
|
|
|
|
|
|
|
|
$this->assertEquals($item_calc->getTotalTaxes(), 2.4);
|
|
|
|
$this->assertEquals($item_calc->getSubTotal(), 10);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testInvoiceItemTotalSimpleWithDiscountWithDoubleInclusiveTax()
|
|
|
|
{
|
|
|
|
$item = InvoiceItemFactory::create();
|
|
|
|
$item->quantity = 1;
|
2020-09-06 11:38:10 +02:00
|
|
|
$item->cost = 10;
|
2020-03-21 06:37:30 +01:00
|
|
|
$item->is_amount_discount = true;
|
|
|
|
$item->discount = 1;
|
|
|
|
$item->tax_rate1 = 10;
|
|
|
|
$item->tax_rate2 = 17.5;
|
|
|
|
|
|
|
|
$this->invoice->line_items = [$item];
|
|
|
|
|
|
|
|
$settings = new \stdClass;
|
|
|
|
$settings->inclusive_taxes = false;
|
|
|
|
$settings->precision = 2;
|
|
|
|
|
|
|
|
$item_calc = new InvoiceItemSumInclusive($this->invoice);
|
|
|
|
$item_calc->process();
|
|
|
|
|
|
|
|
$this->assertEquals($item_calc->getSubTotal(), 9);
|
|
|
|
$this->assertEquals($item_calc->getTotalTaxes(), 2.16);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testInvoiceItemTotalSimpleWithDiscountWithDoubleInclusiveTaxMultiQuantity()
|
|
|
|
{
|
|
|
|
$item = InvoiceItemFactory::create();
|
|
|
|
$item->quantity = 2;
|
2020-09-06 11:38:10 +02:00
|
|
|
$item->cost = 10;
|
2020-03-21 06:37:30 +01:00
|
|
|
$item->is_amount_discount = true;
|
|
|
|
$item->discount = 1;
|
|
|
|
$item->tax_rate1 = 10;
|
|
|
|
$item->tax_rate2 = 17.5;
|
|
|
|
|
|
|
|
$this->invoice->line_items = [$item];
|
|
|
|
|
|
|
|
$settings = new \stdClass;
|
|
|
|
$settings->inclusive_taxes = false;
|
|
|
|
$settings->precision = 2;
|
|
|
|
|
|
|
|
$item_calc = new InvoiceItemSumInclusive($this->invoice);
|
|
|
|
$item_calc->process();
|
|
|
|
|
|
|
|
$this->assertEquals($item_calc->getSubTotal(), 19);
|
|
|
|
$this->assertEquals($item_calc->getTotalTaxes(), 4.56);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testInvoiceItemTotalSimpleWithPercentDiscountWithDoubleInclusiveTaxMultiQuantity()
|
|
|
|
{
|
|
|
|
$item = InvoiceItemFactory::create();
|
|
|
|
$item->quantity = 2;
|
2020-09-06 11:38:10 +02:00
|
|
|
$item->cost = 10;
|
2020-03-21 06:37:30 +01:00
|
|
|
$item->is_amount_discount = false;
|
|
|
|
$item->discount = 1;
|
|
|
|
$item->tax_rate1 = 10;
|
|
|
|
$item->tax_rate2 = 17.5;
|
|
|
|
|
|
|
|
$this->invoice->line_items = [$item];
|
|
|
|
$this->invoice->is_amount_discount = false;
|
|
|
|
|
|
|
|
$settings = new \stdClass;
|
|
|
|
$settings->inclusive_taxes = false;
|
|
|
|
$settings->precision = 2;
|
|
|
|
|
|
|
|
$item_calc = new InvoiceItemSumInclusive($this->invoice);
|
|
|
|
$item_calc->process();
|
|
|
|
|
|
|
|
$this->assertEquals($item_calc->getSubTotal(), 19.8);
|
|
|
|
$this->assertEquals($item_calc->getTotalTaxes(), 4.75);
|
|
|
|
}
|
|
|
|
}
|