Some more code to facilitate creating your very first account.

This commit is contained in:
Sander Dorigo 2014-06-30 15:46:12 +02:00
parent b216c1e16b
commit 67ef8f6be6
10 changed files with 200 additions and 8 deletions

View File

@ -2,7 +2,7 @@
return [
'driver' => 'smtp',
'host' => '',
'host' => ';',
'port' => 587,
'from' => ['address' => '', 'name' => 'Firefly V'],
'encryption' => 'tls',

View File

@ -0,0 +1,99 @@
<?php
use Firefly\Storage\Account\AccountRepositoryInterface as ARI;
class AccountController extends \BaseController {
public function __construct(ARI $accounts) {
$this->accounts = $accounts;
}
/**
* Display a listing of the resource.
*
* @return Response
*/
public function index()
{
}
/**
* Show the form for creating a new resource.
*
* @return Response
*/
public function create()
{
if($this->accounts->count() == 0) {
return View::make('accounts.create-first-time');
}
return View::make('accounts');
}
/**
* Store a newly created resource in storage.
*
* @return Response
*/
public function store()
{
$account = $this->accounts->store();
if($account === false) {
Session::flash('error','Could not create account with provided information');
return Redirect::route('accounts.create')->withInput()->withErrors($this->accounts->validator);
}
}
/**
* Display the specified resource.
*
* @param int $id
* @return Response
*/
public function show($id)
{
//
}
/**
* Show the form for editing the specified resource.
*
* @param int $id
* @return Response
*/
public function edit($id)
{
//
}
/**
* Update the specified resource in storage.
*
* @param int $id
* @return Response
*/
public function update($id)
{
//
}
/**
* Remove the specified resource from storage.
*
* @param int $id
* @return Response
*/
public function destroy($id)
{
//
}
}

View File

@ -6,6 +6,9 @@ namespace Firefly\Storage\Account;
interface AccountRepositoryInterface
{
public function count();
public function store();
}

View File

@ -5,6 +5,8 @@ namespace Firefly\Storage\Account;
class EloquentAccountRepository implements AccountRepositoryInterface
{
public $validator;
public function __construct()
{
}
@ -14,4 +16,15 @@ class EloquentAccountRepository implements AccountRepositoryInterface
}
public function store() {
$account = new \Account;
$account->name = Input::get('name');
if($account->isValid()) {
}
$this->validator = $account->validator;
return false;
}
}

View File

@ -1,9 +1,14 @@
<?php
class Account extends Eloquent
class Account extends Elegant
{
public static $rules
= [
'name' => 'required|between:100,100',
];
public function accountType()
{
return $this->belongsTo('AccountType');

View File

@ -4,12 +4,15 @@
class Elegant extends Eloquent
{
public static $rules = [];
public $validator;
public function isValid()
{
return Validator::make(
$validator = Validator::make(
$this->toArray(),
$this::$rules
)->passes();
);
$this->validator = $validator;
return $validator->passes();
}
}

View File

@ -17,8 +17,10 @@ Route::get('/verify/{verification}',['uses' => 'UserController@verify','as' => '
Route::get('/reset/{reset}',['uses' => 'UserController@reset','as' => 'reset','before' => 'guest']);
Route::get('/logout',['uses' => 'UserController@logout','as' => 'logout','before' => 'auth']);
Route::get('/remindme',['uses' => 'UserController@remindme','as' => 'remindme','before' => 'guest']);
Route::post('/login',['uses' => 'UserController@postLogin','before' => 'csrf|guest']);
Route::post('/register',['uses' => 'UserController@postRegister','before' => 'csrf|guest']);
Route::post('/remindme',['uses' => 'UserController@postRemindme','before' => 'csrf|guest']);
Route::post('/remindme',['uses' => 'UserController@postRemindme','before' => 'csrf|guest']);
// accountcontroller
Route::get('/accounts/create',['uses' => 'AccountController@create','as' => 'accounts.create','before' => 'auth']);
Route::post('/accounts/store',['uses' => 'AccountController@store','as' => 'accounts.store','before' => 'csrf|auth']);

View File

@ -0,0 +1,66 @@
@extends('layouts.default')
@section('content')
<div class="row">
<div class="col-lg-8 col-md-8 col-sm-12">
<h1>Firefly<br/>
<small>Add a new account</small>
</h1>
<p class="lead">
Accounts are the record holders for transactions and transfers. Money moves
from one account to another.
</p>
<p>
In a double-entry bookkeeping system (such as this one) there is a "from" account and a "to"
account, even when money is created from thin air (such as interest, or when new accounts already have
a positive balance).
</p>
<p>
Your first account should be a checking or savings account. Enter its name and if relevant
the current balance. Check your bank statements for the last current balance you can find.
</p>
{{Form::open(['class' => 'form-horizontal','url' => route('accounts.store')])}}
<div class="form-group">
{{ Form::label('name', 'Account name', ['class' => 'col-sm-3 control-label'])}}
<div class="col-sm-9">
{{ Form::text('name', Input::old('name'), ['class' => 'form-control']) }}
@if($errors->has('name'))
<p class="text-danger">{{$errors->first('name')}}</p>
@else
<p class="text-info">Use something descriptive such as "checking account" or "My Bank Main Account".</p>
@endif
</div>
</div>
<div class="form-group">
{{ Form::label('openingbalance', 'Opening balance', ['class' => 'col-sm-3 control-label'])}}
<div class="col-sm-9">
{{ Form::input('number','openingbalance', Input::old('openingbalance'), ['step' => 'any', 'class' => 'form-control'])}}
@if($errors->has('openingbalance'))
<p class="text-danger">{{$errors->first('openingbalance')}}</p>
@else
<p class="text-info">What's the current balance of this new account?</p>
@endif
</div>
</div>
<div class="form-group">
{{ Form::label('openingbalancedate', 'Opening balance date', ['class' => 'col-sm-3 control-label'])}}
<div class="col-sm-9">
{{ Form::input('date','openingbalancedate', Input::old('openingbalancedate') ?: date('Y-m-d'), ['class' => 'form-control']) }}
@if($errors->has('openingbalancedate'))
<p class="text-danger">{{$errors->first('openingbalancedate')}}</p>
@else
<p class="text-info">When was this the balance of the new account? Since your bank statements may lag behind, update this date to match the date of the last known balance of the account.</p>
@endif
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-3 col-sm-9">
<button type="submit" class="btn btn-default">Create my first account</button>
</div>
</div>
</form>
</div>
</div>
@stop

View File

@ -19,6 +19,7 @@
</head>
<body>
<div class="container">
@include('partials.flashes')
@yield('content')
</div>

View File

@ -23,7 +23,7 @@
Click the link below to create your first account, and get started with Firefly.
</p>
<p>
<a href="#" class="btn btn-info">Start with a new account</a>
<a href="{{route('accounts.create')}}" class="btn btn-info">Start with a new account</a>
</p>
</div>