diff --git a/db/dump/fixtures.before.sql b/db/dump/fixtures.before.sql index 547771f4a4..df62cc7873 100644 --- a/db/dump/fixtures.before.sql +++ b/db/dump/fixtures.before.sql @@ -2144,6 +2144,9 @@ UPDATE `vn`.`business` UPDATE `vn`.`business` b SET b.`workerBusinessProfessionalCategoryFk` = 2 WHERE b.`workerFk` = 1110; +UPDATE `vn`.`business` b + SET b.`departmentFk` = 53 + WHERE b.`workerFk` = 72; UPDATE `vn`.`business` b SET b.`departmentFk` = 43 diff --git a/db/routines/vn/procedures/item_getLack.sql b/db/routines/vn/procedures/item_getLack.sql index 1a54f03962..51c09e5226 100644 --- a/db/routines/vn/procedures/item_getLack.sql +++ b/db/routines/vn/procedures/item_getLack.sql @@ -9,7 +9,9 @@ CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`item_getLack`( vSize INT, vOrigen INT, vLack INT, - vWarehouseFk INT + vWarehouseFk INT, + vCategoryFk INT, + vTypeFk INT ) BEGIN /** @@ -26,10 +28,12 @@ BEGIN SELECT i.id itemFk, i.longName, + i.name, w.id warehouseFk, p.`name` producer, i.`size`, i.category, + it.categoryFk, w.name warehouse, SUM(IFNULL(sub.amount,0)) lack, i.inkFk, @@ -59,13 +63,15 @@ BEGIN AND ic.display AND it.code != 'GEN' AND (vSelf IS NULL OR i.id = vSelf) - AND (vLongname IS NULL OR i.name = vLongname) + AND (vLongname IS NULL OR i.longName LIKE CONCAT('%', vLongname, '%')) AND (vProducerName IS NULL OR p.`name` LIKE CONCAT('%', vProducerName, '%')) AND (vColor IS NULL OR vColor = i.inkFk) AND (vSize IS NULL OR vSize = i.`size`) AND (vOrigen IS NULL OR vOrigen = w.id) AND (vLack IS NULL OR vLack = sub.amount) AND (vWarehouseFk IS NULL OR vWarehouseFk = w.id) + AND (vCategoryFk IS NULL OR vCategoryFk = it.categoryFk) + AND (vTypeFk IS NULL OR vTypeFk = i.typeFk) GROUP BY i.id, w.id HAVING lack < 0; diff --git a/modules/ticket/back/methods/sale/replaceItem.js b/modules/ticket/back/methods/sale/replaceItem.js index b1702f17f5..fdfba6f483 100644 --- a/modules/ticket/back/methods/sale/replaceItem.js +++ b/modules/ticket/back/methods/sale/replaceItem.js @@ -90,6 +90,7 @@ module.exports = Self => { }); await models.Chat.sendCheckingPresence(ctx, salesPerson.id, message); + if (tx) await tx.commit(); return resultReplaceItem; } catch (e) { if (tx) await tx.rollback(); diff --git a/modules/ticket/back/methods/ticket/itemLack.js b/modules/ticket/back/methods/ticket/itemLack.js index 7cda324598..7e56ba8079 100644 --- a/modules/ticket/back/methods/ticket/itemLack.js +++ b/modules/ticket/back/methods/ticket/itemLack.js @@ -15,12 +15,12 @@ module.exports = Self => { http: {source: 'query'} }, { - arg: 'id', + arg: 'itemFk', type: 'number', description: 'The item id', }, { - arg: 'longname', + arg: 'longName', type: 'string', description: 'Article name', }, @@ -30,9 +30,9 @@ module.exports = Self => { description: 'Supplier id', }, { - arg: 'colour', + arg: 'inkFk', type: 'string', - description: 'Colour\'s item', + description: 'InkFk\'s item', }, { arg: 'size', @@ -49,6 +49,16 @@ module.exports = Self => { type: 'number', description: 'The warehouse id', }, + { + arg: 'typeFk', + type: 'number', + description: 'The type id', + }, + { + arg: 'categoryFk', + type: 'number', + description: 'The category id', + }, { arg: 'lack', type: 'number', @@ -80,9 +90,9 @@ module.exports = Self => { Object.assign(myOptions, options); const filterKeyOrder = [ - 'id', 'force', 'days', 'longname', 'supplier', - 'colour', 'size', 'originFk', - 'lack', 'warehouseFk' + 'itemFk', 'force', 'days', 'longName', 'supplier', + 'inkFk', 'size', 'originFk', + 'lack', 'warehouseFk', 'categoryFk', 'typeFk' ]; delete ctx?.args?.ctx; diff --git a/modules/ticket/back/methods/ticket/itemLackDetail.js b/modules/ticket/back/methods/ticket/itemLackDetail.js index fb8ce682f6..2b13b5c3ef 100644 --- a/modules/ticket/back/methods/ticket/itemLackDetail.js +++ b/modules/ticket/back/methods/ticket/itemLackDetail.js @@ -37,8 +37,8 @@ module.exports = Self => { if (typeof options == 'object') Object.assign(myOptions, options); const vDated = (Date.vnNew()); vDated.setHours(0, 0, 0, 0); - const scopeDays = filter.where.scopeDays ?? 0; - let alertLevels = filter.where.alertLevelCode; + const scopeDays = filter?.where?.scopeDays ?? 0; + let alertLevels = filter?.where?.alertLevelCode; if (!alertLevels) alertLevels = (await Self.app.models.AlertLevel.find({fields: ['code']})).map(({code}) => code); @@ -46,7 +46,7 @@ module.exports = Self => { const stmt = new ParameterizedSQL(` SELECT s.id, st.code, - t.id, + t.id ticketFk, t.nickname, c.id customerId, t.shipped, diff --git a/modules/ticket/back/methods/ticket/specs/itemLack.spec.js b/modules/ticket/back/methods/ticket/specs/itemLack.spec.js index c746d989d9..fb3a604315 100644 --- a/modules/ticket/back/methods/ticket/specs/itemLack.spec.js +++ b/modules/ticket/back/methods/ticket/specs/itemLack.spec.js @@ -25,7 +25,7 @@ describe('Item Lack', () => { it('should return data with filter.id', async() => { const filter = { - id: 5 + itemFk: 5 }; const result = await models.Ticket.itemLack(ctx, filter, options); @@ -34,7 +34,7 @@ describe('Item Lack', () => { it('should return data with filter.longname', async() => { const filter = { - longname: 'Ranged weapon pistol 9mm' + longName: 'Ranged weapon pistol 9mm' }; const result = await models.Ticket.itemLack(ctx, filter, options); @@ -43,7 +43,7 @@ describe('Item Lack', () => { it('should return data with filter.color', async() => { const filter = { - colour: 'WHT' + inkFk: 'WHT' }; const result = await models.Ticket.itemLack(ctx, filter, options); diff --git a/modules/ticket/back/methods/ticket/specs/split.spec.js b/modules/ticket/back/methods/ticket/specs/split.spec.js index 7543e47d65..f39eebf84f 100644 --- a/modules/ticket/back/methods/ticket/specs/split.spec.js +++ b/modules/ticket/back/methods/ticket/specs/split.spec.js @@ -39,9 +39,13 @@ describe('Split', () => { it('should split tickets with count 2 and success', async() => { const data = {ticketFk: 14, sales: [33]}; - const result = await models.Ticket.split(ctx, data, options); + const result = await models.Ticket.split(ctx, data, Date.vnNew(), options); + const newTicket = await models.Ticket.findById(result.newTicket, null, options); + expect(newTicket).toBeDefined(); expect(data.ticketFk).toEqual(result.ticket); + expect(data.ticketFk).toEqual(result.ticket); + expect(data.ticketFk).not.toEqual(result.newTicket); expect('split').toEqual(result.status); }); }); diff --git a/modules/ticket/back/methods/ticket/split.js b/modules/ticket/back/methods/ticket/split.js index 23223db7d7..f3e688ec89 100644 --- a/modules/ticket/back/methods/ticket/split.js +++ b/modules/ticket/back/methods/ticket/split.js @@ -10,7 +10,7 @@ module.exports = Self => { http: {source: 'body'} }, { - arg: 'date', + arg: 'landed', type: 'date', required: true, } @@ -25,8 +25,7 @@ module.exports = Self => { } }); - Self.split = async(ctx, ticket, options) => { - const {ticketFk} = ticket; + Self.split = async(ctx, {ticketFk, sales}, landed, options) => { const models = Self.app.models; const myOptions = {}; let tx; @@ -51,18 +50,21 @@ module.exports = Self => { [ticketFk], myOptions); if (vNewTicket === 0) return result; - const sales = await models.Sale.find({ - where: {id: {inq: ticket.sales}} + const salesToUpdate = await models.Sale.find({ + where: {id: {inq: sales}} }, myOptions); - const updateIsPicked = sales.map(({sid}) => Self.rawSql(` + const updateIsPicked = salesToUpdate.map(({sid}) => Self.rawSql(` UPDATE vn.sale SET isPicked = (id = ?) WHERE ticketFk = ?`, [sid, ticketFk], myOptions)); await Promise.all(updateIsPicked); - await Self.transferSales(ctx, ticketFk, vNewTicket, sales, myOptions); + await Self.transferSales(ctx, ticketFk, vNewTicket, salesToUpdate, myOptions); await Self.rawSql(`CALL vn.ticket_setState(?, ?)`, [ticketFk, 'FIXING'], myOptions); + + const newTicket = await models.Ticket.findById(vNewTicket, null, myOptions); + await newTicket.updateAttributes({landed}, myOptions); if (tx) await tx.commit(); return {ticket: ticketFk, newTicket: vNewTicket, status: 'split'}; } catch (e) { diff --git a/modules/ticket/back/methods/ticket/state.js b/modules/ticket/back/methods/ticket/state.js index fea9475f8c..792d5bb28a 100644 --- a/modules/ticket/back/methods/ticket/state.js +++ b/modules/ticket/back/methods/ticket/state.js @@ -43,8 +43,16 @@ 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); + const {id, code} = await models.State.findOne({ + where: { + or: [ + {code: params.code}, + {id: params.code} + ] + } + }, myOptions); params.stateFk = id; + params.code = code; } if (!params.userFk) {