Skip to content

Commit

Permalink
Change calculation of Not Budgeted Last Month
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
devbanana committed Oct 2, 2014
1 parent 2b62a94 commit e88940b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
17 changes: 9 additions & 8 deletions src/Devbanana/BudgetBundle/Entity/BudgetRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit e88940b

Please sign in to comment.