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',
'auto_budget_type' => 'numeric|integer|gte:0|lte:31',
'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',
];
}

View File

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

View File

@ -77,6 +77,7 @@
<td class="hidden-sm hidden-xs" style="width:40px;">
{% 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 }}">
<span data-id="{{ piggy.id }}" class="fa fa-plus"></span></a>