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 @@
*
* @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;
......
......@@ -14,13 +14,13 @@
QUI::$Ajax->registerFunction(
'package_quiqqer_discount_ajax_list',
function ($params) {
$Grid = new QUI\Utils\Grid();
$Grid = new QUI\Utils\Grid();
$Discounts = new QUI\ERP\Discount\Handler();
$result = [];
$Locale = QUI::getLocale();
$result = [];
$Locale = QUI::getLocale();
// search
$params = $Grid->parseDBParams(\json_decode($params, true));
$params = $Grid->parseDBParams(json_decode($params, true));
$params['where'] = [
'hidden' => 0
......@@ -31,15 +31,15 @@ function ($params) {
foreach ($data as $entry) {
$entry['title'] = [
'quiqqer/discount',
'discount.'.$entry['id'].'.title'
'discount.' . $entry['id'] . '.title'
];
$entry['text'] = $Locale->get(
'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'];
// attributes
......
......@@ -15,12 +15,12 @@
'package_quiqqer_discount_ajax_search',
function ($fields, $params) {
$Discounts = new QUI\ERP\Discount\Handler();
$result = [];
$Locale = QUI::getLocale();
$result = [];
$Locale = QUI::getLocale();
$allowedFields = $Discounts->getChildAttributes();
$query = [];
$query = [];
$params = json_decode($params, true);
$fields = json_decode($fields, true);
......@@ -44,7 +44,7 @@ function ($fields, $params) {
}
$query['where_or'][$field] = [
'type' => '%LIKE%',
'type' => '%LIKE%',
'value' => $value
];
}
......@@ -55,12 +55,12 @@ function ($fields, $params) {
foreach ($data as $entry) {
$entry['title'] = [
'quiqqer/discount',
'discount.'.$entry['id'].'.title'
'discount.' . $entry['id'] . '.title'
];
$entry['text'] = $Locale->get(
'quiqqer/discount',
'discount.'.$entry['id'].'.title'
'discount.' . $entry['id'] . '.title'
);
$result[] = $entry;
......
......@@ -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();
......
Dieser Diff ist reduziert.
......@@ -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,6 +52,7 @@ 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
{
......@@ -65,12 +70,12 @@ 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');
$purchaseQuantityFrom = $Discount->getAttribute('purchase_quantity_from');
$purchaseQuantityUntil = $Discount->getAttribute('purchase_quantity_until');
if ($quantity === 0) {
......@@ -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
*
* @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');
$purchaseValueFrom = $Discount->getAttribute('purchase_value_from');
$purchaseValueUntil = $Discount->getAttribute('purchase_value_until');
// wenn complement, z.B. 10€, muss geprüft werden
// ob meine value grösser ist als der gegebene value
if ((int)$Discount->getAttribute('discount_type') === ErpCalc::CALCULATION_COMPLEMENT
&& $Discount->getAttribute('discount') > $value) {
if (
(int)$Discount->getAttribute('discount_type') === ErpCalc::CALCULATION_COMPLEMENT
&& $Discount->getAttribute('discount') > $value
) {
return false;
}
......@@ -134,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
......@@ -156,7 +164,7 @@ public static function onQuiqqerProductsCalcListProduct(
return (int)$Discount->getAttribute('scope') === Handler::DISCOUNT_SCOPE_EVERY_PRODUCT;
});
if (!\is_array($userDiscounts) || empty($userDiscounts)) {
if (empty($userDiscounts)) {
return;
}
......@@ -168,7 +176,7 @@ public static function onQuiqqerProductsCalcListProduct(
return;
}
$PriceFactors = $Product->getPriceFactors();
$PriceFactors = $Product->getPriceFactors();
$productQuantity = $Product->getQuantity();
$productNettoSum = $attributes['calculated_nettoSum'];
......@@ -184,7 +192,7 @@ public static function onQuiqqerProductsCalcListProduct(
// check if Pricefactor is already in
$factors = $PriceFactors->toArray();
$Factor = $Discount->toPriceFactor(
$Factor = $Discount->toPriceFactor(
$Calc->getUser()->getLocale(),
$Calc->getUser()
);
......@@ -208,20 +216,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
......@@ -232,12 +237,8 @@ public static function onQuiqqerProductsCalcList(
return (int)$Discount->getAttribute('scope') == Handler::DISCOUNT_SCOPE_TOTAL;
});
if (!\is_array($userDiscounts)) {
return;
}
$listQuantity = $List->getQuantity();
$products = $List->getProducts();
$products = $List->getProducts();
$PriceFactors = $List->getPriceFactors();
/* @var $Discount Discount */
......@@ -254,7 +255,7 @@ public static function onQuiqqerProductsCalcList(
$productIds = $Discount->getAttribute('articles');
if ($productIds) {
$productIds = \explode(',', $productIds);
$productIds = explode(',', $productIds);
// product id check
$existProductIdInList = function ($products, $productIds) {
......@@ -279,7 +280,7 @@ public static function onQuiqqerProductsCalcList(
$categories = $Discount->getAttribute('categories');
if ($categories) {
$categories = \explode(',', $categories);
$categories = explode(',', $categories);
// product category check
$existCategoryInList = function ($products, $categories) {
......@@ -307,7 +308,7 @@ public static function onQuiqqerProductsCalcList(
// check if Pricefactor is already in
$factors = $PriceFactors->toArray();
$Factor = $Discount->toPriceFactor(
$Factor = $Discount->toPriceFactor(
$Calc->getUser()->getLocale(),
$Calc->getUser()
);
......
......@@ -7,6 +7,7 @@
namespace QUI\ERP\Discount;
use QUI;
use QUI\Database\Exception;
use QUI\Permissions\Permission;
/**
......@@ -130,7 +131,7 @@ public function __construct()
// create new translation var for the discount
$this->Events->addEvent('onCreateEnd', function ($New, $data) {
/* @var $New QUI\ERP\Discount\Discount */
$newVar = 'discount.'.$New->getId().'.title';
$newVar = 'discount.' . $New->getId() . '.title';
$current = QUI::getLocale()->getCurrent();
$title = $New->getAttribute('title');
......@@ -146,9 +147,9 @@ public function __construct()
try {
QUI\Translator::addUserVar('quiqqer/discount', $newVar, [
$current => $title,
$current => $title,
'datatype' => 'php,js',
'package' => 'quiqqer/discount'
'package' => 'quiqqer/discount'
]);
} catch (QUI\Exception $Exception) {
QUI::getMessagesHandler()->addAttention(
......@@ -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,11 +10,12 @@
/**
* 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
......@@ -45,7 +46,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 +62,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,15 +32,15 @@ class Utils
public static function getUserDiscounts(UserInterface $User): array
{
$guString = UserGroups::getUserGroupStringFromUser($User);
$guString = ','.\str_replace(',', ',|,', $guString).',';
$guString = ',' . str_replace(',', ',|,', $guString) . ',';
$result = [];
$result = [];
$Discounts = new Handler();
$personalDiscounts = $Discounts->getChildren([
'where' => [
'user_groups' => [
'type' => 'REGEXP',
'type' => 'REGEXP',
'value' => $guString
]
]
......@@ -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;
......@@ -70,14 +74,14 @@ public static function getUserDiscounts(UserInterface $User): array
*/
public static function getProductDiscounts(Product $Product): array
{
$result = [];
$result = [];
$Discounts = new Handler();
$productDiscounts = $Discounts->getChildren([
'where' => [
'user_groups' => [
'type' => 'REGEXP',
'value' => ','.$Product->getId().','
'type' => 'REGEXP',
'value' => ',' . $Product->getId() . ','
]
]
]);
......@@ -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,16 +115,16 @@ 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 = [];
$result = [];
$Discounts = new Handler();
$personalDiscounts = $Discounts->getChildren([
'where' => [
'active' => 1,
'active' => 1,
'user_groups' => [
'type' => 'REGEXP',
'type' => 'REGEXP',
'value' => $guString
]
]
......@@ -128,31 +132,31 @@ public static function getActiveUserDiscounts(UserInterface $User): array
$discounts = $Discounts->getChildren([
'where' => [
'active' => 1,
'active' => 1,
'user_groups' => ''
]
]);
$discountsNULL = $Discounts->getChildren([
'where' => [
'active' => 1,
'active' => 1,
'user_groups' => null
]
]);
$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
......@@ -180,7 +181,7 @@ public static function getActiveUserDiscounts(UserInterface $User): array
public static function getUsableUserDiscounts(UserInterface $User): array
{
$discounts = self::getActiveUserDiscounts($User);
$result = [];
$result = [];
/* @var $Discount 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