From 9294e2c347d28f5f93e196ce943d63d88af47eaf Mon Sep 17 00:00:00 2001 From: David Bomba Date: Fri, 13 Oct 2023 13:43:59 +1100 Subject: [PATCH] Minor Fixes for templates --- app/Services/Client/Statement.php | 4 ++-- app/Services/Pdf/PdfMock.php | 25 +++++++++++++---------- app/Services/Template/TemplateService.php | 6 ++++++ lang/en/texts.php | 2 ++ 4 files changed, 24 insertions(+), 13 deletions(-) diff --git a/app/Services/Client/Statement.php b/app/Services/Client/Statement.php index 4cca2b8bb770..7bd42e14cef9 100644 --- a/app/Services/Client/Statement.php +++ b/app/Services/Client/Statement.php @@ -144,8 +144,8 @@ class Statement 'variables' => collect([$variables]), 'invoices' => $this->getInvoices()->get(), 'payments' => $this->options['show_payments_table'] ? $this->getPayments()->get() : collect([]), - 'credits' => $this->options['show_credits_table'] ? $this->getCredits()->get() : [], - 'aging' => $this->options['show_aging_table'] ? $this->getAging() : [], + 'credits' => $this->options['show_credits_table'] ? $this->getCredits()->get() : collect([]), + 'aging' => $this->options['show_aging_table'] ? $this->getAging() : collect([]), ]); $html = $ts->getHtml(); diff --git a/app/Services/Pdf/PdfMock.php b/app/Services/Pdf/PdfMock.php index c120168f2427..c7b98de46a71 100644 --- a/app/Services/Pdf/PdfMock.php +++ b/app/Services/Pdf/PdfMock.php @@ -195,7 +195,6 @@ class PdfMock { return ['values' => [ - '$client.shipping_postal_code' => '46420', '$client.billing_postal_code' => '11243', '$company.city_state_postal' => 'Beveley Hills, CA, 90210', @@ -496,6 +495,8 @@ class PdfMock '$show_shipping_address' => $this->settings->show_shipping_address ? 'flex' : 'none', '$show_shipping_address_block' => $this->settings->show_shipping_address ? 'block' : 'none', '$show_shipping_address_visibility' => $this->settings->show_shipping_address ? 'visible' : 'hidden', + '$start_date' => '31/01/2023', + '$end_date' => '31/12/2023', ], 'labels' => $this->mockTranslatedLabels(), ]; @@ -811,21 +812,23 @@ class PdfMock '$tax_label' => ctrans('texts.tax'), '$dir_label' => '', '$to_label' => ctrans('texts.to'), + '$start_date_label' => ctrans('texts.start_date'), + '$end_date_label' => ctrans('texts.end_date'), ]; } - + private function getVendorStubVariables() { return ['values' => [ - '$vendor.billing_postal_code' => '06270-5526', - '$company.postal_city_state' => '29359 New Loy, Delaware', - '$company.city_state_postal' => 'New Loy, Delaware 29359', - '$product.gross_line_total' => '', - '$purchase_order.po_number' => 'PO12345', - '$vendor.postal_city_state' => '06270-5526 Jameyhaven, West Virginia', - '$vendor.city_state_postal' => 'Jameyhaven, West Virginia 06270-5526', - '$purchase_order.due_date' => '02-12-2021', - '$vendor.billing_address1' => '589', + '$vendor.billing_postal_code' => '06270-5526', + '$company.postal_city_state' => '29359 New Loy, Delaware', + '$company.city_state_postal' => 'New Loy, Delaware 29359', + '$product.gross_line_total' => '', + '$purchase_order.po_number' => 'PO12345', + '$vendor.postal_city_state' => '06270-5526 Jameyhaven, West Virginia', + '$vendor.city_state_postal' => 'Jameyhaven, West Virginia 06270-5526', + '$purchase_order.due_date' => '02-12-2021', + '$vendor.billing_address1' => '589', '$vendor.billing_address2' => '761 Odessa Centers Suite 673', '$invoiceninja.whitelabel' => 'https://invoicing.co/images/new_logo.png', '$purchase_order.custom1' => 'Custom 1', diff --git a/app/Services/Template/TemplateService.php b/app/Services/Template/TemplateService.php index d7b0264e928a..8c4bd93b8ba3 100644 --- a/app/Services/Template/TemplateService.php +++ b/app/Services/Template/TemplateService.php @@ -84,6 +84,12 @@ class TemplateService }); $this->twig->addFunction($function); + $filter = new \Twig\TwigFilter('sum', function (array $array, string $column) { + return array_sum(array_column($array, $column)); + }); + + $this->twig->addFilter($filter); + return $this; } diff --git a/lang/en/texts.php b/lang/en/texts.php index aa407bc9b054..68ebe6f49f11 100644 --- a/lang/en/texts.php +++ b/lang/en/texts.php @@ -5163,6 +5163,8 @@ $LANG = array( 'click_or_drop_files_here' => 'Click or drop files here', 'payment_refund_receipt' => 'Payment Refund Receipt # :number', 'payment_receipt' => 'Payment Receipt # :number', + 'load_template_description' => 'The template will be applied to following:', + 'run_template' => 'Run template', ); return $LANG;