Firefly III: a personal finances manager
PHP accountingbudgetbudgetingbudgetscash-flowcashflowcredit-carddockerexpensesfinancefinancesfinanciallinuxmoneypaycheckpersonal-financephpphp7
Completed the renaming of some methods.
James Cole15fd8cf486b9
diff --git a/app/Helpers/Report/ReportHelper.php b/app/Helpers/Report/ReportHelper.phpindex 7f028d6a10..43349c78a1 100644--- a/app/Helpers/Report/ReportHelper.php+++ b/app/Helpers/Report/ReportHelper.php@@ -63,7 +63,7 @@ class ReportHelper implements ReportHelperInterface$repository = app('FireflyIII\Repositories\Category\CategoryRepositoryInterface');$set = $repository->getCategories();foreach ($set as $category) {- $spent = $repository->balanceInPeriodForList($category, $start, $end, $accounts);+ $spent = $repository->balanceInPeriod($category, $start, $end, $accounts);$category->spent = $spent;$object->addCategory($category);}@@ -222,7 +222,7 @@ class ReportHelper implements ReportHelperInterface// no repetition(s) for this budget:if ($repetitions->count() == 0) {- $spent = $repository->balanceInPeriodForList($budget, $start, $end, $accounts);+ $spent = $repository->balanceInPeriod($budget, $start, $end, $accounts);$budgetLine = new BudgetLine;$budgetLine->setBudget($budget);$budgetLine->setOverspent($spent);@@ -237,7 +237,7 @@ class ReportHelper implements ReportHelperInterface$budgetLine = new BudgetLine;$budgetLine->setBudget($budget);$budgetLine->setRepetition($repetition);- $expenses = $repository->balanceInPeriodForList($budget, $start, $end, $accounts);+ $expenses = $repository->balanceInPeriod($budget, $start, $end, $accounts);// 200 en -100 is 100, vergeleken met 0 === 1// 200 en -200 is 0, vergeleken met 0 === 0diff --git a/app/Http/Controllers/BudgetController.php b/app/Http/Controllers/BudgetController.phpindex 74876933e4..2bece914ec 100644--- a/app/Http/Controllers/BudgetController.php+++ b/app/Http/Controllers/BudgetController.php@@ -159,7 +159,7 @@ class BudgetController extends Controller// loop the budgets:/** @var Budget $budget */foreach ($budgets as $budget) {- $budget->spent = $repository->balanceInPeriodForList($budget, $start, $end, $accounts);+ $budget->spent = $repository->balanceInPeriod($budget, $start, $end, $accounts);$budget->currentRep = $repository->getCurrentRepetition($budget, $start, $end);if ($budget->currentRep) {$budgeted = bcadd($budgeted, $budget->currentRep->amount);diff --git a/app/Http/Controllers/Chart/BudgetController.php b/app/Http/Controllers/Chart/BudgetController.phpindex 05515f27af..14298452cc 100644--- a/app/Http/Controllers/Chart/BudgetController.php+++ b/app/Http/Controllers/Chart/BudgetController.php@@ -86,7 +86,7 @@ class BudgetController extends Controller$budgeted = 0;} else {$name = $budget->name;- $sum = $repository->balanceInPeriodForList($budget, $currentStart, $currentEnd, $accounts);+ $sum = $repository->balanceInPeriod($budget, $currentStart, $currentEnd, $accounts);$budgeted = $repository->getBudgetLimitRepetitions($budget, $currentStart, $currentEnd)->sum('amount');}@@ -144,7 +144,7 @@ class BudgetController extends Controller$end->subDay();$chartDate = clone $end;$chartDate->startOfMonth();- $spent = $repository->balanceInPeriodForList($budget, $first, $end, $accounts) * -1;+ $spent = $repository->balanceInPeriod($budget, $first, $end, $accounts) * -1;$entries->push([$chartDate, $spent]);$first = Navigation::addPeriod($first, $range, 0);}@@ -233,13 +233,13 @@ class BudgetController extends Controllerforeach ($budgets as $budget) {$repetitions = $repository->getBudgetLimitRepetitions($budget, $start, $end);if ($repetitions->count() == 0) {- $expenses = $repository->balanceInPeriodForList($budget, $start, $end, $accounts) * -1;+ $expenses = $repository->balanceInPeriod($budget, $start, $end, $accounts) * -1;$allEntries->push([$budget->name, 0, 0, $expenses, 0, 0]);continue;}/** @var LimitRepetition $repetition */foreach ($repetitions as $repetition) {- $expenses = $repository->balanceInPeriodForList($budget, $repetition->startdate, $repetition->enddate, $accounts) * -1;+ $expenses = $repository->balanceInPeriod($budget, $repetition->startdate, $repetition->enddate, $accounts) * -1;// $left can be less than zero.// $overspent can be more than zero ( = overspending)@@ -293,7 +293,7 @@ class BudgetController extends Controller// filter empty budgets:foreach ($allBudgets as $budget) {- $spent = $repository->balanceInPeriodForList($budget, $start, $end, $accounts);+ $spent = $repository->balanceInPeriod($budget, $start, $end, $accounts);if ($spent != 0) {$budgets->push($budget);}@@ -309,7 +309,7 @@ class BudgetController extends Controller// each budget, fill the row:foreach ($budgets as $budget) {- $spent = $repository->balanceInPeriodForList($budget, $start, $month, $accounts);+ $spent = $repository->balanceInPeriod($budget, $start, $month, $accounts);$row[] = $spent * -1;}$entries->push($row);diff --git a/app/Http/Controllers/Chart/CategoryController.php b/app/Http/Controllers/Chart/CategoryController.phpindex cca2c2d5a3..7494c85abd 100644--- a/app/Http/Controllers/Chart/CategoryController.php+++ b/app/Http/Controllers/Chart/CategoryController.php@@ -316,7 +316,7 @@ class CategoryController extends Controller$entries = new Collection;$categories = $allCategories->filter(function (Category $category) use ($repository, $start, $end, $accounts) {- $spent = $repository->balanceInPeriodForList($category, $start, $end, $accounts);+ $spent = $repository->balanceInPeriod($category, $start, $end, $accounts);if ($spent < 0) {return $category;}@@ -331,7 +331,7 @@ class CategoryController extends Controller$row = [clone $start]; // make a row:foreach ($categories as $category) { // each budget, fill the row- $spent = $repository->balanceInPeriodForList($category, $start, $month, $accounts);+ $spent = $repository->balanceInPeriod($category, $start, $month, $accounts);if ($spent < 0) {$row[] = $spent * -1;} else {@@ -375,7 +375,7 @@ class CategoryController extends Controller$allEntries = new Collection;$categories = $allCategories->filter(function (Category $category) use ($repository, $start, $end, $accounts) {- $spent = $repository->balanceInPeriodForList($category, $start, $end, $accounts);+ $spent = $repository->balanceInPeriod($category, $start, $end, $accounts);if ($spent > 0) {return $category;}@@ -390,7 +390,7 @@ class CategoryController extends Controller$row = [clone $start]; // make a row:foreach ($categories as $category) { // each budget, fill the row- $spent = $repository->balanceInPeriodForList($category, $start, $month, $accounts);+ $spent = $repository->balanceInPeriod($category, $start, $month, $accounts);if ($spent > 0) {$row[] = $spent;} else {diff --git a/app/Repositories/Budget/BudgetRepository.php b/app/Repositories/Budget/BudgetRepository.phpindex 49280c742f..0e0b9d1623 100644--- a/app/Repositories/Budget/BudgetRepository.php+++ b/app/Repositories/Budget/BudgetRepository.php@@ -320,22 +320,9 @@ class BudgetRepository extends ComponentRepository implements BudgetRepositoryIn** @return string*/- public function balanceInPeriodForList(Budget $budget, Carbon $start, Carbon $end, Collection $accounts)+ public function balanceInPeriod(Budget $budget, Carbon $start, Carbon $end, Collection $accounts){- return $this->commonBalanceInPeriodForList($budget, $start, $end, $accounts);- }-- /**- * @param Budget $budget- * @param Carbon $start- * @param Carbon $end- * @param bool $shared- *- * @return string- */- public function balanceInPeriod(Budget $budget, Carbon $start, Carbon $end, $shared = true)- {- return $this->commonBalanceInPeriod($budget, $start, $end, $shared);+ return $this->commonBalanceInPeriod($budget, $start, $end, $accounts);}/**diff --git a/app/Repositories/Budget/BudgetRepositoryInterface.php b/app/Repositories/Budget/BudgetRepositoryInterface.phpindex 9594f2d2bc..ad298b47a2 100644--- a/app/Repositories/Budget/BudgetRepositoryInterface.php+++ b/app/Repositories/Budget/BudgetRepositoryInterface.php@@ -126,19 +126,6 @@ interface BudgetRepositoryInterface*/public function getWithoutBudgetSum(Carbon $start, Carbon $end);- /**- *- * Same as ::spentInPeriod but corrects journals for their amount (tags).- *- * @param Budget $budget- * @param Carbon $start- * @param Carbon $end- * @param boolean $shared- *- * @return string- */- public function balanceInPeriod(Budget $budget, Carbon $start, Carbon $end, $shared = true);-/**** Same as ::spentInPeriod but corrects journals for a set of accounts@@ -150,7 +137,7 @@ interface BudgetRepositoryInterface** @return string*/- public function balanceInPeriodForList(Budget $budget, Carbon $start, Carbon $end, Collection $accounts);+ public function balanceInPeriod(Budget $budget, Carbon $start, Carbon $end, Collection $accounts);/*** @param array $datadiff --git a/app/Repositories/Category/CategoryRepository.php b/app/Repositories/Category/CategoryRepository.phpindex aae38137fe..897a246cdf 100644--- a/app/Repositories/Category/CategoryRepository.php+++ b/app/Repositories/Category/CategoryRepository.php@@ -242,20 +242,6 @@ class CategoryRepository extends ComponentRepository implements CategoryReposito->get(['transaction_journals.*']);}- /**- * @param Category $category- * @param Carbon $start- * @param Carbon $end- *- * @param bool $shared- *- * @return string- */- public function balanceInPeriod(Category $category, Carbon $start, Carbon $end, $shared = false)- {- return $this->commonBalanceInPeriod($category, $start, $end, $shared);- }-/*** @param Category $category* @param Carbon $start@@ -264,9 +250,9 @@ class CategoryRepository extends ComponentRepository implements CategoryReposito** @return string*/- public function balanceInPeriodForList(Category $category, Carbon $start, Carbon $end, Collection $accounts)+ public function balanceInPeriod(Category $category, Carbon $start, Carbon $end, Collection $accounts){- return $this->commonBalanceInPeriodForList($category, $start, $end, $accounts);+ return $this->commonBalanceInPeriod($category, $start, $end, $accounts);}/**diff --git a/app/Repositories/Category/CategoryRepositoryInterface.php b/app/Repositories/Category/CategoryRepositoryInterface.phpindex d54cdb5f55..8f269bdab9 100644--- a/app/Repositories/Category/CategoryRepositoryInterface.php+++ b/app/Repositories/Category/CategoryRepositoryInterface.php@@ -147,21 +147,7 @@ interface CategoryRepositoryInterfacepublic function getWithoutCategory(Carbon $start, Carbon $end);/**- * Corrected for tags.- *- * @param Category $category- * @param \Carbon\Carbon $start- * @param \Carbon\Carbon $end- *- * @param bool $shared- *- * @return string- */- public function balanceInPeriod(Category $category, Carbon $start, Carbon $end, $shared = false);--- /**- * Corrected for tags.+ * Corrected for tags and list of accounts.** @param Category $category* @param \Carbon\Carbon $start@@ -170,7 +156,7 @@ interface CategoryRepositoryInterface** @return string*/- public function balanceInPeriodForList(Category $category, Carbon $start, Carbon $end, Collection $accounts);+ public function balanceInPeriod(Category $category, Carbon $start, Carbon $end, Collection $accounts);/*** @param Category $categorydiff --git a/app/Repositories/Shared/ComponentRepository.php b/app/Repositories/Shared/ComponentRepository.phpindex 7f91fb8c13..8a198fe14a 100644--- a/app/Repositories/Shared/ComponentRepository.php+++ b/app/Repositories/Shared/ComponentRepository.php@@ -17,55 +17,6 @@ use Illuminate\Support\Collection;class ComponentRepository{-- /**- * @param $object- * @param Carbon $start- * @param Carbon $end- *- * @param bool $shared- *- * @return string- */- protected function commonBalanceInPeriod($object, Carbon $start, Carbon $end, $shared = false)- {- $cache = new CacheProperties; // we must cache this.- $cache->addProperty($object->id);- $cache->addProperty(get_class($object));- $cache->addProperty($start);- $cache->addProperty($end);- $cache->addProperty($shared);- $cache->addProperty('balanceInPeriod');-- if ($cache->has()) {- return $cache->get(); // @codeCoverageIgnore- }-- if ($shared === true) { // shared is true: always ignore transfers between accounts!- $sum = $object->transactionjournals()- ->transactionTypes([TransactionType::WITHDRAWAL, TransactionType::DEPOSIT, TransactionType::OPENING_BALANCE])- ->before($end)- ->after($start)- ->get(['transaction_journals.*'])->sum('amount');- } else {- // do something else, SEE budgets.- // get all journals in this month where the asset account is NOT shared.- $sum = $object->transactionjournals()->before($end)->after($start)- ->leftJoin('transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id')- ->leftJoin('accounts', 'accounts.id', '=', 'transactions.account_id')- ->transactionTypes([TransactionType::WITHDRAWAL, TransactionType::DEPOSIT, TransactionType::OPENING_BALANCE])- ->leftJoin(- 'account_meta', function (JoinClause $join) {- $join->on('account_meta.account_id', '=', 'accounts.id')->where('account_meta.name', '=', 'accountRole');- }- )->where('account_meta.data', '!=', '"sharedAsset"')->get(['transaction_journals.*'])->sum('amount');- }-- $cache->store($sum);-- return $sum;- }-/*** @param $object* @param Carbon $start@@ -74,7 +25,7 @@ class ComponentRepository** @return string*/- protected function commonBalanceInPeriodForList($object, Carbon $start, Carbon $end, Collection $accounts)+ protected function commonBalanceInPeriod($object, Carbon $start, Carbon $end, Collection $accounts){$cache = new CacheProperties; // we must cache this.$cache->addProperty($object->id);