From d28fe81c51572227c91254394b65e4b3458512d1 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Thu, 4 Apr 2019 12:38:39 +1100 Subject: [PATCH] Invoice Item Factory --- app/Factory/InvoiceItemFactory.php | 27 +++++++ app/Filters/InvoiceFilters.php | 111 +++++++++++++++++++++++++++++ 2 files changed, 138 insertions(+) create mode 100644 app/Factory/InvoiceItemFactory.php create mode 100644 app/Filters/InvoiceFilters.php diff --git a/app/Factory/InvoiceItemFactory.php b/app/Factory/InvoiceItemFactory.php new file mode 100644 index 000000000000..d0fb921441e7 --- /dev/null +++ b/app/Factory/InvoiceItemFactory.php @@ -0,0 +1,27 @@ +qty = 0; + $item->cost = 0; + $item->product_key = ''; + $item->notes = ''; + $item->discount = 0; + $item->is_amount_discount = false; + $item->tax_name1 = ''; + $item->tax_rate1 = 0; + $item->tax_name2 = ''; + $item->tax_rate2 = 0; + $item->sort_id = 0; + $item->line_total = 0; + $item->invoice_item_type_id = 0; + + return $item; + } +} + diff --git a/app/Filters/InvoiceFilters.php b/app/Filters/InvoiceFilters.php new file mode 100644 index 000000000000..7477dc208d66 --- /dev/null +++ b/app/Filters/InvoiceFilters.php @@ -0,0 +1,111 @@ +builder; + + return $this->builder->where(function ($query) use ($filter) { + $query->where('invoices.custom_value1', 'like', '%'.$filter.'%') + ->orWhere('invoices.custom_value2', 'like' , '%'.$filter.'%') + ->orWhere('invoices.custom_value3', 'like' , '%'.$filter.'%') + ->orWhere('invoices.custom_value4', 'like' , '%'.$filter.'%'); + }); + } + + /** + * Filters the list based on the status + * archived, active, deleted + * + * @param string filter + * @return Illuminate\Database\Query\Builder + */ + public function status(string $filter = '') : Builder + { + if(strlen($filter) == 0) + return $this->builder; + + $table = 'products'; + $filters = explode(',', $filter); + + return $this->builder->where(function ($query) use ($filters, $table) { + $query->whereNull($table . '.id'); + + if (in_array(parent::STATUS_ACTIVE, $filters)) { + $query->orWhereNull($table . '.deleted_at'); + } + + if (in_array(parent::STATUS_ARCHIVED, $filters)) { + $query->orWhere(function ($query) use ($table) { + $query->whereNotNull($table . '.deleted_at'); + + if (! in_array($table, ['users'])) { + $query->where($table . '.is_deleted', '=', 0); + } + }); + } + + if (in_array(parent::STATUS_DELETED, $filters)) { + $query->orWhere($table . '.is_deleted', '=', 1); + } + }); + } + + /** + * Sorts the list based on $sort + * + * @param string sort formatted as column|asc + * @return Illuminate\Database\Query\Builder + */ + public function sort(string $sort) : Builder + { + $sort_col = explode("|", $sort); + return $this->builder->orderBy($sort_col[0], $sort_col[1]); + } + + /** + * Returns the base query + * + * @param int company_id + * @return Illuminate\Database\Query\Builder + * @deprecated + */ + public function baseQuery(int $company_id, User $user) : Builder + { + + } + + /** + * Filters the query by the users company ID + * + * @param $company_id The company Id + * @return Illuminate\Database\Query\Builder + */ + public function entityFilter() + { + + return $this->builder->whereCompanyId(auth()->user()->company()->id); + + } + +} \ No newline at end of file