send message to salesPerson #1315
gitea/salix/dev This commit looks good Details

This commit is contained in:
Joan Sanchez 2019-04-11 09:38:53 +02:00
parent 1dd8fdd96b
commit 353167734e
3 changed files with 27 additions and 6 deletions

View File

@ -3,10 +3,17 @@
vn-td-editable {
text {
border-bottom: 1px solid rgba(0,0,0,.12);
min-height: 15px;
cursor: pointer;
display: block
}
text::after {
overflow: hidden;
content: '';
clear: both;
}
outline: none;
position: relative;
&:not([disabled="true"]) {

View File

@ -80,5 +80,6 @@
"We weren't able to send this SMS": "No hemos podido enviar el SMS",
"This client can't be invoiced": "Este cliente no puede ser facturado",
"This ticket can't be invoiced": "Este ticket no puede ser facturado",
"That item is not available on that day": "That item is not available on that day"
"That item is not available on that day": "That item is not available on that day",
"That item doesn't exists": "That item doesn't exists"
}

View File

@ -31,15 +31,16 @@ module.exports = Self => {
});
Self.confirm = async ctx => {
const models = Self.app.models;
let transaction = await Self.beginTransaction({});
let options = {transaction: transaction};
try {
let item = await Self.app.models.Item.findById(ctx.args.itemFk);
let item = await models.Item.findById(ctx.args.itemFk);
if (!item)
throw new UserError(`That item doesn't exists`);
let request = await Self.app.models.TicketRequest.findById(ctx.args.id, {
let request = await models.TicketRequest.findById(ctx.args.id, {
include: {relation: 'ticket'}
});
@ -60,15 +61,19 @@ module.exports = Self => {
if (request.saleFk) {
let sale = await Self.app.models.Sale.findById(request.saleFk);
sale.updateAttributes({itemFk: ctx.args.itemFk, quantity: ctx.args.quantity, description: item.description}, options);
let sale = await models.Sale.findById(request.saleFk);
sale.updateAttributes({
itemFk: ctx.args.itemFk,
quantity: ctx.args.quantity,
description: item.description
}, options);
} else {
params = {
ticketFk: request.ticketFk,
itemFk: ctx.args.itemFk,
quantity: ctx.args.quantity
};
sale = await Self.app.models.Sale.create(params, options);
sale = await models.Sale.create(params, options);
request.updateAttributes({saleFk: sale.id, itemFk: sale.itemFk}, options);
}
@ -76,6 +81,14 @@ module.exports = Self => {
params = [sale.id];
await Self.rawSql(query, params, options);
const message = `Se ha comprado ${params.quantity} unidades de "${item.description}" (#${params.itemFk}) `
+ `para el ticket #${params.ticketFk}`;
await models.Message.send(ctx, {
recipientFk: request.requesterFk,
message: message
}, options);
await transaction.commit();
} catch (error) {
await transaction.rollback();