diff --git a/app/Services/PdfMaker/Designs/Plain.php b/app/Services/PdfMaker/Designs/Plain.php index 32b9608dd..3b523df8f 100644 --- a/app/Services/PdfMaker/Designs/Plain.php +++ b/app/Services/PdfMaker/Designs/Plain.php @@ -89,6 +89,33 @@ class Plain { $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']]; } @@ -109,10 +136,14 @@ class Plain foreach ($items as $row) { $element = ['element' => 'tr', 'content' => '', 'elements' => []]; - foreach ($row as $child) { - $element['elements'][] = ['element' => 'td', 'content' => $child, 'properties' => ['class' => 'border-t-2 border-b border-gray-200 px-4 py-4']]; + foreach ($this->context['product-table-columns'] as $key => $cell) { + $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; }