Fix historical crypto settlement calculations
This commit is contained in:
@@ -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));
|
||||
|
||||
Reference in New Issue
Block a user