Firefly III: a personal finances manager
PHP accountingbudgetbudgetingbudgetscash-flowcashflowcredit-carddockerexpensesfinancefinancesfinanciallinuxmoneypaycheckpersonal-financephpphp7
Some more code to facilitate creating your very first account.
Sander Dorigo67ef8f6be6ce
diff --git a/app/config/mail.php b/app/config/mail.phpindex a208c28e86..f9444f6c2e 100644--- a/app/config/mail.php+++ b/app/config/mail.php@@ -2,7 +2,7 @@return ['driver' => 'smtp',- 'host' => '',+ 'host' => ';','port' => 587,'from' => ['address' => '', 'name' => 'Firefly V'],'encryption' => 'tls',diff --git a/app/controllers/AccountController.php b/app/controllers/AccountController.phpnew file mode 100644index 0000000000..efd7cc92d7--- /dev/null+++ b/app/controllers/AccountController.php@@ -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)+ {+ //+ }+++}diff --git a/app/lib/Firefly/Storage/Account/AccountRepositoryInterface.php b/app/lib/Firefly/Storage/Account/AccountRepositoryInterface.phpindex 39399bdbce..a8d4a21ddc 100644--- a/app/lib/Firefly/Storage/Account/AccountRepositoryInterface.php+++ b/app/lib/Firefly/Storage/Account/AccountRepositoryInterface.php@@ -6,6 +6,9 @@ namespace Firefly\Storage\Account;interface AccountRepositoryInterface{+public function count();+ public function store();+}\ No newline at end of filediff --git a/app/lib/Firefly/Storage/Account/EloquentAccountRepository.php b/app/lib/Firefly/Storage/Account/EloquentAccountRepository.phpindex 81fbca3990..5c03c33304 100644--- a/app/lib/Firefly/Storage/Account/EloquentAccountRepository.php+++ b/app/lib/Firefly/Storage/Account/EloquentAccountRepository.php@@ -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;+ }+}\ No newline at end of filediff --git a/app/models/Account.php b/app/models/Account.phpindex 3f206da7c4..ffc5863ca9 100644--- a/app/models/Account.php+++ b/app/models/Account.php@@ -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');diff --git a/app/models/Elegant.php b/app/models/Elegant.phpindex 94318f6afa..8d4bc8b4ac 100644--- a/app/models/Elegant.php+++ b/app/models/Elegant.php@@ -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();}}\ No newline at end of filediff --git a/app/routes.php b/app/routes.phpindex b4511d3af8..324aaa29d4 100644--- a/app/routes.php+++ b/app/routes.php@@ -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']);\ No newline at end of file+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']);\ No newline at end of filediff --git a/app/views/accounts/create-first-time.blade.php b/app/views/accounts/create-first-time.blade.phpnew file mode 100644index 0000000000..0be135e733--- /dev/null+++ b/app/views/accounts/create-first-time.blade.php@@ -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\ No newline at end of filediff --git a/app/views/layouts/default.blade.php b/app/views/layouts/default.blade.phpindex 1ee555f09b..08c91c3350 100644--- a/app/views/layouts/default.blade.php+++ b/app/views/layouts/default.blade.php@@ -19,6 +19,7 @@</head><body><div class="container">+ @include('partials.flashes')@yield('content')</div>diff --git a/app/views/start.blade.php b/app/views/start.blade.phpindex 736e57dfe2..2f1821e78c 100644--- a/app/views/start.blade.php+++ b/app/views/start.blade.php@@ -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>