Improve sort order in client portal tables

This commit is contained in:
David Bomba 2024-11-26 14:55:42 +11:00
parent 1d531023fe
commit 2b5728c6d0
5 changed files with 30 additions and 5 deletions

View File

@ -174,7 +174,7 @@ class PaymentController extends Controller
$payment_hash->payment_id = $payment->id;
$payment_hash->save();
}
$payment->type_id = PaymentType::CREDIT;
$payment = $payment->service()->applyCredits($payment_hash)->save();
/** @var \Illuminate\Database\Eloquent\Collection<\App\Models\Invoice> $invoices */

View File

@ -48,7 +48,13 @@ class CreditsTable extends Component
$query->whereDate('due_date', '>=', now())
->orWhereNull('due_date');
})
->orderBy($this->sort_field, $this->sort_asc ? 'asc' : 'desc')
// ->orderBy($this->sort_field, $this->sort_asc ? 'asc' : 'desc')
->when($this->sort_field == 'number', function ($q){
$q->orderByRaw("REGEXP_REPLACE(number,'[^0-9]+','')+0 " . ($this->sort_asc ? 'desc' : 'asc'));
})
->when($this->sort_field != 'number', function ($q){
$q->orderBy($this->sort_field, ($this->sort_asc ? 'desc' : 'asc'));
})
->withTrashed()
->paginate($this->per_page);

View File

@ -51,7 +51,13 @@ class InvoicesTable extends Component
->where('is_deleted', false)
->where('is_proforma', false)
->with('client.gateway_tokens', 'client.contacts')
->orderBy($this->sort_field, $this->sort_asc ? 'asc' : 'desc');
->when($this->sort_field == 'number', function ($q){
$q->orderByRaw("REGEXP_REPLACE(number,'[^0-9]+','')+0 " . ($this->sort_asc ? 'desc' : 'asc'));
})
->when($this->sort_field != 'number', function ($q){
$q->orderBy($this->sort_field, ($this->sort_asc ? 'desc' : 'asc'));
});
// ->orderBy($this->sort_field, $this->sort_asc ? 'asc' : 'desc');
if (in_array('paid', $this->status)) {
$local_status[] = Invoice::STATUS_PAID;

View File

@ -42,7 +42,13 @@ class PaymentsTable extends Component
->where('company_id', auth()->guard('contact')->user()->company_id)
->where('client_id', auth()->guard('contact')->user()->client_id)
->whereIn('status_id', [Payment::STATUS_FAILED, Payment::STATUS_COMPLETED, Payment::STATUS_PENDING, Payment::STATUS_REFUNDED, Payment::STATUS_PARTIALLY_REFUNDED])
->orderBy($this->sort_field, $this->sort_asc ? 'desc' : 'asc')
// ->orderBy($this->sort_field, $this->sort_asc ? 'desc' : 'asc')
->when($this->sort_field == 'number', function ($q){
$q->orderByRaw("REGEXP_REPLACE(number,'[^0-9]+','')+0 " . ($this->sort_asc ? 'desc' : 'asc'));
})
->when($this->sort_field != 'number', function ($q){
$q->orderBy($this->sort_field, ($this->sort_asc ? 'desc' : 'asc'));
})
->withTrashed()
->paginate($this->per_page);

View File

@ -53,7 +53,14 @@ class QuotesTable extends Component
{
$query = Quote::query()
->with('client.contacts', 'company')
->orderBy($this->sort, $this->sort_asc ? 'asc' : 'desc');
// ->orderBy($this->sort, $this->sort_asc ? 'asc' : 'desc');
->when($this->sort == 'number', function ($q){
$q->orderByRaw("REGEXP_REPLACE(number,'[^0-9]+','')+0 " . ($this->sort_asc ? 'desc' : 'asc'));
})
->when($this->sort != 'number', function ($q){
$q->orderBy($this->sort, ($this->sort_asc ? 'desc' : 'asc'));
});
if (count($this->status) > 0) {
/* Special filter for expired*/