Sort by status_id for quotes in client portal

This commit is contained in:
David Bomba 2022-08-19 15:11:48 +10:00
parent 86166802b0
commit 4460e970bd

View File

@ -20,7 +20,6 @@ use Livewire\WithPagination;
class QuotesTable extends Component class QuotesTable extends Component
{ {
use WithSorting;
use WithPagination; use WithPagination;
public $per_page = 10; public $per_page = 10;
@ -29,6 +28,19 @@ class QuotesTable extends Component
public $company; public $company;
public $sort_field = 'status_id'; // Default sortBy. Feel free to change or pull from client/company settings.
public $sort_asc = true;
public function sortBy($field)
{
$this->sort_field === $field
? $this->sort_asc = ! $this->sort_asc
: $this->sort_asc = true;
$this->sort_field = $field;
}
public function mount() public function mount()
{ {
MultiDB::setDb($this->company->db); MultiDB::setDb($this->company->db);
@ -36,6 +48,7 @@ class QuotesTable extends Component
public function render() public function render()
{ {
$query = Quote::query() $query = Quote::query()
->with('client.gateway_tokens', 'company', 'client.contacts') ->with('client.gateway_tokens', 'company', 'client.contacts')
->orderBy($this->sort_field, $this->sort_asc ? 'asc' : 'desc'); ->orderBy($this->sort_field, $this->sort_asc ? 'asc' : 'desc');
@ -44,7 +57,6 @@ class QuotesTable extends Component
/* Special filter for expired*/ /* Special filter for expired*/
if (in_array('-1', $this->status)) { if (in_array('-1', $this->status)) {
// $query->whereDate('due_date', '<=', now()->startOfDay());
$query->where(function ($query) { $query->where(function ($query) {
$query->whereDate('due_date', '<=', now()->startOfDay()) $query->whereDate('due_date', '<=', now()->startOfDay())
@ -69,10 +81,6 @@ class QuotesTable extends Component
->where('company_id', $this->company->id) ->where('company_id', $this->company->id)
->where('client_id', auth()->guard('contact')->user()->client->id) ->where('client_id', auth()->guard('contact')->user()->client->id)
->where('status_id', '<>', Quote::STATUS_DRAFT) ->where('status_id', '<>', Quote::STATUS_DRAFT)
// ->where(function ($query){
// $query->whereDate('due_date', '>=', now())
// ->orWhereNull('due_date');
// })
->where('is_deleted', 0) ->where('is_deleted', 0)
->withTrashed() ->withTrashed()
->paginate($this->per_page); ->paginate($this->per_page);