Skip to content
Code-Schnipsel Gruppen Projekte
Commit fed4f6f4 erstellt von Henning Leutz's avatar Henning Leutz :martial_arts_uniform:
Dateien durchsuchen

chore: discount utils

Übergeordneter cf1a024d
Keine zugehörigen Branchen gefunden
Keine zugehörigen Tags gefunden
Keine zugehörigen Merge Requests gefunden
Pipeline-Nr.
...@@ -129,8 +129,6 @@ define('package/quiqqer/discount/bin/controls/DiscountEdit', [ ...@@ -129,8 +129,6 @@ define('package/quiqqer/discount/bin/controls/DiscountEdit', [
data.discount_type = Discounts.DISCOUNT_TYPE_PERCENT; data.discount_type = Discounts.DISCOUNT_TYPE_PERCENT;
} }
console.log(data);
QUIFormUtils.setDataToForm(data, Form); QUIFormUtils.setDataToForm(data, Form);
self.$Translate = new Translation({ self.$Translate = new Translation({
......
...@@ -74,7 +74,7 @@ ...@@ -74,7 +74,7 @@
<en><![CDATA[Purchase value]]></en> <en><![CDATA[Purchase value]]></en>
</locale> </locale>
<locale name="discount.grid.articles"> <locale name="discount.grid.articles">
<de><![CDATA[Zugewiesene Artikel]]></de> <de><![CDATA[Zugewiesene Produkte]]></de>
<en><![CDATA[Assigned products]]></en> <en><![CDATA[Assigned products]]></en>
</locale> </locale>
<locale name="discount.grid.categories"> <locale name="discount.grid.categories">
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
use QUI\Users\User; use QUI\Users\User;
use QUI\Permissions\Permission; use QUI\Permissions\Permission;
use QUI\Utils\Security\Orthos; use QUI\Utils\Security\Orthos;
use QUI\ERP\Areas\Utils as AreaUtils;
/** /**
* Class Discount * Class Discount
...@@ -114,6 +115,27 @@ public function __construct($id, Handler $Factory) ...@@ -114,6 +115,27 @@ public function __construct($id, Handler $Factory)
)); ));
} }
// cleanup user group save
$cleanup = QUI\Utils\ArrayHelper::cleanup($this->getAttribute('user_groups'));
$cleanup = implode(',', $cleanup);
if (!empty($cleanup)) {
$cleanup = ',' . $cleanup . ',';
}
$this->setAttribute('user_groups', $cleanup);
// cleanup product(s)
$cleanup = QUI\Utils\ArrayHelper::cleanup($this->getAttribute('articles'));
$cleanup = implode(',', $cleanup);
if (!empty($cleanup)) {
$cleanup = ',' . $cleanup . ',';
}
$this->setAttribute('articles', $cleanup);
}); });
} }
...@@ -170,15 +192,28 @@ public function canCombinedWith(Discount $Discount) ...@@ -170,15 +192,28 @@ public function canCombinedWith(Discount $Discount)
/** /**
* is the user allowed to use the discount * is the user allowed to use the discount
* *
* @param User $User * @param QUI\Interfaces\Users\User $User
* @return boolean * @return boolean
*/ */
public function canUsedBy(User $User) public function canUsedBy(QUI\Interfaces\Users\User $User)
{ {
if ($this->isActive() === false) { if ($this->isActive() === false) {
return false; return false;
} }
$userGroupValue = $this->getAttribute('user_groups');
$areasValue = $this->getAttribute('areas');
// if groups and areas are empty, everbody is allowed
if (empty($userGroupValue) && empty($areasValue)) {
return true;
}
// not in area
if (!empty($areasValue) && !AreaUtils::isUserInAreas($User, $areasValue)) {
return false;
}
$userGroups = QUI\Utils\UserGroups::parseUsersGroupsString( $userGroups = QUI\Utils\UserGroups::parseUsersGroupsString(
$this->getAttribute('user_groups') $this->getAttribute('user_groups')
); );
......
<?php
/**
* This file contains QUI\ERP\Discount\Utils
*/
namespace QUI\ERP\Discount;
use QUI\ERP\Products\Product\Product;
use QUI\Utils\UserGroups;
use QUI\Interfaces\Users\User as UserInterface;
/**
* Class Utils
*
* @package QUI\ERP\Discount
*/
class Utils
{
/**
* Return all discounts which are usable by the user
*
* @param \QUI\Interfaces\Users\User $User
* @return array
*/
public static function getUserDiscounts(UserInterface $User)
{
$guString = UserGroups::getUserGroupStringFromUser($User);
$guString = ',' . str_replace(',', ',|,', $guString) . ',';
$result = array();
$Discounts = new Handler();
$personalDiscounts = $Discounts->getChildren(array(
'where' => array(
'user_groups' => array(
'type' => 'REGEXP',
'value' => $guString
)
)
));
$discounts = $Discounts->getChildren(array(
'where' => array(
'user_groups' => ''
)
));
if (!empty($personalDiscounts)) {
$result = array_merge($personalDiscounts, $result);
}
if (!empty($discounts)) {
$result = array_merge($discounts, $result);
}
return $result;
}
/**
* Return all discounts which are usable with the product
*
* @param Product $Product
* @return array
*/
public static function getProductDiscounts(Product $Product)
{
$result = array();
$Discounts = new Handler();
$productDiscounts = $Discounts->getChildren(array(
'where' => array(
'user_groups' => array(
'type' => 'REGEXP',
'value' => ',' . $Product->getId() . ','
)
)
));
$discounts = $Discounts->getChildren(array(
'where' => array(
'user_groups' => ''
)
));
if (!empty($productDiscounts)) {
$result = array_merge($productDiscounts, $result);
}
if (!empty($discounts)) {
$result = array_merge($discounts, $result);
}
return $result;
}
/**
* Return all active discounts which are usable by the user
*
* @param \QUI\Interfaces\Users\User $User
* @return array
*/
public static function getActiveUserDiscounts(UserInterface $User)
{
$guString = UserGroups::getUserGroupStringFromUser($User);
$guString = ',' . str_replace(',', ',|,', $guString) . ',';
$result = array();
$Discounts = new Handler();
$personalDiscounts = $Discounts->getChildren(array(
'where' => array(
'active' => 1,
'user_groups' => array(
'type' => 'REGEXP',
'value' => $guString
)
)
));
$discounts = $Discounts->getChildren(array(
'where' => array(
'active' => 1,
'user_groups' => ''
)
));
if (!empty($personalDiscounts)) {
$result = array_merge($personalDiscounts, $result);
}
if (!empty($discounts)) {
$result = array_merge($discounts, $result);
}
return $result;
}
/**
* Return all active and usable discounts which are usable by the user
*
* @param \QUI\Interfaces\Users\User $User
* @return array
*/
public static function getUsableUserDiscounts(UserInterface $User)
{
$discounts = self::getActiveUserDiscounts($User);
$result = array();
/* @var $Discount Discount */
foreach ($discounts as $Discount) {
if ($Discount->canUsedBy($User)) {
$result[] = $Discount;
}
}
return $result;
}
}
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