From e88940b69a38cb1368f2ce9defefc182c65ddc36 Mon Sep 17 00:00:00 2001 From: Brandon Olivares Date: Wed, 1 Oct 2014 20:02:13 -0400 Subject: [PATCH] Change calculation of Not Budgeted Last Month Resolves #17 * Not Budgeted Last Month should be last month's Available to Budget. Currently is simply total income minus total budgeted, which doesn't work when there is overspending. --- README.md | 4 ++++ .../BudgetBundle/Entity/BudgetRepository.php | 17 +++++++++-------- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index b1a7a7a..c0ecaa2 100644 --- a/README.md +++ b/README.md @@ -20,6 +20,10 @@ Budget Banana is a web-based interface to help you to live out these four rules Change Log ------------- +### v0.1.3 - 2014-10-01 ### + +* Fixed calculation of **Not Budgeted Last Month** ([#17](https://github.com/devbanana/Budget-Banana/issues/17)) + ### v0.1.2 - 2014-09-18 ### * Fixed broken images on category page ([#12](https://github.com/devbanana/Budget-Banana/issues/12)) diff --git a/src/Devbanana/BudgetBundle/Entity/BudgetRepository.php b/src/Devbanana/BudgetBundle/Entity/BudgetRepository.php index 0b56e84..0b18728 100644 --- a/src/Devbanana/BudgetBundle/Entity/BudgetRepository.php +++ b/src/Devbanana/BudgetBundle/Entity/BudgetRepository.php @@ -116,16 +116,17 @@ public function getAvailableToBudget(Budget $budget) */ public function getNotBudgetedLastMonth(Budget $budget) { - // Get all income assigned to months before this month - $totalIncome = $this->getEntityManager() - ->getRepository('DevbananaBudgetBundle:LineItem') - ->getTotalIncomeBefore($budget); + $lastMonth = clone $budget->getMonth(); + $lastMonth->modify('-1 month'); - $totalBudgeted = $this->getEntityManager() - ->getRepository('DevbananaBudgetBundle:BudgetCategories') - ->getTotalBudgetedBefore($budget); + $lastMonthBudget = $this->findOneByMonth($lastMonth); - return bcsub($totalIncome, $totalBudgeted, 2); + if ($lastMonthBudget) { + return $this->getAvailableToBudget($lastMonthBudget); + } + else { + return '0.00'; + } } public function getOverSpentLastMonth(Budget $budget)