diff --git a/bin/controls/Select.js b/bin/controls/Select.js index 57cf0948429d317ddb76a0c9681259ef845f16a6..cd1a509d118e0d445bdd672aef835c214cfc8366 100644 --- a/bin/controls/Select.js +++ b/bin/controls/Select.js @@ -36,7 +36,8 @@ define('package/quiqqer/discount/bin/controls/Select', [ Type : 'package/quiqqer/discount/bin/controls/Select', Binds: [ - 'searchDiscounts' + 'searchDiscounts', + '$onSearchButtonClick' ], initialize: function (options) { diff --git a/src/QUI/ERP/Discount/Discount.php b/src/QUI/ERP/Discount/Discount.php index 32af3db43698c07c1db75f3f4eb92a26c7fa6707..123ac36d15e65f0dff7c78fd1300c955762070d1 100644 --- a/src/QUI/ERP/Discount/Discount.php +++ b/src/QUI/ERP/Discount/Discount.php @@ -61,7 +61,7 @@ public function __construct($id, Handler $Factory) $cleanup = implode(',', $cleanup); if (!empty($cleanup)) { - $cleanup = ',' . $cleanup . ','; + $cleanup = ','.$cleanup.','; } $this->setAttribute('user_groups', $cleanup); @@ -72,7 +72,7 @@ public function __construct($id, Handler $Factory) $cleanup = implode(',', $cleanup); if (!empty($cleanup)) { - $cleanup = ',' . $cleanup . ','; + $cleanup = ','.$cleanup.','; } $this->setAttribute('articles', $cleanup); @@ -83,7 +83,7 @@ public function __construct($id, Handler $Factory) $cleanup = implode(',', $cleanup); if (!empty($cleanup)) { - $cleanup = ',' . $cleanup . ','; + $cleanup = ','.$cleanup.','; } $this->setAttribute('user_groups', $cleanup); @@ -94,7 +94,7 @@ public function __construct($id, Handler $Factory) $cleanup = implode(',', $cleanup); if (!empty($cleanup)) { - $cleanup = ',' . $cleanup . ','; + $cleanup = ','.$cleanup.','; } $this->setAttribute('articles', $cleanup); @@ -108,7 +108,7 @@ public function __construct($id, Handler $Factory) $this->Events->addEvent('onDeleteEnd', function () { QUI\Translator::delete( 'quiqqer/discount', - 'discount.' . $this->getId() . '.title' + 'discount.'.$this->getId().'.title' ); }); @@ -118,19 +118,19 @@ public function __construct($id, Handler $Factory) if ($this->getAttribute('date_from') && !Orthos::checkMySqlDatetimeSyntax($this->getAttribute('date_from')) ) { - throw new QUI\ERP\Discount\Exception(array( + throw new QUI\ERP\Discount\Exception([ 'quiqqer/discount', 'exception.discount.date_from.wrong' - )); + ]); } if ($this->getAttribute('date_until') && !Orthos::checkMySqlDatetimeSyntax($this->getAttribute('date_until')) ) { - throw new QUI\ERP\Discount\Exception(array( + throw new QUI\ERP\Discount\Exception([ 'quiqqer/discount', 'exception.discount.date_until.wrong' - )); + ]); } $purchaseQuantityFrom = $this->getAttribute('purchase_quantity_from'); @@ -139,45 +139,55 @@ public function __construct($id, Handler $Factory) $purchaseValueUntil = $this->getAttribute('purchase_value_until'); - if ($purchaseQuantityFrom === false - || $purchaseQuantityFrom < 0 - ) { - throw new QUI\ERP\Discount\Exception(array( + if ($purchaseQuantityFrom === false || $purchaseQuantityFrom < 0) { + throw new QUI\ERP\Discount\Exception([ 'quiqqer/discount', 'exception.discount.purchase_quantity_from.wrong' - )); + ]); } - if ($purchaseQuantityUntil === false - || $purchaseQuantityUntil < 0 - ) { - throw new QUI\ERP\Discount\Exception(array( + if ($purchaseQuantityUntil === false || $purchaseQuantityUntil < 0) { + throw new QUI\ERP\Discount\Exception([ 'quiqqer/discount', 'exception.discount.purchase_quantity_until.wrong' - )); + ]); } - if ($purchaseValueFrom === false - || $purchaseValueFrom < 0 - ) { - throw new QUI\ERP\Discount\Exception(array( + if ($purchaseValueFrom === false || $purchaseValueFrom < 0) { + throw new QUI\ERP\Discount\Exception([ 'quiqqer/discount', 'exception.discount.purchase_value_from.wrong' - )); + ]); } - if ($purchaseValueUntil === false - || $purchaseValueUntil < 0 - ) { - throw new QUI\ERP\Discount\Exception(array( + if ($purchaseValueUntil === false || $purchaseValueUntil < 0) { + throw new QUI\ERP\Discount\Exception([ 'quiqqer/discount', 'exception.discount.purchase_value_until.wrong' - )); + ]); } }); } + /** + * @param string $key + * @param array|bool|object|string $value + * @return QUI\QDOM|void + */ + public function setAttribute($key, $value) + { + if ($key === 'lastSumDiscount' && empty($value)) { + $value = null; + } + + if ($key === 'lastProductDiscount' && empty($value)) { + $value = null; + } + + parent::setAttribute($key, $value); + } + /** * Return the discount title * @@ -192,7 +202,7 @@ public function getTitle($Locale = null) return $Locale->get( 'quiqqer/discount', - 'discount.' . $this->getId() . '.title' + 'discount.'.$this->getId().'.title' ); } @@ -312,14 +322,14 @@ public function canUsedBy(QUI\Interfaces\Users\User $User) public function verifyCombinationWith(Discount $Discount) { if ($this->canCombinedWith($Discount) === false) { - throw new QUI\ERP\Discount\Exception(array( + throw new QUI\ERP\Discount\Exception([ 'quiqqer/discount', 'exception.discount.not.combinable', - array( + [ 'id' => $this->getId(), 'discountId' => $Discount->getId() - ) - )); + ] + ]); } } @@ -332,14 +342,14 @@ public function verifyCombinationWith(Discount $Discount) public function verifyUser(User $User) { if ($this->canUsedBy($User) === false) { - throw new QUI\ERP\Discount\Exception(array( + throw new QUI\ERP\Discount\Exception([ 'quiqqer/discount', 'exception.discount.user.cant.use.discount', - array( + [ 'id' => $this->getId(), 'userId' => $User->getId() - ) - )); + ] + ]); } } @@ -377,7 +387,7 @@ public function toPriceFactor($Locale = null) $hideDiscounts = (int)$Config->getValue('products', 'hideDiscounts'); if ($this->getAttribute('scope') == Handler::DISCOUNT_SCOPE_TOTAL) { - return new PriceFactor(array( + return new PriceFactor([ 'title' => $this->getTitle($Locale), 'description' => '', 'priority' => (int)$this->getAttribute('priority'), @@ -386,10 +396,10 @@ public function toPriceFactor($Locale = null) 'value' => $this->getAttribute('discount') * -1, 'visible' => $hideDiscounts ? false : true, 'vat' => $this->getAttribute('vat') - )); + ]); } - return new QUI\ERP\Products\Utils\PriceFactor(array( + return new QUI\ERP\Products\Utils\PriceFactor([ 'title' => $this->getTitle($Locale), 'description' => '', 'priority' => (int)$this->getAttribute('priority'), @@ -397,6 +407,6 @@ public function toPriceFactor($Locale = null) 'basis' => $basis, 'value' => $this->getAttribute('discount') * -1, 'visible' => $hideDiscounts ? false : true - )); + ]); } }