Skip to content

Firefly III: a personal finances manager

Fix #10824

James Colef3b7a3015dcc
diff --git a/app/Api/V1/Controllers/Autocomplete/AccountController.php b/app/Api/V1/Controllers/Autocomplete/AccountController.php
index a9dba92ca5..bf1d7a3716 100644
--- a/app/Api/V1/Controllers/Autocomplete/AccountController.php
+++ b/app/Api/V1/Controllers/Autocomplete/AccountController.php
@@ -114,6 +114,7 @@ class AccountController extends Controller
'id' => (string) $account->id,
'name' => $account->name,
'name_with_balance' => $nameWithBalance,
+ 'active' => $account->active,
'type' => $account->accountType->type,
'currency_id' => (string) $useCurrency->id,
'currency_name' => $useCurrency->name,
diff --git a/app/Api/V1/Controllers/Autocomplete/BudgetController.php b/app/Api/V1/Controllers/Autocomplete/BudgetController.php
index 3fd273d329..f64500bf38 100644
--- a/app/Api/V1/Controllers/Autocomplete/BudgetController.php
+++ b/app/Api/V1/Controllers/Autocomplete/BudgetController.php
@@ -69,6 +69,7 @@ class BudgetController extends Controller
static fn (Budget $item) => [
'id' => (string) $item->id,
'name' => $item->name,
+ 'active' => $item->active,
]
);
diff --git a/app/Http/Controllers/Transaction/ConvertController.php b/app/Http/Controllers/Transaction/ConvertController.php
index 8f24176f59..e0a6229231 100644
--- a/app/Http/Controllers/Transaction/ConvertController.php
+++ b/app/Http/Controllers/Transaction/ConvertController.php
@@ -337,6 +337,9 @@ class ConvertController extends Controller
'type' => $transactionType->type,
];
+ $sourceTransaction = $journal->transactions()->where('amount', '<', 0)->first();
+ $amount = $sourceTransaction?->amount ?? '0';
+
// also set the currency to the currency of the source account, in case you're converting a deposit into a transfer.
if (TransactionTypeEnum::TRANSFER->value === $transactionType->type && TransactionTypeEnum::DEPOSIT->value === $journal->transactionType->type) {
$source = $this->accountRepository->find((int) $sourceId);
@@ -346,7 +349,20 @@ class ConvertController extends Controller
if ($sourceCurrency instanceof TransactionCurrency && $destCurrency instanceof TransactionCurrency && $sourceCurrency->code !== $destCurrency->code) {
$update['currency_id'] = $sourceCurrency->id;
$update['foreign_currency_id'] = $destCurrency->id;
- $update['foreign_amount'] = '1'; // not the best solution but at this point the amount is hard to get.
+ $update['foreign_amount'] = Steam::positive($amount); // not the best solution but at this point the amount is hard to get.
+ }
+ }
+
+ // same thing for converting a withdrawal into a transfer, but with the currency of the destination account.
+ if (TransactionTypeEnum::TRANSFER->value === $transactionType->type && TransactionTypeEnum::WITHDRAWAL->value === $journal->transactionType->type) {
+ $source = $this->accountRepository->find((int) $sourceId);
+ $sourceCurrency = $this->accountRepository->getAccountCurrency($source);
+ $dest = $this->accountRepository->find((int) $destinationId);
+ $destCurrency = $this->accountRepository->getAccountCurrency($dest);
+ if ($sourceCurrency instanceof TransactionCurrency && $destCurrency instanceof TransactionCurrency && $sourceCurrency->code !== $destCurrency->code) {
+ $update['currency_id'] = $sourceCurrency->id;
+ $update['foreign_currency_id'] = $destCurrency->id;
+ $update['foreign_amount'] = Steam::positive($amount); // not the best solution but at this point the amount is hard to get.
}
}
diff --git a/changelog.md b/changelog.md
index 33c6b58bbf..989f8cc33a 100644
--- a/changelog.md
+++ b/changelog.md
@@ -27,6 +27,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
- [Issue 10813](https://github.com/firefly-iii/firefly-iii/issues/10813) (Error "Argument #2 ($symbol) must be of type string" while try open subscriptions section) reported by @mrResident
- #10819
- #10820
+- #10824
### API
diff --git a/routes/api.php b/routes/api.php
index be21f9248c..64775c9b77 100644
--- a/routes/api.php
+++ b/routes/api.php
@@ -48,6 +48,7 @@ Route::group(
// Auto complete routes
Route::get('accounts', ['uses' => 'AccountController@accounts', 'as' => 'accounts']);
Route::get('bills', ['uses' => 'BillController@bills', 'as' => 'bills']);
+ Route::get('subscriptions', ['uses' => 'BillController@bills', 'as' => 'subscriptions']);
Route::get('budgets', ['uses' => 'BudgetController@budgets', 'as' => 'budgets']);
Route::get('categories', ['uses' => 'CategoryController@categories', 'as' => 'categories']);
Route::get('currencies', ['uses' => 'CurrencyController@currencies', 'as' => 'currencies']);