4804-ticket.descriptor_sms #1217

Merged
vicent merged 12 commits from 4804-ticket.descriptor_sms into dev 2022-12-21 11:30:02 +00:00
5 changed files with 45 additions and 33 deletions
Showing only changes of commit 84c6604dd9 - Show all commits

View File

@ -0,0 +1,3 @@
INSERT INTO `salix`.`ACL` (`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`)
VALUES
('TicketLog', 'getChanges', 'READ', 'ALLOW', 'ROLE', 'employee');

View File

@ -2728,9 +2728,12 @@ UPDATE `account`.`user`
SET `hasGrant` = 1 SET `hasGrant` = 1
WHERE `id` = 66; WHERE `id` = 66;
INSERT INTO `vn`.`ticketLog` (`originFk`, userFk, `action`, changedModel, oldInstance, newInstance, changedModelId) INSERT INTO `vn`.`ticketLog` (`originFk`, userFk, `action`, changedModel, oldInstance, newInstance, changedModelId, `description`)
VALUES VALUES
(7, 18, 'update', 'Sale', '{"quantity":1}', '{"quantity":10}', 22); (7, 18, 'update', 'Sale', '{"quantity":1}', '{"quantity":10}', 1, NULL),
(7, 18, 'update', 'Ticket', '{"quantity":1,"concept":"Chest ammo box"}', '{"quantity":10,"concept":"Chest ammo box"}', 1, NULL),
(7, 18, 'update', 'Sale', '{"price":3}', '{"price":5}', 1, NULL),
(7, 18, 'update', NULL, NULL, NULL, NULL, "Cambio cantidad Melee weapon heavy shield 1x0.5m de '5' a '10'");
INSERT INTO `vn`.`osTicketConfig` (`id`, `host`, `user`, `password`, `oldStatus`, `newStatusId`, `day`, `comment`, `hostDb`, `userDb`, `passwordDb`, `portDb`, `responseType`, `fromEmailId`, `replyTo`) INSERT INTO `vn`.`osTicketConfig` (`id`, `host`, `user`, `password`, `oldStatus`, `newStatusId`, `day`, `comment`, `hostDb`, `userDb`, `passwordDb`, `portDb`, `responseType`, `fromEmailId`, `replyTo`)

View File

@ -1,52 +1,51 @@
module.exports = Self => { module.exports = Self => {
Self.remoteMethodCtx('getChanges', { Self.remoteMethodCtx('getChanges', {
description: 'Get item id and quantity changes on the sales of a ticket', description: 'Check if a ticket is editable',
accessType: 'WRITE', accessType: 'READ',
accepts: [ accepts: [{
{ arg: 'id',
arg: 'ticketId', type: 'number',
description: 'the ticket id', required: true,
type: 'number', description: 'the ticket id',
required: true, http: {source: 'path'}
http: {source: 'body'} }],
}
],
returns: { returns: {
type: 'object', type: 'object',
root: true root: true
}, },
http: { http: {
path: `/:id/getChanges`, path: `/:id/getChanges`,
verb: 'POST' verb: 'get'
} }
}); });
Self.getChanges = async(ctx, ticketId, options) => { Self.getChanges = async(ctx, id, options) => {
const models = Self.app.models; const models = Self.app.models;
const myOptions = {}; const myOptions = {};
let tx;
if (typeof options == 'object') if (typeof options == 'object')
Object.assign(myOptions, options); Object.assign(myOptions, options);
if (!myOptions.transaction) { const ticketLogs = await models.TicketLog.find({where: {originFk: id}}, myOptions);
tx = await Self.beginTransaction({});
myOptions.transaction = tx;
}
try { const changes = [];
const ticketLogs = await models.TicketLog.find({where: {originFk: ticketId}}, myOptions); for (const ticketLog of ticketLogs) {
const isUpdate = ticketLog.action == 'update';
for (const ticketLog of ticketLogs) { if (ticketLog.description && isUpdate)
if (ticketLog) changes.push(ticketLog.description);
const oldQuantity = ticketLog.oldInstance ? ticketLog.oldInstance.quantity : null;
const newQuantity = ticketLog.newInstance ? ticketLog.newInstance.quantity : null;
if (ticketLog.changedModel == 'Sale' && isUpdate && ticketLog.newInstance.quantity) {
const item = await models.Item.findById(ticketLog.changedModelId, null, myOptions);
changes.push(`${item.name} cambia de ${oldQuantity} a ${newQuantity}`);
} }
if (tx) await tx.commit(); if (ticketLog.changedModel == 'Ticket' && isUpdate && ticketLog.newInstance.quantity)
changes.push(`${ticketLog.oldInstance.concept} cambia de ${oldQuantity} a ${newQuantity}`);
return state;
} catch (e) {
if (tx) await tx.rollback();
throw e;
} }
return changes.join('\n');
}; };
}; };

View File

@ -225,9 +225,15 @@ class Controller extends Section {
} }
sendChangesSms() { sendChangesSms() {
this.showSMSDialog({ return this.$http.get(`TicketLogs/${this.id}/getChanges`)
message: this.$t('Send changes') .then(res => {
}); const params = {
ticketId: this.id,
created: this.ticket.updated,
changes: res.data
};
this.showSMSDialog({message: this.$t('Send changes', params)});
});
} }
showSMSDialog(params) { showSMSDialog(params) {

View File

@ -23,3 +23,4 @@ Restore ticket: Restaurar ticket
You are going to restore this ticket: Vas a restaurar este ticket You are going to restore this ticket: Vas a restaurar este ticket
Are you sure you want to restore this ticket?: ¿Seguro que quieres restaurar el ticket? Are you sure you want to restore this ticket?: ¿Seguro que quieres restaurar el ticket?
Are you sure you want to refund all?: ¿Seguro que quieres abonar todo? Are you sure you want to refund all?: ¿Seguro que quieres abonar todo?
Send changes: "Verdnatura le recuerda:\rPedido {{ticketId}} día {{created | date: 'dd/MM/yyyy'}}\r{{changes}}"