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

feat: quiqqer v2 compatibility

Übergeordneter b5672d86
No related branches found
No related tags found
3 Merge Requests!5feat!: quiqqer v2,!4feat!: quiqqer v2,!3feat!: quiqqer v2
...@@ -9,13 +9,16 @@ ...@@ -9,13 +9,16 @@
* *
* @param integer $discountId - Discount-ID * @param integer $discountId - Discount-ID
*/ */
use QUI\ERP\Discount\Discount;
QUI::$Ajax->registerFunction( QUI::$Ajax->registerFunction(
'package_quiqqer_discount_ajax_activate', 'package_quiqqer_discount_ajax_activate',
function ($discountId) { function ($discountId) {
$Handler = new QUI\ERP\Discount\Handler(); $Handler = new QUI\ERP\Discount\Handler();
$Discount = $Handler->getChild($discountId); $Discount = $Handler->getChild($discountId);
/* @var $Discount \QUI\ERP\Discount\Discount */ /* @var $Discount Discount */
$Discount->setAttribute('active', 1); $Discount->setAttribute('active', 1);
$Discount->update(); $Discount->update();
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
QUI::$Ajax->registerFunction( QUI::$Ajax->registerFunction(
'package_quiqqer_discount_ajax_create', 'package_quiqqer_discount_ajax_create',
function ($params) { function ($params) {
$params = json_decode($params, true); $params = json_decode($params, true);
$Discounts = new QUI\ERP\Discount\Handler(); $Discounts = new QUI\ERP\Discount\Handler();
if (!isset($params['active'])) { if (!isset($params['active'])) {
......
...@@ -9,13 +9,16 @@ ...@@ -9,13 +9,16 @@
* *
* @param integer $discountId - Discount-ID * @param integer $discountId - Discount-ID
*/ */
use QUI\ERP\Discount\Discount;
QUI::$Ajax->registerFunction( QUI::$Ajax->registerFunction(
'package_quiqqer_discount_ajax_deactivate', 'package_quiqqer_discount_ajax_deactivate',
function ($discountId) { function ($discountId) {
$Handler = new QUI\ERP\Discount\Handler(); $Handler = new QUI\ERP\Discount\Handler();
$Discount = $Handler->getChild($discountId); $Discount = $Handler->getChild($discountId);
/* @var $Discount \QUI\ERP\Discount\Discount */ /* @var $Discount Discount */
$Discount->setAttribute('active', 0); $Discount->setAttribute('active', 0);
$Discount->update(); $Discount->update();
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
'package_quiqqer_discount_ajax_deleteChild', 'package_quiqqer_discount_ajax_deleteChild',
function ($discountId) { function ($discountId) {
$Discounts = new QUI\ERP\Discount\Handler(); $Discounts = new QUI\ERP\Discount\Handler();
$Discount = $Discounts->getChild($discountId); $Discount = $Discounts->getChild($discountId);
$Discount->delete(); $Discount->delete();
}, },
['discountId'], ['discountId'],
......
...@@ -14,8 +14,8 @@ ...@@ -14,8 +14,8 @@
QUI::$Ajax->registerFunction( QUI::$Ajax->registerFunction(
'package_quiqqer_discount_ajax_deleteChildren', 'package_quiqqer_discount_ajax_deleteChildren',
function ($discountIds) { function ($discountIds) {
$discountIds = json_decode($discountIds, true); $discountIds = json_decode($discountIds, true);
$Discounts = new QUI\ERP\Discount\Handler(); $Discounts = new QUI\ERP\Discount\Handler();
$ExceptionStack = new QUI\ExceptionStack(); $ExceptionStack = new QUI\ExceptionStack();
foreach ($discountIds as $discountId) { foreach ($discountIds as $discountId) {
......
...@@ -11,14 +11,17 @@ ...@@ -11,14 +11,17 @@
* *
* @return array * @return array
*/ */
use QUI\ERP\Discount\Discount;
QUI::$Ajax->registerFunction( QUI::$Ajax->registerFunction(
'package_quiqqer_discount_ajax_get', 'package_quiqqer_discount_ajax_get',
function ($id) { function ($id) {
$Discounts = new QUI\ERP\Discount\Handler(); $Discounts = new QUI\ERP\Discount\Handler();
$Discount = $Discounts->getChild($id); $Discount = $Discounts->getChild($id);
$attributes = $Discount->getAttributes(); $attributes = $Discount->getAttributes();
/* @var $Discount \QUI\ERP\Discount\Discount */ /* @var $Discount Discount */
$attributes['title'] = $Discount->getTitle(); $attributes['title'] = $Discount->getTitle();
return $attributes; return $attributes;
......
...@@ -14,13 +14,13 @@ ...@@ -14,13 +14,13 @@
QUI::$Ajax->registerFunction( QUI::$Ajax->registerFunction(
'package_quiqqer_discount_ajax_list', 'package_quiqqer_discount_ajax_list',
function ($params) { function ($params) {
$Grid = new QUI\Utils\Grid(); $Grid = new QUI\Utils\Grid();
$Discounts = new QUI\ERP\Discount\Handler(); $Discounts = new QUI\ERP\Discount\Handler();
$result = []; $result = [];
$Locale = QUI::getLocale(); $Locale = QUI::getLocale();
// search // search
$params = $Grid->parseDBParams(\json_decode($params, true)); $params = $Grid->parseDBParams(json_decode($params, true));
$params['where'] = [ $params['where'] = [
'hidden' => 0 'hidden' => 0
...@@ -31,15 +31,15 @@ function ($params) { ...@@ -31,15 +31,15 @@ function ($params) {
foreach ($data as $entry) { foreach ($data as $entry) {
$entry['title'] = [ $entry['title'] = [
'quiqqer/discount', 'quiqqer/discount',
'discount.'.$entry['id'].'.title' 'discount.' . $entry['id'] . '.title'
]; ];
$entry['text'] = $Locale->get( $entry['text'] = $Locale->get(
'quiqqer/discount', 'quiqqer/discount',
'discount.'.$entry['id'].'.title' 'discount.' . $entry['id'] . '.title'
); );
$type = (int)$entry['discount_type']; $type = (int)$entry['discount_type'];
$usageType = (int)$entry['usage_type']; $usageType = (int)$entry['usage_type'];
// attributes // attributes
......
...@@ -15,12 +15,12 @@ ...@@ -15,12 +15,12 @@
'package_quiqqer_discount_ajax_search', 'package_quiqqer_discount_ajax_search',
function ($fields, $params) { function ($fields, $params) {
$Discounts = new QUI\ERP\Discount\Handler(); $Discounts = new QUI\ERP\Discount\Handler();
$result = []; $result = [];
$Locale = QUI::getLocale(); $Locale = QUI::getLocale();
$allowedFields = $Discounts->getChildAttributes(); $allowedFields = $Discounts->getChildAttributes();
$query = []; $query = [];
$params = json_decode($params, true); $params = json_decode($params, true);
$fields = json_decode($fields, true); $fields = json_decode($fields, true);
...@@ -44,7 +44,7 @@ function ($fields, $params) { ...@@ -44,7 +44,7 @@ function ($fields, $params) {
} }
$query['where_or'][$field] = [ $query['where_or'][$field] = [
'type' => '%LIKE%', 'type' => '%LIKE%',
'value' => $value 'value' => $value
]; ];
} }
...@@ -55,12 +55,12 @@ function ($fields, $params) { ...@@ -55,12 +55,12 @@ function ($fields, $params) {
foreach ($data as $entry) { foreach ($data as $entry) {
$entry['title'] = [ $entry['title'] = [
'quiqqer/discount', 'quiqqer/discount',
'discount.'.$entry['id'].'.title' 'discount.' . $entry['id'] . '.title'
]; ];
$entry['text'] = $Locale->get( $entry['text'] = $Locale->get(
'quiqqer/discount', 'quiqqer/discount',
'discount.'.$entry['id'].'.title' 'discount.' . $entry['id'] . '.title'
); );
$result[] = $entry; $result[] = $entry;
......
...@@ -9,13 +9,16 @@ ...@@ -9,13 +9,16 @@
* *
* @param integer $discountId - Discount-ID * @param integer $discountId - Discount-ID
*/ */
use QUI\ERP\Discount\Discount;
QUI::$Ajax->registerFunction( QUI::$Ajax->registerFunction(
'package_quiqqer_discount_ajax_toggle', 'package_quiqqer_discount_ajax_toggle',
function ($discountId) { function ($discountId) {
$Handler = new QUI\ERP\Discount\Handler(); $Handler = new QUI\ERP\Discount\Handler();
$Discount = $Handler->getChild($discountId); $Discount = $Handler->getChild($discountId);
/* @var $Discount \QUI\ERP\Discount\Discount */ /* @var $Discount Discount */
if ($Discount->isActive()) { if ($Discount->isActive()) {
$Discount->setAttribute('active', 0); $Discount->setAttribute('active', 0);
} else { } else {
......
...@@ -16,8 +16,8 @@ ...@@ -16,8 +16,8 @@
'package_quiqqer_discount_ajax_update', 'package_quiqqer_discount_ajax_update',
function ($discountId, $params) { function ($discountId, $params) {
$Discounts = new QUI\ERP\Discount\Handler(); $Discounts = new QUI\ERP\Discount\Handler();
$Discount = $Discounts->getChild($discountId); $Discount = $Discounts->getChild($discountId);
$params = json_decode($params, true); $params = json_decode($params, true);
$Discount->setAttributes($params); $Discount->setAttributes($params);
$Discount->update(); $Discount->update();
......
Dieser Diff ist reduziert.
...@@ -7,11 +7,15 @@ ...@@ -7,11 +7,15 @@
namespace QUI\ERP\Discount; namespace QUI\ERP\Discount;
use QUI; use QUI;
use QUI\Database\Exception;
use QUI\ERP\Accounting\Calc as ErpCalc; use QUI\ERP\Accounting\Calc as ErpCalc;
use QUI\ERP\Products\Product\UniqueProduct; use QUI\ERP\Products\Product\UniqueProduct;
use QUI\ERP\Products\Utils\Calc; use QUI\ERP\Products\Utils\Calc;
use QUI\ERP\Products\Product\ProductList; use QUI\ERP\Products\Product\ProductList;
use function array_filter;
use function explode;
/** /**
* Class EventHandling * Class EventHandling
* *
...@@ -20,19 +24,19 @@ ...@@ -20,19 +24,19 @@
class EventHandling class EventHandling
{ {
/** /**
* @var null * @var Handler|null
*/ */
protected static $Handler = null; protected static ?Handler $Handler = null;
/** /**
* @var array * @var array
*/ */
protected static $userDiscounts = []; protected static array $userDiscounts = [];
/** /**
* Return the global * Return the global
* *
* @return Handler * @return Handler|null
*/ */
protected static function getHandler(): ?Handler protected static function getHandler(): ?Handler
{ {
...@@ -48,6 +52,7 @@ protected static function getHandler(): ?Handler ...@@ -48,6 +52,7 @@ protected static function getHandler(): ?Handler
* *
* @param QUI\Interfaces\Users\User $User * @param QUI\Interfaces\Users\User $User
* @return array * @return array
* @throws Exception
*/ */
protected static function getUserDiscounts(QUI\Interfaces\Users\User $User): array protected static function getUserDiscounts(QUI\Interfaces\Users\User $User): array
{ {
...@@ -65,12 +70,12 @@ protected static function getUserDiscounts(QUI\Interfaces\Users\User $User): arr ...@@ -65,12 +70,12 @@ protected static function getUserDiscounts(QUI\Interfaces\Users\User $User): arr
* - Einkaufsmengeprüfung * - Einkaufsmengeprüfung
* *
* @param Discount $Discount * @param Discount $Discount
* @param integer|double $quantity * @param double|integer $quantity
* @return bool * @return bool
*/ */
public static function isDiscountUsableWithQuantity(Discount $Discount, $quantity): bool public static function isDiscountUsableWithQuantity(Discount $Discount, float|int $quantity): bool
{ {
$purchaseQuantityFrom = $Discount->getAttribute('purchase_quantity_from'); $purchaseQuantityFrom = $Discount->getAttribute('purchase_quantity_from');
$purchaseQuantityUntil = $Discount->getAttribute('purchase_quantity_until'); $purchaseQuantityUntil = $Discount->getAttribute('purchase_quantity_until');
if ($quantity === 0) { if ($quantity === 0) {
...@@ -93,22 +98,24 @@ public static function isDiscountUsableWithQuantity(Discount $Discount, $quantit ...@@ -93,22 +98,24 @@ public static function isDiscountUsableWithQuantity(Discount $Discount, $quantit
} }
/** /**
* Discount pirchase value check for usage * Discount purchase value check for usage
* - Einkaufswertprüfung * - Einkaufswertprüfung
* *
* @param Discount $Discount * @param Discount $Discount
* @param integer|double $value * @param float|integer $value
* @return bool * @return bool
*/ */
public static function isDiscountUsableWithPurchaseValue(Discount $Discount, $value): bool public static function isDiscountUsableWithPurchaseValue(Discount $Discount, float|int $value): bool
{ {
$purchaseValueFrom = $Discount->getAttribute('purchase_value_from'); $purchaseValueFrom = $Discount->getAttribute('purchase_value_from');
$purchaseValueUntil = $Discount->getAttribute('purchase_value_until'); $purchaseValueUntil = $Discount->getAttribute('purchase_value_until');
// wenn complement, z.B. 10€, muss geprüft werden // wenn complement, z.B. 10€, muss geprüft werden
// ob meine value grösser ist als der gegebene value // ob meine value grösser ist als der gegebene value
if ((int)$Discount->getAttribute('discount_type') === ErpCalc::CALCULATION_COMPLEMENT if (
&& $Discount->getAttribute('discount') > $value) { (int)$Discount->getAttribute('discount_type') === ErpCalc::CALCULATION_COMPLEMENT
&& $Discount->getAttribute('discount') > $value
) {
return false; return false;
} }
...@@ -134,18 +141,19 @@ public static function isDiscountUsableWithPurchaseValue(Discount $Discount, $va ...@@ -134,18 +141,19 @@ public static function isDiscountUsableWithPurchaseValue(Discount $Discount, $va
* *
* @param QUI\ERP\Products\Utils\Calc $Calc * @param QUI\ERP\Products\Utils\Calc $Calc
* @param UniqueProduct $Product * @param UniqueProduct $Product
* @throws Exception
*/ */
public static function onQuiqqerProductsCalcListProduct( public static function onQuiqqerProductsCalcListProduct(
Calc $Calc, Calc $Calc,
UniqueProduct $Product UniqueProduct $Product
) { ): void {
$userDiscounts = self::getUserDiscounts($Calc->getUser()); $userDiscounts = self::getUserDiscounts($Calc->getUser());
if (!\is_array($userDiscounts) || empty($userDiscounts)) { if (empty($userDiscounts)) {
return; return;
} }
$userDiscounts = \array_filter($userDiscounts, function ($Discount) { $userDiscounts = array_filter($userDiscounts, function ($Discount) {
/* @var $Discount Discount */ /* @var $Discount Discount */
// don't use manuel usage type // don't use manuel usage type
...@@ -156,7 +164,7 @@ public static function onQuiqqerProductsCalcListProduct( ...@@ -156,7 +164,7 @@ public static function onQuiqqerProductsCalcListProduct(
return (int)$Discount->getAttribute('scope') === Handler::DISCOUNT_SCOPE_EVERY_PRODUCT; return (int)$Discount->getAttribute('scope') === Handler::DISCOUNT_SCOPE_EVERY_PRODUCT;
}); });
if (!\is_array($userDiscounts) || empty($userDiscounts)) { if (empty($userDiscounts)) {
return; return;
} }
...@@ -168,7 +176,7 @@ public static function onQuiqqerProductsCalcListProduct( ...@@ -168,7 +176,7 @@ public static function onQuiqqerProductsCalcListProduct(
return; return;
} }
$PriceFactors = $Product->getPriceFactors(); $PriceFactors = $Product->getPriceFactors();
$productQuantity = $Product->getQuantity(); $productQuantity = $Product->getQuantity();
$productNettoSum = $attributes['calculated_nettoSum']; $productNettoSum = $attributes['calculated_nettoSum'];
...@@ -184,7 +192,7 @@ public static function onQuiqqerProductsCalcListProduct( ...@@ -184,7 +192,7 @@ public static function onQuiqqerProductsCalcListProduct(
// check if Pricefactor is already in // check if Pricefactor is already in
$factors = $PriceFactors->toArray(); $factors = $PriceFactors->toArray();
$Factor = $Discount->toPriceFactor( $Factor = $Discount->toPriceFactor(
$Calc->getUser()->getLocale(), $Calc->getUser()->getLocale(),
$Calc->getUser() $Calc->getUser()
); );
...@@ -208,20 +216,17 @@ public static function onQuiqqerProductsCalcListProduct( ...@@ -208,20 +216,17 @@ public static function onQuiqqerProductsCalcListProduct(
* *
* @param Calc $Calc * @param Calc $Calc
* @param ProductList $List * @param ProductList $List
* @param integer|double $nettoSum * @param float|integer $nettoSum
* @throws Exception
*/ */
public static function onQuiqqerProductsCalcList( public static function onQuiqqerProductsCalcList(
Calc $Calc, Calc $Calc,
ProductList $List, ProductList $List,
$nettoSum float|int $nettoSum
) { ): void {
$userDiscounts = self::getUserDiscounts($Calc->getUser()); $userDiscounts = self::getUserDiscounts($Calc->getUser());
if (!\is_array($userDiscounts)) { $userDiscounts = array_filter($userDiscounts, function ($Discount) {
return;
}
$userDiscounts = \array_filter($userDiscounts, function ($Discount) {
/* @var $Discount Discount */ /* @var $Discount Discount */
// don't use manuel usage type // don't use manuel usage type
...@@ -232,12 +237,8 @@ public static function onQuiqqerProductsCalcList( ...@@ -232,12 +237,8 @@ public static function onQuiqqerProductsCalcList(
return (int)$Discount->getAttribute('scope') == Handler::DISCOUNT_SCOPE_TOTAL; return (int)$Discount->getAttribute('scope') == Handler::DISCOUNT_SCOPE_TOTAL;
}); });
if (!\is_array($userDiscounts)) {
return;
}
$listQuantity = $List->getQuantity(); $listQuantity = $List->getQuantity();
$products = $List->getProducts(); $products = $List->getProducts();
$PriceFactors = $List->getPriceFactors(); $PriceFactors = $List->getPriceFactors();
/* @var $Discount Discount */ /* @var $Discount Discount */
...@@ -254,7 +255,7 @@ public static function onQuiqqerProductsCalcList( ...@@ -254,7 +255,7 @@ public static function onQuiqqerProductsCalcList(
$productIds = $Discount->getAttribute('articles'); $productIds = $Discount->getAttribute('articles');
if ($productIds) { if ($productIds) {
$productIds = \explode(',', $productIds); $productIds = explode(',', $productIds);
// product id check // product id check
$existProductIdInList = function ($products, $productIds) { $existProductIdInList = function ($products, $productIds) {
...@@ -279,7 +280,7 @@ public static function onQuiqqerProductsCalcList( ...@@ -279,7 +280,7 @@ public static function onQuiqqerProductsCalcList(
$categories = $Discount->getAttribute('categories'); $categories = $Discount->getAttribute('categories');
if ($categories) { if ($categories) {
$categories = \explode(',', $categories); $categories = explode(',', $categories);
// product category check // product category check
$existCategoryInList = function ($products, $categories) { $existCategoryInList = function ($products, $categories) {
...@@ -307,7 +308,7 @@ public static function onQuiqqerProductsCalcList( ...@@ -307,7 +308,7 @@ public static function onQuiqqerProductsCalcList(
// check if Pricefactor is already in // check if Pricefactor is already in
$factors = $PriceFactors->toArray(); $factors = $PriceFactors->toArray();
$Factor = $Discount->toPriceFactor( $Factor = $Discount->toPriceFactor(
$Calc->getUser()->getLocale(), $Calc->getUser()->getLocale(),
$Calc->getUser() $Calc->getUser()
); );
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
namespace QUI\ERP\Discount; namespace QUI\ERP\Discount;
use QUI; use QUI;
use QUI\Database\Exception;
use QUI\Permissions\Permission; use QUI\Permissions\Permission;
/** /**
...@@ -130,7 +131,7 @@ public function __construct() ...@@ -130,7 +131,7 @@ public function __construct()
// create new translation var for the discount // create new translation var for the discount
$this->Events->addEvent('onCreateEnd', function ($New, $data) { $this->Events->addEvent('onCreateEnd', function ($New, $data) {
/* @var $New QUI\ERP\Discount\Discount */ /* @var $New QUI\ERP\Discount\Discount */
$newVar = 'discount.'.$New->getId().'.title'; $newVar = 'discount.' . $New->getId() . '.title';
$current = QUI::getLocale()->getCurrent(); $current = QUI::getLocale()->getCurrent();
$title = $New->getAttribute('title'); $title = $New->getAttribute('title');
...@@ -146,9 +147,9 @@ public function __construct() ...@@ -146,9 +147,9 @@ public function __construct()
try { try {
QUI\Translator::addUserVar('quiqqer/discount', $newVar, [ QUI\Translator::addUserVar('quiqqer/discount', $newVar, [
$current => $title, $current => $title,
'datatype' => 'php,js', 'datatype' => 'php,js',
'package' => 'quiqqer/discount' 'package' => 'quiqqer/discount'
]); ]);
} catch (QUI\Exception $Exception) { } catch (QUI\Exception $Exception) {
QUI::getMessagesHandler()->addAttention( QUI::getMessagesHandler()->addAttention(
...@@ -163,7 +164,7 @@ public function __construct() ...@@ -163,7 +164,7 @@ public function __construct()
* *
* @return string * @return string
*/ */
public function getDataBaseTableName() public function getDataBaseTableName(): string
{ {
return QUI::getDBTableName('discounts'); return QUI::getDBTableName('discounts');
} }
...@@ -173,7 +174,7 @@ public function getDataBaseTableName() ...@@ -173,7 +174,7 @@ public function getDataBaseTableName()
* *
* @return string * @return string
*/ */
public function getChildClass() public function getChildClass(): string
{ {
return 'QUI\ERP\Discount\Discount'; return 'QUI\ERP\Discount\Discount';
} }
...@@ -183,7 +184,7 @@ public function getChildClass() ...@@ -183,7 +184,7 @@ public function getChildClass()
* *
* @return array * @return array
*/ */
public function getChildAttributes() public function getChildAttributes(): array
{ {
return [ return [
'active', 'active',
...@@ -217,8 +218,9 @@ public function getChildAttributes() ...@@ -217,8 +218,9 @@ public function getChildAttributes()
* *
* @param array $queryParams * @param array $queryParams
* @return array - [Child, Child, Child] * @return array - [Child, Child, Child]
* @throws Exception
*/ */
public function getChildrenData($queryParams = []) public function getChildrenData(array $queryParams = []): array
{ {
if (!isset($queryParams['order'])) { if (!isset($queryParams['order'])) {
$queryParams['order'] = 'priority ASC'; $queryParams['order'] = 'priority ASC';
......
...@@ -10,11 +10,12 @@ ...@@ -10,11 +10,12 @@
/** /**
* Class PriceFactor * Class PriceFactor
* This pricefactors is used by Handler::DISCOUNT_SCOPE_TOTAL * This price factor is used by Handler::DISCOUNT_SCOPE_TOTAL
* *
* @package QUI\ERP\Discount * @package QUI\ERP\Discount
*/ */
class PriceFactor extends QUI\ERP\Products\Utils\PriceFactor implements QUI\ERP\Products\Interfaces\PriceFactorWithVatInterface class PriceFactor extends QUI\ERP\Products\Utils\PriceFactor implements
QUI\ERP\Products\Interfaces\PriceFactorWithVatInterface
{ {
/** /**
* @var string * @var string
...@@ -45,7 +46,7 @@ public function __construct(array $params) ...@@ -45,7 +46,7 @@ public function __construct(array $params)
* @return QUI\ERP\Tax\TaxType * @return QUI\ERP\Tax\TaxType
* @throws QUI\Exception * @throws QUI\Exception
*/ */
public function getVatType() public function getVatType(): QUI\ERP\Tax\TaxType
{ {
if (!$this->vat) { if (!$this->vat) {
return QUI\ERP\Tax\Utils::getShopTaxType(); return QUI\ERP\Tax\Utils::getShopTaxType();
...@@ -61,7 +62,7 @@ public function getVatType() ...@@ -61,7 +62,7 @@ public function getVatType()
$Handler = new QUI\ERP\Tax\Handler(); $Handler = new QUI\ERP\Tax\Handler();
return $Handler->getTaxType($standardTax[1]); return $Handler->getTaxType($standardTax[1]);
} catch (QUI\Exception $Exception) { } catch (QUI\Exception) {
} }
return QUI\ERP\Tax\Utils::getShopTaxType(); return QUI\ERP\Tax\Utils::getShopTaxType();
......
...@@ -10,6 +10,10 @@ ...@@ -10,6 +10,10 @@
use QUI\Utils\UserGroups; use QUI\Utils\UserGroups;
use QUI\Interfaces\Users\User as UserInterface; use QUI\Interfaces\Users\User as UserInterface;
use function array_filter;
use function array_merge;
use function str_replace;
/** /**
* Class Utils * Class Utils
* *
...@@ -20,7 +24,7 @@ class Utils ...@@ -20,7 +24,7 @@ class Utils
/** /**
* Return all discounts which are usable by the user * Return all discounts which are usable by the user
* *
* @param \QUI\Interfaces\Users\User $User * @param UserInterface $User
* @return array * @return array
* *
* @throws \QUI\Database\Exception * @throws \QUI\Database\Exception
...@@ -28,15 +32,15 @@ class Utils ...@@ -28,15 +32,15 @@ class Utils
public static function getUserDiscounts(UserInterface $User): array public static function getUserDiscounts(UserInterface $User): array
{ {
$guString = UserGroups::getUserGroupStringFromUser($User); $guString = UserGroups::getUserGroupStringFromUser($User);
$guString = ','.\str_replace(',', ',|,', $guString).','; $guString = ',' . str_replace(',', ',|,', $guString) . ',';
$result = []; $result = [];
$Discounts = new Handler(); $Discounts = new Handler();
$personalDiscounts = $Discounts->getChildren([ $personalDiscounts = $Discounts->getChildren([
'where' => [ 'where' => [
'user_groups' => [ 'user_groups' => [
'type' => 'REGEXP', 'type' => 'REGEXP',
'value' => $guString 'value' => $guString
] ]
] ]
...@@ -50,11 +54,11 @@ public static function getUserDiscounts(UserInterface $User): array ...@@ -50,11 +54,11 @@ public static function getUserDiscounts(UserInterface $User): array
if (!empty($personalDiscounts)) { if (!empty($personalDiscounts)) {
$result = \array_merge($personalDiscounts, $result); $result = array_merge($personalDiscounts, $result);
} }
if (!empty($discounts)) { if (!empty($discounts)) {
$result = \array_merge($discounts, $result); $result = array_merge($discounts, $result);
} }
return $result; return $result;
...@@ -70,14 +74,14 @@ public static function getUserDiscounts(UserInterface $User): array ...@@ -70,14 +74,14 @@ public static function getUserDiscounts(UserInterface $User): array
*/ */
public static function getProductDiscounts(Product $Product): array public static function getProductDiscounts(Product $Product): array
{ {
$result = []; $result = [];
$Discounts = new Handler(); $Discounts = new Handler();
$productDiscounts = $Discounts->getChildren([ $productDiscounts = $Discounts->getChildren([
'where' => [ 'where' => [
'user_groups' => [ 'user_groups' => [
'type' => 'REGEXP', 'type' => 'REGEXP',
'value' => ','.$Product->getId().',' 'value' => ',' . $Product->getId() . ','
] ]
] ]
]); ]);
...@@ -90,11 +94,11 @@ public static function getProductDiscounts(Product $Product): array ...@@ -90,11 +94,11 @@ public static function getProductDiscounts(Product $Product): array
if (!empty($productDiscounts)) { if (!empty($productDiscounts)) {
$result = \array_merge($productDiscounts, $result); $result = array_merge($productDiscounts, $result);
} }
if (!empty($discounts)) { if (!empty($discounts)) {
$result = \array_merge($discounts, $result); $result = array_merge($discounts, $result);
} }
return $result; return $result;
...@@ -103,7 +107,7 @@ public static function getProductDiscounts(Product $Product): array ...@@ -103,7 +107,7 @@ public static function getProductDiscounts(Product $Product): array
/** /**
* Return all active discounts which are usable by the user * Return all active discounts which are usable by the user
* *
* @param \QUI\Interfaces\Users\User $User * @param UserInterface $User
* @return array * @return array
* *
* @throws \QUI\Database\Exception * @throws \QUI\Database\Exception
...@@ -111,16 +115,16 @@ public static function getProductDiscounts(Product $Product): array ...@@ -111,16 +115,16 @@ public static function getProductDiscounts(Product $Product): array
public static function getActiveUserDiscounts(UserInterface $User): array public static function getActiveUserDiscounts(UserInterface $User): array
{ {
$guString = UserGroups::getUserGroupStringFromUser($User); $guString = UserGroups::getUserGroupStringFromUser($User);
$guString = ','.\str_replace(',', ',|,', $guString).','; $guString = ',' . str_replace(',', ',|,', $guString) . ',';
$result = []; $result = [];
$Discounts = new Handler(); $Discounts = new Handler();
$personalDiscounts = $Discounts->getChildren([ $personalDiscounts = $Discounts->getChildren([
'where' => [ 'where' => [
'active' => 1, 'active' => 1,
'user_groups' => [ 'user_groups' => [
'type' => 'REGEXP', 'type' => 'REGEXP',
'value' => $guString 'value' => $guString
] ]
] ]
...@@ -128,31 +132,31 @@ public static function getActiveUserDiscounts(UserInterface $User): array ...@@ -128,31 +132,31 @@ public static function getActiveUserDiscounts(UserInterface $User): array
$discounts = $Discounts->getChildren([ $discounts = $Discounts->getChildren([
'where' => [ 'where' => [
'active' => 1, 'active' => 1,
'user_groups' => '' 'user_groups' => ''
] ]
]); ]);
$discountsNULL = $Discounts->getChildren([ $discountsNULL = $Discounts->getChildren([
'where' => [ 'where' => [
'active' => 1, 'active' => 1,
'user_groups' => null 'user_groups' => null
] ]
]); ]);
$discounts = \array_merge($discounts, $discountsNULL); $discounts = array_merge($discounts, $discountsNULL);
if (!empty($personalDiscounts)) { if (!empty($personalDiscounts)) {
$result = \array_merge($personalDiscounts, $result); $result = array_merge($personalDiscounts, $result);
} }
if (!empty($discounts)) { if (!empty($discounts)) {
$result = \array_merge($discounts, $result); $result = array_merge($discounts, $result);
} }
$alreadyAttached = []; $alreadyAttached = [];
$result = \array_filter($result, function ($Discount) use (&$alreadyAttached) { return array_filter($result, function ($Discount) use (&$alreadyAttached) {
/* @var $Discount Discount */ /* @var $Discount Discount */
$id = $Discount->getId(); $id = $Discount->getId();
...@@ -164,15 +168,12 @@ public static function getActiveUserDiscounts(UserInterface $User): array ...@@ -164,15 +168,12 @@ public static function getActiveUserDiscounts(UserInterface $User): array
return true; return true;
}); });
return $result;
} }
/** /**
* Return all active and usable discounts which are usable by the user * Return all active and usable discounts which are usable by the user
* *
* @param \QUI\Interfaces\Users\User $User * @param UserInterface $User
* @return array * @return array
* *
* @throws \QUI\Database\Exception * @throws \QUI\Database\Exception
...@@ -180,7 +181,7 @@ public static function getActiveUserDiscounts(UserInterface $User): array ...@@ -180,7 +181,7 @@ public static function getActiveUserDiscounts(UserInterface $User): array
public static function getUsableUserDiscounts(UserInterface $User): array public static function getUsableUserDiscounts(UserInterface $User): array
{ {
$discounts = self::getActiveUserDiscounts($User); $discounts = self::getActiveUserDiscounts($User);
$result = []; $result = [];
/* @var $Discount Discount */ /* @var $Discount Discount */
foreach ($discounts as $Discount) { foreach ($discounts as $Discount) {
......
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