mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-07-12 19:34:31 +02:00
Added a button to update exchange rates via web gui.
This commit is contained in:
parent
ff7c1cddc7
commit
af42c3cca0
11 changed files with 1137 additions and 909 deletions
34
src/Services/ExchangeRateUpdater.php
Normal file
34
src/Services/ExchangeRateUpdater.php
Normal file
|
@ -0,0 +1,34 @@
|
|||
<?php
|
||||
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
|
||||
use App\Entity\PriceInformations\Currency;
|
||||
use Brick\Math\BigDecimal;
|
||||
use Swap\Swap;
|
||||
|
||||
class ExchangeRateUpdater
|
||||
{
|
||||
private $base_currency;
|
||||
private $swap;
|
||||
|
||||
public function __construct(string $base_currency, Swap $swap)
|
||||
{
|
||||
$this->base_currency = $base_currency;
|
||||
$this->swap = $swap;
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the exchange rate of the given currency using the globally configured providers.
|
||||
* @param Currency $currency
|
||||
* @return Currency
|
||||
*/
|
||||
public function update(Currency $currency): Currency
|
||||
{
|
||||
$rate = $this->swap->latest($currency->getIsoCode().'/'.$this->base_currency);
|
||||
$currency->setExchangeRate(BigDecimal::of($rate->getValue()));
|
||||
return $currency;
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue