1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-06 11:12:43 +01:00
invoiceninja/app/Http/Livewire/InvoicesTable.php

72 lines
1.9 KiB
PHP
Raw Normal View History

<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://opensource.org/licenses/AAL
*/
namespace App\Http\Livewire;
use App\Models\Invoice;
use App\Utils\Traits\WithSorting;
use Carbon\Carbon;
use Livewire\Component;
use Livewire\WithPagination;
class InvoicesTable extends Component
{
use WithPagination, WithSorting;
public $per_page = 10;
public $status = [];
public function render()
{
$local_status = [];
$query = Invoice::query()
->orderBy($this->sort_field, $this->sort_asc ? 'asc' : 'desc');
if (in_array('paid', $this->status)) {
$local_status[] = Invoice::STATUS_PAID;
}
if (in_array('unpaid', $this->status)) {
$local_status[] = Invoice::STATUS_SENT;
$local_status[] = Invoice::STATUS_PARTIAL;
}
if (in_array('overdue', $this->status)) {
$local_status[] = Invoice::STATUS_SENT;
$local_status[] = Invoice::STATUS_PARTIAL;
}
if (count($local_status) > 0) {
$query = $query->whereIn('status_id', array_unique($local_status));
2020-09-02 22:08:12 +02:00
}
if (in_array('overdue', $this->status)) {
$query = $query->where(function ($query) {
$query
->orWhere('due_date', '<', Carbon::now())
->orWhere('partial_due_date', '<', Carbon::now());
});
}
2020-05-14 03:05:18 +02:00
$query = $query
->where('client_id', auth('contact')->user()->client->id)
2020-07-23 12:17:09 +02:00
->where('status_id', '<>', Invoice::STATUS_DRAFT)
2020-05-14 03:05:18 +02:00
->paginate($this->per_page);
return render('components.livewire.invoices-table', [
'invoices' => $query,
]);
}
}