Skip to content

Firefly III: a personal finances manager

Reinstated soft deletes, added first steps for account controller.

James Cole3d01669cea0d
diff --git a/app/Http/Controllers/AccountController.php b/app/Http/Controllers/AccountController.php
new file mode 100644
index 0000000000..2af08d0dd1
--- /dev/null
+++ b/app/Http/Controllers/AccountController.php
@@ -0,0 +1,32 @@
+<?php namespace FireflyIII\Http\Controllers;
+
+use Auth;
+use Config;
+use FireflyIII\Http\Requests;
+use Illuminate\Http\Request;
+use View;
+
+/**
+ * Class AccountController
+ *
+ * @package FireflyIII\Http\Controllers
+ */
+class AccountController extends Controller
+{
+ public function __construct()
+ {
+ View::share('mainTitleIcon', 'fa-credit-card');
+ View::share('title', 'Accounts');
+ }
+
+ public function index($what = 'default')
+ {
+ $subTitle = Config::get('firefly.subTitlesByIdentifier.' . $what);
+ $subTitleIcon = Config::get('firefly.subIconsByIdentifier.' . $what);
+ $types = Config::get('firefly.accountTypesByIdentifier.' . $what);
+ $accounts = Auth::user()->accounts()->accountTypeIn($types)->get(['accounts.*']);
+
+ return view('accounts.index', compact('what', 'subTitleIcon', 'subTitle', 'accounts'));
+ }
+
+}
diff --git a/app/Http/Controllers/GoogleChartController.php b/app/Http/Controllers/GoogleChartController.php
index dfd6ff5249..ec59d392ba 100644
--- a/app/Http/Controllers/GoogleChartController.php
+++ b/app/Http/Controllers/GoogleChartController.php
@@ -4,15 +4,19 @@ use Auth;
use Carbon\Carbon;
use FireflyIII\Http\Requests;
use FireflyIII\Models\Account;
+use FireflyIII\Models\Bill;
use FireflyIII\Models\Budget;
use FireflyIII\Models\LimitRepetition;
+use FireflyIII\Models\TransactionJournal;
use Grumpydictator\Gchart\GChart;
use Illuminate\Database\Query\Builder as QueryBuilder;
+use Illuminate\Database\Query\JoinClause;
use Illuminate\Http\Request;
use Preferences;
use Response;
use Session;
use Steam;
+use Crypt;
/**
* Class GoogleChartController
@@ -133,5 +137,92 @@ class GoogleChartController extends Controller
return Response::json($chart->getData());
}
+ public function allCategoriesHomeChart(GChart $chart)
+ {
+ $chart->addColumn('Category', 'string');
+ $chart->addColumn('Spent', 'number');
+
+ // query!
+ $start = Session::get('start', Carbon::now()->startOfMonth());
+ $end = Session::get('end', Carbon::now()->endOfMonth());
+ $set = TransactionJournal::leftJoin(
+ 'transactions',
+ function (JoinClause $join) {
+ $join->on('transaction_journals.id', '=', 'transactions.transaction_journal_id')->where('amount', '>', 0);
+ }
+ )
+ ->leftJoin(
+ 'category_transaction_journal', 'category_transaction_journal.transaction_journal_id', '=', 'transaction_journals.id'
+ )
+ ->leftJoin('categories', 'categories.id', '=', 'category_transaction_journal.category_id')
+ ->leftJoin('transaction_types', 'transaction_types.id', '=', 'transaction_journals.transaction_type_id')
+ ->before($end)
+ ->after($start)
+ ->where('transaction_types.type', 'Withdrawal')
+ ->groupBy('categories.id')
+ ->orderBy('sum', 'DESC')
+ ->get(['categories.id', 'categories.name', \DB::Raw('SUM(`transactions`.`amount`) AS `sum`')]);
+
+ foreach ($set as $entry) {
+ $entry->name = strlen($entry->name) == 0 ? '(no category)' : $entry->name;
+ $chart->addRow($entry->name, floatval($entry->sum));
+ }
+
+ $chart->generate();
+
+ return Response::json($chart->getData());
+
+ }
+
+ public function billsOverview(GChart $chart)
+ {
+ $paid = ['items' => [], 'amount' => 0];
+ $unpaid = ['items' => [], 'amount' => 0];
+ $start = Session::get('start', Carbon::now()->startOfMonth());
+ $end = Session::get('end', Carbon::now()->endOfMonth());
+
+ $chart->addColumn('Name', 'string');
+ $chart->addColumn('Amount', 'number');
+
+ $set = Bill::
+ leftJoin(
+ 'transaction_journals', function (JoinClause $join) use ($start, $end) {
+ $join->on('bills.id', '=', 'transaction_journals.bill_id')
+ ->where('transaction_journals.date', '>=', $start->format('Y-m-d'))
+ ->where('transaction_journals.date', '<=', $end->format('Y-m-d'));
+ }
+ )
+ ->leftJoin(
+ 'transactions', function (JoinClause $join) {
+ $join->on('transaction_journals.id', '=', 'transactions.transaction_journal_id')->where('transactions.amount', '>', 0);
+ }
+ )
+ ->where('active', 1)
+ ->groupBy('bills.id')
+ ->get(
+ ['bills.id', 'bills.name', 'transaction_journals.description',
+ 'transaction_journals.encrypted',
+ 'transaction_journals.id as journalId',
+ \DB::Raw('SUM(`bills`.`amount_min` + `bills`.`amount_max`) / 2 as `averageAmount`'),
+ 'transactions.amount AS actualAmount']
+ );
+
+ foreach ($set as $entry) {
+ if (intval($entry->journalId) == 0) {
+ $unpaid['items'][] = $entry->name;
+ $unpaid['amount'] += floatval($entry->averageAmount);
+ } else {
+ $description = intval($entry->encrypted) == 1 ? Crypt::decrypt($entry->description) : $entry->description;
+ $paid['items'][] = $description;
+ $paid['amount'] += floatval($entry->actualAmount);
+ }
+ }
+ $chart->addRow('Unpaid: ' . join(', ', $unpaid['items']), $unpaid['amount']);
+ $chart->addRow('Paid: ' . join(', ', $paid['items']), $paid['amount']);
+ $chart->generate();
+
+ return Response::json($chart->getData());
+ }
+
}
diff --git a/app/Http/routes.php b/app/Http/routes.php
index e6f4c05abb..b450730ae3 100644
--- a/app/Http/routes.php
+++ b/app/Http/routes.php
@@ -15,8 +15,8 @@ Route::group(
*/
Route::get('/accounts/{what}', ['uses' => 'AccountController@index', 'as' => 'accounts.index'])->where('what', 'revenue|asset|expense');
Route::get('/accounts/create/{what}', ['uses' => 'AccountController@create', 'as' => 'accounts.create'])->where('what', 'revenue|asset|expense');
- //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/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']);
/**
@@ -64,8 +64,8 @@ Route::group(
*/
Route::get('/chart/home/account', ['uses' => 'GoogleChartController@allAccountsBalanceChart']);
Route::get('/chart/home/budgets', ['uses' => 'GoogleChartController@allBudgetsHomeChart']);
- //Route::get('/chart/home/categories', ['uses' => 'GoogleChartController@allCategoriesHomeChart']);
- //Route::get('/chart/home/bills', ['uses' => 'GoogleChartController@billsOverview']);
+ Route::get('/chart/home/categories', ['uses' => 'GoogleChartController@allCategoriesHomeChart']);
+ Route::get('/chart/home/bills', ['uses' => 'GoogleChartController@billsOverview']);
//Route::get('/chart/account/{account}/{view?}', ['uses' => 'GoogleChartController@accountBalanceChart']);
//Route::get('/chart/reports/income-expenses/{year}', ['uses' => 'GoogleChartController@yearInExp']);
//Route::get('/chart/reports/income-expenses-sum/{year}', ['uses' => 'GoogleChartController@yearInExpSum']);
diff --git a/app/Models/Account.php b/app/Models/Account.php
index 88d31b7578..ce10f0a971 100644
--- a/app/Models/Account.php
+++ b/app/Models/Account.php
@@ -2,6 +2,7 @@
use Illuminate\Database\Eloquent\Builder as EloquentBuilder;
use Illuminate\Database\Eloquent\Model;
+use Illuminate\Database\Eloquent\SoftDeletes;
/**
* Class Account
@@ -10,6 +11,7 @@ use Illuminate\Database\Eloquent\Model;
*/
class Account extends Model
{
+ use SoftDeletes;
public function accountMeta()
{
diff --git a/app/Models/Budget.php b/app/Models/Budget.php
index 58f0c0ed64..ca32aeec57 100644
--- a/app/Models/Budget.php
+++ b/app/Models/Budget.php
@@ -1,10 +1,12 @@
<?php namespace FireflyIII\Models;
use Illuminate\Database\Eloquent\Model;
+use Illuminate\Database\Eloquent\SoftDeletes;
class Budget extends Model
{
+ use SoftDeletes;
public function budgetlimits()
{
diff --git a/app/Models/Category.php b/app/Models/Category.php
index 0e0fbd6dda..21e5009739 100644
--- a/app/Models/Category.php
+++ b/app/Models/Category.php
@@ -1,9 +1,11 @@
<?php namespace FireflyIII\Models;
use Illuminate\Database\Eloquent\Model;
+use Illuminate\Database\Eloquent\SoftDeletes;
class Category extends Model
{
+ use SoftDeletes;
public function getDates()
{
diff --git a/app/Models/Component.php b/app/Models/Component.php
index 43a462e80a..c79422d80e 100644
--- a/app/Models/Component.php
+++ b/app/Models/Component.php
@@ -1,9 +1,11 @@
<?php namespace FireflyIII\Models;
use Illuminate\Database\Eloquent\Model;
+use Illuminate\Database\Eloquent\SoftDeletes;
class Component extends Model
{
+ use SoftDeletes;
public function getDates()
{
diff --git a/app/Models/PiggyBank.php b/app/Models/PiggyBank.php
index 55139268d5..2f332cfce8 100644
--- a/app/Models/PiggyBank.php
+++ b/app/Models/PiggyBank.php
@@ -1,9 +1,11 @@
<?php namespace FireflyIII\Models;
use Illuminate\Database\Eloquent\Model;
+use Illuminate\Database\Eloquent\SoftDeletes;
class PiggyBank extends Model
{
+ use SoftDeletes;
public function account()
{
diff --git a/app/Models/Transaction.php b/app/Models/Transaction.php
index 7eb172a1cb..362ca5a032 100644
--- a/app/Models/Transaction.php
+++ b/app/Models/Transaction.php
@@ -1,9 +1,11 @@
<?php namespace FireflyIII\Models;
use Illuminate\Database\Eloquent\Model;
+use Illuminate\Database\Eloquent\SoftDeletes;
class Transaction extends Model
{
+ use SoftDeletes;
public function account()
{
diff --git a/app/Models/TransactionCurrency.php b/app/Models/TransactionCurrency.php
index 4dac839a3f..731026e55f 100644
--- a/app/Models/TransactionCurrency.php
+++ b/app/Models/TransactionCurrency.php
@@ -1,9 +1,11 @@
<?php namespace FireflyIII\Models;
use Illuminate\Database\Eloquent\Model;
+use Illuminate\Database\Eloquent\SoftDeletes;
class TransactionCurrency extends Model
{
+ use SoftDeletes;
public function getDates()
{
diff --git a/app/Models/TransactionGroup.php b/app/Models/TransactionGroup.php
index 0828846de7..dad9d4d42b 100644
--- a/app/Models/TransactionGroup.php
+++ b/app/Models/TransactionGroup.php
@@ -1,9 +1,11 @@
<?php namespace FireflyIII\Models;
use Illuminate\Database\Eloquent\Model;
+use Illuminate\Database\Eloquent\SoftDeletes;
class TransactionGroup extends Model
{
+ use SoftDeletes;
public function getDates()
{
diff --git a/app/Models/TransactionJournal.php b/app/Models/TransactionJournal.php
index 1d712f0021..6540f93a63 100644
--- a/app/Models/TransactionJournal.php
+++ b/app/Models/TransactionJournal.php
@@ -4,9 +4,11 @@ use Carbon\Carbon;
use Crypt;
use Illuminate\Database\Eloquent\Builder as EloquentBuilder;
use Illuminate\Database\Eloquent\Model;
+use Illuminate\Database\Eloquent\SoftDeletes;
class TransactionJournal extends Model
{
+ use SoftDeletes;
public function bill()
{
diff --git a/app/Models/TransactionType.php b/app/Models/TransactionType.php
index 2261ef16b5..1010173cd3 100644
--- a/app/Models/TransactionType.php
+++ b/app/Models/TransactionType.php
@@ -1,9 +1,11 @@
<?php namespace FireflyIII\Models;
use Illuminate\Database\Eloquent\Model;
+use Illuminate\Database\Eloquent\SoftDeletes;
class TransactionType extends Model
{
+ use SoftDeletes;
public function getDates()
{
diff --git a/app/Support/Amount.php b/app/Support/Amount.php
index 019f6cc0c1..81809ecc97 100644
--- a/app/Support/Amount.php
+++ b/app/Support/Amount.php
@@ -2,10 +2,11 @@
namespace FireflyIII\Support;
+use Cache;
use FireflyIII\Models\Transaction;
use FireflyIII\Models\TransactionCurrency;
use Preferences as Prefs;
-use Cache;
+
/**
* Class Amount
*
@@ -13,6 +14,21 @@ use Cache;
*/
class Amount
{
+ /**
+ * @param $amount
+ * @param bool $coloured
+ *
+ * @return string
+ */
+ public function format($amount, $coloured = true)
+ {
+ $currencySymbol = $this->getCurrencySymbol();
+
+ return $this->formatWithSymbol($currencySymbol, $amount, $coloured);
+
+
+ }
+
/**
* @param \Transaction $transaction
* @param bool $coloured
@@ -29,7 +45,6 @@ class Amount
}
-
/**
* @param string $symbol
* @param float $amount
@@ -58,6 +73,31 @@ class Amount
return $symbol . ' ' . $string;
}
+
+ /**
+ * @return string
+ */
+ public function getCurrencySymbol()
+ {
+ if (defined('FFCURRENCYSYMBOL')) {
+ return FFCURRENCYSYMBOL;
+ }
+ if (\Cache::has('FFCURRENCYSYMBOL')) {
+ define('FFCURRENCYSYMBOL', \Cache::get('FFCURRENCYSYMBOL'));
+
+ return FFCURRENCYSYMBOL;
+ }
+
+ $currencyPreference = Prefs::get('currencyPreference', 'EUR');
+ $currency = TransactionCurrency::whereCode($currencyPreference->data)->first();
+
+ \Cache::forever('FFCURRENCYSYMBOL', $currency->symbol);
+
+ define('FFCURRENCYSYMBOL', $currency->symbol);
+
+ return $currency->symbol;
+ }
+
/**
* @return string
*/
diff --git a/config/firefly.php b/config/firefly.php
index c17ca873e3..5ee38389c2 100644
--- a/config/firefly.php
+++ b/config/firefly.php
@@ -1,15 +1,15 @@
<?php
return [
- 'index_periods' => ['1D', '1W', '1M', '3M', '6M', '1Y', 'custom'],
- 'budget_periods' => ['daily', 'weekly', 'monthly', 'quarterly', 'half-year', 'yearly'],
- 'piggy_bank_periods' => [
+ 'index_periods' => ['1D', '1W', '1M', '3M', '6M', '1Y', 'custom'],
+ 'budget_periods' => ['daily', 'weekly', 'monthly', 'quarterly', 'half-year', 'yearly'],
+ 'piggy_bank_periods' => [
'week' => 'Week',
'month' => 'Month',
'quarter' => 'Quarter',
'year' => 'Year'
],
- 'periods_to_text' => [
+ 'periods_to_text' => [
'weekly' => 'A week',
'monthly' => 'A month',
'quarterly' => 'A quarter',
@@ -17,12 +17,12 @@ return [
'yearly' => 'A year',
],
- 'accountRoles' => [
+ 'accountRoles' => [
'defaultExpense' => 'Default expense account',
'sharedExpense' => 'Shared expense account'
],
- 'range_to_text' => [
+ 'range_to_text' => [
'1D' => 'day',
'1W' => 'week',
'1M' => 'month',
@@ -30,7 +30,7 @@ return [
'6M' => 'half year',
'custom' => '(custom)'
],
- 'range_to_name' => [
+ 'range_to_name' => [
'1D' => 'one day',
'1W' => 'one week',
'1M' => 'one month',
@@ -38,7 +38,7 @@ return [
'6M' => 'six months',
'1Y' => 'one year',
],
- 'range_to_repeat_freq' => [
+ 'range_to_repeat_freq' => [
'1D' => 'weekly',
'1W' => 'weekly',
'1M' => 'monthly',
@@ -46,4 +46,28 @@ return [
'6M' => 'half-year',
'custom' => 'monthly'
],
+ 'subTitlesByIdentifier' =>
+ [
+ 'asset' => 'Asset accounts',
+ 'expense' => 'Expense accounts',
+ 'revenue' => 'Revenue accounts',
+ ],
+ 'subIconsByIdentifier' =>
+ [
+ 'asset' => 'fa-money',
+ 'Asset account' => 'fa-money',
+ 'Default account' => 'fa-money',
+ 'Cash account' => 'fa-money',
+ 'expense' => 'fa-shopping-cart',
+ 'Expense account' => 'fa-shopping-cart',
+ 'Beneficiary account' => 'fa-shopping-cart',
+ 'revenue' => 'fa-download',
+ 'Revenue account' => 'fa-download',
+ ],
+ 'accountTypesByIdentifier' =>
+ [
+ 'asset' => ['Default account', 'Asset account'],
+ 'expense' => ['Expense account', 'Beneficiary account'],
+ 'revenue' => ['Revenue account'],
+ ],
];
diff --git a/resources/views/accounts/index.blade.php b/resources/views/accounts/index.blade.php
new file mode 100644
index 0000000000..628fc76b41
--- /dev/null
+++ b/resources/views/accounts/index.blade.php
@@ -0,0 +1,41 @@
+@extends('layouts.default')
+@section('content')
+{{-- Breadcrumbs::renderIfExists(Route::getCurrentRoute()->getName(), $what) --}}
+<div class="row">
+ <div class="col-lg-12 col-md-12 col-sm-12">
+ <div class="panel panel-default">
+ <div class="panel-heading">
+ <i class="fa {{{$subTitleIcon}}}"></i> {{{$subTitle}}}
+
+ <!-- ACTIONS MENU -->
+ <div class="pull-right">
+ <div class="btn-group">
+ <button type="button" class="btn btn-default btn-xs dropdown-toggle" data-toggle="dropdown">
+ Actions
+ <span class="caret"></span>
+ </button>
+ <ul class="dropdown-menu pull-right" role="menu">
+ <li><a href="{{route('accounts.create',$what)}}"><i class="fa fa-plus fa-fw"></i> New {{$what}} account</a></li>
+ </ul>
+ </div>
+ </div>
+
+
+ </div>
+ @include('list.accounts')
+ </div>
+ </div>
+</div>
+@stop
+@section('scripts')
+<script type="text/javascript">
+ var what = '{{{$what}}}';
+ var currencyCode = '{{Amount::getCurrencyCode()}}';
+</script>
+
+<!-- load the libraries and scripts necessary for Google Charts: -->
+<script type="text/javascript" src="https://www.google.com/jsapi"></script>
+<script type="text/javascript" src="js/gcharts.options.js"></script>
+<script type="text/javascript" src="js/gcharts.js"></script>
+<script type="text/javascript" src="js/accounts.js"></script>
+@stop
diff --git a/resources/views/list/accounts.blade.php b/resources/views/list/accounts.blade.php
new file mode 100644
index 0000000000..d367bc5b18
--- /dev/null
+++ b/resources/views/list/accounts.blade.php
@@ -0,0 +1,38 @@
+<table class="table table-striped">
+ <tr>
+ <th>&nbsp;</th>
+ <th>Name</th>
+ <th>Role</th>
+ <th>Current balance</th>
+ <th>Active</th>
+ <th>Last activity</th>
+ </tr>
+ @foreach($accounts as $account)
+ <tr>
+ <td>
+ <div class="btn-group btn-group-xs">
+ <a class="btn btn-default btn-xs" href="{{route('accounts.edit',$account->id)}}"><span class="glyphicon glyphicon-pencil"></span></a>
+ <a class="btn btn-danger btn-xs" href="{{route('accounts.delete',$account->id)}}"><span class="glyphicon glyphicon-trash"></span></a>
+ </div>
+ </td>
+ <td><a href="{{route('accounts.show',$account->id)}}">{{{$account->name}}}</a></td>
+ <td>{{{$account->accountRole}}}</td>
+ <td>{!! Amount::format(Steam::balance($account)) !!}</td>
+ <td>
+ @if($account->active)
+ <i class="fa fa-fw fa-check"></i>
+ @else
+ <i class="fa fa-fw fa-ban"></i>
+ @endif
+ </td>
+ <td>
+ @if($account->lastActivityDate)
+ {{{$account->lastActivityDate->format('j F Y')}}}
+ @else
+ <em>Never</em>
+ @endif
+ </td>
+ </tr>
+
+ @endforeach
+</table>