diff --git a/app/Http/Controllers/BudgetController.php b/app/Http/Controllers/BudgetController.php index 63b12faeaa..76d3683f16 100644 --- a/app/Http/Controllers/BudgetController.php +++ b/app/Http/Controllers/BudgetController.php @@ -81,7 +81,7 @@ class BudgetController extends Controller */ public function amount(Request $request, Budget $budget) { - $amount = intval($request->get('amount')); + $amount = strval($request->get('amount')); $start = Carbon::createFromFormat('Y-m-d', $request->get('start')); $end = Carbon::createFromFormat('Y-m-d', $request->get('end')); $budgetLimit = $this->repository->updateLimitAmount($budget, $start, $end, $amount); diff --git a/app/Repositories/Budget/BudgetRepository.php b/app/Repositories/Budget/BudgetRepository.php index e4be053696..88c2872307 100644 --- a/app/Repositories/Budget/BudgetRepository.php +++ b/app/Repositories/Budget/BudgetRepository.php @@ -87,6 +87,7 @@ class BudgetRepository implements BudgetRepositoryInterface /** @var AccountRepositoryInterface $accountRepository */ $accountRepository = app(AccountRepositoryInterface::class); $accounts = $accountRepository->getAccountsByType([AccountType::DEFAULT, AccountType::ASSET]); + $defaultCurrency = app('amount')->getDefaultCurrency(); $return = []; /** @var Budget $budget */ foreach ($budgets as $budget) { @@ -105,7 +106,7 @@ class BudgetRepository implements BudgetRepositoryInterface if ($limit->start_date->isSameDay($start) && $limit->end_date->isSameDay($end) ) { $return[$budgetId]['currentLimit'] = $limit; - $return[$budgetId]['budgeted'] = $limit->amount; + $return[$budgetId]['budgeted'] = round($limit->amount, $defaultCurrency->decimal_places); continue; } // otherwise it's just one of the many relevant repetitions: @@ -599,11 +600,11 @@ class BudgetRepository implements BudgetRepositoryInterface * @param Budget $budget * @param Carbon $start * @param Carbon $end - * @param int $amount + * @param string $amount * * @return BudgetLimit */ - public function updateLimitAmount(Budget $budget, Carbon $start, Carbon $end, int $amount): BudgetLimit + public function updateLimitAmount(Budget $budget, Carbon $start, Carbon $end, string $amount): BudgetLimit { // count the limits: $limits = $budget->budgetlimits() @@ -626,7 +627,7 @@ class BudgetRepository implements BudgetRepositoryInterface } // delete if amount is zero. - if (null !== $limit && $amount <= 0.0) { + if (null !== $limit && bccomp('0', $amount) < 0) { $limit->delete(); return new BudgetLimit; diff --git a/app/Repositories/Budget/BudgetRepositoryInterface.php b/app/Repositories/Budget/BudgetRepositoryInterface.php index ee4a15d9d2..473c363512 100644 --- a/app/Repositories/Budget/BudgetRepositoryInterface.php +++ b/app/Repositories/Budget/BudgetRepositoryInterface.php @@ -214,5 +214,5 @@ interface BudgetRepositoryInterface * * @return BudgetLimit */ - public function updateLimitAmount(Budget $budget, Carbon $start, Carbon $end, int $amount): BudgetLimit; + public function updateLimitAmount(Budget $budget, Carbon $start, Carbon $end, string $amount): BudgetLimit; } diff --git a/resources/views/budgets/index.twig b/resources/views/budgets/index.twig index 71ba5fd301..6c071bd65a 100644 --- a/resources/views/budgets/index.twig +++ b/resources/views/budgets/index.twig @@ -164,7 +164,7 @@ {% endif %} {% if budgetInformation[budget.id]['currentLimit'] %} - {% set repAmount = budgetInformation[budget.id]['currentLimit'].amount %} + {% set repAmount = budgetInformation[budget.id]['budgeted'] %} {% else %} {% set repAmount = '0' %} {% endif %} @@ -174,8 +174,8 @@