From 8ec85b9cd34d50a07ba8856134952da3f1793588 Mon Sep 17 00:00:00 2001 From: Maksim Stojkovic <18454392+maksimstojkovic@users.noreply.github.com> Date: Tue, 28 Dec 2021 01:26:37 +1100 Subject: [PATCH] added custom product fields to delivery notes --- app/Services/PdfMaker/Design.php | 47 ++++++++++++++++++++++++++++---- 1 file changed, 42 insertions(+), 5 deletions(-) diff --git a/app/Services/PdfMaker/Design.php b/app/Services/PdfMaker/Design.php index 14053737b8b7..4e29441ed28f 100644 --- a/app/Services/PdfMaker/Design.php +++ b/app/Services/PdfMaker/Design.php @@ -286,12 +286,33 @@ class Design extends BaseDesign return []; } + $thead = [ + ['element' => 'th', 'content' => '$item_label', 'properties' => ['data-ref' => 'delivery_note-item_label']], + ['element' => 'th', 'content' => '$description_label', 'properties' => ['data-ref' => 'delivery_note-description_label']], + ['element' => 'th', 'content' => '$product.quantity_label', 'properties' => ['data-ref' => 'delivery_note-product.quantity_label']], + ]; + + $items = $this->transformLineItems($this->entity->line_items, $this->type); + + $this->processNewLines($items); + $product_customs = [false, false, false, false]; + + foreach ($items as $row) { + for ($i = 0; $i < count($product_customs); $i++) { + if (!empty($row['delivery_note.delivery_note' . ($i + 1)])) { + $product_customs[$i] = true; + } + } + } + + for ($i = 0; $i < count($product_customs); $i++) { + if ($product_customs[$i]) { + array_push($thead, ['element' => 'th', 'content' => '$product.product' . ($i + 1) . '_label', 'properties' => ['data-ref' => 'delivery_note-product.product' . ($i + 1) . '_label']]); + } + } + return [ - ['element' => 'thead', 'elements' => [ - ['element' => 'th', 'content' => '$item_label', 'properties' => ['data-ref' => 'delivery_note-item_label']], - ['element' => 'th', 'content' => '$description_label', 'properties' => ['data-ref' => 'delivery_note-description_label']], - ['element' => 'th', 'content' => '$product.quantity_label', 'properties' => ['data-ref' => 'delivery_note-product.quantity_label']], - ]], + ['element' => 'thead', 'elements' => $thead], ['element' => 'tbody', 'elements' => $this->buildTableBody(self::DELIVERY_NOTE)], ]; } @@ -528,6 +549,16 @@ class Design extends BaseDesign } if ($type == self::DELIVERY_NOTE) { + $product_customs = [false, false, false, false]; + + foreach ($items as $row) { + for ($i = 0; $i < count($product_customs); $i++) { + if (!empty($row['delivery_note.delivery_note' . ($i + 1)])) { + $product_customs[$i] = true; + } + } + } + foreach ($items as $row) { $element = ['element' => 'tr', 'elements' => []]; @@ -535,6 +566,12 @@ class Design extends BaseDesign $element['elements'][] = ['element' => 'td', 'content' => $row['delivery_note.notes'], 'properties' => ['data-ref' => 'delivery_note_table.notes-td']]; $element['elements'][] = ['element' => 'td', 'content' => $row['delivery_note.quantity'], 'properties' => ['data-ref' => 'delivery_note_table.quantity-td']]; + for ($i = 0; $i < count($product_customs); $i++) { + if ($product_customs[$i]) { + $element['elements'][] = ['element' => 'td', 'content' => $row['delivery_note.delivery_note' . ($i + 1)], 'properties' => ['data-ref' => 'delivery_note_table.product' . ($i + 1) . '-td']]; + } + } + $elements[] = $element; }