mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Alright for issue #6 a lot of things have been updated. Piggy banks can now be made "repeated" in a different form, viewed and edited; Firefly will properly trigger to make the "instances". Also the show-view is finished which doesn't do much but helps in seeing how it works. [skip ci]
This commit is contained in:
parent
12e5f80d80
commit
95c10a0a71
@ -1,25 +0,0 @@
|
||||
$(function () {
|
||||
|
||||
updatePiggyFields();
|
||||
$('input[name="repeats"]').on('change',updatePiggyFields);
|
||||
|
||||
});
|
||||
|
||||
function updatePiggyFields() {
|
||||
//var val = $('input[name="repeats"]').checked;
|
||||
|
||||
console.log('Repeating elements: ' + $('.repeat-piggy').length);
|
||||
console.log('Non-repeating elements: ' + $('.no-repeat-piggy').length);
|
||||
|
||||
if($('input[name="repeats"]').prop( "checked" )) {
|
||||
// checked, repeats!
|
||||
console.log('repeats!');
|
||||
$('.repeat-piggy').show();
|
||||
$('.no-repeat-piggy').hide();
|
||||
} else {
|
||||
console.log('no repeats!');
|
||||
// unchecked, does not repeat!
|
||||
$('.no-repeat-piggy').show();
|
||||
$('.repeat-piggy').hide();
|
||||
}
|
||||
}
|
@ -34,6 +34,9 @@ class PiggybankController extends BaseController
|
||||
return View::make('piggybanks.create-piggybank')->with('accounts', $accounts)->with('periods', $periods);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return $this
|
||||
*/
|
||||
public function createRepeated()
|
||||
{
|
||||
$periods = Config::get('firefly.piggybank_periods');
|
||||
@ -60,7 +63,9 @@ class PiggybankController extends BaseController
|
||||
*/
|
||||
public function destroy(Piggybank $piggyBank)
|
||||
{
|
||||
$piggyBank->delete();
|
||||
// TODO move to repository.
|
||||
$this->_repository->destroy($piggyBank);
|
||||
Event::fire('piggybanks.change');
|
||||
Session::flash('success', 'Piggy bank deleted.');
|
||||
|
||||
return Redirect::route('piggybanks.index');
|
||||
@ -74,8 +79,16 @@ class PiggybankController extends BaseController
|
||||
public function edit(Piggybank $piggyBank)
|
||||
{
|
||||
$accounts = $this->_accounts->getActiveDefaultAsSelectList();
|
||||
$periods = Config::get('firefly.piggybank_periods');
|
||||
if ($piggyBank->repeats == 1) {
|
||||
return View::make('piggybanks.edit-repeated')->with('piggybank', $piggyBank)->with('accounts', $accounts)
|
||||
->with('periods', $periods);
|
||||
} else {
|
||||
return View::make('piggybanks.edit-piggybank')->with('piggybank', $piggyBank)->with('accounts', $accounts)
|
||||
->with('periods', $periods);
|
||||
}
|
||||
|
||||
|
||||
return View::make('piggybanks.edit')->with('piggybank', $piggyBank)->with('accounts', $accounts);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -85,6 +98,8 @@ class PiggybankController extends BaseController
|
||||
{
|
||||
$countRepeating = $this->_repository->countRepeating();
|
||||
$countNonRepeating = $this->_repository->countNonrepeating();
|
||||
Event::fire('piggybanks.change'); // TODO remove
|
||||
|
||||
$piggybanks = $this->_repository->get();
|
||||
return View::make('piggybanks.index')->with('piggybanks', $piggybanks)
|
||||
->with('countRepeating', $countRepeating)
|
||||
@ -96,6 +111,7 @@ class PiggybankController extends BaseController
|
||||
*/
|
||||
public function show(Piggybank $piggyBank)
|
||||
{
|
||||
Event::fire('piggybanks.change'); // TODO remove
|
||||
return View::make('piggybanks.show')->with('piggyBank', $piggyBank);
|
||||
}
|
||||
|
||||
@ -109,12 +125,14 @@ class PiggybankController extends BaseController
|
||||
|
||||
// extend the data array with the settings needed to create a piggy bank:
|
||||
$data['repeats'] = 0;
|
||||
$data['rep_times'] = 0;
|
||||
$data['rep_times'] = 1;
|
||||
$data['rep_every'] = 1;
|
||||
$data['order'] = 0;
|
||||
|
||||
$piggyBank = $this->_repository->store($data);
|
||||
if (!is_null($piggyBank->id)) {
|
||||
Session::flash('success', 'New piggy bank "' . $piggyBank->name . '" created!');
|
||||
Event::fire('piggybanks.change');
|
||||
|
||||
return Redirect::route('piggybanks.index');
|
||||
|
||||
@ -138,19 +156,19 @@ class PiggybankController extends BaseController
|
||||
|
||||
// extend the data array with the settings needed to create a repeated:
|
||||
$data['repeats'] = 1;
|
||||
$data['startdate'] = new Carbon;
|
||||
$data['order'] = 0;
|
||||
|
||||
$piggyBank = $this->_repository->store($data);
|
||||
if ($piggyBank->validate()) {
|
||||
Session::flash('success', 'New piggy bank "' . $piggyBank->name . '" created!');
|
||||
Event::fire('piggybanks.change');
|
||||
|
||||
return Redirect::route('piggybanks.index');
|
||||
|
||||
} else {
|
||||
Session::flash('error', 'Could not save piggy bank: ' . $piggyBank->errors()->first());
|
||||
|
||||
return Redirect::route('piggybanks.create')->withInput();
|
||||
return Redirect::route('piggybanks.create.repeated')->withInput()->withErrors($piggyBank->errors());
|
||||
}
|
||||
|
||||
}
|
||||
@ -158,12 +176,12 @@ class PiggybankController extends BaseController
|
||||
/**
|
||||
* @return $this|\Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function update()
|
||||
public function update(Piggybank $piggyBank)
|
||||
{
|
||||
|
||||
$piggyBank = $this->_repository->update(Input::all());
|
||||
$piggyBank = $this->_repository->update($piggyBank, Input::all());
|
||||
if ($piggyBank->validate()) {
|
||||
Session::flash('success', 'Piggy bank "' . $piggyBank->name . '" updated.');
|
||||
Event::fire('piggybanks.change');
|
||||
|
||||
return Redirect::route('piggybanks.index');
|
||||
} else {
|
||||
@ -180,6 +198,7 @@ class PiggybankController extends BaseController
|
||||
*/
|
||||
public function updateAmount(Piggybank $piggybank)
|
||||
{
|
||||
Event::fire('piggybanks.change');
|
||||
$this->_repository->updateAmount($piggybank, Input::get('amount'));
|
||||
}
|
||||
}
|
@ -25,11 +25,12 @@ class CreatePiggybanksTable extends Migration
|
||||
$table->integer('account_id')->unsigned();
|
||||
$table->string('name', 100);
|
||||
$table->decimal('targetamount', 10, 2);
|
||||
$table->date('targetdate')->nullable();
|
||||
$table->date('startdate')->nullable();
|
||||
$table->date('targetdate')->nullable();
|
||||
$table->boolean('repeats');
|
||||
$table->enum('rep_length', ['day', 'week', 'month', 'year'])->nullable();
|
||||
$table->smallInteger('rep_times')->unsigned();
|
||||
$table->smallInteger('rep_every')->unsigned();
|
||||
$table->smallInteger('rep_times')->unsigned()->nullable();
|
||||
$table->enum('reminder', ['day', 'week', 'month', 'year'])->nullable();
|
||||
$table->smallInteger('reminder_skip')->unsigned();
|
||||
$table->integer('order')->unsigned();
|
||||
|
@ -17,10 +17,12 @@ class CreatePiggyInstance extends Migration {
|
||||
$table->increments('id');
|
||||
$table->timestamps();
|
||||
$table->integer('piggybank_id')->unsigned();
|
||||
$table->date('targetdate')->nullable();
|
||||
$table->date('startdate')->nullable();
|
||||
$table->date('targetdate')->nullable();
|
||||
$table->decimal('currentamount',10,2);
|
||||
|
||||
$table->unique(['piggybank_id','startdate','targetdate']);
|
||||
|
||||
// connect instance to piggybank.
|
||||
$table->foreign('piggybank_id')
|
||||
->references('id')->on('piggybanks')
|
||||
|
@ -40,6 +40,18 @@ class EloquentPiggybankRepository implements PiggybankRepositoryInterface
|
||||
)->where('repeats', 1)->count();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Piggybank $piggyBank
|
||||
*
|
||||
* @return mixed|void
|
||||
*/
|
||||
public function destroy(\Piggybank $piggyBank)
|
||||
{
|
||||
$piggyBank->delete();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $piggyBankId
|
||||
*
|
||||
@ -57,9 +69,7 @@ class EloquentPiggybankRepository implements PiggybankRepositoryInterface
|
||||
*/
|
||||
public function get()
|
||||
{
|
||||
return \Piggybank::with('account')->leftJoin('accounts', 'accounts.id', '=', 'piggybanks.account_id')->where(
|
||||
'accounts.user_id', \Auth::user()->id
|
||||
)->get(['piggybanks.*']);
|
||||
return \Auth::user()->piggybanks()->with(['account', 'piggybankrepetitions'])->get();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -90,12 +100,12 @@ class EloquentPiggybankRepository implements PiggybankRepositoryInterface
|
||||
if ($piggyBank->validate()) {
|
||||
if (!is_null($piggyBank->targetdate) && $piggyBank->targetdate < $today) {
|
||||
$piggyBank->errors()->add('targetdate', 'Target date cannot be in the past.');
|
||||
|
||||
return $piggyBank;
|
||||
}
|
||||
|
||||
if (!is_null($piggyBank->reminder) && !is_null($piggyBank->targetdate)) {
|
||||
// first period for reminder is AFTER target date.
|
||||
// just flash a warning
|
||||
$reminderSkip = $piggyBank->reminder_skip < 1 ? 1 : intval($piggyBank->reminder_skip);
|
||||
$firstReminder = new Carbon;
|
||||
switch ($piggyBank->reminder) {
|
||||
@ -116,7 +126,10 @@ class EloquentPiggybankRepository implements PiggybankRepositoryInterface
|
||||
break;
|
||||
}
|
||||
if ($firstReminder > $piggyBank->targetdate) {
|
||||
$piggyBank->errors()->add('reminder', 'The reminder has been set to remind you after the piggy bank will expire.');
|
||||
$piggyBank->errors()->add(
|
||||
'reminder', 'The reminder has been set to remind you after the piggy bank will expire.'
|
||||
);
|
||||
|
||||
return $piggyBank;
|
||||
}
|
||||
}
|
||||
@ -127,26 +140,51 @@ class EloquentPiggybankRepository implements PiggybankRepositoryInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Piggybank $piggy
|
||||
* @param $data
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function update($data)
|
||||
public function update(\Piggybank $piggy, $data)
|
||||
{
|
||||
$piggyBank = $this->find($data['id']);
|
||||
if ($piggyBank) {
|
||||
/** @var \Firefly\Storage\Account\AccountRepositoryInterface $accounts */
|
||||
$accounts = \App::make('Firefly\Storage\Account\AccountRepositoryInterface');
|
||||
$account = $accounts->find($data['account_id']);
|
||||
// update piggybank accordingly:
|
||||
$piggyBank->name = $data['name'];
|
||||
$piggyBank->target = floatval($data['target']);
|
||||
$piggyBank->account()->associate($account);
|
||||
if ($piggyBank->validate()) {
|
||||
$piggyBank->save();
|
||||
}
|
||||
$account = isset($data['account_id']) ? $accounts->find($data['account_id']) : null;
|
||||
|
||||
if (!is_null($account)) {
|
||||
$piggy->account()->associate($account);
|
||||
}
|
||||
|
||||
return $piggyBank;
|
||||
$piggy->name = $data['name'];
|
||||
$piggy->targetamount = floatval($data['targetamount']);
|
||||
$piggy->reminder = isset($data['reminder']) && $data['reminder'] != 'none' ? $data['reminder'] : null;
|
||||
$piggy->reminder_skip = $data['reminder_skip'];
|
||||
$piggy->targetdate = strlen($data['targetdate']) > 0 ? new Carbon($data['targetdate']) : null;
|
||||
$piggy->startdate
|
||||
= isset($data['startdate']) && strlen($data['startdate']) > 0 ? new Carbon($data['startdate']) : null;
|
||||
|
||||
// everything we can update for NON repeating piggy banks:
|
||||
if ($piggy->repeats == 0) {
|
||||
// if non-repeating there is only one PiggyBank instance and we can delete it safely.
|
||||
// it will be recreated.
|
||||
$piggy->piggybankrepetitions()->first()->delete();
|
||||
} else {
|
||||
// we can delete all of them, because reasons
|
||||
foreach ($piggy->piggybankrepetitions()->get() as $rep) {
|
||||
$rep->delete();
|
||||
}
|
||||
|
||||
$piggy->rep_every = intval($data['rep_every']);
|
||||
$piggy->rep_length = $data['rep_length'];
|
||||
}
|
||||
if ($piggy->validate()) {
|
||||
// check the things we check for new piggies
|
||||
$piggy->save();
|
||||
}
|
||||
|
||||
|
||||
return $piggy;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -11,6 +11,28 @@ namespace Firefly\Storage\Piggybank;
|
||||
interface PiggybankRepositoryInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function count();
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function countNonrepeating();
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function countRepeating();
|
||||
|
||||
/**
|
||||
* @param \Piggybank $piggyBank
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function destroy(\Piggybank $piggyBank);
|
||||
|
||||
/**
|
||||
* @param $piggyBankId
|
||||
*
|
||||
@ -21,17 +43,7 @@ interface PiggybankRepositoryInterface
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function count();
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function countRepeating();
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function countNonrepeating();
|
||||
public function get();
|
||||
|
||||
/**
|
||||
* @param $data
|
||||
@ -41,9 +53,12 @@ interface PiggybankRepositoryInterface
|
||||
public function store($data);
|
||||
|
||||
/**
|
||||
* @param \Piggybank $piggy
|
||||
* @param $data
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function get();
|
||||
public function update(\Piggybank $piggy, $data);
|
||||
|
||||
/**
|
||||
* @param \Piggybank $piggyBank
|
||||
@ -53,11 +68,4 @@ interface PiggybankRepositoryInterface
|
||||
*/
|
||||
public function updateAmount(\Piggybank $piggyBank, $amount);
|
||||
|
||||
/**
|
||||
* @param $data
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function update($data);
|
||||
|
||||
}
|
114
app/lib/Firefly/Trigger/Piggybanks/EloquentPiggybankTrigger.php
Normal file
114
app/lib/Firefly/Trigger/Piggybanks/EloquentPiggybankTrigger.php
Normal file
@ -0,0 +1,114 @@
|
||||
<?php
|
||||
|
||||
namespace Firefly\Trigger\Piggybanks;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Database\QueryException;
|
||||
use Illuminate\Events\Dispatcher;
|
||||
|
||||
/**
|
||||
* Class EloquentPiggybankTrigger
|
||||
*
|
||||
* @package Firefly\Trigger\Piggybanks
|
||||
*/
|
||||
class EloquentPiggybankTrigger
|
||||
{
|
||||
/**
|
||||
* @param Dispatcher $events
|
||||
*/
|
||||
public function subscribe(Dispatcher $events)
|
||||
{
|
||||
$events->listen(
|
||||
'piggybanks.change', 'Firefly\Trigger\Piggybanks\EloquentPiggybankTrigger@updatePiggybankRepetitions'
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function updatePiggybankRepetitions()
|
||||
{
|
||||
// grab all piggy banks.
|
||||
$piggybanks = \Auth::user()->piggybanks()->with(['piggybankrepetitions'])->where('repeats', 0)->get();
|
||||
$today = new Carbon;
|
||||
/** @var \Piggybank $piggy */
|
||||
foreach ($piggybanks as $piggy) {
|
||||
if (count($piggy->piggybankrepetitions) == 0) {
|
||||
$rep = new \PiggybankRepetition;
|
||||
$rep->piggybank()->associate($piggy);
|
||||
$rep->targetdate = $piggy->targetdate;
|
||||
$rep->startdate = $piggy->startdate;
|
||||
$rep->currentamount = 0;
|
||||
try {
|
||||
$rep->save();
|
||||
} catch (QueryException $e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
unset($piggy, $piggybanks, $rep);
|
||||
|
||||
// grab all repeated transactions.
|
||||
$repeatedExpenses = \Auth::user()->piggybanks()->with(['piggybankrepetitions'])->where('repeats', 1)->get();
|
||||
/** @var \Piggybank $repeated */
|
||||
foreach ($repeatedExpenses as $repeated) {
|
||||
// loop from start to today or something
|
||||
$rep = new \PiggybankRepetition;
|
||||
$rep->piggybank()->associate($repeated);
|
||||
$rep->startdate = $repeated->startdate;
|
||||
$rep->targetdate = $repeated->targetdate;
|
||||
$rep->currentamount = 0;
|
||||
try {
|
||||
\Log::debug(
|
||||
'Creating initial rep ('.$repeated->name.') (from ' . ($rep->startdate ? $rep->startdate->format('d-m-Y')
|
||||
: 'NULL') . ' to '
|
||||
. ($rep->targetdate ? $rep->targetdate->format('d-m-Y') : 'NULL') . ')'
|
||||
);
|
||||
$rep->save();
|
||||
} catch (QueryException $e) {
|
||||
\Log::error('FAILED initital repetition.');
|
||||
}
|
||||
unset($rep);
|
||||
|
||||
if ($repeated->targetdate <= $today) {
|
||||
// add 1 month to startdate, or maybe X period, like 3 weeks.
|
||||
$startTarget = clone $repeated->targetdate;
|
||||
while ($startTarget <= $today) {
|
||||
$startCurrent = clone $startTarget;
|
||||
|
||||
// add some kind of period to start current making $endCurrent.
|
||||
$endCurrent = clone $startCurrent;
|
||||
switch ($repeated->rep_length) {
|
||||
default:
|
||||
die('No rep lengt!');
|
||||
break;
|
||||
case 'day':
|
||||
$endCurrent->addDays($repeated->rep_every);
|
||||
break;
|
||||
case 'week':
|
||||
$endCurrent->addWeeks($repeated->rep_every);
|
||||
break;
|
||||
case 'month':
|
||||
$endCurrent->addMonths($repeated->rep_every);
|
||||
break;
|
||||
case 'year':
|
||||
$endCurrent->addYears($repeated->rep_every);
|
||||
break;
|
||||
}
|
||||
|
||||
$rep = new \PiggybankRepetition;
|
||||
$rep->piggybank()->associate($repeated);
|
||||
$rep->startdate = $startCurrent;
|
||||
$rep->targetdate = $endCurrent;
|
||||
$rep->currentamount = 0;
|
||||
$startTarget = $endCurrent;
|
||||
try {
|
||||
$rep->save();
|
||||
} catch (QueryException $e) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -9,59 +9,62 @@ use LaravelBook\Ardent\Ardent as Ardent;
|
||||
* @property \Carbon\Carbon $created_at
|
||||
* @property \Carbon\Carbon $updated_at
|
||||
* @property integer $account_id
|
||||
* @property \Carbon\Carbon $targetdate
|
||||
* @property string $name
|
||||
* @property float $amount
|
||||
* @property float $target
|
||||
* @property float $targetamount
|
||||
* @property \Carbon\Carbon $targetdate
|
||||
* @property \Carbon\Carbon $startdate
|
||||
* @property boolean $repeats
|
||||
* @property string $rep_length
|
||||
* @property integer $rep_every
|
||||
* @property integer $rep_times
|
||||
* @property string $reminder
|
||||
* @property integer $reminder_skip
|
||||
* @property integer $order
|
||||
* @property-read \Account $account
|
||||
* @property-read \Illuminate\Database\Eloquent\Collection|\PiggybankRepetition[] $piggybankrepetitions
|
||||
* @method static \Illuminate\Database\Query\Builder|\Piggybank whereId($value)
|
||||
* @method static \Illuminate\Database\Query\Builder|\Piggybank whereCreatedAt($value)
|
||||
* @method static \Illuminate\Database\Query\Builder|\Piggybank whereUpdatedAt($value)
|
||||
* @method static \Illuminate\Database\Query\Builder|\Piggybank whereAccountId($value)
|
||||
* @method static \Illuminate\Database\Query\Builder|\Piggybank whereTargetdate($value)
|
||||
* @method static \Illuminate\Database\Query\Builder|\Piggybank whereName($value)
|
||||
* @method static \Illuminate\Database\Query\Builder|\Piggybank whereAmount($value)
|
||||
* @method static \Illuminate\Database\Query\Builder|\Piggybank whereTarget($value)
|
||||
* @method static \Illuminate\Database\Query\Builder|\Piggybank whereOrder($value)
|
||||
* @property float $targetamount
|
||||
* @property string $startdate
|
||||
* @property boolean $repeats
|
||||
* @property string $rep_length
|
||||
* @property integer $rep_times
|
||||
* @property string $reminder
|
||||
* @method static \Illuminate\Database\Query\Builder|\Piggybank whereTargetamount($value)
|
||||
* @method static \Illuminate\Database\Query\Builder|\Piggybank whereTargetdate($value)
|
||||
* @method static \Illuminate\Database\Query\Builder|\Piggybank whereStartdate($value)
|
||||
* @method static \Illuminate\Database\Query\Builder|\Piggybank whereRepeats($value)
|
||||
* @method static \Illuminate\Database\Query\Builder|\Piggybank whereRepLength($value)
|
||||
* @method static \Illuminate\Database\Query\Builder|\Piggybank whereRepEvery($value)
|
||||
* @method static \Illuminate\Database\Query\Builder|\Piggybank whereRepTimes($value)
|
||||
* @method static \Illuminate\Database\Query\Builder|\Piggybank whereReminder($value)
|
||||
* @method static \Illuminate\Database\Query\Builder|\Piggybank whereReminderSkip($value)
|
||||
* @method static \Illuminate\Database\Query\Builder|\Piggybank whereOrder($value)
|
||||
*/
|
||||
class Piggybank extends Ardent
|
||||
{
|
||||
public static $rules
|
||||
= [
|
||||
'account_id' => 'required|exists:accounts,id',
|
||||
'name' => 'required|between:1,255',
|
||||
'targetamount' => 'required|min:0',
|
||||
'targetdate' => 'date',
|
||||
'startdate' => 'date',
|
||||
'repeats' => 'required|between:0,1',
|
||||
'rep_length' => 'in:day,week,month,year',
|
||||
'rep_times' => 'required|min:0|max:100',
|
||||
'reminder' => 'in:day,week,month,year',
|
||||
'reminder_skip' => 'required|min:0|max:100',
|
||||
'order' => 'required:min:1',
|
||||
'account_id' => 'required|exists:accounts,id', // link to Account
|
||||
'name' => 'required|between:1,255', // name
|
||||
'targetamount' => 'required|min:0', // amount you want to save
|
||||
'startdate' => 'date', // when you started
|
||||
'targetdate' => 'date', // when its due
|
||||
'repeats' => 'required|between:0,1', // does it repeat?
|
||||
'rep_length' => 'in:day,week,month,year', // how long is the period?
|
||||
'rep_every' => 'required|min:1|max:100', // how often does it repeat? every 3 years.
|
||||
'rep_times' => 'min:1|max:100', // how many times do you want to save this amount? eg. 3 times
|
||||
'reminder' => 'in:day,week,month,year', // want a reminder to put money in this?
|
||||
'reminder_skip' => 'required|min:0|max:100', // every week? every 2 months?
|
||||
'order' => 'required:min:1', // not yet used.
|
||||
];
|
||||
public $fillable
|
||||
= [
|
||||
'account_id',
|
||||
'name',
|
||||
'targetamount',
|
||||
'targetdate',
|
||||
'startdate',
|
||||
'targetdate',
|
||||
'repeats',
|
||||
'rep_length',
|
||||
'rep_every',
|
||||
'rep_times',
|
||||
'reminder',
|
||||
'reminder_skip',
|
||||
@ -81,11 +84,12 @@ class Piggybank extends Ardent
|
||||
'account_id' => 'factory|Account',
|
||||
'name' => 'string',
|
||||
'targetamount' => 'required|min:0',
|
||||
'targetdate' => $start,
|
||||
'startdate' => $today,
|
||||
'targetdate' => $start,
|
||||
'repeats' => 0,
|
||||
'rep_length' => null,
|
||||
'rep_times' => 0,
|
||||
'rep_every' => 0,
|
||||
'reminder' => null,
|
||||
'reminder_skip' => 0,
|
||||
'order' => 1,
|
||||
@ -105,9 +109,95 @@ class Piggybank extends Ardent
|
||||
*/
|
||||
public function getDates()
|
||||
{
|
||||
return ['created_at', 'updated_at', 'targetdate'];
|
||||
return ['created_at', 'updated_at', 'targetdate','startdate'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Firefly shouldn't create piggybank repetions that completely
|
||||
* lie in the future, so we should be able to safely grab the "latest"
|
||||
* one and use that to calculate when the user will be reminded.
|
||||
*/
|
||||
public function nextReminderDate()
|
||||
{
|
||||
if(is_null($this->reminder)) {
|
||||
return null;
|
||||
}
|
||||
/** @var \PiggybankRepetition $rep */
|
||||
$rep = $this->currentRelevantRep();
|
||||
if($rep) {
|
||||
$today = new Carbon;
|
||||
if(is_null($rep->startdate)) {
|
||||
switch($this->reminder) {
|
||||
case 'day':
|
||||
return $today;
|
||||
break;
|
||||
case 'week':
|
||||
return $today->endOfWeek();
|
||||
break;
|
||||
case 'month':
|
||||
return $today->endOfMonth();
|
||||
break;
|
||||
case 'year':
|
||||
return $today->endOfYear();
|
||||
break;
|
||||
|
||||
}
|
||||
} else {
|
||||
// start with the start date
|
||||
// when its bigger than today, return it:
|
||||
$start = clone $rep->startdate;
|
||||
while($start <= $today) {
|
||||
switch($this->reminder) {
|
||||
case 'day':
|
||||
$start->addDay();
|
||||
break;
|
||||
case 'week':
|
||||
$start->addWeek();
|
||||
break;
|
||||
case 'month':
|
||||
$start->addMonth();
|
||||
break;
|
||||
case 'year':
|
||||
$start->addYear();
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
return $start;
|
||||
}
|
||||
// if start date is null, simple switch on
|
||||
// the reminder period (if any) and go to the end of the period.
|
||||
|
||||
// otherwise, keep jumping until we are past today.
|
||||
}
|
||||
|
||||
|
||||
return new Carbon;
|
||||
}
|
||||
|
||||
/**
|
||||
* Grabs the PiggyBankRepetition that's currently relevant / active
|
||||
*/
|
||||
public function currentRelevantRep() {
|
||||
return $this->piggybankrepetitions()
|
||||
->where(function ($q) {
|
||||
$today = new Carbon;
|
||||
$q->whereNull('startdate');
|
||||
$q->orWhere('startdate','<=',$today->format('Y-m-d'));
|
||||
})
|
||||
->where(function ($q) {
|
||||
$today = new Carbon;
|
||||
$q->whereNull('targetdate');
|
||||
$q->orWhere('targetdate','>=',$today->format('Y-m-d'));
|
||||
})
|
||||
->first();
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
*/
|
||||
public function piggybankrepetitions()
|
||||
{
|
||||
return $this->hasMany('PiggybankRepetition');
|
||||
|
@ -63,4 +63,5 @@ class PiggybankRepetition extends Ardent
|
||||
return $this->belongsTo('Piggybank');
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -202,7 +202,7 @@ Route::group(['before' => 'csrf|auth'], function () {
|
||||
// piggy bank controller
|
||||
Route::post('/piggybanks/store/piggybank',['uses' => 'PiggybankController@storePiggybank','as' => 'piggybanks.store.piggybank']);
|
||||
Route::post('/piggybanks/store/repeated',['uses' => 'PiggybankController@storeRepeated','as' => 'piggybanks.store.repeated']);
|
||||
Route::post('/piggybanks/update', ['uses' => 'PiggybankController@update','as' => 'piggybanks.update']);
|
||||
Route::post('/piggybanks/update/{piggybank}', ['uses' => 'PiggybankController@update','as' => 'piggybanks.update']);
|
||||
Route::post('/piggybanks/destroy/{piggybank}', ['uses' => 'PiggybankController@destroy','as' => 'piggybanks.destroy']);
|
||||
|
||||
// preferences controller
|
||||
|
@ -72,9 +72,9 @@
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
{{ Form::label('rep_times', 'Repeat every', ['class' => 'col-sm-4 control-label'])}}
|
||||
{{ Form::label('rep_every', 'Repeat every', ['class' => 'col-sm-4 control-label'])}}
|
||||
<div class="col-sm-8">
|
||||
<input type="number" step="1" min="1" value="{{Input::old('rep_times') ?: 1}}" style="width:50px;display:inline;" max="100" name="rep_times" class="form-control" />
|
||||
<input type="number" step="1" min="1" value="{{Input::old('rep_every') ?: 1}}" style="width:50px;display:inline;" max="100" name="rep_every" class="form-control" />
|
||||
|
||||
<select class="form-control" name="rep_length" style="width:150px;display: inline">
|
||||
@foreach($periods as $period)
|
||||
@ -97,6 +97,19 @@
|
||||
|
||||
<h4>Optional fields</h4>
|
||||
|
||||
<div class="form-group">
|
||||
{{ Form::label('startdate', 'Start date', ['class' => 'col-sm-4 control-label'])}}
|
||||
<div class="col-sm-8">
|
||||
<input type="date" name="startdate" value="{{Input::old('startdate') ?: date('Y-m-d')}}"
|
||||
class="form-control"/>
|
||||
@if($errors->has('startdate'))
|
||||
<p class="text-danger">{{$errors->first('startdate')}}</p>
|
||||
@else
|
||||
<span class="help-block">This date indicates when you start(ed) saving money for this piggy bank. This field defaults to today and you should keep it on today.</span>
|
||||
@endif
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
{{ Form::label('reminder', 'Remind you every', ['class' => 'col-sm-4 control-label'])}}
|
||||
<div class="col-sm-8">
|
||||
@ -146,7 +159,7 @@
|
||||
|
||||
<div class="form-group">
|
||||
<div class="col-sm-offset-4 col-sm-8">
|
||||
<button type="submit" class="btn btn-default btn-success">Create the piggy bank</button>
|
||||
<button type="submit" class="btn btn-default btn-success">Create the repeated expense</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -29,11 +29,7 @@
|
||||
<div class="form-group">
|
||||
<div class="col-sm-8">
|
||||
<input type="submit" name="submit" value="Remove piggy bank" class="btn btn-danger" />
|
||||
@if(Input::get('from') == 'date')
|
||||
<a href="{{route('budgets.index')}}" class="btn-default btn">Cancel</a>
|
||||
@else
|
||||
<a href="{{route('budgets.index.budget')}}" class="btn-default btn">Cancel</a>
|
||||
@endif
|
||||
<a href="{{route('piggybanks.index')}}" class="btn-default btn">Cancel</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
138
app/views/piggybanks/edit-piggybank.blade.php
Normal file
138
app/views/piggybanks/edit-piggybank.blade.php
Normal file
@ -0,0 +1,138 @@
|
||||
@extends('layouts.default')
|
||||
@section('content')
|
||||
<div class="row">
|
||||
<div class="col-lg-12 col-md-12 col-sm-12">
|
||||
<h1>Firefly
|
||||
<small>Edit piggy bank "{{{$piggybank->name}}}"</small>
|
||||
</h1>
|
||||
<p class="lead">Use piggy banks to save for a one-time goal.</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{{Form::open(['class' => 'form-horizontal','url' => route('piggybanks.update',$piggybank->id)])}}
|
||||
|
||||
<div class="row">
|
||||
<div class="col-lg-6 col-md-12 col-sm-6">
|
||||
<h4>Mandatory fields</h4>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="name" class="col-sm-4 control-label">Name</label>
|
||||
<div class="col-sm-8">
|
||||
<input type="text" name="name" class="form-control" id="name" value="{{Input::old('name') ?: $piggybank->name}}" placeholder="{{{$piggybank->name}}}">
|
||||
@if($errors->has('name'))
|
||||
<p class="text-danger">{{$errors->first('name')}}</p>
|
||||
@else
|
||||
<span class="help-block">For example: new bike, new camera</span>
|
||||
@endif
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="account_id" class="col-sm-4 control-label">
|
||||
Saving account
|
||||
</label>
|
||||
<div class="col-sm-8">
|
||||
{{Form::select('account_id',$accounts,Input::old('account_id') ?: $piggybank->account_id,['class' => 'form-control'])}}
|
||||
@if($errors->has('account_id'))
|
||||
<p class="text-danger">{{$errors->first('account_id')}}</p>
|
||||
@else
|
||||
<span class="help-block">Indicate on which account you've got your savings.</span>
|
||||
@endif
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
{{ Form::label('targetamount', 'Target amount', ['class' => 'col-sm-4 control-label'])}}
|
||||
<div class="col-sm-8">
|
||||
<div class="input-group">
|
||||
<span class="input-group-addon">€</span>
|
||||
{{Form::input('number','targetamount', Input::old('targetamount') ?: $piggybank->targetamount, ['step' => 'any', 'min' => '1', 'class' => 'form-control'])}}
|
||||
</div>
|
||||
|
||||
@if($errors->has('targetamount'))
|
||||
<p class="text-danger">{{$errors->first('targetamount')}}</p>
|
||||
@else
|
||||
<span class="help-block">How much money do you need to save?</span>
|
||||
@endif
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-lg-6 col-md-12 col-sm-6">
|
||||
<h4>Optional fields</h4>
|
||||
|
||||
|
||||
<div class="form-group">
|
||||
{{ Form::label('startdate', 'Start date', ['class' => 'col-sm-4 control-label'])}}
|
||||
<div class="col-sm-8">
|
||||
<input type="date" name="startdate" value="{{Input::old('startdate') ?: $piggybank->startdate->format('Y-m-d')}}"
|
||||
class="form-control"/>
|
||||
@if($errors->has('startdate'))
|
||||
<p class="text-danger">{{$errors->first('startdate')}}</p>
|
||||
@else
|
||||
<span class="help-block">This date indicates when you start(ed) saving money for this piggy bank. This field defaults to today and you should keep it on today.</span>
|
||||
@endif
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
{{ Form::label('targetdate', 'Target date', ['class' => 'col-sm-4 control-label'])}}
|
||||
<div class="col-sm-8">
|
||||
@if(is_null($piggybank->targetdate))
|
||||
<input type="date" name="targetdate" value="{{Input::old('targetdate') ?: ''}}"
|
||||
class="form-control"/>
|
||||
@else
|
||||
<input type="date" name="targetdate" value="{{Input::old('targetdate') ?: $piggybank->targetdate->format('Y-m-d')}}"
|
||||
class="form-control"/>
|
||||
@endif
|
||||
@if($errors->has('targetdate'))
|
||||
<p class="text-danger">{{$errors->first('targetdate')}}</p>
|
||||
@else
|
||||
<span class="help-block">If this piggy bank has a dead line, enter it here.</span>
|
||||
@endif
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
{{ Form::label('reminder', 'Remind you every', ['class' => 'col-sm-4 control-label'])}}
|
||||
<div class="col-sm-8">
|
||||
<input type="number" step="1" min="1" value="{{Input::old('reminder_skip') ?: $piggybank->reminder_skip}}" style="width:50px;display:inline;" max="100" name="reminder_skip" class="form-control" />
|
||||
|
||||
<select class="form-control" name="reminder" style="width:150px;display: inline">
|
||||
<option value="none" label="do not remind me">do not remind me</option>
|
||||
@foreach($periods as $period)
|
||||
@if($period == $piggybank->reminder)
|
||||
<option value="{{$period}}" label="{{$period}}" selected="selected">{{$period}}</option>
|
||||
@else
|
||||
<option value="{{$period}}" label="{{$period}}">{{$period}}</option>
|
||||
@endif
|
||||
@endforeach
|
||||
</select>
|
||||
@if($errors->has('reminder'))
|
||||
<p class="text-danger">{{$errors->first('reminder')}}</p>
|
||||
@else
|
||||
<span class="help-block">Enter a number and a period and Firefly will remind you to add money
|
||||
to this piggy bank every now and then.</span>
|
||||
@endif
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-lg-6 col-md-12 col-sm-6">
|
||||
|
||||
<div class="form-group">
|
||||
<div class="col-sm-offset-4 col-sm-8">
|
||||
<button type="submit" class="btn btn-default btn-success">Update the piggy bank</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{{Form::close()}}
|
||||
@stop
|
||||
@section('scripts')
|
||||
<?php echo javascript_include_tag('piggybanks-create'); ?>
|
||||
@stop
|
174
app/views/piggybanks/edit-repeated.blade.php
Normal file
174
app/views/piggybanks/edit-repeated.blade.php
Normal file
@ -0,0 +1,174 @@
|
||||
@extends('layouts.default')
|
||||
@section('content')
|
||||
<div class="row">
|
||||
<div class="col-lg-12 col-md-12 col-sm-12">
|
||||
<h1>Firefly
|
||||
<small>Edit repeated expense "{{{$piggybank->name}}}"</small>
|
||||
</h1>
|
||||
<p class="lead">Create repeated expenses to keep track of long-term planned expenses</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{{Form::open(['class' => 'form-horizontal','url' => route('piggybanks.update',$piggybank->id)])}}
|
||||
|
||||
<div class="row">
|
||||
<div class="col-lg-6 col-md-12 col-sm-6">
|
||||
<h4>Mandatory fields</h4>
|
||||
|
||||
|
||||
<div class="form-group">
|
||||
<label for="name" class="col-sm-4 control-label">Name</label>
|
||||
<div class="col-sm-8">
|
||||
<input type="text" name="name" class="form-control" id="name" value="{{Input::old('name') ?: $piggybank->name}}" placeholder="Name">
|
||||
@if($errors->has('name'))
|
||||
<p class="text-danger">{{$errors->first('name')}}</p>
|
||||
@else
|
||||
<span class="help-block">For example: new bike, new camera</span>
|
||||
@endif
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="account_id" class="col-sm-4 control-label">
|
||||
Saving account
|
||||
</label>
|
||||
<div class="col-sm-8">
|
||||
{{Form::select('account_id',$accounts,Input::old('account_id') ?: $piggybank->account_id,['class' => 'form-control'])}}
|
||||
@if($errors->has('account_id'))
|
||||
<p class="text-danger">{{$errors->first('account_id')}}</p>
|
||||
@else
|
||||
<span class="help-block">Indicate on which account you've got your savings.</span>
|
||||
@endif
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
{{ Form::label('targetamount', 'Target amount', ['class' => 'col-sm-4 control-label'])}}
|
||||
<div class="col-sm-8">
|
||||
<div class="input-group">
|
||||
<span class="input-group-addon">€</span>
|
||||
{{Form::input('number','targetamount', Input::old('targetamount') ?: $piggybank->targetamount, ['step' => 'any', 'min' => '1', 'class' => 'form-control'])}}
|
||||
</div>
|
||||
|
||||
@if($errors->has('targetamount'))
|
||||
<p class="text-danger">{{$errors->first('targetamount')}}</p>
|
||||
@else
|
||||
<span class="help-block">How much money do you need to save?</span>
|
||||
@endif
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
{{ Form::label('targetdate', 'Target date', ['class' => 'col-sm-4 control-label'])}}
|
||||
<div class="col-sm-8">
|
||||
<input type="date" name="targetdate" value="{{Input::old('targetdate') ?: $piggybank->targetdate->format('Y-m-d')}}"
|
||||
class="form-control"/>
|
||||
@if($errors->has('targetdate'))
|
||||
<p class="text-danger">{{$errors->first('targetdate')}}</p>
|
||||
@else
|
||||
<span class="help-block">A deadline is needed to properly repeat this repeated expesnse.</span>
|
||||
@endif
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
{{ Form::label('rep_every', 'Repeat every', ['class' => 'col-sm-4 control-label'])}}
|
||||
<div class="col-sm-8">
|
||||
<input type="number" step="1" min="1" value="{{Input::old('rep_every') ?: $piggybank->rep_every}}" style="width:50px;display:inline;" max="100" name="rep_every" class="form-control" />
|
||||
|
||||
<select class="form-control" name="rep_length" style="width:150px;display: inline">
|
||||
@foreach($periods as $period)
|
||||
@if($period == $piggybank->rep_length || Input::old('reminder') == $period)
|
||||
<option value="{{$period}}" label="{{$period}}" selected="selected">{{$period}}</option>
|
||||
@else
|
||||
<option value="{{$period}}" label="{{$period}}">{{$period}}</option>
|
||||
@endif
|
||||
@endforeach
|
||||
</select>
|
||||
@if($errors->has('rep_length'))
|
||||
<p class="text-danger">{{$errors->first('rep_length')}}</p>
|
||||
@else
|
||||
<span class="help-block">Something about every X years bla bla bla.</span>
|
||||
@endif
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-lg-6 col-md-12 col-sm-6">
|
||||
|
||||
<h4>Optional fields</h4>
|
||||
<div class="form-group">
|
||||
{{ Form::label('startdate', 'Start date', ['class' => 'col-sm-4 control-label'])}}
|
||||
<div class="col-sm-8">
|
||||
<input type="date" name="startdate" value="{{Input::old('startdate') ?: $piggybank->startdate->format('Y-m-d')}}"
|
||||
class="form-control"/>
|
||||
@if($errors->has('startdate'))
|
||||
<p class="text-danger">{{$errors->first('startdate')}}</p>
|
||||
@else
|
||||
<span class="help-block">This date indicates when you start(ed) saving money for this piggy bank. This field defaults to today and you should keep it on today.</span>
|
||||
@endif
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
{{ Form::label('reminder', 'Remind you every', ['class' => 'col-sm-4 control-label'])}}
|
||||
<div class="col-sm-8">
|
||||
<input type="number" step="1" min="1" value="{{Input::old('reminder_skip') ?: $piggybank->reminder_skip}}" style="width:50px;display:inline;" max="100" name="reminder_skip" class="form-control" />
|
||||
|
||||
<select class="form-control" name="reminder" style="width:150px;display: inline">
|
||||
<option value="none" label="do not remind me">do not remind me</option>
|
||||
@foreach($periods as $period)
|
||||
@if($period == $piggybank->reminder)
|
||||
<option value="{{$period}}" label="{{$period}}" selected="selected">{{$period}}</option>
|
||||
@else
|
||||
<option value="{{$period}}" label="{{$period}}">{{$period}}</option>
|
||||
@endif
|
||||
@endforeach
|
||||
</select>
|
||||
@if($errors->has('reminder'))
|
||||
<p class="text-danger">{{$errors->first('reminder')}}</p>
|
||||
@else
|
||||
<span class="help-block">Enter a number and a period and Firefly will remind you to save money
|
||||
for this repeated expense every now and then.</span>
|
||||
@endif
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
<!--
|
||||
<div class="form-group">
|
||||
{{ Form::label('targetdate', 'Target date', ['class' => 'col-sm-4 control-label'])}}
|
||||
<div class="col-sm-8">
|
||||
{{ Form::input('date','targetdate', Input::old('targetdate') ?: '', ['class'
|
||||
=> 'form-control']) }}
|
||||
@if($errors->has('targetdate'))
|
||||
<p class="text-danger">{{$errors->first('targetdate')}}</p>
|
||||
@else
|
||||
<span class="help-block">
|
||||
If you want to, set a target date. This will inform you how much money you should save to
|
||||
get to the target amount.
|
||||
</span>
|
||||
@endif
|
||||
</div>
|
||||
</div>
|
||||
-->
|
||||
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-lg-6 col-md-12 col-sm-6">
|
||||
|
||||
<div class="form-group">
|
||||
<div class="col-sm-offset-4 col-sm-8">
|
||||
<button type="submit" class="btn btn-default btn-success">Update the repeated expense</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{{Form::close()}}
|
||||
@stop
|
||||
@section('scripts')
|
||||
<?php echo javascript_include_tag('piggybanks-create'); ?>
|
||||
@stop
|
@ -1,105 +0,0 @@
|
||||
@extends('layouts.default')
|
||||
@section('content')
|
||||
<div class="row">
|
||||
<div class="col-lg-12 col-md-12 col-sm-12">
|
||||
<h1>Firefly
|
||||
<small>Edit piggy bank "{{{$piggybank->name}}}"</small>
|
||||
</h1>
|
||||
<p class="lead">Use piggy banks to make saving money easier</p>
|
||||
<p class="text-info">
|
||||
Saving money is <em>hard</em>. Piggy banks allow you to group money
|
||||
from an account together. If you also set a target (and a target date) you
|
||||
can save towards your goals.
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{{Form::open(['class' => 'form-horizontal','url' => route('piggybanks.update')])}}
|
||||
{{Form::hidden('id',$piggybank->id)}}
|
||||
<div class="row">
|
||||
<div class="col-lg-6 col-md-12 col-sm-6">
|
||||
<h4>Mandatory fields</h4>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="name" class="col-sm-4 control-label">Name</label>
|
||||
<div class="col-sm-8">
|
||||
<input type="text" name="name" class="form-control" id="name" value="{{{Input::old('name') ?: $piggybank->name}}}" placeholder="Name">
|
||||
@if($errors->has('name'))
|
||||
<p class="text-danger">{{$errors->first('name')}}</p>
|
||||
@else
|
||||
<span class="help-block">For example: new bike, new camera</span>
|
||||
@endif
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
{{ Form::label('target', 'Target amount', ['class' => 'col-sm-4 control-label'])}}
|
||||
<div class="col-sm-8">
|
||||
<div class="input-group">
|
||||
<span class="input-group-addon">€</span>
|
||||
{{Form::input('number','target', Input::old('target') ?: $piggybank->target, ['step' => 'any', 'min' => '1', 'class' => 'form-control'])}}
|
||||
</div>
|
||||
|
||||
@if($errors->has('target'))
|
||||
<p class="text-danger">{{$errors->first('target')}}</p>
|
||||
@else
|
||||
<span class="help-block">How much money do you need to save?</span>
|
||||
@endif
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="account_id" class="col-sm-4 control-label">
|
||||
Saving account
|
||||
</label>
|
||||
<div class="col-sm-8">
|
||||
{{Form::select('account_id',$accounts,Input::old('account_id') ?: $piggybank->account_id,['class' => 'form-control'])}}
|
||||
@if($errors->has('account_id'))
|
||||
<p class="text-danger">{{$errors->first('account_id')}}</p>
|
||||
@else
|
||||
<span class="help-block">Indicate on which account you've got your savings.</span>
|
||||
@endif
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
<div class="col-lg-6 col-md-12 col-sm-6">
|
||||
<h4>Optional fields</h4>
|
||||
|
||||
<div class="form-group">
|
||||
{{ Form::label('targetdate', 'Target date', ['class' => 'col-sm-4 control-label'])}}
|
||||
<div class="col-sm-8">
|
||||
{{ Form::input('date','targetdate', Input::old('targetdate') ?: $piggybank->targetdate, ['class'
|
||||
=> 'form-control']) }}
|
||||
@if($errors->has('targetdate'))
|
||||
<p class="text-danger">{{$errors->first('targetdate')}}</p>
|
||||
@else
|
||||
<span class="help-block">
|
||||
If you want to, set a target date. This will inform you how much money you should save to
|
||||
get to the target amount.
|
||||
</span>
|
||||
@endif
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-lg-6 col-md-12 col-sm-6">
|
||||
|
||||
|
||||
|
||||
<div class="form-group">
|
||||
<div class="col-sm-offset-4 col-sm-8">
|
||||
<button type="submit" class="btn btn-default btn-success">Create the piggy bank</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{{Form::close()}}
|
||||
|
||||
|
||||
@stop
|
@ -36,6 +36,46 @@
|
||||
<h3>Current piggy banks</h3>
|
||||
@if($countNonRepeating == 0)
|
||||
<p class="text-warning">No piggy banks found.</p>
|
||||
@else
|
||||
<table class="table table-bordered">
|
||||
@foreach($piggybanks as $piggyBank)
|
||||
@if($piggyBank->repeats == 0)
|
||||
<!-- display piggy bank -->
|
||||
<tr>
|
||||
<td>
|
||||
<h4><a href="{{route('piggybanks.show',$piggyBank->id)}}">{{{$piggyBank->name}}}</a></h4>
|
||||
<p>
|
||||
<!-- target amount -->
|
||||
Saving up to {{mf($piggyBank->targetamount)}}.
|
||||
<!-- currently saved -->
|
||||
Currently saved
|
||||
{{mf($piggyBank->currentRelevantRep()->currentamount)}}.
|
||||
|
||||
<!-- start date (if any) -->
|
||||
@if(!is_null($piggyBank->startdate))
|
||||
Start date: {{$piggyBank->currentRelevantRep()->startdate->format('d M Y')}}.
|
||||
@endif
|
||||
|
||||
<!-- target date (if any) -->
|
||||
@if(!is_null($piggyBank->targetdate))
|
||||
Target date: {{$piggyBank->currentRelevantRep()->targetdate->format('d M Y')}}.
|
||||
@endif
|
||||
|
||||
@if(!is_null($piggyBank->reminder))
|
||||
Next reminder: {{$piggyBank->nextReminderDate()->format('d M Y')}}
|
||||
@endif
|
||||
|
||||
</p>
|
||||
<div class="btn-group-xs btn-group">
|
||||
<a href="{{route('piggybanks.edit',$piggyBank->id)}}" class="btn btn-default"><span class="glyphicon glyphicon-pencil"></span></a>
|
||||
<a href="{{route('piggybanks.delete',$piggyBank->id)}}" class="btn btn-danger"><span class="glyphicon glyphicon-trash"></span></a>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
@endif
|
||||
@endforeach
|
||||
</table>
|
||||
@endif
|
||||
|
||||
</div>
|
||||
@ -43,6 +83,45 @@
|
||||
<h3>Current repeated expenses</h3>
|
||||
@if($countRepeating == 0)
|
||||
<p class="text-warning">No repeated expenses found.</p>
|
||||
@else
|
||||
<table class="table table-bordered">
|
||||
@foreach($piggybanks as $repeated)
|
||||
@if($repeated->repeats == 1)
|
||||
<!-- display repeated expense -->
|
||||
<tr><td>
|
||||
<h4><a href="{{route('piggybanks.show',$repeated->id)}}">{{{$repeated->name}}}</a></h4>
|
||||
<p>
|
||||
<!-- target amount -->
|
||||
Saving up to {{mf($repeated->targetamount)}}.
|
||||
|
||||
<!-- currently saved -->
|
||||
Currently saved
|
||||
{{mf($piggyBank->currentRelevantRep()->currentamount)}}.
|
||||
|
||||
<!-- start date (if any) -->
|
||||
@if(!is_null($piggyBank->startdate))
|
||||
Start date: {{$piggyBank->currentRelevantRep()->startdate->format('d M Y')}}.
|
||||
@endif
|
||||
|
||||
<!-- target date (if any) -->
|
||||
@if(!is_null($piggyBank->targetdate))
|
||||
Target date: {{$piggyBank->currentRelevantRep()->targetdate->format('d M Y')}}.
|
||||
@endif
|
||||
|
||||
@if(!is_null($piggyBank->reminder))
|
||||
Next reminder: {{$piggyBank->nextReminderDate()->format('d M Y')}}
|
||||
@endif
|
||||
|
||||
|
||||
</p>
|
||||
<div class="btn-group-xs btn-group">
|
||||
<a href="{{route('piggybanks.edit',$repeated->id)}}" class="btn btn-default"><span class="glyphicon glyphicon-pencil"></span></a>
|
||||
<a href="{{route('piggybanks.delete',$repeated->id)}}" class="btn btn-danger"><span class="glyphicon glyphicon-trash"></span></a>
|
||||
</div>
|
||||
</td></tr>
|
||||
@endif
|
||||
@endforeach
|
||||
</table>
|
||||
@endif
|
||||
</div>
|
||||
</div>
|
||||
|
@ -5,14 +5,127 @@
|
||||
<h1>Firefly
|
||||
<small>Piggy bank "{{{$piggyBank->name}}}"</small>
|
||||
</h1>
|
||||
<p class="lead">Set targets and save money</p>
|
||||
<p class="text-info">
|
||||
Saving money is <em>hard</em>. Piggy banks allow you to group money
|
||||
from an account together. If you also set a target (and a target date) you
|
||||
can save towards your goals.
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-lg-6 col-md-6 col-sm-12">
|
||||
<h3>Piggy bank info</h3>
|
||||
<table class="table table-bordered table-striped">
|
||||
<tr>
|
||||
<th>Field</th>
|
||||
<th>Value</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Type (repeats)</td>
|
||||
<td>
|
||||
@if($piggyBank->repeats == 1)
|
||||
Repeated expense
|
||||
@else
|
||||
Piggy bank
|
||||
@endif
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Name</td>
|
||||
<td>{{{$piggyBank->name}}} (#{{$piggyBank->id}})</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Account</td>
|
||||
<td><a href="{{route('accounts.show',$piggyBank->account_id)}}">{{{$piggyBank->account->name}}}</a></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Target amount</td>
|
||||
<td>{{mf($piggyBank->targetamount)}}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Start date</td>
|
||||
<td>
|
||||
@if(is_null($piggyBank->startdate))
|
||||
<em>No start date</em>
|
||||
@else
|
||||
{{$piggyBank->startdate->format('jS F Y')}}
|
||||
@endif
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Target date</td>
|
||||
<td>
|
||||
@if(is_null($piggyBank->targetdate))
|
||||
<em>No target date</em>
|
||||
@else
|
||||
{{$piggyBank->targetdate->format('jS F Y')}}
|
||||
@endif
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td>Repeats every</td>
|
||||
<td>
|
||||
@if(!is_null($piggyBank->rep_length))
|
||||
Every {{$piggyBank->rep_every}} {{$piggyBank->rep_length}}(s)
|
||||
@if(!is_null($piggyBank->rep_times))
|
||||
({{$piggyBank->rep_times}} times)
|
||||
@else
|
||||
(indefinitely)
|
||||
@endif
|
||||
@else
|
||||
<em>Does not repeat</em>
|
||||
@endif
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Reminder</td>
|
||||
<td>
|
||||
@if(is_null($piggyBank->reminder))
|
||||
<em>(no reminder)</em>
|
||||
@else
|
||||
Every {{$piggyBank->reminder_skip}} {{$piggyBank->reminder}}(s)
|
||||
@endif
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
<div class="col-lg-6 col-md-6 col-sm-12">
|
||||
<h3>Piggy bank instances info</h3>
|
||||
@foreach($piggyBank->piggybankrepetitions()->orderBy('startdate')->get() as $rep)
|
||||
<table class="table table-bordered table-striped">
|
||||
<tr>
|
||||
<th style="width:50%;">Field</th>
|
||||
<th>Value</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>ID</td>
|
||||
<td>#{{$rep->id}}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Current amount</td>
|
||||
<td>{{mf($rep->currentamount)}}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Start date</td>
|
||||
<td>
|
||||
@if(is_null($rep->startdate))
|
||||
<em>No start date</em>
|
||||
@else
|
||||
{{$rep->startdate->format('jS F Y')}}
|
||||
@endif
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Target date</td>
|
||||
<td>
|
||||
@if(is_null($rep->targetdate))
|
||||
<em>No target date</em>
|
||||
@else
|
||||
{{$rep->targetdate->format('jS F Y')}}
|
||||
@endif
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
@endforeach
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@stop
|
||||
|
||||
@section('scripts')
|
||||
|
@ -92,13 +92,16 @@ Event::subscribe('Firefly\Helper\Form\FormTrigger');
|
||||
|
||||
// do something with events:
|
||||
Event::subscribe('Firefly\Trigger\Limits\EloquentLimitTrigger');
|
||||
Event::subscribe('Firefly\Trigger\Piggybanks\EloquentPiggybankTrigger');
|
||||
|
||||
//App::booted(
|
||||
// function () {
|
||||
// $forms = new \Firefly\Helper\Form\FormTrigger;
|
||||
// $forms->registerFormExtensions();
|
||||
// }
|
||||
//);
|
||||
|
||||
|
||||
App::booted(
|
||||
function () {
|
||||
$forms = new \Firefly\Helper\Form\FormTrigger;
|
||||
$forms->registerFormExtensions();
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
return $app;
|
||||
|
Loading…
Reference in New Issue
Block a user