Skip to content
Code-Schnipsel Gruppen Projekte
Commit 7917f46a erstellt von Patrick Müller's avatar Patrick Müller
Dateien durchsuchen

feat: runtime cache for user brutto/netto status

Übergeordneter b03ab178
No related branches found
No related tags found
Keine zugehörigen Merge Requests gefunden
......@@ -27,6 +27,13 @@ class User
*/
const IS_BRUTTO_USER = 2;
/**
* Runtime cache for user brutt/netto status
*
* @var array
*/
protected static $userBruttoNettoStatus = [];
/**
* Return the brutto netto status
* is the user a netto or brutto user
......@@ -36,15 +43,22 @@ class User
*/
public static function getBruttoNettoUserStatus(UserInterface $User)
{
$uid = $User->getId();
if (isset(self::$userBruttoNettoStatus[$uid])) {
return self::$userBruttoNettoStatus[$uid];
}
if (QUI::getUsers()->isSystemUser($User)) {
return self::IS_NETTO_USER;
self::$userBruttoNettoStatus[$uid] = self::IS_NETTO_USER;
return self::$userBruttoNettoStatus[$uid];
}
if ($User instanceof QUI\ERP\User && $User->hasBruttoNettoStatus()) {
return $User->isNetto();
self::$userBruttoNettoStatus[$uid] = $User->isNetto();
return self::$userBruttoNettoStatus[$uid];
}
$nettoStatus = $User->getAttribute('quiqqer.erp.isNettoUser');
if (\is_numeric($nettoStatus)) {
......@@ -54,20 +68,23 @@ public static function getBruttoNettoUserStatus(UserInterface $User)
switch ($nettoStatus) {
case self::IS_NETTO_USER:
case self::IS_BRUTTO_USER:
return $nettoStatus;
self::$userBruttoNettoStatus[$uid] = $nettoStatus;
return self::$userBruttoNettoStatus[$uid];
}
$euVatId = $User->getAttribute('quiqqer.erp.euVatId');
$taxId = $User->getAttribute('quiqqer.erp.taxId');
if (!empty($euVatId) || !empty($taxId)) {
return self::IS_NETTO_USER;
self::$userBruttoNettoStatus[$uid] = self::IS_NETTO_USER;
return self::$userBruttoNettoStatus[$uid];
}
try {
$Package = QUI::getPackage('quiqqer/tax');
} catch (QUI\Exception $Exception) {
return self::IS_BRUTTO_USER;
self::$userBruttoNettoStatus[$uid] = self::IS_BRUTTO_USER;
return self::$userBruttoNettoStatus[$uid];
}
try {
......@@ -75,7 +92,8 @@ public static function getBruttoNettoUserStatus(UserInterface $User)
} catch (QUI\Exception $Exception) {
QUI\System\Log::writeDebugException($Exception);
return self::IS_NETTO_USER;
self::$userBruttoNettoStatus[$uid] = self::IS_NETTO_USER;
return self::$userBruttoNettoStatus[$uid];
}
// @todo quiqqer.erp.isNettoUser beachten, die eigenschaft ist besser, gab es damals noch nicht
......@@ -88,10 +106,12 @@ public static function getBruttoNettoUserStatus(UserInterface $User)
&& $Address->getAttribute('company')
) {
if ($Config->getValue('shop', 'companyForceBruttoPrice')) {
return self::IS_BRUTTO_USER;
self::$userBruttoNettoStatus[$uid] = self::IS_BRUTTO_USER;
return self::$userBruttoNettoStatus[$uid];
}
return self::IS_NETTO_USER;
self::$userBruttoNettoStatus[$uid] = self::IS_NETTO_USER;
return self::$userBruttoNettoStatus[$uid];
}
if (\is_array($Address)
......@@ -99,10 +119,12 @@ public static function getBruttoNettoUserStatus(UserInterface $User)
&& $Address['company'] == 1
) {
if ($Config->getValue('shop', 'companyForceBruttoPrice')) {
return self::IS_BRUTTO_USER;
self::$userBruttoNettoStatus[$uid] = self::IS_BRUTTO_USER;
return self::$userBruttoNettoStatus[$uid];
}
return self::IS_NETTO_USER;
self::$userBruttoNettoStatus[$uid] = self::IS_NETTO_USER;
return self::$userBruttoNettoStatus[$uid];
}
} catch (QUI\Exception $Exception) {
// no address found
......@@ -114,7 +136,8 @@ public static function getBruttoNettoUserStatus(UserInterface $User)
$isNetto = $Config->getValue('shop', 'isNetto');
if ($isNetto) {
return self::IS_NETTO_USER;
self::$userBruttoNettoStatus[$uid] = self::IS_NETTO_USER;
return self::$userBruttoNettoStatus[$uid];
}
......@@ -122,13 +145,16 @@ public static function getBruttoNettoUserStatus(UserInterface $User)
$Tax = QUI\ERP\Tax\Utils::getTaxByUser($User);
if ($Tax->getValue() == 0) {
return self::IS_NETTO_USER;
self::$userBruttoNettoStatus[$uid] = self::IS_NETTO_USER;
return self::$userBruttoNettoStatus[$uid];
}
} catch (QUI\Exception $Exception) {
return self::IS_NETTO_USER;
self::$userBruttoNettoStatus[$uid] = self::IS_NETTO_USER;
return self::$userBruttoNettoStatus[$uid];
}
return self::IS_BRUTTO_USER;
self::$userBruttoNettoStatus[$uid] = self::IS_BRUTTO_USER;
return self::$userBruttoNettoStatus[$uid];
}
/**
......
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