diff --git a/ajax/list.php b/ajax/list.php index 42d5ee2cefc1ed16d6ec273d38f5d9e1a56f7f1f..2c16c43b338eda6ffe05220f405e7bb0bbb99b71 100644 --- a/ajax/list.php +++ b/ajax/list.php @@ -16,7 +16,7 @@ function ($params) { $Grid = new QUI\Utils\Grid(); $Discounts = new QUI\ERP\Discount\Handler(); - $result = array(); + $result = []; $Locale = QUI::getLocale(); // search @@ -25,17 +25,18 @@ function ($params) { ); foreach ($data as $entry) { - $entry['title'] = array( + $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 switch ($type) { @@ -48,11 +49,21 @@ function ($params) { break; } + switch ($usageType) { + case QUI\ERP\Discount\Handler::DISCOUNT_USAGE_TYPE_MANUEL: + case QUI\ERP\Discount\Handler::DISCOUNT_USAGE_TYPE_AUTOMATIC: + break; + + default: + $entry['usage_type'] = QUI\ERP\Discount\Handler::DISCOUNT_USAGE_TYPE_MANUEL; + break; + } + $result[] = $entry; } return $Grid->parseResult($result, $Discounts->countChildren()); }, - array('params'), + ['params'], 'Permission::checkAdminUser' ); diff --git a/bin/classes/Handler.js b/bin/classes/Handler.js index 7ea53015dfbfaa85eeaef1a98b1bf8298100cbb9..ff55c8de02a7737beb9927641f821b1b4dc00686 100644 --- a/bin/classes/Handler.js +++ b/bin/classes/Handler.js @@ -48,6 +48,16 @@ define('package/quiqqer/discount/bin/classes/Handler', [ */ DISCOUNT_SCOPE_UNIQUE: 3, + /** + * discount usage type -> the discount will be used manuel + */ + DISCOUNT_USAGE_TYPE_MANUEL: 0, + + /** + * discount usage type -> the discount will be used manuel + */ + DISCOUNT_USAGE_TYPE_AUTOMATIC: 1, + /** * Search discounts * diff --git a/bin/controls/DiscountEdit.html b/bin/controls/DiscountEdit.html index 603e89bd91e204f0acc36ca2e2664f81c82922a3..27083e9ceb7bcb7f52fb0e7e97ee599f4cfde353 100644 --- a/bin/controls/DiscountEdit.html +++ b/bin/controls/DiscountEdit.html @@ -149,7 +149,7 @@ </td> </tr> <tr> - <td colspan="2"> + <td> <label class="field-container"> <span class="field-container-item" title="{{usageScope}}"> {{usageScope}} @@ -162,6 +162,19 @@ </select> </label> </td> + <td> + <label class="field-container"> + <span class="field-container-item"> + {{usageType}} + <span class="field-container-item-help" + title="{{usageTypeDescription}}"></span> + </span> + <select name="usage_type" class="field-container-field"> + <option value="0">{{usageTypeManuel}}</option> + <option value="1">{{usageTypeAutomatic}}</option> + </select> + </label> + </td> </tr> <tr> <td colspan="2"> diff --git a/bin/controls/DiscountEdit.js b/bin/controls/DiscountEdit.js index f58528f0725cd7d365c3c104bae32422f88841a9..2ba308df04a45c5c55def62ec1b37087c23c0e26 100644 --- a/bin/controls/DiscountEdit.js +++ b/bin/controls/DiscountEdit.js @@ -3,17 +3,6 @@ * * @author www.pcsg.de (Henning Leutz) * - * @require qui/QUI - * @require qui/controls/Control - * @require qui/controls/buttons/Button - * @require qui/utils/Form - * @require Locale - * @require Mustache - * @require package/quiqqer/discount/bin/Discounts - * @require package/quiqqer/translator/bin/controls/VariableTranslation - * @require text!package/quiqqer/discount/bin/controls/DiscountEdit.html - * @require css!package/quiqqer/discount/bin/controls/DiscountEdit.css - * * @event onLoaded */ define('package/quiqqer/discount/bin/controls/DiscountEdit', [ @@ -101,7 +90,12 @@ define('package/quiqqer/discount/bin/controls/DiscountEdit', [ usageAssignmentProduct : QUILocale.get(lg, 'control.edit.template.assignment.product'), usageAssignmentCategory: QUILocale.get(lg, 'control.edit.template.assignment.category'), usageAssignmentUser : QUILocale.get(lg, 'control.edit.template.assignment.user'), - usageAssignmentCombine : QUILocale.get(lg, 'control.edit.template.assignment.combine') + usageAssignmentCombine : QUILocale.get(lg, 'control.edit.template.assignment.combine'), + + usageType : QUILocale.get(lg, 'discount.usage_type'), + usageTypeDescription: QUILocale.get(lg, 'discount.usage_type.description'), + usageTypeManuel : QUILocale.get(lg, 'discount.usage_type.manuel'), + usageTypeAutomatic : QUILocale.get(lg, 'discount.usage_type.automatic') })); @@ -130,6 +124,7 @@ define('package/quiqqer/discount/bin/controls/DiscountEdit', [ self.getAttribute('discountId') ).then(function (data) { + data.usage_type = parseInt(data.usage_type); data.discount_type = parseInt(data.discount_type); data.priority = parseInt(data.priority); @@ -142,6 +137,15 @@ define('package/quiqqer/discount/bin/controls/DiscountEdit', [ data.discount_type = Discounts.DISCOUNT_TYPE_PERCENT; } + switch (data.usage_type) { + case Discounts.DISCOUNT_USAGE_TYPE_MANUEL: + case Discounts.DISCOUNT_USAGE_TYPE_AUTOMATIC: + break; + + default: + data.usage_type = Discounts.DISCOUNT_USAGE_TYPE_MANUEL; + } + QUIFormUtils.setDataToForm(data, Form); self.$Translate = new Translation({ diff --git a/bin/controls/Discounts.js b/bin/controls/Discounts.js index bbd2382dff31b7572932b5a7efb436b5305881ab..5119fd09fafbc84b20040378bf0a894a01ad3266 100644 --- a/bin/controls/Discounts.js +++ b/bin/controls/Discounts.js @@ -4,15 +4,6 @@ * * @author www.pcsg.de (Henning Leutz) * @module package/quiqqer/discount/bin/controls/Discounts - * - * @require qui/QUI - * @require qui/controls/desktop/Panel - * @require qui/controls/buttons/Button - * @require qui/controls/windows/Confirm - * @require qui/controls/windows/Prompt - * @require controls/grid/Grid - * @require Locale - * @require package/quiqqer/discount/bin/classes/Handler */ define('package/quiqqer/discount/bin/controls/Discounts', [ @@ -176,6 +167,11 @@ define('package/quiqqer/discount/bin/controls/Discounts', [ dataIndex: 'purchase_value', dataType : 'number', width : 100 + }, { + header : QUILocale.get(lg, 'discount.grid.usage_type'), + dataIndex: 'usageTypeText', + dataType : 'string', + width : 100 }, { header : QUILocale.get(lg, 'discount.grid.areas'), dataIndex: 'areas', @@ -265,13 +261,18 @@ define('package/quiqqer/discount/bin/controls/Discounts', [ perPage: this.$Grid.options.perPage, page : this.$Grid.options.page }).then(function (result) { - var i, len, active, entry, discountType; + var i, len, active, entry, discountType, usage_type; for (i = 0, len = result.data.length; i < len; i++) { entry = result.data[i]; active = parseInt(result.data[i].active); discountType = parseInt(result.data[i].discount_type); + usage_type = parseInt(result.data[i].usage_type); + + if (!usage_type) { + usage_type = 0; + } if (active) { entry.status = { @@ -301,10 +302,16 @@ define('package/quiqqer/discount/bin/controls/Discounts', [ entry.discountTypeText = '%'; + if (usage_type === 0) { + entry.usageTypeText = QUILocale.get(lg, 'discount.usage_type.manuel'); + } else { + entry.usageTypeText = QUILocale.get(lg, 'discount.usage_type.automatic'); + } + if (parseInt(entry.discount_type) === Discounts.DISCOUNT_TYPE_CURRENCY) { entry.discountTypeText = '€'; } - + result.data[i] = entry; } diff --git a/bin/controls/Select.js b/bin/controls/Select.js index cd1a509d118e0d445bdd672aef835c214cfc8366..000f2a8509721de508596f9b0524196cf4e598ae 100644 --- a/bin/controls/Select.js +++ b/bin/controls/Select.js @@ -3,11 +3,6 @@ * * @module package/quiqqer/discount/bin/controls/Select * @author www.pcsg.de (Henning Leutz) - * - * @require qui/controls/elements/Select - * @require package/quiqqer/discount/bin/controls/SelectItem - * @require package/quiqqer/discount/bin/classes/Handler - * @require Locale */ define('package/quiqqer/discount/bin/controls/Select', [ diff --git a/bin/controls/SelectItem.js b/bin/controls/SelectItem.js index d6b9d0261e9e273e16c5f68b070968b546342d74..07e3229021572369d0edec0d8fce9af4e3b5b86a 100644 --- a/bin/controls/SelectItem.js +++ b/bin/controls/SelectItem.js @@ -3,10 +3,6 @@ * * @module package/quiqqer/discount/bin/controls/SelectItem * @author www.pcsg.de (Henning Leutz) - * - * @require qui/controls/Control - * @require package/quiqqer/discount/bin/classes/Handler - * @require Locale */ define('package/quiqqer/discount/bin/controls/SelectItem', [ diff --git a/composer.json b/composer.json index c7af9e78d3bdebf84ac9f9f2ef8e36e7fda39c36..2faa963c6f3a344d31ec25835fcc8e1f18f99181 100644 --- a/composer.json +++ b/composer.json @@ -2,7 +2,7 @@ "name": "quiqqer/discount", "type": "quiqqer-plugin", "description": "Discounts", - "version": "dev-dev", + "version": "dev-master", "license": "", "authors": [ { diff --git a/database.xml b/database.xml index 71182386db7f1912e0d5b6c734faeeafe9f42b77..524d8969342ae42a74052d9e7caf183be27c8995 100644 --- a/database.xml +++ b/database.xml @@ -5,6 +5,7 @@ <field type="INT(10) NOT NULL PRIMARY KEY">id</field> <field type="INT(1) DEFAULT 0">active</field> <field type="varchar(255) NULL">discount</field> + <field type="int(2) NULL">usage_type</field> <field type="int(2) NULL">discount_type</field> <field type="text NULL">date_from</field> <field type="text NULL">date_until</field> diff --git a/locale.xml b/locale.xml index 89b01be289c2d74e490ab97995260d3d65f2f2eb..a43c33ad10b4d3159375d614e3e504f84ad1d7d8 100644 --- a/locale.xml +++ b/locale.xml @@ -35,7 +35,6 @@ <de><![CDATA[Darf Rabatte löschen.]]></de> <en><![CDATA[Is allowed to delete discounts.]]></en> </locale> - </groups> @@ -128,6 +127,10 @@ <de><![CDATA[Rabatt ist inaktiv. Klick um zu aktivieren]]></de> <en><![CDATA[Discount is inactive. Click to activate]]></en> </locale> + <locale name="discount.grid.usage_type"> + <de><![CDATA[Ausführung]]></de> + <en><![CDATA[Execution]]></en> + </locale> <locale name="control.edit.template.header"> <de><![CDATA[Rabatt]]></de> @@ -306,6 +309,30 @@ <en><![CDATA[Edit discount [id]]]></en> </locale> + <locale name="discount.usage_type"> + <de><![CDATA[Ausführung]]></de> + <en><![CDATA[Execution]]></en> + </locale> + <locale name="discount.usage_type.description"> + <de><![CDATA[ +Manuell: Dieser Rabett kann nur manuell zu einer Bestellung hinzufügt werden. Zum Beispiel durch einen Gutschein-Code oder eine Erweiterung. + +Automatisch: Dieser Rabatt wird automatisch einer Bestellung hinzufügt wenn die Bedingungen zutreffen. + ]]></de> + <en><![CDATA[ +Manual: This discount can only be added manually to an order. For example, by a coupon code or an extension. + +Automatic: This discount is automatically added to an order if the conditions apply. + ]]></en> + </locale> + <locale name="discount.usage_type.manuel"> + <de><![CDATA[Manuell hinzufügen (z.B.: Gutschein-Code)]]></de> + <en><![CDATA[Add manuel (eq: Coupon code)]]></en> + </locale> + <locale name="discount.usage_type.automatic"> + <de><![CDATA[Automatisch hinzufügen]]></de> + <en><![CDATA[Add automatically]]></en> + </locale> </groups> diff --git a/src/QUI/ERP/Discount/Handler.php b/src/QUI/ERP/Discount/Handler.php index be38d876e6c90ba15fcfa400f48cc6fcc47c43c6..f0878d09cc7cafc49e5d6c55de16ac1cb906aa0c 100644 --- a/src/QUI/ERP/Discount/Handler.php +++ b/src/QUI/ERP/Discount/Handler.php @@ -46,6 +46,17 @@ class Handler extends QUI\CRUD\Factory */ const DISCOUNT_PRICEFACTOR_TYPE = 'DISCOUNT_PRICE_FACTOR'; + /** + * discount usage type -> the discount will be used manuel + */ + const DISCOUNT_USAGE_TYPE_MANUEL = 0; + + /** + * discount usage type -> the discount will be used manuel + */ + const DISCOUNT_USAGE_TYPE_AUTOMATIC = 1; + + /** * Handler constructor. */ @@ -118,6 +129,7 @@ public function getChildAttributes() return [ 'active', 'discount', + 'usage_type', 'discount_type', 'date_from', 'date_until',