diff --git a/app/Services/Client/Statement.php b/app/Services/Client/Statement.php index 1c26d19324d4..daafb5bb4973 100644 --- a/app/Services/Client/Statement.php +++ b/app/Services/Client/Statement.php @@ -28,6 +28,7 @@ use App\Utils\Ninja; use App\Utils\Number; 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\Facades\DB; use Illuminate\Support\LazyCollection; @@ -123,7 +124,7 @@ class Statement */ protected function setupEntity(): self { - if (count($this->getInvoices()) >= 1) { + if ($this->getInvoices()->count() >= 1) { $this->entity = $this->getInvoices()->first(); } @@ -218,7 +219,7 @@ class Statement * * @return Invoice[]|\Illuminate\Database\Eloquent\Collection */ - protected function getInvoices(): LazyCollection + protected function getInvoices(): Builder { return Invoice::withTrashed() ->where('is_deleted', false) @@ -226,8 +227,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') - ->cursor(); + ->orderBy('number', 'ASC'); } /** @@ -235,7 +235,7 @@ class Statement * * @return Payment[]|\Illuminate\Database\Eloquent\Collection */ - protected function getPayments(): LazyCollection + protected function getPayments(): Builder { return Payment::withTrashed() ->with('client.country','invoices') @@ -244,8 +244,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') - ->cursor(); + ->orderBy('number', 'ASC'); } /** diff --git a/app/Services/PdfMaker/Design.php b/app/Services/PdfMaker/Design.php index eb858b225248..8416ae729f47 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 as $invoice) { + foreach ($this->invoices->cursor() 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 as $payment) { + foreach ($this->payments->cursor() as $payment) { foreach ($payment->invoices as $invoice) { $element = ['element' => 'tr', 'elements' => []]; diff --git a/app/Services/PdfMaker/Designs/Utilities/DesignHelpers.php b/app/Services/PdfMaker/Designs/Utilities/DesignHelpers.php index dd04ead2ed3a..82bbc3db684f 100644 --- a/app/Services/PdfMaker/Designs/Utilities/DesignHelpers.php +++ b/app/Services/PdfMaker/Designs/Utilities/DesignHelpers.php @@ -41,7 +41,7 @@ trait DesignHelpers if (isset($this->context['invoices'])) { $this->invoices = $this->context['invoices']; - if (\count($this->invoices) >= 1) { + if ($this->invoices->count() >= 1) { $this->entity = $this->invoices->first(); } }