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
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
(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`)

View File

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

View File

@ -225,9 +225,15 @@ class Controller extends Section {
}
sendChangesSms() {
this.showSMSDialog({
message: this.$t('Send changes')
});
return this.$http.get(`TicketLogs/${this.id}/getChanges`)
.then(res => {
const params = {
ticketId: this.id,
created: this.ticket.updated,
changes: res.data
};
this.showSMSDialog({message: this.$t('Send changes', 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
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?
Send changes: "Verdnatura le recuerda:\rPedido {{ticketId}} día {{created | date: 'dd/MM/yyyy'}}\r{{changes}}"