This commit is contained in:
James Cole 2017-11-18 11:32:35 +01:00
parent 64fc6b6523
commit 1045ed13fa
No known key found for this signature in database
GPG Key ID: C16961E655E74B5E
4 changed files with 10 additions and 9 deletions

View File

@ -81,7 +81,7 @@ class BudgetController extends Controller
*/ */
public function amount(Request $request, Budget $budget) 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')); $start = Carbon::createFromFormat('Y-m-d', $request->get('start'));
$end = Carbon::createFromFormat('Y-m-d', $request->get('end')); $end = Carbon::createFromFormat('Y-m-d', $request->get('end'));
$budgetLimit = $this->repository->updateLimitAmount($budget, $start, $end, $amount); $budgetLimit = $this->repository->updateLimitAmount($budget, $start, $end, $amount);

View File

@ -87,6 +87,7 @@ class BudgetRepository implements BudgetRepositoryInterface
/** @var AccountRepositoryInterface $accountRepository */ /** @var AccountRepositoryInterface $accountRepository */
$accountRepository = app(AccountRepositoryInterface::class); $accountRepository = app(AccountRepositoryInterface::class);
$accounts = $accountRepository->getAccountsByType([AccountType::DEFAULT, AccountType::ASSET]); $accounts = $accountRepository->getAccountsByType([AccountType::DEFAULT, AccountType::ASSET]);
$defaultCurrency = app('amount')->getDefaultCurrency();
$return = []; $return = [];
/** @var Budget $budget */ /** @var Budget $budget */
foreach ($budgets as $budget) { foreach ($budgets as $budget) {
@ -105,7 +106,7 @@ class BudgetRepository implements BudgetRepositoryInterface
if ($limit->start_date->isSameDay($start) && $limit->end_date->isSameDay($end) if ($limit->start_date->isSameDay($start) && $limit->end_date->isSameDay($end)
) { ) {
$return[$budgetId]['currentLimit'] = $limit; $return[$budgetId]['currentLimit'] = $limit;
$return[$budgetId]['budgeted'] = $limit->amount; $return[$budgetId]['budgeted'] = round($limit->amount, $defaultCurrency->decimal_places);
continue; continue;
} }
// otherwise it's just one of the many relevant repetitions: // otherwise it's just one of the many relevant repetitions:
@ -599,11 +600,11 @@ class BudgetRepository implements BudgetRepositoryInterface
* @param Budget $budget * @param Budget $budget
* @param Carbon $start * @param Carbon $start
* @param Carbon $end * @param Carbon $end
* @param int $amount * @param string $amount
* *
* @return BudgetLimit * @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: // count the limits:
$limits = $budget->budgetlimits() $limits = $budget->budgetlimits()
@ -626,7 +627,7 @@ class BudgetRepository implements BudgetRepositoryInterface
} }
// delete if amount is zero. // delete if amount is zero.
if (null !== $limit && $amount <= 0.0) { if (null !== $limit && bccomp('0', $amount) < 0) {
$limit->delete(); $limit->delete();
return new BudgetLimit; return new BudgetLimit;

View File

@ -214,5 +214,5 @@ interface BudgetRepositoryInterface
* *
* @return BudgetLimit * @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;
} }

View File

@ -164,7 +164,7 @@
{% endif %} {% endif %}
</td> </td>
{% if budgetInformation[budget.id]['currentLimit'] %} {% if budgetInformation[budget.id]['currentLimit'] %}
{% set repAmount = budgetInformation[budget.id]['currentLimit'].amount %} {% set repAmount = budgetInformation[budget.id]['budgeted'] %}
{% else %} {% else %}
{% set repAmount = '0' %} {% set repAmount = '0' %}
{% endif %} {% endif %}
@ -174,8 +174,8 @@
<div class="input-group-addon">{{ defaultCurrency.symbol|raw }}</div> <div class="input-group-addon">{{ defaultCurrency.symbol|raw }}</div>
<input type="hidden" name="balance_currency_id" value="{{ defaultCurrency.id }}"/> <input type="hidden" name="balance_currency_id" value="{{ defaultCurrency.id }}"/>
<input class="form-control budgetAmount" data-original="{{ repAmount }}" <input class="form-control budgetAmount" data-original="{{ repAmount }}"
data-id="{{ budget.id }}" value="{{ repAmount|round }}" autocomplete="off" data-id="{{ budget.id }}" value="{{ repAmount }}" autocomplete="off"
step="1" min="0" name="amount" type="number"> min="0" name="amount" type="number">
</div> </div>
</td> </td>
<td class="hidden-sm hidden-xs spent" data-id="{{ budget.id }}" data-spent="{{ budgetInformation[budget.id]['spent'] }}" <td class="hidden-sm hidden-xs spent" data-id="{{ budget.id }}" data-spent="{{ budgetInformation[budget.id]['spent'] }}"