diff --git a/app/DataMapper/CompanySettings.php b/app/DataMapper/CompanySettings.php index a45639f65f0b..a8db721b733d 100644 --- a/app/DataMapper/CompanySettings.php +++ b/app/DataMapper/CompanySettings.php @@ -693,13 +693,13 @@ class CompanySettings extends BaseSettings '$invoice.date', '$due_date', '$total', - '$outstanding', + '$amount', ], 'statement_payment_columns' => [ '$invoice.number', '$payment.date', '$method', - '$outstanding', + '$amount', ], ]; diff --git a/app/Http/Controllers/ClientStatementController.php b/app/Http/Controllers/ClientStatementController.php index 002aadd2b882..f0d2c018de57 100644 --- a/app/Http/Controllers/ClientStatementController.php +++ b/app/Http/Controllers/ClientStatementController.php @@ -110,10 +110,9 @@ class ClientStatementController extends BaseController public function statement(CreateStatementRequest $request) { - $pdf = $request->client()->service()->statement([ - 'start_date' => $request->start_date, - 'end_date' => $request->end_date, - ]); + $pdf = $request->client()->service()->statement( + $request->only(['start_date', 'end_date', 'show_payments_table', 'show_aging_table']) + ); if ($pdf) { return response()->streamDownload(function () use ($pdf) { diff --git a/app/Http/Requests/Statements/CreateStatementRequest.php b/app/Http/Requests/Statements/CreateStatementRequest.php index c4a2c31506ba..d887edfdd9e6 100644 --- a/app/Http/Requests/Statements/CreateStatementRequest.php +++ b/app/Http/Requests/Statements/CreateStatementRequest.php @@ -42,6 +42,11 @@ class CreateStatementRequest extends Request $input = $this->decodePrimaryKeys($input); $this->replace($input); + + $this->merge([ + 'show_payments_table' => $this->has('show_payments_table') ? \boolval($this->show_payments_table) : false, + 'show_aging_table' => $this->has('show_aging_table') ? \boolval($this->show_aging_table) : false, + ]); } public function client(): ?Client diff --git a/app/Services/Client/Statement.php b/app/Services/Client/Statement.php index 5d6d5a0e4376..e18f9707618a 100644 --- a/app/Services/Client/Statement.php +++ b/app/Services/Client/Statement.php @@ -221,6 +221,7 @@ class Statement ->where('client_id', $this->client->id) ->whereIn('status_id', [Invoice::STATUS_SENT, Invoice::STATUS_PARTIAL, Invoice::STATUS_PAID]) ->whereBetween('date', [$this->options['start_date'], $this->options['end_date']]) + ->orderBy('number', 'ASC') ->get(); } @@ -235,6 +236,7 @@ class Statement ->where('client_id', $this->client->id) ->whereIn('status_id', [Payment::STATUS_COMPLETED, Payment::STATUS_PARTIALLY_REFUNDED, Payment::STATUS_REFUNDED]) ->whereBetween('date', [$this->options['start_date'], $this->options['end_date']]) + ->orderBy('number', 'ASC') ->get(); } diff --git a/app/Services/PdfMaker/Design.php b/app/Services/PdfMaker/Design.php index 818307c806ef..a8d278f4985f 100644 --- a/app/Services/PdfMaker/Design.php +++ b/app/Services/PdfMaker/Design.php @@ -232,7 +232,7 @@ class Design extends BaseDesign ]], ['element' => 'tr', 'properties' => [], 'elements' => [ ['element' => 'th', 'properties' => [], 'content' => '$balance_due_label'], - ['element' => 'th', 'properties' => [], 'content' => '$balance_due'], + ['element' => 'th', 'properties' => [], 'content' => Number::formatMoney($this->invoices->sum('balance'), $this->entity->client)], ]], ]; } @@ -379,10 +379,10 @@ class Design extends BaseDesign return []; } - $outstanding = $this->invoices->sum('amount'); + $outstanding = $this->invoices->sum('balance'); return [ - ['element' => 'p', 'content' => '$outstanding_label: $outstanding'], + ['element' => 'p', 'content' => '$outstanding_label: ' . Number::formatMoney($outstanding, $this->entity->client)], ]; } @@ -424,10 +424,14 @@ class Design extends BaseDesign public function statementPaymentTableTotals(): array { - if ($this->type !== self::STATEMENT || !$this->payments->first()) { + if (is_null($this->payments) && $this->type !== self::STATEMENT) { return []; } + if (\array_key_exists('show_payments_table', $this->options) && $this->options['show_payments_table'] === false) { + return []; + } + $payment = $this->payments->first(); return [ diff --git a/app/Services/PdfMaker/PdfMaker.php b/app/Services/PdfMaker/PdfMaker.php index aad88b9e37fb..2f50f9882ddb 100644 --- a/app/Services/PdfMaker/PdfMaker.php +++ b/app/Services/PdfMaker/PdfMaker.php @@ -83,9 +83,9 @@ class PdfMaker } /** - * Return compiled HTML. + * Final method to get compiled HTML. * - * @param bool $final deprecated + * @param bool $final @deprecated * @return mixed */ public function getCompiledHTML($final = false) diff --git a/app/Utils/HtmlEngine.php b/app/Utils/HtmlEngine.php index a678ce62721e..991a0895e8e2 100644 --- a/app/Utils/HtmlEngine.php +++ b/app/Utils/HtmlEngine.php @@ -453,6 +453,9 @@ class HtmlEngine $data['$payment.date'] = ['value' => ' ', 'label' => ctrans('texts.payment_date')]; $data['$method'] = ['value' => ' ', 'label' => ctrans('texts.method')]; + $data['$amount'] = ['value' => '', 'label' => ctrans('texts.amount')]; + $data['$statement'] = ['value' => '', 'label' => ctrans('texts.statement')]; + $arrKeysLength = array_map('strlen', array_keys($data)); array_multisort($arrKeysLength, SORT_DESC, $data); diff --git a/database/migrations/2021_09_08_115919_update_designs.php b/database/migrations/2021_09_16_115919_update_designs.php similarity index 100% rename from database/migrations/2021_09_08_115919_update_designs.php rename to database/migrations/2021_09_16_115919_update_designs.php diff --git a/resources/views/pdf-designs/bold.html b/resources/views/pdf-designs/bold.html index 689c6cbb06a0..6b98d8824369 100644 --- a/resources/views/pdf-designs/bold.html +++ b/resources/views/pdf-designs/bold.html @@ -257,6 +257,11 @@ max-height: 160px; } + #statement-invoice-table-totals > p { + margin-right: 2rem; + margin-top: 1rem; + } + /** Useful snippets, uncomment to enable. **/ /** Hide company logo **/ diff --git a/resources/views/pdf-designs/hipster.html b/resources/views/pdf-designs/hipster.html index 4180fceeaf9b..a2af152de09b 100644 --- a/resources/views/pdf-designs/hipster.html +++ b/resources/views/pdf-designs/hipster.html @@ -345,6 +345,12 @@ ? document.getElementById(tableIdentifier).style.display = 'none' : ''; }); + + // If we have elements in these tables, we can change label to "Statement" & hide entity details. + if (document.querySelectorAll('#statement-payment-table > tbody, #statement-payment-table > tbody, #statement-aging-table-totals > tbody').length > 0) { + document.querySelector('.entity-label').innerText = '$statement_label'; + document.querySelector('.entity-details-wrapper').style.display = 'none'; + } }); diff --git a/resources/views/pdf-designs/tech.html b/resources/views/pdf-designs/tech.html index b6d7c479dfe2..139eb8214825 100644 --- a/resources/views/pdf-designs/tech.html +++ b/resources/views/pdf-designs/tech.html @@ -54,8 +54,12 @@ height: 120px; } - .company-logo { - height: 100%; + .company-logo-wrapper { + padding-bottom: 60px; + } + + .company-logo-wrapper { + height: 5rem; } .header-invoice-number { @@ -266,8 +270,10 @@