Skip to content

Commit

Permalink
close #1880 Fixed: Reports Not all categories are displayed
Browse files Browse the repository at this point in the history
  • Loading branch information
cuneytsenturk committed Feb 27, 2021
1 parent e4a461a commit 587dde8
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 36 deletions.
54 changes: 36 additions & 18 deletions app/Abstracts/Listeners/Report.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,49 +51,67 @@ public function getYears()
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)
Expand Down
9 changes: 6 additions & 3 deletions app/Listeners/Report/AddAccounts.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ public function handleFilterShowing(FilterShowing $event)
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';
}

Expand Down Expand Up @@ -74,14 +75,16 @@ public function handleRowsShowing(RowsShowing $event)
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);
Expand Down
8 changes: 5 additions & 3 deletions app/Listeners/Report/AddCustomers.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function handleFilterShowing(FilterShowing $event)
return;
}

$event->class->filters['customers'] = $this->getCustomers();
$event->class->filters['customers'] = $this->getCustomers(true);
$event->class->filters['routes']['customers'] = 'customers.index';
}

Expand Down Expand Up @@ -73,14 +73,16 @@ public function handleRowsShowing(RowsShowing $event)
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);
Expand Down
9 changes: 6 additions & 3 deletions app/Listeners/Report/AddExpenseCategories.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ public function handleFilterShowing(FilterShowing $event)
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'];
}

Expand Down Expand Up @@ -56,14 +57,16 @@ public function handleRowsShowing(RowsShowing $event)
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);
Expand Down
9 changes: 6 additions & 3 deletions app/Listeners/Report/AddIncomeCategories.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ public function handleFilterShowing(FilterShowing $event)
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'];
}

Expand Down Expand Up @@ -56,14 +57,16 @@ public function handleRowsShowing(RowsShowing $event)
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);
Expand Down
8 changes: 5 additions & 3 deletions app/Listeners/Report/AddIncomeExpenseCategories.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function handleFilterShowing(FilterShowing $event)
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'];
}

Expand Down Expand Up @@ -75,14 +75,16 @@ public function handleRowsShowing(RowsShowing $event)

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);
Expand Down
8 changes: 5 additions & 3 deletions app/Listeners/Report/AddVendors.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function handleFilterShowing(FilterShowing $event)
return;
}

$event->class->filters['vendors'] = $this->getVendors();
$event->class->filters['vendors'] = $this->getVendors(true);
$event->class->filters['routes']['vendors'] = 'vendors.index';
}

Expand Down Expand Up @@ -73,14 +73,16 @@ public function handleRowsShowing(RowsShowing $event)
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);
Expand Down

0 comments on commit 587dde8

Please sign in to comment.