Refactor quote filters

This commit is contained in:
David Bomba 2022-12-21 22:08:00 +11:00
parent fbb137b357
commit 7290fcd05a
3 changed files with 22 additions and 9 deletions

View File

@ -78,6 +78,7 @@ class BankTransactionFilters extends QueryFilters
$status_parameters = explode(',', $value); $status_parameters = explode(',', $value);
$status_array = []; $status_array = [];
$debit_or_withdrawal_array = []; $debit_or_withdrawal_array = [];
if (in_array('all', $status_parameters)) { if (in_array('all', $status_parameters)) {

View File

@ -42,20 +42,26 @@ class PurchaseOrderFilters extends QueryFilters
return $this->builder; return $this->builder;
} }
$po_status = [];
if (in_array('draft', $status_parameters)) { if (in_array('draft', $status_parameters)) {
$this->builder->where('status_id', PurchaseOrder::STATUS_DRAFT); $po_status[] = PurchaseOrder::STATUS_DRAFT;
} }
if (in_array('sent', $status_parameters)) { if (in_array('sent', $status_parameters)) {
$this->builder->where('status_id', PurchaseOrder::STATUS_SENT); $po_status[] = PurchaseOrder::STATUS_SENT;
} }
if (in_array('accepted', $status_parameters)) { if (in_array('accepted', $status_parameters)) {
$this->builder->where('status_id', PurchaseOrder::STATUS_ACCEPTED); $po_status[] = PurchaseOrder::STATUS_ACCEPTED;
} }
if (in_array('cancelled', $status_parameters)) { if (in_array('cancelled', $status_parameters)) {
$this->builder->where('status_id', PurchaseOrder::STATUS_CANCELLED); $po_status[] = PurchaseOrder::STATUS_CANCELLED;
}
if(count($status_parameters) >=1) {
$this->builder->whereIn('status_id', $status_parameters);
} }
return $this->builder; return $this->builder;

View File

@ -66,25 +66,31 @@ class QuoteFilters extends QueryFilters
return $this->builder; return $this->builder;
} }
$quote_filters = [];
if (in_array('draft', $status_parameters)) { if (in_array('draft', $status_parameters)) {
$this->builder->where('status_id', Quote::STATUS_DRAFT); $quote_filters[] = Quote::STATUS_DRAFT;
} }
if (in_array('sent', $status_parameters)) { if (in_array('sent', $status_parameters)) {
$this->builder->where('status_id', Quote::STATUS_SENT); $quote_filters[] = Quote::STATUS_SENT;
} }
if (in_array('approved', $status_parameters)) { if (in_array('approved', $status_parameters)) {
$this->builder->where('status_id', Quote::STATUS_APPROVED); $quote_filters[] = Quote::STATUS_APPROVED;
}
if(count($quote_filters) >=1){
$this->builder->whereIn('status_id', $quote_filters);
} }
if (in_array('expired', $status_parameters)) { if (in_array('expired', $status_parameters)) {
$this->builder->where('status_id', Quote::STATUS_SENT) $this->builder->orWhere('status_id', Quote::STATUS_SENT)
->where('due_date', '>=', now()->toDateString()); ->where('due_date', '>=', now()->toDateString());
} }
if (in_array('upcoming', $status_parameters)) { if (in_array('upcoming', $status_parameters)) {
$this->builder->where('status_id', Quote::STATUS_SENT) $this->builder->orWhere('status_id', Quote::STATUS_SENT)
->where('due_date', '<=', now()->toDateString()) ->where('due_date', '<=', now()->toDateString())
->orderBy('due_date', 'DESC'); ->orderBy('due_date', 'DESC');
} }