mirror of
				https://github.com/firefly-iii/firefly-iii.git
				synced 2025-10-31 10:47:00 +00:00 
			
		
		
		
	Pretty much finished the default piggy banks, now for the repeating ones (issue #6). [skip ci]
This commit is contained in:
		| @@ -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); | ||||
|     } | ||||
|  | ||||
|  | ||||
|   | ||||
| @@ -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); | ||||
|         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; | ||||
|             } | ||||
|  | ||||
| @@ -118,17 +116,11 @@ class EloquentPiggybankRepository implements PiggybankRepositoryInterface | ||||
|                         break; | ||||
|                 } | ||||
|                 if ($firstReminder > $piggyBank->targetdate) { | ||||
|                     $piggyBank->errors()->add('reminder','Something reminder bla.'); | ||||
|                     $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; | ||||
|   | ||||
| @@ -66,7 +66,11 @@ | ||||
|             <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> | ||||
|  | ||||
| @@ -75,14 +79,18 @@ | ||||
|             <div class="col-sm-8"> | ||||
|                 <input type="date" name="targetdate" value="{{Input::old('targetdate') ?: ''}}" | ||||
|                        class="form-control"/> | ||||
|                         @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="1" style="width:50px;display:inline;" max="100" name="reminder_skip" class="form-control" /> | ||||
|                 <input type="number" step="1" min="1" value="{{Input::old('reminder_skip') ?: 1}}" 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> | ||||
| @@ -90,8 +98,12 @@ | ||||
|                         <option value="{{$period}}" label="{{$period}}">{{$period}}</option> | ||||
|                     @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> | ||||
|  | ||||
|   | ||||
| @@ -3,23 +3,19 @@ | ||||
| <div class="row"> | ||||
|     <div class="col-lg-12 col-md-12 col-sm-12"> | ||||
|         <h1>Firefly | ||||
|             <small>Create a new piggy bank</small> | ||||
|             <small>Create a new repeated expense</small> | ||||
|         </h1> | ||||
|         <p class="lead">Create 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> | ||||
|         <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.store')])}} | ||||
| {{Form::open(['class' => 'form-horizontal','url' => route('piggybanks.store.repeated')])}} | ||||
|  | ||||
| <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"> | ||||
| @@ -47,39 +43,22 @@ | ||||
|         </div> | ||||
|  | ||||
|         <div class="form-group"> | ||||
|             {{ Form::label('target', 'Target amount', ['class' => 'col-sm-4 control-label'])}} | ||||
|             {{ 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','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'])}} | ||||
|                 </div> | ||||
|  | ||||
|                 @if($errors->has('target')) | ||||
|                 <p class="text-danger">{{$errors->first('target')}}</p> | ||||
|                 @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"> | ||||
|             <label for="create" class="col-sm-4 control-label">Repeat this piggy bank.</label> | ||||
|             <div class="col-sm-8"> | ||||
|                 <div class="checkbox"> | ||||
|                     <label> | ||||
|                         {{Form::checkbox('repeats',1,Input::old('repeats') == '1')}} | ||||
|                         Repeat this piggy bank | ||||
|                     </label> | ||||
|                 </div> | ||||
|                 <span class="help-block">If you need to save money annually (to save for taxes) use this form and fill | ||||
|                     in the fields that will appear.</span> | ||||
|             </div> | ||||
|         </div> | ||||
|  | ||||
|         <div class="repeat-piggy"> | ||||
|         <h4>Mandatory fields for repeating piggy banks</h4> | ||||
|             Fields be here. | ||||
|         </div> | ||||
|  | ||||
|  | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user