mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-11 13:42:49 +01:00
56 lines
1.6 KiB
PHP
56 lines
1.6 KiB
PHP
<?php
|
|
|
|
/**
|
|
* 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
|
|
*/
|
|
|
|
namespace App\Services\PdfMaker\Designs\Utilities;
|
|
|
|
trait BuildTableHeader
|
|
{
|
|
/**
|
|
* This method will help us decide either we show
|
|
* one "tax rate" column in the table or 3 custom tax rates.
|
|
*
|
|
* Logic below will help us calculate that & inject the result in the
|
|
* global state of the $context (design state).
|
|
*
|
|
* @return void
|
|
*/
|
|
public function processTaxColumns(): void
|
|
{
|
|
if (isset($this->context['product-table-columns']['$product.tax'])) {
|
|
$line_items = collect($this->invoice->line_items);
|
|
|
|
$tax1 = $line_items->where('tax_name1', '<>', '')->where('type_id', 1)->count();
|
|
$tax2 = $line_items->where('tax_name2', '<>', '')->where('type_id', 1)->count();
|
|
$tax3 = $line_items->where('tax_name3', '<>', '')->where('type_id', 1)->count();
|
|
$taxes = [];
|
|
|
|
if ($tax1 > 0) {
|
|
array_push($taxes, '$product.tax_rate1');
|
|
}
|
|
|
|
if ($tax2 > 0) {
|
|
array_push($taxes, '$product.tax_rate2');
|
|
}
|
|
|
|
if ($tax3 > 0) {
|
|
array_push($taxes, '$product.tax_rate3');
|
|
}
|
|
|
|
$key = array_search('$product.tax', $this->context['product-table-columns'], true);
|
|
|
|
if ($key) {
|
|
array_splice($this->context['product-table-columns'], $key, 1, $taxes);
|
|
}
|
|
}
|
|
}
|
|
}
|