|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Livewire;
|
|
|
|
|
|
|
|
use App\Models\Order;
|
|
|
|
use Illuminate\Contracts\View\Factory;
|
|
|
|
use Illuminate\Foundation\Application;
|
|
|
|
use Illuminate\Support\Carbon;
|
|
|
|
use Illuminate\View\View;
|
|
|
|
use Livewire\Component;
|
|
|
|
use Livewire\WithPagination;
|
|
|
|
|
|
|
|
class OrdersTable extends Component
|
|
|
|
{
|
|
|
|
use WithPagination;
|
|
|
|
|
|
|
|
protected string $paginationTheme = 'bootstrap';
|
|
|
|
|
|
|
|
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
|
|
|
|
{
|
|
|
|
$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
|
|
|
|
{
|
|
|
|
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,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
}
|