mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-19 10:53:31 +00:00
Piggies can have no target amount.
This commit is contained in:
@@ -77,8 +77,11 @@ class AmountController extends Controller
|
||||
{
|
||||
$leftOnAccount = $this->piggyRepos->leftOnAccount($piggyBank, today(config('app.timezone')));
|
||||
$savedSoFar = $this->piggyRepos->getCurrentAmount($piggyBank);
|
||||
$maxAmount = $leftOnAccount;
|
||||
if (0.000 !== (float) $piggyBank->targetamount) {
|
||||
$leftToSave = bcsub($piggyBank->targetamount, $savedSoFar);
|
||||
$maxAmount = min($leftOnAccount, $leftToSave);
|
||||
}
|
||||
$currency = $this->accountRepos->getAccountCurrency($piggyBank->account) ?? app('amount')->getDefaultCurrency();
|
||||
|
||||
return view('piggy-banks.add', compact('piggyBank', 'maxAmount', 'currency'));
|
||||
@@ -97,8 +100,12 @@ class AmountController extends Controller
|
||||
$date = session('end', today(config('app.timezone')));
|
||||
$leftOnAccount = $this->piggyRepos->leftOnAccount($piggyBank, $date);
|
||||
$savedSoFar = $this->piggyRepos->getCurrentAmount($piggyBank);
|
||||
$maxAmount = $leftOnAccount;
|
||||
|
||||
if (0.000 !== (float) $piggyBank->targetamount) {
|
||||
$leftToSave = bcsub($piggyBank->targetamount, $savedSoFar);
|
||||
$maxAmount = min($leftOnAccount, $leftToSave);
|
||||
}
|
||||
$currency = $this->accountRepos->getAccountCurrency($piggyBank->account) ?? app('amount')->getDefaultCurrency();
|
||||
|
||||
return view('piggy-banks.add-mobile', compact('piggyBank', 'maxAmount', 'currency'));
|
||||
|
@@ -30,6 +30,7 @@ use FireflyIII\Http\Requests\PiggyBankUpdateRequest;
|
||||
use FireflyIII\Models\PiggyBank;
|
||||
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||
use FireflyIII\Repositories\PiggyBank\PiggyBankRepositoryInterface;
|
||||
use Amount;
|
||||
use Illuminate\Contracts\View\Factory;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Routing\Redirector;
|
||||
@@ -77,13 +78,14 @@ class EditController extends Controller
|
||||
{
|
||||
$subTitle = (string) trans('firefly.update_piggy_title', ['name' => $piggyBank->name]);
|
||||
$subTitleIcon = 'fa-pencil';
|
||||
$targetDate = null;
|
||||
$startDate = null;
|
||||
$note = $piggyBank->notes()->first();
|
||||
// Flash some data to fill the form.
|
||||
$targetDate = $piggyBank->targetdate?->format('Y-m-d');
|
||||
$startDate = $piggyBank->startdate?->format('Y-m-d');
|
||||
$currency = $this->accountRepository->getAccountCurrency($piggyBank->account);
|
||||
if (null === $currency) {
|
||||
$currency = Amount::getDefaultCurrency();
|
||||
}
|
||||
|
||||
$preFilled = ['name' => $piggyBank->name,
|
||||
'account_id' => $piggyBank->account_id,
|
||||
@@ -93,6 +95,9 @@ class EditController extends Controller
|
||||
'object_group' => $piggyBank->objectGroups->first() ? $piggyBank->objectGroups->first()->title : '',
|
||||
'notes' => null === $note ? '' : $note->text,
|
||||
];
|
||||
if(0.0 === (float) $piggyBank->targetamount) {
|
||||
$preFilled['targetamount'] = '';
|
||||
}
|
||||
session()->flash('preFilled', $preFilled);
|
||||
|
||||
// put previous url in session if not redirect from store (not "return_to_edit").
|
||||
|
@@ -61,7 +61,7 @@ class PiggyBankStoreRequest extends FormRequest
|
||||
return [
|
||||
'name' => 'required|between:1,255|uniquePiggyBankForUser',
|
||||
'account_id' => 'required|belongsToUser:accounts',
|
||||
'targetamount' => 'required|numeric|gte:0.01|max:1000000000',
|
||||
'targetamount' => 'nullable|numeric|max:1000000000',
|
||||
'startdate' => 'date',
|
||||
'targetdate' => 'date|nullable',
|
||||
'order' => 'integer|min:1',
|
||||
|
@@ -65,7 +65,7 @@ class PiggyBankUpdateRequest extends FormRequest
|
||||
return [
|
||||
'name' => sprintf('required|between:1,255|uniquePiggyBankForUser:%d', $piggy->id),
|
||||
'account_id' => 'required|belongsToUser:accounts',
|
||||
'targetamount' => 'required|numeric|gte:0.01|max:1000000000',
|
||||
'targetamount' => 'nullable|numeric|max:1000000000',
|
||||
'startdate' => 'date',
|
||||
'targetdate' => 'date|nullable',
|
||||
'order' => 'integer|min:1',
|
||||
|
@@ -77,6 +77,8 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
* @property string $email
|
||||
* @property int|null $user_group_id
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|Budget whereUserGroupId($value)
|
||||
* @property-read Collection|\FireflyIII\Models\Note[] $notes
|
||||
* @property-read int|null $notes_count
|
||||
*/
|
||||
class Budget extends Model
|
||||
{
|
||||
|
@@ -91,8 +91,13 @@ trait ModifiesPiggyBanks
|
||||
$today = today(config('app.timezone'));
|
||||
$leftOnAccount = $this->leftOnAccount($piggyBank, $today);
|
||||
$savedSoFar = (string) $this->getRepetition($piggyBank)->currentamount;
|
||||
$maxAmount = $leftOnAccount;
|
||||
$leftToSave = null;
|
||||
if (0.0 !== (float) $piggyBank->targetamount) {
|
||||
$leftToSave = bcsub($piggyBank->targetamount, $savedSoFar);
|
||||
$maxAmount = 1 === bccomp($leftOnAccount, $leftToSave) ? $leftToSave : $leftOnAccount;
|
||||
}
|
||||
|
||||
$compare = bccomp($amount, $maxAmount);
|
||||
$result = $compare <= 0;
|
||||
|
||||
|
@@ -88,15 +88,23 @@ class PiggyBankTransformer extends AbstractTransformer
|
||||
$currentAmountStr = $this->piggyRepos->getCurrentAmount($piggyBank);
|
||||
$currentAmount = number_format((float) $currentAmountStr, $currency->decimal_places, '.', '');
|
||||
|
||||
// left to save:
|
||||
// Amounts, depending on 0.0 state of target amount
|
||||
$percentage = null;
|
||||
$targetAmountString = null;
|
||||
$leftToSaveString = null;
|
||||
$savePerMonth = null;
|
||||
if (0.000 !== (float) $piggyBank->targetamount) {
|
||||
$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 = number_format((float) $targetAmount, $currency->decimal_places, '.', '');
|
||||
$leftToSaveString = number_format((float) $leftToSave, $currency->decimal_places, '.', '');
|
||||
$savePerMonth = number_format((float) $this->piggyRepos->getSuggestedMonthlyAmount($piggyBank), $currency->decimal_places, '.', '');
|
||||
}
|
||||
$startDate = $piggyBank->startdate?->toAtomString();
|
||||
$targetDate = $piggyBank->targetdate?->toAtomString();
|
||||
|
||||
// target and percentage:
|
||||
$targetAmount = $piggyBank->targetamount;
|
||||
$targetAmount = 1 === bccomp('0.01', (string)$targetAmount) ? '0.01' : $targetAmount;
|
||||
$percentage = (int)(0 !== bccomp('0', $currentAmountStr) ? $currentAmountStr / $targetAmount * 100 : 0);
|
||||
|
||||
return [
|
||||
'id' => (string) $piggyBank->id,
|
||||
@@ -109,11 +117,11 @@ class PiggyBankTransformer extends AbstractTransformer
|
||||
'currency_code' => $currency->code,
|
||||
'currency_symbol' => $currency->symbol,
|
||||
'currency_decimal_places' => (int) $currency->decimal_places,
|
||||
'target_amount' => number_format((float)$targetAmount, $currency->decimal_places, '.', ''),
|
||||
'target_amount' => $targetAmountString,
|
||||
'percentage' => $percentage,
|
||||
'current_amount' => $currentAmount,
|
||||
'left_to_save' => number_format((float)$leftToSave, $currency->decimal_places, '.', ''),
|
||||
'save_per_month' => number_format((float)$this->piggyRepos->getSuggestedMonthlyAmount($piggyBank), $currency->decimal_places, '.', ''),
|
||||
'left_to_save' => $leftToSaveString,
|
||||
'save_per_month' => $savePerMonth,
|
||||
'start_date' => $startDate,
|
||||
'target_date' => $targetDate,
|
||||
'order' => (int) $piggyBank->order,
|
||||
|
@@ -57,6 +57,7 @@
|
||||
</td>
|
||||
|
||||
<td class="hidden-sm hidden-xs piggyBar">
|
||||
{% if null != piggy.percentage %}
|
||||
<div class="progress progress" style="margin-bottom:0;">
|
||||
<div
|
||||
{% if piggy.percentage == 100 %}
|
||||
@@ -71,17 +72,20 @@
|
||||
{{ piggy.percentage }}%
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
</td>
|
||||
|
||||
|
||||
<td class="hidden-sm hidden-xs" style="width:40px;">
|
||||
{% if piggy.left_to_save > 0 %}
|
||||
{% 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>
|
||||
{% endif %}
|
||||
</td>
|
||||
<td class="hidden-sm hidden-xs" style="text-align:right;">
|
||||
{% if null != piggy.target_amount %}
|
||||
<span title="{{ 'target_amount'|_ }}">{{ formatAmountBySymbol(piggy.target_amount,piggy.currency_symbol,piggy.currency_decimal_places) }}</span>
|
||||
{% endif %}
|
||||
</td>
|
||||
<td class="hidden-sm hidden-xs" style="text-align:right;">
|
||||
{% if piggy.left_to_save > 0 %}
|
||||
|
@@ -42,24 +42,28 @@
|
||||
<td>{{ piggy.object_group_title }}</a></td>
|
||||
</tr>
|
||||
{% endif %}
|
||||
{% if null != piggy.target_amount %}
|
||||
<tr>
|
||||
<td>{{ 'target_amount'|_ }}</td>
|
||||
<td>
|
||||
{{ formatAmountBySymbol(piggy.target_amount, piggy.currency_symbol, piggy.currency_decimal_places) }}
|
||||
</td>
|
||||
</tr>
|
||||
{% endif %}
|
||||
<tr>
|
||||
<td>{{ 'saved_so_far'|_ }}</td>
|
||||
<td>
|
||||
{{ formatAmountBySymbol(piggy.current_amount, piggy.currency_symbol, piggy.currency_decimal_places) }}
|
||||
</td>
|
||||
</tr>
|
||||
{% if null != piggy.left_to_save %}
|
||||
<tr>
|
||||
<td>{{ 'left_to_save'|_ }}</td>
|
||||
<td>
|
||||
{{ formatAmountBySymbol(piggy.left_to_save, piggy.currency_symbol, piggy.currency_decimal_places) }}
|
||||
</td>
|
||||
</tr>
|
||||
{% endif %}
|
||||
<tr>
|
||||
<td>{{ 'start_date'|_ }}</td>
|
||||
<td>
|
||||
|
Reference in New Issue
Block a user