4804-ticket.descriptor_sms #1217
|
@ -0,0 +1,3 @@
|
||||||
|
INSERT INTO `salix`.`ACL` (`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`)
|
||||||
|
VALUES
|
||||||
|
('TicketLog', 'getChanges', 'READ', 'ALLOW', 'ROLE', 'employee');
|
|
@ -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`)
|
||||||
|
|
|
@ -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',
|
|
||||||
description: 'the ticket id',
|
|
||||||
type: 'number',
|
type: 'number',
|
||||||
required: true,
|
required: true,
|
||||||
http: {source: 'body'}
|
description: 'the ticket id',
|
||||||
}
|
http: {source: 'path'}
|
||||||
],
|
}],
|
||||||
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 ticketLogs = await models.TicketLog.find({where: {originFk: ticketId}}, myOptions);
|
|
||||||
|
|
||||||
|
const changes = [];
|
||||||
for (const ticketLog of ticketLogs) {
|
for (const ticketLog of ticketLogs) {
|
||||||
if (ticketLog)
|
const isUpdate = ticketLog.action == 'update';
|
||||||
|
|
||||||
|
if (ticketLog.description && isUpdate)
|
||||||
|
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');
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
@ -225,8 +225,14 @@ 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)});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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}}"
|
||||||
|
|
Loading…
Reference in New Issue