company->db); $this->sort_asc = false; $this->sort_field = 'date'; } public function render() { $local_status = []; $query = PurchaseOrder::query() ->with('vendor.contacts') ->orderBy($this->sort_field, $this->sort_asc ? 'asc' : 'desc') ->where('company_id', $this->company->id) ->where('is_deleted', false); // if (in_array('paid', $this->status)) { // $local_status[] = Invoice::STATUS_PAID; // } // if (in_array('unpaid', $this->status)) { // $local_status[] = Invoice::STATUS_SENT; // $local_status[] = Invoice::STATUS_PARTIAL; // } // if (in_array('overdue', $this->status)) { // $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 ->where('vendor_id', auth()->guard('vendor')->user()->vendor_id) // ->where('status_id', '<>', Invoice::STATUS_DRAFT) // ->where('status_id', '<>', Invoice::STATUS_CANCELLED) ->withTrashed() ->paginate($this->per_page); return render('components.livewire.purchase-orders-table', [ 'purchase_orders' => $query ]); } }