From f82870bec674bd3e9c1573a8014a5f71575dc33b Mon Sep 17 00:00:00 2001 From: alexm Date: Mon, 19 Dec 2022 14:39:38 +0100 Subject: [PATCH] feat(item_fixed-price): recalculate rate2 and when change item keep minPrice of item --- db/changes/225001/00-priceFixed_getRate2.sql | 23 ++++++++++ .../item/back/methods/fixed-price/getRate2.js | 34 ++++++++++++++ modules/item/back/models/fixed-price.js | 1 + modules/item/front/fixed-price/index.html | 46 ++++++++++++------- modules/item/front/fixed-price/index.js | 23 +++++++++- modules/item/front/fixed-price/locale/es.yml | 2 - 6 files changed, 109 insertions(+), 20 deletions(-) create mode 100644 db/changes/225001/00-priceFixed_getRate2.sql create mode 100644 modules/item/back/methods/fixed-price/getRate2.js diff --git a/db/changes/225001/00-priceFixed_getRate2.sql b/db/changes/225001/00-priceFixed_getRate2.sql new file mode 100644 index 000000000..cf36efb57 --- /dev/null +++ b/db/changes/225001/00-priceFixed_getRate2.sql @@ -0,0 +1,23 @@ +DROP FUNCTION IF EXISTS `vn`.`priceFixed_getRate2`; + +DELIMITER $$ +$$ +CREATE FUNCTION `vn`.`priceFixed_getRate2`(vFixedPriceFk INT, vRate3 DOUBLE) +RETURNS DOUBLE +BEGIN + + DECLARE vWarehouse INT; + DECLARE vRate2 DOUBLE; + + SELECT round(vRate3 * (1 + ((r.rate2 - r.rate3)/100)), 2) INTO vRate2 + FROM vn.rate r + JOIN vn.priceFixed p ON p.id = vFixedPriceFk + WHERE r.dated <= p.started + AND r.warehouseFk = p.warehouseFk + ORDER BY r.dated DESC + LIMIT 1; + + RETURN vRate2; + +END$$ +DELIMITER ; diff --git a/modules/item/back/methods/fixed-price/getRate2.js b/modules/item/back/methods/fixed-price/getRate2.js new file mode 100644 index 000000000..b8811f425 --- /dev/null +++ b/modules/item/back/methods/fixed-price/getRate2.js @@ -0,0 +1,34 @@ +module.exports = Self => { + Self.remoteMethod('getRate2', { + description: 'Return the rate2.', + accessType: 'READ', + accepts: [ + { + arg: 'fixedPriceId', + type: 'integer', + description: 'The fixedPrice Id', + required: true + }, + { + arg: 'rate3', + type: 'number', + description: `The price rate 3`, + required: true + } + ], + returns: { + type: 'number', + root: true + }, + http: { + path: `/getRate2`, + verb: 'GET' + } + }); + + Self.getRate2 = async(fixedPriceId, rate3) => { + const [result] = await Self.rawSql(`SELECT vn.priceFixed_getRate2(?, ?) as rate2`, + [fixedPriceId, rate3]); + return result.rate2; + }; +}; diff --git a/modules/item/back/models/fixed-price.js b/modules/item/back/models/fixed-price.js index 9c78c586f..91010805f 100644 --- a/modules/item/back/models/fixed-price.js +++ b/modules/item/back/models/fixed-price.js @@ -1,4 +1,5 @@ module.exports = Self => { require('../methods/fixed-price/filter')(Self); require('../methods/fixed-price/upsertFixedPrice')(Self); + require('../methods/fixed-price/getRate2')(Self); }; diff --git a/modules/item/front/fixed-price/index.html b/modules/item/front/fixed-price/index.html index 9498bf96f..f9d177562 100644 --- a/modules/item/front/fixed-price/index.html +++ b/modules/item/front/fixed-price/index.html @@ -41,14 +41,12 @@ Warehouse - P.P.U. + field="rate2"> + Grouping price - P.P.P. + field="rate3"> + Packing price Min price @@ -72,7 +70,7 @@ show-field="name" value-field="id" search-function="$ctrl.itemSearchFunc($search)" - on-change="$ctrl.upsertPrice(price)" + on-change="$ctrl.upsertPrice(price, true)" order="id DESC" tabindex="1"> @@ -112,18 +110,32 @@ - - + + {{price.rate2 | currency: 'EUR':2}} + + + + + - - + + {{price.rate3 | currency: 'EUR':2}} + + + + + { + const rate2 = res.data; + if (rate2) { + price.rate2 = rate2; + this.upsertPrice(price); + } + }); + } } ngModule.vnComponent('vnFixedPrice', { diff --git a/modules/item/front/fixed-price/locale/es.yml b/modules/item/front/fixed-price/locale/es.yml index 3f400336d..6bdfcb678 100644 --- a/modules/item/front/fixed-price/locale/es.yml +++ b/modules/item/front/fixed-price/locale/es.yml @@ -3,5 +3,3 @@ Search prices by item ID or code: Buscar por ID de artículo o código Search fixed prices: Buscar precios fijados Add fixed price: Añadir precio fijado This row will be removed: Esta linea se eliminará -Price By Unit: Precio Por Unidad -Price By Package: Precio Por Paquete \ No newline at end of file