Removed temporary table on ticket closure
gitea/salix/pipeline/head This commit looks good
Details
gitea/salix/pipeline/head This commit looks good
Details
This commit is contained in:
parent
db081501eb
commit
edf3f1e96e
|
@ -10,11 +10,9 @@ module.exports = app => {
|
|||
message: 'Task executed successfully'
|
||||
});
|
||||
|
||||
await db.rawSql(`DROP TEMPORARY TABLE IF EXISTS tmp.ticket_close`);
|
||||
await db.rawSql(`
|
||||
CREATE TEMPORARY TABLE tmp.ticket_close ENGINE = MEMORY (
|
||||
const tickets = await db.rawSql(`
|
||||
SELECT
|
||||
t.id AS ticketFk
|
||||
t.id
|
||||
FROM expedition e
|
||||
JOIN ticket t ON t.id = e.ticketFk
|
||||
JOIN warehouse wh ON wh.id = t.warehouseFk AND wh.hasComission
|
||||
|
@ -23,22 +21,22 @@ module.exports = app => {
|
|||
WHERE al.code = 'PACKED'
|
||||
AND DATE(t.shipped) BETWEEN DATE_ADD(CURDATE(), INTERVAL -2 DAY) AND CURDATE()
|
||||
AND t.refFk IS NULL
|
||||
GROUP BY e.ticketFk)`);
|
||||
|
||||
await closeAll(req.args);
|
||||
GROUP BY e.ticketFk`);
|
||||
const ticketIds = tickets.map(ticket => ticket.id);
|
||||
|
||||
await closeAll(ticketIds, req.args);
|
||||
await db.rawSql(`
|
||||
UPDATE ticket t
|
||||
JOIN ticketState ts ON t.id = ts.ticketFk
|
||||
JOIN alertLevel al ON al.alertLevel = ts.alertLevel
|
||||
JOIN agencyMode am ON am.id = t.agencyModeFk
|
||||
JOIN deliveryMethod dm ON dm.id = am.deliveryMethodFk
|
||||
JOIN zone z ON z.id = t.zoneFk
|
||||
SET t.routeFk = NULL
|
||||
WHERE shipped BETWEEN CURDATE() AND util.dayEnd(CURDATE())
|
||||
AND al.code NOT IN('DELIVERED','PACKED')
|
||||
AND t.routeFk
|
||||
AND z.name LIKE '%MADRID%'`);
|
||||
UPDATE ticket t
|
||||
JOIN ticketState ts ON t.id = ts.ticketFk
|
||||
JOIN alertLevel al ON al.alertLevel = ts.alertLevel
|
||||
JOIN agencyMode am ON am.id = t.agencyModeFk
|
||||
JOIN deliveryMethod dm ON dm.id = am.deliveryMethodFk
|
||||
JOIN zone z ON z.id = t.zoneFk
|
||||
SET t.routeFk = NULL
|
||||
WHERE shipped BETWEEN CURDATE() AND util.dayEnd(CURDATE())
|
||||
AND al.code NOT IN('DELIVERED','PACKED')
|
||||
AND t.routeFk
|
||||
AND z.name LIKE '%MADRID%'`);
|
||||
} catch (error) {
|
||||
next(error);
|
||||
}
|
||||
|
@ -54,11 +52,9 @@ module.exports = app => {
|
|||
message: 'Task executed successfully'
|
||||
});
|
||||
|
||||
await db.rawSql(`DROP TEMPORARY TABLE IF EXISTS tmp.ticket_close`);
|
||||
await db.rawSql(`
|
||||
CREATE TEMPORARY TABLE tmp.ticket_close ENGINE = MEMORY (
|
||||
const tickets = await db.rawSql(`
|
||||
SELECT
|
||||
t.id AS ticketFk
|
||||
t.id
|
||||
FROM expedition e
|
||||
JOIN ticket t ON t.id = e.ticketFk
|
||||
JOIN ticketState ts ON ts.ticketFk = t.id
|
||||
|
@ -66,11 +62,12 @@ module.exports = app => {
|
|||
WHERE al.code = 'PACKED'
|
||||
AND t.id = :ticketId
|
||||
AND t.refFk IS NULL
|
||||
GROUP BY e.ticketFk)`, {
|
||||
GROUP BY e.ticketFk`, {
|
||||
ticketId: reqArgs.ticketId
|
||||
});
|
||||
const ticketIds = tickets.map(ticket => ticket.id);
|
||||
|
||||
await closeAll(reqArgs);
|
||||
await closeAll(ticketIds, reqArgs);
|
||||
} catch (error) {
|
||||
next(error);
|
||||
}
|
||||
|
@ -92,11 +89,9 @@ module.exports = app => {
|
|||
message: 'Task executed successfully'
|
||||
});
|
||||
|
||||
await db.rawSql(`DROP TEMPORARY TABLE IF EXISTS tmp.ticket_close`);
|
||||
await db.rawSql(`
|
||||
CREATE TEMPORARY TABLE tmp.ticket_close ENGINE = MEMORY (
|
||||
const tickets = await db.rawSql(`
|
||||
SELECT
|
||||
t.id AS ticketFk
|
||||
t.id
|
||||
FROM expedition e
|
||||
JOIN ticket t ON t.id = e.ticketFk
|
||||
JOIN ticketState ts ON ts.ticketFk = t.id
|
||||
|
@ -106,13 +101,14 @@ module.exports = app => {
|
|||
AND t.warehouseFk = :warehouseId
|
||||
AND DATE(t.shipped) BETWEEN DATE_ADD(:to, INTERVAL -2 DAY) AND :to
|
||||
AND t.refFk IS NULL
|
||||
GROUP BY e.ticketFk)`, {
|
||||
GROUP BY e.ticketFk`, {
|
||||
agencyModeId: reqArgs.agencyModeId,
|
||||
warehouseId: reqArgs.warehouseId,
|
||||
to: reqArgs.to
|
||||
});
|
||||
const ticketIds = tickets.map(ticket => ticket.id);
|
||||
|
||||
await closeAll(reqArgs);
|
||||
await closeAll(ticketIds, reqArgs);
|
||||
} catch (error) {
|
||||
next(error);
|
||||
}
|
||||
|
@ -128,11 +124,9 @@ module.exports = app => {
|
|||
message: 'Task executed successfully'
|
||||
});
|
||||
|
||||
await db.rawSql(`DROP TEMPORARY TABLE IF EXISTS tmp.ticket_close`);
|
||||
await db.rawSql(`
|
||||
CREATE TEMPORARY TABLE tmp.ticket_close ENGINE = MEMORY (
|
||||
const tickets = await db.rawSql(`
|
||||
SELECT
|
||||
t.id AS ticketFk
|
||||
t.id
|
||||
FROM expedition e
|
||||
JOIN ticket t ON t.id = e.ticketFk
|
||||
JOIN ticketState ts ON ts.ticketFk = t.id
|
||||
|
@ -140,17 +134,18 @@ module.exports = app => {
|
|||
WHERE al.code = 'PACKED'
|
||||
AND t.routeFk = :routeId
|
||||
AND t.refFk IS NULL
|
||||
GROUP BY e.ticketFk)`, {
|
||||
GROUP BY e.ticketFk`, {
|
||||
routeId: reqArgs.routeId
|
||||
});
|
||||
const ticketIds = tickets.map(ticket => ticket.id);
|
||||
|
||||
await closeAll(reqArgs);
|
||||
await closeAll(ticketIds, reqArgs);
|
||||
} catch (error) {
|
||||
next(error);
|
||||
}
|
||||
});
|
||||
|
||||
async function closeAll(reqArgs) {
|
||||
async function closeAll(ticketIds, reqArgs) {
|
||||
const failedtickets = [];
|
||||
const tickets = await db.rawSql(`
|
||||
SELECT
|
||||
|
@ -162,12 +157,12 @@ module.exports = app => {
|
|||
c.hasToInvoice,
|
||||
co.hasDailyInvoice,
|
||||
eu.email salesPersonEmail
|
||||
FROM tmp.ticket_close tt
|
||||
JOIN ticket t ON t.id = tt.ticketFk
|
||||
FROM ticket t
|
||||
JOIN client c ON c.id = t.clientFk
|
||||
JOIN province p ON p.id = c.provinceFk
|
||||
JOIN country co ON co.id = p.countryFk
|
||||
LEFT JOIN account.emailUser eu ON eu.userFk = c.salesPersonFk`);
|
||||
LEFT JOIN account.emailUser eu ON eu.userFk = c.salesPersonFk
|
||||
WHERE t.id IN(?)`, [ticketIds]);
|
||||
|
||||
for (const ticket of tickets) {
|
||||
try {
|
||||
|
@ -224,7 +219,5 @@ module.exports = app => {
|
|||
html: body
|
||||
});
|
||||
}
|
||||
|
||||
await db.rawSql(`DROP TEMPORARY TABLE tmp.ticket_close`);
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue