mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2026-04-18 20:39:39 +00:00
Compare commits
No commits in common. "07172392963fa54e64f6ae0d7fa9b4b4bd75db79" and "a6be786d5dd12dcb58d8c5e65e0804da454142ad" have entirely different histories.
0717239296
...
a6be786d5d
5 changed files with 309 additions and 387 deletions
|
|
@ -25,7 +25,8 @@
|
||||||
"doctrine/doctrine-migrations-bundle": "^3.0",
|
"doctrine/doctrine-migrations-bundle": "^3.0",
|
||||||
"doctrine/orm": "^3.2.0",
|
"doctrine/orm": "^3.2.0",
|
||||||
"dompdf/dompdf": "^v3.0.0",
|
"dompdf/dompdf": "^v3.0.0",
|
||||||
"part-db/swap-bundle": "^6.0.0",
|
"florianv/swap": "^4.0",
|
||||||
|
"florianv/swap-bundle": "dev-master",
|
||||||
"gregwar/captcha-bundle": "^2.1.0",
|
"gregwar/captcha-bundle": "^2.1.0",
|
||||||
"hshn/base64-encoded-file": "^5.0",
|
"hshn/base64-encoded-file": "^5.0",
|
||||||
"jbtronics/2fa-webauthn": "^3.0.0",
|
"jbtronics/2fa-webauthn": "^3.0.0",
|
||||||
|
|
|
||||||
650
composer.lock
generated
650
composer.lock
generated
File diff suppressed because it is too large
Load diff
|
|
@ -5,9 +5,6 @@ florianv_swap:
|
||||||
|
|
||||||
providers:
|
providers:
|
||||||
european_central_bank: ~ # European Central Bank (only works for EUR base currency)
|
european_central_bank: ~ # European Central Bank (only works for EUR base currency)
|
||||||
central_bank_of_czech_republic: ~
|
fixer: # Fixer.io (needs an API key)
|
||||||
central_bank_of_republic_turkey: ~
|
access_key: "%env(string:default:settings:exchange_rate:fixerApiKey:INVALID)%"
|
||||||
national_bank_of_romania: ~
|
#exchange_rates_api: ~
|
||||||
|
|
||||||
fixer: # Fixer.io (needs an API key)
|
|
||||||
access_key: "%env(string:settings:exchange_rate:fixerApiKey)%"
|
|
||||||
|
|
@ -26,8 +26,6 @@ use App\Entity\PriceInformations\Currency;
|
||||||
use App\Settings\SystemSettings\LocalizationSettings;
|
use App\Settings\SystemSettings\LocalizationSettings;
|
||||||
use Brick\Math\BigDecimal;
|
use Brick\Math\BigDecimal;
|
||||||
use Brick\Math\RoundingMode;
|
use Brick\Math\RoundingMode;
|
||||||
use Exchanger\Exception\UnsupportedCurrencyPairException;
|
|
||||||
use Exchanger\Exception\UnsupportedExchangeQueryException;
|
|
||||||
use Swap\Swap;
|
use Swap\Swap;
|
||||||
|
|
||||||
class ExchangeRateUpdater
|
class ExchangeRateUpdater
|
||||||
|
|
@ -41,21 +39,15 @@ class ExchangeRateUpdater
|
||||||
*/
|
*/
|
||||||
public function update(Currency $currency): Currency
|
public function update(Currency $currency): Currency
|
||||||
{
|
{
|
||||||
try {
|
//Currency pairs are always in the format "BASE/QUOTE"
|
||||||
//Try it in the direction QUOTE/BASE first, as most providers provide rates in this direction
|
$rate = $this->swap->latest($this->localizationSettings->baseCurrency.'/'.$currency->getIsoCode());
|
||||||
$rate = $this->swap->latest($currency->getIsoCode().'/'.$this->localizationSettings->baseCurrency);
|
//The rate says how many quote units are worth one base unit
|
||||||
$effective_rate = BigDecimal::of($rate->getValue());
|
//So we need to invert it to get the exchange rate
|
||||||
} catch (UnsupportedCurrencyPairException|UnsupportedExchangeQueryException $exception) {
|
|
||||||
//Otherwise try to get it inverse and calculate it ourselfes, from the format "BASE/QUOTE"
|
|
||||||
$rate = $this->swap->latest($this->localizationSettings->baseCurrency.'/'.$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_bd = BigDecimal::of($rate->getValue());
|
||||||
$effective_rate = BigDecimal::one()->dividedBy($rate_bd, Currency::PRICE_SCALE, RoundingMode::HALF_UP);
|
$rate_inverted = BigDecimal::one()->dividedBy($rate_bd, Currency::PRICE_SCALE, RoundingMode::HALF_UP);
|
||||||
}
|
|
||||||
|
|
||||||
$currency->setExchangeRate($effective_rate);
|
$currency->setExchangeRate($rate_inverted);
|
||||||
|
|
||||||
return $currency;
|
return $currency;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
12
symfony.lock
12
symfony.lock
|
|
@ -133,6 +133,15 @@
|
||||||
"ekino/phpstan-banned-code": {
|
"ekino/phpstan-banned-code": {
|
||||||
"version": "v0.3.1"
|
"version": "v0.3.1"
|
||||||
},
|
},
|
||||||
|
"florianv/exchanger": {
|
||||||
|
"version": "1.4.1"
|
||||||
|
},
|
||||||
|
"florianv/swap": {
|
||||||
|
"version": "3.5.0"
|
||||||
|
},
|
||||||
|
"florianv/swap-bundle": {
|
||||||
|
"version": "5.0.x-dev"
|
||||||
|
},
|
||||||
"gregwar/captcha": {
|
"gregwar/captcha": {
|
||||||
"version": "v1.1.7"
|
"version": "v1.1.7"
|
||||||
},
|
},
|
||||||
|
|
@ -245,9 +254,6 @@
|
||||||
"./config/packages/datatables.yaml"
|
"./config/packages/datatables.yaml"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"part-db/swap-bundle": {
|
|
||||||
"version": "v6.0.0"
|
|
||||||
},
|
|
||||||
"php-http/discovery": {
|
"php-http/discovery": {
|
||||||
"version": "1.18",
|
"version": "1.18",
|
||||||
"recipe": {
|
"recipe": {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue