mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Fixed a bug where limits and limit repetitions would not be updated and/or created because of double post calls and missing events.
This commit is contained in:
parent
15e99bd672
commit
4f4e6fac16
@ -40,7 +40,7 @@ class BudgetController extends BaseController
|
||||
/*
|
||||
* A newly stored limit also created a limit repetition.
|
||||
*/
|
||||
Event::fire('limits.store', [$limit]); // Still in use.
|
||||
Event::fire('limits.store', [$limit]); // TODO Nothing responds here!
|
||||
|
||||
} else {
|
||||
if ($amount > 0) {
|
||||
@ -49,7 +49,7 @@ class BudgetController extends BaseController
|
||||
/*
|
||||
* An updated limit also updates the associated limit repetitions.
|
||||
*/
|
||||
Event::fire('limits.update', [$limit]); // Still in use.
|
||||
Event::fire('limits.update', [$limit]); // TODO Nothing responds here!
|
||||
} else {
|
||||
$limit->delete();
|
||||
}
|
||||
|
64
app/lib/FireflyIII/Event/Budget.php
Normal file
64
app/lib/FireflyIII/Event/Budget.php
Normal file
@ -0,0 +1,64 @@
|
||||
<?php
|
||||
namespace FireflyIII\Event;
|
||||
|
||||
|
||||
use Illuminate\Database\QueryException;
|
||||
use Illuminate\Events\Dispatcher;
|
||||
|
||||
class Budget
|
||||
{
|
||||
|
||||
/**
|
||||
* @param \Limit $limit
|
||||
*/
|
||||
public function storeOrUpdateLimit(\Limit $limit)
|
||||
{
|
||||
/** @var \FireflyIII\Shared\Toolkit\Date $dateKit */
|
||||
$dateKit = \App::make('FireflyIII\Shared\Toolkit\Date');
|
||||
|
||||
|
||||
$end = $dateKit->addPeriod(clone $limit->startdate, $limit->repeat_freq, 0);
|
||||
$end->subDay();
|
||||
|
||||
$set = $limit->limitrepetitions()->where('startdate', $limit->startdate->format('Y-m-d'))->where('enddate', $end->format('Y-m-d'))->get();
|
||||
/*
|
||||
* Create new LimitRepetition:
|
||||
*/
|
||||
if ($set->count() == 0) {
|
||||
|
||||
$repetition = new \LimitRepetition();
|
||||
$repetition->startdate = $limit->startdate;
|
||||
$repetition->enddate = $end;
|
||||
$repetition->amount = $limit->amount;
|
||||
$repetition->limit()->associate($limit);
|
||||
|
||||
try {
|
||||
$repetition->save();
|
||||
} catch (QueryException $e) {
|
||||
\Log::error('Trying to save new Limitrepetition failed!');
|
||||
\Log::error($e->getMessage());
|
||||
}
|
||||
} else {
|
||||
if ($set->count() == 1) {
|
||||
/*
|
||||
* Update existing one.
|
||||
*/
|
||||
$repetition = $set->first();
|
||||
$repetition->amount = $limit->amount;
|
||||
$repetition->save();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Dispatcher $events
|
||||
*/
|
||||
public function subscribe(Dispatcher $events)
|
||||
{
|
||||
$events->listen('limits.store', 'FireflyIII\Event\Budget@storeOrUpdateLimit');
|
||||
$events->listen('limits.update', 'FireflyIII\Event\Budget@storeOrUpdateLimit');
|
||||
|
||||
}
|
||||
}
|
@ -89,6 +89,7 @@ require $framework . '/Illuminate/Foundation/start.php';
|
||||
//Event::subscribe('Firefly\Trigger\Recurring\EloquentRecurringTrigger');
|
||||
//Event::subscribe('Firefly\Trigger\Journals\EloquentJournalTrigger');
|
||||
Event::subscribe('FireflyIII\Event\Piggybank');
|
||||
Event::subscribe('FireflyIII\Event\Budget');
|
||||
|
||||
// TODO event that creates a relationship between transaction journals and recurring events when created.
|
||||
// TODO event that updates the relationship between transaction journals and recurring events when edited.
|
||||
|
@ -1,8 +1,8 @@
|
||||
$(function () {
|
||||
updateRanges();
|
||||
$('input[type="range"]').change(updateSingleRange);
|
||||
//$('input[type="range"]').change(updateSingleRange);
|
||||
$('input[type="range"]').on('input', updateSingleRange);
|
||||
$('input[type="number"]').on('change', updateSingleRange);
|
||||
//$('input[type="number"]').on('change', updateSingleRange);
|
||||
$('input[type="number"]').on('input', updateSingleRange);
|
||||
$('.updateIncome').on('click', updateIncome);
|
||||
|
||||
@ -56,6 +56,7 @@ function updateSingleRange(e) {
|
||||
|
||||
// send a post to Firefly to update the amount:
|
||||
console.log('Value is: ' + value);
|
||||
console.log('POST! with ID ' + id + ' AND value ' + value);
|
||||
$.post('budgets/amount/' + id, {amount: value}).success(function (data) {
|
||||
console.log('Budget ' + data.name + ' updated!');
|
||||
// update the link if relevant:
|
||||
|
Loading…
Reference in New Issue
Block a user