feat: refs #6321 sql lackDetail step1

This commit is contained in:
Javier Segarra 2025-02-06 10:26:38 +01:00
parent 24411f9af1
commit 1af01ad747
1 changed files with 28 additions and 28 deletions

View File

@ -35,11 +35,10 @@ module.exports = Self => {
const myOptions = {}; const myOptions = {};
if (typeof options == 'object') Object.assign(myOptions, options); if (typeof options == 'object') Object.assign(myOptions, options);
const vDated = Date.vnNew();
const stmt = new ParameterizedSQL( const scopeDays = filter.where.scopeDays ?? 2;
` const stmt = new ParameterizedSQL(`
SELECT SELECT s.id,
s.id,
st.code, st.code,
t.id, t.id,
t.nickname, t.nickname,
@ -56,24 +55,24 @@ module.exports = Self => {
al.code alertLevelCode, al.code alertLevelCode,
z.name zoneName, z.name zoneName,
z.id zoneFk, z.id zoneFk,
Format(z.hour, "hh:mm") theoreticalhour, z.hour theoreticalhour,
cn.isRookie, cn.isRookie,
IF(ISNULL(sc.saleClonedFk),0,1) turno, sc.saleClonedFk turno,
IF(ISNULL(tr.saleFk),0,1) peticionCompra, tr.saleFk peticionCompra,
DATE_FORMAT(IF(HOUR(t.shipped), t.shipped, IF(zc.hour, zc.hour, z.hour)),'%H:%i') minTimed, DATE_FORMAT(IF(HOUR(t.shipped), t.shipped, IF(zc.hour, zc.hour, z.hour)),'%H:%i') minTimed,
FALSE isBasket, FALSE isBasket,
substitution.hasObservation, substitution.hasObservation,
IF(d.code = 'spainTeamVip', 1, 0) hasToIgnore d.code = 'spainTeamVip' hasToIgnore
FROM sale s FROM sale s
LEFT JOIN saleGroupDetail sgd ON sgd.saleFk = s.id LEFT JOIN saleGroupDetail sgd ON sgd.saleFk = s.id
INNER JOIN ticket t ON t.id =s.ticketFk JOIN ticket t ON t.id = s.ticketFk
LEFT JOIN zone z ON z.id = t.zoneFk LEFT JOIN zone z ON z.id = t.zoneFk
LEFT JOIN zoneClosure zc ON zc.zoneFk = t.zoneFk LEFT JOIN zoneClosure zc ON zc.zoneFk = t.zoneFk
AND zc.dated = DATE(t.shipped) AND zc.dated = DATE(t.shipped)
INNER JOIN client c ON c.id=t.clientFk JOIN client c ON c.id=t.clientFk
LEFT JOIN bs.clientNewBorn cn ON cn.clientFk=c.id LEFT JOIN bs.clientNewBorn cn ON cn.clientFk=c.id
INNER JOIN agencyMode ag ON ag.id=t.agencyModeFk JOIN agencyMode ag ON ag.id=t.agencyModeFk
INNER JOIN ticketState tls ON tls.ticketFk=t.id JOIN ticketState tls ON tls.ticketFk=t.id
LEFT JOIN state st ON st.id=tls.state LEFT JOIN state st ON st.id=tls.state
LEFT JOIN alertLevel al ON al.id = st.alertLevel LEFT JOIN alertLevel al ON al.id = st.alertLevel
LEFT JOIN saleCloned sc ON sc.saleClonedFk = s.id LEFT JOIN saleCloned sc ON sc.saleClonedFk = s.id
@ -83,7 +82,7 @@ module.exports = Self => {
LEFT JOIN ( LEFT JOIN (
SELECT co.clientFk, IF(COUNT(*) > 0, FALSE, TRUE) hasObservation SELECT co.clientFk, IF(COUNT(*) > 0, FALSE, TRUE) hasObservation
FROM clientObservation co FROM clientObservation co
INNER JOIN observationType ot ON ot.id = co.observationTypeFk JOIN observationType ot ON ot.id = co.observationTypeFk
WHERE ot.code = 'substitution' WHERE ot.code = 'substitution'
GROUP BY co.clientFk GROUP BY co.clientFk
) substitution ON substitution.clientFk = c.id ) substitution ON substitution.clientFk = c.id
@ -118,11 +117,11 @@ module.exports = Self => {
NULL, NULL,
TRUE, TRUE,
substitution.hasObservation, substitution.hasObservation,
IF(d.code = 'spainTeamVip', 1, 0) d.code = 'spainTeamVip'
FROM hedera.orderRow r FROM hedera.orderRow r
INNER JOIN hedera.order o ON o.id = r.orderFk JOIN hedera.order o ON o.id = r.orderFk
INNER JOIN client c ON c.id = o.customer_id JOIN client c ON c.id = o.customer_id
INNER JOIN agencyMode ag ON ag.id=o.agency_id JOIN agencyMode ag ON ag.id=o.agency_id
LEFT JOIN bs.clientNewBorn cn ON cn.clientFk=c.id LEFT JOIN bs.clientNewBorn cn ON cn.clientFk=c.id
LEFT JOIN workerDepartment wd ON wd.workerFk = c.salesPersonFk LEFT JOIN workerDepartment wd ON wd.workerFk = c.salesPersonFk
LEFT JOIN department d ON d.id = wd.departmentFk LEFT JOIN department d ON d.id = wd.departmentFk
@ -139,16 +138,17 @@ module.exports = Self => {
AND NOT o.confirmed AND NOT o.confirmed
AND r.itemFk = ? AND r.itemFk = ?
AND r.amount AND r.amount
ORDER BY hasToIgnore, isBasket;`, ORDER BY hasToIgnore, isBasket
[ `,
filter.where.warehouseFk, [
itemFk, filter.where.warehouseFk,
2, itemFk,
filter.where.alertLevelCode, scopeDays,
2, filter.where.alertLevelCode,
filter.where.warehouseFk, scopeDays,
itemFk filter.where.warehouseFk,
]); itemFk
]);
const sql = ParameterizedSQL.join([stmt], ';'); const sql = ParameterizedSQL.join([stmt], ';');
const result = await conn.executeStmt(sql, myOptions); const result = await conn.executeStmt(sql, myOptions);