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