From 587dde8a3a881db2600b7b3f4c70565e2514c7ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=BCneyt=20=C5=9Eent=C3=BCrk?= Date: Sat, 27 Feb 2021 21:03:56 +0300 Subject: [PATCH] close #1880 Fixed: Reports Not all categories are displayed --- app/Abstracts/Listeners/Report.php | 54 ++++++++++++------- app/Listeners/Report/AddAccounts.php | 9 ++-- app/Listeners/Report/AddCustomers.php | 8 +-- app/Listeners/Report/AddExpenseCategories.php | 9 ++-- app/Listeners/Report/AddIncomeCategories.php | 9 ++-- .../Report/AddIncomeExpenseCategories.php | 8 +-- app/Listeners/Report/AddVendors.php | 8 +-- 7 files changed, 69 insertions(+), 36 deletions(-) diff --git a/app/Abstracts/Listeners/Report.php b/app/Abstracts/Listeners/Report.php index 676e3c07f..3ac17963e 100644 --- a/app/Abstracts/Listeners/Report.php +++ b/app/Abstracts/Listeners/Report.php @@ -51,49 +51,67 @@ abstract class Report return $years; } - public function getAccounts() + public function getAccounts($limit = false) { - return Account::enabled()->orderBy('name')->take(setting('default.select_limit'))->pluck('name', 'id')->toArray(); + $model = Account::enabled()->orderBy('name'); + + if ($limit !== false) { + $model->take(setting('default.select_limit')); + } + + return $model->pluck('name', 'id')->toArray(); } - public function getItemCategories() + public function getItemCategories($limit = false) { - return $this->getCategories('item'); + return $this->getCategories('item', $limit); } - public function getIncomeCategories() + public function getIncomeCategories($limit = false) { - return $this->getCategories('income'); + return $this->getCategories('income', $limit); } - public function getExpenseCategories() + public function getExpenseCategories($limit = false) { - return $this->getCategories('expense'); + return $this->getCategories('expense', $limit); } - public function getIncomeExpenseCategories() + public function getIncomeExpenseCategories($limit = false) { - return $this->getCategories(['income', 'expense']); + return $this->getCategories(['income', 'expense'], $limit); } - public function getCategories($types) + public function getCategories($types, $limit = false) { - return Category::type($types)->orderBy('name')->take(setting('default.select_limit'))->pluck('name', 'id')->toArray(); + $model = Category::type($types)->orderBy('name'); + + if ($limit !== false) { + $model->take(setting('default.select_limit')); + } + + return $model->pluck('name', 'id')->toArray(); } - public function getCustomers() + public function getCustomers($limit = false) { - return $this->getContacts($this->getCustomerTypes()); + return $this->getContacts($this->getCustomerTypes(), $limit); } - public function getVendors() + public function getVendors($limit = false) { - return $this->getContacts($this->getVendorTypes()); + return $this->getContacts($this->getVendorTypes(), $limit); } - public function getContacts($types) + public function getContacts($types, $limit = false) { - return Contact::type($types)->orderBy('name')->take(setting('default.select_limit'))->pluck('name', 'id')->toArray(); + $model = Contact::type($types)->orderBy('name'); + + if ($limit !== false) { + $model->take(setting('default.select_limit')); + } + + return $model->pluck('name', 'id')->toArray(); } public function applyDateFilter($event) diff --git a/app/Listeners/Report/AddAccounts.php b/app/Listeners/Report/AddAccounts.php index fbaf8c0f1..fdc9aa2dd 100644 --- a/app/Listeners/Report/AddAccounts.php +++ b/app/Listeners/Report/AddAccounts.php @@ -28,7 +28,8 @@ class AddAccounts extends Listener return; } - $event->class->filters['accounts'] = $this->getAccounts(); + // send true for add limit on search and filter.. + $event->class->filters['accounts'] = $this->getAccounts(true); $event->class->filters['routes']['accounts'] = 'accounts.index'; } @@ -74,14 +75,16 @@ class AddAccounts extends Listener return; } + $all_accounts = $this->getAccounts(); + if ($account_ids = $this->getSearchStringValue('account_id')) { $accounts = explode(',', $account_ids); - $rows = collect($event->class->filters['accounts'])->filter(function ($value, $key) use ($accounts) { + $rows = collect($all_accounts)->filter(function ($value, $key) use ($accounts) { return in_array($key, $accounts); }); } else { - $rows = $event->class->filters['accounts']; + $rows = $all_accounts; } $this->setRowNamesAndValues($event, $rows); diff --git a/app/Listeners/Report/AddCustomers.php b/app/Listeners/Report/AddCustomers.php index b208c8f17..dd47e9ba9 100644 --- a/app/Listeners/Report/AddCustomers.php +++ b/app/Listeners/Report/AddCustomers.php @@ -27,7 +27,7 @@ class AddCustomers extends Listener return; } - $event->class->filters['customers'] = $this->getCustomers(); + $event->class->filters['customers'] = $this->getCustomers(true); $event->class->filters['routes']['customers'] = 'customers.index'; } @@ -73,14 +73,16 @@ class AddCustomers extends Listener return; } + $all_customers = $this->getCustomers(); + if ($customer_ids = $this->getSearchStringValue('customer_id')) { $customers = explode(',', $customer_ids); - $rows = collect($event->class->filters['customers'])->filter(function ($value, $key) use ($customers) { + $rows = collect($all_customers)->filter(function ($value, $key) use ($customers) { return in_array($key, $customers); }); } else { - $rows = $event->class->filters['customers']; + $rows = $all_customers; } $this->setRowNamesAndValues($event, $rows); diff --git a/app/Listeners/Report/AddExpenseCategories.php b/app/Listeners/Report/AddExpenseCategories.php index fef703fc3..fcd38dd08 100644 --- a/app/Listeners/Report/AddExpenseCategories.php +++ b/app/Listeners/Report/AddExpenseCategories.php @@ -25,7 +25,8 @@ class AddExpenseCategories extends Listener return; } - $event->class->filters['categories'] = $this->getExpenseCategories(); + // send true for add limit on search and filter.. + $event->class->filters['categories'] = $this->getExpenseCategories(true); $event->class->filters['routes']['categories'] = ['categories.index', 'search=type:expense']; } @@ -56,14 +57,16 @@ class AddExpenseCategories extends Listener return; } + $all_categories = $this->getExpenseCategories(); + if ($category_ids = $this->getSearchStringValue('category_id')) { $categories = explode(',', $category_ids); - $rows = collect($event->class->filters['categories'])->filter(function ($value, $key) use ($categories) { + $rows = collect($all_categories)->filter(function ($value, $key) use ($categories) { return in_array($key, $categories); }); } else { - $rows = $event->class->filters['categories']; + $rows = $all_categories; } $this->setRowNamesAndValues($event, $rows); diff --git a/app/Listeners/Report/AddIncomeCategories.php b/app/Listeners/Report/AddIncomeCategories.php index f725b94ed..2896cc3f8 100644 --- a/app/Listeners/Report/AddIncomeCategories.php +++ b/app/Listeners/Report/AddIncomeCategories.php @@ -25,7 +25,8 @@ class AddIncomeCategories extends Listener return; } - $event->class->filters['categories'] = $this->getIncomeCategories(); + // send true for add limit on search and filter.. + $event->class->filters['categories'] = $this->getIncomeCategories(true); $event->class->filters['routes']['categories'] = ['categories.index', 'search=type:income']; } @@ -56,14 +57,16 @@ class AddIncomeCategories extends Listener return; } + $all_categories = $this->getIncomeCategories(); + if ($category_ids = $this->getSearchStringValue('category_id')) { $categories = explode(',', $category_ids); - $rows = collect($event->class->filters['categories'])->filter(function ($value, $key) use ($categories) { + $rows = collect($all_categories)->filter(function ($value, $key) use ($categories) { return in_array($key, $categories); }); } else { - $rows = $event->class->filters['categories']; + $rows = $all_categories; } $this->setRowNamesAndValues($event, $rows); diff --git a/app/Listeners/Report/AddIncomeExpenseCategories.php b/app/Listeners/Report/AddIncomeExpenseCategories.php index 183dc3789..010ca0589 100644 --- a/app/Listeners/Report/AddIncomeExpenseCategories.php +++ b/app/Listeners/Report/AddIncomeExpenseCategories.php @@ -26,7 +26,7 @@ class AddIncomeExpenseCategories extends Listener return; } - $event->class->filters['categories'] = $this->getIncomeExpenseCategories(); + $event->class->filters['categories'] = $this->getIncomeExpenseCategories(true); $event->class->filters['routes']['categories'] = ['categories.index', 'search=type:income,expense']; } @@ -75,14 +75,16 @@ class AddIncomeExpenseCategories extends Listener break; case 'App\Reports\IncomeExpenseSummary': + $all_categories = $this->getIncomeExpenseCategories(); + if ($category_ids = $this->getSearchStringValue('category_id')) { $categories = explode(',', $category_ids); - $rows = collect($event->class->filters['categories'])->filter(function ($value, $key) use ($categories) { + $rows = collect($all_categories)->filter(function ($value, $key) use ($categories) { return in_array($key, $categories); }); } else { - $rows = $event->class->filters['categories']; + $rows = $all_categories; } $this->setRowNamesAndValues($event, $rows); diff --git a/app/Listeners/Report/AddVendors.php b/app/Listeners/Report/AddVendors.php index 696b4c2eb..f69dda83f 100644 --- a/app/Listeners/Report/AddVendors.php +++ b/app/Listeners/Report/AddVendors.php @@ -27,7 +27,7 @@ class AddVendors extends Listener return; } - $event->class->filters['vendors'] = $this->getVendors(); + $event->class->filters['vendors'] = $this->getVendors(true); $event->class->filters['routes']['vendors'] = 'vendors.index'; } @@ -73,14 +73,16 @@ class AddVendors extends Listener return; } + $all_vendors = $this->getVendors(); + if ($vendor_ids = $this->getSearchStringValue('vendor_id')) { $vendors = explode(',', $vendor_ids); - $rows = collect($event->class->filters['vendors'])->filter(function ($value, $key) use ($vendors) { + $rows = collect($all_vendors)->filter(function ($value, $key) use ($vendors) { return in_array($key, $vendors); }); } else { - $rows = $event->class->filters['vendors']; + $rows = $all_vendors; } $this->setRowNamesAndValues($event, $rows);