From df26a40e636eab5b8c13f5b858d8d9c207f3ac07 Mon Sep 17 00:00:00 2001 From: vicent Date: Fri, 8 Apr 2022 07:37:17 +0200 Subject: [PATCH 1/9] feat(claim_action): add smart-table and 'change destinantion' to all rows --- .../methods/claim/updateClaimDestination.js | 53 +++++ modules/claim/back/models/claim.js | 1 + modules/claim/front/action/index.html | 190 +++++++++++------- modules/claim/front/action/index.js | 68 +++++++ modules/claim/front/action/locale/es.yml | 5 +- modules/claim/front/action/style.scss | 4 + 6 files changed, 249 insertions(+), 72 deletions(-) create mode 100644 modules/claim/back/methods/claim/updateClaimDestination.js diff --git a/modules/claim/back/methods/claim/updateClaimDestination.js b/modules/claim/back/methods/claim/updateClaimDestination.js new file mode 100644 index 0000000000..104fbaf0b6 --- /dev/null +++ b/modules/claim/back/methods/claim/updateClaimDestination.js @@ -0,0 +1,53 @@ + +module.exports = Self => { + Self.remoteMethod('updateClaimDestination', { + description: 'Update a claim with privileges', + accessType: 'WRITE', + accepts: [{ + arg: 'rows', + type: ['object'], + required: true, + description: `the sales which will be modified the claimDestinationFk` + }, { + arg: 'claimDestinationFk', + type: 'number', + required: true + }], + returns: { + type: 'object', + root: true + }, + http: { + path: `/updateClaimDestination`, + verb: 'post' + } + }); + + Self.updateClaimDestination = async(rows, claimDestinationFk, options) => { + let tx; + const myOptions = {}; + + if (typeof options == 'object') + Object.assign(myOptions, options); + + if (!myOptions.transaction) { + tx = await Self.beginTransaction({}); + myOptions.transaction = tx; + } + + try { + const models = Self.app.models; + for (let row of rows) { + const claimEnd = await models.ClaimEnd.findById(row.id, null, myOptions); + await claimEnd.updateAttribute('claimDestinationFk', claimDestinationFk, myOptions); + } + + if (tx) await tx.commit(); + + return {}; + } catch (e) { + if (tx) await tx.rollback(); + throw e; + } + }; +}; diff --git a/modules/claim/back/models/claim.js b/modules/claim/back/models/claim.js index fba11cfb6a..36187b78b7 100644 --- a/modules/claim/back/models/claim.js +++ b/modules/claim/back/models/claim.js @@ -7,4 +7,5 @@ module.exports = Self => { require('../methods/claim/uploadFile')(Self); require('../methods/claim/updateClaimAction')(Self); require('../methods/claim/isEditable')(Self); + require('../methods/claim/updateClaimDestination')(Self); }; diff --git a/modules/claim/front/action/index.html b/modules/claim/front/action/index.html index 6c0e2402d0..425c0cbe90 100644 --- a/modules/claim/front/action/index.html +++ b/modules/claim/front/action/index.html @@ -19,65 +19,88 @@ -
- - - - - - - - -
- - - - - Id - Ticket - Destination - Landed - Quantity - Description - Price - Disc. - Total - - - - + +
+ + + + + + + + + + +
+
+ + + + + + + + + + + + + + + + + + - - + + + + + + + + + + + + + + +
+ + + IdTicketDestinationLandedQuantityDescriptionPriceDisc.Total
+ {{::saleClaimed.sale.itemFk | zeroFill:6}} - - - - + + {{::saleClaimed.sale.ticketFk}} - - - + + - - {{::saleClaimed.sale.ticket.landed | date: 'dd/MM/yyyy'}} - {{::saleClaimed.sale.quantity}} - {{::saleClaimed.sale.concept}} - {{::saleClaimed.sale.price | currency: 'EUR':2}} - {{::saleClaimed.sale.discount}} % - + {{::saleClaimed.sale.ticket.landed | date: 'dd/MM/yyyy'}}{{::saleClaimed.sale.quantity}}{{::saleClaimed.sale.concept}}{{::saleClaimed.sale.price | currency: 'EUR':2}}{{::saleClaimed.sale.discount}} % {{saleClaimed.sale.quantity * saleClaimed.sale.price * ((100 - saleClaimed.sale.discount) / 100) | currency: 'EUR':2}} - - + - - - - - - - +
+ +
- \ No newline at end of file + + + + + +
+
{{$ctrl.$t('Change destination to all selected rows', {total: $ctrl.checked.length})}}
+ + + + +
+
+ + + + +
\ No newline at end of file diff --git a/modules/claim/front/action/index.js b/modules/claim/front/action/index.js index 4b32142119..c65e45a770 100644 --- a/modules/claim/front/action/index.js +++ b/modules/claim/front/action/index.js @@ -5,6 +5,7 @@ import './style.scss'; export default class Controller extends Section { constructor($element, $) { super($element, $); + this.newDestination; this.filter = { include: [ {relation: 'sale', @@ -21,6 +22,55 @@ export default class Controller extends Section { }; this.getResolvedState(); this.maxResponsibility = 5; + this.smartTableOptions = { + activeButtons: { + search: true + }, + columns: [ + { + field: 'claimDestinationFk', + autocomplete: { + url: 'ClaimDestinations', + showField: 'description', + valueField: 'id' + } + } + ] + }; + } + + exprBuilder(param, value) { + console.log(param, value); + switch (param) { + case 'search': + return {saleFk: value}; + case 'itemFk': + return {'sale.itemFk': value}; + case 'ticketFk': + return {'sale.ticketFk': value}; + case 'claimDestinationFk': + case 'landed': + case 'quantity': + case 'description': + case 'price': + case 'discount': + case 'total': + case 'id': + return {[param]: value}; + } + } + + get checked() { + const salesClaimed = this.$.model.data || []; + console.log(salesClaimed); + + const checkedSalesClaimed = []; + for (let saleClaimed of salesClaimed) { + if (saleClaimed.$checked) + checkedSalesClaimed.push(saleClaimed); + } + + return checkedSalesClaimed; } getResolvedState() { @@ -125,6 +175,24 @@ export default class Controller extends Section { onSave() { this.vnApp.showSuccess(this.$t('Data saved!')); } + + onResponse() { + const rowsToEdit = []; + for (let row of this.checked) + rowsToEdit.push({id: row.id}); + + const data = { + rows: rowsToEdit, + claimDestinationFk: this.newDestination + }; + + const query = `Claims/updateClaimDestination`; + this.$http.post(query, data) + .then(() => { + this.$.model.refresh(); + this.vnApp.showSuccess(this.$t('Data saved!')); + }); + } } ngModule.vnComponent('vnClaimAction', { diff --git a/modules/claim/front/action/locale/es.yml b/modules/claim/front/action/locale/es.yml index 22b2740b35..97640d9dc2 100644 --- a/modules/claim/front/action/locale/es.yml +++ b/modules/claim/front/action/locale/es.yml @@ -7,4 +7,7 @@ Regularize: Regularizar Do you want to insert greuges?: Desea insertar greuges? Insert greuges on client card: Insertar greuges en la ficha del cliente Greuge added: Greuge añadido -ClaimGreugeDescription: Reclamación id {{claimId}} \ No newline at end of file +ClaimGreugeDescription: Reclamación id {{claimId}} +Change destination: Cambiar destino +Change destination to all selected rows: Cambiar destino a {{total}} fila(s) seleccionada(s) +Add observation to all selected clients: Añadir observación a {{total}} cliente(s) seleccionado(s) diff --git a/modules/claim/front/action/style.scss b/modules/claim/front/action/style.scss index bac316287f..f93d41f9f3 100644 --- a/modules/claim/front/action/style.scss +++ b/modules/claim/front/action/style.scss @@ -39,4 +39,8 @@ vn-claim-action { max-height: 350px; } } + + .right { + float: right; + } } \ No newline at end of file From 313e911940e4722ed3c19f0e3226c5cf4e042c7c Mon Sep 17 00:00:00 2001 From: vicent Date: Tue, 12 Apr 2022 10:09:00 +0200 Subject: [PATCH 2/9] fix(claim_action): smart-table --- .../methods/claim-end/deleteSalesClaimed.js | 51 ++++++++++++ .../claim/back/methods/claim-end/filter.js | 82 +++++++++++++++++++ modules/claim/back/models/claim-end.js | 4 + modules/claim/front/action/index.html | 45 +++++----- modules/claim/front/action/index.js | 48 ++++++++--- modules/claim/front/action/style.scss | 2 +- 6 files changed, 198 insertions(+), 34 deletions(-) create mode 100644 modules/claim/back/methods/claim-end/deleteSalesClaimed.js create mode 100644 modules/claim/back/methods/claim-end/filter.js create mode 100644 modules/claim/back/models/claim-end.js diff --git a/modules/claim/back/methods/claim-end/deleteSalesClaimed.js b/modules/claim/back/methods/claim-end/deleteSalesClaimed.js new file mode 100644 index 0000000000..722e3058b4 --- /dev/null +++ b/modules/claim/back/methods/claim-end/deleteSalesClaimed.js @@ -0,0 +1,51 @@ +module.exports = Self => { + Self.remoteMethodCtx('deleteSalesClaimed', { + description: 'Deletes the selected sales', + accessType: 'WRITE', + accepts: [{ + arg: 'sales', + type: ['object'], + required: true, + description: 'The sales to remove' + }], + returns: { + type: ['object'], + root: true + }, + http: { + path: `/deleteSalesClaimed`, + verb: 'POST' + } + }); + + Self.deleteSalesClaimed = async(ctx, sales, 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 promises = []; + for (let sale of sales) { + const deletedSale = models.ClaimEnd.destroyById(sale.id, myOptions); + promises.push(deletedSale); + } + + const deletedSales = await Promise.all(promises); + + if (tx) await tx.commit(); + + return deletedSales; + } catch (e) { + if (tx) await tx.rollback(); + throw e; + } + }; +}; diff --git a/modules/claim/back/methods/claim-end/filter.js b/modules/claim/back/methods/claim-end/filter.js new file mode 100644 index 0000000000..63c7c1657b --- /dev/null +++ b/modules/claim/back/methods/claim-end/filter.js @@ -0,0 +1,82 @@ + +const ParameterizedSQL = require('loopback-connector').ParameterizedSQL; +const buildFilter = require('vn-loopback/util/filter').buildFilter; +const mergeFilters = require('vn-loopback/util/filter').mergeFilters; + +module.exports = Self => { + Self.remoteMethodCtx('filter', { + description: 'Find all instances of the model matched by filter from the data source.', + accessType: 'READ', + accepts: [ + { + arg: 'filter', + type: 'object', + description: 'Filter defining where, order, offset, and limit - must be a JSON-encoded string', + http: {source: 'query'} + }, { + arg: 'search', + type: 'string', + description: `If it's and integer searchs by id, otherwise it searchs by client id`, + http: {source: 'query'} + } + ], + returns: { + type: ['object'], + root: true + }, + http: { + path: `/filter`, + verb: 'GET' + } + }); + + Self.filter = async(ctx, filter, options) => { + const conn = Self.dataSource.connector; + const myOptions = {}; + + if (typeof options == 'object') + Object.assign(myOptions, options); + + const where = buildFilter(ctx.args, (param, value) => { + switch (param) { + case 'search': + return /^\d+$/.test(value) + ? {'i.id': value} + : {'i.name': {like: `%${value}%`}}; + } + }); + + filter = mergeFilters(filter, {where}); + + const stmts = []; + + const stmt = new ParameterizedSQL( + `SELECT * + FROM ( + SELECT + ce.id, + ce.claimFk, + s.itemFk, + s.ticketFk, + ce.claimDestinationFk, + t.landed, + s.quantity, + s.concept, + s.price, + s.discount, + s.quantity * s.price * ((100 - s.discount) / 100) total + FROM vn.claimEnd ce + LEFT JOIN vn.sale s ON s.id = ce.saleFk + LEFT JOIN vn.ticket t ON t.id = s.ticketFk + ) ce` + ); + + stmt.merge(conn.makeSuffix(filter)); + const itemsIndex = stmts.push(stmt) - 1; + + const sql = ParameterizedSQL.join(stmts, ';'); + const result = await conn.executeStmt(sql, myOptions); + + return itemsIndex === 0 ? result : result[itemsIndex]; + }; +}; diff --git a/modules/claim/back/models/claim-end.js b/modules/claim/back/models/claim-end.js new file mode 100644 index 0000000000..5da87b35f4 --- /dev/null +++ b/modules/claim/back/models/claim-end.js @@ -0,0 +1,4 @@ +module.exports = Self => { + require('../methods/claim-end/filter')(Self); + require('../methods/claim-end/deleteSalesClaimed')(Self); +}; diff --git a/modules/claim/front/action/index.html b/modules/claim/front/action/index.html index 425c0cbe90..55372f0e61 100644 --- a/modules/claim/front/action/index.html +++ b/modules/claim/front/action/index.html @@ -1,10 +1,8 @@ - @@ -70,7 +69,7 @@ Destination Landed Quantity - Description + Description Price Disc. Total @@ -90,53 +89,55 @@ - {{::saleClaimed.sale.itemFk | zeroFill:6}} + {{::saleClaimed.itemFk | zeroFill:6}} - {{::saleClaimed.sale.ticketFk}} + {{::saleClaimed.ticketFk}} - {{::saleClaimed.sale.ticket.landed | date: 'dd/MM/yyyy'}} - {{::saleClaimed.sale.quantity}} - {{::saleClaimed.sale.concept}} - {{::saleClaimed.sale.price | currency: 'EUR':2}} - {{::saleClaimed.sale.discount}} % + {{::saleClaimed.landed | date: 'dd/MM/yyyy'}} + {{::saleClaimed.quantity}} + {{::saleClaimed.concept}} + {{::saleClaimed.price | currency: 'EUR':2}} + {{::saleClaimed.discount}} % - {{saleClaimed.sale.quantity * saleClaimed.sale.price * - ((100 - saleClaimed.sale.discount) / 100) | currency: 'EUR':2}} + {{saleClaimed.quantity * saleClaimed.price * + ((100 - saleClaimed.discount) / 100) | currency: 'EUR':2}} - + + + + + { + this.vnApp.showSuccess(this.$t('Data saved!')); + }).catch(e => { + this.$.model.refresh(); + throw e; + }); + } + + removeSales(saleClaimed) { + const params = {sales: [saleClaimed]}; + this.$http.post(`ClaimEnds/deleteSalesClaimed`, params).then(() => { + this.$.model.refresh(); + this.vnApp.showSuccess(this.$t('Data saved!')); + }); + } + getResolvedState() { const query = `ClaimStates/findOne`; const params = { @@ -104,8 +130,8 @@ export default class Controller extends Section { calculateTotals() { this.claimedTotal = 0; this.salesClaimed.forEach(sale => { - const price = sale.sale.quantity * sale.sale.price; - const discount = (sale.sale.discount * (sale.sale.quantity * sale.sale.price)) / 100; + const price = sale.quantity * sale.price; + const discount = (sale.discount * (sale.quantity * sale.price)) / 100; this.claimedTotal += price - discount; }); } diff --git a/modules/claim/front/action/style.scss b/modules/claim/front/action/style.scss index f93d41f9f3..ae41135151 100644 --- a/modules/claim/front/action/style.scss +++ b/modules/claim/front/action/style.scss @@ -41,6 +41,6 @@ vn-claim-action { } .right { - float: right; + padding-left: 620px; } } \ No newline at end of file From 4872407723c74f42f2d455ca58c2450cf9eb75f7 Mon Sep 17 00:00:00 2001 From: vicent Date: Tue, 12 Apr 2022 11:57:56 +0200 Subject: [PATCH 3/9] fix test --- e2e/helpers/selectors.js | 2 +- .../claim/back/methods/claim-end/filter.js | 11 ---------- modules/claim/front/action/index.html | 4 ++-- modules/claim/front/action/index.spec.js | 22 ++++++++++++++++--- 4 files changed, 22 insertions(+), 17 deletions(-) diff --git a/e2e/helpers/selectors.js b/e2e/helpers/selectors.js index d664cfbad9..2b31e7b55f 100644 --- a/e2e/helpers/selectors.js +++ b/e2e/helpers/selectors.js @@ -725,7 +725,7 @@ export default { claimAction: { importClaimButton: 'vn-claim-action vn-button[label="Import claim"]', anyLine: 'vn-claim-action vn-tbody > vn-tr', - firstDeleteLine: 'vn-claim-action vn-tr:nth-child(1) vn-icon-button[icon="delete"]', + firstDeleteLine: 'vn-claim-action tr:nth-child(1) vn-icon-button[icon="delete"]', isPaidWithManaCheckbox: 'vn-claim-action vn-check[ng-model="$ctrl.claim.isChargedToMana"]' }, ordersIndex: { diff --git a/modules/claim/back/methods/claim-end/filter.js b/modules/claim/back/methods/claim-end/filter.js index 63c7c1657b..8bf06a1b15 100644 --- a/modules/claim/back/methods/claim-end/filter.js +++ b/modules/claim/back/methods/claim-end/filter.js @@ -37,17 +37,6 @@ module.exports = Self => { if (typeof options == 'object') Object.assign(myOptions, options); - const where = buildFilter(ctx.args, (param, value) => { - switch (param) { - case 'search': - return /^\d+$/.test(value) - ? {'i.id': value} - : {'i.name': {like: `%${value}%`}}; - } - }); - - filter = mergeFilters(filter, {where}); - const stmts = []; const stmt = new ParameterizedSQL( diff --git a/modules/claim/front/action/index.html b/modules/claim/front/action/index.html index 55372f0e61..8dd84a2c00 100644 --- a/modules/claim/front/action/index.html +++ b/modules/claim/front/action/index.html @@ -87,7 +87,7 @@ {{::saleClaimed.itemFk | zeroFill:6}} @@ -95,7 +95,7 @@ + ng-click="ticketDescriptor.show($event, saleClaimed.ticketFk)"> {{::saleClaimed.ticketFk}} diff --git a/modules/claim/front/action/index.spec.js b/modules/claim/front/action/index.spec.js index f25f2eb3c1..ab104f93a8 100644 --- a/modules/claim/front/action/index.spec.js +++ b/modules/claim/front/action/index.spec.js @@ -43,9 +43,9 @@ describe('claim', () => { describe('calculateTotals()', () => { it('should calculate the total price of the items claimed', () => { controller.salesClaimed = [ - {sale: {quantity: 5, price: 2, discount: 0}}, - {sale: {quantity: 10, price: 2, discount: 0}}, - {sale: {quantity: 10, price: 2, discount: 0}} + {quantity: 5, price: 2, discount: 0}, + {quantity: 10, price: 2, discount: 0}, + {quantity: 10, price: 2, discount: 0} ]; controller.calculateTotals(); @@ -151,5 +151,21 @@ describe('claim', () => { expect(controller.vnApp.showMessage).toHaveBeenCalledWith('Greuge added'); }); }); + + describe('onResponse()', () => { + it('should perform a post query and show a success message', () => { + jest.spyOn(controller.vnApp, 'showSuccess'); + + const data = { + rows: {id: 1}, + claimDestinationFk: 1 + }; + $httpBackend.expect('POST', `Claims/updateClaimDestination`, data).respond({}); + controller.save(data); + $httpBackend.flush(); + + expect(controller.vnApp.showSuccess).toHaveBeenCalled(); + }); + }); }); }); From 5921891161d0ec896a53078e8b890ceb9337de27 Mon Sep 17 00:00:00 2001 From: vicent Date: Tue, 12 Apr 2022 12:20:36 +0200 Subject: [PATCH 4/9] refactor: updated css --- modules/claim/front/action/index.html | 2 +- modules/claim/front/action/style.scss | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/claim/front/action/index.html b/modules/claim/front/action/index.html index 8dd84a2c00..70b0ef0fb5 100644 --- a/modules/claim/front/action/index.html +++ b/modules/claim/front/action/index.html @@ -32,7 +32,7 @@ Date: Tue, 12 Apr 2022 12:32:48 +0200 Subject: [PATCH 5/9] fix: frontTest --- modules/claim/front/action/index.spec.js | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/modules/claim/front/action/index.spec.js b/modules/claim/front/action/index.spec.js index ab104f93a8..458d5e8319 100644 --- a/modules/claim/front/action/index.spec.js +++ b/modules/claim/front/action/index.spec.js @@ -156,12 +156,8 @@ describe('claim', () => { it('should perform a post query and show a success message', () => { jest.spyOn(controller.vnApp, 'showSuccess'); - const data = { - rows: {id: 1}, - claimDestinationFk: 1 - }; - $httpBackend.expect('POST', `Claims/updateClaimDestination`, data).respond({}); - controller.save(data); + $httpBackend.expect('POST', `Claims/updateClaimDestination`).respond({}); + controller.onResponse(); $httpBackend.flush(); expect(controller.vnApp.showSuccess).toHaveBeenCalled(); From ad3b3c44d623208cfcd11686a92ae103aa57ba07 Mon Sep 17 00:00:00 2001 From: vicent Date: Tue, 12 Apr 2022 12:44:46 +0200 Subject: [PATCH 6/9] refactor: replace let for const --- modules/claim/back/methods/claim-end/deleteSalesClaimed.js | 6 ++---- modules/claim/back/methods/claim/updateClaimDestination.js | 6 ++---- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/modules/claim/back/methods/claim-end/deleteSalesClaimed.js b/modules/claim/back/methods/claim-end/deleteSalesClaimed.js index 722e3058b4..d716f650d6 100644 --- a/modules/claim/back/methods/claim-end/deleteSalesClaimed.js +++ b/modules/claim/back/methods/claim-end/deleteSalesClaimed.js @@ -21,15 +21,13 @@ module.exports = Self => { Self.deleteSalesClaimed = async(ctx, sales, options) => { const models = Self.app.models; const myOptions = {}; - let tx; + const tx = await Self.beginTransaction({}); if (typeof options == 'object') Object.assign(myOptions, options); - if (!myOptions.transaction) { - tx = await Self.beginTransaction({}); + if (!myOptions.transaction) myOptions.transaction = tx; - } try { const promises = []; diff --git a/modules/claim/back/methods/claim/updateClaimDestination.js b/modules/claim/back/methods/claim/updateClaimDestination.js index 104fbaf0b6..a4f8238277 100644 --- a/modules/claim/back/methods/claim/updateClaimDestination.js +++ b/modules/claim/back/methods/claim/updateClaimDestination.js @@ -24,16 +24,14 @@ module.exports = Self => { }); Self.updateClaimDestination = async(rows, claimDestinationFk, options) => { - let tx; + const tx = await Self.beginTransaction({}); const myOptions = {}; if (typeof options == 'object') Object.assign(myOptions, options); - if (!myOptions.transaction) { - tx = await Self.beginTransaction({}); + if (!myOptions.transaction) myOptions.transaction = tx; - } try { const models = Self.app.models; From 9a171d5202153bb02ec330c5d1a633300212a5bc Mon Sep 17 00:00:00 2001 From: vicent Date: Tue, 12 Apr 2022 12:45:07 +0200 Subject: [PATCH 7/9] refactor --- modules/claim/back/methods/claim-end/filter.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/modules/claim/back/methods/claim-end/filter.js b/modules/claim/back/methods/claim-end/filter.js index 8bf06a1b15..0dda16a3a7 100644 --- a/modules/claim/back/methods/claim-end/filter.js +++ b/modules/claim/back/methods/claim-end/filter.js @@ -1,7 +1,5 @@ const ParameterizedSQL = require('loopback-connector').ParameterizedSQL; -const buildFilter = require('vn-loopback/util/filter').buildFilter; -const mergeFilters = require('vn-loopback/util/filter').mergeFilters; module.exports = Self => { Self.remoteMethodCtx('filter', { From c1edb8206ee1d32b397516d67831bfb4836244f9 Mon Sep 17 00:00:00 2001 From: vicent Date: Tue, 12 Apr 2022 12:46:26 +0200 Subject: [PATCH 8/9] refactor --- modules/claim/front/action/index.html | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/modules/claim/front/action/index.html b/modules/claim/front/action/index.html index 70b0ef0fb5..059764ae23 100644 --- a/modules/claim/front/action/index.html +++ b/modules/claim/front/action/index.html @@ -114,10 +114,7 @@ {{::saleClaimed.concept}} {{::saleClaimed.price | currency: 'EUR':2}} {{::saleClaimed.discount}} % - - {{saleClaimed.quantity * saleClaimed.price * - ((100 - saleClaimed.discount) / 100) | currency: 'EUR':2}} - + {{saleClaimed.total | currency: 'EUR':2}} Date: Thu, 21 Apr 2022 09:34:13 +0200 Subject: [PATCH 9/9] pull request changed --- .../{deleteSalesClaimed.js => deleteClamedSales.js} | 8 ++++---- .../claim/back/methods/claim/updateClaimDestination.js | 8 ++++++-- modules/claim/back/models/claim-end.js | 2 +- modules/claim/front/action/index.js | 2 +- 4 files changed, 12 insertions(+), 8 deletions(-) rename modules/claim/back/methods/claim-end/{deleteSalesClaimed.js => deleteClamedSales.js} (84%) diff --git a/modules/claim/back/methods/claim-end/deleteSalesClaimed.js b/modules/claim/back/methods/claim-end/deleteClamedSales.js similarity index 84% rename from modules/claim/back/methods/claim-end/deleteSalesClaimed.js rename to modules/claim/back/methods/claim-end/deleteClamedSales.js index d716f650d6..a6142c0fd2 100644 --- a/modules/claim/back/methods/claim-end/deleteSalesClaimed.js +++ b/modules/claim/back/methods/claim-end/deleteClamedSales.js @@ -1,6 +1,6 @@ module.exports = Self => { - Self.remoteMethodCtx('deleteSalesClaimed', { - description: 'Deletes the selected sales', + Self.remoteMethodCtx('deleteClamedSales', { + description: 'Deletes the claimed sales', accessType: 'WRITE', accepts: [{ arg: 'sales', @@ -13,12 +13,12 @@ module.exports = Self => { root: true }, http: { - path: `/deleteSalesClaimed`, + path: `/deleteClamedSales`, verb: 'POST' } }); - Self.deleteSalesClaimed = async(ctx, sales, options) => { + Self.deleteClamedSales = async(ctx, sales, options) => { const models = Self.app.models; const myOptions = {}; const tx = await Self.beginTransaction({}); diff --git a/modules/claim/back/methods/claim/updateClaimDestination.js b/modules/claim/back/methods/claim/updateClaimDestination.js index a4f8238277..190883c6d3 100644 --- a/modules/claim/back/methods/claim/updateClaimDestination.js +++ b/modules/claim/back/methods/claim/updateClaimDestination.js @@ -35,14 +35,18 @@ module.exports = Self => { try { const models = Self.app.models; + const promises = []; for (let row of rows) { const claimEnd = await models.ClaimEnd.findById(row.id, null, myOptions); - await claimEnd.updateAttribute('claimDestinationFk', claimDestinationFk, myOptions); + const updatedClaimEnd = claimEnd.updateAttribute('claimDestinationFk', claimDestinationFk, myOptions); + promises.push(updatedClaimEnd); } + const updatedSales = await Promise.all(promises); + if (tx) await tx.commit(); - return {}; + return updatedSales; } catch (e) { if (tx) await tx.rollback(); throw e; diff --git a/modules/claim/back/models/claim-end.js b/modules/claim/back/models/claim-end.js index 5da87b35f4..75ecda59a6 100644 --- a/modules/claim/back/models/claim-end.js +++ b/modules/claim/back/models/claim-end.js @@ -1,4 +1,4 @@ module.exports = Self => { require('../methods/claim-end/filter')(Self); - require('../methods/claim-end/deleteSalesClaimed')(Self); + require('../methods/claim-end/deleteClamedSales')(Self); }; diff --git a/modules/claim/front/action/index.js b/modules/claim/front/action/index.js index baa3f9781d..10b629f273 100644 --- a/modules/claim/front/action/index.js +++ b/modules/claim/front/action/index.js @@ -93,7 +93,7 @@ export default class Controller extends Section { removeSales(saleClaimed) { const params = {sales: [saleClaimed]}; - this.$http.post(`ClaimEnds/deleteSalesClaimed`, params).then(() => { + this.$http.post(`ClaimEnds/deleteClamedSales`, params).then(() => { this.$.model.refresh(); this.vnApp.showSuccess(this.$t('Data saved!')); });