Skip to content

Firefly III: a personal finances manager

Extra fix to cover for #1091

James Colecdeabaaf9aff
diff --git a/app/Console/Commands/UpgradeDatabase.php b/app/Console/Commands/UpgradeDatabase.php
index 372b9a19ac..9fee614b95 100644
--- a/app/Console/Commands/UpgradeDatabase.php
+++ b/app/Console/Commands/UpgradeDatabase.php
@@ -146,6 +146,7 @@ class UpgradeDatabase extends Command
// both 0? set to default currency:
if (0 === $accountCurrency && 0 === $obCurrency) {
+ AccountMeta::where('account_id', $account->id)->where('name', 'currency_id')->forceDelete();
AccountMeta::create(['account_id' => $account->id, 'name' => 'currency_id', 'data' => $defaultCurrency->id]);
$this->line(sprintf('Account #%d ("%s") now has a currency setting (%s).', $account->id, $account->name, $defaultCurrencyCode));
@@ -508,11 +509,13 @@ class UpgradeDatabase extends Command
*
* @return string
*/
- private function var_dump_ret($mixed = null): string {
+ private function var_dump_ret($mixed = null): string
+ {
ob_start();
var_dump($mixed);
$content = ob_get_contents();
ob_end_clean();
+
return $content;
}
diff --git a/app/Http/Requests/JournalFormRequest.php b/app/Http/Requests/JournalFormRequest.php
index 10396f5e50..f23dcdd650 100644
--- a/app/Http/Requests/JournalFormRequest.php
+++ b/app/Http/Requests/JournalFormRequest.php
@@ -91,33 +91,33 @@ class JournalFormRequest extends Request
{
$what = $this->get('what');
$rules = [
- 'what' => 'required|in:withdrawal,deposit,transfer',
- 'date' => 'required|date',
-
+ 'what' => 'required|in:withdrawal,deposit,transfer',
+ 'date' => 'required|date',
+ 'amount_currency_id_amount' => 'exists:transaction_currencies,id|required',
// then, custom fields:
- 'interest_date' => 'date|nullable',
- 'book_date' => 'date|nullable',
- 'process_date' => 'date|nullable',
- 'due_date' => 'date|nullable',
- 'payment_date' => 'date|nullable',
- 'invoice_date' => 'date|nullable',
- 'internal_reference' => 'min:1,max:255|nullable',
- 'notes' => 'min:1,max:50000|nullable',
+ 'interest_date' => 'date|nullable',
+ 'book_date' => 'date|nullable',
+ 'process_date' => 'date|nullable',
+ 'due_date' => 'date|nullable',
+ 'payment_date' => 'date|nullable',
+ 'invoice_date' => 'date|nullable',
+ 'internal_reference' => 'min:1,max:255|nullable',
+ 'notes' => 'min:1,max:50000|nullable',
// and then transaction rules:
- 'description' => 'required|between:1,255',
- 'amount' => 'numeric|required|more:0',
- 'budget_id' => 'mustExist:budgets,id|belongsToUser:budgets,id|nullable',
- 'category' => 'between:1,255|nullable',
- 'source_account_id' => 'numeric|belongsToUser:accounts,id|nullable',
- 'source_account_name' => 'between:1,255|nullable',
- 'destination_account_id' => 'numeric|belongsToUser:accounts,id|nullable',
- 'destination_account_name' => 'between:1,255|nullable',
- 'piggy_bank_id' => 'between:1,255|nullable',
+ 'description' => 'required|between:1,255',
+ 'amount' => 'numeric|required|more:0',
+ 'budget_id' => 'mustExist:budgets,id|belongsToUser:budgets,id|nullable',
+ 'category' => 'between:1,255|nullable',
+ 'source_account_id' => 'numeric|belongsToUser:accounts,id|nullable',
+ 'source_account_name' => 'between:1,255|nullable',
+ 'destination_account_id' => 'numeric|belongsToUser:accounts,id|nullable',
+ 'destination_account_name' => 'between:1,255|nullable',
+ 'piggy_bank_id' => 'between:1,255|nullable',
// foreign currency amounts
- 'native_amount' => 'numeric|more:0|nullable',
- 'source_amount' => 'numeric|more:0|nullable',
- 'destination_amount' => 'numeric|more:0|nullable',
+ 'native_amount' => 'numeric|more:0|nullable',
+ 'source_amount' => 'numeric|more:0|nullable',
+ 'destination_amount' => 'numeric|more:0|nullable',
];
// some rules get an upgrade depending on the type of data:
diff --git a/app/Repositories/Journal/SupportJournalsTrait.php b/app/Repositories/Journal/SupportJournalsTrait.php
index fd856d9b56..5815cc8a4f 100644
--- a/app/Repositories/Journal/SupportJournalsTrait.php
+++ b/app/Repositories/Journal/SupportJournalsTrait.php
@@ -249,6 +249,10 @@ trait SupportJournalsTrait
case TransactionType::WITHDRAWAL:
// continue:
$nativeCurrencyId = intval($accounts[$check]->getMeta('currency_id'));
+ if ($nativeCurrencyId === 0) {
+ // fall back to given ID (not everybody upgrades nicely).
+ $nativeCurrencyId = $submittedCurrencyId;
+ }
// does not match? Then user has submitted amount in a foreign currency:
if ($nativeCurrencyId !== $submittedCurrencyId) {
diff --git a/app/Support/Steam.php b/app/Support/Steam.php
index b971028029..989801716a 100644
--- a/app/Support/Steam.php
+++ b/app/Support/Steam.php
@@ -72,6 +72,7 @@ class Steam
->leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id')
->where('transaction_journals.date', '<=', $date->format('Y-m-d'))
->where('transactions.foreign_currency_id', $currencyId)
+ ->where('transactions.transaction_currency_id', '!=', $currencyId)
->sum('transactions.foreign_amount')
);
$balance = bcadd($nativeBalance, $foreignBalance);
@@ -114,6 +115,7 @@ class Steam
->leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id')
->where('transaction_journals.date', '<=', $date->format('Y-m-d'))
->where('transactions.foreign_currency_id', $currencyId)
+ ->where('transactions.transaction_currency_id', '!=', $currencyId)
->sum('transactions.foreign_amount')
);
$balance = bcadd($nativeBalance, $foreignBalance);