Skip to content
Code-Schnipsel Gruppen Projekte
Bestätigt Commit 39746eb2 erstellt von Henning Leutz's avatar Henning Leutz :martial_arts_uniform:
Dateien durchsuchen

feat: compatibility quiqqer v2

Übergeordneter b6575a2b
No related branches found
No related tags found
3 Merge Requests!45feat!: quiqqer v2,!44feat!: quiqqer v2,!43feat!: quiqqer v2
......@@ -14,7 +14,6 @@
$allowed = QUI\ERP\Currency\Handler::getAllowedCurrencies();
$result = [];
/* @var $Currency \QUI\ERP\Currency\Currency */
foreach ($allowed as $Currency) {
$result[] = $Currency->toArray();
}
......
......@@ -12,11 +12,10 @@
function ($currency) {
$allowed = QUI\ERP\Currency\Handler::getAllowedCurrencies();
$allowed = \array_map(function ($Currency) {
/* @var $Currency \QUI\ERP\Currency\Currency */
return $Currency->getCode();
}, $allowed);
$allowed = \array_flip($allowed);
$allowed = array_flip($allowed);
if (!isset($allowed[$currency])) {
return;
......
......@@ -9,6 +9,9 @@
*
* @return array
*/
use QUI\ERP\Currency\Handler;
QUI::$Ajax->registerFunction(
'package_quiqqer_currency_ajax_update',
function ($currency, $code, $rate, $precision, $type, $customData) {
......@@ -17,7 +20,7 @@ function ($currency, $code, $rate, $precision, $type, $customData) {
QUI\ERP\Currency\Handler::updateCurrency($currency, [
'rate' => $rate,
'code' => $code,
'type' => !empty($type) ? $type : \QUI\ERP\Currency\Handler::CURRENCY_TYPE_DEFAULT,
'type' => !empty($type) ? $type : Handler::CURRENCY_TYPE_DEFAULT,
'customData' => $customData
]);
......
......@@ -15,9 +15,10 @@
"email": "support@pcsg.de"
},
"require": {
"php": "^8.1",
"ext-intl": "*",
"quiqqer\/quiqqer": "*",
"quiqqer\/qui": ">=1|*@dev"
"quiqqer\/quiqqer": "^2",
"quiqqer\/qui": "^1|^2"
},
"autoload": {
"psr-4": {
......
......@@ -9,6 +9,8 @@
use NumberFormatter;
use QUI;
use QUI\Exception;
use function array_key_exists;
use function floatval;
use function is_array;
......@@ -35,27 +37,27 @@ abstract class AbstractCurrency implements CurrencyInterface
/**
* @var string
*/
protected $code;
protected string $code;
/**
* @var integer
*/
protected $precision = 2;
protected int $precision = 2;
/**
* @var float|bool
*/
protected $exchangeRate = false;
protected bool|float $exchangeRate = false;
/**
* @var int
*/
protected $autoupdate = 1;
protected mixed $autoupdate = 1;
/**
* @var QUI\Locale
* @var ?QUI\Locale
*/
protected $Locale;
protected ?QUI\Locale $Locale;
protected array $customData = [];
......@@ -104,7 +106,7 @@ public function __construct(array $data, $Locale = false)
*
* @param QUI\Locale $Locale
*/
public function setLocale(QUI\Locale $Locale)
public function setLocale(QUI\Locale $Locale): void
{
$this->Locale = $Locale;
}
......@@ -203,9 +205,8 @@ public function amount($amount, QUI\Locale $Locale = null): float
}
$amount = str_replace(',', '.', $amount);
$amount = floatval($amount);
return $amount;
return floatval($amount);
}
/**
......@@ -275,11 +276,11 @@ public function autoupdate(): bool
*
* @param float|string $amount
* @param string|CurrencyInterface $Currency
* @return float
* @return float|int|string
*
* @throws QUI\Exception
* @throws Exception
*/
public function convert($amount, $Currency)
public function convert($amount, $Currency): float|int|string
{
if (!is_numeric($amount)) {
QUI\System\Log::addError('Only numeric are allowed Currency->convert()', [
......@@ -347,7 +348,7 @@ public function convertFormat($amount, $Currency): string
* @param boolean|string|Currency $Currency - optional, default = false -> return own exchange rate
* @return float|boolean
*/
public function getExchangeRate($Currency = false)
public function getExchangeRate($Currency = false): float|bool
{
if ($Currency === false) {
return $this->exchangeRate;
......@@ -376,7 +377,7 @@ public function getExchangeRate($Currency = false)
*
* @param float|integer $rate
*/
public function setExchangeRate($rate)
public function setExchangeRate($rate): void
{
$this->exchangeRate = (float)$rate;
}
......@@ -408,7 +409,7 @@ public function getCustomData(): array
* @param $value
* @return void
*/
public function setCustomDataEntry(string $key, $value)
public function setCustomDataEntry(string $key, $value): void
{
$this->customData[$key] = $value;
}
......@@ -419,7 +420,7 @@ public function setCustomDataEntry(string $key, $value)
* @param string $key
* @return mixed
*/
public function getCustomDataEntry(string $key)
public function getCustomDataEntry(string $key): mixed
{
if (array_key_exists($key, $this->customData)) {
return $this->customData[$key];
......
......@@ -18,15 +18,18 @@ class Calc
/**
* Convert the amount from one to another currency
*
* @param float|string $amount
* @param string|Currency $currencyFrom - based currency
* @param string|Currency $currencyTo - optional, wanted currency, default = EUR
* @param float|int|string $amount
* @param string|array|Currency $currencyFrom - based currency
* @param array|string|Currency $currencyTo - optional, wanted currency, default = EUR
* @return float
*
* @throws QUI\Exception
*/
public static function convert($amount, $currencyFrom, $currencyTo = 'EUR'): float
{
public static function convert(
float|int|string $amount,
Currency|array|string $currencyFrom,
Currency|array|string $currencyTo = 'EUR'
): float {
$From = Handler::getCurrency($currencyFrom);
$To = Handler::getCurrency($currencyTo);
......@@ -36,16 +39,18 @@ public static function convert($amount, $currencyFrom, $currencyTo = 'EUR'): flo
/**
* Convert with currency sign
*
* @param float|string $amount
* @param string|Currency $currencyFrom - based currency
* @param string|Currency $currencyTo - optional, wanted currency, default = EUR
*
* @param float|int|string $amount
* @param array|string|Currency $currencyFrom - based currency
* @param array|string|Currency $currencyTo - optional, wanted currency, default = EUR
* @return string
*
* @throws QUI\Exception
*/
public static function convertWithSign($amount, $currencyFrom, $currencyTo = 'EUR'): string
{
public static function convertWithSign(
float|int|string $amount,
Currency|array|string $currencyFrom,
Currency|array|string $currencyTo = 'EUR'
): string {
$From = Handler::getCurrency($currencyFrom);
$To = Handler::getCurrency($currencyTo);
......@@ -55,15 +60,16 @@ public static function convertWithSign($amount, $currencyFrom, $currencyTo = 'EU
/**
* Return the exchange rate between two currencies
*
* @param string|Currency $currencyFrom
* @param string|Currency $currencyTo
*
* @param array|string|Currency $currencyFrom
* @param array|string|Currency $currencyTo
* @return float|boolean
*
* @throws QUI\Exception
*/
public static function getExchangeRateBetween($currencyFrom, $currencyTo)
{
public static function getExchangeRateBetween(
Currency|array|string $currencyFrom,
Currency|array|string $currencyTo
): float|bool {
$From = Handler::getCurrency($currencyFrom);
$To = Handler::getCurrency($currencyTo);
......
......@@ -39,7 +39,7 @@ public static function getAccountingCurrency(): ?Currency
return Handler::getCurrency(
self::conf('currency', 'accountingCurrency')
);
} catch (QUI\Exception $Exception) {
} catch (QUI\Exception) {
return Handler::getDefaultCurrency();
}
}
......@@ -47,19 +47,19 @@ public static function getAccountingCurrency(): ?Currency
/**
* Return currency conf
*
* @param $section
* @param $key
* @param string $section
* @param string|null $key
*
* @return array|bool|string
*/
public static function conf($section, $key)
public static function conf(string $section, ?string $key): bool|array|string
{
try {
$Package = QUI::getPackage('quiqqer/currency');
$Config = $Package->getConfig();
return $Config->get($section, $key);
} catch (QUI\Exception $Exception) {
} catch (QUI\Exception) {
}
return false;
......
......@@ -35,10 +35,9 @@ public function __construct()
* @throws Exception
* @see \QUI\System\Console\Tool::execute()
*/
public function execute()
public function execute(): void
{
Import::import();
QUI::getEvents()->fireEvent('quiqqerCurrencyImport');
}
}
......@@ -18,10 +18,9 @@ class Cron
* Start import
* @throws QUI\Exception
*/
public static function import()
public static function import(): void
{
Import::import();
QUI::getEvents()->fireEvent('quiqqerCurrencyImport');
}
}
......@@ -20,7 +20,7 @@ class EventHandler
/**
* @param QUI\Template $TemplateManager
*/
public static function onTemplateGetHeader(QUI\Template $TemplateManager)
public static function onTemplateGetHeader(QUI\Template $TemplateManager): void
{
try {
$Currency = Handler::getDefaultCurrency();
......@@ -50,7 +50,7 @@ public static function onTemplateGetHeader(QUI\Template $TemplateManager)
* @param array $params Additional parameters passed to the method.
* @return void
*/
public static function onPackageConfigSave(Package $Package, array $params)
public static function onPackageConfigSave(Package $Package, array $params): void
{
if ($Package->getName() !== 'quiqqer/currency') {
return;
......
......@@ -362,11 +362,11 @@ public static function getData(): array
/**
* Return a currency
*
* @param string|Currency $currency
* @param Currency|string|array $currency
* @return Currency
* @throws QUI\Exception
*/
public static function getCurrency($currency): Currency
public static function getCurrency(Currency|string|array $currency): Currency
{
if ($currency instanceof Currency) {
return $currency;
......
......@@ -26,14 +26,14 @@ class Import
*
* @throws QUI\Exception
*/
public static function importCurrenciesFromECB()
public static function importCurrenciesFromECB(): void
{
$values = self::getECBData();
foreach ($values as $currency => $rate) {
try {
Handler::getCurrency($currency);
} catch (QUI\Exception $Exception) {
} catch (QUI\Exception) {
// currency not exists, we must create it
Handler::createCurrency($currency, $rate);
}
......@@ -50,7 +50,7 @@ public static function importCurrenciesFromECB()
*
* @throws QUI\Exception
*/
public static function import()
public static function import(): void
{
$values = self::getECBData();
......
0% oder .
You are about to add 0 people to the discussion. Proceed with caution.
Bearbeitung dieser Nachricht zuerst beenden!
Bitte registrieren oder zum Kommentieren