From bbcf71619ce2f80be8dcfb8c1dff604d9b88651a Mon Sep 17 00:00:00 2001 From: sergiodt Date: Wed, 2 Oct 2024 09:56:36 +0200 Subject: [PATCH 1/5] fix: refs #6861 duplicatedTicketsInReserve --- .../vn/procedures/collection_getTickets.sql | 7 +-- .../itemShelvingSale_addBySale copy.sql | 48 +++++++++++++++++++ 2 files changed, 52 insertions(+), 3 deletions(-) create mode 100644 db/routines/vn/procedures/itemShelvingSale_addBySale copy.sql diff --git a/db/routines/vn/procedures/collection_getTickets.sql b/db/routines/vn/procedures/collection_getTickets.sql index 0f675041a..1391c27d4 100644 --- a/db/routines/vn/procedures/collection_getTickets.sql +++ b/db/routines/vn/procedures/collection_getTickets.sql @@ -46,7 +46,7 @@ BEGIN LEFT JOIN observation ob ON ob.ticketFk = t.id WHERE t.id = vParamFk AND t.shipped >= vYesterday - UNION ALL + UNION SELECT t.id ticketFk, IF(NOT(vItemPackingTypeFk <=> 'V'), cc.code, CONCAT(SUBSTRING('ABCDEFGH', tc.wagon, 1), '-', tc.`level`)) `level`, am.name agencyName, @@ -67,7 +67,7 @@ BEGIN LEFT JOIN vn.worker w ON w.id = c.salesPersonFk LEFT JOIN observation ob ON ob.ticketFk = t.id WHERE tc.collectionFk = vParamFk - UNION ALL + UNION SELECT sg.ticketFk, NULL `level`, am.name agencyName, @@ -84,6 +84,7 @@ BEGIN LEFT JOIN observation ob ON ob.ticketFk = t.id LEFT JOIN vn.client c ON c.id = t.clientFk WHERE sc.id = vParamFk - AND t.shipped >= vYesterday; + AND t.shipped >= vYesterday + GROUP BY ticketFk; END$$ DELIMITER ; diff --git a/db/routines/vn/procedures/itemShelvingSale_addBySale copy.sql b/db/routines/vn/procedures/itemShelvingSale_addBySale copy.sql new file mode 100644 index 000000000..7da1a82fa --- /dev/null +++ b/db/routines/vn/procedures/itemShelvingSale_addBySale copy.sql @@ -0,0 +1,48 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`itemShelvingSale_deleteAdded`( + vSelf INT(11) +) +proc: BEGIN +/** + * Borra una reservea devolviendo la cantidad al itemShelving + * + * @param vSelf Identificador del itemShelvingSale + */ + DECLARE vSaleFk INT; + DECLARE vHasSalesPicked BOOL; + + DECLARE EXIT HANDLER FOR SQLEXCEPTION + BEGIN + ROLLBACK; + RESIGNAL; + END; + + SELECT iss.saleFk INTO vSaleFk + FROM itemShelvingSale iss + JOIN sale s ON s.id = iss.saleFk + WHERE iss.id = vSelf AND s.isAdded ; + + IF vSaleFk IS NULL THEN + CALL util.throw('The sale can not be deleted'); + END IF; + + SELECT COUNT(*) INTO vHasSalesPicked + FROM itemShelvingSale + WHERE saleFk = vSaleFk AND isPicked; + + IF vHasSalesPicked THEN + CALL util.throw('The sale can not be deleted with sales picked'); + END IF; + + START TRANSACTION; + + UPDATE itemShelvingSale iss + JOIN itemShelving ish ON ish.id = iss.itemShelvingFk + SET ish.available = ish.available + iss.quantity + WHERE iss.saleFk = vSaleFk; + + DELETE FROM sale WHERE id = vSaleFk; + + COMMIT; +END$$ +DELIMITER ; \ No newline at end of file From 324875ec1f779f049b996b821418470378a627b0 Mon Sep 17 00:00:00 2001 From: sergiodt Date: Fri, 4 Oct 2024 10:42:33 +0200 Subject: [PATCH 2/5] fix: refs #6861 deleteAdded --- .../vn/procedures/collection_getTickets.sql | 5 ++--- ...copy.sql => itemShelvingSale_deleteAdded.sql} | 16 ++++++++-------- 2 files changed, 10 insertions(+), 11 deletions(-) rename db/routines/vn/procedures/{itemShelvingSale_addBySale copy.sql => itemShelvingSale_deleteAdded.sql} (85%) diff --git a/db/routines/vn/procedures/collection_getTickets.sql b/db/routines/vn/procedures/collection_getTickets.sql index 1391c27d4..fed7a3eb6 100644 --- a/db/routines/vn/procedures/collection_getTickets.sql +++ b/db/routines/vn/procedures/collection_getTickets.sql @@ -21,9 +21,8 @@ BEGIN SELECT tob.ticketFk, tob.description FROM vn.ticketObservation tob JOIN vn.ticketCollection tc ON tc.ticketFk = tob.ticketFk - LEFT JOIN vn.observationType ot ON ot.id = tob.observationTypeFk - WHERE ot.`code` = 'itemPicker' - AND tc.collectionFk = vParamFk + JOIN vn.observationType ot ON ot.id = tob.observationTypeFk AND ot.`code` = 'itemPicker' + WHERE tc.collectionFk = vParamFk OR tc.ticketFk = vParamFk ) SELECT t.id ticketFk, IF(!(vItemPackingTypeFk <=> 'V'), cc.code, CONCAT(SUBSTRING('ABCDEFGH', tc.wagon, 1), '-', tc.`level`)) `level`, diff --git a/db/routines/vn/procedures/itemShelvingSale_addBySale copy.sql b/db/routines/vn/procedures/itemShelvingSale_deleteAdded.sql similarity index 85% rename from db/routines/vn/procedures/itemShelvingSale_addBySale copy.sql rename to db/routines/vn/procedures/itemShelvingSale_deleteAdded.sql index 7da1a82fa..0de523127 100644 --- a/db/routines/vn/procedures/itemShelvingSale_addBySale copy.sql +++ b/db/routines/vn/procedures/itemShelvingSale_deleteAdded.sql @@ -12,15 +12,17 @@ proc: BEGIN DECLARE vHasSalesPicked BOOL; DECLARE EXIT HANDLER FOR SQLEXCEPTION - BEGIN - ROLLBACK; - RESIGNAL; - END; + BEGIN + ROLLBACK; + RESIGNAL; + END; + + START TRANSACTION; SELECT iss.saleFk INTO vSaleFk FROM itemShelvingSale iss JOIN sale s ON s.id = iss.saleFk - WHERE iss.id = vSelf AND s.isAdded ; + WHERE iss.id = vSelf AND s.isAdded; IF vSaleFk IS NULL THEN CALL util.throw('The sale can not be deleted'); @@ -31,11 +33,9 @@ proc: BEGIN WHERE saleFk = vSaleFk AND isPicked; IF vHasSalesPicked THEN - CALL util.throw('The sale can not be deleted with sales picked'); + CALL util.throw('A sale with picked sales cannot be deleted'); END IF; - START TRANSACTION; - UPDATE itemShelvingSale iss JOIN itemShelving ish ON ish.id = iss.itemShelvingFk SET ish.available = ish.available + iss.quantity From 5d7d9f8d9e4e9c4e5a6562c49b6a48adc45e038e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Andr=C3=A9s?= Date: Fri, 4 Oct 2024 13:07:54 +0200 Subject: [PATCH 3/5] fix: refs #6861 deleteAdded --- db/routines/vn/procedures/itemShelvingSale_deleteAdded.sql | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/db/routines/vn/procedures/itemShelvingSale_deleteAdded.sql b/db/routines/vn/procedures/itemShelvingSale_deleteAdded.sql index 0de523127..9b15e82d1 100644 --- a/db/routines/vn/procedures/itemShelvingSale_deleteAdded.sql +++ b/db/routines/vn/procedures/itemShelvingSale_deleteAdded.sql @@ -22,9 +22,10 @@ proc: BEGIN SELECT iss.saleFk INTO vSaleFk FROM itemShelvingSale iss JOIN sale s ON s.id = iss.saleFk - WHERE iss.id = vSelf AND s.isAdded; + WHERE iss.id = vSelf AND s.isAdded + FOR UPDATE; - IF vSaleFk IS NULL THEN + IF vSaleFk IS NULL THEN CALL util.throw('The sale can not be deleted'); END IF; @@ -32,7 +33,7 @@ proc: BEGIN FROM itemShelvingSale WHERE saleFk = vSaleFk AND isPicked; - IF vHasSalesPicked THEN + IF vHasSalesPicked THEN CALL util.throw('A sale with picked sales cannot be deleted'); END IF; From 52e8bac168830e72f9df7e5be41cbaf9893df6ea Mon Sep 17 00:00:00 2001 From: sergiodt Date: Fri, 4 Oct 2024 13:34:04 +0200 Subject: [PATCH 4/5] fix: refs #7524 backSuppliersPackaging --- .../back/methods/supplier/getWithPackaging.js | 40 +++++++++++++++++++ .../supplier/specs/getWithPackaging.spec.js | 32 +++++++++++++++ modules/supplier/back/models/supplier.js | 1 + 3 files changed, 73 insertions(+) create mode 100644 modules/supplier/back/methods/supplier/getWithPackaging.js create mode 100644 modules/supplier/back/methods/supplier/specs/getWithPackaging.spec.js diff --git a/modules/supplier/back/methods/supplier/getWithPackaging.js b/modules/supplier/back/methods/supplier/getWithPackaging.js new file mode 100644 index 000000000..658b0696c --- /dev/null +++ b/modules/supplier/back/methods/supplier/getWithPackaging.js @@ -0,0 +1,40 @@ +module.exports = Self => { + Self.remoteMethod('getWithPackaging', { + description: 'Returns the list of suppliers with an entry of type packaging', + accessType: 'READ', + returns: { + type: 'object', + root: true + }, + http: { + path: `/getWithPackaging`, + verb: 'GET' + }, + nolimit: true + }); + Self.getWithPackaging = async options => { + const models = Self.app.models; + const myOptions = {}; + + if (typeof options == 'object') + Object.assign(myOptions, options); + + const entries = await models.Entry.find({ + where: {typeFk: 'packaging'}, + include: { + relation: 'supplier', + scope: { + fields: ['id', 'name'] + } + }, + fields: {supplierFk: true} + }, myOptions); + + const result = entries.map(item => ({ + id: item.supplier().id, + name: item.supplier().name + })); + return Array.from(new Map(result.map(entry => [entry.id, entry])).values()); + }; +}; + diff --git a/modules/supplier/back/methods/supplier/specs/getWithPackaging.spec.js b/modules/supplier/back/methods/supplier/specs/getWithPackaging.spec.js new file mode 100644 index 000000000..f73d20f84 --- /dev/null +++ b/modules/supplier/back/methods/supplier/specs/getWithPackaging.spec.js @@ -0,0 +1,32 @@ +const {models} = require('vn-loopback/server/server'); + +describe('Supplier getWithPackaging()', () => { + it('should return a list of suppliers with an entry of type packaging', async() => { + const typeFk = 'packaging'; + + const tx = await models.Supplier.beginTransaction({}); + const myOptions = {transaction: tx}; + + try { + const entry = await models.Entry.findOne( + { + where: { + id: 1 + }, + myOptions + }); + + await entry.updateAttributes({ + typeFk: typeFk, + }); + + const result = await models.Supplier.getWithPackaging(myOptions); + + expect(result.length).toEqual(1); + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); +}); diff --git a/modules/supplier/back/models/supplier.js b/modules/supplier/back/models/supplier.js index 2d3ffef3e..7e6908d57 100644 --- a/modules/supplier/back/models/supplier.js +++ b/modules/supplier/back/models/supplier.js @@ -12,6 +12,7 @@ module.exports = Self => { require('../methods/supplier/campaignMetricsEmail')(Self); require('../methods/supplier/newSupplier')(Self); require('../methods/supplier/getItemsPackaging')(Self); + require('../methods/supplier/getWithPackaging')(Self); Self.validatesPresenceOf('name', { message: 'The social name cannot be empty' From e90d48c7774a2ad504bce6cc698c1cffe5178c45 Mon Sep 17 00:00:00 2001 From: sergiodt Date: Mon, 7 Oct 2024 08:00:34 +0200 Subject: [PATCH 5/5] fix: refs #7524 backSuppliersPackaging --- modules/supplier/back/methods/supplier/getWithPackaging.js | 7 ++++++- .../back/methods/supplier/specs/getWithPackaging.spec.js | 1 + 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/modules/supplier/back/methods/supplier/getWithPackaging.js b/modules/supplier/back/methods/supplier/getWithPackaging.js index 658b0696c..07e563412 100644 --- a/modules/supplier/back/methods/supplier/getWithPackaging.js +++ b/modules/supplier/back/methods/supplier/getWithPackaging.js @@ -15,12 +15,17 @@ module.exports = Self => { Self.getWithPackaging = async options => { const models = Self.app.models; const myOptions = {}; + const oneYearAgo = new Date(); + oneYearAgo.setFullYear(oneYearAgo.getFullYear() - 1); if (typeof options == 'object') Object.assign(myOptions, options); const entries = await models.Entry.find({ - where: {typeFk: 'packaging'}, + where: { + typeFk: 'packaging', + created: {gte: oneYearAgo} + }, include: { relation: 'supplier', scope: { diff --git a/modules/supplier/back/methods/supplier/specs/getWithPackaging.spec.js b/modules/supplier/back/methods/supplier/specs/getWithPackaging.spec.js index f73d20f84..bd30d7437 100644 --- a/modules/supplier/back/methods/supplier/specs/getWithPackaging.spec.js +++ b/modules/supplier/back/methods/supplier/specs/getWithPackaging.spec.js @@ -18,6 +18,7 @@ describe('Supplier getWithPackaging()', () => { await entry.updateAttributes({ typeFk: typeFk, + created: new Date() }); const result = await models.Supplier.getWithPackaging(myOptions);