diff --git a/modules/ticket/back/methods/sale-tracking/delete.js b/modules/ticket/back/methods/sale-tracking/delete.js new file mode 100644 index 000000000..50f7ff396 --- /dev/null +++ b/modules/ticket/back/methods/sale-tracking/delete.js @@ -0,0 +1,53 @@ + +module.exports = Self => { + Self.remoteMethod('delete', { + description: 'Elimina el registro (si se cumple la condiciĆ³n) y inserta uno nuevo', + accessType: 'READ', + accepts: [ + { + arg: 'saleFk', + type: 'number', + description: 'The sale id' + }, + { + arg: 'stateCode', + type: 'string' + } + ], + returns: { + type: ['object'], + root: true + }, + http: { + path: `/delete`, + verb: 'POST' + } + }); + + Self.delete = async(saleFk, stateCode, options) => { + const models = Self.app.models; + const myOptions = {}; + + if (typeof options == 'object') + Object.assign(myOptions, options); + + // const [itemShelvingSale] = await models.ItemShelvingSale.find({saleFk: saleFk}, myOptions); + // if (itemShelvingSale) await itemShelvingSale.destroy(myOptions); + + // const filter = { + // where: { + // saleFk: saleFk, + // code: stateCode + // } + // }; + // const [saleTracking] = await models.SaleTracking.find(filter, myOptions); + // return saleTracking.destroy(myOptions); + + query = `CALL vn.saleTracking_del(?, ?)`; + return Self.rawSql(query, + [ + saleFk, + stateCode, + ], myOptions); + }; +}; diff --git a/modules/ticket/back/methods/sale-tracking/replace.js b/modules/ticket/back/methods/sale-tracking/replace.js new file mode 100644 index 000000000..886ca4bfa --- /dev/null +++ b/modules/ticket/back/methods/sale-tracking/replace.js @@ -0,0 +1,69 @@ + +module.exports = Self => { + Self.remoteMethodCtx('replace', { + description: 'Remplaza el registro o lo crea si no existe', + accessType: 'READ', + accepts: [ + { + arg: 'saleFk', + type: 'number', + description: 'The sale id' + }, + { + arg: 'isChecked', + type: 'boolean' + }, + { + arg: 'quantity', + type: 'number' + }, + { + arg: 'stateCode', + type: 'string' + } + ], + returns: { + type: ['object'], + root: true + }, + http: { + path: `/replace`, + verb: 'POST' + } + }); + + Self.replace = async(ctx, saleFk, isChecked, quantity, stateCode, options) => { + const models = Self.app.models; + const myOptions = {}; + const userId = ctx.req.accessToken.userId; + + if (typeof options == 'object') + Object.assign(myOptions, options); + + // const state = await models.State.findOne({ + // where: {code: stateCode} + // }, myOptions); + + // if (!state) return; + + // const data = { + // saleFk: saleFk, + // isChecked: isChecked, + // originalQuantity: quantity, + // workerFk: userId, + // stateFk: state.id + // }; + // return models.SaleTracking.replaceOrCreate(data, myOptions); + + query = `CALL vn.saleTracking_new(?, ?, ?, ?, ?, ?)`; + return Self.rawSql(query, + [ + saleFk, + isChecked, + quantity, + userId, + stateCode, + null + ], myOptions); + }; +}; diff --git a/modules/ticket/back/models/sale-tracking.js b/modules/ticket/back/models/sale-tracking.js index 4a46dd6b7..446bdf37b 100644 --- a/modules/ticket/back/models/sale-tracking.js +++ b/modules/ticket/back/models/sale-tracking.js @@ -1,3 +1,5 @@ module.exports = Self => { require('../methods/sale-tracking/listSaleTracking')(Self); + require('../methods/sale-tracking/replace')(Self); + require('../methods/sale-tracking/delete')(Self); }; diff --git a/modules/ticket/front/sale-tracking/index.html b/modules/ticket/front/sale-tracking/index.html index 0309dde13..8d3fa65af 100644 --- a/modules/ticket/front/sale-tracking/index.html +++ b/modules/ticket/front/sale-tracking/index.html @@ -1,6 +1,6 @@ - + - + - + - + - + { - this.salePreparingList = res.data; - for (const salePreparing of this.salePreparingList) { - for (const sale of this.sales) { - if (salePreparing.saleFk == sale.id) - sale.preparingList = salePreparing; - } - } + res.data.forEach(salePreparing => { + const sale = this.sales.find(sale => salePreparing.saleFk === sale.id); + if (sale) sale.preparingList = salePreparing; + }); }); } } @@ -83,12 +80,46 @@ class Controller extends Section { this.saleId = sale.id; this.$.itemShelvingSale.show(); } + + clickPreviousSelected(index) { + const sale = this.sales[index]; + if (!sale.preparingList.isPreviousSelected) { + this.saleTrackingNew(sale, 'PREVIOUS_PREPARATION', false); + sale.preparingList.isPreviousSelected = true; + } else { + this.saleTrackingDel(sale, 'PREVIOUS_PREPARATION'); + sale.preparingList.isPreviousSelected = false; + } + } + + saleTrackingNew(sale, stateCode, isChecked) { + const params = { + saleFk: sale.id, + isChecked: isChecked, + quantity: sale.quantity, + stateCode: stateCode + }; + this.$http.post(`SaleTrackings/replace`, params).then(() => { + this.vnApp.showSuccess(this.$t('Data saved!')); + }); + } + + saleTrackingDel(sale, stateCode) { + const params = { + saleFk: sale.id, + stateCode: stateCode + }; + this.$http.post(`SaleTrackings/delete`, params).then(() => { + this.vnApp.showSuccess(this.$t('Data saved!')); + }); + } } ngModule.vnComponent('vnTicketSaleTracking', { template: require('./index.html'), controller: Controller, bindings: { - ticket: '<' + ticket: '<', + model: '