From 2709572276797cd30f78ffa7c744099d62aa0d65 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20Beganovi=C4=87?= Date: Mon, 23 Aug 2021 14:22:07 +0200 Subject: [PATCH] Support for payments on statement --- app/Services/PdfMaker/Design.php | 48 ++++++++++++++++++++++++++++++-- 1 file changed, 45 insertions(+), 3 deletions(-) diff --git a/app/Services/PdfMaker/Design.php b/app/Services/PdfMaker/Design.php index 9b4ca31d1da9..7fab4d4b089d 100644 --- a/app/Services/PdfMaker/Design.php +++ b/app/Services/PdfMaker/Design.php @@ -13,6 +13,9 @@ namespace App\Services\PdfMaker; use App\Models\Credit; +use App\Models\GatewayType; +use App\Models\Invoice; +use App\Models\Payment; use App\Models\Quote; use App\Services\PdfMaker\Designs\Utilities\BaseDesign; use App\Services\PdfMaker\Designs\Utilities\DesignHelpers; @@ -47,6 +50,9 @@ class Design extends BaseDesign /** @var Invoice[] */ public $invoices; + /** @var Payment[] */ + public $payments; + const BOLD = 'bold'; const BUSINESS = 'business'; const CLEAN = 'clean'; @@ -126,6 +132,10 @@ class Design extends BaseDesign 'id' => 'statement-invoice-table', 'elements' => $this->statementInvoiceTable(), ], + 'statement-payment-table' => [ + 'id' => 'statement-payment-table', + 'elements' => $this->statementPaymentTable(), + ], 'table-totals' => [ 'id' => 'table-totals', 'elements' => $this->tableTotals(), @@ -326,12 +336,12 @@ class Design extends BaseDesign */ public function statementInvoiceTable(): array { - $tbody = []; - - if (is_null($this->invoices)) { + if (is_null($this->invoices) || $this->type !== self::STATEMENT) { return []; } + $tbody = []; + foreach ($this->invoices as $invoice) { $element = ['element' => 'tr', 'elements' => []]; @@ -350,6 +360,38 @@ class Design extends BaseDesign ]; } + /** + * Parent method for building payments table within statement. + * + * @return array + */ + public function statementPaymentTable() + { + if (is_null($this->payments) || $this->type !== self::STATEMENT) { + return []; + } + + $tbody = []; + + foreach ($this->payments as $payment) { + foreach ($payment->invoices as $invoice) { + $element = ['element' => 'tr', 'elements' => []]; + + $element['elements'][] = ['element' => 'td', 'content' => $invoice->number]; + $element['elements'][] = ['element' => 'td', 'content' => $this->translateDate($payment->date, $payment->client->date_format(), $payment->client->locale()) ?: ' ']; + $element['elements'][] = ['element' => 'td', 'content' => GatewayType::getAlias($payment->gateway_type_id) ?: ' ']; + $element['elements'][] = ['element' => 'td', 'content' => Number::formatMoney($payment->partial, $payment->client) ?: ' ']; + + $tbody[] = $element; + } + } + + return [ + ['element' => 'thead', 'elements' => $this->buildTableHeader('statement_payment')], + ['element' => 'tbody', 'elements' => $tbody], + ]; + } + /** * Generate the structure of table headers. () *