1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-09-21 17:01:33 +02:00
invoiceninja/app/Http/Livewire/CreditsTable.php

57 lines
1.4 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)
*
2021-06-16 08:58:16 +02:00
* @license https://www.elastic.co/licensing/elastic-license
*/
namespace App\Http\Livewire;
use App\Libraries\MultiDB;
use App\Models\Credit;
use App\Utils\Traits\WithSorting;
use Livewire\Component;
use Livewire\WithPagination;
class CreditsTable extends Component
{
use WithPagination;
use WithSorting;
public $per_page = 10;
public $company;
public function mount()
{
MultiDB::setDb($this->company->db);
}
public function render()
{
2021-07-03 23:46:25 +02:00
$query = Credit::query()
2020-06-10 15:35:39 +02:00
->where('client_id', auth('contact')->user()->client->id)
2021-07-03 23:46:25 +02:00
->where('company_id', $this->company->id)
2021-02-11 14:14:11 +01:00
->where('status_id', '<>', Credit::STATUS_DRAFT)
2021-10-04 00:36:30 +02:00
->where('is_deleted', 0)
2021-07-03 23:46:25 +02:00
->where(function ($query){
2021-10-05 04:12:21 +02:00
$query->whereDate('due_date', '>=', now())
2021-10-05 04:49:15 +02:00
->orWhereNull('due_date')
->orWhere('due_date', '=', '');
2021-07-03 23:46:25 +02:00
})
->orderBy($this->sort_field, $this->sort_asc ? 'asc' : 'desc')
2021-09-10 21:48:09 +02:00
->withTrashed()
->paginate($this->per_page);
return render('components.livewire.credits-table', [
'credits' => $query,
]);
}
}