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 @@ +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 @@ 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 @@ ['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) --}} +
+
+
+
+ {{{$subTitle}}} + + +
+
+ + +
+
+ + +
+ @include('list.accounts') +
+
+
+@stop +@section('scripts') + + + + + + + +@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 @@ + + + + + + + + + + @foreach($accounts as $account) + + + + + + + + + + @endforeach +
 NameRoleCurrent balanceActiveLast activity
+
+ + +
+
{{{$account->name}}}{{{$account->accountRole}}}{!! Amount::format(Steam::balance($account)) !!} + @if($account->active) + + @else + + @endif + + @if($account->lastActivityDate) + {{{$account->lastActivityDate->format('j F Y')}}} + @else + Never + @endif +