2019-09-03 05:39:35 +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) 2020. Invoice Ninja LLC (https://invoiceninja.com)
|
|
|
|
*
|
|
|
|
* @license https://opensource.org/licenses/AAL
|
|
|
|
*/
|
2019-09-03 05:39:35 +02:00
|
|
|
namespace Tests\Unit;
|
|
|
|
|
|
|
|
use Tests\TestCase;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
* @covers App\Utils\Traits\MakesInvoiceValues
|
|
|
|
*/
|
|
|
|
class MakesInvoiceValuesTest extends TestCase
|
|
|
|
{
|
2020-03-21 06:37:30 +01:00
|
|
|
public function testStrReplaceArray()
|
|
|
|
{
|
|
|
|
$columns = ['custom_invoice_label3'];
|
|
|
|
|
|
|
|
$columns = str_replace(
|
2020-03-26 04:23:57 +01:00
|
|
|
['custom_invoice_label1',
|
2020-03-21 06:37:30 +01:00
|
|
|
'custom_invoice_label2',
|
|
|
|
'custom_invoice_label3',
|
2020-09-06 11:38:10 +02:00
|
|
|
'custom_invoice_label4', ],
|
2020-03-26 04:23:57 +01:00
|
|
|
['custom_invoice_value1',
|
2020-03-21 06:37:30 +01:00
|
|
|
'custom_invoice_value2',
|
|
|
|
'custom_invoice_value3',
|
2020-09-06 11:38:10 +02:00
|
|
|
'custom_invoice_value4', ],
|
2020-03-26 04:23:57 +01:00
|
|
|
$columns
|
|
|
|
);
|
2020-03-21 06:37:30 +01:00
|
|
|
|
2020-09-06 11:38:10 +02:00
|
|
|
$this->assertTrue(in_array('custom_invoice_value3', $columns));
|
|
|
|
$this->assertFalse(in_array('custom_invoice_value1', $columns));
|
2020-03-21 06:37:30 +01:00
|
|
|
}
|
2019-09-03 05:39:35 +02:00
|
|
|
|
2019-09-04 07:10:10 +02:00
|
|
|
public function testFilteringItemTaxes()
|
|
|
|
{
|
|
|
|
$taxes = collect();
|
2019-09-03 05:39:35 +02:00
|
|
|
|
2020-09-06 11:38:10 +02:00
|
|
|
$tax_name = 'GST';
|
|
|
|
$tax_rate = '10.00';
|
2019-09-04 07:10:10 +02:00
|
|
|
|
2020-09-06 11:38:10 +02:00
|
|
|
$key = str_replace(' ', '', $tax_name.$tax_rate);
|
2019-09-04 07:10:10 +02:00
|
|
|
|
2020-09-06 11:38:10 +02:00
|
|
|
$group_tax = collect(['key' => $key, 'total' => 20, 'tax_name' => $tax_name.' '.$tax_rate.'%']);
|
2020-03-21 06:37:30 +01:00
|
|
|
$taxes->push($group_tax);
|
2020-09-06 11:38:10 +02:00
|
|
|
$group_tax = collect(['key' => $key, 'total' => 30, 'tax_name' => $tax_name.' '.$tax_rate.'%']);
|
2020-03-21 06:37:30 +01:00
|
|
|
$taxes->push($group_tax);
|
2020-09-06 11:38:10 +02:00
|
|
|
$group_tax = collect(['key' => $key, 'total' => 30, 'tax_name' => $tax_name.' '.$tax_rate.'%']);
|
2020-03-21 06:37:30 +01:00
|
|
|
$taxes->push($group_tax);
|
2020-09-06 11:38:10 +02:00
|
|
|
$group_tax = collect(['key' => $key, 'total' => 20, 'tax_name' => $tax_name.' '.$tax_rate.'%']);
|
2020-03-21 06:37:30 +01:00
|
|
|
$taxes->push($group_tax);
|
2020-09-06 11:38:10 +02:00
|
|
|
$group_tax = collect(['key' => 'VAT', 'total' => 20, 'tax_name' => 'VAT'.' '.'17.5%']);
|
2020-03-21 06:37:30 +01:00
|
|
|
$taxes->push($group_tax);
|
2019-09-04 07:10:10 +02:00
|
|
|
|
|
|
|
$this->assertEquals(5, $taxes->count());
|
|
|
|
|
|
|
|
$keys = $taxes->pluck('key')->unique();
|
|
|
|
|
2020-09-06 11:38:10 +02:00
|
|
|
$this->assertEquals('GST10.00', $keys->first());
|
2019-09-04 07:10:10 +02:00
|
|
|
|
|
|
|
$tax_array = [];
|
|
|
|
|
2020-03-21 06:37:30 +01:00
|
|
|
foreach ($keys as $key) {
|
|
|
|
$tax_name = $taxes->filter(function ($value, $k) use ($key) {
|
2019-09-04 07:10:10 +02:00
|
|
|
return $value['key'] == $key;
|
|
|
|
})->pluck('tax_name')->first();
|
|
|
|
|
2020-03-21 06:37:30 +01:00
|
|
|
$total_line_tax = $taxes->filter(function ($value, $k) use ($key) {
|
2019-09-04 07:10:10 +02:00
|
|
|
return $value['key'] == $key;
|
|
|
|
})->sum('total');
|
2020-09-06 11:38:10 +02:00
|
|
|
|
2019-09-04 07:10:10 +02:00
|
|
|
$tax_array[] = ['name' => $tax_name, 'total' => $total_line_tax];
|
|
|
|
}
|
|
|
|
|
2019-09-04 07:15:42 +02:00
|
|
|
//$this->assertEquals("GST10.00", print_r($tax_array));
|
|
|
|
$this->assertEquals(100, $tax_array[0]['total']);
|
2019-09-04 07:10:10 +02:00
|
|
|
}
|
2019-09-03 05:39:35 +02:00
|
|
|
}
|