2019-04-04 11:28:53 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Tests\Unit;
|
|
|
|
|
|
|
|
use App\Factory\InvoiceItemFactory;
|
|
|
|
use App\Helpers\Invoice\InvoiceItemCalc;
|
|
|
|
use Tests\TestCase;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
* @covers App\Helpers\Invoice\InvoiceItemCalc
|
|
|
|
*/
|
|
|
|
class InvoiceItemTest extends TestCase
|
|
|
|
{
|
|
|
|
public function setUp()
|
|
|
|
{
|
|
|
|
|
|
|
|
parent::setUp();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testInvoiceItemTotalSimple()
|
|
|
|
{
|
|
|
|
$item = InvoiceItemFactory::create();
|
|
|
|
$item->qty = 1;
|
|
|
|
$item->cost =10;
|
|
|
|
$item->is_amount_discount = true;
|
|
|
|
|
2019-04-05 11:08:29 +02:00
|
|
|
$settings = new \stdClass;
|
2019-04-15 01:51:43 +02:00
|
|
|
$settings->inclusive_taxes = true;
|
2019-04-05 11:08:29 +02:00
|
|
|
$settings->precision = 2;
|
2019-04-04 11:28:53 +02:00
|
|
|
|
2019-04-05 11:08:29 +02:00
|
|
|
$item_calc = new InvoiceItemCalc($item, $settings);
|
2019-04-04 11:28:53 +02:00
|
|
|
$item_calc->process();
|
|
|
|
|
|
|
|
$this->assertEquals($item_calc->getLineTotal(), 10);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testInvoiceItemTotalSimpleWithDiscount()
|
|
|
|
{
|
|
|
|
$item = InvoiceItemFactory::create();
|
|
|
|
$item->qty = 1;
|
|
|
|
$item->cost =10;
|
|
|
|
$item->is_amount_discount = true;
|
|
|
|
$item->discount = 2;
|
|
|
|
|
2019-04-05 11:08:29 +02:00
|
|
|
$settings = new \stdClass;
|
2019-04-15 01:51:43 +02:00
|
|
|
$settings->inclusive_taxes = true;
|
2019-04-05 11:08:29 +02:00
|
|
|
$settings->precision = 2;
|
|
|
|
$item_calc = new InvoiceItemCalc($item, $settings);
|
2019-04-04 11:28:53 +02:00
|
|
|
$item_calc->process();
|
|
|
|
|
|
|
|
$this->assertEquals($item_calc->getLineTotal(), 8);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testInvoiceItemTotalSimpleWithDiscountWithPrecision()
|
|
|
|
{
|
|
|
|
$item = InvoiceItemFactory::create();
|
|
|
|
$item->qty = 1;
|
|
|
|
$item->cost =10;
|
|
|
|
$item->is_amount_discount = true;
|
|
|
|
$item->discount = 2.521254522145214511;
|
|
|
|
|
2019-04-05 11:08:29 +02:00
|
|
|
$settings = new \stdClass;
|
2019-04-15 01:51:43 +02:00
|
|
|
$settings->inclusive_taxes = true;
|
2019-04-05 11:08:29 +02:00
|
|
|
$settings->precision = 2;
|
2019-04-04 11:28:53 +02:00
|
|
|
|
2019-04-05 11:08:29 +02:00
|
|
|
$item_calc = new InvoiceItemCalc($item, $settings);
|
2019-04-04 11:28:53 +02:00
|
|
|
$item_calc->process();
|
|
|
|
|
|
|
|
$this->assertEquals($item_calc->getLineTotal(), 7.48);
|
|
|
|
}
|
|
|
|
|
2019-04-04 11:53:40 +02:00
|
|
|
public function testInvoiceItemTotalSimpleWithDiscountWithPrecisionWithSingleInclusiveTax()
|
2019-04-04 11:28:53 +02:00
|
|
|
{
|
|
|
|
$item = InvoiceItemFactory::create();
|
|
|
|
$item->qty = 1;
|
|
|
|
$item->cost =10;
|
|
|
|
$item->is_amount_discount = true;
|
|
|
|
$item->discount = 2.521254522145214511;
|
2019-04-04 11:53:40 +02:00
|
|
|
$item->tax_rate1 = 10;
|
2019-04-04 11:28:53 +02:00
|
|
|
|
2019-04-05 11:08:29 +02:00
|
|
|
$settings = new \stdClass;
|
2019-04-15 01:51:43 +02:00
|
|
|
$settings->inclusive_taxes = true;
|
2019-04-05 11:08:29 +02:00
|
|
|
$settings->precision = 2;
|
2019-04-04 11:28:53 +02:00
|
|
|
|
2019-04-05 11:08:29 +02:00
|
|
|
$item_calc = new InvoiceItemCalc($item, $settings);
|
2019-04-04 11:28:53 +02:00
|
|
|
$item_calc->process();
|
|
|
|
|
2019-04-04 11:53:40 +02:00
|
|
|
$this->assertEquals($item_calc->getTotalTaxes(), 0.68);
|
2019-04-04 11:28:53 +02:00
|
|
|
}
|
|
|
|
|
2019-04-04 11:53:40 +02:00
|
|
|
public function testInvoiceItemTotalSimpleWithDiscountWithPrecisionWithSingleExclusiveTax()
|
2019-04-04 11:28:53 +02:00
|
|
|
{
|
|
|
|
$item = InvoiceItemFactory::create();
|
|
|
|
$item->qty = 1;
|
|
|
|
$item->cost =10;
|
|
|
|
$item->is_amount_discount = true;
|
|
|
|
$item->discount = 2.521254522145214511;
|
2019-04-04 11:53:40 +02:00
|
|
|
$item->tax_rate1 = 10;
|
2019-04-04 11:28:53 +02:00
|
|
|
|
2019-04-05 11:08:29 +02:00
|
|
|
$settings = new \stdClass;
|
2019-04-15 01:51:43 +02:00
|
|
|
$settings->inclusive_taxes = false;
|
2019-04-05 11:08:29 +02:00
|
|
|
$settings->precision = 2;
|
2019-04-04 11:28:53 +02:00
|
|
|
|
2019-04-05 11:08:29 +02:00
|
|
|
$item_calc = new InvoiceItemCalc($item, $settings);
|
2019-04-04 11:28:53 +02:00
|
|
|
$item_calc->process();
|
|
|
|
|
2019-04-04 11:53:40 +02:00
|
|
|
$this->assertEquals($item_calc->getTotalTaxes(), 0.75);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testInvoiceItemTotalSimpleWithDiscountWithPrecisionWithDoubleInclusiveTax()
|
|
|
|
{
|
|
|
|
$item = InvoiceItemFactory::create();
|
|
|
|
$item->qty = 1;
|
|
|
|
$item->cost =10;
|
|
|
|
$item->is_amount_discount = true;
|
|
|
|
$item->discount = 2.521254522145214511;
|
|
|
|
$item->tax_rate1 = 10;
|
|
|
|
$item->tax_rate2 = 17.5;
|
|
|
|
|
2019-04-05 11:08:29 +02:00
|
|
|
$settings = new \stdClass;
|
2019-04-15 01:51:43 +02:00
|
|
|
$settings->inclusive_taxes = true;
|
2019-04-05 11:08:29 +02:00
|
|
|
$settings->precision = 2;
|
2019-04-04 11:53:40 +02:00
|
|
|
|
2019-04-05 11:08:29 +02:00
|
|
|
$item_calc = new InvoiceItemCalc($item, $settings);
|
2019-04-04 11:53:40 +02:00
|
|
|
$item_calc->process();
|
|
|
|
|
|
|
|
$this->assertEquals($item_calc->getTotalTaxes(), 1.79);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testInvoiceItemTotalSimpleWithDiscountWithPrecisionWithDoubleExclusiveTax()
|
|
|
|
{
|
|
|
|
$item = InvoiceItemFactory::create();
|
|
|
|
$item->qty = 1;
|
|
|
|
$item->cost =10;
|
|
|
|
$item->is_amount_discount = true;
|
|
|
|
$item->discount = 2.521254522145214511;
|
|
|
|
$item->tax_rate1 = 10;
|
|
|
|
$item->tax_rate2 = 17.5;
|
|
|
|
|
2019-04-05 11:08:29 +02:00
|
|
|
$settings = new \stdClass;
|
2019-04-15 01:51:43 +02:00
|
|
|
$settings->inclusive_taxes = false;
|
2019-04-05 11:08:29 +02:00
|
|
|
$settings->precision = 2;
|
2019-04-04 11:53:40 +02:00
|
|
|
|
2019-04-05 11:08:29 +02:00
|
|
|
$item_calc = new InvoiceItemCalc($item, $settings);
|
2019-04-04 11:53:40 +02:00
|
|
|
$item_calc->process();
|
|
|
|
|
|
|
|
$this->assertEquals($item_calc->getTotalTaxes(), 2.06);
|
2019-04-15 01:51:43 +02:00
|
|
|
$this->assertEquals($item_calc->getGroupedTaxes()->count(), 2);
|
2019-04-04 11:28:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2019-04-04 11:53:40 +02:00
|
|
|
|
|
|
|
|