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

fix: uuid handling

Übergeordneter f5e7b069
Keine zugehörigen Branchen gefunden
Keine zugehörigen Tags gefunden
3 Merge Requests!87refactor: code stability,!86refactor: code stability,!85refactor: code stability
......@@ -254,7 +254,7 @@ define('package/quiqqer/erp/bin/backend/controls/userData/UserData', [
if (this.$CustomerEdit) {
this.$CustomerEdit.setStyle('display', 'inline');
}
console.log('user data', data);
let dataPromise = Promise.resolve();
let addressPromise = Promise.resolve();
......@@ -475,7 +475,7 @@ define('package/quiqqer/erp/bin/backend/controls/userData/UserData', [
/**
* Sets data by specific address.
*
* @param {Object} address - Adress data
* @param {Object} address - Address data
* @return {void}
*/
$setDataByAddress: function(address) {
......@@ -483,7 +483,7 @@ define('package/quiqqer/erp/bin/backend/controls/userData/UserData', [
this.$AddressField.value = address.id;
this.setAttribute('id', address.id);
this.setAttribute('addressId', address.id);
this.setAttribute('addressId', address.uuid);
this.$refreshValues();
......@@ -515,7 +515,7 @@ define('package/quiqqer/erp/bin/backend/controls/userData/UserData', [
},
/**
* Set a address to the user data
* Set an address to the user data
*
* @param {String|Number} addressId
* @return {Promise}
......
......@@ -34,6 +34,10 @@ public function __construct($data = [], $User = null)
if (isset($data['id'])) {
$this->id = (int)$data['id'];
}
if (isset($data['uuid'])) {
$this->uuid = $data['uuid'];
}
}
/**
......@@ -44,13 +48,7 @@ public function __construct($data = [], $User = null)
*/
public function getDisplay(array $options = []): string
{
try {
$Engine = QUI::getTemplateManager()->getEngine(true);
} catch (QUI\Exception $Exception) {
QUI\System\Log::writeDebugException($Exception);
return '';
}
$Engine = QUI::getTemplateManager()->getEngine(true);
$contactPerson = '';
$isCompany = false;
......
......@@ -21,17 +21,17 @@ interface NumberRangeInterface
* @param null|QUI\Locale $Locale
* @return string
*/
public function getTitle($Locale = null);
public function getTitle(QUI\Locale $Locale = null): string;
/**
* Return the current start of the range
*
* @return int
*/
public function getRange();
public function getRange(): int;
/**
* @param $range
* @param int $range
*/
public function setRange($range);
public function setRange(int $range);
}
......@@ -8,6 +8,9 @@
use QUI;
use QUI\ExceptionStack;
use QUI\Users\User;
use function is_array;
use function is_string;
use function json_decode;
......@@ -219,11 +222,10 @@ public function import(Comments $Comments): void
/**
* Get comments by user
*
* @param QUI\Users\User $User
* @return Comments
* @param User $User
* @return Comments|null
*
* @throws QUI\Exception
* @throws QUI\ExceptionStack
* @throws ExceptionStack
*/
public static function getCommentsByUser(QUI\Users\User $User): ?Comments
{
......
......@@ -64,10 +64,10 @@ class Price
*/
public function __construct($price, QUI\ERP\Currency\Currency $Currency, $User = false)
{
$this->price = $price;
$this->price = $price;
$this->Currency = $Currency;
$this->User = $User;
$this->User = $User;
$this->discounts = [];
if (!QUI::getUsers()->isUser($User)) {
......@@ -82,9 +82,9 @@ public function __construct($price, QUI\ERP\Currency\Currency $Currency, $User =
public function toArray(): array
{
return [
'price' => $this->value(),
'currency' => $this->getCurrency()->getCode(),
'display' => $this->getDisplayPrice(),
'price' => $this->value(),
'currency' => $this->getCurrency()->getCode(),
'display' => $this->getDisplayPrice(),
'isMinimalPrice' => $this->isMinimalPrice()
];
}
......@@ -186,17 +186,17 @@ public function getCurrency(): QUI\ERP\Currency\Currency
/**
* Validates a price value
*
* @param int|float|string $value
* @param mixed $value
* @param QUI\Locale|null $Locale - based locale, in which the price is
* @return float|int|null
*/
public static function validatePrice($value, $Locale = null)
public static function validatePrice(mixed $value, QUI\Locale $Locale = null): float|int|null
{
if (is_float($value)) {
return round($value, QUI\ERP\Defaults::getPrecision());
}
$value = (string)$value;
$value = (string)$value;
$isNegative = substr($value, 0, 1) === '-';
// value cleanup
......@@ -216,10 +216,10 @@ public static function validatePrice($value, $Locale = null)
$negativeTurn = -1;
}
$decimalSeparator = $Locale->getDecimalSeparator();
$decimalSeparator = $Locale->getDecimalSeparator();
$thousandSeparator = $Locale->getGroupingSeparator();
$decimal = mb_strpos($value, $decimalSeparator);
$decimal = mb_strpos($value, $decimalSeparator);
$thousands = mb_strpos($value, $thousandSeparator);
if ($thousands === false && $decimal === false) {
......
......@@ -19,6 +19,7 @@
use function get_class;
use function is_array;
use function is_bool;
use function is_numeric;
use function json_decode;
use function trim;
......@@ -37,9 +38,9 @@ class User extends QUI\QDOM implements UserInterface
protected int $id;
/**
* @var string|int
* @var string
*/
protected string|int $uuid;
protected string $uuid = '';
/**
* @var string
......@@ -101,7 +102,12 @@ public function __construct(array $attributes)
}
}
$this->id = $attributes['id'];
if (!isset($attributes['id']) && !isset($attributes['uuid'])) {
throw new QUI\ERP\Exception(
'Missing attribute: id or uuid'
);
}
$this->isCompany = !empty($attributes['isCompany']) || !empty($attributes['company']);
$this->lang = $attributes['lang'];
$this->username = $attributes['username'];
......@@ -114,10 +120,19 @@ public function __construct(array $attributes)
$this->country = $attributes['country'];
}
if (isset($attributes['id'])) {
$this->id = $attributes['id'];
}
if (isset($attributes['uuid'])) {
$this->uuid = $attributes['uuid'];
}
if (empty($this->uuid)) {
$this->uuid = $this->id;
}
if (isset($attributes['data']) && is_array($attributes['data'])) {
$this->setAttributes($attributes['data']);
unset($attributes['data']);
......@@ -145,7 +160,6 @@ public function __construct(array $attributes)
public static function getNeedles(): array
{
return [
'id',
'country',
'username',
'firstname',
......@@ -206,6 +220,7 @@ public static function convertUserToErpUser(UserInterface $User): User
return new self([
'id' => $User->getId(),
'uuid' => $User->getUUID(),
'country' => $country,
'username' => $User->getUsername(),
'firstname' => $User->getAttribute('firstname'),
......@@ -258,6 +273,7 @@ public static function convertUserDataToErpUser(array $user): User
/**
* @return int|false
* @deprecated
*/
public function getId(): int|false
{
......@@ -266,6 +282,7 @@ public function getId(): int|false
/**
* @return string
* @deprecated
*/
public function getUniqueId(): string
{
......@@ -375,7 +392,7 @@ public function getAttributes(): array
{
$attributes = parent::getAttributes();
$attributes['country'] = $this->getCountry();
$attributes['id'] = $this->getId();
$attributes['uuid'] = $this->getUUID();
$attributes['lang'] = $this->getLang();
$attributes['isCompany'] = $this->isCompany();
$attributes['firstname'] = $this->getAttribute('firstname');
......@@ -400,18 +417,12 @@ public function getAttributes(): array
*/
public function getAttribute(string $name): mixed
{
switch ($name) {
case 'firstname':
return $this->firstName;
case 'lastname':
return $this->lastName;
case 'country':
return $this->getCountry();
}
return parent::getAttribute($name);
return match ($name) {
'firstname' => $this->firstName,
'lastname' => $this->lastName,
'country' => $this->getCountry(),
default => parent::getAttribute($name),
};
}
/**
......
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