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