mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2026-05-03 20:56:21 +00:00
Code cleanup
This commit is contained in:
@@ -72,7 +72,7 @@ class BoxController extends Controller
|
||||
$end = session('end', today(config('app.timezone'))->endOfMonth());
|
||||
$today = today(config('app.timezone'));
|
||||
$display = 2; // see method docs.
|
||||
$boxTitle = (string)trans('firefly.spent');
|
||||
$boxTitle = (string) trans('firefly.spent');
|
||||
|
||||
$cache = new CacheProperties();
|
||||
$cache->addProperty($start);
|
||||
@@ -113,24 +113,24 @@ class BoxController extends Controller
|
||||
$spentAmount = $spent[$currency->id]['sum'] ?? '0';
|
||||
app('log')->debug(sprintf('Spent for default currency for all budgets in this period: %s', $spentAmount));
|
||||
|
||||
$days = (int)($today->between($start, $end) ? $today->diffInDays($start, true) + 1 : $end->diffInDays($start, true) + 1);
|
||||
$days = (int) ($today->between($start, $end) ? $today->diffInDays($start, true) + 1 : $end->diffInDays($start, true) + 1);
|
||||
app('log')->debug(sprintf('Number of days left: %d', $days));
|
||||
$spentPerDay = bcdiv($spentAmount, (string)$days);
|
||||
$spentPerDay = bcdiv($spentAmount, (string) $days);
|
||||
app('log')->debug(sprintf('Available to spend per day: %s', $spentPerDay));
|
||||
if ($availableBudgets->count() > 0) {
|
||||
$display = 0; // assume user overspent
|
||||
$boxTitle = (string)trans('firefly.overspent');
|
||||
$totalAvailableSum = (string)$availableBudgets->sum('amount');
|
||||
$boxTitle = (string) trans('firefly.overspent');
|
||||
$totalAvailableSum = (string) $availableBudgets->sum('amount');
|
||||
app('log')->debug(sprintf('Total available sum is %s', $totalAvailableSum));
|
||||
// calculate with available budget.
|
||||
$leftToSpendAmount = bcadd($totalAvailableSum, $spentAmount);
|
||||
app('log')->debug(sprintf('So left to spend is %s', $leftToSpendAmount));
|
||||
if (bccomp($leftToSpendAmount, '0') >= 0) {
|
||||
app('log')->debug('Left to spend is positive or zero!');
|
||||
$boxTitle = (string)trans('firefly.left_to_spend');
|
||||
$boxTitle = (string) trans('firefly.left_to_spend');
|
||||
$activeDaysLeft = $this->activeDaysLeft($start, $end); // see method description.
|
||||
$display = 1; // not overspent
|
||||
$leftPerDayAmount = 0 === $activeDaysLeft ? $leftToSpendAmount : bcdiv($leftToSpendAmount, (string)$activeDaysLeft);
|
||||
$leftPerDayAmount = 0 === $activeDaysLeft ? $leftToSpendAmount : bcdiv($leftToSpendAmount, (string) $activeDaysLeft);
|
||||
app('log')->debug(sprintf('Left to spend per day is %s', $leftPerDayAmount));
|
||||
}
|
||||
}
|
||||
@@ -185,7 +185,7 @@ class BoxController extends Controller
|
||||
|
||||
/** @var array $journal */
|
||||
foreach ($set as $journal) {
|
||||
$currencyId = (int)$journal['currency_id'];
|
||||
$currencyId = (int) $journal['currency_id'];
|
||||
$amount = $journal['amount'] ?? '0';
|
||||
$incomes[$currencyId] ??= '0';
|
||||
$incomes[$currencyId] = bcadd($incomes[$currencyId], app('steam')->positive($amount));
|
||||
@@ -203,7 +203,7 @@ class BoxController extends Controller
|
||||
|
||||
/** @var array $journal */
|
||||
foreach ($set as $journal) {
|
||||
$currencyId = (int)$journal['currency_id'];
|
||||
$currencyId = (int) $journal['currency_id'];
|
||||
$expenses[$currencyId] ??= '0';
|
||||
$expenses[$currencyId] = bcadd($expenses[$currencyId], $journal['amount'] ?? '0');
|
||||
$sums[$currencyId] ??= '0';
|
||||
|
||||
@@ -53,7 +53,7 @@ class BudgetController extends Controller
|
||||
|
||||
$this->middleware(
|
||||
function ($request, $next) {
|
||||
app('view')->share('title', (string)trans('firefly.budgets'));
|
||||
app('view')->share('title', (string) trans('firefly.budgets'));
|
||||
app('view')->share('mainTitleIcon', 'fa-pie-chart');
|
||||
$this->repository = app(BudgetRepositoryInterface::class);
|
||||
$this->abRepository = app(AvailableBudgetRepositoryInterface::class);
|
||||
|
||||
@@ -51,7 +51,7 @@ class FrontpageController extends Controller
|
||||
// percentage!
|
||||
$pct = 0;
|
||||
if (0 !== bccomp($piggyBank->target_amount, '0')) {
|
||||
$pct = (int)bcmul(bcdiv($amount, $piggyBank->target_amount), '100');
|
||||
$pct = (int) bcmul(bcdiv($amount, $piggyBank->target_amount), '100');
|
||||
}
|
||||
|
||||
$entry = [
|
||||
|
||||
@@ -103,7 +103,7 @@ class IntroController extends Controller
|
||||
app('preferences')->set($key, false);
|
||||
app('preferences')->mark();
|
||||
|
||||
return response()->json(['message' => (string)trans('firefly.intro_boxes_after_refresh')]);
|
||||
return response()->json(['message' => (string) trans('firefly.intro_boxes_after_refresh')]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -55,7 +55,7 @@ class ReconcileController extends Controller
|
||||
$this->middleware(
|
||||
function ($request, $next) {
|
||||
app('view')->share('mainTitleIcon', 'fa-credit-card');
|
||||
app('view')->share('title', (string)trans('firefly.accounts'));
|
||||
app('view')->share('title', (string) trans('firefly.accounts'));
|
||||
$this->accountRepos = app(AccountRepositoryInterface::class);
|
||||
|
||||
return $next($request);
|
||||
|
||||
@@ -72,13 +72,13 @@ class RecurrenceController extends Controller
|
||||
$start = Carbon::createFromFormat('Y-m-d', $request->get('start'));
|
||||
$end = Carbon::createFromFormat('Y-m-d', $request->get('end'));
|
||||
$firstDate = Carbon::createFromFormat('Y-m-d', $request->get('first_date'));
|
||||
$endDate = '' !== (string)$request->get('end_date') ? Carbon::createFromFormat('Y-m-d', $request->get('end_date')) : null;
|
||||
$endsAt = (string)$request->get('ends');
|
||||
$endDate = '' !== (string) $request->get('end_date') ? Carbon::createFromFormat('Y-m-d', $request->get('end_date')) : null;
|
||||
$endsAt = (string) $request->get('ends');
|
||||
$repetitionType = explode(',', $request->get('type'))[0];
|
||||
$repetitions = (int)$request->get('reps');
|
||||
$weekend = (int)$request->get('weekend');
|
||||
$repetitions = (int) $request->get('reps');
|
||||
$weekend = (int) $request->get('weekend');
|
||||
$repetitionMoment = '';
|
||||
$skip = (int)$request->get('skip');
|
||||
$skip = (int) $request->get('skip');
|
||||
$skip = $skip < 0 || $skip > 31 ? 0 : $skip;
|
||||
$weekend = $weekend < 1 || $weekend > 4 ? 1 : $weekend;
|
||||
|
||||
@@ -153,7 +153,7 @@ class RecurrenceController extends Controller
|
||||
*/
|
||||
public function suggest(Request $request): JsonResponse
|
||||
{
|
||||
$string = '' === (string)$request->get('date') ? date('Y-m-d') : (string)$request->get('date');
|
||||
$string = '' === (string) $request->get('date') ? date('Y-m-d') : (string) $request->get('date');
|
||||
$today = today(config('app.timezone'))->startOfDay();
|
||||
|
||||
try {
|
||||
@@ -165,37 +165,37 @@ class RecurrenceController extends Controller
|
||||
return response()->json();
|
||||
}
|
||||
$date->startOfDay();
|
||||
$preSelected = (string)$request->get('pre_select');
|
||||
$preSelected = (string) $request->get('pre_select');
|
||||
$locale = app('steam')->getLocale();
|
||||
|
||||
app('log')->debug(sprintf('date = %s, today = %s. date > today? %s', $date->toAtomString(), $today->toAtomString(), var_export($date > $today, true)));
|
||||
app('log')->debug(sprintf('past = true? %s', var_export('true' === (string)$request->get('past'), true)));
|
||||
app('log')->debug(sprintf('past = true? %s', var_export('true' === (string) $request->get('past'), true)));
|
||||
|
||||
$result = [];
|
||||
if ($date > $today || 'true' === (string)$request->get('past')) {
|
||||
if ($date > $today || 'true' === (string) $request->get('past')) {
|
||||
app('log')->debug('Will fill dropdown.');
|
||||
$weekly = sprintf('weekly,%s', $date->dayOfWeekIso);
|
||||
$monthly = sprintf('monthly,%s', $date->day);
|
||||
$dayOfWeek = (string)trans(sprintf('config.dow_%s', $date->dayOfWeekIso));
|
||||
$dayOfWeek = (string) trans(sprintf('config.dow_%s', $date->dayOfWeekIso));
|
||||
$ndom = sprintf('ndom,%s,%s', $date->weekOfMonth, $date->dayOfWeekIso);
|
||||
$yearly = sprintf('yearly,%s', $date->format('Y-m-d'));
|
||||
$yearlyDate = $date->isoFormat((string)trans('config.month_and_day_no_year_js', [], $locale));
|
||||
$yearlyDate = $date->isoFormat((string) trans('config.month_and_day_no_year_js', [], $locale));
|
||||
$result = [
|
||||
'daily' => ['label' => (string)trans('firefly.recurring_daily'), 'selected' => str_starts_with($preSelected, 'daily')],
|
||||
'daily' => ['label' => (string) trans('firefly.recurring_daily'), 'selected' => str_starts_with($preSelected, 'daily')],
|
||||
$weekly => [
|
||||
'label' => (string)trans('firefly.recurring_weekly', ['weekday' => $dayOfWeek]),
|
||||
'label' => (string) trans('firefly.recurring_weekly', ['weekday' => $dayOfWeek]),
|
||||
'selected' => str_starts_with($preSelected, 'weekly'),
|
||||
],
|
||||
$monthly => [
|
||||
'label' => (string)trans('firefly.recurring_monthly', ['dayOfMonth' => $date->day]),
|
||||
'label' => (string) trans('firefly.recurring_monthly', ['dayOfMonth' => $date->day]),
|
||||
'selected' => str_starts_with($preSelected, 'monthly'),
|
||||
],
|
||||
$ndom => [
|
||||
'label' => (string)trans('firefly.recurring_ndom', ['weekday' => $dayOfWeek, 'dayOfMonth' => $date->weekOfMonth]),
|
||||
'label' => (string) trans('firefly.recurring_ndom', ['weekday' => $dayOfWeek, 'dayOfMonth' => $date->weekOfMonth]),
|
||||
'selected' => str_starts_with($preSelected, 'ndom'),
|
||||
],
|
||||
$yearly => [
|
||||
'label' => (string)trans('firefly.recurring_yearly', ['date' => $yearlyDate]),
|
||||
'label' => (string) trans('firefly.recurring_yearly', ['date' => $yearlyDate]),
|
||||
'selected' => str_starts_with($preSelected, 'yearly'),
|
||||
],
|
||||
];
|
||||
|
||||
@@ -41,11 +41,11 @@ class RuleController extends Controller
|
||||
*/
|
||||
public function action(Request $request): JsonResponse
|
||||
{
|
||||
$count = (int)$request->get('count') > 0 ? (int)$request->get('count') : 1;
|
||||
$count = (int) $request->get('count') > 0 ? (int) $request->get('count') : 1;
|
||||
$keys = array_keys(config('firefly.rule-actions'));
|
||||
$actions = [];
|
||||
foreach ($keys as $key) {
|
||||
$actions[$key] = (string)trans('firefly.rule_action_'.$key.'_choice');
|
||||
$actions[$key] = (string) trans('firefly.rule_action_'.$key.'_choice');
|
||||
}
|
||||
|
||||
try {
|
||||
@@ -68,12 +68,12 @@ class RuleController extends Controller
|
||||
*/
|
||||
public function trigger(Request $request): JsonResponse
|
||||
{
|
||||
$count = (int)$request->get('count') > 0 ? (int)$request->get('count') : 1;
|
||||
$count = (int) $request->get('count') > 0 ? (int) $request->get('count') : 1;
|
||||
$operators = config('search.operators');
|
||||
$triggers = [];
|
||||
foreach ($operators as $key => $operator) {
|
||||
if ('user_action' !== $key && false === $operator['alias']) {
|
||||
$triggers[$key] = (string)trans(sprintf('firefly.rule_trigger_%s_choice', $key));
|
||||
$triggers[$key] = (string) trans(sprintf('firefly.rule_trigger_%s_choice', $key));
|
||||
}
|
||||
}
|
||||
asort($triggers);
|
||||
|
||||
Reference in New Issue
Block a user