From 73d5bfd3bc7fe5329f9568e3b9d6cc1bce4911de Mon Sep 17 00:00:00 2001 From: Henning Leutz <leutz@pcsg.de> Date: Fri, 22 May 2020 15:16:10 +0200 Subject: [PATCH] feat: refactor: consider_vat option for discounts --- bin/controls/DiscountEdit.html | 44 ++++++++++++++++---------- bin/controls/DiscountEdit.js | 5 +++ locale.xml | 18 ++++++++++- src/QUI/ERP/Discount/Discount.php | 17 +++++++++- src/QUI/ERP/Discount/EventHandling.php | 9 ++++-- 5 files changed, 71 insertions(+), 22 deletions(-) diff --git a/bin/controls/DiscountEdit.html b/bin/controls/DiscountEdit.html index 27083e9..9b872ff 100644 --- a/bin/controls/DiscountEdit.html +++ b/bin/controls/DiscountEdit.html @@ -9,7 +9,7 @@ </thead> <tbody> - <tr class="odd"> + <tr> <td> <label class="field-container"> <span class="field-container-item"> @@ -19,7 +19,7 @@ </label> </td> </tr> - <tr class="even"> + <tr> <td> <label class="field-container"> <span class="field-container-item"> @@ -29,7 +29,7 @@ </label> </td> </tr> - <tr class="even"> + <tr> <td> <label class="field-container"> <span class="field-container-item"> @@ -46,7 +46,7 @@ </label> </td> </tr> - <tr class="even"> + <tr> <td> <label class="field-container"> <span class="field-container-item" title="{{calculationBasis}}"> @@ -61,6 +61,22 @@ </label> </td> </tr> + <tr> + <td> + <label class="field-container"> + <span class="field-container-item" title="{{calculationBasis}}"> + {{considerVat}} + </span> + <select type="text" name="consider_vat" + class="field-container-field" style="width: 100%" + > + <option value="auto">{{considerVatAuto}}</option> + <option value="brutto">{{considerVatBrutto}}</option> + <option value="netto">{{considerVatNetto}}</option> + </select> + </label> + </td> + </tr> <tr> <td> <label class="field-container"> @@ -91,8 +107,7 @@ <span class="fa fa-calendar"></span> {{usageFrom}} </span> - <input type="datetime" name="date_from" - class="field-container-field"/> + <input type="datetime" name="date_from" class="field-container-field"/> </label> </td> <td> @@ -101,8 +116,7 @@ <span class="fa fa-calendar"></span> {{usageTo}} </span> - <input type="datetime" name="date_until" - class="field-container-field"/> + <input type="datetime" name="date_until" class="field-container-field"/> </label> </td> </tr> @@ -112,8 +126,7 @@ <span class="field-container-item"> {{usageAmountOf}} </span> - <input type="number" min="0" name="purchase_quantity_from" - class="field-container-field"/> + <input type="number" min="0" name="purchase_quantity_from" class="field-container-field"/> </label> </td> <td> @@ -121,8 +134,7 @@ <span class="field-container-item"> {{usageAmountTo}} </span> - <input type="number" min="0" name="purchase_quantity_until" - class="field-container-field"/> + <input type="number" min="0" name="purchase_quantity_until" class="field-container-field"/> </label> </td> </tr> @@ -133,8 +145,7 @@ <span class="fa fa-money"></span> {{usageValueOf}} </span> - <input type="number" min="0" name="purchase_value_from" - class="field-container-field"/> + <input type="number" min="0" name="purchase_value_from" class="field-container-field"/> </label> </td> <td> @@ -143,8 +154,7 @@ <span class="fa fa-money"></span> {{usageValueTo}} </span> - <input type="number" min="0" name="purchase_value_until" - class="field-container-field"/> + <input type="number" min="0" name="purchase_value_until" class="field-container-field"/> </label> </td> </tr> @@ -297,4 +307,4 @@ </tr> </tbody> </table> -</form> \ No newline at end of file +</form> diff --git a/bin/controls/DiscountEdit.js b/bin/controls/DiscountEdit.js index 2ba308d..9c9b6f4 100644 --- a/bin/controls/DiscountEdit.js +++ b/bin/controls/DiscountEdit.js @@ -87,6 +87,11 @@ define('package/quiqqer/discount/bin/controls/DiscountEdit', [ calculationBasisCalcBrutto: QUILocale.get(lg, 'control.edit.template.calculationBasis.calculationBasisCalcBrutto'), calculationPriority : QUILocale.get(lg, 'control.edit.template.calculationPriority'), + considerVat : QUILocale.get(lg, 'control.edit.template.considerVat'), + considerVatAuto : QUILocale.get(lg, 'control.edit.template.considerVat.auto'), + considerVatNetto : QUILocale.get(lg, 'control.edit.template.considerVat.netto'), + considerVatBrutto: QUILocale.get(lg, 'control.edit.template.considerVat.brutto'), + 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'), diff --git a/locale.xml b/locale.xml index 999902e..ea10495 100644 --- a/locale.xml +++ b/locale.xml @@ -278,6 +278,22 @@ <de><![CDATA[Zonen]]></de> <en><![CDATA[Areas]]></en> </locale> + <locale name="control.edit.template.considerVat"> + <de><![CDATA[MwSt. beachten]]></de> + <en><![CDATA[Consider VAT]]></en> + </locale> + <locale name="control.edit.template.considerVat.auto"> + <de><![CDATA[automatisch]]></de> + <en><![CDATA[automatic]]></en> + </locale> + <locale name="control.edit.template.considerVat.netto"> + <de><![CDATA[netto]]></de> + <en><![CDATA[net]]></en> + </locale> + <locale name="control.edit.template.considerVat.brutto"> + <de><![CDATA[brutto]]></de> + <en><![CDATA[gross]]></en> + </locale> <locale name="control.select.search.placeholder"> <de><![CDATA[Suche nach einem Rabatt ...]]></de> @@ -346,4 +362,4 @@ Automatic: This discount is automatically added to an order if the conditions ap </groups> -</locales> \ No newline at end of file +</locales> diff --git a/src/QUI/ERP/Discount/Discount.php b/src/QUI/ERP/Discount/Discount.php index f7199d2..c32a232 100644 --- a/src/QUI/ERP/Discount/Discount.php +++ b/src/QUI/ERP/Discount/Discount.php @@ -41,6 +41,10 @@ public function __construct($id, Handler $Factory) break; } + if ($this->getAttribute('consider_vat') === false) { + $this->setAttribute('consider_vat', 'auto'); + } + $scope = (int)$this->getAttribute('scope'); switch ($scope) { @@ -452,9 +456,11 @@ public function verifyUser(User $User) * Parse the discount to a price factor * * @param null|QUI\Locale $Locale - optional, locale object + * @param null|QUI\Interfaces\Users\User $Customer - optional, + * * @return QUI\ERP\Products\Interfaces\PriceFactorWithVatInterface|QUI\ERP\Products\Interfaces\PriceFactorInterface */ - public function toPriceFactor($Locale = null) + public function toPriceFactor($Locale = null, $Customer = null) { switch ($this->getAttribute('discount_type')) { case QUI\ERP\Accounting\Calc::CALCULATION_PERCENTAGE: @@ -476,6 +482,15 @@ public function toPriceFactor($Locale = null) $basis = QUI\ERP\Accounting\Calc::CALCULATION_BASIS_CURRENTPRICE; } + // check calculation basis VAT + $useAuto = $this->getAttribute('consider_vat') === 'auto' + && $Customer + && QUI\ERP\Utils\User::isNettoUser($Customer) === false; + + if ($useAuto || $this->getAttribute('consider_vat') === 'brutto') { + $basis = QUI\ERP\Accounting\Calc::CALCULATION_BASIS_VAT_BRUTTO; + } + try { $Plugin = QUI::getPackage('quiqqer/products'); $Config = $Plugin->getConfig(); diff --git a/src/QUI/ERP/Discount/EventHandling.php b/src/QUI/ERP/Discount/EventHandling.php index 14fd306..4bac048 100644 --- a/src/QUI/ERP/Discount/EventHandling.php +++ b/src/QUI/ERP/Discount/EventHandling.php @@ -7,6 +7,7 @@ namespace QUI\ERP\Discount; use QUI; +use QUI\ERP\Accounting\Calc as ErpCalc; use QUI\ERP\Products\Product\UniqueProduct; use QUI\ERP\Products\Utils\Calc; use QUI\ERP\Products\Product\ProductList; @@ -106,7 +107,7 @@ protected static function isDiscountUsableWithPurchaseValue(Discount $Discount, // 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') === Calc::CALCULATION_COMPLEMENT + if ((int)$Discount->getAttribute('discount_type') === ErpCalc::CALCULATION_COMPLEMENT && $Discount->getAttribute('discount') > $value) { return false; } @@ -182,7 +183,8 @@ public static function onQuiqqerProductsCalcListProduct( $Product->getPriceFactors()->addToEnd( $Discount->toPriceFactor( - $Calc->getUser()->getLocale() + $Calc->getUser()->getLocale(), + $Calc->getUser() ) ); @@ -296,7 +298,8 @@ public static function onQuiqqerProductsCalcList( $List->getPriceFactors()->addToEnd( $Discount->toPriceFactor( - $Calc->getUser()->getLocale() + $Calc->getUser()->getLocale(), + $Calc->getUser() ) ); -- GitLab