From 024cb1e3f4ec1f02b20e52101d4fe17c33cb3807 Mon Sep 17 00:00:00 2001 From: vicent Date: Tue, 6 Jun 2023 11:56:14 +0200 Subject: [PATCH] refs #5561 feat: permite modificar registros --- db/changes/232401/00-aclSaleTracking.sql | 3 + .../back/methods/item-shelving-sale/filter.js | 6 +- modules/item/back/models/item-shelving.json | 5 - modules/monitor/front/index/orders/index.html | 22 ++-- .../back/methods/sale-tracking/delete.js | 26 ++++- .../sale-tracking/deleteSaleGroupDetail.js | 49 ++++++++ .../ticket/back/methods/sale-tracking/new.js | 35 ++++-- modules/ticket/back/models/sale-tracking.js | 1 + modules/ticket/front/sale-tracking/index.html | 106 ++++++------------ modules/ticket/front/sale-tracking/index.js | 80 +++++++++++-- modules/ticket/front/sale-tracking/style.scss | 9 -- 11 files changed, 219 insertions(+), 123 deletions(-) create mode 100644 db/changes/232401/00-aclSaleTracking.sql create mode 100644 modules/ticket/back/methods/sale-tracking/deleteSaleGroupDetail.js diff --git a/db/changes/232401/00-aclSaleTracking.sql b/db/changes/232401/00-aclSaleTracking.sql new file mode 100644 index 000000000..441945fe2 --- /dev/null +++ b/db/changes/232401/00-aclSaleTracking.sql @@ -0,0 +1,3 @@ +INSERT INTO `salix`.`ACL` (model, property, accessType, permission, principalType, principalId) + VALUES + ('SaleTracking', 'deleteSaleGroupDetail', 'WRITE', 'ALLOW', 'ROLE', 'employee'); diff --git a/modules/item/back/methods/item-shelving-sale/filter.js b/modules/item/back/methods/item-shelving-sale/filter.js index 12029d33d..01a9f1856 100644 --- a/modules/item/back/methods/item-shelving-sale/filter.js +++ b/modules/item/back/methods/item-shelving-sale/filter.js @@ -28,11 +28,15 @@ module.exports = Self => { Object.assign(myOptions, options); const stmt = new ParameterizedSQL(` - SELECT iss.created, + SELECT + iss.id, + iss.created, iss.saleFk, iss.quantity, iss.userFk, + ish.id itemShelvingFk, ish.shelvingFk, + s.parkingFk, p.code, u.name FROM itemShelvingSale iss diff --git a/modules/item/back/models/item-shelving.json b/modules/item/back/models/item-shelving.json index 49bebcb6b..0b1d0eceb 100644 --- a/modules/item/back/models/item-shelving.json +++ b/modules/item/back/models/item-shelving.json @@ -35,11 +35,6 @@ "type": "belongsTo", "model": "VnUser", "foreignKey": "userFk" - }, - "shelving": { - "type": "belongsTo", - "model": "Shelving", - "foreignKey": "shelvingFk" } } } diff --git a/modules/monitor/front/index/orders/index.html b/modules/monitor/front/index/orders/index.html index 74e80e40e..4d1171185 100644 --- a/modules/monitor/front/index/orders/index.html +++ b/modules/monitor/front/index/orders/index.html @@ -32,7 +32,7 @@ - @@ -46,7 +46,7 @@ ui-sref="order.card.summary({id: {{::order.id}}})" target="_blank"> - @@ -98,7 +98,7 @@ scroll-offset="100"> - Filter by selection - Exclude selection - Remove filter - Remove all filters - Copy value @@ -138,4 +138,4 @@ on-accept="$ctrl.onDelete()" question="All the selected elements will be deleted. Are you sure you want to continue?" message="Delete selected elements"> - \ No newline at end of file + diff --git a/modules/ticket/back/methods/sale-tracking/delete.js b/modules/ticket/back/methods/sale-tracking/delete.js index 68b8b8ddc..000c52621 100644 --- a/modules/ticket/back/methods/sale-tracking/delete.js +++ b/modules/ticket/back/methods/sale-tracking/delete.js @@ -26,15 +26,29 @@ module.exports = Self => { Self.delete = async(saleFk, stateCode, options) => { const myOptions = {}; + let tx; if (typeof options == 'object') Object.assign(myOptions, options); - query = `CALL vn.saleTracking_del(?, ?)`; - return Self.rawSql(query, - [ - saleFk, - stateCode, - ], myOptions); + if (!myOptions.transaction) { + tx = await Self.beginTransaction({}); + myOptions.transaction = tx; + } + + try { + const result = await Self.rawSql(`CALL vn.saleTracking_del(?, ?)`, + [ + saleFk, + stateCode, + ], myOptions); + + if (tx) await tx.commit(); + + return result; + } catch (e) { + if (tx) await tx.rollback(); + throw e; + } }; }; diff --git a/modules/ticket/back/methods/sale-tracking/deleteSaleGroupDetail.js b/modules/ticket/back/methods/sale-tracking/deleteSaleGroupDetail.js new file mode 100644 index 000000000..13806edf0 --- /dev/null +++ b/modules/ticket/back/methods/sale-tracking/deleteSaleGroupDetail.js @@ -0,0 +1,49 @@ + +module.exports = Self => { + Self.remoteMethod('deleteSaleGroupDetail', { + description: 'Elimina los registros de saleGroupDetail', + accessType: 'WRITE', + accepts: [ + { + arg: 'saleFk', + type: 'number', + description: 'The sale id' + } + ], + returns: { + type: ['object'], + root: true + }, + http: { + path: `/deleteSaleGroupDetail`, + verb: 'POST' + } + }); + + Self.deleteSaleGroupDetail = async(saleFk, options) => { + const models = Self.app.models; + const myOptions = {}; + let tx; + + if (typeof options == 'object') + Object.assign(myOptions, options); + + if (!myOptions.transaction) { + tx = await Self.beginTransaction({}); + myOptions.transaction = tx; + } + + try { + const deletes = await models.SaleGroupDetail.destroyAll({ + saleFk: saleFk + }, myOptions); + + if (tx) await tx.commit(); + + return deletes; + } catch (e) { + if (tx) await tx.rollback(); + throw e; + } + }; +}; diff --git a/modules/ticket/back/methods/sale-tracking/new.js b/modules/ticket/back/methods/sale-tracking/new.js index d946fc40c..ec5951d7d 100644 --- a/modules/ticket/back/methods/sale-tracking/new.js +++ b/modules/ticket/back/methods/sale-tracking/new.js @@ -33,21 +33,34 @@ module.exports = Self => { }); Self.new = async(ctx, saleFk, isChecked, quantity, stateCode, options) => { - const myOptions = {}; const userId = ctx.req.accessToken.userId; + const myOptions = {}; + let tx; if (typeof options == 'object') Object.assign(myOptions, options); - query = `CALL vn.saleTracking_new(?, ?, ?, ?, ?, ?, ?)`; - return Self.rawSql(query, - [ - saleFk, - isChecked, - quantity, - userId, - stateCode, - null - ], myOptions); + if (!myOptions.transaction) { + tx = await Self.beginTransaction({}); + myOptions.transaction = tx; + } + try { + const result = await Self.rawSql(`CALL vn.saleTracking_new(?, ?, ?, ?, ?, ?)`, + [ + saleFk, + isChecked, + quantity, + userId, + stateCode, + null + ], myOptions); + + if (tx) await tx.commit(); + + return result; + } catch (e) { + if (tx) await tx.rollback(); + throw e; + } }; }; diff --git a/modules/ticket/back/models/sale-tracking.js b/modules/ticket/back/models/sale-tracking.js index 54a2b5a1a..38de256be 100644 --- a/modules/ticket/back/models/sale-tracking.js +++ b/modules/ticket/back/models/sale-tracking.js @@ -3,4 +3,5 @@ module.exports = Self => { require('../methods/sale-tracking/listSaleTracking')(Self); require('../methods/sale-tracking/new')(Self); require('../methods/sale-tracking/delete')(Self); + require('../methods/sale-tracking/deleteSaleGroupDetail')(Self); }; diff --git a/modules/ticket/front/sale-tracking/index.html b/modules/ticket/front/sale-tracking/index.html index e51bc7499..1ae845a74 100644 --- a/modules/ticket/front/sale-tracking/index.html +++ b/modules/ticket/front/sale-tracking/index.html @@ -6,6 +6,16 @@ order="concept ASC, quantity DESC" auto-load="true"> + + + + @@ -29,7 +39,7 @@ }" class="circleState" vn-tooltip="sale group detail" - > + vn-click-stop="$ctrl.clickSaleGroupDetail($index)"> + - + Quantity Worker - Shelving - Parking + Shelving + Parking Created @@ -186,7 +195,7 @@ + on-change="$ctrl.updateQuantity(itemShelvingSale)"> @@ -197,8 +206,24 @@ {{::itemShelvingSale.name | dashIfEmpty}} - {{::itemShelvingSale.shelvingFk}} - {{::itemShelvingSale.code}} + + + + + + + + {{::itemShelvingSale.created | date: 'dd/MM/yyyy HH:mm'}} @@ -209,64 +234,3 @@ vn-id="worker-descriptor"> - - - diff --git a/modules/ticket/front/sale-tracking/index.js b/modules/ticket/front/sale-tracking/index.js index 3016043d6..8521a03af 100644 --- a/modules/ticket/front/sale-tracking/index.js +++ b/modules/ticket/front/sale-tracking/index.js @@ -28,49 +28,61 @@ class Controller extends Section { this.$.itemShelvingSale.show(); } + clickSaleGroupDetail(index) { + const sale = this.sales[index]; + const params = { + saleFk: sale.saleFk + }; + return this.$http.post('SaleTrackings/deleteSaleGroupDetail', params) + .then(() => { + sale.hasSaleGroupDetail = false; + this.vnApp.showSuccess(this.$t('Data saved!')); + }); + } + clickPreviousSelected(index) { const sale = this.sales[index]; if (!sale.isPreviousSelected) { - sale.isPreviousSelected = true; this.saleTrackingNew(sale, 'PREVIOUS_PREPARATION', false); + sale.isPreviousSelected = true; } else { + this.saleTrackingDel(sale, 'PREVIOUS_PREPARATION'); sale.isPreviousSelected = false; sale.isPrevious = false; - this.saleTrackingDel(sale, 'PREVIOUS_PREPARATION'); } } clickPrevious(index) { const sale = this.sales[index]; if (!sale.isPrevious) { + this.saleTrackingNew(sale, 'PREVIOUS_PREPARATION', true); sale.isPrevious = true; sale.isPreviousSelected = true; - this.saleTrackingNew(sale, 'PREVIOUS_PREPARATION', true); } else { - sale.isPrevious = false; this.saleTrackingNew(sale, 'PREVIOUS_PREPARATION', false); + sale.isPrevious = false; } } clickPrepared(index) { const sale = this.sales[index]; if (!sale.isPrepared) { - sale.isPrepared = true; this.saleTrackingNew(sale, 'PREPARED', true); + sale.isPrepared = true; } else { - sale.isPrepared = false; this.saleTrackingDel(sale, 'PREPARED'); + sale.isPrepared = false; } } clickControled(index) { const sale = this.sales[index]; if (!sale.isControled) { - sale.isControled = true; this.saleTrackingNew(sale, 'CHECKED', true); + sale.isControled = true; } else { - sale.isControled = false; this.saleTrackingDel(sale, 'CHECKED'); + sale.isControled = false; } } @@ -81,7 +93,7 @@ class Controller extends Section { quantity: sale.quantity, stateCode: stateCode }; - this.$http.post(`SaleTrackings/replace`, params).then(() => { + this.$http.post(`SaleTrackings/new`, params).then(() => { this.vnApp.showSuccess(this.$t('Data saved!')); }); } @@ -95,6 +107,56 @@ class Controller extends Section { this.vnApp.showSuccess(this.$t('Data saved!')); }); } + + updateQuantity(itemShelvingSale) { + const params = { + quantity: itemShelvingSale.quantity + }; + this.$http.patch(`ItemShelvingSales/${itemShelvingSale.id}`, params) + .then(() => { + this.vnApp.showSuccess(this.$t('Data saved!')); + }); + } + + updateShelving(itemShelvingSale) { + const params = { + shelvingFk: itemShelvingSale.shelvingFk + }; + this.$http.patch(`ItemShelvings/${itemShelvingSale.itemShelvingFk}`, params) + .then(res => { + const filter = { + fields: ['parkingFk'], + where: { + code: res.data.shelvingFk + } + }; + this.$http.get(`Shelvings/findOne`, {filter}) + .then(res => { + itemShelvingSale.parkingFk = res.data.parkingFk; + }); + + this.vnApp.showSuccess(this.$t('Data saved!')); + }); + } + + updateParking(itemShelvingSale) { + const filter = { + fields: ['id'], + where: { + code: itemShelvingSale.shelvingFk + } + }; + this.$http.get(`Shelvings/findOne`, {filter}) + .then(res => { + const params = { + parkingFk: itemShelvingSale.parkingFk + }; + this.$http.patch(`Shelvings/${res.data.id}`, params) + .then(() => { + this.vnApp.showSuccess(this.$t('Data saved!')); + }); + }); + } } ngModule.vnComponent('vnTicketSaleTracking', { diff --git a/modules/ticket/front/sale-tracking/style.scss b/modules/ticket/front/sale-tracking/style.scss index 78a0bda1d..f0807d75d 100644 --- a/modules/ticket/front/sale-tracking/style.scss +++ b/modules/ticket/front/sale-tracking/style.scss @@ -1,14 +1,5 @@ @import "variables"; -vn-sale-tracking { - .chip { - display: inline-block; - min-width: 15px; - min-height: 25px; - } - -} - .circleState { display: inline-block; justify-content: center;