diff --git a/app/Http/Controllers/HomeController.php b/app/Http/Controllers/HomeController.php index a030940de4..1e256f6378 100644 --- a/app/Http/Controllers/HomeController.php +++ b/app/Http/Controllers/HomeController.php @@ -1,10 +1,12 @@ accounts()->accountTypeIn(['Asset account', 'Default account'])->count(); + $count = Auth::user()->accounts()->accountTypeIn(['Asset account', 'Default account'])->count(); $title = 'Firefly'; $subTitle = 'What\'s playing?'; $mainTitleIcon = 'fa-fire'; - $transactions = []; + $transactions = []; + $frontPage = Preferences::get('frontPageAccounts', []); + $start = Session::get('start', Carbon::now()->startOfMonth()); + $end = Session::get('end', Carbon::now()->endOfMonth()); - return view('index', compact('count', 'title', 'subTitle', 'mainTitleIcon','transactions')); + 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')); } /** @@ -54,6 +82,7 @@ class HomeController extends Controller Preferences::set('viewRange', $range); Session::forget('range'); } + return Redirect::to(URL::previous()); } @@ -62,7 +91,11 @@ class HomeController extends Controller */ 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()); } @@ -72,7 +105,11 @@ class HomeController extends Controller */ 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()); } diff --git a/app/Http/routes.php b/app/Http/routes.php index 878edade9b..7eaa83087c 100644 --- a/app/Http/routes.php +++ b/app/Http/routes.php @@ -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/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']); +Route::get('/accounts/show/{account}/{view?}', ['uses' => 'AccountController@show', 'as' => 'accounts.show']); /* * 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/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::post('/transactions/relatedSearch/{tj}', ['uses' => 'TransactionController@relatedSearch', 'as' => 'transactions.relatedSearch']); //Route::post('/transactions/alreadyRelated/{tj}', ['uses' => 'TransactionController@alreadyRelated', 'as' => 'transactions.alreadyRelated']); diff --git a/app/Models/Account.php b/app/Models/Account.php index 167b301a8d..ec0b931223 100644 --- a/app/Models/Account.php +++ b/app/Models/Account.php @@ -1,7 +1,8 @@ whereIn('account_types.type', $types); } + public function getDates() + { + return ['created_at', 'updated_at']; + } + } diff --git a/app/Models/TransactionJournal.php b/app/Models/TransactionJournal.php index 0c4c694eef..ada65f6e16 100644 --- a/app/Models/TransactionJournal.php +++ b/app/Models/TransactionJournal.php @@ -1,7 +1,7 @@ belongsTo('FireflyIII\User'); } + public function getDates() + { + return ['created_at', 'updated_at','date']; + } + } diff --git a/app/Providers/FireflyServiceProvider.php b/app/Providers/FireflyServiceProvider.php index 7ef6bae2df..3c0b53e882 100644 --- a/app/Providers/FireflyServiceProvider.php +++ b/app/Providers/FireflyServiceProvider.php @@ -18,6 +18,11 @@ class FireflyServiceProvider extends ServiceProvider return new \FireflyIII\Support\Navigation; } ); + $this->app->bind( + 'amount', function () { + return new \FireflyIII\Support\Amount; + } + ); } } \ No newline at end of file diff --git a/app/Support/Amount.php b/app/Support/Amount.php new file mode 100644 index 0000000000..af02b5b8e8 --- /dev/null +++ b/app/Support/Amount.php @@ -0,0 +1,57 @@ +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 '' . $symbol . ' ' . $string . ''; + } + if ($amount > 0) { + return '' . $symbol . ' ' . $string . ''; + } + + return '' . $symbol . ' ' . $string . ''; + } + + // € + return $symbol . ' ' . $string; + } +} \ No newline at end of file diff --git a/app/Support/Facades/Amount.php b/app/Support/Facades/Amount.php new file mode 100644 index 0000000000..38320a72cc --- /dev/null +++ b/app/Support/Facades/Amount.php @@ -0,0 +1,23 @@ + '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) { switch ($range) { @@ -90,6 +47,39 @@ class Navigation 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) { $formatMap = [ @@ -116,15 +106,6 @@ class Navigation 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) { $functionMap = [ diff --git a/composer.lock b/composer.lock index c2f91f6d29..2dc0c4a7a0 100644 --- a/composer.lock +++ b/composer.lock @@ -1013,16 +1013,16 @@ }, { "name": "laravel/framework", - "version": "v5.0.0", + "version": "v5.0.2", "source": { "type": "git", "url": "https://github.com/laravel/framework.git", - "reference": "44c61252b5762ff53ad181ed416e3006c50a6a9b" + "reference": "30391aa20874c30725f653bea1ea5b895a5217cf" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/laravel/framework/zipball/44c61252b5762ff53ad181ed416e3006c50a6a9b", - "reference": "44c61252b5762ff53ad181ed416e3006c50a6a9b", + "url": "https://api.github.com/repos/laravel/framework/zipball/30391aa20874c30725f653bea1ea5b895a5217cf", + "reference": "30391aa20874c30725f653bea1ea5b895a5217cf", "shasum": "" }, "require": { @@ -1134,7 +1134,7 @@ "framework", "laravel" ], - "time": "2015-02-04 13:59:07" + "time": "2015-02-06 23:14:12" }, { "name": "league/flysystem", diff --git a/config/app.php b/config/app.php index f24472e5ff..66080a7d2a 100644 --- a/config/app.php +++ b/config/app.php @@ -200,6 +200,7 @@ return [ 'Html' => 'Illuminate\Html\HtmlFacade', 'Preferences' => 'FireflyIII\Support\Facades\Preferences', 'Navigation' => 'FireflyIII\Support\Facades\Navigation', + 'Amount' => 'FireflyIII\Support\Facades\Amount', ], diff --git a/resources/views/list/journals-tiny.blade.php b/resources/views/list/journals-tiny.blade.php new file mode 100644 index 0000000000..7f10e8e322 --- /dev/null +++ b/resources/views/list/journals-tiny.blade.php @@ -0,0 +1,35 @@ +