diff --git a/front/core/components/confirm/confirm.js b/front/core/components/confirm/confirm.js index 9d53df798..f187a3cb4 100644 --- a/front/core/components/confirm/confirm.js +++ b/front/core/components/confirm/confirm.js @@ -1,6 +1,7 @@ import ngModule from '../../module'; import Dialog from '../dialog'; import template from './confirm.html'; +import './style.scss'; export default class Confirm extends Dialog { constructor($element, $, $transclude) { diff --git a/front/core/components/confirm/style.scss b/front/core/components/confirm/style.scss new file mode 100644 index 000000000..d3cea6cb1 --- /dev/null +++ b/front/core/components/confirm/style.scss @@ -0,0 +1,3 @@ +.vn-confirm .window { + max-width: 30em +} \ No newline at end of file diff --git a/modules/ticket/back/methods/ticket/recalculateComponents.js b/modules/ticket/back/methods/ticket/recalculateComponents.js new file mode 100644 index 000000000..4b0cbee5d --- /dev/null +++ b/modules/ticket/back/methods/ticket/recalculateComponents.js @@ -0,0 +1,31 @@ +const UserError = require('vn-loopback/util/user-error'); +module.exports = Self => { + Self.remoteMethodCtx('recalculateComponents', { + description: 'Calculates the price of a sale and its components', + accessType: 'WRITE', + accepts: [{ + arg: 'id', + description: 'The ticket id', + type: 'number', + required: true, + http: {source: 'path'} + }], + returns: { + type: 'Number', + root: true + }, + http: { + path: `/:id/recalculateComponents`, + verb: 'POST' + } + }); + + Self.recalculateComponents = async(ctx, id) => { + const isEditable = await Self.isEditable(ctx, id); + + if (!isEditable) + throw new UserError(`The sales of this ticket can't be modified`); + + return Self.rawSql('CALL vn.ticket_recalcComponents(?)', [id]); + }; +}; diff --git a/modules/ticket/back/models/ticket.js b/modules/ticket/back/models/ticket.js index ed3a85da2..c42df62ef 100644 --- a/modules/ticket/back/models/ticket.js +++ b/modules/ticket/back/models/ticket.js @@ -26,6 +26,7 @@ module.exports = Self => { require('../methods/ticket/addSale')(Self); require('../methods/ticket/transferSales')(Self); require('../methods/ticket/canHaveStowaway')(Self); + require('../methods/ticket/recalculateComponents')(Self); Self.observe('before save', async function(ctx) { if (ctx.isNewInstance) return; diff --git a/modules/ticket/front/descriptor/index.html b/modules/ticket/front/descriptor/index.html index 12bd5105d..decc0b6d4 100644 --- a/modules/ticket/front/descriptor/index.html +++ b/modules/ticket/front/descriptor/index.html @@ -198,6 +198,13 @@ + question="Are you sure you want to send it?" + message="Send Delivery Note"> + + + \ No newline at end of file diff --git a/modules/ticket/front/descriptor/index.js b/modules/ticket/front/descriptor/index.js index 9cb320a31..9dac78406 100644 --- a/modules/ticket/front/descriptor/index.js +++ b/modules/ticket/front/descriptor/index.js @@ -35,6 +35,11 @@ class Controller extends Component { callback: this.showRegenerateInvoiceDialog, show: () => this.hasInvoice() }, + { + name: 'Recalculate components', + callback: this.comfirmRecalculateComponents, + show: () => this.isEditable + }, ]; } @@ -287,9 +292,26 @@ class Controller extends Component { return this.ticket.refFk !== null; } + /** + * Shows a delivery-note send confirmation + */ confirmDeliveryNote() { this.$.confirmDeliveryNote.show(); } + + /** + * Shows an invoice confirmation + */ + comfirmRecalculateComponents() { + this.$.recalculateComponentsConfirmation.show(); + } + + recalculateComponents() { + const query = `Tickets/${this.ticket.id}/recalculateComponents`; + this.$http.post(query).then(res => { + this.vnApp.showSuccess(this.$translate.instant('Data saved!')); + }); + } } Controller.$inject = ['$element', '$scope', 'aclService', '$httpParamSerializer']; diff --git a/modules/ticket/front/descriptor/locale/es.yml b/modules/ticket/front/descriptor/locale/es.yml index 1703c5ffb..2f72e226e 100644 --- a/modules/ticket/front/descriptor/locale/es.yml +++ b/modules/ticket/front/descriptor/locale/es.yml @@ -25,4 +25,6 @@ You are going to regenerate the invoice: Vas a regenerar la factura Are you sure you want to regenerate the invoice?: ¿Seguro que quieres regenerar la factura? Invoice sent for a regeneration, will be available in a few minutes: La factura ha sido enviada para ser regenerada, estará disponible en unos minutos Shipped hour updated: Hora de envio modificada -Deleted ticket: Ticket eliminado \ No newline at end of file +Deleted ticket: Ticket eliminado +Recalculate components: Recalcular componentes +Are you sure you want to recalculate the components?: ¿Seguro que quieres recalcular los componentes? \ No newline at end of file