Make sure integers are converted to strings because sqlite sucks.

This commit is contained in:
James Cole 2024-12-29 06:32:50 +01:00
parent 9a9dd9e075
commit 3c20e5f3af
No known key found for this signature in database
GPG Key ID: B49A324B7EAD6D80
11 changed files with 21 additions and 14 deletions

View File

@ -74,7 +74,7 @@ class CorrectsDatabase extends Command
'correction:recalculates-liabilities', 'correction:recalculates-liabilities',
'correction:preferences', 'correction:preferences',
// 'correction:transaction-types', // resource heavy, disabled. // 'correction:transaction-types', // resource heavy, disabled.
// 'correction:recalculate-native-amounts', // not necessary, disabled. 'correction:recalculate-native-amounts', // not necessary, disabled.
'firefly-iii:report-integrity', 'firefly-iii:report-integrity',
]; ];
foreach ($commands as $command) { foreach ($commands as $command) {

View File

@ -160,8 +160,8 @@ class DebugController extends Controller
Artisan::call('view:clear'); Artisan::call('view:clear');
// also do some recalculations. // also do some recalculations.
Artisan::call('firefly-iii:trigger-credit-recalculation'); Artisan::call('correction:recalculates-liabilities');
AccountBalanceCalculator::recalculateAll(true); AccountBalanceCalculator::recalculateAll(false);
try { try {
Artisan::call('twig:clean'); Artisan::call('twig:clean');

View File

@ -57,6 +57,7 @@ class Account extends Model
'active' => 'boolean', 'active' => 'boolean',
'encrypted' => 'boolean', 'encrypted' => 'boolean',
'virtual_balance' => 'string', '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']; protected $fillable = ['user_id', 'user_group_id', 'account_type_id', 'name', 'active', 'virtual_balance', 'iban', 'native_virtual_balance'];

View File

@ -38,19 +38,20 @@ class AutoBudget extends Model
use ReturnsIntegerIdTrait; use ReturnsIntegerIdTrait;
use SoftDeletes; use SoftDeletes;
#[\Deprecated] #[\Deprecated] /** @deprecated */
public const int AUTO_BUDGET_ADJUSTED = 3; public const int AUTO_BUDGET_ADJUSTED = 3;
#[\Deprecated] #[\Deprecated] /** @deprecated */
public const int AUTO_BUDGET_RESET = 1; public const int AUTO_BUDGET_RESET = 1;
#[\Deprecated] #[\Deprecated] /** @deprecated */
public const int AUTO_BUDGET_ROLLOVER = 2; public const int AUTO_BUDGET_ROLLOVER = 2;
protected $casts protected $casts
= [ = [
'amount' => 'string', 'amount' => 'string',
'native_amount' => 'string',
]; ];
protected $fillable = ['budget_id', 'amount', 'period']; protected $fillable = ['budget_id', 'amount', 'period','native_amount'];
public function budget(): BelongsTo public function budget(): BelongsTo
{ {

View File

@ -50,9 +50,10 @@ class AvailableBudget extends Model
'end_date' => 'date', 'end_date' => 'date',
'transaction_currency_id' => 'int', 'transaction_currency_id' => 'int',
'amount' => 'string', '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). * Route binder. Converts the key in the URL to the specified object (or throw 404).

View File

@ -49,6 +49,7 @@ class BudgetLimit extends Model
'end_date' => SeparateTimezoneCaster::class, 'end_date' => SeparateTimezoneCaster::class,
'auto_budget' => 'boolean', 'auto_budget' => 'boolean',
'amount' => 'string', 'amount' => 'string',
'native_amount' => 'string',
]; ];
protected $dispatchesEvents protected $dispatchesEvents
= [ = [

View File

@ -53,9 +53,10 @@ class PiggyBank extends Model
'active' => 'boolean', 'active' => 'boolean',
'encrypted' => 'boolean', 'encrypted' => 'boolean',
'target_amount' => 'string', '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). * Route binder. Converts the key in the URL to the specified object (or throw 404).

View File

@ -42,9 +42,10 @@ class PiggyBankEvent extends Model
'updated_at' => 'datetime', 'updated_at' => 'datetime',
'date' => SeparateTimezoneCaster::class, 'date' => SeparateTimezoneCaster::class,
'amount' => 'string', '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']; protected $hidden = ['amount_encrypted'];

View File

@ -586,7 +586,7 @@ class BillRepository implements BillRepositoryInterface
$minField = $convertToNative && $bill->transactionCurrency->id !== $default->id ? 'native_amount_min' : 'amount_min'; $minField = $convertToNative && $bill->transactionCurrency->id !== $default->id ? 'native_amount_min' : 'amount_min';
$maxField = $convertToNative && $bill->transactionCurrency->id !== $default->id ? 'native_amount_max' : 'amount_max'; $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) { if ($total > 0) {
$currency = $convertToNative && $bill->transactionCurrency->id !== $default->id ? $default : $bill->transactionCurrency; $currency = $convertToNative && $bill->transactionCurrency->id !== $default->id ? $default : $bill->transactionCurrency;

View File

@ -65,7 +65,7 @@ class Amount
// Log::debug(sprintf('Overruled, amount is now %s', $amount)); // Log::debug(sprintf('Overruled, amount is now %s', $amount));
} }
return $amount; return (string) $amount;
} }
public function convertToNative(?User $user = null): bool public function convertToNative(?User $user = null): bool

View File

@ -198,8 +198,10 @@ class FrontpageChartGenerator
} }
$useNative = $this->convertToNative && $this->default->id !== $limit->transaction_currency_id; $useNative = $this->convertToNative && $this->default->id !== $limit->transaction_currency_id;
$amount = $limit->amount; $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; $amount = $limit->native_amount;
Log::debug(sprintf('Amount is now "%s".', $amount));
} }
@ -208,7 +210,6 @@ class FrontpageChartGenerator
$data[1]['entries'][$title] ??= '0'; $data[1]['entries'][$title] ??= '0';
$data[2]['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[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[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 $data[2]['entries'][$title] = bcadd($data[2]['entries'][$title], 1 === bccomp($amount, $sumSpent) ? '0' : bcmul(bcadd($entry['sum'], $amount), '-1')); // overspent