diff --git a/bin/backend/controls/shippingRules/CreateRule.html b/bin/backend/controls/shippingRules/CreateRule.html index bb9051f4ee1dd7c05220a66536323161a6d2f4fd..77603251945c5958f58cf5e8a0ae63abfc8f2463 100644 --- a/bin/backend/controls/shippingRules/CreateRule.html +++ b/bin/backend/controls/shippingRules/CreateRule.html @@ -54,6 +54,9 @@ <option value="PERCENTAGE"> {{discountPercentage}} </option> + <option value="PERCENTAGE_ORDER"> + {{discountPercentageOrder}} + </option> </select> <input type="number" name="discount" @@ -231,4 +234,4 @@ </tbody> </table> -</form> \ No newline at end of file +</form> diff --git a/bin/backend/controls/shippingRules/CreateRule.js b/bin/backend/controls/shippingRules/CreateRule.js index 124c2f91feaa411215e4f9727f68e18ba9b4f143..d7510fd011810157f886a53a5a30a1eb1726d292 100644 --- a/bin/backend/controls/shippingRules/CreateRule.js +++ b/bin/backend/controls/shippingRules/CreateRule.js @@ -55,30 +55,31 @@ define('package/quiqqer/shipping/bin/backend/controls/shippingRules/CreateRule', this.$Elm.addClass('quiqqer-shipping-rule-create'); this.$Elm.set('html', Mustache.render(template, { - generalHeader : QUILocale.get(lg, 'shipping.edit.template.general'), - title : QUILocale.get(lg, 'shipping.edit.template.title'), - workingTitle : QUILocale.get('quiqqer/system', 'workingtitle'), - calculationPriority : QUILocale.get(lg, 'shipping.edit.template.calculationPriority'), - discountTitle : QUILocale.get(lg, 'shipping.edit.template.discount'), - discountDescription : QUILocale.get(lg, 'shipping.edit.template.discount.description'), - discountAbsolute : QUILocale.get(lg, 'shipping.edit.template.discount.absolute'), - discountPercentage : QUILocale.get(lg, 'shipping.edit.template.discount.percentage'), - statusTitle : QUILocale.get(lg, 'shipping.edit.template.status'), - statusDescription : QUILocale.get(lg, 'shipping.edit.template.status.description'), - noRulesTitle : QUILocale.get(lg, 'shipping.edit.template.noRules'), - noRulesText : QUILocale.get(lg, 'shipping.edit.template.noRules.text'), - unitTitle : QUILocale.get(lg, 'shipping.edit.template.unit'), - unitHeader : QUILocale.get(lg, 'shipping.edit.template.unitTitle'), - usageHeader : QUILocale.get(lg, 'shipping.edit.template.usage'), - usageFrom : QUILocale.get(lg, 'shipping.edit.template.usage.from'), - usageTo : QUILocale.get(lg, 'shipping.edit.template.usage.to'), - usageAmountOf : QUILocale.get(lg, 'shipping.edit.template.shopping.amount.of'), - usageAmountTo : QUILocale.get(lg, 'shipping.edit.template.shopping.amount.to'), - usageValueOf : QUILocale.get(lg, 'shipping.edit.template.purchase.value.of'), - usageValueTo : QUILocale.get(lg, 'shipping.edit.template.purchase.value.to'), - usageAssignmentUser : QUILocale.get(lg, 'shipping.edit.template.assignment.user'), - usageAssignmentProduct: QUILocale.get(lg, 'shipping.edit.template.assignment.product'), - usageAssignmentArea : QUILocale.get(lg, 'shipping.edit.template.assignment.areas'), + generalHeader : QUILocale.get(lg, 'shipping.edit.template.general'), + title : QUILocale.get(lg, 'shipping.edit.template.title'), + workingTitle : QUILocale.get('quiqqer/system', 'workingtitle'), + calculationPriority : QUILocale.get(lg, 'shipping.edit.template.calculationPriority'), + discountTitle : QUILocale.get(lg, 'shipping.edit.template.discount'), + discountDescription : QUILocale.get(lg, 'shipping.edit.template.discount.description'), + discountAbsolute : QUILocale.get(lg, 'shipping.edit.template.discount.absolute'), + discountPercentage : QUILocale.get(lg, 'shipping.edit.template.discount.percentage'), + discountPercentageOrder: QUILocale.get(lg, 'shipping.edit.template.discount.percentageOrder'), + statusTitle : QUILocale.get(lg, 'shipping.edit.template.status'), + statusDescription : QUILocale.get(lg, 'shipping.edit.template.status.description'), + noRulesTitle : QUILocale.get(lg, 'shipping.edit.template.noRules'), + noRulesText : QUILocale.get(lg, 'shipping.edit.template.noRules.text'), + unitTitle : QUILocale.get(lg, 'shipping.edit.template.unit'), + unitHeader : QUILocale.get(lg, 'shipping.edit.template.unitTitle'), + usageHeader : QUILocale.get(lg, 'shipping.edit.template.usage'), + usageFrom : QUILocale.get(lg, 'shipping.edit.template.usage.from'), + usageTo : QUILocale.get(lg, 'shipping.edit.template.usage.to'), + usageAmountOf : QUILocale.get(lg, 'shipping.edit.template.shopping.amount.of'), + usageAmountTo : QUILocale.get(lg, 'shipping.edit.template.shopping.amount.to'), + usageValueOf : QUILocale.get(lg, 'shipping.edit.template.purchase.value.of'), + usageValueTo : QUILocale.get(lg, 'shipping.edit.template.purchase.value.to'), + usageAssignmentUser : QUILocale.get(lg, 'shipping.edit.template.assignment.user'), + usageAssignmentProduct : QUILocale.get(lg, 'shipping.edit.template.assignment.product'), + usageAssignmentArea : QUILocale.get(lg, 'shipping.edit.template.assignment.areas'), productHeader : QUILocale.get(lg, 'shipping.edit.template.assignment.product.header'), usageAssignmentProductOnly : QUILocale.get(lg, 'shipping.edit.template.assignment.product.only'), diff --git a/bin/backend/controls/shippingRules/Rule.html b/bin/backend/controls/shippingRules/Rule.html index f8e1c2828b4c6150264714431df712cb4f23e75f..9e45a8b29de933105ff514dc5e105ecfcd77af9c 100644 --- a/bin/backend/controls/shippingRules/Rule.html +++ b/bin/backend/controls/shippingRules/Rule.html @@ -54,6 +54,9 @@ <option value="1"> {{discountPercentage}} </option> + <option value="PERCENTAGE_ORDER"> + {{discountPercentageOrder}} + </option> </select> <input type="number" step="0.01" diff --git a/bin/backend/controls/shippingRules/Rule.js b/bin/backend/controls/shippingRules/Rule.js index 80cd2a79e6e3a0f3a8c05a8a09e897fdb0209391..0e8acd75731131cd2d553bd3f01582d4e62e098f 100644 --- a/bin/backend/controls/shippingRules/Rule.js +++ b/bin/backend/controls/shippingRules/Rule.js @@ -73,30 +73,31 @@ define('package/quiqqer/shipping/bin/backend/controls/shippingRules/Rule', [ }); this.$Elm.set('html', Mustache.render(template, { - generalHeader : QUILocale.get(lg, 'shipping.edit.template.general'), - title : QUILocale.get(lg, 'shipping.edit.template.title'), - workingTitle : QUILocale.get('quiqqer/system', 'workingtitle'), - calculationPriority : QUILocale.get(lg, 'shipping.edit.template.calculationPriority'), - discountTitle : QUILocale.get(lg, 'shipping.edit.template.discount'), - discountDescription : QUILocale.get(lg, 'shipping.edit.template.discount.description'), - discountAbsolute : QUILocale.get(lg, 'shipping.edit.template.discount.absolute'), - discountPercentage : QUILocale.get(lg, 'shipping.edit.template.discount.percentage'), - statusTitle : QUILocale.get(lg, 'shipping.edit.template.status'), - statusDescription : QUILocale.get(lg, 'shipping.edit.template.status.description'), - noRulesTitle : QUILocale.get(lg, 'shipping.edit.template.noRules'), - noRulesText : QUILocale.get(lg, 'shipping.edit.template.noRules.text'), - unitTitle : QUILocale.get(lg, 'shipping.edit.template.unit'), - unitHeader : QUILocale.get(lg, 'shipping.edit.template.unitTitle'), - usageHeader : QUILocale.get(lg, 'shipping.edit.template.usage'), - usageFrom : QUILocale.get(lg, 'shipping.edit.template.usage.from'), - usageTo : QUILocale.get(lg, 'shipping.edit.template.usage.to'), - usageAmountOf : QUILocale.get(lg, 'shipping.edit.template.shopping.amount.of'), - usageAmountTo : QUILocale.get(lg, 'shipping.edit.template.shopping.amount.to'), - usageValueOf : QUILocale.get(lg, 'shipping.edit.template.purchase.value.of'), - usageValueTo : QUILocale.get(lg, 'shipping.edit.template.purchase.value.to'), - usageAssignmentUser : QUILocale.get(lg, 'shipping.edit.template.assignment.user'), - usageAssignmentProduct: QUILocale.get(lg, 'shipping.edit.template.assignment.product'), - usageAssignmentArea : QUILocale.get(lg, 'shipping.edit.template.assignment.areas'), + generalHeader : QUILocale.get(lg, 'shipping.edit.template.general'), + title : QUILocale.get(lg, 'shipping.edit.template.title'), + workingTitle : QUILocale.get('quiqqer/system', 'workingtitle'), + calculationPriority : QUILocale.get(lg, 'shipping.edit.template.calculationPriority'), + discountTitle : QUILocale.get(lg, 'shipping.edit.template.discount'), + discountDescription : QUILocale.get(lg, 'shipping.edit.template.discount.description'), + discountAbsolute : QUILocale.get(lg, 'shipping.edit.template.discount.absolute'), + discountPercentage : QUILocale.get(lg, 'shipping.edit.template.discount.percentage'), + discountPercentageOrder: QUILocale.get(lg, 'shipping.edit.template.discount.percentageOrder'), + statusTitle : QUILocale.get(lg, 'shipping.edit.template.status'), + statusDescription : QUILocale.get(lg, 'shipping.edit.template.status.description'), + noRulesTitle : QUILocale.get(lg, 'shipping.edit.template.noRules'), + noRulesText : QUILocale.get(lg, 'shipping.edit.template.noRules.text'), + unitTitle : QUILocale.get(lg, 'shipping.edit.template.unit'), + unitHeader : QUILocale.get(lg, 'shipping.edit.template.unitTitle'), + usageHeader : QUILocale.get(lg, 'shipping.edit.template.usage'), + usageFrom : QUILocale.get(lg, 'shipping.edit.template.usage.from'), + usageTo : QUILocale.get(lg, 'shipping.edit.template.usage.to'), + usageAmountOf : QUILocale.get(lg, 'shipping.edit.template.shopping.amount.of'), + usageAmountTo : QUILocale.get(lg, 'shipping.edit.template.shopping.amount.to'), + usageValueOf : QUILocale.get(lg, 'shipping.edit.template.purchase.value.of'), + usageValueTo : QUILocale.get(lg, 'shipping.edit.template.purchase.value.to'), + usageAssignmentUser : QUILocale.get(lg, 'shipping.edit.template.assignment.user'), + usageAssignmentProduct : QUILocale.get(lg, 'shipping.edit.template.assignment.product'), + usageAssignmentArea : QUILocale.get(lg, 'shipping.edit.template.assignment.areas'), productHeader : QUILocale.get(lg, 'shipping.edit.template.assignment.product.header'), usageAssignmentProductOnly : QUILocale.get(lg, 'shipping.edit.template.assignment.product.only'), diff --git a/bin/backend/utils/ShippingUtils.js b/bin/backend/utils/ShippingUtils.js index f115459446d195855d05a4b4825583c5d12e4ab0..17bcd1cc5475eb23b8df56f760a8479345787e38 100644 --- a/bin/backend/utils/ShippingUtils.js +++ b/bin/backend/utils/ShippingUtils.js @@ -51,6 +51,11 @@ define('package/quiqqer/shipping/bin/backend/utils/ShippingUtils', [ 'quiqqer/shipping', 'discount.type.abs' ); + } else if (parseInt(ruleData.discount_type) === 2) { + ruleData.discount_type_text = QUILocale.get( + 'quiqqer/shipping', + 'discount.type.percentageOrder' + ); } else { ruleData.discount_type_text = QUILocale.get( 'quiqqer/shipping', @@ -61,4 +66,4 @@ define('package/quiqqer/shipping/bin/backend/utils/ShippingUtils', [ return ruleData; } }; -}); \ No newline at end of file +}); diff --git a/locale.xml b/locale.xml index 072336e676905d22cf4c7af9e4e6f747a6bea754..2acb92831f383547283f706ff748e50edeb356d1 100644 --- a/locale.xml +++ b/locale.xml @@ -85,6 +85,10 @@ <de><![CDATA[Auf / Abschlag % (prozentual)]]></de> <en><![CDATA[Discount % (percentage)]]></en> </locale> + <locale name="discount.type.percentageOrder"> + <de><![CDATA[Warenwert Auf / Abschlag % (prozentual vom Warenwert)]]></de> + <en><![CDATA[Value of goods Discount % (as a percentage of the value of the goods)]]></en> + </locale> <locale name="message.no.rule.found.order.continue"> <de><![CDATA[ @@ -597,6 +601,10 @@ <de><![CDATA[Auf / Abschlag % (prozentual)]]></de> <en><![CDATA[Discount % (percentage)]]></en> </locale> + <locale name="shipping.edit.template.discount.percentageOrder"> + <de><![CDATA[Warenwert Auf / Abschlag % (prozentual vom Warenwert)]]></de> + <en><![CDATA[Value of goods Discount % (as a percentage of the value of the goods)]]></en> + </locale> <locale name="shipping.edit.template.discount.type"> <de><![CDATA[Typ]]></de> <en><![CDATA[Type]]></en> diff --git a/src/QUI/ERP/Shipping/Methods/Standard/ShippingType.php b/src/QUI/ERP/Shipping/Methods/Standard/ShippingType.php index 94e871aa64ad0170868300d5e7c8efe97c8e71b7..0cb78d1ee3d4fef7dc65c0151bf21f27a257f4e0 100644 --- a/src/QUI/ERP/Shipping/Methods/Standard/ShippingType.php +++ b/src/QUI/ERP/Shipping/Methods/Standard/ShippingType.php @@ -145,6 +145,8 @@ public function canUsedBy( return false; } + Debug::addLog("{$this->getTitle()} :: {$ShippingEntry->getTitle()} :: User is in areas"); + $userGroups = QUI\Utils\UserGroups::parseUsersGroupsString( $ShippingEntry->getAttribute('user_groups') ); diff --git a/src/QUI/ERP/Shipping/Rules/Factory.php b/src/QUI/ERP/Shipping/Rules/Factory.php index e9a36f6dde0e436e9cce38fc02afa34dd360e823..5759303d55dfef286b2c40ef9c77ee9e59729950 100644 --- a/src/QUI/ERP/Shipping/Rules/Factory.php +++ b/src/QUI/ERP/Shipping/Rules/Factory.php @@ -27,6 +27,11 @@ class Factory extends QUI\CRUD\Factory */ const DISCOUNT_TYPE_PERCENTAGE = 1; + /** + * percentage discount from order sum (total) // PERCENTAGE_ORDER + */ + const DISCOUNT_TYPE_PC_ORDER = 2; + /** * Handler constructor. */ @@ -135,8 +140,13 @@ public function createChild($data = []) $data['discount_type'] = RuleFactory::DISCOUNT_TYPE_PERCENTAGE; break; + case 'PERCENTAGE_ORDER': + $data['discount_type'] = RuleFactory::DISCOUNT_TYPE_PC_ORDER; + break; + case RuleFactory::DISCOUNT_TYPE_ABS: case RuleFactory::DISCOUNT_TYPE_PERCENTAGE: + case RuleFactory::DISCOUNT_TYPE_PC_ORDER: break; default: diff --git a/src/QUI/ERP/Shipping/Rules/ShippingRule.php b/src/QUI/ERP/Shipping/Rules/ShippingRule.php index 806c554ed33c0a9546c31ef38175b91252b3d3e8..34f5761f7d517895a32f76383cb294c39667345a 100644 --- a/src/QUI/ERP/Shipping/Rules/ShippingRule.php +++ b/src/QUI/ERP/Shipping/Rules/ShippingRule.php @@ -86,6 +86,9 @@ public function __construct($id, Factory $Factory) $attributes['discount_type'] === 'PERCENTAGE' ) { $attributes['discount_type'] = RuleFactory::DISCOUNT_TYPE_PERCENTAGE; + } elseif ($attributes['discount_type'] === RuleFactory::DISCOUNT_TYPE_PC_ORDER || + $attributes['discount_type'] === 'PERCENTAGE_ORDER') { + $attributes['discount_type'] = RuleFactory::DISCOUNT_TYPE_PC_ORDER; } else { $attributes['discount_type'] = RuleFactory::DISCOUNT_TYPE_ABS; } diff --git a/src/QUI/ERP/Shipping/Types/ShippingEntry.php b/src/QUI/ERP/Shipping/Types/ShippingEntry.php index f0c26fcd66185fbca3b493c306632ca84da4b7bc..ce1f6c5e6deabca95d7969e5e89353d889e08499 100644 --- a/src/QUI/ERP/Shipping/Types/ShippingEntry.php +++ b/src/QUI/ERP/Shipping/Types/ShippingEntry.php @@ -205,6 +205,8 @@ public function getPrice() $rules = $this->getShippingRules(); $price = 0; + $Order = $this->Order; + foreach ($rules as $Rule) { $discount = $Rule->getAttribute('discount'); $type = $Rule->getDiscountType(); @@ -214,6 +216,26 @@ public function getPrice() continue; } + if ($type === QUI\ERP\Shipping\Rules\Factory::DISCOUNT_TYPE_PC_ORDER && $Order) { + try { + /* @var $Order QUI\ERP\Order\Order */ + $Order = $this->Order; + $Calculation = $Order->getPriceCalculation(); + $nettoSum = $Calculation->getNettoSum()->get(); + + if (!$nettoSum) { + continue; + } + + $pc = \round($nettoSum * ($discount / 100)); + $price = $price + $pc; + + continue; + } catch (QUI\Exception $Exception) { + QUI\System\Log::addDebug($Exception->getMessage()); + } + } + $pc = \round($price * ($discount / 100)); $price = $price + $pc; }