From e063e5686fba5a7ed7de61dc58fde451fd0a918a Mon Sep 17 00:00:00 2001 From: James Cole Date: Thu, 14 Aug 2014 18:02:31 +0200 Subject: [PATCH] Pretty much finished the default piggy banks, now for the repeating ones (issue #6). [skip ci] --- app/controllers/PiggybankController.php | 3 +- .../Piggybank/EloquentPiggybankRepository.php | 20 +++------- .../piggybanks/create-piggybank.blade.php | 14 ++++++- .../piggybanks/create-repeated.blade.php | 37 ++++--------------- 4 files changed, 29 insertions(+), 45 deletions(-) diff --git a/app/controllers/PiggybankController.php b/app/controllers/PiggybankController.php index 8dc335bc31..2c3d7940b4 100644 --- a/app/controllers/PiggybankController.php +++ b/app/controllers/PiggybankController.php @@ -35,9 +35,10 @@ class PiggybankController extends BaseController public function createRepeated() { + $periods = Config::get('firefly.piggybank_periods'); $accounts = $this->_accounts->getActiveDefaultAsSelectList(); - return View::make('piggybanks.create')->with('accounts', $accounts); + return View::make('piggybanks.create-repeated')->with('accounts', $accounts)->with('periods',$periods); } diff --git a/app/lib/Firefly/Storage/Piggybank/EloquentPiggybankRepository.php b/app/lib/Firefly/Storage/Piggybank/EloquentPiggybankRepository.php index 144b3fab8b..49d927f0ea 100644 --- a/app/lib/Firefly/Storage/Piggybank/EloquentPiggybankRepository.php +++ b/app/lib/Firefly/Storage/Piggybank/EloquentPiggybankRepository.php @@ -69,7 +69,6 @@ class EloquentPiggybankRepository implements PiggybankRepositoryInterface */ public function store($data) { - var_dump($data); if ($data['targetdate'] == '') { unset($data['targetdate']); } @@ -83,15 +82,14 @@ class EloquentPiggybankRepository implements PiggybankRepositoryInterface $piggyBank = new \Piggybank($data); - $piggyBank->account()->associate($account); + if (!is_null($account)) { + $piggyBank->account()->associate($account); + } $today = new Carbon; if ($piggyBank->validate()) { - echo 'Valid, but some more checking!'; - if (!is_null($piggyBank->targetdate) && $piggyBank->targetdate < $today) { $piggyBank->errors()->add('targetdate', 'Target date cannot be in the past.'); - return $piggyBank; } @@ -100,7 +98,7 @@ class EloquentPiggybankRepository implements PiggybankRepositoryInterface // just flash a warning $reminderSkip = $piggyBank->reminder_skip < 1 ? 1 : intval($piggyBank->reminder_skip); $firstReminder = new Carbon; - switch($piggyBank->reminder) { + switch ($piggyBank->reminder) { case 'day': $firstReminder->addDays($reminderSkip); break; @@ -117,18 +115,12 @@ class EloquentPiggybankRepository implements PiggybankRepositoryInterface throw new FireflyException('Invalid reminder period'); break; } - if($firstReminder > $piggyBank->targetdate) { - $piggyBank->errors()->add('reminder','Something reminder bla.'); + if ($firstReminder > $piggyBank->targetdate) { + $piggyBank->errors()->add('reminder', 'The reminder has been set to remind you after the piggy bank will expire.'); return $piggyBank; } } - $piggyBank->save(); - } else { - echo 'Does not validate'; - - print_r($piggyBank->errors()->all()); - exit; } return $piggyBank; diff --git a/app/views/piggybanks/create-piggybank.blade.php b/app/views/piggybanks/create-piggybank.blade.php index 80e2bb86a6..3342e1135d 100644 --- a/app/views/piggybanks/create-piggybank.blade.php +++ b/app/views/piggybanks/create-piggybank.blade.php @@ -66,7 +66,11 @@
+ @if($errors->has('startdate')) +

{{$errors->first('startdate')}}

+ @else 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. + @endif
@@ -75,14 +79,18 @@
+ @if($errors->has('targetdate')) +

{{$errors->first('targetdate')}}

+ @else If this piggy bank has a dead line, enter it here. + @endif
{{ Form::label('reminder', 'Remind you every', ['class' => 'col-sm-4 control-label'])}}
- + + @if($errors->has('reminder')) +

{{$errors->first('reminder')}}

+ @else Enter a number and a period and Firefly will remind you to add money to this piggy bank every now and then. + @endif
diff --git a/app/views/piggybanks/create-repeated.blade.php b/app/views/piggybanks/create-repeated.blade.php index dd4605a5b3..51547d0ff1 100644 --- a/app/views/piggybanks/create-repeated.blade.php +++ b/app/views/piggybanks/create-repeated.blade.php @@ -3,23 +3,19 @@

Firefly - Create a new piggy bank + Create a new repeated expense

-

Create piggy banks to make saving money easier

-

- Saving money is hard. 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. -

+

Create repeated expenses to keep track of long-term planned expenses

-{{Form::open(['class' => 'form-horizontal','url' => route('piggybanks.store')])}} +{{Form::open(['class' => 'form-horizontal','url' => route('piggybanks.store.repeated')])}}

Mandatory fields

+
@@ -47,39 +43,22 @@
- {{ Form::label('target', 'Target amount', ['class' => 'col-sm-4 control-label'])}} + {{ Form::label('targetamount', 'Target amount', ['class' => 'col-sm-4 control-label'])}}
- {{Form::input('number','target', Input::old('target'), ['step' => 'any', 'min' => '1', 'class' => 'form-control'])}} + {{Form::input('number','targetamount', Input::old('targetamount'), ['step' => 'any', 'min' => '1', 'class' => 'form-control'])}}
- @if($errors->has('target')) -

{{$errors->first('target')}}

+ @if($errors->has('targetamount')) +

{{$errors->first('targetamount')}}

@else How much money do you need to save? @endif
-
- -
-
- -
- If you need to save money annually (to save for taxes) use this form and fill - in the fields that will appear. -
-
-
-

Mandatory fields for repeating piggy banks

- Fields be here. -