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

Refactor quotes-table for simple model bind

This commit is contained in:
Benjamin Beganović 2020-09-03 11:14:24 +02:00
parent 60ae138e11
commit 1f77b87331
2 changed files with 7 additions and 27 deletions

View File

@ -4,6 +4,7 @@ namespace App\Http\Livewire;
use App\Models\Quote;
use App\Utils\Traits\WithSorting;
use Illuminate\Support\Facades\DB;
use Livewire\Component;
use Livewire\WithPagination;
@ -15,34 +16,13 @@ class QuotesTable extends Component
public $per_page = 10;
public $status = [];
public function statusChange($status)
{
if (in_array($status, $this->status)) {
return $this->status = array_diff($this->status, [$status]);
}
array_push($this->status, $status);
}
public function render()
{
$query = Quote::query()
->orderBy($this->sort_field, $this->sort_asc ? 'asc' : 'desc');
if (in_array('draft', $this->status)) {
$query = $query->orWhere('status_id', Quote::STATUS_DRAFT);
}
if (in_array('sent', $this->status)) {
$query = $query->orWhere('status_id', Quote::STATUS_SENT);
}
if (in_array('approved', $this->status)) {
$query = $query->orWhere('status_id', Quote::STATUS_APPROVED);
}
if (in_array('expired', $this->status)) {
$query = $query->orWhere('status_id', Quote::STATUS_EXPIRED);
if (count($this->status) > 0) {
$query = $query->whereIn('status_id', $this->status);
}
$query = $query

View File

@ -11,19 +11,19 @@
</div>
<div class="flex items-center">
<div class="mr-3">
<input wire:click="statusChange('draft')" type="checkbox" class="cursor-pointer form-checkbox" id="draft-checkbox">
<input wire:model="status" value="{{ App\Models\Quote::STATUS_DRAFT }}" type="checkbox" class="cursor-pointer form-checkbox" id="draft-checkbox">
<label for="draft-checkbox" class="text-sm cursor-pointer">{{ ctrans('texts.status_draft') }}</label>
</div>
<div class="mr-3">
<input wire:click="statusChange('sent')" value="sent" type="checkbox" class="cursor-pointer form-checkbox" id="sent-checkbox">
<input wire:model="status" value="{{ App\Models\Quote::STATUS_SENT }}" value="sent" type="checkbox" class="cursor-pointer form-checkbox" id="sent-checkbox">
<label for="sent-checkbox" class="text-sm cursor-pointer">{{ ctrans('texts.status_pending') }}</label>
</div>
<div class="mr-3">
<input wire:click="statusChange('approved')" value="approved" type="checkbox" class="cursor-pointer form-checkbox" id="approved-checkbox">
<input wire:model="status" value="{{ App\Models\Quote::STATUS_APPROVED }}" value="approved" type="checkbox" class="cursor-pointer form-checkbox" id="approved-checkbox">
<label for="approved-checkbox" class="text-sm cursor-pointer">{{ ctrans('texts.approved') }}</label>
</div>
<div class="mr-3">
<input wire:click="statusChange('expired')" value="expired" type="checkbox" class="cursor-pointer form-checkbox" id="expired-checkbox">
<input wire:model="status" value="{{ App\Models\Quote::STATUS_EXPIRED }}" value="expired" type="checkbox" class="cursor-pointer form-checkbox" id="expired-checkbox">
<label for="expired-checkbox" class="text-sm cursor-pointer">{{ ctrans('texts.expired') }}</label>
</div>
</div>