mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Some preliminary work on issue #6. Breaks a lot of tests. [skip ci]
This commit is contained in:
parent
f52cc01a8e
commit
9e77bf51bb
@ -25,13 +25,21 @@ class PiggybankController extends BaseController
|
||||
/**
|
||||
* @return $this
|
||||
*/
|
||||
public function create()
|
||||
public function createPiggybank()
|
||||
{
|
||||
$accounts = $this->_accounts->getActiveDefaultAsSelectList();
|
||||
|
||||
return View::make('piggybanks.create-piggybank')->with('accounts', $accounts);
|
||||
}
|
||||
|
||||
public function createRepeated()
|
||||
{
|
||||
$accounts = $this->_accounts->getActiveDefaultAsSelectList();
|
||||
|
||||
return View::make('piggybanks.create')->with('accounts', $accounts);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param Piggybank $piggyBank
|
||||
*
|
||||
@ -72,20 +80,12 @@ class PiggybankController extends BaseController
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$count = $this->_repository->count();
|
||||
$countRepeating = $this->_repository->countRepeating();
|
||||
$countNonRepeating = $this->_repository->countNonrepeating();
|
||||
$piggybanks = $this->_repository->get();
|
||||
$accounts = [];
|
||||
// get accounts:
|
||||
foreach ($piggybanks as $piggyBank) {
|
||||
$account = $piggyBank->account;
|
||||
$id = $account->id;
|
||||
$accounts[$id] = $account;
|
||||
}
|
||||
|
||||
|
||||
return View::make('piggybanks.index')->with('count', $count)->with('accounts', $accounts)->with(
|
||||
'piggybanks', $piggybanks
|
||||
);
|
||||
return View::make('piggybanks.index')->with('piggybanks', $piggybanks)
|
||||
->with('countRepeating',$countRepeating)
|
||||
->with('countNonRepeating',$countNonRepeating);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -96,6 +96,34 @@ class PiggybankController extends BaseController
|
||||
return View::make('piggybanks.show')->with('piggyBank', $piggyBank);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return $this|\Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function storePiggybank()
|
||||
{
|
||||
$data = Input::all();
|
||||
unset($data['_token']);
|
||||
|
||||
// extend the data array with the settings needed to create a piggy bank:
|
||||
$data['repeats'] = 0;
|
||||
$data['rep_times'] = 0;
|
||||
$data['order'] = 0;
|
||||
|
||||
$piggyBank = $this->_repository->store($data);
|
||||
if ($piggyBank->validate()) {
|
||||
Session::flash('success', 'New piggy bank "' . $piggyBank->name . '" created!');
|
||||
|
||||
return Redirect::route('piggybanks.index');
|
||||
|
||||
|
||||
} else {
|
||||
Session::flash('error', 'Could not save piggy bank: ' . $piggyBank->errors()->first());
|
||||
|
||||
return Redirect::route('piggybanks.create.piggybank')->withInput()->withErrors($piggyBank->errors());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @return $this|\Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
|
@ -34,6 +34,21 @@ class EloquentPiggybankRepository implements PiggybankRepositoryInterface
|
||||
)->where('piggybanks.id', $piggyBankId)->first(['piggybanks.*']);
|
||||
}
|
||||
|
||||
public function countRepeating()
|
||||
{
|
||||
return \Piggybank::leftJoin('accounts', 'accounts.id', '=', 'piggybanks.account_id')->where(
|
||||
'accounts.user_id', \Auth::user()->id
|
||||
)->where('repeats', 1)->count();
|
||||
}
|
||||
|
||||
public function countNonrepeating()
|
||||
{
|
||||
return \Piggybank::leftJoin('accounts', 'accounts.id', '=', 'piggybanks.account_id')->where(
|
||||
'accounts.user_id', \Auth::user()->id
|
||||
)->where('repeats', 0)->count();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
@ -57,14 +72,8 @@ class EloquentPiggybankRepository implements PiggybankRepositoryInterface
|
||||
$account = isset($data['account_id']) ? $accounts->find($data['account_id']) : null;
|
||||
|
||||
|
||||
$piggyBank = new \Piggybank;
|
||||
$piggyBank = new \Piggybank($data);
|
||||
$piggyBank->account()->associate($account);
|
||||
$piggyBank->targetdate
|
||||
= isset($data['targetdate']) && strlen($data['targetdate']) > 0 ? $data['targetdate'] : null;
|
||||
$piggyBank->name = isset($data['name']) ? $data['name'] : null;
|
||||
$piggyBank->amount = 0;
|
||||
$piggyBank->target = floatval($data['target']);
|
||||
$piggyBank->order = 1;
|
||||
if ($piggyBank->validate()) {
|
||||
$piggyBank->save();
|
||||
}
|
||||
|
@ -23,6 +23,16 @@ interface PiggybankRepositoryInterface
|
||||
*/
|
||||
public function count();
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function countRepeating();
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function countNonrepeating();
|
||||
|
||||
/**
|
||||
* @param $data
|
||||
*
|
||||
|
@ -39,6 +39,15 @@ use LaravelBook\Ardent\Ardent as Ardent;
|
||||
*/
|
||||
class Piggybank extends Ardent
|
||||
{
|
||||
public $fillable = [
|
||||
'name',
|
||||
'account_id',
|
||||
'targetamount',
|
||||
'repeats',
|
||||
'rep_times',
|
||||
'order'
|
||||
];
|
||||
|
||||
public static $rules
|
||||
= [
|
||||
'account_id' => 'required|exists:accounts,id',
|
||||
|
@ -135,7 +135,8 @@ Route::group(['before' => 'auth'], function () {
|
||||
|
||||
// piggy bank controller
|
||||
Route::get('/piggybanks',['uses' => 'PiggybankController@index','as' => 'piggybanks.index']);
|
||||
Route::get('/piggybanks/create', ['uses' => 'PiggybankController@create','as' => 'piggybanks.create']);
|
||||
Route::get('/piggybanks/create/piggybank', ['uses' => 'PiggybankController@createPiggybank','as' => 'piggybanks.create.piggybank']);
|
||||
Route::get('/piggybanks/create/repeated', ['uses' => 'PiggybankController@createRepeated','as' => 'piggybanks.create.repeated']);
|
||||
Route::get('/piggybanks/show/{piggybank}', ['uses' => 'PiggybankController@show','as' => 'piggybanks.show']);
|
||||
Route::get('/piggybanks/edit/{piggybank}', ['uses' => 'PiggybankController@edit','as' => 'piggybanks.edit']);
|
||||
Route::get('/piggybanks/delete/{piggybank}', ['uses' => 'PiggybankController@delete','as' => 'piggybanks.delete']);
|
||||
@ -199,7 +200,8 @@ Route::group(['before' => 'csrf|auth'], function () {
|
||||
|
||||
|
||||
// piggy bank controller
|
||||
Route::post('/piggybanks/store',['uses' => 'PiggybankController@store','as' => 'piggybanks.store']);
|
||||
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/destroy/{piggybank}', ['uses' => 'PiggybankController@destroy','as' => 'piggybanks.destroy']);
|
||||
|
||||
|
101
app/views/piggybanks/create-piggybank.blade.php
Normal file
101
app/views/piggybanks/create-piggybank.blade.php
Normal file
@ -0,0 +1,101 @@
|
||||
@extends('layouts.default')
|
||||
@section('content')
|
||||
<div class="row">
|
||||
<div class="col-lg-12 col-md-12 col-sm-12">
|
||||
<h1>Firefly
|
||||
<small>Create a new piggy bank</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.store.piggybank')])}}
|
||||
|
||||
<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')}}" 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') ?: Input::get('account'),['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'), ['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') ?: date('Y-m-d')}}"
|
||||
class="form-control"/>
|
||||
<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>
|
||||
</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') ?: ''}}"
|
||||
class="form-control"/>
|
||||
<span class="help-block">This field indicates when you want to have saved the indicated amount.</span>
|
||||
</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
|
||||
@section('scripts')
|
||||
<?php echo javascript_include_tag('piggybanks-create'); ?>
|
||||
@stop
|
@ -16,152 +16,37 @@
|
||||
to the piggy bank.
|
||||
</p>
|
||||
<p>
|
||||
<a href="{{route('piggybanks.create')}}" class="btn btn-success">Create new piggy bank</a>
|
||||
<a href="{{route('piggybanks.create.piggybank')}}" class="btn btn-success">Create new piggy bank</a>
|
||||
</p>
|
||||
</div>
|
||||
<div class="col-lg-6 col-md-6 col-sm-12">
|
||||
<p class="lead">Repeated expenses</p>
|
||||
<p class="lead">Save money for repeated expenses</p>
|
||||
<p class="text-info">
|
||||
Taxes are due every year. Or maybe you want to save up for your yearly fireworks-binge. Buy a new smart
|
||||
phone every three years. Firefly can help you organize these repeated expenses.
|
||||
</p>
|
||||
<p>
|
||||
<a href="{{route('piggybanks.create')}}" class="btn btn-success">Create new repeated expense</a>
|
||||
<a href="{{route('piggybanks.create.repeated')}}" class="btn btn-success">Create new repeated expense</a>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
{{--
|
||||
|
||||
<p class="text-info">
|
||||
Saving money is <em>hard</em>. Firefly's piggy banks can help you to save money. You can do two things using
|
||||
these piggy banks:
|
||||
</p>
|
||||
<ol class="text-info">
|
||||
<li>Save money towards a singular goal such as a new bike or a new car.</li>
|
||||
<li>Save money repeatedly, for yearly expenses or long-term recurring investments. One example may be buying
|
||||
a new phone every three year.</li>
|
||||
</ol>
|
||||
@if($count == 0)
|
||||
<p>
|
||||
<a href="{{route('piggybanks.create')}}" class="btn btn-success">Create new piggy bank</a>
|
||||
</p>
|
||||
<div class="row">
|
||||
<div class="col-lg-6 col-md-6 col-sm-12">
|
||||
<h3>Current piggy banks</h3>
|
||||
@if($countNonRepeating == 0)
|
||||
<p class="text-warning">No piggy banks found.</p>
|
||||
@endif
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
@if($count > 0)
|
||||
<div class="row">
|
||||
<div class="col-lg-12 col-md-12 col-sm-12">
|
||||
<h4>Accounts used for piggy banks</h4>
|
||||
<p class="text-info">
|
||||
@if(count($accounts) != 1)
|
||||
These (savings) accounts have
|
||||
@else
|
||||
This (savings) account has
|
||||
@endif
|
||||
@if(count($piggybanks) == 1)
|
||||
a piggy bank
|
||||
@else
|
||||
piggy banks
|
||||
@endif
|
||||
associated to
|
||||
@if(count($piggybanks) != 1)
|
||||
them.
|
||||
@else
|
||||
it.
|
||||
@endif
|
||||
If you transfer money to or from
|
||||
@if(count($accounts) != 1)
|
||||
these accounts,
|
||||
@else
|
||||
this account,
|
||||
@endif
|
||||
you may associate it with your @if(count($piggybanks) != 1)
|
||||
piggy banks.
|
||||
@else
|
||||
piggy bank.
|
||||
@endif
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-lg-6 col-md-6 col-sm-12">
|
||||
<table class="table table-striped">
|
||||
<tr>
|
||||
<th>Account</th>
|
||||
<th>Current balance</th>
|
||||
<th>Left for (other) piggy banks</th>
|
||||
<th>Total target</th>
|
||||
</tr>
|
||||
@foreach($accounts as $account)
|
||||
<tr>
|
||||
<td>{{{$account->name}}}</td>
|
||||
<td id="account_{{$account->id}}_total" data-raw="{{$account->balance}}">{{mf($account->balance)}}</td>
|
||||
<td id="account_{{$account->id}}_left" data-raw="{{$account->left}}">{{mf($account->left)}}</td>
|
||||
<td>{{mf($account->total)}}</td>
|
||||
</tr>
|
||||
@endforeach
|
||||
</table>
|
||||
<h3>Current repeated expenses</h3>
|
||||
@if($countRepeating == 0)
|
||||
<p class="text-warning">No repeated expenses found.</p>
|
||||
@endif
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-lg-12 col-md-6 col-sm-12">
|
||||
<h3>Piggy banks</h3>
|
||||
|
||||
@foreach($piggybanks as $piggybank)
|
||||
<h4>
|
||||
<a href="{{route('piggybanks.show',$piggybank->id)}}">{{{$piggybank->name}}}</a>
|
||||
</h4>
|
||||
@endforeach
|
||||
|
||||
|
||||
@foreach($piggybanks as $piggybank)
|
||||
|
||||
@if(!is_null($piggybank->targetdate))
|
||||
<p>
|
||||
Target date: {{$piggybank->targetdate->format('jS F Y')}}
|
||||
</p>
|
||||
@endif
|
||||
<table class="table table-bordered">
|
||||
<tr>
|
||||
<td style="width:15%;">
|
||||
<div class="input-group">
|
||||
<span class="input-group-addon">€</span>
|
||||
<input class="form-control" type="number" data-piggy="{{$piggybank->id}}" data-account="{{$piggybank->account_id}}" step="any" min="0" max="{{$piggybank->target}}" id="piggy_{{$piggybank->id}}_amount" value="{{$piggybank->amount}}" />
|
||||
</div>
|
||||
</td>
|
||||
<td><input type="range" data-account="{{$piggybank->account_id}}" name="piggy_{{$piggybank->id}}" min="0" max="{{$piggybank->target}}" step="any" value="{{$piggybank->amount}}" /></td>
|
||||
<td style="width: 10%;"><span id="piggy_{{$piggybank->id}}_pct">{{$piggybank->pct}}</span></td>
|
||||
<td style="width:8%;">
|
||||
<div class="btn-group btn-group-xs">
|
||||
<a href="{{route('piggybanks.edit',$piggybank->id)}}" class="btn btn-default btn-xs"><span class="glyphicon glyphicon-pencil"></span></a>
|
||||
<a href="{{route('piggybanks.delete',$piggybank->id)}}" class="btn btn-danger btn-xs"><span class="glyphicon glyphicon-trash"></span></a>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
@endforeach
|
||||
<p>
|
||||
<a href="{{route('piggybanks.create')}}" class="btn btn-success">Create new piggy bank</a>
|
||||
</p>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
@endif
|
||||
--}}
|
||||
|
||||
@stop
|
||||
@section('scripts')
|
||||
<script type="text/javascript">
|
||||
var accountBalances = [];
|
||||
var accountLeft = [];
|
||||
@foreach($accounts as $account)
|
||||
accountBalances[{{$account->id}}] = {{$account->balance()}};
|
||||
accountLeft[{{$account->id}}] = {{$account->left}};
|
||||
@endforeach
|
||||
</script>
|
||||
|
||||
<?php echo javascript_include_tag('piggybanks'); ?>
|
||||
@stop
|
Loading…
Reference in New Issue
Block a user