Firefly III: a personal finances manager
PHP accountingbudgetbudgetingbudgetscash-flowcashflowcredit-carddockerexpensesfinancefinancesfinanciallinuxmoneypaycheckpersonal-financephpphp7
Code cleanup.
James Cole3d4489efe6be
diff --git a/app/Helpers/Csv/Wizard.php b/app/Helpers/Csv/Wizard.phpindex ef2a274829..e3d36a8047 100644--- a/app/Helpers/Csv/Wizard.php+++ b/app/Helpers/Csv/Wizard.php@@ -62,16 +62,12 @@ class Wizard implements WizardInterface{$configRoles = config('csv.roles');$maps = [];--- if (is_array($map)) {- $keys = array_keys($map);- foreach ($keys as $index) {- if (isset($roles[$index])) {- $name = $roles[$index];- if ($configRoles[$name]['mappable']) {- $maps[$index] = $name;- }+ $keys = array_keys($map);+ foreach ($keys as $index) {+ if (isset($roles[$index])) {+ $name = $roles[$index];+ if ($configRoles[$name]['mappable']) {+ $maps[$index] = $name;}}}diff --git a/app/Helpers/FiscalHelper.php b/app/Helpers/FiscalHelper.phpindex 3f5c9eebc9..e9b2cdc08c 100644--- a/app/Helpers/FiscalHelper.php+++ b/app/Helpers/FiscalHelper.php@@ -24,11 +24,7 @@ class FiscalHelper implements FiscalHelperInterface*/public function __construct(){- if (Preferences::get('customFiscalYear', 0)->data) {- $this->useCustomFiscalYear = true;- } else {- $this->useCustomFiscalYear = false;- }+ $this->useCustomFiscalYear = Preferences::get('customFiscalYear', false)->data;}/**@@ -44,9 +40,10 @@ class FiscalHelper implements FiscalHelperInterface// add 1 year and sub 1 day$endDate->addYear();$endDate->subDay();- } else {- $endDate->endOfYear();++ return $endDate;}+ $endDate->endOfYear();return $endDate;@@ -70,9 +67,10 @@ class FiscalHelper implements FiscalHelperInterfaceif ($startDate > $date) {$startDate->subYear();}- } else {- $startDate->startOfYear();++ return $startDate;}+ $startDate->startOfYear();return $startDate;}diff --git a/app/Helpers/Report/AccountReportHelper.php b/app/Helpers/Report/AccountReportHelper.phpindex 43d58a136d..a5edc9c590 100644--- a/app/Helpers/Report/AccountReportHelper.php+++ b/app/Helpers/Report/AccountReportHelper.php@@ -40,44 +40,20 @@ class AccountReportHelper implements AccountReportHelperInterface$endAmount = '0';$diff = '0';$ids = $accounts->pluck('id')->toArray();-- $yesterday = clone $start;+ $yesterday = clone $start;$yesterday->subDay();-// get balances for start.- $startSet = Account::leftJoin('transactions', 'transactions.account_id', '=', 'accounts.id')- ->leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id')- ->whereIn('accounts.id', $ids)- ->whereNull('transaction_journals.deleted_at')- ->whereNull('transactions.deleted_at')- ->where('transaction_journals.date', '<=', $yesterday->format('Y-m-d'))- ->groupBy('accounts.id')- ->get(['accounts.id', DB::raw('SUM(`transactions`.`amount`) as `balance`')]);+ $startSet = $this->getSet($ids, $yesterday);// a special consideration for accounts that did exist on this exact day.// we also grab the balance from today just in case, to see if that changes things.// it's a fall back for users who (rightly so) start keeping score at the first of// the month and find the first report lacking / broken.- $backupSet = Account::leftJoin('transactions', 'transactions.account_id', '=', 'accounts.id')- ->leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id')- ->whereIn('accounts.id', $ids)- ->whereNull('transaction_journals.deleted_at')- ->whereNull('transactions.deleted_at')- ->where('transaction_journals.date', '<=', $start->format('Y-m-d'))- ->groupBy('accounts.id')- ->get(['accounts.id', DB::raw('SUM(`transactions`.`amount`) as `balance`')]);+ $backupSet = $this->getSet($ids, $start);// and end:- $endSet = Account::leftJoin('transactions', 'transactions.account_id', '=', 'accounts.id')- ->leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id')- ->whereIn('accounts.id', $ids)- ->whereNull('transaction_journals.deleted_at')- ->whereNull('transactions.deleted_at')- ->where('transaction_journals.date', '<=', $end->format('Y-m-d'))- ->groupBy('accounts.id')- ->get(['accounts.id', DB::raw('SUM(`transactions`.`amount`) as `balance`')]);-+ $endSet = $this->getSet($ids, $end);$accounts->each(function (Account $account) use ($startSet, $endSet, $backupSet) {@@ -86,7 +62,6 @@ class AccountReportHelper implements AccountReportHelperInterface* made on today. So to get todays "start" balance, we sub one* day.*/- //$account->startBalance = '0';$account->endBalance = '0';$currentStart = $startSet->filter(@@ -121,7 +96,6 @@ class AccountReportHelper implements AccountReportHelperInterface});-// summarize:foreach ($accounts as $account) {$startAmount = bcadd($startAmount, $account->startBalance);@@ -137,4 +111,22 @@ class AccountReportHelper implements AccountReportHelperInterfacereturn $object;}++ /**+ * @param array $ids+ * @param Carbon $date+ *+ * @return Collection+ */+ private function getSet(array $ids, Carbon $date): Collection+ {+ Account::leftJoin('transactions', 'transactions.account_id', '=', 'accounts.id')+ ->leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id')+ ->whereIn('accounts.id', $ids)+ ->whereNull('transaction_journals.deleted_at')+ ->whereNull('transactions.deleted_at')+ ->where('transaction_journals.date', '<=', $date->format('Y-m-d'))+ ->groupBy('accounts.id')+ ->get(['accounts.id', DB::raw('SUM(`transactions`.`amount`) as `balance`')]);+ }}diff --git a/app/Helpers/Report/BudgetReportHelper.php b/app/Helpers/Report/BudgetReportHelper.phpindex 39ba0d8660..75c50408d5 100644--- a/app/Helpers/Report/BudgetReportHelper.php+++ b/app/Helpers/Report/BudgetReportHelper.php@@ -129,6 +129,11 @@ class BudgetReportHelper implements BudgetReportHelperInterface$set->push($budget);}}+ $set = $set->sortBy(+ function (Budget $budget) {+ return $budget->name;+ }+ );return $set;}diff --git a/app/Helpers/Report/ReportHelper.php b/app/Helpers/Report/ReportHelper.phpindex 6d4a660db1..dc8c7e71a9 100644--- a/app/Helpers/Report/ReportHelper.php+++ b/app/Helpers/Report/ReportHelper.php@@ -125,7 +125,7 @@ class ReportHelper implements ReportHelperInterface}$set = new Collection($array);- $set = $set->sort(+ $set = $set->sortBy(function (Category $category) {return $category->name;}diff --git a/app/Http/Controllers/Admin/UserController.php b/app/Http/Controllers/Admin/UserController.phpindex 9dbc765d07..7fe3bf1b70 100644--- a/app/Http/Controllers/Admin/UserController.php+++ b/app/Http/Controllers/Admin/UserController.php@@ -32,33 +32,25 @@ class UserController extends Controller$subTitle = strval(trans('firefly.user_administration'));$subTitleIcon = 'fa-users';$confirmAccount = env('MUST_CONFIRM_ACCOUNT', false);-- // list all users:- $users = $repository->all();+ $users = $repository->all();// add meta stuff.$users->each(function (User $user) use ($confirmAccount) {// is user activated?- $isConfirmed = Preferences::getForUser($user, 'user_confirmed', false)->data;+ $isConfirmed = Preferences::getForUser($user, 'user_confirmed', false)->data;+ $user->activated = true;if ($isConfirmed === false && $confirmAccount === true) {$user->activated = false;- } else {- $user->activated = true;}- // is user admin?$user->isAdmin = $user->hasRole('owner');-- // user has 2FA enabled?- $is2faEnabled = Preferences::getForUser($user, 'twoFactorAuthEnabled', false)->data;- $has2faSecret = !is_null(Preferences::getForUser($user, 'twoFactorAuthSecret'));+ $is2faEnabled = Preferences::getForUser($user, 'twoFactorAuthEnabled', false)->data;+ $has2faSecret = !is_null(Preferences::getForUser($user, 'twoFactorAuthSecret'));+ $user->has2FA = false;if ($is2faEnabled && $has2faSecret) {$user->has2FA = true;- } else {- $user->has2FA = false;}-});diff --git a/app/Http/Controllers/PreferencesController.php b/app/Http/Controllers/PreferencesController.phpindex 9683dd9515..e7106a218b 100644--- a/app/Http/Controllers/PreferencesController.php+++ b/app/Http/Controllers/PreferencesController.php@@ -130,7 +130,7 @@ class PreferencesController extends ControllerPreferences::set('budgetMaximum', $budgetMaximum);// custom fiscal year- $customFiscalYear = (int)Input::get('customFiscalYear');+ $customFiscalYear = intval(Input::get('customFiscalYear')) === 1;$fiscalYearStart = date('m-d', strtotime(Input::get('fiscalYearStart')));Preferences::set('customFiscalYear', $customFiscalYear);Preferences::set('fiscalYearStart', $fiscalYearStart);diff --git a/app/Providers/AccountServiceProvider.php b/app/Providers/AccountServiceProvider.phpindex b8bd3dec20..9f0041a758 100644--- a/app/Providers/AccountServiceProvider.php+++ b/app/Providers/AccountServiceProvider.php@@ -2,7 +2,6 @@namespace FireflyIII\Providers;-use Auth;use FireflyIII\Exceptions\FireflyException;use Illuminate\Foundation\Application;use Illuminate\Support\ServiceProvider;@@ -34,10 +33,10 @@ class AccountServiceProvider extends ServiceProvider$this->app->bind('FireflyIII\Repositories\Account\AccountRepositoryInterface',function (Application $app, array $arguments) {- if (!isset($arguments[0]) && Auth::check()) {- return app('FireflyIII\Repositories\Account\AccountRepository', [Auth::user()]);+ if (!isset($arguments[0]) && $app->auth->check()) {+ return app('FireflyIII\Repositories\Account\AccountRepository', [$app->auth->user()]);} else {- if (!isset($arguments[0]) && !Auth::check()) {+ if (!isset($arguments[0]) && !$app->auth->check()) {throw new FireflyException('There is no user present.');}}diff --git a/app/Providers/AttachmentServiceProvider.php b/app/Providers/AttachmentServiceProvider.phpindex eb35505e2f..e0da2cd9e9 100644--- a/app/Providers/AttachmentServiceProvider.php+++ b/app/Providers/AttachmentServiceProvider.php@@ -2,7 +2,6 @@namespace FireflyIII\Providers;-use Auth;use FireflyIII\Exceptions\FireflyException;use Illuminate\Foundation\Application;use Illuminate\Support\ServiceProvider;@@ -34,10 +33,10 @@ class AttachmentServiceProvider extends ServiceProvider$this->app->bind('FireflyIII\Repositories\Attachment\AttachmentRepositoryInterface',function (Application $app, array $arguments) {- if (!isset($arguments[0]) && Auth::check()) {- return app('FireflyIII\Repositories\Attachment\AttachmentRepository', [Auth::user()]);+ if (!isset($arguments[0]) && $app->auth->check()) {+ return app('FireflyIII\Repositories\Attachment\AttachmentRepository', [$app->auth->user()]);} else {- if (!isset($arguments[0]) && !Auth::check()) {+ if (!isset($arguments[0]) && !$app->auth->check()) {throw new FireflyException('There is no user present.');}}diff --git a/app/Providers/BillServiceProvider.php b/app/Providers/BillServiceProvider.phpindex 1ba84eaf3d..c6de019fdb 100644--- a/app/Providers/BillServiceProvider.php+++ b/app/Providers/BillServiceProvider.php@@ -2,7 +2,6 @@namespace FireflyIII\Providers;-use Auth;use FireflyIII\Exceptions\FireflyException;use Illuminate\Foundation\Application;use Illuminate\Support\ServiceProvider;@@ -34,10 +33,10 @@ class BillServiceProvider extends ServiceProvider$this->app->bind('FireflyIII\Repositories\Bill\BillRepositoryInterface',function (Application $app, array $arguments) {- if (!isset($arguments[0]) && Auth::check()) {- return app('FireflyIII\Repositories\Bill\BillRepository', [Auth::user()]);+ if (!isset($arguments[0]) && $app->auth->check()) {+ return app('FireflyIII\Repositories\Bill\BillRepository', [$app->auth->user()]);} else {- if (!isset($arguments[0]) && !Auth::check()) {+ if (!isset($arguments[0]) && !$app->auth->check()) {throw new FireflyException('There is no user present.');}}diff --git a/app/Providers/BudgetServiceProvider.php b/app/Providers/BudgetServiceProvider.phpindex 02364b9eb5..60cb44b5fe 100644--- a/app/Providers/BudgetServiceProvider.php+++ b/app/Providers/BudgetServiceProvider.php@@ -2,7 +2,6 @@namespace FireflyIII\Providers;-use Auth;use FireflyIII\Exceptions\FireflyException;use Illuminate\Foundation\Application;use Illuminate\Support\ServiceProvider;@@ -34,10 +33,10 @@ class BudgetServiceProvider extends ServiceProvider$this->app->bind('FireflyIII\Repositories\Budget\BudgetRepositoryInterface',function (Application $app, array $arguments) {- if (!isset($arguments[0]) && Auth::check()) {- return app('FireflyIII\Repositories\Budget\BudgetRepository', [Auth::user()]);+ if (!isset($arguments[0]) && $app->auth->check()) {+ return app('FireflyIII\Repositories\Budget\BudgetRepository', [$app->auth->user()]);} else {- if (!isset($arguments[0]) && !Auth::check()) {+ if (!isset($arguments[0]) && !$app->auth->check()) {throw new FireflyException('There is no user present.');}}diff --git a/app/Providers/CategoryServiceProvider.php b/app/Providers/CategoryServiceProvider.phpindex 6e8ce7decd..c299e57c12 100644--- a/app/Providers/CategoryServiceProvider.php+++ b/app/Providers/CategoryServiceProvider.php@@ -2,7 +2,6 @@namespace FireflyIII\Providers;-use Auth;use FireflyIII\Exceptions\FireflyException;use Illuminate\Foundation\Application;use Illuminate\Support\ServiceProvider;@@ -34,10 +33,10 @@ class CategoryServiceProvider extends ServiceProvider$this->app->bind('FireflyIII\Repositories\Category\CategoryRepositoryInterface',function (Application $app, array $arguments) {- if (!isset($arguments[0]) && Auth::check()) {- return app('FireflyIII\Repositories\Category\CategoryRepository', [Auth::user()]);+ if (!isset($arguments[0]) && $app->auth->check()) {+ return app('FireflyIII\Repositories\Category\CategoryRepository', [$app->auth->user()]);} else {- if (!isset($arguments[0]) && !Auth::check()) {+ if (!isset($arguments[0]) && !$app->auth->check()) {throw new FireflyException('There is no user present.');}}@@ -49,10 +48,10 @@ class CategoryServiceProvider extends ServiceProvider$this->app->bind('FireflyIII\Repositories\Category\SingleCategoryRepositoryInterface',function (Application $app, array $arguments) {- if (!isset($arguments[0]) && Auth::check()) {- return app('FireflyIII\Repositories\Category\SingleCategoryRepository', [Auth::user()]);+ if (!isset($arguments[0]) && $app->auth->check()) {+ return app('FireflyIII\Repositories\Category\SingleCategoryRepository', [$app->auth->user()]);} else {- if (!isset($arguments[0]) && !Auth::check()) {+ if (!isset($arguments[0]) && !$app->auth->check()) {throw new FireflyException('There is no user present.');}}diff --git a/app/Providers/ExportJobServiceProvider.php b/app/Providers/ExportJobServiceProvider.phpindex b63d2b8819..fe4a5da13a 100644--- a/app/Providers/ExportJobServiceProvider.php+++ b/app/Providers/ExportJobServiceProvider.php@@ -2,7 +2,6 @@namespace FireflyIII\Providers;-use Auth;use FireflyIII\Exceptions\FireflyException;use Illuminate\Foundation\Application;use Illuminate\Support\ServiceProvider;@@ -25,10 +24,10 @@ class ExportJobServiceProvider extends ServiceProvider$this->app->bind('FireflyIII\Repositories\ExportJob\ExportJobRepositoryInterface',function (Application $app, array $arguments) {- if (!isset($arguments[0]) && Auth::check()) {- return app('FireflyIII\Repositories\ExportJob\ExportJobRepository', [Auth::user()]);+ if (!isset($arguments[0]) && $app->auth->check()) {+ return app('FireflyIII\Repositories\ExportJob\ExportJobRepository', [$app->auth->user()]);} else {- if (!isset($arguments[0]) && !Auth::check()) {+ if (!isset($arguments[0]) && !$app->auth->check()) {throw new FireflyException('There is no user present.');}}diff --git a/app/Providers/PiggyBankServiceProvider.php b/app/Providers/PiggyBankServiceProvider.phpindex 2586776891..d8174a4a0c 100644--- a/app/Providers/PiggyBankServiceProvider.php+++ b/app/Providers/PiggyBankServiceProvider.php@@ -2,7 +2,6 @@namespace FireflyIII\Providers;-use Auth;use FireflyIII\Exceptions\FireflyException;use Illuminate\Foundation\Application;use Illuminate\Support\ServiceProvider;@@ -35,10 +34,10 @@ class PiggyBankServiceProvider extends ServiceProvider$this->app->bind('FireflyIII\Repositories\PiggyBank\PiggyBankRepositoryInterface',function (Application $app, array $arguments) {- if (!isset($arguments[0]) && Auth::check()) {- return app('FireflyIII\Repositories\PiggyBank\PiggyBankRepository', [Auth::user()]);+ if (!isset($arguments[0]) && $app->auth->check()) {+ return app('FireflyIII\Repositories\PiggyBank\PiggyBankRepository', [$app->auth->user()]);} else {- if (!isset($arguments[0]) && !Auth::check()) {+ if (!isset($arguments[0]) && !$app->auth->check()) {throw new FireflyException('There is no user present.');}}diff --git a/app/Providers/RuleGroupServiceProvider.php b/app/Providers/RuleGroupServiceProvider.phpindex 82a9566303..ddea53d92a 100644--- a/app/Providers/RuleGroupServiceProvider.php+++ b/app/Providers/RuleGroupServiceProvider.php@@ -2,7 +2,6 @@namespace FireflyIII\Providers;-use Auth;use FireflyIII\Exceptions\FireflyException;use Illuminate\Foundation\Application;use Illuminate\Support\ServiceProvider;@@ -35,10 +34,10 @@ class RuleGroupServiceProvider extends ServiceProvider$this->app->bind('FireflyIII\Repositories\RuleGroup\RuleGroupRepositoryInterface',function (Application $app, array $arguments) {- if (!isset($arguments[0]) && Auth::check()) {- return app('FireflyIII\Repositories\RuleGroup\RuleGroupRepository', [Auth::user()]);+ if (!isset($arguments[0]) && $app->auth->check()) {+ return app('FireflyIII\Repositories\RuleGroup\RuleGroupRepository', [$app->auth->user()]);} else {- if (!isset($arguments[0]) && !Auth::check()) {+ if (!isset($arguments[0]) && !$app->auth->check()) {throw new FireflyException('There is no user present.');}}diff --git a/app/Providers/RuleServiceProvider.php b/app/Providers/RuleServiceProvider.phpindex c3480920f1..38059ecd6f 100644--- a/app/Providers/RuleServiceProvider.php+++ b/app/Providers/RuleServiceProvider.php@@ -2,7 +2,6 @@namespace FireflyIII\Providers;-use Auth;use FireflyIII\Exceptions\FireflyException;use Illuminate\Foundation\Application;use Illuminate\Support\ServiceProvider;@@ -34,10 +33,10 @@ class RuleServiceProvider extends ServiceProvider$this->app->bind('FireflyIII\Repositories\Rule\RuleRepositoryInterface',function (Application $app, array $arguments) {- if (!isset($arguments[0]) && Auth::check()) {- return app('FireflyIII\Repositories\Rule\RuleRepository', [Auth::user()]);+ if (!isset($arguments[0]) && $app->auth->check()) {+ return app('FireflyIII\Repositories\Rule\RuleRepository', [$app->auth->user()]);} else {- if (!isset($arguments[0]) && !Auth::check()) {+ if (!isset($arguments[0]) && !$app->auth->check()) {throw new FireflyException('There is no user present.');}}diff --git a/app/Providers/TagServiceProvider.php b/app/Providers/TagServiceProvider.phpindex 227b27e73c..0d59552cfc 100644--- a/app/Providers/TagServiceProvider.php+++ b/app/Providers/TagServiceProvider.php@@ -2,7 +2,6 @@namespace FireflyIII\Providers;-use Auth;use FireflyIII\Exceptions\FireflyException;use Illuminate\Foundation\Application;use Illuminate\Support\ServiceProvider;@@ -34,10 +33,10 @@ class TagServiceProvider extends ServiceProvider$this->app->bind('FireflyIII\Repositories\Tag\TagRepositoryInterface',function (Application $app, array $arguments) {- if (!isset($arguments[0]) && Auth::check()) {- return app('FireflyIII\Repositories\Tag\TagRepository', [Auth::user()]);+ if (!isset($arguments[0]) && $app->auth->check()) {+ return app('FireflyIII\Repositories\Tag\TagRepository', [$app->auth->user()]);} else {- if (!isset($arguments[0]) && !Auth::check()) {+ if (!isset($arguments[0]) && !$app->auth->check()) {throw new FireflyException('There is no user present.');}}