Skip to content

Firefly III: a personal finances manager

More code cleanup.

James Cole6a9d931ba399
diff --git a/app/Helpers/Report/ReportHelper.php b/app/Helpers/Report/ReportHelper.php
index 084cd6ed3e..7dc00d2fd3 100644
--- a/app/Helpers/Report/ReportHelper.php
+++ b/app/Helpers/Report/ReportHelper.php
@@ -65,7 +65,7 @@ class ReportHelper implements ReportHelperInterface
/** @var \FireflyIII\Repositories\Category\SingleCategoryRepositoryInterface $singleRepository */
$singleRepository = app('FireflyIII\Repositories\Category\SingleCategoryRepositoryInterface');
- $set = $repository->getCategories();
+ $set = $repository->listCategories();
foreach ($set as $category) {
$spent = $singleRepository->balanceInPeriod($category, $start, $end, $accounts);
$category->spent = $spent;
diff --git a/app/Http/Controllers/CategoryController.php b/app/Http/Controllers/CategoryController.php
index 4257e86e58..fe7a1ebeae 100644
--- a/app/Http/Controllers/CategoryController.php
+++ b/app/Http/Controllers/CategoryController.php
@@ -115,7 +115,7 @@ class CategoryController extends Controller
*/
public function index(CRI $repository, SCRI $singleRepository)
{
- $categories = $repository->getCategories();
+ $categories = $repository->listCategories();
$categories->each(
function (Category $category) use ($singleRepository) {
@@ -135,7 +135,7 @@ class CategoryController extends Controller
{
$start = Session::get('start', Carbon::now()->startOfMonth());
$end = Session::get('end', Carbon::now()->startOfMonth());
- $list = $repository->getWithoutCategory($start, $end);
+ $list = $repository->listNoCategory($start, $end);
$subTitle = trans(
'firefly.without_category_between',
['start' => $start->formatLocalized($this->monthAndDayFormat), 'end' => $end->formatLocalized($this->monthAndDayFormat)]
diff --git a/app/Http/Controllers/JsonController.php b/app/Http/Controllers/JsonController.php
index 7ba3db7f7a..7005084b4b 100644
--- a/app/Http/Controllers/JsonController.php
+++ b/app/Http/Controllers/JsonController.php
@@ -179,7 +179,7 @@ class JsonController extends Controller
*/
public function categories(CRI $repository)
{
- $list = $repository->getCategories();
+ $list = $repository->listCategories();
$return = [];
foreach ($list as $entry) {
$return[] = $entry->name;
diff --git a/app/Repositories/Category/CategoryRepository.php b/app/Repositories/Category/CategoryRepository.php
index 269255cba6..5e1deb4636 100644
--- a/app/Repositories/Category/CategoryRepository.php
+++ b/app/Repositories/Category/CategoryRepository.php
@@ -8,7 +8,6 @@ use DB;
use FireflyIII\Models\Category;
use FireflyIII\Models\TransactionType;
use FireflyIII\Sql\Query;
-use FireflyIII\Support\CacheProperties;
use Illuminate\Database\Query\JoinClause;
use Illuminate\Support\Collection;
@@ -21,31 +20,8 @@ class CategoryRepository implements CategoryRepositoryInterface
{
/**
- * @return Collection
- */
- public function getCategories()
- {
- $cache = new CacheProperties;
- $cache->addProperty('category-list');
-
- if ($cache->has()) {
- return $cache->get();
- }
-
- /** @var Collection $set */
- $set = Auth::user()->categories()->orderBy('name', 'ASC')->get();
- $set = $set->sortBy(
- function (Category $category) {
- return strtolower($category->name);
- }
- );
-
- $cache->store($set);
-
- return $set;
- }
-
- /**
+ * TODO REMOVE ME
+ *
* @param Carbon $start
* @param Carbon $end
*
@@ -106,12 +82,33 @@ class CategoryRepository implements CategoryRepositoryInterface
}
/**
+ * Returns a list of all the categories belonging to a user.
+ *
+ * @return Collection
+ */
+ public function listCategories()
+ {
+ /** @var Collection $set */
+ $set = Auth::user()->categories()->orderBy('name', 'ASC')->get();
+ $set = $set->sortBy(
+ function (Category $category) {
+ return strtolower($category->name);
+ }
+ );
+
+ return $set;
+ }
+
+ /**
+ * Returns a list of transaction journals in the range (all types, all accounts) that have no category
+ * associated to them.
+ *
* @param Carbon $start
* @param Carbon $end
*
* @return Collection
*/
- public function getWithoutCategory(Carbon $start, Carbon $end)
+ public function listNoCategory(Carbon $start, Carbon $end)
{
return Auth::user()
->transactionjournals()
@@ -181,100 +178,6 @@ class CategoryRepository implements CategoryRepositoryInterface
}
- /**
- * Returns a collection of Categories appended with the amount of money that has been earned
- * in these categories, based on the $accounts involved, in period X.
- * The amount earned in category X in period X is saved in field "earned".
- *
- * @param $accounts
- * @param $start
- * @param $end
- *
- * @return Collection
- */
- public function earnedForAccounts(Collection $accounts, Carbon $start, Carbon $end)
- {
- $accountIds = [];
- foreach ($accounts as $account) {
- $accountIds[] = $account->id;
- }
-
-
- $collection = Auth::user()->categories()
- ->leftJoin('category_transaction_journal', 'category_transaction_journal.category_id', '=', 'categories.id')
- ->leftJoin('transaction_journals', 'category_transaction_journal.transaction_journal_id', '=', 'transaction_journals.id')
- ->leftJoin('transaction_types', 'transaction_types.id', '=', 'transaction_journals.transaction_type_id')
- ->leftJoin(
- 'transactions AS t_src', function (JoinClause $join) {
- $join->on('t_src.transaction_journal_id', '=', 'transaction_journals.id')->where('t_src.amount', '<', 0);
- }
- )
- ->leftJoin(
- 'transactions AS t_dest', function (JoinClause $join) {
- $join->on('t_dest.transaction_journal_id', '=', 'transaction_journals.id')->where('t_dest.amount', '>', 0);
- }
- )
- ->whereIn('t_dest.account_id', $accountIds)// to these accounts (earned)
- ->whereNotIn('t_src.account_id', $accountIds)//-- but not from these accounts
- ->whereIn(
- 'transaction_types.type', [TransactionType::DEPOSIT, TransactionType::TRANSFER, TransactionType::OPENING_BALANCE]
- )
- ->where('transaction_journals.date', '>=', $start->format('Y-m-d'))
- ->where('transaction_journals.date', '<=', $end->format('Y-m-d'))
- ->groupBy('categories.id')
- ->get(['categories.*', DB::Raw('SUM(`t_dest`.`amount`) AS `earned`')]);
-
- return $collection;
-
-
- }
-
- /**
- * Returns a collection of Categories appended with the amount of money that has been spent
- * in these categories, based on the $accounts involved, in period X.
- * The amount earned in category X in period X is saved in field "spent".
- *
- * @param $accounts
- * @param $start
- * @param $end
- *
- * @return Collection
- */
- public function spentForAccounts(Collection $accounts, Carbon $start, Carbon $end)
- {
- $accountIds = [];
- foreach ($accounts as $account) {
- $accountIds[] = $account->id;
- }
-
-
- $collection = Auth::user()->categories()
- ->leftJoin('category_transaction_journal', 'category_transaction_journal.category_id', '=', 'categories.id')
- ->leftJoin('transaction_journals', 'category_transaction_journal.transaction_journal_id', '=', 'transaction_journals.id')
- ->leftJoin('transaction_types', 'transaction_types.id', '=', 'transaction_journals.transaction_type_id')
- ->leftJoin(
- 'transactions AS t_src', function (JoinClause $join) {
- $join->on('t_src.transaction_journal_id', '=', 'transaction_journals.id')->where('t_src.amount', '<', 0);
- }
- )
- ->leftJoin(
- 'transactions AS t_dest', function (JoinClause $join) {
- $join->on('t_dest.transaction_journal_id', '=', 'transaction_journals.id')->where('t_dest.amount', '>', 0);
- }
- )
- ->whereIn('t_src.account_id', $accountIds)// from these accounts (spent)
- ->whereNotIn('t_dest.account_id', $accountIds)//-- but not from these accounts (spent internally)
- ->whereIn(
- 'transaction_types.type', [TransactionType::WITHDRAWAL, TransactionType::TRANSFER, TransactionType::OPENING_BALANCE]
- )// spent on these things.
- ->where('transaction_journals.date', '>=', $start->format('Y-m-d'))
- ->where('transaction_journals.date', '<=', $end->format('Y-m-d'))
- ->groupBy('categories.id')
- ->get(['categories.*', DB::Raw('SUM(`t_dest`.`amount`) AS `spent`')]);
-
- return $collection;
- }
-
/**
* Returns a collection of Categories appended with the amount of money that has been spent
* in these categories, based on the $accounts involved, in period X, grouped per month.
diff --git a/app/Repositories/Category/CategoryRepositoryInterface.php b/app/Repositories/Category/CategoryRepositoryInterface.php
index fd44e95db5..2bf6825beb 100644
--- a/app/Repositories/Category/CategoryRepositoryInterface.php
+++ b/app/Repositories/Category/CategoryRepositoryInterface.php
@@ -14,18 +14,6 @@ use Illuminate\Support\Collection;
interface CategoryRepositoryInterface
{
- /**
- * Returns a collection of Categories appended with the amount of money that has been earned
- * in these categories, based on the $accounts involved, in period X.
- * The amount earned in category X in period X is saved in field "earned".
- *
- * @param $accounts
- * @param $start
- * @param $end
- *
- * @return Collection
- */
- public function earnedForAccounts(Collection $accounts, Carbon $start, Carbon $end);
/**
* Returns a collection of Categories appended with the amount of money that has been earned
@@ -40,11 +28,6 @@ interface CategoryRepositoryInterface
*/
public function earnedForAccountsPerMonth(Collection $accounts, Carbon $start, Carbon $end);
- /**
- * @return Collection
- */
- public function getCategories();
-
/**
* Corrected for tags.
*
@@ -56,25 +39,22 @@ interface CategoryRepositoryInterface
public function getCategoriesAndExpenses(Carbon $start, Carbon $end);
/**
- * @param Carbon $start
- * @param Carbon $end
+ * Returns a list of all the categories belonging to a user.
*
* @return Collection
*/
- public function getWithoutCategory(Carbon $start, Carbon $end);
+ public function listCategories();
/**
- * Returns a collection of Categories appended with the amount of money that has been spent
- * in these categories, based on the $accounts involved, in period X.
- * The amount earned in category X in period X is saved in field "spent".
+ * Returns a list of transaction journals in the range (all types, all accounts) that have no category
+ * associated to them.
*
- * @param $accounts
- * @param $start
- * @param $end
+ * @param Carbon $start
+ * @param Carbon $end
*
* @return Collection
*/
- public function spentForAccounts(Collection $accounts, Carbon $start, Carbon $end);
+ public function listNoCategory(Carbon $start, Carbon $end);
/**
* Returns a collection of Categories appended with the amount of money that has been spent