From f3e582f2216ed9be4075e4b0443b7fdda45a6350 Mon Sep 17 00:00:00 2001 From: Henning Leutz <leutz@pcsg.de> Date: Wed, 24 Apr 2024 15:25:56 +0200 Subject: [PATCH] refactor: code style phpcbf --- ajax/list.php | 12 ++-- ajax/search.php | 12 ++-- src/QUI/ERP/Discount/Discount.php | 77 +++++++++++++------------- src/QUI/ERP/Discount/EventHandling.php | 18 +++--- src/QUI/ERP/Discount/Utils.php | 26 ++++----- 5 files changed, 75 insertions(+), 70 deletions(-) diff --git a/ajax/list.php b/ajax/list.php index ccab3b3..c01ebe6 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 ed5bed6..0dfdbc1 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 0c158d8..92a6496 100644 --- a/src/QUI/ERP/Discount/Discount.php +++ b/src/QUI/ERP/Discount/Discount.php @@ -65,7 +65,7 @@ public function __construct($id, Handler $Factory) $cleanup = \implode(',', $cleanup); if (!empty($cleanup)) { - $cleanup = ','.$cleanup.','; + $cleanup = ',' . $cleanup . ','; } $this->setAttribute('user_groups', $cleanup); @@ -76,7 +76,7 @@ public function __construct($id, Handler $Factory) $cleanup = \implode(',', $cleanup); if (!empty($cleanup)) { - $cleanup = ','.$cleanup.','; + $cleanup = ',' . $cleanup . ','; } $this->setAttribute('articles', $cleanup); @@ -87,7 +87,7 @@ public function __construct($id, Handler $Factory) $cleanup = \implode(',', $cleanup); if (!empty($cleanup)) { - $cleanup = ','.$cleanup.','; + $cleanup = ',' . $cleanup . ','; } $this->setAttribute('user_groups', $cleanup); @@ -98,7 +98,7 @@ public function __construct($id, Handler $Factory) $cleanup = \implode(',', $cleanup); if (!empty($cleanup)) { - $cleanup = ','.$cleanup.','; + $cleanup = ',' . $cleanup . ','; } $this->setAttribute('articles', $cleanup); @@ -112,14 +112,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 +129,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 +139,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 +218,8 @@ public function setAttribute($key, $value) $value = null; } - if ($key === 'scope' || + if ( + $key === 'scope' || $key === 'discount_type' || $key === 'usage_type' ) { @@ -240,7 +243,7 @@ public function getTitle($Locale = null) return $Locale->get( 'quiqqer/discount', - 'discount.'.$this->getId().'.title' + 'discount.' . $this->getId() . '.title' ); } @@ -296,9 +299,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 +313,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 +329,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 +371,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 +468,7 @@ public function verifyCombinationWith(Discount $Discount) 'quiqqer/discount', 'exception.discount.not.combinable', [ - 'id' => $this->getId(), + 'id' => $this->getId(), 'discountId' => $Discount->getId() ] ]); @@ -485,7 +488,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 +527,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 +555,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 +592,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 +605,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 4b452c6..ebb506a 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/Utils.php b/src/QUI/ERP/Discount/Utils.php index 7cd5fd1..4e843db 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) { -- GitLab