From 3e5e5b376fd782d79a34c22c63be04d4ff931be0 Mon Sep 17 00:00:00 2001 From: James Cole Date: Fri, 1 May 2015 22:44:35 +0200 Subject: [PATCH] Made it almost to the accounts. --- app/Providers/ConfigServiceProvider.php | 4 +- app/Providers/FireflyServiceProvider.php | 6 +- .../{TwigSupport.php => Twig/General.php} | 51 ++++++-- app/Support/Twig/Journals.php | 78 ++++++++++++ public/js/sb-admin-2.js | 4 +- resources/twig/accounts/create.twig | 61 ++++++++++ resources/twig/accounts/delete.twig | 36 ++++++ resources/twig/accounts/edit.twig | 72 +++++++++++ resources/twig/accounts/index.twig | 46 +++++++ resources/twig/accounts/show.twig | 60 ++++++++++ resources/twig/index.twig | 3 - resources/twig/layout/default.twig | 69 ++++++----- resources/twig/list/accounts.twig | 59 +++++++++ resources/twig/list/journals.twig | 113 ++++++++++++++++++ resources/twig/partials/menu.twig | 42 +++---- 15 files changed, 633 insertions(+), 71 deletions(-) rename app/Support/{TwigSupport.php => Twig/General.php} (54%) create mode 100644 app/Support/Twig/Journals.php create mode 100644 resources/twig/accounts/create.twig create mode 100644 resources/twig/accounts/delete.twig create mode 100644 resources/twig/accounts/edit.twig create mode 100644 resources/twig/accounts/index.twig create mode 100644 resources/twig/accounts/show.twig create mode 100644 resources/twig/list/accounts.twig create mode 100644 resources/twig/list/journals.twig diff --git a/app/Providers/ConfigServiceProvider.php b/app/Providers/ConfigServiceProvider.php index c4deebb1d1..77dd2eef93 100644 --- a/app/Providers/ConfigServiceProvider.php +++ b/app/Providers/ConfigServiceProvider.php @@ -161,7 +161,9 @@ class ConfigServiceProvider extends ServiceProvider ] ], 'Session', - 'Route' + 'Route', + 'Config', + 'ExpandedForm' ], /* diff --git a/app/Providers/FireflyServiceProvider.php b/app/Providers/FireflyServiceProvider.php index 844db98847..b9d5601eaa 100644 --- a/app/Providers/FireflyServiceProvider.php +++ b/app/Providers/FireflyServiceProvider.php @@ -9,7 +9,8 @@ use FireflyIII\Support\ExpandedForm; use FireflyIII\Support\Navigation; use FireflyIII\Support\Preferences; use FireflyIII\Support\Steam; -use FireflyIII\Support\TwigSupport; +use FireflyIII\Support\Twig\General; +use FireflyIII\Support\Twig\Journals; use FireflyIII\Validation\FireflyValidator; use Illuminate\Support\ServiceProvider; use Twig; @@ -36,7 +37,8 @@ class FireflyServiceProvider extends ServiceProvider $config = App::make('config'); Twig::addExtension(new Functions($config)); - Twig::addExtension(new TwigSupport); + Twig::addExtension(new General); + Twig::addExtension(new Journals); } public function register() diff --git a/app/Support/TwigSupport.php b/app/Support/Twig/General.php similarity index 54% rename from app/Support/TwigSupport.php rename to app/Support/Twig/General.php index 9e09690a3a..e80e327bdc 100644 --- a/app/Support/TwigSupport.php +++ b/app/Support/Twig/General.php @@ -1,8 +1,9 @@ format(App::make('steam')->balance($account)); - }, ['is_safe' => ['html']] - ); - $filters[] = new Twig_SimpleFilter( - 'activeRoute', function ($string) { - if (Route::getCurrentRoute()->getName() == $string) { - return 'active'; - } - - return ''; + return App::make('steam')->balance($account); } ); + + // should be a function but OK + $filters[] = new Twig_SimpleFilter( + 'getAccountRole', function ($name) { + return Config::get('firefly.accountRoles.' . $name); + } + ); + return $filters; } @@ -68,12 +71,34 @@ class TwigSupport extends Twig_Extension } ); + $functions[] = new Twig_SimpleFunction( 'env', function ($name, $default) { return env($name, $default); } ); + $functions[] = new Twig_SimpleFunction( + 'activeRoute', function ($context) { + $args = func_get_args(); + $route = $args[1]; + $what = isset($args[2]) ? $args[2] : false; + $activeWhat = isset($context['what']) ? $context['what'] : false; + // activeRoute + if (!($what === false)) { + if ($what == $activeWhat && Route::getCurrentRoute()->getName() == $route) { + return 'active because-active-what'; + } + } else { + if (Route::getCurrentRoute()->getName() == $route) { + return 'active because-route-matches'; + } + } + + return 'not-xxx-at-all'; + }, ['needs_context' => true] + ); + return $functions; @@ -84,7 +109,7 @@ class TwigSupport extends Twig_Extension */ public function getName() { - return 'FireflyIII\Support\TwigSupport'; + return 'FireflyIII\Support\Twig\General'; } } \ No newline at end of file diff --git a/app/Support/Twig/Journals.php b/app/Support/Twig/Journals.php new file mode 100644 index 0000000000..a8c2105832 --- /dev/null +++ b/app/Support/Twig/Journals.php @@ -0,0 +1,78 @@ +transactionType->type; + if ($type == 'Withdrawal') { + return ''; + } + if ($type == 'Deposit') { + return ''; + } + if ($type == 'Transfer') { + return ''; + } + if ($type == 'Opening balance') { + return ''; + } + + + }, ['is_safe' => ['html']] + ); + + return $filters; + } + + public function getFunctions() + { + $functions = []; + + $functions[] = new Twig_SimpleFunction( + 'invalidJournal', function (TransactionJournal $journal) { + if (!isset($journal->transactions[1]) || !isset($journal->transactions[0])) { + return true; + } + + return false; + } + ); + + $functions[] = new Twig_SimpleFunction( + 'relevantTags', function (TransactionJournal $journal) { + return 'TODO'.$journal->amount; + } + ); + + return $functions; + } + + /** + * Returns the name of the extension. + * + * @return string The extension name + */ + public function getName() + { + return 'FireflyIII\Support\Twig\Journals'; + } +} \ No newline at end of file diff --git a/public/js/sb-admin-2.js b/public/js/sb-admin-2.js index 5be2c883ad..469460fd16 100755 --- a/public/js/sb-admin-2.js +++ b/public/js/sb-admin-2.js @@ -29,8 +29,8 @@ $(function() { var url = window.location; var element = $('ul.nav a').filter(function() { return this.href == url || url.href.indexOf(this.href) == 0; - }).addClass('active').parent().parent().addClass('in').parent(); + }).parent().parent().addClass('in').parent();/*addClass('active')*/ if (element.is('li')) { - element.addClass('active'); + //element.addClass('active'); } }); diff --git a/resources/twig/accounts/create.twig b/resources/twig/accounts/create.twig new file mode 100644 index 0000000000..9439400236 --- /dev/null +++ b/resources/twig/accounts/create.twig @@ -0,0 +1,61 @@ +{% extends "./layout/default.twig" %} +{% block content %} + {{ Breadcrumbs.renderIfExists(Route.getCurrentRoute.getName, what) }} +
+ + +
+
+
+
+ Mandatory fields +
+
+ {{ ExpandedForm.text('name') }} +
+
+
+ +
+ + @if(what == 'asset') +
+
+ Optional fields +
+
+ + {{ ExpandedForm.balance('openingBalance') }} + {{ ExpandedForm.date('openingBalanceDate', date('Y-m-d')) }} + {{ ExpandedForm.select('accountRole',Config.get('firefly.accountRoles'), null, {'helpText' : 'Any extra options resulting from your choice can be set later.'}) }} + {{ ExpandedForm.balance('virtualBalance') }} + +
+
+ @endif + + +
+
+ Options +
+
+ {{ ExpandedForm.optionsList('create','account') }} +
+
+ +
+
+
+
+

+ +

+
+
+ +
+--> +{% endblock %} \ No newline at end of file diff --git a/resources/twig/accounts/delete.twig b/resources/twig/accounts/delete.twig new file mode 100644 index 0000000000..f6ee597cdb --- /dev/null +++ b/resources/twig/accounts/delete.twig @@ -0,0 +1,36 @@ +{% extends "./layout/default.twig" %} +{% block content %} +{!! Breadcrumbs::renderIfExists(Route::getCurrentRoute()->getName(), $account) !!} +{!! Form::open(['class' => 'form-horizontal','id' => 'destroy','url' => route('accounts.destroy',$account->id)]) !!} +
+
+
+
+ Delete account "{{{$account->name}}}" +
+
+

+ Are you sure that you want to delete the {{strtolower($account->accountType->type)}} "{{$account->name}}"? +

+ + @if($account->transactions()->count() > 0) +

+ {{ucfirst($account->accountType->type)}} "{{{$account->name}}}" still has {{$account->transactions()->count()}} transaction(s) associated to it. These will be deleted as well. +

+ @endif + @if($account->piggyBanks()->count() > 0) +

+ {{ucfirst($account->accountType->type)}} "{{{$account->name}}}" still has {{$account->piggyBanks()->count()}} piggy bank(s) associated to it. These will be deleted as well. +

+ @endif +

+ + Cancel +

+
+
+
+
+ +{!! Form::close() !!} +{% endblock %} diff --git a/resources/twig/accounts/edit.twig b/resources/twig/accounts/edit.twig new file mode 100644 index 0000000000..0ecfceb939 --- /dev/null +++ b/resources/twig/accounts/edit.twig @@ -0,0 +1,72 @@ +{% extends "./layout/default.twig" %} +{% block content %} +{!! Breadcrumbs::renderIfExists(Route::getCurrentRoute()->getName(), $account) !!} +{!! Form::model($account, ['class' => 'form-horizontal','id' => 'update','url' => route('accounts.update',$account->id)]) !!} + + + +
+
+
+
+ Mandatory fields +
+
+ {!! ExpandedForm::text('name') !!} +
+
+ +
+
+
+
+ Optional fields +
+
+ @if($account->accounttype->type == 'Default account' || $account->accounttype->type == 'Asset account') + {!! ExpandedForm::balance('openingBalance',null, ['currency' => $openingBalance ? $openingBalance->transactionCurrency : null]) !!} + {!! ExpandedForm::date('openingBalanceDate') !!} + {!! ExpandedForm::select('accountRole',Config::get('firefly.accountRoles')) !!} + {!! ExpandedForm::balance('virtualBalance',null) !!} + {!! Form::hidden('id',$account->id) !!} + @endif + {!! ExpandedForm::checkbox('active','1') !!} +
+
+ + + @if(Session::get('preFilled')['accountRole'] == 'ccAsset') +
+
+ Credit card options +
+
+ {!! ExpandedForm::select('ccType',Config::get('firefly.ccTypes')) !!} + {!! ExpandedForm::date('ccMonthlyPaymentDate',null,['helpText' => 'Select any year and any month, it will be ignored anway. Only the day of the month is relevant.']) !!} +
+
+ @endif + + +
+
+ Options +
+
+ {!! ExpandedForm::optionsList('update','account') !!} +
+
+
+
+
+
+

+ +

+
+
+ +{!! Form::close() !!} +{% endblock %} diff --git a/resources/twig/accounts/index.twig b/resources/twig/accounts/index.twig new file mode 100644 index 0000000000..a596dd3111 --- /dev/null +++ b/resources/twig/accounts/index.twig @@ -0,0 +1,46 @@ +{% extends "./layout/default.twig" %} +{% block content %} +{{ Breadcrumbs.renderIfExists(Route.getCurrentRoute.getName, what) }} +
+
+
+
+ {{ subTitle}} + + +
+
+ + +
+
+ + +
+ {% include 'list/accounts.twig' %} +
+
+
+{% endblock %} + +{% block styles %} + +{% endblock %} + +{% block scripts %} + + + + + + + + +{% endblock %} diff --git a/resources/twig/accounts/show.twig b/resources/twig/accounts/show.twig new file mode 100644 index 0000000000..59ea7654ae --- /dev/null +++ b/resources/twig/accounts/show.twig @@ -0,0 +1,60 @@ +{% extends "./layout/default.twig" %} +{% block content %} +{{ Breadcrumbs.renderIfExists(Route.getCurrentRoute.getName, account) }} +
+
+
+
+ {{ account.name }} + + + +
+
+ + +
+
+
+
+
+
+
+
+
+ + +
+
+
+
+ Transactions +
+
+ {% include 'list/journals.twig' with {sorting:true} %} +
+
+
+ + + +{% endblock %} + +{% block scripts %} + + + + + + + + +{% endblock %} \ No newline at end of file diff --git a/resources/twig/index.twig b/resources/twig/index.twig index c767243e4c..91956567ad 100644 --- a/resources/twig/index.twig +++ b/resources/twig/index.twig @@ -204,9 +204,6 @@ {% endblock %} {% block scripts %} - diff --git a/resources/twig/layout/default.twig b/resources/twig/layout/default.twig index 58d5289c8e..cfe1190903 100644 --- a/resources/twig/layout/default.twig +++ b/resources/twig/layout/default.twig @@ -11,19 +11,19 @@ {% endif %} {% if subTitle %} - // {{subTitle}} + // {{ subTitle }} {% endif %} - - - - - - + + + + + + - + - + {% block styles %}{% endblock %} @@ -52,7 +52,7 @@
- {% include('partials/menu.twig') %} + {% include 'partials/menu.twig' %}
@@ -60,20 +60,21 @@

{% if mainTitleIcon %} - + {% endif %} {{ title }} {% if subTitle %} - - {% if subTitleIcon %} - - {% endif %} - {{ subTitle }} - + + {% if subTitleIcon %} + + {% endif %} + {{ subTitle }} + {% endif %} - +

@@ -88,18 +89,20 @@ -
+
+
@@ -130,26 +133,34 @@ var token = "{{csrf_token()}}"; var firstDate = moment("{{Session.get('first').format('Y-m-d')}}"); var currentMonthName = "{{ currentMonthName }}"; - var previousMonthName = "{{ previousMonthName }}"; - var nextMonthName = "{{ nextMonthName }}"; - $('#daterange span').text(titleString); + var previousMonthName = "{{ previousMonthName }}"; + var nextMonthName = "{{ nextMonthName }}"; + var currencyCode = '{{getCurrencyCode() }}'; + $('#daterange span').text(titleString); {% block scripts %}{% endblock %} diff --git a/resources/twig/list/accounts.twig b/resources/twig/list/accounts.twig new file mode 100644 index 0000000000..200f09eb04 --- /dev/null +++ b/resources/twig/list/accounts.twig @@ -0,0 +1,59 @@ + + + + + + {% if what == 'asset' %} + + {% endif %} + + + + + + + + {% for account in accounts %} + + + + {% if what == "asset" %} + + {% endif %} + + + {% if account.lastActivityDate %} + + {% else %} + + {% endif %} + + + + + {% endfor %} + +
 NameRoleCurrent balanceActiveLast activityBalance difference between {{ Session.get('start').format('jS F Y') }} and {{ Session.get('end').format('jS F Y') }}
+
+ + +
+
{{ account.name }} + {% for entry in account.accountmeta %} + {% if entry.name == 'accountRole' %} + {{ entry.data|getAccountRole }} + {% endif %} + {% endfor %} + {{ account|balance|formatAmount }} + {% if account.active %} + + {% else %} + + {% endif %} + + {{ account.lastActivityDate.format('j F Y') }} + + Never + + {{ (account.endBalance - account.startBalance)|formatAmount }} +
\ No newline at end of file diff --git a/resources/twig/list/journals.twig b/resources/twig/list/journals.twig new file mode 100644 index 0000000000..34ff958003 --- /dev/null +++ b/resources/twig/list/journals.twig @@ -0,0 +1,113 @@ +{{ journals.render }} + + + + + + + + + + + {% if not hideBudgets %} + + {% endif %} + + + {% if not hideCategories %} + + {% endif %} + + + {% if not hideBills %} + + {% endif %} + + {% for journal in journals %} + {% if invalidJournal(journal) %} + + + + + + + {% else %} + + + + + + + + + + + + {% if not hideBudgets %} + + {% endif %} + + + {% if not hideCategories %} + + {% endif %} + + + {% if not hideBills %} + + {% endif %} + + {% endif %} + + {% endfor %} +
 DescriptionAmountDateFromTo
+
+ +
+
 {{ journal.description }}Invalid journal: Found {{journal.transactions.count() }} transaction(s)
+
+ {% if sorting %} + + {% endif %} + + +
+
+ {{ journal|typeIcon }} + + {{journal.description}} + + {% if not hideTags %} + {{ relevantTags(journal) }} + {% else %} + {{ journal|formatJournal }} + {% endif %} + + {{journal.date.format('j F Y')}} + + {% if journal.transactions[0].account.accountType.type == 'Cash account' %} + (cash) + {% else %} + {{journal.transactions[0].account.name}} + {% endif %} + + {% if journal.transactions[1].account.accountType.type == 'Cash account' %} + (cash) + {% else %} + {{journal.transactions[1].account.name}} + {% endif %} + + {% if journal.budgets[0] %} + {{journal.budgets[0].name}} + {% endif %} + + {% if journal.categories[0] %} + {{journal.categories[0].name}} + {% endif %} + + {% if journal.bill %} + {{journal.bill.name}} + {% endif %} +
+ +{{ journals.render }} diff --git a/resources/twig/partials/menu.twig b/resources/twig/partials/menu.twig index 2c6dfe5056..91eec49241 100644 --- a/resources/twig/partials/menu.twig +++ b/resources/twig/partials/menu.twig @@ -90,86 +90,86 @@
  • - Dashboard + Dashboard
  • -
  • +
  • Accounts
  • - Budgets + Budgets
  • - Categories + Categories
  • - Tags + Tags
  • - Reports + Reports
  • -
  • +
  • Transactions
  • -
  • +
  • Money management
  • -
  • +
  • Create new