fix(sale): rocket is only sent if it has sales
gitea/salix/pipeline/pr-master This commit looks good
Details
gitea/salix/pipeline/pr-master This commit looks good
Details
This commit is contained in:
parent
4833ba4def
commit
789e0e65e3
|
@ -86,39 +86,41 @@ module.exports = Self => {
|
||||||
if (salesPersonFk && newStateOrder >= stateChecked.order) {
|
if (salesPersonFk && newStateOrder >= stateChecked.order) {
|
||||||
const sales = await Self.rawSql(`
|
const sales = await Self.rawSql(`
|
||||||
SELECT DISTINCT s.id,
|
SELECT DISTINCT s.id,
|
||||||
s.itemFk,
|
s.itemFk,
|
||||||
s.concept,
|
s.concept,
|
||||||
s.originalQuantity AS oldQuantity,
|
s.originalQuantity AS oldQuantity,
|
||||||
s.quantity AS newQuantity
|
s.quantity AS newQuantity
|
||||||
FROM vn.sale s
|
FROM vn.sale s
|
||||||
WHERE s.ticketFk = ?
|
WHERE s.ticketFk = ?
|
||||||
AND s.originalQuantity IS NOT NULL
|
AND s.originalQuantity IS NOT NULL
|
||||||
AND s.originalQuantity <> s.quantity
|
AND s.originalQuantity <> s.quantity
|
||||||
`, [params.ticketFk], myOptions);
|
`, [params.ticketFk], myOptions);
|
||||||
|
|
||||||
let changes = '';
|
if (sales.length) {
|
||||||
const url = await models.Url.getUrl();
|
let changes = '';
|
||||||
const $t = ctx.req.__;
|
const url = await models.Url.getUrl();
|
||||||
for (let sale of sales) {
|
const $t = ctx.req.__;
|
||||||
changes += `\r\n-` + $t('Changes in sales', {
|
for (let sale of sales) {
|
||||||
itemId: sale.itemFk,
|
changes += `\r\n-` + $t('Changes in sales', {
|
||||||
concept: sale.concept,
|
itemId: sale.itemFk,
|
||||||
oldQuantity: sale.oldQuantity,
|
concept: sale.concept,
|
||||||
newQuantity: sale.newQuantity,
|
oldQuantity: sale.oldQuantity,
|
||||||
itemUrl: `${url}item/${sale.itemFk}/summary`
|
newQuantity: sale.newQuantity,
|
||||||
});
|
itemUrl: `${url}item/${sale.itemFk}/summary`
|
||||||
const currentSale = await models.Sale.findById(sale.id, null, myOptions);
|
});
|
||||||
await currentSale.updateAttributes({
|
const currentSale = await models.Sale.findById(sale.id, null, myOptions);
|
||||||
originalQuantity: currentSale.quantity
|
await currentSale.updateAttributes({
|
||||||
}, myOptions);
|
originalQuantity: currentSale.quantity
|
||||||
}
|
}, myOptions);
|
||||||
|
}
|
||||||
|
|
||||||
const message = $t('Changed sale quantity', {
|
const message = $t('Changed sale quantity', {
|
||||||
ticketId: ticket.id,
|
ticketId: ticket.id,
|
||||||
changes: changes,
|
changes: changes,
|
||||||
ticketUrl: `${url}ticket/${ticket.id}/sale`
|
ticketUrl: `${url}ticket/${ticket.id}/sale`
|
||||||
});
|
});
|
||||||
await models.Chat.sendCheckingPresence(ctx, salesPersonFk, message, myOptions);
|
await models.Chat.sendCheckingPresence(ctx, salesPersonFk, message, myOptions);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
await Self.rawSql(`CALL vn.ticket_setState(?, ?)`, [ticket.id, params.code], myOptions);
|
await Self.rawSql(`CALL vn.ticket_setState(?, ?)`, [ticket.id, params.code], myOptions);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue