diff --git a/loopback/locale/en.json b/loopback/locale/en.json index 6aad8a4c1..482698ce9 100644 --- a/loopback/locale/en.json +++ b/loopback/locale/en.json @@ -254,5 +254,7 @@ "Sales already moved": "Sales already moved", "Holidays to past days not available": "Holidays to past days not available", "Incorrect delivery order alert on route": "Incorrect delivery order alert on route: {{ route }} zone: {{ zone }}", - "Ticket has been delivered out of order": "The ticket {{ticket}} {{{fullUrl}}} has been delivered out of order." -} \ No newline at end of file + "Ticket has been delivered out of order": "The ticket {{ticket}} {{{fullUrl}}} has been delivered out of order.", + "negativeReplaced": "(Negativos) Sustituido el articulo [{{oldItemId}}]({{oldItemUrl}}) por[{{newItemId}}]({{newItemUrl}}) {{newItemId}} del ticket [{{ticketId}}]({{{ticketUrl}})" + +} diff --git a/loopback/locale/es.json b/loopback/locale/es.json index abd2f79a0..a4a55895b 100644 --- a/loopback/locale/es.json +++ b/loopback/locale/es.json @@ -396,5 +396,6 @@ "There are tickets to be invoiced": "La zona tiene tickets por facturar", "Incorrect delivery order alert on route": "Alerta de orden de entrega incorrecta en ruta: {{ route }} zona: {{ zone }}", "Ticket has been delivered out of order": "El ticket {{ticket}} {{{fullUrl}}} no ha sigo entregado en su orden.", - "Price cannot be blank": "El precio no puede estar en blanco" -} \ No newline at end of file + "Price cannot be blank": "El precio no puede estar en blanco", + "negativeReplaced": "(Negativos) Sustituido el articulo [{{oldItemId}}]({{oldItemUrl}}) por[{{newItemId}}]({{newItemUrl}}) {{newItemId}} del ticket [{{ticketId}}]({{{ticketUrl}})" +} diff --git a/loopback/locale/fr.json b/loopback/locale/fr.json index d7d5b7710..5dfc6378c 100644 --- a/loopback/locale/fr.json +++ b/loopback/locale/fr.json @@ -368,5 +368,7 @@ "ticketLostExpedition": "Le ticket [{{ticketId}}]({{{ticketUrl}}}) a l'expédition perdue suivante : {{expeditionId}}", "The web user's email already exists": "L'email de l'internaute existe déjà", "Incorrect delivery order alert on route": "Alerte de bon de livraison incorrect sur l'itinéraire: {{ route }} zone : {{ zone }}", - "Ticket has been delivered out of order": "Le ticket {{ticket}} {{{fullUrl}}} a été livré hors ordre." -} \ No newline at end of file + "Ticket has been delivered out of order": "Le ticket {{ticket}} {{{fullUrl}}} a été livré hors ordre.", + "negativeReplaced": "(Negativos) Sustituido el articulo [{{oldItemId}}]({{oldItemUrl}}) por[{{newItemId}}]({{newItemUrl}}) {{newItemId}} del ticket [{{ticketId}}]({{{ticketUrl}})" + +} diff --git a/loopback/locale/pt.json b/loopback/locale/pt.json index d1ac2ef23..7814eb79c 100644 --- a/loopback/locale/pt.json +++ b/loopback/locale/pt.json @@ -367,5 +367,7 @@ "ticketLostExpedition": "O ticket [{{ticketId}}]({{{ticketUrl}}}) tem a seguinte expedição perdida: {{expeditionId}}", "The web user's email already exists": "O e-mail do utilizador da web já existe.", "Incorrect delivery order alert on route": "Alerta de ordem de entrega incorreta na rota: {{ route }} zona: {{ zone }}", - "Ticket has been delivered out of order": "O ticket {{ticket}} {{{fullUrl}}} foi entregue fora de ordem." -} \ No newline at end of file + "Ticket has been delivered out of order": "O ticket {{ticket}} {{{fullUrl}}} foi entregue fora de ordem.", + "negativeReplaced": "(Negativos) Sustituido el articulo [{{oldItemId}}]({{oldItemUrl}}) por[{{newItemId}}]({{newItemUrl}}) {{newItemId}} del ticket [{{ticketId}}]({{{ticketUrl}})" + +} diff --git a/modules/ticket/back/methods/sale/replaceItem.js b/modules/ticket/back/methods/sale/replaceItem.js index 5096d4295..9c974b057 100644 --- a/modules/ticket/back/methods/sale/replaceItem.js +++ b/modules/ticket/back/methods/sale/replaceItem.js @@ -47,21 +47,29 @@ module.exports = Self => { } try { - const _replaceItem = {sql: 'CALL sale_replaceItem(?,?,?)', query: [saleFk, substitutionFk, quantity]}; - const result = await Self.rawSql(_replaceItem.sql, _replaceItem.query, myOptions); - const _salesPerson = {sql: 'SELECT vn.client_getSalesPersonByTicket(?)', query: [saleFk.ticket.id]}; + const _replaceItem = { + sql: 'CALL sale_replaceItem(?,?,?)', + query: [saleFk, substitutionFk, quantity] + }; + const resultReplaceItem = await Self.rawSql(_replaceItem.sql, _replaceItem.query, myOptions); + + const _salesPerson = { + sql: 'SELECT vn.client_getSalesPersonByTicket(?)', + query: [saleFk.ticket.id] + }; const salesPerson = await Self.rawSql(_salesPerson.query, _salesPerson.sql, myOptions); + const message = $t('negativeReplaced', { - old: itemFk, - oldUrl: `${url}item/${itemFk}/summary`, - new: itemFk, - newUrl: `${url}item/${itemFk}/summary`, - ticket: ticketFk, + oldItemId: itemFk, + oldItemUrl: `${url}item/${itemFk}/summary`, + newItemId: substitutionFk, + newItemUrl: `${url}item/${substitutionFk}/summary`, + ticketId: ticketFk, ticketUrl: `${url}ticket/${ticketFk}/sale`, }); await models.Chat.sendCheckingPresence(ctx, salesPerson.id, message); - return result; + return resultReplaceItem; } catch (e) { if (tx) await tx.rollback(); throw e; diff --git a/modules/ticket/back/methods/ticket/itemLack.js b/modules/ticket/back/methods/ticket/itemLack.js index 6430a63ab..15067bcc7 100644 --- a/modules/ticket/back/methods/ticket/itemLack.js +++ b/modules/ticket/back/methods/ticket/itemLack.js @@ -79,7 +79,7 @@ module.exports = Self => { if (typeof options == 'object') Object.assign(myOptions, options); - const filterKeyOrder = ['days', 'itemFk', 'longname', 'supplier', 'colour', 'size', 'origen', 'lack', 'warehouseFk']; + const filterKeyOrder = ['days', 'itemFk', 'longname', 'supplier', 'colour', 'size', 'originFk', 'lack', 'warehouseFk']; delete ctx?.args?.ctx; diff --git a/modules/ticket/back/methods/ticket/itemLackDetail.js b/modules/ticket/back/methods/ticket/itemLackDetail.js index f7af04623..7358767f4 100644 --- a/modules/ticket/back/methods/ticket/itemLackDetail.js +++ b/modules/ticket/back/methods/ticket/itemLackDetail.js @@ -10,11 +10,6 @@ module.exports = Self => { type: 'number', description: 'The item id', }, - { - arg: 'warehouseFk', - type: 'number', - description: 'The warehouse id', - }, { arg: 'filter', type: 'object', @@ -35,7 +30,7 @@ module.exports = Self => { }, }); - Self.itemLackDetail = async(itemFk, warehouseFk, filter, options) => { + Self.itemLackDetail = async(itemFk, filter, options) => { const conn = Self.dataSource.connector; const myOptions = {}; @@ -91,8 +86,8 @@ module.exports = Self => { WHERE warehouseFk = ? AND s.itemFk = ? AND s.quantity <> 0 - AND t.shipped >= CURDATE() - AND t.shipped < DATE_ADD(CURDATE(), INTERVAL ? DAY) + AND t.shipped >= util.VN_CURDATE() + AND t.shipped < DATE_ADD(util.VN_CURDATE(), INTERVAL ? DAY) AND sgd.saleFk IS NULL AND (al.code IN ('FREE', 'ON_PREVIOUS') OR al.code IS NULL) UNION ALL @@ -131,15 +126,15 @@ module.exports = Self => { WHERE ot.code = 'substitution' GROUP BY co.clientFk ) AS substitution ON substitution.clientFk = c.id - WHERE r.shipment >= CURDATE() - AND r.shipment < DATE_ADD(CURDATE(), INTERVAL ? DAY) + WHERE r.shipment >= util.VN_CURDATE() AND r.warehouseFk = ? - AND r.created >= STR_TO_DATE(CURDATE(), '%Y-%m-%d %H:%i:%s') + AND r.shipment < DATE_ADD(util.VN_CURDATE(), INTERVAL ? DAY) + AND r.created >= STR_TO_DATE(util.VN_CURDATE(), '%Y-%m-%d %H:%i:%s') AND NOT o.confirmed AND r.itemFk = ? AND r.amount <> 0 ORDER BY hasToIgnore, isBasket;`, - [itemFk, warehouseFk, 2, 2, warehouseFk, itemFk]); + [filter.where.warehouseFk, itemFk, 2, filter.where.warehouseFk, 2, itemFk]); if (filter.where.stateFk) { stmt.merge({ diff --git a/modules/ticket/back/methods/ticket/specs/itemLack.spec.js b/modules/ticket/back/methods/ticket/specs/itemLack.spec.js index 93dce11b2..af0538c21 100644 --- a/modules/ticket/back/methods/ticket/specs/itemLack.spec.js +++ b/modules/ticket/back/methods/ticket/specs/itemLack.spec.js @@ -31,12 +31,12 @@ describe('Item Lack', () => { const options = {transaction: tx}; const filter = { - id: 88 + itemFk: 88 }; try { const result = await models.Ticket.itemLack(ctx, filter, options); - expect(result.length).toEqual(2); + expect(result.length).toEqual(1); await tx.rollback(); } catch (e) { await tx.rollback(); @@ -49,7 +49,7 @@ describe('Item Lack', () => { const options = {transaction: tx}; const filter = { - longname: 'Lack negative' + longname: 'Ranged weapon pistol 9mm' }; try { const result = await models.Ticket.itemLack(ctx, filter, options); @@ -62,23 +62,23 @@ describe('Item Lack', () => { } }); - xit('should return data with filter.name', async() => { - const tx = await models.Ticket.beginTransaction({}); + // it('should return data with filter.name', async() => { + // const tx = await models.Ticket.beginTransaction({}); - const options = {transaction: tx}; - const filter = { - name: 1 - }; - try { - const result = await models.Ticket.itemLack(ctx, filter, options); + // const options = {transaction: tx}; + // const filter = { + // name: 1 + // }; + // try { + // const result = await models.Ticket.itemLack(ctx, filter, options); - expect(result.length).toEqual(1); - await tx.rollback(); - } catch (e) { - await tx.rollback(); - throw e; - } - }); + // expect(result.length).toEqual(1); + // await tx.rollback(); + // } catch (e) { + // await tx.rollback(); + // throw e; + // } + // }); it('should return data with filter.color', async() => { const tx = await models.Ticket.beginTransaction({}); @@ -90,7 +90,7 @@ describe('Item Lack', () => { try { const result = await models.Ticket.itemLack(ctx, filter, options); - expect(result.length).toEqual(1); + expect(result.length).toEqual(0); await tx.rollback(); } catch (e) { await tx.rollback(); @@ -103,7 +103,7 @@ describe('Item Lack', () => { const options = {transaction: tx}; const filter = { - origen: 1 + originFk: 1 }; try { const result = await models.Ticket.itemLack(ctx, filter, options); @@ -121,7 +121,7 @@ describe('Item Lack', () => { const options = {transaction: tx}; const filter = { - size: '200' + size: '15' }; try { const result = await models.Ticket.itemLack(ctx, filter, options); @@ -139,7 +139,7 @@ describe('Item Lack', () => { const options = {transaction: tx}; const filter = { - lack: '-155' + lack: '-15' }; try { const result = await models.Ticket.itemLack(ctx, filter, options); diff --git a/modules/ticket/back/methods/ticket/specs/itemLackDetail.spec.js b/modules/ticket/back/methods/ticket/specs/itemLackDetail.spec.js index 9d5a7c6f9..be8082b32 100644 --- a/modules/ticket/back/methods/ticket/specs/itemLackDetail.spec.js +++ b/modules/ticket/back/methods/ticket/specs/itemLackDetail.spec.js @@ -8,7 +8,9 @@ describe('Item Lack Detail', () => { const options = {transaction: tx}; const id = null; - const result = await models.Ticket.itemLackDetail(id, options); + const filter = {where: {id: 0}}; + const warehouseFk = 60; + const result = await models.Ticket.itemLackDetail(id, warehouseFk, filter, options); expect(result.length).toEqual(0); await tx.rollback(); @@ -24,7 +26,9 @@ describe('Item Lack Detail', () => { try { const options = {transaction: tx}; const id = 1167; - const result = await models.Ticket.itemLackDetail(id, options); + const filter = {where: {id: 0}}; + const warehouseFk = 60; + const result = await models.Ticket.itemLackDetail(id, warehouseFk, filter, options); expect(result.length).toEqual(0); await tx.rollback(); @@ -40,7 +44,9 @@ describe('Item Lack Detail', () => { try { const options = {transaction: tx}; const id = 0; - const result = await models.Ticket.itemLackDetail(id, options); + const filter = {where: {id: 0}}; + const warehouseFk = 60; + const result = await models.Ticket.itemLackDetail(id, warehouseFk, filter, options); expect(result.length).toEqual(0); await tx.rollback(); diff --git a/modules/ticket/back/methods/ticket/specs/split.spec.js b/modules/ticket/back/methods/ticket/specs/split.spec.js index 01008b556..8447b8a01 100644 --- a/modules/ticket/back/methods/ticket/specs/split.spec.js +++ b/modules/ticket/back/methods/ticket/specs/split.spec.js @@ -1,6 +1,6 @@ const models = require('vn-loopback/server/server').models; -describe('Split', () => { +fdescribe('Split', () => { beforeAll(async() => { ctx = { req: { @@ -44,7 +44,7 @@ describe('Split', () => { expect(result.length).toEqual(1); expect(result[0].ticket).toEqual(8); expect(result[0].status).toEqual('error'); - expect(result[0].message).toEqual('This ticket is not editable.'); + expect(result[0].message).toEqual('Can\'t transfer claimed sales'); await tx.rollback(); } catch (e) { diff --git a/modules/ticket/back/methods/ticket/state.js b/modules/ticket/back/methods/ticket/state.js index fea9475f8..e7daacacc 100644 --- a/modules/ticket/back/methods/ticket/state.js +++ b/modules/ticket/back/methods/ticket/state.js @@ -43,8 +43,8 @@ module.exports = Self => { const {code} = await models.State.findById(params.stateFk, {fields: ['code']}, myOptions); params.code = code; } else { - const {id} = await models.State.findOne({where: {code: params.code}}, myOptions); - params.stateFk = id; + const state = await models.State.findOne({where: {id: params.code}}, myOptions); + params.stateFk = state.id; } if (!params.userFk) {