diff --git a/bin/backend/controls/articles/ArticleList.js b/bin/backend/controls/articles/ArticleList.js index 35df93882d7123074bb25d48dfd35bc5e659a36a..844510c16b15887eb4d04dc91cdc82a1187d031b 100644 --- a/bin/backend/controls/articles/ArticleList.js +++ b/bin/backend/controls/articles/ArticleList.js @@ -530,6 +530,36 @@ define('package/quiqqer/erp/bin/backend/controls/articles/ArticleList', [ this.$priceFactors.splice(prio, 0, priceFactor); }, + + /** + * edit a price factor + * + * { + * calculation : 2, + * calculation_basis: 2, + * description : Form.elements.title.value, + * identifier : "", + * index : priority, + * nettoSum : data.nettoSum, + * nettoSumFormatted: data.nettoSumFormatted, + * sum : data.sum, + * sumFormatted : data.sumFormatted, + * title : Form.elements.title.value, + * value : data.sum, + * valueText : data.sumFormatted, + * vat : Form.elements.vat.value, + * visible : 1 + * } + * + * @param index + * @param priceFactor + */ + editPriceFactor: function (index, priceFactor) { + for (let k in priceFactor) { + this.$priceFactors[index][k] = priceFactor[k]; + } + }, + /** * Return the articles count * diff --git a/bin/backend/controls/articles/BruttoCalcButton.js b/bin/backend/controls/articles/BruttoCalcButton.js index 32179bfb2febea925aafa126d93212cf80302d81..b9214550546d3a756a53a2abd98a214f58b3c005 100644 --- a/bin/backend/controls/articles/BruttoCalcButton.js +++ b/bin/backend/controls/articles/BruttoCalcButton.js @@ -21,7 +21,7 @@ define('package/quiqqer/erp/bin/backend/controls/articles/BruttoCalcButton', [ ], options: { - Price: null + Price: null // input element for the price }, initialize: function (options) { diff --git a/bin/backend/controls/articles/windows/PriceFactors.css b/bin/backend/controls/articles/windows/PriceFactors.css index 333e743ff27825b64f44f428878aef8fab1f2e3f..608ccd6ba36f139630e1c2ff129157ee6bdead5b 100644 --- a/bin/backend/controls/articles/windows/PriceFactors.css +++ b/bin/backend/controls/articles/windows/PriceFactors.css @@ -2,4 +2,12 @@ font-weight: bold; font-size: 10px; margin-right: 5px; -} \ No newline at end of file +} + +.quiqqer-erp-priceFactors-factor button { + border-color: rgba(147, 128, 108, 0.25); + border-style: solid; + border-width: 1px 1px 1px 0; + border-radius: 0; + box-shadow: none; +} diff --git a/bin/backend/controls/articles/windows/PriceFactors.html b/bin/backend/controls/articles/windows/PriceFactors.html index 7e4b869dc9268b1a4a1efee663e35a7472dabfab..244122e9ed9b2d4384d462f02d1aef50daf27a56 100644 --- a/bin/backend/controls/articles/windows/PriceFactors.html +++ b/bin/backend/controls/articles/windows/PriceFactors.html @@ -13,7 +13,7 @@ {{#priceFactors}} <tr data-index="{{index}}"> <td> - <div class="field-container"> + <div class="field-container quiqqer-erp-priceFactors-factor"> <label style="width: 100%; display: flex;"> <span class="field-container-item"> <span class="pricefactor-index">#{{priority}}</span> @@ -21,6 +21,9 @@ </span> <span class="field-container-field">{{valueText}}</span> </label> + <button class="qui-button edit" style="width: 50px; cursor: pointer;"> + <span class="fa fa-edit"></span> + </button> <button class="qui-button delete" style="width: 50px; cursor: pointer;"> <span class="fa fa-close"></span> </button> diff --git a/bin/backend/controls/articles/windows/PriceFactors.js b/bin/backend/controls/articles/windows/PriceFactors.js index 05a385834b12063a64549a3999d484bd2653b2ac..9b2586f4a42bdcb41b762d7ec891ca2db38f0fba 100644 --- a/bin/backend/controls/articles/windows/PriceFactors.js +++ b/bin/backend/controls/articles/windows/PriceFactors.js @@ -122,6 +122,13 @@ define('package/quiqqer/erp/bin/backend/controls/articles/windows/PriceFactors', this.refresh(); }); + Content.getElements('.edit').addEvent('click', (e) => { + e.stop(); + let index = e.target.getParent('tr').get('data-index'); + + this.editPriceFactor(index); + }); + PriceFactorButton.addEvent('click', (e) => { e.stop(); this.addPriceFactor(); @@ -248,6 +255,131 @@ define('package/quiqqer/erp/bin/backend/controls/articles/windows/PriceFactors', }).open(); }, + /** + * edit a price factor window + */ + editPriceFactor: function (index) { + const ArticleList = this.getAttribute('ArticleList'); + let priceFactors = ArticleList.getPriceFactors(); + let calculations = ArticleList.getCalculation(); + + if (!priceFactors.length) { + return; + } + + if (typeof calculations.vatArray === 'undefined') { + calculations.vatArray = {}; + } + + const factor = priceFactors[index]; + + new QUIConfirm({ + icon : 'fa fa-edit', + title : QUILocale.get(lg, 'pricefactors.edit.window.title'), + maxHeight: 400, + maxWidth : 580, + autoclose: false, + events : { + onOpen: (Win) => { + const Content = Win.getContent(); + + Win.Loader.show(); + + Content.set({ + html: Mustache.render(templateAdd, { + titlePrice : QUILocale.get(lg, 'title.price'), + titleTitle : QUILocale.get(lg, 'title.title'), + titlePriority: QUILocale.get(lg, 'title.priority'), + titleVat : QUILocale.get(lg, 'title.vat'), + + calculationBasis : QUILocale.get(lg, 'calculationBasis'), + calculationBasisNetto : QUILocale.get(lg, 'calculationBasis.netto'), + calculationBasisCalcPrice : QUILocale.get(lg, 'calculationBasis.calculationBasisCalcPrice'), + calculationBasisCalcBrutto: QUILocale.get(lg, 'calculationBasis.calculationBasisCalcBrutto'), + }) + }); + + require([ + 'package/quiqqer/erp/bin/backend/controls/articles/BruttoCalcButton' + ], (Calc) => { + new Calc({ + Price: Content.getElement('[name="price"]') + }).inject( + Content.getElement('[name="price"]'), + 'after' + ); + + Content.getElement('[name="priority"]') + .set('value', ArticleList.countPriceFactors() + 1); + + // vat + const VatSelect = Content.getElement('[name="vat"]'); + + for (let vat in calculations.calculations.vatArray) { + new Element('option', { + html : vat + '%', + value: vat + }).inject(VatSelect); + } + + const Form = Content.getElement('form'); + + Form.elements.price.value = factor.nettoSum; + Form.elements.title.value = factor.title; + Form.elements.vat.value = factor.vat; + Form.elements.priority.value = factor.priority; + + Win.Loader.hide(); + }); + }, + + onSubmit: (Win) => { + const Form = Win.getContent().getElement('form'); + const price = Form.elements.price.value; + const currency = ArticleList.getAttribute('currency'); + + if (!price || price === '') { + return; + } + + Win.Loader.show(); + + this.getPriceFactorData( + price, + Form.elements.vat.value, + currency + ).then((data) => { + let priority = Form.elements.priority.value; + + if (priority === '') { + priority = 1; + } + + ArticleList.editPriceFactor(index, { + calculation : 2, + calculation_basis: 2, + description : Form.elements.title.value, + identifier : "", + index : priority - 1, + nettoSum : data.nettoSum, + nettoSumFormatted: data.nettoSumFormatted, + sum : data.sum, + sumFormatted : data.sumFormatted, + title : Form.elements.title.value, + value : data.sum, + valueText : data.valueText, + vat : Form.elements.vat.value, + visible : 1 + }); + + Win.close(); + this.refresh(); + }); + } + } + }).open(); + }, + /** * returns the current currency formatter of the article list * diff --git a/locale.xml b/locale.xml index 62beddf0bd1008a8b7b072b30a46bcb8a590515d..bfd12ba2f0b38f485782e682febe9c3438f6784c 100644 --- a/locale.xml +++ b/locale.xml @@ -1300,6 +1300,11 @@ Allowed characters: Letters, numbers and _ ä ö ü ß]]></en> <en><![CDATA[Edit pricefactors]]></en> </locale> + <locale name="pricefactors.edit.window.title"> + <de><![CDATA[Preisfaktor bearbeiten]]></de> + <en><![CDATA[Edit pricefactor]]></en> + </locale> + <locale name="controls.QuantityUnitWindow.title"> <de><![CDATA[Mengeneinheit]]></de> <en><![CDATA[Quantity unit]]></en>