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,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;
}
}
}

View File

@ -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 FiscalHelperInterface
if ($startDate > $date) {
$startDate->subYear();
}
} else {
$startDate->startOfYear();
return $startDate;
}
$startDate->startOfYear();
return $startDate;
}

View File

@ -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 AccountReportHelperInterface
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 = $set->sortBy(
function (Budget $budget) {
return $budget->name;
}
);
return $set;
}

View File

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

View File

@ -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;
}
}
);

View File

@ -130,7 +130,7 @@ class PreferencesController extends Controller
Preferences::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);

View File

@ -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.');
}
}

View File

@ -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.');
}
}

View File

@ -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.');
}
}

View File

@ -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.');
}
}

View File

@ -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.');
}
}

View File

@ -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.');
}
}

View File

@ -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.');
}
}

View File

@ -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.');
}
}

View File

@ -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.');
}
}

View File

@ -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.');
}
}