diff --git a/app/Filters/BankTransactionFilters.php b/app/Filters/BankTransactionFilters.php index f76cc81cfdb7..e7cff05feee9 100644 --- a/app/Filters/BankTransactionFilters.php +++ b/app/Filters/BankTransactionFilters.php @@ -55,6 +55,55 @@ class BankTransactionFilters extends QueryFilters } + +/** + * Filter based on client status. + * + * Statuses we need to handle + * - all + * - unmatched + * - matched + * - converted + * - deposits + * - withdrawals + * + * @return Builder + */ + public function client_status(string $value = '') :Builder + { + if (strlen($value) == 0) { + return $this->builder; + } + + $status_parameters = explode(',', $value); + + if (in_array('all', $status_parameters)) { + return $this->builder; + } + + if (in_array('unmatched', $status_parameters)) { + $this->builder->where('status_id', BankTransaction::STATUS_UNMATCHED); + } + + if (in_array('matched', $status_parameters)) { + $this->builder->where('status_id', BankTransaction::STATUS_MATCHED); + } + + if (in_array('converted', $status_parameters)) { + $this->builder->where('status_id', BankTransaction::STATUS_CONVERTED); + } + + if (in_array('deposits', $status_parameters)) { + $this->builder->where('base_type', 'CREDIT'); + } + + if (in_array('withdrawals', $status_parameters)) { + $this->builder->where('base_type', 'DEBIT'); + } + + return $this->builder; + } + /** * Filters the list based on the status * archived, active, deleted. diff --git a/app/Filters/ExpenseFilters.php b/app/Filters/ExpenseFilters.php index 174acff790af..d7e10ac0f4f1 100644 --- a/app/Filters/ExpenseFilters.php +++ b/app/Filters/ExpenseFilters.php @@ -44,6 +44,55 @@ class ExpenseFilters extends QueryFilters }); } + /** + * Filter based on client status. + * + * Statuses we need to handle + * - all + * - logged + * - pending + * - invoiced + * - paid + * - unpaid + * + * @return Builder + */ + public function client_status(string $value = '') :Builder + { + if (strlen($value) == 0) { + return $this->builder; + } + + $status_parameters = explode(',', $value); + + if (in_array('all', $status_parameters)) { + return $this->builder; + } + + if (in_array('logged', $status_parameters)) { + $this->builder->where('amount', '>', 0); + } + + if (in_array('pending', $status_parameters)) { + $this->builder->whereNull('invoice_id')->whereNotNull('payment_date'); + } + + if (in_array('invoiced', $status_parameters)) { + $this->builder->whereNotNull('invoice_id'); + } + + if (in_array('paid', $status_parameters)) { + $this->builder->whereNotNull('payment_date'); + } + + if (in_array('unpaid', $status_parameters)) { + $this->builder->whereNull('payment_date'); + } + + return $this->builder; + } + + /** * Filters the list based on the status * archived, active, deleted. diff --git a/app/Filters/PurchaseOrderFilters.php b/app/Filters/PurchaseOrderFilters.php index 3aa91958ef36..2d9f957d75f6 100644 --- a/app/Filters/PurchaseOrderFilters.php +++ b/app/Filters/PurchaseOrderFilters.php @@ -17,19 +17,20 @@ use Illuminate\Database\Eloquent\Builder; class PurchaseOrderFilters extends QueryFilters { + /** * Filter based on client status. * * Statuses we need to handle * - all - * - paid - * - unpaid - * - overdue - * - reversed + * - draft + * - sent + * - accepted + * - cancelled * * @return Builder */ - public function credit_status(string $value = '') :Builder + public function client_status(string $value = '') :Builder { if (strlen($value) == 0) { return $this->builder; @@ -45,16 +46,17 @@ class PurchaseOrderFilters extends QueryFilters $this->builder->where('status_id', PurchaseOrder::STATUS_DRAFT); } - if (in_array('partial', $status_parameters)) { - $this->builder->where('status_id', PurchaseOrder::STATUS_PARTIAL); + if (in_array('sent', $status_parameters)) { + $this->builder->where('status_id', PurchaseOrder::STATUS_SENT); } - if (in_array('applied', $status_parameters)) { - $this->builder->where('status_id', PurchaseOrder::STATUS_APPLIED); + if (in_array('accepted', $status_parameters)) { + $this->builder->where('status_id', PurchaseOrder::STATUS_ACCEPTED); } - //->where('due_date', '>', Carbon::now()) - //->orWhere('partial_due_date', '>', Carbon::now()); + if (in_array('cancelled', $status_parameters)) { + $this->builder->where('status_id', PurchaseOrder::STATUS_CANCELLED); + } return $this->builder; } diff --git a/app/Filters/TaskFilters.php b/app/Filters/TaskFilters.php index d0f7f2419c05..f8278f506043 100644 --- a/app/Filters/TaskFilters.php +++ b/app/Filters/TaskFilters.php @@ -41,6 +41,37 @@ class TaskFilters extends QueryFilters }); } + + /** + * Filter based on client status. + * + * Statuses we need to handle + * - all + * - invoiced + * + * @param string client_status The invoice status as seen by the client + * @return Builder + */ + public function client_status(string $value = '') :Builder + { + if (strlen($value) == 0) { + return $this->builder; + } + + $status_parameters = explode(',', $value); + + if (in_array('all', $status_parameters)) { + return $this->builder; + } + + if (in_array('invoiced', $status_parameters)) { + $this->builder->whereNotNull('invoice_id'); + } + + return $this->builder; + } + + /** * Filters the list based on the status * archived, active, deleted. diff --git a/app/Listeners/Invoice/InvoiceEmailFailedActivity.php b/app/Listeners/Invoice/InvoiceEmailFailedActivity.php index 122bdc972379..b46493528fb8 100644 --- a/app/Listeners/Invoice/InvoiceEmailFailedActivity.php +++ b/app/Listeners/Invoice/InvoiceEmailFailedActivity.php @@ -21,8 +21,6 @@ class InvoiceEmailFailedActivity implements ShouldQueue { protected $activity_repo; - public $delay = 5; - /** * Create the event listener. *