mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-05 18:52:44 +01:00
Refactor invoice-table for simple model bind & support for gateway-fees
This commit is contained in:
parent
1f77b87331
commit
1bbf7392ad
@ -20,39 +20,37 @@ class InvoicesTable extends Component
|
||||
|
||||
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()
|
||||
{
|
||||
$local_status = [];
|
||||
|
||||
$query = Invoice::query()
|
||||
->orderBy($this->sort_field, $this->sort_asc ? 'asc' : 'desc');
|
||||
|
||||
if (in_array('paid', $this->status)) {
|
||||
$query = $query->orWhere('status_id', Invoice::STATUS_PAID);
|
||||
$local_status[] = Invoice::STATUS_PAID;
|
||||
}
|
||||
|
||||
if (in_array('unpaid', $this->status)) {
|
||||
$query = $query->orWhereIn('status_id', [Invoice::STATUS_SENT, Invoice::STATUS_PARTIAL]);
|
||||
}
|
||||
|
||||
if (in_array('gateway-fees', $this->status)) {
|
||||
$query = $query->orWhere('status_id', Invoice::STATUS_PAID); // Update this to correct status id (4).
|
||||
$local_status[] = Invoice::STATUS_SENT;
|
||||
$local_status[] = Invoice::STATUS_PARTIAL;
|
||||
}
|
||||
|
||||
if (in_array('overdue', $this->status)) {
|
||||
$query = $query->orWhereIn('status_id', [Invoice::STATUS_SENT, Invoice::STATUS_PARTIAL])
|
||||
->where(function ($query) {
|
||||
$query
|
||||
->orWhere('due_date', '<', Carbon::now())
|
||||
->orWhere('partial_due_date', '<', Carbon::now());
|
||||
});
|
||||
$local_status[] = Invoice::STATUS_SENT;
|
||||
$local_status[] = Invoice::STATUS_PARTIAL;
|
||||
}
|
||||
|
||||
if (count($local_status) > 0) {
|
||||
$query = $query->whereIn('status_id', array_unique($local_status));
|
||||
}
|
||||
|
||||
if (in_array('overdue', $this->status)) {
|
||||
$query = $query->where(function ($query) {
|
||||
$query
|
||||
->orWhere('due_date', '<', Carbon::now())
|
||||
->orWhere('partial_due_date', '<', Carbon::now());
|
||||
});
|
||||
}
|
||||
|
||||
$query = $query
|
||||
@ -60,6 +58,27 @@ class InvoicesTable extends Component
|
||||
->where('status_id', '<>', Invoice::STATUS_DRAFT)
|
||||
->paginate($this->per_page);
|
||||
|
||||
if (in_array('gateway_fees', $this->status)) {
|
||||
$transformed = $query
|
||||
->getCollection()
|
||||
->filter(function ($invoice) {
|
||||
$invoice['line_items'] = collect($invoice->line_items)
|
||||
->filter(function ($item) {
|
||||
return $item->type_id == "4" || $item->type_id == 4;
|
||||
});
|
||||
|
||||
return count($invoice['line_items']);
|
||||
});
|
||||
|
||||
$query = new \Illuminate\Pagination\LengthAwarePaginator(
|
||||
$transformed,
|
||||
$transformed->count(),
|
||||
$query->perPage(),
|
||||
$query->currentPage(),
|
||||
['path' => request()->url(), 'query' => ['page' => $query->currentPage()]]
|
||||
);
|
||||
}
|
||||
|
||||
return render('components.livewire.invoices-table', [
|
||||
'invoices' => $query,
|
||||
]);
|
||||
|
@ -11,19 +11,19 @@
|
||||
</div>
|
||||
<div class="flex items-center">
|
||||
<div class="mr-3">
|
||||
<input wire:click="statusChange('paid')" type="checkbox" class="cursor-pointer form-checkbox" id="paid-checkbox">
|
||||
<input wire:model="status" value="paid" type="checkbox" class="cursor-pointer form-checkbox" id="paid-checkbox">
|
||||
<label for="paid-checkbox" class="text-sm cursor-pointer">{{ ctrans('texts.status_paid') }}</label>
|
||||
</div>
|
||||
<div class="mr-3">
|
||||
<input wire:click="statusChange('unpaid')" type="checkbox" class="cursor-pointer form-checkbox" id="unpaid-checkbox">
|
||||
<input wire:model="status" value="unpaid" type="checkbox" class="cursor-pointer form-checkbox" id="unpaid-checkbox">
|
||||
<label for="unpaid-checkbox" class="text-sm cursor-pointer">{{ ctrans('texts.status_unpaid') }}</label>
|
||||
</div>
|
||||
<div class="mr-3">
|
||||
<input wire:click="statusChange('overdue')" type="checkbox" class="cursor-pointer form-checkbox" id="overdue-checkbox">
|
||||
<input wire:model="status" value="overdue" type="checkbox" class="cursor-pointer form-checkbox" id="overdue-checkbox">
|
||||
<label for="overdue-checkbox" class="text-sm cursor-pointer">{{ ctrans('texts.overdue') }}</label>
|
||||
</div>
|
||||
<div class="mr-3">
|
||||
<input wire:click="statusChange('gateway-fees')" type="checkbox" class="cursor-pointer form-checkbox" id="gateway-fees-checkbox">
|
||||
<input wire:model="status" value="gateway_fees" type="checkbox" class="cursor-pointer form-checkbox" id="gateway-fees-checkbox">
|
||||
<label for="gateway-fees-checkbox" class="text-sm cursor-pointer">{{ ctrans('texts.gateway_fees') }}</label>
|
||||
</div>
|
||||
</div>
|
||||
|
Loading…
Reference in New Issue
Block a user