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)