diff --git a/app/Http/Livewire/InvoicesTable.php b/app/Http/Livewire/InvoicesTable.php index 151dd575d9e2..ea0682d9d2c9 100644 --- a/app/Http/Livewire/InvoicesTable.php +++ b/app/Http/Livewire/InvoicesTable.php @@ -20,35 +20,37 @@ class InvoicesTable extends Component public $status = []; - public function statusChange($status) - { - if (in_array($status, $this->status)) { - return $this->status = array_diff($this->status, [$status]); - } - - array_push($this->status, $status); - } - public function render() { + $local_status = []; + $query = Invoice::query() ->orderBy($this->sort_field, $this->sort_asc ? 'asc' : 'desc'); if (in_array('paid', $this->status)) { - $query = $query->orWhere('status_id', Invoice::STATUS_PAID); + $local_status[] = Invoice::STATUS_PAID; } if (in_array('unpaid', $this->status)) { - $query = $query->orWhereIn('status_id', [Invoice::STATUS_SENT, Invoice::STATUS_PARTIAL]); + $local_status[] = Invoice::STATUS_SENT; + $local_status[] = Invoice::STATUS_PARTIAL; } if (in_array('overdue', $this->status)) { - $query = $query->orWhereIn('status_id', [Invoice::STATUS_SENT, Invoice::STATUS_PARTIAL]) - ->where(function ($query) { - $query - ->orWhere('due_date', '<', Carbon::now()) - ->orWhere('partial_due_date', '<', Carbon::now()); - }); + $local_status[] = Invoice::STATUS_SENT; + $local_status[] = Invoice::STATUS_PARTIAL; + } + + if (count($local_status) > 0) { + $query = $query->whereIn('status_id', array_unique($local_status)); + } + + if (in_array('overdue', $this->status)) { + $query = $query->where(function ($query) { + $query + ->orWhere('due_date', '<', Carbon::now()) + ->orWhere('partial_due_date', '<', Carbon::now()); + }); } $query = $query @@ -56,6 +58,27 @@ class InvoicesTable extends Component ->where('status_id', '<>', Invoice::STATUS_DRAFT) ->paginate($this->per_page); + if (in_array('gateway_fees', $this->status)) { + $transformed = $query + ->getCollection() + ->filter(function ($invoice) { + $invoice['line_items'] = collect($invoice->line_items) + ->filter(function ($item) { + return $item->type_id == "4" || $item->type_id == 4; + }); + + return count($invoice['line_items']); + }); + + $query = new \Illuminate\Pagination\LengthAwarePaginator( + $transformed, + $transformed->count(), + $query->perPage(), + $query->currentPage(), + ['path' => request()->url(), 'query' => ['page' => $query->currentPage()]] + ); + } + return render('components.livewire.invoices-table', [ 'invoices' => $query, ]); diff --git a/app/Http/Livewire/QuotesTable.php b/app/Http/Livewire/QuotesTable.php index 9bf687da3764..356e552a99d8 100644 --- a/app/Http/Livewire/QuotesTable.php +++ b/app/Http/Livewire/QuotesTable.php @@ -4,6 +4,7 @@ namespace App\Http\Livewire; use App\Models\Quote; use App\Utils\Traits\WithSorting; +use Illuminate\Support\Facades\DB; use Livewire\Component; use Livewire\WithPagination; @@ -15,34 +16,13 @@ class QuotesTable extends Component public $per_page = 10; public $status = []; - public function statusChange($status) - { - if (in_array($status, $this->status)) { - return $this->status = array_diff($this->status, [$status]); - } - - array_push($this->status, $status); - } - public function render() { $query = Quote::query() ->orderBy($this->sort_field, $this->sort_asc ? 'asc' : 'desc'); - if (in_array('draft', $this->status)) { - $query = $query->orWhere('status_id', Quote::STATUS_DRAFT); - } - - if (in_array('sent', $this->status)) { - $query = $query->orWhere('status_id', Quote::STATUS_SENT); - } - - if (in_array('approved', $this->status)) { - $query = $query->orWhere('status_id', Quote::STATUS_APPROVED); - } - - if (in_array('expired', $this->status)) { - $query = $query->orWhere('status_id', Quote::STATUS_EXPIRED); + if (count($this->status) > 0) { + $query = $query->whereIn('status_id', $this->status); } $query = $query diff --git a/resources/views/portal/ninja2020/components/livewire/invoices-table.blade.php b/resources/views/portal/ninja2020/components/livewire/invoices-table.blade.php index a70383ec8993..55c4634feb18 100644 --- a/resources/views/portal/ninja2020/components/livewire/invoices-table.blade.php +++ b/resources/views/portal/ninja2020/components/livewire/invoices-table.blade.php @@ -1,8 +1,8 @@
- - @@ -11,50 +11,54 @@
- +
- +
- +
+
+ + +
-
-
- +
+
+
- - - - - - @forelse($invoices as $invoice) - - - - - - - @empty - @@ -112,9 +116,9 @@
+ + {{ ctrans('texts.invoice_number') }} + {{ ctrans('texts.invoice_date') }} + {{ ctrans('texts.balance') }} + {{ ctrans('texts.due_date') }} + {{ ctrans('texts.status') }} @@ -65,33 +69,33 @@
+ + {{ $invoice->number }} + {{ $invoice->formatDate($invoice->date, $invoice->client->date_format()) }} + {{ App\Utils\Number::formatMoney($invoice->balance, $invoice->client) }} + {{ $invoice->formatDate($invoice->due_date, $invoice->client->date_format()) }} + {!! App\Models\Invoice::badgeForStatus($invoice->status) !!} + @if($invoice->isPayable())
@csrf -
@@ -103,7 +107,7 @@
+ {{ ctrans('texts.no_results') }}
-
+
@if($invoices->total() > 0) -
- +
- +
- +
- +