mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-07-10 02:14:31 +02:00
Really use euro as base currency when querying exchange rates, so we can use the configuration-free ECB provider
This should fixes issue #154.
This commit is contained in:
parent
2b2fc6f1e6
commit
7235cb72b4
4 changed files with 29 additions and 7 deletions
|
@ -22,6 +22,7 @@ namespace App\Services;
|
|||
|
||||
use App\Entity\PriceInformations\Currency;
|
||||
use Brick\Math\BigDecimal;
|
||||
use Brick\Math\RoundingMode;
|
||||
use Swap\Swap;
|
||||
|
||||
class ExchangeRateUpdater
|
||||
|
@ -40,8 +41,15 @@ class ExchangeRateUpdater
|
|||
*/
|
||||
public function update(Currency $currency): Currency
|
||||
{
|
||||
$rate = $this->swap->latest($currency->getIsoCode().'/'.$this->base_currency);
|
||||
$currency->setExchangeRate(BigDecimal::of($rate->getValue()));
|
||||
//Currency pairs are always in the format "BASE/QUOTE"
|
||||
$rate = $this->swap->latest($this->base_currency.'/'.$currency->getIsoCode());
|
||||
//The rate says how many quote units are worth one base unit
|
||||
//So we need to invert it to get the exchange rate
|
||||
|
||||
$rate_bd = BigDecimal::of($rate->getValue());
|
||||
$rate_inverted = BigDecimal::one()->dividedBy($rate_bd, Currency::PRICE_SCALE, RoundingMode::HALF_UP);
|
||||
|
||||
$currency->setExchangeRate($rate_inverted);
|
||||
|
||||
return $currency;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue