Fixed a bug in the budget controller.

This commit is contained in:
James Cole 2015-04-03 19:11:55 +02:00
parent 8b085af6a1
commit 0faef542c1
2 changed files with 11 additions and 3 deletions

View File

@ -22,6 +22,9 @@ use URL;
class BudgetController extends Controller class BudgetController extends Controller
{ {
/**
*
*/
public function __construct() public function __construct()
{ {
View::share('title', 'Budgets'); View::share('title', 'Budgets');
@ -32,7 +35,6 @@ class BudgetController extends Controller
* @param Budget $budget * @param Budget $budget
* *
* @return \Illuminate\Http\JsonResponse * @return \Illuminate\Http\JsonResponse
* @throws Exception
*/ */
public function amount(Budget $budget, BudgetRepositoryInterface $repository) public function amount(Budget $budget, BudgetRepositoryInterface $repository)
{ {

View File

@ -120,10 +120,12 @@ class BudgetRepository implements BudgetRepositoryInterface
*/ */
public function updateLimitAmount(Budget $budget, Carbon $date, $amount) public function updateLimitAmount(Budget $budget, Carbon $date, $amount)
{ {
// there should be a budget limit for this startdate:
/** @var BudgetLimit $limit */ /** @var BudgetLimit $limit */
$limit = $budget->limitrepetitions()->where('limit_repetitions.startdate', $date)->first(['limit_repetitions.*']); $limit = $budget->budgetlimits()->where('budget_limits.startdate', $date)->first(['budget_limits.*']);
if (!$limit) { if (!$limit) {
// create one! // if not, create one!
$limit = new BudgetLimit; $limit = new BudgetLimit;
$limit->budget()->associate($budget); $limit->budget()->associate($budget);
$limit->startdate = $date; $limit->startdate = $date;
@ -131,6 +133,10 @@ class BudgetRepository implements BudgetRepositoryInterface
$limit->repeat_freq = 'monthly'; $limit->repeat_freq = 'monthly';
$limit->repeats = 0; $limit->repeats = 0;
$limit->save(); $limit->save();
// likewise, there should be a limit repetition to match the end date
// (which is always the end of the month) but that is caught by an event.
} else { } else {
if ($amount > 0) { if ($amount > 0) {
$limit->amount = $amount; $limit->amount = $amount;