You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
topnotch_website/app/Livewire/OrdersTable.php

65 lines
2.3 KiB
PHTML

3 months ago
<?php
namespace App\Livewire;
use App\Models\Order;
use Illuminate\Contracts\View\Factory;
use Illuminate\Foundation\Application;
3 months ago
use Illuminate\Support\Carbon;
use Illuminate\View\View;
3 months ago
use Livewire\Component;
use Livewire\WithPagination;
class OrdersTable extends Component
{
use WithPagination;
protected string $paginationTheme = 'bootstrap';
3 months ago
public bool $showCustomerColumn;
public string $orderType = 'active';
public string $search = '';
public string $title = '';
public string $customer_id = '';
public Carbon $today;
public function mount(bool $showCustomerColumn, string $orderType, string $title, ?string $customer_id = null): void
3 months ago
{
$this->today = Carbon::today();
$this->showCustomerColumn = $showCustomerColumn;
$this->orderType = $orderType;
$this->title = $title;
$this->customer_id = $customer_id ?? '';
}
public function render(): \Illuminate\Contracts\View\View|Factory|Application|View
3 months ago
{
return view('livewire.orders-table', [
'orders' => Order::with('customer')
->when($this->customer_id != null, fn ($q) => $q->where('customer_id', $this->customer_id))
->when($this->orderType === 'active', fn ($q) => $q->active())
->when($this->orderType === 'invoiced', fn ($q) => $q->invoiced())
->when($this->orderType === 'finished', fn ($q) => $q->finished())
->when($this->search !== '', function ($query) {
$query->whereHas('customer', function ($query) {
$query->where('company_name', 'like', '%'.$this->search.'%');
})->orWhere('customer_po', 'like', '%'.$this->search.'%')
->orWhere('internal_po', 'like', '%'.$this->search.'%')
->orWhere('order_date', 'like', '%'.$this->search.'%')
->orWhere('due_date', 'like', '%'.$this->search.'%')
->orWhere('status', 'like', '%'.$this->search.'%');
})
->orderByDesc('rush')
->orderBy('due_date')
->paginate(15)
->withQueryString(),
'today' => $this->today,
]);
}
}