Code cleanup.

This commit is contained in:
James Cole
2016-04-27 10:38:51 +02:00
parent 6aa50e3c00
commit 3d4489efe6
17 changed files with 81 additions and 108 deletions

View File

@@ -62,9 +62,6 @@ class Wizard implements WizardInterface
{ {
$configRoles = config('csv.roles'); $configRoles = config('csv.roles');
$maps = []; $maps = [];
if (is_array($map)) {
$keys = array_keys($map); $keys = array_keys($map);
foreach ($keys as $index) { foreach ($keys as $index) {
if (isset($roles[$index])) { if (isset($roles[$index])) {
@@ -74,7 +71,6 @@ class Wizard implements WizardInterface
} }
} }
} }
}
return $maps; return $maps;

View File

@@ -24,11 +24,7 @@ class FiscalHelper implements FiscalHelperInterface
*/ */
public function __construct() public function __construct()
{ {
if (Preferences::get('customFiscalYear', 0)->data) { $this->useCustomFiscalYear = Preferences::get('customFiscalYear', false)->data;
$this->useCustomFiscalYear = true;
} else {
$this->useCustomFiscalYear = false;
}
} }
/** /**
@@ -44,9 +40,10 @@ class FiscalHelper implements FiscalHelperInterface
// add 1 year and sub 1 day // add 1 year and sub 1 day
$endDate->addYear(); $endDate->addYear();
$endDate->subDay(); $endDate->subDay();
} else {
$endDate->endOfYear(); return $endDate;
} }
$endDate->endOfYear();
return $endDate; return $endDate;
@@ -70,9 +67,10 @@ class FiscalHelper implements FiscalHelperInterface
if ($startDate > $date) { if ($startDate > $date) {
$startDate->subYear(); $startDate->subYear();
} }
} else {
$startDate->startOfYear(); return $startDate;
} }
$startDate->startOfYear();
return $startDate; return $startDate;
} }

View File

@@ -40,44 +40,20 @@ class AccountReportHelper implements AccountReportHelperInterface
$endAmount = '0'; $endAmount = '0';
$diff = '0'; $diff = '0';
$ids = $accounts->pluck('id')->toArray(); $ids = $accounts->pluck('id')->toArray();
$yesterday = clone $start; $yesterday = clone $start;
$yesterday->subDay(); $yesterday->subDay();
// get balances for start. // get balances for start.
$startSet = Account::leftJoin('transactions', 'transactions.account_id', '=', 'accounts.id') $startSet = $this->getSet($ids, $yesterday);
->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`')]);
// a special consideration for accounts that did exist on this exact day. // 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. // 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 // 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. // the month and find the first report lacking / broken.
$backupSet = Account::leftJoin('transactions', 'transactions.account_id', '=', 'accounts.id') $backupSet = $this->getSet($ids, $start);
->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`')]);
// and end: // and end:
$endSet = Account::leftJoin('transactions', 'transactions.account_id', '=', 'accounts.id') $endSet = $this->getSet($ids, $end);
->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`')]);
$accounts->each( $accounts->each(
function (Account $account) use ($startSet, $endSet, $backupSet) { 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 * made on today. So to get todays "start" balance, we sub one
* day. * day.
*/ */
//
$account->startBalance = '0'; $account->startBalance = '0';
$account->endBalance = '0'; $account->endBalance = '0';
$currentStart = $startSet->filter( $currentStart = $startSet->filter(
@@ -121,7 +96,6 @@ class AccountReportHelper implements AccountReportHelperInterface
} }
); );
// summarize: // summarize:
foreach ($accounts as $account) { foreach ($accounts as $account) {
$startAmount = bcadd($startAmount, $account->startBalance); $startAmount = bcadd($startAmount, $account->startBalance);
@@ -137,4 +111,22 @@ class AccountReportHelper implements AccountReportHelperInterface
return $object; return $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`')]);
}
} }

View File

@@ -129,6 +129,11 @@ class BudgetReportHelper implements BudgetReportHelperInterface
$set->push($budget); $set->push($budget);
} }
} }
$set = $set->sortBy(
function (Budget $budget) {
return $budget->name;
}
);
return $set; return $set;
} }

View File

@@ -125,7 +125,7 @@ class ReportHelper implements ReportHelperInterface
} }
$set = new Collection($array); $set = new Collection($array);
$set = $set->sort( $set = $set->sortBy(
function (Category $category) { function (Category $category) {
return $category->name; return $category->name;
} }

View File

@@ -32,8 +32,6 @@ class UserController extends Controller
$subTitle = strval(trans('firefly.user_administration')); $subTitle = strval(trans('firefly.user_administration'));
$subTitleIcon = 'fa-users'; $subTitleIcon = 'fa-users';
$confirmAccount = env('MUST_CONFIRM_ACCOUNT', false); $confirmAccount = env('MUST_CONFIRM_ACCOUNT', false);
// list all users:
$users = $repository->all(); $users = $repository->all();
// add meta stuff. // add meta stuff.
@@ -41,24 +39,18 @@ class UserController extends Controller
function (User $user) use ($confirmAccount) { function (User $user) use ($confirmAccount) {
// is user activated? // 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) { if ($isConfirmed === false && $confirmAccount === true) {
$user->activated = false; $user->activated = false;
} else {
$user->activated = true;
} }
// is user admin?
$user->isAdmin = $user->hasRole('owner'); $user->isAdmin = $user->hasRole('owner');
// user has 2FA enabled?
$is2faEnabled = Preferences::getForUser($user, 'twoFactorAuthEnabled', false)->data; $is2faEnabled = Preferences::getForUser($user, 'twoFactorAuthEnabled', false)->data;
$has2faSecret = !is_null(Preferences::getForUser($user, 'twoFactorAuthSecret')); $has2faSecret = !is_null(Preferences::getForUser($user, 'twoFactorAuthSecret'));
$user->has2FA = false;
if ($is2faEnabled && $has2faSecret) { if ($is2faEnabled && $has2faSecret) {
$user->has2FA = true; $user->has2FA = true;
} else {
$user->has2FA = false;
} }
} }
); );

View File

@@ -130,7 +130,7 @@ class PreferencesController extends Controller
Preferences::set('budgetMaximum', $budgetMaximum); Preferences::set('budgetMaximum', $budgetMaximum);
// custom fiscal year // custom fiscal year
$customFiscalYear = (int)Input::get('customFiscalYear'); $customFiscalYear = intval(Input::get('customFiscalYear')) === 1;
$fiscalYearStart = date('m-d', strtotime(Input::get('fiscalYearStart'))); $fiscalYearStart = date('m-d', strtotime(Input::get('fiscalYearStart')));
Preferences::set('customFiscalYear', $customFiscalYear); Preferences::set('customFiscalYear', $customFiscalYear);
Preferences::set('fiscalYearStart', $fiscalYearStart); Preferences::set('fiscalYearStart', $fiscalYearStart);

View File

@@ -2,7 +2,6 @@
namespace FireflyIII\Providers; namespace FireflyIII\Providers;
use Auth;
use FireflyIII\Exceptions\FireflyException; use FireflyIII\Exceptions\FireflyException;
use Illuminate\Foundation\Application; use Illuminate\Foundation\Application;
use Illuminate\Support\ServiceProvider; use Illuminate\Support\ServiceProvider;
@@ -34,10 +33,10 @@ class AccountServiceProvider extends ServiceProvider
$this->app->bind( $this->app->bind(
'FireflyIII\Repositories\Account\AccountRepositoryInterface', 'FireflyIII\Repositories\Account\AccountRepositoryInterface',
function (Application $app, array $arguments) { function (Application $app, array $arguments) {
if (!isset($arguments[0]) && Auth::check()) { if (!isset($arguments[0]) && $app->auth->check()) {
return app('FireflyIII\Repositories\Account\AccountRepository', [Auth::user()]); return app('FireflyIII\Repositories\Account\AccountRepository', [$app->auth->user()]);
} else { } else {
if (!isset($arguments[0]) && !Auth::check()) { if (!isset($arguments[0]) && !$app->auth->check()) {
throw new FireflyException('There is no user present.'); throw new FireflyException('There is no user present.');
} }
} }

View File

@@ -2,7 +2,6 @@
namespace FireflyIII\Providers; namespace FireflyIII\Providers;
use Auth;
use FireflyIII\Exceptions\FireflyException; use FireflyIII\Exceptions\FireflyException;
use Illuminate\Foundation\Application; use Illuminate\Foundation\Application;
use Illuminate\Support\ServiceProvider; use Illuminate\Support\ServiceProvider;
@@ -34,10 +33,10 @@ class AttachmentServiceProvider extends ServiceProvider
$this->app->bind( $this->app->bind(
'FireflyIII\Repositories\Attachment\AttachmentRepositoryInterface', 'FireflyIII\Repositories\Attachment\AttachmentRepositoryInterface',
function (Application $app, array $arguments) { function (Application $app, array $arguments) {
if (!isset($arguments[0]) && Auth::check()) { if (!isset($arguments[0]) && $app->auth->check()) {
return app('FireflyIII\Repositories\Attachment\AttachmentRepository', [Auth::user()]); return app('FireflyIII\Repositories\Attachment\AttachmentRepository', [$app->auth->user()]);
} else { } else {
if (!isset($arguments[0]) && !Auth::check()) { if (!isset($arguments[0]) && !$app->auth->check()) {
throw new FireflyException('There is no user present.'); throw new FireflyException('There is no user present.');
} }
} }

View File

@@ -2,7 +2,6 @@
namespace FireflyIII\Providers; namespace FireflyIII\Providers;
use Auth;
use FireflyIII\Exceptions\FireflyException; use FireflyIII\Exceptions\FireflyException;
use Illuminate\Foundation\Application; use Illuminate\Foundation\Application;
use Illuminate\Support\ServiceProvider; use Illuminate\Support\ServiceProvider;
@@ -34,10 +33,10 @@ class BillServiceProvider extends ServiceProvider
$this->app->bind( $this->app->bind(
'FireflyIII\Repositories\Bill\BillRepositoryInterface', 'FireflyIII\Repositories\Bill\BillRepositoryInterface',
function (Application $app, array $arguments) { function (Application $app, array $arguments) {
if (!isset($arguments[0]) && Auth::check()) { if (!isset($arguments[0]) && $app->auth->check()) {
return app('FireflyIII\Repositories\Bill\BillRepository', [Auth::user()]); return app('FireflyIII\Repositories\Bill\BillRepository', [$app->auth->user()]);
} else { } else {
if (!isset($arguments[0]) && !Auth::check()) { if (!isset($arguments[0]) && !$app->auth->check()) {
throw new FireflyException('There is no user present.'); throw new FireflyException('There is no user present.');
} }
} }

View File

@@ -2,7 +2,6 @@
namespace FireflyIII\Providers; namespace FireflyIII\Providers;
use Auth;
use FireflyIII\Exceptions\FireflyException; use FireflyIII\Exceptions\FireflyException;
use Illuminate\Foundation\Application; use Illuminate\Foundation\Application;
use Illuminate\Support\ServiceProvider; use Illuminate\Support\ServiceProvider;
@@ -34,10 +33,10 @@ class BudgetServiceProvider extends ServiceProvider
$this->app->bind( $this->app->bind(
'FireflyIII\Repositories\Budget\BudgetRepositoryInterface', 'FireflyIII\Repositories\Budget\BudgetRepositoryInterface',
function (Application $app, array $arguments) { function (Application $app, array $arguments) {
if (!isset($arguments[0]) && Auth::check()) { if (!isset($arguments[0]) && $app->auth->check()) {
return app('FireflyIII\Repositories\Budget\BudgetRepository', [Auth::user()]); return app('FireflyIII\Repositories\Budget\BudgetRepository', [$app->auth->user()]);
} else { } else {
if (!isset($arguments[0]) && !Auth::check()) { if (!isset($arguments[0]) && !$app->auth->check()) {
throw new FireflyException('There is no user present.'); throw new FireflyException('There is no user present.');
} }
} }

View File

@@ -2,7 +2,6 @@
namespace FireflyIII\Providers; namespace FireflyIII\Providers;
use Auth;
use FireflyIII\Exceptions\FireflyException; use FireflyIII\Exceptions\FireflyException;
use Illuminate\Foundation\Application; use Illuminate\Foundation\Application;
use Illuminate\Support\ServiceProvider; use Illuminate\Support\ServiceProvider;
@@ -34,10 +33,10 @@ class CategoryServiceProvider extends ServiceProvider
$this->app->bind( $this->app->bind(
'FireflyIII\Repositories\Category\CategoryRepositoryInterface', 'FireflyIII\Repositories\Category\CategoryRepositoryInterface',
function (Application $app, array $arguments) { function (Application $app, array $arguments) {
if (!isset($arguments[0]) && Auth::check()) { if (!isset($arguments[0]) && $app->auth->check()) {
return app('FireflyIII\Repositories\Category\CategoryRepository', [Auth::user()]); return app('FireflyIII\Repositories\Category\CategoryRepository', [$app->auth->user()]);
} else { } else {
if (!isset($arguments[0]) && !Auth::check()) { if (!isset($arguments[0]) && !$app->auth->check()) {
throw new FireflyException('There is no user present.'); throw new FireflyException('There is no user present.');
} }
} }
@@ -49,10 +48,10 @@ class CategoryServiceProvider extends ServiceProvider
$this->app->bind( $this->app->bind(
'FireflyIII\Repositories\Category\SingleCategoryRepositoryInterface', 'FireflyIII\Repositories\Category\SingleCategoryRepositoryInterface',
function (Application $app, array $arguments) { function (Application $app, array $arguments) {
if (!isset($arguments[0]) && Auth::check()) { if (!isset($arguments[0]) && $app->auth->check()) {
return app('FireflyIII\Repositories\Category\SingleCategoryRepository', [Auth::user()]); return app('FireflyIII\Repositories\Category\SingleCategoryRepository', [$app->auth->user()]);
} else { } else {
if (!isset($arguments[0]) && !Auth::check()) { if (!isset($arguments[0]) && !$app->auth->check()) {
throw new FireflyException('There is no user present.'); throw new FireflyException('There is no user present.');
} }
} }

View File

@@ -2,7 +2,6 @@
namespace FireflyIII\Providers; namespace FireflyIII\Providers;
use Auth;
use FireflyIII\Exceptions\FireflyException; use FireflyIII\Exceptions\FireflyException;
use Illuminate\Foundation\Application; use Illuminate\Foundation\Application;
use Illuminate\Support\ServiceProvider; use Illuminate\Support\ServiceProvider;
@@ -25,10 +24,10 @@ class ExportJobServiceProvider extends ServiceProvider
$this->app->bind( $this->app->bind(
'FireflyIII\Repositories\ExportJob\ExportJobRepositoryInterface', 'FireflyIII\Repositories\ExportJob\ExportJobRepositoryInterface',
function (Application $app, array $arguments) { function (Application $app, array $arguments) {
if (!isset($arguments[0]) && Auth::check()) { if (!isset($arguments[0]) && $app->auth->check()) {
return app('FireflyIII\Repositories\ExportJob\ExportJobRepository', [Auth::user()]); return app('FireflyIII\Repositories\ExportJob\ExportJobRepository', [$app->auth->user()]);
} else { } else {
if (!isset($arguments[0]) && !Auth::check()) { if (!isset($arguments[0]) && !$app->auth->check()) {
throw new FireflyException('There is no user present.'); throw new FireflyException('There is no user present.');
} }
} }

View File

@@ -2,7 +2,6 @@
namespace FireflyIII\Providers; namespace FireflyIII\Providers;
use Auth;
use FireflyIII\Exceptions\FireflyException; use FireflyIII\Exceptions\FireflyException;
use Illuminate\Foundation\Application; use Illuminate\Foundation\Application;
use Illuminate\Support\ServiceProvider; use Illuminate\Support\ServiceProvider;
@@ -35,10 +34,10 @@ class PiggyBankServiceProvider extends ServiceProvider
$this->app->bind( $this->app->bind(
'FireflyIII\Repositories\PiggyBank\PiggyBankRepositoryInterface', 'FireflyIII\Repositories\PiggyBank\PiggyBankRepositoryInterface',
function (Application $app, array $arguments) { function (Application $app, array $arguments) {
if (!isset($arguments[0]) && Auth::check()) { if (!isset($arguments[0]) && $app->auth->check()) {
return app('FireflyIII\Repositories\PiggyBank\PiggyBankRepository', [Auth::user()]); return app('FireflyIII\Repositories\PiggyBank\PiggyBankRepository', [$app->auth->user()]);
} else { } else {
if (!isset($arguments[0]) && !Auth::check()) { if (!isset($arguments[0]) && !$app->auth->check()) {
throw new FireflyException('There is no user present.'); throw new FireflyException('There is no user present.');
} }
} }

View File

@@ -2,7 +2,6 @@
namespace FireflyIII\Providers; namespace FireflyIII\Providers;
use Auth;
use FireflyIII\Exceptions\FireflyException; use FireflyIII\Exceptions\FireflyException;
use Illuminate\Foundation\Application; use Illuminate\Foundation\Application;
use Illuminate\Support\ServiceProvider; use Illuminate\Support\ServiceProvider;
@@ -35,10 +34,10 @@ class RuleGroupServiceProvider extends ServiceProvider
$this->app->bind( $this->app->bind(
'FireflyIII\Repositories\RuleGroup\RuleGroupRepositoryInterface', 'FireflyIII\Repositories\RuleGroup\RuleGroupRepositoryInterface',
function (Application $app, array $arguments) { function (Application $app, array $arguments) {
if (!isset($arguments[0]) && Auth::check()) { if (!isset($arguments[0]) && $app->auth->check()) {
return app('FireflyIII\Repositories\RuleGroup\RuleGroupRepository', [Auth::user()]); return app('FireflyIII\Repositories\RuleGroup\RuleGroupRepository', [$app->auth->user()]);
} else { } else {
if (!isset($arguments[0]) && !Auth::check()) { if (!isset($arguments[0]) && !$app->auth->check()) {
throw new FireflyException('There is no user present.'); throw new FireflyException('There is no user present.');
} }
} }

View File

@@ -2,7 +2,6 @@
namespace FireflyIII\Providers; namespace FireflyIII\Providers;
use Auth;
use FireflyIII\Exceptions\FireflyException; use FireflyIII\Exceptions\FireflyException;
use Illuminate\Foundation\Application; use Illuminate\Foundation\Application;
use Illuminate\Support\ServiceProvider; use Illuminate\Support\ServiceProvider;
@@ -34,10 +33,10 @@ class RuleServiceProvider extends ServiceProvider
$this->app->bind( $this->app->bind(
'FireflyIII\Repositories\Rule\RuleRepositoryInterface', 'FireflyIII\Repositories\Rule\RuleRepositoryInterface',
function (Application $app, array $arguments) { function (Application $app, array $arguments) {
if (!isset($arguments[0]) && Auth::check()) { if (!isset($arguments[0]) && $app->auth->check()) {
return app('FireflyIII\Repositories\Rule\RuleRepository', [Auth::user()]); return app('FireflyIII\Repositories\Rule\RuleRepository', [$app->auth->user()]);
} else { } else {
if (!isset($arguments[0]) && !Auth::check()) { if (!isset($arguments[0]) && !$app->auth->check()) {
throw new FireflyException('There is no user present.'); throw new FireflyException('There is no user present.');
} }
} }

View File

@@ -2,7 +2,6 @@
namespace FireflyIII\Providers; namespace FireflyIII\Providers;
use Auth;
use FireflyIII\Exceptions\FireflyException; use FireflyIII\Exceptions\FireflyException;
use Illuminate\Foundation\Application; use Illuminate\Foundation\Application;
use Illuminate\Support\ServiceProvider; use Illuminate\Support\ServiceProvider;
@@ -34,10 +33,10 @@ class TagServiceProvider extends ServiceProvider
$this->app->bind( $this->app->bind(
'FireflyIII\Repositories\Tag\TagRepositoryInterface', 'FireflyIII\Repositories\Tag\TagRepositoryInterface',
function (Application $app, array $arguments) { function (Application $app, array $arguments) {
if (!isset($arguments[0]) && Auth::check()) { if (!isset($arguments[0]) && $app->auth->check()) {
return app('FireflyIII\Repositories\Tag\TagRepository', [Auth::user()]); return app('FireflyIII\Repositories\Tag\TagRepository', [$app->auth->user()]);
} else { } else {
if (!isset($arguments[0]) && !Auth::check()) { if (!isset($arguments[0]) && !$app->auth->check()) {
throw new FireflyException('There is no user present.'); throw new FireflyException('There is no user present.');
} }
} }