diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 0000000000000000000000000000000000000000..b8d20acb6c365ad8036a7b36d47dabd876d08efa --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,3 @@ +include: + - project: 'quiqqer/stabilization/semantic-release' + file: '/ci-templates/.gitlab-ci.yml' diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000000000000000000000000000000000000..a01d4040be8d75cd5e7e277e2951a0182588d9aa --- /dev/null +++ b/LICENSE @@ -0,0 +1 @@ +PCSG QEL-1.0 \ No newline at end of file diff --git a/ajax/list.php b/ajax/list.php index ccab3b3554eb2862696e28bfb87af3d2aeaef79a..c01ebe6796519bebcf4692c1f426e3a4b3561e2a 100644 --- a/ajax/list.php +++ b/ajax/list.php @@ -14,10 +14,10 @@ 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)); @@ -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 diff --git a/ajax/search.php b/ajax/search.php index ed5bed6b547b04777961ce1beace37b9b0e28848..0dfdbc15dbc5e7e7c0dfa2187107fe0f6858f075 100644 --- a/ajax/search.php +++ b/ajax/search.php @@ -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; diff --git a/src/QUI/ERP/Discount/Discount.php b/src/QUI/ERP/Discount/Discount.php index 0c158d8ece863bbc9971e2737e4425b91065d4dd..2715d73681b662bdb25545db46ae9eaf77858022 100644 --- a/src/QUI/ERP/Discount/Discount.php +++ b/src/QUI/ERP/Discount/Discount.php @@ -11,7 +11,6 @@ use QUI\Users\User; use QUI\Permissions\Permission; use QUI\Utils\Security\Orthos; - use QUI\ERP\Areas\Utils as AreaUtils; /** @@ -65,7 +64,7 @@ public function __construct($id, Handler $Factory) $cleanup = \implode(',', $cleanup); if (!empty($cleanup)) { - $cleanup = ','.$cleanup.','; + $cleanup = ',' . $cleanup . ','; } $this->setAttribute('user_groups', $cleanup); @@ -76,7 +75,7 @@ public function __construct($id, Handler $Factory) $cleanup = \implode(',', $cleanup); if (!empty($cleanup)) { - $cleanup = ','.$cleanup.','; + $cleanup = ',' . $cleanup . ','; } $this->setAttribute('articles', $cleanup); @@ -87,7 +86,7 @@ public function __construct($id, Handler $Factory) $cleanup = \implode(',', $cleanup); if (!empty($cleanup)) { - $cleanup = ','.$cleanup.','; + $cleanup = ',' . $cleanup . ','; } $this->setAttribute('user_groups', $cleanup); @@ -98,7 +97,7 @@ public function __construct($id, Handler $Factory) $cleanup = \implode(',', $cleanup); if (!empty($cleanup)) { - $cleanup = ','.$cleanup.','; + $cleanup = ',' . $cleanup . ','; } $this->setAttribute('articles', $cleanup); @@ -112,14 +111,15 @@ public function __construct($id, Handler $Factory) $this->Events->addEvent('onDeleteEnd', function () { QUI\Translator::delete( 'quiqqer/discount', - 'discount.'.$this->getId().'.title' + 'discount.' . $this->getId() . '.title' ); }); $this->Events->addEvent('onSaveBegin', function () { Permission::checkPermission('quiqqer.areas.area.edit'); - if ($this->getAttribute('date_from') + if ( + $this->getAttribute('date_from') && !Orthos::checkMySqlDatetimeSyntax($this->getAttribute('date_from')) ) { throw new QUI\ERP\Discount\Exception([ @@ -128,7 +128,8 @@ public function __construct($id, Handler $Factory) ]); } - if ($this->getAttribute('date_until') + if ( + $this->getAttribute('date_until') && !Orthos::checkMySqlDatetimeSyntax($this->getAttribute('date_until')) ) { throw new QUI\ERP\Discount\Exception([ @@ -137,10 +138,10 @@ public function __construct($id, Handler $Factory) ]); } - $purchaseQuantityFrom = $this->getAttribute('purchase_quantity_from'); + $purchaseQuantityFrom = $this->getAttribute('purchase_quantity_from'); $purchaseQuantityUntil = $this->getAttribute('purchase_quantity_until'); - $purchaseValueFrom = $this->getAttribute('purchase_value_from'); - $purchaseValueUntil = $this->getAttribute('purchase_value_until'); + $purchaseValueFrom = $this->getAttribute('purchase_value_from'); + $purchaseValueUntil = $this->getAttribute('purchase_value_until'); if ($purchaseQuantityFrom !== '' && ($purchaseQuantityFrom === false || $purchaseQuantityFrom < 0)) { throw new QUI\ERP\Discount\Exception([ @@ -216,7 +217,8 @@ public function setAttribute($key, $value) $value = null; } - if ($key === 'scope' || + if ( + $key === 'scope' || $key === 'discount_type' || $key === 'usage_type' ) { @@ -240,7 +242,7 @@ public function getTitle($Locale = null) return $Locale->get( 'quiqqer/discount', - 'discount.'.$this->getId().'.title' + 'discount.' . $this->getId() . '.title' ); } @@ -296,9 +298,9 @@ public function canUsedBy(QUI\Interfaces\Users\User $User) } // usage definitions / limits - $dateFrom = $this->getAttribute('date_from'); + $dateFrom = $this->getAttribute('date_from'); $dateUntil = $this->getAttribute('date_until'); - $now = \time(); + $now = \time(); if ($dateFrom && \strtotime($dateFrom) > $now) { return false; @@ -310,7 +312,7 @@ public function canUsedBy(QUI\Interfaces\Users\User $User) // assignment $userGroupValue = $this->getAttribute('user_groups'); - $areasValue = $this->getAttribute('areas'); + $areasValue = $this->getAttribute('areas'); // if groups and areas are empty, everbody is allowed if (empty($userGroupValue) && empty($areasValue)) { @@ -326,7 +328,7 @@ public function canUsedBy(QUI\Interfaces\Users\User $User) $this->getAttribute('user_groups') ); - $discountUsers = $userGroups['users']; + $discountUsers = $userGroups['users']; $discountGroups = $userGroups['groups']; // user checking @@ -368,7 +370,7 @@ public function canUsedWith(QUI\ERP\Products\Interfaces\ProductInterface $Produc return false; } - $articles = $this->getAttribute('articles'); + $articles = $this->getAttribute('articles'); $categories = $this->getAttribute('categories'); if (\is_string($articles)) { @@ -465,7 +467,7 @@ public function verifyCombinationWith(Discount $Discount) 'quiqqer/discount', 'exception.discount.not.combinable', [ - 'id' => $this->getId(), + 'id' => $this->getId(), 'discountId' => $Discount->getId() ] ]); @@ -485,7 +487,7 @@ public function verifyUser(User $User) 'quiqqer/discount', 'exception.discount.user.cant.use.discount', [ - 'id' => $this->getId(), + 'id' => $this->getId(), 'userId' => $User->getId() ] ]); @@ -524,8 +526,8 @@ public function toPriceFactor($Locale = null, $Customer = null) // check calculation basis VAT $useAuto = $this->getAttribute('consider_vat') === 'auto' - && $Customer - && QUI\ERP\Utils\User::isNettoUser($Customer) === false; + && $Customer + && QUI\ERP\Utils\User::isNettoUser($Customer) === false; if ($useAuto || $this->getAttribute('consider_vat') === 'brutto') { $basis = QUI\ERP\Accounting\Calc::CALCULATION_BASIS_VAT_BRUTTO; @@ -552,30 +554,30 @@ public function toPriceFactor($Locale = null, $Customer = null) } return new PriceFactor([ - 'identifier' => 'discount-'.$this->getId(), - 'title' => $this->getTitle($Locale), - 'valueText' => $valueText, + 'identifier' => 'discount-' . $this->getId(), + 'title' => $this->getTitle($Locale), + 'valueText' => $valueText, 'description' => '', - 'priority' => (int)$this->getAttribute('priority'), + 'priority' => (int)$this->getAttribute('priority'), 'calculation' => $calculation, - 'basis' => $basis, - 'value' => $this->getAttribute('discount') * -1, - 'visible' => $hideDiscounts ? false : true, - 'vat' => $this->getAttribute('vat') + 'basis' => $basis, + 'value' => $this->getAttribute('discount') * -1, + 'visible' => $hideDiscounts ? false : true, + 'vat' => $this->getAttribute('vat') ]); } // to product return new QUI\ERP\Products\Utils\PriceFactor([ - 'identifier' => 'discount-'.$this->getId(), - 'title' => $this->getTitle($Locale), + 'identifier' => 'discount-' . $this->getId(), + 'title' => $this->getTitle($Locale), // 'valueText' => $this->getTitle($Locale), 'description' => '', - 'priority' => (int)$this->getAttribute('priority'), + 'priority' => (int)$this->getAttribute('priority'), 'calculation' => $calculation, - 'basis' => $basis, - 'value' => $this->getAttribute('discount') * -1, - 'visible' => $hideDiscounts ? false : true + 'basis' => $basis, + 'value' => $this->getAttribute('discount') * -1, + 'visible' => $hideDiscounts ? false : true ]); } @@ -589,7 +591,7 @@ public function update() $this->Events->fireEvent('saveBegin'); $this->Events->fireEvent('updateBegin'); - $needles = $this->Factory->getChildAttributes(); + $needles = $this->Factory->getChildAttributes(); $savedData = []; foreach ($needles as $needle) { @@ -602,7 +604,7 @@ public function update() switch ($needle) { case 'user_groups': if (!empty($value)) { - $value = ','.$value.','; + $value = ',' . $value . ','; } break; } diff --git a/src/QUI/ERP/Discount/EventHandling.php b/src/QUI/ERP/Discount/EventHandling.php index 4b452c69fd10ec95544e67c5d854cf6a2ded98e5..ebb506aa8c659a58160e1e8b3af0626430057cbe 100644 --- a/src/QUI/ERP/Discount/EventHandling.php +++ b/src/QUI/ERP/Discount/EventHandling.php @@ -70,7 +70,7 @@ protected static function getUserDiscounts(QUI\Interfaces\Users\User $User): arr */ public static function isDiscountUsableWithQuantity(Discount $Discount, $quantity): bool { - $purchaseQuantityFrom = $Discount->getAttribute('purchase_quantity_from'); + $purchaseQuantityFrom = $Discount->getAttribute('purchase_quantity_from'); $purchaseQuantityUntil = $Discount->getAttribute('purchase_quantity_until'); if ($quantity === 0) { @@ -102,13 +102,15 @@ public static function isDiscountUsableWithQuantity(Discount $Discount, $quantit */ public static function isDiscountUsableWithPurchaseValue(Discount $Discount, $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; } @@ -168,7 +170,7 @@ public static function onQuiqqerProductsCalcListProduct( return; } - $PriceFactors = $Product->getPriceFactors(); + $PriceFactors = $Product->getPriceFactors(); $productQuantity = $Product->getQuantity(); $productNettoSum = $attributes['calculated_nettoSum']; @@ -184,7 +186,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() ); @@ -237,7 +239,7 @@ public static function onQuiqqerProductsCalcList( } $listQuantity = $List->getQuantity(); - $products = $List->getProducts(); + $products = $List->getProducts(); $PriceFactors = $List->getPriceFactors(); /* @var $Discount Discount */ @@ -307,7 +309,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() ); diff --git a/src/QUI/ERP/Discount/Handler.php b/src/QUI/ERP/Discount/Handler.php index b706918422f10d1a9354db31f31a7d52734b4098..bde72a9ebd37cfaf313880c6a69b5d7ed851079b 100644 --- a/src/QUI/ERP/Discount/Handler.php +++ b/src/QUI/ERP/Discount/Handler.php @@ -22,7 +22,7 @@ class Handler extends QUI\CRUD\Factory const DISCOUNT_TYPE_PERCENT = 1; /** - * discount type -> crrency + * discount type -> currency */ const DISCOUNT_TYPE_CURRENCY = 2; @@ -130,7 +130,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 +146,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( diff --git a/src/QUI/ERP/Discount/Utils.php b/src/QUI/ERP/Discount/Utils.php index 7cd5fd1811e877abfd69dc922cfba7950e8d2673..4e843db45cbcc4b29ce1b7c71e3db190b670312e 100644 --- a/src/QUI/ERP/Discount/Utils.php +++ b/src/QUI/ERP/Discount/Utils.php @@ -28,15 +28,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 ] ] @@ -70,14 +70,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() . ',' ] ] ]); @@ -111,16 +111,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,14 +128,14 @@ 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 ] ]); @@ -180,7 +180,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) {