Merge branch 'develop' into 5.8-dev

# Conflicts:
#	app/Api/V1/Controllers/Chart/AccountController.php
#	app/Api/V1/Controllers/Insight/Expense/AccountController.php
#	app/Api/V1/Controllers/Insight/Expense/BillController.php
#	app/Api/V1/Controllers/Insight/Expense/BudgetController.php
#	app/Api/V1/Controllers/Insight/Expense/CategoryController.php
#	app/Api/V1/Controllers/Insight/Expense/PeriodController.php
#	app/Console/Commands/Upgrade/MigrateToGroups.php
#	app/Http/Controllers/Account/IndexController.php
#	app/Http/Controllers/Budget/AvailableBudgetController.php
#	app/Http/Controllers/Budget/BudgetLimitController.php
#	app/Http/Controllers/Budget/EditController.php
#	app/Http/Controllers/Chart/AccountController.php
#	app/Http/Controllers/Json/FrontpageController.php
#	app/Http/Controllers/PiggyBank/EditController.php
This commit is contained in:
James Cole
2022-12-24 06:15:26 +01:00
47 changed files with 428 additions and 306 deletions

View File

@@ -135,6 +135,7 @@ class EditController extends Controller
// code to handle active-checkboxes
$hasOldInput = null !== $request->old('_token');
$virtualBalance = null === $account->virtual_balance ? '0' : $account->virtual_balance;
$preFilled = [
'account_number' => $repository->getMetaValue($account, 'account_number'),
'account_role' => $repository->getMetaValue($account, 'account_role'),
@@ -143,9 +144,9 @@ class EditController extends Controller
'BIC' => $repository->getMetaValue($account, 'BIC'),
'opening_balance_date' => $openingBalanceDate,
'liability_type_id' => $account->account_type_id,
'opening_balance' => number_format((float) $openingBalanceAmount, $currency->decimal_places, '.', ''),
'opening_balance' => app('steam')->bcround($openingBalanceAmount, $currency->decimal_places),
'liability_direction' => $this->repository->getMetaValue($account, 'liability_direction'),
'virtual_balance' => number_format((float) $account->virtual_balance, $currency->decimal_places, '.', ''),
'virtual_balance' => app('steam')->bcround($virtualBalance, $currency->decimal_places),
'currency_id' => $currency->id,
'include_net_worth' => $includeNetWorth,
'interest' => $repository->getMetaValue($account, 'interest'),

View File

@@ -106,7 +106,7 @@ class IndexController extends Controller
$account->startBalance = $this->isInArray($startBalances, $account->id);
$account->endBalance = $this->isInArray($endBalances, $account->id);
$account->difference = bcsub($account->endBalance, $account->startBalance);
$account->interest = number_format((float) $this->repository->getMetaValue($account, 'interest'), 4, '.', '');
$account->interest = app('steam')->bcround($this->repository->getMetaValue($account, 'interest'), 4);
$account->interestPeriod = (string) trans(sprintf('firefly.interest_calc_%s', $this->repository->getMetaValue($account, 'interest_period')));
$account->accountTypeString = (string) trans(sprintf('firefly.account_type_%s', $account->accountType->type));
$account->current_debt = '0';
@@ -163,14 +163,19 @@ class IndexController extends Controller
$endBalances = app('steam')->balancesByAccounts($accounts, $end);
$activities = app('steam')->getLastActivities($ids);
$accounts->each(
function (Account $account) use ($activities, $startBalances, $endBalances) {
// TODO lots of queries in this block of code.
$interest = (string)$this->repository->getMetaValue($account, 'interest');
$interest = '' === $interest ? '0' : $interest;
// See reference nr. 68
$account->lastActivityDate = $this->isInArrayDate($activities, $account->id);
$account->startBalance = $this->isInArray($startBalances, $account->id);
$account->endBalance = $this->isInArray($endBalances, $account->id);
$account->difference = bcsub($account->endBalance, $account->startBalance);
$account->interest = number_format((float) $this->repository->getMetaValue($account, 'interest'), 4, '.', '');
$account->interest = app('steam')->bcround($interest, 4);
$account->interestPeriod = (string) trans(
sprintf('firefly.interest_calc_%s', $this->repository->getMetaValue($account, 'interest_period'))
);

View File

@@ -124,8 +124,8 @@ class ReconcileController extends Controller
$startDate = clone $start;
$startDate->subDay();
$startBalance = number_format((float) app('steam')->balance($account, $startDate), $currency->decimal_places, '.', '');
$endBalance = number_format((float) app('steam')->balance($account, $end), $currency->decimal_places, '.', '');
$startBalance = app('steam')->bcround(app('steam')->balance($account, $startDate), $currency->decimal_places);
$endBalance = app('steam')->bcround( app('steam')->balance($account, $end), $currency->decimal_places);
$subTitleIcon = config(sprintf('firefly.subIconsByIdentifier.%s', $account->accountType->type));
$subTitle = (string) trans('firefly.reconcile_account', ['account' => $account->name]);

View File

@@ -157,7 +157,7 @@ class RegisterController extends Controller
$allowRegistration = $this->allowedToRegister();
if (false === $allowRegistration) {
$message = 'Registration is currently not available.';
$message = 'Registration is currently not available. If you are the administrator, you can enable this in the administration.';
return view('error', compact('message'));
}

View File

@@ -89,8 +89,8 @@ class EditController extends Controller
}
$currency = app('amount')->getDefaultCurrency();
$bill->amount_min = round((float) $bill->amount_min, $currency->decimal_places);
$bill->amount_max = round((float) $bill->amount_max, $currency->decimal_places);
$bill->amount_min = app('steam')->bcround($bill->amount_min, $currency->decimal_places);
$bill->amount_max = app('steam')->bcround($bill->amount_max, $currency->decimal_places);
$rules = $this->repository->getRulesForBill($bill);
$defaultCurrency = app('amount')->getDefaultCurrency();

View File

@@ -65,7 +65,7 @@ class BudgetLimitController extends Controller
parent::__construct();
$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->opsRepository = app(OperationsRepositoryInterface::class);
@@ -78,9 +78,9 @@ class BudgetLimitController extends Controller
}
/**
* @param Budget $budget
* @param Carbon $start
* @param Carbon $end
* @param Budget $budget
* @param Carbon $start
* @param Carbon $end
*
* @return Factory|View
*/
@@ -107,8 +107,8 @@ class BudgetLimitController extends Controller
}
/**
* @param Request $request
* @param BudgetLimit $budgetLimit
* @param Request $request
* @param BudgetLimit $budgetLimit
*
* @return RedirectResponse|Redirector
*/
@@ -121,7 +121,7 @@ class BudgetLimitController extends Controller
}
/**
* @param Request $request
* @param Request $request
*
* @return JsonResponse
* @throws FireflyException
@@ -130,14 +130,14 @@ class BudgetLimitController extends Controller
{
Log::debug('Going to store new budget-limit.', $request->all());
// first search for existing one and update it if necessary.
$currency = $this->currencyRepos->find((int) $request->get('transaction_currency_id'));
$budget = $this->repository->find((int) $request->get('budget_id'));
$currency = $this->currencyRepos->find((int)$request->get('transaction_currency_id'));
$budget = $this->repository->find((int)$request->get('budget_id'));
if (null === $currency || null === $budget) {
throw new FireflyException('No valid currency or budget.');
}
$start = Carbon::createFromFormat('Y-m-d', $request->get('start'));
$end = Carbon::createFromFormat('Y-m-d', $request->get('end'));
$amount = (string) $request->get('amount');
$amount = (string)$request->get('amount');
$start->startOfDay();
$end->startOfDay();
@@ -150,17 +150,17 @@ class BudgetLimitController extends Controller
$limit = $this->blRepository->find($budget, $currency, $start, $end);
// sanity check on amount:
if ((float) $amount === 0.0) {
if (0 === bccomp($amount, '0')) {
if (null !== $limit) {
$this->blRepository->destroyBudgetLimit($limit);
}
// return empty=ish array:
return response()->json([]);
}
if ((int) $amount > 268435456) {
if ((int)$amount > 268435456) { // intentional cast to integer
$amount = '268435456';
}
if ((float) $amount < 0.0) {
if (-1 === bccomp($amount, '0')) {
$amount = bcmul($amount, '-1');
}
@@ -172,7 +172,7 @@ class BudgetLimitController extends Controller
$limit = $this->blRepository->store(
[
'budget_id' => $request->get('budget_id'),
'currency_id' => (int) $request->get('transaction_currency_id'),
'currency_id' => (int)$request->get('transaction_currency_id'),
'start_date' => $start,
'end_date' => $end,
'amount' => $amount,
@@ -187,7 +187,7 @@ class BudgetLimitController extends Controller
$array['spent'] = $spentArr[$currency->id]['sum'] ?? '0';
$array['left_formatted'] = app('amount')->formatAnything($limit->transactionCurrency, bcadd($array['spent'], $array['amount']));
$array['amount_formatted'] = app('amount')->formatAnything($limit->transactionCurrency, $limit['amount']);
$array['days_left'] = (string) $this->activeDaysLeft($start, $end);
$array['days_left'] = (string)$this->activeDaysLeft($start, $end);
// left per day:
$array['left_per_day'] = bcdiv(bcadd($array['spent'], $array['amount']), $array['days_left']);
@@ -201,20 +201,20 @@ class BudgetLimitController extends Controller
}
/**
* @param Request $request
* @param BudgetLimit $budgetLimit
* @param Request $request
* @param BudgetLimit $budgetLimit
*
* @return JsonResponse
*/
public function update(Request $request, BudgetLimit $budgetLimit): JsonResponse
{
$amount = (string) $request->get('amount');
$amount = (string)$request->get('amount');
if ('' === $amount) {
$amount = '0';
}
// sanity check on amount:
if ((float) $amount === 0.0) {
if (0 === bccomp($amount, '0')) {
$budgetId = $budgetLimit->budget_id;
$currency = $budgetLimit->transactionCurrency;
$this->blRepository->destroyBudgetLimit($budgetLimit);
@@ -226,10 +226,10 @@ class BudgetLimitController extends Controller
];
return response()->json($array);
}
if ((int) $amount > 268435456) { // 268 million
if ((int)$amount > 268435456) { // 268 million, intentional integer
$amount = '268435456';
}
if ((float) $amount < 0.0) {
if (-1 === bccomp($amount, '0')) {
$amount = bcmul($amount, '-1');
}
@@ -246,12 +246,12 @@ class BudgetLimitController extends Controller
$array['spent'] = $spentArr[$budgetLimit->transactionCurrency->id]['sum'] ?? '0';
$array['left_formatted'] = app('amount')->formatAnything($limit->transactionCurrency, bcadd($array['spent'], $array['amount']));
$array['amount_formatted'] = app('amount')->formatAnything($limit->transactionCurrency, $limit['amount']);
$array['days_left'] = (string) $this->activeDaysLeft($limit->start_date, $limit->end_date);
$array['days_left'] = (string)$this->activeDaysLeft($limit->start_date, $limit->end_date);
// left per day:
$array['left_per_day'] = bcdiv(bcadd($array['spent'], $array['amount']), $array['days_left']);
// left per day formatted.
$array['amount'] = number_format((float) $limit['amount'], $limit->transactionCurrency->decimal_places, '.', '');
$array['amount'] = app('steam')->bcround($limit['amount'], $limit->transactionCurrency->decimal_places);
$array['left_per_day_formatted'] = app('amount')->formatAnything($limit->transactionCurrency, $array['left_per_day']);
return response()->json($array);

View File

@@ -56,7 +56,7 @@ class EditController 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->attachments = app(AttachmentHelperInterface::class);
@@ -69,41 +69,41 @@ class EditController extends Controller
/**
* Budget edit form.
*
* @param Request $request
* @param Budget $budget
* @param Request $request
* @param Budget $budget
*
* @return Factory|View
*/
public function edit(Request $request, Budget $budget)
{
$subTitle = (string) trans('firefly.edit_budget', ['name' => $budget->name]);
$subTitle = (string)trans('firefly.edit_budget', ['name' => $budget->name]);
$autoBudget = $this->repository->getAutoBudget($budget);
// auto budget types
$autoBudgetTypes = [
0 => (string) trans('firefly.auto_budget_none'),
AutoBudget::AUTO_BUDGET_RESET => (string) trans('firefly.auto_budget_reset'),
AutoBudget::AUTO_BUDGET_ROLLOVER => (string) trans('firefly.auto_budget_rollover'),
0 => (string)trans('firefly.auto_budget_none'),
AutoBudget::AUTO_BUDGET_RESET => (string)trans('firefly.auto_budget_reset'),
AutoBudget::AUTO_BUDGET_ROLLOVER => (string)trans('firefly.auto_budget_rollover'),
];
$autoBudgetPeriods = [
'daily' => (string) trans('firefly.auto_budget_period_daily'),
'weekly' => (string) trans('firefly.auto_budget_period_weekly'),
'monthly' => (string) trans('firefly.auto_budget_period_monthly'),
'quarterly' => (string) trans('firefly.auto_budget_period_quarterly'),
'half_year' => (string) trans('firefly.auto_budget_period_half_year'),
'yearly' => (string) trans('firefly.auto_budget_period_yearly'),
'daily' => (string)trans('firefly.auto_budget_period_daily'),
'weekly' => (string)trans('firefly.auto_budget_period_weekly'),
'monthly' => (string)trans('firefly.auto_budget_period_monthly'),
'quarterly' => (string)trans('firefly.auto_budget_period_quarterly'),
'half_year' => (string)trans('firefly.auto_budget_period_half_year'),
'yearly' => (string)trans('firefly.auto_budget_period_yearly'),
];
// code to handle active-checkboxes
$hasOldInput = null !== $request->old('_token');
$currency = app('amount')->getDefaultCurrency();
$preFilled = [
'active' => $hasOldInput ? (bool) $request->old('active') : $budget->active,
'auto_budget_currency_id' => $hasOldInput ? (int) $request->old('auto_budget_currency_id') : $currency->id,
'active' => $hasOldInput ? (bool)$request->old('active') : $budget->active,
'auto_budget_currency_id' => $hasOldInput ? (int)$request->old('auto_budget_currency_id') : $currency->id,
];
if ($autoBudget) {
$amount = $hasOldInput ? $request->old('auto_budget_amount') : $autoBudget->amount;
$preFilled['auto_budget_amount'] = number_format((float) $amount, $autoBudget->transactionCurrency->decimal_places, '.', '');
$preFilled['auto_budget_amount'] = app('steam')->bcround($amount, $autoBudget->transactionCurrency->decimal_places);
}
// put previous url in session if not redirect from store (not "return_to_edit").
@@ -119,8 +119,8 @@ class EditController extends Controller
/**
* Budget update routine.
*
* @param BudgetFormUpdateRequest $request
* @param Budget $budget
* @param BudgetFormUpdateRequest $request
* @param Budget $budget
*
* @return RedirectResponse
*/
@@ -129,7 +129,7 @@ class EditController extends Controller
$data = $request->getBudgetData();
$this->repository->update($budget, $data);
$request->session()->flash('success', (string) trans('firefly.updated_budget', ['name' => $budget->name]));
$request->session()->flash('success', (string)trans('firefly.updated_budget', ['name' => $budget->name]));
$this->repository->cleanupBudgets();
app('preferences')->mark();
@@ -141,14 +141,14 @@ class EditController extends Controller
$this->attachments->saveAttachmentsForModel($budget, $files);
}
if (null !== $files && auth()->user()->hasRole('demo')) {
session()->flash('info', (string) trans('firefly.no_att_demo_user'));
session()->flash('info', (string)trans('firefly.no_att_demo_user'));
}
if (count($this->attachments->getMessages()->get('attachments')) > 0) {
$request->session()->flash('info', $this->attachments->getMessages()->get('attachments'));
}
if (1 === (int) $request->get('return_to_edit')) {
if (1 === (int)$request->get('return_to_edit')) {
$request->session()->put('budgets.edit.fromUpdate', true);
$redirect = redirect(route('budgets.edit', [$budget->id]))->withInput(['return_to_edit' => 1]);

View File

@@ -222,7 +222,7 @@ class IndexController extends Controller
$currency = $limit->transactionCurrency ?? $defaultCurrency;
$array['budgeted'][] = [
'id' => $limit->id,
'amount' => number_format((float) $limit->amount, $currency->decimal_places, '.', ''),
'amount' => app('steam')->bcround($limit->amount, $currency->decimal_places),
'start_date' => $limit->start_date->isoFormat($this->monthAndDayFormat),
'end_date' => $limit->end_date->isoFormat($this->monthAndDayFormat),
'in_range' => $limit->start_date->isSameDay($start) && $limit->end_date->isSameDay($end),

View File

@@ -130,7 +130,7 @@ class AccountController extends Controller
$tempData[] = [
'name' => $accountNames[$accountId],
'difference' => $diff,
'diff_float' => (float)$diff,
'diff_float' => (float) $diff, // intentional float
'currency_id' => $currencyId,
];
}
@@ -482,7 +482,6 @@ class AccountController extends Controller
];
$entries = [];
$current = clone $start;
if ('1D' === $step) {
// per day the entire period, balance for every day.
$format = (string)trans('config.month_and_day_js', [], $locale);
@@ -581,7 +580,7 @@ class AccountController extends Controller
$tempData[] = [
'name' => $accountNames[$accountId],
'difference' => $diff,
'diff_float' => (float)$diff,
'diff_float' => (float) $diff, // intentional float
'currency_id' => $currencyId,
];
}

View File

@@ -484,13 +484,13 @@ class BudgetController extends Controller
// get budget limit in this period for this currency.
$limit = $this->blRepository->find($budget, $currency, $currentStart, $currentEnd);
if (null !== $limit) {
$chartData[1]['entries'][$title] = round((float) $limit->amount, $currency->decimal_places);
$chartData[1]['entries'][$title] = app('steam')->bcround($limit->amount, $currency->decimal_places);
}
// get spent amount in this period for this currency.
$sum = $this->opsRepository->sumExpenses($currentStart, $currentEnd, $accounts, new Collection([$budget]), $currency);
$amount = app('steam')->positive($sum[$currency->id]['sum'] ?? '0');
$chartData[0]['entries'][$title] = round((float) $amount, $currency->decimal_places);
$chartData[0]['entries'][$title] = app('steam')->bcround($amount, $currency->decimal_places);
$currentStart = clone $currentEnd;
$currentStart->addDay()->startOfDay();
@@ -535,7 +535,7 @@ class BudgetController extends Controller
$title = $currentStart->isoFormat($titleFormat);
$sum = $this->nbRepository->sumExpenses($currentStart, $currentEnd, $accounts, $currency);
$amount = app('steam')->positive($sum[$currency->id]['sum'] ?? '0');
$chartData[$title] = round((float) $amount, $currency->decimal_places);
$chartData[$title] = app('steam')->bcround($amount, $currency->decimal_places);
$currentStart = app('navigation')->addPeriod($currentStart, $preferredRange, 0);
}

View File

@@ -243,8 +243,8 @@ class ReportController extends Controller
while ($currentStart <= $end) {
$key = $currentStart->format($format);
$title = $currentStart->isoFormat($titleFormat);
$income['entries'][$title] = round((float) ($currency[$key]['earned'] ?? '0'), $currency['currency_decimal_places']);
$expense['entries'][$title] = round((float) ($currency[$key]['spent'] ?? '0'), $currency['currency_decimal_places']);
$income['entries'][$title] = app('steam')->bcround(($currency[$key]['earned'] ?? '0'), $currency['currency_decimal_places']);
$expense['entries'][$title] = app('steam')->bcround(($currency[$key]['spent'] ?? '0'), $currency['currency_decimal_places']);
$currentStart = app('navigation')->addPeriod($currentStart, $preferredRange, 0);
}

View File

@@ -1,4 +1,5 @@
<?php
/**
* FrontpageController.php
* Copyright (c) 2019 james@firefly-iii.org
@@ -38,7 +39,7 @@ class FrontpageController extends Controller
/**
* Piggy bank pie chart.
*
* @param PiggyBankRepositoryInterface $repository
* @param PiggyBankRepositoryInterface $repository
*
* @return JsonResponse
*/
@@ -52,7 +53,7 @@ class FrontpageController extends Controller
if (1 === bccomp($amount, '0')) {
// percentage!
$pct = 0;
if (0.0 !== (float) $piggyBank->targetamount) {
if (0 !== bccomp($piggyBank->targetamount, '0')) {
$pct = round(($amount / $piggyBank->targetamount) * 100);
}

View File

@@ -238,8 +238,8 @@ class ReconcileController extends Controller
$startDate->subDay();
$currency = $this->accountRepos->getAccountCurrency($account) ?? app('amount')->getDefaultCurrency();
$startBalance = round((float) app('steam')->balance($account, $startDate), $currency->decimal_places);
$endBalance = round((float) app('steam')->balance($account, $end), $currency->decimal_places);
$startBalance = app('steam')->bcround(app('steam')->balance($account, $startDate), $currency->decimal_places);
$endBalance = app('steam')->bcround(app('steam')->balance($account, $end), $currency->decimal_places);
// get the transactions
$selectionStart = clone $start;

View File

@@ -77,7 +77,7 @@ class AmountController extends Controller
$leftOnAccount = $this->piggyRepos->leftOnAccount($piggyBank, today(config('app.timezone')));
$savedSoFar = $this->piggyRepos->getCurrentAmount($piggyBank);
$maxAmount = $leftOnAccount;
if (0.000 !== (float) $piggyBank->targetamount) {
if (0 !== bccomp($piggyBank->targetamount,'0')) {
$leftToSave = bcsub($piggyBank->targetamount, $savedSoFar);
$maxAmount = min($leftOnAccount, $leftToSave);
}
@@ -101,7 +101,7 @@ class AmountController extends Controller
$savedSoFar = $this->piggyRepos->getCurrentAmount($piggyBank);
$maxAmount = $leftOnAccount;
if (0.000 !== (float) $piggyBank->targetamount) {
if (0 !== bccomp($piggyBank->targetamount,'0')) {
$leftToSave = bcsub($piggyBank->targetamount, $savedSoFar);
$maxAmount = min($leftOnAccount, $leftToSave);
}
@@ -181,7 +181,7 @@ class AmountController extends Controller
return redirect(route('piggy-banks.index'));
}
$amount = number_format((float) $request->get('amount'), 12, '.', '');
$amount = (string) $request->get('amount');
session()->flash(
'error',

View File

@@ -56,7 +56,7 @@ class EditController extends Controller
$this->middleware(
function ($request, $next) {
app('view')->share('title', (string) trans('firefly.piggyBanks'));
app('view')->share('title', (string)trans('firefly.piggyBanks'));
app('view')->share('mainTitleIcon', 'fa-bullseye');
$this->attachments = app(AttachmentHelperInterface::class);
@@ -70,13 +70,13 @@ class EditController extends Controller
/**
* Edit a piggy bank.
*
* @param PiggyBank $piggyBank
* @param PiggyBank $piggyBank
*
* @return Factory|View
*/
public function edit(PiggyBank $piggyBank)
{
$subTitle = (string) trans('firefly.update_piggy_title', ['name' => $piggyBank->name]);
$subTitle = (string)trans('firefly.update_piggy_title', ['name' => $piggyBank->name]);
$subTitleIcon = 'fa-pencil';
$note = $piggyBank->notes()->first();
// Flash some data to fill the form.
@@ -87,15 +87,16 @@ class EditController extends Controller
$currency = Amount::getDefaultCurrency();
}
$preFilled = ['name' => $piggyBank->name,
'account_id' => $piggyBank->account_id,
'targetamount' => number_format((float) $piggyBank->targetamount, $currency->decimal_places, '.', ''),
'targetdate' => $targetDate,
'startdate' => $startDate,
'object_group' => $piggyBank->objectGroups->first() ? $piggyBank->objectGroups->first()->title : '',
'notes' => null === $note ? '' : $note->text,
$preFilled = [
'name' => $piggyBank->name,
'account_id' => $piggyBank->account_id,
'targetamount' => app('steam')->bcround($piggyBank->targetamount, $currency->decimal_places),
'targetdate' => $targetDate,
'startdate' => $startDate,
'object_group' => $piggyBank->objectGroups->first() ? $piggyBank->objectGroups->first()->title : '',
'notes' => null === $note ? '' : $note->text,
];
if (0.0 === (float) $piggyBank->targetamount) {
if (0 === bccomp($piggyBank->targetamount, '0')) {
$preFilled['targetamount'] = '';
}
session()->flash('preFilled', $preFilled);
@@ -112,8 +113,8 @@ class EditController extends Controller
/**
* Update a piggy bank.
*
* @param PiggyBankUpdateRequest $request
* @param PiggyBank $piggyBank
* @param PiggyBankUpdateRequest $request
* @param PiggyBank $piggyBank
*
* @return RedirectResponse|Redirector
*/
@@ -122,7 +123,7 @@ class EditController extends Controller
$data = $request->getPiggyBankData();
$piggyBank = $this->piggyRepos->update($piggyBank, $data);
session()->flash('success', (string) trans('firefly.updated_piggy_bank', ['name' => $piggyBank->name]));
session()->flash('success', (string)trans('firefly.updated_piggy_bank', ['name' => $piggyBank->name]));
app('preferences')->mark();
// store new attachment(s):
@@ -132,7 +133,7 @@ class EditController extends Controller
$this->attachments->saveAttachmentsForModel($piggyBank, $files);
}
if (null !== $files && auth()->user()->hasRole('demo')) {
session()->flash('info', (string) trans('firefly.no_att_demo_user'));
session()->flash('info', (string)trans('firefly.no_att_demo_user'));
}
if (count($this->attachments->getMessages()->get('attachments')) > 0) {
@@ -140,7 +141,7 @@ class EditController extends Controller
}
$redirect = redirect($this->getPreviousUrl('piggy-banks.edit.url'));
if (1 === (int) $request->get('return_to_edit')) {
if (1 === (int)$request->get('return_to_edit')) {
session()->put('piggy-banks.edit.fromUpdate', true);
$redirect = redirect(route('piggy-banks.edit', [$piggyBank->id]));

View File

@@ -188,7 +188,7 @@ class BudgetController extends Controller
$result[$key]['transactions']++;
$result[$key]['sum'] = bcadd($journal['amount'], $result[$key]['sum']);
$result[$key]['avg'] = bcdiv($result[$key]['sum'], (string) $result[$key]['transactions']);
$result[$key]['avg_float'] = (float) $result[$key]['avg'];
$result[$key]['avg_float'] = (float) $result[$key]['avg']; // intentional float
}
}
}
@@ -267,7 +267,7 @@ class BudgetController extends Controller
$total = $sums[$currencyId]['sum'] ?? '0';
$pct = '0';
if (0 !== bccomp($sum, '0') && 0 !== bccomp($total, '9')) {
$pct = round((float) bcmul(bcdiv($sum, $total), '100'));
$pct = round((float) bcmul(bcdiv($sum, $total), '100')); // intentional float
}
$report[$budgetId]['currencies'][$currencyId]['sum_pct'] = $pct;
}
@@ -384,7 +384,7 @@ class BudgetController extends Controller
$result[] = [
'description' => $journal['description'],
'transaction_group_id' => $journal['transaction_group_id'],
'amount_float' => (float) $journal['amount'],
'amount_float' => (float) $journal['amount'], // intentional float
'amount' => $journal['amount'],
'date' => $journal['date']->isoFormat($this->monthAndDayFormat),
'date_sort' => $journal['date']->format('Y-m-d'),

View File

@@ -302,7 +302,7 @@ class CategoryController extends Controller
$result[$key]['transactions']++;
$result[$key]['sum'] = bcadd($journal['amount'], $result[$key]['sum']);
$result[$key]['avg'] = bcdiv($result[$key]['sum'], (string) $result[$key]['transactions']);
$result[$key]['avg_float'] = (float) $result[$key]['avg'];
$result[$key]['avg_float'] = (float) $result[$key]['avg']; // intentional float
}
}
}

View File

@@ -137,6 +137,7 @@ class DeleteController extends Controller
Log::debug(sprintf('Now going to trigger updated account event for account #%d', $account->id));
event(new UpdatedAccount($account));
}
app('preferences')->mark();
return redirect($this->getPreviousUrl('transactions.delete.url'));

View File

@@ -145,7 +145,7 @@ class MassController extends Controller
// reverse amounts
foreach ($journals as $index => $journal) {
$journals[$index]['amount'] = number_format((float) app('steam')->positive($journal['amount']), $journal['currency_decimal_places'], '.', '');
$journals[$index]['amount'] = app('steam')->bcround(app('steam')->positive($journal['amount']), $journal['currency_decimal_places']);
$journals[$index]['foreign_amount'] = null === $journal['foreign_amount'] ?
null : app('steam')->positive($journal['foreign_amount']);
}

View File

@@ -46,7 +46,7 @@ class PiggyBankUpdateRequest extends FormRequest
'name' => $this->convertString('name'),
'startdate' => $this->getCarbonDate('startdate'),
'account_id' => $this->convertInteger('account_id'),
'targetamount' => $this->convertString('targetamount'),
'targetamount' => trim($this->convertString('targetamount')),
'targetdate' => $this->getCarbonDate('targetdate'),
'notes' => $this->stringWithNewlines('notes'),
'object_group_title' => $this->convertString('object_group'),