mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2024-12-27 17:31:09 -06:00
Reinstated soft deletes, added first steps for account controller.
This commit is contained in:
parent
1499b2cd40
commit
3d01669cea
32
app/Http/Controllers/AccountController.php
Normal file
32
app/Http/Controllers/AccountController.php
Normal file
@ -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'));
|
||||
}
|
||||
|
||||
}
|
@ -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());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -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']);
|
||||
|
@ -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()
|
||||
{
|
||||
|
@ -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()
|
||||
{
|
||||
|
@ -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()
|
||||
{
|
||||
|
@ -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()
|
||||
{
|
||||
|
@ -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()
|
||||
{
|
||||
|
@ -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()
|
||||
{
|
||||
|
@ -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()
|
||||
{
|
||||
|
@ -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()
|
||||
{
|
||||
|
@ -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()
|
||||
{
|
||||
|
@ -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()
|
||||
{
|
||||
|
@ -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
|
||||
*/
|
||||
|
@ -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'],
|
||||
],
|
||||
];
|
||||
|
41
resources/views/accounts/index.blade.php
Normal file
41
resources/views/accounts/index.blade.php
Normal file
@ -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
|
38
resources/views/list/accounts.blade.php
Normal file
38
resources/views/list/accounts.blade.php
Normal file
@ -0,0 +1,38 @@
|
||||
<table class="table table-striped">
|
||||
<tr>
|
||||
<th> </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>
|
Loading…
Reference in New Issue
Block a user