diff --git a/app/Exception/FireflyException.php b/app/Exceptions/FireflyException.php similarity index 58% rename from app/Exception/FireflyException.php rename to app/Exceptions/FireflyException.php index a2d36d3b59..a0079fa618 100644 --- a/app/Exception/FireflyException.php +++ b/app/Exceptions/FireflyException.php @@ -1,12 +1,12 @@ 'required|between:1,100|uniqueForUser:accounts,name', + 'openingBalance' => 'required|numeric' + ]; + } +} \ No newline at end of file diff --git a/app/Http/routes.php b/app/Http/routes.php index b450730ae3..46d6a44e39 100644 --- a/app/Http/routes.php +++ b/app/Http/routes.php @@ -18,6 +18,9 @@ Route::group( Route::get('/accounts/edit/{account}', ['uses' => 'AccountController@edit', 'as' => 'accounts.edit']); Route::get('/accounts/delete/{account}', ['uses' => 'AccountController@delete', 'as' => 'accounts.delete']); Route::get('/accounts/show/{account}/{view?}', ['uses' => 'AccountController@show', 'as' => 'accounts.show']); + Route::post('/accounts/store', ['uses' => 'AccountController@store', 'as' => 'accounts.store']); +// Route::post('/accounts/update/{account}', ['uses' => 'AccountController@update', 'as' => 'accounts.update']); +// Route::post('/accounts/destroy/{account}', ['uses' => 'AccountController@destroy', 'as' => 'accounts.destroy']); /** * Bills Controller diff --git a/app/Providers/FireflyServiceProvider.php b/app/Providers/FireflyServiceProvider.php index 88d9837a6b..692249373b 100644 --- a/app/Providers/FireflyServiceProvider.php +++ b/app/Providers/FireflyServiceProvider.php @@ -3,9 +3,22 @@ namespace FireflyIII\Providers; use Illuminate\Support\ServiceProvider; +use Validator; +use FireflyIII\Validation\FireflyValidator; +/** + * Class FireflyServiceProvider + * + * @package FireflyIII\Providers + */ class FireflyServiceProvider extends ServiceProvider { + public function boot() { + Validator::resolver(function($translator, $data, $rules, $messages) + { + return new FireflyValidator($translator, $data, $rules, $messages); + }); + } public function register() { $this->app->bind( @@ -29,6 +42,11 @@ class FireflyServiceProvider extends ServiceProvider return new \FireflyIII\Support\Steam; } ); + $this->app->bind( + 'expandedform', function () { + return new \FireflyIII\Support\ExpandedForm; + } + ); } } \ No newline at end of file diff --git a/app/Support/Amount.php b/app/Support/Amount.php index 81809ecc97..a9a1d12a32 100644 --- a/app/Support/Amount.php +++ b/app/Support/Amount.php @@ -122,4 +122,12 @@ class Amount return $currency->code; } + + public function getDefaultCurrency() + { + $currencyPreference = Prefs::get('currencyPreference', 'EUR'); + $currency = TransactionCurrency::whereCode($currencyPreference->data)->first(); + + return $currency; + } } \ No newline at end of file diff --git a/app/Support/ExpandedForm.php b/app/Support/ExpandedForm.php new file mode 100644 index 0000000000..a6ecdd0a88 --- /dev/null +++ b/app/Support/ExpandedForm.php @@ -0,0 +1,213 @@ +label($name, $options); + $options = $this->expandOptionArray($name, $label, $options); + $classes = $this->getHolderClasses($name); + $value = $this->fillFieldValue($name, $value); + $options['step'] = 'any'; + $defaultCurrency = isset($options['currency']) ? $options['currency'] : Amount::getDefaultCurrency(); + $currencies = TransactionCurrency::orderBy('code', 'ASC')->get(); + $html = View::make('form.balance', compact('defaultCurrency', 'currencies', 'classes', 'name', 'label', 'value', 'options'))->render(); + + return $html; + } + + /** + * @param $name + * @param $options + * + * @return mixed + */ + public function label($name, $options) + { + if (isset($options['label'])) { + return $options['label']; + } + $labels = ['amount_min' => 'Amount (min)', 'amount_max' => 'Amount (max)', 'match' => 'Matches on', 'repeat_freq' => 'Repetition', + 'account_from_id' => 'Account from', 'account_to_id' => 'Account to', 'account_id' => 'Asset account', 'budget_id' => 'Budget' + , 'piggy_bank_id' => 'Piggy bank']; + + + return isset($labels[$name]) ? $labels[$name] : str_replace('_', ' ', ucfirst($name)); + + } + + /** + * @param $name + * @param $label + * @param array $options + * + * @return array + */ + public function expandOptionArray($name, $label, array $options) + { + $options['class'] = 'form-control'; + $options['id'] = 'ffInput_' . $name; + $options['autocomplete'] = 'off'; + $options['placeholder'] = ucfirst($label); + + return $options; + } + + /** + * @param $name + * + * @return string + */ + public function getHolderClasses($name) + { + /* + * Get errors, warnings and successes from session: + */ + /** @var MessageBag $errors */ + $errors = Session::get('errors'); + + /** @var MessageBag $successes */ + $successes = Session::get('successes'); + + switch (true) { + case (!is_null($errors) && $errors->has($name)): + $classes = 'form-group has-error has-feedback'; + break; + case (!is_null($successes) && $successes->has($name)): + $classes = 'form-group has-success has-feedback'; + break; + default: + $classes = 'form-group'; + break; + } + + return $classes; + } + + /** + * @param $name + * @param $value + * + * @return mixed + */ + public function fillFieldValue($name, $value) + { + if (Session::has('preFilled')) { + $preFilled = \Session::get('preFilled'); + $value = isset($preFilled[$name]) && is_null($value) ? $preFilled[$name] : $value; + } + if (!is_null(Input::old($name))) { + $value = Input::old($name); + } + + return $value; + } + + /** + * @param $name + * @param int $value + * @param null $checked + * @param array $options + * + * @return string + */ + public function checkbox($name, $value = 1, $checked = null, $options = []) + { + $options['checked'] = $checked === true ? true : null; + $label = $this->label($name, $options); + $options = $this->expandOptionArray($name, $label, $options); + $classes = $this->getHolderClasses($name); + $value = $this->fillFieldValue($name, $value); + + unset($options['placeholder'], $options['autocomplete'], $options['class']); + + $html = View::make('form.checkbox', compact('classes', 'name', 'label', 'value', 'options'))->render(); + + return $html; + } + + /** + * @param $name + * @param null $value + * @param array $options + * + * @return string + */ + public function date($name, $value = null, array $options = []) + { + $label = $this->label($name, $options); + $options = $this->expandOptionArray($name, $label, $options); + $classes = $this->getHolderClasses($name); + $value = $this->fillFieldValue($name, $value); + $html = View::make('form.date', compact('classes', 'name', 'label', 'value', 'options'))->render(); + + return $html; + } + + /** + * @param $type + * @param $name + * + * @return string + */ + public function optionsList($type, $name) + { + $previousValue = \Input::old('post_submit_action'); + $previousValue = is_null($previousValue) ? 'store' : $previousValue; + $html = \View::make('form.options', compact('type', 'name', 'previousValue'))->render(); + + return $html; + } + + public function select($name, array $list = [], $selected = null, array $options = []) + { + $label = $this->label($name, $options); + $options = $this->expandOptionArray($name, $label, $options); + $classes = $this->getHolderClasses($name); + $selected = $this->fillFieldValue($name, $selected); + $html = \View::make('form.select', compact('classes', 'name', 'label', 'selected', 'options', 'list'))->render(); + + return $html; + } + + /** + * @param $name + * @param null $value + * @param array $options + * + * @return string + */ + public function text($name, $value = null, array $options = []) + { + $label = $this->label($name, $options); + $options = $this->expandOptionArray($name, $label, $options); + $classes = $this->getHolderClasses($name); + $value = $this->fillFieldValue($name, $value); + $html = View::make('form.text', compact('classes', 'name', 'label', 'value', 'options'))->render(); + + return $html; + + } +} \ No newline at end of file diff --git a/app/Support/Facades/ExpandedForm.php b/app/Support/Facades/ExpandedForm.php new file mode 100644 index 0000000000..008e85d7a7 --- /dev/null +++ b/app/Support/Facades/ExpandedForm.php @@ -0,0 +1,23 @@ +where($parameters[1],$value)->count(); + if($count == 0) { + return true; + } + return false; + + } +} + diff --git a/bootstrap/app.php b/bootstrap/app.php index ebe5d21ae4..e3697dc4ad 100644 --- a/bootstrap/app.php +++ b/bootstrap/app.php @@ -11,6 +11,8 @@ | */ +use FireflyIII\Validation\FireflyValidator; + $app = new Illuminate\Foundation\Application( realpath(__DIR__.'/../') ); diff --git a/config/app.php b/config/app.php index 377fc5eedf..3c67782ca7 100644 --- a/config/app.php +++ b/config/app.php @@ -164,44 +164,45 @@ return [ 'aliases' => [ - 'App' => 'Illuminate\Support\Facades\App', - 'Artisan' => 'Illuminate\Support\Facades\Artisan', - 'Auth' => 'Illuminate\Support\Facades\Auth', - 'Blade' => 'Illuminate\Support\Facades\Blade', - 'Bus' => 'Illuminate\Support\Facades\Bus', - 'Cache' => 'Illuminate\Support\Facades\Cache', - 'Config' => 'Illuminate\Support\Facades\Config', - 'Cookie' => 'Illuminate\Support\Facades\Cookie', - 'Crypt' => 'Illuminate\Support\Facades\Crypt', - 'DB' => 'Illuminate\Support\Facades\DB', - 'Eloquent' => 'Illuminate\Database\Eloquent\Model', - 'Event' => 'Illuminate\Support\Facades\Event', - 'File' => 'Illuminate\Support\Facades\File', - 'Hash' => 'Illuminate\Support\Facades\Hash', - 'Input' => 'Illuminate\Support\Facades\Input', - 'Inspiring' => 'Illuminate\Foundation\Inspiring', - 'Lang' => 'Illuminate\Support\Facades\Lang', - 'Log' => 'Illuminate\Support\Facades\Log', - 'Mail' => 'Illuminate\Support\Facades\Mail', - 'Password' => 'Illuminate\Support\Facades\Password', - 'Queue' => 'Illuminate\Support\Facades\Queue', - 'Redirect' => 'Illuminate\Support\Facades\Redirect', - 'Redis' => 'Illuminate\Support\Facades\Redis', - 'Request' => 'Illuminate\Support\Facades\Request', - 'Response' => 'Illuminate\Support\Facades\Response', - 'Route' => 'Illuminate\Support\Facades\Route', - 'Schema' => 'Illuminate\Support\Facades\Schema', - 'Session' => 'Illuminate\Support\Facades\Session', - 'Storage' => 'Illuminate\Support\Facades\Storage', - 'URL' => 'Illuminate\Support\Facades\URL', - 'Validator' => 'Illuminate\Support\Facades\Validator', - 'View' => 'Illuminate\Support\Facades\View', - 'Form' => 'Illuminate\Html\FormFacade', - 'Html' => 'Illuminate\Html\HtmlFacade', - 'Preferences' => 'FireflyIII\Support\Facades\Preferences', - 'Navigation' => 'FireflyIII\Support\Facades\Navigation', - 'Amount' => 'FireflyIII\Support\Facades\Amount', - 'Steam' => 'FireflyIII\Support\Facades\Steam', + 'App' => 'Illuminate\Support\Facades\App', + 'Artisan' => 'Illuminate\Support\Facades\Artisan', + 'Auth' => 'Illuminate\Support\Facades\Auth', + 'Blade' => 'Illuminate\Support\Facades\Blade', + 'Bus' => 'Illuminate\Support\Facades\Bus', + 'Cache' => 'Illuminate\Support\Facades\Cache', + 'Config' => 'Illuminate\Support\Facades\Config', + 'Cookie' => 'Illuminate\Support\Facades\Cookie', + 'Crypt' => 'Illuminate\Support\Facades\Crypt', + 'DB' => 'Illuminate\Support\Facades\DB', + 'Eloquent' => 'Illuminate\Database\Eloquent\Model', + 'Event' => 'Illuminate\Support\Facades\Event', + 'File' => 'Illuminate\Support\Facades\File', + 'Hash' => 'Illuminate\Support\Facades\Hash', + 'Input' => 'Illuminate\Support\Facades\Input', + 'Inspiring' => 'Illuminate\Foundation\Inspiring', + 'Lang' => 'Illuminate\Support\Facades\Lang', + 'Log' => 'Illuminate\Support\Facades\Log', + 'Mail' => 'Illuminate\Support\Facades\Mail', + 'Password' => 'Illuminate\Support\Facades\Password', + 'Queue' => 'Illuminate\Support\Facades\Queue', + 'Redirect' => 'Illuminate\Support\Facades\Redirect', + 'Redis' => 'Illuminate\Support\Facades\Redis', + 'Request' => 'Illuminate\Support\Facades\Request', + 'Response' => 'Illuminate\Support\Facades\Response', + 'Route' => 'Illuminate\Support\Facades\Route', + 'Schema' => 'Illuminate\Support\Facades\Schema', + 'Session' => 'Illuminate\Support\Facades\Session', + 'Storage' => 'Illuminate\Support\Facades\Storage', + 'URL' => 'Illuminate\Support\Facades\URL', + 'Validator' => 'Illuminate\Support\Facades\Validator', + 'View' => 'Illuminate\Support\Facades\View', + 'Form' => 'Illuminate\Html\FormFacade', + 'Html' => 'Illuminate\Html\HtmlFacade', + 'Preferences' => 'FireflyIII\Support\Facades\Preferences', + 'Navigation' => 'FireflyIII\Support\Facades\Navigation', + 'Amount' => 'FireflyIII\Support\Facades\Amount', + 'Steam' => 'FireflyIII\Support\Facades\Steam', + 'ExpandedForm' => 'FireflyIII\Support\Facades\ExpandedForm', ], diff --git a/resources/views/accounts/create.blade.php b/resources/views/accounts/create.blade.php new file mode 100644 index 0000000000..0b0df1b5d5 --- /dev/null +++ b/resources/views/accounts/create.blade.php @@ -0,0 +1,60 @@ +@extends('layouts.default') +@section('content') +{{-- Breadcrumbs::renderIfExists(Route::getCurrentRoute()->getName(), $what) --}} +{!! Form::open(['class' => 'form-horizontal','id' => 'store','route' => 'accounts.store']) !!} +{!! Form::hidden('what',$what) !!} + +@foreach ($errors->all() as $error) +

{{ $error }}

+@endforeach + +
+
+
+
+ Mandatory fields +
+
+ {!! ExpandedForm::text('name') !!} +
+
+

+ +

+
+ +
+ + +
+
+ Optional fields +
+
+ @if($what == 'asset') + {!! ExpandedForm::balance('openingBalance') !!} + {!! ExpandedForm::date('openingBalanceDate', date('Y-m-d')) !!} + {!! ExpandedForm::select('account_role',Config::get('firefly.accountRoles')) !!} + @endif + {!! ExpandedForm::checkbox('active','1',true) !!} +
+
+ + + +
+
+ Options +
+
+ {!! ExpandedForm::optionsList('create','account') !!} +
+
+ +
+
+ + +@stop diff --git a/resources/views/form/amount.blade.php b/resources/views/form/amount.blade.php new file mode 100644 index 0000000000..82e462b490 --- /dev/null +++ b/resources/views/form/amount.blade.php @@ -0,0 +1,22 @@ +
+ +
+
+
+ + +
+ {{Form::input('number', $name, $value, $options)}} + + +
+ @include('form.feedback') +
+ {{Form::input('hidden','amount_currency_id',$defaultCurrency->id)}} +
\ No newline at end of file diff --git a/resources/views/form/balance.blade.php b/resources/views/form/balance.blade.php new file mode 100644 index 0000000000..50a834ecb9 --- /dev/null +++ b/resources/views/form/balance.blade.php @@ -0,0 +1,22 @@ +
+ +
+
+
+ + +
+ {!! Form::input('number', $name, $value, $options) !!} + +
+ @include('form.feedback') +
+ + {!! Form::input('hidden','balance_currency_id',$defaultCurrency->id) !!} +
\ No newline at end of file diff --git a/resources/views/form/checkbox.blade.php b/resources/views/form/checkbox.blade.php new file mode 100644 index 0000000000..038bac2dc5 --- /dev/null +++ b/resources/views/form/checkbox.blade.php @@ -0,0 +1,11 @@ +
+ +
+
+ +
+ @include('form.feedback') +
+
\ No newline at end of file diff --git a/resources/views/form/date.blade.php b/resources/views/form/date.blade.php new file mode 100644 index 0000000000..71ab250e1a --- /dev/null +++ b/resources/views/form/date.blade.php @@ -0,0 +1,7 @@ +
+ +
+ {!! Form::input('date', $name, $value, $options) !!} + @include('form.feedback') +
+
\ No newline at end of file diff --git a/resources/views/form/feedback.blade.php b/resources/views/form/feedback.blade.php new file mode 100644 index 0000000000..d6f895fdf2 --- /dev/null +++ b/resources/views/form/feedback.blade.php @@ -0,0 +1,12 @@ +@if($errors->has($name)) + +

{{{$errors->first($name)}}}

+@endif +@if(Session::has('warnings') && Session::get('warnings')->has($name)) + +

{{{Session::get('warnings')->first($name)}}}

+@endif +@if(Session::has('successes') && Session::get('successes')->has($name)) + +

{{{Session::get('successes')->first($name)}}}

+@endif \ No newline at end of file diff --git a/resources/views/form/integer.blade.php b/resources/views/form/integer.blade.php new file mode 100644 index 0000000000..cfd93a09c2 --- /dev/null +++ b/resources/views/form/integer.blade.php @@ -0,0 +1,9 @@ +
+ +
+
+ {!! Form::input('number', $name, $value, $options) !!} + @include('form.feedback') +
+
+
\ No newline at end of file diff --git a/resources/views/form/options.blade.php b/resources/views/form/options.blade.php new file mode 100644 index 0000000000..7c84250eea --- /dev/null +++ b/resources/views/form/options.blade.php @@ -0,0 +1,69 @@ +@if($type == 'create') +
+ +
+
+ +
+
+
+@endif +@if($type == 'update') +
+ +
+
+ +
+
+
+@endif + +
+ +
+
+ +
+
+
+ +@if($type == 'create') +
+ +
+
+ +
+
+
+@endif + +@if($type == 'update') +
+ +
+
+
+
+
+@endif \ No newline at end of file diff --git a/resources/views/form/select.blade.php b/resources/views/form/select.blade.php new file mode 100644 index 0000000000..6b5e8a2012 --- /dev/null +++ b/resources/views/form/select.blade.php @@ -0,0 +1,8 @@ +
+ +
+ {!! Form::select($name, $list, $selected , $options ) !!} + @include('form.feedback') + +
+
\ No newline at end of file diff --git a/resources/views/form/tags.blade.php b/resources/views/form/tags.blade.php new file mode 100644 index 0000000000..d9d0c31bd2 --- /dev/null +++ b/resources/views/form/tags.blade.php @@ -0,0 +1,7 @@ +
+ +
+ {!! Form::input('text', $name, $value, $options) !!} + @include('form.feedback') +
+
\ No newline at end of file diff --git a/resources/views/form/text.blade.php b/resources/views/form/text.blade.php new file mode 100644 index 0000000000..d9d0c31bd2 --- /dev/null +++ b/resources/views/form/text.blade.php @@ -0,0 +1,7 @@ +
+ +
+ {!! Form::input('text', $name, $value, $options) !!} + @include('form.feedback') +
+
\ No newline at end of file