mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-12 23:45:10 +00:00
Fix #9878
This commit is contained in:
@@ -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,
|
||||
|
@@ -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',
|
||||
|
@@ -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));
|
||||
|
@@ -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>
|
||||
|
Reference in New Issue
Block a user