Support for payments on statement

This commit is contained in:
Benjamin Beganović 2021-08-23 14:22:07 +02:00
parent 9dc61da56e
commit 2709572276

View File

@ -13,6 +13,9 @@
namespace App\Services\PdfMaker; namespace App\Services\PdfMaker;
use App\Models\Credit; use App\Models\Credit;
use App\Models\GatewayType;
use App\Models\Invoice;
use App\Models\Payment;
use App\Models\Quote; use App\Models\Quote;
use App\Services\PdfMaker\Designs\Utilities\BaseDesign; use App\Services\PdfMaker\Designs\Utilities\BaseDesign;
use App\Services\PdfMaker\Designs\Utilities\DesignHelpers; use App\Services\PdfMaker\Designs\Utilities\DesignHelpers;
@ -47,6 +50,9 @@ class Design extends BaseDesign
/** @var Invoice[] */ /** @var Invoice[] */
public $invoices; public $invoices;
/** @var Payment[] */
public $payments;
const BOLD = 'bold'; const BOLD = 'bold';
const BUSINESS = 'business'; const BUSINESS = 'business';
const CLEAN = 'clean'; const CLEAN = 'clean';
@ -126,6 +132,10 @@ class Design extends BaseDesign
'id' => 'statement-invoice-table', 'id' => 'statement-invoice-table',
'elements' => $this->statementInvoiceTable(), 'elements' => $this->statementInvoiceTable(),
], ],
'statement-payment-table' => [
'id' => 'statement-payment-table',
'elements' => $this->statementPaymentTable(),
],
'table-totals' => [ 'table-totals' => [
'id' => 'table-totals', 'id' => 'table-totals',
'elements' => $this->tableTotals(), 'elements' => $this->tableTotals(),
@ -326,12 +336,12 @@ class Design extends BaseDesign
*/ */
public function statementInvoiceTable(): array public function statementInvoiceTable(): array
{ {
$tbody = []; if (is_null($this->invoices) || $this->type !== self::STATEMENT) {
if (is_null($this->invoices)) {
return []; return [];
} }
$tbody = [];
foreach ($this->invoices as $invoice) { foreach ($this->invoices as $invoice) {
$element = ['element' => 'tr', 'elements' => []]; $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. (<thead/>) * Generate the structure of table headers. (<thead/>)
* *