Moved default language, default timezone and base currency settings to new settings system

This commit is contained in:
Jan Böhmer 2024-08-03 23:14:29 +02:00
parent 463812fb3d
commit 2ab2b7f77d
27 changed files with 211 additions and 83 deletions

View file

@ -23,6 +23,7 @@ declare(strict_types=1);
namespace App\Services\Formatters;
use App\Entity\PriceInformations\Currency;
use App\Settings\SystemSettings\LocalizationSettings;
use Locale;
use NumberFormatter;
@ -30,7 +31,7 @@ class MoneyFormatter
{
protected string $locale;
public function __construct(protected string $base_currency)
public function __construct(private readonly LocalizationSettings $localizationSettings)
{
$this->locale = Locale::getDefault();
}
@ -45,7 +46,7 @@ class MoneyFormatter
*/
public function format(string|float $value, ?Currency $currency = null, int $decimals = 5, bool $show_all_digits = false): string
{
$iso_code = $this->base_currency;
$iso_code = $this->localizationSettings->baseCurrency;
if ($currency instanceof Currency && ($currency->getIsoCode() !== null && $currency->getIsoCode() !== '')) {
$iso_code = $currency->getIsoCode();
}

View file

@ -35,6 +35,7 @@ use App\Entity\Parts\Supplier;
use App\Entity\PriceInformations\Currency;
use App\Entity\PriceInformations\Orderdetail;
use App\Entity\PriceInformations\Pricedetail;
use App\Settings\SystemSettings\LocalizationSettings;
use Brick\Math\BigDecimal;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\Intl\Currencies;
@ -47,7 +48,7 @@ class PKPartImporter
{
use PKImportHelperTrait;
public function __construct(EntityManagerInterface $em, PropertyAccessorInterface $propertyAccessor, private readonly string $base_currency)
public function __construct(EntityManagerInterface $em, PropertyAccessorInterface $propertyAccessor, private readonly LocalizationSettings $localizationSettings)
{
$this->em = $em;
$this->propertyAccessor = $propertyAccessor;
@ -210,7 +211,7 @@ class PKPartImporter
$currency_iso_code = strtoupper($currency_iso_code);
//We do not have a currency for the base currency to be consistent with prices without currencies
if ($currency_iso_code === $this->base_currency) {
if ($currency_iso_code === $this->localizationSettings->baseCurrency) {
return null;
}

View file

@ -41,6 +41,7 @@ use App\Services\InfoProviderSystem\DTOs\ParameterDTO;
use App\Services\InfoProviderSystem\DTOs\PartDetailDTO;
use App\Services\InfoProviderSystem\DTOs\PriceDTO;
use App\Services\InfoProviderSystem\DTOs\PurchaseInfoDTO;
use App\Settings\SystemSettings\LocalizationSettings;
use Doctrine\ORM\EntityManagerInterface;
/**
@ -52,8 +53,11 @@ final class DTOtoEntityConverter
private const TYPE_DATASHEETS_NAME = 'Datasheet';
private const TYPE_IMAGE_NAME = 'Image';
public function __construct(private readonly EntityManagerInterface $em, private readonly string $base_currency)
private readonly string $base_currency;
public function __construct(private readonly EntityManagerInterface $em, LocalizationSettings $localizationSettings)
{
$this->base_currency = $localizationSettings->baseCurrency;
}
/**

View file

@ -25,6 +25,7 @@ namespace App\Services\Parts;
use App\Entity\Parts\Part;
use App\Entity\PriceInformations\Currency;
use App\Entity\PriceInformations\Pricedetail;
use App\Settings\SystemSettings\LocalizationSettings;
use Brick\Math\BigDecimal;
use Brick\Math\RoundingMode;
use Doctrine\ORM\PersistentCollection;
@ -39,7 +40,7 @@ class PricedetailHelper
{
protected string $locale;
public function __construct(protected string $base_currency)
public function __construct()
{
$this->locale = Locale::getDefault();
}

View file

@ -23,13 +23,14 @@ declare(strict_types=1);
namespace App\Services\Tools;
use App\Entity\PriceInformations\Currency;
use App\Settings\SystemSettings\LocalizationSettings;
use Brick\Math\BigDecimal;
use Brick\Math\RoundingMode;
use Swap\Swap;
class ExchangeRateUpdater
{
public function __construct(private readonly string $base_currency, private readonly Swap $swap)
public function __construct(private LocalizationSettings $localizationSettings, private readonly Swap $swap)
{
}
@ -39,7 +40,7 @@ class ExchangeRateUpdater
public function update(Currency $currency): Currency
{
//Currency pairs are always in the format "BASE/QUOTE"
$rate = $this->swap->latest($this->base_currency.'/'.$currency->getIsoCode());
$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