mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Some code cleanup courtesy of PHPStorm.
This commit is contained in:
parent
820722f44e
commit
f69be86c74
@ -89,18 +89,13 @@ class ChartJsAccountChartGenerator implements AccountChartGenerator
|
|||||||
{
|
{
|
||||||
// language:
|
// language:
|
||||||
$format = trans('config.month_and_day');
|
$format = trans('config.month_and_day');
|
||||||
$data = [
|
$data = ['count' => 0, 'labels' => [], 'datasets' => [],];
|
||||||
'count' => 0,
|
|
||||||
'labels' => [],
|
|
||||||
'datasets' => [],
|
|
||||||
];
|
|
||||||
$current = clone $start;
|
$current = clone $start;
|
||||||
while ($current <= $end) {
|
while ($current <= $end) {
|
||||||
$data['labels'][] = $current->formatLocalized($format);
|
$data['labels'][] = $current->formatLocalized($format);
|
||||||
$current->addDay();
|
$current->addDay();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
foreach ($accounts as $account) {
|
foreach ($accounts as $account) {
|
||||||
$set = [
|
$set = [
|
||||||
'label' => $account->name,
|
'label' => $account->name,
|
||||||
@ -148,8 +143,8 @@ class ChartJsAccountChartGenerator implements AccountChartGenerator
|
|||||||
'datasets' => [
|
'datasets' => [
|
||||||
[
|
[
|
||||||
'label' => $account->name,
|
'label' => $account->name,
|
||||||
'data' => []
|
'data' => [],
|
||||||
]
|
],
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
$range = Steam::balanceInRange($account, $start, $end);
|
$range = Steam::balanceInRange($account, $start, $end);
|
||||||
|
@ -63,7 +63,8 @@ class Wizard implements WizardInterface
|
|||||||
|
|
||||||
|
|
||||||
if (is_array($map)) {
|
if (is_array($map)) {
|
||||||
foreach ($map as $index => $field) {
|
$keys = array_keys($map);
|
||||||
|
foreach ($keys as $index) {
|
||||||
if (isset($roles[$index])) {
|
if (isset($roles[$index])) {
|
||||||
$name = $roles[$index];
|
$name = $roles[$index];
|
||||||
if ($configRoles[$name]['mappable']) {
|
if ($configRoles[$name]['mappable']) {
|
||||||
|
@ -66,15 +66,7 @@ class AuthController extends Controller
|
|||||||
*/
|
*/
|
||||||
public function login(Request $request)
|
public function login(Request $request)
|
||||||
{
|
{
|
||||||
$this->validate(
|
$this->validate($request, [$this->loginUsername() => 'required', 'password' => 'required',]);
|
||||||
$request, [
|
|
||||||
$this->loginUsername() => 'required', 'password' => 'required',
|
|
||||||
]
|
|
||||||
);
|
|
||||||
|
|
||||||
// If the class is using the ThrottlesLogins trait, we can automatically throttle
|
|
||||||
// the login attempts for this application. We'll key this by the username and
|
|
||||||
// the IP address of the client making these requests into this application.
|
|
||||||
$throttles = $this->isUsingThrottlesLoginsTrait();
|
$throttles = $this->isUsingThrottlesLoginsTrait();
|
||||||
|
|
||||||
if ($throttles && $this->hasTooManyLoginAttempts($request)) {
|
if ($throttles && $this->hasTooManyLoginAttempts($request)) {
|
||||||
@ -102,10 +94,6 @@ class AuthController extends Controller
|
|||||||
$message = trans('firefly.' . $code . '_error', ['email' => $credentials['email']]);
|
$message = trans('firefly.' . $code . '_error', ['email' => $credentials['email']]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// If the login attempt was unsuccessful we will increment the number of attempts
|
|
||||||
// to login and redirect the user back to the login form. Of course, when this
|
|
||||||
// user surpasses their maximum number of attempts they will get locked out.
|
|
||||||
if ($throttles) {
|
if ($throttles) {
|
||||||
$this->incrementLoginAttempts($request);
|
$this->incrementLoginAttempts($request);
|
||||||
}
|
}
|
||||||
|
@ -43,6 +43,8 @@ class CategoryController extends Controller
|
|||||||
* @param SCRI $repository
|
* @param SCRI $repository
|
||||||
* @param Category $category
|
* @param Category $category
|
||||||
*
|
*
|
||||||
|
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
|
||||||
|
*
|
||||||
* @return \Symfony\Component\HttpFoundation\Response
|
* @return \Symfony\Component\HttpFoundation\Response
|
||||||
*/
|
*/
|
||||||
public function all(SCRI $repository, Category $category)
|
public function all(SCRI $repository, Category $category)
|
||||||
@ -67,7 +69,6 @@ class CategoryController extends Controller
|
|||||||
$spentArray = $repository->spentPerDay($category, $start, $end);
|
$spentArray = $repository->spentPerDay($category, $start, $end);
|
||||||
$earnedArray = $repository->earnedPerDay($category, $start, $end);
|
$earnedArray = $repository->earnedPerDay($category, $start, $end);
|
||||||
|
|
||||||
|
|
||||||
while ($start <= $end) {
|
while ($start <= $end) {
|
||||||
$currentEnd = Navigation::endOfPeriod($start, $range);
|
$currentEnd = Navigation::endOfPeriod($start, $range);
|
||||||
|
|
||||||
@ -161,23 +162,8 @@ class CategoryController extends Controller
|
|||||||
return Response::json($cache->get()); // @codeCoverageIgnore
|
return Response::json($cache->get()); // @codeCoverageIgnore
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* category
|
|
||||||
* year:
|
|
||||||
* spent: x
|
|
||||||
* earned: x
|
|
||||||
* year
|
|
||||||
* spent: x
|
|
||||||
* earned: x
|
|
||||||
*/
|
|
||||||
$entries = new Collection;
|
$entries = new Collection;
|
||||||
// go by category, not by year.
|
$set = $repository->listMultiYear($categories, $accounts, $start, $end);
|
||||||
|
|
||||||
// given a set of categories and accounts, it should not be difficult to get
|
|
||||||
// the exact array of data we need.
|
|
||||||
|
|
||||||
// then get the data for "no category".
|
|
||||||
$set = $repository->listMultiYear($categories, $accounts, $start, $end);
|
|
||||||
|
|
||||||
/** @var Category $category */
|
/** @var Category $category */
|
||||||
foreach ($categories as $category) {
|
foreach ($categories as $category) {
|
||||||
|
@ -79,8 +79,8 @@ class CsvController extends Controller
|
|||||||
if ($this->data->hasHeaders()) {
|
if ($this->data->hasHeaders()) {
|
||||||
$headers = $firstRow;
|
$headers = $firstRow;
|
||||||
}
|
}
|
||||||
|
$keys = array_keys(Config::get('csv.roles'));
|
||||||
foreach (Config::get('csv.roles') as $name => $role) {
|
foreach ($keys as $name) {
|
||||||
$availableRoles[$name] = trans('firefly.csv_column_' . $name);//$role['name'];
|
$availableRoles[$name] = trans('firefly.csv_column_' . $name);//$role['name'];
|
||||||
}
|
}
|
||||||
ksort($availableRoles);
|
ksort($availableRoles);
|
||||||
@ -105,7 +105,7 @@ class CsvController extends Controller
|
|||||||
}
|
}
|
||||||
$data = [
|
$data = [
|
||||||
'date-format' => Session::get('csv-date-format'),
|
'date-format' => Session::get('csv-date-format'),
|
||||||
'has-headers' => Session::get('csv-has-headers')
|
'has-headers' => Session::get('csv-has-headers'),
|
||||||
];
|
];
|
||||||
if (Session::has('csv-map')) {
|
if (Session::has('csv-map')) {
|
||||||
$data['map'] = Session::get('csv-map');
|
$data['map'] = Session::get('csv-map');
|
||||||
@ -174,7 +174,7 @@ class CsvController extends Controller
|
|||||||
$delimiters = [
|
$delimiters = [
|
||||||
',' => trans('form.csv_comma'),
|
',' => trans('form.csv_comma'),
|
||||||
';' => trans('form.csv_semicolon'),
|
';' => trans('form.csv_semicolon'),
|
||||||
'tab' => trans('form.csv_tab')
|
'tab' => trans('form.csv_tab'),
|
||||||
];
|
];
|
||||||
|
|
||||||
// get a list of asset accounts:
|
// get a list of asset accounts:
|
||||||
|
@ -134,28 +134,20 @@ class RuleController extends Controller
|
|||||||
{
|
{
|
||||||
// has old input?
|
// has old input?
|
||||||
if (Input::old()) {
|
if (Input::old()) {
|
||||||
// process old triggers.
|
|
||||||
$oldTriggers = $this->getPreviousTriggers();
|
$oldTriggers = $this->getPreviousTriggers();
|
||||||
$triggerCount = count($oldTriggers);
|
$triggerCount = count($oldTriggers);
|
||||||
|
$oldActions = $this->getPreviousActions();
|
||||||
// process old actions
|
$actionCount = count($oldActions);
|
||||||
$oldActions = $this->getPreviousActions();
|
|
||||||
$actionCount = count($oldActions);
|
|
||||||
} else {
|
} else {
|
||||||
// get current triggers
|
|
||||||
$oldTriggers = $this->getCurrentTriggers($rule);
|
$oldTriggers = $this->getCurrentTriggers($rule);
|
||||||
$triggerCount = count($oldTriggers);
|
$triggerCount = count($oldTriggers);
|
||||||
|
$oldActions = $this->getCurrentActions($rule);
|
||||||
// get current actions
|
$actionCount = count($oldActions);
|
||||||
$oldActions = $this->getCurrentActions($rule);
|
|
||||||
$actionCount = count($oldActions);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// get rule trigger for update / store-journal:
|
// get rule trigger for update / store-journal:
|
||||||
$primaryTrigger = $rule->ruleTriggers()->where('trigger_type', 'user_action')->first()->trigger_value;
|
$primaryTrigger = $rule->ruleTriggers()->where('trigger_type', 'user_action')->first()->trigger_value;
|
||||||
|
$subTitle = trans('firefly.edit_rule', ['title' => $rule->title]);
|
||||||
|
|
||||||
$subTitle = trans('firefly.edit_rule', ['title' => $rule->title]);
|
|
||||||
|
|
||||||
// put previous url in session if not redirect from store (not "return_to_edit").
|
// put previous url in session if not redirect from store (not "return_to_edit").
|
||||||
if (Session::get('rules.rule.edit.fromUpdate') !== true) {
|
if (Session::get('rules.rule.edit.fromUpdate') !== true) {
|
||||||
|
@ -46,7 +46,7 @@ class RuleGroupController extends Controller
|
|||||||
Session::flash('gaEventCategory', 'rules');
|
Session::flash('gaEventCategory', 'rules');
|
||||||
Session::flash('gaEventAction', 'create-rule-group');
|
Session::flash('gaEventAction', 'create-rule-group');
|
||||||
|
|
||||||
return view('rules.rule-group.create', compact('subTitleIcon', 'what', 'subTitle'));
|
return view('rules.rule-group.create', compact('subTitleIcon', 'subTitle'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -58,9 +58,7 @@ class TransactionController extends Controller
|
|||||||
$accounts = ExpandedForm::makeSelectList($repository->getAccounts(['Default account', 'Asset account']));
|
$accounts = ExpandedForm::makeSelectList($repository->getAccounts(['Default account', 'Asset account']));
|
||||||
$budgets = ExpandedForm::makeSelectList(Auth::user()->budgets()->get());
|
$budgets = ExpandedForm::makeSelectList(Auth::user()->budgets()->get());
|
||||||
$budgets[0] = trans('form.noBudget');
|
$budgets[0] = trans('form.noBudget');
|
||||||
|
$piggyBanks = Auth::user()->piggyBanks()->orderBy('order', 'ASC')->get();
|
||||||
// piggy bank list:
|
|
||||||
$piggyBanks = Auth::user()->piggyBanks()->orderBy('order', 'ASC')->get();
|
|
||||||
/** @var PiggyBank $piggy */
|
/** @var PiggyBank $piggy */
|
||||||
foreach ($piggyBanks as $piggy) {
|
foreach ($piggyBanks as $piggy) {
|
||||||
$piggy->name = $piggy->name . ' (' . Amount::format($piggy->currentRelevantRep()->currentamount, false) . ')';
|
$piggy->name = $piggy->name . ' (' . Amount::format($piggy->currentRelevantRep()->currentamount, false) . ')';
|
||||||
@ -161,7 +159,7 @@ class TransactionController extends Controller
|
|||||||
'date' => $journal->date->format('Y-m-d'),
|
'date' => $journal->date->format('Y-m-d'),
|
||||||
'category' => '',
|
'category' => '',
|
||||||
'budget_id' => 0,
|
'budget_id' => 0,
|
||||||
'piggy_bank_id' => 0
|
'piggy_bank_id' => 0,
|
||||||
];
|
];
|
||||||
// get tags:
|
// get tags:
|
||||||
$preFilled['tags'] = join(',', $journal->tags->pluck('tag')->toArray());
|
$preFilled['tags'] = join(',', $journal->tags->pluck('tag')->toArray());
|
||||||
|
@ -54,7 +54,6 @@ class FireflyServiceProvider extends ServiceProvider
|
|||||||
public function register()
|
public function register()
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
$this->app->bind(
|
$this->app->bind(
|
||||||
'preferences', function () {
|
'preferences', function () {
|
||||||
return new Preferences;
|
return new Preferences;
|
||||||
|
@ -76,22 +76,7 @@ class CategoryRepository implements CategoryRepositoryInterface
|
|||||||
*/
|
*/
|
||||||
public function listMultiYear(Collection $categories, Collection $accounts, Carbon $start, Carbon $end)
|
public function listMultiYear(Collection $categories, Collection $accounts, Carbon $start, Carbon $end)
|
||||||
{
|
{
|
||||||
/*
|
|
||||||
* select categories.id, DATE_FORMAT(transaction_journals.date,"%Y") as dateFormatted, transaction_types.type, SUM(amount) as sum from categories
|
|
||||||
|
|
||||||
left join category_transaction_journal ON category_transaction_journal.category_id = categories.id
|
|
||||||
left join transaction_journals ON transaction_journals.id = category_transaction_journal.transaction_journal_id
|
|
||||||
left join transaction_types ON transaction_types.id = transaction_journals.transaction_type_id
|
|
||||||
left join transactions ON transactions.transaction_journal_id = transaction_journals.id
|
|
||||||
|
|
||||||
|
|
||||||
where
|
|
||||||
categories.user_id =1
|
|
||||||
and transaction_types.type in ("Withdrawal","Deposit")
|
|
||||||
and transactions.account_id IN (2,4,6,10,11,610,725,879,1248)
|
|
||||||
|
|
||||||
group by categories.id, transaction_types.type, dateFormatted
|
|
||||||
*/
|
|
||||||
$set = Auth::user()->categories()
|
$set = Auth::user()->categories()
|
||||||
->leftJoin('category_transaction_journal', 'category_transaction_journal.category_id', '=', 'categories.id')
|
->leftJoin('category_transaction_journal', 'category_transaction_journal.category_id', '=', 'categories.id')
|
||||||
->leftJoin('transaction_journals', 'transaction_journals.id', '=', 'category_transaction_journal.transaction_journal_id')
|
->leftJoin('transaction_journals', 'transaction_journals.id', '=', 'category_transaction_journal.transaction_journal_id')
|
||||||
@ -100,6 +85,8 @@ group by categories.id, transaction_types.type, dateFormatted
|
|||||||
->whereIn('transaction_types.type', [TransactionType::DEPOSIT, TransactionType::WITHDRAWAL])
|
->whereIn('transaction_types.type', [TransactionType::DEPOSIT, TransactionType::WITHDRAWAL])
|
||||||
->whereIn('transactions.account_id', $accounts->pluck('id')->toArray())
|
->whereIn('transactions.account_id', $accounts->pluck('id')->toArray())
|
||||||
->whereIn('categories.id', $categories->pluck('id')->toArray())
|
->whereIn('categories.id', $categories->pluck('id')->toArray())
|
||||||
|
->where('transaction_journals.date', '>=', $start->format('Y-m-d'))
|
||||||
|
->where('transaction_journals.date', '<=', $end->format('Y-m-d'))
|
||||||
->groupBy('categories.id')
|
->groupBy('categories.id')
|
||||||
->groupBy('transaction_types.type')
|
->groupBy('transaction_types.type')
|
||||||
->groupBy('dateFormatted')
|
->groupBy('dateFormatted')
|
||||||
@ -108,7 +95,7 @@ group by categories.id, transaction_types.type, dateFormatted
|
|||||||
'categories.*',
|
'categories.*',
|
||||||
DB::Raw('DATE_FORMAT(`transaction_journals`.`date`,"%Y") as `dateFormatted`'),
|
DB::Raw('DATE_FORMAT(`transaction_journals`.`date`,"%Y") as `dateFormatted`'),
|
||||||
'transaction_types.type',
|
'transaction_types.type',
|
||||||
DB::Raw('SUM(`amount`) as `sum`')
|
DB::Raw('SUM(`amount`) as `sum`'),
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -158,7 +145,7 @@ group by categories.id, transaction_types.type, dateFormatted
|
|||||||
[
|
[
|
||||||
'categories.*',
|
'categories.*',
|
||||||
DB::Raw('DATE_FORMAT(`transaction_journals`.`date`,"%Y-%m") as `dateFormatted`'),
|
DB::Raw('DATE_FORMAT(`transaction_journals`.`date`,"%Y-%m") as `dateFormatted`'),
|
||||||
DB::Raw('SUM(`t_dest`.`amount`) AS `earned`')
|
DB::Raw('SUM(`t_dest`.`amount`) AS `earned`'),
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -212,7 +199,7 @@ group by categories.id, transaction_types.type, dateFormatted
|
|||||||
[
|
[
|
||||||
'categories.*',
|
'categories.*',
|
||||||
DB::Raw('DATE_FORMAT(`transaction_journals`.`date`,"%Y-%m") as `dateFormatted`'),
|
DB::Raw('DATE_FORMAT(`transaction_journals`.`date`,"%Y-%m") as `dateFormatted`'),
|
||||||
DB::Raw('SUM(`t_src`.`amount`) AS `spent`')
|
DB::Raw('SUM(`t_src`.`amount`) AS `spent`'),
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -286,7 +273,7 @@ group by categories.id, transaction_types.type, dateFormatted
|
|||||||
|
|
||||||
$single = $query->first(
|
$single = $query->first(
|
||||||
[
|
[
|
||||||
DB::Raw('SUM(`transactions`.`amount`) as `sum`')
|
DB::Raw('SUM(`transactions`.`amount`) as `sum`'),
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
if (!is_null($single)) {
|
if (!is_null($single)) {
|
||||||
|
@ -72,7 +72,7 @@ class Processor
|
|||||||
$foundTriggers = 0;
|
$foundTriggers = 0;
|
||||||
$hitTriggers = 0;
|
$hitTriggers = 0;
|
||||||
/** @var RuleTrigger $trigger */
|
/** @var RuleTrigger $trigger */
|
||||||
foreach ($this->rule->ruleTriggers()->orderBy('order', 'ASC')->get() as $index => $trigger) {
|
foreach ($this->rule->ruleTriggers()->orderBy('order', 'ASC')->get() as $trigger) {
|
||||||
$foundTriggers++;
|
$foundTriggers++;
|
||||||
$type = $trigger->trigger_type;
|
$type = $trigger->trigger_type;
|
||||||
|
|
||||||
@ -110,7 +110,7 @@ class Processor
|
|||||||
* @var int $index
|
* @var int $index
|
||||||
* @var RuleAction $action
|
* @var RuleAction $action
|
||||||
*/
|
*/
|
||||||
foreach ($this->rule->ruleActions()->orderBy('order', 'ASC')->get() as $index => $action) {
|
foreach ($this->rule->ruleActions()->orderBy('order', 'ASC')->get() as $action) {
|
||||||
$type = $action->action_type;
|
$type = $action->action_type;
|
||||||
$class = $this->actionTypes[$type];
|
$class = $this->actionTypes[$type];
|
||||||
Log::debug('Action #' . $action->id . ' for rule #' . $action->rule_id . ' (' . $type . ')');
|
Log::debug('Action #' . $action->id . ' for rule #' . $action->rule_id . ' (' . $type . ')');
|
||||||
|
@ -44,29 +44,29 @@ class FromAccountEnds implements TriggerInterface
|
|||||||
*/
|
*/
|
||||||
public function triggered()
|
public function triggered()
|
||||||
{
|
{
|
||||||
$fromAccountName = strtolower($this->journal->source_account->name);
|
$name = strtolower($this->journal->source_account->name);
|
||||||
$fromAccountNameLength = strlen($fromAccountName);
|
$nameLength = strlen($name);
|
||||||
$search = strtolower($this->trigger->trigger_value);
|
$search = strtolower($this->trigger->trigger_value);
|
||||||
$searchLength = strlen($search);
|
$searchLength = strlen($search);
|
||||||
|
|
||||||
// if the string to search for is longer than the account name,
|
// if the string to search for is longer than the account name,
|
||||||
// shorten the search string.
|
// shorten the search string.
|
||||||
if ($searchLength > $fromAccountNameLength) {
|
if ($searchLength > $nameLength) {
|
||||||
Log::debug('Search string "' . $search . '" (' . $searchLength . ') is longer than "' . $fromAccountName . '" (' . $fromAccountNameLength . '). ');
|
Log::debug('Search string "' . $search . '" (' . $searchLength . ') is longer than "' . $name . '" (' . $nameLength . '). ');
|
||||||
$search = substr($search, ($fromAccountNameLength * -1));
|
$search = substr($search, ($nameLength * -1));
|
||||||
$searchLength = strlen($search);
|
$searchLength = strlen($search);
|
||||||
Log::debug('Search string is now "' . $search . '" (' . $searchLength . ') instead.');
|
Log::debug('Search string is now "' . $search . '" (' . $searchLength . ') instead.');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
$part = substr($fromAccountName, $searchLength * -1);
|
$part = substr($name, $searchLength * -1);
|
||||||
|
|
||||||
if ($part == $search) {
|
if ($part == $search) {
|
||||||
Log::debug('"' . $fromAccountName . '" ends with "' . $search . '". Return true.');
|
Log::debug('"' . $name . '" ends with "' . $search . '". Return true.');
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
Log::debug('"' . $fromAccountName . '" does not end with "' . $search . '". Return false.');
|
Log::debug('"' . $name . '" does not end with "' . $search . '". Return false.');
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user