Skip to content
Code-Schnipsel Gruppen Projekte
Commit 2fce7ba4 erstellt von Henning Leutz's avatar Henning Leutz :martial_arts_uniform:
Dateien durchsuchen

Merge branch 'feat-quiqqer-v2' into 'dev'

feat!: quiqqer v2

See merge request !43
Übergeordnete b6575a2b f21f0904
Keine zugehörigen Branchen gefunden
Keine zugehörigen Tags gefunden
3 Merge Requests!45feat!: quiqqer v2,!44feat!: quiqqer v2,!43feat!: quiqqer v2
Pipeline-Nr. 7285 bestanden
Dieser Commit ist Teil des Merge Request !44. Hier erstellte Kommentare werden im Kontext dieses Merge Request erstellt.
werden angezeigt mit 94 Ergänzungen und 57 Löschungen
.gitignore 0 → 100644
+ 4
0
Zeige Datei @ 2fce7ba4
tools/
phpstan.neon
.phpunit.result.cache
phpunit.xml
\ No newline at end of file
.phive/phars.xml 0 → 100644
+ 4
0
Zeige Datei @ 2fce7ba4
<?xml version="1.0" encoding="UTF-8"?>
<phive xmlns="https://phar.io/phive">
<phar name="phpstan" version="^1.10.67" installed="1.10.67" location="./tools/phpstan" copy="false"/>
</phive>
......@@ -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
]);
......
{
"name": "quiqqer\/currency",
"name": "quiqqer/currency",
"type": "quiqqer-module",
"description": "Integrates different currencies in QUIQQER",
"license": "GPL-3.0-or-later",
......@@ -7,7 +7,7 @@
{
"name": "Henning Leutz",
"email": "leutz@pcsg.de",
"homepage": "http:\/\/www.pcsg.de",
"homepage": "https://www.pcsg.de",
"role": "Developer"
}
],
......@@ -15,13 +15,14 @@
"email": "support@pcsg.de"
},
"require": {
"php": "^8.1",
"ext-intl": "*",
"quiqqer\/quiqqer": "*",
"quiqqer\/qui": ">=1|*@dev"
"quiqqer/core": "^2",
"quiqqer/qui": "^1"
},
"autoload": {
"psr-4": {
"QUI\\ERP\\Currency\\": "src\/QUI\/ERP\/Currency"
"QUI\\ERP\\Currency\\": "src/QUI/ERP/Currency"
}
}
}
+ 0
0
Zeige Datei @ 2fce7ba4
phpstan.dist.neon 0 → 100644
+ 10
0
Zeige Datei @ 2fce7ba4
includes:
- phpstan-baseline.neon
parameters:
level: 1
paths:
- src
- ajax
bootstrapFiles:
- tests/phpstan-bootstrap.php
\ No newline at end of file
......@@ -8,6 +8,7 @@
use NumberFormatter;
use QUI;
use QUI\Exception;
use function array_key_exists;
use function floatval;
......@@ -35,27 +36,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 +105,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 +204,8 @@ public function amount($amount, QUI\Locale $Locale = null): float
}
$amount = str_replace(',', '.', $amount);
$amount = floatval($amount);
return $amount;
return floatval($amount);
}
/**
......@@ -275,11 +275,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 +347,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 +376,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 +408,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 +419,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();
......
<?php
if (!defined('QUIQQER_SYSTEM')) {
define('QUIQQER_SYSTEM', true);
}
if (!defined('QUIQQER_AJAX')) {
define('QUIQQER_AJAX', true);
}
putenv("QUIQQER_OTHER_AUTOLOADERS=KEEP");
require_once __DIR__ . '/../../../../bootstrap.php';
0% Lade oder .
You are about to add 0 people to the discussion. Proceed with caution.
Bearbeitung dieser Nachricht zuerst beenden!
Bitte registrieren oder zum Kommentieren