From 813fc7bd5e1c538306e09acaeffe5a0b83c80eed Mon Sep 17 00:00:00 2001 From: David Bomba Date: Mon, 30 Jan 2023 11:07:55 +1100 Subject: [PATCH] change entity details from table to div --- app/Services/PdfMaker/Design.php | 73 +++++++++++++++++++ .../Designs/Utilities/DesignHelpers.php | 10 +-- resources/views/pdf-designs/clean.html | 21 ++++-- 3 files changed, 94 insertions(+), 10 deletions(-) diff --git a/app/Services/PdfMaker/Design.php b/app/Services/PdfMaker/Design.php index 6d2a54d0ac..98aed75318 100644 --- a/app/Services/PdfMaker/Design.php +++ b/app/Services/PdfMaker/Design.php @@ -310,6 +310,79 @@ class Design extends BaseDesign { + if ($this->type === 'statement') { + + $s_date = $this->translateDate($this->options['start_date'], $this->client->date_format(), $this->client->locale()) . " - " . $this->translateDate($this->options['end_date'], $this->client->date_format(), $this->client->locale()); + + return [ + ['element' => 'p', 'content' => "

".ctrans('texts.statement')."

", 'properties' => ['data-ref' => 'statement-label']], + ['element' => 'p', 'content' => ctrans('texts.statement_date'), 'properties' => ['data-ref' => 'statement-label'],'elements' => + ['element' => 'span', 'content' => "{$s_date} "] + ], + ['element' => 'p', 'content' => '$balance_due_label', 'properties' => ['data-ref' => 'statement-label'],'elements' => + ['element' => 'span', 'content' => Number::formatMoney($this->invoices->sum('balance'), $this->client)] + ], + ]; + + } + + $variables = $this->context['pdf_variables']['invoice_details']; + + if ($this->entity instanceof Quote) { + $variables = $this->context['pdf_variables']['quote_details']; + + if ($this->entity->partial > 0) { + $variables[] = '$quote.balance_due'; + } + } + + if ($this->entity instanceof Credit) { + $variables = $this->context['pdf_variables']['credit_details']; + } + + if($this->vendor){ + + $variables = $this->context['pdf_variables']['purchase_order_details']; + + } + + $elements = []; + + // We don't want to show account balance or invoice total on PDF.. or any amount with currency. + if ($this->type == self::DELIVERY_NOTE) { + $variables = array_filter($variables, function ($m) { + return !in_array($m, ['$invoice.balance_due', '$invoice.total']); + }); + } + + foreach ($variables as $variable) { + $_variable = explode('.', $variable)[1]; + $_customs = ['custom1', 'custom2', 'custom3', 'custom4']; + + /* 2/7/2022 don't show custom values if they are empty */ + $var = str_replace("custom", "custom_value", $_variable); + + if (in_array($_variable, $_customs) && !empty($this->entity->{$var})) { + $elements[] = ['element' => 'div', 'properties' => ['style' => "display: table-row; visibility: {$this->entityVariableCheck($_variable)};"],'elements' => [ + ['element' => 'div', 'content' => $variable . '_label', 'properties' => ['style' => 'display: table-cell;', 'data-ref' => 'entity_details-' . substr($variable, 1) . '_label']], + ['element' => 'div', 'content' => $variable, 'properties' => ['style' => 'display: table-cell;', 'data-ref' => 'entity_details-' . substr($variable, 1)]], + ]]; + } else { + $elements[] = ['element' => 'div', 'properties' => ['style' => "display: table-row; visibility: {$this->entityVariableCheck($variable)};"], 'elements' => [ + ['element' => 'span', 'content' => $variable . '_label', 'properties' => ['style' => 'display: table-cell;','data-ref' => 'entity_details-' . substr($variable, 1) . '_label']], + ['element' => 'span', 'content' => $variable, 'properties' => ['style' => 'display: table-cell;','data-ref' => 'entity_details-' . substr($variable, 1)]], + ]]; + } + } + + return $elements; + + } + + public function entityDetailsx(): array + { + + if ($this->type === 'statement') { // $s_date = $this->translateDate(now(), $this->client->date_format(), $this->client->locale()); diff --git a/app/Services/PdfMaker/Designs/Utilities/DesignHelpers.php b/app/Services/PdfMaker/Designs/Utilities/DesignHelpers.php index b6393f5635..7f8c5f57ad 100644 --- a/app/Services/PdfMaker/Designs/Utilities/DesignHelpers.php +++ b/app/Services/PdfMaker/Designs/Utilities/DesignHelpers.php @@ -246,14 +246,14 @@ trait DesignHelpers ]]; } - public function entityVariableCheck(string $variable): bool + public function entityVariableCheck(string $variable): string { // Extract $invoice.date => date // so we can append date as $entity->date and not $entity->$invoice.date; // When it comes to invoice balance, we'll always show it. if ($variable == '$invoice.total') { - return false; + return 'visible'; } // Some variables don't map 1:1 to table columns. This gives us support for such cases. @@ -272,14 +272,14 @@ trait DesignHelpers } if (is_null($this->entity->{$_variable})) { - return true; + return 'collapse'; } if (empty($this->entity->{$_variable})) { - return true; + return 'collapse'; } - return false; + return 'visible'; } public function composeFromPartials(array $partials) diff --git a/resources/views/pdf-designs/clean.html b/resources/views/pdf-designs/clean.html index 29b5e567ca..a26b77b556 100644 --- a/resources/views/pdf-designs/clean.html +++ b/resources/views/pdf-designs/clean.html @@ -34,6 +34,11 @@ padding: 0; } + span { + margin-left:2px; + margin-right:2px; + } + #qr-bill { width:100% !important; box-sizing: border-box; @@ -83,14 +88,18 @@ .client-and-entity-wrapper { display: flex; - padding: 1rem; + padding: 0.2rem; border-top: 1px solid #d8d8d8; border-bottom: 1px solid #d8d8d8; } #entity-details { - text-align: left; - margin-right: 20px; + display: flex; + flex-direction: column; + line-height: var(--line-height); + padding-right: 5px; + white-space: nowrap; + margin-right: auto; } #entity-details > tr, @@ -105,12 +114,15 @@ display: flex; flex-direction: column; line-height: var(--line-height); + margin-right: auto; } #shipping-details { display: flex; + float:right; flex-direction: column; line-height: var(--line-height); + margin-right: auto; } #client-details > :first-child { @@ -360,8 +372,7 @@

$entity_label

-
-
+