Fix historical crypto settlement calculations
All checks were successful
Deploy / deploy-staging (push) Successful in 34s
Deploy / deploy-production (push) Has been skipped

This commit is contained in:
2026-09-13 00:18:43 +02:00
parent 72b7202a8a
commit d0dd38823d
7 changed files with 121 additions and 14 deletions

View File

@@ -386,6 +386,42 @@ final class FxRatesRepository
}
}
public function replaceFetchRates(int $fetchId, array $rates): void
{
if ($fetchId <= 0) {
return;
}
$normalizedRates = [];
foreach ($rates as $currencyCode => $rate) {
$currencyCode = strtoupper(trim((string) $currencyCode));
if ($currencyCode !== '' && is_numeric($rate) && (float) $rate > 0) {
$normalizedRates[$currencyCode] = (float) $rate;
}
}
$this->pdo->prepare('DELETE FROM ' . $this->table('rates') . ' WHERE fetch_id = :fetch_id')
->execute(['fetch_id' => $fetchId]);
if ($normalizedRates === []) {
return;
}
$placeholders = [];
$params = ['fetch_id' => $fetchId];
$index = 0;
foreach ($normalizedRates as $currencyCode => $rate) {
$codeKey = 'currency_code_' . $index;
$valueKey = 'current_value_' . $index;
$placeholders[] = "(:fetch_id, :{$codeKey}, :{$valueKey})";
$params[$codeKey] = $currencyCode;
$params[$valueKey] = $rate;
$index++;
}
$this->pdo->prepare(
'INSERT INTO ' . $this->table('rates') . ' (fetch_id, currency_code, current_value) VALUES ' . implode(', ', $placeholders)
)->execute($params);
}
public function findFetchByBaseAndFetchedAt(string $baseCurrency, string $fetchedAt): ?array
{
$baseCurrency = strtoupper(trim($baseCurrency));