Skip to content
Code-Schnipsel Gruppen Projekte

Revisionen vergleichen

Änderungen werden so angezeigt, als ob die Quellrevision mit der Zielrevision zusammengeführt würde. Erfahre mehr über den Vergleich von Revisionen.

Quelle

Zielprojekt auswählen
No results found

Ziel

Zielprojekt auswählen
  • quiqqer/discount
1 Ergebnis
Änderungen anzeigen
Commits auf Quelle (11)
werden angezeigt mit 214 Ergänzungen und 169 Löschungen
tools/
phpstan.neon
.phpunit.result.cache
phpunit.xml
\ No newline at end of file
<?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>
......@@ -9,13 +9,16 @@
*
* @param integer $discountId - Discount-ID
*/
use QUI\ERP\Discount\Discount;
QUI::$Ajax->registerFunction(
'package_quiqqer_discount_ajax_activate',
function ($discountId) {
$Handler = new QUI\ERP\Discount\Handler();
$Handler = new QUI\ERP\Discount\Handler();
$Discount = $Handler->getChild($discountId);
/* @var $Discount \QUI\ERP\Discount\Discount */
/* @var $Discount Discount */
$Discount->setAttribute('active', 1);
$Discount->update();
......
......@@ -12,7 +12,7 @@
QUI::$Ajax->registerFunction(
'package_quiqqer_discount_ajax_create',
function ($params) {
$params = json_decode($params, true);
$params = json_decode($params, true);
$Discounts = new QUI\ERP\Discount\Handler();
if (!isset($params['active'])) {
......
......@@ -9,13 +9,16 @@
*
* @param integer $discountId - Discount-ID
*/
use QUI\ERP\Discount\Discount;
QUI::$Ajax->registerFunction(
'package_quiqqer_discount_ajax_deactivate',
function ($discountId) {
$Handler = new QUI\ERP\Discount\Handler();
$Handler = new QUI\ERP\Discount\Handler();
$Discount = $Handler->getChild($discountId);
/* @var $Discount \QUI\ERP\Discount\Discount */
/* @var $Discount Discount */
$Discount->setAttribute('active', 0);
$Discount->update();
......
......@@ -15,7 +15,7 @@
'package_quiqqer_discount_ajax_deleteChild',
function ($discountId) {
$Discounts = new QUI\ERP\Discount\Handler();
$Discount = $Discounts->getChild($discountId);
$Discount = $Discounts->getChild($discountId);
$Discount->delete();
},
['discountId'],
......
......@@ -14,8 +14,8 @@
QUI::$Ajax->registerFunction(
'package_quiqqer_discount_ajax_deleteChildren',
function ($discountIds) {
$discountIds = json_decode($discountIds, true);
$Discounts = new QUI\ERP\Discount\Handler();
$discountIds = json_decode($discountIds, true);
$Discounts = new QUI\ERP\Discount\Handler();
$ExceptionStack = new QUI\ExceptionStack();
foreach ($discountIds as $discountId) {
......
......@@ -11,14 +11,17 @@
*
* @return array
*/
use QUI\ERP\Discount\Discount;
QUI::$Ajax->registerFunction(
'package_quiqqer_discount_ajax_get',
function ($id) {
$Discounts = new QUI\ERP\Discount\Handler();
$Discount = $Discounts->getChild($id);
$Discounts = new QUI\ERP\Discount\Handler();
$Discount = $Discounts->getChild($id);
$attributes = $Discount->getAttributes();
/* @var $Discount \QUI\ERP\Discount\Discount */
/* @var $Discount Discount */
$attributes['title'] = $Discount->getTitle();
return $attributes;
......
......@@ -20,7 +20,7 @@ function ($params) {
$Locale = QUI::getLocale();
// search
$params = $Grid->parseDBParams(\json_decode($params, true));
$params = $Grid->parseDBParams(json_decode($params, true));
$params['where'] = [
'hidden' => 0
......
......@@ -9,13 +9,16 @@
*
* @param integer $discountId - Discount-ID
*/
use QUI\ERP\Discount\Discount;
QUI::$Ajax->registerFunction(
'package_quiqqer_discount_ajax_toggle',
function ($discountId) {
$Handler = new QUI\ERP\Discount\Handler();
$Handler = new QUI\ERP\Discount\Handler();
$Discount = $Handler->getChild($discountId);
/* @var $Discount \QUI\ERP\Discount\Discount */
/* @var $Discount Discount */
if ($Discount->isActive()) {
$Discount->setAttribute('active', 0);
} else {
......
......@@ -16,8 +16,8 @@
'package_quiqqer_discount_ajax_update',
function ($discountId, $params) {
$Discounts = new QUI\ERP\Discount\Handler();
$Discount = $Discounts->getChild($discountId);
$params = json_decode($params, true);
$Discount = $Discounts->getChild($discountId);
$params = json_decode($params, true);
$Discount->setAttributes($params);
$Discount->update();
......
{
"name": "quiqqer\/discount",
"name": "quiqqer/discount",
"type": "quiqqer-plugin",
"description": "Create discounts for user groups, specific users as well as time controlled.",
"license": [
......@@ -9,25 +9,25 @@
{
"name": "Henning Leutz",
"email": "leutz@pcsg.de",
"homepage": "http:\/\/www.pcsg.de",
"homepage": "https://www.pcsg.de",
"role": "Developer"
}
],
"support": {
"email": "support@pcsg.de",
"url": "http:\/\/www.pcsg.de"
"url": "https://www.pcsg.de"
},
"require": {
"php": ">=5.3",
"quiqqer\/quiqqer": "*@dev",
"quiqqer\/areas": "*@dev",
"quiqqer\/products": "^1.6|*@dev",
"quiqqer\/tax": "*@dev"
"php": "^8.2",
"quiqqer/core": "^2",
"quiqqer/areas": "^2",
"quiqqer/products": "^2",
"quiqqer/tax": "^2"
},
"autoload": {
"psr-4": {
"QUI\\ERP\\Discount\\": "src\/QUI\/ERP\/Discount",
"QUITests\\ERP\\Discount\\": "tests\/QUITests\/ERP\/Discount"
"QUI\\ERP\\Discount\\": "src/QUI/ERP/Discount",
"QUITests\\ERP\\Discount\\": "tests/QUITests/ERP/Discount"
}
}
}
includes:
- phpstan-baseline.neon
parameters:
level: 1
paths:
- src
- ajax
bootstrapFiles:
- tests/phpstan-bootstrap.php
\ No newline at end of file
......@@ -7,12 +7,25 @@
namespace QUI\ERP\Discount;
use QUI;
use QUI\Database\Exception;
use QUI\ERP\Order\OrderInterface;
use QUI\ERP\Products\Interfaces\PriceFactorInterface;
use QUI\ERP\Products\Interfaces\PriceFactorWithVatInterface;
use QUI\ERP\Products\Utils\PriceFactor;
use QUI\Users\User;
use QUI\Permissions\Permission;
use QUI\Utils\Security\Orthos;
use QUI\ERP\Areas\Utils as AreaUtils;
use function array_key_exists;
use function explode;
use function implode;
use function is_array;
use function is_numeric;
use function is_string;
use function strtotime;
use function time;
/**
* Class Discount
* @package QUI\ERP\Discount
......@@ -24,6 +37,7 @@ class Discount extends QUI\CRUD\Child
*
* @param int $id
* @param Handler $Factory
* @throws Exception
*/
public function __construct($id, Handler $Factory)
{
......@@ -61,7 +75,7 @@ public function __construct($id, Handler $Factory)
// cleanup user group save
$cleanup = QUI\Utils\ArrayHelper::cleanup($this->getAttribute('user_groups'));
$cleanup = \implode(',', $cleanup);
$cleanup = implode(',', $cleanup);
if (!empty($cleanup)) {
$cleanup = ',' . $cleanup . ',';
......@@ -72,7 +86,7 @@ public function __construct($id, Handler $Factory)
// cleanup product(s)
$cleanup = QUI\Utils\ArrayHelper::cleanup($this->getAttribute('articles'));
$cleanup = \implode(',', $cleanup);
$cleanup = implode(',', $cleanup);
if (!empty($cleanup)) {
$cleanup = ',' . $cleanup . ',';
......@@ -83,7 +97,7 @@ public function __construct($id, Handler $Factory)
// cleanup user group save
$cleanup = QUI\Utils\ArrayHelper::cleanup($this->getAttribute('user_groups'));
$cleanup = \implode(',', $cleanup);
$cleanup = implode(',', $cleanup);
if (!empty($cleanup)) {
$cleanup = ',' . $cleanup . ',';
......@@ -94,7 +108,7 @@ public function __construct($id, Handler $Factory)
// cleanup product(s)
$cleanup = QUI\Utils\ArrayHelper::cleanup($this->getAttribute('articles'));
$cleanup = \implode(',', $cleanup);
$cleanup = implode(',', $cleanup);
if (!empty($cleanup)) {
$cleanup = ',' . $cleanup . ',';
......@@ -203,29 +217,29 @@ public function __construct($id, Handler $Factory)
}
/**
* @param string $key
* @param array|bool|object|string $value
* @return QUI\QDOM|void
* @param string $name
* @param mixed $value
* @return void
*/
public function setAttribute($key, $value)
public function setAttribute(string $name, mixed $value): void
{
if ($key === 'lastSumDiscount' && empty($value)) {
if ($name === 'lastSumDiscount' && empty($value)) {
$value = null;
}
if ($key === 'lastProductDiscount' && empty($value)) {
if ($name === 'lastProductDiscount' && empty($value)) {
$value = null;
}
if (
$key === 'scope' ||
$key === 'discount_type' ||
$key === 'usage_type'
$name === 'scope' ||
$name === 'discount_type' ||
$name === 'usage_type'
) {
$value = (int)$value;
}
parent::setAttribute($key, $value);
parent::setAttribute($name, $value);
}
/**
......@@ -234,7 +248,7 @@ public function setAttribute($key, $value)
* @param null|QUI\Locale $Locale - optional, locale object
* @return string
*/
public function getTitle($Locale = null)
public function getTitle(QUI\Locale $Locale = null): string
{
if (!$Locale) {
$Locale = QUI::getLocale();
......@@ -251,9 +265,9 @@ public function getTitle($Locale = null)
*
* @return boolean
*/
public function isActive()
public function isActive(): bool
{
return $this->getAttribute('active') ? true : false;
return (bool)$this->getAttribute('active');
}
/**
......@@ -262,7 +276,7 @@ public function isActive()
* @param Discount $Discount
* @return bool
*/
public function canCombinedWith(Discount $Discount)
public function canCombinedWith(Discount $Discount): bool
{
$combine = $this->getAttribute('combine');
......@@ -270,16 +284,10 @@ public function canCombinedWith(Discount $Discount)
return false;
}
$combine = \implode($combine, ',');
$combine = implode($combine, ',');
if (!\is_array($combine)) {
return false;
}
foreach ($combine as $combineId) {
if ($Discount->getId() == $combineId) {
return true;
}
if (in_array($Discount->getId(), (array)$combine)) {
return true;
}
return false;
......@@ -291,7 +299,7 @@ public function canCombinedWith(Discount $Discount)
* @param QUI\Interfaces\Users\User $User
* @return boolean
*/
public function canUsedBy(QUI\Interfaces\Users\User $User)
public function canUsedBy(QUI\Interfaces\Users\User $User): bool
{
if ($this->isActive() === false) {
return false;
......@@ -300,13 +308,13 @@ public function canUsedBy(QUI\Interfaces\Users\User $User)
// usage definitions / limits
$dateFrom = $this->getAttribute('date_from');
$dateUntil = $this->getAttribute('date_until');
$now = \time();
$now = time();
if ($dateFrom && \strtotime($dateFrom) > $now) {
if ($dateFrom && strtotime($dateFrom) > $now) {
return false;
}
if ($dateUntil && \strtotime($dateUntil) < $now) {
if ($dateUntil && strtotime($dateUntil) < $now) {
return false;
}
......@@ -314,7 +322,7 @@ public function canUsedBy(QUI\Interfaces\Users\User $User)
$userGroupValue = $this->getAttribute('user_groups');
$areasValue = $this->getAttribute('areas');
// if groups and areas are empty, everbody is allowed
// if groups and areas are empty, everybody is allowed
if (empty($userGroupValue) && empty($areasValue)) {
return true;
}
......@@ -336,6 +344,10 @@ public function canUsedBy(QUI\Interfaces\Users\User $User)
if ($User->getId() == $uid) {
return true;
}
if ($User->getUUID() == $uid) {
return true;
}
}
// group checking
......@@ -344,7 +356,11 @@ public function canUsedBy(QUI\Interfaces\Users\User $User)
/* @var $Group QUI\Groups\Group */
foreach ($discountGroups as $gid) {
foreach ($groupsOfUser as $Group) {
if ($Group->getId() == $gid) {
if ($Group->getUsers() == $gid) {
return true;
}
if ($Group->getUUID() == $gid) {
return true;
}
}
......@@ -359,26 +375,26 @@ public function canUsedBy(QUI\Interfaces\Users\User $User)
* @param QUI\ERP\Products\Interfaces\ProductInterface $Product
* @return boolean
*/
public function canUsedWith(QUI\ERP\Products\Interfaces\ProductInterface $Product)
public function canUsedWith(QUI\ERP\Products\Interfaces\ProductInterface $Product): bool
{
if ($this->isActive() === false) {
return false;
}
// coupon
if ($Product->getId() === '-') {
if ($Product->getId() === -1) {
return false;
}
$articles = $this->getAttribute('articles');
$categories = $this->getAttribute('categories');
if (\is_string($articles)) {
$articles = \explode(',', $articles);
if (is_string($articles)) {
$articles = explode(',', $articles);
}
if (\is_string($categories)) {
$categories = \explode(',', $categories);
if (is_string($categories)) {
$categories = explode(',', $categories);
}
......@@ -388,9 +404,9 @@ public function canUsedWith(QUI\ERP\Products\Interfaces\ProductInterface $Produc
}
// article / product check
if (\is_array($articles)) {
if (is_array($articles)) {
foreach ($articles as $articleId) {
if ((int)$Product->getId() === (int)$articleId) {
if ($Product->getId() === (int)$articleId) {
return true;
}
}
......@@ -401,7 +417,7 @@ public function canUsedWith(QUI\ERP\Products\Interfaces\ProductInterface $Produc
return true;
}
if (!\is_array($categories)) {
if (!is_array($categories)) {
return false;
}
......@@ -410,7 +426,7 @@ public function canUsedWith(QUI\ERP\Products\Interfaces\ProductInterface $Produc
foreach ($productCategories as $Category) {
/* @var $Category QUI\ERP\Products\Category\Category */
if ((int)$Category->getId() === (int)$category) {
if ($Category->getId() === (int)$category) {
return true;
}
}
......@@ -424,7 +440,7 @@ public function canUsedWith(QUI\ERP\Products\Interfaces\ProductInterface $Produc
* @param OrderInterface $Order
* @return bool
*/
public function canUsedInOrder(OrderInterface $Order)
public function canUsedInOrder(OrderInterface $Order): bool
{
if ($this->isActive() === false) {
return false;
......@@ -436,7 +452,7 @@ public function canUsedInOrder(OrderInterface $Order)
/* @var $Article QUI\ERP\Accounting\Article */
$id = $Article->getId();
if (!\is_numeric($id)) {
if (!is_numeric($id)) {
continue;
}
......@@ -446,7 +462,7 @@ public function canUsedInOrder(OrderInterface $Order)
if ($this->canUsedWith($Product)) {
return true;
}
} catch (QUI\Exception $Exception) {
} catch (QUI\Exception) {
continue;
}
}
......@@ -460,7 +476,7 @@ public function canUsedInOrder(OrderInterface $Order)
* @param Discount $Discount
* @throws QUI\ERP\Discount\Exception
*/
public function verifyCombinationWith(Discount $Discount)
public function verifyCombinationWith(Discount $Discount): void
{
if ($this->canCombinedWith($Discount) === false) {
throw new QUI\ERP\Discount\Exception([
......@@ -480,7 +496,7 @@ public function verifyCombinationWith(Discount $Discount)
* @param User $User
* @throws QUI\ERP\Discount\Exception
*/
public function verifyUser(User $User)
public function verifyUser(User $User): void
{
if ($this->canUsedBy($User) === false) {
throw new QUI\ERP\Discount\Exception([
......@@ -488,7 +504,7 @@ public function verifyUser(User $User)
'exception.discount.user.cant.use.discount',
[
'id' => $this->getId(),
'userId' => $User->getId()
'userId' => $User->getUUID()
]
]);
}
......@@ -497,13 +513,15 @@ public function verifyUser(User $User)
/**
* Parse the discount to a price factor
*
* @param null|QUI\Locale $Locale - optional, locale object
* @param null|QUI\Interfaces\Users\User $Customer - optional,
* @param null $Locale - optional, locale object
* @param null $Customer - optional,
*
* @return QUI\ERP\Products\Interfaces\PriceFactorWithVatInterface|QUI\ERP\Products\Interfaces\PriceFactorInterface
* @return PriceFactorInterface|PriceFactorWithVatInterface|PriceFactor
*/
public function toPriceFactor($Locale = null, $Customer = null)
{
public function toPriceFactor(
$Locale = null,
$Customer = null
): QUI\ERP\Products\Interfaces\PriceFactorInterface|QUI\ERP\Products\Interfaces\PriceFactorWithVatInterface|QUI\ERP\Products\Utils\PriceFactor {
switch ($this->getAttribute('discount_type')) {
case QUI\ERP\Accounting\Calc::CALCULATION_PERCENTAGE:
$calculation = QUI\ERP\Accounting\Calc::CALCULATION_PERCENTAGE;
......@@ -515,14 +533,10 @@ public function toPriceFactor($Locale = null, $Customer = null)
break;
}
switch ($this->getAttribute('price_calculation_basis')) {
case QUI\ERP\Accounting\Calc::CALCULATION_BASIS_NETTO:
$basis = QUI\ERP\Accounting\Calc::CALCULATION_BASIS_NETTO;
break;
default:
$basis = QUI\ERP\Accounting\Calc::CALCULATION_BASIS_CURRENTPRICE;
}
$basis = match ($this->getAttribute('price_calculation_basis')) {
QUI\ERP\Accounting\Calc::CALCULATION_BASIS_NETTO => QUI\ERP\Accounting\Calc::CALCULATION_BASIS_NETTO,
default => QUI\ERP\Accounting\Calc::CALCULATION_BASIS_CURRENTPRICE,
};
// check calculation basis VAT
$useAuto = $this->getAttribute('consider_vat') === 'auto'
......@@ -542,7 +556,7 @@ public function toPriceFactor($Locale = null, $Customer = null)
$Config = $Plugin->getConfig();
$hideDiscounts = (int)$Config->getValue('products', 'hideDiscounts');
} catch (QUI\Exception $Exception) {
} catch (QUI\Exception) {
$hideDiscounts = false;
}
......@@ -562,7 +576,7 @@ public function toPriceFactor($Locale = null, $Customer = null)
'calculation' => $calculation,
'basis' => $basis,
'value' => $this->getAttribute('discount') * -1,
'visible' => $hideDiscounts ? false : true,
'visible' => !$hideDiscounts,
'vat' => $this->getAttribute('vat')
]);
}
......@@ -577,7 +591,6 @@ public function toPriceFactor($Locale = null, $Customer = null)
'calculation' => $calculation,
'basis' => $basis,
'value' => $this->getAttribute('discount') * -1,
'visible' => $hideDiscounts ? false : true
]);
}
......@@ -586,7 +599,7 @@ public function toPriceFactor($Locale = null, $Customer = null)
*
* @throws QUI\ExceptionStack|QUI\Exception
*/
public function update()
public function update(): void
{
$this->Events->fireEvent('saveBegin');
$this->Events->fireEvent('updateBegin');
......@@ -595,18 +608,16 @@ public function update()
$savedData = [];
foreach ($needles as $needle) {
if (!\array_key_exists($needle, $this->attributes)) {
if (!array_key_exists($needle, $this->attributes)) {
continue;
}
$value = $this->getAttribute($needle);
switch ($needle) {
case 'user_groups':
if (!empty($value)) {
$value = ',' . $value . ',';
}
break;
if ($needle == 'user_groups') {
if (!empty($value)) {
$value = ',' . $value . ',';
}
}
$savedData[$needle] = $value;
......
......@@ -7,11 +7,15 @@
namespace QUI\ERP\Discount;
use QUI;
use QUI\Database\Exception;
use QUI\ERP\Accounting\Calc as ErpCalc;
use QUI\ERP\Products\Product\UniqueProduct;
use QUI\ERP\Products\Utils\Calc;
use QUI\ERP\Products\Product\ProductList;
use function array_filter;
use function explode;
/**
* Class EventHandling
*
......@@ -20,19 +24,19 @@
class EventHandling
{
/**
* @var null
* @var Handler|null
*/
protected static $Handler = null;
protected static ?Handler $Handler = null;
/**
* @var array
*/
protected static $userDiscounts = [];
protected static array $userDiscounts = [];
/**
* Return the global
*
* @return Handler
* @return Handler|null
*/
protected static function getHandler(): ?Handler
{
......@@ -48,16 +52,17 @@ protected static function getHandler(): ?Handler
*
* @param QUI\Interfaces\Users\User $User
* @return array
* @throws Exception
*/
protected static function getUserDiscounts(QUI\Interfaces\Users\User $User): array
{
if (isset(self::$userDiscounts[$User->getId()])) {
return self::$userDiscounts[$User->getId()];
if (isset(self::$userDiscounts[$User->getUUID()])) {
return self::$userDiscounts[$User->getUUID()];
}
self::$userDiscounts[$User->getId()] = Utils::getActiveUserDiscounts($User);
self::$userDiscounts[$User->getUUID()] = Utils::getActiveUserDiscounts($User);
return self::$userDiscounts[$User->getId()];
return self::$userDiscounts[$User->getUUID()];
}
/**
......@@ -65,10 +70,10 @@ protected static function getUserDiscounts(QUI\Interfaces\Users\User $User): arr
* - Einkaufsmengeprüfung
*
* @param Discount $Discount
* @param integer|double $quantity
* @param double|integer $quantity
* @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');
$purchaseQuantityUntil = $Discount->getAttribute('purchase_quantity_until');
......@@ -93,14 +98,14 @@ public static function isDiscountUsableWithQuantity(Discount $Discount, $quantit
}
/**
* Discount pirchase value check for usage
* Discount purchase value check for usage
* - Einkaufswertprüfung
*
* @param Discount $Discount
* @param integer|double $value
* @param float|integer $value
* @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');
$purchaseValueUntil = $Discount->getAttribute('purchase_value_until');
......@@ -136,18 +141,19 @@ public static function isDiscountUsableWithPurchaseValue(Discount $Discount, $va
*
* @param QUI\ERP\Products\Utils\Calc $Calc
* @param UniqueProduct $Product
* @throws Exception
*/
public static function onQuiqqerProductsCalcListProduct(
Calc $Calc,
UniqueProduct $Product
) {
): void {
$userDiscounts = self::getUserDiscounts($Calc->getUser());
if (!\is_array($userDiscounts) || empty($userDiscounts)) {
if (empty($userDiscounts)) {
return;
}
$userDiscounts = \array_filter($userDiscounts, function ($Discount) {
$userDiscounts = array_filter($userDiscounts, function ($Discount) {
/* @var $Discount Discount */
// don't use manuel usage type
......@@ -158,18 +164,11 @@ public static function onQuiqqerProductsCalcListProduct(
return (int)$Discount->getAttribute('scope') === Handler::DISCOUNT_SCOPE_EVERY_PRODUCT;
});
if (!\is_array($userDiscounts) || empty($userDiscounts)) {
return;
}
try {
$attributes = $Product->getAttributes();
} catch (QUI\Exception $Exception) {
QUI\System\Log::writeDebugException($Exception);
if (empty($userDiscounts)) {
return;
}
$attributes = $Product->getAttributes();
$PriceFactors = $Product->getPriceFactors();
$productQuantity = $Product->getQuantity();
$productNettoSum = $attributes['calculated_nettoSum'];
......@@ -184,7 +183,7 @@ public static function onQuiqqerProductsCalcListProduct(
continue;
}
// check if Pricefactor is already in
// check if price factor is already in
$factors = $PriceFactors->toArray();
$Factor = $Discount->toPriceFactor(
$Calc->getUser()->getLocale(),
......@@ -210,20 +209,17 @@ public static function onQuiqqerProductsCalcListProduct(
*
* @param Calc $Calc
* @param ProductList $List
* @param integer|double $nettoSum
* @param float|integer $nettoSum
* @throws Exception
*/
public static function onQuiqqerProductsCalcList(
Calc $Calc,
ProductList $List,
$nettoSum
) {
float|int $nettoSum
): void {
$userDiscounts = self::getUserDiscounts($Calc->getUser());
if (!\is_array($userDiscounts)) {
return;
}
$userDiscounts = \array_filter($userDiscounts, function ($Discount) {
$userDiscounts = array_filter($userDiscounts, function ($Discount) {
/* @var $Discount Discount */
// don't use manuel usage type
......@@ -234,10 +230,6 @@ public static function onQuiqqerProductsCalcList(
return (int)$Discount->getAttribute('scope') == Handler::DISCOUNT_SCOPE_TOTAL;
});
if (!\is_array($userDiscounts)) {
return;
}
$listQuantity = $List->getQuantity();
$products = $List->getProducts();
$PriceFactors = $List->getPriceFactors();
......@@ -256,7 +248,7 @@ public static function onQuiqqerProductsCalcList(
$productIds = $Discount->getAttribute('articles');
if ($productIds) {
$productIds = \explode(',', $productIds);
$productIds = explode(',', $productIds);
// product id check
$existProductIdInList = function ($products, $productIds) {
......@@ -281,7 +273,7 @@ public static function onQuiqqerProductsCalcList(
$categories = $Discount->getAttribute('categories');
if ($categories) {
$categories = \explode(',', $categories);
$categories = explode(',', $categories);
// product category check
$existCategoryInList = function ($products, $categories) {
......
......@@ -7,6 +7,7 @@
namespace QUI\ERP\Discount;
use QUI;
use QUI\Database\Exception;
use QUI\Permissions\Permission;
/**
......@@ -49,7 +50,7 @@ class Handler extends QUI\CRUD\Factory
const DISCOUNT_SCOPE_GRAND_TOTAL = 4;
/**
* pricefactor discount type
* price factor discount type
*/
const DISCOUNT_PRICEFACTOR_TYPE = 'DISCOUNT_PRICE_FACTOR';
......@@ -163,7 +164,7 @@ public function __construct()
*
* @return string
*/
public function getDataBaseTableName()
public function getDataBaseTableName(): string
{
return QUI::getDBTableName('discounts');
}
......@@ -173,7 +174,7 @@ public function getDataBaseTableName()
*
* @return string
*/
public function getChildClass()
public function getChildClass(): string
{
return 'QUI\ERP\Discount\Discount';
}
......@@ -183,7 +184,7 @@ public function getChildClass()
*
* @return array
*/
public function getChildAttributes()
public function getChildAttributes(): array
{
return [
'active',
......@@ -217,8 +218,9 @@ public function getChildAttributes()
*
* @param array $queryParams
* @return array - [Child, Child, Child]
* @throws Exception
*/
public function getChildrenData($queryParams = [])
public function getChildrenData(array $queryParams = []): array
{
if (!isset($queryParams['order'])) {
$queryParams['order'] = 'priority ASC';
......
......@@ -10,22 +10,18 @@
/**
* 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
*/
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
*/
protected string $type = Handler::DISCOUNT_PRICEFACTOR_TYPE;
/**
* @var string|null
*/
protected $vat = null;
/**
* PriceFactor constructor.
* @param array $params
......@@ -45,7 +41,7 @@ public function __construct(array $params)
* @return QUI\ERP\Tax\TaxType
* @throws QUI\Exception
*/
public function getVatType()
public function getVatType(): QUI\ERP\Tax\TaxType
{
if (!$this->vat) {
return QUI\ERP\Tax\Utils::getShopTaxType();
......@@ -61,7 +57,7 @@ public function getVatType()
$Handler = new QUI\ERP\Tax\Handler();
return $Handler->getTaxType($standardTax[1]);
} catch (QUI\Exception $Exception) {
} catch (QUI\Exception) {
}
return QUI\ERP\Tax\Utils::getShopTaxType();
......
......@@ -10,6 +10,10 @@
use QUI\Utils\UserGroups;
use QUI\Interfaces\Users\User as UserInterface;
use function array_filter;
use function array_merge;
use function str_replace;
/**
* Class Utils
*
......@@ -20,7 +24,7 @@ class Utils
/**
* Return all discounts which are usable by the user
*
* @param \QUI\Interfaces\Users\User $User
* @param UserInterface $User
* @return array
*
* @throws \QUI\Database\Exception
......@@ -28,7 +32,7 @@ class Utils
public static function getUserDiscounts(UserInterface $User): array
{
$guString = UserGroups::getUserGroupStringFromUser($User);
$guString = ',' . \str_replace(',', ',|,', $guString) . ',';
$guString = ',' . str_replace(',', ',|,', $guString) . ',';
$result = [];
$Discounts = new Handler();
......@@ -50,11 +54,11 @@ public static function getUserDiscounts(UserInterface $User): array
if (!empty($personalDiscounts)) {
$result = \array_merge($personalDiscounts, $result);
$result = array_merge($personalDiscounts, $result);
}
if (!empty($discounts)) {
$result = \array_merge($discounts, $result);
$result = array_merge($discounts, $result);
}
return $result;
......@@ -90,11 +94,11 @@ public static function getProductDiscounts(Product $Product): array
if (!empty($productDiscounts)) {
$result = \array_merge($productDiscounts, $result);
$result = array_merge($productDiscounts, $result);
}
if (!empty($discounts)) {
$result = \array_merge($discounts, $result);
$result = array_merge($discounts, $result);
}
return $result;
......@@ -103,7 +107,7 @@ public static function getProductDiscounts(Product $Product): array
/**
* Return all active discounts which are usable by the user
*
* @param \QUI\Interfaces\Users\User $User
* @param UserInterface $User
* @return array
*
* @throws \QUI\Database\Exception
......@@ -111,7 +115,7 @@ public static function getProductDiscounts(Product $Product): array
public static function getActiveUserDiscounts(UserInterface $User): array
{
$guString = UserGroups::getUserGroupStringFromUser($User);
$guString = ',' . \str_replace(',', ',|,', $guString) . ',';
$guString = ',' . str_replace(',', ',|,', $guString) . ',';
$result = [];
$Discounts = new Handler();
......@@ -140,19 +144,19 @@ public static function getActiveUserDiscounts(UserInterface $User): array
]
]);
$discounts = \array_merge($discounts, $discountsNULL);
$discounts = array_merge($discounts, $discountsNULL);
if (!empty($personalDiscounts)) {
$result = \array_merge($personalDiscounts, $result);
$result = array_merge($personalDiscounts, $result);
}
if (!empty($discounts)) {
$result = \array_merge($discounts, $result);
$result = array_merge($discounts, $result);
}
$alreadyAttached = [];
$result = \array_filter($result, function ($Discount) use (&$alreadyAttached) {
return array_filter($result, function ($Discount) use (&$alreadyAttached) {
/* @var $Discount Discount */
$id = $Discount->getId();
......@@ -164,15 +168,12 @@ public static function getActiveUserDiscounts(UserInterface $User): array
return true;
});
return $result;
}
/**
* Return all active and usable discounts which are usable by the user
*
* @param \QUI\Interfaces\Users\User $User
* @param UserInterface $User
* @return array
*
* @throws \QUI\Database\Exception
......
<?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';