From 3c20e5f3af0e8446ae7929abf07d44a5f9677a8e Mon Sep 17 00:00:00 2001 From: James Cole Date: Sun, 29 Dec 2024 06:32:50 +0100 Subject: [PATCH] Make sure integers are converted to strings because sqlite sucks. --- app/Console/Commands/Correction/CorrectsDatabase.php | 2 +- app/Http/Controllers/DebugController.php | 4 ++-- app/Models/Account.php | 1 + app/Models/AutoBudget.php | 9 +++++---- app/Models/AvailableBudget.php | 3 ++- app/Models/BudgetLimit.php | 1 + app/Models/PiggyBank.php | 3 ++- app/Models/PiggyBankEvent.php | 3 ++- app/Repositories/Bill/BillRepository.php | 2 +- app/Support/Amount.php | 2 +- app/Support/Chart/Budget/FrontpageChartGenerator.php | 5 +++-- 11 files changed, 21 insertions(+), 14 deletions(-) diff --git a/app/Console/Commands/Correction/CorrectsDatabase.php b/app/Console/Commands/Correction/CorrectsDatabase.php index 4e03e756f1..1d9ea62112 100644 --- a/app/Console/Commands/Correction/CorrectsDatabase.php +++ b/app/Console/Commands/Correction/CorrectsDatabase.php @@ -74,7 +74,7 @@ class CorrectsDatabase extends Command 'correction:recalculates-liabilities', 'correction:preferences', // 'correction:transaction-types', // resource heavy, disabled. - // 'correction:recalculate-native-amounts', // not necessary, disabled. + 'correction:recalculate-native-amounts', // not necessary, disabled. 'firefly-iii:report-integrity', ]; foreach ($commands as $command) { diff --git a/app/Http/Controllers/DebugController.php b/app/Http/Controllers/DebugController.php index 510a4ca910..db80fd18b4 100644 --- a/app/Http/Controllers/DebugController.php +++ b/app/Http/Controllers/DebugController.php @@ -160,8 +160,8 @@ class DebugController extends Controller Artisan::call('view:clear'); // also do some recalculations. - Artisan::call('firefly-iii:trigger-credit-recalculation'); - AccountBalanceCalculator::recalculateAll(true); + Artisan::call('correction:recalculates-liabilities'); + AccountBalanceCalculator::recalculateAll(false); try { Artisan::call('twig:clean'); diff --git a/app/Models/Account.php b/app/Models/Account.php index dbe1dd9388..03d87fc708 100644 --- a/app/Models/Account.php +++ b/app/Models/Account.php @@ -57,6 +57,7 @@ class Account extends Model 'active' => 'boolean', 'encrypted' => 'boolean', 'virtual_balance' => 'string', + 'native_virtual_balance' => 'string', ]; protected $fillable = ['user_id', 'user_group_id', 'account_type_id', 'name', 'active', 'virtual_balance', 'iban', 'native_virtual_balance']; diff --git a/app/Models/AutoBudget.php b/app/Models/AutoBudget.php index 5adcd34e4d..a2d475c176 100644 --- a/app/Models/AutoBudget.php +++ b/app/Models/AutoBudget.php @@ -38,19 +38,20 @@ class AutoBudget extends Model use ReturnsIntegerIdTrait; use SoftDeletes; - #[\Deprecated] + #[\Deprecated] /** @deprecated */ public const int AUTO_BUDGET_ADJUSTED = 3; - #[\Deprecated] + #[\Deprecated] /** @deprecated */ public const int AUTO_BUDGET_RESET = 1; - #[\Deprecated] + #[\Deprecated] /** @deprecated */ public const int AUTO_BUDGET_ROLLOVER = 2; protected $casts = [ 'amount' => 'string', + 'native_amount' => 'string', ]; - protected $fillable = ['budget_id', 'amount', 'period']; + protected $fillable = ['budget_id', 'amount', 'period','native_amount']; public function budget(): BelongsTo { diff --git a/app/Models/AvailableBudget.php b/app/Models/AvailableBudget.php index d2b8abc7a1..eef99656af 100644 --- a/app/Models/AvailableBudget.php +++ b/app/Models/AvailableBudget.php @@ -50,9 +50,10 @@ class AvailableBudget extends Model 'end_date' => 'date', 'transaction_currency_id' => 'int', 'amount' => 'string', + 'native_amount' => 'string', ]; - protected $fillable = ['user_id', 'user_group_id', 'transaction_currency_id', 'amount', 'start_date', 'end_date', 'start_date_tz', 'end_date_tz']; + protected $fillable = ['user_id', 'user_group_id', 'transaction_currency_id', 'amount', 'start_date', 'end_date', 'start_date_tz', 'end_date_tz','native_amount']; /** * Route binder. Converts the key in the URL to the specified object (or throw 404). diff --git a/app/Models/BudgetLimit.php b/app/Models/BudgetLimit.php index 8e69f95d15..b2a652db14 100644 --- a/app/Models/BudgetLimit.php +++ b/app/Models/BudgetLimit.php @@ -49,6 +49,7 @@ class BudgetLimit extends Model 'end_date' => SeparateTimezoneCaster::class, 'auto_budget' => 'boolean', 'amount' => 'string', + 'native_amount' => 'string', ]; protected $dispatchesEvents = [ diff --git a/app/Models/PiggyBank.php b/app/Models/PiggyBank.php index 7ffa94029d..58c9a25697 100644 --- a/app/Models/PiggyBank.php +++ b/app/Models/PiggyBank.php @@ -53,9 +53,10 @@ class PiggyBank extends Model 'active' => 'boolean', 'encrypted' => 'boolean', 'target_amount' => 'string', + 'native_target_amount' => 'string', ]; - protected $fillable = ['name', 'order', 'target_amount', 'start_date', 'start_date_tz', 'target_date', 'target_date_tz', 'active', 'transaction_currency_id']; + protected $fillable = ['name', 'order', 'target_amount', 'start_date', 'start_date_tz', 'target_date', 'target_date_tz', 'active', 'transaction_currency_id','native_target_amount']; /** * Route binder. Converts the key in the URL to the specified object (or throw 404). diff --git a/app/Models/PiggyBankEvent.php b/app/Models/PiggyBankEvent.php index 41df8cb704..059768e70b 100644 --- a/app/Models/PiggyBankEvent.php +++ b/app/Models/PiggyBankEvent.php @@ -42,9 +42,10 @@ class PiggyBankEvent extends Model 'updated_at' => 'datetime', 'date' => SeparateTimezoneCaster::class, 'amount' => 'string', + 'amount' => 'native_string', ]; - protected $fillable = ['piggy_bank_id', 'transaction_journal_id', 'date', 'date_tz', 'amount']; + protected $fillable = ['piggy_bank_id', 'transaction_journal_id', 'date', 'date_tz', 'amount','native_amount']; protected $hidden = ['amount_encrypted']; diff --git a/app/Repositories/Bill/BillRepository.php b/app/Repositories/Bill/BillRepository.php index 5015776d3f..185fc700be 100644 --- a/app/Repositories/Bill/BillRepository.php +++ b/app/Repositories/Bill/BillRepository.php @@ -586,7 +586,7 @@ class BillRepository implements BillRepositoryInterface $minField = $convertToNative && $bill->transactionCurrency->id !== $default->id ? 'native_amount_min' : 'amount_min'; $maxField = $convertToNative && $bill->transactionCurrency->id !== $default->id ? 'native_amount_max' : 'amount_max'; - // Log::debug(sprintf('min field is %s, max field is %s', $minField, $maxField)); + Log::debug(sprintf('min field is %s, max field is %s', $minField, $maxField)); if ($total > 0) { $currency = $convertToNative && $bill->transactionCurrency->id !== $default->id ? $default : $bill->transactionCurrency; diff --git a/app/Support/Amount.php b/app/Support/Amount.php index 06a7659929..9d21ef4e67 100644 --- a/app/Support/Amount.php +++ b/app/Support/Amount.php @@ -65,7 +65,7 @@ class Amount // Log::debug(sprintf('Overruled, amount is now %s', $amount)); } - return $amount; + return (string) $amount; } public function convertToNative(?User $user = null): bool diff --git a/app/Support/Chart/Budget/FrontpageChartGenerator.php b/app/Support/Chart/Budget/FrontpageChartGenerator.php index 0481718c47..5c96be4488 100644 --- a/app/Support/Chart/Budget/FrontpageChartGenerator.php +++ b/app/Support/Chart/Budget/FrontpageChartGenerator.php @@ -198,8 +198,10 @@ class FrontpageChartGenerator } $useNative = $this->convertToNative && $this->default->id !== $limit->transaction_currency_id; $amount = $limit->amount; - if ($useNative) { + Log::debug(sprintf('Amount is "%s".', $amount)); + if ($useNative && $limit->transaction_currency_id !== $this->default->id) { $amount = $limit->native_amount; + Log::debug(sprintf('Amount is now "%s".', $amount)); } @@ -208,7 +210,6 @@ class FrontpageChartGenerator $data[1]['entries'][$title] ??= '0'; $data[2]['entries'][$title] ??= '0'; - $data[0]['entries'][$title] = bcadd($data[0]['entries'][$title], 1 === bccomp($sumSpent, $amount) ? $amount : $sumSpent); // spent $data[1]['entries'][$title] = bcadd($data[1]['entries'][$title], 1 === bccomp($amount, $sumSpent) ? bcadd($entry['sum'], $amount) : '0'); // left to spent $data[2]['entries'][$title] = bcadd($data[2]['entries'][$title], 1 === bccomp($amount, $sumSpent) ? '0' : bcmul(bcadd($entry['sum'], $amount), '-1')); // overspent