Skip to content

Firefly III: a personal finances manager

Make sure edit controller actually updates the type of the recurring transaction.

James Colebb75b6c0991e
diff --git a/app/Http/Controllers/Recurring/EditController.php b/app/Http/Controllers/Recurring/EditController.php
index dad642c442..144489d599 100644
--- a/app/Http/Controllers/Recurring/EditController.php
+++ b/app/Http/Controllers/Recurring/EditController.php
@@ -187,7 +187,6 @@ final class EditController extends Controller
{
$data = $request->getAll();
$recurrence = $this->repository->update($recurrence, $data);
-
$request->session()->flash('success', (string) trans('firefly.updated_recurrence', ['title' => $recurrence->title]));
Log::channel('audit')->info(sprintf('Updated recurrence #%d.', $recurrence->id), $data);
diff --git a/app/Services/Internal/Update/RecurrenceUpdateService.php b/app/Services/Internal/Update/RecurrenceUpdateService.php
index cb0d97b5df..dfd9946019 100644
--- a/app/Services/Internal/Update/RecurrenceUpdateService.php
+++ b/app/Services/Internal/Update/RecurrenceUpdateService.php
@@ -24,12 +24,15 @@ declare(strict_types=1);
namespace FireflyIII\Services\Internal\Update;
+use FireflyIII\Enums\TransactionTypeEnum;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Factory\TransactionCurrencyFactory;
use FireflyIII\Models\Note;
use FireflyIII\Models\Recurrence;
use FireflyIII\Models\RecurrenceRepetition;
use FireflyIII\Models\RecurrenceTransaction;
+use FireflyIII\Models\Transaction;
+use FireflyIII\Models\TransactionType;
use FireflyIII\Services\Internal\Support\RecurringTransactionTrait;
use FireflyIII\Services\Internal\Support\TransactionTypeTrait;
use FireflyIII\User;
@@ -90,6 +93,14 @@ class RecurrenceUpdateService
if (array_key_exists('notes', $info)) {
$this->setNoteText($recurrence, $info['notes']);
}
+ // update the type.
+ if (array_key_exists('type', $info)) {
+ $type = ucfirst($info['type']);
+ $object = TransactionType::query()->where('type', $type)->first();
+ if(null !== $object) {
+ $recurrence->transaction_type_id = $object->id;
+ }
+ }
}
$recurrence->save();
@@ -100,7 +111,7 @@ class RecurrenceUpdateService
$this->updateRepetitions($recurrence, $data['repetitions'] ?? []);
}
// update all transactions:
- // update all transactions (and associated meta-data)
+ // update all transactions (and associated metadata)
if (array_key_exists('transactions', $data)) {
$this->updateTransactions($recurrence, $data['transactions'] ?? []);
}
@@ -238,6 +249,13 @@ class RecurrenceUpdateService
if (array_key_exists('piggy_bank_id', $submitted)) {
$this->updatePiggyBank($transaction, (int) $submitted['piggy_bank_id']);
}
+ if(array_key_exists('type', $submitted)) {
+ $type = TransactionType::query()->where('type', ucfirst($submitted['type']))->first();
+ if(null !== $type) {
+ $transaction->transaction_type_id = $type->id;
+ $transaction->save();
+ }
+ }
}
/**
diff --git a/resources/assets/v3/js/pages/recurring/shared/create-button-switcher.js b/resources/assets/v3/js/pages/recurring/shared/create-button-switcher.js
index 052584a16b..28564e5f7c 100644
--- a/resources/assets/v3/js/pages/recurring/shared/create-button-switcher.js
+++ b/resources/assets/v3/js/pages/recurring/shared/create-button-switcher.js
@@ -26,7 +26,7 @@ function createButtonSwitcher() {
list[i].addEventListener('click', (event) => {
let transactionType = event.currentTarget.dataset.value;
- // console.log('Clicked value is ' + transactionType);
+ console.log('Clicked value is ' + transactionType);
switchTransactionType(transactionType);
return false;
});
diff --git a/resources/assets/v3/js/pages/recurring/shared/switch-transaction-type.js b/resources/assets/v3/js/pages/recurring/shared/switch-transaction-type.js
index fe9743c41b..2e3f74aacd 100644
--- a/resources/assets/v3/js/pages/recurring/shared/switch-transaction-type.js
+++ b/resources/assets/v3/js/pages/recurring/shared/switch-transaction-type.js
@@ -31,6 +31,7 @@ function switchTransactionType(transactionType) {
list[i].classList.add('btn-secondary');
}
}
+ document.querySelector('input[type="hidden"][name="transaction_type"]').value = transactionType;
if ('withdrawal' === transactionType) {
// hide source account name:
document.getElementById('deposit_source_id_holder').style.display = 'none';