invoiceninja/app/Http/Livewire/RecurringInvoicesTable.php

58 lines
1.4 KiB
PHP
Raw Normal View History

<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
2022-04-27 13:20:41 +10:00
* @copyright Copyright (c) 2022. Invoice Ninja LLC (https://invoiceninja.com)
*
2021-06-16 16:58:16 +10:00
* @license https://www.elastic.co/licensing/elastic-license
*/
namespace App\Http\Livewire;
2021-07-04 07:46:25 +10:00
use App\Libraries\MultiDB;
use App\Models\RecurringInvoice;
use App\Utils\Traits\WithSorting;
use Livewire\Component;
use Livewire\WithPagination;
class RecurringInvoicesTable extends Component
{
use WithPagination, WithSorting;
public $per_page = 10;
2021-07-04 07:46:25 +10:00
public $company;
2021-04-19 16:57:25 +02:00
public function mount()
{
2021-07-04 07:46:25 +10:00
MultiDB::setDb($this->company->db);
2021-04-19 16:57:25 +02:00
$this->sort_asc = false;
$this->sort_field = 'date';
}
public function render()
{
$query = RecurringInvoice::query();
$query = $query
2022-09-16 14:20:46 +10:00
->where('client_id', auth()->guard('contact')->user()->client_id)
2021-07-04 07:46:25 +10:00
->where('company_id', $this->company->id)
2021-11-10 15:16:56 +11:00
->whereIn('status_id', [RecurringInvoice::STATUS_ACTIVE])
->orderBy('status_id', 'asc')
->with('client')
->orderBy($this->sort_field, $this->sort_asc ? 'asc' : 'desc')
2021-09-10 21:47:28 +02:00
->withTrashed()
->where('is_deleted', false)
->paginate($this->per_page);
return render('components.livewire.recurring-invoices-table', [
'invoices' => $query,
]);
}
}