Merge branch 'develop' into 5.8-dev

# Conflicts:
#	composer.lock
This commit is contained in:
James Cole 2022-12-29 11:36:07 +01:00
commit 85a2a87806
No known key found for this signature in database
GPG Key ID: B49A324B7EAD6D80
3 changed files with 15 additions and 17 deletions

View File

@ -77,7 +77,7 @@ class BudgetFormUpdateRequest extends FormRequest
'active' => 'numeric|between:0,1', 'active' => 'numeric|between:0,1',
'auto_budget_type' => 'numeric|integer|gte:0|lte:31', 'auto_budget_type' => 'numeric|integer|gte:0|lte:31',
'auto_budget_currency_id' => 'exists:transaction_currencies,id', 'auto_budget_currency_id' => 'exists:transaction_currencies,id',
'auto_budget_amount' => 'min:0|max:1000000000|required_if:auto_budget_type,1|required_if:auto_budget_type,2', 'auto_budget_amount' => 'min:0|max:1000000000|required_if:auto_budget_type,1|required_if:auto_budget_type,2|numeric',
'auto_budget_period' => 'in:daily,weekly,monthly,quarterly,half_year,yearly', 'auto_budget_period' => 'in:daily,weekly,monthly,quarterly,half_year,yearly',
]; ];
} }

View File

@ -87,22 +87,19 @@ class PiggyBankTransformer extends AbstractTransformer
} }
// get currently saved amount: // get currently saved amount:
$currentAmountStr = $this->piggyRepos->getCurrentAmount($piggyBank); $currentAmount = app('steam')->bcround($this->piggyRepos->getCurrentAmount($piggyBank), $currency->decimal_places);
$currentAmount = app('steam')->bcround($currentAmountStr, $currency->decimal_places);
// Amounts, depending on 0.0 state of target amount // Amounts, depending on 0.0 state of target amount
$percentage = null; $percentage = null;
$targetAmountString = null; $targetAmount = $piggyBank->targetamount;
$leftToSaveString = null; $leftToSave = null;
$savePerMonth = null; $savePerMonth = null;
if (0 !== bccomp(app('steam')->bcround($currentAmountStr, $currency->decimal_places), '0')) { if (0 !== bccomp($targetAmount, '0')) { // target amount is not 0.00
$leftToSave = bcsub($piggyBank->targetamount, $currentAmountStr); $leftToSave = bcsub($piggyBank->targetamount, $currentAmount);
$targetAmount = (string)$piggyBank->targetamount; $percentage = (int)bcmul(bcdiv($currentAmount, $targetAmount), '100');
$targetAmount = 1 === bccomp('0.01', $targetAmount) ? '0.01' : $targetAmount; $targetAmount = app('steam')->bcround($targetAmount, $currency->decimal_places);
$percentage = (int)(0 !== bccomp('0', $currentAmountStr) ? $currentAmountStr / $targetAmount * 100 : 0); $leftToSave = app('steam')->bcround($leftToSave, $currency->decimal_places);
$targetAmountString = app('steam')->bcround($targetAmount, $currency->decimal_places); $savePerMonth = app('steam')->bcround($this->piggyRepos->getSuggestedMonthlyAmount($piggyBank), $currency->decimal_places);
$leftToSaveString = app('steam')->bcround($leftToSave, $currency->decimal_places);
$savePerMonth = app('steam')->bcround($this->piggyRepos->getSuggestedMonthlyAmount($piggyBank), $currency->decimal_places);
} }
$startDate = $piggyBank->startdate?->toAtomString(); $startDate = $piggyBank->startdate?->toAtomString();
$targetDate = $piggyBank->targetdate?->toAtomString(); $targetDate = $piggyBank->targetdate?->toAtomString();
@ -119,10 +116,10 @@ class PiggyBankTransformer extends AbstractTransformer
'currency_code' => $currency->code, 'currency_code' => $currency->code,
'currency_symbol' => $currency->symbol, 'currency_symbol' => $currency->symbol,
'currency_decimal_places' => (int)$currency->decimal_places, 'currency_decimal_places' => (int)$currency->decimal_places,
'target_amount' => $targetAmountString, 'target_amount' => $targetAmount,
'percentage' => $percentage, 'percentage' => $percentage,
'current_amount' => $currentAmount, 'current_amount' => $currentAmount,
'left_to_save' => $leftToSaveString, 'left_to_save' => $leftToSave,
'save_per_month' => $savePerMonth, 'save_per_month' => $savePerMonth,
'start_date' => $startDate, 'start_date' => $startDate,
'target_date' => $targetDate, 'target_date' => $targetDate,

View File

@ -77,6 +77,7 @@
<td class="hidden-sm hidden-xs" style="width:40px;"> <td class="hidden-sm hidden-xs" style="width:40px;">
{% if piggy.left_to_save > 0 or null == piggy.left_to_save %} {% if piggy.left_to_save > 0 or null == piggy.left_to_save %}
<a href="{{ route('piggy-banks.add-money', piggy.id) }}" class="btn btn-default btn-xs addMoney" data-id="{{ piggy.id }}"> <a href="{{ route('piggy-banks.add-money', piggy.id) }}" class="btn btn-default btn-xs addMoney" data-id="{{ piggy.id }}">
<span data-id="{{ piggy.id }}" class="fa fa-plus"></span></a> <span data-id="{{ piggy.id }}" class="fa fa-plus"></span></a>