From 375e6f1faf394cbbdabdaf0264e68f0c42122594 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Sun, 19 Dec 2021 15:58:59 +1100 Subject: [PATCH] Fixes for statements --- app/Console/Commands/CheckData.php | 16 ++++++++++++++++ app/Services/Client/Statement.php | 15 +++++++++------ app/Services/PdfMaker/Design.php | 4 ++-- 3 files changed, 27 insertions(+), 8 deletions(-) diff --git a/app/Console/Commands/CheckData.php b/app/Console/Commands/CheckData.php index 4189e0d8ca60..68ca30c41db4 100644 --- a/app/Console/Commands/CheckData.php +++ b/app/Console/Commands/CheckData.php @@ -949,3 +949,19 @@ ORDER BY clients.id; return $type.'s'; } } + + +/* query if we want to company company ledger to client balance + $results = \DB::select( \DB::raw(" + SELECT + clients.id as client_id, + clients.balance as client_balance + from clients, + (select max(company_ledgers.id) as cid, company_ledgers.client_id as client_id, company_ledgers.balance as balance + FROM company_ledgers) ledger + where clients.id=ledger.client_id + AND clients.balance != ledger.balance + GROUP BY clients.id + ORDER BY clients.id; + ") ); + */ \ No newline at end of file diff --git a/app/Services/Client/Statement.php b/app/Services/Client/Statement.php index 9a27def41654..0ff972eeca37 100644 --- a/app/Services/Client/Statement.php +++ b/app/Services/Client/Statement.php @@ -30,6 +30,7 @@ use App\Utils\PhantomJS\Phantom; use App\Utils\Traits\Pdf\PdfMaker as PdfMakerTrait; use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Collection; +use Illuminate\Support\Carbon; use Illuminate\Support\Facades\DB; use Illuminate\Support\LazyCollection; @@ -220,15 +221,16 @@ class Statement * * @return Invoice[]|\Illuminate\Database\Eloquent\Collection */ - protected function getInvoices(): Builder + protected function getInvoices(): \Illuminate\Support\LazyCollection { return Invoice::withTrashed() ->where('is_deleted', false) ->where('company_id', $this->client->company_id) ->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'); + ->whereBetween('date', [Carbon::parse($this->options['start_date']), Carbon::parse($this->options['end_date'])]) + ->orderBy('number', 'ASC') + ->cursor(); } /** @@ -236,7 +238,7 @@ class Statement * * @return Payment[]|\Illuminate\Database\Eloquent\Collection */ - protected function getPayments(): Builder + protected function getPayments(): \Illuminate\Support\LazyCollection { return Payment::withTrashed() ->with('client.country','invoices') @@ -244,8 +246,9 @@ class Statement ->where('company_id', $this->client->company_id) ->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'); + ->whereBetween('date', [Carbon::parse($this->options['start_date']), Carbon::parse($this->options['end_date'])]) + ->orderBy('number', 'ASC') + ->cursor(); } /** diff --git a/app/Services/PdfMaker/Design.php b/app/Services/PdfMaker/Design.php index fee18cd16cda..14053737b8b7 100644 --- a/app/Services/PdfMaker/Design.php +++ b/app/Services/PdfMaker/Design.php @@ -359,7 +359,7 @@ class Design extends BaseDesign $tbody = []; - foreach ($this->invoices->cursor() as $invoice) { + foreach ($this->invoices as $invoice) { $element = ['element' => 'tr', 'elements' => []]; $element['elements'][] = ['element' => 'td', 'content' => $invoice->number]; @@ -407,7 +407,7 @@ class Design extends BaseDesign $tbody = []; - foreach ($this->payments->cursor() as $payment) { + foreach ($this->payments as $payment) { foreach ($payment->invoices as $invoice) { $element = ['element' => 'tr', 'elements' => []];