1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 21:22:58 +01:00
invoiceninja/app/Livewire/CreditsTable.php

62 lines
1.5 KiB
PHP
Raw Normal View History

<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
2024-04-12 06:15:41 +02:00
* @copyright Copyright (c) 2024. Invoice Ninja LLC (https://invoiceninja.com)
*
2021-06-16 08:58:16 +02:00
* @license https://www.elastic.co/licensing/elastic-license
*/
2023-12-13 17:52:49 +01:00
namespace App\Livewire;
use App\Libraries\MultiDB;
2022-12-23 01:33:14 +01:00
use App\Models\Company;
use App\Models\Credit;
use App\Utils\Traits\WithSorting;
use Livewire\Component;
use Livewire\WithPagination;
class CreditsTable extends Component
{
use WithPagination;
use WithSorting;
2022-12-23 01:33:14 +01:00
public int $per_page = 10;
2022-12-23 01:33:14 +01:00
public Company $company;
public string $db;
public int $company_id;
public function mount()
{
2022-12-23 01:33:14 +01:00
MultiDB::setDb($this->db);
$this->company = Company::find($this->company_id);
}
public function render()
{
$query = Credit::query()
2021-07-03 23:46:25 +02:00
->where('company_id', $this->company->id)
2022-12-23 01:33:14 +01:00
->where('client_id', auth()->guard('contact')->user()->client_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)
->where(function ($query) {
2021-10-05 04:12:21 +02:00
$query->whereDate('due_date', '>=', now())
2021-12-11 21:55:35 +01:00
->orWhereNull('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,
]);
}
}