From 871447cc6e1aaf309928676b74a07fca494515de Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Tue, 5 Mar 2024 08:07:54 +0100 Subject: [PATCH] refs #6321 feat: updates --- db/changes/240601/01-updateACLItemLack.sql | 2 + .../ticket/back/methods/ticket/itemLack.js | 2 +- .../back/methods/ticket/itemLackDetail.js | 81 +++++++++++-------- 3 files changed, 51 insertions(+), 34 deletions(-) diff --git a/db/changes/240601/01-updateACLItemLack.sql b/db/changes/240601/01-updateACLItemLack.sql index 13521325f..90f05e14b 100644 --- a/db/changes/240601/01-updateACLItemLack.sql +++ b/db/changes/240601/01-updateACLItemLack.sql @@ -1,3 +1,5 @@ -- Auto-generated SQL script #202401191358 INSERT INTO salix.ACL (model,property,accessType,permission,principalType,principalId) VALUES ('Ticket','itemLack','READ','ALLOW','ROLE','employee'); +INSERT INTO salix.ACL (model,property,accessType,permission,principalType,principalId) + VALUES ('Ticket','itemLackDetail','READ','ALLOW','ROLE','employee'); diff --git a/modules/ticket/back/methods/ticket/itemLack.js b/modules/ticket/back/methods/ticket/itemLack.js index fa4b500fb..383d0ba5b 100644 --- a/modules/ticket/back/methods/ticket/itemLack.js +++ b/modules/ticket/back/methods/ticket/itemLack.js @@ -167,7 +167,7 @@ module.exports = Self => { return [ { - 'itemFk': 7176, + 'itemFk': 72176, 'longName': 'Anthurium Olivius x20', 'warehouseFk': 60, 'producer': null, diff --git a/modules/ticket/back/methods/ticket/itemLackDetail.js b/modules/ticket/back/methods/ticket/itemLackDetail.js index e0efc4c19..fc3ecd675 100644 --- a/modules/ticket/back/methods/ticket/itemLackDetail.js +++ b/modules/ticket/back/methods/ticket/itemLackDetail.js @@ -1,4 +1,5 @@ /* eslint-disable no-console */ +const ParameterizedSQL = require('loopback-connector').ParameterizedSQL; module.exports = Self => { Self.remoteMethod('itemLackDetail', { description: 'Download a ticket delivery note document', @@ -8,62 +9,76 @@ module.exports = Self => { arg: 'id', type: 'number', description: 'The item id', - } + }, ], returns: [ { arg: 'body', type: ['object'], - root: true - } + root: true, + }, ], http: { path: `/itemLack/:id/detail`, - verb: 'GET' - } + verb: 'GET', + }, }); Self.itemLackDetail = async(id, options) => { - const myOptions = {}; - // const versionSQL = false; - if (typeof options == 'object') - Object.assign(myOptions, options); + const conn = Self.dataSource.connector; - const detail = await Self.rawSQL(` + const myOptions = {}; + if (typeof options == 'object') Object.assign(myOptions, options); + + const stmt = new ParameterizedSQL( + ` SELECT - s.Id_Movimiento, st.code, t.Id_Ticket, t.Alias, t.Fecha, s.Cantidad, ag.Agencia, + s.id saleFk, + st.code, + t.id ticketFk, + t.nickname, + t.hour, + s.quantity, + ag.name, ts.alertLevel alertLevel, st.name stateName, st.id stateId, - s.Id_Article id, + s.itemFk itemFk, al.code alertLevelCode, z.name, z.hour theoreticalhour, cn.isRookie, sc.saleClonedFk turno, tr.saleFk peticionCompra, - t.Fecha minTimed + t.hour minTimed FROM - Sale s - JOIN Tickets t ON t.Id_Ticket=s.Id_Ticket -- vn.ticket - LEFT JOIN zone z ON z.id = t.zoneFk -- vn.zone - LEFT JOIN zoneClosure zc ON zc.zoneFk = t.zoneFk AND zc.dated = DateValue(t.Fecha) - JOIN Clientes c ON c.Id_Cliente=t.Id_Cliente -- vn.client - LEFT JOIN clientNewBorn cn ON cn.clientFk=c.Id_Cliente - JOIN Agencias ag ON ag.Id_Agencia=t.Id_Agencia -- vn.agencyMode - JOIN ticketState tls ON ts.ticketFk=t.Id_Ticket -- vn.sale - LEFT JOIN state s ON st.id=ts.state - LEFT JOIN alertLevel al ON al.id = st.alertLevel - LEFT JOIN saleCloned sc ON sc.saleClonedFk = s.Id_Movimiento - LEFT JOIN ticketRequest tr ON tr.saleFk = s.Id_Movimiento - WHERE - AND s.Id_Article = ? - AND NOT Cantidad - AND Fecha >= util.VN_CURDATE() - AND Fecha < INTERVAL util.VN_CURDATE() + INTERVAL ? + 1 DAY - ORDER BY s.Id_Movimiento DESC+ - `, [id, 2], myOptions); + vn.sale s + JOIN vn.ticket t ON t.id=s.ticketFk -- vn.ticket + LEFT JOIN vn.zone z ON z.id = t.zoneFk -- vn.zone + LEFT JOIN vn.zoneClosure zc ON zc.zoneFk = t.zoneFk -- AND zc.dated = DateValue(t.Fecha) + JOIN vn.client c ON c.id=t.clientFk -- vn.client + LEFT JOIN bs.clientNewBorn cn ON cn.clientFk=c.id + JOIN vn.agencyMode agm ON agm.id=t.agencyModeFk -- vn.agencyMode + JOIN vn.agency ag ON ag.id=agm.id -- vn.agencyMode + JOIN vn.ticketState ts ON ts.ticketFk=t.id -- vn.sale + LEFT JOIN vn.state st ON st.id=ts.state + LEFT JOIN vn.alertLevel al ON al.id = st.alertLevel + LEFT JOIN vn.saleCloned sc ON sc.saleClonedFk = s.id + LEFT JOIN vn.ticketRequest tr ON tr.saleFk = s.id + LIMIT 1 + `, + null + ); + // WHERE + // s.itemFk = ? - return detail; + // AND t.landed >= util.VN_CURDATE() + // AND t.landed < INTERVAL util.VN_CURDATE() + INTERVAL ? + 1 DAY + // ORDER BY s.id DESC+ + // [id,2] + + const sql = ParameterizedSQL.join([stmt], ';'); + const result = await conn.executeStmt(sql, myOptions); + return result; }; };