From 61b6e266da49a3b3c76d2e1838e096003cbc8b0f Mon Sep 17 00:00:00 2001 From: James Cole Date: Fri, 30 Aug 2019 09:30:06 +0200 Subject: [PATCH] Catch "no category" entries. --- .../Category/OperationsRepository.php | 22 +++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/app/Repositories/Category/OperationsRepository.php b/app/Repositories/Category/OperationsRepository.php index e6fde5812a..fc44bb7eeb 100644 --- a/app/Repositories/Category/OperationsRepository.php +++ b/app/Repositories/Category/OperationsRepository.php @@ -78,12 +78,19 @@ class OperationsRepository implements OperationsRepositoryInterface if (null === $categories || (null !== $categories && 0 === $categories->count())) { $collector->setCategories($this->getCategories()); } + $collector->withCategoryInformation(); $journals = $collector->getExtractedJournals(); $array = []; foreach ($journals as $journal) { - $currencyId = (int)$journal['currency_id']; - $categoryId = (int)$journal['category_id']; + $currencyId = (int)$journal['currency_id']; + $categoryId = (int)$journal['category_id']; + $categoryName = (string)$journal['category_name']; + + // catch "no category" entries. + if (0 === $categoryId) { + $categoryName = (string)trans('firefly.no_category'); + } // info about the currency: $array[$currencyId] = $array[$currencyId] ?? [ @@ -98,7 +105,7 @@ class OperationsRepository implements OperationsRepositoryInterface // info about the categories: $array[$currencyId]['categories'][$categoryId] = $array[$currencyId]['categories'][$categoryId] ?? [ 'id' => $categoryId, - 'name' => $journal['category_name'], + 'name' => $categoryName, 'transaction_journals' => [], ]; @@ -143,12 +150,19 @@ class OperationsRepository implements OperationsRepositoryInterface if (null === $categories || (null !== $categories && 0 === $categories->count())) { $collector->setCategories($this->getCategories()); } + $collector->withCategoryInformation(); $journals = $collector->getExtractedJournals(); $array = []; foreach ($journals as $journal) { $currencyId = (int)$journal['currency_id']; $categoryId = (int)$journal['category_id']; + $categoryName = (string)$journal['category_name']; + + // catch "no category" entries. + if (0 === $categoryId) { + $categoryName = (string)trans('firefly.no_category'); + } // info about the currency: $array[$currencyId] = $array[$currencyId] ?? [ @@ -163,7 +177,7 @@ class OperationsRepository implements OperationsRepositoryInterface // info about the categories: $array[$currencyId]['categories'][$categoryId] = $array[$currencyId]['categories'][$categoryId] ?? [ 'id' => $categoryId, - 'name' => $journal['category_name'], + 'name' => $categoryName, 'transaction_journals' => [], ];