From a446e0650f88d5219f4c455078cc6b9a8f6c4703 Mon Sep 17 00:00:00 2001 From: jgallego Date: Thu, 4 Aug 2022 17:52:25 +0200 Subject: [PATCH] recalcPrices --- .../entry/back/methods/entry/recalcPrices.js | 47 +++++++++++++++++++ modules/entry/back/models/entry.js | 1 + modules/entry/front/descriptor/index.html | 5 ++ modules/entry/front/descriptor/index.js | 6 +++ modules/entry/front/descriptor/locale/es.yml | 4 +- 5 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 modules/entry/back/methods/entry/recalcPrices.js diff --git a/modules/entry/back/methods/entry/recalcPrices.js b/modules/entry/back/methods/entry/recalcPrices.js new file mode 100644 index 000000000..56bf51150 --- /dev/null +++ b/modules/entry/back/methods/entry/recalcPrices.js @@ -0,0 +1,47 @@ + +const ParameterizedSQL = require('loopback-connector').ParameterizedSQL; +module.exports = Self => { + Self.remoteMethodCtx('recalcPrices', { + description: 'Recalc all prices in the entry', + accessType: 'WRITE', + accepts: [{ + arg: 'id', + type: 'number', + required: true, + description: 'The entry id', + http: {source: 'path'} + }], + returns: { + type: ['object'], + root: true + }, + http: { + path: `/:id/recalcPrices`, + verb: 'POST' + } + }); + + Self.recalcPrices = async(ctx, id, options) => { + let tx; + const myOptions = {}; + + if (typeof options == 'object') + Object.assign(myOptions, options); + + if (!myOptions.transaction) { + tx = await Self.beginTransaction({}); + myOptions.transaction = tx; + } + + try { + await Self.rawSql('CALL vn.buy_recalcPricesByEntry(?)', [ + id + ], myOptions); + + if (tx) await tx.commit(); + } catch (e) { + if (tx) await tx.rollback(); + throw e; + } + }; +}; diff --git a/modules/entry/back/models/entry.js b/modules/entry/back/models/entry.js index 573e5b1cb..6bb173aab 100644 --- a/modules/entry/back/models/entry.js +++ b/modules/entry/back/models/entry.js @@ -6,4 +6,5 @@ module.exports = Self => { require('../methods/entry/importBuys')(Self); require('../methods/entry/importBuysPreview')(Self); require('../methods/entry/lastItemBuys')(Self); + require('../methods/entry/recalcPrices')(Self); }; diff --git a/modules/entry/front/descriptor/index.html b/modules/entry/front/descriptor/index.html index 7b61a0cf5..4c7ea2476 100644 --- a/modules/entry/front/descriptor/index.html +++ b/modules/entry/front/descriptor/index.html @@ -8,6 +8,11 @@ translate> Show entry report + + Recalc prices +
diff --git a/modules/entry/front/descriptor/index.js b/modules/entry/front/descriptor/index.js index fed3787d4..207b407d2 100644 --- a/modules/entry/front/descriptor/index.js +++ b/modules/entry/front/descriptor/index.js @@ -90,6 +90,12 @@ class Controller extends Descriptor { entryId: this.entry.id }); } + + recalcPrices() { + this.$http.post(`Entries/${this.id}/recalcPrices`).then(() => { + this.vnApp.showSuccess(this.$t('Prices recalculated!')); + }); + } } ngModule.vnComponent('vnEntryDescriptor', { diff --git a/modules/entry/front/descriptor/locale/es.yml b/modules/entry/front/descriptor/locale/es.yml index ad2fef6f3..5c4f9122e 100644 --- a/modules/entry/front/descriptor/locale/es.yml +++ b/modules/entry/front/descriptor/locale/es.yml @@ -4,4 +4,6 @@ All travels with current agency: Todos los envios con la agencia actual All entries with current supplier: Todas las entradas con el proveedor actual Show entry report: Ver informe del pedido Is inventory entry: Es una entrada de inventario -Is virtual entry: Es una redada \ No newline at end of file +Is virtual entry: Es una redada +Recalc prices: Recalcular precios +Prices recalculated: Precios recalculados \ No newline at end of file