This commit is contained in:
James Cole
2025-04-20 12:41:46 +02:00
parent 8f5e58e8ad
commit a861126c0f
4 changed files with 48 additions and 37 deletions

View File

@@ -79,6 +79,7 @@ class EditController extends Controller
$preFilled = [
'name' => $piggyBank->name,
'transaction_currency_id' => (int) $piggyBank->transaction_currency_id,
'target_amount' => app('steam')->bcround($piggyBank->target_amount, $piggyBank->transactionCurrency->decimal_places),
'target_date' => $targetDate,
'start_date' => $startDate,

View File

@@ -53,6 +53,7 @@ class PiggyBankUpdateRequest extends FormRequest
'start_date' => $this->getCarbonDate('start_date'),
'target_amount' => trim($this->convertString('target_amount')),
'target_date' => $this->getCarbonDate('target_date'),
'transaction_currency_id' => $this->convertInteger('transaction_currency_id'),
'notes' => $this->stringWithNewlines('notes'),
'object_group_title' => $this->convertString('object_group'),
];
@@ -80,6 +81,7 @@ class PiggyBankUpdateRequest extends FormRequest
'accounts.*' => 'required|belongsToUser:accounts',
'target_amount' => ['nullable', new IsValidPositiveAmount()],
'start_date' => 'date',
'transaction_currency_id' => 'exists:transaction_currencies,id',
'target_date' => 'date|nullable',
'order' => 'integer|max:32768|min:1',
'object_group' => 'min:0|max:255',

View File

@@ -31,6 +31,7 @@ use FireflyIII\Models\Account;
use FireflyIII\Models\Note;
use FireflyIII\Models\PiggyBank;
use FireflyIII\Models\Transaction;
use FireflyIII\Models\TransactionCurrency;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\Repositories\ObjectGroup\CreatesObjectGroups;
use FireflyIII\Support\Http\Api\ExchangeRateConverter;
@@ -223,6 +224,8 @@ trait ModifiesPiggyBanks
$factory = new PiggyBankFactory();
$factory->user = $this->user;
// the piggy bank currency is set or updated FIRST, if it exists.
$factory->linkToAccountIds($piggyBank, $data['accounts'] ?? []);
@@ -280,6 +283,13 @@ trait ModifiesPiggyBanks
if (array_key_exists('name', $data) && '' !== $data['name']) {
$piggyBank->name = $data['name'];
}
if (array_key_exists('transaction_currency_id', $data) && is_int($data['transaction_currency_id'])) {
$currency = TransactionCurrency::find($data['transaction_currency_id']);
if (null !== $currency) {
$piggyBank->transaction_currency_id = $currency->id;
}
}
if (array_key_exists('target_amount', $data) && '' !== $data['target_amount']) {
$piggyBank->target_amount = $data['target_amount'];
}
@@ -326,8 +336,7 @@ trait ModifiesPiggyBanks
->where('accounts.user_id', $this->user->id)
->where('piggy_banks.order', '<=', $newOrder)->where('piggy_banks.order', '>', $oldOrder)
->where('piggy_banks.id', '!=', $piggyBank->id)
->distinct()->decrement('piggy_banks.order')
;
->distinct()->decrement('piggy_banks.order');
$piggyBank->order = $newOrder;
Log::debug(sprintf('[1] Order of piggy #%d ("%s") from %d to %d', $piggyBank->id, $piggyBank->name, $oldOrder, $newOrder));
@@ -340,8 +349,7 @@ trait ModifiesPiggyBanks
->where('accounts.user_id', $this->user->id)
->where('piggy_banks.order', '>=', $newOrder)->where('piggy_banks.order', '<', $oldOrder)
->where('piggy_banks.id', '!=', $piggyBank->id)
->distinct()->increment('piggy_banks.order')
;
->distinct()->increment('piggy_banks.order');
$piggyBank->order = $newOrder;
Log::debug(sprintf('[2] Order of piggy #%d ("%s") from %d to %d', $piggyBank->id, $piggyBank->name, $oldOrder, $newOrder));

View File

@@ -23,7 +23,7 @@
<div class="box-body">
{{ ExpandedForm.text('name') }}
{{ ExpandedForm.amountNoCurrency('target_amount') }}
{{ CurrencyForm.currencyList('transaction_currency_id', null, {helpText:'piggy_default_currency'|_}) }}
{{ CurrencyForm.currencyList('transaction_currency_id', preFilled.transaction_currency_id, {helpText:'piggy_default_currency'|_}) }}
{{ AccountForm.assetLiabilityMultiAccountList('accounts', preFilled.accounts, {label: 'saveOnAccounts'|_, helpText: 'piggy_account_currency_match'|_ }) }}
</div>