mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-05 18:52:44 +01:00
Extract helpers for tax calculations into another file
This commit is contained in:
parent
efd698c9c5
commit
ee6da44a94
@ -12,11 +12,12 @@
|
||||
|
||||
namespace App\Services\PdfMaker\Designs;
|
||||
|
||||
use App\Services\PdfMaker\Designs\Utilities\BuildTableHeader;
|
||||
use App\Utils\Traits\MakesInvoiceValues;
|
||||
|
||||
class Plain
|
||||
{
|
||||
use MakesInvoiceValues;
|
||||
use MakesInvoiceValues, BuildTableHeader;
|
||||
|
||||
public $elements;
|
||||
|
||||
@ -87,35 +88,10 @@ class Plain
|
||||
|
||||
public function buildTableHeader(): array
|
||||
{
|
||||
$this->processTaxColumns();
|
||||
|
||||
$elements = [];
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($this->context['product-table-columns'] as $column) {
|
||||
$elements[] = ['element' => 'th', 'content' => $column . '_label', 'properties' => ['class' => 'px-4 py-2']];
|
||||
}
|
||||
@ -140,10 +116,6 @@ class Plain
|
||||
$element['elements'][] = ['element' => 'td', 'content' => $row[$cell], 'properties' => ['class' => 'border-t-2 border-b border-gray-200 px-4 py-4']];
|
||||
}
|
||||
|
||||
// foreach ($row as $child) {
|
||||
// $element['elements'][] = ['element' => 'td', 'content' => $child, 'properties' => ['class' => 'border-t-2 border-b border-gray-200 px-4 py-4']];
|
||||
// }
|
||||
|
||||
$elements[] = $element;
|
||||
}
|
||||
|
||||
|
55
app/Services/PdfMaker/Designs/Utilities/BuildTableHeader.php
Normal file
55
app/Services/PdfMaker/Designs/Utilities/BuildTableHeader.php
Normal file
@ -0,0 +1,55 @@
|
||||
<?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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user