mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-12 15:35:15 +00:00
Remove many references to (float)
This commit is contained in:
@@ -162,7 +162,7 @@ class AvailableBudgetController extends Controller
|
||||
*/
|
||||
public function edit(AvailableBudget $availableBudget, Carbon $start, Carbon $end)
|
||||
{
|
||||
$availableBudget->amount = number_format((float) $availableBudget->amount, $availableBudget->transactionCurrency->decimal_places, '.', '');
|
||||
$availableBudget->amount = app('steam')->bcround($availableBudget->amount, $availableBudget->transactionCurrency->decimal_places);
|
||||
|
||||
return view('budgets.available-budgets.edit', compact('availableBudget', 'start', 'end'));
|
||||
}
|
||||
|
@@ -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);
|
||||
|
@@ -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,19 +141,17 @@ 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]);
|
||||
|
||||
}
|
||||
|
||||
return $redirect;
|
||||
|
@@ -210,7 +210,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),
|
||||
|
Reference in New Issue
Block a user