From 193a1b0325793e567b1eba16028cd4c02a136b43 Mon Sep 17 00:00:00 2001 From: James Cole Date: Mon, 1 Jun 2015 18:13:54 +0200 Subject: [PATCH 01/47] Basic tutorial for new users. --- app/Http/Controllers/HomeController.php | 5 + app/Http/Controllers/NewUserController.php | 119 ++++++++++++++++++ app/Http/Requests/NewUserFormRequest.php | 37 ++++++ app/Http/routes.php | 52 ++++---- .../Account/AccountRepository.php | 101 +++++++-------- resources/lang/en/firefly.php | 7 ++ resources/lang/en/form.php | 7 ++ resources/lang/nl/firefly.php | 7 ++ resources/lang/nl/form.php | 7 ++ resources/twig/index.twig | 22 +--- resources/twig/new-user/index.twig | 45 +++++++ 11 files changed, 316 insertions(+), 93 deletions(-) create mode 100644 app/Http/Controllers/NewUserController.php create mode 100644 app/Http/Requests/NewUserFormRequest.php create mode 100644 resources/twig/new-user/index.twig diff --git a/app/Http/Controllers/HomeController.php b/app/Http/Controllers/HomeController.php index 3b09b9f96c..58d6937b4a 100644 --- a/app/Http/Controllers/HomeController.php +++ b/app/Http/Controllers/HomeController.php @@ -53,6 +53,11 @@ class HomeController extends Controller $types = Config::get('firefly.accountTypesByIdentifier.asset'); $count = $repository->countAccounts($types); + + if($count == 0) { + return Redirect::route('new-user.index'); + } + $title = 'Firefly'; $subTitle = trans('firefly.welcomeBack'); $mainTitleIcon = 'fa-fire'; diff --git a/app/Http/Controllers/NewUserController.php b/app/Http/Controllers/NewUserController.php new file mode 100644 index 0000000000..f7f736065b --- /dev/null +++ b/app/Http/Controllers/NewUserController.php @@ -0,0 +1,119 @@ +countAccounts($types); + + if ($count > 0) { + return Redirect::route('index'); + + } + + return view('new-user.index'); + } + + /** + * @param NewUserFormRequest $request + * @param AccountRepositoryInterface $repository + */ + public function submit(NewUserFormRequest $request, AccountRepositoryInterface $repository) + { + + // create normal asset account: + $assetAccount = [ + 'name' => $request->get('bank_name'), + 'accountType' => 'asset', + 'virtualBalance' => 0, + 'active' => true, + 'user' => Auth::user()->id, + 'accountRole' => 'defaultAsset', + 'openingBalance' => floatval($request->input('bank_balance')), + 'openingBalanceDate' => new Carbon, + 'openingBalanceCurrency' => intval($request->input('balance_currency_id')), + ]; + + $repository->store($assetAccount); + + // create savings account + if (strlen($request->get('savings_balance') > 0)) { + $savingsAccount = [ + 'name' => $request->get('bank_name') . ' savings account', + 'accountType' => 'asset', + 'virtualBalance' => 0, + 'active' => true, + 'user' => Auth::user()->id, + 'accountRole' => 'savingAsset', + 'openingBalance' => floatval($request->input('savings_balance')), + 'openingBalanceDate' => new Carbon, + 'openingBalanceCurrency' => intval($request->input('balance_currency_id')), + ]; + $repository->store($savingsAccount); + } + + + // create credit card. + if (strlen($request->get('credit_card_limit') > 0)) { + $creditAccount = [ + 'name' => 'Credit card', + 'accountType' => 'asset', + 'virtualBalance' => floatval($request->get('credit_card_limit')), + 'active' => true, + 'user' => Auth::user()->id, + 'accountRole' => 'ccAsset', + 'openingBalance' => null, + 'openingBalanceDate' => null, + 'openingBalanceCurrency' => intval($request->input('balance_currency_id')), + ]; + $creditCard = $repository->store($creditAccount); + + // store meta for CC: + AccountMeta::create( + [ + 'name' => 'ccType', + 'data' => 'monthlyFull', + 'account_id' => $creditCard->id, + ] + ); + AccountMeta::create( + [ + 'name' => 'ccMonthlyPaymentDate', + 'data' => Carbon::now()->year.'-01-01', + 'account_id' => $creditCard->id, + ] + ); + + } + Session::flash('success', 'New account(s) created!'); + + return Redirect::route('home'); + } +} \ No newline at end of file diff --git a/app/Http/Requests/NewUserFormRequest.php b/app/Http/Requests/NewUserFormRequest.php new file mode 100644 index 0000000000..b500ce6b02 --- /dev/null +++ b/app/Http/Requests/NewUserFormRequest.php @@ -0,0 +1,37 @@ + 'required|between:1,200', + 'bank_balance' => 'required|numeric', + 'savings_balance' => 'numeric', + 'credit_card_limit' => 'numeric', + 'balance_currency_id' => 'exists:transaction_currencies,id', + ]; + } +} diff --git a/app/Http/routes.php b/app/Http/routes.php index 750d9a7b3b..b813ee389c 100644 --- a/app/Http/routes.php +++ b/app/Http/routes.php @@ -15,13 +15,13 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; // models Route::bind( 'account', - function($value) { + function ($value) { if (Auth::check()) { $object = Account::leftJoin('account_types', 'account_types.id', '=', 'accounts.account_type_id') - ->where('account_types.editable', 1) - ->where('accounts.id', $value) - ->where('user_id', Auth::user()->id) - ->first(['accounts.*']); + ->where('account_types.editable', 1) + ->where('accounts.id', $value) + ->where('user_id', Auth::user()->id) + ->first(['accounts.*']); if ($object) { return $object; } @@ -31,7 +31,7 @@ Route::bind( ); Route::bind( - 'tj', function($value) { + 'tj', function ($value) { if (Auth::check()) { $object = TransactionJournal::where('id', $value)->where('user_id', Auth::user()->id)->first(); if ($object) { @@ -44,7 +44,7 @@ Route::bind( ); Route::bind( - 'currency', function($value) { + 'currency', function ($value) { if (Auth::check()) { $object = TransactionCurrency::find($value); if ($object) { @@ -56,7 +56,7 @@ Route::bind( ); Route::bind( - 'bill', function($value) { + 'bill', function ($value) { if (Auth::check()) { $object = Bill::where('id', $value)->where('user_id', Auth::user()->id)->first(); if ($object) { @@ -69,7 +69,7 @@ Route::bind( ); Route::bind( - 'budget', function($value) { + 'budget', function ($value) { if (Auth::check()) { $object = Budget::where('id', $value)->where('user_id', Auth::user()->id)->first(); if ($object) { @@ -82,7 +82,7 @@ Route::bind( ); Route::bind( - 'reminder', function($value) { + 'reminder', function ($value) { if (Auth::check()) { $object = Reminder::where('id', $value)->where('user_id', Auth::user()->id)->first(); if ($object) { @@ -95,13 +95,13 @@ Route::bind( ); Route::bind( - 'limitrepetition', function($value) { + 'limitrepetition', function ($value) { if (Auth::check()) { $object = LimitRepetition::where('limit_repetitions.id', $value) - ->leftjoin('budget_limits', 'budget_limits.id', '=', 'limit_repetitions.budget_limit_id') - ->leftJoin('budgets', 'budgets.id', '=', 'budget_limits.budget_id') - ->where('budgets.user_id', Auth::user()->id) - ->first(['limit_repetitions.*']); + ->leftjoin('budget_limits', 'budget_limits.id', '=', 'limit_repetitions.budget_limit_id') + ->leftJoin('budgets', 'budgets.id', '=', 'budget_limits.budget_id') + ->where('budgets.user_id', Auth::user()->id) + ->first(['limit_repetitions.*']); if ($object) { return $object; } @@ -112,12 +112,12 @@ Route::bind( ); Route::bind( - 'piggyBank', function($value) { + 'piggyBank', function ($value) { if (Auth::check()) { $object = PiggyBank::where('piggy_banks.id', $value) - ->leftJoin('accounts', 'accounts.id', '=', 'piggy_banks.account_id') - ->where('accounts.user_id', Auth::user()->id) - ->first(['piggy_banks.*']); + ->leftJoin('accounts', 'accounts.id', '=', 'piggy_banks.account_id') + ->where('accounts.user_id', Auth::user()->id) + ->first(['piggy_banks.*']); if ($object) { return $object; } @@ -128,7 +128,7 @@ Route::bind( ); Route::bind( - 'category', function($value) { + 'category', function ($value) { if (Auth::check()) { $object = Category::where('id', $value)->where('user_id', Auth::user()->id)->first(); if ($object) { @@ -142,7 +142,7 @@ Route::bind( /** @noinspection PhpUnusedParameterInspection */ Route::bind( - 'reminder', function($value) { + 'reminder', function ($value) { if (Auth::check()) { /** @var \FireflyIII\Models\Reminder $object */ $object = Reminder::find($value); @@ -158,7 +158,7 @@ Route::bind( ); Route::bind( - 'tag', function($value) { + 'tag', function ($value) { if (Auth::check()) { $object = Tag::where('id', $value)->where('user_id', Auth::user()->id)->first(); if ($object) { @@ -189,7 +189,7 @@ Route::get('/routes', ['uses' => 'HomeController@routes', 'as' => 'routes']); * Home Controller */ Route::group( - ['middleware' => ['auth', 'range', 'reminders']], function() { + ['middleware' => ['auth', 'range', 'reminders']], function () { Route::get('/', ['uses' => 'HomeController@index', 'as' => 'index', 'middleware' => 'cleanup']); Route::get('/home', ['uses' => 'HomeController@index', 'as' => 'home']); Route::post('/daterange', ['uses' => 'HomeController@dateRange', 'as' => 'daterange']); @@ -317,6 +317,12 @@ Route::group( Route::get('/json/box/bills-paid', ['uses' => 'JsonController@boxBillsPaid', 'as' => 'json.box.unpaid']); Route::get('/json/transaction-journals/{what}', 'JsonController@transactionJournals'); + /** + * New user Controller + */ + Route::get('/new-user', ['uses' => 'NewUserController@index', 'as' => 'new-user.index']); + Route::post('/new-user/submit', ['uses' => 'NewUserController@submit', 'as' => 'new-user.submit']); + /** * Piggy Bank Controller */ diff --git a/app/Repositories/Account/AccountRepository.php b/app/Repositories/Account/AccountRepository.php index e5900e802b..a6ec7f81bd 100644 --- a/app/Repositories/Account/AccountRepository.php +++ b/app/Repositories/Account/AccountRepository.php @@ -64,7 +64,7 @@ class AccountRepository implements AccountRepositoryInterface public function getAccounts(array $types) { $result = Auth::user()->accounts()->with( - ['accountmeta' => function(HasMany $query) { + ['accountmeta' => function (HasMany $query) { $query->where('name', 'accountRole'); }] )->accountTypeIn($types)->orderBy('accounts.name', 'ASC')->get(['accounts.*'])->sortBy('name'); @@ -79,15 +79,15 @@ class AccountRepository implements AccountRepositoryInterface public function getCreditCards() { return Auth::user()->accounts() - ->hasMetaValue('accountRole', 'ccAsset') - ->hasMetaValue('ccType', 'monthlyFull') - ->get( - [ - 'accounts.*', - 'ccType.data as ccType', - 'accountRole.data as accountRole' - ] - ); + ->hasMetaValue('accountRole', 'ccAsset') + ->hasMetaValue('ccType', 'monthlyFull') + ->get( + [ + 'accounts.*', + 'ccType.data as ccType', + 'accountRole.data as accountRole' + ] + ); } /** @@ -132,18 +132,18 @@ class AccountRepository implements AccountRepositoryInterface public function getFrontpageTransactions(Account $account, Carbon $start, Carbon $end) { return Auth::user() - ->transactionjournals() - ->with(['transactions']) - ->leftJoin('transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id') - ->leftJoin('accounts', 'accounts.id', '=', 'transactions.account_id')->where('accounts.id', $account->id) - ->leftJoin('transaction_currencies', 'transaction_currencies.id', '=', 'transaction_journals.transaction_currency_id') - ->leftJoin('transaction_types', 'transaction_types.id', '=', 'transaction_journals.transaction_type_id') - ->before($end) - ->after($start) - ->orderBy('transaction_journals.date', 'DESC') - ->orderBy('transaction_journals.id', 'DESC') - ->take(10) - ->get(['transaction_journals.*', 'transaction_currencies.symbol', 'transaction_types.type']); + ->transactionjournals() + ->with(['transactions']) + ->leftJoin('transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id') + ->leftJoin('accounts', 'accounts.id', '=', 'transactions.account_id')->where('accounts.id', $account->id) + ->leftJoin('transaction_currencies', 'transaction_currencies.id', '=', 'transaction_journals.transaction_currency_id') + ->leftJoin('transaction_types', 'transaction_types.id', '=', 'transaction_journals.transaction_type_id') + ->before($end) + ->after($start) + ->orderBy('transaction_journals.date', 'DESC') + ->orderBy('transaction_journals.id', 'DESC') + ->take(10) + ->get(['transaction_journals.*', 'transaction_currencies.symbol', 'transaction_types.type']); } /** @@ -156,13 +156,13 @@ class AccountRepository implements AccountRepositoryInterface { $offset = ($page - 1) * 50; $query = Auth::user() - ->transactionJournals() - ->withRelevantData() - ->leftJoin('transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id') - ->where('transactions.account_id', $account->id) - ->orderBy('transaction_journals.date', 'DESC') - ->orderBy('transaction_journals.order', 'ASC') - ->orderBy('transaction_journals.id', 'DESC'); + ->transactionJournals() + ->withRelevantData() + ->leftJoin('transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id') + ->where('transactions.account_id', $account->id) + ->orderBy('transaction_journals.date', 'DESC') + ->orderBy('transaction_journals.order', 'ASC') + ->orderBy('transaction_journals.id', 'DESC'); $count = $query->count(); $set = $query->take(50)->offset($offset)->get(['transaction_journals.*']); @@ -213,7 +213,7 @@ class AccountRepository implements AccountRepositoryInterface } $accounts->each( - function(Account $account) use ($start, $end) { + function (Account $account) use ($start, $end) { $account->startBalance = Steam::balance($account, $start, true); $account->endBalance = Steam::balance($account, $end, true); $account->piggyBalance = 0; @@ -251,7 +251,7 @@ class AccountRepository implements AccountRepositoryInterface $end = clone Session::get('end', new Carbon); $accounts->each( - function(Account $account) use ($start, $end) { + function (Account $account) use ($start, $end) { $account->startBalance = Steam::balance($account, $start); $account->endBalance = Steam::balance($account, $end); @@ -289,25 +289,26 @@ class AccountRepository implements AccountRepositoryInterface */ public function getTransfersInRange(Account $account, Carbon $start, Carbon $end) { - $set = TransactionJournal::whereIn( - 'id', function(Builder $q) use ($account, $start, $end) { + $set = TransactionJournal::whereIn( + 'id', function (Builder $q) use ($account, $start, $end) { $q->select('transaction_journals.id') - ->from('transactions') - ->leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id') - ->leftJoin('transaction_types', 'transaction_types.id', '=', 'transaction_journals.transaction_type_id') - ->where('transactions.account_id', $account->id) - ->where('transaction_journals.user_id', Auth::user()->id) - ->where('transaction_journals.date', '>=', $start->format('Y-m-d')) - ->where('transaction_journals.date', '<=', $end->format('Y-m-d')) - ->where('transaction_types.type', 'Transfer'); + ->from('transactions') + ->leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id') + ->leftJoin('transaction_types', 'transaction_types.id', '=', 'transaction_journals.transaction_type_id') + ->where('transactions.account_id', $account->id) + ->where('transaction_journals.user_id', Auth::user()->id) + ->where('transaction_journals.date', '>=', $start->format('Y-m-d')) + ->where('transaction_journals.date', '<=', $end->format('Y-m-d')) + ->where('transaction_types.type', 'Transfer'); } )->get(); $filtered = $set->filter( - function(TransactionJournal $journal) use ($account) { + function (TransactionJournal $journal) use ($account) { if ($journal->destination_account->id == $account->id) { return $journal; } + return null; } ); @@ -342,9 +343,9 @@ class AccountRepository implements AccountRepositoryInterface public function openingBalanceTransaction(Account $account) { return TransactionJournal::accountIs($account) - ->orderBy('transaction_journals.date', 'ASC') - ->orderBy('created_at', 'ASC') - ->first(['transaction_journals.*']); + ->orderBy('transaction_journals.date', 'ASC') + ->orderBy('created_at', 'ASC') + ->first(['transaction_journals.*']); } /** @@ -364,11 +365,11 @@ class AccountRepository implements AccountRepositoryInterface $opposingData = [ 'user' => $data['user'], 'accountType' => $type, - 'virtual_balance' => $data['virtualBalance'], + 'virtualBalance' => 0, 'name' => $data['name'] . ' initial balance', 'active' => false, ]; - $opposing = $this->storeAccount($opposingData); + $opposing = $this->storeAccount($opposingData); $this->storeInitialBalance($newAccount, $opposing, $data); } @@ -418,7 +419,7 @@ class AccountRepository implements AccountRepositoryInterface 'name' => $data['name'] . ' initial balance', 'active' => false, ]; - $opposing = $this->storeAccount($opposingData); + $opposing = $this->storeAccount($opposingData); $this->storeInitialBalance($account, $opposing, $data); } @@ -445,15 +446,17 @@ class AccountRepository implements AccountRepositoryInterface 'user_id' => $data['user'], 'account_type_id' => $accountType->id, 'name' => $data['name'], + 'virtual_balance' => $data['virtualBalance'], 'active' => $data['active'] === true ? true : false, ] ); if (!$newAccount->isValid()) { // does the account already exist? - $searchData = [ + $searchData = [ 'user_id' => $data['user'], 'account_type_id' => $accountType->id, + 'virtual_balance' => $data['virtualBalance'], 'name' => $data['name'] ]; $existingAccount = Account::firstOrNullEncrypted($searchData); diff --git a/resources/lang/en/firefly.php b/resources/lang/en/firefly.php index 9f99552a15..904bc4f92a 100644 --- a/resources/lang/en/firefly.php +++ b/resources/lang/en/firefly.php @@ -18,6 +18,13 @@ return [ 'showEverything' => 'Show everything', 'never' => 'Never', + // new user: + 'submit' => 'Submit', + 'getting_started' => 'Getting started', + 'to_get_started' => 'To get started with Firefly, please enter your current bank\'s name, and the balance of your checking account:', + 'savings_balance_text' => 'If you have a savings account, please enter the current balance of your savings account:', + 'cc_balance_text' => 'If you have a credit card, please enter your credit card\'s limit.', + // forms: 'mandatoryFields' => 'Mandatory fields', 'optionalFields' => 'Optional fields', diff --git a/resources/lang/en/form.php b/resources/lang/en/form.php index aeacd0ebfd..b88dd2d972 100644 --- a/resources/lang/en/form.php +++ b/resources/lang/en/form.php @@ -1,5 +1,12 @@ 'Bank name', + 'bank_balance' => 'Balance', + 'savings_balance' => 'Savings balance', + 'credit_card_limit' => 'Credit card limit', + 'name' => 'Name', 'active' => 'Active', 'amount_min' => 'Minimum amount', diff --git a/resources/lang/nl/firefly.php b/resources/lang/nl/firefly.php index 28f289d678..5156ff662b 100644 --- a/resources/lang/nl/firefly.php +++ b/resources/lang/nl/firefly.php @@ -18,6 +18,13 @@ return [ 'showEverything' => 'Laat alles zien', 'never' => 'Nooit', + // new user: + 'submit' => 'Invoeren', + 'getting_started' => 'Aan de start!', + 'to_get_started' => 'Begin met de naam van de bank waar je je betaalrekening hebt, en het saldo van die rekening.', + 'savings_balance_text' => 'Voer ook het saldo van je spaarrekening in, als je die hebt.', + 'cc_balance_text' => 'Als je een credit card hebt, vul dan hier je credit cardlimiet in.', + // forms: 'mandatoryFields' => 'Verplichte velden', 'optionalFields' => 'Optionele velden', diff --git a/resources/lang/nl/form.php b/resources/lang/nl/form.php index 239641c082..4c1bcda15f 100644 --- a/resources/lang/nl/form.php +++ b/resources/lang/nl/form.php @@ -1,5 +1,12 @@ 'Banknaam', + 'bank_balance' => 'Saldo', + 'savings_balance' => 'Saldo van spaarrekening', + 'credit_card_limit' => 'Credit card limiet', + 'name' => 'Naam', 'active' => 'Actief', 'amount_min' => 'Minimumbedrag', diff --git a/resources/twig/index.twig b/resources/twig/index.twig index 05d277f5f6..caebbdf93e 100644 --- a/resources/twig/index.twig +++ b/resources/twig/index.twig @@ -2,25 +2,7 @@ {% block content %} {{ Breadcrumbs.renderIfExists }} -{% if count == 0 %} -
-
-

{{ 'welcome'|_ }}

- -

- {{ 'createNewAsset'|_ }} - -

-
-
-
- -{% else %} - - - {% include 'partials/boxes.twig' %} +{% include 'partials/boxes.twig' %}
@@ -200,8 +182,6 @@
-{% endif %} - {% endblock %} {% block scripts %} diff --git a/resources/twig/new-user/index.twig b/resources/twig/new-user/index.twig new file mode 100644 index 0000000000..a92de14d80 --- /dev/null +++ b/resources/twig/new-user/index.twig @@ -0,0 +1,45 @@ +{% extends "./layout/default.twig" %} +{% block content %} +{{ Breadcrumbs.renderIfExists }} + +
+
+

{{ 'getting_started'|_ }}

+

+ {{ 'to_get_started'|_ }} +

+
+ + + {{ ExpandedForm.text('bank_name')}} + {{ ExpandedForm.balance('bank_balance')}} + +

+ {{ 'savings_balance_text'|_ }} +

+ + {{ ExpandedForm.balance('savings_balance') }} + +

+ {{ 'cc_balance_text'|_ }} + +

+ + {{ ExpandedForm.balance('credit_card_limit') }} + +

+ +

+
+
+
+ + +{% endblock %} +{% block scripts %} + + + + + +{% endblock %} From 294d0e388a51aa9dc9ced1deeb3d115f86fdf067 Mon Sep 17 00:00:00 2001 From: James Cole Date: Mon, 1 Jun 2015 18:41:18 +0200 Subject: [PATCH 02/47] Add cache to main chart. --- .../Controllers/Chart/AccountController.php | 28 +++++++- app/Support/ChartProperties.php | 65 +++++++++++++++++++ 2 files changed, 92 insertions(+), 1 deletion(-) create mode 100644 app/Support/ChartProperties.php diff --git a/app/Http/Controllers/Chart/AccountController.php b/app/Http/Controllers/Chart/AccountController.php index 5c9e11e3c1..645867c445 100644 --- a/app/Http/Controllers/Chart/AccountController.php +++ b/app/Http/Controllers/Chart/AccountController.php @@ -2,16 +2,19 @@ namespace FireflyIII\Http\Controllers\Chart; +use Cache; use Carbon\Carbon; use FireflyIII\Http\Controllers\Controller; use FireflyIII\Models\Account; use FireflyIII\Repositories\Account\AccountRepositoryInterface; +use FireflyIII\Support\ChartProperties; use Grumpydictator\Gchart\GChart; use Illuminate\Support\Collection; use Preferences; use Response; use Session; use Steam; +use Auth; /** * Class AccountController @@ -93,6 +96,26 @@ class AccountController extends Controller $end = Session::get('end', Carbon::now()->endOfMonth()); $accounts = $repository->getFrontpageAccounts($frontPage); + // chart properties for cache: + $chartProperties = new ChartProperties(); + $chartProperties->addProperty(Auth::user()->id); + $chartProperties->addProperty($frontPage); + $chartProperties->addProperty($start); + $chartProperties->addProperty($end); + $chartProperties->addProperty('frontpage'); + + /** @var Account $account */ + foreach($accounts as $account) { + $chartProperties->addProperty($repository->getLastActivity($account)); + } + + $md5 = $chartProperties->md5(); + + if (Cache::has($md5)) { + return Cache::get($md5); + } + + $index = 1; /** @var Account $account */ foreach ($accounts as $account) { @@ -115,7 +138,10 @@ class AccountController extends Controller } $chart->generate(); - return Response::json($chart->getData()); + $data = $chart->getData(); + Cache::forever($md5, $data); + + return Response::json($data); } diff --git a/app/Support/ChartProperties.php b/app/Support/ChartProperties.php new file mode 100644 index 0000000000..2b128274fa --- /dev/null +++ b/app/Support/ChartProperties.php @@ -0,0 +1,65 @@ +properties = new Collection; + } + + /** + * @param $property + */ + public function addProperty($property) + { + $this->properties->push($property); + } + + + /** + * @return string + */ + public function md5() + { + $string = ''; + foreach ($this->properties as $property) { + + if ($property instanceof Collection || $property instanceof EloquentCollection) { + $string .= print_r($property->toArray(), true); + continue; + } + if ($property instanceof Carbon) { + $string .= $property->toRfc3339String(); + continue; + } + if (is_object($property)) { + $string .= $property->__toString(); + } + if (is_array($property)) { + $string .= print_r($property, true); + } + $string .= (string)$property; + } + + return md5($string); + } +} \ No newline at end of file From 546787802d1411acb63da0813190e51195e4b0a6 Mon Sep 17 00:00:00 2001 From: James Cole Date: Tue, 2 Jun 2015 17:14:03 +0200 Subject: [PATCH 03/47] Some code cleanup [skip ci] --- app/Http/Controllers/Chart/AccountController.php | 1 + app/Http/Controllers/Chart/BudgetController.php | 4 ++++ app/Http/Controllers/HomeController.php | 12 ++++++------ 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/app/Http/Controllers/Chart/AccountController.php b/app/Http/Controllers/Chart/AccountController.php index 645867c445..204f99c03f 100644 --- a/app/Http/Controllers/Chart/AccountController.php +++ b/app/Http/Controllers/Chart/AccountController.php @@ -103,6 +103,7 @@ class AccountController extends Controller $chartProperties->addProperty($start); $chartProperties->addProperty($end); $chartProperties->addProperty('frontpage'); + $chartProperties->addProperty('accounts'); /** @var Account $account */ foreach($accounts as $account) { diff --git a/app/Http/Controllers/Chart/BudgetController.php b/app/Http/Controllers/Chart/BudgetController.php index 12c1f9e476..81f7229603 100644 --- a/app/Http/Controllers/Chart/BudgetController.php +++ b/app/Http/Controllers/Chart/BudgetController.php @@ -2,11 +2,13 @@ namespace FireflyIII\Http\Controllers\Chart; +use Auth; use Carbon\Carbon; use FireflyIII\Http\Controllers\Controller; use FireflyIII\Models\Budget; use FireflyIII\Models\LimitRepetition; use FireflyIII\Repositories\Budget\BudgetRepositoryInterface; +use FireflyIII\Support\ChartProperties; use Grumpydictator\Gchart\GChart; use Illuminate\Support\Collection; use Navigation; @@ -112,6 +114,8 @@ class BudgetController extends Controller $end = Session::get('end', Carbon::now()->endOfMonth()); $allEntries = new Collection; + + /** @var Budget $budget */ foreach ($budgets as $budget) { $repetitions = $repository->getBudgetLimitRepetitions($budget, $start, $end); if ($repetitions->count() == 0) { diff --git a/app/Http/Controllers/HomeController.php b/app/Http/Controllers/HomeController.php index 58d6937b4a..a28ad3acfe 100644 --- a/app/Http/Controllers/HomeController.php +++ b/app/Http/Controllers/HomeController.php @@ -46,15 +46,15 @@ class HomeController extends Controller /** * @param AccountRepositoryInterface $repository * - * @return \Illuminate\View\View + * @return \Illuminate\Http\RedirectResponse|\Illuminate\View\View */ public function index(AccountRepositoryInterface $repository) { - $types = Config::get('firefly.accountTypesByIdentifier.asset'); - $count = $repository->countAccounts($types); + $types = Config::get('firefly.accountTypesByIdentifier.asset'); + $count = $repository->countAccounts($types); - if($count == 0) { + if ($count == 0) { return Redirect::route('new-user.index'); } @@ -78,8 +78,8 @@ class HomeController extends Controller if ($sum != 0) { Session::flash( 'error', 'Your transactions are unbalanced. This means a' - . ' withdrawal, deposit or transfer was not stored properly. ' - . 'Please check your accounts and transactions for errors.' + . ' withdrawal, deposit or transfer was not stored properly. ' + . 'Please check your accounts and transactions for errors.' ); } From 71947c097f853e144fa63e3caf5da6bcb1a46ca7 Mon Sep 17 00:00:00 2001 From: James Cole Date: Tue, 2 Jun 2015 17:44:50 +0200 Subject: [PATCH 04/47] Some experiments with a cache control thing. [skip ci] --- app/Http/Controllers/AccountController.php | 3 + app/Http/Controllers/BillController.php | 5 ++ app/Http/Controllers/BudgetController.php | 5 ++ app/Http/Controllers/CategoryController.php | 4 + .../Controllers/Chart/AccountController.php | 61 ++++++++++--- app/Http/Controllers/Chart/BillController.php | 42 ++++++++- .../Controllers/Chart/BudgetController.php | 89 +++++++++++++++++-- .../Controllers/Chart/CategoryController.php | 24 ++++- app/Http/Controllers/CurrencyController.php | 3 + app/Http/Controllers/NewUserController.php | 2 + app/Http/Controllers/PiggyBankController.php | 7 ++ .../Controllers/PreferencesController.php | 1 + app/Http/Controllers/TagController.php | 3 + .../Controllers/TransactionController.php | 6 ++ app/Support/ChartProperties.php | 12 +++ app/Support/Preferences.php | 21 ++++- 16 files changed, 263 insertions(+), 25 deletions(-) diff --git a/app/Http/Controllers/AccountController.php b/app/Http/Controllers/AccountController.php index bddabbd04b..ffe7354574 100644 --- a/app/Http/Controllers/AccountController.php +++ b/app/Http/Controllers/AccountController.php @@ -86,6 +86,7 @@ class AccountController extends Controller $repository->destroy($account); Session::flash('success', trans('firefly.' . $typeName . '_deleted', ['name' => $name])); + Preferences::mark(); return Redirect::to(Session::get('accounts.delete.url')); } @@ -206,6 +207,7 @@ class AccountController extends Controller $account = $repository->store($accountData); Session::flash('success', 'New account "' . $account->name . '" stored!'); + Preferences::mark(); if (intval(Input::get('create_another')) === 1) { // set value so create routine will not overwrite URL: @@ -246,6 +248,7 @@ class AccountController extends Controller $repository->update($account, $accountData); Session::flash('success', 'Account "' . $account->name . '" updated.'); + Preferences::mark(); if (intval(Input::get('return_to_edit')) === 1) { // set value so edit routine will not overwrite URL: diff --git a/app/Http/Controllers/BillController.php b/app/Http/Controllers/BillController.php index 80bc497336..6d96298615 100644 --- a/app/Http/Controllers/BillController.php +++ b/app/Http/Controllers/BillController.php @@ -6,6 +6,7 @@ use FireflyIII\Models\Bill; use FireflyIII\Models\TransactionJournal; use FireflyIII\Repositories\Bill\BillRepositoryInterface; use Input; +use Preferences; use Redirect; use Session; use URL; @@ -75,6 +76,7 @@ class BillController extends Controller $repository->destroy($bill); Session::flash('success', 'The bill was deleted.'); + Preferences::mark(); return Redirect::to(Session::get('bills.delete.url')); @@ -141,6 +143,7 @@ class BillController extends Controller Session::flash('success', 'Rescanned everything.'); + Preferences::mark(); return Redirect::to(URL::previous()); } @@ -172,6 +175,7 @@ class BillController extends Controller $billData = $request->getBillData(); $bill = $repository->store($billData); Session::flash('success', 'Bill "' . e($bill->name) . '" stored.'); + Preferences::mark(); if (intval(Input::get('create_another')) === 1) { // set value so create routine will not overwrite URL: @@ -198,6 +202,7 @@ class BillController extends Controller $bill = $repository->update($bill, $billData); Session::flash('success', 'Bill "' . e($bill->name) . '" updated.'); + Preferences::mark(); if (intval(Input::get('return_to_edit')) === 1) { // set value so edit routine will not overwrite URL: diff --git a/app/Http/Controllers/BudgetController.php b/app/Http/Controllers/BudgetController.php index b4d0cca20e..95d43d1535 100644 --- a/app/Http/Controllers/BudgetController.php +++ b/app/Http/Controllers/BudgetController.php @@ -49,6 +49,7 @@ class BudgetController extends Controller if ($amount == 0) { $limitRepetition = null; } + Preferences::mark(); return Response::json(['name' => $budget->name, 'repetition' => $limitRepetition ? $limitRepetition->id : 0]); @@ -102,6 +103,7 @@ class BudgetController extends Controller Session::flash('success', 'The budget "' . e($name) . '" was deleted.'); + Preferences::mark(); return Redirect::to(Session::get('budgets.delete.url')); @@ -196,6 +198,7 @@ class BudgetController extends Controller $date = Session::get('start', Carbon::now()->startOfMonth())->format('FY'); Preferences::set('budgetIncomeTotal' . $date, intval(Input::get('amount'))); + Preferences::mark(); return Redirect::route('budgets.index'); } @@ -242,6 +245,7 @@ class BudgetController extends Controller $budget = $repository->store($budgetData); Session::flash('success', 'New budget "' . $budget->name . '" stored!'); + Preferences::mark(); if (intval(Input::get('create_another')) === 1) { // set value so create routine will not overwrite URL: @@ -272,6 +276,7 @@ class BudgetController extends Controller $repository->update($budget, $budgetData); Session::flash('success', 'Budget "' . $budget->name . '" updated.'); + Preferences::mark(); if (intval(Input::get('return_to_edit')) === 1) { // set value so edit routine will not overwrite URL: diff --git a/app/Http/Controllers/CategoryController.php b/app/Http/Controllers/CategoryController.php index 92f027ab26..6de44dbba9 100644 --- a/app/Http/Controllers/CategoryController.php +++ b/app/Http/Controllers/CategoryController.php @@ -7,6 +7,7 @@ use FireflyIII\Models\Category; use FireflyIII\Repositories\Category\CategoryRepositoryInterface; use Illuminate\Pagination\LengthAwarePaginator; use Input; +use Preferences; use Redirect; use Session; use URL; @@ -77,6 +78,7 @@ class CategoryController extends Controller $repository->destroy($category); Session::flash('success', 'The category "' . e($name) . '" was deleted.'); + Preferences::mark(); return Redirect::to(Session::get('categories.delete.url')); } @@ -168,6 +170,7 @@ class CategoryController extends Controller $category = $repository->store($categoryData); Session::flash('success', 'New category "' . $category->name . '" stored!'); + Preferences::mark(); if (intval(Input::get('create_another')) === 1) { Session::put('categories.create.fromStore', true); @@ -195,6 +198,7 @@ class CategoryController extends Controller $repository->update($category, $categoryData); Session::flash('success', 'Category "' . $category->name . '" updated.'); + Preferences::mark(); if (intval(Input::get('return_to_edit')) === 1) { Session::put('categories.edit.fromUpdate', true); diff --git a/app/Http/Controllers/Chart/AccountController.php b/app/Http/Controllers/Chart/AccountController.php index 204f99c03f..e7f4d5b7fc 100644 --- a/app/Http/Controllers/Chart/AccountController.php +++ b/app/Http/Controllers/Chart/AccountController.php @@ -2,6 +2,7 @@ namespace FireflyIII\Http\Controllers\Chart; +use Auth; use Cache; use Carbon\Carbon; use FireflyIII\Http\Controllers\Controller; @@ -10,11 +11,11 @@ use FireflyIII\Repositories\Account\AccountRepositoryInterface; use FireflyIII\Support\ChartProperties; use Grumpydictator\Gchart\GChart; use Illuminate\Support\Collection; +use Log; use Preferences; use Response; use Session; use Steam; -use Auth; /** * Class AccountController @@ -40,6 +41,23 @@ class AccountController extends Controller $start = new Carbon($year . '-' . $month . '-01'); $end = clone $start; $end->endOfMonth(); + + // chart properties for cache: + $chartProperties = new ChartProperties(); + $chartProperties->addProperty($start); + $chartProperties->addProperty($end); + $chartProperties->addProperty('all'); + $chartProperties->addProperty('accounts'); + $md5 = $chartProperties->md5(); + + + if (Cache::has($md5)) { + Log::debug('Successfully returned cached chart [' . $md5 . '].'); + + return Response::json(Cache::get($md5)); + } + + $chart->addColumn(trans('firefly.dayOfMonth'), 'date'); /** @var Collection $accounts */ @@ -76,7 +94,10 @@ class AccountController extends Controller } $chart->generate(); - return Response::json($chart->getData()); + $data = $chart->getData(); + Cache::forever($md5, $data); + + return Response::json($data); } /** @@ -98,22 +119,17 @@ class AccountController extends Controller // chart properties for cache: $chartProperties = new ChartProperties(); - $chartProperties->addProperty(Auth::user()->id); - $chartProperties->addProperty($frontPage); $chartProperties->addProperty($start); $chartProperties->addProperty($end); $chartProperties->addProperty('frontpage'); $chartProperties->addProperty('accounts'); - - /** @var Account $account */ - foreach($accounts as $account) { - $chartProperties->addProperty($repository->getLastActivity($account)); - } - $md5 = $chartProperties->md5(); + if (Cache::has($md5)) { - return Cache::get($md5); + Log::debug('Successfully returned cached chart [' . $md5 . '].'); + + return Response::json(Cache::get($md5)); } @@ -165,6 +181,24 @@ class AccountController extends Controller $current = clone $start; $today = new Carbon; + // chart properties for cache: + $chartProperties = new ChartProperties(); + $chartProperties->addProperty($start); + $chartProperties->addProperty($end); + $chartProperties->addProperty('frontpage'); + $chartProperties->addProperty('single'); + $chartProperties->addProperty($account->id); + $md5 = $chartProperties->md5(); + + + if (Cache::has($md5)) { + Log::debug('Successfully returned cached chart [' . $md5 . '].'); + + return Response::json(Cache::get($md5)); + } + + + while ($end >= $current) { $certain = $current < $today; $chart->addRow(clone $current, Steam::balance($account, $current), $certain); @@ -174,6 +208,9 @@ class AccountController extends Controller $chart->generate(); - return Response::json($chart->getData()); + $data = $chart->getData(); + Cache::forever($md5, $data); + + return Response::json($data); } } diff --git a/app/Http/Controllers/Chart/BillController.php b/app/Http/Controllers/Chart/BillController.php index 9ba00ee2fc..569aee84d5 100644 --- a/app/Http/Controllers/Chart/BillController.php +++ b/app/Http/Controllers/Chart/BillController.php @@ -8,12 +8,14 @@ use FireflyIII\Models\Bill; use FireflyIII\Models\TransactionJournal; use FireflyIII\Repositories\Account\AccountRepositoryInterface; use FireflyIII\Repositories\Bill\BillRepositoryInterface; +use FireflyIII\Support\ChartProperties; use Grumpydictator\Gchart\GChart; use Illuminate\Support\Collection; use Response; use Session; use Steam; - +use Cache; +use Log; /** * Class BillController * @@ -38,6 +40,18 @@ class BillController extends Controller $chart->addColumn(trans('firefly.minAmount'), 'number'); $chart->addColumn(trans('firefly.billEntry'), 'number'); + $chartProperties = new ChartProperties; + $chartProperties->addProperty('single'); + $chartProperties->addProperty('bill'); + $chartProperties->addProperty($bill->id); + $md5 = $chartProperties->md5(); + + if (Cache::has($md5)) { + Log::debug('Successfully returned cached chart [' . $md5 . '].'); + + return Response::json(Cache::get($md5)); + } + // get first transaction or today for start: $results = $repository->getJournals($bill); /** @var TransactionJournal $result */ @@ -47,8 +61,10 @@ class BillController extends Controller $chart->generate(); - return Response::json($chart->getData()); + $data = $chart->getData(); + Cache::forever($md5, $data); + return Response::json($data); } /** @@ -68,6 +84,22 @@ class BillController extends Controller $start = Session::get('start', Carbon::now()->startOfMonth()); $end = Session::get('end', Carbon::now()->endOfMonth()); + + + // chart properties for cache: + $chartProperties = new ChartProperties(); + $chartProperties->addProperty($start); + $chartProperties->addProperty($end); + $chartProperties->addProperty('bills'); + $chartProperties->addProperty('frontpage'); + $md5 = $chartProperties->md5(); + + if (Cache::has($md5)) { + Log::debug('Successfully returned cached chart [' . $md5 . '].'); + + return Response::json(Cache::get($md5)); + } + $bills = $repository->getActiveBills(); $paid = new Collection; // journals. $unpaid = new Collection; // bills @@ -133,8 +165,12 @@ class BillController extends Controller $chart->addRow(trans('firefly.unpaid') . ': ' . join(', ', $unpaidDescriptions), $unpaidAmount); $chart->addRow(trans('firefly.paid') . ': ' . join(', ', $paidDescriptions), $paidAmount); + $chart->generate(); - return Response::json($chart->getData()); + $data = $chart->getData(); + Cache::forever($md5, $data); + + return Response::json($data); } } diff --git a/app/Http/Controllers/Chart/BudgetController.php b/app/Http/Controllers/Chart/BudgetController.php index 81f7229603..649c2be783 100644 --- a/app/Http/Controllers/Chart/BudgetController.php +++ b/app/Http/Controllers/Chart/BudgetController.php @@ -2,7 +2,7 @@ namespace FireflyIII\Http\Controllers\Chart; -use Auth; +use Cache; use Carbon\Carbon; use FireflyIII\Http\Controllers\Controller; use FireflyIII\Models\Budget; @@ -11,6 +11,7 @@ use FireflyIII\Repositories\Budget\BudgetRepositoryInterface; use FireflyIII\Support\ChartProperties; use Grumpydictator\Gchart\GChart; use Illuminate\Support\Collection; +use Log; use Navigation; use Preferences; use Response; @@ -43,6 +44,21 @@ class BudgetController extends Controller $final->addYears(2); $last = Navigation::endOfX($last, $range, $final); + // chart properties for cache: + $chartProperties = new ChartProperties(); + $chartProperties->addProperty($first); + $chartProperties->addProperty($last); + $chartProperties->addProperty('budget'); + $chartProperties->addProperty('budget'); + $md5 = $chartProperties->md5(); + + if (Cache::has($md5)) { + Log::debug('Successfully returned cached chart [' . $md5 . '].'); + + return Response::json(Cache::get($md5)); + } + + while ($first < $last) { $end = Navigation::addPeriod($first, $range, 0); @@ -55,7 +71,10 @@ class BudgetController extends Controller $chart->generate(); - return Response::json($chart->getData()); + $data = $chart->getData(); + Cache::forever($md5, $data); + + return Response::json($data); } /** @@ -73,6 +92,22 @@ class BudgetController extends Controller $start = clone $repetition->startdate; $end = $repetition->enddate; + // chart properties for cache: + $chartProperties = new ChartProperties(); + $chartProperties->addProperty($start); + $chartProperties->addProperty($end); + $chartProperties->addProperty('budget'); + $chartProperties->addProperty('limit'); + $chartProperties->addProperty($budget->id); + $chartProperties->addProperty($repetition->id); + $md5 = $chartProperties->md5(); + + if (Cache::has($md5)) { + Log::debug('Successfully returned cached chart [' . $md5 . '].'); + + return Response::json(Cache::get($md5)); + } + $chart->addColumn(trans('firefly.day'), 'date'); $chart->addColumn(trans('firefly.left'), 'number'); @@ -90,7 +125,10 @@ class BudgetController extends Controller } $chart->generate(); - return Response::json($chart->getData()); + $data = $chart->getData(); + Cache::forever($md5, $data); + + return Response::json($data); } @@ -114,6 +152,20 @@ class BudgetController extends Controller $end = Session::get('end', Carbon::now()->endOfMonth()); $allEntries = new Collection; + // chart properties for cache: + $chartProperties = new ChartProperties(); + $chartProperties->addProperty($start); + $chartProperties->addProperty($end); + $chartProperties->addProperty('budget'); + $chartProperties->addProperty('all'); + $md5 = $chartProperties->md5(); + + if (Cache::has($md5)) { + Log::debug('Successfully returned cached chart [' . $md5 . '].'); + + return Response::json(Cache::get($md5)); + } + /** @var Budget $budget */ foreach ($budgets as $budget) { @@ -131,9 +183,9 @@ class BudgetController extends Controller $overspent = $expenses > floatval($repetition->amount) ? $expenses - floatval($repetition->amount) : 0; $allEntries->push( [$budget->name . ' (' . $repetition->startdate->formatLocalized($this->monthAndDayFormat) . ')', - $left, - $spent, - $overspent + $left, + $spent, + $overspent ] ); } @@ -150,7 +202,10 @@ class BudgetController extends Controller $chart->generate(); - return Response::json($chart->getData()); + $data = $chart->getData(); + Cache::forever($md5, $data); + + return Response::json($data); } @@ -171,6 +226,21 @@ class BudgetController extends Controller $shared = $shared == 'shared' ? true : false; $budgets = $repository->getBudgets(); + // chart properties for cache: + $chartProperties = new ChartProperties(); + $chartProperties->addProperty($start); + $chartProperties->addProperty($end); + $chartProperties->addProperty('budget'); + $chartProperties->addProperty('year'); + $md5 = $chartProperties->md5(); + + + if (Cache::has($md5)) { + Log::debug('Successfully returned cached chart [' . $md5 . '].'); + + return Response::json(Cache::get($md5)); + } + // add columns: $chart->addColumn(trans('firefly.month'), 'date'); foreach ($budgets as $budget) { @@ -196,6 +266,9 @@ class BudgetController extends Controller $chart->generate(); - return Response::json($chart->getData()); + $data = $chart->getData(); + Cache::forever($md5, $data); + + return Response::json($data); } } diff --git a/app/Http/Controllers/Chart/CategoryController.php b/app/Http/Controllers/Chart/CategoryController.php index c6f42cad5b..8c076a1791 100644 --- a/app/Http/Controllers/Chart/CategoryController.php +++ b/app/Http/Controllers/Chart/CategoryController.php @@ -3,11 +3,14 @@ namespace FireflyIII\Http\Controllers\Chart; +use Cache; use Carbon\Carbon; use FireflyIII\Http\Controllers\Controller; use FireflyIII\Models\Category; use FireflyIII\Repositories\Category\CategoryRepositoryInterface; +use FireflyIII\Support\ChartProperties; use Grumpydictator\Gchart\GChart; +use Log; use Navigation; use Preferences; use Response; @@ -75,6 +78,22 @@ class CategoryController extends Controller $start = Session::get('start', Carbon::now()->startOfMonth()); $end = Session::get('end', Carbon::now()->endOfMonth()); + + // chart properties for cache: + $chartProperties = new ChartProperties; + $chartProperties->addProperty($start); + $chartProperties->addProperty($end); + $chartProperties->addProperty('category'); + $chartProperties->addProperty('frontpage'); + $md5 = $chartProperties->md5(); + + + if (Cache::has($md5)) { + Log::debug('Successfully returned cached chart [' . $md5 . '].'); + + return Response::json(Cache::get($md5)); + } + $set = $repository->getCategoriesAndExpensesCorrected($start, $end); // sort by callback: @@ -99,7 +118,10 @@ class CategoryController extends Controller $chart->generate(); - return Response::json($chart->getData()); + $data = $chart->getData(); + Cache::forever($md5, $data); + + return Response::json($data); } diff --git a/app/Http/Controllers/CurrencyController.php b/app/Http/Controllers/CurrencyController.php index 6f57851cb9..8f34c5422d 100644 --- a/app/Http/Controllers/CurrencyController.php +++ b/app/Http/Controllers/CurrencyController.php @@ -59,6 +59,7 @@ class CurrencyController extends Controller { Preferences::set('currencyPreference', $currency->code); + Preferences::mark(); Session::flash('success', $currency->name . ' is now the default currency.'); Cache::forget('FFCURRENCYSYMBOL'); @@ -170,6 +171,7 @@ class CurrencyController extends Controller if (Auth::user()->hasRole('owner')) { $currency = $repository->store($data); Session::flash('success', 'Currency "' . $currency->name . '" created'); + } if (intval(Input::get('create_another')) === 1) { @@ -198,6 +200,7 @@ class CurrencyController extends Controller $currency = $repository->update($currency, $data); } Session::flash('success', 'Currency "' . e($currency->name) . '" updated.'); + Preferences::mark(); if (intval(Input::get('return_to_edit')) === 1) { diff --git a/app/Http/Controllers/NewUserController.php b/app/Http/Controllers/NewUserController.php index f7f736065b..7dc2738bcd 100644 --- a/app/Http/Controllers/NewUserController.php +++ b/app/Http/Controllers/NewUserController.php @@ -6,6 +6,7 @@ use Config; use FireflyIII\Http\Requests\NewUserFormRequest; use FireflyIII\Models\AccountMeta; use FireflyIII\Repositories\Account\AccountRepositoryInterface; +use Preferences; use Redirect; use Session; use View; @@ -113,6 +114,7 @@ class NewUserController extends Controller } Session::flash('success', 'New account(s) created!'); + Preferences::mark(); return Redirect::route('home'); } diff --git a/app/Http/Controllers/PiggyBankController.php b/app/Http/Controllers/PiggyBankController.php index 6961b5787b..f9bc5f87c6 100644 --- a/app/Http/Controllers/PiggyBankController.php +++ b/app/Http/Controllers/PiggyBankController.php @@ -10,6 +10,7 @@ use FireflyIII\Repositories\Account\AccountRepositoryInterface; use FireflyIII\Repositories\PiggyBank\PiggyBankRepositoryInterface; use Illuminate\Support\Collection; use Input; +use Preferences; use Redirect; use Session; use Steam; @@ -108,6 +109,7 @@ class PiggyBankController extends Controller Session::flash('success', 'Piggy bank "' . e($piggyBank->name) . '" deleted.'); + Preferences::mark(); $repository->destroy($piggyBank); return Redirect::to(Session::get('piggy-banks.delete.url')); @@ -208,6 +210,7 @@ class PiggyBankController extends Controller // set all users piggy banks to zero: $repository->reset(); + if (is_array($data)) { foreach ($data as $order => $id) { $repository->setOrder(intval($id), (intval($order) + 1)); @@ -240,6 +243,7 @@ class PiggyBankController extends Controller $repository->createEvent($piggyBank, $amount); Session::flash('success', 'Added ' . Amount::format($amount, false) . ' to "' . e($piggyBank->name) . '".'); + Preferences::mark(); } else { Session::flash('error', 'Could not add ' . Amount::format($amount, false) . ' to "' . e($piggyBank->name) . '".'); } @@ -268,6 +272,7 @@ class PiggyBankController extends Controller $repository->createEvent($piggyBank, $amount * -1); Session::flash('success', 'Removed ' . Amount::format($amount, false) . ' from "' . e($piggyBank->name) . '".'); + Preferences::mark(); } else { Session::flash('error', 'Could not remove ' . Amount::format($amount, false) . ' from "' . e($piggyBank->name) . '".'); } @@ -328,6 +333,7 @@ class PiggyBankController extends Controller $piggyBank = $repository->store($piggyBankData); Session::flash('success', 'Stored piggy bank "' . e($piggyBank->name) . '".'); + Preferences::mark(); if (intval(Input::get('create_another')) === 1) { Session::put('piggy-banks.create.fromStore', true); @@ -362,6 +368,7 @@ class PiggyBankController extends Controller $piggyBank = $repository->update($piggyBank, $piggyBankData); Session::flash('success', 'Updated piggy bank "' . e($piggyBank->name) . '".'); + Preferences::mark(); if (intval(Input::get('return_to_edit')) === 1) { Session::put('piggy-banks.edit.fromUpdate', true); diff --git a/app/Http/Controllers/PreferencesController.php b/app/Http/Controllers/PreferencesController.php index 0848155a01..5fd6e4fd24 100644 --- a/app/Http/Controllers/PreferencesController.php +++ b/app/Http/Controllers/PreferencesController.php @@ -77,6 +77,7 @@ class PreferencesController extends Controller Session::flash('success', 'Preferences saved!'); + Preferences::mark(); return Redirect::route('preferences'); } diff --git a/app/Http/Controllers/TagController.php b/app/Http/Controllers/TagController.php index 8473f1d5e3..ad3423fb1e 100644 --- a/app/Http/Controllers/TagController.php +++ b/app/Http/Controllers/TagController.php @@ -106,6 +106,7 @@ class TagController extends Controller $repository->destroy($tag); Session::flash('success', 'Tag "' . e($tagName) . '" was deleted.'); + Preferences::mark(); return Redirect::to(route('tags.index')); } @@ -226,6 +227,7 @@ class TagController extends Controller $repository->store($data); Session::flash('success', 'The tag has been created!'); + Preferences::mark(); if (intval(Input::get('create_another')) === 1) { // set value so create routine will not overwrite URL: @@ -271,6 +273,7 @@ class TagController extends Controller $repository->update($tag, $data); Session::flash('success', 'Tag "' . e($data['tag']) . '" updated.'); + Preferences::mark(); if (intval(Input::get('return_to_edit')) === 1) { // set value so edit routine will not overwrite URL: diff --git a/app/Http/Controllers/TransactionController.php b/app/Http/Controllers/TransactionController.php index 223dab527a..575d35c383 100644 --- a/app/Http/Controllers/TransactionController.php +++ b/app/Http/Controllers/TransactionController.php @@ -11,6 +11,7 @@ use FireflyIII\Models\TransactionJournal; use FireflyIII\Repositories\Account\AccountRepositoryInterface; use FireflyIII\Repositories\Journal\JournalRepositoryInterface; use Input; +use Preferences; use Redirect; use Response; use Session; @@ -104,6 +105,8 @@ class TransactionController extends Controller $repository->delete($transactionJournal); + Preferences::mark(); + // redirect to previous URL: return Redirect::to(Session::get('transactions.delete.url')); } @@ -235,6 +238,7 @@ class TransactionController extends Controller } } } + Preferences::mark(); return Response::json([true]); @@ -281,6 +285,7 @@ class TransactionController extends Controller $repository->deactivateReminder($request->get('reminder_id')); Session::flash('success', 'New transaction "' . $journal->description . '" stored!'); + Preferences::mark(); if (intval(Input::get('create_another')) === 1) { // set value so create routine will not overwrite URL: @@ -312,6 +317,7 @@ class TransactionController extends Controller // update, get events by date and sort DESC Session::flash('success', 'Transaction "' . e($journalData['description']) . '" updated.'); + Preferences::mark(); if (intval(Input::get('return_to_edit')) === 1) { // set value so edit routine will not overwrite URL: diff --git a/app/Support/ChartProperties.php b/app/Support/ChartProperties.php index 2b128274fa..e12d864808 100644 --- a/app/Support/ChartProperties.php +++ b/app/Support/ChartProperties.php @@ -3,9 +3,11 @@ namespace FireflyIII\Support; +use Auth; use Carbon\Carbon; use Illuminate\Database\Eloquent\Collection as EloquentCollection; use Illuminate\Support\Collection; +use Preferences; /** * Class ChartProperties @@ -24,6 +26,8 @@ class ChartProperties public function __construct() { $this->properties = new Collection; + $this->addProperty(Auth::user()->id); + $this->addProperty(Preferences::lastActivity()); } /** @@ -41,25 +45,33 @@ class ChartProperties public function md5() { $string = ''; + //Log::debug('--- building string ---'); foreach ($this->properties as $property) { if ($property instanceof Collection || $property instanceof EloquentCollection) { $string .= print_r($property->toArray(), true); + // Log::debug('added collection (size=' . $property->count() . ')'); continue; } if ($property instanceof Carbon) { $string .= $property->toRfc3339String(); + // Log::debug('Added time: ' . $property->toRfc3339String()); continue; } if (is_object($property)) { $string .= $property->__toString(); + // Log::debug('Added object of class ' . get_class($property)); } if (is_array($property)) { $string .= print_r($property, true); + // Log::debug('Added array (size=' . count($property) . ')'); } $string .= (string)$property; + // Log::debug('Added cast to string: ' . $property); } + // Log::debug('--- done building string ---'); + return md5($string); } } \ No newline at end of file diff --git a/app/Support/Preferences.php b/app/Support/Preferences.php index 3d53d9c16a..bf781877d7 100644 --- a/app/Support/Preferences.php +++ b/app/Support/Preferences.php @@ -4,7 +4,7 @@ namespace FireflyIII\Support; use Auth; use FireflyIII\Models\Preference; - +use Log; /** * Class Preferences * @@ -12,6 +12,25 @@ use FireflyIII\Models\Preference; */ class Preferences { + /** + * @return string + */ + public function lastActivity() + { + $preference = $this->get('lastActivity', microtime())->data; + + return md5($preference); + } + + /** + * @return bool + */ + public function mark() { + Log::debug('MARK!'); + $this->set('lastActivity',microtime()); + return true; + } + /** * @param $name * @param null $default From 616c849b1f25007112484db82ac446e3508edcc0 Mon Sep 17 00:00:00 2001 From: James Cole Date: Tue, 2 Jun 2015 17:58:30 +0200 Subject: [PATCH 05/47] Fixed tests. --- app/Http/Controllers/AccountController.php | 2 +- app/Repositories/Account/AccountRepository.php | 17 +++++++++-------- app/Support/ChartProperties.php | 11 ++--------- tests/controllers/AccountControllerTest.php | 1 + tests/controllers/BillControllerTest.php | 1 + tests/controllers/BudgetControllerTest.php | 1 + tests/controllers/PreferencesControllerTest.php | 1 + 7 files changed, 16 insertions(+), 18 deletions(-) diff --git a/app/Http/Controllers/AccountController.php b/app/Http/Controllers/AccountController.php index ffe7354574..dbef12d1e4 100644 --- a/app/Http/Controllers/AccountController.php +++ b/app/Http/Controllers/AccountController.php @@ -12,7 +12,7 @@ use Session; use Steam; use URL; use View; - +use Preferences; /** * Class AccountController * diff --git a/app/Repositories/Account/AccountRepository.php b/app/Repositories/Account/AccountRepository.php index a6ec7f81bd..dc9939aeab 100644 --- a/app/Repositories/Account/AccountRepository.php +++ b/app/Repositories/Account/AccountRepository.php @@ -363,11 +363,11 @@ class AccountRepository implements AccountRepositoryInterface if ($data['openingBalance'] != 0) { $type = $data['openingBalance'] < 0 ? 'expense' : 'revenue'; $opposingData = [ - 'user' => $data['user'], - 'accountType' => $type, + 'user' => $data['user'], + 'accountType' => $type, 'virtualBalance' => 0, - 'name' => $data['name'] . ' initial balance', - 'active' => false, + 'name' => $data['name'] . ' initial balance', + 'active' => false, ]; $opposing = $this->storeAccount($opposingData); $this->storeInitialBalance($newAccount, $opposing, $data); @@ -414,10 +414,11 @@ class AccountRepository implements AccountRepositoryInterface // create new opening balance. $type = $data['openingBalance'] < 0 ? 'expense' : 'revenue'; $opposingData = [ - 'user' => $data['user'], - 'accountType' => $type, - 'name' => $data['name'] . ' initial balance', - 'active' => false, + 'user' => $data['user'], + 'accountType' => $type, + 'name' => $data['name'] . ' initial balance', + 'active' => false, + 'virtualBalance' => 0, ]; $opposing = $this->storeAccount($opposingData); $this->storeInitialBalance($account, $opposing, $data); diff --git a/app/Support/ChartProperties.php b/app/Support/ChartProperties.php index e12d864808..3bff338446 100644 --- a/app/Support/ChartProperties.php +++ b/app/Support/ChartProperties.php @@ -7,7 +7,7 @@ use Auth; use Carbon\Carbon; use Illuminate\Database\Eloquent\Collection as EloquentCollection; use Illuminate\Support\Collection; -use Preferences; +use Preferences as Prefs; /** * Class ChartProperties @@ -27,7 +27,7 @@ class ChartProperties { $this->properties = new Collection; $this->addProperty(Auth::user()->id); - $this->addProperty(Preferences::lastActivity()); + $this->addProperty(Prefs::lastActivity()); } /** @@ -50,28 +50,21 @@ class ChartProperties if ($property instanceof Collection || $property instanceof EloquentCollection) { $string .= print_r($property->toArray(), true); - // Log::debug('added collection (size=' . $property->count() . ')'); continue; } if ($property instanceof Carbon) { $string .= $property->toRfc3339String(); - // Log::debug('Added time: ' . $property->toRfc3339String()); continue; } if (is_object($property)) { $string .= $property->__toString(); - // Log::debug('Added object of class ' . get_class($property)); } if (is_array($property)) { $string .= print_r($property, true); - // Log::debug('Added array (size=' . count($property) . ')'); } $string .= (string)$property; - // Log::debug('Added cast to string: ' . $property); } - // Log::debug('--- done building string ---'); - return md5($string); } } \ No newline at end of file diff --git a/tests/controllers/AccountControllerTest.php b/tests/controllers/AccountControllerTest.php index 5913d750c7..0ff00f50ba 100644 --- a/tests/controllers/AccountControllerTest.php +++ b/tests/controllers/AccountControllerTest.php @@ -69,6 +69,7 @@ class AccountControllerTest extends TestCase Preferences::shouldReceive('get')->withArgs(['viewRange', '1M'])->andReturn($pref); + $language = FactoryMuffin::create('FireflyIII\Models\Preference'); $language->data = 'en'; Preferences::shouldReceive('get')->withArgs(['language', 'en'])->andReturn($language); diff --git a/tests/controllers/BillControllerTest.php b/tests/controllers/BillControllerTest.php index 7ae7e26760..7242424df2 100644 --- a/tests/controllers/BillControllerTest.php +++ b/tests/controllers/BillControllerTest.php @@ -188,6 +188,7 @@ class BillControllerTest extends TestCase $repository->shouldReceive('nextExpectedMatch')->once()->andReturn(new Carbon); Amount::shouldReceive('format')->andReturn('XX'); + Amount::shouldReceive('formatJournal')->andReturn('XX'); Amount::shouldReceive('getCurrencyCode')->andReturn('XX'); diff --git a/tests/controllers/BudgetControllerTest.php b/tests/controllers/BudgetControllerTest.php index df08b1502a..01f8b7c9d4 100644 --- a/tests/controllers/BudgetControllerTest.php +++ b/tests/controllers/BudgetControllerTest.php @@ -193,6 +193,7 @@ class BudgetControllerTest extends TestCase $this->be($budget->user); $date = Carbon::now()->startOfMonth()->format('FY'); Preferences::shouldReceive('set')->once()->withArgs(['budgetIncomeTotal' . $date, 1001]); + Preferences::shouldReceive('mark')->once()->andReturn(true); // language preference: $language = FactoryMuffin::create('FireflyIII\Models\Preference'); diff --git a/tests/controllers/PreferencesControllerTest.php b/tests/controllers/PreferencesControllerTest.php index 7a6a5b3b87..af3b9d1ab9 100644 --- a/tests/controllers/PreferencesControllerTest.php +++ b/tests/controllers/PreferencesControllerTest.php @@ -97,6 +97,7 @@ class PreferencesControllerTest extends TestCase Preferences::shouldReceive('set')->once()->withArgs(['viewRange', '1M']); Preferences::shouldReceive('set')->once()->withArgs(['budgetMaximum', 0]); Preferences::shouldReceive('set')->once()->withArgs(['language', 'en']); + Preferences::shouldReceive('mark')->once()->andReturn(true); // language preference: $language = FactoryMuffin::create('FireflyIII\Models\Preference'); From be17e4481e6f508dc3d5f0a9e8674e2310bdeeea Mon Sep 17 00:00:00 2001 From: James Cole Date: Tue, 2 Jun 2015 18:05:42 +0200 Subject: [PATCH 06/47] Cache boxes. --- app/Http/Controllers/JsonController.php | 89 ++++++++++++++++++++++--- 1 file changed, 79 insertions(+), 10 deletions(-) diff --git a/app/Http/Controllers/JsonController.php b/app/Http/Controllers/JsonController.php index b88dc0e0b3..9ad1f8b6a7 100644 --- a/app/Http/Controllers/JsonController.php +++ b/app/Http/Controllers/JsonController.php @@ -1,6 +1,7 @@ startOfMonth()); - $end = Session::get('end', Carbon::now()->endOfMonth()); + $start = Session::get('start', Carbon::now()->startOfMonth()); + $end = Session::get('end', Carbon::now()->endOfMonth()); + + // works for json too! + $prop = new ChartProperties; + $prop->addProperty($start); + $prop->addProperty($end); + $prop->addProperty('box-bills-paid'); + $md5 = $prop->md5(); + if (Cache::has($md5)) { + Log::debug('Successfully returned cached box bills-paid [' . $md5 . ']'); + + return Response::json(Cache::get($md5)); + } + $amount = 0; + // these two functions are the same as the chart $bills = $repository->getActiveBills(); @@ -60,8 +77,10 @@ class JsonController extends Controller $amount += $accountRepository->getTransfersInRange($creditCard, $start, $end)->sum('amount'); } } + $data = ['box' => 'bills-paid', 'amount' => Amount::format($amount, false), 'amount_raw' => $amount]; + Cache::forever($md5, $data); - return Response::json(['box' => 'bills-paid', 'amount' => Amount::format($amount, false), 'amount_raw' => $amount]); + return Response::json($data); } /** @@ -75,6 +94,19 @@ class JsonController extends Controller $amount = 0; $start = Session::get('start', Carbon::now()->startOfMonth()); $end = Session::get('end', Carbon::now()->endOfMonth()); + + // works for json too! + $prop = new ChartProperties; + $prop->addProperty($start); + $prop->addProperty($end); + $prop->addProperty('box-bills-unpaid'); + $md5 = $prop->md5(); + if (Cache::has($md5)) { + Log::debug('Successfully returned cached box bills-unpaid [' . $md5 . ']'); + + return Response::json(Cache::get($md5)); + } + $bills = $repository->getActiveBills(); $unpaid = new Collection; // bills @@ -109,7 +141,10 @@ class JsonController extends Controller $amount += $current; } - return Response::json(['box' => 'bills-unpaid', 'amount' => Amount::format($amount, false), 'amount_raw' => $amount]); + $data = ['box' => 'bills-unpaid', 'amount' => Amount::format($amount, false), 'amount_raw' => $amount]; + Cache::forever($md5, $data); + + return Response::json($data); } /** @@ -119,11 +154,28 @@ class JsonController extends Controller */ public function boxIn(ReportQueryInterface $reportQuery) { - $start = Session::get('start', Carbon::now()->startOfMonth()); - $end = Session::get('end', Carbon::now()->endOfMonth()); + $start = Session::get('start', Carbon::now()->startOfMonth()); + $end = Session::get('end', Carbon::now()->endOfMonth()); + + // works for json too! + $prop = new ChartProperties; + $prop->addProperty($start); + $prop->addProperty($end); + $prop->addProperty('box-in'); + $md5 = $prop->md5(); + if (Cache::has($md5)) { + Log::debug('Successfully returned cached box in [' . $md5 . ']'); + + return Response::json(Cache::get($md5)); + } + + $amount = $reportQuery->incomeInPeriodCorrected($start, $end, true)->sum('amount'); - return Response::json(['box' => 'in', 'amount' => Amount::format($amount, false), 'amount_raw' => $amount]); + $data = ['box' => 'in', 'amount' => Amount::format($amount, false), 'amount_raw' => $amount]; + Cache::forever($md5, $data); + + return Response::json($data); } /** @@ -133,11 +185,28 @@ class JsonController extends Controller */ public function boxOut(ReportQueryInterface $reportQuery) { - $start = Session::get('start', Carbon::now()->startOfMonth()); - $end = Session::get('end', Carbon::now()->endOfMonth()); + $start = Session::get('start', Carbon::now()->startOfMonth()); + $end = Session::get('end', Carbon::now()->endOfMonth()); + + + // works for json too! + $prop = new ChartProperties; + $prop->addProperty($start); + $prop->addProperty($end); + $prop->addProperty('box-out'); + $md5 = $prop->md5(); + if (Cache::has($md5)) { + Log::debug('Successfully returned cached box out [' . $md5 . ']'); + + return Response::json(Cache::get($md5)); + } + $amount = $reportQuery->expenseInPeriodCorrected($start, $end, true)->sum('amount'); - return Response::json(['box' => 'out', 'amount' => Amount::format($amount, false), 'amount_raw' => $amount]); + $data = ['box' => 'out', 'amount' => Amount::format($amount, false), 'amount_raw' => $amount]; + Cache::forever($md5, $data); + + return Response::json($data); } /** From 2e75446665018dd05b087e00d8a0cae0112fbd23 Mon Sep 17 00:00:00 2001 From: James Cole Date: Tue, 2 Jun 2015 18:13:23 +0200 Subject: [PATCH 07/47] Fixed some JS bugs [skip ci] --- public/js/budgets.js | 60 +++++++++++++++++++++++--------------------- 1 file changed, 32 insertions(+), 28 deletions(-) diff --git a/public/js/budgets.js b/public/js/budgets.js index 52e80dff01..ee4ecceb21 100644 --- a/public/js/budgets.js +++ b/public/js/budgets.js @@ -2,43 +2,47 @@ function drawSpentBar() { "use strict"; + if ($('.spentBar').length > 0) { + var overspent = spent > budgeted; + var pct; - var overspent = spent > budgeted; - var pct; - - if (overspent) { - // draw overspent bar - pct = (budgeted / spent) * 100; - $('.spentBar .progress-bar-warning').css('width', pct + '%'); - $('.spentBar .progress-bar-danger').css('width', (100 - pct) + '%'); - } else { - // draw normal bar: - pct = (spent / budgeted) * 100; - $('.spentBar .progress-bar-info').css('width', pct + '%'); + if (overspent) { + // draw overspent bar + pct = (budgeted / spent) * 100; + $('.spentBar .progress-bar-warning').css('width', pct + '%'); + $('.spentBar .progress-bar-danger').css('width', (100 - pct) + '%'); + } else { + // draw normal bar: + pct = (spent / budgeted) * 100; + $('.spentBar .progress-bar-info').css('width', pct + '%'); + } } } function drawBudgetedBar() { "use strict"; - var budgetedMuch = budgeted > budgetIncomeTotal; - // recalculate percentage: + if ($('.budgetedBar').length > 0) { + var budgetedMuch = budgeted > budgetIncomeTotal; - var pct; - if (budgetedMuch) { - // budgeted too much. - pct = (budgetIncomeTotal / budgeted) * 100; - $('.budgetedBar .progress-bar-warning').css('width', pct + '%'); - $('.budgetedBar .progress-bar-danger').css('width', (100 - pct) + '%'); - $('.budgetedBar .progress-bar-info').css('width', 0); - } else { - pct = (budgeted / budgetIncomeTotal) * 100; - $('.budgetedBar .progress-bar-warning').css('width', 0); - $('.budgetedBar .progress-bar-danger').css('width', 0); - $('.budgetedBar .progress-bar-info').css('width', pct + '%'); + // recalculate percentage: + + var pct; + if (budgetedMuch) { + // budgeted too much. + pct = (budgetIncomeTotal / budgeted) * 100; + $('.budgetedBar .progress-bar-warning').css('width', pct + '%'); + $('.budgetedBar .progress-bar-danger').css('width', (100 - pct) + '%'); + $('.budgetedBar .progress-bar-info').css('width', 0); + } else { + pct = (budgeted / budgetIncomeTotal) * 100; + $('.budgetedBar .progress-bar-warning').css('width', 0); + $('.budgetedBar .progress-bar-danger').css('width', 0); + $('.budgetedBar .progress-bar-info').css('width', pct + '%'); + } + + $('#budgetedAmount').html(currencySymbol + ' ' + budgeted.toFixed(2)); } - - $('#budgetedAmount').html(currencySymbol + ' ' + budgeted.toFixed(2)); } function updateBudgetedAmounts(e) { From 72dd06493228a420d352e5c6fe580109de4c8258 Mon Sep 17 00:00:00 2001 From: James Cole Date: Tue, 2 Jun 2015 21:58:30 +0200 Subject: [PATCH 08/47] Fix count in transaction search [skip ci] --- resources/twig/search/index.twig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/twig/search/index.twig b/resources/twig/search/index.twig index c00b12b931..cd9b4f740f 100644 --- a/resources/twig/search/index.twig +++ b/resources/twig/search/index.twig @@ -7,7 +7,7 @@
- Transactions ({ result.transactions|length }}) + Transactions ({{ result.transactions|length }})
{% include 'list/journals-tiny' with {'transactions' : result.transactions} %} From b935e323402b2c2c89f759b3c2fdcc4f1a0acc22 Mon Sep 17 00:00:00 2001 From: James Cole Date: Tue, 2 Jun 2015 22:07:38 +0200 Subject: [PATCH 09/47] Fix amount in tag list [skip ci] --- app/Models/TransactionJournal.php | 32 +++++++++++++++++++++++-------- resources/twig/list/journals.twig | 2 +- 2 files changed, 25 insertions(+), 9 deletions(-) diff --git a/app/Models/TransactionJournal.php b/app/Models/TransactionJournal.php index 8aedbd44d2..5b771bd9cf 100644 --- a/app/Models/TransactionJournal.php +++ b/app/Models/TransactionJournal.php @@ -60,13 +60,13 @@ use Watson\Validating\ValidatingTrait; * @method static \FireflyIII\Models\TransactionJournal onDate($date) * @method static \FireflyIII\Models\TransactionJournal transactionTypes($types) * @method static \FireflyIII\Models\TransactionJournal withRelevantData() - * @property-read mixed $expense_account - * @property string account_encrypted - * @property bool joinedTransactions - * @property bool joinedTransactionTypes - * @property mixed account_id - * @property mixed name - * @property mixed symbol + * @property-read mixed $expense_account + * @property string account_encrypted + * @property bool joinedTransactions + * @property bool joinedTransactionTypes + * @property mixed account_id + * @property mixed name + * @property mixed symbol */ class TransactionJournal extends Model { @@ -219,6 +219,22 @@ class TransactionJournal extends Model } + /** + * @return string + */ + public function getCorrectAmountAttribute() + { + + switch ($this->transactionType->type) { + case 'Deposit': + return $this->transactions()->where('amount', '>', 0)->first()->amount; + case 'Withdrawal': + return $this->transactions()->where('amount', '<', 0)->first()->amount; + } + + return '0'; + } + /** * @codeCoverageIgnore * @return \Illuminate\Database\Eloquent\Relations\HasMany @@ -379,7 +395,7 @@ class TransactionJournal extends Model public function scopeWithRelevantData(EloquentBuilder $query) { $query->with( - ['transactions' => function(HasMany $q) { + ['transactions' => function (HasMany $q) { $q->orderBy('amount', 'ASC'); }, 'transactiontype', 'transactioncurrency', 'budgets', 'categories', 'transactions.account.accounttype', 'bill', 'budgets', 'categories'] ); diff --git a/resources/twig/list/journals.twig b/resources/twig/list/journals.twig index 78812ceda0..44df7e1abb 100644 --- a/resources/twig/list/journals.twig +++ b/resources/twig/list/journals.twig @@ -57,7 +57,7 @@ {% if not hideTags %} {{ relevantTags(journal)|raw }} {% else %} - {{ journal.correctedActualAmount|formatAmount }} + {{ journal.correctAmount|formatAmount }} {% endif %} From 21631780bb659108983bf42eed6bcda55c450a6b Mon Sep 17 00:00:00 2001 From: James Cole Date: Tue, 2 Jun 2015 22:22:47 +0200 Subject: [PATCH 10/47] Fix some tests --- app/Handlers/Events/ConnectJournalToPiggyBank.php | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/app/Handlers/Events/ConnectJournalToPiggyBank.php b/app/Handlers/Events/ConnectJournalToPiggyBank.php index f33e283fa1..701daa11c7 100644 --- a/app/Handlers/Events/ConnectJournalToPiggyBank.php +++ b/app/Handlers/Events/ConnectJournalToPiggyBank.php @@ -4,7 +4,6 @@ use Auth; use FireflyIII\Events\JournalCreated; use FireflyIII\Models\PiggyBank; use FireflyIII\Models\PiggyBankEvent; -use FireflyIII\Models\Transaction; use FireflyIII\Models\TransactionJournal; /** @@ -53,17 +52,9 @@ class ConnectJournalToPiggyBank return false; } - $amount = $journal->amount; - /** @var Transaction $transaction */ - foreach ($journal->transactions()->get() as $transaction) { - if ($transaction->account_id == $piggyBank->account_id) { - if ($transaction->amount < 0) { - $amount = $transaction->amount * -1; - } - } - } - - $repetition->currentamount += $amount; + $amount = $journal->correct_amount; + bcscale(2); + $repetition->currentamount = bcadd($repetition->currentamount, $amount); $repetition->save(); PiggyBankEvent::create(['piggy_bank_id' => $piggyBank->id, 'transaction_journal_id' => $journal->id, 'date' => $journal->date, 'amount' => $amount]); From d1d6c48d9b6d35c2658cd254263f8a22892d9d22 Mon Sep 17 00:00:00 2001 From: Sander Dorigo Date: Wed, 3 Jun 2015 11:27:47 +0200 Subject: [PATCH 11/47] Update GA code --- resources/twig/layout/default.twig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/twig/layout/default.twig b/resources/twig/layout/default.twig index 7247597006..044699368f 100644 --- a/resources/twig/layout/default.twig +++ b/resources/twig/layout/default.twig @@ -161,7 +161,7 @@ m.parentNode.insertBefore(a, m) })(window, document, 'script', '//www.google-analytics.com/analytics.js', 'ga'); - ga('create', '{{ env('ANALYTICS_ID', 'XXX-XX-X') }}', 'auto'); + ga('create', '{{ env('ANALYTICS_ID', 'XXX-XX-X') }}', {'siteSpeedSampleRate': 100}); ga('send', 'pageview'); // send an event if relevant: From 4b0b79199dfacf791eb5ecd0d50ad895d16a7c28 Mon Sep 17 00:00:00 2001 From: James Cole Date: Wed, 3 Jun 2015 17:32:50 +0200 Subject: [PATCH 12/47] Some cleanup. --- app/Http/Controllers/HomeController.php | 11 +++ config/app.php | 10 +-- public/js/transactions.js | 104 +++++++++++++++++++++++- resources/twig/form/amount.twig | 2 +- resources/twig/form/balance.twig | 2 +- resources/twig/form/checkbox.twig | 2 +- resources/twig/form/date.twig | 2 +- resources/twig/form/integer.twig | 2 +- resources/twig/form/location.twig | 2 +- resources/twig/form/multiRadio.twig | 2 +- resources/twig/form/select.twig | 2 +- resources/twig/form/tags.twig | 2 +- resources/twig/form/text.twig | 2 +- resources/twig/form/textarea.twig | 2 +- resources/twig/layout/default.twig | 2 +- resources/twig/transactions/create.twig | 62 +++++++++----- 16 files changed, 172 insertions(+), 39 deletions(-) diff --git a/app/Http/Controllers/HomeController.php b/app/Http/Controllers/HomeController.php index a28ad3acfe..2c2d9a8789 100644 --- a/app/Http/Controllers/HomeController.php +++ b/app/Http/Controllers/HomeController.php @@ -2,6 +2,7 @@ use Carbon\Carbon; use Config; +use FireflyIII\Models\TransactionJournal; use FireflyIII\Repositories\Account\AccountRepositoryInterface; use Input; use Preferences; @@ -40,6 +41,16 @@ class HomeController extends Controller { Session::clear(); + // encrypt transaction journal description + $set = TransactionJournal::where('encrypted', 0)->take(100)->get(); + /** @var TransactionJournal $entry */ + foreach ($set as $entry) { + $description = $entry->description; + $entry->description = $description; + $entry->save(); + } + unset($set, $entry, $description); + return Redirect::route('index'); } diff --git a/config/app.php b/config/app.php index 7c8c30c9c3..c23a78eb01 100644 --- a/config/app.php +++ b/config/app.php @@ -115,7 +115,7 @@ return [ */ 'Illuminate\Foundation\Providers\ArtisanServiceProvider', 'Illuminate\Auth\AuthServiceProvider', - 'Illuminate\Bus\BusServiceProvider', + //'Illuminate\Bus\BusServiceProvider', 'Illuminate\Cache\CacheServiceProvider', 'Illuminate\Foundation\Providers\ConsoleSupportServiceProvider', 'Illuminate\Routing\ControllerServiceProvider', @@ -139,16 +139,16 @@ return [ 'TwigBridge\ServiceProvider', 'DaveJamesMiller\Breadcrumbs\ServiceProvider', -// 'Barryvdh\Debugbar\ServiceProvider', -// 'Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider', + //'Barryvdh\Debugbar\ServiceProvider', + //'Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider', 'Zizaco\Entrust\EntrustServiceProvider', /* * Application Service Providers... */ 'FireflyIII\Providers\AppServiceProvider', - 'FireflyIII\Providers\BusServiceProvider', - 'FireflyIII\Providers\ConfigServiceProvider', + //'FireflyIII\Providers\BusServiceProvider', + //'FireflyIII\Providers\ConfigServiceProvider', 'FireflyIII\Providers\EventServiceProvider', 'FireflyIII\Providers\RouteServiceProvider', 'FireflyIII\Providers\FireflyServiceProvider', diff --git a/public/js/transactions.js b/public/js/transactions.js index b9cee1ded4..bb70ee82c8 100644 --- a/public/js/transactions.js +++ b/public/js/transactions.js @@ -1,4 +1,4 @@ -/* globals what, $ */ +/* globals what:true, $, doSwitch, txt, middleCrumbName, title,button, middleCrumbUrl, piggiesLength, breadcrumbs */ $(document).ready(function () { "use strict"; if ($('input[name="expense_account"]').length > 0) { @@ -38,4 +38,104 @@ $(document).ready(function () { }); } -}); \ No newline at end of file + // respond to switch buttons: + if (doSwitch) { + updateButtons(); + updateForm(); + updateLayout(); + } + + +}); + +function updateLayout() { + "use strict"; + $('#subTitle').text(title[what]); + $('.breadcrumb .active').text(breadcrumbs[what]); + $('.breadcrumb li:nth-child(2)').html('' + middleCrumbName[what] + ''); + $('#transaction-btn').html(' ' + button[what]); +} + +function updateForm() { + "use strict"; + + $('input[name="what"]').val(what); + + switch (what) { + case 'withdrawal': + $('#account_id_holder').show(); + $('#expense_account_holder').show(); + $('#revenue_account_holder').hide(); + $('#account_from_id_holder').hide(); + $('#account_to_id_holder').hide(); + $('#budget_id_holder').show(); + $('#piggy_bank_id_holder').hide(); + + + if ($('#ffInput_revenue_account').val().length > 0) { + $('#ffInput_expense_account').val($('#ffInput_revenue_account').val()); + } + + break; + case 'deposit': + $('#account_id_holder').show(); + $('#expense_account_holder').hide(); + $('#revenue_account_holder').show(); + $('#account_from_id_holder').hide(); + $('#account_to_id_holder').hide(); + $('#budget_id_holder').hide(); + $('#piggy_bank_id_holder').hide(); + + if ($('#ffInput_expense_account').val().length > 0) { + $('#ffInput_revenue_account').val($('#ffInput_expense_account').val()); + } + + break; + case 'transfer': + $('#account_id_holder').hide(); + $('#expense_account_holder').hide(); + $('#revenue_account_holder').hide(); + $('#account_from_id_holder').show(); + $('#account_to_id_holder').show(); + $('#budget_id_holder').hide(); + if (piggiesLength === 0) { + $('#piggy_bank_id_holder').hide(); + } else { + $('#piggy_bank_id_holder').show(); + } + break; + } +} + + +function updateButtons() { + "use strict"; + $('.switch').each(function (i, v) { + var button = $(v); + + // remove click event: + button.unbind('click'); + // new click event: + button.bind('click', clickButton); + + if (button.data('what') == what) { + button.removeClass('btn-default').addClass('btn-info').html(' ' + txt[button.data('what')]); + console.log('Now displaying form for ' + what); + } else { + button.removeClass('btn-info').addClass('btn-default').text(txt[button.data('what')]); + } + }); +} + +function clickButton(e) { + "use strict"; + var button = $(e.target); + var newWhat = button.data('what'); + if (newWhat != what) { + what = newWhat; + updateButtons(); + updateForm(); + updateLayout(); + } + return false; +} \ No newline at end of file diff --git a/resources/twig/form/amount.twig b/resources/twig/form/amount.twig index cc0ff82ae1..765b200feb 100644 --- a/resources/twig/form/amount.twig +++ b/resources/twig/form/amount.twig @@ -1,4 +1,4 @@ -
+
diff --git a/resources/twig/form/balance.twig b/resources/twig/form/balance.twig index 882db8e808..e8e8e05ae0 100644 --- a/resources/twig/form/balance.twig +++ b/resources/twig/form/balance.twig @@ -1,4 +1,4 @@ -
+
diff --git a/resources/twig/form/checkbox.twig b/resources/twig/form/checkbox.twig index 21d8e59177..448986aa03 100644 --- a/resources/twig/form/checkbox.twig +++ b/resources/twig/form/checkbox.twig @@ -1,4 +1,4 @@ -
+
diff --git a/resources/twig/form/date.twig b/resources/twig/form/date.twig index 33a300d057..918b5bc6fd 100644 --- a/resources/twig/form/date.twig +++ b/resources/twig/form/date.twig @@ -1,4 +1,4 @@ -
+
{{ Form.input('date', name, value, options) }} diff --git a/resources/twig/form/integer.twig b/resources/twig/form/integer.twig index 527a5b2fea..f8fc237bfc 100644 --- a/resources/twig/form/integer.twig +++ b/resources/twig/form/integer.twig @@ -1,4 +1,4 @@ -
+
diff --git a/resources/twig/form/location.twig b/resources/twig/form/location.twig index efb95bb6c3..582181e434 100644 --- a/resources/twig/form/location.twig +++ b/resources/twig/form/location.twig @@ -1,4 +1,4 @@ -
+
diff --git a/resources/twig/form/multiRadio.twig b/resources/twig/form/multiRadio.twig index b79ff1559c..b03b69be7e 100644 --- a/resources/twig/form/multiRadio.twig +++ b/resources/twig/form/multiRadio.twig @@ -1,4 +1,4 @@ -
+
{% for value,description in list %} diff --git a/resources/twig/form/select.twig b/resources/twig/form/select.twig index 6956207700..40ac6949f3 100644 --- a/resources/twig/form/select.twig +++ b/resources/twig/form/select.twig @@ -1,4 +1,4 @@ -
+
{{ Form.select(name, list, selected , options ) }} diff --git a/resources/twig/form/tags.twig b/resources/twig/form/tags.twig index 9160512040..3a00f1479c 100644 --- a/resources/twig/form/tags.twig +++ b/resources/twig/form/tags.twig @@ -1,4 +1,4 @@ -
+
{{ Form.input('text', name, value, options) }} diff --git a/resources/twig/form/text.twig b/resources/twig/form/text.twig index 428b238b70..d13baef62a 100644 --- a/resources/twig/form/text.twig +++ b/resources/twig/form/text.twig @@ -1,4 +1,4 @@ -
+
{{ Form.input('text', name, value, options) }} diff --git a/resources/twig/form/textarea.twig b/resources/twig/form/textarea.twig index 6d1d950a04..4eb913d919 100644 --- a/resources/twig/form/textarea.twig +++ b/resources/twig/form/textarea.twig @@ -1,4 +1,4 @@ -
+
{{ Form.textarea(name, value, options) }} diff --git a/resources/twig/layout/default.twig b/resources/twig/layout/default.twig index 044699368f..a5ef822a86 100644 --- a/resources/twig/layout/default.twig +++ b/resources/twig/layout/default.twig @@ -66,7 +66,7 @@ {{ title }} {% if subTitle %} - + {% if subTitleIcon %} {% endif %} diff --git a/resources/twig/transactions/create.twig b/resources/twig/transactions/create.twig index 8c6724b14e..b40817560c 100644 --- a/resources/twig/transactions/create.twig +++ b/resources/twig/transactions/create.twig @@ -11,29 +11,35 @@ {{ 'mandatoryFields'|_ }}
+ + + {{ ExpandedForm.text('description') }} - {% if what == 'deposit' or what == 'withdrawal' %} - {{ ExpandedForm.select('account_id',accounts) }} - {% endif %} + + + {{ ExpandedForm.select('account_id',accounts) }} - {% if what == 'withdrawal' %} - {{ ExpandedForm.text('expense_account') }} - {% endif %} + {{ ExpandedForm.text('expense_account') }} - {% if what == 'deposit' %} - {{ ExpandedForm.text('revenue_account') }} - {% endif %} + {{ ExpandedForm.text('revenue_account') }} - {% if what == 'transfer' %} - {{ ExpandedForm.select('account_from_id',accounts) }} - {{ ExpandedForm.select('account_to_id',accounts) }} - {% endif %} + {{ ExpandedForm.select('account_from_id',accounts) }} + {{ ExpandedForm.select('account_to_id',accounts) }} @@ -51,9 +57,7 @@
- {% if what == 'withdrawal' %} - {{ ExpandedForm.select('budget_id',budgets,0) }} - {% endif %} + {{ ExpandedForm.select('budget_id',budgets,0) }} {{ ExpandedForm.text('category') }} @@ -62,9 +66,7 @@ - {% if what == 'withdrawal' and piggies|length > 0 %} - {{ ExpandedForm.select('piggy_bank_id',piggies) }} - {% endif %} + {{ ExpandedForm.select('piggy_bank_id',piggies) }}
@@ -82,7 +84,7 @@

-

@@ -94,6 +96,26 @@ {% block scripts %} From a7f6848e53474dfff6c3f14260e0b30d3658b46b Mon Sep 17 00:00:00 2001 From: James Cole Date: Wed, 3 Jun 2015 18:22:47 +0200 Subject: [PATCH 13/47] Lots of stuff gets cached now. --- .../Controllers/Chart/AccountController.php | 8 +- app/Http/Controllers/Chart/BillController.php | 6 +- .../Controllers/Chart/BudgetController.php | 10 +- .../Controllers/Chart/CategoryController.php | 4 +- app/Http/Controllers/HomeController.php | 6 +- app/Http/Controllers/JsonController.php | 10 +- app/Http/Middleware/Reminders.php | 65 ++-- app/Models/TransactionJournal.php | 37 ++- .../Account/AccountRepository.php | 36 ++- ...hartProperties.php => CacheProperties.php} | 10 +- app/Support/Preferences.php | 2 - app/Support/Steam.php | 17 +- app/Support/Twig/Journal.php | 39 ++- composer.json | 1 - composer.lock | 277 +++++++----------- 15 files changed, 286 insertions(+), 242 deletions(-) rename app/Support/{ChartProperties.php => CacheProperties.php} (89%) diff --git a/app/Http/Controllers/Chart/AccountController.php b/app/Http/Controllers/Chart/AccountController.php index e7f4d5b7fc..ae14e368f0 100644 --- a/app/Http/Controllers/Chart/AccountController.php +++ b/app/Http/Controllers/Chart/AccountController.php @@ -8,7 +8,7 @@ use Carbon\Carbon; use FireflyIII\Http\Controllers\Controller; use FireflyIII\Models\Account; use FireflyIII\Repositories\Account\AccountRepositoryInterface; -use FireflyIII\Support\ChartProperties; +use FireflyIII\Support\CacheProperties; use Grumpydictator\Gchart\GChart; use Illuminate\Support\Collection; use Log; @@ -43,7 +43,7 @@ class AccountController extends Controller $end->endOfMonth(); // chart properties for cache: - $chartProperties = new ChartProperties(); + $chartProperties = new CacheProperties(); $chartProperties->addProperty($start); $chartProperties->addProperty($end); $chartProperties->addProperty('all'); @@ -118,7 +118,7 @@ class AccountController extends Controller $accounts = $repository->getFrontpageAccounts($frontPage); // chart properties for cache: - $chartProperties = new ChartProperties(); + $chartProperties = new CacheProperties(); $chartProperties->addProperty($start); $chartProperties->addProperty($end); $chartProperties->addProperty('frontpage'); @@ -182,7 +182,7 @@ class AccountController extends Controller $today = new Carbon; // chart properties for cache: - $chartProperties = new ChartProperties(); + $chartProperties = new CacheProperties(); $chartProperties->addProperty($start); $chartProperties->addProperty($end); $chartProperties->addProperty('frontpage'); diff --git a/app/Http/Controllers/Chart/BillController.php b/app/Http/Controllers/Chart/BillController.php index 569aee84d5..d79c879350 100644 --- a/app/Http/Controllers/Chart/BillController.php +++ b/app/Http/Controllers/Chart/BillController.php @@ -8,7 +8,7 @@ use FireflyIII\Models\Bill; use FireflyIII\Models\TransactionJournal; use FireflyIII\Repositories\Account\AccountRepositoryInterface; use FireflyIII\Repositories\Bill\BillRepositoryInterface; -use FireflyIII\Support\ChartProperties; +use FireflyIII\Support\CacheProperties; use Grumpydictator\Gchart\GChart; use Illuminate\Support\Collection; use Response; @@ -40,7 +40,7 @@ class BillController extends Controller $chart->addColumn(trans('firefly.minAmount'), 'number'); $chart->addColumn(trans('firefly.billEntry'), 'number'); - $chartProperties = new ChartProperties; + $chartProperties = new CacheProperties; $chartProperties->addProperty('single'); $chartProperties->addProperty('bill'); $chartProperties->addProperty($bill->id); @@ -87,7 +87,7 @@ class BillController extends Controller // chart properties for cache: - $chartProperties = new ChartProperties(); + $chartProperties = new CacheProperties(); $chartProperties->addProperty($start); $chartProperties->addProperty($end); $chartProperties->addProperty('bills'); diff --git a/app/Http/Controllers/Chart/BudgetController.php b/app/Http/Controllers/Chart/BudgetController.php index 649c2be783..9627a53c07 100644 --- a/app/Http/Controllers/Chart/BudgetController.php +++ b/app/Http/Controllers/Chart/BudgetController.php @@ -8,7 +8,7 @@ use FireflyIII\Http\Controllers\Controller; use FireflyIII\Models\Budget; use FireflyIII\Models\LimitRepetition; use FireflyIII\Repositories\Budget\BudgetRepositoryInterface; -use FireflyIII\Support\ChartProperties; +use FireflyIII\Support\CacheProperties; use Grumpydictator\Gchart\GChart; use Illuminate\Support\Collection; use Log; @@ -45,7 +45,7 @@ class BudgetController extends Controller $last = Navigation::endOfX($last, $range, $final); // chart properties for cache: - $chartProperties = new ChartProperties(); + $chartProperties = new CacheProperties(); $chartProperties->addProperty($first); $chartProperties->addProperty($last); $chartProperties->addProperty('budget'); @@ -93,7 +93,7 @@ class BudgetController extends Controller $end = $repetition->enddate; // chart properties for cache: - $chartProperties = new ChartProperties(); + $chartProperties = new CacheProperties(); $chartProperties->addProperty($start); $chartProperties->addProperty($end); $chartProperties->addProperty('budget'); @@ -153,7 +153,7 @@ class BudgetController extends Controller $allEntries = new Collection; // chart properties for cache: - $chartProperties = new ChartProperties(); + $chartProperties = new CacheProperties(); $chartProperties->addProperty($start); $chartProperties->addProperty($end); $chartProperties->addProperty('budget'); @@ -227,7 +227,7 @@ class BudgetController extends Controller $budgets = $repository->getBudgets(); // chart properties for cache: - $chartProperties = new ChartProperties(); + $chartProperties = new CacheProperties(); $chartProperties->addProperty($start); $chartProperties->addProperty($end); $chartProperties->addProperty('budget'); diff --git a/app/Http/Controllers/Chart/CategoryController.php b/app/Http/Controllers/Chart/CategoryController.php index 8c076a1791..b86eb143f3 100644 --- a/app/Http/Controllers/Chart/CategoryController.php +++ b/app/Http/Controllers/Chart/CategoryController.php @@ -8,7 +8,7 @@ use Carbon\Carbon; use FireflyIII\Http\Controllers\Controller; use FireflyIII\Models\Category; use FireflyIII\Repositories\Category\CategoryRepositoryInterface; -use FireflyIII\Support\ChartProperties; +use FireflyIII\Support\CacheProperties; use Grumpydictator\Gchart\GChart; use Log; use Navigation; @@ -80,7 +80,7 @@ class CategoryController extends Controller $end = Session::get('end', Carbon::now()->endOfMonth()); // chart properties for cache: - $chartProperties = new ChartProperties; + $chartProperties = new CacheProperties; $chartProperties->addProperty($start); $chartProperties->addProperty($end); $chartProperties->addProperty('category'); diff --git a/app/Http/Controllers/HomeController.php b/app/Http/Controllers/HomeController.php index 2c2d9a8789..7ffa3d9b4e 100644 --- a/app/Http/Controllers/HomeController.php +++ b/app/Http/Controllers/HomeController.php @@ -62,9 +62,11 @@ class HomeController extends Controller public function index(AccountRepositoryInterface $repository) { + $types = Config::get('firefly.accountTypesByIdentifier.asset'); $count = $repository->countAccounts($types); + if ($count == 0) { return Redirect::route('new-user.index'); } @@ -78,8 +80,11 @@ class HomeController extends Controller $end = Session::get('end', Carbon::now()->endOfMonth()); $accounts = $repository->getFrontpageAccounts($frontPage); $savings = $repository->getSavingsAccounts(); + $piggyBankAccounts = $repository->getPiggyBankAccounts(); + + $savingsTotal = 0; foreach ($savings as $savingAccount) { $savingsTotal += Steam::balance($savingAccount, $end); @@ -100,7 +105,6 @@ class HomeController extends Controller $transactions[] = [$set, $account]; } } - return view('index', compact('count', 'title', 'savings', 'subTitle', 'mainTitleIcon', 'transactions', 'savingsTotal', 'piggyBankAccounts')); } diff --git a/app/Http/Controllers/JsonController.php b/app/Http/Controllers/JsonController.php index 9ad1f8b6a7..1908ed7dcf 100644 --- a/app/Http/Controllers/JsonController.php +++ b/app/Http/Controllers/JsonController.php @@ -11,7 +11,7 @@ use FireflyIII\Repositories\Bill\BillRepositoryInterface; use FireflyIII\Repositories\Category\CategoryRepositoryInterface; use FireflyIII\Repositories\Journal\JournalRepositoryInterface; use FireflyIII\Repositories\Tag\TagRepositoryInterface; -use FireflyIII\Support\ChartProperties; +use FireflyIII\Support\CacheProperties; use Illuminate\Support\Collection; use Log; use Response; @@ -40,7 +40,7 @@ class JsonController extends Controller $end = Session::get('end', Carbon::now()->endOfMonth()); // works for json too! - $prop = new ChartProperties; + $prop = new CacheProperties; $prop->addProperty($start); $prop->addProperty($end); $prop->addProperty('box-bills-paid'); @@ -96,7 +96,7 @@ class JsonController extends Controller $end = Session::get('end', Carbon::now()->endOfMonth()); // works for json too! - $prop = new ChartProperties; + $prop = new CacheProperties; $prop->addProperty($start); $prop->addProperty($end); $prop->addProperty('box-bills-unpaid'); @@ -158,7 +158,7 @@ class JsonController extends Controller $end = Session::get('end', Carbon::now()->endOfMonth()); // works for json too! - $prop = new ChartProperties; + $prop = new CacheProperties; $prop->addProperty($start); $prop->addProperty($end); $prop->addProperty('box-in'); @@ -190,7 +190,7 @@ class JsonController extends Controller // works for json too! - $prop = new ChartProperties; + $prop = new CacheProperties; $prop->addProperty($start); $prop->addProperty($end); $prop->addProperty('box-out'); diff --git a/app/Http/Middleware/Reminders.php b/app/Http/Middleware/Reminders.php index 9814e448d0..eb161a4123 100644 --- a/app/Http/Middleware/Reminders.php +++ b/app/Http/Middleware/Reminders.php @@ -3,11 +3,12 @@ namespace FireflyIII\Http\Middleware; use App; +use Cache; use Carbon\Carbon; use Closure; use FireflyIII\Models\PiggyBank; use FireflyIII\Models\Reminder; -use FireflyIII\User; +use FireflyIII\Support\CacheProperties; use Illuminate\Contracts\Auth\Guard; use Illuminate\Http\Request; use View; @@ -47,35 +48,49 @@ class Reminders */ public function handle(Request $request, Closure $next) { + + if ($this->auth->check() && !$request->isXmlHttpRequest()) { // do reminders stuff. - $reminders = []; - if ($this->auth->user() instanceof User) { - $piggyBanks = $this->auth->user()->piggyBanks()->where('remind_me', 1)->get(); - /** @var \FireflyIII\Helpers\Reminders\ReminderHelperInterface $helper */ - $helper = App::make('FireflyIII\Helpers\Reminders\ReminderHelperInterface'); - /** @var PiggyBank $piggyBank */ - foreach ($piggyBanks as $piggyBank) { - $helper->createReminders($piggyBank, new Carbon); - } - // delete invalid reminders - // this is a construction SQLITE cannot handle :( - if (env('DB_CONNECTION') != 'sqlite') { - Reminder::whereUserId($this->auth->user()->id) - ->leftJoin('piggy_banks', 'piggy_banks.id', '=', 'remindersable_id') - ->whereNull('piggy_banks.id') - ->delete(); - } + // abuse CacheProperties to find out if we need to do this: + $properties = new CacheProperties; - // get and list active reminders: - $reminders = $this->auth->user()->reminders()->today()->get(); - $reminders->each( - function (Reminder $reminder) use ($helper) { - $reminder->description = $helper->getReminderText($reminder); - } - ); + $properties->addProperty('reminders'); + $md5 = $properties->md5(); + + if (Cache::has($md5)) { + $reminders = Cache::get($md5); + View::share('reminders', $reminders); + + return $next($request); } + + + $piggyBanks = $this->auth->user()->piggyBanks()->where('remind_me', 1)->get(); + + /** @var \FireflyIII\Helpers\Reminders\ReminderHelperInterface $helper */ + $helper = App::make('FireflyIII\Helpers\Reminders\ReminderHelperInterface'); + + /** @var PiggyBank $piggyBank */ + foreach ($piggyBanks as $piggyBank) { + $helper->createReminders($piggyBank, new Carbon); + } + // delete invalid reminders + // this is a construction SQLITE cannot handle :( + if (env('DB_CONNECTION') != 'sqlite') { + Reminder::whereUserId($this->auth->user()->id)->leftJoin('piggy_banks', 'piggy_banks.id', '=', 'remindersable_id') + ->whereNull('piggy_banks.id')->delete(); + } + + // get and list active reminders: + $reminders = $this->auth->user()->reminders()->today()->get(); + $reminders->each( + function (Reminder $reminder) use ($helper) { + $reminder->description = $helper->getReminderText($reminder); + } + ); + Cache::forever($md5, $reminders); View::share('reminders', $reminders); } diff --git a/app/Models/TransactionJournal.php b/app/Models/TransactionJournal.php index 5b771bd9cf..b4fc946b3e 100644 --- a/app/Models/TransactionJournal.php +++ b/app/Models/TransactionJournal.php @@ -1,7 +1,9 @@ addProperty($this->id); + $prop->addProperty('amount'); + $md5 = $prop->md5(); + if (Cache::has($md5)) { + return Cache::get($md5); + } + + $amount = '0'; bcscale(2); /** @var Transaction $t */ @@ -147,6 +158,8 @@ class TransactionJournal extends Model * If the journal has tags, it gets complicated. */ if ($this->tags->count() == 0) { + Cache::forever($md5, $amount); + return $amount; } @@ -160,6 +173,7 @@ class TransactionJournal extends Model foreach ($others as $other) { $amount = bcsub($amount, $other->actual_amount); } + Cache::forever($md5, $amount); return $amount; } @@ -167,6 +181,8 @@ class TransactionJournal extends Model // if this journal is part of an advancePayment AND the journal is a deposit, // then the journal amount is correcting a withdrawal, and the amount is zero: if ($advancePayment && $this->transactionType->type == 'Deposit') { + Cache::forever($md5, '0'); + return '0'; } @@ -180,12 +196,15 @@ class TransactionJournal extends Model $transfer = $balancingAct->transactionJournals()->transactionTypes(['Transfer'])->first(); if ($transfer) { $amount = bcsub($amount, $transfer->actual_amount); + Cache::forever($md5, $amount); return $amount; } } // @codeCoverageIgnore } // @codeCoverageIgnore + Cache::forever($md5, $amount); + return $amount; } @@ -219,6 +238,15 @@ class TransactionJournal extends Model } + /** + * @codeCoverageIgnore + * @return \Illuminate\Database\Eloquent\Relations\HasMany + */ + public function transactions() + { + return $this->hasMany('FireflyIII\Models\Transaction'); + } + /** * @return string */ @@ -235,15 +263,6 @@ class TransactionJournal extends Model return '0'; } - /** - * @codeCoverageIgnore - * @return \Illuminate\Database\Eloquent\Relations\HasMany - */ - public function transactions() - { - return $this->hasMany('FireflyIII\Models\Transaction'); - } - /** * @codeCoverageIgnore * @return string[] diff --git a/app/Repositories/Account/AccountRepository.php b/app/Repositories/Account/AccountRepository.php index dc9939aeab..02559a82d9 100644 --- a/app/Repositories/Account/AccountRepository.php +++ b/app/Repositories/Account/AccountRepository.php @@ -4,6 +4,7 @@ namespace FireflyIII\Repositories\Account; use App; use Auth; +use Cache; use Carbon\Carbon; use Config; use DB; @@ -15,6 +16,7 @@ use FireflyIII\Models\Preference; use FireflyIII\Models\Transaction; use FireflyIII\Models\TransactionJournal; use FireflyIII\Models\TransactionType; +use FireflyIII\Support\CacheProperties; use Illuminate\Database\Eloquent\Relations\HasMany; use Illuminate\Database\Query\Builder; use Illuminate\Pagination\LengthAwarePaginator; @@ -109,12 +111,23 @@ class AccountRepository implements AccountRepositoryInterface */ public function getFrontpageAccounts(Preference $preference) { + $cache = new CacheProperties(); + $cache->addProperty($preference->data); + $cache->addProperty('frontPageaccounts'); + $md5 = $cache->md5(); + if (Cache::has($md5)) { + return Cache::get($md5); + } + + if ($preference->data == []) { $accounts = Auth::user()->accounts()->accountTypeIn(['Default account', 'Asset account'])->orderBy('accounts.name', 'ASC')->get(['accounts.*']); } else { $accounts = Auth::user()->accounts()->whereIn('id', $preference->data)->orderBy('accounts.name', 'ASC')->get(['accounts.*']); } + Cache::forever($md5, $accounts); + return $accounts; } @@ -131,7 +144,16 @@ class AccountRepository implements AccountRepositoryInterface */ public function getFrontpageTransactions(Account $account, Carbon $start, Carbon $end) { - return Auth::user() + $prop = new CacheProperties(); + $prop->addProperty($account->id); + $prop->addProperty($start); + $prop->addProperty($end); + $md5 = $prop->md5(); + if(Cache::has($md5)) { + return Cache::get($md5); + } + + $set = Auth::user() ->transactionjournals() ->with(['transactions']) ->leftJoin('transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id') @@ -144,6 +166,8 @@ class AccountRepository implements AccountRepositoryInterface ->orderBy('transaction_journals.id', 'DESC') ->take(10) ->get(['transaction_journals.*', 'transaction_currencies.symbol', 'transaction_types.type']); + Cache::forever($md5, $set); + return $set; } /** @@ -207,6 +231,14 @@ class AccountRepository implements AccountRepositoryInterface $ids[] = intval($id->account_id); } + $cache = new CacheProperties; + $cache->addProperty($ids); + $cache->addProperty('piggyAccounts'); + $md5 = $cache->md5(); + if (Cache::has($md5)) { + return Cache::get($md5); + } + $ids = array_unique($ids); if (count($ids) > 0) { $accounts = Auth::user()->accounts()->whereIn('id', $ids)->get(); @@ -231,6 +263,8 @@ class AccountRepository implements AccountRepositoryInterface } ); + Cache::forever($md5, $accounts); + return $accounts; } diff --git a/app/Support/ChartProperties.php b/app/Support/CacheProperties.php similarity index 89% rename from app/Support/ChartProperties.php rename to app/Support/CacheProperties.php index 3bff338446..699d7e9a26 100644 --- a/app/Support/ChartProperties.php +++ b/app/Support/CacheProperties.php @@ -10,11 +10,11 @@ use Illuminate\Support\Collection; use Preferences as Prefs; /** - * Class ChartProperties + * Class CacheProperties * * @package FireflyIII\Support */ -class ChartProperties +class CacheProperties { /** @var Collection */ @@ -56,6 +56,12 @@ class ChartProperties $string .= $property->toRfc3339String(); continue; } + + if (is_array($property)) { + $string .= print_r($property, true); + continue; + } + if (is_object($property)) { $string .= $property->__toString(); } diff --git a/app/Support/Preferences.php b/app/Support/Preferences.php index bf781877d7..d5ddc4f181 100644 --- a/app/Support/Preferences.php +++ b/app/Support/Preferences.php @@ -4,7 +4,6 @@ namespace FireflyIII\Support; use Auth; use FireflyIII\Models\Preference; -use Log; /** * Class Preferences * @@ -26,7 +25,6 @@ class Preferences * @return bool */ public function mark() { - Log::debug('MARK!'); $this->set('lastActivity',microtime()); return true; } diff --git a/app/Support/Steam.php b/app/Support/Steam.php index a04e3ee002..6e61e3cff5 100644 --- a/app/Support/Steam.php +++ b/app/Support/Steam.php @@ -2,10 +2,9 @@ namespace FireflyIII\Support; +use Cache; use Carbon\Carbon; use FireflyIII\Models\Account; -use FireflyIII\Models\PiggyBank; -use FireflyIII\Models\PiggyBankRepetition; /** * Class Steam @@ -24,6 +23,19 @@ class Steam */ public function balance(Account $account, Carbon $date, $ignoreVirtualBalance = false) { + + // abuse chart properties: + $properties = new CacheProperties; + $properties->addProperty($account->id); + $properties->addProperty('balance'); + $properties->addProperty($date); + $properties->addProperty($ignoreVirtualBalance); + $md5 = $properties->md5(); + if (Cache::has($md5)) { + return Cache::get($md5); + } + + // find the first known transaction on this account: $firstDateObject = $account ->transactions() @@ -45,6 +57,7 @@ class Steam if (!$ignoreVirtualBalance) { $balance = bcadd($balance, $account->virtual_balance); } + Cache::forever($md5, round($balance, 2)); return round($balance, 2); } diff --git a/app/Support/Twig/Journal.php b/app/Support/Twig/Journal.php index beaafae668..ba03775a5d 100644 --- a/app/Support/Twig/Journal.php +++ b/app/Support/Twig/Journal.php @@ -4,7 +4,9 @@ namespace FireflyIII\Support\Twig; use App; +use Cache; use FireflyIII\Models\TransactionJournal; +use FireflyIII\Support\CacheProperties; use Twig_Extension; use Twig_SimpleFilter; use Twig_SimpleFunction; @@ -26,21 +28,38 @@ class Journal extends Twig_Extension $filters = []; $filters[] = new Twig_SimpleFilter( - 'typeIcon', function(TransactionJournal $journal) { + 'typeIcon', function (TransactionJournal $journal) { + + $prop = new CacheProperties(); + $prop->addProperty($journal->id); + $prop->addProperty('typeIcon'); + $md5 = $prop->md5(); + if (Cache::has($md5)) { + return Cache::get($md5); + } + $type = $journal->transactionType->type; switch ($type) { case 'Withdrawal': - return ''; + $txt = ''; + break; case 'Deposit': - return ''; + $txt = ''; + break; case 'Transfer': - return ''; + $txt = ''; + break; case 'Opening balance': - return ''; + $txt = ''; + break; default: - return ''; + $txt = ''; + break; } + Cache::forever($md5, $txt); + + return $txt; }, ['is_safe' => ['html']] @@ -59,7 +78,7 @@ class Journal extends Twig_Extension $functions = []; $functions[] = new Twig_SimpleFunction( - 'invalidJournal', function(TransactionJournal $journal) { + 'invalidJournal', function (TransactionJournal $journal) { if (!isset($journal->transactions[1]) || !isset($journal->transactions[0])) { return true; } @@ -69,7 +88,7 @@ class Journal extends Twig_Extension ); $functions[] = new Twig_SimpleFunction( - 'relevantTags', function(TransactionJournal $journal) { + 'relevantTags', function (TransactionJournal $journal) { if ($journal->tags->count() == 0) { return App::make('amount')->formatJournal($journal); } @@ -82,7 +101,7 @@ class Journal extends Twig_Extension $amount = App::make('amount')->format($journal->actual_amount, false); return ' ' . $tag->tag . ''; + . '"> ' . $tag->tag . ''; } /* @@ -92,7 +111,7 @@ class Journal extends Twig_Extension $amount = App::make('amount')->formatJournal($journal, false); return ' ' . $tag->tag . ''; + . '"> ' . $tag->tag . ''; } /* * AdvancePayment with a withdrawal will show the amount with a link to diff --git a/composer.json b/composer.json index 48d5895bfe..f123bbe2b4 100644 --- a/composer.json +++ b/composer.json @@ -28,7 +28,6 @@ "illuminate/html": "~5.0", "league/commonmark": "0.7.*", "rcrowe/twigbridge": "0.7.x@dev", - "twig/extensions": "~1.2", "zizaco/entrust": "dev-laravel-5" }, "require-dev": { diff --git a/composer.lock b/composer.lock index 09cf164f3e..e65ab9a13c 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "hash": "a0c92aa0223617ca2730500921bdd82c", + "hash": "077d2b2548df62c8ef92871c6e52c856", "packages": [ { "name": "classpreloader/classpreloader", @@ -943,16 +943,16 @@ }, { "name": "laravel/framework", - "version": "v5.0.31", + "version": "v5.0.32", "source": { "type": "git", "url": "https://github.com/laravel/framework.git", - "reference": "db0a7400465df159ba8c6eaa954f97f50bc19687" + "reference": "85f12207cf45cc288e9e6b9b5d184aad5f08e2ca" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/laravel/framework/zipball/db0a7400465df159ba8c6eaa954f97f50bc19687", - "reference": "db0a7400465df159ba8c6eaa954f97f50bc19687", + "url": "https://api.github.com/repos/laravel/framework/zipball/85f12207cf45cc288e9e6b9b5d184aad5f08e2ca", + "reference": "85f12207cf45cc288e9e6b9b5d184aad5f08e2ca", "shasum": "" }, "require": { @@ -1065,7 +1065,7 @@ "framework", "laravel" ], - "time": "2015-05-11 22:15:00" + "time": "2015-05-29 18:56:49" }, { "name": "league/commonmark", @@ -1645,17 +1645,17 @@ }, { "name": "symfony/console", - "version": "v2.6.8", + "version": "v2.6.9", "target-dir": "Symfony/Component/Console", "source": { "type": "git", "url": "https://github.com/symfony/Console.git", - "reference": "2343f6d8026306bd330e0c987e4c102483c213e7" + "reference": "b5ec0c11a204718f2b656357f5505a8e578f30dd" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/Console/zipball/2343f6d8026306bd330e0c987e4c102483c213e7", - "reference": "2343f6d8026306bd330e0c987e4c102483c213e7", + "url": "https://api.github.com/repos/symfony/Console/zipball/b5ec0c11a204718f2b656357f5505a8e578f30dd", + "reference": "b5ec0c11a204718f2b656357f5505a8e578f30dd", "shasum": "" }, "require": { @@ -1699,11 +1699,11 @@ ], "description": "Symfony Console Component", "homepage": "https://symfony.com", - "time": "2015-05-22 14:53:08" + "time": "2015-05-29 14:42:58" }, { "name": "symfony/debug", - "version": "v2.6.8", + "version": "v2.6.9", "target-dir": "Symfony/Component/Debug", "source": { "type": "git", @@ -1764,21 +1764,20 @@ }, { "name": "symfony/event-dispatcher", - "version": "v2.6.8", - "target-dir": "Symfony/Component/EventDispatcher", + "version": "v2.7.0", "source": { "type": "git", "url": "https://github.com/symfony/EventDispatcher.git", - "reference": "672593bc4b0043a0acf91903bb75a1c82d8f2e02" + "reference": "687039686d0e923429ba6e958d0baa920cd5d458" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/EventDispatcher/zipball/672593bc4b0043a0acf91903bb75a1c82d8f2e02", - "reference": "672593bc4b0043a0acf91903bb75a1c82d8f2e02", + "url": "https://api.github.com/repos/symfony/EventDispatcher/zipball/687039686d0e923429ba6e958d0baa920cd5d458", + "reference": "687039686d0e923429ba6e958d0baa920cd5d458", "shasum": "" }, "require": { - "php": ">=5.3.3" + "php": ">=5.3.9" }, "require-dev": { "psr/log": "~1.0", @@ -1795,11 +1794,11 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "2.6-dev" + "dev-master": "2.7-dev" } }, "autoload": { - "psr-0": { + "psr-4": { "Symfony\\Component\\EventDispatcher\\": "" } }, @@ -1819,25 +1818,24 @@ ], "description": "Symfony EventDispatcher Component", "homepage": "https://symfony.com", - "time": "2015-05-02 15:18:45" + "time": "2015-05-02 15:21:08" }, { "name": "symfony/filesystem", - "version": "v2.6.8", - "target-dir": "Symfony/Component/Filesystem", + "version": "v2.7.0", "source": { "type": "git", "url": "https://github.com/symfony/Filesystem.git", - "reference": "1f8429f72a5bfa58b33fd96824bea146fc4b3f49" + "reference": "ae4551fd6d4d4f51f2e7390fbc902fbd67f3b7ba" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/Filesystem/zipball/1f8429f72a5bfa58b33fd96824bea146fc4b3f49", - "reference": "1f8429f72a5bfa58b33fd96824bea146fc4b3f49", + "url": "https://api.github.com/repos/symfony/Filesystem/zipball/ae4551fd6d4d4f51f2e7390fbc902fbd67f3b7ba", + "reference": "ae4551fd6d4d4f51f2e7390fbc902fbd67f3b7ba", "shasum": "" }, "require": { - "php": ">=5.3.3" + "php": ">=5.3.9" }, "require-dev": { "symfony/phpunit-bridge": "~2.7" @@ -1845,11 +1843,11 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "2.6-dev" + "dev-master": "2.7-dev" } }, "autoload": { - "psr-0": { + "psr-4": { "Symfony\\Component\\Filesystem\\": "" } }, @@ -1869,11 +1867,11 @@ ], "description": "Symfony Filesystem Component", "homepage": "https://symfony.com", - "time": "2015-05-15 13:32:45" + "time": "2015-05-15 13:33:16" }, { "name": "symfony/finder", - "version": "v2.6.8", + "version": "v2.6.9", "target-dir": "Symfony/Component/Finder", "source": { "type": "git", @@ -1923,7 +1921,7 @@ }, { "name": "symfony/http-foundation", - "version": "v2.6.8", + "version": "v2.6.9", "target-dir": "Symfony/Component/HttpFoundation", "source": { "type": "git", @@ -1977,17 +1975,17 @@ }, { "name": "symfony/http-kernel", - "version": "v2.6.8", + "version": "v2.6.9", "target-dir": "Symfony/Component/HttpKernel", "source": { "type": "git", "url": "https://github.com/symfony/HttpKernel.git", - "reference": "a9a6f595941fce8dddd64f4e9bf47747cf1515fc" + "reference": "7c883eb1a5d8b52b1fa6d4134b82304c6bb7007f" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/HttpKernel/zipball/a9a6f595941fce8dddd64f4e9bf47747cf1515fc", - "reference": "a9a6f595941fce8dddd64f4e9bf47747cf1515fc", + "url": "https://api.github.com/repos/symfony/HttpKernel/zipball/7c883eb1a5d8b52b1fa6d4134b82304c6bb7007f", + "reference": "7c883eb1a5d8b52b1fa6d4134b82304c6bb7007f", "shasum": "" }, "require": { @@ -2051,11 +2049,11 @@ ], "description": "Symfony HttpKernel Component", "homepage": "https://symfony.com", - "time": "2015-05-27 00:17:10" + "time": "2015-05-29 22:55:07" }, { "name": "symfony/process", - "version": "v2.6.8", + "version": "v2.6.9", "target-dir": "Symfony/Component/Process", "source": { "type": "git", @@ -2105,7 +2103,7 @@ }, { "name": "symfony/routing", - "version": "v2.6.8", + "version": "v2.6.9", "target-dir": "Symfony/Component/Routing", "source": { "type": "git", @@ -2174,7 +2172,7 @@ }, { "name": "symfony/security-core", - "version": "v2.6.8", + "version": "v2.6.9", "target-dir": "Symfony/Component/Security/Core", "source": { "type": "git", @@ -2238,17 +2236,17 @@ }, { "name": "symfony/translation", - "version": "v2.6.8", + "version": "v2.6.9", "target-dir": "Symfony/Component/Translation", "source": { "type": "git", "url": "https://github.com/symfony/Translation.git", - "reference": "d030b3d8d9699795dbf8c59e915ef879007a4483" + "reference": "89cdf3c43bc24c85dd8173dfcf5a979a95e5bd9c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/Translation/zipball/d030b3d8d9699795dbf8c59e915ef879007a4483", - "reference": "d030b3d8d9699795dbf8c59e915ef879007a4483", + "url": "https://api.github.com/repos/symfony/Translation/zipball/89cdf3c43bc24c85dd8173dfcf5a979a95e5bd9c", + "reference": "89cdf3c43bc24c85dd8173dfcf5a979a95e5bd9c", "shasum": "" }, "require": { @@ -2293,11 +2291,11 @@ ], "description": "Symfony Translation Component", "homepage": "https://symfony.com", - "time": "2015-05-22 14:37:51" + "time": "2015-05-29 14:42:58" }, { "name": "symfony/var-dumper", - "version": "v2.6.8", + "version": "v2.6.9", "target-dir": "Symfony/Component/VarDumper", "source": { "type": "git", @@ -2355,58 +2353,6 @@ ], "time": "2015-05-01 14:14:24" }, - { - "name": "twig/extensions", - "version": "v1.2.0", - "source": { - "type": "git", - "url": "https://github.com/twigphp/Twig-extensions.git", - "reference": "8cf4b9fe04077bd54fc73f4fde83347040c3b8cd" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/twigphp/Twig-extensions/zipball/8cf4b9fe04077bd54fc73f4fde83347040c3b8cd", - "reference": "8cf4b9fe04077bd54fc73f4fde83347040c3b8cd", - "shasum": "" - }, - "require": { - "twig/twig": "~1.12" - }, - "require-dev": { - "symfony/translation": "~2.3" - }, - "suggest": { - "symfony/translation": "Allow the time_diff output to be translated" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.2.x-dev" - } - }, - "autoload": { - "psr-0": { - "Twig_Extensions_": "lib/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Fabien Potencier", - "email": "fabien@symfony.com" - } - ], - "description": "Common additional features for Twig that do not directly belong in core", - "homepage": "http://twig.sensiolabs.org/doc/extensions/index.html", - "keywords": [ - "i18n", - "text" - ], - "time": "2014-10-30 14:30:03" - }, { "name": "twig/twig", "version": "v1.18.1", @@ -2466,16 +2412,16 @@ }, { "name": "vlucas/phpdotenv", - "version": "v1.1.0", + "version": "v1.1.1", "source": { "type": "git", "url": "https://github.com/vlucas/phpdotenv.git", - "reference": "732d2adb7d916c9593b9d58c3b0d9ebefead07aa" + "reference": "0cac554ce06277e33ddf9f0b7ade4b8bbf2af3fa" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/vlucas/phpdotenv/zipball/732d2adb7d916c9593b9d58c3b0d9ebefead07aa", - "reference": "732d2adb7d916c9593b9d58c3b0d9ebefead07aa", + "url": "https://api.github.com/repos/vlucas/phpdotenv/zipball/0cac554ce06277e33ddf9f0b7ade4b8bbf2af3fa", + "reference": "0cac554ce06277e33ddf9f0b7ade4b8bbf2af3fa", "shasum": "" }, "require": { @@ -2485,11 +2431,6 @@ "phpunit/phpunit": "~4.0" }, "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.0-dev" - } - }, "autoload": { "psr-0": { "Dotenv": "src/" @@ -2513,20 +2454,20 @@ "env", "environment" ], - "time": "2014-12-05 15:19:21" + "time": "2015-05-30 15:59:26" }, { "name": "watson/validating", - "version": "1.0.2", + "version": "1.0.3", "source": { "type": "git", "url": "https://github.com/dwightwatson/validating.git", - "reference": "47320813a45cc35384e72364484d54fe44dcd3fb" + "reference": "c32912f760b456c043657951683ed6c468ab83e7" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/dwightwatson/validating/zipball/47320813a45cc35384e72364484d54fe44dcd3fb", - "reference": "47320813a45cc35384e72364484d54fe44dcd3fb", + "url": "https://api.github.com/repos/dwightwatson/validating/zipball/c32912f760b456c043657951683ed6c468ab83e7", + "reference": "c32912f760b456c043657951683ed6c468ab83e7", "shasum": "" }, "require": { @@ -2568,7 +2509,7 @@ "laravel", "validation" ], - "time": "2015-05-23 00:03:54" + "time": "2015-06-03 02:25:38" }, { "name": "zizaco/entrust", @@ -3322,16 +3263,16 @@ }, { "name": "phpspec/phpspec", - "version": "2.2.0", + "version": "2.2.1", "source": { "type": "git", "url": "https://github.com/phpspec/phpspec.git", - "reference": "9727d75919a00455433e867565bc022f0b985a39" + "reference": "e9a40577323e67f1de2e214abf32976a0352d8f8" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpspec/phpspec/zipball/9727d75919a00455433e867565bc022f0b985a39", - "reference": "9727d75919a00455433e867565bc022f0b985a39", + "url": "https://api.github.com/repos/phpspec/phpspec/zipball/e9a40577323e67f1de2e214abf32976a0352d8f8", + "reference": "e9a40577323e67f1de2e214abf32976a0352d8f8", "shasum": "" }, "require": { @@ -3396,7 +3337,7 @@ "testing", "tests" ], - "time": "2015-04-18 16:22:51" + "time": "2015-05-30 15:21:40" }, { "name": "phpspec/prophecy", @@ -3460,16 +3401,16 @@ }, { "name": "phpunit/php-code-coverage", - "version": "2.0.17", + "version": "2.1.3", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-code-coverage.git", - "reference": "c4e8e7725e351184a76544634855b8a9c405a6e3" + "reference": "28a6b34e91d789b2608072ab3c82eaae7cdb973c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/c4e8e7725e351184a76544634855b8a9c405a6e3", - "reference": "c4e8e7725e351184a76544634855b8a9c405a6e3", + "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/28a6b34e91d789b2608072ab3c82eaae7cdb973c", + "reference": "28a6b34e91d789b2608072ab3c82eaae7cdb973c", "shasum": "" }, "require": { @@ -3492,7 +3433,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "2.0.x-dev" + "dev-master": "2.1.x-dev" } }, "autoload": { @@ -3518,7 +3459,7 @@ "testing", "xunit" ], - "time": "2015-05-25 05:11:59" + "time": "2015-06-03 07:01:01" }, { "name": "phpunit/php-file-iterator", @@ -3706,16 +3647,16 @@ }, { "name": "phpunit/phpunit", - "version": "4.6.7", + "version": "4.6.10", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "57bf06dd4eebe2a5ced79a8de71509e7d5c18b25" + "reference": "7b5fe98b28302a8b25693b2298bca74463336975" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/57bf06dd4eebe2a5ced79a8de71509e7d5c18b25", - "reference": "57bf06dd4eebe2a5ced79a8de71509e7d5c18b25", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/7b5fe98b28302a8b25693b2298bca74463336975", + "reference": "7b5fe98b28302a8b25693b2298bca74463336975", "shasum": "" }, "require": { @@ -3774,20 +3715,20 @@ "testing", "xunit" ], - "time": "2015-05-25 05:18:18" + "time": "2015-06-03 05:03:30" }, { "name": "phpunit/phpunit-mock-objects", - "version": "2.3.1", + "version": "2.3.3", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit-mock-objects.git", - "reference": "74ffb87f527f24616f72460e54b595f508dccb5c" + "reference": "253c005852591fd547fc18cd5b7b43a1ec82d8f7" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit-mock-objects/zipball/74ffb87f527f24616f72460e54b595f508dccb5c", - "reference": "74ffb87f527f24616f72460e54b595f508dccb5c", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit-mock-objects/zipball/253c005852591fd547fc18cd5b7b43a1ec82d8f7", + "reference": "253c005852591fd547fc18cd5b7b43a1ec82d8f7", "shasum": "" }, "require": { @@ -3829,7 +3770,7 @@ "mock", "xunit" ], - "time": "2015-04-02 05:36:41" + "time": "2015-05-29 05:19:18" }, { "name": "satooshi/php-coveralls", @@ -4272,21 +4213,20 @@ }, { "name": "symfony/class-loader", - "version": "v2.6.8", - "target-dir": "Symfony/Component/ClassLoader", + "version": "v2.7.0", "source": { "type": "git", "url": "https://github.com/symfony/ClassLoader.git", - "reference": "abf5632a31402ae6ac19cd00683faf603046440a" + "reference": "fa19598cb708b92d983b34aae313f57c217f9386" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/ClassLoader/zipball/abf5632a31402ae6ac19cd00683faf603046440a", - "reference": "abf5632a31402ae6ac19cd00683faf603046440a", + "url": "https://api.github.com/repos/symfony/ClassLoader/zipball/fa19598cb708b92d983b34aae313f57c217f9386", + "reference": "fa19598cb708b92d983b34aae313f57c217f9386", "shasum": "" }, "require": { - "php": ">=5.3.3" + "php": ">=5.3.9" }, "require-dev": { "symfony/finder": "~2.0,>=2.0.5", @@ -4295,11 +4235,11 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "2.6-dev" + "dev-master": "2.7-dev" } }, "autoload": { - "psr-0": { + "psr-4": { "Symfony\\Component\\ClassLoader\\": "" } }, @@ -4319,25 +4259,24 @@ ], "description": "Symfony ClassLoader Component", "homepage": "https://symfony.com", - "time": "2015-05-15 13:32:45" + "time": "2015-05-15 13:33:16" }, { "name": "symfony/config", - "version": "v2.6.8", - "target-dir": "Symfony/Component/Config", + "version": "v2.7.0", "source": { "type": "git", "url": "https://github.com/symfony/Config.git", - "reference": "2696c5bc7c31485a482c10865d713de9fcc7aa31" + "reference": "537e9912063e66aa70cbcddd7d6e6e8db61d98e4" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/Config/zipball/2696c5bc7c31485a482c10865d713de9fcc7aa31", - "reference": "2696c5bc7c31485a482c10865d713de9fcc7aa31", + "url": "https://api.github.com/repos/symfony/Config/zipball/537e9912063e66aa70cbcddd7d6e6e8db61d98e4", + "reference": "537e9912063e66aa70cbcddd7d6e6e8db61d98e4", "shasum": "" }, "require": { - "php": ">=5.3.3", + "php": ">=5.3.9", "symfony/filesystem": "~2.3" }, "require-dev": { @@ -4346,11 +4285,11 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "2.6-dev" + "dev-master": "2.7-dev" } }, "autoload": { - "psr-0": { + "psr-4": { "Symfony\\Component\\Config\\": "" } }, @@ -4370,25 +4309,24 @@ ], "description": "Symfony Config Component", "homepage": "https://symfony.com", - "time": "2015-05-15 13:32:45" + "time": "2015-05-15 13:33:16" }, { "name": "symfony/stopwatch", - "version": "v2.6.8", - "target-dir": "Symfony/Component/Stopwatch", + "version": "v2.7.0", "source": { "type": "git", "url": "https://github.com/symfony/Stopwatch.git", - "reference": "b470f87c69837cb71115f1fa720388bb19b63635" + "reference": "7702945bceddc0e1f744519abb8a2baeb94bd5ce" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/Stopwatch/zipball/b470f87c69837cb71115f1fa720388bb19b63635", - "reference": "b470f87c69837cb71115f1fa720388bb19b63635", + "url": "https://api.github.com/repos/symfony/Stopwatch/zipball/7702945bceddc0e1f744519abb8a2baeb94bd5ce", + "reference": "7702945bceddc0e1f744519abb8a2baeb94bd5ce", "shasum": "" }, "require": { - "php": ">=5.3.3" + "php": ">=5.3.9" }, "require-dev": { "symfony/phpunit-bridge": "~2.7" @@ -4396,11 +4334,11 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "2.6-dev" + "dev-master": "2.7-dev" } }, "autoload": { - "psr-0": { + "psr-4": { "Symfony\\Component\\Stopwatch\\": "" } }, @@ -4420,25 +4358,24 @@ ], "description": "Symfony Stopwatch Component", "homepage": "https://symfony.com", - "time": "2015-05-02 15:18:45" + "time": "2015-05-02 15:21:08" }, { "name": "symfony/yaml", - "version": "v2.6.8", - "target-dir": "Symfony/Component/Yaml", + "version": "v2.7.0", "source": { "type": "git", "url": "https://github.com/symfony/Yaml.git", - "reference": "f157ab074e453ecd4c0fa775f721f6e67a99d9e2" + "reference": "4a29a5248aed4fb45f626a7bbbd330291492f5c3" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/Yaml/zipball/f157ab074e453ecd4c0fa775f721f6e67a99d9e2", - "reference": "f157ab074e453ecd4c0fa775f721f6e67a99d9e2", + "url": "https://api.github.com/repos/symfony/Yaml/zipball/4a29a5248aed4fb45f626a7bbbd330291492f5c3", + "reference": "4a29a5248aed4fb45f626a7bbbd330291492f5c3", "shasum": "" }, "require": { - "php": ">=5.3.3" + "php": ">=5.3.9" }, "require-dev": { "symfony/phpunit-bridge": "~2.7" @@ -4446,11 +4383,11 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "2.6-dev" + "dev-master": "2.7-dev" } }, "autoload": { - "psr-0": { + "psr-4": { "Symfony\\Component\\Yaml\\": "" } }, @@ -4470,7 +4407,7 @@ ], "description": "Symfony Yaml Component", "homepage": "https://symfony.com", - "time": "2015-05-02 15:18:45" + "time": "2015-05-02 15:21:08" } ], "aliases": [], From 409ec2e0867cf50f36f4d516de863dcf1d32cab9 Mon Sep 17 00:00:00 2001 From: James Cole Date: Wed, 3 Jun 2015 21:15:52 +0200 Subject: [PATCH 14/47] Should fix tests. --- .../Controllers/Chart/AccountController.php | 30 ++++-------- app/Http/Controllers/Chart/BillController.php | 18 +++----- .../Controllers/Chart/BudgetController.php | 37 +++++---------- .../Controllers/Chart/CategoryController.php | 10 ++-- app/Http/Controllers/HomeController.php | 10 ---- app/Http/Controllers/JsonController.php | 34 +++++--------- app/Http/Middleware/Reminders.php | 7 ++- app/Models/TransactionJournal.php | 6 +-- .../Account/AccountRepository.php | 19 ++++---- app/Support/CacheProperties.php | 46 +++++++++++++++---- app/Support/Steam.php | 6 +-- app/Support/Twig/Journal.php | 6 +-- tests/controllers/AccountControllerTest.php | 6 +-- tests/controllers/BudgetControllerTest.php | 6 +++ tests/controllers/HomeControllerTest.php | 4 ++ .../controllers/PreferencesControllerTest.php | 8 ++++ .../charts/ChartBillControllerTest.php | 8 ++++ tests/helpers/ReportHelperTest.php | 3 ++ tests/models/TransactionJournalModelTest.php | 10 ++++ tests/repositories/BillRepositoryTest.php | 3 ++ tests/repositories/JournalRepositoryTest.php | 6 +++ 21 files changed, 151 insertions(+), 132 deletions(-) diff --git a/app/Http/Controllers/Chart/AccountController.php b/app/Http/Controllers/Chart/AccountController.php index ae14e368f0..bd862d3012 100644 --- a/app/Http/Controllers/Chart/AccountController.php +++ b/app/Http/Controllers/Chart/AccountController.php @@ -48,14 +48,10 @@ class AccountController extends Controller $chartProperties->addProperty($end); $chartProperties->addProperty('all'); $chartProperties->addProperty('accounts'); - $md5 = $chartProperties->md5(); - - - if (Cache::has($md5)) { - Log::debug('Successfully returned cached chart [' . $md5 . '].'); - - return Response::json(Cache::get($md5)); + if ($chartProperties->has()) { + return Response::json($chartProperties->get()); } + $md5 = $chartProperties->getMd5(); $chart->addColumn(trans('firefly.dayOfMonth'), 'date'); @@ -123,14 +119,10 @@ class AccountController extends Controller $chartProperties->addProperty($end); $chartProperties->addProperty('frontpage'); $chartProperties->addProperty('accounts'); - $md5 = $chartProperties->md5(); - - - if (Cache::has($md5)) { - Log::debug('Successfully returned cached chart [' . $md5 . '].'); - - return Response::json(Cache::get($md5)); + if ($chartProperties->has()) { + return Response::json($chartProperties->get()); } + $md5 = $chartProperties->getMd5(); $index = 1; @@ -188,14 +180,10 @@ class AccountController extends Controller $chartProperties->addProperty('frontpage'); $chartProperties->addProperty('single'); $chartProperties->addProperty($account->id); - $md5 = $chartProperties->md5(); - - - if (Cache::has($md5)) { - Log::debug('Successfully returned cached chart [' . $md5 . '].'); - - return Response::json(Cache::get($md5)); + if ($chartProperties->has()) { + return Response::json($chartProperties->get()); } + $md5 = $chartProperties->getMd5(); diff --git a/app/Http/Controllers/Chart/BillController.php b/app/Http/Controllers/Chart/BillController.php index d79c879350..7950e294ed 100644 --- a/app/Http/Controllers/Chart/BillController.php +++ b/app/Http/Controllers/Chart/BillController.php @@ -44,13 +44,10 @@ class BillController extends Controller $chartProperties->addProperty('single'); $chartProperties->addProperty('bill'); $chartProperties->addProperty($bill->id); - $md5 = $chartProperties->md5(); - - if (Cache::has($md5)) { - Log::debug('Successfully returned cached chart [' . $md5 . '].'); - - return Response::json(Cache::get($md5)); + if ($chartProperties->has()) { + return Response::json($chartProperties->get()); } + $md5 = $chartProperties->getMd5(); // get first transaction or today for start: $results = $repository->getJournals($bill); @@ -92,13 +89,10 @@ class BillController extends Controller $chartProperties->addProperty($end); $chartProperties->addProperty('bills'); $chartProperties->addProperty('frontpage'); - $md5 = $chartProperties->md5(); - - if (Cache::has($md5)) { - Log::debug('Successfully returned cached chart [' . $md5 . '].'); - - return Response::json(Cache::get($md5)); + if ($chartProperties->has()) { + return Response::json($chartProperties->get()); } + $md5 = $chartProperties->getMd5(); $bills = $repository->getActiveBills(); $paid = new Collection; // journals. diff --git a/app/Http/Controllers/Chart/BudgetController.php b/app/Http/Controllers/Chart/BudgetController.php index 9627a53c07..731f87b4de 100644 --- a/app/Http/Controllers/Chart/BudgetController.php +++ b/app/Http/Controllers/Chart/BudgetController.php @@ -50,13 +50,10 @@ class BudgetController extends Controller $chartProperties->addProperty($last); $chartProperties->addProperty('budget'); $chartProperties->addProperty('budget'); - $md5 = $chartProperties->md5(); - - if (Cache::has($md5)) { - Log::debug('Successfully returned cached chart [' . $md5 . '].'); - - return Response::json(Cache::get($md5)); + if ($chartProperties->has()) { + return Response::json($chartProperties->get()); } + $md5 = $chartProperties->getMd5(); while ($first < $last) { @@ -100,13 +97,10 @@ class BudgetController extends Controller $chartProperties->addProperty('limit'); $chartProperties->addProperty($budget->id); $chartProperties->addProperty($repetition->id); - $md5 = $chartProperties->md5(); - - if (Cache::has($md5)) { - Log::debug('Successfully returned cached chart [' . $md5 . '].'); - - return Response::json(Cache::get($md5)); + if ($chartProperties->has()) { + return Response::json($chartProperties->get()); } + $md5 = $chartProperties->getMd5(); $chart->addColumn(trans('firefly.day'), 'date'); $chart->addColumn(trans('firefly.left'), 'number'); @@ -158,13 +152,10 @@ class BudgetController extends Controller $chartProperties->addProperty($end); $chartProperties->addProperty('budget'); $chartProperties->addProperty('all'); - $md5 = $chartProperties->md5(); - - if (Cache::has($md5)) { - Log::debug('Successfully returned cached chart [' . $md5 . '].'); - - return Response::json(Cache::get($md5)); + if ($chartProperties->has()) { + return Response::json($chartProperties->get()); } + $md5 = $chartProperties->getMd5(); /** @var Budget $budget */ @@ -232,14 +223,10 @@ class BudgetController extends Controller $chartProperties->addProperty($end); $chartProperties->addProperty('budget'); $chartProperties->addProperty('year'); - $md5 = $chartProperties->md5(); - - - if (Cache::has($md5)) { - Log::debug('Successfully returned cached chart [' . $md5 . '].'); - - return Response::json(Cache::get($md5)); + if ($chartProperties->has()) { + return Response::json($chartProperties->get()); } + $md5 = $chartProperties->getMd5(); // add columns: $chart->addColumn(trans('firefly.month'), 'date'); diff --git a/app/Http/Controllers/Chart/CategoryController.php b/app/Http/Controllers/Chart/CategoryController.php index b86eb143f3..5d0a57b031 100644 --- a/app/Http/Controllers/Chart/CategoryController.php +++ b/app/Http/Controllers/Chart/CategoryController.php @@ -85,14 +85,10 @@ class CategoryController extends Controller $chartProperties->addProperty($end); $chartProperties->addProperty('category'); $chartProperties->addProperty('frontpage'); - $md5 = $chartProperties->md5(); - - - if (Cache::has($md5)) { - Log::debug('Successfully returned cached chart [' . $md5 . '].'); - - return Response::json(Cache::get($md5)); + if ($chartProperties->has()) { + return Response::json($chartProperties->get()); } + $md5 = $chartProperties->getMd5(); $set = $repository->getCategoriesAndExpensesCorrected($start, $end); diff --git a/app/Http/Controllers/HomeController.php b/app/Http/Controllers/HomeController.php index 7ffa3d9b4e..17472183d5 100644 --- a/app/Http/Controllers/HomeController.php +++ b/app/Http/Controllers/HomeController.php @@ -41,16 +41,6 @@ class HomeController extends Controller { Session::clear(); - // encrypt transaction journal description - $set = TransactionJournal::where('encrypted', 0)->take(100)->get(); - /** @var TransactionJournal $entry */ - foreach ($set as $entry) { - $description = $entry->description; - $entry->description = $description; - $entry->save(); - } - unset($set, $entry, $description); - return Redirect::route('index'); } diff --git a/app/Http/Controllers/JsonController.php b/app/Http/Controllers/JsonController.php index 1908ed7dcf..9d0295411a 100644 --- a/app/Http/Controllers/JsonController.php +++ b/app/Http/Controllers/JsonController.php @@ -13,7 +13,6 @@ use FireflyIII\Repositories\Journal\JournalRepositoryInterface; use FireflyIII\Repositories\Tag\TagRepositoryInterface; use FireflyIII\Support\CacheProperties; use Illuminate\Support\Collection; -use Log; use Response; use Session; use Steam; @@ -44,12 +43,10 @@ class JsonController extends Controller $prop->addProperty($start); $prop->addProperty($end); $prop->addProperty('box-bills-paid'); - $md5 = $prop->md5(); - if (Cache::has($md5)) { - Log::debug('Successfully returned cached box bills-paid [' . $md5 . ']'); - - return Response::json(Cache::get($md5)); + if ($prop->has()) { + return Response::json($prop->get()); } + $md5 = $prop->getMd5(); $amount = 0; @@ -100,12 +97,10 @@ class JsonController extends Controller $prop->addProperty($start); $prop->addProperty($end); $prop->addProperty('box-bills-unpaid'); - $md5 = $prop->md5(); - if (Cache::has($md5)) { - Log::debug('Successfully returned cached box bills-unpaid [' . $md5 . ']'); - - return Response::json(Cache::get($md5)); + if ($prop->has()) { + return Response::json($prop->get()); } + $md5 = $prop->getMd5(); $bills = $repository->getActiveBills(); $unpaid = new Collection; // bills @@ -162,13 +157,10 @@ class JsonController extends Controller $prop->addProperty($start); $prop->addProperty($end); $prop->addProperty('box-in'); - $md5 = $prop->md5(); - if (Cache::has($md5)) { - Log::debug('Successfully returned cached box in [' . $md5 . ']'); - - return Response::json(Cache::get($md5)); + if ($prop->has()) { + return Response::json($prop->get()); } - + $md5 = $prop->getMd5(); $amount = $reportQuery->incomeInPeriodCorrected($start, $end, true)->sum('amount'); @@ -194,12 +186,10 @@ class JsonController extends Controller $prop->addProperty($start); $prop->addProperty($end); $prop->addProperty('box-out'); - $md5 = $prop->md5(); - if (Cache::has($md5)) { - Log::debug('Successfully returned cached box out [' . $md5 . ']'); - - return Response::json(Cache::get($md5)); + if ($prop->has()) { + return Response::json($prop->get()); } + $md5 = $prop->getMd5(); $amount = $reportQuery->expenseInPeriodCorrected($start, $end, true)->sum('amount'); diff --git a/app/Http/Middleware/Reminders.php b/app/Http/Middleware/Reminders.php index eb161a4123..5f663e84c4 100644 --- a/app/Http/Middleware/Reminders.php +++ b/app/Http/Middleware/Reminders.php @@ -57,14 +57,13 @@ class Reminders $properties = new CacheProperties; $properties->addProperty('reminders'); - $md5 = $properties->md5(); - - if (Cache::has($md5)) { - $reminders = Cache::get($md5); + if ($properties->has()) { + $reminders = $properties->get(); View::share('reminders', $reminders); return $next($request); } + $md5 = $properties->getMd5(); $piggyBanks = $this->auth->user()->piggyBanks()->where('remind_me', 1)->get(); diff --git a/app/Models/TransactionJournal.php b/app/Models/TransactionJournal.php index b4fc946b3e..60f76d1cbe 100644 --- a/app/Models/TransactionJournal.php +++ b/app/Models/TransactionJournal.php @@ -139,10 +139,10 @@ class TransactionJournal extends Model $prop = new CacheProperties(); $prop->addProperty($this->id); $prop->addProperty('amount'); - $md5 = $prop->md5(); - if (Cache::has($md5)) { - return Cache::get($md5); + if ($prop->has()) { + return $prop->get(); } + $md5 = $prop->getMd5(); $amount = '0'; diff --git a/app/Repositories/Account/AccountRepository.php b/app/Repositories/Account/AccountRepository.php index 02559a82d9..352a89b756 100644 --- a/app/Repositories/Account/AccountRepository.php +++ b/app/Repositories/Account/AccountRepository.php @@ -114,10 +114,10 @@ class AccountRepository implements AccountRepositoryInterface $cache = new CacheProperties(); $cache->addProperty($preference->data); $cache->addProperty('frontPageaccounts'); - $md5 = $cache->md5(); - if (Cache::has($md5)) { - return Cache::get($md5); + if ($cache->has()) { + return $cache->get(); } + $md5 = $cache->getMd5(); if ($preference->data == []) { @@ -148,10 +148,10 @@ class AccountRepository implements AccountRepositoryInterface $prop->addProperty($account->id); $prop->addProperty($start); $prop->addProperty($end); - $md5 = $prop->md5(); - if(Cache::has($md5)) { - return Cache::get($md5); + if ($prop->has()) { + return $prop->get(); } + $md5 = $prop->getMd5(); $set = Auth::user() ->transactionjournals() @@ -167,6 +167,7 @@ class AccountRepository implements AccountRepositoryInterface ->take(10) ->get(['transaction_journals.*', 'transaction_currencies.symbol', 'transaction_types.type']); Cache::forever($md5, $set); + return $set; } @@ -234,10 +235,10 @@ class AccountRepository implements AccountRepositoryInterface $cache = new CacheProperties; $cache->addProperty($ids); $cache->addProperty('piggyAccounts'); - $md5 = $cache->md5(); - if (Cache::has($md5)) { - return Cache::get($md5); + if ($cache->has()) { + return $cache->get(); } + $md5 = $cache->getMd5(); $ids = array_unique($ids); if (count($ids) > 0) { diff --git a/app/Support/CacheProperties.php b/app/Support/CacheProperties.php index 699d7e9a26..f7f7018b44 100644 --- a/app/Support/CacheProperties.php +++ b/app/Support/CacheProperties.php @@ -4,6 +4,7 @@ namespace FireflyIII\Support; use Auth; +use Cache; use Carbon\Carbon; use Illuminate\Database\Eloquent\Collection as EloquentCollection; use Illuminate\Support\Collection; @@ -17,6 +18,8 @@ use Preferences as Prefs; class CacheProperties { + /** @var string */ + protected $md5 = ''; /** @var Collection */ protected $properties; @@ -38,39 +41,62 @@ class CacheProperties $this->properties->push($property); } + /** + * @return mixed + */ + public function get() + { + return Cache::get($this->md5); + } /** * @return string */ - public function md5() + public function getMd5() + { + return $this->md5; + } + + /** + * @return bool + */ + public function has() + { + $this->md5(); + + return Cache::has($this->md5); + } + + /** + * @return void + */ + private function md5() { - $string = ''; - //Log::debug('--- building string ---'); foreach ($this->properties as $property) { if ($property instanceof Collection || $property instanceof EloquentCollection) { - $string .= print_r($property->toArray(), true); + $this->md5 .= print_r($property->toArray(), true); continue; } if ($property instanceof Carbon) { - $string .= $property->toRfc3339String(); + $this->md5 .= $property->toRfc3339String(); continue; } if (is_array($property)) { - $string .= print_r($property, true); + $this->md5 .= print_r($property, true); continue; } if (is_object($property)) { - $string .= $property->__toString(); + $this->md5 .= $property->__toString(); } if (is_array($property)) { - $string .= print_r($property, true); + $this->md5 .= print_r($property, true); } - $string .= (string)$property; + $this->md5 .= (string)$property; } - return md5($string); + $this->md5 = md5($this->md5); } } \ No newline at end of file diff --git a/app/Support/Steam.php b/app/Support/Steam.php index 6e61e3cff5..5e3804864b 100644 --- a/app/Support/Steam.php +++ b/app/Support/Steam.php @@ -30,10 +30,10 @@ class Steam $properties->addProperty('balance'); $properties->addProperty($date); $properties->addProperty($ignoreVirtualBalance); - $md5 = $properties->md5(); - if (Cache::has($md5)) { - return Cache::get($md5); + if ($properties->has()) { + return $properties->get(); } + $md5 = $properties->getMd5(); // find the first known transaction on this account: diff --git a/app/Support/Twig/Journal.php b/app/Support/Twig/Journal.php index ba03775a5d..7e53787fde 100644 --- a/app/Support/Twig/Journal.php +++ b/app/Support/Twig/Journal.php @@ -33,10 +33,10 @@ class Journal extends Twig_Extension $prop = new CacheProperties(); $prop->addProperty($journal->id); $prop->addProperty('typeIcon'); - $md5 = $prop->md5(); - if (Cache::has($md5)) { - return Cache::get($md5); + if ($prop->has()) { + return $prop->get(); } + $md5 = $prop->getMd5(); $type = $journal->transactionType->type; diff --git a/tests/controllers/AccountControllerTest.php b/tests/controllers/AccountControllerTest.php index 0ff00f50ba..d1b548e774 100644 --- a/tests/controllers/AccountControllerTest.php +++ b/tests/controllers/AccountControllerTest.php @@ -1,9 +1,6 @@ once()->andReturn($currency); Amount::shouldReceive('getAllCurrencies')->once()->andReturn([$currency]); Amount::shouldReceive('getCurrencyCode')->andReturn('X'); + $lastActivity = FactoryMuffin::create('FireflyIII\Models\Preference'); + $lastActivity->data = microtime(); + Preferences::shouldReceive('lastActivity')->andReturn($lastActivity); $this->call('GET', '/accounts/create/asset'); $this->assertResponseOk(); diff --git a/tests/controllers/BudgetControllerTest.php b/tests/controllers/BudgetControllerTest.php index 01f8b7c9d4..84cf4eda92 100644 --- a/tests/controllers/BudgetControllerTest.php +++ b/tests/controllers/BudgetControllerTest.php @@ -194,6 +194,9 @@ class BudgetControllerTest extends TestCase $date = Carbon::now()->startOfMonth()->format('FY'); Preferences::shouldReceive('set')->once()->withArgs(['budgetIncomeTotal' . $date, 1001]); Preferences::shouldReceive('mark')->once()->andReturn(true); + $lastActivity = FactoryMuffin::create('FireflyIII\Models\Preference'); + $lastActivity->data = microtime(); + Preferences::shouldReceive('lastActivity')->andReturn($lastActivity); // language preference: $language = FactoryMuffin::create('FireflyIII\Models\Preference'); @@ -386,6 +389,9 @@ class BudgetControllerTest extends TestCase Amount::shouldReceive('format')->andReturn('xx'); Amount::shouldReceive('getCurrencyCode')->andReturn('X'); Amount::shouldReceive('getCurrencySymbol')->andReturn('X'); + $lastActivity = FactoryMuffin::create('FireflyIII\Models\Preference'); + $lastActivity->data = microtime(); + Preferences::shouldReceive('lastActivity')->andReturn($lastActivity); // language preference: $language = FactoryMuffin::create('FireflyIII\Models\Preference'); diff --git a/tests/controllers/HomeControllerTest.php b/tests/controllers/HomeControllerTest.php index 71444d6fef..4ec8a289d1 100644 --- a/tests/controllers/HomeControllerTest.php +++ b/tests/controllers/HomeControllerTest.php @@ -108,6 +108,10 @@ class HomeControllerTest extends TestCase $language->save(); Preferences::shouldReceive('get')->withAnyArgs()->andReturn($language); + $lastActivity = FactoryMuffin::create('FireflyIII\Models\Preference'); + $lastActivity->data = microtime(); + Preferences::shouldReceive('lastActivity')->andReturn($lastActivity); + Amount::shouldReceive('getCurrencyCode')->andReturn('EUR'); Amount::shouldReceive('format')->andReturn('xxx'); diff --git a/tests/controllers/PreferencesControllerTest.php b/tests/controllers/PreferencesControllerTest.php index af3b9d1ab9..93ec1fa3ec 100644 --- a/tests/controllers/PreferencesControllerTest.php +++ b/tests/controllers/PreferencesControllerTest.php @@ -62,6 +62,10 @@ class PreferencesControllerTest extends TestCase Amount::shouldReceive('getAllCurrencies')->andReturn(new Collection); Amount::shouldReceive('getDefaultCurrency')->andReturn($currency); + $lastActivity = FactoryMuffin::create('FireflyIII\Models\Preference'); + $lastActivity->data = microtime(); + Preferences::shouldReceive('lastActivity')->andReturn($lastActivity); + // language preference: $language = FactoryMuffin::create('FireflyIII\Models\Preference'); $language->data = 'en'; @@ -105,6 +109,10 @@ class PreferencesControllerTest extends TestCase $language->save(); Preferences::shouldReceive('get')->withAnyArgs()->andReturn($language); + $lastActivity = FactoryMuffin::create('FireflyIII\Models\Preference'); + $lastActivity->data = microtime(); + Preferences::shouldReceive('lastActivity')->andReturn($lastActivity); + $this->call('POST', '/preferences', $data); $this->assertResponseStatus(302); diff --git a/tests/controllers/charts/ChartBillControllerTest.php b/tests/controllers/charts/ChartBillControllerTest.php index 884c4627ff..b7f3ec3f9d 100644 --- a/tests/controllers/charts/ChartBillControllerTest.php +++ b/tests/controllers/charts/ChartBillControllerTest.php @@ -60,6 +60,14 @@ class ChartBillControllerTest extends TestCase $repository->shouldReceive('createFakeBill')->andReturn($bills->first()); Steam::shouldReceive('balance')->andReturn(-10, 0); + $lastActivity = FactoryMuffin::create('FireflyIII\Models\Preference'); + $lastActivity->data = microtime(); + Preferences::shouldReceive('lastActivity')->andReturn($lastActivity); + + $language = FactoryMuffin::create('FireflyIII\Models\Preference'); + $language->data = 'en'; + Preferences::shouldReceive('get')->withArgs(['language', 'en'])->andReturn($language); + $this->call('GET', '/chart/bill/frontpage'); $this->assertResponseOk(); diff --git a/tests/helpers/ReportHelperTest.php b/tests/helpers/ReportHelperTest.php index 3598c959eb..7adfaddf77 100644 --- a/tests/helpers/ReportHelperTest.php +++ b/tests/helpers/ReportHelperTest.php @@ -111,6 +111,9 @@ class ReportHelperTest extends TestCase */ public function testGetBillReport() { + $user = FactoryMuffin::create('FireflyIII\User'); + $this->be($user); + // factory! $set = new Collection; $journals = new Collection; diff --git a/tests/models/TransactionJournalModelTest.php b/tests/models/TransactionJournalModelTest.php index d05f285529..26c98d80be 100644 --- a/tests/models/TransactionJournalModelTest.php +++ b/tests/models/TransactionJournalModelTest.php @@ -62,6 +62,8 @@ class TransactionJournalModelTest extends TestCase */ public function testGetAmountAttributeAdvancePayment() { + $user = FactoryMuffin::create('FireflyIII\User'); + $this->be($user); // make types: $withdrawalType = FactoryMuffin::create('FireflyIII\Models\TransactionType'); $depositType = FactoryMuffin::create('FireflyIII\Models\TransactionType'); @@ -120,6 +122,9 @@ class TransactionJournalModelTest extends TestCase */ public function testGetAmountAttributeBalancingAct() { + $user = FactoryMuffin::create('FireflyIII\User'); + $this->be($user); + // make types: $withdrawalType = FactoryMuffin::create('FireflyIII\Models\TransactionType'); FactoryMuffin::create('FireflyIII\Models\TransactionType'); @@ -177,6 +182,8 @@ class TransactionJournalModelTest extends TestCase */ public function testGetAmountAttributeNoTags() { + $user = FactoryMuffin::create('FireflyIII\User'); + $this->be($user); $journal = FactoryMuffin::create('FireflyIII\Models\TransactionJournal'); $journal->transactions[0]->amount = 123.45; @@ -194,6 +201,9 @@ class TransactionJournalModelTest extends TestCase */ public function testGetAmountAttributeTag() { + $user = FactoryMuffin::create('FireflyIII\User'); + $this->be($user); + // has a normal tag, but nothing special. // make tag $tag = FactoryMuffin::create('FireflyIII\Models\Tag'); diff --git a/tests/repositories/BillRepositoryTest.php b/tests/repositories/BillRepositoryTest.php index 5c1de9fe92..2e22d58e7a 100644 --- a/tests/repositories/BillRepositoryTest.php +++ b/tests/repositories/BillRepositoryTest.php @@ -38,6 +38,9 @@ class BillRepositoryTest extends TestCase public function testBillPaymentsInRange() { + $user = FactoryMuffin::create('FireflyIII\User'); + $this->be($user); + $bill = FactoryMuffin::create('FireflyIII\Models\Bill'); $start = Carbon::now()->startOfMonth(); $end = Carbon::now()->endOfMonth(); diff --git a/tests/repositories/JournalRepositoryTest.php b/tests/repositories/JournalRepositoryTest.php index 375b06e70d..e0bc5443b5 100644 --- a/tests/repositories/JournalRepositoryTest.php +++ b/tests/repositories/JournalRepositoryTest.php @@ -446,6 +446,9 @@ class JournalRepositoryTest extends TestCase */ public function testUpdate() { + $user = FactoryMuffin::create('FireflyIII\User'); + $this->be($user); + for ($i = 0; $i < 4; $i++) { FactoryMuffin::create('FireflyIII\Models\AccountType'); } @@ -504,6 +507,9 @@ class JournalRepositoryTest extends TestCase */ public function testUpdateNoTags() { + $user = FactoryMuffin::create('FireflyIII\User'); + $this->be($user); + for ($i = 0; $i < 4; $i++) { FactoryMuffin::create('FireflyIII\Models\AccountType'); } From cc7c2e952cd137279e9263479b7222f5c38ff256 Mon Sep 17 00:00:00 2001 From: James Cole Date: Wed, 3 Jun 2015 21:25:11 +0200 Subject: [PATCH 15/47] Code cleanup [skip ci] --- app/Helpers/Collection/BalanceLine.php | 1 + app/Helpers/Collection/Bill.php | 2 +- app/Helpers/Collection/Category.php | 2 +- app/Helpers/Collection/Expense.php | 2 +- app/Helpers/Collection/Income.php | 2 +- app/Helpers/Report/ReportHelper.php | 3 +- app/Helpers/Report/ReportHelperInterface.php | 2 +- app/Helpers/Report/ReportQuery.php | 100 ++++++++--------- app/Http/Controllers/AccountController.php | 11 +- app/Http/Controllers/Auth/AuthController.php | 2 +- app/Http/Controllers/BillController.php | 2 +- app/Http/Controllers/BudgetController.php | 2 +- app/Http/Controllers/CategoryController.php | 4 +- .../Controllers/Chart/AccountController.php | 58 +++++----- app/Http/Controllers/Chart/BillController.php | 39 ++++--- .../Controllers/Chart/BudgetController.php | 74 ++++++------- .../Controllers/Chart/CategoryController.php | 23 ++-- app/Http/Controllers/HomeController.php | 21 ++-- app/Http/Controllers/JsonController.php | 62 +++++------ app/Http/Controllers/NewUserController.php | 2 +- app/Http/Controllers/PiggyBankController.php | 10 +- .../Controllers/TransactionController.php | 2 +- app/Http/Middleware/Authenticate.php | 3 +- app/Http/Middleware/Reminders.php | 13 +-- app/Http/breadcrumbs.php | 102 +++++++++--------- app/Models/Account.php | 42 ++++---- app/Models/AccountMeta.php | 16 +-- app/Models/AccountType.php | 12 +-- app/Models/Bill.php | 44 ++++---- app/Models/Budget.php | 22 ++-- app/Models/BudgetLimit.php | 22 ++-- app/Models/Category.php | 20 ++-- app/Models/Component.php | 10 +- app/Models/LimitRepetition.php | 18 ++-- app/Models/PiggyBank.php | 42 ++++---- app/Models/PiggyBankEvent.php | 20 ++-- app/Models/PiggyBankRepetition.php | 30 +++--- app/Models/Preference.php | 18 ++-- app/Models/Reminder.php | 34 +++--- app/Models/Tag.php | 26 ++--- app/Models/Transaction.php | 26 ++--- app/Models/TransactionCurrency.php | 16 +-- app/Models/TransactionGroup.php | 16 +-- app/Models/TransactionJournal.php | 22 ++-- app/Models/TransactionRelation.php | 2 +- app/Models/TransactionType.php | 12 +-- app/Providers/BusServiceProvider.php | 2 +- app/Providers/EventServiceProvider.php | 12 +-- app/Providers/FireflyServiceProvider.php | 12 +-- app/Providers/RouteServiceProvider.php | 2 +- .../Account/AccountRepository.php | 22 ++-- app/Repositories/Budget/BudgetRepository.php | 94 ++++++++-------- .../Category/CategoryRepository.php | 54 +++++----- .../Journal/JournalRepository.php | 2 +- .../PiggyBank/PiggyBankRepository.php | 2 +- .../Reminder/ReminderRepository.php | 40 +++---- app/Repositories/Tag/TagRepository.php | 2 +- app/Services/Registrar.php | 6 +- app/Support/CacheProperties.php | 8 ++ app/Support/Navigation.php | 4 +- app/Support/Preferences.php | 19 ++-- app/Support/Search/Search.php | 12 +-- app/Support/Steam.php | 18 ++-- app/Support/Twig/Budget.php | 18 ++-- app/Support/Twig/General.php | 22 ++-- app/Support/Twig/Journal.php | 14 ++- app/Support/Twig/PiggyBank.php | 2 +- app/Support/Twig/Translation.php | 2 +- app/User.php | 28 ++--- 69 files changed, 695 insertions(+), 716 deletions(-) diff --git a/app/Helpers/Collection/BalanceLine.php b/app/Helpers/Collection/BalanceLine.php index de82b6814d..d491f32959 100644 --- a/app/Helpers/Collection/BalanceLine.php +++ b/app/Helpers/Collection/BalanceLine.php @@ -64,6 +64,7 @@ class BalanceLine if ($this->getRole() == self::ROLE_DIFFROLE) { return trans('firefly.leftUnbalanced'); } + return ''; } diff --git a/app/Helpers/Collection/Bill.php b/app/Helpers/Collection/Bill.php index de5b86fc97..34b3205c6b 100644 --- a/app/Helpers/Collection/Bill.php +++ b/app/Helpers/Collection/Bill.php @@ -41,7 +41,7 @@ class Bill public function getBills() { $this->bills->sortBy( - function(BillLine $bill) { + function (BillLine $bill) { $active = intval($bill->getBill()->active) == 0 ? 1 : 0; $name = $bill->getBill()->name; diff --git a/app/Helpers/Collection/Category.php b/app/Helpers/Collection/Category.php index 71af3c2607..84f426487a 100644 --- a/app/Helpers/Collection/Category.php +++ b/app/Helpers/Collection/Category.php @@ -55,7 +55,7 @@ class Category public function getCategories() { $this->categories->sortByDesc( - function(CategoryModel $category) { + function (CategoryModel $category) { return $category->spent; } ); diff --git a/app/Helpers/Collection/Expense.php b/app/Helpers/Collection/Expense.php index f328bfd42a..a66c1ef86d 100644 --- a/app/Helpers/Collection/Expense.php +++ b/app/Helpers/Collection/Expense.php @@ -67,7 +67,7 @@ class Expense public function getExpenses() { $this->expenses->sortByDesc( - function(stdClass $object) { + function (stdClass $object) { return $object->amount; } ); diff --git a/app/Helpers/Collection/Income.php b/app/Helpers/Collection/Income.php index 2b635f8aa4..c3caf9eba7 100644 --- a/app/Helpers/Collection/Income.php +++ b/app/Helpers/Collection/Income.php @@ -68,7 +68,7 @@ class Income public function getIncomes() { $this->incomes->sortByDesc( - function(stdClass $object) { + function (stdClass $object) { return $object->amount; } ); diff --git a/app/Helpers/Report/ReportHelper.php b/app/Helpers/Report/ReportHelper.php index a1e337531a..4790b1d81c 100644 --- a/app/Helpers/Report/ReportHelper.php +++ b/app/Helpers/Report/ReportHelper.php @@ -66,10 +66,11 @@ class ReportHelper implements ReportHelperInterface // remove cash account, if any: $accounts = $accounts->filter( - function(Account $account) { + function (Account $account) { if ($account->accountType->type != 'Cash account') { return $account; } + return null; } ); diff --git a/app/Helpers/Report/ReportHelperInterface.php b/app/Helpers/Report/ReportHelperInterface.php index e1e0a3df1a..75ffbdfd0c 100644 --- a/app/Helpers/Report/ReportHelperInterface.php +++ b/app/Helpers/Report/ReportHelperInterface.php @@ -5,9 +5,9 @@ namespace FireflyIII\Helpers\Report; use Carbon\Carbon; use FireflyIII\Helpers\Collection\Account as AccountCollection; use FireflyIII\Helpers\Collection\Balance; +use FireflyIII\Helpers\Collection\Bill as BillCollection; use FireflyIII\Helpers\Collection\Budget as BudgetCollection; use FireflyIII\Helpers\Collection\Category as CategoryCollection; -use FireflyIII\Helpers\Collection\Bill as BillCollection; use FireflyIII\Helpers\Collection\Expense; use FireflyIII\Helpers\Collection\Income; diff --git a/app/Helpers/Report/ReportQuery.php b/app/Helpers/Report/ReportQuery.php index 5bcf09f9d8..2e720e0653 100644 --- a/app/Helpers/Report/ReportQuery.php +++ b/app/Helpers/Report/ReportQuery.php @@ -35,15 +35,15 @@ class ReportQuery implements ReportQueryInterface $query = $this->queryJournalsWithTransactions($start, $end); if ($includeShared === false) { $query->where( - function(Builder $query) { + function (Builder $query) { $query->where( - function(Builder $q) { // only get withdrawals not from a shared account + function (Builder $q) { // only get withdrawals not from a shared account $q->where('transaction_types.type', 'Withdrawal'); $q->where('acm_from.data', '!=', '"sharedAsset"'); } ); $query->orWhere( - function(Builder $q) { // and transfers from a shared account. + function (Builder $q) { // and transfers from a shared account. $q->where('transaction_types.type', 'Transfer'); $q->where('acm_to.data', '=', '"sharedAsset"'); } @@ -61,17 +61,18 @@ class ReportQuery implements ReportQueryInterface ); $data->each( - function(TransactionJournal $journal) { + function (TransactionJournal $journal) { if (intval($journal->account_encrypted) == 1) { $journal->name = Crypt::decrypt($journal->name); } } ); $data = $data->filter( - function(TransactionJournal $journal) { + function (TransactionJournal $journal) { if ($journal->amount != 0) { return $journal; } + return null; } ); @@ -91,26 +92,26 @@ class ReportQuery implements ReportQueryInterface public function getAllAccounts(Carbon $start, Carbon $end, $includeShared = false) { $query = Auth::user()->accounts()->orderBy('accounts.name', 'ASC') - ->accountTypeIn(['Default account', 'Asset account', 'Cash account']); + ->accountTypeIn(['Default account', 'Asset account', 'Cash account']); if ($includeShared === false) { $query->leftJoin( - 'account_meta', function(JoinClause $join) { + 'account_meta', function (JoinClause $join) { $join->on('account_meta.account_id', '=', 'accounts.id')->where('account_meta.name', '=', 'accountRole'); } ) - ->orderBy('accounts.name', 'ASC') - ->where( - function(Builder $query) { + ->orderBy('accounts.name', 'ASC') + ->where( + function (Builder $query) { - $query->where('account_meta.data', '!=', '"sharedAsset"'); - $query->orWhereNull('account_meta.data'); + $query->where('account_meta.data', '!=', '"sharedAsset"'); + $query->orWhereNull('account_meta.data'); - } - ); + } + ); } $set = $query->get(['accounts.*']); $set->each( - function(Account $account) use ($start, $end) { + function (Account $account) use ($start, $end) { /** * The balance for today always incorporates transactions * made on today. So to get todays "start" balance, we sub one @@ -151,15 +152,15 @@ class ReportQuery implements ReportQueryInterface // only get deposits not to a shared account // and transfers to a shared account. $query->where( - function(Builder $query) { + function (Builder $query) { $query->where( - function(Builder $q) { + function (Builder $q) { $q->where('transaction_types.type', 'Deposit'); $q->where('acm_to.data', '!=', '"sharedAsset"'); } ); $query->orWhere( - function(Builder $q) { + function (Builder $q) { $q->where('transaction_types.type', 'Transfer'); $q->where('acm_from.data', '=', '"sharedAsset"'); } @@ -178,17 +179,18 @@ class ReportQuery implements ReportQueryInterface ); $data->each( - function(TransactionJournal $journal) { + function (TransactionJournal $journal) { if (intval($journal->account_encrypted) == 1) { $journal->name = Crypt::decrypt($journal->name); } } ); $data = $data->filter( - function(TransactionJournal $journal) { + function (TransactionJournal $journal) { if ($journal->amount != 0) { return $journal; } + return null; } ); @@ -210,16 +212,16 @@ class ReportQuery implements ReportQueryInterface { return floatval( - Auth::user()->transactionjournals() - ->leftJoin('transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id') - ->leftJoin('budget_transaction_journal', 'budget_transaction_journal.transaction_journal_id', '=', 'transaction_journals.id') - ->transactionTypes(['Withdrawal']) - ->where('transactions.account_id', $account->id) - ->before($end) - ->after($start) - ->where('budget_transaction_journal.budget_id', $budget->id) - ->get(['transaction_journals.*'])->sum('amount') - ) * -1; + Auth::user()->transactionjournals() + ->leftJoin('transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id') + ->leftJoin('budget_transaction_journal', 'budget_transaction_journal.transaction_journal_id', '=', 'transaction_journals.id') + ->transactionTypes(['Withdrawal']) + ->where('transactions.account_id', $account->id) + ->before($end) + ->after($start) + ->where('budget_transaction_journal.budget_id', $budget->id) + ->get(['transaction_journals.*'])->sum('amount') + ) * -1; } /** @@ -254,28 +256,28 @@ class ReportQuery implements ReportQueryInterface { $query = TransactionJournal:: leftJoin( - 'transactions as t_from', function(JoinClause $join) { + 'transactions as t_from', function (JoinClause $join) { $join->on('t_from.transaction_journal_id', '=', 'transaction_journals.id')->where('t_from.amount', '<', 0); } ) - ->leftJoin('accounts as ac_from', 't_from.account_id', '=', 'ac_from.id') - ->leftJoin( - 'account_meta as acm_from', function(JoinClause $join) { - $join->on('ac_from.id', '=', 'acm_from.account_id')->where('acm_from.name', '=', 'accountRole'); - } - ) - ->leftJoin( - 'transactions as t_to', function(JoinClause $join) { - $join->on('t_to.transaction_journal_id', '=', 'transaction_journals.id')->where('t_to.amount', '>', 0); - } - ) - ->leftJoin('accounts as ac_to', 't_to.account_id', '=', 'ac_to.id') - ->leftJoin( - 'account_meta as acm_to', function(JoinClause $join) { - $join->on('ac_to.id', '=', 'acm_to.account_id')->where('acm_to.name', '=', 'accountRole'); - } - ) - ->leftJoin('transaction_types', 'transaction_types.id', '=', 'transaction_journals.transaction_type_id'); + ->leftJoin('accounts as ac_from', 't_from.account_id', '=', 'ac_from.id') + ->leftJoin( + 'account_meta as acm_from', function (JoinClause $join) { + $join->on('ac_from.id', '=', 'acm_from.account_id')->where('acm_from.name', '=', 'accountRole'); + } + ) + ->leftJoin( + 'transactions as t_to', function (JoinClause $join) { + $join->on('t_to.transaction_journal_id', '=', 'transaction_journals.id')->where('t_to.amount', '>', 0); + } + ) + ->leftJoin('accounts as ac_to', 't_to.account_id', '=', 'ac_to.id') + ->leftJoin( + 'account_meta as acm_to', function (JoinClause $join) { + $join->on('ac_to.id', '=', 'acm_to.account_id')->where('acm_to.name', '=', 'accountRole'); + } + ) + ->leftJoin('transaction_types', 'transaction_types.id', '=', 'transaction_journals.transaction_type_id'); $query->before($end)->after($start)->where('transaction_journals.user_id', Auth::user()->id); return $query; diff --git a/app/Http/Controllers/AccountController.php b/app/Http/Controllers/AccountController.php index dbef12d1e4..be1a8545c8 100644 --- a/app/Http/Controllers/AccountController.php +++ b/app/Http/Controllers/AccountController.php @@ -7,12 +7,13 @@ use FireflyIII\Http\Requests\AccountFormRequest; use FireflyIII\Models\Account; use FireflyIII\Repositories\Account\AccountRepositoryInterface; use Input; +use Preferences; use Redirect; use Session; use Steam; use URL; use View; -use Preferences; + /** * Class AccountController * @@ -155,7 +156,7 @@ class AccountController extends Controller $start = clone Session::get('start', Carbon::now()->startOfMonth()); $start->subDay(); $accounts->each( - function(Account $account) use ($start, $repository) { + function (Account $account) use ($start, $repository) { $account->lastActivityDate = $repository->getLastActivity($account); $account->startBalance = Steam::balance($account, $start); $account->endBalance = Steam::balance($account, clone Session::get('end', Carbon::now()->endOfMonth())); @@ -200,11 +201,11 @@ class AccountController extends Controller 'user' => Auth::user()->id, 'accountRole' => $request->input('accountRole'), 'openingBalance' => floatval($request->input('openingBalance')), - 'openingBalanceDate' => new Carbon((string) $request->input('openingBalanceDate')), + 'openingBalanceDate' => new Carbon((string)$request->input('openingBalanceDate')), 'openingBalanceCurrency' => intval($request->input('balance_currency_id')), ]; - $account = $repository->store($accountData); + $account = $repository->store($accountData); Session::flash('success', 'New account "' . $account->name . '" stored!'); Preferences::mark(); @@ -239,7 +240,7 @@ class AccountController extends Controller 'accountRole' => $request->input('accountRole'), 'virtualBalance' => floatval($request->input('virtualBalance')), 'openingBalance' => floatval($request->input('openingBalance')), - 'openingBalanceDate' => new Carbon((string) $request->input('openingBalanceDate')), + 'openingBalanceDate' => new Carbon((string)$request->input('openingBalanceDate')), 'openingBalanceCurrency' => intval($request->input('balance_currency_id')), 'ccType' => $request->input('ccType'), 'ccMonthlyPaymentDate' => $request->input('ccMonthlyPaymentDate'), diff --git a/app/Http/Controllers/Auth/AuthController.php b/app/Http/Controllers/Auth/AuthController.php index a44ab81cbc..7819d86383 100644 --- a/app/Http/Controllers/Auth/AuthController.php +++ b/app/Http/Controllers/Auth/AuthController.php @@ -109,7 +109,7 @@ class AuthController extends Controller if (User::count() == 1) { $admin = Role::where('name', 'owner')->first(); $this->auth->user()->attachRole($admin); -// $this->auth->user()->roles()->save($admin); + // $this->auth->user()->roles()->save($admin); } diff --git a/app/Http/Controllers/BillController.php b/app/Http/Controllers/BillController.php index 6d96298615..045b242b97 100644 --- a/app/Http/Controllers/BillController.php +++ b/app/Http/Controllers/BillController.php @@ -112,7 +112,7 @@ class BillController extends Controller { $bills = $repository->getBills(); $bills->each( - function(Bill $bill) use ($repository) { + function (Bill $bill) use ($repository) { $bill->nextExpectedMatch = $repository->nextExpectedMatch($bill); $bill->lastFoundMatch = $repository->lastFoundMatch($bill); } diff --git a/app/Http/Controllers/BudgetController.php b/app/Http/Controllers/BudgetController.php index 95d43d1535..0925ce2056 100644 --- a/app/Http/Controllers/BudgetController.php +++ b/app/Http/Controllers/BudgetController.php @@ -242,7 +242,7 @@ class BudgetController extends Controller 'name' => $request->input('name'), 'user' => Auth::user()->id, ]; - $budget = $repository->store($budgetData); + $budget = $repository->store($budgetData); Session::flash('success', 'New budget "' . $budget->name . '" stored!'); Preferences::mark(); diff --git a/app/Http/Controllers/CategoryController.php b/app/Http/Controllers/CategoryController.php index 6de44dbba9..b6f016f272 100644 --- a/app/Http/Controllers/CategoryController.php +++ b/app/Http/Controllers/CategoryController.php @@ -114,7 +114,7 @@ class CategoryController extends Controller $categories = $repository->getCategories(); $categories->each( - function(Category $category) use ($repository) { + function (Category $category) use ($repository) { $category->lastActivity = $repository->getLatestActivity($category); } ); @@ -167,7 +167,7 @@ class CategoryController extends Controller 'name' => $request->input('name'), 'user' => Auth::user()->id, ]; - $category = $repository->store($categoryData); + $category = $repository->store($categoryData); Session::flash('success', 'New category "' . $category->name . '" stored!'); Preferences::mark(); diff --git a/app/Http/Controllers/Chart/AccountController.php b/app/Http/Controllers/Chart/AccountController.php index bd862d3012..af8aef6b57 100644 --- a/app/Http/Controllers/Chart/AccountController.php +++ b/app/Http/Controllers/Chart/AccountController.php @@ -2,8 +2,6 @@ namespace FireflyIII\Http\Controllers\Chart; -use Auth; -use Cache; use Carbon\Carbon; use FireflyIII\Http\Controllers\Controller; use FireflyIII\Models\Account; @@ -11,7 +9,6 @@ use FireflyIII\Repositories\Account\AccountRepositoryInterface; use FireflyIII\Support\CacheProperties; use Grumpydictator\Gchart\GChart; use Illuminate\Support\Collection; -use Log; use Preferences; use Response; use Session; @@ -43,15 +40,14 @@ class AccountController extends Controller $end->endOfMonth(); // chart properties for cache: - $chartProperties = new CacheProperties(); - $chartProperties->addProperty($start); - $chartProperties->addProperty($end); - $chartProperties->addProperty('all'); - $chartProperties->addProperty('accounts'); - if ($chartProperties->has()) { - return Response::json($chartProperties->get()); + $cache = new CacheProperties(); + $cache->addProperty($start); + $cache->addProperty($end); + $cache->addProperty('all'); + $cache->addProperty('accounts'); + if ($cache->has()) { + return Response::json($cache->get()); } - $md5 = $chartProperties->getMd5(); $chart->addColumn(trans('firefly.dayOfMonth'), 'date'); @@ -91,7 +87,7 @@ class AccountController extends Controller $chart->generate(); $data = $chart->getData(); - Cache::forever($md5, $data); + $cache->store($data); return Response::json($data); } @@ -114,15 +110,14 @@ class AccountController extends Controller $accounts = $repository->getFrontpageAccounts($frontPage); // chart properties for cache: - $chartProperties = new CacheProperties(); - $chartProperties->addProperty($start); - $chartProperties->addProperty($end); - $chartProperties->addProperty('frontpage'); - $chartProperties->addProperty('accounts'); - if ($chartProperties->has()) { - return Response::json($chartProperties->get()); + $cache = new CacheProperties(); + $cache->addProperty($start); + $cache->addProperty($end); + $cache->addProperty('frontpage'); + $cache->addProperty('accounts'); + if ($cache->has()) { + return Response::json($cache->get()); } - $md5 = $chartProperties->getMd5(); $index = 1; @@ -148,7 +143,7 @@ class AccountController extends Controller $chart->generate(); $data = $chart->getData(); - Cache::forever($md5, $data); + $cache->store($data); return Response::json($data); @@ -174,18 +169,15 @@ class AccountController extends Controller $today = new Carbon; // chart properties for cache: - $chartProperties = new CacheProperties(); - $chartProperties->addProperty($start); - $chartProperties->addProperty($end); - $chartProperties->addProperty('frontpage'); - $chartProperties->addProperty('single'); - $chartProperties->addProperty($account->id); - if ($chartProperties->has()) { - return Response::json($chartProperties->get()); + $cache = new CacheProperties(); + $cache->addProperty($start); + $cache->addProperty($end); + $cache->addProperty('frontpage'); + $cache->addProperty('single'); + $cache->addProperty($account->id); + if ($cache->has()) { + return Response::json($cache->get()); } - $md5 = $chartProperties->getMd5(); - - while ($end >= $current) { $certain = $current < $today; @@ -197,7 +189,7 @@ class AccountController extends Controller $chart->generate(); $data = $chart->getData(); - Cache::forever($md5, $data); + $cache->store($data); return Response::json($data); } diff --git a/app/Http/Controllers/Chart/BillController.php b/app/Http/Controllers/Chart/BillController.php index 7950e294ed..a1b8985ee5 100644 --- a/app/Http/Controllers/Chart/BillController.php +++ b/app/Http/Controllers/Chart/BillController.php @@ -14,8 +14,7 @@ use Illuminate\Support\Collection; use Response; use Session; use Steam; -use Cache; -use Log; + /** * Class BillController * @@ -40,14 +39,13 @@ class BillController extends Controller $chart->addColumn(trans('firefly.minAmount'), 'number'); $chart->addColumn(trans('firefly.billEntry'), 'number'); - $chartProperties = new CacheProperties; - $chartProperties->addProperty('single'); - $chartProperties->addProperty('bill'); - $chartProperties->addProperty($bill->id); - if ($chartProperties->has()) { - return Response::json($chartProperties->get()); + $cache = new CacheProperties; + $cache->addProperty('single'); + $cache->addProperty('bill'); + $cache->addProperty($bill->id); + if ($cache->has()) { + return Response::json($cache->get()); } - $md5 = $chartProperties->getMd5(); // get first transaction or today for start: $results = $repository->getJournals($bill); @@ -59,7 +57,7 @@ class BillController extends Controller $chart->generate(); $data = $chart->getData(); - Cache::forever($md5, $data); + $cache->store($data); return Response::json($data); } @@ -79,20 +77,19 @@ class BillController extends Controller $chart->addColumn(trans('firefly.name'), 'string'); $chart->addColumn(trans('firefly.amount'), 'number'); - $start = Session::get('start', Carbon::now()->startOfMonth()); - $end = Session::get('end', Carbon::now()->endOfMonth()); + $start = Session::get('start', Carbon::now()->startOfMonth()); + $end = Session::get('end', Carbon::now()->endOfMonth()); // chart properties for cache: - $chartProperties = new CacheProperties(); - $chartProperties->addProperty($start); - $chartProperties->addProperty($end); - $chartProperties->addProperty('bills'); - $chartProperties->addProperty('frontpage'); - if ($chartProperties->has()) { - return Response::json($chartProperties->get()); + $cache = new CacheProperties(); + $cache->addProperty($start); + $cache->addProperty($end); + $cache->addProperty('bills'); + $cache->addProperty('frontpage'); + if ($cache->has()) { + return Response::json($cache->get()); } - $md5 = $chartProperties->getMd5(); $bills = $repository->getActiveBills(); $paid = new Collection; // journals. @@ -163,7 +160,7 @@ class BillController extends Controller $chart->generate(); $data = $chart->getData(); - Cache::forever($md5, $data); + $cache->store($data); return Response::json($data); } diff --git a/app/Http/Controllers/Chart/BudgetController.php b/app/Http/Controllers/Chart/BudgetController.php index 731f87b4de..dbd569d682 100644 --- a/app/Http/Controllers/Chart/BudgetController.php +++ b/app/Http/Controllers/Chart/BudgetController.php @@ -2,7 +2,6 @@ namespace FireflyIII\Http\Controllers\Chart; -use Cache; use Carbon\Carbon; use FireflyIII\Http\Controllers\Controller; use FireflyIII\Models\Budget; @@ -11,7 +10,6 @@ use FireflyIII\Repositories\Budget\BudgetRepositoryInterface; use FireflyIII\Support\CacheProperties; use Grumpydictator\Gchart\GChart; use Illuminate\Support\Collection; -use Log; use Navigation; use Preferences; use Response; @@ -45,15 +43,14 @@ class BudgetController extends Controller $last = Navigation::endOfX($last, $range, $final); // chart properties for cache: - $chartProperties = new CacheProperties(); - $chartProperties->addProperty($first); - $chartProperties->addProperty($last); - $chartProperties->addProperty('budget'); - $chartProperties->addProperty('budget'); - if ($chartProperties->has()) { - return Response::json($chartProperties->get()); + $cache = new CacheProperties(); + $cache->addProperty($first); + $cache->addProperty($last); + $cache->addProperty('budget'); + $cache->addProperty('budget'); + if ($cache->has()) { + return Response::json($cache->get()); } - $md5 = $chartProperties->getMd5(); while ($first < $last) { @@ -69,7 +66,7 @@ class BudgetController extends Controller $chart->generate(); $data = $chart->getData(); - Cache::forever($md5, $data); + $cache->store($data); return Response::json($data); } @@ -90,17 +87,16 @@ class BudgetController extends Controller $end = $repetition->enddate; // chart properties for cache: - $chartProperties = new CacheProperties(); - $chartProperties->addProperty($start); - $chartProperties->addProperty($end); - $chartProperties->addProperty('budget'); - $chartProperties->addProperty('limit'); - $chartProperties->addProperty($budget->id); - $chartProperties->addProperty($repetition->id); - if ($chartProperties->has()) { - return Response::json($chartProperties->get()); + $cache = new CacheProperties(); + $cache->addProperty($start); + $cache->addProperty($end); + $cache->addProperty('budget'); + $cache->addProperty('limit'); + $cache->addProperty($budget->id); + $cache->addProperty($repetition->id); + if ($cache->has()) { + return Response::json($cache->get()); } - $md5 = $chartProperties->getMd5(); $chart->addColumn(trans('firefly.day'), 'date'); $chart->addColumn(trans('firefly.left'), 'number'); @@ -120,7 +116,7 @@ class BudgetController extends Controller $chart->generate(); $data = $chart->getData(); - Cache::forever($md5, $data); + $cache->store($data); return Response::json($data); @@ -147,15 +143,14 @@ class BudgetController extends Controller $allEntries = new Collection; // chart properties for cache: - $chartProperties = new CacheProperties(); - $chartProperties->addProperty($start); - $chartProperties->addProperty($end); - $chartProperties->addProperty('budget'); - $chartProperties->addProperty('all'); - if ($chartProperties->has()) { - return Response::json($chartProperties->get()); + $cache = new CacheProperties(); + $cache->addProperty($start); + $cache->addProperty($end); + $cache->addProperty('budget'); + $cache->addProperty('all'); + if ($cache->has()) { + return Response::json($cache->get()); } - $md5 = $chartProperties->getMd5(); /** @var Budget $budget */ @@ -194,7 +189,7 @@ class BudgetController extends Controller $chart->generate(); $data = $chart->getData(); - Cache::forever($md5, $data); + $cache->store($data); return Response::json($data); @@ -218,15 +213,14 @@ class BudgetController extends Controller $budgets = $repository->getBudgets(); // chart properties for cache: - $chartProperties = new CacheProperties(); - $chartProperties->addProperty($start); - $chartProperties->addProperty($end); - $chartProperties->addProperty('budget'); - $chartProperties->addProperty('year'); - if ($chartProperties->has()) { - return Response::json($chartProperties->get()); + $cache = new CacheProperties(); + $cache->addProperty($start); + $cache->addProperty($end); + $cache->addProperty('budget'); + $cache->addProperty('year'); + if ($cache->has()) { + return Response::json($cache->get()); } - $md5 = $chartProperties->getMd5(); // add columns: $chart->addColumn(trans('firefly.month'), 'date'); @@ -254,7 +248,7 @@ class BudgetController extends Controller $chart->generate(); $data = $chart->getData(); - Cache::forever($md5, $data); + $cache->store($data); return Response::json($data); } diff --git a/app/Http/Controllers/Chart/CategoryController.php b/app/Http/Controllers/Chart/CategoryController.php index 5d0a57b031..fed7840398 100644 --- a/app/Http/Controllers/Chart/CategoryController.php +++ b/app/Http/Controllers/Chart/CategoryController.php @@ -3,14 +3,12 @@ namespace FireflyIII\Http\Controllers\Chart; -use Cache; use Carbon\Carbon; use FireflyIII\Http\Controllers\Controller; use FireflyIII\Models\Category; use FireflyIII\Repositories\Category\CategoryRepositoryInterface; use FireflyIII\Support\CacheProperties; use Grumpydictator\Gchart\GChart; -use Log; use Navigation; use Preferences; use Response; @@ -80,22 +78,21 @@ class CategoryController extends Controller $end = Session::get('end', Carbon::now()->endOfMonth()); // chart properties for cache: - $chartProperties = new CacheProperties; - $chartProperties->addProperty($start); - $chartProperties->addProperty($end); - $chartProperties->addProperty('category'); - $chartProperties->addProperty('frontpage'); - if ($chartProperties->has()) { - return Response::json($chartProperties->get()); + $cache = new CacheProperties; + $cache->addProperty($start); + $cache->addProperty($end); + $cache->addProperty('category'); + $cache->addProperty('frontpage'); + if ($cache->has()) { + return Response::json($cache->get()); } - $md5 = $chartProperties->getMd5(); - $set = $repository->getCategoriesAndExpensesCorrected($start, $end); + $set = $repository->getCategoriesAndExpensesCorrected($start, $end); // sort by callback: uasort( $set, - function($left, $right) { + function ($left, $right) { if ($left['sum'] == $right['sum']) { return 0; } @@ -115,7 +112,7 @@ class CategoryController extends Controller $chart->generate(); $data = $chart->getData(); - Cache::forever($md5, $data); + $cache->store($data); return Response::json($data); diff --git a/app/Http/Controllers/HomeController.php b/app/Http/Controllers/HomeController.php index 17472183d5..4477ae09d3 100644 --- a/app/Http/Controllers/HomeController.php +++ b/app/Http/Controllers/HomeController.php @@ -2,7 +2,6 @@ use Carbon\Carbon; use Config; -use FireflyIII\Models\TransactionJournal; use FireflyIII\Repositories\Account\AccountRepositoryInterface; use Input; use Preferences; @@ -61,20 +60,19 @@ class HomeController extends Controller return Redirect::route('new-user.index'); } - $title = 'Firefly'; - $subTitle = trans('firefly.welcomeBack'); - $mainTitleIcon = 'fa-fire'; - $transactions = []; - $frontPage = Preferences::get('frontPageAccounts', []); - $start = Session::get('start', Carbon::now()->startOfMonth()); - $end = Session::get('end', Carbon::now()->endOfMonth()); - $accounts = $repository->getFrontpageAccounts($frontPage); - $savings = $repository->getSavingsAccounts(); + $title = 'Firefly'; + $subTitle = trans('firefly.welcomeBack'); + $mainTitleIcon = 'fa-fire'; + $transactions = []; + $frontPage = Preferences::get('frontPageAccounts', []); + $start = Session::get('start', Carbon::now()->startOfMonth()); + $end = Session::get('end', Carbon::now()->endOfMonth()); + $accounts = $repository->getFrontpageAccounts($frontPage); + $savings = $repository->getSavingsAccounts(); $piggyBankAccounts = $repository->getPiggyBankAccounts(); - $savingsTotal = 0; foreach ($savings as $savingAccount) { $savingsTotal += Steam::balance($savingAccount, $end); @@ -95,6 +93,7 @@ class HomeController extends Controller $transactions[] = [$set, $account]; } } + return view('index', compact('count', 'title', 'savings', 'subTitle', 'mainTitleIcon', 'transactions', 'savingsTotal', 'piggyBankAccounts')); } diff --git a/app/Http/Controllers/JsonController.php b/app/Http/Controllers/JsonController.php index 9d0295411a..37ce8f34f5 100644 --- a/app/Http/Controllers/JsonController.php +++ b/app/Http/Controllers/JsonController.php @@ -1,7 +1,6 @@ endOfMonth()); // works for json too! - $prop = new CacheProperties; - $prop->addProperty($start); - $prop->addProperty($end); - $prop->addProperty('box-bills-paid'); - if ($prop->has()) { - return Response::json($prop->get()); + $cache = new CacheProperties; + $cache->addProperty($start); + $cache->addProperty($end); + $cache->addProperty('box-bills-paid'); + if ($cache->has()) { + return Response::json($cache->get()); } - $md5 = $prop->getMd5(); $amount = 0; @@ -75,7 +73,8 @@ class JsonController extends Controller } } $data = ['box' => 'bills-paid', 'amount' => Amount::format($amount, false), 'amount_raw' => $amount]; - Cache::forever($md5, $data); + $cache->store($data); + return Response::json($data); } @@ -93,14 +92,13 @@ class JsonController extends Controller $end = Session::get('end', Carbon::now()->endOfMonth()); // works for json too! - $prop = new CacheProperties; - $prop->addProperty($start); - $prop->addProperty($end); - $prop->addProperty('box-bills-unpaid'); - if ($prop->has()) { - return Response::json($prop->get()); + $cache = new CacheProperties; + $cache->addProperty($start); + $cache->addProperty($end); + $cache->addProperty('box-bills-unpaid'); + if ($cache->has()) { + return Response::json($cache->get()); } - $md5 = $prop->getMd5(); $bills = $repository->getActiveBills(); $unpaid = new Collection; // bills @@ -137,7 +135,7 @@ class JsonController extends Controller } $data = ['box' => 'bills-unpaid', 'amount' => Amount::format($amount, false), 'amount_raw' => $amount]; - Cache::forever($md5, $data); + $cache->store($data); return Response::json($data); } @@ -153,19 +151,18 @@ class JsonController extends Controller $end = Session::get('end', Carbon::now()->endOfMonth()); // works for json too! - $prop = new CacheProperties; - $prop->addProperty($start); - $prop->addProperty($end); - $prop->addProperty('box-in'); - if ($prop->has()) { - return Response::json($prop->get()); + $cache = new CacheProperties; + $cache->addProperty($start); + $cache->addProperty($end); + $cache->addProperty('box-in'); + if ($cache->has()) { + return Response::json($cache->get()); } - $md5 = $prop->getMd5(); $amount = $reportQuery->incomeInPeriodCorrected($start, $end, true)->sum('amount'); $data = ['box' => 'in', 'amount' => Amount::format($amount, false), 'amount_raw' => $amount]; - Cache::forever($md5, $data); + $cache->store($data); return Response::json($data); } @@ -182,19 +179,18 @@ class JsonController extends Controller // works for json too! - $prop = new CacheProperties; - $prop->addProperty($start); - $prop->addProperty($end); - $prop->addProperty('box-out'); - if ($prop->has()) { - return Response::json($prop->get()); + $cache = new CacheProperties; + $cache->addProperty($start); + $cache->addProperty($end); + $cache->addProperty('box-out'); + if ($cache->has()) { + return Response::json($cache->get()); } - $md5 = $prop->getMd5(); $amount = $reportQuery->expenseInPeriodCorrected($start, $end, true)->sum('amount'); $data = ['box' => 'out', 'amount' => Amount::format($amount, false), 'amount_raw' => $amount]; - Cache::forever($md5, $data); + $cache->store($data); return Response::json($data); } diff --git a/app/Http/Controllers/NewUserController.php b/app/Http/Controllers/NewUserController.php index 7dc2738bcd..29734168c2 100644 --- a/app/Http/Controllers/NewUserController.php +++ b/app/Http/Controllers/NewUserController.php @@ -107,7 +107,7 @@ class NewUserController extends Controller AccountMeta::create( [ 'name' => 'ccMonthlyPaymentDate', - 'data' => Carbon::now()->year.'-01-01', + 'data' => Carbon::now()->year . '-01-01', 'account_id' => $creditCard->id, ] ); diff --git a/app/Http/Controllers/PiggyBankController.php b/app/Http/Controllers/PiggyBankController.php index f9bc5f87c6..381f1c544c 100644 --- a/app/Http/Controllers/PiggyBankController.php +++ b/app/Http/Controllers/PiggyBankController.php @@ -139,11 +139,11 @@ class PiggyBankController extends Controller $targetDate = $targetDate->format('Y-m-d'); } $preFilled = ['name' => $piggyBank->name, - 'account_id' => $piggyBank->account_id, - 'targetamount' => $piggyBank->targetamount, - 'targetdate' => $targetDate, - 'reminder' => $piggyBank->reminder, - 'remind_me' => intval($piggyBank->remind_me) == 1 && !is_null($piggyBank->reminder) ? true : false + 'account_id' => $piggyBank->account_id, + 'targetamount' => $piggyBank->targetamount, + 'targetdate' => $targetDate, + 'reminder' => $piggyBank->reminder, + 'remind_me' => intval($piggyBank->remind_me) == 1 && !is_null($piggyBank->reminder) ? true : false ]; Session::flash('preFilled', $preFilled); Session::flash('gaEventCategory', 'piggy-banks'); diff --git a/app/Http/Controllers/TransactionController.php b/app/Http/Controllers/TransactionController.php index 575d35c383..e3fb0f0e31 100644 --- a/app/Http/Controllers/TransactionController.php +++ b/app/Http/Controllers/TransactionController.php @@ -253,7 +253,7 @@ class TransactionController extends Controller public function show(JournalRepositoryInterface $repository, TransactionJournal $journal) { $journal->transactions->each( - function(Transaction $t) use ($journal, $repository) { + function (Transaction $t) use ($journal, $repository) { $t->before = $repository->getAmountBefore($journal, $t); $t->after = $t->before + $t->amount; } diff --git a/app/Http/Middleware/Authenticate.php b/app/Http/Middleware/Authenticate.php index d447376e03..e83a32aefb 100644 --- a/app/Http/Middleware/Authenticate.php +++ b/app/Http/Middleware/Authenticate.php @@ -1,12 +1,13 @@ addProperty('reminders'); - if ($properties->has()) { - $reminders = $properties->get(); + $cache->addProperty('reminders'); + if ($cache->has()) { + $reminders = $cache->get(); View::share('reminders', $reminders); return $next($request); } - $md5 = $properties->getMd5(); - $piggyBanks = $this->auth->user()->piggyBanks()->where('remind_me', 1)->get(); @@ -89,7 +86,7 @@ class Reminders $reminder->description = $helper->getReminderText($reminder); } ); - Cache::forever($md5, $reminders); + $cache->store($reminders); View::share('reminders', $reminders); } diff --git a/app/Http/breadcrumbs.php b/app/Http/breadcrumbs.php index 80aa857876..fd8e5a146f 100644 --- a/app/Http/breadcrumbs.php +++ b/app/Http/breadcrumbs.php @@ -17,7 +17,7 @@ use FireflyIII\Models\TransactionJournal; */ Breadcrumbs::register( 'home', - function(Generator $breadcrumbs) { + function (Generator $breadcrumbs) { $breadcrumbs->push(trans('breadcrumbs.home'), route('index')); } @@ -25,7 +25,7 @@ Breadcrumbs::register( Breadcrumbs::register( 'index', - function(Generator $breadcrumbs) { + function (Generator $breadcrumbs) { $breadcrumbs->push(trans('breadcrumbs.home'), route('index')); } @@ -34,21 +34,21 @@ Breadcrumbs::register( // accounts Breadcrumbs::register( - 'accounts.index', function(Generator $breadcrumbs, $what) { + 'accounts.index', function (Generator $breadcrumbs, $what) { $breadcrumbs->parent('home'); $breadcrumbs->push(trans('breadcrumbs.' . strtolower(e($what)) . '_accounts'), route('accounts.index', [$what])); } ); Breadcrumbs::register( - 'accounts.create', function(Generator $breadcrumbs, $what) { + 'accounts.create', function (Generator $breadcrumbs, $what) { $breadcrumbs->parent('accounts.index', $what); $breadcrumbs->push(trans('breadcrumbs.new_' . strtolower(e($what)) . '_account'), route('accounts.create', [$what])); } ); Breadcrumbs::register( - 'accounts.show', function(Generator $breadcrumbs, Account $account) { + 'accounts.show', function (Generator $breadcrumbs, Account $account) { $what = Config::get('firefly.shortNamesByFullName.' . $account->accountType->type); @@ -58,7 +58,7 @@ Breadcrumbs::register( } ); Breadcrumbs::register( - 'accounts.delete', function(Generator $breadcrumbs, Account $account) { + 'accounts.delete', function (Generator $breadcrumbs, Account $account) { $breadcrumbs->parent('accounts.show', $account); $breadcrumbs->push(trans('breadcrumbs.delete_account', ['name' => e($account->name)]), route('accounts.delete', [$account->id])); } @@ -66,7 +66,7 @@ Breadcrumbs::register( Breadcrumbs::register( - 'accounts.edit', function(Generator $breadcrumbs, Account $account) { + 'accounts.edit', function (Generator $breadcrumbs, Account $account) { $breadcrumbs->parent('accounts.show', $account); $what = Config::get('firefly.shortNamesByFullName.' . $account->accountType->type); @@ -76,40 +76,40 @@ Breadcrumbs::register( // budgets. Breadcrumbs::register( - 'budgets.index', function(Generator $breadcrumbs) { + 'budgets.index', function (Generator $breadcrumbs) { $breadcrumbs->parent('home'); $breadcrumbs->push(trans('breadcrumbs.budgets'), route('budgets.index')); } ); Breadcrumbs::register( - 'budgets.create', function(Generator $breadcrumbs) { + 'budgets.create', function (Generator $breadcrumbs) { $breadcrumbs->parent('budgets.index'); $breadcrumbs->push(trans('breadcrumbs.newBudget'), route('budgets.create')); } ); Breadcrumbs::register( - 'budgets.edit', function(Generator $breadcrumbs, Budget $budget) { + 'budgets.edit', function (Generator $breadcrumbs, Budget $budget) { $breadcrumbs->parent('budgets.show', $budget); $breadcrumbs->push(trans('breadcrumbs.edit_budget', ['name' => e($budget->name)]), route('budgets.edit', [$budget->id])); } ); Breadcrumbs::register( - 'budgets.delete', function(Generator $breadcrumbs, Budget $budget) { + 'budgets.delete', function (Generator $breadcrumbs, Budget $budget) { $breadcrumbs->parent('budgets.show', $budget); $breadcrumbs->push(trans('breadcrumbs.delete_budget', ['name' => e($budget->name)]), route('budgets.delete', [$budget->id])); } ); Breadcrumbs::register( - 'budgets.noBudget', function(Generator $breadcrumbs, $subTitle) { + 'budgets.noBudget', function (Generator $breadcrumbs, $subTitle) { $breadcrumbs->parent('budgets.index'); $breadcrumbs->push($subTitle, route('budgets.noBudget')); } ); Breadcrumbs::register( - 'budgets.show', function(Generator $breadcrumbs, Budget $budget, LimitRepetition $repetition = null) { + 'budgets.show', function (Generator $breadcrumbs, Budget $budget, LimitRepetition $repetition = null) { $breadcrumbs->parent('budgets.index'); $breadcrumbs->push(e($budget->name), route('budgets.show', [$budget->id])); if (!is_null($repetition) && !is_null($repetition->id)) { @@ -122,33 +122,33 @@ Breadcrumbs::register( // categories Breadcrumbs::register( - 'categories.index', function(Generator $breadcrumbs) { + 'categories.index', function (Generator $breadcrumbs) { $breadcrumbs->parent('home'); $breadcrumbs->push(trans('breadcrumbs.categories'), route('categories.index')); } ); Breadcrumbs::register( - 'categories.create', function(Generator $breadcrumbs) { + 'categories.create', function (Generator $breadcrumbs) { $breadcrumbs->parent('categories.index'); $breadcrumbs->push(trans('breadcrumbs.newCategory'), route('categories.create')); } ); Breadcrumbs::register( - 'categories.edit', function(Generator $breadcrumbs, Category $category) { + 'categories.edit', function (Generator $breadcrumbs, Category $category) { $breadcrumbs->parent('categories.show', $category); $breadcrumbs->push(trans('breadcrumbs.edit_category', ['name' => e($category->name)]), route('categories.edit', [$category->id])); } ); Breadcrumbs::register( - 'categories.delete', function(Generator $breadcrumbs, Category $category) { + 'categories.delete', function (Generator $breadcrumbs, Category $category) { $breadcrumbs->parent('categories.show', $category); $breadcrumbs->push(trans('breadcrumbs.delete_category', ['name' => e($category->name)]), route('categories.delete', [$category->id])); } ); Breadcrumbs::register( - 'categories.show', function(Generator $breadcrumbs, Category $category) { + 'categories.show', function (Generator $breadcrumbs, Category $category) { $breadcrumbs->parent('categories.index'); $breadcrumbs->push(e($category->name), route('categories.show', [$category->id])); @@ -156,7 +156,7 @@ Breadcrumbs::register( ); Breadcrumbs::register( - 'categories.noCategory', function(Generator $breadcrumbs, $subTitle) { + 'categories.noCategory', function (Generator $breadcrumbs, $subTitle) { $breadcrumbs->parent('categories.index'); $breadcrumbs->push($subTitle, route('categories.noCategory')); } @@ -164,20 +164,20 @@ Breadcrumbs::register( // currencies. Breadcrumbs::register( - 'currency.index', function(Generator $breadcrumbs) { + 'currency.index', function (Generator $breadcrumbs) { $breadcrumbs->parent('home'); $breadcrumbs->push(trans('breadcrumbs.currencies'), route('currency.index')); } ); Breadcrumbs::register( - 'currency.edit', function(Generator $breadcrumbs, TransactionCurrency $currency) { + 'currency.edit', function (Generator $breadcrumbs, TransactionCurrency $currency) { $breadcrumbs->parent('currency.index'); $breadcrumbs->push(trans('breadcrumbs.edit_currency', ['name' => e($currency->name)]), route('currency.edit', [$currency->id])); } ); Breadcrumbs::register( - 'currency.delete', function(Generator $breadcrumbs, TransactionCurrency $currency) { + 'currency.delete', function (Generator $breadcrumbs, TransactionCurrency $currency) { $breadcrumbs->parent('currency.index'); $breadcrumbs->push(trans('breadcrumbs.delete_currency', ['name' => e($currency->name)]), route('currency.delete', [$currency->id])); } @@ -186,33 +186,33 @@ Breadcrumbs::register( // piggy banks Breadcrumbs::register( - 'piggy-banks.index', function(Generator $breadcrumbs) { + 'piggy-banks.index', function (Generator $breadcrumbs) { $breadcrumbs->parent('home'); $breadcrumbs->push(trans('breadcrumbs.piggyBanks'), route('piggy-banks.index')); } ); Breadcrumbs::register( - 'piggy-banks.create', function(Generator $breadcrumbs) { + 'piggy-banks.create', function (Generator $breadcrumbs) { $breadcrumbs->parent('piggy-banks.index'); $breadcrumbs->push(trans('breadcrumbs.newPiggyBank'), route('piggy-banks.create')); } ); Breadcrumbs::register( - 'piggy-banks.edit', function(Generator $breadcrumbs, PiggyBank $piggyBank) { + 'piggy-banks.edit', function (Generator $breadcrumbs, PiggyBank $piggyBank) { $breadcrumbs->parent('piggy-banks.show', $piggyBank); $breadcrumbs->push(trans('breadcrumbs.edit_piggyBank', ['name' => e($piggyBank->name)]), route('piggy-banks.edit', [$piggyBank->id])); } ); Breadcrumbs::register( - 'piggy-banks.delete', function(Generator $breadcrumbs, PiggyBank $piggyBank) { + 'piggy-banks.delete', function (Generator $breadcrumbs, PiggyBank $piggyBank) { $breadcrumbs->parent('piggy-banks.show', $piggyBank); $breadcrumbs->push(trans('breadcrumbs.delete_piggyBank', ['name' => e($piggyBank->name)]), route('piggy-banks.delete', [$piggyBank->id])); } ); Breadcrumbs::register( - 'piggy-banks.show', function(Generator $breadcrumbs, PiggyBank $piggyBank) { + 'piggy-banks.show', function (Generator $breadcrumbs, PiggyBank $piggyBank) { $breadcrumbs->parent('piggy-banks.index'); $breadcrumbs->push(e($piggyBank->name), route('piggy-banks.show', [$piggyBank->id])); @@ -221,7 +221,7 @@ Breadcrumbs::register( // preferences Breadcrumbs::register( - 'preferences', function(Generator $breadcrumbs) { + 'preferences', function (Generator $breadcrumbs) { $breadcrumbs->parent('home'); $breadcrumbs->push(trans('breadcrumbs.preferences'), route('preferences')); @@ -230,14 +230,14 @@ Breadcrumbs::register( // profile Breadcrumbs::register( - 'profile', function(Generator $breadcrumbs) { + 'profile', function (Generator $breadcrumbs) { $breadcrumbs->parent('home'); $breadcrumbs->push(trans('breadcrumbs.profile'), route('profile')); } ); Breadcrumbs::register( - 'change-password', function(Generator $breadcrumbs) { + 'change-password', function (Generator $breadcrumbs) { $breadcrumbs->parent('profile'); $breadcrumbs->push(trans('breadcrumbs.changePassword'), route('change-password')); @@ -246,33 +246,33 @@ Breadcrumbs::register( // bills Breadcrumbs::register( - 'bills.index', function(Generator $breadcrumbs) { + 'bills.index', function (Generator $breadcrumbs) { $breadcrumbs->parent('home'); $breadcrumbs->push(trans('breadcrumbs.bills'), route('bills.index')); } ); Breadcrumbs::register( - 'bills.create', function(Generator $breadcrumbs) { + 'bills.create', function (Generator $breadcrumbs) { $breadcrumbs->parent('bills.index'); $breadcrumbs->push(trans('breadcrumbs.newBill'), route('bills.create')); } ); Breadcrumbs::register( - 'bills.edit', function(Generator $breadcrumbs, Bill $bill) { + 'bills.edit', function (Generator $breadcrumbs, Bill $bill) { $breadcrumbs->parent('bills.show', $bill); $breadcrumbs->push(trans('breadcrumbs.edit_bill', ['name' => e($bill->name)]), route('bills.edit', [$bill->id])); } ); Breadcrumbs::register( - 'bills.delete', function(Generator $breadcrumbs, Bill $bill) { + 'bills.delete', function (Generator $breadcrumbs, Bill $bill) { $breadcrumbs->parent('bills.show', $bill); $breadcrumbs->push(trans('breadcrumbs.delete_bill', ['name' => e($bill->name)]), route('bills.delete', [$bill->id])); } ); Breadcrumbs::register( - 'bills.show', function(Generator $breadcrumbs, Bill $bill) { + 'bills.show', function (Generator $breadcrumbs, Bill $bill) { $breadcrumbs->parent('bills.index'); $breadcrumbs->push(e($bill->name), route('bills.show', [$bill->id])); @@ -281,7 +281,7 @@ Breadcrumbs::register( // reminders Breadcrumbs::register( - 'reminders.index', function(Generator $breadcrumbs) { + 'reminders.index', function (Generator $breadcrumbs) { $breadcrumbs->parent('home'); $breadcrumbs->push(trans('breadcrumbs.reminders'), route('reminders.index')); @@ -290,7 +290,7 @@ Breadcrumbs::register( // reminders Breadcrumbs::register( - 'reminders.show', function(Generator $breadcrumbs, Reminder $reminder) { + 'reminders.show', function (Generator $breadcrumbs, Reminder $reminder) { $breadcrumbs->parent('reminders.index'); $breadcrumbs->push(trans('breadcrumbs.reminder', ['id' => e($reminder->id)]), route('reminders.show', [$reminder->id])); @@ -300,14 +300,14 @@ Breadcrumbs::register( // reports Breadcrumbs::register( - 'reports.index', function(Generator $breadcrumbs) { + 'reports.index', function (Generator $breadcrumbs) { $breadcrumbs->parent('home'); $breadcrumbs->push(trans('breadcrumbs.reports'), route('reports.index')); } ); Breadcrumbs::register( - 'reports.year', function(Generator $breadcrumbs, Carbon $date, $shared) { + 'reports.year', function (Generator $breadcrumbs, Carbon $date, $shared) { $breadcrumbs->parent('reports.index'); if ($shared) { $title = trans('breadcrumbs.yearly_report_shared', ['date' => $date->year]); @@ -319,7 +319,7 @@ Breadcrumbs::register( ); Breadcrumbs::register( - 'reports.month', function(Generator $breadcrumbs, Carbon $date, $shared) { + 'reports.month', function (Generator $breadcrumbs, Carbon $date, $shared) { $breadcrumbs->parent('reports.year', $date, $shared); if ($shared) { @@ -334,7 +334,7 @@ Breadcrumbs::register( // search Breadcrumbs::register( - 'search', function(Generator $breadcrumbs, $query) { + 'search', function (Generator $breadcrumbs, $query) { $breadcrumbs->parent('home'); $breadcrumbs->push(trans('breadcrumbs.searchResult', ['query' => e($query)]), route('search')); } @@ -342,33 +342,33 @@ Breadcrumbs::register( // transactions Breadcrumbs::register( - 'transactions.index', function(Generator $breadcrumbs, $what) { + 'transactions.index', function (Generator $breadcrumbs, $what) { $breadcrumbs->parent('home'); $breadcrumbs->push(trans('breadcrumbs.' . $what . '_list'), route('transactions.index', [$what])); } ); Breadcrumbs::register( - 'transactions.create', function(Generator $breadcrumbs, $what) { + 'transactions.create', function (Generator $breadcrumbs, $what) { $breadcrumbs->parent('transactions.index', $what); $breadcrumbs->push(trans('breadcrumbs.create_' . e($what)), route('transactions.create', [$what])); } ); Breadcrumbs::register( - 'transactions.edit', function(Generator $breadcrumbs, TransactionJournal $journal) { + 'transactions.edit', function (Generator $breadcrumbs, TransactionJournal $journal) { $breadcrumbs->parent('transactions.show', $journal); $breadcrumbs->push(trans('breadcrumbs.edit_journal', ['description' => $journal->description]), route('transactions.edit', [$journal->id])); } ); Breadcrumbs::register( - 'transactions.delete', function(Generator $breadcrumbs, TransactionJournal $journal) { + 'transactions.delete', function (Generator $breadcrumbs, TransactionJournal $journal) { $breadcrumbs->parent('transactions.show', $journal); $breadcrumbs->push(trans('breadcrumbs.delete_journal', ['description' => e($journal->description)]), route('transactions.delete', [$journal->id])); } ); Breadcrumbs::register( - 'transactions.show', function(Generator $breadcrumbs, TransactionJournal $journal) { + 'transactions.show', function (Generator $breadcrumbs, TransactionJournal $journal) { $breadcrumbs->parent('transactions.index', strtolower($journal->transactionType->type)); $breadcrumbs->push($journal->description, route('transactions.show', [$journal->id])); @@ -378,28 +378,28 @@ Breadcrumbs::register( // tags Breadcrumbs::register( - 'tags.index', function(Generator $breadcrumbs) { + 'tags.index', function (Generator $breadcrumbs) { $breadcrumbs->parent('home'); $breadcrumbs->push(trans('breadcrumbs.tags'), route('tags.index')); } ); Breadcrumbs::register( - 'tags.create', function(Generator $breadcrumbs) { + 'tags.create', function (Generator $breadcrumbs) { $breadcrumbs->parent('tags.index'); $breadcrumbs->push(trans('breadcrumbs.createTag'), route('tags.create')); } ); Breadcrumbs::register( - 'tags.edit', function(Generator $breadcrumbs, Tag $tag) { + 'tags.edit', function (Generator $breadcrumbs, Tag $tag) { $breadcrumbs->parent('tags.show', $tag); $breadcrumbs->push(trans('breadcrumbs.edit_tag', ['tag' => e($tag->tag)]), route('tags.edit', [$tag->id])); } ); Breadcrumbs::register( - 'tags.delete', function(Generator $breadcrumbs, Tag $tag) { + 'tags.delete', function (Generator $breadcrumbs, Tag $tag) { $breadcrumbs->parent('tags.show', $tag); $breadcrumbs->push(trans('breadcrumbs.delete_tag', ['tag' => e($tag->tag)]), route('tags.delete', [$tag->id])); } @@ -407,7 +407,7 @@ Breadcrumbs::register( Breadcrumbs::register( - 'tags.show', function(Generator $breadcrumbs, Tag $tag) { + 'tags.show', function (Generator $breadcrumbs, Tag $tag) { $breadcrumbs->parent('tags.index'); $breadcrumbs->push(e($tag->tag), route('tags.show', [$tag->id])); } diff --git a/app/Models/Account.php b/app/Models/Account.php index c621afca8e..5453a136a1 100644 --- a/app/Models/Account.php +++ b/app/Models/Account.php @@ -11,22 +11,22 @@ use Watson\Validating\ValidatingTrait; * Class Account * * @package FireflyIII\Models - * @property integer $id - * @property \Carbon\Carbon $created_at - * @property \Carbon\Carbon $updated_at - * @property \Carbon\Carbon $deleted_at - * @property integer $user_id - * @property integer $account_type_id - * @property string $name - * @property boolean $active - * @property boolean $encrypted - * @property float $virtual_balance - * @property string $virtual_balance_encrypted + * @property integer $id + * @property \Carbon\Carbon $created_at + * @property \Carbon\Carbon $updated_at + * @property \Carbon\Carbon $deleted_at + * @property integer $user_id + * @property integer $account_type_id + * @property string $name + * @property boolean $active + * @property boolean $encrypted + * @property float $virtual_balance + * @property string $virtual_balance_encrypted * @property-read \Illuminate\Database\Eloquent\Collection|\FireflyIII\Models\AccountMeta[] $accountMeta - * @property-read \FireflyIII\Models\AccountType $accountType - * @property-read \Illuminate\Database\Eloquent\Collection|\FireflyIII\Models\PiggyBank[] $piggyBanks + * @property-read \FireflyIII\Models\AccountType $accountType + * @property-read \Illuminate\Database\Eloquent\Collection|\FireflyIII\Models\PiggyBank[] $piggyBanks * @property-read \Illuminate\Database\Eloquent\Collection|\FireflyIII\Models\Transaction[] $transactions - * @property-read \FireflyIII\User $user + * @property-read \FireflyIII\User $user * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Account whereId($value) * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Account whereCreatedAt($value) * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Account whereUpdatedAt($value) @@ -40,12 +40,12 @@ use Watson\Validating\ValidatingTrait; * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Account whereVirtualBalanceEncrypted($value) * @method static \FireflyIII\Models\Account accountTypeIn($types) * @method static \FireflyIII\Models\Account hasMetaValue($name, $value) - * @property boolean joinedAccountTypes - * @property mixed startBalance - * @property mixed endBalance - * @property mixed lastActivityDate - * @property mixed piggyBalance - * @property mixed difference + * @property boolean joinedAccountTypes + * @property mixed startBalance + * @property mixed endBalance + * @property mixed lastActivityDate + * @property mixed piggyBalance + * @property mixed difference * @propery mixed percentage * */ @@ -216,7 +216,7 @@ class Account extends Model { $joinName = str_replace('.', '_', $name); $query->leftJoin( - 'account_meta as ' . $joinName, function(JoinClause $join) use ($joinName, $name) { + 'account_meta as ' . $joinName, function (JoinClause $join) use ($joinName, $name) { $join->on($joinName . '.account_id', '=', 'accounts.id')->where($joinName . '.name', '=', $name); } ); diff --git a/app/Models/AccountMeta.php b/app/Models/AccountMeta.php index f3ec8dfb60..279fe60765 100644 --- a/app/Models/AccountMeta.php +++ b/app/Models/AccountMeta.php @@ -6,14 +6,14 @@ use Watson\Validating\ValidatingTrait; /** * Class AccountMeta * - * @codeCoverageIgnore + * @codeCoverageIgnore * @package FireflyIII\Models - * @property integer $id - * @property \Carbon\Carbon $created_at - * @property \Carbon\Carbon $updated_at - * @property integer $account_id - * @property string $name - * @property string $data + * @property integer $id + * @property \Carbon\Carbon $created_at + * @property \Carbon\Carbon $updated_at + * @property integer $account_id + * @property string $name + * @property string $data * @property-read \FireflyIII\Models\Account $account * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\AccountMeta whereId($value) * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\AccountMeta whereCreatedAt($value) @@ -33,7 +33,7 @@ class AccountMeta extends Model 'name' => 'required|between:1,100', 'data' => 'required' ]; - protected $table = 'account_meta'; + protected $table = 'account_meta'; /** * diff --git a/app/Models/AccountType.php b/app/Models/AccountType.php index 10c10a1ef4..2148b9e961 100644 --- a/app/Models/AccountType.php +++ b/app/Models/AccountType.php @@ -5,13 +5,13 @@ use Illuminate\Database\Eloquent\Model; /** * Class AccountType * - * @codeCoverageIgnore + * @codeCoverageIgnore * @package FireflyIII\Models - * @property integer $id - * @property \Carbon\Carbon $created_at - * @property \Carbon\Carbon $updated_at - * @property string $type - * @property boolean $editable + * @property integer $id + * @property \Carbon\Carbon $created_at + * @property \Carbon\Carbon $updated_at + * @property string $type + * @property boolean $editable * @property-read \Illuminate\Database\Eloquent\Collection|\FireflyIII\Models\Account[] $accounts * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\AccountType whereId($value) * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\AccountType whereCreatedAt($value) diff --git a/app/Models/Bill.php b/app/Models/Bill.php index 70fab19668..a1b048e99a 100644 --- a/app/Models/Bill.php +++ b/app/Models/Bill.php @@ -7,26 +7,26 @@ use Illuminate\Database\Eloquent\Model; * FireflyIII\Models\Bill * * @codeCoverageIgnore Class Bill - * @package FireflyIII\Models - * @property integer $id - * @property \Carbon\Carbon $created_at - * @property \Carbon\Carbon $updated_at - * @property integer $user_id - * @property string $name - * @property string $match - * @property float $amount_min - * @property string $amount_min_encrypted - * @property float $amount_max - * @property string $amount_max_encrypted - * @property \Carbon\Carbon $date - * @property boolean $active - * @property boolean $automatch - * @property string $repeat_freq - * @property integer $skip - * @property boolean $name_encrypted - * @property boolean $match_encrypted + * @package FireflyIII\Models + * @property integer $id + * @property \Carbon\Carbon $created_at + * @property \Carbon\Carbon $updated_at + * @property integer $user_id + * @property string $name + * @property string $match + * @property float $amount_min + * @property string $amount_min_encrypted + * @property float $amount_max + * @property string $amount_max_encrypted + * @property \Carbon\Carbon $date + * @property boolean $active + * @property boolean $automatch + * @property string $repeat_freq + * @property integer $skip + * @property boolean $name_encrypted + * @property boolean $match_encrypted * @property-read \Illuminate\Database\Eloquent\Collection|\FireflyIII\Models\TransactionJournal[] $transactionjournals - * @property-read \FireflyIII\User $user + * @property-read \FireflyIII\User $user * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Bill whereId($value) * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Bill whereCreatedAt($value) * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Bill whereUpdatedAt($value) @@ -44,14 +44,14 @@ use Illuminate\Database\Eloquent\Model; * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Bill whereSkip($value) * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Bill whereNameEncrypted($value) * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Bill whereMatchEncrypted($value) - * @property mixed nextExpectedMatch - * @property mixed lastFoundMatch + * @property mixed nextExpectedMatch + * @property mixed lastFoundMatch */ class Bill extends Model { protected $fillable - = ['name', 'match', 'amount_min', 'match_encrypted', 'name_encrypted', 'user_id', 'amount_max', 'date', 'repeat_freq', 'skip', 'automatch', 'active', ]; + = ['name', 'match', 'amount_min', 'match_encrypted', 'name_encrypted', 'user_id', 'amount_max', 'date', 'repeat_freq', 'skip', 'automatch', 'active',]; protected $hidden = ['amount_min_encrypted', 'amount_max_encrypted', 'name_encrypted', 'match_encrypted']; diff --git a/app/Models/Budget.php b/app/Models/Budget.php index 7de89a558e..02f1e46808 100644 --- a/app/Models/Budget.php +++ b/app/Models/Budget.php @@ -7,19 +7,19 @@ use Illuminate\Database\Eloquent\SoftDeletes; /** * Class Budget * - * @codeCoverageIgnore + * @codeCoverageIgnore * @package FireflyIII\Models - * @property integer $id - * @property \Carbon\Carbon $created_at - * @property \Carbon\Carbon $updated_at - * @property \Carbon\Carbon $deleted_at - * @property string $name - * @property integer $user_id - * @property boolean $active - * @property boolean $encrypted - * @property-read \Illuminate\Database\Eloquent\Collection|\FireflyIII\Models\BudgetLimit[] $budgetlimits + * @property integer $id + * @property \Carbon\Carbon $created_at + * @property \Carbon\Carbon $updated_at + * @property \Carbon\Carbon $deleted_at + * @property string $name + * @property integer $user_id + * @property boolean $active + * @property boolean $encrypted + * @property-read \Illuminate\Database\Eloquent\Collection|\FireflyIII\Models\BudgetLimit[] $budgetlimits * @property-read \Illuminate\Database\Eloquent\Collection|\FireflyIII\Models\TransactionJournal[] $transactionjournals - * @property-read \FireflyIII\User $user + * @property-read \FireflyIII\User $user * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Budget whereId($value) * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Budget whereCreatedAt($value) * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Budget whereUpdatedAt($value) diff --git a/app/Models/BudgetLimit.php b/app/Models/BudgetLimit.php index 921f37d9db..42e72dc502 100644 --- a/app/Models/BudgetLimit.php +++ b/app/Models/BudgetLimit.php @@ -5,18 +5,18 @@ use Illuminate\Database\Eloquent\Model; /** * Class BudgetLimit * - * @codeCoverageIgnore + * @codeCoverageIgnore * @package FireflyIII\Models - * @property integer $id - * @property \Carbon\Carbon $created_at - * @property \Carbon\Carbon $updated_at - * @property integer $budget_id - * @property \Carbon\Carbon $startdate - * @property float $amount - * @property string $amount_encrypted - * @property boolean $repeats - * @property string $repeat_freq - * @property-read \FireflyIII\Models\Budget $budget + * @property integer $id + * @property \Carbon\Carbon $created_at + * @property \Carbon\Carbon $updated_at + * @property integer $budget_id + * @property \Carbon\Carbon $startdate + * @property float $amount + * @property string $amount_encrypted + * @property boolean $repeats + * @property string $repeat_freq + * @property-read \FireflyIII\Models\Budget $budget * @property-read \Illuminate\Database\Eloquent\Collection|\FireflyIII\Models\LimitRepetition[] $limitrepetitions * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\BudgetLimit whereId($value) * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\BudgetLimit whereCreatedAt($value) diff --git a/app/Models/Category.php b/app/Models/Category.php index 3497fd9dc6..dc4f7cbbff 100644 --- a/app/Models/Category.php +++ b/app/Models/Category.php @@ -8,15 +8,15 @@ use Illuminate\Database\Eloquent\SoftDeletes; * Class Category * * @package FireflyIII\Models - * @property integer $id - * @property \Carbon\Carbon $created_at - * @property \Carbon\Carbon $updated_at - * @property \Carbon\Carbon $deleted_at - * @property string $name - * @property integer $user_id - * @property boolean $encrypted + * @property integer $id + * @property \Carbon\Carbon $created_at + * @property \Carbon\Carbon $updated_at + * @property \Carbon\Carbon $deleted_at + * @property string $name + * @property integer $user_id + * @property boolean $encrypted * @property-read \Illuminate\Database\Eloquent\Collection|\FireflyIII\Models\TransactionJournal[] $transactionjournals - * @property-read \FireflyIII\User $user + * @property-read \FireflyIII\User $user * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Category whereId($value) * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Category whereCreatedAt($value) * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Category whereUpdatedAt($value) @@ -24,8 +24,8 @@ use Illuminate\Database\Eloquent\SoftDeletes; * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Category whereName($value) * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Category whereUserId($value) * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Category whereEncrypted($value) - * @property mixed spent - * @property mixed lastActivity + * @property mixed spent + * @property mixed lastActivity */ class Category extends Model { diff --git a/app/Models/Component.php b/app/Models/Component.php index ac43425ad7..84686751be 100644 --- a/app/Models/Component.php +++ b/app/Models/Component.php @@ -6,15 +6,15 @@ use Illuminate\Database\Eloquent\SoftDeletes; /** * Class Component * - * @codeCoverageIgnore + * @codeCoverageIgnore * @package FireflyIII\Models - * @property integer $id + * @property integer $id * @property \Carbon\Carbon $created_at * @property \Carbon\Carbon $updated_at * @property \Carbon\Carbon $deleted_at - * @property string $name - * @property integer $user_id - * @property string $class + * @property string $name + * @property integer $user_id + * @property string $class * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Component whereId($value) * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Component whereCreatedAt($value) * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Component whereUpdatedAt($value) diff --git a/app/Models/LimitRepetition.php b/app/Models/LimitRepetition.php index 1adffb5e18..d5fd692dae 100644 --- a/app/Models/LimitRepetition.php +++ b/app/Models/LimitRepetition.php @@ -5,16 +5,16 @@ use Illuminate\Database\Eloquent\Model; /** * Class LimitRepetition * - * @codeCoverageIgnore + * @codeCoverageIgnore * @package FireflyIII\Models - * @property integer $id - * @property \Carbon\Carbon $created_at - * @property \Carbon\Carbon $updated_at - * @property integer $budget_limit_id - * @property \Carbon\Carbon $startdate - * @property \Carbon\Carbon $enddate - * @property float $amount - * @property string $amount_encrypted + * @property integer $id + * @property \Carbon\Carbon $created_at + * @property \Carbon\Carbon $updated_at + * @property integer $budget_limit_id + * @property \Carbon\Carbon $startdate + * @property \Carbon\Carbon $enddate + * @property float $amount + * @property string $amount_encrypted * @property-read \FireflyIII\Models\BudgetLimit $budgetLimit * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\LimitRepetition whereId($value) * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\LimitRepetition whereCreatedAt($value) diff --git a/app/Models/PiggyBank.php b/app/Models/PiggyBank.php index a08241d1a1..44c05fa63b 100644 --- a/app/Models/PiggyBank.php +++ b/app/Models/PiggyBank.php @@ -7,27 +7,27 @@ use Illuminate\Database\Eloquent\SoftDeletes; /** * Class PiggyBank * - * @codeCoverageIgnore + * @codeCoverageIgnore * @package FireflyIII\Models - * @property integer $id - * @property \Carbon\Carbon $created_at - * @property \Carbon\Carbon $updated_at - * @property \Carbon\Carbon $deleted_at - * @property integer $account_id - * @property string $name - * @property float $targetamount - * @property string $targetamount_encrypted - * @property \Carbon\Carbon $startdate - * @property \Carbon\Carbon $targetdate - * @property string $reminder - * @property integer $reminder_skip - * @property boolean $remind_me - * @property integer $order - * @property boolean $encrypted - * @property-read \FireflyIII\Models\Account $account + * @property integer $id + * @property \Carbon\Carbon $created_at + * @property \Carbon\Carbon $updated_at + * @property \Carbon\Carbon $deleted_at + * @property integer $account_id + * @property string $name + * @property float $targetamount + * @property string $targetamount_encrypted + * @property \Carbon\Carbon $startdate + * @property \Carbon\Carbon $targetdate + * @property string $reminder + * @property integer $reminder_skip + * @property boolean $remind_me + * @property integer $order + * @property boolean $encrypted + * @property-read \FireflyIII\Models\Account $account * @property-read \Illuminate\Database\Eloquent\Collection|\FireflyIII\Models\PiggyBankRepetition[] $piggyBankRepetitions - * @property-read \Illuminate\Database\Eloquent\Collection|\FireflyIII\Models\PiggyBankEvent[] $piggyBankEvents - * @property-read \Illuminate\Database\Eloquent\Collection|\FireflyIII\Models\Reminder[] $reminders + * @property-read \Illuminate\Database\Eloquent\Collection|\FireflyIII\Models\PiggyBankEvent[] $piggyBankEvents + * @property-read \Illuminate\Database\Eloquent\Collection|\FireflyIII\Models\Reminder[] $reminders * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\PiggyBank whereId($value) * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\PiggyBank whereCreatedAt($value) * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\PiggyBank whereUpdatedAt($value) @@ -43,14 +43,14 @@ use Illuminate\Database\Eloquent\SoftDeletes; * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\PiggyBank whereRemindMe($value) * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\PiggyBank whereOrder($value) * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\PiggyBank whereEncrypted($value) - * @property PiggyBankRepetition currentRep + * @property PiggyBankRepetition currentRep */ class PiggyBank extends Model { use SoftDeletes; protected $fillable - = ['name', 'account_id', 'order', 'reminder_skip', 'targetamount', 'startdate', 'targetdate', 'reminder', 'remind_me']; + = ['name', 'account_id', 'order', 'reminder_skip', 'targetamount', 'startdate', 'targetdate', 'reminder', 'remind_me']; protected $hidden = ['targetamount_encrypted', 'encrypted']; /** diff --git a/app/Models/PiggyBankEvent.php b/app/Models/PiggyBankEvent.php index 2c03dadace..6b9bdceda1 100644 --- a/app/Models/PiggyBankEvent.php +++ b/app/Models/PiggyBankEvent.php @@ -5,17 +5,17 @@ use Illuminate\Database\Eloquent\Model; /** * Class PiggyBankEvent * - * @codeCoverageIgnore + * @codeCoverageIgnore * @package FireflyIII\Models - * @property integer $id - * @property \Carbon\Carbon $created_at - * @property \Carbon\Carbon $updated_at - * @property integer $piggy_bank_id - * @property integer $transaction_journal_id - * @property \Carbon\Carbon $date - * @property float $amount - * @property string $amount_encrypted - * @property-read \FireflyIII\Models\PiggyBank $piggyBank + * @property integer $id + * @property \Carbon\Carbon $created_at + * @property \Carbon\Carbon $updated_at + * @property integer $piggy_bank_id + * @property integer $transaction_journal_id + * @property \Carbon\Carbon $date + * @property float $amount + * @property string $amount_encrypted + * @property-read \FireflyIII\Models\PiggyBank $piggyBank * @property-read \FireflyIII\Models\TransactionJournal $transactionJournal * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\PiggyBankEvent whereId($value) * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\PiggyBankEvent whereCreatedAt($value) diff --git a/app/Models/PiggyBankRepetition.php b/app/Models/PiggyBankRepetition.php index 699b712c25..a24066f2ee 100644 --- a/app/Models/PiggyBankRepetition.php +++ b/app/Models/PiggyBankRepetition.php @@ -7,16 +7,16 @@ use Illuminate\Database\Eloquent\Model; /** * Class PiggyBankRepetition * - * @codeCoverageIgnore + * @codeCoverageIgnore * @package FireflyIII\Models - * @property integer $id - * @property \Carbon\Carbon $created_at - * @property \Carbon\Carbon $updated_at - * @property integer $piggy_bank_id - * @property \Carbon\Carbon $startdate - * @property \Carbon\Carbon $targetdate - * @property float $currentamount - * @property string $currentamount_encrypted + * @property integer $id + * @property \Carbon\Carbon $created_at + * @property \Carbon\Carbon $updated_at + * @property integer $piggy_bank_id + * @property \Carbon\Carbon $startdate + * @property \Carbon\Carbon $targetdate + * @property float $currentamount + * @property string $currentamount_encrypted * @property-read \FireflyIII\Models\PiggyBank $piggyBank * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\PiggyBankRepetition whereId($value) * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\PiggyBankRepetition whereCreatedAt($value) @@ -77,13 +77,13 @@ class PiggyBankRepetition extends Model $q->orWhereNull('startdate'); } ) - ->where( - function (EloquentBuilder $q) use ($date) { + ->where( + function (EloquentBuilder $q) use ($date) { - $q->where('targetdate', '>=', $date->format('Y-m-d 00:00:00')); - $q->orWhereNull('targetdate'); - } - ); + $q->where('targetdate', '>=', $date->format('Y-m-d 00:00:00')); + $q->orWhereNull('targetdate'); + } + ); } /** diff --git a/app/Models/Preference.php b/app/Models/Preference.php index a25fd850e6..3f22c4330d 100644 --- a/app/Models/Preference.php +++ b/app/Models/Preference.php @@ -6,16 +6,16 @@ use Illuminate\Database\Eloquent\Model; /** * Class Preference * - * @codeCoverageIgnore + * @codeCoverageIgnore * @package FireflyIII\Models - * @property integer $id - * @property \Carbon\Carbon $created_at - * @property \Carbon\Carbon $updated_at - * @property integer $user_id - * @property string $name - * @property string $name_encrypted - * @property string $data - * @property string $data_encrypted + * @property integer $id + * @property \Carbon\Carbon $created_at + * @property \Carbon\Carbon $updated_at + * @property integer $user_id + * @property string $name + * @property string $name_encrypted + * @property string $data + * @property string $data_encrypted * @property-read \FireflyIII\User $user * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Preference whereId($value) * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Preference whereCreatedAt($value) diff --git a/app/Models/Reminder.php b/app/Models/Reminder.php index 99baf19835..b4797dae8d 100644 --- a/app/Models/Reminder.php +++ b/app/Models/Reminder.php @@ -8,21 +8,21 @@ use Illuminate\Database\Eloquent\Model; /** * Class Reminder * - * @codeCoverageIgnore + * @codeCoverageIgnore * @package FireflyIII\Models - * @property integer $id - * @property \Carbon\Carbon $created_at - * @property \Carbon\Carbon $updated_at - * @property integer $user_id - * @property \Carbon\Carbon $startdate - * @property \Carbon\Carbon $enddate - * @property boolean $active - * @property boolean $notnow - * @property integer $remindersable_id - * @property string $remindersable_type - * @property string $metadata - * @property boolean $encrypted - * @property-read \ $remindersable + * @property integer $id + * @property \Carbon\Carbon $created_at + * @property \Carbon\Carbon $updated_at + * @property integer $user_id + * @property \Carbon\Carbon $startdate + * @property \Carbon\Carbon $enddate + * @property boolean $active + * @property boolean $notnow + * @property integer $remindersable_id + * @property string $remindersable_type + * @property string $metadata + * @property boolean $encrypted + * @property-read \ $remindersable * @property-read \FireflyIII\User $user * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Reminder whereId($value) * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Reminder whereCreatedAt($value) @@ -38,13 +38,13 @@ use Illuminate\Database\Eloquent\Model; * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Reminder whereEncrypted($value) * @method static \FireflyIII\Models\Reminder onDates($start, $end) * @method static \FireflyIII\Models\Reminder today() - * @property string description + * @property string description */ class Reminder extends Model { - protected $fillable = ['user_id', 'startdate', 'metadata', 'enddate', 'active', 'notnow', 'remindersable_id', 'remindersable_type', ]; + protected $fillable = ['user_id', 'startdate', 'metadata', 'enddate', 'active', 'notnow', 'remindersable_id', 'remindersable_type',]; protected $hidden = ['encrypted']; /** @@ -124,7 +124,7 @@ class Reminder extends Model $today = new Carbon; return $query->where('startdate', '<=', $today->format('Y-m-d 00:00:00'))->where('enddate', '>=', $today->format('Y-m-d 00:00:00'))->where('active', 1) - ->where('notnow', 0); + ->where('notnow', 0); } /** diff --git a/app/Models/Tag.php b/app/Models/Tag.php index 0fb6a9c876..7018ecc8fa 100644 --- a/app/Models/Tag.php +++ b/app/Models/Tag.php @@ -10,20 +10,20 @@ use Watson\Validating\ValidatingTrait; * Class Tag * * @package FireflyIII\Models - * @property integer $id - * @property \Carbon\Carbon $created_at - * @property \Carbon\Carbon $updated_at - * @property string $deleted_at - * @property integer $user_id - * @property string $tag - * @property string $tagMode - * @property \Carbon\Carbon $date - * @property string $description - * @property float $latitude - * @property float $longitude - * @property integer $zoomLevel + * @property integer $id + * @property \Carbon\Carbon $created_at + * @property \Carbon\Carbon $updated_at + * @property string $deleted_at + * @property integer $user_id + * @property string $tag + * @property string $tagMode + * @property \Carbon\Carbon $date + * @property string $description + * @property float $latitude + * @property float $longitude + * @property integer $zoomLevel * @property-read \Illuminate\Database\Eloquent\Collection|\FireflyIII\Models\TransactionJournal[] $transactionjournals - * @property-read \FireflyIII\User $user + * @property-read \FireflyIII\User $user * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Tag whereId($value) * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Tag whereCreatedAt($value) * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Tag whereUpdatedAt($value) diff --git a/app/Models/Transaction.php b/app/Models/Transaction.php index 827f6958e3..26ca48ef45 100644 --- a/app/Models/Transaction.php +++ b/app/Models/Transaction.php @@ -9,18 +9,18 @@ use Watson\Validating\ValidatingTrait; /** * Class Transaction * - * @codeCoverageIgnore + * @codeCoverageIgnore * @package FireflyIII\Models - * @property integer $id - * @property \Carbon\Carbon $created_at - * @property \Carbon\Carbon $updated_at - * @property \Carbon\Carbon $deleted_at - * @property integer $account_id - * @property integer $transaction_journal_id - * @property string $description - * @property float $amount - * @property string $amount_encrypted - * @property-read \FireflyIII\Models\Account $account + * @property integer $id + * @property \Carbon\Carbon $created_at + * @property \Carbon\Carbon $updated_at + * @property \Carbon\Carbon $deleted_at + * @property integer $account_id + * @property integer $transaction_journal_id + * @property string $description + * @property float $amount + * @property string $amount_encrypted + * @property-read \FireflyIII\Models\Account $account * @property-read \FireflyIII\Models\TransactionJournal $transactionJournal * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Transaction whereId($value) * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Transaction whereCreatedAt($value) @@ -33,8 +33,8 @@ use Watson\Validating\ValidatingTrait; * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Transaction whereAmountEncrypted($value) * @method static \FireflyIII\Models\Transaction after($date) * @method static \FireflyIII\Models\Transaction before($date) - * @property mixed before - * @property mixed after + * @property mixed before + * @property mixed after */ class Transaction extends Model { diff --git a/app/Models/TransactionCurrency.php b/app/Models/TransactionCurrency.php index edc8797aca..27b21f36c3 100644 --- a/app/Models/TransactionCurrency.php +++ b/app/Models/TransactionCurrency.php @@ -6,15 +6,15 @@ use Illuminate\Database\Eloquent\SoftDeletes; /** * Class TransactionCurrency * - * @codeCoverageIgnore + * @codeCoverageIgnore * @package FireflyIII\Models - * @property integer $id - * @property \Carbon\Carbon $created_at - * @property \Carbon\Carbon $updated_at - * @property \Carbon\Carbon $deleted_at - * @property string $code - * @property string $name - * @property string $symbol + * @property integer $id + * @property \Carbon\Carbon $created_at + * @property \Carbon\Carbon $updated_at + * @property \Carbon\Carbon $deleted_at + * @property string $code + * @property string $name + * @property string $symbol * @property-read \Illuminate\Database\Eloquent\Collection|\FireflyIII\Models\TransactionJournal[] $transactionJournals * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\TransactionCurrency whereId($value) * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\TransactionCurrency whereCreatedAt($value) diff --git a/app/Models/TransactionGroup.php b/app/Models/TransactionGroup.php index 9ef702872c..bb41749ca2 100644 --- a/app/Models/TransactionGroup.php +++ b/app/Models/TransactionGroup.php @@ -6,16 +6,16 @@ use Illuminate\Database\Eloquent\SoftDeletes; /** * Class TransactionGroup * - * @codeCoverageIgnore + * @codeCoverageIgnore * @package FireflyIII\Models - * @property integer $id - * @property \Carbon\Carbon $created_at - * @property \Carbon\Carbon $updated_at - * @property \Carbon\Carbon $deleted_at - * @property integer $user_id - * @property string $relation + * @property integer $id + * @property \Carbon\Carbon $created_at + * @property \Carbon\Carbon $updated_at + * @property \Carbon\Carbon $deleted_at + * @property integer $user_id + * @property string $relation * @property-read \Illuminate\Database\Eloquent\Collection|\FireflyIII\Models\TransactionJournal[] $transactionjournals - * @property-read \FireflyIII\User $user + * @property-read \FireflyIII\User $user * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\TransactionGroup whereId($value) * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\TransactionGroup whereCreatedAt($value) * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\TransactionGroup whereUpdatedAt($value) diff --git a/app/Models/TransactionJournal.php b/app/Models/TransactionJournal.php index 60f76d1cbe..2248c31229 100644 --- a/app/Models/TransactionJournal.php +++ b/app/Models/TransactionJournal.php @@ -1,6 +1,5 @@ addProperty($this->id); - $prop->addProperty('amount'); - if ($prop->has()) { - return $prop->get(); + $cache = new CacheProperties(); + $cache->addProperty($this->id); + $cache->addProperty('amount'); + if ($cache->has()) { + return $cache->get(); } - $md5 = $prop->getMd5(); $amount = '0'; @@ -158,7 +156,7 @@ class TransactionJournal extends Model * If the journal has tags, it gets complicated. */ if ($this->tags->count() == 0) { - Cache::forever($md5, $amount); + $cache->store($amount); return $amount; } @@ -173,7 +171,7 @@ class TransactionJournal extends Model foreach ($others as $other) { $amount = bcsub($amount, $other->actual_amount); } - Cache::forever($md5, $amount); + $cache->store($amount); return $amount; } @@ -181,7 +179,7 @@ class TransactionJournal extends Model // if this journal is part of an advancePayment AND the journal is a deposit, // then the journal amount is correcting a withdrawal, and the amount is zero: if ($advancePayment && $this->transactionType->type == 'Deposit') { - Cache::forever($md5, '0'); + $cache->store('0'); return '0'; } @@ -196,14 +194,14 @@ class TransactionJournal extends Model $transfer = $balancingAct->transactionJournals()->transactionTypes(['Transfer'])->first(); if ($transfer) { $amount = bcsub($amount, $transfer->actual_amount); - Cache::forever($md5, $amount); + $cache->store($amount); return $amount; } } // @codeCoverageIgnore } // @codeCoverageIgnore - Cache::forever($md5, $amount); + $cache->store($amount); return $amount; } diff --git a/app/Models/TransactionRelation.php b/app/Models/TransactionRelation.php index 056d61fdd8..aa4d3810af 100644 --- a/app/Models/TransactionRelation.php +++ b/app/Models/TransactionRelation.php @@ -5,7 +5,7 @@ use Illuminate\Database\Eloquent\Model; /** * Class TransactionRelation * - * @codeCoverageIgnore + * @codeCoverageIgnore * @package FireflyIII\Models */ class TransactionRelation extends Model diff --git a/app/Models/TransactionType.php b/app/Models/TransactionType.php index 697b0e8432..098d5bcfc7 100644 --- a/app/Models/TransactionType.php +++ b/app/Models/TransactionType.php @@ -6,13 +6,13 @@ use Illuminate\Database\Eloquent\SoftDeletes; /** * Class TransactionType * - * @codeCoverageIgnore + * @codeCoverageIgnore * @package FireflyIII\Models - * @property integer $id - * @property \Carbon\Carbon $created_at - * @property \Carbon\Carbon $updated_at - * @property \Carbon\Carbon $deleted_at - * @property string $type + * @property integer $id + * @property \Carbon\Carbon $created_at + * @property \Carbon\Carbon $updated_at + * @property \Carbon\Carbon $deleted_at + * @property string $type * @property-read \Illuminate\Database\Eloquent\Collection|\FireflyIII\Models\TransactionJournal[] $transactionJournals * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\TransactionType whereId($value) * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\TransactionType whereCreatedAt($value) diff --git a/app/Providers/BusServiceProvider.php b/app/Providers/BusServiceProvider.php index 1eef3684d7..dc2e86ac21 100644 --- a/app/Providers/BusServiceProvider.php +++ b/app/Providers/BusServiceProvider.php @@ -23,7 +23,7 @@ class BusServiceProvider extends ServiceProvider public function boot(Dispatcher $dispatcher) { $dispatcher->mapUsing( - function($command) { + function ($command) { return Dispatcher::simpleMapping( $command, 'FireflyIII\Commands', 'FireflyIII\Handlers\Commands' ); diff --git a/app/Providers/EventServiceProvider.php b/app/Providers/EventServiceProvider.php index 3e01105bd5..9299f12fcb 100644 --- a/app/Providers/EventServiceProvider.php +++ b/app/Providers/EventServiceProvider.php @@ -52,12 +52,12 @@ class EventServiceProvider extends ServiceProvider $this->registerDeleteEvents(); $this->registerCreateEvents(); BudgetLimit::saved( - function(BudgetLimit $budgetLimit) { + function (BudgetLimit $budgetLimit) { $end = Navigation::addPeriod(clone $budgetLimit->startdate, $budgetLimit->repeat_freq, 0); $end->subDay(); $set = $budgetLimit->limitrepetitions()->where('startdate', $budgetLimit->startdate->format('Y-m-d'))->where('enddate', $end->format('Y-m-d')) - ->get(); + ->get(); if ($set->count() == 0) { $repetition = new LimitRepetition; $repetition->startdate = $budgetLimit->startdate; @@ -91,7 +91,7 @@ class EventServiceProvider extends ServiceProvider protected function registerDeleteEvents() { TransactionJournal::deleted( - function(TransactionJournal $journal) { + function (TransactionJournal $journal) { /** @var Transaction $transaction */ foreach ($journal->transactions()->get() as $transaction) { @@ -100,7 +100,7 @@ class EventServiceProvider extends ServiceProvider } ); PiggyBank::deleting( - function(PiggyBank $piggyBank) { + function (PiggyBank $piggyBank) { $reminders = $piggyBank->reminders()->get(); /** @var Reminder $reminder */ foreach ($reminders as $reminder) { @@ -110,7 +110,7 @@ class EventServiceProvider extends ServiceProvider ); Account::deleted( - function(Account $account) { + function (Account $account) { /** @var Transaction $transaction */ foreach ($account->transactions()->get() as $transaction) { @@ -131,7 +131,7 @@ class EventServiceProvider extends ServiceProvider // move this routine to a filter // in case of repeated piggy banks and/or other problems. PiggyBank::created( - function(PiggyBank $piggyBank) { + function (PiggyBank $piggyBank) { $repetition = new PiggyBankRepetition; $repetition->piggyBank()->associate($piggyBank); $repetition->startdate = is_null($piggyBank->startdate) ? null : $piggyBank->startdate; diff --git a/app/Providers/FireflyServiceProvider.php b/app/Providers/FireflyServiceProvider.php index ab5d1be9e5..eff456ea08 100644 --- a/app/Providers/FireflyServiceProvider.php +++ b/app/Providers/FireflyServiceProvider.php @@ -30,7 +30,7 @@ class FireflyServiceProvider extends ServiceProvider public function boot() { Validator::resolver( - function($translator, $data, $rules, $messages) { + function ($translator, $data, $rules, $messages) { return new FireflyValidator($translator, $data, $rules, $messages); } ); @@ -55,28 +55,28 @@ class FireflyServiceProvider extends ServiceProvider $this->app->bind( - 'preferences', function() { + 'preferences', function () { return new Preferences; } ); $this->app->bind( - 'navigation', function() { + 'navigation', function () { return new Navigation; } ); $this->app->bind( - 'amount', function() { + 'amount', function () { return new Amount; } ); $this->app->bind( - 'steam', function() { + 'steam', function () { return new Steam; } ); $this->app->bind( - 'expandedform', function() { + 'expandedform', function () { return new ExpandedForm; } ); diff --git a/app/Providers/RouteServiceProvider.php b/app/Providers/RouteServiceProvider.php index b95fa98635..4e40f5bec8 100644 --- a/app/Providers/RouteServiceProvider.php +++ b/app/Providers/RouteServiceProvider.php @@ -44,7 +44,7 @@ class RouteServiceProvider extends ServiceProvider public function map(Router $router) { $router->group( - ['namespace' => $this->namespace], function($router) { + ['namespace' => $this->namespace], function ($router) { /** @noinspection PhpIncludeInspection */ require app_path('Http/routes.php'); } diff --git a/app/Repositories/Account/AccountRepository.php b/app/Repositories/Account/AccountRepository.php index 352a89b756..15889ff5d7 100644 --- a/app/Repositories/Account/AccountRepository.php +++ b/app/Repositories/Account/AccountRepository.php @@ -4,7 +4,6 @@ namespace FireflyIII\Repositories\Account; use App; use Auth; -use Cache; use Carbon\Carbon; use Config; use DB; @@ -117,7 +116,6 @@ class AccountRepository implements AccountRepositoryInterface if ($cache->has()) { return $cache->get(); } - $md5 = $cache->getMd5(); if ($preference->data == []) { @@ -126,7 +124,7 @@ class AccountRepository implements AccountRepositoryInterface $accounts = Auth::user()->accounts()->whereIn('id', $preference->data)->orderBy('accounts.name', 'ASC')->get(['accounts.*']); } - Cache::forever($md5, $accounts); + $cache->store($accounts); return $accounts; } @@ -144,14 +142,13 @@ class AccountRepository implements AccountRepositoryInterface */ public function getFrontpageTransactions(Account $account, Carbon $start, Carbon $end) { - $prop = new CacheProperties(); - $prop->addProperty($account->id); - $prop->addProperty($start); - $prop->addProperty($end); - if ($prop->has()) { - return $prop->get(); + $cache = new CacheProperties(); + $cache->addProperty($account->id); + $cache->addProperty($start); + $cache->addProperty($end); + if ($cache->has()) { + return $cache->get(); } - $md5 = $prop->getMd5(); $set = Auth::user() ->transactionjournals() @@ -166,7 +163,7 @@ class AccountRepository implements AccountRepositoryInterface ->orderBy('transaction_journals.id', 'DESC') ->take(10) ->get(['transaction_journals.*', 'transaction_currencies.symbol', 'transaction_types.type']); - Cache::forever($md5, $set); + $cache->store($set); return $set; } @@ -238,7 +235,6 @@ class AccountRepository implements AccountRepositoryInterface if ($cache->has()) { return $cache->get(); } - $md5 = $cache->getMd5(); $ids = array_unique($ids); if (count($ids) > 0) { @@ -264,7 +260,7 @@ class AccountRepository implements AccountRepositoryInterface } ); - Cache::forever($md5, $accounts); + $cache->store($accounts); return $accounts; diff --git a/app/Repositories/Budget/BudgetRepository.php b/app/Repositories/Budget/BudgetRepository.php index efe12c2eab..bed615d4ad 100644 --- a/app/Repositories/Budget/BudgetRepository.php +++ b/app/Repositories/Budget/BudgetRepository.php @@ -79,10 +79,10 @@ class BudgetRepository implements BudgetRepositoryInterface /** @var Collection $repetitions */ return LimitRepetition:: leftJoin('budget_limits', 'limit_repetitions.budget_limit_id', '=', 'budget_limits.id') - ->where('limit_repetitions.startdate', '<=', $end->format('Y-m-d 00:00:00')) - ->where('limit_repetitions.startdate', '>=', $start->format('Y-m-d 00:00:00')) - ->where('budget_limits.budget_id', $budget->id) - ->get(['limit_repetitions.*']); + ->where('limit_repetitions.startdate', '<=', $end->format('Y-m-d 00:00:00')) + ->where('limit_repetitions.startdate', '>=', $start->format('Y-m-d 00:00:00')) + ->where('budget_limits.budget_id', $budget->id) + ->get(['limit_repetitions.*']); } /** @@ -154,9 +154,9 @@ class BudgetRepository implements BudgetRepositoryInterface $setQuery = $budget->transactionJournals()->withRelevantData()->take($take)->offset($offset) - ->orderBy('transaction_journals.date', 'DESC') - ->orderBy('transaction_journals.order', 'ASC') - ->orderBy('transaction_journals.id', 'DESC'); + ->orderBy('transaction_journals.date', 'DESC') + ->orderBy('transaction_journals.order', 'ASC') + ->orderBy('transaction_journals.id', 'DESC'); $countQuery = $budget->transactionJournals(); @@ -196,9 +196,9 @@ class BudgetRepository implements BudgetRepositoryInterface public function getLimitAmountOnDate(Budget $budget, Carbon $date) { $repetition = LimitRepetition::leftJoin('budget_limits', 'limit_repetitions.budget_limit_id', '=', 'budget_limits.id') - ->where('limit_repetitions.startdate', $date->format('Y-m-d 00:00:00')) - ->where('budget_limits.budget_id', $budget->id) - ->first(['limit_repetitions.*']); + ->where('limit_repetitions.startdate', $date->format('Y-m-d 00:00:00')) + ->where('budget_limits.budget_id', $budget->id) + ->first(['limit_repetitions.*']); if ($repetition) { return floatval($repetition->amount); @@ -216,15 +216,15 @@ class BudgetRepository implements BudgetRepositoryInterface public function getWithoutBudget(Carbon $start, Carbon $end) { return Auth::user() - ->transactionjournals() - ->leftJoin('budget_transaction_journal', 'budget_transaction_journal.transaction_journal_id', '=', 'transaction_journals.id') - ->whereNull('budget_transaction_journal.id') - ->before($end) - ->after($start) - ->orderBy('transaction_journals.date', 'DESC') - ->orderBy('transaction_journals.order', 'ASC') - ->orderBy('transaction_journals.id', 'DESC') - ->get(['transaction_journals.*']); + ->transactionjournals() + ->leftJoin('budget_transaction_journal', 'budget_transaction_journal.transaction_journal_id', '=', 'transaction_journals.id') + ->whereNull('budget_transaction_journal.id') + ->before($end) + ->after($start) + ->orderBy('transaction_journals.date', 'DESC') + ->orderBy('transaction_journals.order', 'ASC') + ->orderBy('transaction_journals.id', 'DESC') + ->get(['transaction_journals.*']); } /** @@ -236,22 +236,22 @@ class BudgetRepository implements BudgetRepositoryInterface public function getWithoutBudgetSum(Carbon $start, Carbon $end) { $noBudgetSet = Auth::user() - ->transactionjournals() - ->whereNotIn( - 'transaction_journals.id', function (QueryBuilder $query) use ($start, $end) { - $query - ->select('transaction_journals.id') - ->from('transaction_journals') - ->leftJoin('budget_transaction_journal', 'budget_transaction_journal.transaction_journal_id', '=', 'transaction_journals.id') - ->where('transaction_journals.date', '>=', $start->format('Y-m-d 00:00:00')) - ->where('transaction_journals.date', '<=', $end->format('Y-m-d 00:00:00')) - ->whereNotNull('budget_transaction_journal.budget_id'); - } - ) - ->after($start) - ->before($end) - ->transactionTypes(['Withdrawal']) - ->get(['transaction_journals.*'])->sum('amount'); + ->transactionjournals() + ->whereNotIn( + 'transaction_journals.id', function (QueryBuilder $query) use ($start, $end) { + $query + ->select('transaction_journals.id') + ->from('transaction_journals') + ->leftJoin('budget_transaction_journal', 'budget_transaction_journal.transaction_journal_id', '=', 'transaction_journals.id') + ->where('transaction_journals.date', '>=', $start->format('Y-m-d 00:00:00')) + ->where('transaction_journals.date', '<=', $end->format('Y-m-d 00:00:00')) + ->whereNotNull('budget_transaction_journal.budget_id'); + } + ) + ->after($start) + ->before($end) + ->transactionTypes(['Withdrawal']) + ->get(['transaction_journals.*'])->sum('amount'); return floatval($noBudgetSet) * -1; } @@ -272,18 +272,18 @@ class BudgetRepository implements BudgetRepositoryInterface } else { // get all journals in this month where the asset account is NOT shared. $sum = $budget->transactionjournals() - ->before($end) - ->after($start) - ->leftJoin('transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id') - ->leftJoin('accounts', 'accounts.id', '=', 'transactions.account_id') - ->leftJoin( - 'account_meta', function (JoinClause $join) { - $join->on('account_meta.account_id', '=', 'accounts.id')->where('account_meta.name', '=', 'accountRole'); - } - ) - ->where('account_meta.data', '!=', '"sharedAsset"') - ->get(['transaction_journals.*']) - ->sum('amount'); + ->before($end) + ->after($start) + ->leftJoin('transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id') + ->leftJoin('accounts', 'accounts.id', '=', 'transactions.account_id') + ->leftJoin( + 'account_meta', function (JoinClause $join) { + $join->on('account_meta.account_id', '=', 'accounts.id')->where('account_meta.name', '=', 'accountRole'); + } + ) + ->where('account_meta.data', '!=', '"sharedAsset"') + ->get(['transaction_journals.*']) + ->sum('amount'); $sum = floatval($sum); } diff --git a/app/Repositories/Category/CategoryRepository.php b/app/Repositories/Category/CategoryRepository.php index 5bf3dfd1b1..1fbb964e42 100644 --- a/app/Repositories/Category/CategoryRepository.php +++ b/app/Repositories/Category/CategoryRepository.php @@ -49,7 +49,7 @@ class CategoryRepository implements CategoryRepositoryInterface /** @var Collection $set */ $set = Auth::user()->categories()->orderBy('name', 'ASC')->get(); $set->sortBy( - function(Category $category) { + function (Category $category) { return $category->name; } ); @@ -67,16 +67,16 @@ class CategoryRepository implements CategoryRepositoryInterface public function getCategoriesAndExpensesCorrected($start, $end) { $set = Auth::user()->transactionjournals() - ->leftJoin( - 'category_transaction_journal', 'category_transaction_journal.transaction_journal_id', '=', 'transaction_journals.id' - ) - ->leftJoin('categories', 'categories.id', '=', 'category_transaction_journal.category_id') - ->before($end) - ->where('categories.user_id', Auth::user()->id) - ->after($start) - ->transactionTypes(['Withdrawal']) - ->groupBy('categories.id') - ->get(['categories.id as category_id', 'categories.encrypted as category_encrypted', 'categories.name', 'transaction_journals.*']); + ->leftJoin( + 'category_transaction_journal', 'category_transaction_journal.transaction_journal_id', '=', 'transaction_journals.id' + ) + ->leftJoin('categories', 'categories.id', '=', 'category_transaction_journal.category_id') + ->before($end) + ->where('categories.user_id', Auth::user()->id) + ->after($start) + ->transactionTypes(['Withdrawal']) + ->groupBy('categories.id') + ->get(['categories.id as category_id', 'categories.encrypted as category_encrypted', 'categories.name', 'transaction_journals.*']); $result = []; foreach ($set as $entry) { @@ -143,10 +143,10 @@ class CategoryRepository implements CategoryRepositoryInterface public function getLatestActivity(Category $category) { $latest = $category->transactionjournals() - ->orderBy('transaction_journals.date', 'DESC') - ->orderBy('transaction_journals.order', 'ASC') - ->orderBy('transaction_journals.id', 'DESC') - ->first(); + ->orderBy('transaction_journals.date', 'DESC') + ->orderBy('transaction_journals.order', 'ASC') + ->orderBy('transaction_journals.id', 'DESC') + ->first(); if ($latest) { return $latest->date; } @@ -163,15 +163,15 @@ class CategoryRepository implements CategoryRepositoryInterface public function getWithoutCategory(Carbon $start, Carbon $end) { return Auth::user() - ->transactionjournals() - ->leftJoin('category_transaction_journal', 'category_transaction_journal.transaction_journal_id', '=', 'transaction_journals.id') - ->whereNull('category_transaction_journal.id') - ->before($end) - ->after($start) - ->orderBy('transaction_journals.date', 'DESC') - ->orderBy('transaction_journals.order', 'ASC') - ->orderBy('transaction_journals.id', 'DESC') - ->get(['transaction_journals.*']); + ->transactionjournals() + ->leftJoin('category_transaction_journal', 'category_transaction_journal.transaction_journal_id', '=', 'transaction_journals.id') + ->whereNull('category_transaction_journal.id') + ->before($end) + ->after($start) + ->orderBy('transaction_journals.date', 'DESC') + ->orderBy('transaction_journals.order', 'ASC') + ->orderBy('transaction_journals.id', 'DESC') + ->get(['transaction_journals.*']); } /** @@ -190,8 +190,8 @@ class CategoryRepository implements CategoryRepositoryInterface // always ignore transfers between accounts! $sum = floatval( $category->transactionjournals() - ->transactionTypes(['Withdrawal']) - ->before($end)->after($start)->get(['transaction_journals.*'])->sum('amount') + ->transactionTypes(['Withdrawal']) + ->before($end)->after($start)->get(['transaction_journals.*'])->sum('amount') ); } else { @@ -204,7 +204,7 @@ class CategoryRepository implements CategoryRepositoryInterface ->leftJoin('transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id') ->leftJoin('accounts', 'accounts.id', '=', 'transactions.account_id') ->leftJoin( - 'account_meta', function(JoinClause $join) { + 'account_meta', function (JoinClause $join) { $join->on('account_meta.account_id', '=', 'accounts.id')->where('account_meta.name', '=', 'accountRole'); } ) diff --git a/app/Repositories/Journal/JournalRepository.php b/app/Repositories/Journal/JournalRepository.php index a7fb12f50a..965ad63b43 100644 --- a/app/Repositories/Journal/JournalRepository.php +++ b/app/Repositories/Journal/JournalRepository.php @@ -111,7 +111,7 @@ class JournalRepository implements JournalRepositoryInterface */ public function getJournalsOfTypes(array $types, $offset, $page) { - $set = Auth::user()->transactionJournals()->transactionTypes($types)->withRelevantData()->take(50)->offset($offset) + $set = Auth::user()->transactionJournals()->transactionTypes($types)->withRelevantData()->take(50)->offset($offset) ->orderBy('date', 'DESC') ->orderBy('order', 'ASC') ->orderBy('id', 'DESC') diff --git a/app/Repositories/PiggyBank/PiggyBankRepository.php b/app/Repositories/PiggyBank/PiggyBankRepository.php index 3db4693284..78c8d80b2d 100644 --- a/app/Repositories/PiggyBank/PiggyBankRepository.php +++ b/app/Repositories/PiggyBank/PiggyBankRepository.php @@ -102,7 +102,7 @@ class PiggyBankRepository implements PiggyBankRepositoryInterface public function setOrder($id, $order) { $piggyBank = PiggyBank::leftJoin('accounts', 'accounts.id', '=', 'piggy_banks.account_id')->where('accounts.user_id', Auth::user()->id) - ->where('piggy_banks.id', $id)->first(['piggy_banks.*']); + ->where('piggy_banks.id', $id)->first(['piggy_banks.*']); if ($piggyBank) { $piggyBank->order = $order; $piggyBank->save(); diff --git a/app/Repositories/Reminder/ReminderRepository.php b/app/Repositories/Reminder/ReminderRepository.php index ae04c59c66..8db6d0ada0 100644 --- a/app/Repositories/Reminder/ReminderRepository.php +++ b/app/Repositories/Reminder/ReminderRepository.php @@ -36,14 +36,14 @@ class ReminderRepository implements ReminderRepositoryInterface $today = new Carbon; // active reminders: $active = Auth::user()->reminders() - ->where('notnow', 0) - ->where('active', 1) - ->where('startdate', '<=', $today->format('Y-m-d 00:00:00')) - ->where('enddate', '>=', $today->format('Y-m-d 00:00:00')) - ->get(); + ->where('notnow', 0) + ->where('active', 1) + ->where('startdate', '<=', $today->format('Y-m-d 00:00:00')) + ->where('enddate', '>=', $today->format('Y-m-d 00:00:00')) + ->get(); $active->each( - function(Reminder $reminder) { + function (Reminder $reminder) { $reminder->description = $this->helper->getReminderText($reminder); } ); @@ -58,11 +58,11 @@ class ReminderRepository implements ReminderRepositoryInterface public function getDismissedReminders() { $dismissed = Auth::user()->reminders() - ->where('notnow', 1) - ->get(); + ->where('notnow', 1) + ->get(); $dismissed->each( - function(Reminder $reminder) { + function (Reminder $reminder) { $reminder->description = $this->helper->getReminderText($reminder); } ); @@ -77,18 +77,18 @@ class ReminderRepository implements ReminderRepositoryInterface { $expired = Auth::user()->reminders() - ->where('notnow', 0) - ->where('active', 1) - ->where( - function (Builder $q) { - $today = new Carbon; - $q->where('startdate', '>', $today->format('Y-m-d 00:00:00')); - $q->orWhere('enddate', '<', $today->format('Y-m-d 00:00:00')); - } - )->get(); + ->where('notnow', 0) + ->where('active', 1) + ->where( + function (Builder $q) { + $today = new Carbon; + $q->where('startdate', '>', $today->format('Y-m-d 00:00:00')); + $q->orWhere('enddate', '<', $today->format('Y-m-d 00:00:00')); + } + )->get(); $expired->each( - function(Reminder $reminder) { + function (Reminder $reminder) { $reminder->description = $this->helper->getReminderText($reminder); } ); @@ -106,7 +106,7 @@ class ReminderRepository implements ReminderRepositoryInterface ->get(); $inactive->each( - function(Reminder $reminder) { + function (Reminder $reminder) { $reminder->description = $this->helper->getReminderText($reminder); } ); diff --git a/app/Repositories/Tag/TagRepository.php b/app/Repositories/Tag/TagRepository.php index 358eeac892..252a08a2a9 100644 --- a/app/Repositories/Tag/TagRepository.php +++ b/app/Repositories/Tag/TagRepository.php @@ -109,7 +109,7 @@ class TagRepository implements TagRepositoryInterface /** @var Collection $tags */ $tags = Auth::user()->tags()->get(); $tags->sortBy( - function(Tag $tag) { + function (Tag $tag) { return $tag->tag; } ); diff --git a/app/Services/Registrar.php b/app/Services/Registrar.php index 6f9ffa729a..5f69c7ba24 100644 --- a/app/Services/Registrar.php +++ b/app/Services/Registrar.php @@ -41,9 +41,9 @@ class Registrar implements RegistrarContract { return Validator::make( $data, [ - 'email' => 'required|email|max:255|unique:users', - 'password' => 'required|confirmed|min:6', - ] + 'email' => 'required|email|max:255|unique:users', + 'password' => 'required|confirmed|min:6', + ] ); } diff --git a/app/Support/CacheProperties.php b/app/Support/CacheProperties.php index f7f7018b44..9c3cffd501 100644 --- a/app/Support/CacheProperties.php +++ b/app/Support/CacheProperties.php @@ -99,4 +99,12 @@ class CacheProperties $this->md5 = md5($this->md5); } + + /** + * @param $data + */ + public function store($data) + { + Cache::forever($this->md5, $data); + } } \ No newline at end of file diff --git a/app/Support/Navigation.php b/app/Support/Navigation.php index f2dd884673..542cd669f3 100644 --- a/app/Support/Navigation.php +++ b/app/Support/Navigation.php @@ -118,7 +118,7 @@ class Navigation 'year' => 'endOfYear', 'yearly' => 'endOfYear', ]; - $specials = ['mont', 'monthly']; + $specials = ['mont', 'monthly']; $currentEnd = clone $theCurrentEnd; @@ -270,7 +270,7 @@ class Navigation '3M' => 'lastOfQuarter', '1Y' => 'endOfYear', ]; - $end = clone $start; + $end = clone $start; if (isset($functionMap[$range])) { $function = $functionMap[$range]; diff --git a/app/Support/Preferences.php b/app/Support/Preferences.php index d5ddc4f181..5d24ca6818 100644 --- a/app/Support/Preferences.php +++ b/app/Support/Preferences.php @@ -4,6 +4,7 @@ namespace FireflyIII\Support; use Auth; use FireflyIII\Models\Preference; + /** * Class Preferences * @@ -21,14 +22,6 @@ class Preferences return md5($preference); } - /** - * @return bool - */ - public function mark() { - $this->set('lastActivity',microtime()); - return true; - } - /** * @param $name * @param null $default @@ -85,4 +78,14 @@ class Preferences return $pref; } + + /** + * @return bool + */ + public function mark() + { + $this->set('lastActivity', microtime()); + + return true; + } } diff --git a/app/Support/Search/Search.php b/app/Support/Search/Search.php index 7b1e0f42b5..a493ad0741 100644 --- a/app/Support/Search/Search.php +++ b/app/Support/Search/Search.php @@ -25,7 +25,7 @@ class Search implements SearchInterface public function searchAccounts(array $words) { return Auth::user()->accounts()->with('accounttype')->where( - function(EloquentBuilder $q) use ($words) { + function (EloquentBuilder $q) use ($words) { foreach ($words as $word) { $q->orWhere('name', 'LIKE', '%' . e($word) . '%'); } @@ -43,7 +43,7 @@ class Search implements SearchInterface /** @var Collection $set */ $set = Auth::user()->budgets()->get(); $newSet = $set->filter( - function(Budget $b) use ($words) { + function (Budget $b) use ($words) { $found = 0; foreach ($words as $word) { if (!(strpos(strtolower($b->name), strtolower($word)) === false)) { @@ -68,7 +68,7 @@ class Search implements SearchInterface /** @var Collection $set */ $set = Auth::user()->categories()->get(); $newSet = $set->filter( - function(Category $c) use ($words) { + function (Category $c) use ($words) { $found = 0; foreach ($words as $word) { if (!(strpos(strtolower($c->name), strtolower($word)) === false)) { @@ -103,7 +103,7 @@ class Search implements SearchInterface { // decrypted transaction journals: $decrypted = Auth::user()->transactionjournals()->withRelevantData()->where('encrypted', 0)->where( - function(EloquentBuilder $q) use ($words) { + function (EloquentBuilder $q) use ($words) { foreach ($words as $word) { $q->orWhere('description', 'LIKE', '%' . e($word) . '%'); } @@ -113,7 +113,7 @@ class Search implements SearchInterface // encrypted $all = Auth::user()->transactionjournals()->withRelevantData()->where('encrypted', 1)->get(); $set = $all->filter( - function(TransactionJournal $journal) use ($words) { + function (TransactionJournal $journal) use ($words) { foreach ($words as $word) { $haystack = strtolower($journal->description); $word = strtolower($word); @@ -129,7 +129,7 @@ class Search implements SearchInterface $filtered = $set->merge($decrypted); $filtered->sortBy( - function(TransactionJournal $journal) { + function (TransactionJournal $journal) { return intval($journal->date->format('U')); } ); diff --git a/app/Support/Steam.php b/app/Support/Steam.php index 5e3804864b..234559844b 100644 --- a/app/Support/Steam.php +++ b/app/Support/Steam.php @@ -2,7 +2,6 @@ namespace FireflyIII\Support; -use Cache; use Carbon\Carbon; use FireflyIII\Models\Account; @@ -25,15 +24,14 @@ class Steam { // abuse chart properties: - $properties = new CacheProperties; - $properties->addProperty($account->id); - $properties->addProperty('balance'); - $properties->addProperty($date); - $properties->addProperty($ignoreVirtualBalance); - if ($properties->has()) { - return $properties->get(); + $cache = new CacheProperties; + $cache->addProperty($account->id); + $cache->addProperty('balance'); + $cache->addProperty($date); + $cache->addProperty($ignoreVirtualBalance); + if ($cache->has()) { + return $cache->get(); } - $md5 = $properties->getMd5(); // find the first known transaction on this account: @@ -57,7 +55,7 @@ class Steam if (!$ignoreVirtualBalance) { $balance = bcadd($balance, $account->virtual_balance); } - Cache::forever($md5, round($balance, 2)); + $cache->store(round($balance, 2)); return round($balance, 2); } diff --git a/app/Support/Twig/Budget.php b/app/Support/Twig/Budget.php index 2424f8b0c8..f1ce2ff4da 100644 --- a/app/Support/Twig/Budget.php +++ b/app/Support/Twig/Budget.php @@ -19,18 +19,18 @@ class Budget extends Twig_Extension */ public function getFunctions() { - $functions = []; + $functions = []; $functions[] = new Twig_SimpleFunction( - 'spentInRepetitionCorrected', function(LimitRepetition $repetition) { + 'spentInRepetitionCorrected', function (LimitRepetition $repetition) { $sum = Auth::user()->transactionjournals() - ->leftJoin('budget_transaction_journal', 'budget_transaction_journal.transaction_journal_id', '=', 'transaction_journals.id') - ->leftJoin('budget_limits', 'budget_limits.budget_id', '=', 'budget_transaction_journal.budget_id') - ->leftJoin('limit_repetitions', 'limit_repetitions.budget_limit_id', '=', 'budget_limits.id') - ->before($repetition->enddate) - ->after($repetition->startdate) - ->where('limit_repetitions.id', '=', $repetition->id) - ->get(['transaction_journals.*'])->sum('amount'); + ->leftJoin('budget_transaction_journal', 'budget_transaction_journal.transaction_journal_id', '=', 'transaction_journals.id') + ->leftJoin('budget_limits', 'budget_limits.budget_id', '=', 'budget_transaction_journal.budget_id') + ->leftJoin('limit_repetitions', 'limit_repetitions.budget_limit_id', '=', 'budget_limits.id') + ->before($repetition->enddate) + ->after($repetition->startdate) + ->where('limit_repetitions.id', '=', $repetition->id) + ->get(['transaction_journals.*'])->sum('amount'); return floatval($sum); } diff --git a/app/Support/Twig/General.php b/app/Support/Twig/General.php index 81ea504928..c1bcf09e16 100644 --- a/app/Support/Twig/General.php +++ b/app/Support/Twig/General.php @@ -31,31 +31,31 @@ class General extends Twig_Extension $filters = []; $filters[] = new Twig_SimpleFilter( - 'formatAmount', function($string) { + 'formatAmount', function ($string) { return App::make('amount')->format($string); }, ['is_safe' => ['html']] ); $filters[] = new Twig_SimpleFilter( - 'formatTransaction', function(Transaction $transaction) { + 'formatTransaction', function (Transaction $transaction) { return App::make('amount')->formatTransaction($transaction); }, ['is_safe' => ['html']] ); $filters[] = new Twig_SimpleFilter( - 'formatAmountPlain', function($string) { + 'formatAmountPlain', function ($string) { return App::make('amount')->format($string, false); }, ['is_safe' => ['html']] ); $filters[] = new Twig_SimpleFilter( - 'formatJournal', function($journal) { + 'formatJournal', function ($journal) { return App::make('amount')->formatJournal($journal); }, ['is_safe' => ['html']] ); $filters[] = new Twig_SimpleFilter( - 'balance', function(Account $account = null) { + 'balance', function (Account $account = null) { if (is_null($account)) { return 'NULL'; } @@ -67,7 +67,7 @@ class General extends Twig_Extension // should be a function but OK $filters[] = new Twig_SimpleFilter( - 'getAccountRole', function($name) { + 'getAccountRole', function ($name) { return Config::get('firefly.accountRoles.' . $name); } ); @@ -83,32 +83,32 @@ class General extends Twig_Extension $functions = []; $functions[] = new Twig_SimpleFunction( - 'getCurrencyCode', function() { + 'getCurrencyCode', function () { return App::make('amount')->getCurrencyCode(); } ); $functions[] = new Twig_SimpleFunction( - 'getCurrencySymbol', function() { + 'getCurrencySymbol', function () { return App::make('amount')->getCurrencySymbol(); } ); $functions[] = new Twig_SimpleFunction( - 'phpdate', function($str) { + 'phpdate', function ($str) { return date($str); } ); $functions[] = new Twig_SimpleFunction( - 'env', function($name, $default) { + 'env', function ($name, $default) { return env($name, $default); } ); $functions[] = new Twig_SimpleFunction( - 'activeRoute', function($context) { + 'activeRoute', function ($context) { $args = func_get_args(); $route = $args[1]; $what = isset($args[2]) ? $args[2] : false; diff --git a/app/Support/Twig/Journal.php b/app/Support/Twig/Journal.php index 7e53787fde..293a2a5a34 100644 --- a/app/Support/Twig/Journal.php +++ b/app/Support/Twig/Journal.php @@ -4,7 +4,6 @@ namespace FireflyIII\Support\Twig; use App; -use Cache; use FireflyIII\Models\TransactionJournal; use FireflyIII\Support\CacheProperties; use Twig_Extension; @@ -30,13 +29,12 @@ class Journal extends Twig_Extension $filters[] = new Twig_SimpleFilter( 'typeIcon', function (TransactionJournal $journal) { - $prop = new CacheProperties(); - $prop->addProperty($journal->id); - $prop->addProperty('typeIcon'); - if ($prop->has()) { - return $prop->get(); + $cache = new CacheProperties(); + $cache->addProperty($journal->id); + $cache->addProperty('typeIcon'); + if ($cache->has()) { + return $cache->get(); } - $md5 = $prop->getMd5(); $type = $journal->transactionType->type; @@ -57,7 +55,7 @@ class Journal extends Twig_Extension $txt = ''; break; } - Cache::forever($md5, $txt); + $cache->store($txt); return $txt; diff --git a/app/Support/Twig/PiggyBank.php b/app/Support/Twig/PiggyBank.php index f178aa6316..6ff4aafe90 100644 --- a/app/Support/Twig/PiggyBank.php +++ b/app/Support/Twig/PiggyBank.php @@ -22,7 +22,7 @@ class PiggyBank extends Twig_Extension $functions = []; $functions[] = new Twig_SimpleFunction( - 'currentRelevantRepAmount', function(PB $piggyBank) { + 'currentRelevantRepAmount', function (PB $piggyBank) { return $piggyBank->currentRelevantRep()->currentamount; } ); diff --git a/app/Support/Twig/Translation.php b/app/Support/Twig/Translation.php index d91c1816e6..1cb3314cf2 100644 --- a/app/Support/Twig/Translation.php +++ b/app/Support/Twig/Translation.php @@ -21,7 +21,7 @@ class Translation extends Twig_Extension $filters = []; $filters[] = new Twig_SimpleFilter( - '_', function($name) { + '_', function ($name) { return trans('firefly.' . $name); diff --git a/app/User.php b/app/User.php index 0207cc0fad..f1c7774829 100644 --- a/app/User.php +++ b/app/User.php @@ -11,20 +11,20 @@ use Zizaco\Entrust\Traits\EntrustUserTrait; * Class User * * @package FireflyIII - * @property integer $id - * @property \Carbon\Carbon $created_at - * @property \Carbon\Carbon $updated_at - * @property string $email - * @property string $password - * @property string $reset - * @property string $remember_token - * @property-read \Illuminate\Database\Eloquent\Collection|\FireflyIII\Models\Account[] $accounts - * @property-read \Illuminate\Database\Eloquent\Collection|\FireflyIII\Models\Tag[] $tags - * @property-read \Illuminate\Database\Eloquent\Collection|\FireflyIII\Models\Bill[] $bills - * @property-read \Illuminate\Database\Eloquent\Collection|\FireflyIII\Models\Budget[] $budgets - * @property-read \Illuminate\Database\Eloquent\Collection|\FireflyIII\Models\Category[] $categories - * @property-read \Illuminate\Database\Eloquent\Collection|\FireflyIII\Models\Preference[] $preferences - * @property-read \Illuminate\Database\Eloquent\Collection|\FireflyIII\Models\Reminder[] $reminders + * @property integer $id + * @property \Carbon\Carbon $created_at + * @property \Carbon\Carbon $updated_at + * @property string $email + * @property string $password + * @property string $reset + * @property string $remember_token + * @property-read \Illuminate\Database\Eloquent\Collection|\FireflyIII\Models\Account[] $accounts + * @property-read \Illuminate\Database\Eloquent\Collection|\FireflyIII\Models\Tag[] $tags + * @property-read \Illuminate\Database\Eloquent\Collection|\FireflyIII\Models\Bill[] $bills + * @property-read \Illuminate\Database\Eloquent\Collection|\FireflyIII\Models\Budget[] $budgets + * @property-read \Illuminate\Database\Eloquent\Collection|\FireflyIII\Models\Category[] $categories + * @property-read \Illuminate\Database\Eloquent\Collection|\FireflyIII\Models\Preference[] $preferences + * @property-read \Illuminate\Database\Eloquent\Collection|\FireflyIII\Models\Reminder[] $reminders * @property-read \Illuminate\Database\Eloquent\Collection|\FireflyIII\Models\TransactionJournal[] $transactionjournals * @method static \Illuminate\Database\Query\Builder|\FireflyIII\User whereId($value) * @method static \Illuminate\Database\Query\Builder|\FireflyIII\User whereCreatedAt($value) From 1240c8f6857bd4c892ccda88d1cbe9abcf6628c5 Mon Sep 17 00:00:00 2001 From: James Cole Date: Wed, 3 Jun 2015 21:27:36 +0200 Subject: [PATCH 16/47] Update models [skip ci] --- app/Models/Account.php | 1 - app/Models/AccountMeta.php | 2 +- app/Models/AccountType.php | 2 +- app/Models/Bill.php | 2 +- app/Models/Budget.php | 2 +- app/Models/BudgetLimit.php | 2 +- app/Models/Component.php | 2 +- app/Models/LimitRepetition.php | 2 +- app/Models/Permission.php | 13 +++++++++++++ app/Models/PiggyBank.php | 2 +- app/Models/PiggyBankEvent.php | 2 +- app/Models/PiggyBankRepetition.php | 2 +- app/Models/Preference.php | 2 +- app/Models/Reminder.php | 2 +- app/Models/Role.php | 14 ++++++++++++++ app/Models/Transaction.php | 2 +- app/Models/TransactionCurrency.php | 2 +- app/Models/TransactionGroup.php | 2 +- app/Models/TransactionJournal.php | 1 + app/Models/TransactionRelation.php | 2 +- app/Models/TransactionType.php | 2 +- app/User.php | 1 + 22 files changed, 46 insertions(+), 18 deletions(-) diff --git a/app/Models/Account.php b/app/Models/Account.php index 5453a136a1..f5092a9c96 100644 --- a/app/Models/Account.php +++ b/app/Models/Account.php @@ -47,7 +47,6 @@ use Watson\Validating\ValidatingTrait; * @property mixed piggyBalance * @property mixed difference * @propery mixed percentage - * */ class Account extends Model { diff --git a/app/Models/AccountMeta.php b/app/Models/AccountMeta.php index 279fe60765..1e2d0ce3c3 100644 --- a/app/Models/AccountMeta.php +++ b/app/Models/AccountMeta.php @@ -6,7 +6,7 @@ use Watson\Validating\ValidatingTrait; /** * Class AccountMeta * - * @codeCoverageIgnore + * @codeCoverageIgnore * @package FireflyIII\Models * @property integer $id * @property \Carbon\Carbon $created_at diff --git a/app/Models/AccountType.php b/app/Models/AccountType.php index 2148b9e961..6de461749b 100644 --- a/app/Models/AccountType.php +++ b/app/Models/AccountType.php @@ -5,7 +5,7 @@ use Illuminate\Database\Eloquent\Model; /** * Class AccountType * - * @codeCoverageIgnore + * @codeCoverageIgnore * @package FireflyIII\Models * @property integer $id * @property \Carbon\Carbon $created_at diff --git a/app/Models/Bill.php b/app/Models/Bill.php index a1b048e99a..91f934dbfa 100644 --- a/app/Models/Bill.php +++ b/app/Models/Bill.php @@ -7,7 +7,7 @@ use Illuminate\Database\Eloquent\Model; * FireflyIII\Models\Bill * * @codeCoverageIgnore Class Bill - * @package FireflyIII\Models + * @package FireflyIII\Models * @property integer $id * @property \Carbon\Carbon $created_at * @property \Carbon\Carbon $updated_at diff --git a/app/Models/Budget.php b/app/Models/Budget.php index 02f1e46808..ab529f3e62 100644 --- a/app/Models/Budget.php +++ b/app/Models/Budget.php @@ -7,7 +7,7 @@ use Illuminate\Database\Eloquent\SoftDeletes; /** * Class Budget * - * @codeCoverageIgnore + * @codeCoverageIgnore * @package FireflyIII\Models * @property integer $id * @property \Carbon\Carbon $created_at diff --git a/app/Models/BudgetLimit.php b/app/Models/BudgetLimit.php index 42e72dc502..97f2b16dab 100644 --- a/app/Models/BudgetLimit.php +++ b/app/Models/BudgetLimit.php @@ -5,7 +5,7 @@ use Illuminate\Database\Eloquent\Model; /** * Class BudgetLimit * - * @codeCoverageIgnore + * @codeCoverageIgnore * @package FireflyIII\Models * @property integer $id * @property \Carbon\Carbon $created_at diff --git a/app/Models/Component.php b/app/Models/Component.php index 84686751be..c65a9c8812 100644 --- a/app/Models/Component.php +++ b/app/Models/Component.php @@ -6,7 +6,7 @@ use Illuminate\Database\Eloquent\SoftDeletes; /** * Class Component * - * @codeCoverageIgnore + * @codeCoverageIgnore * @package FireflyIII\Models * @property integer $id * @property \Carbon\Carbon $created_at diff --git a/app/Models/LimitRepetition.php b/app/Models/LimitRepetition.php index d5fd692dae..5f6ea2a6cf 100644 --- a/app/Models/LimitRepetition.php +++ b/app/Models/LimitRepetition.php @@ -5,7 +5,7 @@ use Illuminate\Database\Eloquent\Model; /** * Class LimitRepetition * - * @codeCoverageIgnore + * @codeCoverageIgnore * @package FireflyIII\Models * @property integer $id * @property \Carbon\Carbon $created_at diff --git a/app/Models/Permission.php b/app/Models/Permission.php index a075f74e01..e3c5943928 100644 --- a/app/Models/Permission.php +++ b/app/Models/Permission.php @@ -8,6 +8,19 @@ use Zizaco\Entrust\EntrustPermission; * Class Permission * * @package FireflyIII\Models + * @property integer $id + * @property string $name + * @property string $display_name + * @property string $description + * @property \Carbon\Carbon $created_at + * @property \Carbon\Carbon $updated_at + * @property-read \Illuminate\Database\Eloquent\Collection|\Config::get('entrust.role')[] $roles + * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Permission whereId($value) + * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Permission whereName($value) + * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Permission whereDisplayName($value) + * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Permission whereDescription($value) + * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Permission whereCreatedAt($value) + * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Permission whereUpdatedAt($value) */ class Permission extends EntrustPermission { diff --git a/app/Models/PiggyBank.php b/app/Models/PiggyBank.php index 44c05fa63b..127a65e619 100644 --- a/app/Models/PiggyBank.php +++ b/app/Models/PiggyBank.php @@ -7,7 +7,7 @@ use Illuminate\Database\Eloquent\SoftDeletes; /** * Class PiggyBank * - * @codeCoverageIgnore + * @codeCoverageIgnore * @package FireflyIII\Models * @property integer $id * @property \Carbon\Carbon $created_at diff --git a/app/Models/PiggyBankEvent.php b/app/Models/PiggyBankEvent.php index 6b9bdceda1..98de0f04ef 100644 --- a/app/Models/PiggyBankEvent.php +++ b/app/Models/PiggyBankEvent.php @@ -5,7 +5,7 @@ use Illuminate\Database\Eloquent\Model; /** * Class PiggyBankEvent * - * @codeCoverageIgnore + * @codeCoverageIgnore * @package FireflyIII\Models * @property integer $id * @property \Carbon\Carbon $created_at diff --git a/app/Models/PiggyBankRepetition.php b/app/Models/PiggyBankRepetition.php index a24066f2ee..68d2388acc 100644 --- a/app/Models/PiggyBankRepetition.php +++ b/app/Models/PiggyBankRepetition.php @@ -7,7 +7,7 @@ use Illuminate\Database\Eloquent\Model; /** * Class PiggyBankRepetition * - * @codeCoverageIgnore + * @codeCoverageIgnore * @package FireflyIII\Models * @property integer $id * @property \Carbon\Carbon $created_at diff --git a/app/Models/Preference.php b/app/Models/Preference.php index 3f22c4330d..488a57d0bb 100644 --- a/app/Models/Preference.php +++ b/app/Models/Preference.php @@ -6,7 +6,7 @@ use Illuminate\Database\Eloquent\Model; /** * Class Preference * - * @codeCoverageIgnore + * @codeCoverageIgnore * @package FireflyIII\Models * @property integer $id * @property \Carbon\Carbon $created_at diff --git a/app/Models/Reminder.php b/app/Models/Reminder.php index b4797dae8d..d8c5d90afe 100644 --- a/app/Models/Reminder.php +++ b/app/Models/Reminder.php @@ -8,7 +8,7 @@ use Illuminate\Database\Eloquent\Model; /** * Class Reminder * - * @codeCoverageIgnore + * @codeCoverageIgnore * @package FireflyIII\Models * @property integer $id * @property \Carbon\Carbon $created_at diff --git a/app/Models/Role.php b/app/Models/Role.php index d7df217c7f..543c0580fb 100644 --- a/app/Models/Role.php +++ b/app/Models/Role.php @@ -8,6 +8,20 @@ use Zizaco\Entrust\EntrustRole; * Class Role * * @package FireflyIII\Models + * @property integer $id + * @property string $name + * @property string $display_name + * @property string $description + * @property \Carbon\Carbon $created_at + * @property \Carbon\Carbon $updated_at + * @property-read \Illuminate\Database\Eloquent\Collection|\Config::get('auth.model')[] $users + * @property-read \Illuminate\Database\Eloquent\Collection|\Config::get('entrust.permission')[] $perms + * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Role whereId($value) + * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Role whereName($value) + * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Role whereDisplayName($value) + * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Role whereDescription($value) + * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Role whereCreatedAt($value) + * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Role whereUpdatedAt($value) */ class Role extends EntrustRole { diff --git a/app/Models/Transaction.php b/app/Models/Transaction.php index 26ca48ef45..43f9928439 100644 --- a/app/Models/Transaction.php +++ b/app/Models/Transaction.php @@ -9,7 +9,7 @@ use Watson\Validating\ValidatingTrait; /** * Class Transaction * - * @codeCoverageIgnore + * @codeCoverageIgnore * @package FireflyIII\Models * @property integer $id * @property \Carbon\Carbon $created_at diff --git a/app/Models/TransactionCurrency.php b/app/Models/TransactionCurrency.php index 27b21f36c3..4adad9b216 100644 --- a/app/Models/TransactionCurrency.php +++ b/app/Models/TransactionCurrency.php @@ -6,7 +6,7 @@ use Illuminate\Database\Eloquent\SoftDeletes; /** * Class TransactionCurrency * - * @codeCoverageIgnore + * @codeCoverageIgnore * @package FireflyIII\Models * @property integer $id * @property \Carbon\Carbon $created_at diff --git a/app/Models/TransactionGroup.php b/app/Models/TransactionGroup.php index bb41749ca2..6c980bfac0 100644 --- a/app/Models/TransactionGroup.php +++ b/app/Models/TransactionGroup.php @@ -6,7 +6,7 @@ use Illuminate\Database\Eloquent\SoftDeletes; /** * Class TransactionGroup * - * @codeCoverageIgnore + * @codeCoverageIgnore * @package FireflyIII\Models * @property integer $id * @property \Carbon\Carbon $created_at diff --git a/app/Models/TransactionJournal.php b/app/Models/TransactionJournal.php index 2248c31229..9c577b68f9 100644 --- a/app/Models/TransactionJournal.php +++ b/app/Models/TransactionJournal.php @@ -68,6 +68,7 @@ use Watson\Validating\ValidatingTrait; * @property mixed account_id * @property mixed name * @property mixed symbol + * @property-read mixed $correct_amount */ class TransactionJournal extends Model { diff --git a/app/Models/TransactionRelation.php b/app/Models/TransactionRelation.php index aa4d3810af..056d61fdd8 100644 --- a/app/Models/TransactionRelation.php +++ b/app/Models/TransactionRelation.php @@ -5,7 +5,7 @@ use Illuminate\Database\Eloquent\Model; /** * Class TransactionRelation * - * @codeCoverageIgnore + * @codeCoverageIgnore * @package FireflyIII\Models */ class TransactionRelation extends Model diff --git a/app/Models/TransactionType.php b/app/Models/TransactionType.php index 098d5bcfc7..886858bb2c 100644 --- a/app/Models/TransactionType.php +++ b/app/Models/TransactionType.php @@ -6,7 +6,7 @@ use Illuminate\Database\Eloquent\SoftDeletes; /** * Class TransactionType * - * @codeCoverageIgnore + * @codeCoverageIgnore * @package FireflyIII\Models * @property integer $id * @property \Carbon\Carbon $created_at diff --git a/app/User.php b/app/User.php index f1c7774829..9744811fd3 100644 --- a/app/User.php +++ b/app/User.php @@ -33,6 +33,7 @@ use Zizaco\Entrust\Traits\EntrustUserTrait; * @method static \Illuminate\Database\Query\Builder|\FireflyIII\User wherePassword($value) * @method static \Illuminate\Database\Query\Builder|\FireflyIII\User whereReset($value) * @method static \Illuminate\Database\Query\Builder|\FireflyIII\User whereRememberToken($value) + * @property-read \Illuminate\Database\Eloquent\Collection|\Config::get('entrust.role')[] $roles */ class User extends Model implements AuthenticatableContract, CanResetPasswordContract { From 14dce8a10b99fc439a6699966087d6be809524ae Mon Sep 17 00:00:00 2001 From: James Cole Date: Wed, 3 Jun 2015 21:58:06 +0200 Subject: [PATCH 17/47] Optimized preferences. --- app/Http/Controllers/HomeController.php | 3 +++ app/Models/Preference.php | 24 ----------------- app/Support/Amount.php | 24 ++++++++++++++--- app/Support/Preferences.php | 34 +++++++++---------------- 4 files changed, 36 insertions(+), 49 deletions(-) diff --git a/app/Http/Controllers/HomeController.php b/app/Http/Controllers/HomeController.php index 4477ae09d3..16a9e120b4 100644 --- a/app/Http/Controllers/HomeController.php +++ b/app/Http/Controllers/HomeController.php @@ -67,6 +67,7 @@ class HomeController extends Controller $frontPage = Preferences::get('frontPageAccounts', []); $start = Session::get('start', Carbon::now()->startOfMonth()); $end = Session::get('end', Carbon::now()->endOfMonth()); + $accounts = $repository->getFrontpageAccounts($frontPage); $savings = $repository->getSavingsAccounts(); @@ -79,6 +80,7 @@ class HomeController extends Controller } $sum = $repository->sumOfEverything(); + if ($sum != 0) { Session::flash( 'error', 'Your transactions are unbalanced. This means a' @@ -89,6 +91,7 @@ class HomeController extends Controller foreach ($accounts as $account) { $set = $repository->getFrontpageTransactions($account, $start, $end); + if (count($set) > 0) { $transactions[] = [$set, $account]; } diff --git a/app/Models/Preference.php b/app/Models/Preference.php index 488a57d0bb..263e7e33bc 100644 --- a/app/Models/Preference.php +++ b/app/Models/Preference.php @@ -55,21 +55,6 @@ class Preference extends Model return ['created_at', 'updated_at']; } - /** - * @param $value - * - * @return float|int - */ - public function getNameAttribute($value) - { - if (is_null($this->name_encrypted)) { - return $value; - } - $value = Crypt::decrypt($this->name_encrypted); - - return $value; - } - /** * @param $value */ @@ -79,15 +64,6 @@ class Preference extends Model $this->attributes['data_encrypted'] = Crypt::encrypt(json_encode($value)); } - /** - * @param $value - */ - public function setNameAttribute($value) - { - $this->attributes['name_encrypted'] = Crypt::encrypt($value); - $this->attributes['name'] = $value; - } - /** * @return \Illuminate\Database\Eloquent\Relations\BelongsTo */ diff --git a/app/Support/Amount.php b/app/Support/Amount.php index 8a1916e9ca..101ff86d41 100644 --- a/app/Support/Amount.php +++ b/app/Support/Amount.php @@ -84,6 +84,15 @@ class Amount */ public function formatJournal(TransactionJournal $journal, $coloured = true) { + $cache = new CacheProperties; + $cache->addProperty($journal->id); + $cache->addProperty('formatJournal'); + + if ($cache->has()) { + return $cache->get(); + } + + if (is_null($journal->symbol)) { $symbol = $journal->transactionCurrency->symbol; } else { @@ -94,13 +103,22 @@ class Amount $amount = $amount * -1; } if ($journal->transactionType->type == 'Transfer' && $coloured) { - return '' . $this->formatWithSymbol($symbol, $amount, false) . ''; + $txt = '' . $this->formatWithSymbol($symbol, $amount, false) . ''; + $cache->store($txt); + + return $txt; } if ($journal->transactionType->type == 'Transfer' && !$coloured) { - return $this->formatWithSymbol($symbol, $amount, false); + $txt = $this->formatWithSymbol($symbol, $amount, false); + $cache->store($txt); + + return $txt; } - return $this->formatWithSymbol($symbol, $amount, $coloured); + $txt = $this->formatWithSymbol($symbol, $amount, $coloured); + $cache->store($txt); + + return $txt; } /** diff --git a/app/Support/Preferences.php b/app/Support/Preferences.php index 5d24ca6818..8ed4b17924 100644 --- a/app/Support/Preferences.php +++ b/app/Support/Preferences.php @@ -30,13 +30,10 @@ class Preferences */ public function get($name, $default = null) { - $preferences = Preference::where('user_id', Auth::user()->id)->get(); + $preference = Preference::where('user_id', Auth::user()->id)->where('name', $name)->first(['id','name','data_encrypted']); - /** @var Preference $preference */ - foreach ($preferences as $preference) { - if ($preference->name == $name) { - return $preference; - } + if ($preference) { + return $preference; } // no preference found and default is null: if (is_null($default)) { @@ -56,24 +53,17 @@ class Preferences */ public function set($name, $value) { - $preferences = Preference::where('user_id', Auth::user()->id)->get(); - /** @var Preference $preference */ - foreach ($preferences as $preference) { - if ($preference->name == $name) { - $preference->data = $value; - $preference->save(); - - return $preference; - } - } - $pref = new Preference; - $pref->name = $name; - $pref->data = $value; - - if (!is_null(Auth::user()->id)) { + $pref = Preference::where('user_id', Auth::user()->id)->where('name', $name)->first(['id','name','data_encrypted']); + if ($pref) { + $pref->data = $value; + } else { + $pref = new Preference; + $pref->name = $name; + $pref->data = $value; $pref->user()->associate(Auth::user()); - $pref->save(); + } + $pref->save(); return $pref; From a50949e554221a8d8bbc669281cec26b80a8e158 Mon Sep 17 00:00:00 2001 From: James Cole Date: Wed, 3 Jun 2015 22:11:50 +0200 Subject: [PATCH 18/47] Cache preferences. --- app/Support/Preferences.php | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/app/Support/Preferences.php b/app/Support/Preferences.php index 8ed4b17924..72eaebee6f 100644 --- a/app/Support/Preferences.php +++ b/app/Support/Preferences.php @@ -3,6 +3,7 @@ namespace FireflyIII\Support; use Auth; +use Cache; use FireflyIII\Models\Preference; /** @@ -30,9 +31,17 @@ class Preferences */ public function get($name, $default = null) { - $preference = Preference::where('user_id', Auth::user()->id)->where('name', $name)->first(['id','name','data_encrypted']); + $fullName = 'preference' . Auth::user()->id . $name; + if (Cache::has($fullName)) { + return Cache::get($fullName); + } + + + $preference = Preference::where('user_id', Auth::user()->id)->where('name', $name)->first(['id', 'name', 'data_encrypted']); if ($preference) { + Cache::forever($fullName, $preference); + return $preference; } // no preference found and default is null: @@ -53,7 +62,9 @@ class Preferences */ public function set($name, $value) { - $pref = Preference::where('user_id', Auth::user()->id)->where('name', $name)->first(['id','name','data_encrypted']); + $fullName = 'preference' . Auth::user()->id . $name; + Cache::forget($fullName); + $pref = Preference::where('user_id', Auth::user()->id)->where('name', $name)->first(['id', 'name', 'data_encrypted']); if ($pref) { $pref->data = $value; } else { @@ -65,6 +76,8 @@ class Preferences } $pref->save(); + Cache::forever($fullName, $pref); + return $pref; } From bb1da3183099c0a413e3244fa72cbb7536143697 Mon Sep 17 00:00:00 2001 From: James Cole Date: Thu, 4 Jun 2015 17:43:50 +0200 Subject: [PATCH 19/47] Increase test coverage. --- app/Http/Controllers/BudgetController.php | 15 ++++--- tests/controllers/BudgetControllerTest.php | 23 +++++++++++ tests/helpers/ReportHelperTest.php | 10 ++++- tests/helpers/ReportQueryTest.php | 46 ++++++++++++++++------ 4 files changed, 74 insertions(+), 20 deletions(-) diff --git a/app/Http/Controllers/BudgetController.php b/app/Http/Controllers/BudgetController.php index 0925ce2056..a58248e9fc 100644 --- a/app/Http/Controllers/BudgetController.php +++ b/app/Http/Controllers/BudgetController.php @@ -219,12 +219,15 @@ class BudgetController extends Controller } $journals = $repository->getJournals($budget, $repetition); - $limits = !is_null($repetition->id) ? [$repetition->budgetLimit] : $repository->getBudgetLimits($budget); - $subTitle = !is_null($repetition->id) - ? - trans('firefly.budget_in_month', ['name' => $budget->name, 'month' => $repetition->startdate->formatLocalized($this->monthFormat)]) - : - e($budget->name); + + if (is_null($repetition->id)) { + $limits = $repository->getBudgetLimits($budget); + $subTitle = e($budget->name); + } else { + $limits = [$repetition->budgetLimit]; + $subTitle = trans('firefly.budget_in_month', ['name' => $budget->name, 'month' => $repetition->startdate->formatLocalized($this->monthFormat)]); + } + $journals->setPath('/budgets/show/' . $budget->id); return view('budgets.show', compact('limits', 'budget', 'repetition', 'journals', 'subTitle')); diff --git a/tests/controllers/BudgetControllerTest.php b/tests/controllers/BudgetControllerTest.php index 84cf4eda92..1446f1220a 100644 --- a/tests/controllers/BudgetControllerTest.php +++ b/tests/controllers/BudgetControllerTest.php @@ -258,6 +258,29 @@ class BudgetControllerTest extends TestCase } + /** + * @covers FireflyIII\Http\Controllers\BudgetController::show + */ + public function testShowRepetition() + { + $repetition = FactoryMuffin::create('FireflyIII\Models\LimitRepetition'); + $budget = $repetition->budgetLimit->budget; + $repository = $this->mock('FireflyIII\Repositories\Budget\BudgetRepositoryInterface'); + $this->be($budget->user); + + $paginator = new LengthAwarePaginator(new Collection, 0, 20, 1); + + Amount::shouldReceive('getCurrencyCode')->andReturn('x'); + Amount::shouldReceive('format')->andReturn('x'); + $repository->shouldReceive('getJournals')->andReturn($paginator); + $repository->shouldReceive('getBudgetLimits')->andReturn(new Collection); + + + $this->call('GET', '/budgets/show/' . $budget->id . '/' . $repetition->id); + $this->assertResponseOk(); + + } + /** * @covers FireflyIII\Http\Controllers\BudgetController::store */ diff --git a/tests/helpers/ReportHelperTest.php b/tests/helpers/ReportHelperTest.php index 7adfaddf77..c2be29db02 100644 --- a/tests/helpers/ReportHelperTest.php +++ b/tests/helpers/ReportHelperTest.php @@ -4,8 +4,6 @@ use Carbon\Carbon; use FireflyIII\Helpers\Collection\Account as AccountCollection; use FireflyIII\Helpers\Report\ReportHelper; use FireflyIII\Models\AccountMeta; -use FireflyIII\Models\PiggyBankRepetition; -use FireflyIII\Models\Transaction; use Illuminate\Support\Collection; use League\FactoryMuffin\Facade as FactoryMuffin; @@ -48,13 +46,21 @@ class ReportHelperTest extends TestCase FactoryMuffin::create('FireflyIII\Models\AccountType'); FactoryMuffin::create('FireflyIII\Models\AccountType'); $asset = FactoryMuffin::create('FireflyIII\Models\AccountType'); + $cash = FactoryMuffin::create('FireflyIII\Models\AccountType'); $user = FactoryMuffin::create('FireflyIII\User'); for ($i = 0; $i < 5; $i++) { $account = FactoryMuffin::create('FireflyIII\Models\Account'); $account->user_id = $user->id; $account->account_type_id = $asset->id; $account->save(); + } + + $cashAccount = FactoryMuffin::create('FireflyIII\Models\Account'); + $cashAccount->user_id = $user->id; + $cashAccount->account_type_id = $cash->id; + $cashAccount->save(); + $this->be($user); /** @var AccountCollection $object */ $object = $this->object->getAccountReport(Carbon::now()->startOfMonth(), Carbon::now()->endOfMonth(), false); diff --git a/tests/helpers/ReportQueryTest.php b/tests/helpers/ReportQueryTest.php index af78cd15e8..5c413debde 100644 --- a/tests/helpers/ReportQueryTest.php +++ b/tests/helpers/ReportQueryTest.php @@ -80,16 +80,23 @@ class ReportQueryTest extends TestCase ] ); + $amount = 100; + if($i == 8) { + $amount = 0; // at least one "empty" journal. + } + // update both transactions $journal->transactions[0]->account_id = $account1->id; - $journal->transactions[0]->amount = -100; + $journal->transactions[0]->amount = $amount * -1; $journal->transactions[0]->save(); $journal->transactions[1]->account_id = $account2->id; - $journal->transactions[1]->amount = 100; + $journal->transactions[1]->amount = $amount; $journal->transactions[1]->save(); + + } $this->be($user); @@ -97,7 +104,7 @@ class ReportQueryTest extends TestCase $set = $this->object->expenseInPeriodCorrected($start, $end, false); - $this->assertCount(10, $set); + $this->assertCount(9, $set); } /** @@ -143,13 +150,18 @@ class ReportQueryTest extends TestCase ] ); + $amount = 100; + if($i == 8) { + $amount = 0; // at least one "empty" journal. + } + // update both transactions $journal->transactions[0]->account_id = $account1->id; - $journal->transactions[0]->amount = -100; + $journal->transactions[0]->amount = $amount * -1; $journal->transactions[0]->save(); $journal->transactions[1]->account_id = $account2->id; - $journal->transactions[1]->amount = 100; + $journal->transactions[1]->amount = $amount; $journal->transactions[1]->save(); } @@ -157,7 +169,7 @@ class ReportQueryTest extends TestCase $set = $this->object->expenseInPeriodCorrected($start, $end, true); - $this->assertCount(10, $set); + $this->assertCount(9, $set); } /** @@ -258,13 +270,18 @@ class ReportQueryTest extends TestCase ] ); + $amount = 100; + if($i == 8) { + $amount = 0; // at least one "empty" journal. + } + // update both transactions $journal->transactions[0]->account_id = $account1->id; - $journal->transactions[0]->amount = 100; + $journal->transactions[0]->amount = $amount; $journal->transactions[0]->save(); $journal->transactions[1]->account_id = $account2->id; - $journal->transactions[1]->amount = -100; + $journal->transactions[1]->amount = $amount * -1; $journal->transactions[1]->save(); } @@ -272,7 +289,7 @@ class ReportQueryTest extends TestCase $set = $this->object->incomeInPeriodCorrected($start, $end, false); - $this->assertCount(10, $set); + $this->assertCount(9, $set); } /** @@ -319,13 +336,18 @@ class ReportQueryTest extends TestCase ] ); + $amount = 100; + if($i == 8) { + $amount = 0; // at least one "empty" journal. + } + // update both transactions $journal->transactions[0]->account_id = $account1->id; - $journal->transactions[0]->amount = -100; + $journal->transactions[0]->amount = $amount * -1; $journal->transactions[0]->save(); $journal->transactions[1]->account_id = $account2->id; - $journal->transactions[1]->amount = 100; + $journal->transactions[1]->amount = $amount; $journal->transactions[1]->save(); } @@ -333,7 +355,7 @@ class ReportQueryTest extends TestCase $set = $this->object->incomeInPeriodCorrected($start, $end, true); - $this->assertCount(10, $set); + $this->assertCount(9, $set); } /** From ad1c61d959c61b6f0462d105389bb5a2d41eb9b3 Mon Sep 17 00:00:00 2001 From: James Cole Date: Thu, 4 Jun 2015 21:35:36 +0200 Subject: [PATCH 20/47] Improved test coverage. --- .../Controllers/Chart/AccountController.php | 6 +- app/Http/Controllers/Chart/BillController.php | 4 +- .../Controllers/Chart/BudgetController.php | 8 +- .../Controllers/Chart/CategoryController.php | 2 +- app/Http/Controllers/HomeController.php | 75 ------------ app/Http/Controllers/JsonController.php | 8 +- app/Http/Controllers/NewUserController.php | 2 +- app/Http/Controllers/ReportController.php | 11 +- app/Http/routes.php | 2 - app/Models/TransactionJournal.php | 2 +- .../Account/AccountRepository.php | 6 +- app/Support/Amount.php | 2 +- app/Support/Steam.php | 2 +- app/Support/Twig/Journal.php | 2 +- tests/controllers/HomeControllerTest.php | 28 +++++ tests/controllers/NewUserControllerTest.php | 108 ++++++++++++++++++ 16 files changed, 159 insertions(+), 109 deletions(-) create mode 100644 tests/controllers/NewUserControllerTest.php diff --git a/app/Http/Controllers/Chart/AccountController.php b/app/Http/Controllers/Chart/AccountController.php index af8aef6b57..9681fd7621 100644 --- a/app/Http/Controllers/Chart/AccountController.php +++ b/app/Http/Controllers/Chart/AccountController.php @@ -46,7 +46,7 @@ class AccountController extends Controller $cache->addProperty('all'); $cache->addProperty('accounts'); if ($cache->has()) { - return Response::json($cache->get()); + return Response::json($cache->get()); // @codeCoverageIgnore } @@ -116,7 +116,7 @@ class AccountController extends Controller $cache->addProperty('frontpage'); $cache->addProperty('accounts'); if ($cache->has()) { - return Response::json($cache->get()); + return Response::json($cache->get()); // @codeCoverageIgnore } @@ -176,7 +176,7 @@ class AccountController extends Controller $cache->addProperty('single'); $cache->addProperty($account->id); if ($cache->has()) { - return Response::json($cache->get()); + return Response::json($cache->get()); // @codeCoverageIgnore } while ($end >= $current) { diff --git a/app/Http/Controllers/Chart/BillController.php b/app/Http/Controllers/Chart/BillController.php index a1b8985ee5..7a4c2670bb 100644 --- a/app/Http/Controllers/Chart/BillController.php +++ b/app/Http/Controllers/Chart/BillController.php @@ -44,7 +44,7 @@ class BillController extends Controller $cache->addProperty('bill'); $cache->addProperty($bill->id); if ($cache->has()) { - return Response::json($cache->get()); + return Response::json($cache->get()); // @codeCoverageIgnore } // get first transaction or today for start: @@ -88,7 +88,7 @@ class BillController extends Controller $cache->addProperty('bills'); $cache->addProperty('frontpage'); if ($cache->has()) { - return Response::json($cache->get()); + return Response::json($cache->get()); // @codeCoverageIgnore } $bills = $repository->getActiveBills(); diff --git a/app/Http/Controllers/Chart/BudgetController.php b/app/Http/Controllers/Chart/BudgetController.php index dbd569d682..abcd2ce2a0 100644 --- a/app/Http/Controllers/Chart/BudgetController.php +++ b/app/Http/Controllers/Chart/BudgetController.php @@ -49,7 +49,7 @@ class BudgetController extends Controller $cache->addProperty('budget'); $cache->addProperty('budget'); if ($cache->has()) { - return Response::json($cache->get()); + return Response::json($cache->get()); // @codeCoverageIgnore } @@ -95,7 +95,7 @@ class BudgetController extends Controller $cache->addProperty($budget->id); $cache->addProperty($repetition->id); if ($cache->has()) { - return Response::json($cache->get()); + return Response::json($cache->get()); // @codeCoverageIgnore } $chart->addColumn(trans('firefly.day'), 'date'); @@ -149,7 +149,7 @@ class BudgetController extends Controller $cache->addProperty('budget'); $cache->addProperty('all'); if ($cache->has()) { - return Response::json($cache->get()); + return Response::json($cache->get()); // @codeCoverageIgnore } @@ -219,7 +219,7 @@ class BudgetController extends Controller $cache->addProperty('budget'); $cache->addProperty('year'); if ($cache->has()) { - return Response::json($cache->get()); + return Response::json($cache->get()); // @codeCoverageIgnore } // add columns: diff --git a/app/Http/Controllers/Chart/CategoryController.php b/app/Http/Controllers/Chart/CategoryController.php index fed7840398..b7c4bdb800 100644 --- a/app/Http/Controllers/Chart/CategoryController.php +++ b/app/Http/Controllers/Chart/CategoryController.php @@ -84,7 +84,7 @@ class CategoryController extends Controller $cache->addProperty('category'); $cache->addProperty('frontpage'); if ($cache->has()) { - return Response::json($cache->get()); + return Response::json($cache->get()); // @codeCoverageIgnore } $set = $repository->getCategoriesAndExpensesCorrected($start, $end); diff --git a/app/Http/Controllers/HomeController.php b/app/Http/Controllers/HomeController.php index 16a9e120b4..81e4dacc43 100644 --- a/app/Http/Controllers/HomeController.php +++ b/app/Http/Controllers/HomeController.php @@ -99,79 +99,4 @@ class HomeController extends Controller return view('index', compact('count', 'title', 'savings', 'subTitle', 'mainTitleIcon', 'transactions', 'savingsTotal', 'piggyBankAccounts')); } - - /** - * @codeCoverageIgnore - * @SuppressWarnings(PHPMD.ExcessiveMethodLength) - * @SuppressWarnings(PHPMD.CyclomaticComplexity) - */ - public function routes() - { - $directory = '/vagrant_data/Sites/firefly-iii-help'; - $languages = array_keys(Config::get('firefly.lang')); - $routes = []; - $ignored = [ - 'debugbar.openhandler', 'debugbar.assets.css', 'debugbar.assets.js', 'register', 'routes', 'daterange', - 'flush', 'delete-account-post', 'change-password-post', 'logout', 'login', 'tags.hideTagHelp', - 'budgets.postIncome', 'flush' - ]; - - $ignoreMatch = ['.store', '.update', '.destroy', 'json.']; - - $routeCollection = Route::getRoutes(); - /** @var \Illuminate\Routing\Route $object */ - foreach ($routeCollection as $object) { - // get name: - $name = $object->getName(); - // has name and not in ignore list? - if (strlen($name) > 0 && !in_array($name, $ignored)) { - - // not in ignoreMatch? - $continue = true; - foreach ($ignoreMatch as $ignore) { - $match = strpos($name, $ignore); - if (!($match === false)) { - $continue = false; - } - } - unset($ignore, $match); - - if ($continue) { - - $routes[] = $name; - - // check all languages: - foreach ($languages as $lang) { - $file = $directory . '/' . $lang . '/' . $name . '.md'; - if (!file_exists($file)) { - touch($file); - echo $name . '
'; - } - } - } - - - } - - } - - // loop directories with language file. - // tag the ones not in the list of approved routes. - foreach ($languages as $lang) { - $dir = $directory . '/' . $lang; - $set = scandir($dir); - foreach ($set as $entry) { - if ($entry != '.' && $entry != '..') { - $name = str_replace('.md', '', $entry); - if (!in_array($name, $routes)) { - $file = $dir . '/' . $entry; - unlink($file); - } - } - } - } - echo 'Done!'; - } - - } diff --git a/app/Http/Controllers/JsonController.php b/app/Http/Controllers/JsonController.php index 37ce8f34f5..6dafae3266 100644 --- a/app/Http/Controllers/JsonController.php +++ b/app/Http/Controllers/JsonController.php @@ -43,7 +43,7 @@ class JsonController extends Controller $cache->addProperty($end); $cache->addProperty('box-bills-paid'); if ($cache->has()) { - return Response::json($cache->get()); + return Response::json($cache->get()); // @codeCoverageIgnore } $amount = 0; @@ -97,7 +97,7 @@ class JsonController extends Controller $cache->addProperty($end); $cache->addProperty('box-bills-unpaid'); if ($cache->has()) { - return Response::json($cache->get()); + return Response::json($cache->get()); // @codeCoverageIgnore } $bills = $repository->getActiveBills(); @@ -156,7 +156,7 @@ class JsonController extends Controller $cache->addProperty($end); $cache->addProperty('box-in'); if ($cache->has()) { - return Response::json($cache->get()); + return Response::json($cache->get()); // @codeCoverageIgnore } $amount = $reportQuery->incomeInPeriodCorrected($start, $end, true)->sum('amount'); @@ -184,7 +184,7 @@ class JsonController extends Controller $cache->addProperty($end); $cache->addProperty('box-out'); if ($cache->has()) { - return Response::json($cache->get()); + return Response::json($cache->get()); // @codeCoverageIgnore } $amount = $reportQuery->expenseInPeriodCorrected($start, $end, true)->sum('amount'); diff --git a/app/Http/Controllers/NewUserController.php b/app/Http/Controllers/NewUserController.php index 29734168c2..569d19115b 100644 --- a/app/Http/Controllers/NewUserController.php +++ b/app/Http/Controllers/NewUserController.php @@ -116,6 +116,6 @@ class NewUserController extends Controller Session::flash('success', 'New account(s) created!'); Preferences::mark(); - return Redirect::route('home'); + return Redirect::route('index'); } } \ No newline at end of file diff --git a/app/Http/Controllers/ReportController.php b/app/Http/Controllers/ReportController.php index d776a58e1a..f806cd0328 100644 --- a/app/Http/Controllers/ReportController.php +++ b/app/Http/Controllers/ReportController.php @@ -141,18 +141,9 @@ class ReportController extends Controller Session::flash('gaEventAction', 'year'); Session::flash('gaEventLabel', $start->format('Y')); - return view( 'reports.year', - compact( - 'start', // the date for this report. - 'shared', // is a shared report? - 'accounts', // all accounts - 'incomes', 'expenses', // expenses and incomes. - 'subTitle', 'subTitleIcon', // subtitle and subtitle icon. - 'incomeTopLength', // length of income top X - 'expenseTopLength' // length of expense top X. - ) + compact('start', 'shared', 'accounts', 'incomes', 'expenses', 'subTitle', 'subTitleIcon', 'incomeTopLength', 'expenseTopLength') ); } diff --git a/app/Http/routes.php b/app/Http/routes.php index b813ee389c..cdff0a70a4 100644 --- a/app/Http/routes.php +++ b/app/Http/routes.php @@ -183,8 +183,6 @@ Route::controllers( ] ); -Route::get('/routes', ['uses' => 'HomeController@routes', 'as' => 'routes']); - /** * Home Controller */ diff --git a/app/Models/TransactionJournal.php b/app/Models/TransactionJournal.php index 9c577b68f9..8b00c9b9da 100644 --- a/app/Models/TransactionJournal.php +++ b/app/Models/TransactionJournal.php @@ -140,7 +140,7 @@ class TransactionJournal extends Model $cache->addProperty($this->id); $cache->addProperty('amount'); if ($cache->has()) { - return $cache->get(); + return $cache->get(); // @codeCoverageIgnore } diff --git a/app/Repositories/Account/AccountRepository.php b/app/Repositories/Account/AccountRepository.php index 15889ff5d7..23682dccd8 100644 --- a/app/Repositories/Account/AccountRepository.php +++ b/app/Repositories/Account/AccountRepository.php @@ -114,7 +114,7 @@ class AccountRepository implements AccountRepositoryInterface $cache->addProperty($preference->data); $cache->addProperty('frontPageaccounts'); if ($cache->has()) { - return $cache->get(); + return $cache->get(); // @codeCoverageIgnore } @@ -147,7 +147,7 @@ class AccountRepository implements AccountRepositoryInterface $cache->addProperty($start); $cache->addProperty($end); if ($cache->has()) { - return $cache->get(); + return $cache->get(); // @codeCoverageIgnore } $set = Auth::user() @@ -233,7 +233,7 @@ class AccountRepository implements AccountRepositoryInterface $cache->addProperty($ids); $cache->addProperty('piggyAccounts'); if ($cache->has()) { - return $cache->get(); + return $cache->get(); // @codeCoverageIgnore } $ids = array_unique($ids); diff --git a/app/Support/Amount.php b/app/Support/Amount.php index 101ff86d41..c492e5471a 100644 --- a/app/Support/Amount.php +++ b/app/Support/Amount.php @@ -89,7 +89,7 @@ class Amount $cache->addProperty('formatJournal'); if ($cache->has()) { - return $cache->get(); + return $cache->get(); // @codeCoverageIgnore } diff --git a/app/Support/Steam.php b/app/Support/Steam.php index 234559844b..627faba6d9 100644 --- a/app/Support/Steam.php +++ b/app/Support/Steam.php @@ -30,7 +30,7 @@ class Steam $cache->addProperty($date); $cache->addProperty($ignoreVirtualBalance); if ($cache->has()) { - return $cache->get(); + return $cache->get(); // @codeCoverageIgnore } diff --git a/app/Support/Twig/Journal.php b/app/Support/Twig/Journal.php index 293a2a5a34..36ef577e7a 100644 --- a/app/Support/Twig/Journal.php +++ b/app/Support/Twig/Journal.php @@ -33,7 +33,7 @@ class Journal extends Twig_Extension $cache->addProperty($journal->id); $cache->addProperty('typeIcon'); if ($cache->has()) { - return $cache->get(); + return $cache->get(); // @codeCoverageIgnore } $type = $journal->transactionType->type; diff --git a/tests/controllers/HomeControllerTest.php b/tests/controllers/HomeControllerTest.php index 4ec8a289d1..c4872d64bb 100644 --- a/tests/controllers/HomeControllerTest.php +++ b/tests/controllers/HomeControllerTest.php @@ -122,4 +122,32 @@ class HomeControllerTest extends TestCase } + /** + * @covers FireflyIII\Http\Controllers\HomeController::index + */ + public function testIndexEmpty() + { + $user = FactoryMuffin::create('FireflyIII\User'); + $repository = $this->mock('FireflyIII\Repositories\Account\AccountRepositoryInterface'); + + $this->be($user); + + // mock ALL THE THINGS! + $repository->shouldReceive('countAccounts')->once()->andReturn(0); + + // language preference: + $language = FactoryMuffin::create('FireflyIII\Models\Preference'); + $language->data = 'en'; + $language->save(); + Preferences::shouldReceive('get')->withAnyArgs()->andReturn($language); + + $lastActivity = FactoryMuffin::create('FireflyIII\Models\Preference'); + $lastActivity->data = microtime(); + Preferences::shouldReceive('lastActivity')->andReturn($lastActivity); + + $this->call('GET', '/'); + $this->assertResponseStatus(302); + $this->assertRedirectedToRoute('new-user.index'); + } + } diff --git a/tests/controllers/NewUserControllerTest.php b/tests/controllers/NewUserControllerTest.php new file mode 100644 index 0000000000..e27ddb0d72 --- /dev/null +++ b/tests/controllers/NewUserControllerTest.php @@ -0,0 +1,108 @@ +mock('FireflyIII\Repositories\Account\AccountRepositoryInterface'); + + $this->be($user); + + // mock ALL THE THINGS! + $repository->shouldReceive('countAccounts')->once()->andReturn(0); + + // language preference: + $language = FactoryMuffin::create('FireflyIII\Models\Preference'); + $language->data = 'en'; + $language->save(); + Preferences::shouldReceive('get')->withAnyArgs()->andReturn($language); + + $lastActivity = FactoryMuffin::create('FireflyIII\Models\Preference'); + $lastActivity->data = microtime(); + Preferences::shouldReceive('lastActivity')->andReturn($lastActivity); + + $this->call('GET', '/new-user'); + $this->assertResponseStatus(200); + } + + public function testIndexNoAccounts() + { + $user = FactoryMuffin::create('FireflyIII\User'); + $repository = $this->mock('FireflyIII\Repositories\Account\AccountRepositoryInterface'); + + + $this->be($user); + + // mock ALL THE THINGS! + $repository->shouldReceive('countAccounts')->once()->andReturn(3); + + // language preference: + $language = FactoryMuffin::create('FireflyIII\Models\Preference'); + $language->data = 'en'; + $language->save(); + Preferences::shouldReceive('get')->withAnyArgs()->andReturn($language); + + $lastActivity = FactoryMuffin::create('FireflyIII\Models\Preference'); + $lastActivity->data = microtime(); + Preferences::shouldReceive('lastActivity')->andReturn($lastActivity); + + $this->call('GET', '/new-user'); + $this->assertResponseStatus(302); + $this->assertRedirectedToRoute('index'); + + } + + public function testPostIndex() + { + $user = FactoryMuffin::create('FireflyIII\User'); + $currency = FactoryMuffin::create('FireflyIII\Models\TransactionCurrency'); + $account = FactoryMuffin::create('FireflyIII\Models\Account'); + $repository = $this->mock('FireflyIII\Repositories\Account\AccountRepositoryInterface'); + $this->be($user); + + $data = [ + '_token' => 'replaceMe', + 'bank_name' => 'Some Bank', + 'bank_balance' => '100', + 'balance_currency_id' => $currency->id, + 'savings_balance' => '100', + 'credit_card_limit' => '100', + + ]; + + $repository->shouldReceive('store')->andReturn($account); + + $this->call('POST', '/new-user/submit', $data); + $this->assertResponseStatus(302); + $this->assertRedirectedToRoute('index'); + + } + +} From d579992c98f8a3b7f3eda6ee2d34c05d4935637e Mon Sep 17 00:00:00 2001 From: James Cole Date: Thu, 4 Jun 2015 23:08:44 +0200 Subject: [PATCH 21/47] Slightly improved test coverage. --- tests/models/TransactionJournalModelTest.php | 254 ++++++++++++++++--- 1 file changed, 220 insertions(+), 34 deletions(-) diff --git a/tests/models/TransactionJournalModelTest.php b/tests/models/TransactionJournalModelTest.php index 26c98d80be..23e547620c 100644 --- a/tests/models/TransactionJournalModelTest.php +++ b/tests/models/TransactionJournalModelTest.php @@ -1,6 +1,5 @@ transactions[0]->account_id = $asset->id; - $withdrawal->transactions[0]->amount = -300; + $withdrawal->transactions[0]->amount = -300; $withdrawal->transactions[0]->save(); $withdrawal->transactions[1]->account_id = $expense->id; - $withdrawal->transactions[1]->amount = 300; + $withdrawal->transactions[1]->amount = 300; $withdrawal->transactions[1]->save(); $deposit->transactions[0]->account_id = $revenue->id; - $deposit->transactions[0]->amount = -89.88; + $deposit->transactions[0]->amount = -89.88; $deposit->transactions[0]->save(); $deposit->transactions[1]->account_id = $asset->id; - $deposit->transactions[1]->amount = 89.88; + $deposit->transactions[1]->amount = 89.88; $deposit->transactions[1]->save(); // connect to tag: @@ -149,27 +148,27 @@ class TransactionJournalModelTest extends TestCase $tag->transactionJournals()->save($transfer); // make accounts: - $expense = FactoryMuffin::create('FireflyIII\Models\Account'); + $expense = FactoryMuffin::create('FireflyIII\Models\Account'); $revenue = FactoryMuffin::create('FireflyIII\Models\Account'); - $asset = FactoryMuffin::create('FireflyIII\Models\Account'); + $asset = FactoryMuffin::create('FireflyIII\Models\Account'); $revenue->account_type_id = $asset->account_type_id; $revenue->save(); // transactions are already in place, update them: $withdrawal->transactions[0]->account_id = $asset->id; - $withdrawal->transactions[0]->amount = -123.45; + $withdrawal->transactions[0]->amount = -123.45; $withdrawal->transactions[0]->save(); $withdrawal->transactions[1]->account_id = $expense->id; - $withdrawal->transactions[1]->amount = 123.45; + $withdrawal->transactions[1]->amount = 123.45; $withdrawal->transactions[1]->save(); $transfer->transactions[0]->account_id = $revenue->id; - $transfer->transactions[0]->amount = -123.45; + $transfer->transactions[0]->amount = -123.45; $transfer->transactions[0]->save(); $transfer->transactions[1]->account_id = $asset->id; - $transfer->transactions[1]->amount = 123.45; + $transfer->transactions[1]->amount = 123.45; $transfer->transactions[1]->save(); $amount = $withdrawal->amount; @@ -220,11 +219,11 @@ class TransactionJournalModelTest extends TestCase $expense = FactoryMuffin::create('FireflyIII\Models\Account'); $asset = FactoryMuffin::create('FireflyIII\Models\Account'); - $withdrawal->transactions[0]->amount = -300; + $withdrawal->transactions[0]->amount = -300; $withdrawal->transactions[0]->account_id = $asset->id; $withdrawal->transactions[0]->save(); - $withdrawal->transactions[1]->amount = 300; + $withdrawal->transactions[1]->amount = 300; $withdrawal->transactions[1]->account_id = $expense->id; $withdrawal->transactions[1]->save(); @@ -256,11 +255,11 @@ class TransactionJournalModelTest extends TestCase // update transactions $deposit->transactions[0]->account_id = $asset->id; - $deposit->transactions[0]->amount = 300; + $deposit->transactions[0]->amount = 300; $deposit->transactions[0]->save(); $deposit->transactions[1]->account_id = $revenue->id; - $deposit->transactions[1]->amount = -300; + $deposit->transactions[1]->amount = -300; $deposit->transactions[1]->save(); @@ -275,7 +274,9 @@ class TransactionJournalModelTest extends TestCase */ public function testGetAssetAccountAttributeFallback() { - FactoryMuffin::create('FireflyIII\Models\TransactionType'); + + FactoryMuffin::create('FireflyIII\Models\TransactionType'); // withdrawal + FactoryMuffin::create('FireflyIII\Models\TransactionType'); // deposit // make accounts FactoryMuffin::create('FireflyIII\Models\Account'); @@ -283,21 +284,21 @@ class TransactionJournalModelTest extends TestCase $asset = FactoryMuffin::create('FireflyIII\Models\Account'); // make withdrawal - $depositType = FactoryMuffin::create('FireflyIII\Models\TransactionType'); - $deposit = FactoryMuffin::create('FireflyIII\Models\TransactionJournal'); - $deposit->transaction_type_id = $depositType->id; - $deposit->save(); + $transferType = FactoryMuffin::create('FireflyIII\Models\TransactionType'); // transfer + $transfer = FactoryMuffin::create('FireflyIII\Models\TransactionJournal'); + $transfer->transaction_type_id = $transferType->id; + $transfer->save(); - $deposit->transactions[0]->account_id = $asset->id; - $deposit->transactions[0]->amount = 300; - $deposit->transactions[0]->save(); + $transfer->transactions[0]->account_id = $asset->id; + $transfer->transactions[0]->amount = 300; + $transfer->transactions[0]->save(); - $deposit->transactions[1]->account_id = $revenue->id; - $deposit->transactions[1]->amount = -300; - $deposit->transactions[1]->save(); + $transfer->transactions[1]->account_id = $revenue->id; + $transfer->transactions[1]->amount = -300; + $transfer->transactions[1]->save(); // get asset account: - $result = $deposit->asset_account; + $result = $transfer->asset_account; $this->assertEquals($asset->id, $result->id); } @@ -318,13 +319,12 @@ class TransactionJournalModelTest extends TestCase $withdrawal->save(); - $withdrawal->transactions[0]->account_id = $asset->id; - $withdrawal->transactions[0]->amount = -300; + $withdrawal->transactions[0]->amount = -300; $withdrawal->transactions[0]->save(); $withdrawal->transactions[1]->account_id = $expense->id; - $withdrawal->transactions[1]->amount = 300; + $withdrawal->transactions[1]->amount = 300; $withdrawal->transactions[1]->save(); // get asset account: @@ -333,6 +333,102 @@ class TransactionJournalModelTest extends TestCase $this->assertEquals($asset->id, $result->id); } + /** + * @covers FireflyIII\Models\TransactionJournal::getCorrectAmountAttribute + */ + public function testGetCorrectAmountAttribute() + { + $withdrawal = FactoryMuffin::create('FireflyIII\Models\TransactionType'); // withdrawal + + // make accounts + FactoryMuffin::create('FireflyIII\Models\Account'); + $revenue = FactoryMuffin::create('FireflyIII\Models\Account'); + $asset = FactoryMuffin::create('FireflyIII\Models\Account'); + + // make withdrawal + $journal = FactoryMuffin::create('FireflyIII\Models\TransactionJournal'); + $journal->transaction_type_id = $withdrawal->id; + $journal->save(); + + $journal->transactions[0]->account_id = $asset->id; + $journal->transactions[0]->amount = 300; + $journal->transactions[0]->save(); + + $journal->transactions[1]->account_id = $revenue->id; + $journal->transactions[1]->amount = -300; + $journal->transactions[1]->save(); + + // get asset account: + $result = $journal->correct_amount; + + $this->assertEquals(-300, $result); + } + + /** + * @covers FireflyIII\Models\TransactionJournal::getCorrectAmountAttribute + */ + public function testGetCorrectAmountAttributeDeposit() + { + FactoryMuffin::create('FireflyIII\Models\TransactionType'); // withdrawal + $deposit = FactoryMuffin::create('FireflyIII\Models\TransactionType'); // deposit + + // make accounts + FactoryMuffin::create('FireflyIII\Models\Account'); + $revenue = FactoryMuffin::create('FireflyIII\Models\Account'); + $asset = FactoryMuffin::create('FireflyIII\Models\Account'); + + // make withdrawal + $journal = FactoryMuffin::create('FireflyIII\Models\TransactionJournal'); + $journal->transaction_type_id = $deposit->id; + $journal->save(); + + $journal->transactions[0]->account_id = $asset->id; + $journal->transactions[0]->amount = 300; + $journal->transactions[0]->save(); + + $journal->transactions[1]->account_id = $revenue->id; + $journal->transactions[1]->amount = -300; + $journal->transactions[1]->save(); + + // get asset account: + $result = $journal->correct_amount; + + $this->assertEquals(300, $result); + } + + /** + * @covers FireflyIII\Models\TransactionJournal::getCorrectAmountAttribute + */ + public function testGetCorrectAmountAttributeTransfer() + { + FactoryMuffin::create('FireflyIII\Models\TransactionType'); // withdrawal + FactoryMuffin::create('FireflyIII\Models\TransactionType'); // deposit + $transfer = FactoryMuffin::create('FireflyIII\Models\TransactionType'); // transfer + + // make accounts + FactoryMuffin::create('FireflyIII\Models\Account'); + $revenue = FactoryMuffin::create('FireflyIII\Models\Account'); + $asset = FactoryMuffin::create('FireflyIII\Models\Account'); + + // make withdrawal + $journal = FactoryMuffin::create('FireflyIII\Models\TransactionJournal'); + $journal->transaction_type_id = $transfer->id; + $journal->save(); + + $journal->transactions[0]->account_id = $asset->id; + $journal->transactions[0]->amount = 300; + $journal->transactions[0]->save(); + + $journal->transactions[1]->account_id = $revenue->id; + $journal->transactions[1]->amount = -300; + $journal->transactions[1]->save(); + + // get asset account: + $result = $journal->correct_amount; + + $this->assertEquals('0', $result); + } + /** * @covers FireflyIII\Models\TransactionJournal::getDestinationAccountAttribute */ @@ -350,11 +446,11 @@ class TransactionJournalModelTest extends TestCase $asset = FactoryMuffin::create('FireflyIII\Models\Account'); $deposit->transactions[0]->account_id = $asset->id; - $deposit->transactions[0]->amount = 300; + $deposit->transactions[0]->amount = 300; $deposit->transactions[0]->save(); $deposit->transactions[1]->account_id = $revenue->id; - $deposit->transactions[1]->amount = -300; + $deposit->transactions[1]->amount = -300; $deposit->transactions[1]->save(); // get asset account: @@ -380,11 +476,11 @@ class TransactionJournalModelTest extends TestCase $asset = FactoryMuffin::create('FireflyIII\Models\Account'); $deposit->transactions[0]->account_id = $asset->id; - $deposit->transactions[0]->amount = -300; + $deposit->transactions[0]->amount = -300; $deposit->transactions[0]->save(); $deposit->transactions[1]->account_id = $revenue->id; - $deposit->transactions[1]->amount = -300; + $deposit->transactions[1]->amount = -300; $deposit->transactions[1]->save(); // get asset account: @@ -393,4 +489,94 @@ class TransactionJournalModelTest extends TestCase $this->assertEquals($asset->id, $result->id); } + /** + * @covers FireflyIII\Models\TransactionJournal::getExpenseAccountAttribute + */ + public function testGetExpenseAccountAttribute() + { + FactoryMuffin::create('FireflyIII\Models\TransactionType'); // withdrawal + $depositType = FactoryMuffin::create('FireflyIII\Models\TransactionType'); // deposit + $deposit = FactoryMuffin::create('FireflyIII\Models\TransactionJournal'); + $deposit->transaction_type_id = $depositType->id; + $deposit->save(); + + // make accounts + FactoryMuffin::create('FireflyIII\Models\Account'); + $revenue = FactoryMuffin::create('FireflyIII\Models\Account'); + $asset = FactoryMuffin::create('FireflyIII\Models\Account'); + + $deposit->transactions[0]->account_id = $asset->id; + $deposit->transactions[0]->amount = 300; + $deposit->transactions[0]->save(); + + $deposit->transactions[1]->account_id = $revenue->id; + $deposit->transactions[1]->amount = -300; + $deposit->transactions[1]->save(); + + // get asset account: + $result = $deposit->expense_account; + + $this->assertEquals($revenue->id, $result->id); + } + + /** + * @covers FireflyIII\Models\TransactionJournal::getExpenseAccountAttribute + */ + public function testGetExpenseAccountAttributeFallback() + { + FactoryMuffin::create('FireflyIII\Models\TransactionType'); // withdrawal + FactoryMuffin::create('FireflyIII\Models\TransactionType'); // deposit + $transferType = FactoryMuffin::create('FireflyIII\Models\TransactionType'); // transfer + $transfer = FactoryMuffin::create('FireflyIII\Models\TransactionJournal'); + $transfer->transaction_type_id = $transferType->id; + $transfer->save(); + + // make accounts + FactoryMuffin::create('FireflyIII\Models\Account'); + $revenue = FactoryMuffin::create('FireflyIII\Models\Account'); + $asset = FactoryMuffin::create('FireflyIII\Models\Account'); + + $transfer->transactions[0]->account_id = $asset->id; + $transfer->transactions[0]->amount = 300; + $transfer->transactions[0]->save(); + + $transfer->transactions[1]->account_id = $revenue->id; + $transfer->transactions[1]->amount = -300; + $transfer->transactions[1]->save(); + + // get asset account: + $result = $transfer->expense_account; + + $this->assertEquals($asset->id, $result->id); + } + + /** + * @covers FireflyIII\Models\TransactionJournal::getExpenseAccountAttribute + */ + public function testGetExpenseAccountAttributeWithdrawal() + { + $withdrawalType = FactoryMuffin::create('FireflyIII\Models\TransactionType'); // withdrawal + $withdrawal = FactoryMuffin::create('FireflyIII\Models\TransactionJournal'); + $withdrawal->transaction_type_id = $withdrawalType->id; + $withdrawal->save(); + + // make accounts + FactoryMuffin::create('FireflyIII\Models\Account'); + $revenue = FactoryMuffin::create('FireflyIII\Models\Account'); + $asset = FactoryMuffin::create('FireflyIII\Models\Account'); + + $withdrawal->transactions[0]->account_id = $asset->id; + $withdrawal->transactions[0]->amount = 300; + $withdrawal->transactions[0]->save(); + + $withdrawal->transactions[1]->account_id = $revenue->id; + $withdrawal->transactions[1]->amount = -300; + $withdrawal->transactions[1]->save(); + + // get asset account: + $result = $withdrawal->expense_account; + + $this->assertEquals($asset->id, $result->id); + } + } From fea9bc4e7ebc9b4c0a2bd670db8db42c0962e769 Mon Sep 17 00:00:00 2001 From: James Cole Date: Fri, 5 Jun 2015 07:10:51 +0200 Subject: [PATCH 22/47] Increased coverage and fixed a nasty bug. --- app/Http/Controllers/Auth/AuthController.php | 1 - app/Http/Controllers/NewUserController.php | 20 +-- app/Models/Account.php | 2 +- app/Models/TransactionJournal.php | 4 +- .../Account/AccountRepository.php | 5 +- .../Category/CategoryRepository.php | 4 +- tests/factories/all.php | 20 ++- tests/repositories/AccountRepositoryTest.php | 120 ++++++++++-------- tests/repositories/CategoryRepositoryTest.php | 68 +++++----- tests/repositories/JournalRepositoryTest.php | 37 +++++- 10 files changed, 161 insertions(+), 120 deletions(-) diff --git a/app/Http/Controllers/Auth/AuthController.php b/app/Http/Controllers/Auth/AuthController.php index 7819d86383..4330203b5c 100644 --- a/app/Http/Controllers/Auth/AuthController.php +++ b/app/Http/Controllers/Auth/AuthController.php @@ -109,7 +109,6 @@ class AuthController extends Controller if (User::count() == 1) { $admin = Role::where('name', 'owner')->first(); $this->auth->user()->attachRole($admin); - // $this->auth->user()->roles()->save($admin); } diff --git a/app/Http/Controllers/NewUserController.php b/app/Http/Controllers/NewUserController.php index 569d19115b..8a14f74632 100644 --- a/app/Http/Controllers/NewUserController.php +++ b/app/Http/Controllers/NewUserController.php @@ -23,7 +23,7 @@ class NewUserController extends Controller /** * @param AccountRepositoryInterface $repository * - * @return \Illuminate\View\View + * @@return \Illuminate\Http\RedirectResponse|\Illuminate\View\View */ public function index(AccountRepositoryInterface $repository) { @@ -45,6 +45,8 @@ class NewUserController extends Controller /** * @param NewUserFormRequest $request * @param AccountRepositoryInterface $repository + * + * @return \Illuminate\Http\RedirectResponse */ public function submit(NewUserFormRequest $request, AccountRepositoryInterface $repository) { @@ -97,20 +99,8 @@ class NewUserController extends Controller $creditCard = $repository->store($creditAccount); // store meta for CC: - AccountMeta::create( - [ - 'name' => 'ccType', - 'data' => 'monthlyFull', - 'account_id' => $creditCard->id, - ] - ); - AccountMeta::create( - [ - 'name' => 'ccMonthlyPaymentDate', - 'data' => Carbon::now()->year . '-01-01', - 'account_id' => $creditCard->id, - ] - ); + AccountMeta::create(['name' => 'ccType', 'data' => 'monthlyFull', 'account_id' => $creditCard->id,]); + AccountMeta::create(['name' => 'ccMonthlyPaymentDate', 'data' => Carbon::now()->year . '-01-01', 'account_id' => $creditCard->id,]); } Session::flash('success', 'New account(s) created!'); diff --git a/app/Models/Account.php b/app/Models/Account.php index f5092a9c96..943ecfb862 100644 --- a/app/Models/Account.php +++ b/app/Models/Account.php @@ -46,7 +46,7 @@ use Watson\Validating\ValidatingTrait; * @property mixed lastActivityDate * @property mixed piggyBalance * @property mixed difference - * @propery mixed percentage + * @property mixed percentage */ class Account extends Model { diff --git a/app/Models/TransactionJournal.php b/app/Models/TransactionJournal.php index 8b00c9b9da..ae335b6ead 100644 --- a/app/Models/TransactionJournal.php +++ b/app/Models/TransactionJournal.php @@ -68,7 +68,9 @@ use Watson\Validating\ValidatingTrait; * @property mixed account_id * @property mixed name * @property mixed symbol - * @property-read mixed $correct_amount + * @property-read mixed $correct_amount + * @method static \FireflyIII\Models\TransactionJournal orderBy + * @method static \FireflyIII\Models\TransactionJournal|null first */ class TransactionJournal extends Model { diff --git a/app/Repositories/Account/AccountRepository.php b/app/Repositories/Account/AccountRepository.php index 23682dccd8..d472825600 100644 --- a/app/Repositories/Account/AccountRepository.php +++ b/app/Repositories/Account/AccountRepository.php @@ -373,8 +373,9 @@ class AccountRepository implements AccountRepositoryInterface */ public function openingBalanceTransaction(Account $account) { - return TransactionJournal::accountIs($account) - ->orderBy('transaction_journals.date', 'ASC') + return TransactionJournal + ::orderBy('transaction_journals.date', 'ASC') + ->accountIs($account) ->orderBy('created_at', 'ASC') ->first(['transaction_journals.*']); } diff --git a/app/Repositories/Category/CategoryRepository.php b/app/Repositories/Category/CategoryRepository.php index 1fbb964e42..19e633be6b 100644 --- a/app/Repositories/Category/CategoryRepository.php +++ b/app/Repositories/Category/CategoryRepository.php @@ -75,14 +75,14 @@ class CategoryRepository implements CategoryRepositoryInterface ->where('categories.user_id', Auth::user()->id) ->after($start) ->transactionTypes(['Withdrawal']) - ->groupBy('categories.id') ->get(['categories.id as category_id', 'categories.encrypted as category_encrypted', 'categories.name', 'transaction_journals.*']); $result = []; foreach ($set as $entry) { $categoryId = intval($entry->category_id); if (isset($result[$categoryId])) { - $result[$categoryId]['sum'] += floatval($entry->amount); + bcscale(2); + $result[$categoryId]['sum'] = bcadd($result[$categoryId]['sum'], $entry->amount); } else { $isEncrypted = intval($entry->category_encrypted) == 1 ? true : false; $name = strlen($entry->name) == 0 ? trans('firefly.no_category') : $entry->name; diff --git a/tests/factories/all.php b/tests/factories/all.php index f9c35f9047..6da5476d3d 100644 --- a/tests/factories/all.php +++ b/tests/factories/all.php @@ -9,6 +9,9 @@ if (!class_exists('RandomString')) { */ class RandomString { + public static $count = 0; + public static $set = []; + /** * @param int $length * @@ -18,11 +21,22 @@ if (!class_exists('RandomString')) { { $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; $charactersLength = strlen($characters); - $randomString = ''; + + + $randomString = ''; for ($i = 0; $i < $length; $i++) { $randomString .= $characters[rand(0, $charactersLength - 1)]; } + while (in_array($randomString, self::$set)) { + // create another if its in the current $set: + $randomString = ''; + for ($i = 0; $i < $length; $i++) { + $randomString .= $characters[rand(0, $charactersLength - 1)]; + } + } + self::$set[] = $randomString; + return $randomString; } @@ -32,7 +46,7 @@ if (!class_exists('RandomString')) { FactoryMuffin::define( 'FireflyIII\Models\Role', [ - 'name' => 'word', + 'name' => 'word', ] ); @@ -201,7 +215,7 @@ FactoryMuffin::define( return RandomString::generateRandomString(3); }, 'symbol' => function () { - return RandomString::generateRandomString(2); + return RandomString::generateRandomString(8); }, 'name' => 'word' ] diff --git a/tests/repositories/AccountRepositoryTest.php b/tests/repositories/AccountRepositoryTest.php index d96994e8b0..c2bbaf16cf 100644 --- a/tests/repositories/AccountRepositoryTest.php +++ b/tests/repositories/AccountRepositoryTest.php @@ -3,7 +3,6 @@ use Carbon\Carbon; use FireflyIII\Models\Account; use FireflyIII\Models\AccountMeta; use FireflyIII\Models\Preference; -use FireflyIII\Models\Transaction; use FireflyIII\Repositories\Account\AccountRepository; use Illuminate\Pagination\LengthAwarePaginator; use League\FactoryMuffin\Facade as FactoryMuffin; @@ -113,9 +112,9 @@ class AccountRepositoryTest extends TestCase */ public function testGetFirstTransaction() { - $account = FactoryMuffin::create('FireflyIII\Models\Account'); - $journal = FactoryMuffin::create('FireflyIII\Models\TransactionJournal'); - $first = $journal->transactions()->orderBy('date', 'DESC')->first(); + $account = FactoryMuffin::create('FireflyIII\Models\Account'); + $journal = FactoryMuffin::create('FireflyIII\Models\TransactionJournal'); + $first = $journal->transactions()->orderBy('date', 'DESC')->first(); $first->account_id = $account->id; $first->save(); @@ -414,63 +413,80 @@ class AccountRepositoryTest extends TestCase public function testGetTransfersInRange() { FactoryMuffin::create('FireflyIII\Models\Account'); - - - // three transfers, two out of range: - FactoryMuffin::create('FireflyIII\Models\TransactionType'); - FactoryMuffin::create('FireflyIII\Models\TransactionType'); - $journal1 = FactoryMuffin::create('FireflyIII\Models\TransactionJournal'); - $journal2 = FactoryMuffin::create('FireflyIII\Models\TransactionJournal'); - $journal3 = FactoryMuffin::create('FireflyIII\Models\TransactionJournal'); - $account = FactoryMuffin::create('FireflyIII\Models\Account'); - $journal2->transaction_type_id = $journal1->transaction_type_id; - $journal3->transaction_type_id = $journal1->transaction_type_id; - - // transactions are already present, update them! - $journal1->transactions[0]->account_id = $account->id; - $journal1->transactions[0]->amount = 100; - $journal1->transactions[1]->account_id = $account->id; - $journal1->transactions[1]->amount = 100; - $journal2->transactions[0]->account_id = $account->id; - $journal2->transactions[0]->amount = 100; - $journal2->transactions[1]->account_id = $account->id; - $journal2->transactions[1]->amount = 100; - $journal3->transactions[0]->account_id = $account->id; - $journal3->transactions[0]->amount = 100; - $journal3->transactions[1]->account_id = $account->id; - $journal3->transactions[1]->amount = 100; - $journal1->transactions[0]->save(); - $journal1->transactions[1]->save(); - $journal2->transactions[0]->save(); - $journal2->transactions[1]->save(); - $journal3->transactions[0]->save(); - $journal3->transactions[1]->save(); - - // check date: + FactoryMuffin::create('FireflyIII\Models\TransactionType'); // withdrawal + FactoryMuffin::create('FireflyIII\Models\TransactionType'); // deposit + FactoryMuffin::create('FireflyIII\Models\AccountType'); // expense + FactoryMuffin::create('FireflyIII\Models\AccountType'); // revenue + $asset = FactoryMuffin::create('FireflyIII\Models\AccountType'); // asset + $transfer = FactoryMuffin::create('FireflyIII\Models\TransactionType'); // transfer + $user = FactoryMuffin::create('FireflyIII\User'); // user! + $accounts = []; + $opposings = []; // opposing accounts. + $journals = []; + // dates $start = new Carbon('2014-01-01'); $end = new Carbon('2014-01-31'); $inRange = new Carbon('2014-01-15'); $before = new Carbon('2013-01-15'); - $after = new Carbon('2015-01-15'); - // journal 1 will match: - $journal1->date = $inRange; - $journal1->user_id = $account->user_id; - $journal2->date = $before; - $journal2->user_id = $account->user_id; - $journal3->date = $after; - $journal3->user_id = $account->user_id; - $journal1->save(); - $journal2->save(); - $journal3->save(); - $this->be($account->user); + // create two accounts: + for ($i = 0; $i < 2; $i++) { + $account = FactoryMuffin::create('FireflyIII\Models\Account'); + $account->account_type_id = $asset->id; + $account->user_id = $user->id; + $account->save(); + $accounts[] = $account; - $set = $this->object->getTransfersInRange($account, $start, $end); + $opposing = FactoryMuffin::create('FireflyIII\Models\Account'); + $opposing->account_type_id = $asset->id; + $opposing->user_id = $user->id; + $opposing->save(); + $opposings[] = $opposing; + } + + // for each account, create ten journals + foreach ($accounts as $index => $account) { + for ($i = 0; $i < 10; $i++) { + $journal = FactoryMuffin::create('FireflyIII\Models\TransactionJournal'); + $journal->user_id = $user->id; + $journal->transaction_type_id = $transfer->id; + $journal->save(); + + // if $i < 6, transfer is in range: + if ($i < 6) { + $journal->date = $inRange; + } else { + $journal->date = $before; + } + + /* + * Transfers can go either way (see the amount) + */ + if($i < 4) { + $amount = 100; + } else { + $amount = -100; + } - $this->assertEquals(1, $set->count()); + $journal->transactions[0]->account_id = $account->id; + $journal->transactions[0]->amount = $amount; + $journal->transactions[1]->account_id = $opposings[$index]->id; + $journal->transactions[1]->amount = $amount * -1; + $journal->transactions[0]->save(); + $journal->transactions[1]->save(); + // save journal: + $journal->save(); + $journals[] = $journal; + } + } + $this->be($user); + + $set = $this->object->getTransfersInRange($accounts[0], $start, $end); + + $this->assertEquals(4, $set->count()); $this->assertEquals(100, $set->first()->amount); - $this->assertEquals($journal1->description, $set->first()->description); + $this->assertEquals($journals[0]->description, $set->first()->description); } diff --git a/tests/repositories/CategoryRepositoryTest.php b/tests/repositories/CategoryRepositoryTest.php index 9ea3727bc4..d8fcf3ed76 100644 --- a/tests/repositories/CategoryRepositoryTest.php +++ b/tests/repositories/CategoryRepositoryTest.php @@ -84,53 +84,43 @@ class CategoryRepositoryTest extends TestCase */ public function testGetCategoriesAndExpensesCorrected() { - $user = FactoryMuffin::create('FireflyIII\User'); - $type = FactoryMuffin::create('FireflyIII\Models\TransactionType'); - // some journals and categories: - for ($i = 0; $i < 5; $i++) { - $journal = FactoryMuffin::create('FireflyIII\Models\TransactionJournal'); + $user = FactoryMuffin::create('FireflyIII\User'); + $type = FactoryMuffin::create('FireflyIII\Models\TransactionType'); // withdrawal + $currency = FactoryMuffin::create('FireflyIII\Models\TransactionCurrency'); // something + + // some dates: + $start = new Carbon('2014-01-01'); + $end = new Carbon('2014-01-31'); + $inRange = new Carbon('2014-01-12'); + + // generate three categories + // with ten journals each: + for ($i = 0; $i < 3; $i++) { + // category: /** @var Category $category */ - $category = FactoryMuffin::create('FireflyIII\Models\Category'); - $journal->user_id = $user->id; - $journal->date = new Carbon('2015-02-11'); - $journal->transaction_type_id = $type->id; - $category->user_id = $user->id; - $category->transactionjournals()->save($journal); - $journal->save(); - $category->save(); - } - - for ($i = 0; $i < 5; $i++) { - $journal1 = FactoryMuffin::create('FireflyIII\Models\TransactionJournal'); - $journal2 = FactoryMuffin::create('FireflyIII\Models\TransactionJournal'); - /** @var Category $category */ - $category = FactoryMuffin::create('FireflyIII\Models\Category'); - - $journal1->user_id = $user->id; - $journal1->date = new Carbon('2015-02-11'); - $journal1->transaction_type_id = $type->id; - - $journal2->user_id = $user->id; - $journal2->date = new Carbon('2015-02-11'); - $journal2->transaction_type_id = $type->id; - + $category = FactoryMuffin::create('FireflyIII\Models\Category'); $category->user_id = $user->id; - $category->transactionjournals()->save($journal1); - $category->transactionjournals()->save($journal2); - - $journal1->save(); - $journal2->save(); $category->save(); - } + for ($j = 0; $j < 10; $j++) { + $journal = FactoryMuffin::create('FireflyIII\Models\TransactionJournal'); + $journal->user_id = $user->id; + $journal->transaction_currency_id = $currency->id; + $journal->transaction_type_id = $type->id; // make it a withdrawal + $journal->date = $inRange; + $journal->save(); + // connect to category: + $category->transactionjournals()->save($journal); + } + } $this->be($user); - $set = $this->object->getCategoriesAndExpensesCorrected(new Carbon('2015-02-01'), new Carbon('2015-02-28')); - $this->assertCount(10, $set); + $set = $this->object->getCategoriesAndExpensesCorrected($start, $end); + $this->assertCount(3, $set); reset($set); - // every journal has amount 100. - $this->assertEquals(100, current($set)['sum']); + // 10 journals of 100 each = 1000. + $this->assertEquals('1000', current($set)['sum']); } /** diff --git a/tests/repositories/JournalRepositoryTest.php b/tests/repositories/JournalRepositoryTest.php index e0bc5443b5..a5e32593a7 100644 --- a/tests/repositories/JournalRepositoryTest.php +++ b/tests/repositories/JournalRepositoryTest.php @@ -1,4 +1,5 @@ transaction_type_id = $withdrawal; + $journal->date = $today; + $journal->save(); + + // update transactions: + $journal->transactions[0]->amount = -100; + $journal->transactions[0]->account_id = $asset->id; + $journal->transactions[0]->save(); + + $journal->transactions[1]->amount = 100; + $journal->transactions[1]->account_id = $expense->id; + $journal->transactions[1]->save(); + + // connect to expense + $today->addDay(); + } - $transaction = FactoryMuffin::create('FireflyIII\Models\Transaction'); - $before = $this->object->getAmountBefore($transaction->transactionjournal, $transaction); - - $this->assertEquals(0, $before); + $before = $this->object->getAmountBefore($journal, $journal->transactions[1]); + // five transactions, we check the last one, so amount should be 400. + $this->assertEquals(400, $before); } /** From d4830052193cfff390dfc08a9810a45beffd96fc Mon Sep 17 00:00:00 2001 From: James Cole Date: Fri, 5 Jun 2015 07:49:07 +0200 Subject: [PATCH 23/47] Expanded some tests. --- app/Http/Middleware/Reminders.php | 11 +-- app/Repositories/Tag/TagRepository.php | 8 +- .../Tag/TagRepositoryInterface.php | 2 +- tests/repositories/TagRepositoryTest.php | 87 ++++++++++++++++++- 4 files changed, 96 insertions(+), 12 deletions(-) diff --git a/app/Http/Middleware/Reminders.php b/app/Http/Middleware/Reminders.php index 15e54448b2..0be752e89e 100644 --- a/app/Http/Middleware/Reminders.php +++ b/app/Http/Middleware/Reminders.php @@ -8,6 +8,7 @@ use Closure; use FireflyIII\Models\PiggyBank; use FireflyIII\Models\Reminder; use FireflyIII\Support\CacheProperties; +use FireflyIII\User; use Illuminate\Contracts\Auth\Guard; use Illuminate\Http\Request; use View; @@ -49,7 +50,8 @@ class Reminders { - if ($this->auth->check() && !$request->isXmlHttpRequest()) { + $user = $this->auth->user(); + if ($this->auth->check() && !$request->isXmlHttpRequest() && $user instanceof User) { // do reminders stuff. // abuse CacheProperties to find out if we need to do this: @@ -63,7 +65,7 @@ class Reminders return $next($request); } - $piggyBanks = $this->auth->user()->piggyBanks()->where('remind_me', 1)->get(); + $piggyBanks = $user->piggyBanks()->where('remind_me', 1)->get(); /** @var \FireflyIII\Helpers\Reminders\ReminderHelperInterface $helper */ $helper = App::make('FireflyIII\Helpers\Reminders\ReminderHelperInterface'); @@ -75,12 +77,11 @@ class Reminders // delete invalid reminders // this is a construction SQLITE cannot handle :( if (env('DB_CONNECTION') != 'sqlite') { - Reminder::whereUserId($this->auth->user()->id)->leftJoin('piggy_banks', 'piggy_banks.id', '=', 'remindersable_id') - ->whereNull('piggy_banks.id')->delete(); + Reminder::whereUserId($user->id)->leftJoin('piggy_banks', 'piggy_banks.id', '=', 'remindersable_id')->whereNull('piggy_banks.id')->delete(); } // get and list active reminders: - $reminders = $this->auth->user()->reminders()->today()->get(); + $reminders = $user->reminders()->today()->get(); $reminders->each( function (Reminder $reminder) use ($helper) { $reminder->description = $helper->getReminderText($reminder); diff --git a/app/Repositories/Tag/TagRepository.php b/app/Repositories/Tag/TagRepository.php index 252a08a2a9..6a3323f074 100644 --- a/app/Repositories/Tag/TagRepository.php +++ b/app/Repositories/Tag/TagRepository.php @@ -9,7 +9,6 @@ use FireflyIII\Models\Account; use FireflyIII\Models\Tag; use FireflyIII\Models\TransactionJournal; use FireflyIII\Models\TransactionType; -use Illuminate\Support\Collection; /** * Class TagRepository @@ -64,14 +63,15 @@ class TagRepository implements TagRepositoryInterface * @param Carbon $start * @param Carbon $end * - * @return integer + * @return string */ public function coveredByBalancingActs(Account $account, Carbon $start, Carbon $end) { // the quickest way to do this is by scanning all balancingAct tags // because there will be less of them any way. $tags = Auth::user()->tags()->where('tagMode', 'balancingAct')->get(); - $amount = 0; + $amount = '0'; + bcscale(2); /** @var Tag $tag */ foreach ($tags as $tag) { @@ -80,7 +80,7 @@ class TagRepository implements TagRepositoryInterface /** @var TransactionJournal $journal */ foreach ($journals as $journal) { if ($journal->destination_account->id == $account->id) { - $amount += $journal->amount; + $amount = bcadd($amount, $journal->amount); } } } diff --git a/app/Repositories/Tag/TagRepositoryInterface.php b/app/Repositories/Tag/TagRepositoryInterface.php index 463e0979d2..7d76fa30e8 100644 --- a/app/Repositories/Tag/TagRepositoryInterface.php +++ b/app/Repositories/Tag/TagRepositoryInterface.php @@ -38,7 +38,7 @@ interface TagRepositoryInterface * @param Carbon $start * @param Carbon $end * - * @return float + * @return string */ public function coveredByBalancingActs(Account $account, Carbon $start, Carbon $end); diff --git a/tests/repositories/TagRepositoryTest.php b/tests/repositories/TagRepositoryTest.php index 3a8962dc29..a8b6697b58 100644 --- a/tests/repositories/TagRepositoryTest.php +++ b/tests/repositories/TagRepositoryTest.php @@ -1,6 +1,6 @@ be($user); + + // create transaction and account types: + FactoryMuffin::create('FireflyIII\Models\TransactionType'); // withdrawal + FactoryMuffin::create('FireflyIII\Models\TransactionType'); // deposit + $transfer = FactoryMuffin::create('FireflyIII\Models\TransactionType'); // transfer + FactoryMuffin::create('FireflyIII\Models\AccountType'); // expense + FactoryMuffin::create('FireflyIII\Models\AccountType'); // revenue + $asset = FactoryMuffin::create('FireflyIII\Models\AccountType'); // asset + + // create two accounts: + $fromAccount = FactoryMuffin::create('FireflyIII\Models\Account'); // asset + $toAccount = FactoryMuffin::create('FireflyIII\Models\Account'); // asset + $fromAccount->account_type_id = $asset->id; + $toAccount->account_type_id = $asset->id; + $fromAccount->save(); + $toAccount->save(); + + + // create a tag + $tag = FactoryMuffin::create('FireflyIII\Models\Tag'); + $tag->tagMode = 'balancingAct'; + $tag->user_id = $user->id; + $tag->save(); + + // date + $today = new Carbon('2014-01-12'); + $start = new Carbon('2014-01-01'); + $end = new Carbon('2014-01-31'); + + // store five journals + for ($i = 0; $i < 5; $i++) { + $journal = FactoryMuffin::create('FireflyIII\Models\TransactionJournal'); // deposit! + // set date: + $journal->date = $today; + $journal->user_id = $user->id; + $journal->transaction_type_id = $transfer->id; + $journal->tags()->save($tag); + $journal->save(); + + // update accounts: + $journal->transactions[0]->account_id = $fromAccount->id; + $journal->transactions[0]->amount = '-100'; + $journal->transactions[0]->save(); + $journal->transactions[1]->account_id = $toAccount->id; + $journal->transactions[1]->amount = '100'; + $journal->transactions[1]->save(); + + } + + $amount = $this->object->coveredByBalancingActs($toAccount, $start, $end); + // five transactions, 100 each. + $this->assertEquals('500', $amount); + } + /** * @covers FireflyIII\Repositories\Tag\TagRepository::destroy */ From 3cabe6ca5a2dd5c9444e206466a4050ad1a47d2e Mon Sep 17 00:00:00 2001 From: James Cole Date: Fri, 5 Jun 2015 08:39:23 +0200 Subject: [PATCH 24/47] Improved test coverage. --- app/Repositories/Tag/TagRepository.php | 12 +- tests/repositories/TagRepositoryTest.php | 204 +++++++++++++++++++++++ 2 files changed, 207 insertions(+), 9 deletions(-) diff --git a/app/Repositories/Tag/TagRepository.php b/app/Repositories/Tag/TagRepository.php index 6a3323f074..ee6e89be17 100644 --- a/app/Repositories/Tag/TagRepository.php +++ b/app/Repositories/Tag/TagRepository.php @@ -198,17 +198,11 @@ class TagRepository implements TagRepositoryInterface /* * If any transaction is a deposit, cannot become a balancing act. */ - $count = 0; foreach ($tag->transactionjournals as $journal) { if ($journal->transactionType->type == 'Deposit') { - $count++; + return false; } } - if ($count > 0) { - return false; - } - - return true; } @@ -294,7 +288,6 @@ class TagRepository implements TagRepositoryInterface // tag is attached just like that: if ($withdrawals < 1 && $deposits < 1) { $journal->tags()->save($tag); - return true; } @@ -308,7 +301,8 @@ class TagRepository implements TagRepositoryInterface return $this->matchAll($journal, $tag); } - return false; + // this statement is unreachable. + return false; // @codeCoverageIgnore } diff --git a/tests/repositories/TagRepositoryTest.php b/tests/repositories/TagRepositoryTest.php index a8b6697b58..7bfd0744dc 100644 --- a/tests/repositories/TagRepositoryTest.php +++ b/tests/repositories/TagRepositoryTest.php @@ -365,6 +365,45 @@ class TagRepositoryTest extends TestCase } + /** + * An advance payment accepts only one withdrawal, not two, even not + * if the accounts are the same + * + * @covers FireflyIII\Repositories\Tag\TagRepository::connect + * @covers FireflyIII\Repositories\Tag\TagRepository::connectAdvancePayment + * @covers FireflyIII\Repositories\Tag\TagRepository::matchAll + */ + public function testConnectPaymentTwoWithdrawalsSameAccounts() + { + $withdrawal = FactoryMuffin::create('FireflyIII\Models\TransactionType'); + FactoryMuffin::create('FireflyIII\Models\TransactionType'); + FactoryMuffin::create('FireflyIII\Models\TransactionType'); + + $journal = FactoryMuffin::create('FireflyIII\Models\TransactionJournal'); + $otherJournal = FactoryMuffin::create('FireflyIII\Models\TransactionJournal'); + $tag = FactoryMuffin::create('FireflyIII\Models\Tag'); + + $journal->transaction_type_id = $withdrawal->id; + $otherJournal->transaction_type_id = $withdrawal->id; + + // match up accounts: + $otherJournal->transactions[0]->account_id = $journal->transactions[0]->account_id; + $otherJournal->transactions[1]->account_id = $journal->transactions[1]->account_id; + $otherJournal->transactions[0]->save(); + $otherJournal->transactions[1]->save(); + + + $tag->tagMode = 'advancePayment'; + + $tag->save(); + $journal->save(); + $otherJournal->save(); + $otherJournal->tags()->save($tag); + + $result = $this->object->connect($journal, $tag); + $this->assertFalse($result); + } + /** * @covers FireflyIII\Repositories\Tag\TagRepository::coveredByBalancingActs */ @@ -485,6 +524,171 @@ class TagRepositoryTest extends TestCase $this->assertEquals($data['tag'], $tag->tag); } + /** + * By default, any tag can become an advancePayment + * + * @covers FireflyIII\Repositories\Tag\TagRepository::tagAllowAdvance + */ + public function testTagAllowAdvance() + { + // create a tag + $user = FactoryMuffin::create('FireflyIII\User'); + $tag = FactoryMuffin::create('FireflyIII\Models\Tag'); + $tag->tagMode = 'nothing'; + $tag->user_id = $user->id; + $tag->save(); + + $result = $this->object->tagAllowAdvance($tag); + $this->assertTrue($result); + } + + /** + * If the tag has one transfer, it can NOT become an advance payment. + * + * @covers FireflyIII\Repositories\Tag\TagRepository::tagAllowAdvance + */ + public function testTagAllowAdvanceWithTransfer() + { + // create a tag + $user = FactoryMuffin::create('FireflyIII\User'); + $tag = FactoryMuffin::create('FireflyIII\Models\Tag'); + FactoryMuffin::create('FireflyIII\Models\TransactionType'); // withdrawal + FactoryMuffin::create('FireflyIII\Models\TransactionType'); // deposit + $transfer = FactoryMuffin::create('FireflyIII\Models\TransactionType'); // transfer + $tag->tagMode = 'nothing'; + $tag->user_id = $user->id; + $tag->save(); + + // create withdrawal: + $journal = FactoryMuffin::create('FireflyIII\Models\TransactionJournal'); + $journal->transaction_type_id = $transfer->id; + $journal->save(); + $journal->tags()->save($tag); + + $result = $this->object->tagAllowAdvance($tag); + $this->assertFalse($result); + } + + /** + * If the tag has one withdrawal, it can still become an advance payment. + * + * @covers FireflyIII\Repositories\Tag\TagRepository::tagAllowAdvance + */ + public function testTagAllowAdvanceWithWithdrawal() + { + // create a tag + $user = FactoryMuffin::create('FireflyIII\User'); + $tag = FactoryMuffin::create('FireflyIII\Models\Tag'); + $tag->tagMode = 'nothing'; + $tag->user_id = $user->id; + $tag->save(); + + // create withdrawal: + $journal = FactoryMuffin::create('FireflyIII\Models\TransactionJournal'); + $journal->tags()->save($tag); + + $result = $this->object->tagAllowAdvance($tag); + $this->assertTrue($result); + } + + /** + * If the tag has two withdrawals, it CANNOT become an advance payment. + * + * @covers FireflyIII\Repositories\Tag\TagRepository::tagAllowAdvance + */ + public function testTagAllowAdvanceWithWithdrawals() + { + // create a tag + $user = FactoryMuffin::create('FireflyIII\User'); + $tag = FactoryMuffin::create('FireflyIII\Models\Tag'); + $withdrawal = FactoryMuffin::create('FireflyIII\Models\TransactionType'); + $tag->tagMode = 'nothing'; + $tag->user_id = $user->id; + $tag->save(); + + // create withdrawals + for ($i = 0; $i < 2; $i++) { + $journal = FactoryMuffin::create('FireflyIII\Models\TransactionJournal'); + $journal->transaction_type_id = $withdrawal->id; + $journal->save(); + $journal->tags()->save($tag); + } + + $result = $this->object->tagAllowAdvance($tag); + $this->assertFalse($result); + } + + /** + * By default, an empty tag can become a balancing act. + * + * @covers FireflyIII\Repositories\Tag\TagRepository::tagAllowBalancing + */ + public function testTagAllowBalancing() + { + // create a tag + $user = FactoryMuffin::create('FireflyIII\User'); + $tag = FactoryMuffin::create('FireflyIII\Models\Tag'); + $tag->tagMode = 'nothing'; + $tag->user_id = $user->id; + $tag->save(); + + $result = $this->object->tagAllowBalancing($tag); + $this->assertTrue($result); + } + + /** + * When the tag has one deposit, it can NOT become a balancing act. + * + * @covers FireflyIII\Repositories\Tag\TagRepository::tagAllowBalancing + */ + public function testTagAllowBalancingDeposit() + { + + // create a tag + FactoryMuffin::create('FireflyIII\Models\TransactionType'); // withdrawal + $deposit = FactoryMuffin::create('FireflyIII\Models\TransactionType'); // deposit + $user = FactoryMuffin::create('FireflyIII\User'); + $tag = FactoryMuffin::create('FireflyIII\Models\Tag'); + $tag->tagMode = 'nothing'; + $tag->user_id = $user->id; + $tag->save(); + + // create three journals and connect them: + for ($i = 0; $i < 1; $i++) { + $journal = FactoryMuffin::create('FireflyIII\Models\TransactionJournal'); + $journal->transaction_type_id = $deposit->id; + $journal->save(); + $journal->tags()->save($tag); + } + + $result = $this->object->tagAllowBalancing($tag); + $this->assertFalse($result); + } + + /** + * When the tag has more than 2 transactions connected to it, it cannot become abalancing act. + * + * @covers FireflyIII\Repositories\Tag\TagRepository::tagAllowBalancing + */ + public function testTagAllowBalancingManyJournals() + { + // create a tag + $user = FactoryMuffin::create('FireflyIII\User'); + $tag = FactoryMuffin::create('FireflyIII\Models\Tag'); + $tag->tagMode = 'nothing'; + $tag->user_id = $user->id; + $tag->save(); + + // create three journals and connect them: + for ($i = 0; $i < 3; $i++) { + $journal = FactoryMuffin::create('FireflyIII\Models\TransactionJournal'); + $journal->tags()->save($tag); + } + + $result = $this->object->tagAllowBalancing($tag); + $this->assertFalse($result); + } + /** * @covers FireflyIII\Repositories\Tag\TagRepository::update */ From db0f269dc81e2dfc97b7e34d11caed7615ef219f Mon Sep 17 00:00:00 2001 From: James Cole Date: Fri, 5 Jun 2015 09:50:59 +0200 Subject: [PATCH 25/47] Fix class reference. --- app/Repositories/Tag/TagRepository.php | 1 + 1 file changed, 1 insertion(+) diff --git a/app/Repositories/Tag/TagRepository.php b/app/Repositories/Tag/TagRepository.php index ee6e89be17..26971e9ed1 100644 --- a/app/Repositories/Tag/TagRepository.php +++ b/app/Repositories/Tag/TagRepository.php @@ -9,6 +9,7 @@ use FireflyIII\Models\Account; use FireflyIII\Models\Tag; use FireflyIII\Models\TransactionJournal; use FireflyIII\Models\TransactionType; +use Illuminate\Support\Collection; /** * Class TagRepository From 3a06a6ac070ab7e0073b05d79d1b717c0c5d1517 Mon Sep 17 00:00:00 2001 From: James Cole Date: Fri, 5 Jun 2015 09:51:52 +0200 Subject: [PATCH 26/47] Removed unnecessary code. --- app/Http/Kernel.php | 1 - app/Http/Middleware/Cleanup.php | 223 -------------------------------- app/Http/routes.php | 2 +- 3 files changed, 1 insertion(+), 225 deletions(-) delete mode 100644 app/Http/Middleware/Cleanup.php diff --git a/app/Http/Kernel.php b/app/Http/Kernel.php index f0aac457a4..30bdc71e89 100644 --- a/app/Http/Kernel.php +++ b/app/Http/Kernel.php @@ -37,7 +37,6 @@ class Kernel extends HttpKernel 'auth.basic' => 'Illuminate\Auth\Middleware\AuthenticateWithBasicAuth', 'guest' => 'FireflyIII\Http\Middleware\RedirectIfAuthenticated', 'range' => 'FireflyIII\Http\Middleware\Range', - 'cleanup' => 'FireflyIII\Http\Middleware\Cleanup', 'reminders' => 'FireflyIII\Http\Middleware\Reminders', ]; diff --git a/app/Http/Middleware/Cleanup.php b/app/Http/Middleware/Cleanup.php deleted file mode 100644 index c2dc5a3e46..0000000000 --- a/app/Http/Middleware/Cleanup.php +++ /dev/null @@ -1,223 +0,0 @@ -auth = $auth; - } - - /** - * Handle an incoming request. - * - * @param \Illuminate\Http\Request $request - * @param \Closure $next - * - * @return mixed - */ - public function handle(Request $request, Closure $next) - { - if ($this->auth->guest()) { - return response('Unauthorized.', 401); - } - $count = -1; - - bcscale(0); - - if (env('RUNCLEANUP') == 'true') { - $count = 0; - $count = bcadd($count, $this->encryptAccountAndBills()); - $count = bcadd($count, $this->encryptBudgetsAndCategories()); - $count = bcadd($count, $this->encryptPiggiesAndJournals()); - $count = bcadd($count, $this->encryptRemindersAndPreferences()); - - } - if ($count == 0) { - Session::flash('warning', 'Please open the .env file and change RUNCLEANUP=true to RUNCLEANUP=false'); - } - - return $next($request); - - } - - /** - * @return int - */ - protected function encryptAccountAndBills() - { - $count = 0; - // encrypt account name - $set = Account::where('encrypted', 0)->take(5)->get(); - /** @var Account $entry */ - foreach ($set as $entry) { - $count++; - $name = $entry->name; - $entry->name = $name; - $entry->save(); - } - unset($set, $entry, $name); - - // encrypt bill name - $set = Bill::where('name_encrypted', 0)->take(5)->get(); - /** @var Bill $entry */ - foreach ($set as $entry) { - $count++; - $name = $entry->name; - $entry->name = $name; - $entry->save(); - } - unset($set, $entry, $name); - - // encrypt bill match - $set = Bill::where('match_encrypted', 0)->take(5)->get(); - /** @var Bill $entry */ - foreach ($set as $entry) { - $match = $entry->match; - $entry->match = $match; - $entry->save(); - } - unset($set, $entry, $match); - - - return $count; - - } - - /** - * @return int - */ - protected function encryptBudgetsAndCategories() - { - $count = 0; - // encrypt budget name - $set = Budget::where('encrypted', 0)->take(5)->get(); - /** @var Budget $entry */ - foreach ($set as $entry) { - $count++; - $name = $entry->name; - $entry->name = $name; - $entry->save(); - } - unset($set, $entry, $name); - - // encrypt category name - $set = Category::where('encrypted', 0)->take(5)->get(); - /** @var Category $entry */ - foreach ($set as $entry) { - $count++; - $name = $entry->name; - $entry->name = $name; - $entry->save(); - } - unset($set, $entry, $name); - - return $count; - } - - /** - * @return int - */ - protected function encryptPiggiesAndJournals() - { - $count = 0; - // encrypt piggy bank name - $set = PiggyBank::where('encrypted', 0)->take(5)->get(); - /** @var PiggyBank $entry */ - foreach ($set as $entry) { - $count++; - $name = $entry->name; - $entry->name = $name; - $entry->save(); - } - unset($set, $entry, $name); - - // encrypt transaction journal description - $set = TransactionJournal::where('encrypted', 0)->take(5)->get(); - /** @var TransactionJournal $entry */ - foreach ($set as $entry) { - $count++; - $description = $entry->description; - $entry->description = $description; - $entry->save(); - } - unset($set, $entry, $description); - - return $count; - } - - /** - * @return int - */ - protected function encryptRemindersAndPreferences() - { - $count = 0; - // encrypt reminder metadata - $set = Reminder::where('encrypted', 0)->take(5)->get(); - /** @var Reminder $entry */ - foreach ($set as $entry) { - $count++; - $metadata = $entry->metadata; - $entry->metadata = $metadata; - $entry->save(); - } - unset($set, $entry, $metadata); - - //encrypt preference name - $set = Preference::whereNull('name_encrypted')->take(5)->get(); - /** @var Preference $entry */ - foreach ($set as $entry) { - $count++; - $name = $entry->name; - $entry->name = $name; - $entry->save(); - } - unset($set, $entry, $name); - - //encrypt preference data - $set = Preference::whereNull('data_encrypted')->take(5)->get(); - /** @var Preference $entry */ - foreach ($set as $entry) { - $count++; - $data = $entry->data; - $entry->data = $data; - $entry->save(); - } - unset($set, $entry, $data); - - return $count; - } - -} diff --git a/app/Http/routes.php b/app/Http/routes.php index cdff0a70a4..2b66dac023 100644 --- a/app/Http/routes.php +++ b/app/Http/routes.php @@ -188,7 +188,7 @@ Route::controllers( */ Route::group( ['middleware' => ['auth', 'range', 'reminders']], function () { - Route::get('/', ['uses' => 'HomeController@index', 'as' => 'index', 'middleware' => 'cleanup']); + Route::get('/', ['uses' => 'HomeController@index', 'as' => 'index']); Route::get('/home', ['uses' => 'HomeController@index', 'as' => 'home']); Route::post('/daterange', ['uses' => 'HomeController@dateRange', 'as' => 'daterange']); Route::get('/flush', ['uses' => 'HomeController@flush', 'as' => 'flush']); From 4b7e1ae1c6f6191f93b30b3ddf4f4d1b673df9ea Mon Sep 17 00:00:00 2001 From: James Cole Date: Fri, 5 Jun 2015 10:02:40 +0200 Subject: [PATCH 27/47] Removed duplicate code. --- app/Repositories/Budget/BudgetRepository.php | 28 ++-------- .../Budget/BudgetRepositoryInterface.php | 2 +- .../Category/CategoryRepository.php | 36 ++---------- .../Category/CategoryRepositoryInterface.php | 2 +- .../Shared/ComponentRepository.php | 56 +++++++++++++++++++ tests/repositories/BudgetRepositoryTest.php | 2 + tests/repositories/CategoryRepositoryTest.php | 2 + 7 files changed, 70 insertions(+), 58 deletions(-) create mode 100644 app/Repositories/Shared/ComponentRepository.php diff --git a/app/Repositories/Budget/BudgetRepository.php b/app/Repositories/Budget/BudgetRepository.php index bed615d4ad..86fcab135c 100644 --- a/app/Repositories/Budget/BudgetRepository.php +++ b/app/Repositories/Budget/BudgetRepository.php @@ -7,6 +7,7 @@ use Carbon\Carbon; use FireflyIII\Models\Budget; use FireflyIII\Models\BudgetLimit; use FireflyIII\Models\LimitRepetition; +use FireflyIII\Repositories\Shared\ComponentRepository; use Illuminate\Database\Query\Builder as QueryBuilder; use Illuminate\Database\Query\JoinClause; use Illuminate\Pagination\LengthAwarePaginator; @@ -18,7 +19,7 @@ use Input; * * @package FireflyIII\Repositories\Budget */ -class BudgetRepository implements BudgetRepositoryInterface +class BudgetRepository extends ComponentRepository implements BudgetRepositoryInterface { /** @@ -262,32 +263,11 @@ class BudgetRepository implements BudgetRepositoryInterface * @param Carbon $end * @param bool $shared * - * @return float + * @return string */ public function spentInPeriodCorrected(Budget $budget, Carbon $start, Carbon $end, $shared = true) { - if ($shared === true) { - // get everything: - $sum = floatval($budget->transactionjournals()->before($end)->after($start)->get(['transaction_journals.*'])->sum('amount')); - } else { - // get all journals in this month where the asset account is NOT shared. - $sum = $budget->transactionjournals() - ->before($end) - ->after($start) - ->leftJoin('transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id') - ->leftJoin('accounts', 'accounts.id', '=', 'transactions.account_id') - ->leftJoin( - 'account_meta', function (JoinClause $join) { - $join->on('account_meta.account_id', '=', 'accounts.id')->where('account_meta.name', '=', 'accountRole'); - } - ) - ->where('account_meta.data', '!=', '"sharedAsset"') - ->get(['transaction_journals.*']) - ->sum('amount'); - $sum = floatval($sum); - } - - return $sum; + return $this->spentInPeriod($budget, $start, $end, $shared); } /** diff --git a/app/Repositories/Budget/BudgetRepositoryInterface.php b/app/Repositories/Budget/BudgetRepositoryInterface.php index 0a035bea35..12d3d01b93 100644 --- a/app/Repositories/Budget/BudgetRepositoryInterface.php +++ b/app/Repositories/Budget/BudgetRepositoryInterface.php @@ -134,7 +134,7 @@ interface BudgetRepositoryInterface * @param Carbon $end * @param boolean $shared * - * @return float + * @return string */ public function spentInPeriodCorrected(Budget $budget, Carbon $start, Carbon $end, $shared = true); diff --git a/app/Repositories/Category/CategoryRepository.php b/app/Repositories/Category/CategoryRepository.php index 19e633be6b..c401bca5e3 100644 --- a/app/Repositories/Category/CategoryRepository.php +++ b/app/Repositories/Category/CategoryRepository.php @@ -9,13 +9,13 @@ use FireflyIII\Models\Category; use FireflyIII\Models\TransactionJournal; use Illuminate\Database\Query\JoinClause; use Illuminate\Support\Collection; - +use FireflyIII\Repositories\Shared\ComponentRepository; /** * Class CategoryRepository * * @package FireflyIII\Repositories\Category */ -class CategoryRepository implements CategoryRepositoryInterface +class CategoryRepository extends ComponentRepository implements CategoryRepositoryInterface { /** @@ -181,39 +181,11 @@ class CategoryRepository implements CategoryRepositoryInterface * * @param bool $shared * - * @return float + * @return string */ public function spentInPeriodCorrected(Category $category, Carbon $start, Carbon $end, $shared = false) { - if ($shared === true) { - // shared is true. - // always ignore transfers between accounts! - $sum = floatval( - $category->transactionjournals() - ->transactionTypes(['Withdrawal']) - ->before($end)->after($start)->get(['transaction_journals.*'])->sum('amount') - ); - - } else { - // do something else, SEE budgets. - // get all journals in this month where the asset account is NOT shared. - $sum = $category->transactionjournals() - ->before($end) - ->after($start) - ->transactionTypes(['Withdrawal']) - ->leftJoin('transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id') - ->leftJoin('accounts', 'accounts.id', '=', 'transactions.account_id') - ->leftJoin( - 'account_meta', function (JoinClause $join) { - $join->on('account_meta.account_id', '=', 'accounts.id')->where('account_meta.name', '=', 'accountRole'); - } - ) - ->where('account_meta.data', '!=', '"sharedAsset"') - ->get(['transaction_journals.*'])->sum('amount'); - $sum = floatval($sum); - } - - return $sum; + return $this->spentInPeriod($category, $start, $end, $shared); } /** diff --git a/app/Repositories/Category/CategoryRepositoryInterface.php b/app/Repositories/Category/CategoryRepositoryInterface.php index cfe3f93c50..a24dfb6efe 100644 --- a/app/Repositories/Category/CategoryRepositoryInterface.php +++ b/app/Repositories/Category/CategoryRepositoryInterface.php @@ -81,7 +81,7 @@ interface CategoryRepositoryInterface * * @param bool $shared * - * @return float + * @return string */ public function spentInPeriodCorrected(Category $category, Carbon $start, Carbon $end, $shared = false); diff --git a/app/Repositories/Shared/ComponentRepository.php b/app/Repositories/Shared/ComponentRepository.php new file mode 100644 index 0000000000..db0d5054a0 --- /dev/null +++ b/app/Repositories/Shared/ComponentRepository.php @@ -0,0 +1,56 @@ +transactionjournals() + ->transactionTypes(['Withdrawal']) + ->before($end)->after($start)->get(['transaction_journals.*'])->sum('amount'); + + } else { + // do something else, SEE budgets. + // get all journals in this month where the asset account is NOT shared. + $sum = $object->transactionjournals() + ->before($end) + ->after($start) + ->transactionTypes(['Withdrawal']) + ->leftJoin('transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id') + ->leftJoin('accounts', 'accounts.id', '=', 'transactions.account_id') + ->leftJoin( + 'account_meta', function (JoinClause $join) { + $join->on('account_meta.account_id', '=', 'accounts.id')->where('account_meta.name', '=', 'accountRole'); + } + ) + ->where('account_meta.data', '!=', '"sharedAsset"') + ->get(['transaction_journals.*'])->sum('amount'); + } + + return $sum; + } +} \ No newline at end of file diff --git a/tests/repositories/BudgetRepositoryTest.php b/tests/repositories/BudgetRepositoryTest.php index 8008d78f11..d52716c89f 100644 --- a/tests/repositories/BudgetRepositoryTest.php +++ b/tests/repositories/BudgetRepositoryTest.php @@ -290,6 +290,7 @@ class BudgetRepositoryTest extends TestCase /** * @covers FireflyIII\Repositories\Budget\BudgetRepository::spentInPeriodCorrected + * @covers FireflyIII\Repositories\Shared\ComponentRepository::spentInPeriod */ public function testSpentInPeriodCorrected() { @@ -301,6 +302,7 @@ class BudgetRepositoryTest extends TestCase /** * @covers FireflyIII\Repositories\Budget\BudgetRepository::spentInPeriodCorrected + * @covers FireflyIII\Repositories\Shared\ComponentRepository::spentInPeriod */ public function testSpentInPeriodCorrectedShared() { diff --git a/tests/repositories/CategoryRepositoryTest.php b/tests/repositories/CategoryRepositoryTest.php index d8fcf3ed76..07f553fbc6 100644 --- a/tests/repositories/CategoryRepositoryTest.php +++ b/tests/repositories/CategoryRepositoryTest.php @@ -208,6 +208,7 @@ class CategoryRepositoryTest extends TestCase /** * @covers FireflyIII\Repositories\Category\CategoryRepository::spentInPeriodCorrected + * @covers FireflyIII\Repositories\Shared\ComponentRepository::spentInPeriod */ public function testSpentInPeriodSumCorrected() { @@ -221,6 +222,7 @@ class CategoryRepositoryTest extends TestCase /** * @covers FireflyIII\Repositories\Category\CategoryRepository::spentInPeriodCorrected + * @covers FireflyIII\Repositories\Shared\ComponentRepository::spentInPeriod */ public function testSpentInPeriodSumCorrectedShared() { From 58859eb35ad36d3217239ab03545eb24eae8dd66 Mon Sep 17 00:00:00 2001 From: Scrutinizer Auto-Fixer Date: Fri, 5 Jun 2015 08:40:26 +0000 Subject: [PATCH 28/47] Scrutinizer Auto-Fixes This commit consists of patches automatically generated for this project on https://scrutinizer-ci.com --- app/Helpers/Collection/Bill.php | 2 +- app/Helpers/Collection/Category.php | 2 +- app/Helpers/Collection/Expense.php | 2 +- app/Helpers/Collection/Income.php | 2 +- app/Helpers/Report/ReportHelper.php | 2 +- app/Helpers/Report/ReportQuery.php | 94 ++++++++-------- app/Http/Controllers/AccountController.php | 8 +- app/Http/Controllers/Auth/AuthController.php | 2 +- app/Http/Controllers/BillController.php | 2 +- app/Http/Controllers/BudgetController.php | 2 +- app/Http/Controllers/CategoryController.php | 4 +- .../Controllers/Chart/BudgetController.php | 6 +- .../Controllers/Chart/CategoryController.php | 2 +- app/Http/Controllers/HomeController.php | 4 +- app/Http/Controllers/NewUserController.php | 6 +- app/Http/Controllers/PiggyBankController.php | 10 +- .../Controllers/TransactionController.php | 2 +- app/Http/Middleware/Reminders.php | 2 +- app/Http/breadcrumbs.php | 102 +++++++++--------- app/Http/routes.php | 46 ++++---- app/Models/Account.php | 2 +- app/Models/AccountMeta.php | 2 +- app/Models/Bill.php | 2 +- app/Models/PiggyBank.php | 2 +- app/Models/PiggyBankRepetition.php | 12 +-- app/Models/Reminder.php | 4 +- app/Models/TransactionJournal.php | 2 +- app/Providers/BusServiceProvider.php | 2 +- app/Providers/EventServiceProvider.php | 12 +-- app/Providers/FireflyServiceProvider.php | 12 +-- app/Providers/RouteServiceProvider.php | 2 +- .../Account/AccountRepository.php | 98 ++++++++--------- app/Repositories/Budget/BudgetRepository.php | 71 ++++++------ .../Category/CategoryRepository.php | 46 ++++---- .../Journal/JournalRepository.php | 2 +- .../PiggyBank/PiggyBankRepository.php | 2 +- .../Reminder/ReminderRepository.php | 40 +++---- .../Shared/ComponentRepository.php | 28 ++--- app/Repositories/Tag/TagRepository.php | 2 +- app/Services/Registrar.php | 6 +- app/Support/CacheProperties.php | 2 +- app/Support/Navigation.php | 4 +- app/Support/Preferences.php | 6 +- app/Support/Search/Search.php | 12 +-- app/Support/Twig/Budget.php | 16 +-- app/Support/Twig/General.php | 22 ++-- app/Support/Twig/Journal.php | 10 +- app/Support/Twig/PiggyBank.php | 2 +- app/Support/Twig/Translation.php | 2 +- 49 files changed, 363 insertions(+), 364 deletions(-) diff --git a/app/Helpers/Collection/Bill.php b/app/Helpers/Collection/Bill.php index 34b3205c6b..de5b86fc97 100644 --- a/app/Helpers/Collection/Bill.php +++ b/app/Helpers/Collection/Bill.php @@ -41,7 +41,7 @@ class Bill public function getBills() { $this->bills->sortBy( - function (BillLine $bill) { + function(BillLine $bill) { $active = intval($bill->getBill()->active) == 0 ? 1 : 0; $name = $bill->getBill()->name; diff --git a/app/Helpers/Collection/Category.php b/app/Helpers/Collection/Category.php index 84f426487a..71af3c2607 100644 --- a/app/Helpers/Collection/Category.php +++ b/app/Helpers/Collection/Category.php @@ -55,7 +55,7 @@ class Category public function getCategories() { $this->categories->sortByDesc( - function (CategoryModel $category) { + function(CategoryModel $category) { return $category->spent; } ); diff --git a/app/Helpers/Collection/Expense.php b/app/Helpers/Collection/Expense.php index a66c1ef86d..f328bfd42a 100644 --- a/app/Helpers/Collection/Expense.php +++ b/app/Helpers/Collection/Expense.php @@ -67,7 +67,7 @@ class Expense public function getExpenses() { $this->expenses->sortByDesc( - function (stdClass $object) { + function(stdClass $object) { return $object->amount; } ); diff --git a/app/Helpers/Collection/Income.php b/app/Helpers/Collection/Income.php index c3caf9eba7..2b635f8aa4 100644 --- a/app/Helpers/Collection/Income.php +++ b/app/Helpers/Collection/Income.php @@ -68,7 +68,7 @@ class Income public function getIncomes() { $this->incomes->sortByDesc( - function (stdClass $object) { + function(stdClass $object) { return $object->amount; } ); diff --git a/app/Helpers/Report/ReportHelper.php b/app/Helpers/Report/ReportHelper.php index 4790b1d81c..368c28f50c 100644 --- a/app/Helpers/Report/ReportHelper.php +++ b/app/Helpers/Report/ReportHelper.php @@ -66,7 +66,7 @@ class ReportHelper implements ReportHelperInterface // remove cash account, if any: $accounts = $accounts->filter( - function (Account $account) { + function(Account $account) { if ($account->accountType->type != 'Cash account') { return $account; } diff --git a/app/Helpers/Report/ReportQuery.php b/app/Helpers/Report/ReportQuery.php index 2e720e0653..017d04ef07 100644 --- a/app/Helpers/Report/ReportQuery.php +++ b/app/Helpers/Report/ReportQuery.php @@ -35,15 +35,15 @@ class ReportQuery implements ReportQueryInterface $query = $this->queryJournalsWithTransactions($start, $end); if ($includeShared === false) { $query->where( - function (Builder $query) { + function(Builder $query) { $query->where( - function (Builder $q) { // only get withdrawals not from a shared account + function(Builder $q) { // only get withdrawals not from a shared account $q->where('transaction_types.type', 'Withdrawal'); $q->where('acm_from.data', '!=', '"sharedAsset"'); } ); $query->orWhere( - function (Builder $q) { // and transfers from a shared account. + function(Builder $q) { // and transfers from a shared account. $q->where('transaction_types.type', 'Transfer'); $q->where('acm_to.data', '=', '"sharedAsset"'); } @@ -61,14 +61,14 @@ class ReportQuery implements ReportQueryInterface ); $data->each( - function (TransactionJournal $journal) { + function(TransactionJournal $journal) { if (intval($journal->account_encrypted) == 1) { $journal->name = Crypt::decrypt($journal->name); } } ); $data = $data->filter( - function (TransactionJournal $journal) { + function(TransactionJournal $journal) { if ($journal->amount != 0) { return $journal; } @@ -92,26 +92,26 @@ class ReportQuery implements ReportQueryInterface public function getAllAccounts(Carbon $start, Carbon $end, $includeShared = false) { $query = Auth::user()->accounts()->orderBy('accounts.name', 'ASC') - ->accountTypeIn(['Default account', 'Asset account', 'Cash account']); + ->accountTypeIn(['Default account', 'Asset account', 'Cash account']); if ($includeShared === false) { $query->leftJoin( 'account_meta', function (JoinClause $join) { $join->on('account_meta.account_id', '=', 'accounts.id')->where('account_meta.name', '=', 'accountRole'); } ) - ->orderBy('accounts.name', 'ASC') - ->where( - function (Builder $query) { + ->orderBy('accounts.name', 'ASC') + ->where( + function (Builder $query) { - $query->where('account_meta.data', '!=', '"sharedAsset"'); - $query->orWhereNull('account_meta.data'); + $query->where('account_meta.data', '!=', '"sharedAsset"'); + $query->orWhereNull('account_meta.data'); - } - ); + } + ); } $set = $query->get(['accounts.*']); $set->each( - function (Account $account) use ($start, $end) { + function(Account $account) use ($start, $end) { /** * The balance for today always incorporates transactions * made on today. So to get todays "start" balance, we sub one @@ -152,15 +152,15 @@ class ReportQuery implements ReportQueryInterface // only get deposits not to a shared account // and transfers to a shared account. $query->where( - function (Builder $query) { + function(Builder $query) { $query->where( - function (Builder $q) { + function(Builder $q) { $q->where('transaction_types.type', 'Deposit'); $q->where('acm_to.data', '!=', '"sharedAsset"'); } ); $query->orWhere( - function (Builder $q) { + function(Builder $q) { $q->where('transaction_types.type', 'Transfer'); $q->where('acm_from.data', '=', '"sharedAsset"'); } @@ -179,14 +179,14 @@ class ReportQuery implements ReportQueryInterface ); $data->each( - function (TransactionJournal $journal) { + function(TransactionJournal $journal) { if (intval($journal->account_encrypted) == 1) { $journal->name = Crypt::decrypt($journal->name); } } ); $data = $data->filter( - function (TransactionJournal $journal) { + function(TransactionJournal $journal) { if ($journal->amount != 0) { return $journal; } @@ -212,16 +212,16 @@ class ReportQuery implements ReportQueryInterface { return floatval( - Auth::user()->transactionjournals() - ->leftJoin('transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id') - ->leftJoin('budget_transaction_journal', 'budget_transaction_journal.transaction_journal_id', '=', 'transaction_journals.id') - ->transactionTypes(['Withdrawal']) - ->where('transactions.account_id', $account->id) - ->before($end) - ->after($start) - ->where('budget_transaction_journal.budget_id', $budget->id) - ->get(['transaction_journals.*'])->sum('amount') - ) * -1; + Auth::user()->transactionjournals() + ->leftJoin('transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id') + ->leftJoin('budget_transaction_journal', 'budget_transaction_journal.transaction_journal_id', '=', 'transaction_journals.id') + ->transactionTypes(['Withdrawal']) + ->where('transactions.account_id', $account->id) + ->before($end) + ->after($start) + ->where('budget_transaction_journal.budget_id', $budget->id) + ->get(['transaction_journals.*'])->sum('amount') + ) * -1; } /** @@ -260,24 +260,24 @@ class ReportQuery implements ReportQueryInterface $join->on('t_from.transaction_journal_id', '=', 'transaction_journals.id')->where('t_from.amount', '<', 0); } ) - ->leftJoin('accounts as ac_from', 't_from.account_id', '=', 'ac_from.id') - ->leftJoin( - 'account_meta as acm_from', function (JoinClause $join) { - $join->on('ac_from.id', '=', 'acm_from.account_id')->where('acm_from.name', '=', 'accountRole'); - } - ) - ->leftJoin( - 'transactions as t_to', function (JoinClause $join) { - $join->on('t_to.transaction_journal_id', '=', 'transaction_journals.id')->where('t_to.amount', '>', 0); - } - ) - ->leftJoin('accounts as ac_to', 't_to.account_id', '=', 'ac_to.id') - ->leftJoin( - 'account_meta as acm_to', function (JoinClause $join) { - $join->on('ac_to.id', '=', 'acm_to.account_id')->where('acm_to.name', '=', 'accountRole'); - } - ) - ->leftJoin('transaction_types', 'transaction_types.id', '=', 'transaction_journals.transaction_type_id'); + ->leftJoin('accounts as ac_from', 't_from.account_id', '=', 'ac_from.id') + ->leftJoin( + 'account_meta as acm_from', function (JoinClause $join) { + $join->on('ac_from.id', '=', 'acm_from.account_id')->where('acm_from.name', '=', 'accountRole'); + } + ) + ->leftJoin( + 'transactions as t_to', function (JoinClause $join) { + $join->on('t_to.transaction_journal_id', '=', 'transaction_journals.id')->where('t_to.amount', '>', 0); + } + ) + ->leftJoin('accounts as ac_to', 't_to.account_id', '=', 'ac_to.id') + ->leftJoin( + 'account_meta as acm_to', function (JoinClause $join) { + $join->on('ac_to.id', '=', 'acm_to.account_id')->where('acm_to.name', '=', 'accountRole'); + } + ) + ->leftJoin('transaction_types', 'transaction_types.id', '=', 'transaction_journals.transaction_type_id'); $query->before($end)->after($start)->where('transaction_journals.user_id', Auth::user()->id); return $query; diff --git a/app/Http/Controllers/AccountController.php b/app/Http/Controllers/AccountController.php index be1a8545c8..d431fe4267 100644 --- a/app/Http/Controllers/AccountController.php +++ b/app/Http/Controllers/AccountController.php @@ -156,7 +156,7 @@ class AccountController extends Controller $start = clone Session::get('start', Carbon::now()->startOfMonth()); $start->subDay(); $accounts->each( - function (Account $account) use ($start, $repository) { + function(Account $account) use ($start, $repository) { $account->lastActivityDate = $repository->getLastActivity($account); $account->startBalance = Steam::balance($account, $start); $account->endBalance = Steam::balance($account, clone Session::get('end', Carbon::now()->endOfMonth())); @@ -201,11 +201,11 @@ class AccountController extends Controller 'user' => Auth::user()->id, 'accountRole' => $request->input('accountRole'), 'openingBalance' => floatval($request->input('openingBalance')), - 'openingBalanceDate' => new Carbon((string)$request->input('openingBalanceDate')), + 'openingBalanceDate' => new Carbon((string) $request->input('openingBalanceDate')), 'openingBalanceCurrency' => intval($request->input('balance_currency_id')), ]; - $account = $repository->store($accountData); + $account = $repository->store($accountData); Session::flash('success', 'New account "' . $account->name . '" stored!'); Preferences::mark(); @@ -240,7 +240,7 @@ class AccountController extends Controller 'accountRole' => $request->input('accountRole'), 'virtualBalance' => floatval($request->input('virtualBalance')), 'openingBalance' => floatval($request->input('openingBalance')), - 'openingBalanceDate' => new Carbon((string)$request->input('openingBalanceDate')), + 'openingBalanceDate' => new Carbon((string) $request->input('openingBalanceDate')), 'openingBalanceCurrency' => intval($request->input('balance_currency_id')), 'ccType' => $request->input('ccType'), 'ccMonthlyPaymentDate' => $request->input('ccMonthlyPaymentDate'), diff --git a/app/Http/Controllers/Auth/AuthController.php b/app/Http/Controllers/Auth/AuthController.php index 4330203b5c..e4031afc1e 100644 --- a/app/Http/Controllers/Auth/AuthController.php +++ b/app/Http/Controllers/Auth/AuthController.php @@ -95,7 +95,7 @@ class AuthController extends Controller // send email. Mail::send( - 'emails.registered', [], function (Message $message) use ($email) { + 'emails.registered', [], function(Message $message) use ($email) { $message->to($email, $email)->subject('Welcome to Firefly III!'); } ); diff --git a/app/Http/Controllers/BillController.php b/app/Http/Controllers/BillController.php index 045b242b97..6d96298615 100644 --- a/app/Http/Controllers/BillController.php +++ b/app/Http/Controllers/BillController.php @@ -112,7 +112,7 @@ class BillController extends Controller { $bills = $repository->getBills(); $bills->each( - function (Bill $bill) use ($repository) { + function(Bill $bill) use ($repository) { $bill->nextExpectedMatch = $repository->nextExpectedMatch($bill); $bill->lastFoundMatch = $repository->lastFoundMatch($bill); } diff --git a/app/Http/Controllers/BudgetController.php b/app/Http/Controllers/BudgetController.php index a58248e9fc..48ca342654 100644 --- a/app/Http/Controllers/BudgetController.php +++ b/app/Http/Controllers/BudgetController.php @@ -245,7 +245,7 @@ class BudgetController extends Controller 'name' => $request->input('name'), 'user' => Auth::user()->id, ]; - $budget = $repository->store($budgetData); + $budget = $repository->store($budgetData); Session::flash('success', 'New budget "' . $budget->name . '" stored!'); Preferences::mark(); diff --git a/app/Http/Controllers/CategoryController.php b/app/Http/Controllers/CategoryController.php index b6f016f272..6de44dbba9 100644 --- a/app/Http/Controllers/CategoryController.php +++ b/app/Http/Controllers/CategoryController.php @@ -114,7 +114,7 @@ class CategoryController extends Controller $categories = $repository->getCategories(); $categories->each( - function (Category $category) use ($repository) { + function(Category $category) use ($repository) { $category->lastActivity = $repository->getLatestActivity($category); } ); @@ -167,7 +167,7 @@ class CategoryController extends Controller 'name' => $request->input('name'), 'user' => Auth::user()->id, ]; - $category = $repository->store($categoryData); + $category = $repository->store($categoryData); Session::flash('success', 'New category "' . $category->name . '" stored!'); Preferences::mark(); diff --git a/app/Http/Controllers/Chart/BudgetController.php b/app/Http/Controllers/Chart/BudgetController.php index abcd2ce2a0..46cba626e6 100644 --- a/app/Http/Controllers/Chart/BudgetController.php +++ b/app/Http/Controllers/Chart/BudgetController.php @@ -169,9 +169,9 @@ class BudgetController extends Controller $overspent = $expenses > floatval($repetition->amount) ? $expenses - floatval($repetition->amount) : 0; $allEntries->push( [$budget->name . ' (' . $repetition->startdate->formatLocalized($this->monthAndDayFormat) . ')', - $left, - $spent, - $overspent + $left, + $spent, + $overspent ] ); } diff --git a/app/Http/Controllers/Chart/CategoryController.php b/app/Http/Controllers/Chart/CategoryController.php index b7c4bdb800..ab9102e7a9 100644 --- a/app/Http/Controllers/Chart/CategoryController.php +++ b/app/Http/Controllers/Chart/CategoryController.php @@ -92,7 +92,7 @@ class CategoryController extends Controller // sort by callback: uasort( $set, - function ($left, $right) { + function($left, $right) { if ($left['sum'] == $right['sum']) { return 0; } diff --git a/app/Http/Controllers/HomeController.php b/app/Http/Controllers/HomeController.php index 81e4dacc43..695a522141 100644 --- a/app/Http/Controllers/HomeController.php +++ b/app/Http/Controllers/HomeController.php @@ -84,8 +84,8 @@ class HomeController extends Controller if ($sum != 0) { Session::flash( 'error', 'Your transactions are unbalanced. This means a' - . ' withdrawal, deposit or transfer was not stored properly. ' - . 'Please check your accounts and transactions for errors.' + . ' withdrawal, deposit or transfer was not stored properly. ' + . 'Please check your accounts and transactions for errors.' ); } diff --git a/app/Http/Controllers/NewUserController.php b/app/Http/Controllers/NewUserController.php index 8a14f74632..1508a2448f 100644 --- a/app/Http/Controllers/NewUserController.php +++ b/app/Http/Controllers/NewUserController.php @@ -96,11 +96,11 @@ class NewUserController extends Controller 'openingBalanceDate' => null, 'openingBalanceCurrency' => intval($request->input('balance_currency_id')), ]; - $creditCard = $repository->store($creditAccount); + $creditCard = $repository->store($creditAccount); // store meta for CC: - AccountMeta::create(['name' => 'ccType', 'data' => 'monthlyFull', 'account_id' => $creditCard->id,]); - AccountMeta::create(['name' => 'ccMonthlyPaymentDate', 'data' => Carbon::now()->year . '-01-01', 'account_id' => $creditCard->id,]); + AccountMeta::create(['name' => 'ccType', 'data' => 'monthlyFull', 'account_id' => $creditCard->id, ]); + AccountMeta::create(['name' => 'ccMonthlyPaymentDate', 'data' => Carbon::now()->year . '-01-01', 'account_id' => $creditCard->id, ]); } Session::flash('success', 'New account(s) created!'); diff --git a/app/Http/Controllers/PiggyBankController.php b/app/Http/Controllers/PiggyBankController.php index 381f1c544c..f9bc5f87c6 100644 --- a/app/Http/Controllers/PiggyBankController.php +++ b/app/Http/Controllers/PiggyBankController.php @@ -139,11 +139,11 @@ class PiggyBankController extends Controller $targetDate = $targetDate->format('Y-m-d'); } $preFilled = ['name' => $piggyBank->name, - 'account_id' => $piggyBank->account_id, - 'targetamount' => $piggyBank->targetamount, - 'targetdate' => $targetDate, - 'reminder' => $piggyBank->reminder, - 'remind_me' => intval($piggyBank->remind_me) == 1 && !is_null($piggyBank->reminder) ? true : false + 'account_id' => $piggyBank->account_id, + 'targetamount' => $piggyBank->targetamount, + 'targetdate' => $targetDate, + 'reminder' => $piggyBank->reminder, + 'remind_me' => intval($piggyBank->remind_me) == 1 && !is_null($piggyBank->reminder) ? true : false ]; Session::flash('preFilled', $preFilled); Session::flash('gaEventCategory', 'piggy-banks'); diff --git a/app/Http/Controllers/TransactionController.php b/app/Http/Controllers/TransactionController.php index e3fb0f0e31..575d35c383 100644 --- a/app/Http/Controllers/TransactionController.php +++ b/app/Http/Controllers/TransactionController.php @@ -253,7 +253,7 @@ class TransactionController extends Controller public function show(JournalRepositoryInterface $repository, TransactionJournal $journal) { $journal->transactions->each( - function (Transaction $t) use ($journal, $repository) { + function(Transaction $t) use ($journal, $repository) { $t->before = $repository->getAmountBefore($journal, $t); $t->after = $t->before + $t->amount; } diff --git a/app/Http/Middleware/Reminders.php b/app/Http/Middleware/Reminders.php index 0be752e89e..c74b4f35bc 100644 --- a/app/Http/Middleware/Reminders.php +++ b/app/Http/Middleware/Reminders.php @@ -83,7 +83,7 @@ class Reminders // get and list active reminders: $reminders = $user->reminders()->today()->get(); $reminders->each( - function (Reminder $reminder) use ($helper) { + function(Reminder $reminder) use ($helper) { $reminder->description = $helper->getReminderText($reminder); } ); diff --git a/app/Http/breadcrumbs.php b/app/Http/breadcrumbs.php index fd8e5a146f..80aa857876 100644 --- a/app/Http/breadcrumbs.php +++ b/app/Http/breadcrumbs.php @@ -17,7 +17,7 @@ use FireflyIII\Models\TransactionJournal; */ Breadcrumbs::register( 'home', - function (Generator $breadcrumbs) { + function(Generator $breadcrumbs) { $breadcrumbs->push(trans('breadcrumbs.home'), route('index')); } @@ -25,7 +25,7 @@ Breadcrumbs::register( Breadcrumbs::register( 'index', - function (Generator $breadcrumbs) { + function(Generator $breadcrumbs) { $breadcrumbs->push(trans('breadcrumbs.home'), route('index')); } @@ -34,21 +34,21 @@ Breadcrumbs::register( // accounts Breadcrumbs::register( - 'accounts.index', function (Generator $breadcrumbs, $what) { + 'accounts.index', function(Generator $breadcrumbs, $what) { $breadcrumbs->parent('home'); $breadcrumbs->push(trans('breadcrumbs.' . strtolower(e($what)) . '_accounts'), route('accounts.index', [$what])); } ); Breadcrumbs::register( - 'accounts.create', function (Generator $breadcrumbs, $what) { + 'accounts.create', function(Generator $breadcrumbs, $what) { $breadcrumbs->parent('accounts.index', $what); $breadcrumbs->push(trans('breadcrumbs.new_' . strtolower(e($what)) . '_account'), route('accounts.create', [$what])); } ); Breadcrumbs::register( - 'accounts.show', function (Generator $breadcrumbs, Account $account) { + 'accounts.show', function(Generator $breadcrumbs, Account $account) { $what = Config::get('firefly.shortNamesByFullName.' . $account->accountType->type); @@ -58,7 +58,7 @@ Breadcrumbs::register( } ); Breadcrumbs::register( - 'accounts.delete', function (Generator $breadcrumbs, Account $account) { + 'accounts.delete', function(Generator $breadcrumbs, Account $account) { $breadcrumbs->parent('accounts.show', $account); $breadcrumbs->push(trans('breadcrumbs.delete_account', ['name' => e($account->name)]), route('accounts.delete', [$account->id])); } @@ -66,7 +66,7 @@ Breadcrumbs::register( Breadcrumbs::register( - 'accounts.edit', function (Generator $breadcrumbs, Account $account) { + 'accounts.edit', function(Generator $breadcrumbs, Account $account) { $breadcrumbs->parent('accounts.show', $account); $what = Config::get('firefly.shortNamesByFullName.' . $account->accountType->type); @@ -76,40 +76,40 @@ Breadcrumbs::register( // budgets. Breadcrumbs::register( - 'budgets.index', function (Generator $breadcrumbs) { + 'budgets.index', function(Generator $breadcrumbs) { $breadcrumbs->parent('home'); $breadcrumbs->push(trans('breadcrumbs.budgets'), route('budgets.index')); } ); Breadcrumbs::register( - 'budgets.create', function (Generator $breadcrumbs) { + 'budgets.create', function(Generator $breadcrumbs) { $breadcrumbs->parent('budgets.index'); $breadcrumbs->push(trans('breadcrumbs.newBudget'), route('budgets.create')); } ); Breadcrumbs::register( - 'budgets.edit', function (Generator $breadcrumbs, Budget $budget) { + 'budgets.edit', function(Generator $breadcrumbs, Budget $budget) { $breadcrumbs->parent('budgets.show', $budget); $breadcrumbs->push(trans('breadcrumbs.edit_budget', ['name' => e($budget->name)]), route('budgets.edit', [$budget->id])); } ); Breadcrumbs::register( - 'budgets.delete', function (Generator $breadcrumbs, Budget $budget) { + 'budgets.delete', function(Generator $breadcrumbs, Budget $budget) { $breadcrumbs->parent('budgets.show', $budget); $breadcrumbs->push(trans('breadcrumbs.delete_budget', ['name' => e($budget->name)]), route('budgets.delete', [$budget->id])); } ); Breadcrumbs::register( - 'budgets.noBudget', function (Generator $breadcrumbs, $subTitle) { + 'budgets.noBudget', function(Generator $breadcrumbs, $subTitle) { $breadcrumbs->parent('budgets.index'); $breadcrumbs->push($subTitle, route('budgets.noBudget')); } ); Breadcrumbs::register( - 'budgets.show', function (Generator $breadcrumbs, Budget $budget, LimitRepetition $repetition = null) { + 'budgets.show', function(Generator $breadcrumbs, Budget $budget, LimitRepetition $repetition = null) { $breadcrumbs->parent('budgets.index'); $breadcrumbs->push(e($budget->name), route('budgets.show', [$budget->id])); if (!is_null($repetition) && !is_null($repetition->id)) { @@ -122,33 +122,33 @@ Breadcrumbs::register( // categories Breadcrumbs::register( - 'categories.index', function (Generator $breadcrumbs) { + 'categories.index', function(Generator $breadcrumbs) { $breadcrumbs->parent('home'); $breadcrumbs->push(trans('breadcrumbs.categories'), route('categories.index')); } ); Breadcrumbs::register( - 'categories.create', function (Generator $breadcrumbs) { + 'categories.create', function(Generator $breadcrumbs) { $breadcrumbs->parent('categories.index'); $breadcrumbs->push(trans('breadcrumbs.newCategory'), route('categories.create')); } ); Breadcrumbs::register( - 'categories.edit', function (Generator $breadcrumbs, Category $category) { + 'categories.edit', function(Generator $breadcrumbs, Category $category) { $breadcrumbs->parent('categories.show', $category); $breadcrumbs->push(trans('breadcrumbs.edit_category', ['name' => e($category->name)]), route('categories.edit', [$category->id])); } ); Breadcrumbs::register( - 'categories.delete', function (Generator $breadcrumbs, Category $category) { + 'categories.delete', function(Generator $breadcrumbs, Category $category) { $breadcrumbs->parent('categories.show', $category); $breadcrumbs->push(trans('breadcrumbs.delete_category', ['name' => e($category->name)]), route('categories.delete', [$category->id])); } ); Breadcrumbs::register( - 'categories.show', function (Generator $breadcrumbs, Category $category) { + 'categories.show', function(Generator $breadcrumbs, Category $category) { $breadcrumbs->parent('categories.index'); $breadcrumbs->push(e($category->name), route('categories.show', [$category->id])); @@ -156,7 +156,7 @@ Breadcrumbs::register( ); Breadcrumbs::register( - 'categories.noCategory', function (Generator $breadcrumbs, $subTitle) { + 'categories.noCategory', function(Generator $breadcrumbs, $subTitle) { $breadcrumbs->parent('categories.index'); $breadcrumbs->push($subTitle, route('categories.noCategory')); } @@ -164,20 +164,20 @@ Breadcrumbs::register( // currencies. Breadcrumbs::register( - 'currency.index', function (Generator $breadcrumbs) { + 'currency.index', function(Generator $breadcrumbs) { $breadcrumbs->parent('home'); $breadcrumbs->push(trans('breadcrumbs.currencies'), route('currency.index')); } ); Breadcrumbs::register( - 'currency.edit', function (Generator $breadcrumbs, TransactionCurrency $currency) { + 'currency.edit', function(Generator $breadcrumbs, TransactionCurrency $currency) { $breadcrumbs->parent('currency.index'); $breadcrumbs->push(trans('breadcrumbs.edit_currency', ['name' => e($currency->name)]), route('currency.edit', [$currency->id])); } ); Breadcrumbs::register( - 'currency.delete', function (Generator $breadcrumbs, TransactionCurrency $currency) { + 'currency.delete', function(Generator $breadcrumbs, TransactionCurrency $currency) { $breadcrumbs->parent('currency.index'); $breadcrumbs->push(trans('breadcrumbs.delete_currency', ['name' => e($currency->name)]), route('currency.delete', [$currency->id])); } @@ -186,33 +186,33 @@ Breadcrumbs::register( // piggy banks Breadcrumbs::register( - 'piggy-banks.index', function (Generator $breadcrumbs) { + 'piggy-banks.index', function(Generator $breadcrumbs) { $breadcrumbs->parent('home'); $breadcrumbs->push(trans('breadcrumbs.piggyBanks'), route('piggy-banks.index')); } ); Breadcrumbs::register( - 'piggy-banks.create', function (Generator $breadcrumbs) { + 'piggy-banks.create', function(Generator $breadcrumbs) { $breadcrumbs->parent('piggy-banks.index'); $breadcrumbs->push(trans('breadcrumbs.newPiggyBank'), route('piggy-banks.create')); } ); Breadcrumbs::register( - 'piggy-banks.edit', function (Generator $breadcrumbs, PiggyBank $piggyBank) { + 'piggy-banks.edit', function(Generator $breadcrumbs, PiggyBank $piggyBank) { $breadcrumbs->parent('piggy-banks.show', $piggyBank); $breadcrumbs->push(trans('breadcrumbs.edit_piggyBank', ['name' => e($piggyBank->name)]), route('piggy-banks.edit', [$piggyBank->id])); } ); Breadcrumbs::register( - 'piggy-banks.delete', function (Generator $breadcrumbs, PiggyBank $piggyBank) { + 'piggy-banks.delete', function(Generator $breadcrumbs, PiggyBank $piggyBank) { $breadcrumbs->parent('piggy-banks.show', $piggyBank); $breadcrumbs->push(trans('breadcrumbs.delete_piggyBank', ['name' => e($piggyBank->name)]), route('piggy-banks.delete', [$piggyBank->id])); } ); Breadcrumbs::register( - 'piggy-banks.show', function (Generator $breadcrumbs, PiggyBank $piggyBank) { + 'piggy-banks.show', function(Generator $breadcrumbs, PiggyBank $piggyBank) { $breadcrumbs->parent('piggy-banks.index'); $breadcrumbs->push(e($piggyBank->name), route('piggy-banks.show', [$piggyBank->id])); @@ -221,7 +221,7 @@ Breadcrumbs::register( // preferences Breadcrumbs::register( - 'preferences', function (Generator $breadcrumbs) { + 'preferences', function(Generator $breadcrumbs) { $breadcrumbs->parent('home'); $breadcrumbs->push(trans('breadcrumbs.preferences'), route('preferences')); @@ -230,14 +230,14 @@ Breadcrumbs::register( // profile Breadcrumbs::register( - 'profile', function (Generator $breadcrumbs) { + 'profile', function(Generator $breadcrumbs) { $breadcrumbs->parent('home'); $breadcrumbs->push(trans('breadcrumbs.profile'), route('profile')); } ); Breadcrumbs::register( - 'change-password', function (Generator $breadcrumbs) { + 'change-password', function(Generator $breadcrumbs) { $breadcrumbs->parent('profile'); $breadcrumbs->push(trans('breadcrumbs.changePassword'), route('change-password')); @@ -246,33 +246,33 @@ Breadcrumbs::register( // bills Breadcrumbs::register( - 'bills.index', function (Generator $breadcrumbs) { + 'bills.index', function(Generator $breadcrumbs) { $breadcrumbs->parent('home'); $breadcrumbs->push(trans('breadcrumbs.bills'), route('bills.index')); } ); Breadcrumbs::register( - 'bills.create', function (Generator $breadcrumbs) { + 'bills.create', function(Generator $breadcrumbs) { $breadcrumbs->parent('bills.index'); $breadcrumbs->push(trans('breadcrumbs.newBill'), route('bills.create')); } ); Breadcrumbs::register( - 'bills.edit', function (Generator $breadcrumbs, Bill $bill) { + 'bills.edit', function(Generator $breadcrumbs, Bill $bill) { $breadcrumbs->parent('bills.show', $bill); $breadcrumbs->push(trans('breadcrumbs.edit_bill', ['name' => e($bill->name)]), route('bills.edit', [$bill->id])); } ); Breadcrumbs::register( - 'bills.delete', function (Generator $breadcrumbs, Bill $bill) { + 'bills.delete', function(Generator $breadcrumbs, Bill $bill) { $breadcrumbs->parent('bills.show', $bill); $breadcrumbs->push(trans('breadcrumbs.delete_bill', ['name' => e($bill->name)]), route('bills.delete', [$bill->id])); } ); Breadcrumbs::register( - 'bills.show', function (Generator $breadcrumbs, Bill $bill) { + 'bills.show', function(Generator $breadcrumbs, Bill $bill) { $breadcrumbs->parent('bills.index'); $breadcrumbs->push(e($bill->name), route('bills.show', [$bill->id])); @@ -281,7 +281,7 @@ Breadcrumbs::register( // reminders Breadcrumbs::register( - 'reminders.index', function (Generator $breadcrumbs) { + 'reminders.index', function(Generator $breadcrumbs) { $breadcrumbs->parent('home'); $breadcrumbs->push(trans('breadcrumbs.reminders'), route('reminders.index')); @@ -290,7 +290,7 @@ Breadcrumbs::register( // reminders Breadcrumbs::register( - 'reminders.show', function (Generator $breadcrumbs, Reminder $reminder) { + 'reminders.show', function(Generator $breadcrumbs, Reminder $reminder) { $breadcrumbs->parent('reminders.index'); $breadcrumbs->push(trans('breadcrumbs.reminder', ['id' => e($reminder->id)]), route('reminders.show', [$reminder->id])); @@ -300,14 +300,14 @@ Breadcrumbs::register( // reports Breadcrumbs::register( - 'reports.index', function (Generator $breadcrumbs) { + 'reports.index', function(Generator $breadcrumbs) { $breadcrumbs->parent('home'); $breadcrumbs->push(trans('breadcrumbs.reports'), route('reports.index')); } ); Breadcrumbs::register( - 'reports.year', function (Generator $breadcrumbs, Carbon $date, $shared) { + 'reports.year', function(Generator $breadcrumbs, Carbon $date, $shared) { $breadcrumbs->parent('reports.index'); if ($shared) { $title = trans('breadcrumbs.yearly_report_shared', ['date' => $date->year]); @@ -319,7 +319,7 @@ Breadcrumbs::register( ); Breadcrumbs::register( - 'reports.month', function (Generator $breadcrumbs, Carbon $date, $shared) { + 'reports.month', function(Generator $breadcrumbs, Carbon $date, $shared) { $breadcrumbs->parent('reports.year', $date, $shared); if ($shared) { @@ -334,7 +334,7 @@ Breadcrumbs::register( // search Breadcrumbs::register( - 'search', function (Generator $breadcrumbs, $query) { + 'search', function(Generator $breadcrumbs, $query) { $breadcrumbs->parent('home'); $breadcrumbs->push(trans('breadcrumbs.searchResult', ['query' => e($query)]), route('search')); } @@ -342,33 +342,33 @@ Breadcrumbs::register( // transactions Breadcrumbs::register( - 'transactions.index', function (Generator $breadcrumbs, $what) { + 'transactions.index', function(Generator $breadcrumbs, $what) { $breadcrumbs->parent('home'); $breadcrumbs->push(trans('breadcrumbs.' . $what . '_list'), route('transactions.index', [$what])); } ); Breadcrumbs::register( - 'transactions.create', function (Generator $breadcrumbs, $what) { + 'transactions.create', function(Generator $breadcrumbs, $what) { $breadcrumbs->parent('transactions.index', $what); $breadcrumbs->push(trans('breadcrumbs.create_' . e($what)), route('transactions.create', [$what])); } ); Breadcrumbs::register( - 'transactions.edit', function (Generator $breadcrumbs, TransactionJournal $journal) { + 'transactions.edit', function(Generator $breadcrumbs, TransactionJournal $journal) { $breadcrumbs->parent('transactions.show', $journal); $breadcrumbs->push(trans('breadcrumbs.edit_journal', ['description' => $journal->description]), route('transactions.edit', [$journal->id])); } ); Breadcrumbs::register( - 'transactions.delete', function (Generator $breadcrumbs, TransactionJournal $journal) { + 'transactions.delete', function(Generator $breadcrumbs, TransactionJournal $journal) { $breadcrumbs->parent('transactions.show', $journal); $breadcrumbs->push(trans('breadcrumbs.delete_journal', ['description' => e($journal->description)]), route('transactions.delete', [$journal->id])); } ); Breadcrumbs::register( - 'transactions.show', function (Generator $breadcrumbs, TransactionJournal $journal) { + 'transactions.show', function(Generator $breadcrumbs, TransactionJournal $journal) { $breadcrumbs->parent('transactions.index', strtolower($journal->transactionType->type)); $breadcrumbs->push($journal->description, route('transactions.show', [$journal->id])); @@ -378,28 +378,28 @@ Breadcrumbs::register( // tags Breadcrumbs::register( - 'tags.index', function (Generator $breadcrumbs) { + 'tags.index', function(Generator $breadcrumbs) { $breadcrumbs->parent('home'); $breadcrumbs->push(trans('breadcrumbs.tags'), route('tags.index')); } ); Breadcrumbs::register( - 'tags.create', function (Generator $breadcrumbs) { + 'tags.create', function(Generator $breadcrumbs) { $breadcrumbs->parent('tags.index'); $breadcrumbs->push(trans('breadcrumbs.createTag'), route('tags.create')); } ); Breadcrumbs::register( - 'tags.edit', function (Generator $breadcrumbs, Tag $tag) { + 'tags.edit', function(Generator $breadcrumbs, Tag $tag) { $breadcrumbs->parent('tags.show', $tag); $breadcrumbs->push(trans('breadcrumbs.edit_tag', ['tag' => e($tag->tag)]), route('tags.edit', [$tag->id])); } ); Breadcrumbs::register( - 'tags.delete', function (Generator $breadcrumbs, Tag $tag) { + 'tags.delete', function(Generator $breadcrumbs, Tag $tag) { $breadcrumbs->parent('tags.show', $tag); $breadcrumbs->push(trans('breadcrumbs.delete_tag', ['tag' => e($tag->tag)]), route('tags.delete', [$tag->id])); } @@ -407,7 +407,7 @@ Breadcrumbs::register( Breadcrumbs::register( - 'tags.show', function (Generator $breadcrumbs, Tag $tag) { + 'tags.show', function(Generator $breadcrumbs, Tag $tag) { $breadcrumbs->parent('tags.index'); $breadcrumbs->push(e($tag->tag), route('tags.show', [$tag->id])); } diff --git a/app/Http/routes.php b/app/Http/routes.php index 2b66dac023..3efce92ee6 100644 --- a/app/Http/routes.php +++ b/app/Http/routes.php @@ -15,13 +15,13 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; // models Route::bind( 'account', - function ($value) { + function($value) { if (Auth::check()) { $object = Account::leftJoin('account_types', 'account_types.id', '=', 'accounts.account_type_id') - ->where('account_types.editable', 1) - ->where('accounts.id', $value) - ->where('user_id', Auth::user()->id) - ->first(['accounts.*']); + ->where('account_types.editable', 1) + ->where('accounts.id', $value) + ->where('user_id', Auth::user()->id) + ->first(['accounts.*']); if ($object) { return $object; } @@ -31,7 +31,7 @@ Route::bind( ); Route::bind( - 'tj', function ($value) { + 'tj', function($value) { if (Auth::check()) { $object = TransactionJournal::where('id', $value)->where('user_id', Auth::user()->id)->first(); if ($object) { @@ -44,7 +44,7 @@ Route::bind( ); Route::bind( - 'currency', function ($value) { + 'currency', function($value) { if (Auth::check()) { $object = TransactionCurrency::find($value); if ($object) { @@ -56,7 +56,7 @@ Route::bind( ); Route::bind( - 'bill', function ($value) { + 'bill', function($value) { if (Auth::check()) { $object = Bill::where('id', $value)->where('user_id', Auth::user()->id)->first(); if ($object) { @@ -69,7 +69,7 @@ Route::bind( ); Route::bind( - 'budget', function ($value) { + 'budget', function($value) { if (Auth::check()) { $object = Budget::where('id', $value)->where('user_id', Auth::user()->id)->first(); if ($object) { @@ -82,7 +82,7 @@ Route::bind( ); Route::bind( - 'reminder', function ($value) { + 'reminder', function($value) { if (Auth::check()) { $object = Reminder::where('id', $value)->where('user_id', Auth::user()->id)->first(); if ($object) { @@ -95,13 +95,13 @@ Route::bind( ); Route::bind( - 'limitrepetition', function ($value) { + 'limitrepetition', function($value) { if (Auth::check()) { $object = LimitRepetition::where('limit_repetitions.id', $value) - ->leftjoin('budget_limits', 'budget_limits.id', '=', 'limit_repetitions.budget_limit_id') - ->leftJoin('budgets', 'budgets.id', '=', 'budget_limits.budget_id') - ->where('budgets.user_id', Auth::user()->id) - ->first(['limit_repetitions.*']); + ->leftjoin('budget_limits', 'budget_limits.id', '=', 'limit_repetitions.budget_limit_id') + ->leftJoin('budgets', 'budgets.id', '=', 'budget_limits.budget_id') + ->where('budgets.user_id', Auth::user()->id) + ->first(['limit_repetitions.*']); if ($object) { return $object; } @@ -112,12 +112,12 @@ Route::bind( ); Route::bind( - 'piggyBank', function ($value) { + 'piggyBank', function($value) { if (Auth::check()) { $object = PiggyBank::where('piggy_banks.id', $value) - ->leftJoin('accounts', 'accounts.id', '=', 'piggy_banks.account_id') - ->where('accounts.user_id', Auth::user()->id) - ->first(['piggy_banks.*']); + ->leftJoin('accounts', 'accounts.id', '=', 'piggy_banks.account_id') + ->where('accounts.user_id', Auth::user()->id) + ->first(['piggy_banks.*']); if ($object) { return $object; } @@ -128,7 +128,7 @@ Route::bind( ); Route::bind( - 'category', function ($value) { + 'category', function($value) { if (Auth::check()) { $object = Category::where('id', $value)->where('user_id', Auth::user()->id)->first(); if ($object) { @@ -142,7 +142,7 @@ Route::bind( /** @noinspection PhpUnusedParameterInspection */ Route::bind( - 'reminder', function ($value) { + 'reminder', function($value) { if (Auth::check()) { /** @var \FireflyIII\Models\Reminder $object */ $object = Reminder::find($value); @@ -158,7 +158,7 @@ Route::bind( ); Route::bind( - 'tag', function ($value) { + 'tag', function($value) { if (Auth::check()) { $object = Tag::where('id', $value)->where('user_id', Auth::user()->id)->first(); if ($object) { @@ -187,7 +187,7 @@ Route::controllers( * Home Controller */ Route::group( - ['middleware' => ['auth', 'range', 'reminders']], function () { + ['middleware' => ['auth', 'range', 'reminders']], function() { Route::get('/', ['uses' => 'HomeController@index', 'as' => 'index']); Route::get('/home', ['uses' => 'HomeController@index', 'as' => 'home']); Route::post('/daterange', ['uses' => 'HomeController@dateRange', 'as' => 'daterange']); diff --git a/app/Models/Account.php b/app/Models/Account.php index 943ecfb862..dc2a83ebc0 100644 --- a/app/Models/Account.php +++ b/app/Models/Account.php @@ -215,7 +215,7 @@ class Account extends Model { $joinName = str_replace('.', '_', $name); $query->leftJoin( - 'account_meta as ' . $joinName, function (JoinClause $join) use ($joinName, $name) { + 'account_meta as ' . $joinName, function(JoinClause $join) use ($joinName, $name) { $join->on($joinName . '.account_id', '=', 'accounts.id')->where($joinName . '.name', '=', $name); } ); diff --git a/app/Models/AccountMeta.php b/app/Models/AccountMeta.php index 1e2d0ce3c3..806b62da33 100644 --- a/app/Models/AccountMeta.php +++ b/app/Models/AccountMeta.php @@ -33,7 +33,7 @@ class AccountMeta extends Model 'name' => 'required|between:1,100', 'data' => 'required' ]; - protected $table = 'account_meta'; + protected $table = 'account_meta'; /** * diff --git a/app/Models/Bill.php b/app/Models/Bill.php index 91f934dbfa..6682c7329c 100644 --- a/app/Models/Bill.php +++ b/app/Models/Bill.php @@ -51,7 +51,7 @@ class Bill extends Model { protected $fillable - = ['name', 'match', 'amount_min', 'match_encrypted', 'name_encrypted', 'user_id', 'amount_max', 'date', 'repeat_freq', 'skip', 'automatch', 'active',]; + = ['name', 'match', 'amount_min', 'match_encrypted', 'name_encrypted', 'user_id', 'amount_max', 'date', 'repeat_freq', 'skip', 'automatch', 'active', ]; protected $hidden = ['amount_min_encrypted', 'amount_max_encrypted', 'name_encrypted', 'match_encrypted']; diff --git a/app/Models/PiggyBank.php b/app/Models/PiggyBank.php index 127a65e619..6183258f6b 100644 --- a/app/Models/PiggyBank.php +++ b/app/Models/PiggyBank.php @@ -50,7 +50,7 @@ class PiggyBank extends Model use SoftDeletes; protected $fillable - = ['name', 'account_id', 'order', 'reminder_skip', 'targetamount', 'startdate', 'targetdate', 'reminder', 'remind_me']; + = ['name', 'account_id', 'order', 'reminder_skip', 'targetamount', 'startdate', 'targetdate', 'reminder', 'remind_me']; protected $hidden = ['targetamount_encrypted', 'encrypted']; /** diff --git a/app/Models/PiggyBankRepetition.php b/app/Models/PiggyBankRepetition.php index 68d2388acc..5044981ebc 100644 --- a/app/Models/PiggyBankRepetition.php +++ b/app/Models/PiggyBankRepetition.php @@ -77,13 +77,13 @@ class PiggyBankRepetition extends Model $q->orWhereNull('startdate'); } ) - ->where( - function (EloquentBuilder $q) use ($date) { + ->where( + function (EloquentBuilder $q) use ($date) { - $q->where('targetdate', '>=', $date->format('Y-m-d 00:00:00')); - $q->orWhereNull('targetdate'); - } - ); + $q->where('targetdate', '>=', $date->format('Y-m-d 00:00:00')); + $q->orWhereNull('targetdate'); + } + ); } /** diff --git a/app/Models/Reminder.php b/app/Models/Reminder.php index d8c5d90afe..0167d81364 100644 --- a/app/Models/Reminder.php +++ b/app/Models/Reminder.php @@ -44,7 +44,7 @@ class Reminder extends Model { - protected $fillable = ['user_id', 'startdate', 'metadata', 'enddate', 'active', 'notnow', 'remindersable_id', 'remindersable_type',]; + protected $fillable = ['user_id', 'startdate', 'metadata', 'enddate', 'active', 'notnow', 'remindersable_id', 'remindersable_type', ]; protected $hidden = ['encrypted']; /** @@ -124,7 +124,7 @@ class Reminder extends Model $today = new Carbon; return $query->where('startdate', '<=', $today->format('Y-m-d 00:00:00'))->where('enddate', '>=', $today->format('Y-m-d 00:00:00'))->where('active', 1) - ->where('notnow', 0); + ->where('notnow', 0); } /** diff --git a/app/Models/TransactionJournal.php b/app/Models/TransactionJournal.php index ae335b6ead..6ca596ac44 100644 --- a/app/Models/TransactionJournal.php +++ b/app/Models/TransactionJournal.php @@ -415,7 +415,7 @@ class TransactionJournal extends Model public function scopeWithRelevantData(EloquentBuilder $query) { $query->with( - ['transactions' => function (HasMany $q) { + ['transactions' => function(HasMany $q) { $q->orderBy('amount', 'ASC'); }, 'transactiontype', 'transactioncurrency', 'budgets', 'categories', 'transactions.account.accounttype', 'bill', 'budgets', 'categories'] ); diff --git a/app/Providers/BusServiceProvider.php b/app/Providers/BusServiceProvider.php index dc2e86ac21..1eef3684d7 100644 --- a/app/Providers/BusServiceProvider.php +++ b/app/Providers/BusServiceProvider.php @@ -23,7 +23,7 @@ class BusServiceProvider extends ServiceProvider public function boot(Dispatcher $dispatcher) { $dispatcher->mapUsing( - function ($command) { + function($command) { return Dispatcher::simpleMapping( $command, 'FireflyIII\Commands', 'FireflyIII\Handlers\Commands' ); diff --git a/app/Providers/EventServiceProvider.php b/app/Providers/EventServiceProvider.php index 9299f12fcb..3e01105bd5 100644 --- a/app/Providers/EventServiceProvider.php +++ b/app/Providers/EventServiceProvider.php @@ -52,12 +52,12 @@ class EventServiceProvider extends ServiceProvider $this->registerDeleteEvents(); $this->registerCreateEvents(); BudgetLimit::saved( - function (BudgetLimit $budgetLimit) { + function(BudgetLimit $budgetLimit) { $end = Navigation::addPeriod(clone $budgetLimit->startdate, $budgetLimit->repeat_freq, 0); $end->subDay(); $set = $budgetLimit->limitrepetitions()->where('startdate', $budgetLimit->startdate->format('Y-m-d'))->where('enddate', $end->format('Y-m-d')) - ->get(); + ->get(); if ($set->count() == 0) { $repetition = new LimitRepetition; $repetition->startdate = $budgetLimit->startdate; @@ -91,7 +91,7 @@ class EventServiceProvider extends ServiceProvider protected function registerDeleteEvents() { TransactionJournal::deleted( - function (TransactionJournal $journal) { + function(TransactionJournal $journal) { /** @var Transaction $transaction */ foreach ($journal->transactions()->get() as $transaction) { @@ -100,7 +100,7 @@ class EventServiceProvider extends ServiceProvider } ); PiggyBank::deleting( - function (PiggyBank $piggyBank) { + function(PiggyBank $piggyBank) { $reminders = $piggyBank->reminders()->get(); /** @var Reminder $reminder */ foreach ($reminders as $reminder) { @@ -110,7 +110,7 @@ class EventServiceProvider extends ServiceProvider ); Account::deleted( - function (Account $account) { + function(Account $account) { /** @var Transaction $transaction */ foreach ($account->transactions()->get() as $transaction) { @@ -131,7 +131,7 @@ class EventServiceProvider extends ServiceProvider // move this routine to a filter // in case of repeated piggy banks and/or other problems. PiggyBank::created( - function (PiggyBank $piggyBank) { + function(PiggyBank $piggyBank) { $repetition = new PiggyBankRepetition; $repetition->piggyBank()->associate($piggyBank); $repetition->startdate = is_null($piggyBank->startdate) ? null : $piggyBank->startdate; diff --git a/app/Providers/FireflyServiceProvider.php b/app/Providers/FireflyServiceProvider.php index eff456ea08..ab5d1be9e5 100644 --- a/app/Providers/FireflyServiceProvider.php +++ b/app/Providers/FireflyServiceProvider.php @@ -30,7 +30,7 @@ class FireflyServiceProvider extends ServiceProvider public function boot() { Validator::resolver( - function ($translator, $data, $rules, $messages) { + function($translator, $data, $rules, $messages) { return new FireflyValidator($translator, $data, $rules, $messages); } ); @@ -55,28 +55,28 @@ class FireflyServiceProvider extends ServiceProvider $this->app->bind( - 'preferences', function () { + 'preferences', function() { return new Preferences; } ); $this->app->bind( - 'navigation', function () { + 'navigation', function() { return new Navigation; } ); $this->app->bind( - 'amount', function () { + 'amount', function() { return new Amount; } ); $this->app->bind( - 'steam', function () { + 'steam', function() { return new Steam; } ); $this->app->bind( - 'expandedform', function () { + 'expandedform', function() { return new ExpandedForm; } ); diff --git a/app/Providers/RouteServiceProvider.php b/app/Providers/RouteServiceProvider.php index 4e40f5bec8..b95fa98635 100644 --- a/app/Providers/RouteServiceProvider.php +++ b/app/Providers/RouteServiceProvider.php @@ -44,7 +44,7 @@ class RouteServiceProvider extends ServiceProvider public function map(Router $router) { $router->group( - ['namespace' => $this->namespace], function ($router) { + ['namespace' => $this->namespace], function($router) { /** @noinspection PhpIncludeInspection */ require app_path('Http/routes.php'); } diff --git a/app/Repositories/Account/AccountRepository.php b/app/Repositories/Account/AccountRepository.php index d472825600..7b16735c03 100644 --- a/app/Repositories/Account/AccountRepository.php +++ b/app/Repositories/Account/AccountRepository.php @@ -65,7 +65,7 @@ class AccountRepository implements AccountRepositoryInterface public function getAccounts(array $types) { $result = Auth::user()->accounts()->with( - ['accountmeta' => function (HasMany $query) { + ['accountmeta' => function(HasMany $query) { $query->where('name', 'accountRole'); }] )->accountTypeIn($types)->orderBy('accounts.name', 'ASC')->get(['accounts.*'])->sortBy('name'); @@ -80,15 +80,15 @@ class AccountRepository implements AccountRepositoryInterface public function getCreditCards() { return Auth::user()->accounts() - ->hasMetaValue('accountRole', 'ccAsset') - ->hasMetaValue('ccType', 'monthlyFull') - ->get( - [ - 'accounts.*', - 'ccType.data as ccType', - 'accountRole.data as accountRole' - ] - ); + ->hasMetaValue('accountRole', 'ccAsset') + ->hasMetaValue('ccType', 'monthlyFull') + ->get( + [ + 'accounts.*', + 'ccType.data as ccType', + 'accountRole.data as accountRole' + ] + ); } /** @@ -151,18 +151,18 @@ class AccountRepository implements AccountRepositoryInterface } $set = Auth::user() - ->transactionjournals() - ->with(['transactions']) - ->leftJoin('transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id') - ->leftJoin('accounts', 'accounts.id', '=', 'transactions.account_id')->where('accounts.id', $account->id) - ->leftJoin('transaction_currencies', 'transaction_currencies.id', '=', 'transaction_journals.transaction_currency_id') - ->leftJoin('transaction_types', 'transaction_types.id', '=', 'transaction_journals.transaction_type_id') - ->before($end) - ->after($start) - ->orderBy('transaction_journals.date', 'DESC') - ->orderBy('transaction_journals.id', 'DESC') - ->take(10) - ->get(['transaction_journals.*', 'transaction_currencies.symbol', 'transaction_types.type']); + ->transactionjournals() + ->with(['transactions']) + ->leftJoin('transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id') + ->leftJoin('accounts', 'accounts.id', '=', 'transactions.account_id')->where('accounts.id', $account->id) + ->leftJoin('transaction_currencies', 'transaction_currencies.id', '=', 'transaction_journals.transaction_currency_id') + ->leftJoin('transaction_types', 'transaction_types.id', '=', 'transaction_journals.transaction_type_id') + ->before($end) + ->after($start) + ->orderBy('transaction_journals.date', 'DESC') + ->orderBy('transaction_journals.id', 'DESC') + ->take(10) + ->get(['transaction_journals.*', 'transaction_currencies.symbol', 'transaction_types.type']); $cache->store($set); return $set; @@ -178,13 +178,13 @@ class AccountRepository implements AccountRepositoryInterface { $offset = ($page - 1) * 50; $query = Auth::user() - ->transactionJournals() - ->withRelevantData() - ->leftJoin('transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id') - ->where('transactions.account_id', $account->id) - ->orderBy('transaction_journals.date', 'DESC') - ->orderBy('transaction_journals.order', 'ASC') - ->orderBy('transaction_journals.id', 'DESC'); + ->transactionJournals() + ->withRelevantData() + ->leftJoin('transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id') + ->where('transactions.account_id', $account->id) + ->orderBy('transaction_journals.date', 'DESC') + ->orderBy('transaction_journals.order', 'ASC') + ->orderBy('transaction_journals.id', 'DESC'); $count = $query->count(); $set = $query->take(50)->offset($offset)->get(['transaction_journals.*']); @@ -242,7 +242,7 @@ class AccountRepository implements AccountRepositoryInterface } $accounts->each( - function (Account $account) use ($start, $end) { + function(Account $account) use ($start, $end) { $account->startBalance = Steam::balance($account, $start, true); $account->endBalance = Steam::balance($account, $end, true); $account->piggyBalance = 0; @@ -282,7 +282,7 @@ class AccountRepository implements AccountRepositoryInterface $end = clone Session::get('end', new Carbon); $accounts->each( - function (Account $account) use ($start, $end) { + function(Account $account) use ($start, $end) { $account->startBalance = Steam::balance($account, $start); $account->endBalance = Steam::balance($account, $end); @@ -320,22 +320,22 @@ class AccountRepository implements AccountRepositoryInterface */ public function getTransfersInRange(Account $account, Carbon $start, Carbon $end) { - $set = TransactionJournal::whereIn( - 'id', function (Builder $q) use ($account, $start, $end) { + $set = TransactionJournal::whereIn( + 'id', function(Builder $q) use ($account, $start, $end) { $q->select('transaction_journals.id') - ->from('transactions') - ->leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id') - ->leftJoin('transaction_types', 'transaction_types.id', '=', 'transaction_journals.transaction_type_id') - ->where('transactions.account_id', $account->id) - ->where('transaction_journals.user_id', Auth::user()->id) - ->where('transaction_journals.date', '>=', $start->format('Y-m-d')) - ->where('transaction_journals.date', '<=', $end->format('Y-m-d')) - ->where('transaction_types.type', 'Transfer'); + ->from('transactions') + ->leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id') + ->leftJoin('transaction_types', 'transaction_types.id', '=', 'transaction_journals.transaction_type_id') + ->where('transactions.account_id', $account->id) + ->where('transaction_journals.user_id', Auth::user()->id) + ->where('transaction_journals.date', '>=', $start->format('Y-m-d')) + ->where('transaction_journals.date', '<=', $end->format('Y-m-d')) + ->where('transaction_types.type', 'Transfer'); } )->get(); $filtered = $set->filter( - function (TransactionJournal $journal) use ($account) { + function(TransactionJournal $journal) use ($account) { if ($journal->destination_account->id == $account->id) { return $journal; } @@ -374,10 +374,10 @@ class AccountRepository implements AccountRepositoryInterface public function openingBalanceTransaction(Account $account) { return TransactionJournal - ::orderBy('transaction_journals.date', 'ASC') - ->accountIs($account) - ->orderBy('created_at', 'ASC') - ->first(['transaction_journals.*']); + ::orderBy('transaction_journals.date', 'ASC') + ->accountIs($account) + ->orderBy('created_at', 'ASC') + ->first(['transaction_journals.*']); } /** @@ -401,7 +401,7 @@ class AccountRepository implements AccountRepositoryInterface 'name' => $data['name'] . ' initial balance', 'active' => false, ]; - $opposing = $this->storeAccount($opposingData); + $opposing = $this->storeAccount($opposingData); $this->storeInitialBalance($newAccount, $opposing, $data); } @@ -452,7 +452,7 @@ class AccountRepository implements AccountRepositoryInterface 'active' => false, 'virtualBalance' => 0, ]; - $opposing = $this->storeAccount($opposingData); + $opposing = $this->storeAccount($opposingData); $this->storeInitialBalance($account, $opposing, $data); } @@ -486,7 +486,7 @@ class AccountRepository implements AccountRepositoryInterface if (!$newAccount->isValid()) { // does the account already exist? - $searchData = [ + $searchData = [ 'user_id' => $data['user'], 'account_type_id' => $accountType->id, 'virtual_balance' => $data['virtualBalance'], diff --git a/app/Repositories/Budget/BudgetRepository.php b/app/Repositories/Budget/BudgetRepository.php index 86fcab135c..d14a7da15e 100644 --- a/app/Repositories/Budget/BudgetRepository.php +++ b/app/Repositories/Budget/BudgetRepository.php @@ -9,7 +9,6 @@ use FireflyIII\Models\BudgetLimit; use FireflyIII\Models\LimitRepetition; use FireflyIII\Repositories\Shared\ComponentRepository; use Illuminate\Database\Query\Builder as QueryBuilder; -use Illuminate\Database\Query\JoinClause; use Illuminate\Pagination\LengthAwarePaginator; use Illuminate\Support\Collection; use Input; @@ -80,10 +79,10 @@ class BudgetRepository extends ComponentRepository implements BudgetRepositoryIn /** @var Collection $repetitions */ return LimitRepetition:: leftJoin('budget_limits', 'limit_repetitions.budget_limit_id', '=', 'budget_limits.id') - ->where('limit_repetitions.startdate', '<=', $end->format('Y-m-d 00:00:00')) - ->where('limit_repetitions.startdate', '>=', $start->format('Y-m-d 00:00:00')) - ->where('budget_limits.budget_id', $budget->id) - ->get(['limit_repetitions.*']); + ->where('limit_repetitions.startdate', '<=', $end->format('Y-m-d 00:00:00')) + ->where('limit_repetitions.startdate', '>=', $start->format('Y-m-d 00:00:00')) + ->where('budget_limits.budget_id', $budget->id) + ->get(['limit_repetitions.*']); } /** @@ -155,9 +154,9 @@ class BudgetRepository extends ComponentRepository implements BudgetRepositoryIn $setQuery = $budget->transactionJournals()->withRelevantData()->take($take)->offset($offset) - ->orderBy('transaction_journals.date', 'DESC') - ->orderBy('transaction_journals.order', 'ASC') - ->orderBy('transaction_journals.id', 'DESC'); + ->orderBy('transaction_journals.date', 'DESC') + ->orderBy('transaction_journals.order', 'ASC') + ->orderBy('transaction_journals.id', 'DESC'); $countQuery = $budget->transactionJournals(); @@ -197,9 +196,9 @@ class BudgetRepository extends ComponentRepository implements BudgetRepositoryIn public function getLimitAmountOnDate(Budget $budget, Carbon $date) { $repetition = LimitRepetition::leftJoin('budget_limits', 'limit_repetitions.budget_limit_id', '=', 'budget_limits.id') - ->where('limit_repetitions.startdate', $date->format('Y-m-d 00:00:00')) - ->where('budget_limits.budget_id', $budget->id) - ->first(['limit_repetitions.*']); + ->where('limit_repetitions.startdate', $date->format('Y-m-d 00:00:00')) + ->where('budget_limits.budget_id', $budget->id) + ->first(['limit_repetitions.*']); if ($repetition) { return floatval($repetition->amount); @@ -217,15 +216,15 @@ class BudgetRepository extends ComponentRepository implements BudgetRepositoryIn public function getWithoutBudget(Carbon $start, Carbon $end) { return Auth::user() - ->transactionjournals() - ->leftJoin('budget_transaction_journal', 'budget_transaction_journal.transaction_journal_id', '=', 'transaction_journals.id') - ->whereNull('budget_transaction_journal.id') - ->before($end) - ->after($start) - ->orderBy('transaction_journals.date', 'DESC') - ->orderBy('transaction_journals.order', 'ASC') - ->orderBy('transaction_journals.id', 'DESC') - ->get(['transaction_journals.*']); + ->transactionjournals() + ->leftJoin('budget_transaction_journal', 'budget_transaction_journal.transaction_journal_id', '=', 'transaction_journals.id') + ->whereNull('budget_transaction_journal.id') + ->before($end) + ->after($start) + ->orderBy('transaction_journals.date', 'DESC') + ->orderBy('transaction_journals.order', 'ASC') + ->orderBy('transaction_journals.id', 'DESC') + ->get(['transaction_journals.*']); } /** @@ -237,22 +236,22 @@ class BudgetRepository extends ComponentRepository implements BudgetRepositoryIn public function getWithoutBudgetSum(Carbon $start, Carbon $end) { $noBudgetSet = Auth::user() - ->transactionjournals() - ->whereNotIn( - 'transaction_journals.id', function (QueryBuilder $query) use ($start, $end) { - $query - ->select('transaction_journals.id') - ->from('transaction_journals') - ->leftJoin('budget_transaction_journal', 'budget_transaction_journal.transaction_journal_id', '=', 'transaction_journals.id') - ->where('transaction_journals.date', '>=', $start->format('Y-m-d 00:00:00')) - ->where('transaction_journals.date', '<=', $end->format('Y-m-d 00:00:00')) - ->whereNotNull('budget_transaction_journal.budget_id'); - } - ) - ->after($start) - ->before($end) - ->transactionTypes(['Withdrawal']) - ->get(['transaction_journals.*'])->sum('amount'); + ->transactionjournals() + ->whereNotIn( + 'transaction_journals.id', function (QueryBuilder $query) use ($start, $end) { + $query + ->select('transaction_journals.id') + ->from('transaction_journals') + ->leftJoin('budget_transaction_journal', 'budget_transaction_journal.transaction_journal_id', '=', 'transaction_journals.id') + ->where('transaction_journals.date', '>=', $start->format('Y-m-d 00:00:00')) + ->where('transaction_journals.date', '<=', $end->format('Y-m-d 00:00:00')) + ->whereNotNull('budget_transaction_journal.budget_id'); + } + ) + ->after($start) + ->before($end) + ->transactionTypes(['Withdrawal']) + ->get(['transaction_journals.*'])->sum('amount'); return floatval($noBudgetSet) * -1; } diff --git a/app/Repositories/Category/CategoryRepository.php b/app/Repositories/Category/CategoryRepository.php index c401bca5e3..30006ee96c 100644 --- a/app/Repositories/Category/CategoryRepository.php +++ b/app/Repositories/Category/CategoryRepository.php @@ -49,7 +49,7 @@ class CategoryRepository extends ComponentRepository implements CategoryReposito /** @var Collection $set */ $set = Auth::user()->categories()->orderBy('name', 'ASC')->get(); $set->sortBy( - function (Category $category) { + function(Category $category) { return $category->name; } ); @@ -67,15 +67,15 @@ class CategoryRepository extends ComponentRepository implements CategoryReposito public function getCategoriesAndExpensesCorrected($start, $end) { $set = Auth::user()->transactionjournals() - ->leftJoin( - 'category_transaction_journal', 'category_transaction_journal.transaction_journal_id', '=', 'transaction_journals.id' - ) - ->leftJoin('categories', 'categories.id', '=', 'category_transaction_journal.category_id') - ->before($end) - ->where('categories.user_id', Auth::user()->id) - ->after($start) - ->transactionTypes(['Withdrawal']) - ->get(['categories.id as category_id', 'categories.encrypted as category_encrypted', 'categories.name', 'transaction_journals.*']); + ->leftJoin( + 'category_transaction_journal', 'category_transaction_journal.transaction_journal_id', '=', 'transaction_journals.id' + ) + ->leftJoin('categories', 'categories.id', '=', 'category_transaction_journal.category_id') + ->before($end) + ->where('categories.user_id', Auth::user()->id) + ->after($start) + ->transactionTypes(['Withdrawal']) + ->get(['categories.id as category_id', 'categories.encrypted as category_encrypted', 'categories.name', 'transaction_journals.*']); $result = []; foreach ($set as $entry) { @@ -143,10 +143,10 @@ class CategoryRepository extends ComponentRepository implements CategoryReposito public function getLatestActivity(Category $category) { $latest = $category->transactionjournals() - ->orderBy('transaction_journals.date', 'DESC') - ->orderBy('transaction_journals.order', 'ASC') - ->orderBy('transaction_journals.id', 'DESC') - ->first(); + ->orderBy('transaction_journals.date', 'DESC') + ->orderBy('transaction_journals.order', 'ASC') + ->orderBy('transaction_journals.id', 'DESC') + ->first(); if ($latest) { return $latest->date; } @@ -163,15 +163,15 @@ class CategoryRepository extends ComponentRepository implements CategoryReposito public function getWithoutCategory(Carbon $start, Carbon $end) { return Auth::user() - ->transactionjournals() - ->leftJoin('category_transaction_journal', 'category_transaction_journal.transaction_journal_id', '=', 'transaction_journals.id') - ->whereNull('category_transaction_journal.id') - ->before($end) - ->after($start) - ->orderBy('transaction_journals.date', 'DESC') - ->orderBy('transaction_journals.order', 'ASC') - ->orderBy('transaction_journals.id', 'DESC') - ->get(['transaction_journals.*']); + ->transactionjournals() + ->leftJoin('category_transaction_journal', 'category_transaction_journal.transaction_journal_id', '=', 'transaction_journals.id') + ->whereNull('category_transaction_journal.id') + ->before($end) + ->after($start) + ->orderBy('transaction_journals.date', 'DESC') + ->orderBy('transaction_journals.order', 'ASC') + ->orderBy('transaction_journals.id', 'DESC') + ->get(['transaction_journals.*']); } /** diff --git a/app/Repositories/Journal/JournalRepository.php b/app/Repositories/Journal/JournalRepository.php index 965ad63b43..a7fb12f50a 100644 --- a/app/Repositories/Journal/JournalRepository.php +++ b/app/Repositories/Journal/JournalRepository.php @@ -111,7 +111,7 @@ class JournalRepository implements JournalRepositoryInterface */ public function getJournalsOfTypes(array $types, $offset, $page) { - $set = Auth::user()->transactionJournals()->transactionTypes($types)->withRelevantData()->take(50)->offset($offset) + $set = Auth::user()->transactionJournals()->transactionTypes($types)->withRelevantData()->take(50)->offset($offset) ->orderBy('date', 'DESC') ->orderBy('order', 'ASC') ->orderBy('id', 'DESC') diff --git a/app/Repositories/PiggyBank/PiggyBankRepository.php b/app/Repositories/PiggyBank/PiggyBankRepository.php index 78c8d80b2d..3db4693284 100644 --- a/app/Repositories/PiggyBank/PiggyBankRepository.php +++ b/app/Repositories/PiggyBank/PiggyBankRepository.php @@ -102,7 +102,7 @@ class PiggyBankRepository implements PiggyBankRepositoryInterface public function setOrder($id, $order) { $piggyBank = PiggyBank::leftJoin('accounts', 'accounts.id', '=', 'piggy_banks.account_id')->where('accounts.user_id', Auth::user()->id) - ->where('piggy_banks.id', $id)->first(['piggy_banks.*']); + ->where('piggy_banks.id', $id)->first(['piggy_banks.*']); if ($piggyBank) { $piggyBank->order = $order; $piggyBank->save(); diff --git a/app/Repositories/Reminder/ReminderRepository.php b/app/Repositories/Reminder/ReminderRepository.php index 8db6d0ada0..ae04c59c66 100644 --- a/app/Repositories/Reminder/ReminderRepository.php +++ b/app/Repositories/Reminder/ReminderRepository.php @@ -36,14 +36,14 @@ class ReminderRepository implements ReminderRepositoryInterface $today = new Carbon; // active reminders: $active = Auth::user()->reminders() - ->where('notnow', 0) - ->where('active', 1) - ->where('startdate', '<=', $today->format('Y-m-d 00:00:00')) - ->where('enddate', '>=', $today->format('Y-m-d 00:00:00')) - ->get(); + ->where('notnow', 0) + ->where('active', 1) + ->where('startdate', '<=', $today->format('Y-m-d 00:00:00')) + ->where('enddate', '>=', $today->format('Y-m-d 00:00:00')) + ->get(); $active->each( - function (Reminder $reminder) { + function(Reminder $reminder) { $reminder->description = $this->helper->getReminderText($reminder); } ); @@ -58,11 +58,11 @@ class ReminderRepository implements ReminderRepositoryInterface public function getDismissedReminders() { $dismissed = Auth::user()->reminders() - ->where('notnow', 1) - ->get(); + ->where('notnow', 1) + ->get(); $dismissed->each( - function (Reminder $reminder) { + function(Reminder $reminder) { $reminder->description = $this->helper->getReminderText($reminder); } ); @@ -77,18 +77,18 @@ class ReminderRepository implements ReminderRepositoryInterface { $expired = Auth::user()->reminders() - ->where('notnow', 0) - ->where('active', 1) - ->where( - function (Builder $q) { - $today = new Carbon; - $q->where('startdate', '>', $today->format('Y-m-d 00:00:00')); - $q->orWhere('enddate', '<', $today->format('Y-m-d 00:00:00')); - } - )->get(); + ->where('notnow', 0) + ->where('active', 1) + ->where( + function (Builder $q) { + $today = new Carbon; + $q->where('startdate', '>', $today->format('Y-m-d 00:00:00')); + $q->orWhere('enddate', '<', $today->format('Y-m-d 00:00:00')); + } + )->get(); $expired->each( - function (Reminder $reminder) { + function(Reminder $reminder) { $reminder->description = $this->helper->getReminderText($reminder); } ); @@ -106,7 +106,7 @@ class ReminderRepository implements ReminderRepositoryInterface ->get(); $inactive->each( - function (Reminder $reminder) { + function(Reminder $reminder) { $reminder->description = $this->helper->getReminderText($reminder); } ); diff --git a/app/Repositories/Shared/ComponentRepository.php b/app/Repositories/Shared/ComponentRepository.php index db0d5054a0..3eb8434a37 100644 --- a/app/Repositories/Shared/ComponentRepository.php +++ b/app/Repositories/Shared/ComponentRepository.php @@ -30,25 +30,25 @@ class ComponentRepository // always ignore transfers between accounts! $sum = $object->transactionjournals() - ->transactionTypes(['Withdrawal']) - ->before($end)->after($start)->get(['transaction_journals.*'])->sum('amount'); + ->transactionTypes(['Withdrawal']) + ->before($end)->after($start)->get(['transaction_journals.*'])->sum('amount'); } else { // do something else, SEE budgets. // get all journals in this month where the asset account is NOT shared. $sum = $object->transactionjournals() - ->before($end) - ->after($start) - ->transactionTypes(['Withdrawal']) - ->leftJoin('transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id') - ->leftJoin('accounts', 'accounts.id', '=', 'transactions.account_id') - ->leftJoin( - 'account_meta', function (JoinClause $join) { - $join->on('account_meta.account_id', '=', 'accounts.id')->where('account_meta.name', '=', 'accountRole'); - } - ) - ->where('account_meta.data', '!=', '"sharedAsset"') - ->get(['transaction_journals.*'])->sum('amount'); + ->before($end) + ->after($start) + ->transactionTypes(['Withdrawal']) + ->leftJoin('transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id') + ->leftJoin('accounts', 'accounts.id', '=', 'transactions.account_id') + ->leftJoin( + 'account_meta', function (JoinClause $join) { + $join->on('account_meta.account_id', '=', 'accounts.id')->where('account_meta.name', '=', 'accountRole'); + } + ) + ->where('account_meta.data', '!=', '"sharedAsset"') + ->get(['transaction_journals.*'])->sum('amount'); } return $sum; diff --git a/app/Repositories/Tag/TagRepository.php b/app/Repositories/Tag/TagRepository.php index 26971e9ed1..5f02c0ce5a 100644 --- a/app/Repositories/Tag/TagRepository.php +++ b/app/Repositories/Tag/TagRepository.php @@ -110,7 +110,7 @@ class TagRepository implements TagRepositoryInterface /** @var Collection $tags */ $tags = Auth::user()->tags()->get(); $tags->sortBy( - function (Tag $tag) { + function(Tag $tag) { return $tag->tag; } ); diff --git a/app/Services/Registrar.php b/app/Services/Registrar.php index 5f69c7ba24..6f9ffa729a 100644 --- a/app/Services/Registrar.php +++ b/app/Services/Registrar.php @@ -41,9 +41,9 @@ class Registrar implements RegistrarContract { return Validator::make( $data, [ - 'email' => 'required|email|max:255|unique:users', - 'password' => 'required|confirmed|min:6', - ] + 'email' => 'required|email|max:255|unique:users', + 'password' => 'required|confirmed|min:6', + ] ); } diff --git a/app/Support/CacheProperties.php b/app/Support/CacheProperties.php index 9c3cffd501..9bcc2c808b 100644 --- a/app/Support/CacheProperties.php +++ b/app/Support/CacheProperties.php @@ -94,7 +94,7 @@ class CacheProperties if (is_array($property)) { $this->md5 .= print_r($property, true); } - $this->md5 .= (string)$property; + $this->md5 .= (string) $property; } $this->md5 = md5($this->md5); diff --git a/app/Support/Navigation.php b/app/Support/Navigation.php index 542cd669f3..f2dd884673 100644 --- a/app/Support/Navigation.php +++ b/app/Support/Navigation.php @@ -118,7 +118,7 @@ class Navigation 'year' => 'endOfYear', 'yearly' => 'endOfYear', ]; - $specials = ['mont', 'monthly']; + $specials = ['mont', 'monthly']; $currentEnd = clone $theCurrentEnd; @@ -270,7 +270,7 @@ class Navigation '3M' => 'lastOfQuarter', '1Y' => 'endOfYear', ]; - $end = clone $start; + $end = clone $start; if (isset($functionMap[$range])) { $function = $functionMap[$range]; diff --git a/app/Support/Preferences.php b/app/Support/Preferences.php index 72eaebee6f..0fd7d8a184 100644 --- a/app/Support/Preferences.php +++ b/app/Support/Preferences.php @@ -24,8 +24,8 @@ class Preferences } /** - * @param $name - * @param null $default + * @param string $name + * @param string $default * * @return null|\FireflyIII\Models\Preference */ @@ -56,7 +56,7 @@ class Preferences /** * @param $name - * @param $value + * @param string $value * * @return Preference */ diff --git a/app/Support/Search/Search.php b/app/Support/Search/Search.php index a493ad0741..7b1e0f42b5 100644 --- a/app/Support/Search/Search.php +++ b/app/Support/Search/Search.php @@ -25,7 +25,7 @@ class Search implements SearchInterface public function searchAccounts(array $words) { return Auth::user()->accounts()->with('accounttype')->where( - function (EloquentBuilder $q) use ($words) { + function(EloquentBuilder $q) use ($words) { foreach ($words as $word) { $q->orWhere('name', 'LIKE', '%' . e($word) . '%'); } @@ -43,7 +43,7 @@ class Search implements SearchInterface /** @var Collection $set */ $set = Auth::user()->budgets()->get(); $newSet = $set->filter( - function (Budget $b) use ($words) { + function(Budget $b) use ($words) { $found = 0; foreach ($words as $word) { if (!(strpos(strtolower($b->name), strtolower($word)) === false)) { @@ -68,7 +68,7 @@ class Search implements SearchInterface /** @var Collection $set */ $set = Auth::user()->categories()->get(); $newSet = $set->filter( - function (Category $c) use ($words) { + function(Category $c) use ($words) { $found = 0; foreach ($words as $word) { if (!(strpos(strtolower($c->name), strtolower($word)) === false)) { @@ -103,7 +103,7 @@ class Search implements SearchInterface { // decrypted transaction journals: $decrypted = Auth::user()->transactionjournals()->withRelevantData()->where('encrypted', 0)->where( - function (EloquentBuilder $q) use ($words) { + function(EloquentBuilder $q) use ($words) { foreach ($words as $word) { $q->orWhere('description', 'LIKE', '%' . e($word) . '%'); } @@ -113,7 +113,7 @@ class Search implements SearchInterface // encrypted $all = Auth::user()->transactionjournals()->withRelevantData()->where('encrypted', 1)->get(); $set = $all->filter( - function (TransactionJournal $journal) use ($words) { + function(TransactionJournal $journal) use ($words) { foreach ($words as $word) { $haystack = strtolower($journal->description); $word = strtolower($word); @@ -129,7 +129,7 @@ class Search implements SearchInterface $filtered = $set->merge($decrypted); $filtered->sortBy( - function (TransactionJournal $journal) { + function(TransactionJournal $journal) { return intval($journal->date->format('U')); } ); diff --git a/app/Support/Twig/Budget.php b/app/Support/Twig/Budget.php index f1ce2ff4da..e9dd063e8d 100644 --- a/app/Support/Twig/Budget.php +++ b/app/Support/Twig/Budget.php @@ -21,16 +21,16 @@ class Budget extends Twig_Extension { $functions = []; $functions[] = new Twig_SimpleFunction( - 'spentInRepetitionCorrected', function (LimitRepetition $repetition) { + 'spentInRepetitionCorrected', function(LimitRepetition $repetition) { $sum = Auth::user()->transactionjournals() - ->leftJoin('budget_transaction_journal', 'budget_transaction_journal.transaction_journal_id', '=', 'transaction_journals.id') - ->leftJoin('budget_limits', 'budget_limits.budget_id', '=', 'budget_transaction_journal.budget_id') - ->leftJoin('limit_repetitions', 'limit_repetitions.budget_limit_id', '=', 'budget_limits.id') - ->before($repetition->enddate) - ->after($repetition->startdate) - ->where('limit_repetitions.id', '=', $repetition->id) - ->get(['transaction_journals.*'])->sum('amount'); + ->leftJoin('budget_transaction_journal', 'budget_transaction_journal.transaction_journal_id', '=', 'transaction_journals.id') + ->leftJoin('budget_limits', 'budget_limits.budget_id', '=', 'budget_transaction_journal.budget_id') + ->leftJoin('limit_repetitions', 'limit_repetitions.budget_limit_id', '=', 'budget_limits.id') + ->before($repetition->enddate) + ->after($repetition->startdate) + ->where('limit_repetitions.id', '=', $repetition->id) + ->get(['transaction_journals.*'])->sum('amount'); return floatval($sum); } diff --git a/app/Support/Twig/General.php b/app/Support/Twig/General.php index c1bcf09e16..81ea504928 100644 --- a/app/Support/Twig/General.php +++ b/app/Support/Twig/General.php @@ -31,31 +31,31 @@ class General extends Twig_Extension $filters = []; $filters[] = new Twig_SimpleFilter( - 'formatAmount', function ($string) { + 'formatAmount', function($string) { return App::make('amount')->format($string); }, ['is_safe' => ['html']] ); $filters[] = new Twig_SimpleFilter( - 'formatTransaction', function (Transaction $transaction) { + 'formatTransaction', function(Transaction $transaction) { return App::make('amount')->formatTransaction($transaction); }, ['is_safe' => ['html']] ); $filters[] = new Twig_SimpleFilter( - 'formatAmountPlain', function ($string) { + 'formatAmountPlain', function($string) { return App::make('amount')->format($string, false); }, ['is_safe' => ['html']] ); $filters[] = new Twig_SimpleFilter( - 'formatJournal', function ($journal) { + 'formatJournal', function($journal) { return App::make('amount')->formatJournal($journal); }, ['is_safe' => ['html']] ); $filters[] = new Twig_SimpleFilter( - 'balance', function (Account $account = null) { + 'balance', function(Account $account = null) { if (is_null($account)) { return 'NULL'; } @@ -67,7 +67,7 @@ class General extends Twig_Extension // should be a function but OK $filters[] = new Twig_SimpleFilter( - 'getAccountRole', function ($name) { + 'getAccountRole', function($name) { return Config::get('firefly.accountRoles.' . $name); } ); @@ -83,32 +83,32 @@ class General extends Twig_Extension $functions = []; $functions[] = new Twig_SimpleFunction( - 'getCurrencyCode', function () { + 'getCurrencyCode', function() { return App::make('amount')->getCurrencyCode(); } ); $functions[] = new Twig_SimpleFunction( - 'getCurrencySymbol', function () { + 'getCurrencySymbol', function() { return App::make('amount')->getCurrencySymbol(); } ); $functions[] = new Twig_SimpleFunction( - 'phpdate', function ($str) { + 'phpdate', function($str) { return date($str); } ); $functions[] = new Twig_SimpleFunction( - 'env', function ($name, $default) { + 'env', function($name, $default) { return env($name, $default); } ); $functions[] = new Twig_SimpleFunction( - 'activeRoute', function ($context) { + 'activeRoute', function($context) { $args = func_get_args(); $route = $args[1]; $what = isset($args[2]) ? $args[2] : false; diff --git a/app/Support/Twig/Journal.php b/app/Support/Twig/Journal.php index 36ef577e7a..f239a9097a 100644 --- a/app/Support/Twig/Journal.php +++ b/app/Support/Twig/Journal.php @@ -27,7 +27,7 @@ class Journal extends Twig_Extension $filters = []; $filters[] = new Twig_SimpleFilter( - 'typeIcon', function (TransactionJournal $journal) { + 'typeIcon', function(TransactionJournal $journal) { $cache = new CacheProperties(); $cache->addProperty($journal->id); @@ -76,7 +76,7 @@ class Journal extends Twig_Extension $functions = []; $functions[] = new Twig_SimpleFunction( - 'invalidJournal', function (TransactionJournal $journal) { + 'invalidJournal', function(TransactionJournal $journal) { if (!isset($journal->transactions[1]) || !isset($journal->transactions[0])) { return true; } @@ -86,7 +86,7 @@ class Journal extends Twig_Extension ); $functions[] = new Twig_SimpleFunction( - 'relevantTags', function (TransactionJournal $journal) { + 'relevantTags', function(TransactionJournal $journal) { if ($journal->tags->count() == 0) { return App::make('amount')->formatJournal($journal); } @@ -99,7 +99,7 @@ class Journal extends Twig_Extension $amount = App::make('amount')->format($journal->actual_amount, false); return ' ' . $tag->tag . ''; + . '"> ' . $tag->tag . ''; } /* @@ -109,7 +109,7 @@ class Journal extends Twig_Extension $amount = App::make('amount')->formatJournal($journal, false); return ' ' . $tag->tag . ''; + . '"> ' . $tag->tag . ''; } /* * AdvancePayment with a withdrawal will show the amount with a link to diff --git a/app/Support/Twig/PiggyBank.php b/app/Support/Twig/PiggyBank.php index 6ff4aafe90..f178aa6316 100644 --- a/app/Support/Twig/PiggyBank.php +++ b/app/Support/Twig/PiggyBank.php @@ -22,7 +22,7 @@ class PiggyBank extends Twig_Extension $functions = []; $functions[] = new Twig_SimpleFunction( - 'currentRelevantRepAmount', function (PB $piggyBank) { + 'currentRelevantRepAmount', function(PB $piggyBank) { return $piggyBank->currentRelevantRep()->currentamount; } ); diff --git a/app/Support/Twig/Translation.php b/app/Support/Twig/Translation.php index 1cb3314cf2..d91c1816e6 100644 --- a/app/Support/Twig/Translation.php +++ b/app/Support/Twig/Translation.php @@ -21,7 +21,7 @@ class Translation extends Twig_Extension $filters = []; $filters[] = new Twig_SimpleFilter( - '_', function ($name) { + '_', function($name) { return trans('firefly.' . $name); From e1aa63487abd3ed03a8720a556e7cc94dac52258 Mon Sep 17 00:00:00 2001 From: James Cole Date: Fri, 5 Jun 2015 12:18:20 +0200 Subject: [PATCH 29/47] Optimized a validator. [skip ci] --- .../Account/AccountRepository.php | 98 ++++++------ app/Validation/FireflyValidator.php | 146 +++++++++++++----- tests/controllers/AccountControllerTest.php | 7 +- tests/repositories/AccountRepositoryTest.php | 15 +- 4 files changed, 173 insertions(+), 93 deletions(-) diff --git a/app/Repositories/Account/AccountRepository.php b/app/Repositories/Account/AccountRepository.php index 7b16735c03..dd413a236e 100644 --- a/app/Repositories/Account/AccountRepository.php +++ b/app/Repositories/Account/AccountRepository.php @@ -65,7 +65,7 @@ class AccountRepository implements AccountRepositoryInterface public function getAccounts(array $types) { $result = Auth::user()->accounts()->with( - ['accountmeta' => function(HasMany $query) { + ['accountmeta' => function (HasMany $query) { $query->where('name', 'accountRole'); }] )->accountTypeIn($types)->orderBy('accounts.name', 'ASC')->get(['accounts.*'])->sortBy('name'); @@ -80,15 +80,15 @@ class AccountRepository implements AccountRepositoryInterface public function getCreditCards() { return Auth::user()->accounts() - ->hasMetaValue('accountRole', 'ccAsset') - ->hasMetaValue('ccType', 'monthlyFull') - ->get( - [ - 'accounts.*', - 'ccType.data as ccType', - 'accountRole.data as accountRole' - ] - ); + ->hasMetaValue('accountRole', 'ccAsset') + ->hasMetaValue('ccType', 'monthlyFull') + ->get( + [ + 'accounts.*', + 'ccType.data as ccType', + 'accountRole.data as accountRole' + ] + ); } /** @@ -151,18 +151,18 @@ class AccountRepository implements AccountRepositoryInterface } $set = Auth::user() - ->transactionjournals() - ->with(['transactions']) - ->leftJoin('transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id') - ->leftJoin('accounts', 'accounts.id', '=', 'transactions.account_id')->where('accounts.id', $account->id) - ->leftJoin('transaction_currencies', 'transaction_currencies.id', '=', 'transaction_journals.transaction_currency_id') - ->leftJoin('transaction_types', 'transaction_types.id', '=', 'transaction_journals.transaction_type_id') - ->before($end) - ->after($start) - ->orderBy('transaction_journals.date', 'DESC') - ->orderBy('transaction_journals.id', 'DESC') - ->take(10) - ->get(['transaction_journals.*', 'transaction_currencies.symbol', 'transaction_types.type']); + ->transactionjournals() + ->with(['transactions']) + ->leftJoin('transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id') + ->leftJoin('accounts', 'accounts.id', '=', 'transactions.account_id')->where('accounts.id', $account->id) + ->leftJoin('transaction_currencies', 'transaction_currencies.id', '=', 'transaction_journals.transaction_currency_id') + ->leftJoin('transaction_types', 'transaction_types.id', '=', 'transaction_journals.transaction_type_id') + ->before($end) + ->after($start) + ->orderBy('transaction_journals.date', 'DESC') + ->orderBy('transaction_journals.id', 'DESC') + ->take(10) + ->get(['transaction_journals.*', 'transaction_currencies.symbol', 'transaction_types.type']); $cache->store($set); return $set; @@ -178,13 +178,13 @@ class AccountRepository implements AccountRepositoryInterface { $offset = ($page - 1) * 50; $query = Auth::user() - ->transactionJournals() - ->withRelevantData() - ->leftJoin('transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id') - ->where('transactions.account_id', $account->id) - ->orderBy('transaction_journals.date', 'DESC') - ->orderBy('transaction_journals.order', 'ASC') - ->orderBy('transaction_journals.id', 'DESC'); + ->transactionJournals() + ->withRelevantData() + ->leftJoin('transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id') + ->where('transactions.account_id', $account->id) + ->orderBy('transaction_journals.date', 'DESC') + ->orderBy('transaction_journals.order', 'ASC') + ->orderBy('transaction_journals.id', 'DESC'); $count = $query->count(); $set = $query->take(50)->offset($offset)->get(['transaction_journals.*']); @@ -242,7 +242,7 @@ class AccountRepository implements AccountRepositoryInterface } $accounts->each( - function(Account $account) use ($start, $end) { + function (Account $account) use ($start, $end) { $account->startBalance = Steam::balance($account, $start, true); $account->endBalance = Steam::balance($account, $end, true); $account->piggyBalance = 0; @@ -282,7 +282,7 @@ class AccountRepository implements AccountRepositoryInterface $end = clone Session::get('end', new Carbon); $accounts->each( - function(Account $account) use ($start, $end) { + function (Account $account) use ($start, $end) { $account->startBalance = Steam::balance($account, $start); $account->endBalance = Steam::balance($account, $end); @@ -320,22 +320,22 @@ class AccountRepository implements AccountRepositoryInterface */ public function getTransfersInRange(Account $account, Carbon $start, Carbon $end) { - $set = TransactionJournal::whereIn( - 'id', function(Builder $q) use ($account, $start, $end) { + $set = TransactionJournal::whereIn( + 'id', function (Builder $q) use ($account, $start, $end) { $q->select('transaction_journals.id') - ->from('transactions') - ->leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id') - ->leftJoin('transaction_types', 'transaction_types.id', '=', 'transaction_journals.transaction_type_id') - ->where('transactions.account_id', $account->id) - ->where('transaction_journals.user_id', Auth::user()->id) - ->where('transaction_journals.date', '>=', $start->format('Y-m-d')) - ->where('transaction_journals.date', '<=', $end->format('Y-m-d')) - ->where('transaction_types.type', 'Transfer'); + ->from('transactions') + ->leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id') + ->leftJoin('transaction_types', 'transaction_types.id', '=', 'transaction_journals.transaction_type_id') + ->where('transactions.account_id', $account->id) + ->where('transaction_journals.user_id', Auth::user()->id) + ->where('transaction_journals.date', '>=', $start->format('Y-m-d')) + ->where('transaction_journals.date', '<=', $end->format('Y-m-d')) + ->where('transaction_types.type', 'Transfer'); } )->get(); $filtered = $set->filter( - function(TransactionJournal $journal) use ($account) { + function (TransactionJournal $journal) use ($account) { if ($journal->destination_account->id == $account->id) { return $journal; } @@ -374,10 +374,10 @@ class AccountRepository implements AccountRepositoryInterface public function openingBalanceTransaction(Account $account) { return TransactionJournal - ::orderBy('transaction_journals.date', 'ASC') - ->accountIs($account) - ->orderBy('created_at', 'ASC') - ->first(['transaction_journals.*']); + ::orderBy('transaction_journals.date', 'ASC') + ->accountIs($account) + ->orderBy('created_at', 'ASC') + ->first(['transaction_journals.*']); } /** @@ -401,7 +401,7 @@ class AccountRepository implements AccountRepositoryInterface 'name' => $data['name'] . ' initial balance', 'active' => false, ]; - $opposing = $this->storeAccount($opposingData); + $opposing = $this->storeAccount($opposingData); $this->storeInitialBalance($newAccount, $opposing, $data); } @@ -452,7 +452,7 @@ class AccountRepository implements AccountRepositoryInterface 'active' => false, 'virtualBalance' => 0, ]; - $opposing = $this->storeAccount($opposingData); + $opposing = $this->storeAccount($opposingData); $this->storeInitialBalance($account, $opposing, $data); } @@ -486,7 +486,7 @@ class AccountRepository implements AccountRepositoryInterface if (!$newAccount->isValid()) { // does the account already exist? - $searchData = [ + $searchData = [ 'user_id' => $data['user'], 'account_type_id' => $accountType->id, 'virtual_balance' => $data['virtualBalance'], diff --git a/app/Validation/FireflyValidator.php b/app/Validation/FireflyValidator.php index 59de869bd8..b1d1e18af3 100644 --- a/app/Validation/FireflyValidator.php +++ b/app/Validation/FireflyValidator.php @@ -9,9 +9,8 @@ use Crypt; use DB; use FireflyIII\Models\Account; use FireflyIII\Models\AccountType; -use Illuminate\Contracts\Encryption\DecryptException; +use FireflyIII\User; use Illuminate\Validation\Validator; -use Log; use Navigation; use Symfony\Component\Translation\TranslatorInterface; @@ -93,54 +92,129 @@ class FireflyValidator extends Validator */ public function validateUniqueAccountForUser($attribute, $value, $parameters) { - $type = null; - - /** - * Switch on different cases on which this method can respond: - */ - $hasWhat = isset($this->data['what']); - $hasAccountTypeId = isset($this->data['account_type_id']) && isset($this->data['name']); - $hasAccountId = isset($this->data['id']); - $ignoreId = 0; - - - if ($hasWhat) { - $search = Config::get('firefly.accountTypeByIdentifier.' . $this->data['what']); - $type = AccountType::whereType($search)->first(); - // this field can be used to find the exact type, and continue. + // because a user does not have to be logged in (tests and what-not). + if (!Auth::check()) { + return $this->validateAccountAnonymously(); } - if ($hasAccountTypeId) { + if (isset($this->data['what'])) { + return $this->validateByAccountTypeString($value, $parameters); + } + + if (isset($this->data['account_type_id'])) { + return $this->validateByAccountTypeId($value, $parameters); + } + + + var_dump($attribute); + var_dump($value); + var_dump($parameters); + var_dump($this->data); + + exit; + + + // try to determin type of account: + if (!empty($this->data['what'])) { + $search = Config::get('firefly.accountTypeByIdentifier.' . $this->data['what']); + $type = AccountType::whereType($search)->first(); + } else { $type = AccountType::find($this->data['account_type_id']); } - if ($hasAccountId) { - /** @var Account $account */ - $account = Account::find($this->data['id']); - $ignoreId = intval($this->data['id']); - $type = AccountType::find($account->account_type_id); - unset($account); + // ignore itself, if parameter is given: + if (isset($parameters[0])) { + $ignoreId = $parameters[0]; + } else { + $ignoreId = 0; } - /** - * Try to decrypt data just in case: - */ - try { - $value = Crypt::decrypt($value); - } catch (DecryptException $e) { - // if it fails, probably not encrypted. + // reset to basic check, see what happens: + $userId = Auth::user()->id; + $ignoreId = intval($this->data['id']); + + $set = Account::where('account_type_id', $type->id)->where('id', '!=', $ignoreId)->where('user_id', $userId)->get(); + /** @var Account $entry */ + foreach ($set as $entry) { + if ($entry->name == $value) { + return false; + } } + return true; - if (is_null($type)) { - Log::error('Could not determine type of account to validate.'); + } + /** + * @return bool + */ + protected function validateAccountAnonymously() + { + if (!isset($this->data['user_id'])) { return false; } - // get all accounts with this type, and find the name. - $userId = Auth::check() ? Auth::user()->id : 0; - $set = Account::where('account_type_id', $type->id)->where('id', '!=', $ignoreId)->where('user_id', $userId)->get(); + $user = User::find($this->data['user_id']); + $type = AccountType::find($this->data['account_type_id'])->first(); + $value = $this->data['name']; + + // decrypt if necessary + if (intval($this->data['encrypted']) === 1) { + $value = Crypt::decrypt($this->data['name']); + } + + + $set = $user->accounts()->where('account_type_id', $type->id)->get(); + /** @var Account $entry */ + foreach ($set as $entry) { + if ($entry->name == $value) { + return false; + } + } + + return true; + } + + /** + * @param $value + * @param $parameters + * + * @return bool + */ + protected function validateByAccountTypeString($value, $parameters) + { + $search = Config::get('firefly.accountTypeByIdentifier.' . $this->data['what']); + $type = AccountType::whereType($search)->first(); + $ignore = isset($parameters[0]) ? intval($parameters[0]) : 0; + + $set = Auth::user()->accounts()->where('account_type_id', $type->id)->where('id', '!=', $ignore)->get(); + /** @var Account $entry */ + foreach ($set as $entry) { + if ($entry->name == $value) { + return false; + } + } + + return true; + } + + /** + * @param $value + * @param $parameters + * + * @return bool + */ + protected function validateByAccountTypeId($value, $parameters) + { + $type = AccountType::find($this->data['account_type_id'])->first(); + $ignore = isset($parameters[0]) ? intval($parameters[0]) : 0; + + // if is encrypted, decrypt: + if (intval($this->data['encrypted']) === 1) { + $value = Crypt::decrypt($value); + } + + $set = Auth::user()->accounts()->where('account_type_id', $type->id)->where('id', '!=', $ignore)->get(); /** @var Account $entry */ foreach ($set as $entry) { if ($entry->name == $value) { diff --git a/tests/controllers/AccountControllerTest.php b/tests/controllers/AccountControllerTest.php index d1b548e774..86d5be5128 100644 --- a/tests/controllers/AccountControllerTest.php +++ b/tests/controllers/AccountControllerTest.php @@ -21,6 +21,7 @@ class AccountControllerTest extends TestCase public function setUp() { parent::setUp(); + $this->createAccount(); } @@ -49,8 +50,12 @@ class AccountControllerTest extends TestCase */ public function createAccount() { + $user = FactoryMuffin::create('FireflyIII\User'); + $this->be($user); if (is_null($this->account)) { - $this->account = FactoryMuffin::create('FireflyIII\Models\Account'); + $this->account = FactoryMuffin::create('FireflyIII\Models\Account'); + $this->account->user_id = $user->id; + $this->account->save(); } } diff --git a/tests/repositories/AccountRepositoryTest.php b/tests/repositories/AccountRepositoryTest.php index c2bbaf16cf..876a5c4286 100644 --- a/tests/repositories/AccountRepositoryTest.php +++ b/tests/repositories/AccountRepositoryTest.php @@ -603,6 +603,8 @@ class AccountRepositoryTest extends TestCase } /** + * This function should give a big fat error, but it doesnt. + * * @covers FireflyIII\Repositories\Account\AccountRepository::store * @covers FireflyIII\Repositories\Account\AccountRepository::storeAccount * @covers FireflyIII\Repositories\Account\AccountRepository::storeMetadata @@ -610,12 +612,12 @@ class AccountRepositoryTest extends TestCase */ public function testStoreWithExistingAccount() { - $account = FactoryMuffin::create('FireflyIII\Models\Account'); - FactoryMuffin::create('FireflyIII\Models\AccountType'); - FactoryMuffin::create('FireflyIII\Models\AccountType'); - FactoryMuffin::create('FireflyIII\Models\TransactionType'); - FactoryMuffin::create('FireflyIII\Models\TransactionType'); - FactoryMuffin::create('FireflyIII\Models\TransactionType'); + $account = FactoryMuffin::create('FireflyIII\Models\Account'); // expense + FactoryMuffin::create('FireflyIII\Models\AccountType'); // revenue + FactoryMuffin::create('FireflyIII\Models\AccountType'); // asset + FactoryMuffin::create('FireflyIII\Models\TransactionType'); // withdrawal + FactoryMuffin::create('FireflyIII\Models\TransactionType'); // deposit + FactoryMuffin::create('FireflyIII\Models\TransactionType'); // transfer $currency = FactoryMuffin::create('FireflyIII\Models\TransactionCurrency'); $this->be($account->user); @@ -632,7 +634,6 @@ class AccountRepositoryTest extends TestCase 'openingBalanceDate' => '2015-01-01', ]; - $newAccount = $this->object->store($data); $this->assertEquals($account->name, $newAccount->name); From 8d8308e557f5753f5b7019f8b202047b5f875e4e Mon Sep 17 00:00:00 2001 From: James Cole Date: Fri, 5 Jun 2015 12:34:45 +0200 Subject: [PATCH 30/47] Cleanup another validator [skip ci] --- app/Http/Requests/BillFormRequest.php | 4 +- app/Http/Requests/BudgetFormRequest.php | 4 +- app/Http/Requests/CategoryFormRequest.php | 4 +- app/Http/Requests/TagFormRequest.php | 4 +- app/Models/Bill.php | 2 + app/Models/Tag.php | 2 +- app/Validation/FireflyValidator.php | 87 ++++++----------------- 7 files changed, 33 insertions(+), 74 deletions(-) diff --git a/app/Http/Requests/BillFormRequest.php b/app/Http/Requests/BillFormRequest.php index 452e5a1e7a..3a360f4874 100644 --- a/app/Http/Requests/BillFormRequest.php +++ b/app/Http/Requests/BillFormRequest.php @@ -48,8 +48,8 @@ class BillFormRequest extends Request */ public function rules() { - $nameRule = 'required|between:1,255|uniqueObjectForUser:bills,name,name_encrypted'; - $matchRule = 'required|between:1,255|uniqueObjectForUser:bills,match,match_encrypted'; + $nameRule = 'required|between:1,255|uniqueObjectForUser:bills,name'; + $matchRule = 'required|between:1,255|uniqueObjectForUser:bills,match'; if (intval(Input::get('id')) > 0) { $nameRule .= ',' . intval(Input::get('id')); $matchRule .= ',' . intval(Input::get('id')); diff --git a/app/Http/Requests/BudgetFormRequest.php b/app/Http/Requests/BudgetFormRequest.php index ad871cd07b..38814f1d2d 100644 --- a/app/Http/Requests/BudgetFormRequest.php +++ b/app/Http/Requests/BudgetFormRequest.php @@ -29,9 +29,9 @@ class BudgetFormRequest extends Request public function rules() { - $nameRule = 'required|between:1,100|uniqueObjectForUser:budgets,name,encrypted'; + $nameRule = 'required|between:1,100|uniqueObjectForUser:budgets,name'; if (Budget::find(Input::get('id'))) { - $nameRule = 'required|between:1,100|uniqueObjectForUser:budgets,name,encrypted,' . intval(Input::get('id')); + $nameRule = 'required|between:1,100|uniqueObjectForUser:budgets,' . intval(Input::get('id')); } return [ diff --git a/app/Http/Requests/CategoryFormRequest.php b/app/Http/Requests/CategoryFormRequest.php index 7c32b3329c..04a16ce9b6 100644 --- a/app/Http/Requests/CategoryFormRequest.php +++ b/app/Http/Requests/CategoryFormRequest.php @@ -29,9 +29,9 @@ class CategoryFormRequest extends Request public function rules() { - $nameRule = 'required|between:1,100|uniqueObjectForUser:categories,name,encrypted'; + $nameRule = 'required|between:1,100|uniqueObjectForUser:categories,name'; if (Category::find(Input::get('id'))) { - $nameRule = 'required|between:1,100|uniqueObjectForUser:categories,name,encrypted,' . intval(Input::get('id')); + $nameRule = 'required|between:1,100|uniqueObjectForUser:categories,name,' . intval(Input::get('id')); } return [ diff --git a/app/Http/Requests/TagFormRequest.php b/app/Http/Requests/TagFormRequest.php index 1b2885453d..28773c874c 100644 --- a/app/Http/Requests/TagFormRequest.php +++ b/app/Http/Requests/TagFormRequest.php @@ -28,10 +28,10 @@ class TagFormRequest extends Request public function rules() { $idRule = ''; - $tagRule = 'required|min:1|uniqueObjectForUser:tags,tag,TRUE'; + $tagRule = 'required|min:1|uniqueObjectForUser:tags,tag'; if (Tag::find(Input::get('id'))) { $idRule = 'belongsToUser:tags'; - $tagRule = 'required|min:1|uniqueObjectForUser:tags,tag,TRUE,' . Input::get('id'); + $tagRule = 'required|min:1|uniqueObjectForUser:tags,tag,' . Input::get('id'); } return [ diff --git a/app/Models/Bill.php b/app/Models/Bill.php index 6682c7329c..1afaac6090 100644 --- a/app/Models/Bill.php +++ b/app/Models/Bill.php @@ -55,6 +55,8 @@ class Bill extends Model protected $hidden = ['amount_min_encrypted', 'amount_max_encrypted', 'name_encrypted', 'match_encrypted']; + + /** * @return array */ diff --git a/app/Models/Tag.php b/app/Models/Tag.php index 7018ecc8fa..ac566d2b8d 100644 --- a/app/Models/Tag.php +++ b/app/Models/Tag.php @@ -44,7 +44,7 @@ class Tag extends Model protected $fillable = ['user_id', 'tag', 'date', 'description', 'longitude', 'latitude', 'zoomLevel', 'tagMode']; protected $rules = [ - 'tag' => 'required|min:1|uniqueObjectForUser:tags,tag,TRUE', + 'tag' => 'required|min:1|uniqueObjectForUser:tags,tag', 'description' => 'min:1', 'date' => 'date', 'latitude' => 'numeric|min:-90|max:90', diff --git a/app/Validation/FireflyValidator.php b/app/Validation/FireflyValidator.php index b1d1e18af3..b158abd56d 100644 --- a/app/Validation/FireflyValidator.php +++ b/app/Validation/FireflyValidator.php @@ -10,6 +10,7 @@ use DB; use FireflyIII\Models\Account; use FireflyIII\Models\AccountType; use FireflyIII\User; +use Illuminate\Contracts\Encryption\DecryptException; use Illuminate\Validation\Validator; use Navigation; use Symfony\Component\Translation\TranslatorInterface; @@ -105,44 +106,7 @@ class FireflyValidator extends Validator return $this->validateByAccountTypeId($value, $parameters); } - - var_dump($attribute); - var_dump($value); - var_dump($parameters); - var_dump($this->data); - - exit; - - - // try to determin type of account: - if (!empty($this->data['what'])) { - $search = Config::get('firefly.accountTypeByIdentifier.' . $this->data['what']); - $type = AccountType::whereType($search)->first(); - } else { - $type = AccountType::find($this->data['account_type_id']); - } - - // ignore itself, if parameter is given: - if (isset($parameters[0])) { - $ignoreId = $parameters[0]; - } else { - $ignoreId = 0; - } - - // reset to basic check, see what happens: - $userId = Auth::user()->id; - $ignoreId = intval($this->data['id']); - - $set = Account::where('account_type_id', $type->id)->where('id', '!=', $ignoreId)->where('user_id', $userId)->get(); - /** @var Account $entry */ - foreach ($set as $entry) { - if ($entry->name == $value) { - return false; - } - } - - return true; - + return false; } /** @@ -254,8 +218,7 @@ class FireflyValidator extends Validator * * parameter 0: the table * parameter 1: the field - * parameter 2: the encrypted / not encrypted boolean. Defaults to "encrypted". - * parameter 3: an id to ignore (when editing) + * parameter 2: an id to ignore (when editing) * * @param $attribute * @param $value @@ -265,37 +228,31 @@ class FireflyValidator extends Validator */ public function validateUniqueObjectForUser($attribute, $value, $parameters) { - $table = $parameters[0]; - $field = $parameters[1]; - $encrypted = isset($parameters[2]) ? $parameters[2] : 'encrypted'; - $exclude = isset($parameters[3]) ? $parameters[3] : null; - $alwaysEncrypted = false; - if ($encrypted == 'TRUE') { - $alwaysEncrypted = true; + // try to decrypt value. if it fails, not a problem: + try { + $value = Crypt::decrypt($value); + } catch (DecryptException $e) { + // do not care. } - if (is_null(Auth::user())) { - // user is not logged in.. weird. - return true; - } else { - $query = DB::table($table)->where('user_id', Auth::user()->id); - } + // exclude? + $table = $parameters[0]; + $field = $parameters[1]; + $exclude = isset($parameters[3]) ? intval($parameters[3]) : 0; + // get entries from table + $set = DB::table($table)->where('user_id', Auth::user()->id)->where('id', '!=', $exclude)->get([$field]); - if (!is_null($exclude)) { - $query->where('id', '!=', $exclude); - } - - - $set = $query->get(); foreach ($set as $entry) { - if (!$alwaysEncrypted) { - $isEncrypted = intval($entry->$encrypted) == 1 ? true : false; - } else { - $isEncrypted = true; + $fieldValue = $entry->$field; + // try to decrypt: + try { + $fieldValue = Crypt::decrypt($entry->$field); + } catch (DecryptException $e) { + // dont care } - $checkValue = $isEncrypted ? Crypt::decrypt($entry->$field) : $entry->$field; - if ($checkValue == $value) { + + if ($fieldValue === $value) { return false; } } From 62d5a1da877fe2267e252ecfcb329115c769ba0c Mon Sep 17 00:00:00 2001 From: James Cole Date: Fri, 5 Jun 2015 12:48:58 +0200 Subject: [PATCH 31/47] Cleaning up [skip ci] --- app/Validation/FireflyValidator.php | 50 +++++++++++++---------------- 1 file changed, 22 insertions(+), 28 deletions(-) diff --git a/app/Validation/FireflyValidator.php b/app/Validation/FireflyValidator.php index b158abd56d..a680aeb6a2 100644 --- a/app/Validation/FireflyValidator.php +++ b/app/Validation/FireflyValidator.php @@ -120,12 +120,7 @@ class FireflyValidator extends Validator $user = User::find($this->data['user_id']); $type = AccountType::find($this->data['account_type_id'])->first(); - $value = $this->data['name']; - - // decrypt if necessary - if (intval($this->data['encrypted']) === 1) { - $value = Crypt::decrypt($this->data['name']); - } + $value = $this->tryDecrypt($this->data['name']); $set = $user->accounts()->where('account_type_id', $type->id)->get(); @@ -139,6 +134,22 @@ class FireflyValidator extends Validator return true; } + /** + * @param $value + * + * @return mixed + */ + protected function tryDecrypt($value) + { + try { + $value = Crypt::decrypt($value); + } catch (DecryptException $e) { + // do not care. + } + + return $value; + } + /** * @param $value * @param $parameters @@ -172,11 +183,7 @@ class FireflyValidator extends Validator { $type = AccountType::find($this->data['account_type_id'])->first(); $ignore = isset($parameters[0]) ? intval($parameters[0]) : 0; - - // if is encrypted, decrypt: - if (intval($this->data['encrypted']) === 1) { - $value = Crypt::decrypt($value); - } + $value = $this->tryDecrypt($value); $set = Auth::user()->accounts()->where('account_type_id', $type->id)->where('id', '!=', $ignore)->get(); /** @var Account $entry */ @@ -228,13 +235,7 @@ class FireflyValidator extends Validator */ public function validateUniqueObjectForUser($attribute, $value, $parameters) { - // try to decrypt value. if it fails, not a problem: - try { - $value = Crypt::decrypt($value); - } catch (DecryptException $e) { - // do not care. - } - + $value = $this->tryDecrypt($value); // exclude? $table = $parameters[0]; $field = $parameters[1]; @@ -244,13 +245,7 @@ class FireflyValidator extends Validator $set = DB::table($table)->where('user_id', Auth::user()->id)->where('id', '!=', $exclude)->get([$field]); foreach ($set as $entry) { - $fieldValue = $entry->$field; - // try to decrypt: - try { - $fieldValue = Crypt::decrypt($entry->$field); - } catch (DecryptException $e) { - // dont care - } + $fieldValue = $this->tryDecrypt($entry->$field); if ($fieldValue === $value) { return false; @@ -279,9 +274,8 @@ class FireflyValidator extends Validator $set = $query->get(['piggy_banks.*']); foreach ($set as $entry) { - $isEncrypted = intval($entry->encrypted) == 1 ? true : false; - $checkValue = $isEncrypted ? Crypt::decrypt($entry->name) : $entry->name; - if ($checkValue == $value) { + $fieldValue = $this->tryDecrypt($entry->name); + if ($fieldValue == $value) { return false; } } From 834b1afb38e4fd9cdb636dacefcf49a88e166d16 Mon Sep 17 00:00:00 2001 From: James Cole Date: Fri, 5 Jun 2015 13:39:24 +0200 Subject: [PATCH 32/47] Updated some code [skip ci] --- .scrutinizer.yml | 2 +- .travis.yml | 2 +- app/Http/Controllers/HomeController.php | 1 - app/Http/Controllers/NewUserController.php | 2 +- app/Models/Permission.php | 2 +- app/Models/Role.php | 2 +- .../Category/CategoryRepository.php | 1 - .../Shared/ComponentRepository.php | 41 ++++++++++--------- app/Support/CacheProperties.php | 16 ++------ resources/lang/nl/breadcrumbs.php | 8 ++-- resources/lang/nl/firefly.php | 12 +++--- resources/lang/nl/form.php | 8 ++-- resources/lang/nl/list.php | 2 +- 13 files changed, 45 insertions(+), 54 deletions(-) diff --git a/.scrutinizer.yml b/.scrutinizer.yml index 8486eef106..e36d2f3684 100644 --- a/.scrutinizer.yml +++ b/.scrutinizer.yml @@ -2,4 +2,4 @@ tools: external_code_coverage: timeout: 1800 # Timeout in seconds. - runs: 2 \ No newline at end of file + runs: 2 diff --git a/.travis.yml b/.travis.yml index a0ca8e95fe..150aeec78c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -19,4 +19,4 @@ after_script: - CODECLIMATE_REPO_TOKEN=26489f9e854fcdf7e7660ba29c1455694685465b1f90329a79f7d2bf448acb61 ./vendor/bin/test-reporter --stdout > codeclimate.json - "curl -X POST -d @codeclimate.json -H 'Content-Type: application/json' -H 'User-Agent: Code Climate (PHP Test Reporter v0.1.1)' https://codeclimate.com/test_reports" - wget https://scrutinizer-ci.com/ocular.phar - - php ocular.phar code-coverage:upload --format=php-clover build/logs/clover.xml \ No newline at end of file + - php ocular.phar code-coverage:upload --format=php-clover build/logs/clover.xml diff --git a/app/Http/Controllers/HomeController.php b/app/Http/Controllers/HomeController.php index 695a522141..83ab8ffa33 100644 --- a/app/Http/Controllers/HomeController.php +++ b/app/Http/Controllers/HomeController.php @@ -6,7 +6,6 @@ use FireflyIII\Repositories\Account\AccountRepositoryInterface; use Input; use Preferences; use Redirect; -use Route; use Session; use Steam; diff --git a/app/Http/Controllers/NewUserController.php b/app/Http/Controllers/NewUserController.php index 1508a2448f..684a232a23 100644 --- a/app/Http/Controllers/NewUserController.php +++ b/app/Http/Controllers/NewUserController.php @@ -108,4 +108,4 @@ class NewUserController extends Controller return Redirect::route('index'); } -} \ No newline at end of file +} diff --git a/app/Models/Permission.php b/app/Models/Permission.php index e3c5943928..7b660eb32e 100644 --- a/app/Models/Permission.php +++ b/app/Models/Permission.php @@ -24,4 +24,4 @@ use Zizaco\Entrust\EntrustPermission; */ class Permission extends EntrustPermission { -} \ No newline at end of file +} diff --git a/app/Models/Role.php b/app/Models/Role.php index 543c0580fb..6476a4ee39 100644 --- a/app/Models/Role.php +++ b/app/Models/Role.php @@ -25,4 +25,4 @@ use Zizaco\Entrust\EntrustRole; */ class Role extends EntrustRole { -} \ No newline at end of file +} diff --git a/app/Repositories/Category/CategoryRepository.php b/app/Repositories/Category/CategoryRepository.php index 30006ee96c..235663d83b 100644 --- a/app/Repositories/Category/CategoryRepository.php +++ b/app/Repositories/Category/CategoryRepository.php @@ -7,7 +7,6 @@ use Carbon\Carbon; use Crypt; use FireflyIII\Models\Category; use FireflyIII\Models\TransactionJournal; -use Illuminate\Database\Query\JoinClause; use Illuminate\Support\Collection; use FireflyIII\Repositories\Shared\ComponentRepository; /** diff --git a/app/Repositories/Shared/ComponentRepository.php b/app/Repositories/Shared/ComponentRepository.php index 3eb8434a37..d7b57bbfc5 100644 --- a/app/Repositories/Shared/ComponentRepository.php +++ b/app/Repositories/Shared/ComponentRepository.php @@ -4,6 +4,7 @@ namespace FireflyIII\Repositories\Shared; use Carbon\Carbon; use Illuminate\Database\Query\JoinClause; +use stdClass; /** * Class ComponentRepository @@ -15,42 +16,42 @@ class ComponentRepository /** - * @param $object - * @param Carbon $start - * @param Carbon $end + * @param stdClass $object + * @param Carbon $start + * @param Carbon $end * - * @param bool $shared + * @param bool $shared * * @return string */ - protected function spentInPeriod($object, Carbon $start, Carbon $end, $shared = false) + protected function spentInPeriod(stdClass $object, Carbon $start, Carbon $end, $shared = false) { if ($shared === true) { // shared is true. // always ignore transfers between accounts! $sum = $object->transactionjournals() - ->transactionTypes(['Withdrawal']) - ->before($end)->after($start)->get(['transaction_journals.*'])->sum('amount'); + ->transactionTypes(['Withdrawal']) + ->before($end)->after($start)->get(['transaction_journals.*'])->sum('amount'); } else { // do something else, SEE budgets. // get all journals in this month where the asset account is NOT shared. $sum = $object->transactionjournals() - ->before($end) - ->after($start) - ->transactionTypes(['Withdrawal']) - ->leftJoin('transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id') - ->leftJoin('accounts', 'accounts.id', '=', 'transactions.account_id') - ->leftJoin( - 'account_meta', function (JoinClause $join) { - $join->on('account_meta.account_id', '=', 'accounts.id')->where('account_meta.name', '=', 'accountRole'); - } - ) - ->where('account_meta.data', '!=', '"sharedAsset"') - ->get(['transaction_journals.*'])->sum('amount'); + ->before($end) + ->after($start) + ->transactionTypes(['Withdrawal']) + ->leftJoin('transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id') + ->leftJoin('accounts', 'accounts.id', '=', 'transactions.account_id') + ->leftJoin( + 'account_meta', function (JoinClause $join) { + $join->on('account_meta.account_id', '=', 'accounts.id')->where('account_meta.name', '=', 'accountRole'); + } + ) + ->where('account_meta.data', '!=', '"sharedAsset"') + ->get(['transaction_journals.*'])->sum('amount'); } return $sum; } -} \ No newline at end of file +} diff --git a/app/Support/CacheProperties.php b/app/Support/CacheProperties.php index 9bcc2c808b..f210309c59 100644 --- a/app/Support/CacheProperties.php +++ b/app/Support/CacheProperties.php @@ -75,26 +75,18 @@ class CacheProperties foreach ($this->properties as $property) { if ($property instanceof Collection || $property instanceof EloquentCollection) { - $this->md5 .= print_r($property->toArray(), true); + $this->md5 .= json_encode($property->toArray()); continue; } if ($property instanceof Carbon) { $this->md5 .= $property->toRfc3339String(); continue; } - - if (is_array($property)) { - $this->md5 .= print_r($property, true); - continue; - } - if (is_object($property)) { $this->md5 .= $property->__toString(); } - if (is_array($property)) { - $this->md5 .= print_r($property, true); - } - $this->md5 .= (string) $property; + + $this->md5 .= json_encode($property); } $this->md5 = md5($this->md5); @@ -107,4 +99,4 @@ class CacheProperties { Cache::forever($this->md5, $data); } -} \ No newline at end of file +} diff --git a/resources/lang/nl/breadcrumbs.php b/resources/lang/nl/breadcrumbs.php index 18e12fe0c5..bfed39b02a 100644 --- a/resources/lang/nl/breadcrumbs.php +++ b/resources/lang/nl/breadcrumbs.php @@ -45,10 +45,10 @@ return [ 'changePassword' => 'Verander je wachtwoord', // bills - 'bills' => 'Rekeningen', - 'newBill' => 'Nieuwe rekening', - 'edit_bill' => 'Wijzig rekening ":name"', - 'delete_bill' => 'Verwijder rekening ":name"', + 'bills' => 'Contracten', + 'newBill' => 'Nieuw contract', + 'edit_bill' => 'Wijzig contract ":name"', + 'delete_bill' => 'Verwijder contract ":name"', // reminders 'reminders' => 'Herinneringen', diff --git a/resources/lang/nl/firefly.php b/resources/lang/nl/firefly.php index 5156ff662b..7db9587382 100644 --- a/resources/lang/nl/firefly.php +++ b/resources/lang/nl/firefly.php @@ -45,7 +45,7 @@ return [ 'update_amount' => 'Bedrag bijwerken', // bills: - 'delete_bill' => 'Verwijder rekening ":name"', + 'delete_bill' => 'Verwijder contract ":name"', // accounts: 'details_for_asset' => 'Overzicht voor betaalrekening ":name"', @@ -128,8 +128,8 @@ return [ 'newTransfer' => 'Nieuwe overschrijving', 'moneyIn' => 'Inkomsten', 'moneyOut' => 'Uitgaven', - 'billsToPay' => 'Openstaande rekeningen', - 'billsPaid' => 'Betaalde rekeningen', + 'billsToPay' => 'Openstaande contracten', + 'billsPaid' => 'Betaalde contracten', 'viewDetails' => 'Meer info', 'divided' => 'verdeeld', 'toDivide' => 'te verdelen', @@ -161,7 +161,7 @@ return [ 'transfers' => 'Overschrijvingen', 'moneyManagement' => 'Geldbeheer', 'piggyBanks' => 'Spaarpotjes', - 'bills' => 'Rekeningen', + 'bills' => 'Contracten', 'createNew' => 'Nieuw', 'withdrawal' => 'Uitgave', 'deposit' => 'Inkomsten', @@ -170,7 +170,7 @@ return [ 'Withdrawal' => 'Uitgave', 'Deposit' => 'Inkomsten', 'Transfer' => 'Overschrijving', - 'bill' => 'Rekening', + 'bill' => 'Contracten', 'yes' => 'Ja', 'no' => 'Nee', 'amount' => 'Bedrag', @@ -227,7 +227,7 @@ return [ 'noBudget' => '(geen budget)', 'maxAmount' => 'Maximaal bedrag', 'minAmount' => 'Minimaal bedrag', - 'billEntry' => 'Bedrag voor deze rekening', + 'billEntry' => 'Bedrag voor dit contract', 'name' => 'Naam', 'date' => 'Datum', 'paid' => 'Betaald', diff --git a/resources/lang/nl/form.php b/resources/lang/nl/form.php index 4c1bcda15f..bcb086d5c2 100644 --- a/resources/lang/nl/form.php +++ b/resources/lang/nl/form.php @@ -58,7 +58,7 @@ return [ 'noBudget' => '(geen budget)', 'delete_account' => 'Verwijder rekening ":name"', - 'delete_bill' => 'Verwijder rekening ":name"', + 'delete_bill' => 'Verwijder contract ":name"', 'delete_budget' => 'Verwijder budget ":name"', 'delete_category' => 'Verwijder categorie ":name"', 'delete_currency' => 'Verwijder munteenheid ":name"', @@ -66,7 +66,7 @@ return [ 'delete_journal' => 'Verwijder transactie met omschrijving ":description"', 'account_areYouSure' => 'Weet je zeker dat je de rekening met naam ":name" wilt verwijderen?', - 'bill_areYouSure' => 'Weet je zeker dat je de rekening met naam ":name" wilt verwijderen?', + 'bill_areYouSure' => 'Weet je zeker dat je het contract met naam ":name" wilt verwijderen?', 'budget_areYouSure' => 'Weet je zeker dat je het budget met naam ":name" wilt verwijderen?', 'category_areYouSure' => 'Weet je zeker dat je het category met naam ":name" wilt verwijderen?', 'currency_areYouSure' => 'Weet je zeker dat je de munteenheid met naam ":name" wilt verwijderen?', @@ -78,8 +78,8 @@ return [ '|Ook alle :count transacties verbonden aan deze rekening worden verwijderd.', 'also_delete_piggyBanks' => 'Ook het spaarpotje verbonden aan deze rekening wordt verwijderd.' . '|Ook alle :count spaarpotjes verbonden aan deze rekening worden verwijderd.', - 'bill_keep_transactions' => 'De transactie verbonden aan deze rekening blijft bewaard.' . - '|De :count transacties verbonden aan deze rekening blijven bewaard.', + 'bill_keep_transactions' => 'De transactie verbonden aan dit contract blijft bewaard.' . + '|De :count transacties verbonden aan dit contract blijven bewaard.', 'budget_keep_transactions' => 'De transactie verbonden aan dit budget blijft bewaard.' . '|De :count transacties verbonden aan dit budget blijven bewaard.', 'category_keep_transactions' => 'De transactie verbonden aan deze categorie blijft bewaard.' . diff --git a/resources/lang/nl/list.php b/resources/lang/nl/list.php index 7ade859e8c..a9a8a30b02 100644 --- a/resources/lang/nl/list.php +++ b/resources/lang/nl/list.php @@ -23,7 +23,7 @@ return [ 'to' => 'Naar', 'budget' => 'Budget', 'category' => 'Categorie', - 'bill' => 'Rekening', + 'bill' => 'Contract', 'withdrawal' => 'Uitgave', 'deposit' => 'Inkomsten', 'transfer' => 'Overschrijving', From 40e49ffc3700fd042f0f5c909f65a6c475fe1524 Mon Sep 17 00:00:00 2001 From: James Cole Date: Fri, 5 Jun 2015 16:49:16 +0200 Subject: [PATCH 33/47] Some bug fixes and cleanup. --- app/Http/Controllers/Chart/AccountController.php | 1 + app/Http/Controllers/Chart/BudgetController.php | 14 +++++++++++--- app/Repositories/Shared/ComponentRepository.php | 11 +++++------ app/Support/Navigation.php | 5 +++-- composer.lock | 14 +++++++------- 5 files changed, 27 insertions(+), 18 deletions(-) diff --git a/app/Http/Controllers/Chart/AccountController.php b/app/Http/Controllers/Chart/AccountController.php index 9681fd7621..2c5d4f7a6e 100644 --- a/app/Http/Controllers/Chart/AccountController.php +++ b/app/Http/Controllers/Chart/AccountController.php @@ -63,6 +63,7 @@ class AccountController extends Controller } } + // $index = 1; /** @var Account $account */ diff --git a/app/Http/Controllers/Chart/BudgetController.php b/app/Http/Controllers/Chart/BudgetController.php index 46cba626e6..a10239f5cc 100644 --- a/app/Http/Controllers/Chart/BudgetController.php +++ b/app/Http/Controllers/Chart/BudgetController.php @@ -55,17 +55,25 @@ class BudgetController extends Controller while ($first < $last) { $end = Navigation::addPeriod($first, $range, 0); + $end->subDay(); + + // start date for chart. + $chartDate = clone $end; + $chartDate->startOfMonth(); $spent = $repository->spentInPeriodCorrected($budget, $first, $end); - $chart->addRow($end, $spent); - + $chart->addRow($chartDate, $spent); $first = Navigation::addPeriod($first, $range, 0); + + } $chart->generate(); $data = $chart->getData(); + + $cache->store($data); return Response::json($data); @@ -242,7 +250,7 @@ class BudgetController extends Controller } $chart->addRowArray($row); - $start->addMonth(); + $start->endOfMonth()->addDay(); } $chart->generate(); diff --git a/app/Repositories/Shared/ComponentRepository.php b/app/Repositories/Shared/ComponentRepository.php index d7b57bbfc5..e564b6d6ea 100644 --- a/app/Repositories/Shared/ComponentRepository.php +++ b/app/Repositories/Shared/ComponentRepository.php @@ -4,7 +4,6 @@ namespace FireflyIII\Repositories\Shared; use Carbon\Carbon; use Illuminate\Database\Query\JoinClause; -use stdClass; /** * Class ComponentRepository @@ -16,15 +15,15 @@ class ComponentRepository /** - * @param stdClass $object - * @param Carbon $start - * @param Carbon $end + * @param $object + * @param Carbon $start + * @param Carbon $end * - * @param bool $shared + * @param bool $shared * * @return string */ - protected function spentInPeriod(stdClass $object, Carbon $start, Carbon $end, $shared = false) + protected function spentInPeriod($object, Carbon $start, Carbon $end, $shared = false) { if ($shared === true) { // shared is true. diff --git a/app/Support/Navigation.php b/app/Support/Navigation.php index f2dd884673..b64fb9240e 100644 --- a/app/Support/Navigation.php +++ b/app/Support/Navigation.php @@ -41,6 +41,7 @@ class Navigation '6M' => 6, 'half-year' => 6, ]; + $specialMap = ['1M', 'month', 'monthly']; if (!isset($functionMap[$repeatFreq])) { throw new FireflyException('Cannot do addPeriod for $repeat_freq "' . $repeatFreq . '"'); } @@ -118,7 +119,7 @@ class Navigation 'year' => 'endOfYear', 'yearly' => 'endOfYear', ]; - $specials = ['mont', 'monthly']; + $specials = ['mont', 'monthly']; $currentEnd = clone $theCurrentEnd; @@ -270,7 +271,7 @@ class Navigation '3M' => 'lastOfQuarter', '1Y' => 'endOfYear', ]; - $end = clone $start; + $end = clone $start; if (isset($functionMap[$range])) { $function = $functionMap[$range]; diff --git a/composer.lock b/composer.lock index e65ab9a13c..20b62cda5d 100644 --- a/composer.lock +++ b/composer.lock @@ -3647,16 +3647,16 @@ }, { "name": "phpunit/phpunit", - "version": "4.6.10", + "version": "4.7.0", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "7b5fe98b28302a8b25693b2298bca74463336975" + "reference": "c2241b8d3381be3e4c6125ae347687d59f286784" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/7b5fe98b28302a8b25693b2298bca74463336975", - "reference": "7b5fe98b28302a8b25693b2298bca74463336975", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/c2241b8d3381be3e4c6125ae347687d59f286784", + "reference": "c2241b8d3381be3e4c6125ae347687d59f286784", "shasum": "" }, "require": { @@ -3667,7 +3667,7 @@ "ext-spl": "*", "php": ">=5.3.3", "phpspec/prophecy": "~1.3,>=1.3.1", - "phpunit/php-code-coverage": "~2.0,>=2.0.11", + "phpunit/php-code-coverage": "~2.1", "phpunit/php-file-iterator": "~1.4", "phpunit/php-text-template": "~1.2", "phpunit/php-timer": "~1.0", @@ -3689,7 +3689,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "4.6.x-dev" + "dev-master": "4.7.x-dev" } }, "autoload": { @@ -3715,7 +3715,7 @@ "testing", "xunit" ], - "time": "2015-06-03 05:03:30" + "time": "2015-06-05 04:14:02" }, { "name": "phpunit/phpunit-mock-objects", From 681167bc1b184e77e8a10884e1ed2336f37bff9a Mon Sep 17 00:00:00 2001 From: James Cole Date: Fri, 5 Jun 2015 19:02:23 +0200 Subject: [PATCH 34/47] Some code cleanup. --- app/Models/Permission.php | 14 +-- app/Models/Role.php | 16 +-- app/Models/TransactionJournal.php | 39 +++++-- app/Repositories/Budget/BudgetRepository.php | 102 +++++++++++------- .../Shared/ComponentRepository.php | 18 ++++ app/Support/Twig/Budget.php | 26 +++-- app/Support/Twig/Journal.php | 30 ++++-- app/User.php | 2 +- resources/twig/list/journals.twig | 8 +- 9 files changed, 171 insertions(+), 84 deletions(-) diff --git a/app/Models/Permission.php b/app/Models/Permission.php index 7b660eb32e..7e98ba7eda 100644 --- a/app/Models/Permission.php +++ b/app/Models/Permission.php @@ -8,13 +8,13 @@ use Zizaco\Entrust\EntrustPermission; * Class Permission * * @package FireflyIII\Models - * @property integer $id - * @property string $name - * @property string $display_name - * @property string $description - * @property \Carbon\Carbon $created_at - * @property \Carbon\Carbon $updated_at - * @property-read \Illuminate\Database\Eloquent\Collection|\Config::get('entrust.role')[] $roles + * @property integer $id + * @property string $name + * @property string $display_name + * @property string $description + * @property \Carbon\Carbon $created_at + * @property \Carbon\Carbon $updated_at + * @property-read \Illuminate\Database\Eloquent\Collection|\Config::get('entrust.role')[] $roles * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Permission whereId($value) * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Permission whereName($value) * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Permission whereDisplayName($value) diff --git a/app/Models/Role.php b/app/Models/Role.php index 6476a4ee39..2c3285610e 100644 --- a/app/Models/Role.php +++ b/app/Models/Role.php @@ -8,14 +8,14 @@ use Zizaco\Entrust\EntrustRole; * Class Role * * @package FireflyIII\Models - * @property integer $id - * @property string $name - * @property string $display_name - * @property string $description - * @property \Carbon\Carbon $created_at - * @property \Carbon\Carbon $updated_at - * @property-read \Illuminate\Database\Eloquent\Collection|\Config::get('auth.model')[] $users - * @property-read \Illuminate\Database\Eloquent\Collection|\Config::get('entrust.permission')[] $perms + * @property integer $id + * @property string $name + * @property string $display_name + * @property string $description + * @property \Carbon\Carbon $created_at + * @property \Carbon\Carbon $updated_at + * @property-read \Illuminate\Database\Eloquent\Collection|\Config::get('auth.model')[] $users + * @property-read \Illuminate\Database\Eloquent\Collection|\Config::get('entrust.permission')[] $perms * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Role whereId($value) * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Role whereName($value) * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Role whereDisplayName($value) diff --git a/app/Models/TransactionJournal.php b/app/Models/TransactionJournal.php index 6ca596ac44..8b2a5f68c6 100644 --- a/app/Models/TransactionJournal.php +++ b/app/Models/TransactionJournal.php @@ -68,9 +68,10 @@ use Watson\Validating\ValidatingTrait; * @property mixed account_id * @property mixed name * @property mixed symbol - * @property-read mixed $correct_amount + * @property-read mixed $correct_amount * @method static \FireflyIII\Models\TransactionJournal orderBy * @method static \FireflyIII\Models\TransactionJournal|null first + * @property-read mixed $source_account */ class TransactionJournal extends Model { @@ -294,14 +295,17 @@ class TransactionJournal extends Model */ public function getDestinationAccountAttribute() { - /** @var Transaction $transaction */ - foreach ($this->transactions()->get() as $transaction) { - if (floatval($transaction->amount) > 0) { - return $transaction->account; - } - } + $cache = new CacheProperties; + $cache->addProperty($this->id); + $cache->addProperty('destinationAccount'); - return $this->transactions()->first()->account; + if ($cache->has()) { + return $cache->get(); // @codeCoverageIgnore + } + $account = $this->transactions()->where('amount', '>', 0)->first()->account; + $cache->store($account); + + return $account; } /** @@ -325,6 +329,23 @@ class TransactionJournal extends Model } + /** + * @return Account + */ + public function getSourceAccountAttribute() + { + $cache = new CacheProperties; + $cache->addProperty($this->id); + $cache->addProperty('destinationAccount'); + if ($cache->has()) { + return $cache->get(); // @codeCoverageIgnore + } + $account = $this->transactions()->where('amount', '<', 0)->first()->account; + $cache->store($account); + + return $account; + } + /** * @codeCoverageIgnore * @return \Illuminate\Database\Eloquent\Relations\HasMany @@ -415,7 +436,7 @@ class TransactionJournal extends Model public function scopeWithRelevantData(EloquentBuilder $query) { $query->with( - ['transactions' => function(HasMany $q) { + ['transactions' => function (HasMany $q) { $q->orderBy('amount', 'ASC'); }, 'transactiontype', 'transactioncurrency', 'budgets', 'categories', 'transactions.account.accounttype', 'bill', 'budgets', 'categories'] ); diff --git a/app/Repositories/Budget/BudgetRepository.php b/app/Repositories/Budget/BudgetRepository.php index d14a7da15e..a4a9bda75f 100644 --- a/app/Repositories/Budget/BudgetRepository.php +++ b/app/Repositories/Budget/BudgetRepository.php @@ -8,6 +8,7 @@ use FireflyIII\Models\Budget; use FireflyIII\Models\BudgetLimit; use FireflyIII\Models\LimitRepetition; use FireflyIII\Repositories\Shared\ComponentRepository; +use FireflyIII\Support\CacheProperties; use Illuminate\Database\Query\Builder as QueryBuilder; use Illuminate\Pagination\LengthAwarePaginator; use Illuminate\Support\Collection; @@ -79,10 +80,10 @@ class BudgetRepository extends ComponentRepository implements BudgetRepositoryIn /** @var Collection $repetitions */ return LimitRepetition:: leftJoin('budget_limits', 'limit_repetitions.budget_limit_id', '=', 'budget_limits.id') - ->where('limit_repetitions.startdate', '<=', $end->format('Y-m-d 00:00:00')) - ->where('limit_repetitions.startdate', '>=', $start->format('Y-m-d 00:00:00')) - ->where('budget_limits.budget_id', $budget->id) - ->get(['limit_repetitions.*']); + ->where('limit_repetitions.startdate', '<=', $end->format('Y-m-d 00:00:00')) + ->where('limit_repetitions.startdate', '>=', $start->format('Y-m-d 00:00:00')) + ->where('budget_limits.budget_id', $budget->id) + ->get(['limit_repetitions.*']); } /** @@ -113,7 +114,17 @@ class BudgetRepository extends ComponentRepository implements BudgetRepositoryIn */ public function getCurrentRepetition(Budget $budget, Carbon $date) { - return $budget->limitrepetitions()->where('limit_repetitions.startdate', $date)->first(['limit_repetitions.*']); + $cache = new CacheProperties; + $cache->addProperty($budget->id); + $cache->addProperty($date); + $cache->addProperty('getCurrentRepetition'); + if ($cache->has()) { + return $cache->get(); // @codeCoverageIgnore + } + $data = $budget->limitrepetitions()->where('limit_repetitions.startdate', $date)->first(['limit_repetitions.*']); + $cache->store($data); + + return $data; } /** @@ -150,13 +161,22 @@ class BudgetRepository extends ComponentRepository implements BudgetRepositoryIn */ public function getJournals(Budget $budget, LimitRepetition $repetition = null, $take = 50) { - $offset = intval(Input::get('page')) > 0 ? intval(Input::get('page')) * $take : 0; - + $cache = new CacheProperties; + $cache->addProperty($budget->id); + if ($repetition) { + $cache->addProperty($repetition->id); + } + $cache->addProperty($take); + $cache->addProperty('getJournals'); + if ($cache->has()) { + return $cache->get(); // @codeCoverageIgnore + } + $offset = intval(Input::get('page')) > 0 ? intval(Input::get('page')) * $take : 0; $setQuery = $budget->transactionJournals()->withRelevantData()->take($take)->offset($offset) - ->orderBy('transaction_journals.date', 'DESC') - ->orderBy('transaction_journals.order', 'ASC') - ->orderBy('transaction_journals.id', 'DESC'); + ->orderBy('transaction_journals.date', 'DESC') + ->orderBy('transaction_journals.order', 'ASC') + ->orderBy('transaction_journals.id', 'DESC'); $countQuery = $budget->transactionJournals(); @@ -169,7 +189,11 @@ class BudgetRepository extends ComponentRepository implements BudgetRepositoryIn $set = $setQuery->get(['transaction_journals.*']); $count = $countQuery->count(); - return new LengthAwarePaginator($set, $count, $take, $offset); + + $paginator = new LengthAwarePaginator($set, $count, $take, $offset); + $cache->store($paginator); + + return $paginator; } /** @@ -196,9 +220,9 @@ class BudgetRepository extends ComponentRepository implements BudgetRepositoryIn public function getLimitAmountOnDate(Budget $budget, Carbon $date) { $repetition = LimitRepetition::leftJoin('budget_limits', 'limit_repetitions.budget_limit_id', '=', 'budget_limits.id') - ->where('limit_repetitions.startdate', $date->format('Y-m-d 00:00:00')) - ->where('budget_limits.budget_id', $budget->id) - ->first(['limit_repetitions.*']); + ->where('limit_repetitions.startdate', $date->format('Y-m-d 00:00:00')) + ->where('budget_limits.budget_id', $budget->id) + ->first(['limit_repetitions.*']); if ($repetition) { return floatval($repetition->amount); @@ -216,15 +240,15 @@ class BudgetRepository extends ComponentRepository implements BudgetRepositoryIn public function getWithoutBudget(Carbon $start, Carbon $end) { return Auth::user() - ->transactionjournals() - ->leftJoin('budget_transaction_journal', 'budget_transaction_journal.transaction_journal_id', '=', 'transaction_journals.id') - ->whereNull('budget_transaction_journal.id') - ->before($end) - ->after($start) - ->orderBy('transaction_journals.date', 'DESC') - ->orderBy('transaction_journals.order', 'ASC') - ->orderBy('transaction_journals.id', 'DESC') - ->get(['transaction_journals.*']); + ->transactionjournals() + ->leftJoin('budget_transaction_journal', 'budget_transaction_journal.transaction_journal_id', '=', 'transaction_journals.id') + ->whereNull('budget_transaction_journal.id') + ->before($end) + ->after($start) + ->orderBy('transaction_journals.date', 'DESC') + ->orderBy('transaction_journals.order', 'ASC') + ->orderBy('transaction_journals.id', 'DESC') + ->get(['transaction_journals.*']); } /** @@ -236,22 +260,22 @@ class BudgetRepository extends ComponentRepository implements BudgetRepositoryIn public function getWithoutBudgetSum(Carbon $start, Carbon $end) { $noBudgetSet = Auth::user() - ->transactionjournals() - ->whereNotIn( - 'transaction_journals.id', function (QueryBuilder $query) use ($start, $end) { - $query - ->select('transaction_journals.id') - ->from('transaction_journals') - ->leftJoin('budget_transaction_journal', 'budget_transaction_journal.transaction_journal_id', '=', 'transaction_journals.id') - ->where('transaction_journals.date', '>=', $start->format('Y-m-d 00:00:00')) - ->where('transaction_journals.date', '<=', $end->format('Y-m-d 00:00:00')) - ->whereNotNull('budget_transaction_journal.budget_id'); - } - ) - ->after($start) - ->before($end) - ->transactionTypes(['Withdrawal']) - ->get(['transaction_journals.*'])->sum('amount'); + ->transactionjournals() + ->whereNotIn( + 'transaction_journals.id', function (QueryBuilder $query) use ($start, $end) { + $query + ->select('transaction_journals.id') + ->from('transaction_journals') + ->leftJoin('budget_transaction_journal', 'budget_transaction_journal.transaction_journal_id', '=', 'transaction_journals.id') + ->where('transaction_journals.date', '>=', $start->format('Y-m-d 00:00:00')) + ->where('transaction_journals.date', '<=', $end->format('Y-m-d 00:00:00')) + ->whereNotNull('budget_transaction_journal.budget_id'); + } + ) + ->after($start) + ->before($end) + ->transactionTypes(['Withdrawal']) + ->get(['transaction_journals.*'])->sum('amount'); return floatval($noBudgetSet) * -1; } diff --git a/app/Repositories/Shared/ComponentRepository.php b/app/Repositories/Shared/ComponentRepository.php index e564b6d6ea..e4ee7992df 100644 --- a/app/Repositories/Shared/ComponentRepository.php +++ b/app/Repositories/Shared/ComponentRepository.php @@ -3,6 +3,7 @@ namespace FireflyIII\Repositories\Shared; use Carbon\Carbon; +use FireflyIII\Support\CacheProperties; use Illuminate\Database\Query\JoinClause; /** @@ -25,6 +26,21 @@ class ComponentRepository */ protected function spentInPeriod($object, Carbon $start, Carbon $end, $shared = false) { + // we must cache this. + + $cache = new CacheProperties; + $cache->addProperty($object->id); + $cache->addProperty(get_class($object)); + $cache->addProperty($start); + $cache->addProperty($end); + $cache->addProperty($shared); + $cache->addProperty('spentInPeriod'); + + if($cache->has()) { + return $cache->get(); // @codeCoverageIgnore + } + + if ($shared === true) { // shared is true. // always ignore transfers between accounts! @@ -51,6 +67,8 @@ class ComponentRepository ->get(['transaction_journals.*'])->sum('amount'); } + $cache->store($sum); + return $sum; } } diff --git a/app/Support/Twig/Budget.php b/app/Support/Twig/Budget.php index e9dd063e8d..278f6b0448 100644 --- a/app/Support/Twig/Budget.php +++ b/app/Support/Twig/Budget.php @@ -4,6 +4,7 @@ namespace FireflyIII\Support\Twig; use Auth; use FireflyIII\Models\LimitRepetition; +use FireflyIII\Support\CacheProperties; use Twig_Extension; use Twig_SimpleFunction; @@ -21,18 +22,25 @@ class Budget extends Twig_Extension { $functions = []; $functions[] = new Twig_SimpleFunction( - 'spentInRepetitionCorrected', function(LimitRepetition $repetition) { + 'spentInRepetitionCorrected', function (LimitRepetition $repetition) { + $cache = new CacheProperties; + $cache->addProperty($repetition->id); + $cache->addProperty('spentInRepetitionCorrected'); + if ($cache->has()) { + return $cache->get(); // @codeCoverageIgnore + } $sum = Auth::user()->transactionjournals() - ->leftJoin('budget_transaction_journal', 'budget_transaction_journal.transaction_journal_id', '=', 'transaction_journals.id') - ->leftJoin('budget_limits', 'budget_limits.budget_id', '=', 'budget_transaction_journal.budget_id') - ->leftJoin('limit_repetitions', 'limit_repetitions.budget_limit_id', '=', 'budget_limits.id') - ->before($repetition->enddate) - ->after($repetition->startdate) - ->where('limit_repetitions.id', '=', $repetition->id) - ->get(['transaction_journals.*'])->sum('amount'); + ->leftJoin('budget_transaction_journal', 'budget_transaction_journal.transaction_journal_id', '=', 'transaction_journals.id') + ->leftJoin('budget_limits', 'budget_limits.budget_id', '=', 'budget_transaction_journal.budget_id') + ->leftJoin('limit_repetitions', 'limit_repetitions.budget_limit_id', '=', 'budget_limits.id') + ->before($repetition->enddate) + ->after($repetition->startdate) + ->where('limit_repetitions.id', '=', $repetition->id) + ->get(['transaction_journals.*'])->sum('amount'); + $cache->store($sum); - return floatval($sum); + return $sum; } ); diff --git a/app/Support/Twig/Journal.php b/app/Support/Twig/Journal.php index f239a9097a..6a25aaf9b7 100644 --- a/app/Support/Twig/Journal.php +++ b/app/Support/Twig/Journal.php @@ -87,8 +87,18 @@ class Journal extends Twig_Extension $functions[] = new Twig_SimpleFunction( 'relevantTags', function(TransactionJournal $journal) { + $cache = new CacheProperties; + $cache->addProperty('relevantTags'); + $cache->addProperty($journal->id); + + if($cache->has()) { + return $cache->get(); // @codeCoverageIgnore + } + if ($journal->tags->count() == 0) { - return App::make('amount')->formatJournal($journal); + $string = App::make('amount')->formatJournal($journal); + $cache->store($string); + return $string; } @@ -97,9 +107,10 @@ class Journal extends Twig_Extension // return tag formatted for a "balancing act", even if other // tags are present. $amount = App::make('amount')->format($journal->actual_amount, false); - - return 'id]) . '" class="label label-success" title="' . $amount . '"> ' . $tag->tag . ''; + $cache->store($string); + return $string; } /* @@ -107,9 +118,10 @@ class Journal extends Twig_Extension */ if ($tag->tagMode == 'advancePayment' && $journal->transactionType->type == 'Deposit') { $amount = App::make('amount')->formatJournal($journal, false); - - return 'id]) . '" class="label label-success" title="' . $amount . '"> ' . $tag->tag . ''; + $cache->store($string); + return $string; } /* * AdvancePayment with a withdrawal will show the amount with a link to @@ -118,13 +130,17 @@ class Journal extends Twig_Extension if ($tag->tagMode == 'advancePayment' && $journal->transactionType->type == 'Withdrawal') { $amount = App::make('amount')->formatJournal($journal); - return '' . $amount . ''; + $string = '' . $amount . ''; + $cache->store($string); + return $string; } if ($tag->tagMode == 'nothing') { // return the amount: - return App::make('amount')->formatJournal($journal); + $string = App::make('amount')->formatJournal($journal); + $cache->store($string); + return $string; } } diff --git a/app/User.php b/app/User.php index 9744811fd3..8264621ea1 100644 --- a/app/User.php +++ b/app/User.php @@ -33,7 +33,7 @@ use Zizaco\Entrust\Traits\EntrustUserTrait; * @method static \Illuminate\Database\Query\Builder|\FireflyIII\User wherePassword($value) * @method static \Illuminate\Database\Query\Builder|\FireflyIII\User whereReset($value) * @method static \Illuminate\Database\Query\Builder|\FireflyIII\User whereRememberToken($value) - * @property-read \Illuminate\Database\Eloquent\Collection|\Config::get('entrust.role')[] $roles + * @property-read \Illuminate\Database\Eloquent\Collection|\Config::get('entrust.role')[] $roles */ class User extends Model implements AuthenticatableContract, CanResetPasswordContract { diff --git a/resources/twig/list/journals.twig b/resources/twig/list/journals.twig index 44df7e1abb..f6e737965c 100644 --- a/resources/twig/list/journals.twig +++ b/resources/twig/list/journals.twig @@ -64,17 +64,17 @@ {{journal.date.formatLocalized(monthAndDayFormat)}} - {% if journal.transactions[0].account.accountType.type == 'Cash account' %} + {% if journal.source_account.accountType.type == 'Cash account' %} (cash) {% else %} - {{journal.transactions[0].account.name}} + {{journal.source_account.name}} {% endif %} - {% if journal.transactions[1].account.accountType.type == 'Cash account' %} + {% if journal.destination_account.accountType.type == 'Cash account' %} (cash) {% else %} - {{journal.transactions[1].account.name}} + {{journal.destination_account.name}} {% endif %} From db020db34bca409e5372997cace3bac771074c5d Mon Sep 17 00:00:00 2001 From: James Cole Date: Sat, 6 Jun 2015 15:36:12 +0200 Subject: [PATCH 35/47] Fix tests and fix coverage. --- .../Controllers/TransactionController.php | 2 +- app/Models/TransactionJournal.php | 64 +--- app/Providers/EventServiceProvider.php | 10 +- app/Repositories/Bill/BillRepository.php | 2 +- .../Journal/JournalRepository.php | 5 - app/Repositories/Tag/TagRepository.php | 2 +- app/Support/Amount.php | 4 +- app/Support/CacheProperties.php | 4 + app/Support/Preferences.php | 1 - .../controllers/TransactionControllerTest.php | 2 + tests/models/TransactionJournalModelTest.php | 195 +----------- tests/repositories/AccountRepositoryTest.php | 14 +- tests/repositories/BillRepositoryTest.php | 20 +- tests/repositories/BudgetRepositoryTest.php | 12 + tests/repositories/CategoryRepositoryTest.php | 4 + tests/repositories/JournalRepositoryTest.php | 12 +- .../repositories/PiggyBankRepositoryTest.php | 15 +- tests/repositories/TagRepositoryTest.php | 18 ++ tests/support/AmountSupportTest.php | 281 ++++++++++++++++++ 19 files changed, 381 insertions(+), 286 deletions(-) create mode 100644 tests/support/AmountSupportTest.php diff --git a/app/Http/Controllers/TransactionController.php b/app/Http/Controllers/TransactionController.php index 575d35c383..59cbb56219 100644 --- a/app/Http/Controllers/TransactionController.php +++ b/app/Http/Controllers/TransactionController.php @@ -157,7 +157,7 @@ class TransactionController extends Controller } $preFilled['amount'] = $journal->actual_amount; - $preFilled['account_id'] = $journal->asset_account->id; + $preFilled['account_id'] = $journal->destination_account->id; $preFilled['expense_account'] = $transactions[0]->account->name; $preFilled['revenue_account'] = $transactions[1]->account->name; $preFilled['account_from_id'] = $transactions[1]->account->id; diff --git a/app/Models/TransactionJournal.php b/app/Models/TransactionJournal.php index 8b2a5f68c6..73de69784b 100644 --- a/app/Models/TransactionJournal.php +++ b/app/Models/TransactionJournal.php @@ -7,6 +7,7 @@ use Illuminate\Database\Eloquent\Builder as EloquentBuilder; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\HasMany; use Illuminate\Database\Eloquent\SoftDeletes; +use Log; use Watson\Validating\ValidatingTrait; /** @@ -71,7 +72,7 @@ use Watson\Validating\ValidatingTrait; * @property-read mixed $correct_amount * @method static \FireflyIII\Models\TransactionJournal orderBy * @method static \FireflyIII\Models\TransactionJournal|null first - * @property-read mixed $source_account + * @property-read mixed $source_account */ class TransactionJournal extends Model { @@ -219,36 +220,6 @@ class TransactionJournal extends Model return $this->belongsToMany('FireflyIII\Models\Tag'); } - /** - * @return Account - */ - public function getAssetAccountAttribute() - { - // if it's a deposit, it's the one thats positive - // if it's a withdrawal, it's the one thats negative - // otherwise, it's either (return first one): - - switch ($this->transactionType->type) { - case 'Deposit': - return $this->transactions()->where('amount', '>', 0)->first()->account; - case 'Withdrawal': - return $this->transactions()->where('amount', '<', 0)->first()->account; - - } - - return $this->transactions()->first()->account; - - } - - /** - * @codeCoverageIgnore - * @return \Illuminate\Database\Eloquent\Relations\HasMany - */ - public function transactions() - { - return $this->hasMany('FireflyIII\Models\Transaction'); - } - /** * @return string */ @@ -265,6 +236,15 @@ class TransactionJournal extends Model return '0'; } + /** + * @codeCoverageIgnore + * @return \Illuminate\Database\Eloquent\Relations\HasMany + */ + public function transactions() + { + return $this->hasMany('FireflyIII\Models\Transaction'); + } + /** * @codeCoverageIgnore * @return string[] @@ -308,27 +288,6 @@ class TransactionJournal extends Model return $account; } - /** - * @return Account - */ - public function getExpenseAccountAttribute() - { - // if it's a deposit, it's the one thats negative - // if it's a withdrawal, it's the one thats positive - // otherwise, it's either (return first one): - - switch ($this->transactionType->type) { - case 'Deposit': - return $this->transactions()->where('amount', '<', 0)->first()->account; - case 'Withdrawal': - return $this->transactions()->where('amount', '>', 0)->first()->account; - - } - - return $this->transactions()->first()->account; - - } - /** * @return Account */ @@ -341,6 +300,7 @@ class TransactionJournal extends Model return $cache->get(); // @codeCoverageIgnore } $account = $this->transactions()->where('amount', '<', 0)->first()->account; + $cache->store($account); return $account; diff --git a/app/Providers/EventServiceProvider.php b/app/Providers/EventServiceProvider.php index 3e01105bd5..626b3f6ea2 100644 --- a/app/Providers/EventServiceProvider.php +++ b/app/Providers/EventServiceProvider.php @@ -53,11 +53,14 @@ class EventServiceProvider extends ServiceProvider $this->registerCreateEvents(); BudgetLimit::saved( function(BudgetLimit $budgetLimit) { + Log::debug('Saved!'); $end = Navigation::addPeriod(clone $budgetLimit->startdate, $budgetLimit->repeat_freq, 0); $end->subDay(); - $set = $budgetLimit->limitrepetitions()->where('startdate', $budgetLimit->startdate->format('Y-m-d'))->where('enddate', $end->format('Y-m-d')) - ->get(); + $set = $budgetLimit->limitrepetitions() + ->where('startdate', $budgetLimit->startdate->format('Y-m-d 00:00:00')) + ->where('enddate', $end->format('Y-m-d 00:00:00')) + ->get(); if ($set->count() == 0) { $repetition = new LimitRepetition; $repetition->startdate = $budgetLimit->startdate; @@ -68,8 +71,7 @@ class EventServiceProvider extends ServiceProvider try { $repetition->save(); } catch (QueryException $e) { - Log::error('Trying to save new LimitRepetition failed!'); - Log::error($e->getMessage()); + Log::error('Trying to save new LimitRepetition failed: '.$e->getMessage()); // @codeCoverageIgnore } } else { if ($set->count() == 1) { diff --git a/app/Repositories/Bill/BillRepository.php b/app/Repositories/Bill/BillRepository.php index 54ee071c66..3aa4a34b6f 100644 --- a/app/Repositories/Bill/BillRepository.php +++ b/app/Repositories/Bill/BillRepository.php @@ -265,7 +265,7 @@ class BillRepository implements BillRepositoryInterface $amountMatch = false; $wordMatch = false; $matches = explode(',', $bill->match); - $description = strtolower($journal->description) . ' ' . strtolower($journal->expense_account->name); + $description = strtolower($journal->description) . ' ' . strtolower($journal->destination_account->name); $count = 0; foreach ($matches as $word) { if (!(strpos($description, strtolower($word)) === false)) { diff --git a/app/Repositories/Journal/JournalRepository.php b/app/Repositories/Journal/JournalRepository.php index a7fb12f50a..9e1758310b 100644 --- a/app/Repositories/Journal/JournalRepository.php +++ b/app/Repositories/Journal/JournalRepository.php @@ -48,11 +48,6 @@ class JournalRepository implements JournalRepositoryInterface */ public function delete(TransactionJournal $journal) { - // delete transactions first: - /** @var Transaction $transaction */ - foreach ($journal->transactions()->get() as $transaction) { - $transaction->delete(); - } $journal->delete(); return true; diff --git a/app/Repositories/Tag/TagRepository.php b/app/Repositories/Tag/TagRepository.php index 5f02c0ce5a..276f190821 100644 --- a/app/Repositories/Tag/TagRepository.php +++ b/app/Repositories/Tag/TagRepository.php @@ -318,7 +318,7 @@ class TagRepository implements TagRepositoryInterface $match = true; /** @var TransactionJournal $check */ foreach ($tag->transactionjournals as $check) { - if ($check->asset_account->id != $journal->asset_account->id) { + if ($check->source_account->id != $journal->source_account->id) { $match = false; } } diff --git a/app/Support/Amount.php b/app/Support/Amount.php index c492e5471a..0d4c2a6534 100644 --- a/app/Support/Amount.php +++ b/app/Support/Amount.php @@ -36,7 +36,7 @@ class Amount public function getCurrencySymbol() { if (defined('FFCURRENCYSYMBOL')) { - return FFCURRENCYSYMBOL; + return FFCURRENCYSYMBOL; // @codeCoverageIgnore } $currencyPreference = Prefs::get('currencyPreference', 'EUR'); @@ -149,7 +149,7 @@ class Amount public function getCurrencyCode() { if (defined('FFCURRENCYCODE')) { - return FFCURRENCYCODE; + return FFCURRENCYCODE; // @codeCoverageIgnore } diff --git a/app/Support/CacheProperties.php b/app/Support/CacheProperties.php index f210309c59..f0e1c760ee 100644 --- a/app/Support/CacheProperties.php +++ b/app/Support/CacheProperties.php @@ -9,6 +9,7 @@ use Carbon\Carbon; use Illuminate\Database\Eloquent\Collection as EloquentCollection; use Illuminate\Support\Collection; use Preferences as Prefs; +use Log; /** * Class CacheProperties @@ -62,6 +63,9 @@ class CacheProperties */ public function has() { + if(getenv('APP_ENV') == 'testing') { + return false; + } $this->md5(); return Cache::has($this->md5); diff --git a/app/Support/Preferences.php b/app/Support/Preferences.php index 0fd7d8a184..0a1d287566 100644 --- a/app/Support/Preferences.php +++ b/app/Support/Preferences.php @@ -36,7 +36,6 @@ class Preferences return Cache::get($fullName); } - $preference = Preference::where('user_id', Auth::user()->id)->where('name', $name)->first(['id', 'name', 'data_encrypted']); if ($preference) { diff --git a/tests/controllers/TransactionControllerTest.php b/tests/controllers/TransactionControllerTest.php index 9c672ac1cc..c778f49de2 100644 --- a/tests/controllers/TransactionControllerTest.php +++ b/tests/controllers/TransactionControllerTest.php @@ -97,6 +97,8 @@ class TransactionControllerTest extends TestCase */ public function testEdit() { + $user = FactoryMuffin::create('FireflyIII\User'); + $this->be($user); // make complete journal: $accountType = FactoryMuffin::create('FireflyIII\Models\AccountType'); $journal = FactoryMuffin::create('FireflyIII\Models\TransactionJournal'); diff --git a/tests/models/TransactionJournalModelTest.php b/tests/models/TransactionJournalModelTest.php index 23e547620c..307584cb84 100644 --- a/tests/models/TransactionJournalModelTest.php +++ b/tests/models/TransactionJournalModelTest.php @@ -235,103 +235,6 @@ class TransactionJournalModelTest extends TestCase } - /** - * @covers FireflyIII\Models\TransactionJournal::getAssetAccountAttribute - */ - public function testGetAssetAccountAttributeDeposit() - { - FactoryMuffin::create('FireflyIII\Models\TransactionType'); - - // make withdrawal - $depositType = FactoryMuffin::create('FireflyIII\Models\TransactionType'); - $deposit = FactoryMuffin::create('FireflyIII\Models\TransactionJournal'); - $deposit->transaction_type_id = $depositType->id; - $deposit->save(); - - // make accounts - FactoryMuffin::create('FireflyIII\Models\Account'); - $revenue = FactoryMuffin::create('FireflyIII\Models\Account'); - $asset = FactoryMuffin::create('FireflyIII\Models\Account'); - - // update transactions - $deposit->transactions[0]->account_id = $asset->id; - $deposit->transactions[0]->amount = 300; - $deposit->transactions[0]->save(); - - $deposit->transactions[1]->account_id = $revenue->id; - $deposit->transactions[1]->amount = -300; - $deposit->transactions[1]->save(); - - - // get asset account: - $result = $deposit->asset_account; - - $this->assertEquals($asset->id, $result->id); - } - - /** - * @covers FireflyIII\Models\TransactionJournal::getAssetAccountAttribute - */ - public function testGetAssetAccountAttributeFallback() - { - - FactoryMuffin::create('FireflyIII\Models\TransactionType'); // withdrawal - FactoryMuffin::create('FireflyIII\Models\TransactionType'); // deposit - - // make accounts - FactoryMuffin::create('FireflyIII\Models\Account'); - $revenue = FactoryMuffin::create('FireflyIII\Models\Account'); - $asset = FactoryMuffin::create('FireflyIII\Models\Account'); - - // make withdrawal - $transferType = FactoryMuffin::create('FireflyIII\Models\TransactionType'); // transfer - $transfer = FactoryMuffin::create('FireflyIII\Models\TransactionJournal'); - $transfer->transaction_type_id = $transferType->id; - $transfer->save(); - - $transfer->transactions[0]->account_id = $asset->id; - $transfer->transactions[0]->amount = 300; - $transfer->transactions[0]->save(); - - $transfer->transactions[1]->account_id = $revenue->id; - $transfer->transactions[1]->amount = -300; - $transfer->transactions[1]->save(); - - // get asset account: - $result = $transfer->asset_account; - - $this->assertEquals($asset->id, $result->id); - } - - /** - * @covers FireflyIII\Models\TransactionJournal::getAssetAccountAttribute - */ - public function testGetAssetAccountAttributeWithdrawal() - { - // make accounts - $expense = FactoryMuffin::create('FireflyIII\Models\Account'); - $asset = FactoryMuffin::create('FireflyIII\Models\Account'); - - // make withdrawal - $withdrawalType = FactoryMuffin::create('FireflyIII\Models\TransactionType'); - $withdrawal = FactoryMuffin::create('FireflyIII\Models\TransactionJournal'); - $withdrawal->transaction_type_id = $withdrawalType->id; - $withdrawal->save(); - - - $withdrawal->transactions[0]->account_id = $asset->id; - $withdrawal->transactions[0]->amount = -300; - $withdrawal->transactions[0]->save(); - - $withdrawal->transactions[1]->account_id = $expense->id; - $withdrawal->transactions[1]->amount = 300; - $withdrawal->transactions[1]->save(); - - // get asset account: - $result = $withdrawal->asset_account; - - $this->assertEquals($asset->id, $result->id); - } /** * @covers FireflyIII\Models\TransactionJournal::getCorrectAmountAttribute @@ -434,6 +337,8 @@ class TransactionJournalModelTest extends TestCase */ public function testGetDestinationAccountAttribute() { + $user = FactoryMuffin::create('FireflyIII\User'); + $this->be($user); FactoryMuffin::create('FireflyIII\Models\TransactionType'); $depositType = FactoryMuffin::create('FireflyIII\Models\TransactionType'); $deposit = FactoryMuffin::create('FireflyIII\Models\TransactionJournal'); @@ -462,8 +367,10 @@ class TransactionJournalModelTest extends TestCase /** * @covers FireflyIII\Models\TransactionJournal::getDestinationAccountAttribute */ - public function testGetDestinationAccountAttributeFallback() + public function testGetSourceAccountAttribute() { + $user = FactoryMuffin::create('FireflyIII\User'); + $this->be($user); FactoryMuffin::create('FireflyIII\Models\TransactionType'); $depositType = FactoryMuffin::create('FireflyIII\Models\TransactionType'); $deposit = FactoryMuffin::create('FireflyIII\Models\TransactionJournal'); @@ -475,36 +382,6 @@ class TransactionJournalModelTest extends TestCase $revenue = FactoryMuffin::create('FireflyIII\Models\Account'); $asset = FactoryMuffin::create('FireflyIII\Models\Account'); - $deposit->transactions[0]->account_id = $asset->id; - $deposit->transactions[0]->amount = -300; - $deposit->transactions[0]->save(); - - $deposit->transactions[1]->account_id = $revenue->id; - $deposit->transactions[1]->amount = -300; - $deposit->transactions[1]->save(); - - // get asset account: - $result = $deposit->destination_account; - - $this->assertEquals($asset->id, $result->id); - } - - /** - * @covers FireflyIII\Models\TransactionJournal::getExpenseAccountAttribute - */ - public function testGetExpenseAccountAttribute() - { - FactoryMuffin::create('FireflyIII\Models\TransactionType'); // withdrawal - $depositType = FactoryMuffin::create('FireflyIII\Models\TransactionType'); // deposit - $deposit = FactoryMuffin::create('FireflyIII\Models\TransactionJournal'); - $deposit->transaction_type_id = $depositType->id; - $deposit->save(); - - // make accounts - FactoryMuffin::create('FireflyIII\Models\Account'); - $revenue = FactoryMuffin::create('FireflyIII\Models\Account'); - $asset = FactoryMuffin::create('FireflyIII\Models\Account'); - $deposit->transactions[0]->account_id = $asset->id; $deposit->transactions[0]->amount = 300; $deposit->transactions[0]->save(); @@ -514,69 +391,9 @@ class TransactionJournalModelTest extends TestCase $deposit->transactions[1]->save(); // get asset account: - $result = $deposit->expense_account; + $result = $deposit->source_account; $this->assertEquals($revenue->id, $result->id); } - /** - * @covers FireflyIII\Models\TransactionJournal::getExpenseAccountAttribute - */ - public function testGetExpenseAccountAttributeFallback() - { - FactoryMuffin::create('FireflyIII\Models\TransactionType'); // withdrawal - FactoryMuffin::create('FireflyIII\Models\TransactionType'); // deposit - $transferType = FactoryMuffin::create('FireflyIII\Models\TransactionType'); // transfer - $transfer = FactoryMuffin::create('FireflyIII\Models\TransactionJournal'); - $transfer->transaction_type_id = $transferType->id; - $transfer->save(); - - // make accounts - FactoryMuffin::create('FireflyIII\Models\Account'); - $revenue = FactoryMuffin::create('FireflyIII\Models\Account'); - $asset = FactoryMuffin::create('FireflyIII\Models\Account'); - - $transfer->transactions[0]->account_id = $asset->id; - $transfer->transactions[0]->amount = 300; - $transfer->transactions[0]->save(); - - $transfer->transactions[1]->account_id = $revenue->id; - $transfer->transactions[1]->amount = -300; - $transfer->transactions[1]->save(); - - // get asset account: - $result = $transfer->expense_account; - - $this->assertEquals($asset->id, $result->id); - } - - /** - * @covers FireflyIII\Models\TransactionJournal::getExpenseAccountAttribute - */ - public function testGetExpenseAccountAttributeWithdrawal() - { - $withdrawalType = FactoryMuffin::create('FireflyIII\Models\TransactionType'); // withdrawal - $withdrawal = FactoryMuffin::create('FireflyIII\Models\TransactionJournal'); - $withdrawal->transaction_type_id = $withdrawalType->id; - $withdrawal->save(); - - // make accounts - FactoryMuffin::create('FireflyIII\Models\Account'); - $revenue = FactoryMuffin::create('FireflyIII\Models\Account'); - $asset = FactoryMuffin::create('FireflyIII\Models\Account'); - - $withdrawal->transactions[0]->account_id = $asset->id; - $withdrawal->transactions[0]->amount = 300; - $withdrawal->transactions[0]->save(); - - $withdrawal->transactions[1]->account_id = $revenue->id; - $withdrawal->transactions[1]->amount = -300; - $withdrawal->transactions[1]->save(); - - // get asset account: - $result = $withdrawal->expense_account; - - $this->assertEquals($asset->id, $result->id); - } - } diff --git a/tests/repositories/AccountRepositoryTest.php b/tests/repositories/AccountRepositoryTest.php index 876a5c4286..6a17b5d564 100644 --- a/tests/repositories/AccountRepositoryTest.php +++ b/tests/repositories/AccountRepositoryTest.php @@ -51,11 +51,21 @@ class AccountRepositoryTest extends TestCase /** * @covers FireflyIII\Repositories\Account\AccountRepository::destroy + * @covers FireflyIII\Providers\EventServiceProvider::boot + * @covers FireflyIII\Providers\EventServiceProvider::registerDeleteEvents */ public function testDestroy() { // create account: - $account = FactoryMuffin::create('FireflyIII\Models\Account'); + $account = FactoryMuffin::create('FireflyIII\Models\Account'); + + // create some transactions and attach them to the account: + for ($i = 0; $i < 5; $i++) { + $transaction = FactoryMuffin::create('FireflyIII\Models\Transaction'); + $transaction->account_id = $account->id; + $transaction->save(); + } + $accountId = $account->id; $this->be($account->user); @@ -462,7 +472,7 @@ class AccountRepositoryTest extends TestCase /* * Transfers can go either way (see the amount) */ - if($i < 4) { + if ($i < 4) { $amount = 100; } else { $amount = -100; diff --git a/tests/repositories/BillRepositoryTest.php b/tests/repositories/BillRepositoryTest.php index 2e22d58e7a..57ef8932e0 100644 --- a/tests/repositories/BillRepositoryTest.php +++ b/tests/repositories/BillRepositoryTest.php @@ -303,6 +303,8 @@ class BillRepositoryTest extends TestCase */ public function testScanMatch() { + $user = FactoryMuffin::create('FireflyIII\User'); + $this->be($user); $bill = FactoryMuffin::create('FireflyIII\Models\Bill'); $bill->date = new Carbon('2012-01-07'); $bill->repeat_freq = 'monthly'; @@ -319,24 +321,6 @@ class BillRepositoryTest extends TestCase $journal->user_id = $bill->user_id; $journal->save(); - // two transactions: - $account1 = FactoryMuffin::create('FireflyIII\Models\Account'); - $account2 = FactoryMuffin::create('FireflyIII\Models\Account'); - Transaction::create( - [ - 'account_id' => $account1->id, - 'transaction_journal_id' => $journal->id, - 'amount' => 100, - ] - ); - Transaction::create( - [ - 'account_id' => $account2->id, - 'transaction_journal_id' => $journal->id, - 'amount' => 100, - ] - ); - $this->object->scan($bill, $journal); $newJournal = TransactionJournal::find($journal->id); diff --git a/tests/repositories/BudgetRepositoryTest.php b/tests/repositories/BudgetRepositoryTest.php index d52716c89f..f172274f1e 100644 --- a/tests/repositories/BudgetRepositoryTest.php +++ b/tests/repositories/BudgetRepositoryTest.php @@ -38,6 +38,7 @@ class BudgetRepositoryTest extends TestCase /** * @covers FireflyIII\Repositories\Budget\BudgetRepository::cleanupBudgets + * @covers FireflyIII\Providers\EventServiceProvider::boot */ public function testCleanupBudgets() { @@ -155,6 +156,8 @@ class BudgetRepositoryTest extends TestCase */ public function testGetCurrentRepetition() { + $user = FactoryMuffin::create('FireflyIII\User'); + $this->be($user); /** @var Budget $budget */ $budget = FactoryMuffin::create('FireflyIII\Models\Budget'); $rep = $this->object->getCurrentRepetition($budget, new Carbon); @@ -210,6 +213,9 @@ class BudgetRepositoryTest extends TestCase */ public function testGetJournals() { + $user = FactoryMuffin::create('FireflyIII\User'); + $this->be($user); + $repetition = FactoryMuffin::create('FireflyIII\Models\LimitRepetition'); $set = $this->object->getJournals($repetition->budgetlimit->budget, $repetition); @@ -294,6 +300,9 @@ class BudgetRepositoryTest extends TestCase */ public function testSpentInPeriodCorrected() { + $user = FactoryMuffin::create('FireflyIII\User'); + $this->be($user); + $budget = FactoryMuffin::create('FireflyIII\Models\Budget'); $amount = $this->object->spentInPeriodCorrected($budget, new Carbon, new Carbon, false); @@ -306,6 +315,9 @@ class BudgetRepositoryTest extends TestCase */ public function testSpentInPeriodCorrectedShared() { + $user = FactoryMuffin::create('FireflyIII\User'); + $this->be($user); + $budget = FactoryMuffin::create('FireflyIII\Models\Budget'); $amount = $this->object->spentInPeriodCorrected($budget, new Carbon, new Carbon, true); diff --git a/tests/repositories/CategoryRepositoryTest.php b/tests/repositories/CategoryRepositoryTest.php index 07f553fbc6..63ed85ee83 100644 --- a/tests/repositories/CategoryRepositoryTest.php +++ b/tests/repositories/CategoryRepositoryTest.php @@ -212,6 +212,8 @@ class CategoryRepositoryTest extends TestCase */ public function testSpentInPeriodSumCorrected() { + $user = FactoryMuffin::create('FireflyIII\User'); + $this->be($user); $category = FactoryMuffin::create('FireflyIII\Models\Category'); $sum = $this->object->spentInPeriodCorrected($category, new Carbon, new Carbon, false); @@ -226,6 +228,8 @@ class CategoryRepositoryTest extends TestCase */ public function testSpentInPeriodSumCorrectedShared() { + $user = FactoryMuffin::create('FireflyIII\User'); + $this->be($user); $category = FactoryMuffin::create('FireflyIII\Models\Category'); $sum = $this->object->spentInPeriodCorrected($category, new Carbon, new Carbon, true); diff --git a/tests/repositories/JournalRepositoryTest.php b/tests/repositories/JournalRepositoryTest.php index a5e32593a7..9216dc9662 100644 --- a/tests/repositories/JournalRepositoryTest.php +++ b/tests/repositories/JournalRepositoryTest.php @@ -54,19 +54,13 @@ class JournalRepositoryTest extends TestCase /** * @covers FireflyIII\Repositories\Journal\JournalRepository::delete + * @covers FireflyIII\Providers\EventServiceProvider::boot + * @covers FireflyIII\Providers\EventServiceProvider::registerDeleteEvents */ public function testDelete() { $journal = FactoryMuffin::create('FireflyIII\Models\TransactionJournal'); - $account = FactoryMuffin::create('FireflyIII\Models\Account'); - $transaction = Transaction::create( - [ - 'account_id' => $account->id, - 'transaction_journal_id' => $journal->id, - 'amount' => 100, - ] - ); - + $transaction = $journal->transactions[0]; $this->object->delete($journal); $this->assertEquals(0, TransactionJournal::where('id', $journal->id)->whereNull('deleted_at')->count()); diff --git a/tests/repositories/PiggyBankRepositoryTest.php b/tests/repositories/PiggyBankRepositoryTest.php index 79fd026f59..e032384047 100644 --- a/tests/repositories/PiggyBankRepositoryTest.php +++ b/tests/repositories/PiggyBankRepositoryTest.php @@ -1,7 +1,7 @@ remindersable_id = $piggyBank->id; + $reminder->remindersable_type = 'FireflyIII\Models\PiggyBank'; + $reminder->save(); $this->object->destroy($piggyBank); $this->assertCount(0, PiggyBank::where('id', $piggyBank->id)->whereNull('deleted_at')->get()); + $this->assertCount(0, Reminder::where('id', $reminder->id)->whereNull('deleted_at')->get()); } @@ -125,6 +134,8 @@ class PiggyBankRepositoryTest extends TestCase /** * @covers FireflyIII\Repositories\PiggyBank\PiggyBankRepository::store + * @covers FireflyIII\Providers\EventServiceProvider::boot + * @covers FireflyIII\Providers\EventServiceProvider::registerCreateEvents */ public function testStore() { @@ -147,6 +158,8 @@ class PiggyBankRepositoryTest extends TestCase /** * @covers FireflyIII\Repositories\PiggyBank\PiggyBankRepository::store + * @covers FireflyIII\Providers\EventServiceProvider::boot + * @covers FireflyIII\Providers\EventServiceProvider::registerCreateEvents */ public function testStoreRedirect() { diff --git a/tests/repositories/TagRepositoryTest.php b/tests/repositories/TagRepositoryTest.php index 7bfd0744dc..23d736d5c0 100644 --- a/tests/repositories/TagRepositoryTest.php +++ b/tests/repositories/TagRepositoryTest.php @@ -176,6 +176,9 @@ class TagRepositoryTest extends TestCase */ public function testConnectPaymentMultipleMatch() { + $user = FactoryMuffin::create('FireflyIII\User'); + $this->be($user); + $withdrawal = FactoryMuffin::create('FireflyIII\Models\TransactionType'); $deposit = FactoryMuffin::create('FireflyIII\Models\TransactionType'); FactoryMuffin::create('FireflyIII\Models\TransactionType'); @@ -232,6 +235,9 @@ class TagRepositoryTest extends TestCase */ public function testConnectPaymentNoMatch() { + $user = FactoryMuffin::create('FireflyIII\User'); + $this->be($user); + $withdrawal = FactoryMuffin::create('FireflyIII\Models\TransactionType'); $deposit = FactoryMuffin::create('FireflyIII\Models\TransactionType'); FactoryMuffin::create('FireflyIII\Models\TransactionType'); @@ -289,6 +295,9 @@ class TagRepositoryTest extends TestCase */ public function testConnectPaymentOneTransfer() { + $user = FactoryMuffin::create('FireflyIII\User'); + $this->be($user); + FactoryMuffin::create('FireflyIII\Models\TransactionType'); FactoryMuffin::create('FireflyIII\Models\TransactionType'); $transfer = FactoryMuffin::create('FireflyIII\Models\TransactionType'); @@ -316,6 +325,9 @@ class TagRepositoryTest extends TestCase */ public function testConnectPaymentOneWithdrawal() { + $user = FactoryMuffin::create('FireflyIII\User'); + $this->be($user); + $withdrawal = FactoryMuffin::create('FireflyIII\Models\TransactionType'); FactoryMuffin::create('FireflyIII\Models\TransactionType'); FactoryMuffin::create('FireflyIII\Models\TransactionType'); @@ -343,6 +355,9 @@ class TagRepositoryTest extends TestCase */ public function testConnectPaymentTwoWithdrawals() { + $user = FactoryMuffin::create('FireflyIII\User'); + $this->be($user); + $withdrawal = FactoryMuffin::create('FireflyIII\Models\TransactionType'); FactoryMuffin::create('FireflyIII\Models\TransactionType'); FactoryMuffin::create('FireflyIII\Models\TransactionType'); @@ -375,6 +390,9 @@ class TagRepositoryTest extends TestCase */ public function testConnectPaymentTwoWithdrawalsSameAccounts() { + $user = FactoryMuffin::create('FireflyIII\User'); + $this->be($user); + $withdrawal = FactoryMuffin::create('FireflyIII\Models\TransactionType'); FactoryMuffin::create('FireflyIII\Models\TransactionType'); FactoryMuffin::create('FireflyIII\Models\TransactionType'); diff --git a/tests/support/AmountSupportTest.php b/tests/support/AmountSupportTest.php new file mode 100644 index 0000000000..9100965109 --- /dev/null +++ b/tests/support/AmountSupportTest.php @@ -0,0 +1,281 @@ +object = new Amount; + $user = FactoryMuffin::create('FireflyIII\User'); + $this->be($user); + } + + /** + * Tears down the fixture, for example, closes a network connection. + * This method is called after a test is executed. + */ + public function tearDown() + { + parent::tearDown(); + } + + /** + * @covers FireflyIII\Support\Amount::formatJournal + */ + public function testFormatJournalColouredTransfer() + { + + + FactoryMuffin::create('FireflyIII\Models\TransactionType'); // withdrawal + FactoryMuffin::create('FireflyIII\Models\TransactionType'); // deposit + /** @var \FireflyIII\Models\TransactionJournal $journal */ + $journal = FactoryMuffin::create('FireflyIII\Models\TransactionJournal'); + $symbol = $journal->transactionCurrency->symbol; + + $result = $this->object->formatJournal($journal, true); + + // transfer is blue: + $this->assertTrue(str_contains($result, '')); + // transfer contains currency code: + $this->assertTrue(str_contains($result, $symbol)); + // all amounts are 100. + $this->assertTrue(str_contains($result, '100')); + } + + /** + * @covers FireflyIII\Support\Amount::formatJournal + */ + public function testFormatJournalUncolouredTransfer() + { + FactoryMuffin::create('FireflyIII\Models\TransactionType'); // withdrawal + FactoryMuffin::create('FireflyIII\Models\TransactionType'); // deposit + /** @var \FireflyIII\Models\TransactionJournal $journal */ + $journal = FactoryMuffin::create('FireflyIII\Models\TransactionJournal'); + $symbol = $journal->transactionCurrency->symbol; + + $result = $this->object->formatJournal($journal, false); + + // transfer is not blue: + $this->assertFalse(str_contains($result, '')); + // transfer contains currency code: + $this->assertTrue(str_contains($result, $symbol)); + // all amounts are 100. + $this->assertTrue(str_contains($result, '100')); + } + + /** + * @covers FireflyIII\Support\Amount::formatJournal + */ + public function testFormatJournalWithSymbol() + { + FactoryMuffin::create('FireflyIII\Models\TransactionType'); // withdrawal + /** @var \FireflyIII\Models\TransactionJournal $journal */ + $journal = FactoryMuffin::create('FireflyIII\Models\TransactionJournal'); + $symbol = $journal->transactionCurrency->symbol; + $journal->symbol = $symbol; + + $result = $this->object->formatJournal($journal, true); + + // transfer is not blue: + $this->assertFalse(str_contains($result, '')); + // transfer contains currency code: + $this->assertTrue(str_contains($result, $symbol)); + // all amounts are 100. + $this->assertTrue(str_contains($result, '100')); + } + + /** + * @covers FireflyIII\Support\Amount::formatJournal + */ + public function testFormatJournalWithdrawal() + { + /** @var \FireflyIII\Models\TransactionJournal $journal */ + $journal = FactoryMuffin::create('FireflyIII\Models\TransactionJournal'); + $symbol = $journal->transactionCurrency->symbol; + + $result = $this->object->formatJournal($journal, true); + + // transfer is not blue: + $this->assertFalse(str_contains($result, '')); + // transfer contains currency code: + $this->assertTrue(str_contains($result, $symbol)); + // all amounts are 100. + $this->assertTrue(str_contains($result, '100')); + } + + /** + * @covers FireflyIII\Support\Amount::formatTransaction + */ + public function testFormatTransaction() + { + // is a withdrawal. + $transaction = FactoryMuffin::create('FireflyIII\Models\Transaction'); + $transaction->amount = -100; + $transaction->save(); + $result = $this->object->formatTransaction($transaction, true); + + + // withdrawal is red: + $this->assertTrue(str_contains($result, '')); + // all amounts are 100. + $this->assertTrue(str_contains($result, '100')); + } + + /** + * @covers FireflyIII\Support\Amount::formatWithSymbol + */ + public function testFormatWithSymbolColouredAboveZero() + { + $amount = 123; + $symbol = 'top'; + $coloured = true; + + $result = $this->object->formatWithSymbol($symbol, $amount, $coloured); + + // has colour: + $this->assertTrue(str_contains($result, '')); + // has symbol: + $this->assertTrue(str_contains($result, $symbol)); + // has amount: + $this->assertTrue(str_contains($result, '123')); + } + + /** + * @covers FireflyIII\Support\Amount::formatWithSymbol + */ + public function testFormatWithSymbolColouredBelowZero() + { + $amount = -123; + $symbol = 'top'; + $coloured = true; + + $result = $this->object->formatWithSymbol($symbol, $amount, $coloured); + + // has colour: + $this->assertTrue(str_contains($result, '')); + // has symbol: + $this->assertTrue(str_contains($result, $symbol)); + // has amount: + $this->assertTrue(str_contains($result, '123')); + } + + /** + * @covers FireflyIII\Support\Amount::formatWithSymbol + */ + public function testFormatWithSymbolColouredZero() + { + $amount = 0.0; + $symbol = 'top'; + $coloured = true; + + $result = $this->object->formatWithSymbol($symbol, $amount, $coloured); + + // has colour: + $this->assertTrue(str_contains($result, '#999')); + // has symbol: + $this->assertTrue(str_contains($result, $symbol)); + // has amount: + $this->assertTrue(str_contains($result, '0')); + } + + /** + * @covers FireflyIII\Support\Amount::formatWithSymbol + */ + public function testFormatWithSymbolNotColoured() + { + $amount = 0; + $symbol = 'top'; + $coloured = false; + + $result = $this->object->formatWithSymbol($symbol, $amount, $coloured); + + // has symbol: + $this->assertTrue(str_contains($result, $symbol)); + // has amount: + $this->assertTrue(str_contains($result, '0')); + } + + /** + * @covers FireflyIII\Support\Amount::getAllCurrencies + */ + public function testGetAllCurrencies() + { + $size = TransactionCurrency::count(); + $list = $this->object->getAllCurrencies(); + $this->assertCount($size, $list); + } + + /** + * @covers FireflyIII\Support\Amount::getCurrencyCode + */ + public function testGetCurrencyCode() + { + $code = $this->object->getCurrencyCode(); + $this->assertEquals('EUR', $code); + } + + /** + * @covers FireflyIII\Support\Amount::getCurrencyCode + */ + public function testGetCurrencyCodeNoSuchCurrency() + { + $user = FactoryMuffin::create('FireflyIII\User'); + $this->be($user); + + // delete any currency preferences: + Preference::where('user_id', $user->id)->delete(); + + // delete transaction currencies: + foreach (TransactionCurrency::get() as $c) { + $c->delete(); + } + + $preference = FactoryMuffin::create('FireflyIII\Models\Preference'); + $preference->user_id = $user->id; + $preference->name = 'currencyPreference'; + $preference->data = 'SOM'; + $preference->save(); + + Preferences::shouldReceive('get')->withArgs(['currencyPreference', 'EUR'])->andReturn($preference); + + $code = $this->object->getCurrencyCode(); + $this->assertEquals('EUR', $code); + } + + /** + * @covers FireflyIII\Support\Amount::getCurrencySymbol + */ + public function testGetCurrencySymbol() + { + $result = $this->object->getCurrencySymbol(); + $this->assertEquals('Xi', $result); + } + + /** + * @covers FireflyIII\Support\Amount::getDefaultCurrency + */ + public function testGetDefaultCurrency() + { + $result = $this->object->getCurrencySymbol(); + $this->assertEquals('Xi', $result); + } + + +} From a0f34a7ce1fac4d2c44eab7c5272ee3bd28508cc Mon Sep 17 00:00:00 2001 From: James Cole Date: Sat, 6 Jun 2015 16:26:26 +0200 Subject: [PATCH 36/47] Fix tests. --- tests/support/AmountSupportTest.php | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/tests/support/AmountSupportTest.php b/tests/support/AmountSupportTest.php index 9100965109..66c4882cc7 100644 --- a/tests/support/AmountSupportTest.php +++ b/tests/support/AmountSupportTest.php @@ -264,8 +264,11 @@ class AmountSupportTest extends TestCase */ public function testGetCurrencySymbol() { + // will the the euro: + $eur = TransactionCurrency::whereCode('EUR')->first(); + $result = $this->object->getCurrencySymbol(); - $this->assertEquals('Xi', $result); + $this->assertEquals($eur->symbol, $result); } /** @@ -273,8 +276,11 @@ class AmountSupportTest extends TestCase */ public function testGetDefaultCurrency() { - $result = $this->object->getCurrencySymbol(); - $this->assertEquals('Xi', $result); + // will the the euro: + $eur = TransactionCurrency::whereCode('EUR')->first(); + + $result = $this->object->getDefaultCurrency(); + $this->assertEquals($eur->id, $result->id); } From 1a1f12799393aadf23d5b5bc93a581d5afed8579 Mon Sep 17 00:00:00 2001 From: James Cole Date: Sat, 6 Jun 2015 17:40:41 +0200 Subject: [PATCH 37/47] Cleanup code. --- app/Support/Twig/General.php | 165 +++++++++++++++++++++++++---------- app/Support/Twig/Journal.php | 87 +++++++++++------- 2 files changed, 174 insertions(+), 78 deletions(-) diff --git a/app/Support/Twig/General.php b/app/Support/Twig/General.php index 81ea504928..cea58f5cef 100644 --- a/app/Support/Twig/General.php +++ b/app/Support/Twig/General.php @@ -28,34 +28,95 @@ class General extends Twig_Extension */ public function getFilters() { - $filters = []; + return [ + $this->formatAmount(), + $this->formatTransaction(), + $this->formatAmountPlain(), + $this->formatJournal(), + $this->balance(), + $this->getAccountRole() + ]; - $filters[] = new Twig_SimpleFilter( - 'formatAmount', function($string) { + } + + /** + * {@inheritDoc} + */ + public function getFunctions() + { + return [ + $this->getCurrencyCode(), + $this->getCurrencySymbol(), + $this->phpdate(), + $this->env(), + $this->activeRoute() + ]; + + } + + /** + * {@inheritDoc} + */ + public function getName() + { + return 'FireflyIII\Support\Twig\General'; + } + + /** + * @return Twig_SimpleFilter + */ + protected function formatAmount() + { + return new Twig_SimpleFilter( + 'formatAmount', function ($string) { return App::make('amount')->format($string); }, ['is_safe' => ['html']] ); + } - $filters[] = new Twig_SimpleFilter( - 'formatTransaction', function(Transaction $transaction) { + /** + * @return Twig_SimpleFilter + */ + protected function formatTransaction() + { + return new Twig_SimpleFilter( + 'formatTransaction', function (Transaction $transaction) { return App::make('amount')->formatTransaction($transaction); }, ['is_safe' => ['html']] ); + } - $filters[] = new Twig_SimpleFilter( - 'formatAmountPlain', function($string) { + /** + * @return Twig_SimpleFilter + */ + protected function formatAmountPlain() + { + return new Twig_SimpleFilter( + 'formatAmountPlain', function ($string) { return App::make('amount')->format($string, false); }, ['is_safe' => ['html']] ); + } - $filters[] = new Twig_SimpleFilter( - 'formatJournal', function($journal) { + /** + * @return Twig_SimpleFilter + */ + protected function formatJournal() + { + return new Twig_SimpleFilter( + 'formatJournal', function ($journal) { return App::make('amount')->formatJournal($journal); }, ['is_safe' => ['html']] ); + } - $filters[] = new Twig_SimpleFilter( - 'balance', function(Account $account = null) { + /** + * @return Twig_SimpleFilter + */ + protected function balance() + { + return new Twig_SimpleFilter( + 'balance', function (Account $account = null) { if (is_null($account)) { return 'NULL'; } @@ -64,51 +125,75 @@ class General extends Twig_Extension return App::make('steam')->balance($account, $date); } ); - - // should be a function but OK - $filters[] = new Twig_SimpleFilter( - 'getAccountRole', function($name) { - return Config::get('firefly.accountRoles.' . $name); - } - ); - - return $filters; } /** - * {@inheritDoc} + * @return Twig_SimpleFilter */ - public function getFunctions() + protected function getAccountRole() { - $functions = []; + return new Twig_SimpleFilter( + 'getAccountRole', function ($name) { + return Config::get('firefly.accountRoles.' . $name); + } + ); + } - $functions[] = new Twig_SimpleFunction( - 'getCurrencyCode', function() { + /** + * @return Twig_SimpleFunction + */ + protected function getCurrencyCode() + { + return new Twig_SimpleFunction( + 'getCurrencyCode', function () { return App::make('amount')->getCurrencyCode(); } ); + } - $functions[] = new Twig_SimpleFunction( - 'getCurrencySymbol', function() { + /** + * @return Twig_SimpleFunction + */ + protected function getCurrencySymbol() + { + return new Twig_SimpleFunction( + 'getCurrencySymbol', function () { return App::make('amount')->getCurrencySymbol(); } ); + } - $functions[] = new Twig_SimpleFunction( - 'phpdate', function($str) { + /** + * @return Twig_SimpleFunction + */ + protected function phpdate() + { + return new Twig_SimpleFunction( + 'phpdate', function ($str) { return date($str); } ); + } - - $functions[] = new Twig_SimpleFunction( - 'env', function($name, $default) { + /** + * @return Twig_SimpleFunction + */ + protected function env() + { + return new Twig_SimpleFunction( + 'env', function ($name, $default) { return env($name, $default); } ); + } - $functions[] = new Twig_SimpleFunction( - 'activeRoute', function($context) { + /** + * @return Twig_SimpleFunction + */ + protected function activeRoute() + { + return new Twig_SimpleFunction( + 'activeRoute', function ($context) { $args = func_get_args(); $route = $args[1]; $what = isset($args[2]) ? $args[2] : false; @@ -133,18 +218,6 @@ class General extends Twig_Extension return 'not-xxx-at-all'; }, ['needs_context' => true] ); - - return $functions; - - - } - - /** - * {@inheritDoc} - */ - public function getName() - { - return 'FireflyIII\Support\Twig\General'; } } diff --git a/app/Support/Twig/Journal.php b/app/Support/Twig/Journal.php index 6a25aaf9b7..99752f36e2 100644 --- a/app/Support/Twig/Journal.php +++ b/app/Support/Twig/Journal.php @@ -19,15 +19,45 @@ class Journal extends Twig_Extension { /** - * @SuppressWarnings(PHPMD.CyclomaticComplexity) * @return array */ public function getFilters() { - $filters = []; + $filters = [$this->typeIcon()]; - $filters[] = new Twig_SimpleFilter( - 'typeIcon', function(TransactionJournal $journal) { + return $filters; + } + + /** + * @return array + */ + public function getFunctions() + { + $functions = [ + $this->invalidJournal(), + $this->relevantTags() + ]; + + return $functions; + } + + /** + * Returns the name of the extension. + * + * @return string The extension name + */ + public function getName() + { + return 'FireflyIII\Support\Twig\Journals'; + } + + /** + * @return Twig_SimpleFilter + */ + protected function typeIcon() + { + return new Twig_SimpleFilter( + 'typeIcon', function (TransactionJournal $journal) { $cache = new CacheProperties(); $cache->addProperty($journal->id); @@ -62,21 +92,15 @@ class Journal extends Twig_Extension }, ['is_safe' => ['html']] ); - - return $filters; } /** - * @SuppressWarnings(PHPMD.CyclomaticComplexity) - * - * @return array + * @return Twig_SimpleFunction */ - public function getFunctions() + protected function invalidJournal() { - $functions = []; - - $functions[] = new Twig_SimpleFunction( - 'invalidJournal', function(TransactionJournal $journal) { + return new Twig_SimpleFunction( + 'invalidJournal', function (TransactionJournal $journal) { if (!isset($journal->transactions[1]) || !isset($journal->transactions[0])) { return true; } @@ -84,20 +108,27 @@ class Journal extends Twig_Extension return false; } ); + } - $functions[] = new Twig_SimpleFunction( - 'relevantTags', function(TransactionJournal $journal) { + /** + * @return Twig_SimpleFunction + */ + protected function relevantTags() + { + return new Twig_SimpleFunction( + 'relevantTags', function (TransactionJournal $journal) { $cache = new CacheProperties; $cache->addProperty('relevantTags'); $cache->addProperty($journal->id); - if($cache->has()) { + if ($cache->has()) { return $cache->get(); // @codeCoverageIgnore } if ($journal->tags->count() == 0) { $string = App::make('amount')->formatJournal($journal); $cache->store($string); + return $string; } @@ -107,9 +138,10 @@ class Journal extends Twig_Extension // return tag formatted for a "balancing act", even if other // tags are present. $amount = App::make('amount')->format($journal->actual_amount, false); - $string = ' ' . $tag->tag . ''; + $string = ' ' . $tag->tag . ''; $cache->store($string); + return $string; } @@ -119,8 +151,9 @@ class Journal extends Twig_Extension if ($tag->tagMode == 'advancePayment' && $journal->transactionType->type == 'Deposit') { $amount = App::make('amount')->formatJournal($journal, false); $string = ' ' . $tag->tag . ''; + . '"> ' . $tag->tag . ''; $cache->store($string); + return $string; } /* @@ -132,6 +165,7 @@ class Journal extends Twig_Extension $string = '' . $amount . ''; $cache->store($string); + return $string; } @@ -140,6 +174,7 @@ class Journal extends Twig_Extension // return the amount: $string = App::make('amount')->formatJournal($journal); $cache->store($string); + return $string; } } @@ -148,17 +183,5 @@ class Journal extends Twig_Extension return 'TODO: ' . $journal->amount; } ); - - return $functions; - } - - /** - * Returns the name of the extension. - * - * @return string The extension name - */ - public function getName() - { - return 'FireflyIII\Support\Twig\Journals'; } } From 40b3097374b383134d6f8a4a49d4f2f1dc1ef7d7 Mon Sep 17 00:00:00 2001 From: James Cole Date: Sat, 6 Jun 2015 23:09:12 +0200 Subject: [PATCH 38/47] Lots of cleanup and stuff. --- app/Helpers/Collection/Bill.php | 2 +- app/Helpers/Collection/Category.php | 2 +- app/Helpers/Collection/Expense.php | 2 +- app/Helpers/Collection/Income.php | 2 +- app/Helpers/Report/ReportHelper.php | 2 +- app/Helpers/Report/ReportQuery.php | 94 ++++++++-------- app/Http/Controllers/AccountController.php | 8 +- app/Http/Controllers/Auth/AuthController.php | 2 +- app/Http/Controllers/BillController.php | 2 +- app/Http/Controllers/BudgetController.php | 2 +- app/Http/Controllers/CategoryController.php | 4 +- .../Controllers/Chart/BudgetController.php | 6 +- .../Controllers/Chart/CategoryController.php | 2 +- app/Http/Controllers/HomeController.php | 8 +- app/Http/Controllers/NewUserController.php | 6 +- app/Http/Controllers/PiggyBankController.php | 10 +- .../Controllers/TransactionController.php | 13 +-- app/Http/Middleware/Reminders.php | 2 +- app/Http/breadcrumbs.php | 102 +++++++++--------- app/Http/routes.php | 46 ++++---- app/Models/Account.php | 4 +- app/Models/AccountMeta.php | 4 +- app/Models/AccountType.php | 2 +- app/Models/Bill.php | 5 +- app/Models/Budget.php | 2 +- app/Models/BudgetLimit.php | 2 +- app/Models/Component.php | 2 +- app/Models/LimitRepetition.php | 2 +- app/Models/Permission.php | 8 +- app/Models/PiggyBank.php | 4 +- app/Models/PiggyBankEvent.php | 2 +- app/Models/PiggyBankRepetition.php | 14 +-- app/Models/Preference.php | 2 +- app/Models/Reminder.php | 6 +- app/Models/Role.php | 8 +- app/Models/Transaction.php | 2 +- app/Models/TransactionCurrency.php | 2 +- app/Models/TransactionGroup.php | 2 +- app/Models/TransactionJournal.php | 1 - app/Models/TransactionRelation.php | 2 +- app/Models/TransactionType.php | 2 +- app/Providers/BusServiceProvider.php | 2 +- app/Providers/EventServiceProvider.php | 18 ++-- app/Providers/FireflyServiceProvider.php | 12 +-- app/Providers/RouteServiceProvider.php | 2 +- .../Category/CategoryRepository.php | 49 ++++----- .../Journal/JournalRepository.php | 2 +- .../PiggyBank/PiggyBankRepository.php | 2 +- .../Reminder/ReminderRepository.php | 40 +++---- .../Shared/ComponentRepository.php | 2 +- app/Repositories/Tag/TagRepository.php | 4 +- app/Services/Registrar.php | 6 +- app/Support/CacheProperties.php | 3 +- app/Support/Navigation.php | 2 +- app/Support/Preferences.php | 4 +- app/Support/Search/Search.php | 12 +-- app/Support/Twig/General.php | 75 +++++++++---- app/Support/Twig/PiggyBank.php | 2 +- app/Support/Twig/Translation.php | 2 +- app/Validation/FireflyValidator.php | 2 +- resources/twig/partials/menu.twig | 48 ++++----- 61 files changed, 361 insertions(+), 323 deletions(-) diff --git a/app/Helpers/Collection/Bill.php b/app/Helpers/Collection/Bill.php index de5b86fc97..34b3205c6b 100644 --- a/app/Helpers/Collection/Bill.php +++ b/app/Helpers/Collection/Bill.php @@ -41,7 +41,7 @@ class Bill public function getBills() { $this->bills->sortBy( - function(BillLine $bill) { + function (BillLine $bill) { $active = intval($bill->getBill()->active) == 0 ? 1 : 0; $name = $bill->getBill()->name; diff --git a/app/Helpers/Collection/Category.php b/app/Helpers/Collection/Category.php index 71af3c2607..84f426487a 100644 --- a/app/Helpers/Collection/Category.php +++ b/app/Helpers/Collection/Category.php @@ -55,7 +55,7 @@ class Category public function getCategories() { $this->categories->sortByDesc( - function(CategoryModel $category) { + function (CategoryModel $category) { return $category->spent; } ); diff --git a/app/Helpers/Collection/Expense.php b/app/Helpers/Collection/Expense.php index f328bfd42a..a66c1ef86d 100644 --- a/app/Helpers/Collection/Expense.php +++ b/app/Helpers/Collection/Expense.php @@ -67,7 +67,7 @@ class Expense public function getExpenses() { $this->expenses->sortByDesc( - function(stdClass $object) { + function (stdClass $object) { return $object->amount; } ); diff --git a/app/Helpers/Collection/Income.php b/app/Helpers/Collection/Income.php index 2b635f8aa4..c3caf9eba7 100644 --- a/app/Helpers/Collection/Income.php +++ b/app/Helpers/Collection/Income.php @@ -68,7 +68,7 @@ class Income public function getIncomes() { $this->incomes->sortByDesc( - function(stdClass $object) { + function (stdClass $object) { return $object->amount; } ); diff --git a/app/Helpers/Report/ReportHelper.php b/app/Helpers/Report/ReportHelper.php index 368c28f50c..4790b1d81c 100644 --- a/app/Helpers/Report/ReportHelper.php +++ b/app/Helpers/Report/ReportHelper.php @@ -66,7 +66,7 @@ class ReportHelper implements ReportHelperInterface // remove cash account, if any: $accounts = $accounts->filter( - function(Account $account) { + function (Account $account) { if ($account->accountType->type != 'Cash account') { return $account; } diff --git a/app/Helpers/Report/ReportQuery.php b/app/Helpers/Report/ReportQuery.php index 017d04ef07..2e720e0653 100644 --- a/app/Helpers/Report/ReportQuery.php +++ b/app/Helpers/Report/ReportQuery.php @@ -35,15 +35,15 @@ class ReportQuery implements ReportQueryInterface $query = $this->queryJournalsWithTransactions($start, $end); if ($includeShared === false) { $query->where( - function(Builder $query) { + function (Builder $query) { $query->where( - function(Builder $q) { // only get withdrawals not from a shared account + function (Builder $q) { // only get withdrawals not from a shared account $q->where('transaction_types.type', 'Withdrawal'); $q->where('acm_from.data', '!=', '"sharedAsset"'); } ); $query->orWhere( - function(Builder $q) { // and transfers from a shared account. + function (Builder $q) { // and transfers from a shared account. $q->where('transaction_types.type', 'Transfer'); $q->where('acm_to.data', '=', '"sharedAsset"'); } @@ -61,14 +61,14 @@ class ReportQuery implements ReportQueryInterface ); $data->each( - function(TransactionJournal $journal) { + function (TransactionJournal $journal) { if (intval($journal->account_encrypted) == 1) { $journal->name = Crypt::decrypt($journal->name); } } ); $data = $data->filter( - function(TransactionJournal $journal) { + function (TransactionJournal $journal) { if ($journal->amount != 0) { return $journal; } @@ -92,26 +92,26 @@ class ReportQuery implements ReportQueryInterface public function getAllAccounts(Carbon $start, Carbon $end, $includeShared = false) { $query = Auth::user()->accounts()->orderBy('accounts.name', 'ASC') - ->accountTypeIn(['Default account', 'Asset account', 'Cash account']); + ->accountTypeIn(['Default account', 'Asset account', 'Cash account']); if ($includeShared === false) { $query->leftJoin( 'account_meta', function (JoinClause $join) { $join->on('account_meta.account_id', '=', 'accounts.id')->where('account_meta.name', '=', 'accountRole'); } ) - ->orderBy('accounts.name', 'ASC') - ->where( - function (Builder $query) { + ->orderBy('accounts.name', 'ASC') + ->where( + function (Builder $query) { - $query->where('account_meta.data', '!=', '"sharedAsset"'); - $query->orWhereNull('account_meta.data'); + $query->where('account_meta.data', '!=', '"sharedAsset"'); + $query->orWhereNull('account_meta.data'); - } - ); + } + ); } $set = $query->get(['accounts.*']); $set->each( - function(Account $account) use ($start, $end) { + function (Account $account) use ($start, $end) { /** * The balance for today always incorporates transactions * made on today. So to get todays "start" balance, we sub one @@ -152,15 +152,15 @@ class ReportQuery implements ReportQueryInterface // only get deposits not to a shared account // and transfers to a shared account. $query->where( - function(Builder $query) { + function (Builder $query) { $query->where( - function(Builder $q) { + function (Builder $q) { $q->where('transaction_types.type', 'Deposit'); $q->where('acm_to.data', '!=', '"sharedAsset"'); } ); $query->orWhere( - function(Builder $q) { + function (Builder $q) { $q->where('transaction_types.type', 'Transfer'); $q->where('acm_from.data', '=', '"sharedAsset"'); } @@ -179,14 +179,14 @@ class ReportQuery implements ReportQueryInterface ); $data->each( - function(TransactionJournal $journal) { + function (TransactionJournal $journal) { if (intval($journal->account_encrypted) == 1) { $journal->name = Crypt::decrypt($journal->name); } } ); $data = $data->filter( - function(TransactionJournal $journal) { + function (TransactionJournal $journal) { if ($journal->amount != 0) { return $journal; } @@ -212,16 +212,16 @@ class ReportQuery implements ReportQueryInterface { return floatval( - Auth::user()->transactionjournals() - ->leftJoin('transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id') - ->leftJoin('budget_transaction_journal', 'budget_transaction_journal.transaction_journal_id', '=', 'transaction_journals.id') - ->transactionTypes(['Withdrawal']) - ->where('transactions.account_id', $account->id) - ->before($end) - ->after($start) - ->where('budget_transaction_journal.budget_id', $budget->id) - ->get(['transaction_journals.*'])->sum('amount') - ) * -1; + Auth::user()->transactionjournals() + ->leftJoin('transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id') + ->leftJoin('budget_transaction_journal', 'budget_transaction_journal.transaction_journal_id', '=', 'transaction_journals.id') + ->transactionTypes(['Withdrawal']) + ->where('transactions.account_id', $account->id) + ->before($end) + ->after($start) + ->where('budget_transaction_journal.budget_id', $budget->id) + ->get(['transaction_journals.*'])->sum('amount') + ) * -1; } /** @@ -260,24 +260,24 @@ class ReportQuery implements ReportQueryInterface $join->on('t_from.transaction_journal_id', '=', 'transaction_journals.id')->where('t_from.amount', '<', 0); } ) - ->leftJoin('accounts as ac_from', 't_from.account_id', '=', 'ac_from.id') - ->leftJoin( - 'account_meta as acm_from', function (JoinClause $join) { - $join->on('ac_from.id', '=', 'acm_from.account_id')->where('acm_from.name', '=', 'accountRole'); - } - ) - ->leftJoin( - 'transactions as t_to', function (JoinClause $join) { - $join->on('t_to.transaction_journal_id', '=', 'transaction_journals.id')->where('t_to.amount', '>', 0); - } - ) - ->leftJoin('accounts as ac_to', 't_to.account_id', '=', 'ac_to.id') - ->leftJoin( - 'account_meta as acm_to', function (JoinClause $join) { - $join->on('ac_to.id', '=', 'acm_to.account_id')->where('acm_to.name', '=', 'accountRole'); - } - ) - ->leftJoin('transaction_types', 'transaction_types.id', '=', 'transaction_journals.transaction_type_id'); + ->leftJoin('accounts as ac_from', 't_from.account_id', '=', 'ac_from.id') + ->leftJoin( + 'account_meta as acm_from', function (JoinClause $join) { + $join->on('ac_from.id', '=', 'acm_from.account_id')->where('acm_from.name', '=', 'accountRole'); + } + ) + ->leftJoin( + 'transactions as t_to', function (JoinClause $join) { + $join->on('t_to.transaction_journal_id', '=', 'transaction_journals.id')->where('t_to.amount', '>', 0); + } + ) + ->leftJoin('accounts as ac_to', 't_to.account_id', '=', 'ac_to.id') + ->leftJoin( + 'account_meta as acm_to', function (JoinClause $join) { + $join->on('ac_to.id', '=', 'acm_to.account_id')->where('acm_to.name', '=', 'accountRole'); + } + ) + ->leftJoin('transaction_types', 'transaction_types.id', '=', 'transaction_journals.transaction_type_id'); $query->before($end)->after($start)->where('transaction_journals.user_id', Auth::user()->id); return $query; diff --git a/app/Http/Controllers/AccountController.php b/app/Http/Controllers/AccountController.php index d431fe4267..be1a8545c8 100644 --- a/app/Http/Controllers/AccountController.php +++ b/app/Http/Controllers/AccountController.php @@ -156,7 +156,7 @@ class AccountController extends Controller $start = clone Session::get('start', Carbon::now()->startOfMonth()); $start->subDay(); $accounts->each( - function(Account $account) use ($start, $repository) { + function (Account $account) use ($start, $repository) { $account->lastActivityDate = $repository->getLastActivity($account); $account->startBalance = Steam::balance($account, $start); $account->endBalance = Steam::balance($account, clone Session::get('end', Carbon::now()->endOfMonth())); @@ -201,11 +201,11 @@ class AccountController extends Controller 'user' => Auth::user()->id, 'accountRole' => $request->input('accountRole'), 'openingBalance' => floatval($request->input('openingBalance')), - 'openingBalanceDate' => new Carbon((string) $request->input('openingBalanceDate')), + 'openingBalanceDate' => new Carbon((string)$request->input('openingBalanceDate')), 'openingBalanceCurrency' => intval($request->input('balance_currency_id')), ]; - $account = $repository->store($accountData); + $account = $repository->store($accountData); Session::flash('success', 'New account "' . $account->name . '" stored!'); Preferences::mark(); @@ -240,7 +240,7 @@ class AccountController extends Controller 'accountRole' => $request->input('accountRole'), 'virtualBalance' => floatval($request->input('virtualBalance')), 'openingBalance' => floatval($request->input('openingBalance')), - 'openingBalanceDate' => new Carbon((string) $request->input('openingBalanceDate')), + 'openingBalanceDate' => new Carbon((string)$request->input('openingBalanceDate')), 'openingBalanceCurrency' => intval($request->input('balance_currency_id')), 'ccType' => $request->input('ccType'), 'ccMonthlyPaymentDate' => $request->input('ccMonthlyPaymentDate'), diff --git a/app/Http/Controllers/Auth/AuthController.php b/app/Http/Controllers/Auth/AuthController.php index e4031afc1e..4330203b5c 100644 --- a/app/Http/Controllers/Auth/AuthController.php +++ b/app/Http/Controllers/Auth/AuthController.php @@ -95,7 +95,7 @@ class AuthController extends Controller // send email. Mail::send( - 'emails.registered', [], function(Message $message) use ($email) { + 'emails.registered', [], function (Message $message) use ($email) { $message->to($email, $email)->subject('Welcome to Firefly III!'); } ); diff --git a/app/Http/Controllers/BillController.php b/app/Http/Controllers/BillController.php index 6d96298615..045b242b97 100644 --- a/app/Http/Controllers/BillController.php +++ b/app/Http/Controllers/BillController.php @@ -112,7 +112,7 @@ class BillController extends Controller { $bills = $repository->getBills(); $bills->each( - function(Bill $bill) use ($repository) { + function (Bill $bill) use ($repository) { $bill->nextExpectedMatch = $repository->nextExpectedMatch($bill); $bill->lastFoundMatch = $repository->lastFoundMatch($bill); } diff --git a/app/Http/Controllers/BudgetController.php b/app/Http/Controllers/BudgetController.php index 48ca342654..a58248e9fc 100644 --- a/app/Http/Controllers/BudgetController.php +++ b/app/Http/Controllers/BudgetController.php @@ -245,7 +245,7 @@ class BudgetController extends Controller 'name' => $request->input('name'), 'user' => Auth::user()->id, ]; - $budget = $repository->store($budgetData); + $budget = $repository->store($budgetData); Session::flash('success', 'New budget "' . $budget->name . '" stored!'); Preferences::mark(); diff --git a/app/Http/Controllers/CategoryController.php b/app/Http/Controllers/CategoryController.php index 6de44dbba9..b6f016f272 100644 --- a/app/Http/Controllers/CategoryController.php +++ b/app/Http/Controllers/CategoryController.php @@ -114,7 +114,7 @@ class CategoryController extends Controller $categories = $repository->getCategories(); $categories->each( - function(Category $category) use ($repository) { + function (Category $category) use ($repository) { $category->lastActivity = $repository->getLatestActivity($category); } ); @@ -167,7 +167,7 @@ class CategoryController extends Controller 'name' => $request->input('name'), 'user' => Auth::user()->id, ]; - $category = $repository->store($categoryData); + $category = $repository->store($categoryData); Session::flash('success', 'New category "' . $category->name . '" stored!'); Preferences::mark(); diff --git a/app/Http/Controllers/Chart/BudgetController.php b/app/Http/Controllers/Chart/BudgetController.php index a10239f5cc..517f9e56f9 100644 --- a/app/Http/Controllers/Chart/BudgetController.php +++ b/app/Http/Controllers/Chart/BudgetController.php @@ -177,9 +177,9 @@ class BudgetController extends Controller $overspent = $expenses > floatval($repetition->amount) ? $expenses - floatval($repetition->amount) : 0; $allEntries->push( [$budget->name . ' (' . $repetition->startdate->formatLocalized($this->monthAndDayFormat) . ')', - $left, - $spent, - $overspent + $left, + $spent, + $overspent ] ); } diff --git a/app/Http/Controllers/Chart/CategoryController.php b/app/Http/Controllers/Chart/CategoryController.php index ab9102e7a9..b7c4bdb800 100644 --- a/app/Http/Controllers/Chart/CategoryController.php +++ b/app/Http/Controllers/Chart/CategoryController.php @@ -92,7 +92,7 @@ class CategoryController extends Controller // sort by callback: uasort( $set, - function($left, $right) { + function ($left, $right) { if ($left['sum'] == $right['sum']) { return 0; } diff --git a/app/Http/Controllers/HomeController.php b/app/Http/Controllers/HomeController.php index 83ab8ffa33..6db95ea8ef 100644 --- a/app/Http/Controllers/HomeController.php +++ b/app/Http/Controllers/HomeController.php @@ -67,8 +67,8 @@ class HomeController extends Controller $start = Session::get('start', Carbon::now()->startOfMonth()); $end = Session::get('end', Carbon::now()->endOfMonth()); - $accounts = $repository->getFrontpageAccounts($frontPage); - $savings = $repository->getSavingsAccounts(); + $accounts = $repository->getFrontpageAccounts($frontPage); + $savings = $repository->getSavingsAccounts(); $piggyBankAccounts = $repository->getPiggyBankAccounts(); @@ -83,8 +83,8 @@ class HomeController extends Controller if ($sum != 0) { Session::flash( 'error', 'Your transactions are unbalanced. This means a' - . ' withdrawal, deposit or transfer was not stored properly. ' - . 'Please check your accounts and transactions for errors.' + . ' withdrawal, deposit or transfer was not stored properly. ' + . 'Please check your accounts and transactions for errors.' ); } diff --git a/app/Http/Controllers/NewUserController.php b/app/Http/Controllers/NewUserController.php index 684a232a23..563bf81e28 100644 --- a/app/Http/Controllers/NewUserController.php +++ b/app/Http/Controllers/NewUserController.php @@ -96,11 +96,11 @@ class NewUserController extends Controller 'openingBalanceDate' => null, 'openingBalanceCurrency' => intval($request->input('balance_currency_id')), ]; - $creditCard = $repository->store($creditAccount); + $creditCard = $repository->store($creditAccount); // store meta for CC: - AccountMeta::create(['name' => 'ccType', 'data' => 'monthlyFull', 'account_id' => $creditCard->id, ]); - AccountMeta::create(['name' => 'ccMonthlyPaymentDate', 'data' => Carbon::now()->year . '-01-01', 'account_id' => $creditCard->id, ]); + AccountMeta::create(['name' => 'ccType', 'data' => 'monthlyFull', 'account_id' => $creditCard->id,]); + AccountMeta::create(['name' => 'ccMonthlyPaymentDate', 'data' => Carbon::now()->year . '-01-01', 'account_id' => $creditCard->id,]); } Session::flash('success', 'New account(s) created!'); diff --git a/app/Http/Controllers/PiggyBankController.php b/app/Http/Controllers/PiggyBankController.php index f9bc5f87c6..381f1c544c 100644 --- a/app/Http/Controllers/PiggyBankController.php +++ b/app/Http/Controllers/PiggyBankController.php @@ -139,11 +139,11 @@ class PiggyBankController extends Controller $targetDate = $targetDate->format('Y-m-d'); } $preFilled = ['name' => $piggyBank->name, - 'account_id' => $piggyBank->account_id, - 'targetamount' => $piggyBank->targetamount, - 'targetdate' => $targetDate, - 'reminder' => $piggyBank->reminder, - 'remind_me' => intval($piggyBank->remind_me) == 1 && !is_null($piggyBank->reminder) ? true : false + 'account_id' => $piggyBank->account_id, + 'targetamount' => $piggyBank->targetamount, + 'targetdate' => $targetDate, + 'reminder' => $piggyBank->reminder, + 'remind_me' => intval($piggyBank->remind_me) == 1 && !is_null($piggyBank->reminder) ? true : false ]; Session::flash('preFilled', $preFilled); Session::flash('gaEventCategory', 'piggy-banks'); diff --git a/app/Http/Controllers/TransactionController.php b/app/Http/Controllers/TransactionController.php index 59cbb56219..6eee693adf 100644 --- a/app/Http/Controllers/TransactionController.php +++ b/app/Http/Controllers/TransactionController.php @@ -80,15 +80,15 @@ class TransactionController extends Controller */ public function delete(TransactionJournal $journal) { - $type = strtolower($journal->transactionType->type); - $subTitle = trans('firefly.delete_' . $type, ['description' => $journal->description]); + $what = strtolower($journal->transactionType->type); + $subTitle = trans('firefly.delete_' . $what, ['description' => $journal->description]); // put previous url in session Session::put('transactions.delete.url', URL::previous()); Session::flash('gaEventCategory', 'transactions'); - Session::flash('gaEventAction', 'delete-' . $type); + Session::flash('gaEventAction', 'delete-' . $what); - return view('transactions.delete', compact('journal', 'subTitle')); + return view('transactions.delete', compact('journal', 'subTitle','what')); } @@ -253,14 +253,15 @@ class TransactionController extends Controller public function show(JournalRepositoryInterface $repository, TransactionJournal $journal) { $journal->transactions->each( - function(Transaction $t) use ($journal, $repository) { + function (Transaction $t) use ($journal, $repository) { $t->before = $repository->getAmountBefore($journal, $t); $t->after = $t->before + $t->amount; } ); + $what = strtolower($journal->transactionType->type); $subTitle = trans('firefly.' . $journal->transactionType->type) . ' "' . e($journal->description) . '"'; - return view('transactions.show', compact('journal', 'subTitle')); + return view('transactions.show', compact('journal', 'subTitle','what')); } /** diff --git a/app/Http/Middleware/Reminders.php b/app/Http/Middleware/Reminders.php index c74b4f35bc..0be752e89e 100644 --- a/app/Http/Middleware/Reminders.php +++ b/app/Http/Middleware/Reminders.php @@ -83,7 +83,7 @@ class Reminders // get and list active reminders: $reminders = $user->reminders()->today()->get(); $reminders->each( - function(Reminder $reminder) use ($helper) { + function (Reminder $reminder) use ($helper) { $reminder->description = $helper->getReminderText($reminder); } ); diff --git a/app/Http/breadcrumbs.php b/app/Http/breadcrumbs.php index 80aa857876..fd8e5a146f 100644 --- a/app/Http/breadcrumbs.php +++ b/app/Http/breadcrumbs.php @@ -17,7 +17,7 @@ use FireflyIII\Models\TransactionJournal; */ Breadcrumbs::register( 'home', - function(Generator $breadcrumbs) { + function (Generator $breadcrumbs) { $breadcrumbs->push(trans('breadcrumbs.home'), route('index')); } @@ -25,7 +25,7 @@ Breadcrumbs::register( Breadcrumbs::register( 'index', - function(Generator $breadcrumbs) { + function (Generator $breadcrumbs) { $breadcrumbs->push(trans('breadcrumbs.home'), route('index')); } @@ -34,21 +34,21 @@ Breadcrumbs::register( // accounts Breadcrumbs::register( - 'accounts.index', function(Generator $breadcrumbs, $what) { + 'accounts.index', function (Generator $breadcrumbs, $what) { $breadcrumbs->parent('home'); $breadcrumbs->push(trans('breadcrumbs.' . strtolower(e($what)) . '_accounts'), route('accounts.index', [$what])); } ); Breadcrumbs::register( - 'accounts.create', function(Generator $breadcrumbs, $what) { + 'accounts.create', function (Generator $breadcrumbs, $what) { $breadcrumbs->parent('accounts.index', $what); $breadcrumbs->push(trans('breadcrumbs.new_' . strtolower(e($what)) . '_account'), route('accounts.create', [$what])); } ); Breadcrumbs::register( - 'accounts.show', function(Generator $breadcrumbs, Account $account) { + 'accounts.show', function (Generator $breadcrumbs, Account $account) { $what = Config::get('firefly.shortNamesByFullName.' . $account->accountType->type); @@ -58,7 +58,7 @@ Breadcrumbs::register( } ); Breadcrumbs::register( - 'accounts.delete', function(Generator $breadcrumbs, Account $account) { + 'accounts.delete', function (Generator $breadcrumbs, Account $account) { $breadcrumbs->parent('accounts.show', $account); $breadcrumbs->push(trans('breadcrumbs.delete_account', ['name' => e($account->name)]), route('accounts.delete', [$account->id])); } @@ -66,7 +66,7 @@ Breadcrumbs::register( Breadcrumbs::register( - 'accounts.edit', function(Generator $breadcrumbs, Account $account) { + 'accounts.edit', function (Generator $breadcrumbs, Account $account) { $breadcrumbs->parent('accounts.show', $account); $what = Config::get('firefly.shortNamesByFullName.' . $account->accountType->type); @@ -76,40 +76,40 @@ Breadcrumbs::register( // budgets. Breadcrumbs::register( - 'budgets.index', function(Generator $breadcrumbs) { + 'budgets.index', function (Generator $breadcrumbs) { $breadcrumbs->parent('home'); $breadcrumbs->push(trans('breadcrumbs.budgets'), route('budgets.index')); } ); Breadcrumbs::register( - 'budgets.create', function(Generator $breadcrumbs) { + 'budgets.create', function (Generator $breadcrumbs) { $breadcrumbs->parent('budgets.index'); $breadcrumbs->push(trans('breadcrumbs.newBudget'), route('budgets.create')); } ); Breadcrumbs::register( - 'budgets.edit', function(Generator $breadcrumbs, Budget $budget) { + 'budgets.edit', function (Generator $breadcrumbs, Budget $budget) { $breadcrumbs->parent('budgets.show', $budget); $breadcrumbs->push(trans('breadcrumbs.edit_budget', ['name' => e($budget->name)]), route('budgets.edit', [$budget->id])); } ); Breadcrumbs::register( - 'budgets.delete', function(Generator $breadcrumbs, Budget $budget) { + 'budgets.delete', function (Generator $breadcrumbs, Budget $budget) { $breadcrumbs->parent('budgets.show', $budget); $breadcrumbs->push(trans('breadcrumbs.delete_budget', ['name' => e($budget->name)]), route('budgets.delete', [$budget->id])); } ); Breadcrumbs::register( - 'budgets.noBudget', function(Generator $breadcrumbs, $subTitle) { + 'budgets.noBudget', function (Generator $breadcrumbs, $subTitle) { $breadcrumbs->parent('budgets.index'); $breadcrumbs->push($subTitle, route('budgets.noBudget')); } ); Breadcrumbs::register( - 'budgets.show', function(Generator $breadcrumbs, Budget $budget, LimitRepetition $repetition = null) { + 'budgets.show', function (Generator $breadcrumbs, Budget $budget, LimitRepetition $repetition = null) { $breadcrumbs->parent('budgets.index'); $breadcrumbs->push(e($budget->name), route('budgets.show', [$budget->id])); if (!is_null($repetition) && !is_null($repetition->id)) { @@ -122,33 +122,33 @@ Breadcrumbs::register( // categories Breadcrumbs::register( - 'categories.index', function(Generator $breadcrumbs) { + 'categories.index', function (Generator $breadcrumbs) { $breadcrumbs->parent('home'); $breadcrumbs->push(trans('breadcrumbs.categories'), route('categories.index')); } ); Breadcrumbs::register( - 'categories.create', function(Generator $breadcrumbs) { + 'categories.create', function (Generator $breadcrumbs) { $breadcrumbs->parent('categories.index'); $breadcrumbs->push(trans('breadcrumbs.newCategory'), route('categories.create')); } ); Breadcrumbs::register( - 'categories.edit', function(Generator $breadcrumbs, Category $category) { + 'categories.edit', function (Generator $breadcrumbs, Category $category) { $breadcrumbs->parent('categories.show', $category); $breadcrumbs->push(trans('breadcrumbs.edit_category', ['name' => e($category->name)]), route('categories.edit', [$category->id])); } ); Breadcrumbs::register( - 'categories.delete', function(Generator $breadcrumbs, Category $category) { + 'categories.delete', function (Generator $breadcrumbs, Category $category) { $breadcrumbs->parent('categories.show', $category); $breadcrumbs->push(trans('breadcrumbs.delete_category', ['name' => e($category->name)]), route('categories.delete', [$category->id])); } ); Breadcrumbs::register( - 'categories.show', function(Generator $breadcrumbs, Category $category) { + 'categories.show', function (Generator $breadcrumbs, Category $category) { $breadcrumbs->parent('categories.index'); $breadcrumbs->push(e($category->name), route('categories.show', [$category->id])); @@ -156,7 +156,7 @@ Breadcrumbs::register( ); Breadcrumbs::register( - 'categories.noCategory', function(Generator $breadcrumbs, $subTitle) { + 'categories.noCategory', function (Generator $breadcrumbs, $subTitle) { $breadcrumbs->parent('categories.index'); $breadcrumbs->push($subTitle, route('categories.noCategory')); } @@ -164,20 +164,20 @@ Breadcrumbs::register( // currencies. Breadcrumbs::register( - 'currency.index', function(Generator $breadcrumbs) { + 'currency.index', function (Generator $breadcrumbs) { $breadcrumbs->parent('home'); $breadcrumbs->push(trans('breadcrumbs.currencies'), route('currency.index')); } ); Breadcrumbs::register( - 'currency.edit', function(Generator $breadcrumbs, TransactionCurrency $currency) { + 'currency.edit', function (Generator $breadcrumbs, TransactionCurrency $currency) { $breadcrumbs->parent('currency.index'); $breadcrumbs->push(trans('breadcrumbs.edit_currency', ['name' => e($currency->name)]), route('currency.edit', [$currency->id])); } ); Breadcrumbs::register( - 'currency.delete', function(Generator $breadcrumbs, TransactionCurrency $currency) { + 'currency.delete', function (Generator $breadcrumbs, TransactionCurrency $currency) { $breadcrumbs->parent('currency.index'); $breadcrumbs->push(trans('breadcrumbs.delete_currency', ['name' => e($currency->name)]), route('currency.delete', [$currency->id])); } @@ -186,33 +186,33 @@ Breadcrumbs::register( // piggy banks Breadcrumbs::register( - 'piggy-banks.index', function(Generator $breadcrumbs) { + 'piggy-banks.index', function (Generator $breadcrumbs) { $breadcrumbs->parent('home'); $breadcrumbs->push(trans('breadcrumbs.piggyBanks'), route('piggy-banks.index')); } ); Breadcrumbs::register( - 'piggy-banks.create', function(Generator $breadcrumbs) { + 'piggy-banks.create', function (Generator $breadcrumbs) { $breadcrumbs->parent('piggy-banks.index'); $breadcrumbs->push(trans('breadcrumbs.newPiggyBank'), route('piggy-banks.create')); } ); Breadcrumbs::register( - 'piggy-banks.edit', function(Generator $breadcrumbs, PiggyBank $piggyBank) { + 'piggy-banks.edit', function (Generator $breadcrumbs, PiggyBank $piggyBank) { $breadcrumbs->parent('piggy-banks.show', $piggyBank); $breadcrumbs->push(trans('breadcrumbs.edit_piggyBank', ['name' => e($piggyBank->name)]), route('piggy-banks.edit', [$piggyBank->id])); } ); Breadcrumbs::register( - 'piggy-banks.delete', function(Generator $breadcrumbs, PiggyBank $piggyBank) { + 'piggy-banks.delete', function (Generator $breadcrumbs, PiggyBank $piggyBank) { $breadcrumbs->parent('piggy-banks.show', $piggyBank); $breadcrumbs->push(trans('breadcrumbs.delete_piggyBank', ['name' => e($piggyBank->name)]), route('piggy-banks.delete', [$piggyBank->id])); } ); Breadcrumbs::register( - 'piggy-banks.show', function(Generator $breadcrumbs, PiggyBank $piggyBank) { + 'piggy-banks.show', function (Generator $breadcrumbs, PiggyBank $piggyBank) { $breadcrumbs->parent('piggy-banks.index'); $breadcrumbs->push(e($piggyBank->name), route('piggy-banks.show', [$piggyBank->id])); @@ -221,7 +221,7 @@ Breadcrumbs::register( // preferences Breadcrumbs::register( - 'preferences', function(Generator $breadcrumbs) { + 'preferences', function (Generator $breadcrumbs) { $breadcrumbs->parent('home'); $breadcrumbs->push(trans('breadcrumbs.preferences'), route('preferences')); @@ -230,14 +230,14 @@ Breadcrumbs::register( // profile Breadcrumbs::register( - 'profile', function(Generator $breadcrumbs) { + 'profile', function (Generator $breadcrumbs) { $breadcrumbs->parent('home'); $breadcrumbs->push(trans('breadcrumbs.profile'), route('profile')); } ); Breadcrumbs::register( - 'change-password', function(Generator $breadcrumbs) { + 'change-password', function (Generator $breadcrumbs) { $breadcrumbs->parent('profile'); $breadcrumbs->push(trans('breadcrumbs.changePassword'), route('change-password')); @@ -246,33 +246,33 @@ Breadcrumbs::register( // bills Breadcrumbs::register( - 'bills.index', function(Generator $breadcrumbs) { + 'bills.index', function (Generator $breadcrumbs) { $breadcrumbs->parent('home'); $breadcrumbs->push(trans('breadcrumbs.bills'), route('bills.index')); } ); Breadcrumbs::register( - 'bills.create', function(Generator $breadcrumbs) { + 'bills.create', function (Generator $breadcrumbs) { $breadcrumbs->parent('bills.index'); $breadcrumbs->push(trans('breadcrumbs.newBill'), route('bills.create')); } ); Breadcrumbs::register( - 'bills.edit', function(Generator $breadcrumbs, Bill $bill) { + 'bills.edit', function (Generator $breadcrumbs, Bill $bill) { $breadcrumbs->parent('bills.show', $bill); $breadcrumbs->push(trans('breadcrumbs.edit_bill', ['name' => e($bill->name)]), route('bills.edit', [$bill->id])); } ); Breadcrumbs::register( - 'bills.delete', function(Generator $breadcrumbs, Bill $bill) { + 'bills.delete', function (Generator $breadcrumbs, Bill $bill) { $breadcrumbs->parent('bills.show', $bill); $breadcrumbs->push(trans('breadcrumbs.delete_bill', ['name' => e($bill->name)]), route('bills.delete', [$bill->id])); } ); Breadcrumbs::register( - 'bills.show', function(Generator $breadcrumbs, Bill $bill) { + 'bills.show', function (Generator $breadcrumbs, Bill $bill) { $breadcrumbs->parent('bills.index'); $breadcrumbs->push(e($bill->name), route('bills.show', [$bill->id])); @@ -281,7 +281,7 @@ Breadcrumbs::register( // reminders Breadcrumbs::register( - 'reminders.index', function(Generator $breadcrumbs) { + 'reminders.index', function (Generator $breadcrumbs) { $breadcrumbs->parent('home'); $breadcrumbs->push(trans('breadcrumbs.reminders'), route('reminders.index')); @@ -290,7 +290,7 @@ Breadcrumbs::register( // reminders Breadcrumbs::register( - 'reminders.show', function(Generator $breadcrumbs, Reminder $reminder) { + 'reminders.show', function (Generator $breadcrumbs, Reminder $reminder) { $breadcrumbs->parent('reminders.index'); $breadcrumbs->push(trans('breadcrumbs.reminder', ['id' => e($reminder->id)]), route('reminders.show', [$reminder->id])); @@ -300,14 +300,14 @@ Breadcrumbs::register( // reports Breadcrumbs::register( - 'reports.index', function(Generator $breadcrumbs) { + 'reports.index', function (Generator $breadcrumbs) { $breadcrumbs->parent('home'); $breadcrumbs->push(trans('breadcrumbs.reports'), route('reports.index')); } ); Breadcrumbs::register( - 'reports.year', function(Generator $breadcrumbs, Carbon $date, $shared) { + 'reports.year', function (Generator $breadcrumbs, Carbon $date, $shared) { $breadcrumbs->parent('reports.index'); if ($shared) { $title = trans('breadcrumbs.yearly_report_shared', ['date' => $date->year]); @@ -319,7 +319,7 @@ Breadcrumbs::register( ); Breadcrumbs::register( - 'reports.month', function(Generator $breadcrumbs, Carbon $date, $shared) { + 'reports.month', function (Generator $breadcrumbs, Carbon $date, $shared) { $breadcrumbs->parent('reports.year', $date, $shared); if ($shared) { @@ -334,7 +334,7 @@ Breadcrumbs::register( // search Breadcrumbs::register( - 'search', function(Generator $breadcrumbs, $query) { + 'search', function (Generator $breadcrumbs, $query) { $breadcrumbs->parent('home'); $breadcrumbs->push(trans('breadcrumbs.searchResult', ['query' => e($query)]), route('search')); } @@ -342,33 +342,33 @@ Breadcrumbs::register( // transactions Breadcrumbs::register( - 'transactions.index', function(Generator $breadcrumbs, $what) { + 'transactions.index', function (Generator $breadcrumbs, $what) { $breadcrumbs->parent('home'); $breadcrumbs->push(trans('breadcrumbs.' . $what . '_list'), route('transactions.index', [$what])); } ); Breadcrumbs::register( - 'transactions.create', function(Generator $breadcrumbs, $what) { + 'transactions.create', function (Generator $breadcrumbs, $what) { $breadcrumbs->parent('transactions.index', $what); $breadcrumbs->push(trans('breadcrumbs.create_' . e($what)), route('transactions.create', [$what])); } ); Breadcrumbs::register( - 'transactions.edit', function(Generator $breadcrumbs, TransactionJournal $journal) { + 'transactions.edit', function (Generator $breadcrumbs, TransactionJournal $journal) { $breadcrumbs->parent('transactions.show', $journal); $breadcrumbs->push(trans('breadcrumbs.edit_journal', ['description' => $journal->description]), route('transactions.edit', [$journal->id])); } ); Breadcrumbs::register( - 'transactions.delete', function(Generator $breadcrumbs, TransactionJournal $journal) { + 'transactions.delete', function (Generator $breadcrumbs, TransactionJournal $journal) { $breadcrumbs->parent('transactions.show', $journal); $breadcrumbs->push(trans('breadcrumbs.delete_journal', ['description' => e($journal->description)]), route('transactions.delete', [$journal->id])); } ); Breadcrumbs::register( - 'transactions.show', function(Generator $breadcrumbs, TransactionJournal $journal) { + 'transactions.show', function (Generator $breadcrumbs, TransactionJournal $journal) { $breadcrumbs->parent('transactions.index', strtolower($journal->transactionType->type)); $breadcrumbs->push($journal->description, route('transactions.show', [$journal->id])); @@ -378,28 +378,28 @@ Breadcrumbs::register( // tags Breadcrumbs::register( - 'tags.index', function(Generator $breadcrumbs) { + 'tags.index', function (Generator $breadcrumbs) { $breadcrumbs->parent('home'); $breadcrumbs->push(trans('breadcrumbs.tags'), route('tags.index')); } ); Breadcrumbs::register( - 'tags.create', function(Generator $breadcrumbs) { + 'tags.create', function (Generator $breadcrumbs) { $breadcrumbs->parent('tags.index'); $breadcrumbs->push(trans('breadcrumbs.createTag'), route('tags.create')); } ); Breadcrumbs::register( - 'tags.edit', function(Generator $breadcrumbs, Tag $tag) { + 'tags.edit', function (Generator $breadcrumbs, Tag $tag) { $breadcrumbs->parent('tags.show', $tag); $breadcrumbs->push(trans('breadcrumbs.edit_tag', ['tag' => e($tag->tag)]), route('tags.edit', [$tag->id])); } ); Breadcrumbs::register( - 'tags.delete', function(Generator $breadcrumbs, Tag $tag) { + 'tags.delete', function (Generator $breadcrumbs, Tag $tag) { $breadcrumbs->parent('tags.show', $tag); $breadcrumbs->push(trans('breadcrumbs.delete_tag', ['tag' => e($tag->tag)]), route('tags.delete', [$tag->id])); } @@ -407,7 +407,7 @@ Breadcrumbs::register( Breadcrumbs::register( - 'tags.show', function(Generator $breadcrumbs, Tag $tag) { + 'tags.show', function (Generator $breadcrumbs, Tag $tag) { $breadcrumbs->parent('tags.index'); $breadcrumbs->push(e($tag->tag), route('tags.show', [$tag->id])); } diff --git a/app/Http/routes.php b/app/Http/routes.php index 3efce92ee6..2b66dac023 100644 --- a/app/Http/routes.php +++ b/app/Http/routes.php @@ -15,13 +15,13 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; // models Route::bind( 'account', - function($value) { + function ($value) { if (Auth::check()) { $object = Account::leftJoin('account_types', 'account_types.id', '=', 'accounts.account_type_id') - ->where('account_types.editable', 1) - ->where('accounts.id', $value) - ->where('user_id', Auth::user()->id) - ->first(['accounts.*']); + ->where('account_types.editable', 1) + ->where('accounts.id', $value) + ->where('user_id', Auth::user()->id) + ->first(['accounts.*']); if ($object) { return $object; } @@ -31,7 +31,7 @@ Route::bind( ); Route::bind( - 'tj', function($value) { + 'tj', function ($value) { if (Auth::check()) { $object = TransactionJournal::where('id', $value)->where('user_id', Auth::user()->id)->first(); if ($object) { @@ -44,7 +44,7 @@ Route::bind( ); Route::bind( - 'currency', function($value) { + 'currency', function ($value) { if (Auth::check()) { $object = TransactionCurrency::find($value); if ($object) { @@ -56,7 +56,7 @@ Route::bind( ); Route::bind( - 'bill', function($value) { + 'bill', function ($value) { if (Auth::check()) { $object = Bill::where('id', $value)->where('user_id', Auth::user()->id)->first(); if ($object) { @@ -69,7 +69,7 @@ Route::bind( ); Route::bind( - 'budget', function($value) { + 'budget', function ($value) { if (Auth::check()) { $object = Budget::where('id', $value)->where('user_id', Auth::user()->id)->first(); if ($object) { @@ -82,7 +82,7 @@ Route::bind( ); Route::bind( - 'reminder', function($value) { + 'reminder', function ($value) { if (Auth::check()) { $object = Reminder::where('id', $value)->where('user_id', Auth::user()->id)->first(); if ($object) { @@ -95,13 +95,13 @@ Route::bind( ); Route::bind( - 'limitrepetition', function($value) { + 'limitrepetition', function ($value) { if (Auth::check()) { $object = LimitRepetition::where('limit_repetitions.id', $value) - ->leftjoin('budget_limits', 'budget_limits.id', '=', 'limit_repetitions.budget_limit_id') - ->leftJoin('budgets', 'budgets.id', '=', 'budget_limits.budget_id') - ->where('budgets.user_id', Auth::user()->id) - ->first(['limit_repetitions.*']); + ->leftjoin('budget_limits', 'budget_limits.id', '=', 'limit_repetitions.budget_limit_id') + ->leftJoin('budgets', 'budgets.id', '=', 'budget_limits.budget_id') + ->where('budgets.user_id', Auth::user()->id) + ->first(['limit_repetitions.*']); if ($object) { return $object; } @@ -112,12 +112,12 @@ Route::bind( ); Route::bind( - 'piggyBank', function($value) { + 'piggyBank', function ($value) { if (Auth::check()) { $object = PiggyBank::where('piggy_banks.id', $value) - ->leftJoin('accounts', 'accounts.id', '=', 'piggy_banks.account_id') - ->where('accounts.user_id', Auth::user()->id) - ->first(['piggy_banks.*']); + ->leftJoin('accounts', 'accounts.id', '=', 'piggy_banks.account_id') + ->where('accounts.user_id', Auth::user()->id) + ->first(['piggy_banks.*']); if ($object) { return $object; } @@ -128,7 +128,7 @@ Route::bind( ); Route::bind( - 'category', function($value) { + 'category', function ($value) { if (Auth::check()) { $object = Category::where('id', $value)->where('user_id', Auth::user()->id)->first(); if ($object) { @@ -142,7 +142,7 @@ Route::bind( /** @noinspection PhpUnusedParameterInspection */ Route::bind( - 'reminder', function($value) { + 'reminder', function ($value) { if (Auth::check()) { /** @var \FireflyIII\Models\Reminder $object */ $object = Reminder::find($value); @@ -158,7 +158,7 @@ Route::bind( ); Route::bind( - 'tag', function($value) { + 'tag', function ($value) { if (Auth::check()) { $object = Tag::where('id', $value)->where('user_id', Auth::user()->id)->first(); if ($object) { @@ -187,7 +187,7 @@ Route::controllers( * Home Controller */ Route::group( - ['middleware' => ['auth', 'range', 'reminders']], function() { + ['middleware' => ['auth', 'range', 'reminders']], function () { Route::get('/', ['uses' => 'HomeController@index', 'as' => 'index']); Route::get('/home', ['uses' => 'HomeController@index', 'as' => 'home']); Route::post('/daterange', ['uses' => 'HomeController@dateRange', 'as' => 'daterange']); diff --git a/app/Models/Account.php b/app/Models/Account.php index dc2a83ebc0..8a9f1f80fd 100644 --- a/app/Models/Account.php +++ b/app/Models/Account.php @@ -46,7 +46,7 @@ use Watson\Validating\ValidatingTrait; * @property mixed lastActivityDate * @property mixed piggyBalance * @property mixed difference - * @property mixed percentage + * @property mixed percentage */ class Account extends Model { @@ -215,7 +215,7 @@ class Account extends Model { $joinName = str_replace('.', '_', $name); $query->leftJoin( - 'account_meta as ' . $joinName, function(JoinClause $join) use ($joinName, $name) { + 'account_meta as ' . $joinName, function (JoinClause $join) use ($joinName, $name) { $join->on($joinName . '.account_id', '=', 'accounts.id')->where($joinName . '.name', '=', $name); } ); diff --git a/app/Models/AccountMeta.php b/app/Models/AccountMeta.php index 806b62da33..279fe60765 100644 --- a/app/Models/AccountMeta.php +++ b/app/Models/AccountMeta.php @@ -6,7 +6,7 @@ use Watson\Validating\ValidatingTrait; /** * Class AccountMeta * - * @codeCoverageIgnore + * @codeCoverageIgnore * @package FireflyIII\Models * @property integer $id * @property \Carbon\Carbon $created_at @@ -33,7 +33,7 @@ class AccountMeta extends Model 'name' => 'required|between:1,100', 'data' => 'required' ]; - protected $table = 'account_meta'; + protected $table = 'account_meta'; /** * diff --git a/app/Models/AccountType.php b/app/Models/AccountType.php index 6de461749b..2148b9e961 100644 --- a/app/Models/AccountType.php +++ b/app/Models/AccountType.php @@ -5,7 +5,7 @@ use Illuminate\Database\Eloquent\Model; /** * Class AccountType * - * @codeCoverageIgnore + * @codeCoverageIgnore * @package FireflyIII\Models * @property integer $id * @property \Carbon\Carbon $created_at diff --git a/app/Models/Bill.php b/app/Models/Bill.php index 1afaac6090..76ce0b66ad 100644 --- a/app/Models/Bill.php +++ b/app/Models/Bill.php @@ -7,7 +7,7 @@ use Illuminate\Database\Eloquent\Model; * FireflyIII\Models\Bill * * @codeCoverageIgnore Class Bill - * @package FireflyIII\Models + * @package FireflyIII\Models * @property integer $id * @property \Carbon\Carbon $created_at * @property \Carbon\Carbon $updated_at @@ -51,12 +51,11 @@ class Bill extends Model { protected $fillable - = ['name', 'match', 'amount_min', 'match_encrypted', 'name_encrypted', 'user_id', 'amount_max', 'date', 'repeat_freq', 'skip', 'automatch', 'active', ]; + = ['name', 'match', 'amount_min', 'match_encrypted', 'name_encrypted', 'user_id', 'amount_max', 'date', 'repeat_freq', 'skip', 'automatch', 'active',]; protected $hidden = ['amount_min_encrypted', 'amount_max_encrypted', 'name_encrypted', 'match_encrypted']; - /** * @return array */ diff --git a/app/Models/Budget.php b/app/Models/Budget.php index ab529f3e62..02f1e46808 100644 --- a/app/Models/Budget.php +++ b/app/Models/Budget.php @@ -7,7 +7,7 @@ use Illuminate\Database\Eloquent\SoftDeletes; /** * Class Budget * - * @codeCoverageIgnore + * @codeCoverageIgnore * @package FireflyIII\Models * @property integer $id * @property \Carbon\Carbon $created_at diff --git a/app/Models/BudgetLimit.php b/app/Models/BudgetLimit.php index 97f2b16dab..42e72dc502 100644 --- a/app/Models/BudgetLimit.php +++ b/app/Models/BudgetLimit.php @@ -5,7 +5,7 @@ use Illuminate\Database\Eloquent\Model; /** * Class BudgetLimit * - * @codeCoverageIgnore + * @codeCoverageIgnore * @package FireflyIII\Models * @property integer $id * @property \Carbon\Carbon $created_at diff --git a/app/Models/Component.php b/app/Models/Component.php index c65a9c8812..84686751be 100644 --- a/app/Models/Component.php +++ b/app/Models/Component.php @@ -6,7 +6,7 @@ use Illuminate\Database\Eloquent\SoftDeletes; /** * Class Component * - * @codeCoverageIgnore + * @codeCoverageIgnore * @package FireflyIII\Models * @property integer $id * @property \Carbon\Carbon $created_at diff --git a/app/Models/LimitRepetition.php b/app/Models/LimitRepetition.php index 5f6ea2a6cf..d5fd692dae 100644 --- a/app/Models/LimitRepetition.php +++ b/app/Models/LimitRepetition.php @@ -5,7 +5,7 @@ use Illuminate\Database\Eloquent\Model; /** * Class LimitRepetition * - * @codeCoverageIgnore + * @codeCoverageIgnore * @package FireflyIII\Models * @property integer $id * @property \Carbon\Carbon $created_at diff --git a/app/Models/Permission.php b/app/Models/Permission.php index 7e98ba7eda..3e87ce4207 100644 --- a/app/Models/Permission.php +++ b/app/Models/Permission.php @@ -8,10 +8,10 @@ use Zizaco\Entrust\EntrustPermission; * Class Permission * * @package FireflyIII\Models - * @property integer $id - * @property string $name - * @property string $display_name - * @property string $description + * @property integer $id + * @property string $name + * @property string $display_name + * @property string $description * @property \Carbon\Carbon $created_at * @property \Carbon\Carbon $updated_at * @property-read \Illuminate\Database\Eloquent\Collection|\Config::get('entrust.role')[] $roles diff --git a/app/Models/PiggyBank.php b/app/Models/PiggyBank.php index 6183258f6b..44c05fa63b 100644 --- a/app/Models/PiggyBank.php +++ b/app/Models/PiggyBank.php @@ -7,7 +7,7 @@ use Illuminate\Database\Eloquent\SoftDeletes; /** * Class PiggyBank * - * @codeCoverageIgnore + * @codeCoverageIgnore * @package FireflyIII\Models * @property integer $id * @property \Carbon\Carbon $created_at @@ -50,7 +50,7 @@ class PiggyBank extends Model use SoftDeletes; protected $fillable - = ['name', 'account_id', 'order', 'reminder_skip', 'targetamount', 'startdate', 'targetdate', 'reminder', 'remind_me']; + = ['name', 'account_id', 'order', 'reminder_skip', 'targetamount', 'startdate', 'targetdate', 'reminder', 'remind_me']; protected $hidden = ['targetamount_encrypted', 'encrypted']; /** diff --git a/app/Models/PiggyBankEvent.php b/app/Models/PiggyBankEvent.php index 98de0f04ef..6b9bdceda1 100644 --- a/app/Models/PiggyBankEvent.php +++ b/app/Models/PiggyBankEvent.php @@ -5,7 +5,7 @@ use Illuminate\Database\Eloquent\Model; /** * Class PiggyBankEvent * - * @codeCoverageIgnore + * @codeCoverageIgnore * @package FireflyIII\Models * @property integer $id * @property \Carbon\Carbon $created_at diff --git a/app/Models/PiggyBankRepetition.php b/app/Models/PiggyBankRepetition.php index 5044981ebc..a24066f2ee 100644 --- a/app/Models/PiggyBankRepetition.php +++ b/app/Models/PiggyBankRepetition.php @@ -7,7 +7,7 @@ use Illuminate\Database\Eloquent\Model; /** * Class PiggyBankRepetition * - * @codeCoverageIgnore + * @codeCoverageIgnore * @package FireflyIII\Models * @property integer $id * @property \Carbon\Carbon $created_at @@ -77,13 +77,13 @@ class PiggyBankRepetition extends Model $q->orWhereNull('startdate'); } ) - ->where( - function (EloquentBuilder $q) use ($date) { + ->where( + function (EloquentBuilder $q) use ($date) { - $q->where('targetdate', '>=', $date->format('Y-m-d 00:00:00')); - $q->orWhereNull('targetdate'); - } - ); + $q->where('targetdate', '>=', $date->format('Y-m-d 00:00:00')); + $q->orWhereNull('targetdate'); + } + ); } /** diff --git a/app/Models/Preference.php b/app/Models/Preference.php index 263e7e33bc..56bc6f7cfd 100644 --- a/app/Models/Preference.php +++ b/app/Models/Preference.php @@ -6,7 +6,7 @@ use Illuminate\Database\Eloquent\Model; /** * Class Preference * - * @codeCoverageIgnore + * @codeCoverageIgnore * @package FireflyIII\Models * @property integer $id * @property \Carbon\Carbon $created_at diff --git a/app/Models/Reminder.php b/app/Models/Reminder.php index 0167d81364..b4797dae8d 100644 --- a/app/Models/Reminder.php +++ b/app/Models/Reminder.php @@ -8,7 +8,7 @@ use Illuminate\Database\Eloquent\Model; /** * Class Reminder * - * @codeCoverageIgnore + * @codeCoverageIgnore * @package FireflyIII\Models * @property integer $id * @property \Carbon\Carbon $created_at @@ -44,7 +44,7 @@ class Reminder extends Model { - protected $fillable = ['user_id', 'startdate', 'metadata', 'enddate', 'active', 'notnow', 'remindersable_id', 'remindersable_type', ]; + protected $fillable = ['user_id', 'startdate', 'metadata', 'enddate', 'active', 'notnow', 'remindersable_id', 'remindersable_type',]; protected $hidden = ['encrypted']; /** @@ -124,7 +124,7 @@ class Reminder extends Model $today = new Carbon; return $query->where('startdate', '<=', $today->format('Y-m-d 00:00:00'))->where('enddate', '>=', $today->format('Y-m-d 00:00:00'))->where('active', 1) - ->where('notnow', 0); + ->where('notnow', 0); } /** diff --git a/app/Models/Role.php b/app/Models/Role.php index 2c3285610e..90d89caff6 100644 --- a/app/Models/Role.php +++ b/app/Models/Role.php @@ -8,10 +8,10 @@ use Zizaco\Entrust\EntrustRole; * Class Role * * @package FireflyIII\Models - * @property integer $id - * @property string $name - * @property string $display_name - * @property string $description + * @property integer $id + * @property string $name + * @property string $display_name + * @property string $description * @property \Carbon\Carbon $created_at * @property \Carbon\Carbon $updated_at * @property-read \Illuminate\Database\Eloquent\Collection|\Config::get('auth.model')[] $users diff --git a/app/Models/Transaction.php b/app/Models/Transaction.php index 43f9928439..26ca48ef45 100644 --- a/app/Models/Transaction.php +++ b/app/Models/Transaction.php @@ -9,7 +9,7 @@ use Watson\Validating\ValidatingTrait; /** * Class Transaction * - * @codeCoverageIgnore + * @codeCoverageIgnore * @package FireflyIII\Models * @property integer $id * @property \Carbon\Carbon $created_at diff --git a/app/Models/TransactionCurrency.php b/app/Models/TransactionCurrency.php index 4adad9b216..27b21f36c3 100644 --- a/app/Models/TransactionCurrency.php +++ b/app/Models/TransactionCurrency.php @@ -6,7 +6,7 @@ use Illuminate\Database\Eloquent\SoftDeletes; /** * Class TransactionCurrency * - * @codeCoverageIgnore + * @codeCoverageIgnore * @package FireflyIII\Models * @property integer $id * @property \Carbon\Carbon $created_at diff --git a/app/Models/TransactionGroup.php b/app/Models/TransactionGroup.php index 6c980bfac0..bb41749ca2 100644 --- a/app/Models/TransactionGroup.php +++ b/app/Models/TransactionGroup.php @@ -6,7 +6,7 @@ use Illuminate\Database\Eloquent\SoftDeletes; /** * Class TransactionGroup * - * @codeCoverageIgnore + * @codeCoverageIgnore * @package FireflyIII\Models * @property integer $id * @property \Carbon\Carbon $created_at diff --git a/app/Models/TransactionJournal.php b/app/Models/TransactionJournal.php index 73de69784b..360429b436 100644 --- a/app/Models/TransactionJournal.php +++ b/app/Models/TransactionJournal.php @@ -7,7 +7,6 @@ use Illuminate\Database\Eloquent\Builder as EloquentBuilder; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\HasMany; use Illuminate\Database\Eloquent\SoftDeletes; -use Log; use Watson\Validating\ValidatingTrait; /** diff --git a/app/Models/TransactionRelation.php b/app/Models/TransactionRelation.php index 056d61fdd8..aa4d3810af 100644 --- a/app/Models/TransactionRelation.php +++ b/app/Models/TransactionRelation.php @@ -5,7 +5,7 @@ use Illuminate\Database\Eloquent\Model; /** * Class TransactionRelation * - * @codeCoverageIgnore + * @codeCoverageIgnore * @package FireflyIII\Models */ class TransactionRelation extends Model diff --git a/app/Models/TransactionType.php b/app/Models/TransactionType.php index 886858bb2c..098d5bcfc7 100644 --- a/app/Models/TransactionType.php +++ b/app/Models/TransactionType.php @@ -6,7 +6,7 @@ use Illuminate\Database\Eloquent\SoftDeletes; /** * Class TransactionType * - * @codeCoverageIgnore + * @codeCoverageIgnore * @package FireflyIII\Models * @property integer $id * @property \Carbon\Carbon $created_at diff --git a/app/Providers/BusServiceProvider.php b/app/Providers/BusServiceProvider.php index 1eef3684d7..dc2e86ac21 100644 --- a/app/Providers/BusServiceProvider.php +++ b/app/Providers/BusServiceProvider.php @@ -23,7 +23,7 @@ class BusServiceProvider extends ServiceProvider public function boot(Dispatcher $dispatcher) { $dispatcher->mapUsing( - function($command) { + function ($command) { return Dispatcher::simpleMapping( $command, 'FireflyIII\Commands', 'FireflyIII\Handlers\Commands' ); diff --git a/app/Providers/EventServiceProvider.php b/app/Providers/EventServiceProvider.php index 626b3f6ea2..697f7df767 100644 --- a/app/Providers/EventServiceProvider.php +++ b/app/Providers/EventServiceProvider.php @@ -52,15 +52,15 @@ class EventServiceProvider extends ServiceProvider $this->registerDeleteEvents(); $this->registerCreateEvents(); BudgetLimit::saved( - function(BudgetLimit $budgetLimit) { + function (BudgetLimit $budgetLimit) { Log::debug('Saved!'); $end = Navigation::addPeriod(clone $budgetLimit->startdate, $budgetLimit->repeat_freq, 0); $end->subDay(); $set = $budgetLimit->limitrepetitions() - ->where('startdate', $budgetLimit->startdate->format('Y-m-d 00:00:00')) - ->where('enddate', $end->format('Y-m-d 00:00:00')) - ->get(); + ->where('startdate', $budgetLimit->startdate->format('Y-m-d 00:00:00')) + ->where('enddate', $end->format('Y-m-d 00:00:00')) + ->get(); if ($set->count() == 0) { $repetition = new LimitRepetition; $repetition->startdate = $budgetLimit->startdate; @@ -71,7 +71,7 @@ class EventServiceProvider extends ServiceProvider try { $repetition->save(); } catch (QueryException $e) { - Log::error('Trying to save new LimitRepetition failed: '.$e->getMessage()); // @codeCoverageIgnore + Log::error('Trying to save new LimitRepetition failed: ' . $e->getMessage()); // @codeCoverageIgnore } } else { if ($set->count() == 1) { @@ -93,7 +93,7 @@ class EventServiceProvider extends ServiceProvider protected function registerDeleteEvents() { TransactionJournal::deleted( - function(TransactionJournal $journal) { + function (TransactionJournal $journal) { /** @var Transaction $transaction */ foreach ($journal->transactions()->get() as $transaction) { @@ -102,7 +102,7 @@ class EventServiceProvider extends ServiceProvider } ); PiggyBank::deleting( - function(PiggyBank $piggyBank) { + function (PiggyBank $piggyBank) { $reminders = $piggyBank->reminders()->get(); /** @var Reminder $reminder */ foreach ($reminders as $reminder) { @@ -112,7 +112,7 @@ class EventServiceProvider extends ServiceProvider ); Account::deleted( - function(Account $account) { + function (Account $account) { /** @var Transaction $transaction */ foreach ($account->transactions()->get() as $transaction) { @@ -133,7 +133,7 @@ class EventServiceProvider extends ServiceProvider // move this routine to a filter // in case of repeated piggy banks and/or other problems. PiggyBank::created( - function(PiggyBank $piggyBank) { + function (PiggyBank $piggyBank) { $repetition = new PiggyBankRepetition; $repetition->piggyBank()->associate($piggyBank); $repetition->startdate = is_null($piggyBank->startdate) ? null : $piggyBank->startdate; diff --git a/app/Providers/FireflyServiceProvider.php b/app/Providers/FireflyServiceProvider.php index ab5d1be9e5..eff456ea08 100644 --- a/app/Providers/FireflyServiceProvider.php +++ b/app/Providers/FireflyServiceProvider.php @@ -30,7 +30,7 @@ class FireflyServiceProvider extends ServiceProvider public function boot() { Validator::resolver( - function($translator, $data, $rules, $messages) { + function ($translator, $data, $rules, $messages) { return new FireflyValidator($translator, $data, $rules, $messages); } ); @@ -55,28 +55,28 @@ class FireflyServiceProvider extends ServiceProvider $this->app->bind( - 'preferences', function() { + 'preferences', function () { return new Preferences; } ); $this->app->bind( - 'navigation', function() { + 'navigation', function () { return new Navigation; } ); $this->app->bind( - 'amount', function() { + 'amount', function () { return new Amount; } ); $this->app->bind( - 'steam', function() { + 'steam', function () { return new Steam; } ); $this->app->bind( - 'expandedform', function() { + 'expandedform', function () { return new ExpandedForm; } ); diff --git a/app/Providers/RouteServiceProvider.php b/app/Providers/RouteServiceProvider.php index b95fa98635..4e40f5bec8 100644 --- a/app/Providers/RouteServiceProvider.php +++ b/app/Providers/RouteServiceProvider.php @@ -44,7 +44,7 @@ class RouteServiceProvider extends ServiceProvider public function map(Router $router) { $router->group( - ['namespace' => $this->namespace], function($router) { + ['namespace' => $this->namespace], function ($router) { /** @noinspection PhpIncludeInspection */ require app_path('Http/routes.php'); } diff --git a/app/Repositories/Category/CategoryRepository.php b/app/Repositories/Category/CategoryRepository.php index 235663d83b..f2cc4bc3a6 100644 --- a/app/Repositories/Category/CategoryRepository.php +++ b/app/Repositories/Category/CategoryRepository.php @@ -7,8 +7,9 @@ use Carbon\Carbon; use Crypt; use FireflyIII\Models\Category; use FireflyIII\Models\TransactionJournal; -use Illuminate\Support\Collection; use FireflyIII\Repositories\Shared\ComponentRepository; +use Illuminate\Support\Collection; + /** * Class CategoryRepository * @@ -48,7 +49,7 @@ class CategoryRepository extends ComponentRepository implements CategoryReposito /** @var Collection $set */ $set = Auth::user()->categories()->orderBy('name', 'ASC')->get(); $set->sortBy( - function(Category $category) { + function (Category $category) { return $category->name; } ); @@ -66,15 +67,15 @@ class CategoryRepository extends ComponentRepository implements CategoryReposito public function getCategoriesAndExpensesCorrected($start, $end) { $set = Auth::user()->transactionjournals() - ->leftJoin( - 'category_transaction_journal', 'category_transaction_journal.transaction_journal_id', '=', 'transaction_journals.id' - ) - ->leftJoin('categories', 'categories.id', '=', 'category_transaction_journal.category_id') - ->before($end) - ->where('categories.user_id', Auth::user()->id) - ->after($start) - ->transactionTypes(['Withdrawal']) - ->get(['categories.id as category_id', 'categories.encrypted as category_encrypted', 'categories.name', 'transaction_journals.*']); + ->leftJoin( + 'category_transaction_journal', 'category_transaction_journal.transaction_journal_id', '=', 'transaction_journals.id' + ) + ->leftJoin('categories', 'categories.id', '=', 'category_transaction_journal.category_id') + ->before($end) + ->where('categories.user_id', Auth::user()->id) + ->after($start) + ->transactionTypes(['Withdrawal']) + ->get(['categories.id as category_id', 'categories.encrypted as category_encrypted', 'categories.name', 'transaction_journals.*']); $result = []; foreach ($set as $entry) { @@ -142,10 +143,10 @@ class CategoryRepository extends ComponentRepository implements CategoryReposito public function getLatestActivity(Category $category) { $latest = $category->transactionjournals() - ->orderBy('transaction_journals.date', 'DESC') - ->orderBy('transaction_journals.order', 'ASC') - ->orderBy('transaction_journals.id', 'DESC') - ->first(); + ->orderBy('transaction_journals.date', 'DESC') + ->orderBy('transaction_journals.order', 'ASC') + ->orderBy('transaction_journals.id', 'DESC') + ->first(); if ($latest) { return $latest->date; } @@ -162,15 +163,15 @@ class CategoryRepository extends ComponentRepository implements CategoryReposito public function getWithoutCategory(Carbon $start, Carbon $end) { return Auth::user() - ->transactionjournals() - ->leftJoin('category_transaction_journal', 'category_transaction_journal.transaction_journal_id', '=', 'transaction_journals.id') - ->whereNull('category_transaction_journal.id') - ->before($end) - ->after($start) - ->orderBy('transaction_journals.date', 'DESC') - ->orderBy('transaction_journals.order', 'ASC') - ->orderBy('transaction_journals.id', 'DESC') - ->get(['transaction_journals.*']); + ->transactionjournals() + ->leftJoin('category_transaction_journal', 'category_transaction_journal.transaction_journal_id', '=', 'transaction_journals.id') + ->whereNull('category_transaction_journal.id') + ->before($end) + ->after($start) + ->orderBy('transaction_journals.date', 'DESC') + ->orderBy('transaction_journals.order', 'ASC') + ->orderBy('transaction_journals.id', 'DESC') + ->get(['transaction_journals.*']); } /** diff --git a/app/Repositories/Journal/JournalRepository.php b/app/Repositories/Journal/JournalRepository.php index 9e1758310b..6713821bb9 100644 --- a/app/Repositories/Journal/JournalRepository.php +++ b/app/Repositories/Journal/JournalRepository.php @@ -106,7 +106,7 @@ class JournalRepository implements JournalRepositoryInterface */ public function getJournalsOfTypes(array $types, $offset, $page) { - $set = Auth::user()->transactionJournals()->transactionTypes($types)->withRelevantData()->take(50)->offset($offset) + $set = Auth::user()->transactionJournals()->transactionTypes($types)->withRelevantData()->take(50)->offset($offset) ->orderBy('date', 'DESC') ->orderBy('order', 'ASC') ->orderBy('id', 'DESC') diff --git a/app/Repositories/PiggyBank/PiggyBankRepository.php b/app/Repositories/PiggyBank/PiggyBankRepository.php index 3db4693284..78c8d80b2d 100644 --- a/app/Repositories/PiggyBank/PiggyBankRepository.php +++ b/app/Repositories/PiggyBank/PiggyBankRepository.php @@ -102,7 +102,7 @@ class PiggyBankRepository implements PiggyBankRepositoryInterface public function setOrder($id, $order) { $piggyBank = PiggyBank::leftJoin('accounts', 'accounts.id', '=', 'piggy_banks.account_id')->where('accounts.user_id', Auth::user()->id) - ->where('piggy_banks.id', $id)->first(['piggy_banks.*']); + ->where('piggy_banks.id', $id)->first(['piggy_banks.*']); if ($piggyBank) { $piggyBank->order = $order; $piggyBank->save(); diff --git a/app/Repositories/Reminder/ReminderRepository.php b/app/Repositories/Reminder/ReminderRepository.php index ae04c59c66..8db6d0ada0 100644 --- a/app/Repositories/Reminder/ReminderRepository.php +++ b/app/Repositories/Reminder/ReminderRepository.php @@ -36,14 +36,14 @@ class ReminderRepository implements ReminderRepositoryInterface $today = new Carbon; // active reminders: $active = Auth::user()->reminders() - ->where('notnow', 0) - ->where('active', 1) - ->where('startdate', '<=', $today->format('Y-m-d 00:00:00')) - ->where('enddate', '>=', $today->format('Y-m-d 00:00:00')) - ->get(); + ->where('notnow', 0) + ->where('active', 1) + ->where('startdate', '<=', $today->format('Y-m-d 00:00:00')) + ->where('enddate', '>=', $today->format('Y-m-d 00:00:00')) + ->get(); $active->each( - function(Reminder $reminder) { + function (Reminder $reminder) { $reminder->description = $this->helper->getReminderText($reminder); } ); @@ -58,11 +58,11 @@ class ReminderRepository implements ReminderRepositoryInterface public function getDismissedReminders() { $dismissed = Auth::user()->reminders() - ->where('notnow', 1) - ->get(); + ->where('notnow', 1) + ->get(); $dismissed->each( - function(Reminder $reminder) { + function (Reminder $reminder) { $reminder->description = $this->helper->getReminderText($reminder); } ); @@ -77,18 +77,18 @@ class ReminderRepository implements ReminderRepositoryInterface { $expired = Auth::user()->reminders() - ->where('notnow', 0) - ->where('active', 1) - ->where( - function (Builder $q) { - $today = new Carbon; - $q->where('startdate', '>', $today->format('Y-m-d 00:00:00')); - $q->orWhere('enddate', '<', $today->format('Y-m-d 00:00:00')); - } - )->get(); + ->where('notnow', 0) + ->where('active', 1) + ->where( + function (Builder $q) { + $today = new Carbon; + $q->where('startdate', '>', $today->format('Y-m-d 00:00:00')); + $q->orWhere('enddate', '<', $today->format('Y-m-d 00:00:00')); + } + )->get(); $expired->each( - function(Reminder $reminder) { + function (Reminder $reminder) { $reminder->description = $this->helper->getReminderText($reminder); } ); @@ -106,7 +106,7 @@ class ReminderRepository implements ReminderRepositoryInterface ->get(); $inactive->each( - function(Reminder $reminder) { + function (Reminder $reminder) { $reminder->description = $this->helper->getReminderText($reminder); } ); diff --git a/app/Repositories/Shared/ComponentRepository.php b/app/Repositories/Shared/ComponentRepository.php index e4ee7992df..e4187f9e58 100644 --- a/app/Repositories/Shared/ComponentRepository.php +++ b/app/Repositories/Shared/ComponentRepository.php @@ -36,7 +36,7 @@ class ComponentRepository $cache->addProperty($shared); $cache->addProperty('spentInPeriod'); - if($cache->has()) { + if ($cache->has()) { return $cache->get(); // @codeCoverageIgnore } diff --git a/app/Repositories/Tag/TagRepository.php b/app/Repositories/Tag/TagRepository.php index 276f190821..935c2967fa 100644 --- a/app/Repositories/Tag/TagRepository.php +++ b/app/Repositories/Tag/TagRepository.php @@ -110,7 +110,7 @@ class TagRepository implements TagRepositoryInterface /** @var Collection $tags */ $tags = Auth::user()->tags()->get(); $tags->sortBy( - function(Tag $tag) { + function (Tag $tag) { return $tag->tag; } ); @@ -204,6 +204,7 @@ class TagRepository implements TagRepositoryInterface return false; } } + return true; } @@ -289,6 +290,7 @@ class TagRepository implements TagRepositoryInterface // tag is attached just like that: if ($withdrawals < 1 && $deposits < 1) { $journal->tags()->save($tag); + return true; } diff --git a/app/Services/Registrar.php b/app/Services/Registrar.php index 6f9ffa729a..5f69c7ba24 100644 --- a/app/Services/Registrar.php +++ b/app/Services/Registrar.php @@ -41,9 +41,9 @@ class Registrar implements RegistrarContract { return Validator::make( $data, [ - 'email' => 'required|email|max:255|unique:users', - 'password' => 'required|confirmed|min:6', - ] + 'email' => 'required|email|max:255|unique:users', + 'password' => 'required|confirmed|min:6', + ] ); } diff --git a/app/Support/CacheProperties.php b/app/Support/CacheProperties.php index f0e1c760ee..b4854503d0 100644 --- a/app/Support/CacheProperties.php +++ b/app/Support/CacheProperties.php @@ -9,7 +9,6 @@ use Carbon\Carbon; use Illuminate\Database\Eloquent\Collection as EloquentCollection; use Illuminate\Support\Collection; use Preferences as Prefs; -use Log; /** * Class CacheProperties @@ -63,7 +62,7 @@ class CacheProperties */ public function has() { - if(getenv('APP_ENV') == 'testing') { + if (getenv('APP_ENV') == 'testing') { return false; } $this->md5(); diff --git a/app/Support/Navigation.php b/app/Support/Navigation.php index b64fb9240e..2c3f564a61 100644 --- a/app/Support/Navigation.php +++ b/app/Support/Navigation.php @@ -41,7 +41,7 @@ class Navigation '6M' => 6, 'half-year' => 6, ]; - $specialMap = ['1M', 'month', 'monthly']; + if (!isset($functionMap[$repeatFreq])) { throw new FireflyException('Cannot do addPeriod for $repeat_freq "' . $repeatFreq . '"'); } diff --git a/app/Support/Preferences.php b/app/Support/Preferences.php index 0a1d287566..e705f9cb55 100644 --- a/app/Support/Preferences.php +++ b/app/Support/Preferences.php @@ -25,7 +25,7 @@ class Preferences /** * @param string $name - * @param string $default + * @param string $default * * @return null|\FireflyIII\Models\Preference */ @@ -54,7 +54,7 @@ class Preferences } /** - * @param $name + * @param $name * @param string $value * * @return Preference diff --git a/app/Support/Search/Search.php b/app/Support/Search/Search.php index 7b1e0f42b5..a493ad0741 100644 --- a/app/Support/Search/Search.php +++ b/app/Support/Search/Search.php @@ -25,7 +25,7 @@ class Search implements SearchInterface public function searchAccounts(array $words) { return Auth::user()->accounts()->with('accounttype')->where( - function(EloquentBuilder $q) use ($words) { + function (EloquentBuilder $q) use ($words) { foreach ($words as $word) { $q->orWhere('name', 'LIKE', '%' . e($word) . '%'); } @@ -43,7 +43,7 @@ class Search implements SearchInterface /** @var Collection $set */ $set = Auth::user()->budgets()->get(); $newSet = $set->filter( - function(Budget $b) use ($words) { + function (Budget $b) use ($words) { $found = 0; foreach ($words as $word) { if (!(strpos(strtolower($b->name), strtolower($word)) === false)) { @@ -68,7 +68,7 @@ class Search implements SearchInterface /** @var Collection $set */ $set = Auth::user()->categories()->get(); $newSet = $set->filter( - function(Category $c) use ($words) { + function (Category $c) use ($words) { $found = 0; foreach ($words as $word) { if (!(strpos(strtolower($c->name), strtolower($word)) === false)) { @@ -103,7 +103,7 @@ class Search implements SearchInterface { // decrypted transaction journals: $decrypted = Auth::user()->transactionjournals()->withRelevantData()->where('encrypted', 0)->where( - function(EloquentBuilder $q) use ($words) { + function (EloquentBuilder $q) use ($words) { foreach ($words as $word) { $q->orWhere('description', 'LIKE', '%' . e($word) . '%'); } @@ -113,7 +113,7 @@ class Search implements SearchInterface // encrypted $all = Auth::user()->transactionjournals()->withRelevantData()->where('encrypted', 1)->get(); $set = $all->filter( - function(TransactionJournal $journal) use ($words) { + function (TransactionJournal $journal) use ($words) { foreach ($words as $word) { $haystack = strtolower($journal->description); $word = strtolower($word); @@ -129,7 +129,7 @@ class Search implements SearchInterface $filtered = $set->merge($decrypted); $filtered->sortBy( - function(TransactionJournal $journal) { + function (TransactionJournal $journal) { return intval($journal->date->format('U')); } ); diff --git a/app/Support/Twig/General.php b/app/Support/Twig/General.php index cea58f5cef..4f79622995 100644 --- a/app/Support/Twig/General.php +++ b/app/Support/Twig/General.php @@ -49,7 +49,10 @@ class General extends Twig_Extension $this->getCurrencySymbol(), $this->phpdate(), $this->env(), - $this->activeRoute() + + $this->activeRouteStrict(), + $this->activeRoutePartial(), + $this->activeRoutePartialWhat(), ]; } @@ -188,31 +191,65 @@ class General extends Twig_Extension } /** + * Will return "active" when the current route matches the given argument + * exactly. + * * @return Twig_SimpleFunction */ - protected function activeRoute() + protected function activeRouteStrict() { return new Twig_SimpleFunction( - 'activeRoute', function ($context) { + 'activeRouteStrict', function () { + $args = func_get_args(); + $route = $args[0]; // name of the route. + + if (Route::getCurrentRoute()->getName() == $route) { + return 'active because-route-matches-strict'; + } + + return 'not-xxx-at-all'; + } + ); + } + + /** + * Will return "active" when a part of the route matches the argument. + * ie. "accounts" will match "accounts.index". + * + * @return Twig_SimpleFunction + */ + protected function activeRoutePartial() + { + return new Twig_SimpleFunction( + 'activeRoutePartial', function () { + $args = func_get_args(); + $route = $args[0]; // name of the route. + if (!(strpos(Route::getCurrentRoute()->getName(), $route) === false)) { + return 'active because-route-matches-non-strict'; + } + + return 'not-xxx-at-all'; + } + ); + } + + /** + * This function will return "active" when the current route matches the first argument (even partly) + * but, the variable $what has been set and matches the second argument. + * + * @return Twig_SimpleFunction + */ + protected function activeRoutePartialWhat() + { + return new Twig_SimpleFunction( + 'activeRoutePartialWhat', function ($context) { $args = func_get_args(); - $route = $args[1]; - $what = isset($args[2]) ? $args[2] : false; - $strict = isset($args[3]) ? $args[3] : false; + $route = $args[1]; // name of the route. + $what = $args[2]; // name of the route. $activeWhat = isset($context['what']) ? $context['what'] : false; - // activeRoute - if (!($what === false)) { - if ($what == $activeWhat && Route::getCurrentRoute()->getName() == $route) { - return 'active because-active-what'; - } - } else { - if (!$strict && !(strpos(Route::getCurrentRoute()->getName(), $route) === false)) { - return 'active because-route-matches-non-strict'; - } else { - if ($strict && Route::getCurrentRoute()->getName() == $route) { - return 'active because-route-matches-strict'; - } - } + if ($what == $activeWhat && !(strpos(Route::getCurrentRoute()->getName(), $route) === false)) { + return 'active because-route-matches-non-strict-what'; } return 'not-xxx-at-all'; diff --git a/app/Support/Twig/PiggyBank.php b/app/Support/Twig/PiggyBank.php index f178aa6316..6ff4aafe90 100644 --- a/app/Support/Twig/PiggyBank.php +++ b/app/Support/Twig/PiggyBank.php @@ -22,7 +22,7 @@ class PiggyBank extends Twig_Extension $functions = []; $functions[] = new Twig_SimpleFunction( - 'currentRelevantRepAmount', function(PB $piggyBank) { + 'currentRelevantRepAmount', function (PB $piggyBank) { return $piggyBank->currentRelevantRep()->currentamount; } ); diff --git a/app/Support/Twig/Translation.php b/app/Support/Twig/Translation.php index d91c1816e6..1cb3314cf2 100644 --- a/app/Support/Twig/Translation.php +++ b/app/Support/Twig/Translation.php @@ -21,7 +21,7 @@ class Translation extends Twig_Extension $filters = []; $filters[] = new Twig_SimpleFilter( - '_', function($name) { + '_', function ($name) { return trans('firefly.' . $name); diff --git a/app/Validation/FireflyValidator.php b/app/Validation/FireflyValidator.php index a680aeb6a2..fbb4c8e0bc 100644 --- a/app/Validation/FireflyValidator.php +++ b/app/Validation/FireflyValidator.php @@ -274,7 +274,7 @@ class FireflyValidator extends Validator $set = $query->get(['piggy_banks.*']); foreach ($set as $entry) { - $fieldValue = $this->tryDecrypt($entry->name); + $fieldValue = $this->tryDecrypt($entry->name); if ($fieldValue == $value) { return false; } diff --git a/resources/twig/partials/menu.twig b/resources/twig/partials/menu.twig index 15779368bf..12567de8d6 100644 --- a/resources/twig/partials/menu.twig +++ b/resources/twig/partials/menu.twig @@ -89,83 +89,83 @@
  • - {{ 'dashboard'|_ }} + {{ 'dashboard'|_ }}
  • -
  • +
  • {{ 'accounts'|_ }}
  • - {{ 'budgets'|_ }} + {{ 'budgets'|_ }}
  • - {{ 'categories'|_ }} + {{ 'categories'|_ }}
  • - {{ 'tags'|_ }} + {{ 'tags'|_ }}
  • - {{ 'reports'|_ }} + {{ 'reports'|_ }}
  • -
  • +
  • {{ 'transactions'|_ }}
  • -
  • +
  • {{ 'moneyManagement'|_ }}
  • -
  • +
  • {{ 'createNew'|_ }} @@ -173,17 +173,17 @@