mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-19 10:53:37 +00:00
Fixed more of the index.
This commit is contained in:
@@ -1,10 +1,12 @@
|
|||||||
<?php namespace FireflyIII\Http\Controllers;
|
<?php namespace FireflyIII\Http\Controllers;
|
||||||
|
|
||||||
use Preferences;
|
use Auth;
|
||||||
|
use Carbon\Carbon;
|
||||||
use Navigation;
|
use Navigation;
|
||||||
|
use Preferences;
|
||||||
use Redirect;
|
use Redirect;
|
||||||
use URL;
|
|
||||||
use Session;
|
use Session;
|
||||||
|
use URL;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class HomeController
|
* Class HomeController
|
||||||
@@ -30,12 +32,38 @@ class HomeController extends Controller
|
|||||||
*/
|
*/
|
||||||
public function index()
|
public function index()
|
||||||
{
|
{
|
||||||
// count is fake
|
$count = Auth::user()->accounts()->accountTypeIn(['Asset account', 'Default account'])->count();
|
||||||
$count = \Auth::user()->accounts()->accountTypeIn(['Asset account', 'Default account'])->count();
|
|
||||||
$title = 'Firefly';
|
$title = 'Firefly';
|
||||||
$subTitle = 'What\'s playing?';
|
$subTitle = 'What\'s playing?';
|
||||||
$mainTitleIcon = 'fa-fire';
|
$mainTitleIcon = 'fa-fire';
|
||||||
$transactions = [];
|
$transactions = [];
|
||||||
|
$frontPage = Preferences::get('frontPageAccounts', []);
|
||||||
|
$start = Session::get('start', Carbon::now()->startOfMonth());
|
||||||
|
$end = Session::get('end', Carbon::now()->endOfMonth());
|
||||||
|
|
||||||
|
if ($frontPage->data == []) {
|
||||||
|
$accounts = Auth::user()->accounts()->accountTypeIn(['Default account', 'Asset account'])->get(['accounts.*']);
|
||||||
|
} else {
|
||||||
|
$accounts = Auth::user()->accounts()->whereIn('id', $frontPage->data)->get(['accounts.*']);
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($accounts as $account) {
|
||||||
|
$set = Auth::user()
|
||||||
|
->transactionjournals()
|
||||||
|
->with(['transactions', 'transactioncurrency', 'transactiontype'])
|
||||||
|
->leftJoin('transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id')
|
||||||
|
->leftJoin('accounts', 'accounts.id', '=', 'transactions.account_id')->where('accounts.id', $account->id)
|
||||||
|
->where('date', '>=', $start->format('Y-m-d'))
|
||||||
|
->where('date', '<=', $end->format('Y-m-d'))
|
||||||
|
->orderBy('transaction_journals.date', 'DESC')
|
||||||
|
->orderBy('transaction_journals.id', 'DESC')
|
||||||
|
->take(10)
|
||||||
|
->get(['transaction_journals.*']);
|
||||||
|
if (count($set) > 0) {
|
||||||
|
$transactions[] = [$set, $account];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// var_dump($transactions);
|
||||||
|
|
||||||
return view('index', compact('count', 'title', 'subTitle', 'mainTitleIcon', 'transactions'));
|
return view('index', compact('count', 'title', 'subTitle', 'mainTitleIcon', 'transactions'));
|
||||||
}
|
}
|
||||||
@@ -54,6 +82,7 @@ class HomeController extends Controller
|
|||||||
Preferences::set('viewRange', $range);
|
Preferences::set('viewRange', $range);
|
||||||
Session::forget('range');
|
Session::forget('range');
|
||||||
}
|
}
|
||||||
|
|
||||||
return Redirect::to(URL::previous());
|
return Redirect::to(URL::previous());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -62,7 +91,11 @@ class HomeController extends Controller
|
|||||||
*/
|
*/
|
||||||
public function sessionNext()
|
public function sessionNext()
|
||||||
{
|
{
|
||||||
Navigation::next();
|
$range = Session::get('range');
|
||||||
|
$start = Session::get('start');
|
||||||
|
|
||||||
|
Session::put('start', Navigation::jumpToNext($range, clone $start));
|
||||||
|
|
||||||
return Redirect::to(URL::previous());
|
return Redirect::to(URL::previous());
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -72,7 +105,11 @@ class HomeController extends Controller
|
|||||||
*/
|
*/
|
||||||
public function sessionPrev()
|
public function sessionPrev()
|
||||||
{
|
{
|
||||||
Navigation::prev();
|
$range = Session::get('range');
|
||||||
|
$start = Session::get('start');
|
||||||
|
|
||||||
|
Session::put('start', Navigation::jumpToPrevious($range, clone $start));
|
||||||
|
|
||||||
return Redirect::to(URL::previous());
|
return Redirect::to(URL::previous());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -15,7 +15,7 @@ Route::get('/accounts/{what}', ['uses' => 'AccountController@index', 'as' => 'ac
|
|||||||
Route::get('/accounts/create/{what}', ['uses' => 'AccountController@create', 'as' => 'accounts.create'])->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/edit/{account}', ['uses' => 'AccountController@edit', 'as' => 'accounts.edit']);
|
||||||
//Route::get('/accounts/delete/{account}', ['uses' => 'AccountController@delete', 'as' => 'accounts.delete']);
|
//Route::get('/accounts/delete/{account}', ['uses' => 'AccountController@delete', 'as' => 'accounts.delete']);
|
||||||
//Route::get('/accounts/show/{account}/{view?}', ['uses' => 'AccountController@show', 'as' => 'accounts.show']);
|
Route::get('/accounts/show/{account}/{view?}', ['uses' => 'AccountController@show', 'as' => 'accounts.show']);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Bills Controller
|
* Bills Controller
|
||||||
@@ -116,7 +116,7 @@ Route::get('/transactions/create/{what}', ['uses' => 'TransactionController@crea
|
|||||||
);
|
);
|
||||||
//Route::get('/transaction/edit/{tj}', ['uses' => 'TransactionController@edit', 'as' => 'transactions.edit']);
|
//Route::get('/transaction/edit/{tj}', ['uses' => 'TransactionController@edit', 'as' => 'transactions.edit']);
|
||||||
//Route::get('/transaction/delete/{tj}', ['uses' => 'TransactionController@delete', 'as' => 'transactions.delete']);
|
//Route::get('/transaction/delete/{tj}', ['uses' => 'TransactionController@delete', 'as' => 'transactions.delete']);
|
||||||
//Route::get('/transaction/show/{tj}', ['uses' => 'TransactionController@show', 'as' => 'transactions.show']);
|
Route::get('/transaction/show/{tj}', ['uses' => 'TransactionController@show', 'as' => 'transactions.show']);
|
||||||
//Route::get('/transaction/relate/{tj}', ['uses' => 'TransactionController@relate', 'as' => 'transactions.relate']);
|
//Route::get('/transaction/relate/{tj}', ['uses' => 'TransactionController@relate', 'as' => 'transactions.relate']);
|
||||||
//Route::post('/transactions/relatedSearch/{tj}', ['uses' => 'TransactionController@relatedSearch', 'as' => 'transactions.relatedSearch']);
|
//Route::post('/transactions/relatedSearch/{tj}', ['uses' => 'TransactionController@relatedSearch', 'as' => 'transactions.relatedSearch']);
|
||||||
//Route::post('/transactions/alreadyRelated/{tj}', ['uses' => 'TransactionController@alreadyRelated', 'as' => 'transactions.alreadyRelated']);
|
//Route::post('/transactions/alreadyRelated/{tj}', ['uses' => 'TransactionController@alreadyRelated', 'as' => 'transactions.alreadyRelated']);
|
||||||
|
@@ -1,7 +1,8 @@
|
|||||||
<?php namespace FireflyIII\Models;
|
<?php namespace FireflyIII\Models;
|
||||||
|
|
||||||
use Illuminate\Database\Eloquent\Model;
|
|
||||||
use Illuminate\Database\Eloquent\Builder as EloquentBuilder;
|
use Illuminate\Database\Eloquent\Builder as EloquentBuilder;
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class Account
|
* Class Account
|
||||||
*
|
*
|
||||||
@@ -34,4 +35,9 @@ class Account extends Model
|
|||||||
$query->whereIn('account_types.type', $types);
|
$query->whereIn('account_types.type', $types);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getDates()
|
||||||
|
{
|
||||||
|
return ['created_at', 'updated_at'];
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
<?php namespace FireflyIII\Models;
|
<?php namespace FireflyIII\Models;
|
||||||
|
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Crypt;
|
||||||
class TransactionJournal extends Model
|
class TransactionJournal extends Model
|
||||||
{
|
{
|
||||||
|
|
||||||
@@ -67,5 +67,10 @@ class TransactionJournal extends Model
|
|||||||
return $this->belongsTo('FireflyIII\User');
|
return $this->belongsTo('FireflyIII\User');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getDates()
|
||||||
|
{
|
||||||
|
return ['created_at', 'updated_at','date'];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -18,6 +18,11 @@ class FireflyServiceProvider extends ServiceProvider
|
|||||||
return new \FireflyIII\Support\Navigation;
|
return new \FireflyIII\Support\Navigation;
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
$this->app->bind(
|
||||||
|
'amount', function () {
|
||||||
|
return new \FireflyIII\Support\Amount;
|
||||||
|
}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
57
app/Support/Amount.php
Normal file
57
app/Support/Amount.php
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace FireflyIII\Support;
|
||||||
|
|
||||||
|
use FireflyIII\Models\Transaction;
|
||||||
|
/**
|
||||||
|
* Class Amount
|
||||||
|
*
|
||||||
|
* @package FireflyIII\Support
|
||||||
|
*/
|
||||||
|
class Amount
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @param \Transaction $transaction
|
||||||
|
* @param bool $coloured
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function formatTransaction(Transaction $transaction, $coloured = true)
|
||||||
|
{
|
||||||
|
$symbol = $transaction->transactionJournal->transactionCurrency->symbol;
|
||||||
|
$amount = floatval($transaction->amount);
|
||||||
|
|
||||||
|
return $this->formatWithSymbol($symbol, $amount, $coloured);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $symbol
|
||||||
|
* @param float $amount
|
||||||
|
* @param bool $coloured
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function formatWithSymbol($symbol, $amount, $coloured = true)
|
||||||
|
{
|
||||||
|
$amount = floatval($amount);
|
||||||
|
$amount = round($amount, 2);
|
||||||
|
$string = number_format($amount, 2, ',', '.');
|
||||||
|
|
||||||
|
if ($coloured === true) {
|
||||||
|
if ($amount === 0.0) {
|
||||||
|
return '<span style="color:#999">' . $symbol . ' ' . $string . '</span>';
|
||||||
|
}
|
||||||
|
if ($amount > 0) {
|
||||||
|
return '<span class="text-success">' . $symbol . ' ' . $string . '</span>';
|
||||||
|
}
|
||||||
|
|
||||||
|
return '<span class="text-danger">' . $symbol . ' ' . $string . '</span>';
|
||||||
|
}
|
||||||
|
|
||||||
|
// €
|
||||||
|
return $symbol . ' ' . $string;
|
||||||
|
}
|
||||||
|
}
|
23
app/Support/Facades/Amount.php
Normal file
23
app/Support/Facades/Amount.php
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace FireflyIII\Support\Facades;
|
||||||
|
|
||||||
|
use Illuminate\Support\Facades\Facade;
|
||||||
|
/**
|
||||||
|
* Class Amount
|
||||||
|
*
|
||||||
|
* @package FireflyIII\Support\Facades
|
||||||
|
*/
|
||||||
|
class Amount extends Facade
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Get the registered name of the component.
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
protected static function getFacadeAccessor()
|
||||||
|
{
|
||||||
|
return 'amount';
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@@ -4,7 +4,7 @@ namespace FireflyIII\Support\Facades;
|
|||||||
|
|
||||||
use Illuminate\Support\Facades\Facade;
|
use Illuminate\Support\Facades\Facade;
|
||||||
/**
|
/**
|
||||||
* Class Preferences
|
* Class Navigation
|
||||||
*
|
*
|
||||||
* @package FireflyIII\Support\Facades
|
* @package FireflyIII\Support\Facades
|
||||||
*/
|
*/
|
||||||
|
@@ -4,7 +4,6 @@ namespace FireflyIII\Support;
|
|||||||
|
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
use FireflyIII\Exception\FireflyException;
|
use FireflyIII\Exception\FireflyException;
|
||||||
use Session;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class Navigation
|
* Class Navigation
|
||||||
@@ -15,48 +14,6 @@ class Navigation
|
|||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
public function jumpToPrevious($range, Carbon $date)
|
|
||||||
{
|
|
||||||
$functionMap = [
|
|
||||||
'1D' => 'Day',
|
|
||||||
'1W' => 'Week',
|
|
||||||
'1M' => 'Month',
|
|
||||||
'1Y' => 'Year'
|
|
||||||
];
|
|
||||||
|
|
||||||
if (isset($functionMap[$range])) {
|
|
||||||
$startFunction = 'startOf' . $functionMap[$range];
|
|
||||||
$subFunction = 'sub' . $functionMap[$range];
|
|
||||||
$date->$startFunction()->$subFunction();
|
|
||||||
|
|
||||||
return $date;
|
|
||||||
}
|
|
||||||
if ($range == '3M') {
|
|
||||||
$date->firstOfQuarter()->subMonths(3)->firstOfQuarter();
|
|
||||||
|
|
||||||
return $date;
|
|
||||||
}
|
|
||||||
if ($range == '6M') {
|
|
||||||
$month = intval($date->format('m'));
|
|
||||||
$date->startOfYear();
|
|
||||||
if ($month <= 6) {
|
|
||||||
$date->subMonths(6);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $date;
|
|
||||||
}
|
|
||||||
throw new FireflyException('Cannot do _previous() on ' . $range);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function next()
|
|
||||||
{
|
|
||||||
|
|
||||||
$range = Session::get('range');
|
|
||||||
$start = Session::get('start');
|
|
||||||
|
|
||||||
Session::put('start', Navigation::jumpToNext($range, clone $start));
|
|
||||||
}
|
|
||||||
|
|
||||||
public function jumpToNext($range, Carbon $date)
|
public function jumpToNext($range, Carbon $date)
|
||||||
{
|
{
|
||||||
switch ($range) {
|
switch ($range) {
|
||||||
@@ -90,6 +47,39 @@ class Navigation
|
|||||||
return $date;
|
return $date;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function jumpToPrevious($range, Carbon $date)
|
||||||
|
{
|
||||||
|
$functionMap = [
|
||||||
|
'1D' => 'Day',
|
||||||
|
'1W' => 'Week',
|
||||||
|
'1M' => 'Month',
|
||||||
|
'1Y' => 'Year'
|
||||||
|
];
|
||||||
|
|
||||||
|
if (isset($functionMap[$range])) {
|
||||||
|
$startFunction = 'startOf' . $functionMap[$range];
|
||||||
|
$subFunction = 'sub' . $functionMap[$range];
|
||||||
|
$date->$startFunction()->$subFunction();
|
||||||
|
|
||||||
|
return $date;
|
||||||
|
}
|
||||||
|
if ($range == '3M') {
|
||||||
|
$date->firstOfQuarter()->subMonths(3)->firstOfQuarter();
|
||||||
|
|
||||||
|
return $date;
|
||||||
|
}
|
||||||
|
if ($range == '6M') {
|
||||||
|
$month = intval($date->format('m'));
|
||||||
|
$date->startOfYear();
|
||||||
|
if ($month <= 6) {
|
||||||
|
$date->subMonths(6);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $date;
|
||||||
|
}
|
||||||
|
throw new FireflyException('Cannot do _previous() on ' . $range);
|
||||||
|
}
|
||||||
|
|
||||||
public function periodName($range, Carbon $date)
|
public function periodName($range, Carbon $date)
|
||||||
{
|
{
|
||||||
$formatMap = [
|
$formatMap = [
|
||||||
@@ -116,15 +106,6 @@ class Navigation
|
|||||||
throw new FireflyException('No _periodName() for range "' . $range . '"');
|
throw new FireflyException('No _periodName() for range "' . $range . '"');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function prev()
|
|
||||||
{
|
|
||||||
$range = Session::get('range');
|
|
||||||
$start = Session::get('start');
|
|
||||||
|
|
||||||
Session::put('start', Navigation::jumpToPrevious($range, clone $start));
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public function updateEndDate($range, Carbon $start)
|
public function updateEndDate($range, Carbon $start)
|
||||||
{
|
{
|
||||||
$functionMap = [
|
$functionMap = [
|
||||||
|
10
composer.lock
generated
10
composer.lock
generated
@@ -1013,16 +1013,16 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "laravel/framework",
|
"name": "laravel/framework",
|
||||||
"version": "v5.0.0",
|
"version": "v5.0.2",
|
||||||
"source": {
|
"source": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://github.com/laravel/framework.git",
|
"url": "https://github.com/laravel/framework.git",
|
||||||
"reference": "44c61252b5762ff53ad181ed416e3006c50a6a9b"
|
"reference": "30391aa20874c30725f653bea1ea5b895a5217cf"
|
||||||
},
|
},
|
||||||
"dist": {
|
"dist": {
|
||||||
"type": "zip",
|
"type": "zip",
|
||||||
"url": "https://api.github.com/repos/laravel/framework/zipball/44c61252b5762ff53ad181ed416e3006c50a6a9b",
|
"url": "https://api.github.com/repos/laravel/framework/zipball/30391aa20874c30725f653bea1ea5b895a5217cf",
|
||||||
"reference": "44c61252b5762ff53ad181ed416e3006c50a6a9b",
|
"reference": "30391aa20874c30725f653bea1ea5b895a5217cf",
|
||||||
"shasum": ""
|
"shasum": ""
|
||||||
},
|
},
|
||||||
"require": {
|
"require": {
|
||||||
@@ -1134,7 +1134,7 @@
|
|||||||
"framework",
|
"framework",
|
||||||
"laravel"
|
"laravel"
|
||||||
],
|
],
|
||||||
"time": "2015-02-04 13:59:07"
|
"time": "2015-02-06 23:14:12"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "league/flysystem",
|
"name": "league/flysystem",
|
||||||
|
@@ -200,6 +200,7 @@ return [
|
|||||||
'Html' => 'Illuminate\Html\HtmlFacade',
|
'Html' => 'Illuminate\Html\HtmlFacade',
|
||||||
'Preferences' => 'FireflyIII\Support\Facades\Preferences',
|
'Preferences' => 'FireflyIII\Support\Facades\Preferences',
|
||||||
'Navigation' => 'FireflyIII\Support\Facades\Navigation',
|
'Navigation' => 'FireflyIII\Support\Facades\Navigation',
|
||||||
|
'Amount' => 'FireflyIII\Support\Facades\Amount',
|
||||||
|
|
||||||
],
|
],
|
||||||
|
|
||||||
|
35
resources/views/list/journals-tiny.blade.php
Normal file
35
resources/views/list/journals-tiny.blade.php
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
<div class="list-group">
|
||||||
|
@foreach($transactions as $journal)
|
||||||
|
<a class="list-group-item" title="{{$journal->date->format('jS M Y')}}" href="{{route('transactions.show',$journal->id)}}">
|
||||||
|
|
||||||
|
@if($journal->transactiontype->type == 'Withdrawal')
|
||||||
|
<i class="fa fa-long-arrow-left fa-fw" title="Withdrawal"></i>
|
||||||
|
@endif
|
||||||
|
@if($journal->transactiontype->type == 'Deposit')
|
||||||
|
<i class="fa fa-long-arrow-right fa-fw" title="Deposit"></i>
|
||||||
|
@endif
|
||||||
|
@if($journal->transactiontype->type == 'Transfer')
|
||||||
|
<i class="fa fa-arrows-h fa-fw" title="Transfer"></i>
|
||||||
|
@endif
|
||||||
|
|
||||||
|
{{{$journal->description}}}
|
||||||
|
|
||||||
|
<span class="pull-right small">
|
||||||
|
@if(isset($account))
|
||||||
|
@foreach($journal->transactions as $index => $t)
|
||||||
|
@if($t->account_id == $account->id)
|
||||||
|
{!! Amount::formatTransaction($t) !!}
|
||||||
|
@endif
|
||||||
|
@endforeach
|
||||||
|
@else
|
||||||
|
@foreach($journal->transactions as $index => $t)
|
||||||
|
@if($index == 0)
|
||||||
|
{!! Amount::formatTransaction($t) !!}
|
||||||
|
@endif
|
||||||
|
@endforeach
|
||||||
|
@endif
|
||||||
|
</span>
|
||||||
|
|
||||||
|
</a>
|
||||||
|
@endforeach
|
||||||
|
</div>
|
Reference in New Issue
Block a user