Fix piggy views.

This commit is contained in:
James Cole
2022-12-29 11:29:00 +01:00
parent e4db21f0c0
commit 3666ef8c59
2 changed files with 14 additions and 16 deletions

View File

@@ -87,21 +87,18 @@ 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);
$leftToSaveString = app('steam')->bcround($leftToSave, $currency->decimal_places);
$savePerMonth = app('steam')->bcround($this->piggyRepos->getSuggestedMonthlyAmount($piggyBank), $currency->decimal_places); $savePerMonth = app('steam')->bcround($this->piggyRepos->getSuggestedMonthlyAmount($piggyBank), $currency->decimal_places);
} }
$startDate = $piggyBank->startdate?->toAtomString(); $startDate = $piggyBank->startdate?->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>