From 770c604d6b9e758745a4087305d7fa45fbdb2b12 Mon Sep 17 00:00:00 2001 From: jorgep Date: Thu, 10 Oct 2024 16:30:04 +0200 Subject: [PATCH 01/74] chore: refs #7919 delete if ticketRefund --- db/routines/vn/triggers/ticket_afterUpdate.sql | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/db/routines/vn/triggers/ticket_afterUpdate.sql b/db/routines/vn/triggers/ticket_afterUpdate.sql index f6c5e6523..e849c1faa 100644 --- a/db/routines/vn/triggers/ticket_afterUpdate.sql +++ b/db/routines/vn/triggers/ticket_afterUpdate.sql @@ -12,5 +12,10 @@ BEGIN CALL ticket_doCmr(NEW.id); END IF; END IF; + + IF NEW.isDeleted THEN + DELETE FROM ticketRefund + WHERE refundTicketFk = NEW.id; + END IF; END$$ DELIMITER ; From 78a9b788bf3d77ca736694d4f3fadc259cde69e7 Mon Sep 17 00:00:00 2001 From: guillermo Date: Mon, 14 Oct 2024 08:42:54 +0200 Subject: [PATCH 02/74] feat: refs #7006 itemTypeLog created --- .../vn/triggers/itemType_afterDelete.sql | 12 ++++++++++ .../vn/triggers/itemType_beforeInsert.sql | 8 +++++++ .../vn/triggers/itemType_beforeUpdate.sql | 1 + .../triggers/productionConfig_afterDelete.sql | 2 +- .../11297-graySalal/00-firstScript.sql | 24 +++++++++++++++++++ modules/item/back/models/item-type-log.json | 9 +++++++ 6 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 db/routines/vn/triggers/itemType_afterDelete.sql create mode 100644 db/routines/vn/triggers/itemType_beforeInsert.sql create mode 100644 db/versions/11297-graySalal/00-firstScript.sql create mode 100644 modules/item/back/models/item-type-log.json diff --git a/db/routines/vn/triggers/itemType_afterDelete.sql b/db/routines/vn/triggers/itemType_afterDelete.sql new file mode 100644 index 000000000..32a1ba31c --- /dev/null +++ b/db/routines/vn/triggers/itemType_afterDelete.sql @@ -0,0 +1,12 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`vn`@`localhost` TRIGGER `vn`.`itemType_afterDelete` + AFTER DELETE ON `itemType` + FOR EACH ROW +BEGIN + INSERT INTO itemTypeLog + SET `action` = 'delete', + `changedModel` = 'ItemType', + `changedModelId` = OLD.id, + `userFk` = account.myUser_getId(); +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/itemType_beforeInsert.sql b/db/routines/vn/triggers/itemType_beforeInsert.sql new file mode 100644 index 000000000..d33d8fb56 --- /dev/null +++ b/db/routines/vn/triggers/itemType_beforeInsert.sql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`vn`@`localhost` TRIGGER `vn`.`itemType_beforeInsert` + BEFORE INSERT ON `itemType` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/itemType_beforeUpdate.sql b/db/routines/vn/triggers/itemType_beforeUpdate.sql index 613ae8bfa..6a03d40d0 100644 --- a/db/routines/vn/triggers/itemType_beforeUpdate.sql +++ b/db/routines/vn/triggers/itemType_beforeUpdate.sql @@ -3,6 +3,7 @@ CREATE OR REPLACE DEFINER=`vn`@`localhost` TRIGGER `vn`.`itemType_beforeUpdate` BEFORE UPDATE ON `itemType` FOR EACH ROW BEGIN + SET NEW.editorFk = account.myUser_getId(); IF NEW.itemPackingTypeFk = '' THEN SET NEW.itemPackingTypeFk = NULL; diff --git a/db/routines/vn/triggers/productionConfig_afterDelete.sql b/db/routines/vn/triggers/productionConfig_afterDelete.sql index 6b6800d4f..bd485d590 100644 --- a/db/routines/vn/triggers/productionConfig_afterDelete.sql +++ b/db/routines/vn/triggers/productionConfig_afterDelete.sql @@ -3,7 +3,7 @@ CREATE OR REPLACE DEFINER=`vn`@`localhost` TRIGGER `vn`.`productionConfig_afterD AFTER DELETE ON `productionConfig` FOR EACH ROW BEGIN - INSERT INTO productionConfig + INSERT INTO productionConfigLog SET `action` = 'delete', `changedModel` = 'ProductionConfig', `changedModelId` = OLD.id, diff --git a/db/versions/11297-graySalal/00-firstScript.sql b/db/versions/11297-graySalal/00-firstScript.sql new file mode 100644 index 000000000..d6aeb1ec2 --- /dev/null +++ b/db/versions/11297-graySalal/00-firstScript.sql @@ -0,0 +1,24 @@ +ALTER TABLE vn.itemType + ADD editorFk int(10) unsigned DEFAULT NULL NULL, + ADD CONSTRAINT itemType_user_FK FOREIGN KEY (editorFk) REFERENCES account.`user`(id); + +CREATE TABLE `vn`.`itemTypeLog` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `originFk` int(11) DEFAULT NULL, + `userFk` int(10) unsigned DEFAULT NULL, + `action` set('insert','update','delete') NOT NULL, + `creationDate` timestamp NULL DEFAULT current_timestamp(), + `description` text CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci DEFAULT NULL, + `changedModel` enum('ItemType') NOT NULL DEFAULT 'ItemType', + `oldInstance` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL CHECK (json_valid(`oldInstance`)), + `newInstance` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL CHECK (json_valid(`newInstance`)), + `changedModelId` int(11) NOT NULL, + `changedModelValue` varchar(45) DEFAULT NULL, + `summaryId` varchar(30) DEFAULT NULL, + PRIMARY KEY (`id`), + KEY `itemTypeLogUserFk_idx` (`userFk`), + KEY `itemTypeLog_changedModel` (`changedModel`,`changedModelId`,`creationDate`), + KEY `itemTypeLog_originFk` (`originFk`,`creationDate`), + KEY `itemTypeLog_creationDate_IDX` (`creationDate` DESC) USING BTREE, + CONSTRAINT `itemTypeLogUserFk` FOREIGN KEY (`userFk`) REFERENCES `account`.`user` (`id`) ON DELETE CASCADE ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci `PAGE_COMPRESSED`=1; diff --git a/modules/item/back/models/item-type-log.json b/modules/item/back/models/item-type-log.json new file mode 100644 index 000000000..61e27e9ba --- /dev/null +++ b/modules/item/back/models/item-type-log.json @@ -0,0 +1,9 @@ +{ + "name": "ItemTypeLog", + "base": "Log", + "options": { + "mysql": { + "table": "ItemTypeLog" + } + } +} From 6c621726334adf2a4e93816c7dfceac28f9a6009 Mon Sep 17 00:00:00 2001 From: guillermo Date: Mon, 14 Oct 2024 09:31:35 +0200 Subject: [PATCH 03/74] feat: refs #7006 itemTypeLog created --- db/versions/11297-graySalal/00-firstScript.sql | 3 +++ modules/item/back/model-config.json | 3 +++ modules/item/back/models/item-type-log.json | 2 +- 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/db/versions/11297-graySalal/00-firstScript.sql b/db/versions/11297-graySalal/00-firstScript.sql index d6aeb1ec2..372af804c 100644 --- a/db/versions/11297-graySalal/00-firstScript.sql +++ b/db/versions/11297-graySalal/00-firstScript.sql @@ -22,3 +22,6 @@ CREATE TABLE `vn`.`itemTypeLog` ( KEY `itemTypeLog_creationDate_IDX` (`creationDate` DESC) USING BTREE, CONSTRAINT `itemTypeLogUserFk` FOREIGN KEY (`userFk`) REFERENCES `account`.`user` (`id`) ON DELETE CASCADE ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci `PAGE_COMPRESSED`=1; + +INSERT IGNORE INTO salix.ACL (model,property,principalId) + VALUES ('ItemTypeLog','*','employee'); diff --git a/modules/item/back/model-config.json b/modules/item/back/model-config.json index 5dbe4d62a..dcd973524 100644 --- a/modules/item/back/model-config.json +++ b/modules/item/back/model-config.json @@ -47,6 +47,9 @@ "ItemType": { "dataSource": "vn" }, + "ItemTypeLog": { + "dataSource": "vn" + }, "ItemTypeTag": { "dataSource": "vn" }, diff --git a/modules/item/back/models/item-type-log.json b/modules/item/back/models/item-type-log.json index 61e27e9ba..82a218aa6 100644 --- a/modules/item/back/models/item-type-log.json +++ b/modules/item/back/models/item-type-log.json @@ -3,7 +3,7 @@ "base": "Log", "options": { "mysql": { - "table": "ItemTypeLog" + "table": "itemTypeLog" } } } From 4ee6a46bd567cfbc7660d78daae1b88af76fce6a Mon Sep 17 00:00:00 2001 From: Jon Date: Mon, 14 Oct 2024 11:29:49 +0200 Subject: [PATCH 04/74] feat: added new filter param --- .../back/methods/ticket-request/filter.js | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/modules/ticket/back/methods/ticket-request/filter.js b/modules/ticket/back/methods/ticket-request/filter.js index 5364cef9a..ad000036b 100644 --- a/modules/ticket/back/methods/ticket-request/filter.js +++ b/modules/ticket/back/methods/ticket-request/filter.js @@ -59,6 +59,11 @@ module.exports = Self => { arg: 'state', type: 'string', description: `Search request by request state` + }, + { + arg: 'myTeam', + type: 'boolean', + description: `Team partners` } ], returns: { @@ -75,6 +80,24 @@ module.exports = Self => { const conn = Self.dataSource.connector; const userId = ctx.req.accessToken.userId; const myOptions = {}; + const models = Self.app.models; + const args = ctx.args; + + // Apply filter by team + const teamMembersId = []; + if (args.myTeam != null) { + const worker = await models.Worker.findById(userId, { + include: { + relation: 'collegues' + } + }, myOptions); + const collegues = worker.collegues() || []; + for (let collegue of collegues) + teamMembersId.push(collegue.collegueFk); + + if (teamMembersId.length == 0) + teamMembersId.push(userId); + } if (typeof options == 'object') Object.assign(myOptions, options); @@ -113,6 +136,11 @@ module.exports = Self => { return {'w.id': value}; case 'salesPersonFk': return {'c.salesPersonFk': value}; + case 'myTeam': + if (value) + return {'c.salesPersonFk': {inq: teamMembersId}}; + else + return {'c.salesPersonFk': {nin: teamMembersId}}; } }); From 07849ebeb8234172072b027317ad8517dc34cfe4 Mon Sep 17 00:00:00 2001 From: Jon Date: Mon, 14 Oct 2024 13:25:09 +0200 Subject: [PATCH 05/74] fix: myTeam param --- modules/ticket/back/methods/ticket-request/filter.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/ticket/back/methods/ticket-request/filter.js b/modules/ticket/back/methods/ticket-request/filter.js index ad000036b..2e1d2fbae 100644 --- a/modules/ticket/back/methods/ticket-request/filter.js +++ b/modules/ticket/back/methods/ticket-request/filter.js @@ -138,9 +138,9 @@ module.exports = Self => { return {'c.salesPersonFk': value}; case 'myTeam': if (value) - return {'c.salesPersonFk': {inq: teamMembersId}}; + return {'tr.requesterFk': {inq: teamMembersId}}; else - return {'c.salesPersonFk': {nin: teamMembersId}}; + return {'tr.requesterFk': {nin: teamMembersId}}; } }); From ccf9dbde8e1f8e8612ec3276a49cc7c9d62541c2 Mon Sep 17 00:00:00 2001 From: jorgep Date: Mon, 14 Oct 2024 17:11:12 +0200 Subject: [PATCH 06/74] feat: refs #7919 test --- .../methods/ticket/specs/setDeleted.spec.js | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/modules/ticket/back/methods/ticket/specs/setDeleted.spec.js b/modules/ticket/back/methods/ticket/specs/setDeleted.spec.js index 782c31c02..4e858af8e 100644 --- a/modules/ticket/back/methods/ticket/specs/setDeleted.spec.js +++ b/modules/ticket/back/methods/ticket/specs/setDeleted.spec.js @@ -113,5 +113,25 @@ describe('ticket setDeleted()', () => { expect(error.message).not.toContain('Tickets with associated refunds'); }); + + it('should delete a refund ticket from ticketRefund table', async() => { + const tx = await models.Ticket.beginTransaction({}); + try { + const options = {transaction: tx}; + + const ticketId = 24; + const refundTicket = await models.TicketRefund.findOne({where: {refundTicketFk: ticketId}}, options); + + expect(refundTicket).toBeTruthy(); + + await models.Ticket.setDeleted(ctx, ticketId, options); + const isRemoved = await models.TicketRefund.findOne({where: {refundTicketFk: ticketId}}, options); + + expect(isRemoved).toBeNull(); + await tx.rollback(); + } catch (e) { + await tx.rollback(); + } + }); }); }); From a35208d903f3c3329451da3141a159b66a2a13c3 Mon Sep 17 00:00:00 2001 From: jorgep Date: Mon, 14 Oct 2024 17:14:01 +0200 Subject: [PATCH 07/74] feat: refs #7919 test --- modules/ticket/back/methods/ticket/specs/setDeleted.spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/ticket/back/methods/ticket/specs/setDeleted.spec.js b/modules/ticket/back/methods/ticket/specs/setDeleted.spec.js index 4e858af8e..088487f3a 100644 --- a/modules/ticket/back/methods/ticket/specs/setDeleted.spec.js +++ b/modules/ticket/back/methods/ticket/specs/setDeleted.spec.js @@ -114,7 +114,7 @@ describe('ticket setDeleted()', () => { expect(error.message).not.toContain('Tickets with associated refunds'); }); - it('should delete a refund ticket from ticketRefund table', async() => { + it('should delete the refund - original ticket relation', async() => { const tx = await models.Ticket.beginTransaction({}); try { const options = {transaction: tx}; From 6d4c71d465bf40cd8bf592bfd9e4ffde24293210 Mon Sep 17 00:00:00 2001 From: jorgep Date: Mon, 14 Oct 2024 17:14:40 +0200 Subject: [PATCH 08/74] feat: refs #7919 test --- modules/ticket/back/methods/ticket/specs/setDeleted.spec.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/modules/ticket/back/methods/ticket/specs/setDeleted.spec.js b/modules/ticket/back/methods/ticket/specs/setDeleted.spec.js index 088487f3a..b70c94cee 100644 --- a/modules/ticket/back/methods/ticket/specs/setDeleted.spec.js +++ b/modules/ticket/back/methods/ticket/specs/setDeleted.spec.js @@ -125,9 +125,11 @@ describe('ticket setDeleted()', () => { expect(refundTicket).toBeTruthy(); await models.Ticket.setDeleted(ctx, ticketId, options); - const isRemoved = await models.TicketRefund.findOne({where: {refundTicketFk: ticketId}}, options); + const removedRefundTicket = await models.TicketRefund.findOne({ + where: {refundTicketFk: ticketId}}, + options); - expect(isRemoved).toBeNull(); + expect(removedRefundTicket).toBeNull(); await tx.rollback(); } catch (e) { await tx.rollback(); From 52e573501ad4d5fa120291b24f1ba9cf53dfaea0 Mon Sep 17 00:00:00 2001 From: robert Date: Tue, 15 Oct 2024 08:46:43 +0200 Subject: [PATCH 09/74] feat: refs #8108 create tables itemTag --- .../11300-limeMedeola/00-firstScript.sql | 85 +++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 db/versions/11300-limeMedeola/00-firstScript.sql diff --git a/db/versions/11300-limeMedeola/00-firstScript.sql b/db/versions/11300-limeMedeola/00-firstScript.sql new file mode 100644 index 000000000..21920b692 --- /dev/null +++ b/db/versions/11300-limeMedeola/00-firstScript.sql @@ -0,0 +1,85 @@ +CREATE TABLE IF NOT EXISTS `vn`.`itemFarmingTag` ( + `id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT, + `name` varchar(50) DEFAULT NULL, + PRIMARY KEY (`id`), + UNIQUE KEY `name_UNIQUE` (`name`) +) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT + CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; + +INSERT IGNORE INTO `vn`.`itemFarmingTag` (`name`) VALUES ('Enraizado'); + +UPDATE vn.tag + SET isFree=0, + sourceTable='itemFarmingTag' + WHERE name= 'cultivo'; + + + +CREATE TABLE IF NOT EXISTS `vn`.`itemWrappingTag` ( + `id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT, + `name` varchar(50) DEFAULT NULL, + PRIMARY KEY (`id`), + UNIQUE KEY `name_UNIQUE` (`name`) +) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT + CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; + +INSERT IGNORE INTO `vn`.`itemWrappingTag` (`name`) VALUES ('Bolsa'); +INSERT IGNORE INTO `vn`.`itemWrappingTag` (`name`) VALUES ('Caja cartón'); +INSERT IGNORE INTO `vn`.`itemWrappingTag` (`name`) VALUES ('Caja decorativa'); +INSERT IGNORE INTO `vn`.`itemWrappingTag` (`name`) VALUES ('Celofán'); +INSERT IGNORE INTO `vn`.`itemWrappingTag` (`name`) VALUES ('Papel kraft'); +INSERT IGNORE INTO `vn`.`itemWrappingTag` (`name`) VALUES ('Plástico'); +INSERT IGNORE INTO `vn`.`itemWrappingTag` (`name`) VALUES ('Variable'); + +UPDATE vn.tag + SET isFree=0, + sourceTable='itemWrappingTag' + WHERE name= 'Envoltorio'; + + + +CREATE TABLE IF NOT EXISTS `vn`.`itemLanguageTag` ( + `id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT, + `name` varchar(50) DEFAULT NULL, + PRIMARY KEY (`id`), + UNIQUE KEY `name_UNIQUE` (`name`) +) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT + CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; + +INSERT IGNORE INTO `vn`.`itemLanguageTag` (`name`) VALUES ('Castellano'); +INSERT IGNORE INTO `vn`.`itemLanguageTag` (`name`) VALUES ('Catalán'); +INSERT IGNORE INTO `vn`.`itemLanguageTag` (`name`) VALUES ('Euskera'); +INSERT IGNORE INTO `vn`.`itemLanguageTag` (`name`) VALUES ('Francés'); +INSERT IGNORE INTO `vn`.`itemLanguageTag` (`name`) VALUES ('Gallego'); +INSERT IGNORE INTO `vn`.`itemLanguageTag` (`name`) VALUES ('Inglés'); +INSERT IGNORE INTO `vn`.`itemLanguageTag` (`name`) VALUES ('Portugués'); + +UPDATE vn.tag + SET isFree=0, + sourceTable='itemLanguageTag' + WHERE name= 'Idioma'; + + + +CREATE TABLE IF NOT EXISTS `vn`.`itemStemTag` ( + `id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT, + `name` varchar(50) DEFAULT NULL, + PRIMARY KEY (`id`), + UNIQUE KEY `name_UNIQUE` (`name`) +) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT + CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; + +INSERT IGNORE INTO `vn`.`itemStemTag` (`name`) VALUES ('Natural'); +INSERT IGNORE INTO `vn`.`itemStemTag` (`name`) VALUES ('Seminatural'); +INSERT IGNORE INTO `vn`.`itemStemTag` (`name`) VALUES ('Sintético'); + +UPDATE vn.tag + SET isFree=0, + sourceTable='itemStemTag' + WHERE name= 'Tronco'; + + +GRANT SELECT, UPDATE, INSERT, DELETE ON TABLE vn.itemFarmingTag TO logisticAssist; +GRANT SELECT, UPDATE, INSERT, DELETE ON TABLE vn.itemWrappingTag TO logisticAssist; +GRANT SELECT, UPDATE, INSERT, DELETE ON TABLE vn.itemLanguageTag TO logisticAssist; +GRANT SELECT, UPDATE, INSERT, DELETE ON TABLE vn.itemStemTag TO logisticAssist; \ No newline at end of file From e334152acc901fb1357a59d9da85c317b9b29548 Mon Sep 17 00:00:00 2001 From: Jon Date: Tue, 15 Oct 2024 09:03:15 +0200 Subject: [PATCH 10/74] refactor: deleted comment --- .../ticket/back/methods/ticket-request/filter.js | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/modules/ticket/back/methods/ticket-request/filter.js b/modules/ticket/back/methods/ticket-request/filter.js index 2e1d2fbae..53f90b98f 100644 --- a/modules/ticket/back/methods/ticket-request/filter.js +++ b/modules/ticket/back/methods/ticket-request/filter.js @@ -83,7 +83,12 @@ module.exports = Self => { const models = Self.app.models; const args = ctx.args; - // Apply filter by team + if (typeof options == 'object') + Object.assign(myOptions, options); + + if (ctx.args.mine) + ctx.args.attenderFk = userId; + const teamMembersId = []; if (args.myTeam != null) { const worker = await models.Worker.findById(userId, { @@ -99,12 +104,6 @@ module.exports = Self => { teamMembersId.push(userId); } - if (typeof options == 'object') - Object.assign(myOptions, options); - - if (ctx.args.mine) - ctx.args.attenderFk = userId; - let where = buildFilter(ctx.args, (param, value) => { switch (param) { case 'search': From da55fffef02385c03945fb5ca30b0f42a8961161 Mon Sep 17 00:00:00 2001 From: robert Date: Tue, 15 Oct 2024 11:18:04 +0200 Subject: [PATCH 11/74] feat: refs #8108 addMoreTablesTag --- db/routines/vn/procedures/entry_transfer.sql | 121 ++++++++++++++++++ .../11300-limeMedeola/00-firstScript.sql | 72 ++++++++++- 2 files changed, 189 insertions(+), 4 deletions(-) create mode 100644 db/routines/vn/procedures/entry_transfer.sql diff --git a/db/routines/vn/procedures/entry_transfer.sql b/db/routines/vn/procedures/entry_transfer.sql new file mode 100644 index 000000000..6d7da2b37 --- /dev/null +++ b/db/routines/vn/procedures/entry_transfer.sql @@ -0,0 +1,121 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`entry_transfer`(vOriginalEntry INT, OUT vNewEntry INT) +BEGIN +/** +* Adelanta a mañana la mercancia de una entrada a partir de lo que hay ubicado en el almacén +* +* @param vOriginalEntry entrada que se quiera adelantar +*/ + + DECLARE vNewEntryFk INT; + DECLARE vTravelFk INT; + DECLARE vWarehouseFk INT; + + DECLARE EXIT HANDLER FOR SQLEXCEPTION + BEGIN + ROLLBACK; + RESIGNAL; + END; + + -- Clonar la entrada + CALL entry_clone(vOriginalEntry,vNewEntryFk); + + START TRANSACTION; + + -- Hay que crear un nuevo travel, con salida hoy y llegada mañana y asignar la entrada nueva al nuevo travel. + INSERT INTO travel( + shipped, + landed, + warehouseInFk, + warehouseOutFk, + `ref`, + isReceived, + agencyModeFk) + SELECT util.VN_CURDATE(), + util.VN_CURDATE() + INTERVAL 1 DAY, + t.warehouseInFk, + t.warehouseInFk, + t.`ref`, + t.isReceived, + t.agencyModeFk + FROM travel t + JOIN entry e ON e.travelFk = t.id + WHERE e.id = vOriginalEntry; + + SET vTravelFk = LAST_INSERT_ID(); + + UPDATE entry + SET travelFk = vTravelFk + WHERE id = vNewEntryFk; + + -- Poner a 0 las cantidades + UPDATE buy b + SET b.quantity = 0, b.stickers = 0 + WHERE b.entryFk = vNewEntryFk; + + -- Eliminar duplicados + DELETE b.* + FROM buy b + LEFT JOIN (SELECT b.id, b.itemFk + FROM buy b + WHERE b.entryFk = vNewEntryFk + GROUP BY b.itemFk) tBuy ON tBuy.id = b.id + WHERE b.entryFk = vNewEntryFk + AND tBuy.id IS NULL; + + SELECT t.warehouseInFk INTO vWarehouseFk + FROM travel t + JOIN entry e ON e.travelFk = t.id + WHERE e.id = vOriginalEntry; + + -- Actualizar la nueva entrada con lo que no está ubicado HOY, descontando lo vendido HOY de esas ubicaciones + CREATE OR REPLACE TEMPORARY TABLE tBuy + ENGINE = MEMORY + SELECT tBuy.itemFk, IFNULL(iss.visible,0) visible, tBuy.totalQuantity, IFNULL(sales.sold,0) sold + FROM (SELECT b.itemFk, SUM(b.quantity) totalQuantity + FROM buy b + WHERE b.entryFk = vOriginalEntry + GROUP BY b.itemFk + ) tBuy + LEFT JOIN ( + SELECT ish.itemFk, SUM(visible) visible + FROM itemShelving ish + JOIN shelving sh ON sh.code = ish.shelvingFk + JOIN parking p ON p.id = sh.parkingFk + JOIN sector s ON s.id = p.sectorFk + WHERE s.warehouseFk = vWarehouseFk + AND sh.parked = util.VN_CURDATE() + GROUP BY ish.itemFk) iss ON tBuy.itemFk = iss.itemFk + LEFT JOIN ( + SELECT s.itemFk, SUM(s.quantity) sold + FROM ticket t + JOIN sale s ON s.ticketFk = t.id + JOIN itemShelvingSale iss ON iss.saleFk = s.id + JOIN itemShelving is2 ON is2.id = iss.itemShelvingFk + JOIN shelving s2 ON s2.code = is2.shelvingFk + WHERE t.shipped BETWEEN util.VN_CURDATE() AND util.dayend(util.VN_CURDATE()) + AND s2.parked = util.VN_CURDATE() + GROUP BY s.itemFk) sales ON sales.itemFk = tBuy.itemFk + WHERE visible = tBuy.totalQuantity + OR iss.itemFk IS NULL; + + UPDATE buy b + JOIN (SELECT * FROM tBuy) sub ON sub.itemFk = b.itemFk + SET b.quantity = sub.totalQuantity - sub.visible - sub.sold + WHERE b.entryFk = vNewEntryFk; + + -- Limpia la nueva entrada + DELETE b.* + FROM buy b + WHERE b.entryFk = vNewEntryFk + AND b.quantity = 0; + + COMMIT; + + SET vNewEntry = vNewEntryFk; + + CALL cache.visible_refresh(@c,TRUE,7); + CALL cache.available_refresh(@c, TRUE, 7, util.VN_CURDATE()); + +END$$ +DELIMITER ; diff --git a/db/versions/11300-limeMedeola/00-firstScript.sql b/db/versions/11300-limeMedeola/00-firstScript.sql index 21920b692..313a65e81 100644 --- a/db/versions/11300-limeMedeola/00-firstScript.sql +++ b/db/versions/11300-limeMedeola/00-firstScript.sql @@ -79,7 +79,71 @@ UPDATE vn.tag WHERE name= 'Tronco'; -GRANT SELECT, UPDATE, INSERT, DELETE ON TABLE vn.itemFarmingTag TO logisticAssist; -GRANT SELECT, UPDATE, INSERT, DELETE ON TABLE vn.itemWrappingTag TO logisticAssist; -GRANT SELECT, UPDATE, INSERT, DELETE ON TABLE vn.itemLanguageTag TO logisticAssist; -GRANT SELECT, UPDATE, INSERT, DELETE ON TABLE vn.itemStemTag TO logisticAssist; \ No newline at end of file +CREATE TABLE IF NOT EXISTS `vn`.`itemBreederTag` ( + `id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT, + `name` varchar(50) DEFAULT NULL, + PRIMARY KEY (`id`), + UNIQUE KEY `name_UNIQUE` (`name`) +) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT + CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; + +INSERT IGNORE INTO `vn`.`itemBreederTag` (`name`) VALUES ('David Austin'); + +UPDATE vn.tag + SET isFree=0, + sourceTable='itemBreederTag' + WHERE name= 'Obtentor'; + + + +CREATE TABLE IF NOT EXISTS `vn`.`itemBaseTag` ( + `id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT, + `name` varchar(50) DEFAULT NULL, + PRIMARY KEY (`id`), + UNIQUE KEY `name_UNIQUE` (`name`) +) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT + CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; + +INSERT IGNORE INTO `vn`.`itemBaseTag` (`name`) VALUES ('Biodegradable'); +INSERT IGNORE INTO `vn`.`itemBaseTag` (`name`) VALUES ('Caballete'); +INSERT IGNORE INTO `vn`.`itemBaseTag` (`name`) VALUES ('Cerámica'); +INSERT IGNORE INTO `vn`.`itemBaseTag` (`name`) VALUES ('Cristal'); +INSERT IGNORE INTO `vn`.`itemBaseTag` (`name`) VALUES ('Plástico por inyección'); +INSERT IGNORE INTO `vn`.`itemBaseTag` (`name`) VALUES ('Madera'); +INSERT IGNORE INTO `vn`.`itemBaseTag` (`name`) VALUES ('Plástico'); +INSERT IGNORE INTO `vn`.`itemBaseTag` (`name`) VALUES ('Rígido'); +INSERT IGNORE INTO `vn`.`itemBaseTag` (`name`) VALUES ('Ruedas'); +INSERT IGNORE INTO `vn`.`itemBaseTag` (`name`) VALUES ('Sin soporte rígido'); + +UPDATE vn.tag + SET isFree=0, + sourceTable='itemBaseTag' + WHERE name= 'Soporte'; + + + +CREATE TABLE IF NOT EXISTS `vn`.`itemVatRateTag` ( + `id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT, + `name` varchar(50) DEFAULT NULL, + PRIMARY KEY (`id`), + UNIQUE KEY `name_UNIQUE` (`name`) +) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT + CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; + +INSERT IGNORE INTO `vn`.`itemVatRateTag` (`name`) VALUES ('General'); +INSERT IGNORE INTO `vn`.`itemVatRateTag` (`name`) VALUES ('Reducido'); + + +UPDATE vn.tag + SET isFree=0, + sourceTable='itemVatRateTag' + WHERE name= 'Tipo de IVA'; + + +GRANT SELECT, UPDATE, INSERT, DELETE ON TABLE vn.itemFarmingTag TO logisticAssist; +GRANT SELECT, UPDATE, INSERT, DELETE ON TABLE vn.itemWrappingTag TO logisticAssist; +GRANT SELECT, UPDATE, INSERT, DELETE ON TABLE vn.itemLanguageTag TO logisticAssist; +GRANT SELECT, UPDATE, INSERT, DELETE ON TABLE vn.itemStemTag TO logisticAssist; +GRANT SELECT, UPDATE, INSERT, DELETE ON TABLE vn.itemWrappingTag TO logisticAssist; +GRANT SELECT, UPDATE, INSERT, DELETE ON TABLE vn.itemBaseTag TO logisticAssist; +GRANT SELECT, UPDATE, INSERT, DELETE ON TABLE vn.itemBreederTag TO logisticAssist; \ No newline at end of file From 8da005f08ab1c0775c1cfee83bbdbadff3ca0cfa Mon Sep 17 00:00:00 2001 From: robert Date: Tue, 15 Oct 2024 11:19:08 +0200 Subject: [PATCH 12/74] feat: refs #8108 refs #9108 --- db/routines/vn/procedures/entry_transfer.sql | 121 ------------------- 1 file changed, 121 deletions(-) delete mode 100644 db/routines/vn/procedures/entry_transfer.sql diff --git a/db/routines/vn/procedures/entry_transfer.sql b/db/routines/vn/procedures/entry_transfer.sql deleted file mode 100644 index 6d7da2b37..000000000 --- a/db/routines/vn/procedures/entry_transfer.sql +++ /dev/null @@ -1,121 +0,0 @@ -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`entry_transfer`(vOriginalEntry INT, OUT vNewEntry INT) -BEGIN -/** -* Adelanta a mañana la mercancia de una entrada a partir de lo que hay ubicado en el almacén -* -* @param vOriginalEntry entrada que se quiera adelantar -*/ - - DECLARE vNewEntryFk INT; - DECLARE vTravelFk INT; - DECLARE vWarehouseFk INT; - - DECLARE EXIT HANDLER FOR SQLEXCEPTION - BEGIN - ROLLBACK; - RESIGNAL; - END; - - -- Clonar la entrada - CALL entry_clone(vOriginalEntry,vNewEntryFk); - - START TRANSACTION; - - -- Hay que crear un nuevo travel, con salida hoy y llegada mañana y asignar la entrada nueva al nuevo travel. - INSERT INTO travel( - shipped, - landed, - warehouseInFk, - warehouseOutFk, - `ref`, - isReceived, - agencyModeFk) - SELECT util.VN_CURDATE(), - util.VN_CURDATE() + INTERVAL 1 DAY, - t.warehouseInFk, - t.warehouseInFk, - t.`ref`, - t.isReceived, - t.agencyModeFk - FROM travel t - JOIN entry e ON e.travelFk = t.id - WHERE e.id = vOriginalEntry; - - SET vTravelFk = LAST_INSERT_ID(); - - UPDATE entry - SET travelFk = vTravelFk - WHERE id = vNewEntryFk; - - -- Poner a 0 las cantidades - UPDATE buy b - SET b.quantity = 0, b.stickers = 0 - WHERE b.entryFk = vNewEntryFk; - - -- Eliminar duplicados - DELETE b.* - FROM buy b - LEFT JOIN (SELECT b.id, b.itemFk - FROM buy b - WHERE b.entryFk = vNewEntryFk - GROUP BY b.itemFk) tBuy ON tBuy.id = b.id - WHERE b.entryFk = vNewEntryFk - AND tBuy.id IS NULL; - - SELECT t.warehouseInFk INTO vWarehouseFk - FROM travel t - JOIN entry e ON e.travelFk = t.id - WHERE e.id = vOriginalEntry; - - -- Actualizar la nueva entrada con lo que no está ubicado HOY, descontando lo vendido HOY de esas ubicaciones - CREATE OR REPLACE TEMPORARY TABLE tBuy - ENGINE = MEMORY - SELECT tBuy.itemFk, IFNULL(iss.visible,0) visible, tBuy.totalQuantity, IFNULL(sales.sold,0) sold - FROM (SELECT b.itemFk, SUM(b.quantity) totalQuantity - FROM buy b - WHERE b.entryFk = vOriginalEntry - GROUP BY b.itemFk - ) tBuy - LEFT JOIN ( - SELECT ish.itemFk, SUM(visible) visible - FROM itemShelving ish - JOIN shelving sh ON sh.code = ish.shelvingFk - JOIN parking p ON p.id = sh.parkingFk - JOIN sector s ON s.id = p.sectorFk - WHERE s.warehouseFk = vWarehouseFk - AND sh.parked = util.VN_CURDATE() - GROUP BY ish.itemFk) iss ON tBuy.itemFk = iss.itemFk - LEFT JOIN ( - SELECT s.itemFk, SUM(s.quantity) sold - FROM ticket t - JOIN sale s ON s.ticketFk = t.id - JOIN itemShelvingSale iss ON iss.saleFk = s.id - JOIN itemShelving is2 ON is2.id = iss.itemShelvingFk - JOIN shelving s2 ON s2.code = is2.shelvingFk - WHERE t.shipped BETWEEN util.VN_CURDATE() AND util.dayend(util.VN_CURDATE()) - AND s2.parked = util.VN_CURDATE() - GROUP BY s.itemFk) sales ON sales.itemFk = tBuy.itemFk - WHERE visible = tBuy.totalQuantity - OR iss.itemFk IS NULL; - - UPDATE buy b - JOIN (SELECT * FROM tBuy) sub ON sub.itemFk = b.itemFk - SET b.quantity = sub.totalQuantity - sub.visible - sub.sold - WHERE b.entryFk = vNewEntryFk; - - -- Limpia la nueva entrada - DELETE b.* - FROM buy b - WHERE b.entryFk = vNewEntryFk - AND b.quantity = 0; - - COMMIT; - - SET vNewEntry = vNewEntryFk; - - CALL cache.visible_refresh(@c,TRUE,7); - CALL cache.available_refresh(@c, TRUE, 7, util.VN_CURDATE()); - -END$$ -DELIMITER ; From 4a88ba5078132adee8e7f24657ee29da0445f873 Mon Sep 17 00:00:00 2001 From: jgallego Date: Tue, 15 Oct 2024 15:43:12 +0200 Subject: [PATCH 13/74] feat: refs #7744 closeAll Test --- db/dump/fixtures.before.sql | 24 ++++-- loopback/locale/es.json | 1 + loopback/locale/fr.json | 1 + loopback/locale/pt.json | 1 + modules/invoiceOut/back/models/invoice-out.js | 2 + modules/ticket/back/methods/sale/usesMana.js | 2 +- .../ticket/back/methods/ticket/closeAll.js | 44 +++++----- modules/ticket/back/methods/ticket/closure.js | 10 ++- .../methods/ticket/specs/closeAll.spec.js | 80 +++++++++++++++++++ 9 files changed, 136 insertions(+), 29 deletions(-) create mode 100644 modules/ticket/back/methods/ticket/specs/closeAll.spec.js diff --git a/db/dump/fixtures.before.sql b/db/dump/fixtures.before.sql index 7f7e50dd3..6007b73e0 100644 --- a/db/dump/fixtures.before.sql +++ b/db/dump/fixtures.before.sql @@ -632,14 +632,21 @@ INSERT INTO vn.invoiceOutConfig SET id = 1, parallelism = 8; -INSERT INTO `vn`.`invoiceOutSerial` (`code`, `description`, `isTaxed`, `taxAreaFk`, `isCEE`, `type`) +INSERT INTO `vn`.`invoiceOutSerial` + (`code`,`description`, `isTaxed`, `taxAreaFk`, `isCEE`, `type`) VALUES - ('A', 'Global nacional', 1, 'NATIONAL', 0, 'global'), - ('T', 'Española rapida', 1, 'NATIONAL', 0, 'quick'), - ('V', 'Intracomunitaria global', 0, 'CEE', 1, 'global'), - ('M', 'Múltiple nacional', 1, 'NATIONAL', 0, 'multiple'), - ('R', 'Rectificativa', 1, 'NATIONAL', 0, NULL), - ('E', 'Exportación rápida', 0, 'WORLD', 0, 'quick'); + ('A', 'Global nacional', 1, 'NATIONAL', 0, 'global'), + ('T', 'Española rapida', 1, 'NATIONAL', 0, 'quick'), + ('V', 'Intracomunitaria global', 0, 'CEE', 1, 'global'), + ('M', 'Múltiple nacional', 1, 'NATIONAL', 0, 'multiple'), + ('R', 'Rectificativa', 1, 'NATIONAL', 0, NULL), + ('E', 'Exportación rápida', 0, 'WORLD', 0, 'quick'), + ('H', 'Intracomunitaria rápida', 0, 'CEE', 1, 'quick'), + ('P', 'Factura simplificada', 1, 'NATIONAL', 0, NULL), + ('PE', 'COOPERATIE FLORAHOLLAND UA', 0, 'CEE', 1, NULL), + ('S', 'Simplificada', 1, 'NATIONAL', 0, NULL), + ('X', 'Exportación global', 0, 'WORLD', 0, 'global'), + ('N', 'Múltiple Intracomunitaria', 0, 'CEE', 1, 'multiple'); INSERT INTO `vn`.`invoiceOut`(`id`, `serial`, `amount`, `issued`,`clientFk`, `created`, `companyFk`, `dued`, `booked`, `bankFk`, `hasPdf`) VALUES @@ -2911,7 +2918,8 @@ INSERT INTO `util`.`notification` (`id`, `name`, `description`) (6, 'book-entry-deleted', 'accounting entries deleted'), (7, 'zone-included','An email to notify zoneCollisions'), (8, 'backup-printer-selected','A backup printer has been selected'), - (9, 'mrw-deadline','The MRW deadline has passed'); + (9, 'mrw-deadline','The MRW deadline has passed'), + (10,'invoice-ticket-closure','Tickets not invoiced during the nightly closure ticket process'); TRUNCATE `util`.`notificationAcl`; INSERT INTO `util`.`notificationAcl` (`notificationFk`, `roleFk`) diff --git a/loopback/locale/es.json b/loopback/locale/es.json index 9308fd4ec..0349fa8fb 100644 --- a/loopback/locale/es.json +++ b/loopback/locale/es.json @@ -350,6 +350,7 @@ "Cmr file does not exist": "El archivo del cmr no existe", "You are not allowed to modify the alias": "No estás autorizado a modificar el alias", "The address of the customer must have information about Incoterms and Customs Agent": "El consignatario del cliente debe tener informado Incoterms y Agente de aduanas", + "No invoice series found for these parameters": "No se encontró una serie para estos parámetros", "The line could not be marked": "La linea no puede ser marcada", "Through this procedure, it is not possible to modify the password of users with verified email": "Mediante este procedimiento, no es posible modificar la contraseña de usuarios con correo verificado", "They're not your subordinate": "No es tu subordinado/a.", diff --git a/loopback/locale/fr.json b/loopback/locale/fr.json index a6648b186..23bd5cc04 100644 --- a/loopback/locale/fr.json +++ b/loopback/locale/fr.json @@ -350,6 +350,7 @@ "Cmr file does not exist": "Le fichier cmr n'existe pas", "You are not allowed to modify the alias": "Vous n'êtes pas autorisé à modifier l'alias", "The address of the customer must have information about Incoterms and Customs Agent": "L'adresse du client doit contenir des informations sur les Incoterms et l'agent des douanes", + "No invoice series found for these parameters": "Aucune série de facture trouvée pour ces paramètres", "The line could not be marked": "La ligne ne peut pas être marquée", "This password can only be changed by the user themselves": "Ce mot de passe ne peut être modifié que par l'utilisateur lui-même", "They're not your subordinate": "Ce n'est pas votre subordonné.", diff --git a/loopback/locale/pt.json b/loopback/locale/pt.json index a43f0e780..f85afd607 100644 --- a/loopback/locale/pt.json +++ b/loopback/locale/pt.json @@ -350,6 +350,7 @@ "Cmr file does not exist": "O arquivo CMR não existe", "You are not allowed to modify the alias": "Você não tem permissão para modificar o alias", "The address of the customer must have information about Incoterms and Customs Agent": "O endereço do cliente deve ter informações sobre Incoterms e Agente Aduaneiro", + "No invoice series found for these parameters": "Nenhuma série de fatura encontrada para esses parâmetros", "The line could not be marked": "A linha não pôde ser marcada", "This password can only be changed by the user themselves": "Esta senha só pode ser alterada pelo próprio usuário", "They're not your subordinate": "Eles não são seus subordinados.", diff --git a/modules/invoiceOut/back/models/invoice-out.js b/modules/invoiceOut/back/models/invoice-out.js index bab1fa375..f8fc8cdbf 100644 --- a/modules/invoiceOut/back/models/invoice-out.js +++ b/modules/invoiceOut/back/models/invoice-out.js @@ -79,6 +79,8 @@ module.exports = Self => { type ], myOptions); + if (!serial) + throw new UserError('No invoice series found for these parameters'); const invoiceOutSerial = await Self.app.models.InvoiceOutSerial.findById(serial); if (invoiceOutSerial?.taxAreaFk == 'WORLD') { diff --git a/modules/ticket/back/methods/sale/usesMana.js b/modules/ticket/back/methods/sale/usesMana.js index 31beb3a4c..b4768d80a 100644 --- a/modules/ticket/back/methods/sale/usesMana.js +++ b/modules/ticket/back/methods/sale/usesMana.js @@ -31,6 +31,6 @@ module.exports = Self => { const usesMana = departments.find(department => department.id == workerDepartment.departmentFk); - return usesMana ? true : false; + return !!usesMana; }; }; diff --git a/modules/ticket/back/methods/ticket/closeAll.js b/modules/ticket/back/methods/ticket/closeAll.js index 4fd72d454..1b3f84295 100644 --- a/modules/ticket/back/methods/ticket/closeAll.js +++ b/modules/ticket/back/methods/ticket/closeAll.js @@ -1,11 +1,17 @@ -const UserError = require('vn-loopback/util/user-error'); const closure = require('./closure'); module.exports = Self => { Self.remoteMethodCtx('closeAll', { description: 'Makes the closure process from all warehouses', accessType: 'WRITE', - accepts: [], + accepts: [ + { + arg: 'options', + type: 'object', + http: {source: 'body'}, + description: 'Optional parameters, including transaction.' + } + ], returns: { type: 'object', root: true @@ -16,21 +22,20 @@ module.exports = Self => { } }); - Self.closeAll = async ctx => { + Self.closeAll = async(ctx, options) => { + const userId = ctx.req.accessToken.userId; + const myOptions = {userId}; + + if (typeof options == 'object') + Object.assign(myOptions, options); + + let tx; + // IMPORTANT: Due to its high cost in production, wrapping this process in a transaction may cause timeouts. + const toDate = Date.vnNew(); toDate.setHours(0, 0, 0, 0); toDate.setDate(toDate.getDate() - 1); - const todayMinDate = Date.vnNew(); - todayMinDate.setHours(0, 0, 0, 0); - - const todayMaxDate = Date.vnNew(); - todayMaxDate.setHours(23, 59, 59, 59); - - // Prevent closure for current day - if (toDate >= todayMinDate && toDate <= todayMaxDate) - throw new UserError('You cannot close tickets for today'); - const tickets = await Self.rawSql(` SELECT t.id, t.clientFk, @@ -58,12 +63,12 @@ module.exports = Self => { AND t.shipped BETWEEN ? - INTERVAL tc.closureDaysAgo DAY AND util.dayEnd(?) AND t.refFk IS NULL GROUP BY t.id - `, [toDate, toDate]); + `, [toDate, toDate], myOptions); const ticketIds = tickets.map(ticket => ticket.id); await Self.rawSql(` INSERT INTO util.debug (variable, value) VALUES ('nightInvoicing', ?) - `, [ticketIds.join(',')]); + `, [ticketIds.join(',')], myOptions); await Self.rawSql(` WITH ticketNotInvoiceable AS( @@ -133,9 +138,9 @@ module.exports = Self => { ) SELECT IF(errors = '{"tickets": null}', 'No errors', util.notification_send('invoice-ticket-closure', errors, NULL)) - FROM ticketNotInvoiceable`, [toDate, toDate]); + FROM ticketNotInvoiceable`, [toDate, toDate], myOptions); - await closure(ctx, Self, tickets); + await closure(ctx, Self, tickets, myOptions); await Self.rawSql(` UPDATE ticket t @@ -150,7 +155,10 @@ module.exports = Self => { AND al.code NOT IN ('DELIVERED', 'PACKED') AND NOT t.packages AND tob.id IS NULL - AND t.routeFk`, [toDate, toDate], {userId: ctx.req.accessToken.userId}); + AND t.routeFk`, [toDate, toDate], myOptions); + + if (tx) + await tx.commit(); return { message: 'Success' diff --git a/modules/ticket/back/methods/ticket/closure.js b/modules/ticket/back/methods/ticket/closure.js index 56bd6eccd..64f198834 100644 --- a/modules/ticket/back/methods/ticket/closure.js +++ b/modules/ticket/back/methods/ticket/closure.js @@ -19,9 +19,15 @@ module.exports = async function(ctx, Self, tickets, options) { const failedtickets = []; for (const ticket of tickets) { try { - await Self.rawSql(`CALL util.debugAdd('invoicingTicket', ?)`, [ticket.id], {userId}); + await Self.rawSql(`CALL util.debugAdd('invoicingTicket', ?)`, [ticket.id], {userId}, + myOptions); - await Self.app.models.InvoiceOut.getSerial(ticket.clientFk, ticket.companyFk, ticket.addressFk, 'quick'); + await Self.app.models.InvoiceOut.getSerial( + ticket.clientFk, + ticket.companyFk, + ticket.addressFk, + 'quick', + myOptions); await Self.rawSql( `CALL vn.ticket_closeByTicket(?)`, [ticket.id], diff --git a/modules/ticket/back/methods/ticket/specs/closeAll.spec.js b/modules/ticket/back/methods/ticket/specs/closeAll.spec.js new file mode 100644 index 000000000..4b067ce7e --- /dev/null +++ b/modules/ticket/back/methods/ticket/specs/closeAll.spec.js @@ -0,0 +1,80 @@ +const models = require('vn-loopback/server/server').models; +const LoopBackContext = require('loopback-context'); + +fdescribe('Ticket Closure - closeAll function', () => { + let ctx = { + req: { + getLocale: () => 'es', + accessToken: {userId: 1106}, + headers: {origin: 'http://localhost'}, + __: value => value, + }, + args: {} + }; + let options; + let tx; + let originalVnNew; + + beforeEach(async() => { + spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({active: ctx.req}); + tx = await models.Ticket.beginTransaction({}); + options = {transaction: tx}; + originalVnNew = Date.vnNew; + spyOn(Date, 'vnNew').and.callFake(() => { + const mockDate = originalVnNew(); + mockDate.setDate(mockDate.getDate() + 1); + return mockDate; + }); + }); + + afterEach(async() => { + if (tx) + await tx.rollback(); + }); + + xit('should successfully close all tickets when conditions are met', async() => { + const ticketsBefore = await models.Ticket.find({ + where: { + packages: {neq: 0} + } + }, options); + const packedTicketsIds = ticketsBefore.map(ticket => ticket.id); + + const packedTicketsBefore = await models.TicketLastState.find({ + where: { + ticketFk: {inq: packedTicketsIds}, + lastState: 'Encajado' + } + }, options); + + await models.Ticket.closeAll(ctx, options); + + const packedTicketsAfter = await models.TicketLastState.find({ + where: { + ticketFk: {inq: packedTicketsIds}, + lastState: 'Encajado' + } + }, options); + + expect(packedTicketsBefore.length).toBeGreaterThan(packedTicketsAfter.length); + }); + + fit('should set routeFk to NULL when conditions are met', async() => { + const ticketsBefore = await models.Ticket.find({ + where: { + routeFk: {neq: null} + } + }, options); + + await models.Ticket.closeAll(ctx, options); + + const ticketsAfter = await models.Ticket.find({ + where: { + id: {inq: ticketsBefore.map(ticket => ticket.id)}, + routeFk: {neq: null} + } + }, options); + + expect(ticketsBefore.length).toBeGreaterThan(ticketsAfter.length); + }); +}); From d57f4fc44a7711b891b65b19c7ec8a9b6104abbf Mon Sep 17 00:00:00 2001 From: jorgep Date: Tue, 15 Oct 2024 17:24:14 +0200 Subject: [PATCH 14/74] chore: refs #7919 refactor, drop relation on back --- db/routines/vn/triggers/ticket_afterUpdate.sql | 5 ----- modules/ticket/back/methods/ticket/setDeleted.js | 5 ++++- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/db/routines/vn/triggers/ticket_afterUpdate.sql b/db/routines/vn/triggers/ticket_afterUpdate.sql index e849c1faa..f6c5e6523 100644 --- a/db/routines/vn/triggers/ticket_afterUpdate.sql +++ b/db/routines/vn/triggers/ticket_afterUpdate.sql @@ -12,10 +12,5 @@ BEGIN CALL ticket_doCmr(NEW.id); END IF; END IF; - - IF NEW.isDeleted THEN - DELETE FROM ticketRefund - WHERE refundTicketFk = NEW.id; - END IF; END$$ DELIMITER ; diff --git a/modules/ticket/back/methods/ticket/setDeleted.js b/modules/ticket/back/methods/ticket/setDeleted.js index a684e1cbc..e868e9258 100644 --- a/modules/ticket/back/methods/ticket/setDeleted.js +++ b/modules/ticket/back/methods/ticket/setDeleted.js @@ -49,9 +49,12 @@ module.exports = Self => { where: {originalTicketFk: id} }, myOptions); + const isRefund = !!ticketRefunds?.length; + const allDeleted = ticketRefunds.every(refund => refund.refundTicket().isDeleted); - if (ticketRefunds?.length && !allDeleted) { + if (!isRefund) await models.TicketRefund.destroyAll({refundTicketFk: id}, myOptions); + if (isRefund && !allDeleted) { const notDeleted = []; for (const refund of ticketRefunds) if (!refund.refundTicket().isDeleted) notDeleted.push(refund.refundTicket().id); From c6e764b478b9481376f187c32c9c73b5b26cb23d Mon Sep 17 00:00:00 2001 From: jgallego Date: Wed, 16 Oct 2024 08:32:10 +0200 Subject: [PATCH 15/74] feat: refs #7348 hasDailyInvoice from client --- back/models/autonomy.json | 6 +- back/models/country.json | 4 + back/models/province.json | 5 +- db/routines/vn/procedures/client_create.sql | 10 +- db/routines/vn/procedures/ticket_close.sql | 7 +- .../11302-limeTulip/00-firstScript.sql | 13 ++ .../back/methods/client/createWithUser.js | 20 ++- .../client/specs/createWithUser.spec.js | 143 +++++++++++------- .../ticket/back/methods/ticket/closeAll.js | 4 +- .../back/methods/ticket/closeByTicket.js | 4 +- 10 files changed, 145 insertions(+), 71 deletions(-) create mode 100644 db/versions/11302-limeTulip/00-firstScript.sql diff --git a/back/models/autonomy.json b/back/models/autonomy.json index 8c9d82936..214061cf5 100644 --- a/back/models/autonomy.json +++ b/back/models/autonomy.json @@ -16,6 +16,10 @@ "name": { "type": "string", "required": true + }, + "hasDailyInvoice": { + "type": "boolean", + "description": "Indicates if the autonomy has daily invoice enabled" } }, "relations": { @@ -40,4 +44,4 @@ "permission": "ALLOW" } ] -} \ No newline at end of file +} diff --git a/back/models/country.json b/back/models/country.json index 5b9d842a8..80d456702 100644 --- a/back/models/country.json +++ b/back/models/country.json @@ -28,6 +28,10 @@ }, "continentFk": { "type": "number" + }, + "hasDailyInvoice": { + "type": "boolean", + "description": "Indicates if the autonomy has daily invoice enabled" } }, "relations": { diff --git a/back/models/province.json b/back/models/province.json index 77e0b24a6..61a1574d7 100644 --- a/back/models/province.json +++ b/back/models/province.json @@ -16,6 +16,9 @@ "name": { "type": "string", "required": true + }, + "autonomyFk": { + "type": "number" } }, "relations": { @@ -55,4 +58,4 @@ "permission": "ALLOW" } ] -} \ No newline at end of file +} diff --git a/db/routines/vn/procedures/client_create.sql b/db/routines/vn/procedures/client_create.sql index 3df3df905..fad01c107 100644 --- a/db/routines/vn/procedures/client_create.sql +++ b/db/routines/vn/procedures/client_create.sql @@ -34,22 +34,19 @@ BEGIN DECLARE vIsTaxDataChecked TINYINT(1); DECLARE vHasCoreVnl BOOLEAN; DECLARE vMandateTypeFk INT; - DECLARE vHasDailyInvoice BOOLEAN; SELECT cc.defaultPayMethodFk, cc.defaultDueDay, cc.defaultCredit, cc.defaultIsTaxDataChecked, cc.defaultHasCoreVnl, - cc.defaultMandateTypeFk, - c.hasDailyInvoice + cc.defaultMandateTypeFk INTO vPayMethodFk, vDueDay, vDefaultCredit, vIsTaxDataChecked, vHasCoreVnl, - vMandateTypeFk, - vHasDailyInvoice + vMandateTypeFk FROM clientConfig cc LEFT JOIN province p ON p.id = vProvinceFk LEFT JOIN country c ON c.id = p.countryFk; @@ -70,8 +67,7 @@ BEGIN credit = vDefaultCredit, isTaxDataChecked = vIsTaxDataChecked, hasCoreVnl = vHasCoreVnl, - isEqualizated = FALSE, - hasDailyInvoice = vHasDailyInvoice + isEqualizated = FALSE ON duplicate KEY UPDATE payMethodFk = vPayMethodFk, dueDay = vDueDay, diff --git a/db/routines/vn/procedures/ticket_close.sql b/db/routines/vn/procedures/ticket_close.sql index 0da001ffa..e2dcef9a5 100644 --- a/db/routines/vn/procedures/ticket_close.sql +++ b/db/routines/vn/procedures/ticket_close.sql @@ -43,7 +43,7 @@ BEGIN c.isTaxDataChecked, t.companyFk, t.shipped, - IFNULL(a.hasDailyInvoice, co.hasDailyInvoice), + c.hasDailyInvoice, w.isManaged, c.hasToInvoice INTO vClientFk, @@ -55,9 +55,6 @@ BEGIN vHasToInvoice FROM ticket t JOIN `client` c ON c.id = t.clientFk - JOIN province p ON p.id = c.provinceFk - LEFT JOIN autonomy a ON a.id = p.autonomyFk - JOIN country co ON co.id = p.countryFk JOIN warehouse w ON w.id = t.warehouseFk WHERE t.id = vCurTicketFk; @@ -85,7 +82,7 @@ BEGIN IF(vHasDailyInvoice) AND vHasToInvoice THEN SELECT invoiceSerial(vClientFk, vCompanyFk, 'quick') INTO vSerial; - IF vSerial IS NULL THEN + IF vSerial IS NULL THEN CALL util.throw('Cannot booking without a serial'); END IF; diff --git a/db/versions/11302-limeTulip/00-firstScript.sql b/db/versions/11302-limeTulip/00-firstScript.sql new file mode 100644 index 000000000..7bda31b64 --- /dev/null +++ b/db/versions/11302-limeTulip/00-firstScript.sql @@ -0,0 +1,13 @@ + +UPDATE `vn`.`client` c + JOIN `vn`.`country` co ON co.id=c.countryFk +SET c.hasDailyInvoice = co.hasDailyInvoice +WHERE co.hasDailyInvoice IS NOT NULL + AND c.hasDailyInvoice = FALSE; + +UPDATE `vn`.`client` c + JOIN `vn`.`province` p ON p.id=c.provinceFk + JOIN `vn`.`autonomy` a ON a.id = p.autonomyFk +SET c.hasDailyInvoice = a.hasDailyInvoice +WHERE a.hasDailyInvoice IS NOT NULL + AND c.hasDailyInvoice = FALSE; diff --git a/modules/client/back/methods/client/createWithUser.js b/modules/client/back/methods/client/createWithUser.js index 06b885ab8..c8cd282e1 100644 --- a/modules/client/back/methods/client/createWithUser.js +++ b/modules/client/back/methods/client/createWithUser.js @@ -43,6 +43,23 @@ module.exports = function(Self) { }; try { + const province = await models.Province.findOne({ + where: {id: data.provinceFk}, + fields: ['autonomyFk'] + }); + + const autonomy = province ? await models.Autonomy.findOne({ + where: {id: province.autonomyFk}, + fields: ['hasDailyInvoice'] + }) : null; + + const country = await models.Country.findOne({ + where: {id: data.countryFk}, + fields: ['hasDailyInvoice'] + }); + + const hasDailyInvoice = (autonomy?.hasDailyInvoice ?? country?.hasDailyInvoice) || false; + const account = await models.VnUser.create(user, myOptions); const client = await Self.create({ id: account.id, @@ -57,7 +74,8 @@ module.exports = function(Self) { provinceFk: data.provinceFk, countryFk: data.countryFk, isEqualizated: data.isEqualizated, - businessTypeFk: data.businessTypeFk + businessTypeFk: data.businessTypeFk, + hasDailyInvoice: hasDailyInvoice }, myOptions); const address = await models.Address.create({ diff --git a/modules/client/back/methods/client/specs/createWithUser.spec.js b/modules/client/back/methods/client/specs/createWithUser.spec.js index 5b1ff5da9..f47c24087 100644 --- a/modules/client/back/methods/client/specs/createWithUser.spec.js +++ b/modules/client/back/methods/client/specs/createWithUser.spec.js @@ -1,67 +1,79 @@ const models = require('vn-loopback/server/server').models; + describe('Client Create', () => { - const newAccount = { - userName: 'deadpool', - email: 'deadpool@marvel.com', - fi: '16195279J', - name: 'Wade', - socialName: 'DEADPOOL MARVEL', - street: 'WALL STREET', - city: 'New York', - businessTypeFk: 'florist', - provinceFk: 1 - }; - const newAccountWithoutEmail = JSON.parse(JSON.stringify(newAccount)); - delete newAccountWithoutEmail.email; + let options; + let tx; beforeAll.mockLoopBackContext(); - it(`should not find deadpool as he's not created yet`, async() => { - const tx = await models.Client.beginTransaction({}); + beforeEach(async() => { + tx = await models.Client.beginTransaction({}); + options = {transaction: tx}; + }); + afterEach(async() => await tx.rollback()); + + it('should not find deadpool as he is not created yet', async() => { try { - const options = {transaction: tx}; + const account = await models.VnUser.findOne({where: {name: 'deadpool'}}, options); + const client = await models.Client.findOne({where: {name: 'Wade'}}, options); - const account = await models.VnUser.findOne({where: {name: newAccount.userName}}, options); - const client = await models.Client.findOne({where: {name: newAccount.name}}, options); - - expect(account).toEqual(null); - expect(client).toEqual(null); - - await tx.rollback(); + expect(account).toBeNull(); + expect(client).toBeNull(); } catch (e) { await tx.rollback(); throw e; } }); - it('should not create a new account', async() => { - const tx = await models.Client.beginTransaction({}); - + it('should throw an error when creating a new account without email', async() => { let error; + const newAccountWithoutEmail = { + userName: 'deadpool', + fi: '16195279J', + name: 'Wade', + socialName: 'DEADPOOL MARVEL', + street: 'WALL STREET', + city: 'New York', + businessTypeFk: 'florist', + provinceFk: 1 + }; + try { - const options = {transaction: tx}; await models.Client.createWithUser(newAccountWithoutEmail, options); - - await tx.rollback(); + fail('shapoifaspodifa spdofij'); } catch (e) { - error = e.message; - - await tx.rollback(); + error = e; } - expect(error).toEqual(`An email is necessary`); + expect(error.message).toEqual('An email is necessary'); }); - it('should create a new account', async() => { - const tx = await models.Client.beginTransaction({}); + it('should create a new account with dailyInvoice', async() => { + const newAccount = { + userName: 'deadpool', + email: 'deadpool@marvel.com', + fi: '16195279J', + name: 'Wade', + socialName: 'DEADPOOL MARVEL', + street: 'WALL STREET', + city: 'New York', + businessTypeFk: 'florist', + provinceFk: 1 + }; try { - const options = {transaction: tx}; + const province = await models.Province.findById(newAccount.provinceFk, { + fields: ['id', 'name', 'autonomyFk'], + include: { + relation: 'autonomy' + } + }, options); const client = await models.Client.createWithUser(newAccount, options); const account = await models.VnUser.findOne({where: {name: newAccount.userName}}, options); + expect(province.autonomy().hasDailyInvoice).toBeTruthy(); expect(account.name).toEqual(newAccount.userName); expect(client.id).toEqual(account.id); expect(client.name).toEqual(newAccount.name); @@ -69,8 +81,38 @@ describe('Client Create', () => { expect(client.fi).toEqual(newAccount.fi); expect(client.socialName).toEqual(newAccount.socialName); expect(client.businessTypeFk).toEqual(newAccount.businessTypeFk); - + expect(client.hasDailyInvoice).toBeTruthy(); + } catch (e) { await tx.rollback(); + throw e; + } + }); + + it('should create a new account without dailyInvoice', async() => { + const newAccount = { + userName: 'deadpool', + email: 'deadpool@marvel.com', + fi: '16195279J', + name: 'Wade', + socialName: 'DEADPOOL MARVEL', + street: 'WALL STREET', + city: 'New York', + businessTypeFk: 'florist', + provinceFk: 3 + }; + + try { + const province = await models.Province.findById(newAccount.provinceFk, { + fields: ['id', 'name', 'autonomyFk'], + include: { + relation: 'autonomy' + } + }, options); + + const client = await models.Client.createWithUser(newAccount, options); + + expect(province.autonomy.hasDailyInvoice).toBeFalsy(); + expect(client.hasDailyInvoice).toBeFalsy(); } catch (e) { await tx.rollback(); throw e; @@ -78,26 +120,25 @@ describe('Client Create', () => { }); it('should not be able to create a user if exists', async() => { - const tx = await models.Client.beginTransaction({}); - let error; - + const newAccount = { + userName: 'deadpool', + email: 'deadpool@marvel.com', + fi: '16195279J', + name: 'Wade', + socialName: 'DEADPOOL MARVEL', + street: 'WALL STREET', + city: 'New York', + businessTypeFk: 'florist', + provinceFk: 1 + }; try { - const options = {transaction: tx}; - await models.Client.createWithUser(newAccount, options); - const client = await models.Client.createWithUser(newAccount, options); - - expect(client).toBeNull(); - - await tx.rollback(); + await models.Client.createWithUser(newAccount, options); } catch (e) { - await tx.rollback(); error = e; } - const errorName = error.details.codes.name[0]; - - expect(errorName).toEqual('uniqueness'); + expect(error.message).toContain('already exists'); }); }); diff --git a/modules/ticket/back/methods/ticket/closeAll.js b/modules/ticket/back/methods/ticket/closeAll.js index 4fd72d454..b9060d2f2 100644 --- a/modules/ticket/back/methods/ticket/closeAll.js +++ b/modules/ticket/back/methods/ticket/closeAll.js @@ -41,7 +41,7 @@ module.exports = Self => { c.salesPersonFk, c.isToBeMailed, c.hasToInvoice, - co.hasDailyInvoice, + c.hasDailyInvoice, eu.email salesPersonEmail, t.addressFk FROM ticket t @@ -120,7 +120,7 @@ module.exports = Self => { WHERE (al.code = 'PACKED' OR (am.code = 'refund' AND al.code <> 'delivered')) AND t.shipped BETWEEN ? - INTERVAL tc.closureDaysAgo DAY AND util.dayEnd(?) AND t.refFk IS NULL - AND IFNULL(a.hasDailyInvoice, co.hasDailyInvoice) + AND c.hasDailyInvoice GROUP BY ticketFk HAVING hasErrorToInvoice OR hasErrorTaxDataChecked diff --git a/modules/ticket/back/methods/ticket/closeByTicket.js b/modules/ticket/back/methods/ticket/closeByTicket.js index 40fe048a5..8a21267b6 100644 --- a/modules/ticket/back/methods/ticket/closeByTicket.js +++ b/modules/ticket/back/methods/ticket/closeByTicket.js @@ -50,7 +50,7 @@ module.exports = Self => { c.salesPersonFk, c.isToBeMailed, c.hasToInvoice, - co.hasDailyInvoice, + c.hasDailyInvoice, eu.email salesPersonEmail, t.addressFk FROM expedition e @@ -58,8 +58,6 @@ module.exports = Self => { JOIN ticketState ts ON ts.ticketFk = t.id JOIN alertLevel al ON al.id = ts.alertLevel JOIN client c ON c.id = t.clientFk - JOIN province p ON p.id = c.provinceFk - JOIN country co ON co.id = p.countryFk LEFT JOIN account.emailUser eu ON eu.userFk = c.salesPersonFk WHERE al.code = 'PACKED' AND t.id = ? From aac4dd0a6d1719ccc9937faa67871b5dd205bc78 Mon Sep 17 00:00:00 2001 From: jgallego Date: Wed, 16 Oct 2024 08:52:27 +0200 Subject: [PATCH 16/74] feat: refs #7348 minor bug --- modules/client/back/methods/client/specs/createWithUser.spec.js | 1 - 1 file changed, 1 deletion(-) diff --git a/modules/client/back/methods/client/specs/createWithUser.spec.js b/modules/client/back/methods/client/specs/createWithUser.spec.js index f47c24087..8cff96ac5 100644 --- a/modules/client/back/methods/client/specs/createWithUser.spec.js +++ b/modules/client/back/methods/client/specs/createWithUser.spec.js @@ -41,7 +41,6 @@ describe('Client Create', () => { try { await models.Client.createWithUser(newAccountWithoutEmail, options); - fail('shapoifaspodifa spdofij'); } catch (e) { error = e; } From 8ca097d4a9fc979fe14e4a25e4b3e0df503d1daf Mon Sep 17 00:00:00 2001 From: jorgep Date: Wed, 16 Oct 2024 09:23:39 +0200 Subject: [PATCH 17/74] chore: refs #7919 change var name --- modules/ticket/back/methods/ticket/setDeleted.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/ticket/back/methods/ticket/setDeleted.js b/modules/ticket/back/methods/ticket/setDeleted.js index e868e9258..fcab95ee2 100644 --- a/modules/ticket/back/methods/ticket/setDeleted.js +++ b/modules/ticket/back/methods/ticket/setDeleted.js @@ -49,12 +49,12 @@ module.exports = Self => { where: {originalTicketFk: id} }, myOptions); - const isRefund = !!ticketRefunds?.length; + const hasRefund = !!ticketRefunds?.length; const allDeleted = ticketRefunds.every(refund => refund.refundTicket().isDeleted); - if (!isRefund) await models.TicketRefund.destroyAll({refundTicketFk: id}, myOptions); - if (isRefund && !allDeleted) { + if (!hasRefund) await models.TicketRefund.destroyAll({refundTicketFk: id}, myOptions); + if (hasRefund && !allDeleted) { const notDeleted = []; for (const refund of ticketRefunds) if (!refund.refundTicket().isDeleted) notDeleted.push(refund.refundTicket().id); From 681f82a3ae934f7834d1122ef2821241242f1771 Mon Sep 17 00:00:00 2001 From: jgallego Date: Wed, 16 Oct 2024 16:09:53 +0200 Subject: [PATCH 18/74] feat: refs #7744 test back ok --- .../back/methods/invoiceOut/delete.js | 8 ++--- modules/ticket/back/methods/ticket/closure.js | 3 +- .../methods/ticket/specs/closeAll.spec.js | 32 ++----------------- 3 files changed, 8 insertions(+), 35 deletions(-) diff --git a/modules/invoiceOut/back/methods/invoiceOut/delete.js b/modules/invoiceOut/back/methods/invoiceOut/delete.js index d6efd9961..1ab9a582b 100644 --- a/modules/invoiceOut/back/methods/invoiceOut/delete.js +++ b/modules/invoiceOut/back/methods/invoiceOut/delete.js @@ -37,7 +37,7 @@ module.exports = Self => { const tickets = await models.Ticket.find({ where: {refFk: invoiceOut.ref} }, myOptions); - + const [bookEntry] = await models.Xdiario.find({ where: { SERIE: invoiceOut.ref[0], @@ -55,13 +55,13 @@ module.exports = Self => { if (bookEntry) { if (bookEntry.enlazadoSage) { const params = { - bookEntry: bookEntry.ASIEN, + bookEntry: bookEntry.ASIEN, invoiceOutRef: invoiceOut.ref - } + }; await Self.rawSql(`SELECT util.notification_send('book-entry-deleted', ?, NULL)`, [JSON.stringify(params)], myOptions); - }; + } await models.Xdiario.destroyAll({ ASIEN: bookEntry.ASIEN diff --git a/modules/ticket/back/methods/ticket/closure.js b/modules/ticket/back/methods/ticket/closure.js index 64f198834..e4cb49007 100644 --- a/modules/ticket/back/methods/ticket/closure.js +++ b/modules/ticket/back/methods/ticket/closure.js @@ -19,8 +19,7 @@ module.exports = async function(ctx, Self, tickets, options) { const failedtickets = []; for (const ticket of tickets) { try { - await Self.rawSql(`CALL util.debugAdd('invoicingTicket', ?)`, [ticket.id], {userId}, - myOptions); + await Self.rawSql(`CALL util.debugAdd('invoicingTicket', ?)`, [ticket.id], myOptions); await Self.app.models.InvoiceOut.getSerial( ticket.clientFk, diff --git a/modules/ticket/back/methods/ticket/specs/closeAll.spec.js b/modules/ticket/back/methods/ticket/specs/closeAll.spec.js index 4b067ce7e..f01541eec 100644 --- a/modules/ticket/back/methods/ticket/specs/closeAll.spec.js +++ b/modules/ticket/back/methods/ticket/specs/closeAll.spec.js @@ -1,7 +1,7 @@ const models = require('vn-loopback/server/server').models; const LoopBackContext = require('loopback-context'); -fdescribe('Ticket Closure - closeAll function', () => { +describe('Ticket Closure - closeAll function', () => { let ctx = { req: { getLocale: () => 'es', @@ -17,6 +17,7 @@ fdescribe('Ticket Closure - closeAll function', () => { beforeEach(async() => { spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({active: ctx.req}); + tx = await models.Ticket.beginTransaction({}); options = {transaction: tx}; originalVnNew = Date.vnNew; @@ -32,34 +33,7 @@ fdescribe('Ticket Closure - closeAll function', () => { await tx.rollback(); }); - xit('should successfully close all tickets when conditions are met', async() => { - const ticketsBefore = await models.Ticket.find({ - where: { - packages: {neq: 0} - } - }, options); - const packedTicketsIds = ticketsBefore.map(ticket => ticket.id); - - const packedTicketsBefore = await models.TicketLastState.find({ - where: { - ticketFk: {inq: packedTicketsIds}, - lastState: 'Encajado' - } - }, options); - - await models.Ticket.closeAll(ctx, options); - - const packedTicketsAfter = await models.TicketLastState.find({ - where: { - ticketFk: {inq: packedTicketsIds}, - lastState: 'Encajado' - } - }, options); - - expect(packedTicketsBefore.length).toBeGreaterThan(packedTicketsAfter.length); - }); - - fit('should set routeFk to NULL when conditions are met', async() => { + it('should set routeFk to NULL when conditions are met', async() => { const ticketsBefore = await models.Ticket.find({ where: { routeFk: {neq: null} From de0fe37ffe978118101fdd2c34615b103ec84da7 Mon Sep 17 00:00:00 2001 From: jorgep Date: Wed, 16 Oct 2024 16:16:51 +0200 Subject: [PATCH 19/74] feat: refs #8083 add prop --- modules/ticket/back/models/expedition.json | 117 +++++++++++---------- 1 file changed, 60 insertions(+), 57 deletions(-) diff --git a/modules/ticket/back/models/expedition.json b/modules/ticket/back/models/expedition.json index 2dcca1e87..f3f912ec3 100644 --- a/modules/ticket/back/models/expedition.json +++ b/modules/ticket/back/models/expedition.json @@ -1,63 +1,66 @@ { - "name": "Expedition", - "base": "VnModel", - "mixins": { - "Loggable": true + "name": "Expedition", + "base": "VnModel", + "mixins": { + "Loggable": true + }, + "options": { + "mysql": { + "table": "expedition" + } + }, + "properties": { + "id": { + "id": true, + "type": "number", + "description": "Identifier" }, - "options": { - "mysql": { - "table": "expedition" - } + "freightItemFk": { + "type": "number" }, - "properties": { - "id": { - "id": true, - "type": "number", - "description": "Identifier" - }, - "freightItemFk": { - "type": "number" - }, - "created": { - "type": "date" - }, - "counter": { - "type": "number" - }, - "externalId": { - "type": "string" - } + "created": { + "type": "date" }, - "relations": { - "ticket": { - "type": "belongsTo", - "model": "Ticket", - "foreignKey": "ticketFk" - }, - "agencyMode": { - "type": "belongsTo", - "model": "AgencyMode", - "foreignKey": "agencyModeFk" - }, - "worker": { - "type": "belongsTo", - "model": "Worker", - "foreignKey": "workerFk" - }, - "packages": { - "type": "hasMany", - "model": "TicketPackaging", - "foreignKey": "ticketFk" - }, - "freightItem": { - "type": "belongsTo", - "model": "Item", - "foreignKey": "freightItemFk" - }, - "packaging": { - "type": "belongsTo", - "model": "Package", - "foreignKey": "packagingFk" - } + "counter": { + "type": "number" + }, + "externalId": { + "type": "string" + }, + "stateTypeFk": { + "type": "number" + } + }, + "relations": { + "ticket": { + "type": "belongsTo", + "model": "Ticket", + "foreignKey": "ticketFk" + }, + "agencyMode": { + "type": "belongsTo", + "model": "AgencyMode", + "foreignKey": "agencyModeFk" + }, + "worker": { + "type": "belongsTo", + "model": "Worker", + "foreignKey": "workerFk" + }, + "packages": { + "type": "hasMany", + "model": "TicketPackaging", + "foreignKey": "ticketFk" + }, + "freightItem": { + "type": "belongsTo", + "model": "Item", + "foreignKey": "freightItemFk" + }, + "packaging": { + "type": "belongsTo", + "model": "Package", + "foreignKey": "packagingFk" } } +} \ No newline at end of file From 999cb2dbb44361f20471532e39e52b94a4dee038 Mon Sep 17 00:00:00 2001 From: guillermo Date: Thu, 17 Oct 2024 10:08:27 +0200 Subject: [PATCH 20/74] feat: refs #8119 itemCampaignQuantity --- .../vn/events/itemCampaignQuantity_add.sql | 8 ++ .../procedures/itemCampaignQuantity_add.sql | 81 +++++++++++++++++++ .../11308-redCymbidium/00-firstScript.sql | 24 ++++++ 3 files changed, 113 insertions(+) create mode 100644 db/routines/vn/events/itemCampaignQuantity_add.sql create mode 100644 db/routines/vn/procedures/itemCampaignQuantity_add.sql create mode 100644 db/versions/11308-redCymbidium/00-firstScript.sql diff --git a/db/routines/vn/events/itemCampaignQuantity_add.sql b/db/routines/vn/events/itemCampaignQuantity_add.sql new file mode 100644 index 000000000..a90a678f3 --- /dev/null +++ b/db/routines/vn/events/itemCampaignQuantity_add.sql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`vn`@`localhost` EVENT `vn`.`itemCampaignQuantity_add` + ON SCHEDULE EVERY 5 MINUTE + STARTS '2024-10-18 03:00:00.000' + ON COMPLETION PRESERVE + ENABLE +DO CALL itemCampaignQuantity_add(NULL, NULL, NULL)$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/itemCampaignQuantity_add.sql b/db/routines/vn/procedures/itemCampaignQuantity_add.sql new file mode 100644 index 000000000..af5d0e2de --- /dev/null +++ b/db/routines/vn/procedures/itemCampaignQuantity_add.sql @@ -0,0 +1,81 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`itemCampaignQuantity_add`( + vDateFrom DATE, + vDateTo DATE, + vCampaign VARCHAR(100) +) +proc: BEGIN +/** + * Añade registros a tabla itemCampaignQuantity. + * + * @param vDateFrom Fecha desde + * @param vDateTo Fecha hasta + * @param vCampaign Código de la campaña + */ + DECLARE vYesterday INT; + DECLARE vDefaultCampaign VARCHAR(100); + DECLARE vPreviousDaysToInsert INT; + DECLARE vDateSumFrom DATE; + DECLARE vDateSumTo DATE; + DECLARE vScopeDays DATE; + + SET vYesterday = util.yesterday(); + + IF vDateFrom IS NULL THEN + SET vDateFrom = vYesterday; + END IF; + + IF vDateTo IS NULL THEN + SET vDateTo = vYesterday; + END IF; + + IF vDateFrom > vDateTo THEN + CALL util.throw('Start date cannot be later than end date'); + END IF; + + SELECT defaultCampaign, previousDaysToInsert + INTO vDefaultCampaign, vPreviousDaysToInsert + FROM itemCampaignQuantityConfig; + + IF vCampaign IS NULL THEN + SET vCampaign = vDefaultCampaign; + END IF; + + IF vCampaign IS NULL OR vPreviousDaysToInsert IS NULL THEN + CALL util.throw('Missing values in the configuration table'); + END IF; + + SELECT dated, scopeDays INTO vDateSumTo, vScopeDays + FROM campaign + WHERE dated > util.VN_CURDATE() + AND code = vCampaign + ORDER BY dated + LIMIT 1; + + IF vDateSumTo IS NULL OR vScopeDays IS NULL THEN + CALL util.throw('Missing data in campaign table'); + END IF; + + IF NOT util.VN_CURDATE() BETWEEN vDateSumTo - INTERVAL vPreviousDaysToInsert DAY + AND vDateSumTo THEN + LEAVE proc; + END IF; + + SET vDateSumFrom = vDateSumTo - INTERVAL vScopeDays DAY; + + INSERT INTO itemCampaignQuantity(dated, itemFk, quantity, campaign) + SELECT DATE(s.created), + s.itemFk, + CASE WHEN t.shipped BETWEEN vDateSumFrom AND vDateSumTo + THEN SUM(s.quantity) + END quantity, + vCampaign + FROM sale s + JOIN ticket t ON t.id = s.ticketFk + JOIN client c ON c.id = t.clientFk + WHERE s.created BETWEEN vDateFrom AND util.dayEnd(vDateTo) + AND c.businessTypeFk <> 'worker' + GROUP BY DATE(s.created), s.itemFk + HAVING quantity; +END$$ +DELIMITER ; diff --git a/db/versions/11308-redCymbidium/00-firstScript.sql b/db/versions/11308-redCymbidium/00-firstScript.sql new file mode 100644 index 000000000..ea3436b80 --- /dev/null +++ b/db/versions/11308-redCymbidium/00-firstScript.sql @@ -0,0 +1,24 @@ +CREATE TABLE IF NOT EXISTS vn.itemCampaignQuantity ( + dated date NOT NULL, + itemFk int(11) NOT NULL, + quantity decimal(10,2) NOT NULL, + campaign varchar(100) NOT NULL, + CONSTRAINT itemCampaignQuantity_pk PRIMARY KEY (dated,itemFk), + CONSTRAINT itemCampaignQuantity_item_FK FOREIGN KEY (itemFk) REFERENCES vn.item(id) ON DELETE RESTRICT ON UPDATE CASCADE +) +ENGINE=InnoDB +DEFAULT CHARSET=utf8mb3 +COLLATE=utf8mb3_unicode_ci; + +CREATE TABLE IF NOT EXISTS vn.itemCampaignQuantityConfig ( + id int(10) unsigned NOT NULL PRIMARY, + defaultCampaign varchar(100) NOT NULL COMMENT 'Campaña por defecto si se le pasa NULL', + previousDaysToInsert int(10) unsigned NOT NULL COMMENT 'Días anteriores a la fecha de fin de campaña para insertar', + CONSTRAINT `itemCampaignQuantityConfig_check` CHECK (`id` = 1) +) +ENGINE=InnoDB +DEFAULT CHARSET=utf8mb3 +COLLATE=utf8mb3_unicode_ci; + +INSERT IGNORE INTO vn.itemCampaignQuantityConfig(id, defaultCampaign, previousDaysToInsert) + VALUES (1, 'allSaints', 90); From ec13c41be327c560c3982f70f2b3c2ac159e046e Mon Sep 17 00:00:00 2001 From: guillermo Date: Thu, 17 Oct 2024 10:09:57 +0200 Subject: [PATCH 21/74] feat: refs #8119 itemCampaignQuantity --- db/routines/vn/events/itemCampaignQuantity_add.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/routines/vn/events/itemCampaignQuantity_add.sql b/db/routines/vn/events/itemCampaignQuantity_add.sql index a90a678f3..4deb2d556 100644 --- a/db/routines/vn/events/itemCampaignQuantity_add.sql +++ b/db/routines/vn/events/itemCampaignQuantity_add.sql @@ -1,6 +1,6 @@ DELIMITER $$ CREATE OR REPLACE DEFINER=`vn`@`localhost` EVENT `vn`.`itemCampaignQuantity_add` - ON SCHEDULE EVERY 5 MINUTE + ON SCHEDULE EVERY 1 DAY STARTS '2024-10-18 03:00:00.000' ON COMPLETION PRESERVE ENABLE From 3628abd5bfe87c47c359e01ca54331f1a0bb99f4 Mon Sep 17 00:00:00 2001 From: guillermo Date: Thu, 17 Oct 2024 10:15:45 +0200 Subject: [PATCH 22/74] feat: refs #8119 itemCampaignQuantity --- db/routines/vn/procedures/itemCampaignQuantity_add.sql | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/db/routines/vn/procedures/itemCampaignQuantity_add.sql b/db/routines/vn/procedures/itemCampaignQuantity_add.sql index af5d0e2de..56e68c3b0 100644 --- a/db/routines/vn/procedures/itemCampaignQuantity_add.sql +++ b/db/routines/vn/procedures/itemCampaignQuantity_add.sql @@ -12,13 +12,15 @@ proc: BEGIN * @param vDateTo Fecha hasta * @param vCampaign Código de la campaña */ - DECLARE vYesterday INT; + DECLARE vCurdate DATE; + DECLARE vYesterday DATE; DECLARE vDefaultCampaign VARCHAR(100); DECLARE vPreviousDaysToInsert INT; DECLARE vDateSumFrom DATE; DECLARE vDateSumTo DATE; DECLARE vScopeDays DATE; + SET vCurdate = util.VN_CURDATE(); SET vYesterday = util.yesterday(); IF vDateFrom IS NULL THEN @@ -47,7 +49,7 @@ proc: BEGIN SELECT dated, scopeDays INTO vDateSumTo, vScopeDays FROM campaign - WHERE dated > util.VN_CURDATE() + WHERE dated > vCurdate AND code = vCampaign ORDER BY dated LIMIT 1; @@ -56,7 +58,7 @@ proc: BEGIN CALL util.throw('Missing data in campaign table'); END IF; - IF NOT util.VN_CURDATE() BETWEEN vDateSumTo - INTERVAL vPreviousDaysToInsert DAY + IF NOT vCurdate BETWEEN vDateSumTo - INTERVAL vPreviousDaysToInsert DAY AND vDateSumTo THEN LEAVE proc; END IF; From 41d078aaf1db20eea232fcf1600be544212f4b47 Mon Sep 17 00:00:00 2001 From: guillermo Date: Thu, 17 Oct 2024 10:16:26 +0200 Subject: [PATCH 23/74] feat: refs #8119 itemCampaignQuantity --- db/routines/vn/procedures/itemCampaignQuantity_add.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/routines/vn/procedures/itemCampaignQuantity_add.sql b/db/routines/vn/procedures/itemCampaignQuantity_add.sql index 56e68c3b0..6cadd09be 100644 --- a/db/routines/vn/procedures/itemCampaignQuantity_add.sql +++ b/db/routines/vn/procedures/itemCampaignQuantity_add.sql @@ -18,7 +18,7 @@ proc: BEGIN DECLARE vPreviousDaysToInsert INT; DECLARE vDateSumFrom DATE; DECLARE vDateSumTo DATE; - DECLARE vScopeDays DATE; + DECLARE vScopeDays INT; SET vCurdate = util.VN_CURDATE(); SET vYesterday = util.yesterday(); From 8ca69d3574185ca860ff0cdce42e732412a2d836 Mon Sep 17 00:00:00 2001 From: guillermo Date: Thu, 17 Oct 2024 10:21:39 +0200 Subject: [PATCH 24/74] feat: refs #8119 Minor change --- db/routines/vn/procedures/itemCampaignQuantity_add.sql | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/db/routines/vn/procedures/itemCampaignQuantity_add.sql b/db/routines/vn/procedures/itemCampaignQuantity_add.sql index 6cadd09be..6dffb3918 100644 --- a/db/routines/vn/procedures/itemCampaignQuantity_add.sql +++ b/db/routines/vn/procedures/itemCampaignQuantity_add.sql @@ -68,9 +68,9 @@ proc: BEGIN INSERT INTO itemCampaignQuantity(dated, itemFk, quantity, campaign) SELECT DATE(s.created), s.itemFk, - CASE WHEN t.shipped BETWEEN vDateSumFrom AND vDateSumTo - THEN SUM(s.quantity) - END quantity, + SUM(CASE WHEN t.shipped BETWEEN vDateSumFrom AND vDateSumTo + THEN s.quantity + END) quantity, vCampaign FROM sale s JOIN ticket t ON t.id = s.ticketFk From 2bd98b7fb663a339e314cf7e64cdaf2fe662e712 Mon Sep 17 00:00:00 2001 From: guillermo Date: Thu, 17 Oct 2024 10:29:35 +0200 Subject: [PATCH 25/74] feat: refs #8119 Minor change --- db/versions/11308-redCymbidium/00-firstScript.sql | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/db/versions/11308-redCymbidium/00-firstScript.sql b/db/versions/11308-redCymbidium/00-firstScript.sql index ea3436b80..baa703a5a 100644 --- a/db/versions/11308-redCymbidium/00-firstScript.sql +++ b/db/versions/11308-redCymbidium/00-firstScript.sql @@ -1,4 +1,4 @@ -CREATE TABLE IF NOT EXISTS vn.itemCampaignQuantity ( +CREATE TABLE IF NOT EXISTS `vn`.`itemCampaignQuantity` ( dated date NOT NULL, itemFk int(11) NOT NULL, quantity decimal(10,2) NOT NULL, @@ -10,8 +10,8 @@ ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; -CREATE TABLE IF NOT EXISTS vn.itemCampaignQuantityConfig ( - id int(10) unsigned NOT NULL PRIMARY, +CREATE TABLE IF NOT EXISTS `vn`.`itemCampaignQuantityConfig` ( + id int(10) unsigned NOT NULL PRIMARY KEY, defaultCampaign varchar(100) NOT NULL COMMENT 'Campaña por defecto si se le pasa NULL', previousDaysToInsert int(10) unsigned NOT NULL COMMENT 'Días anteriores a la fecha de fin de campaña para insertar', CONSTRAINT `itemCampaignQuantityConfig_check` CHECK (`id` = 1) @@ -20,5 +20,5 @@ ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; -INSERT IGNORE INTO vn.itemCampaignQuantityConfig(id, defaultCampaign, previousDaysToInsert) +INSERT IGNORE INTO `vn`.`itemCampaignQuantityConfig` (id, defaultCampaign, previousDaysToInsert) VALUES (1, 'allSaints', 90); From f85267db9262c71ddb81017009c08aba9395cd6f Mon Sep 17 00:00:00 2001 From: guillermo Date: Thu, 17 Oct 2024 11:06:11 +0200 Subject: [PATCH 26/74] feat: refs #8119 Fix test --- back/methods/vn-user/specs/renew-token.spec.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/back/methods/vn-user/specs/renew-token.spec.js b/back/methods/vn-user/specs/renew-token.spec.js index 8f1bb54c1..8941916ec 100644 --- a/back/methods/vn-user/specs/renew-token.spec.js +++ b/back/methods/vn-user/specs/renew-token.spec.js @@ -72,9 +72,9 @@ describe('Renew Token', () => { } expect(error).toBeDefined(); - const query = 'SELECT * FROM util.debug'; - const debugLog = await models.Application.rawSql(query, null); + const query = 'SELECT * FROM util.debug WHERE variable = "renewToken"'; + const debugLog = await models.Application.rawSql(query); expect(debugLog.length).toEqual(1); }); From faecbbb3735034876e7544891fc63702e089b0ad Mon Sep 17 00:00:00 2001 From: robert Date: Thu, 17 Oct 2024 13:08:58 +0200 Subject: [PATCH 27/74] feat: refs #8108 saltos de linea --- db/versions/11300-limeMedeola/00-firstScript.sql | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/db/versions/11300-limeMedeola/00-firstScript.sql b/db/versions/11300-limeMedeola/00-firstScript.sql index 313a65e81..28b033b4a 100644 --- a/db/versions/11300-limeMedeola/00-firstScript.sql +++ b/db/versions/11300-limeMedeola/00-firstScript.sql @@ -13,8 +13,6 @@ UPDATE vn.tag sourceTable='itemFarmingTag' WHERE name= 'cultivo'; - - CREATE TABLE IF NOT EXISTS `vn`.`itemWrappingTag` ( `id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT, `name` varchar(50) DEFAULT NULL, @@ -36,8 +34,6 @@ UPDATE vn.tag sourceTable='itemWrappingTag' WHERE name= 'Envoltorio'; - - CREATE TABLE IF NOT EXISTS `vn`.`itemLanguageTag` ( `id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT, `name` varchar(50) DEFAULT NULL, @@ -59,8 +55,6 @@ UPDATE vn.tag sourceTable='itemLanguageTag' WHERE name= 'Idioma'; - - CREATE TABLE IF NOT EXISTS `vn`.`itemStemTag` ( `id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT, `name` varchar(50) DEFAULT NULL, @@ -94,8 +88,6 @@ UPDATE vn.tag sourceTable='itemBreederTag' WHERE name= 'Obtentor'; - - CREATE TABLE IF NOT EXISTS `vn`.`itemBaseTag` ( `id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT, `name` varchar(50) DEFAULT NULL, @@ -120,8 +112,6 @@ UPDATE vn.tag sourceTable='itemBaseTag' WHERE name= 'Soporte'; - - CREATE TABLE IF NOT EXISTS `vn`.`itemVatRateTag` ( `id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT, `name` varchar(50) DEFAULT NULL, @@ -133,13 +123,11 @@ CREATE TABLE IF NOT EXISTS `vn`.`itemVatRateTag` ( INSERT IGNORE INTO `vn`.`itemVatRateTag` (`name`) VALUES ('General'); INSERT IGNORE INTO `vn`.`itemVatRateTag` (`name`) VALUES ('Reducido'); - UPDATE vn.tag SET isFree=0, sourceTable='itemVatRateTag' WHERE name= 'Tipo de IVA'; - GRANT SELECT, UPDATE, INSERT, DELETE ON TABLE vn.itemFarmingTag TO logisticAssist; GRANT SELECT, UPDATE, INSERT, DELETE ON TABLE vn.itemWrappingTag TO logisticAssist; GRANT SELECT, UPDATE, INSERT, DELETE ON TABLE vn.itemLanguageTag TO logisticAssist; From 4bd28c62b9ffc43470ec2f883ee1d4d3b8328872 Mon Sep 17 00:00:00 2001 From: guillermo Date: Fri, 18 Oct 2024 07:35:36 +0200 Subject: [PATCH 28/74] feat: refs #8119 Requested changes --- db/versions/11308-redCymbidium/00-firstScript.sql | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/db/versions/11308-redCymbidium/00-firstScript.sql b/db/versions/11308-redCymbidium/00-firstScript.sql index baa703a5a..6e0afdd8b 100644 --- a/db/versions/11308-redCymbidium/00-firstScript.sql +++ b/db/versions/11308-redCymbidium/00-firstScript.sql @@ -1,14 +1,16 @@ CREATE TABLE IF NOT EXISTS `vn`.`itemCampaignQuantity` ( + `id` int(11) NOT NULL PRIMARY KEY AUTO_INCREMENT, dated date NOT NULL, itemFk int(11) NOT NULL, quantity decimal(10,2) NOT NULL, campaign varchar(100) NOT NULL, - CONSTRAINT itemCampaignQuantity_pk PRIMARY KEY (dated,itemFk), + UNIQUE KEY `itemCampaignQuantity_UNIQUE` (`dated`,`itemFk`), CONSTRAINT itemCampaignQuantity_item_FK FOREIGN KEY (itemFk) REFERENCES vn.item(id) ON DELETE RESTRICT ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 -COLLATE=utf8mb3_unicode_ci; +COLLATE=utf8mb3_unicode_ci +COMMENT='Tallos confirmados por día en los días de más producción de una campaña'; CREATE TABLE IF NOT EXISTS `vn`.`itemCampaignQuantityConfig` ( id int(10) unsigned NOT NULL PRIMARY KEY, From 7e604f1a19f7a993aba6c47b3d522fac3e180a07 Mon Sep 17 00:00:00 2001 From: guillermo Date: Fri, 18 Oct 2024 07:44:28 +0200 Subject: [PATCH 29/74] feat: refs #8119 Requested changes --- db/routines/vn/procedures/itemCampaignQuantity_add.sql | 2 +- db/versions/11308-redCymbidium/00-firstScript.sql | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/db/routines/vn/procedures/itemCampaignQuantity_add.sql b/db/routines/vn/procedures/itemCampaignQuantity_add.sql index 6dffb3918..ca041d2d2 100644 --- a/db/routines/vn/procedures/itemCampaignQuantity_add.sql +++ b/db/routines/vn/procedures/itemCampaignQuantity_add.sql @@ -65,7 +65,7 @@ proc: BEGIN SET vDateSumFrom = vDateSumTo - INTERVAL vScopeDays DAY; - INSERT INTO itemCampaignQuantity(dated, itemFk, quantity, campaign) + REPLACE itemCampaignQuantity(dated, itemFk, quantity, campaign) SELECT DATE(s.created), s.itemFk, SUM(CASE WHEN t.shipped BETWEEN vDateSumFrom AND vDateSumTo diff --git a/db/versions/11308-redCymbidium/00-firstScript.sql b/db/versions/11308-redCymbidium/00-firstScript.sql index 6e0afdd8b..d90cd1ae6 100644 --- a/db/versions/11308-redCymbidium/00-firstScript.sql +++ b/db/versions/11308-redCymbidium/00-firstScript.sql @@ -10,7 +10,7 @@ CREATE TABLE IF NOT EXISTS `vn`.`itemCampaignQuantity` ( ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci -COMMENT='Tallos confirmados por día en los días de más producción de una campaña'; +COMMENT='Tallos confirmados por día en los días de más producción de una campaña. La tabla está pensada para que sea una foto.'; CREATE TABLE IF NOT EXISTS `vn`.`itemCampaignQuantityConfig` ( id int(10) unsigned NOT NULL PRIMARY KEY, From 34deba406bbb8d6792a5334cb4c0367fe43b35a2 Mon Sep 17 00:00:00 2001 From: guillermo Date: Fri, 18 Oct 2024 12:59:52 +0200 Subject: [PATCH 30/74] feat: refs #7266 First commit --- .../reports/item-label/assets/css/style.css | 113 +++++------------- .../reports/item-label/item-label.html | 66 +++++----- 2 files changed, 68 insertions(+), 111 deletions(-) diff --git a/print/templates/reports/item-label/assets/css/style.css b/print/templates/reports/item-label/assets/css/style.css index 1101604b9..0dea5a9e4 100644 --- a/print/templates/reports/item-label/assets/css/style.css +++ b/print/templates/reports/item-label/assets/css/style.css @@ -1,88 +1,37 @@ -* { - box-sizing: border-box; +html { + font-family: "Roboto", "Helvetica", "Arial", sans-serif; + font-size: 12px; } -.label { - font-size: 1.2em; -} - -.barcode { - float: left; - width: 40%; -} - -.barcode h1 { - text-align: center; - font-size: 1.8em; - margin: 0 0 10px 0 -} - -.barcode .image { - text-align: center -} - -.barcode .image img { - width: 170px -} - -.data { - float: left; - width: 60%; -} - -.data .header { - background-color: #000; - text-overflow: ellipsis; - white-space: nowrap; - overflow: hidden; - margin-bottom: 25px; - text-align: right; - font-size: 1.2em; - padding: 0.2em; - color: #FFF -} - -.data .color, -.data .producer { - text-transform: uppercase; - text-align: right; - font-size: 1.5em; - text-overflow: ellipsis; - white-space: nowrap; - overflow: hidden; -} - -.data .producer { - text-justify: inter-character; -} - -.data .details { - border-top: 4px solid #000; - padding-top: 2px; -} - -.data .details .package { - padding-right: 5px; - float: left; +table { width: 50%; + font-size: 12px; + float: right; } - -.package .packing, -.package .dated, -.package .labelNumber { - text-align: right +td { + border: 3px solid white; } - -.package .packing { - font-size: 1.8em; - font-weight: 400 -} - -.data .details .size { - background-color: #000; +.center { text-align: center; - font-size: 3em; - padding: 0.2em 0; - float: left; - width: 50%; - color: #FFF +} +.cursive { + font-style: italic; +} +.bold { + font-weight: bold; +} +.black { + background-color: black; + color: white; +} +.md { + font-size: 18px; +} +.xl { + font-size: 36px; +} +.border-black { + border: 2px solid #000000; +} +.regular-with { + width: 60px; } \ No newline at end of file diff --git a/print/templates/reports/item-label/item-label.html b/print/templates/reports/item-label/item-label.html index 66509ab38..e2526fc6b 100644 --- a/print/templates/reports/item-label/item-label.html +++ b/print/templates/reports/item-label/item-label.html @@ -1,29 +1,37 @@ - - -
-
-

{{item.id}}

-
- -
-
-
-
{{item.name}}
-
{{tags.color}}
-
{{tags.producer}}
-
-
-
{{packing()}}
-
{{formatDate(new Date(), '%W/%d')}}
-
{{labelPage}}
-
-
{{item.size}}
-
-
-
- -
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
1
EUC Cinerea60
Color: LIV150
Origen: VCL
Productor: L'Arenal
Comprador: ATJF:42/11 / 50
Entrada: 358799
E622/2
+ + \ No newline at end of file From b8e782d3a569f935aeb7d55ce65ecde345a7d93b Mon Sep 17 00:00:00 2001 From: carlossa Date: Sun, 20 Oct 2024 15:59:24 +0200 Subject: [PATCH 31/74] fix: refs #6831 filter observation --- modules/client/back/methods/defaulter/filter.js | 3 ++- modules/client/back/methods/defaulter/observationEmail.js | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/modules/client/back/methods/defaulter/filter.js b/modules/client/back/methods/defaulter/filter.js index 9f19dee0a..5359ce4a7 100644 --- a/modules/client/back/methods/defaulter/filter.js +++ b/modules/client/back/methods/defaulter/filter.js @@ -74,7 +74,8 @@ module.exports = Self => { pm.name payMethod, r.finished IS NULL hasRecovery, dp.id departmentFk, - dp.name departmentName + dp.name departmentName, + dp.notificationEmail departmentEmail FROM defaulter d JOIN client c ON c.id = d.clientFk JOIN country cn ON cn.id = c.countryFk diff --git a/modules/client/back/methods/defaulter/observationEmail.js b/modules/client/back/methods/defaulter/observationEmail.js index c06d1d3d0..797e88f74 100644 --- a/modules/client/back/methods/defaulter/observationEmail.js +++ b/modules/client/back/methods/defaulter/observationEmail.js @@ -47,7 +47,7 @@ module.exports = Self => { await models.Mail.create({ subject: $t('Comment added to client', {clientFk: defaulter.clientFk}), body: body, - receiver: `${defaulter.salesPersonName}@verdnatura.es`, + receiver: `${defaulter.departmentEmail}`, replyTo: `${user.name}@verdnatura.es` }, myOptions); } From b88dc1c70fc956920b292f6d16a8e270d85667f6 Mon Sep 17 00:00:00 2001 From: carlossa Date: Sun, 20 Oct 2024 16:23:24 +0200 Subject: [PATCH 32/74] fix: refs #6850 remove notifyPickUp --- modules/claim/back/methods/claim/updateClaim.js | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/modules/claim/back/methods/claim/updateClaim.js b/modules/claim/back/methods/claim/updateClaim.js index 326192385..927e27622 100644 --- a/modules/claim/back/methods/claim/updateClaim.js +++ b/modules/claim/back/methods/claim/updateClaim.js @@ -119,18 +119,4 @@ module.exports = Self => { }); await models.Chat.sendCheckingPresence(ctx, workerId, message); } - - async function notifyPickUp(ctx, workerId, claim) { - const models = Self.app.models; - const url = await models.Url.getUrl(); - const $t = ctx.req.__; // $translate - - const message = $t('Claim will be picked', { - claimId: claim.id, - clientName: claim.client().name, - claimUrl: `${url}claim/${claim.id}/summary`, - claimPickup: $t(claim.pickup) - }); - await models.Chat.sendCheckingPresence(ctx, workerId, message); - } }; From 19fbb836a60f6dd6478f24cf04a54e2c801b4cf7 Mon Sep 17 00:00:00 2001 From: carlossa Date: Mon, 21 Oct 2024 08:30:39 +0200 Subject: [PATCH 33/74] fix: refs #6850 fix model --- modules/claim/back/methods/claim/updateClaim.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/modules/claim/back/methods/claim/updateClaim.js b/modules/claim/back/methods/claim/updateClaim.js index 927e27622..f2f3f9050 100644 --- a/modules/claim/back/methods/claim/updateClaim.js +++ b/modules/claim/back/methods/claim/updateClaim.js @@ -86,9 +86,6 @@ module.exports = Self => { const salesPerson = claim.client().salesPersonUser(); if (salesPerson) { - if (changedPickup && updatedClaim.pickup) - await notifyPickUp(ctx, salesPerson.id, claim); - if (args.claimStateFk) { const newState = await models.ClaimState.findById(args.claimStateFk, null, myOptions); await notifyStateChange(ctx, salesPerson.id, claim, newState.description); From bbc17d1ff886898b90cb2a75d33d8598665fcb27 Mon Sep 17 00:00:00 2001 From: guillermo Date: Mon, 21 Oct 2024 08:33:16 +0200 Subject: [PATCH 34/74] fix: refs #230926 item_getSimilar --- db/routines/vn/procedures/item_getSimilar.sql | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/db/routines/vn/procedures/item_getSimilar.sql b/db/routines/vn/procedures/item_getSimilar.sql index 537f53848..336f3521e 100644 --- a/db/routines/vn/procedures/item_getSimilar.sql +++ b/db/routines/vn/procedures/item_getSimilar.sql @@ -24,6 +24,7 @@ BEGIN CALL cache.available_refresh(vAvailableCalcFk, FALSE, vWarehouseFk, vDated); CALL cache.visible_refresh(vVisibleCalcFk, FALSE, vWarehouseFk); + CALL buy_getUltimate(NULL, vWarehouseFk, vDated); WITH itemTags AS ( SELECT i.id, @@ -74,14 +75,13 @@ BEGIN AND a.calc_id = vAvailableCalcFk LEFT JOIN cache.visible v ON v.item_id = i.id AND v.calc_id = vVisibleCalcFk - LEFT JOIN cache.last_buy lb ON lb.item_id = i.id - AND lb.warehouse_id = vWarehouseFk + LEFT JOIN tmp.buyUltimate bu ON bu.itemFk = i.id LEFT JOIN vn.itemProposal ip ON ip.mateFk = i.id AND ip.itemFk = vSelf LEFT JOIN vn.itemTag it ON it.itemFk = i.id AND it.priority = vPriority LEFT JOIN vn.tag t ON t.id = it.tagFk - LEFT JOIN vn.buy b ON b.id = lb.buy_id + LEFT JOIN vn.buy b ON b.id = bu.buyFk JOIN itemTags its WHERE a.available > 0 AND (i.typeFk = its.typeFk OR NOT vShowType) @@ -98,5 +98,7 @@ BEGIN (i.tag8 = its.tag8) DESC, match8 DESC LIMIT 100; + + DROP TEMPORARY TABLE tmp.buyUltimate; END$$ DELIMITER ; From eea09a9d4ae250a351d90e0fe65030da882c6cd2 Mon Sep 17 00:00:00 2001 From: carlossa Date: Mon, 21 Oct 2024 09:24:53 +0200 Subject: [PATCH 35/74] fix: refs #6850 add code --- modules/claim/back/methods/claim/updateClaim.js | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/modules/claim/back/methods/claim/updateClaim.js b/modules/claim/back/methods/claim/updateClaim.js index f2f3f9050..563b5b53d 100644 --- a/modules/claim/back/methods/claim/updateClaim.js +++ b/modules/claim/back/methods/claim/updateClaim.js @@ -85,13 +85,11 @@ module.exports = Self => { const updatedClaim = await claim.updateAttributes(args, myOptions); const salesPerson = claim.client().salesPersonUser(); - if (salesPerson) { - if (args.claimStateFk) { - const newState = await models.ClaimState.findById(args.claimStateFk, null, myOptions); - await notifyStateChange(ctx, salesPerson.id, claim, newState.description); - if (newState.code == 'canceled') - await notifyStateChange(ctx, claim.workerFk, claim, newState.description); - } + if (salesPerson && args.claimStateFk) { + const newState = await models.ClaimState.findById(args.claimStateFk, null, myOptions); + await notifyStateChange(ctx, salesPerson.id, claim, newState.description); + if (newState.code == 'canceled') + await notifyStateChange(ctx, claim.workerFk, claim, newState.description); } if (tx) await tx.commit(); From 288dc1c598b7cc4ff2457c9bfc9bc683ffce5086 Mon Sep 17 00:00:00 2001 From: jorgep Date: Mon, 21 Oct 2024 10:05:58 +0200 Subject: [PATCH 36/74] feat: refs #7524 myteam filter wip --- .../back/methods/ticket/getTicketsAdvance.js | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/modules/ticket/back/methods/ticket/getTicketsAdvance.js b/modules/ticket/back/methods/ticket/getTicketsAdvance.js index 1bd5f83de..4585c5d61 100644 --- a/modules/ticket/back/methods/ticket/getTicketsAdvance.js +++ b/modules/ticket/back/methods/ticket/getTicketsAdvance.js @@ -50,6 +50,11 @@ module.exports = Self => { type: 'boolean', description: 'True when lines and stock of origin are equal' }, + { + arg: 'myTeam', + type: 'boolean', + description: `Whether to show only tickets for the current logged user team (currently user tickets)` + }, { arg: 'filter', type: 'object', @@ -69,11 +74,27 @@ module.exports = Self => { Self.getTicketsAdvance = async(ctx, options) => { const args = ctx.args; const conn = Self.dataSource.connector; + const userId = ctx.req.accessToken.userId; const myOptions = {}; if (typeof options == 'object') Object.assign(myOptions, options); + const teamMembersId = []; + if (args.myTeam != null) { + const worker = await models.Worker.findById(userId, { + include: { + relation: 'collegues' + } + }, myOptions); + const collegues = worker.collegues() || []; + for (let collegue of collegues) + teamMembersId.push(collegue.collegueFk); + + if (teamMembersId.length == 0) + teamMembersId.push(userId); + } + const where = buildFilter(ctx.args, (param, value) => { switch (param) { case 'id': @@ -96,6 +117,11 @@ module.exports = Self => { }; case 'isFullMovable': return {'f.isFullMovable': value}; + case 'myTeam': + if (value) + return {'c.salesPersonFk': {inq: teamMembersId}}; + else + return {'c.salesPersonFk': {nin: teamMembersId}}; } }); From cb4e8355ba3f21d05c202ded792f3588d1f5bf65 Mon Sep 17 00:00:00 2001 From: jorgep Date: Mon, 21 Oct 2024 10:58:36 +0200 Subject: [PATCH 37/74] feat: refs #7524 myteam filter --- modules/ticket/back/methods/ticket/getTicketsAdvance.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/ticket/back/methods/ticket/getTicketsAdvance.js b/modules/ticket/back/methods/ticket/getTicketsAdvance.js index 4585c5d61..1088d357c 100644 --- a/modules/ticket/back/methods/ticket/getTicketsAdvance.js +++ b/modules/ticket/back/methods/ticket/getTicketsAdvance.js @@ -82,7 +82,7 @@ module.exports = Self => { const teamMembersId = []; if (args.myTeam != null) { - const worker = await models.Worker.findById(userId, { + const worker = await Self.app.models.Worker.findById(userId, { include: { relation: 'collegues' } @@ -119,9 +119,9 @@ module.exports = Self => { return {'f.isFullMovable': value}; case 'myTeam': if (value) - return {'c.salesPersonFk': {inq: teamMembersId}}; + return {'workerFk': {inq: teamMembersId}}; else - return {'c.salesPersonFk': {nin: teamMembersId}}; + return {'workerFk': {nin: teamMembersId}}; } }); From e38c061debb71120f5aefc19f1e91a43531c7765 Mon Sep 17 00:00:00 2001 From: pablone Date: Mon, 21 Oct 2024 11:36:44 +0200 Subject: [PATCH 38/74] fix: add date format on insert data --- .../bs/procedures/clientNewBorn_recalc.sql | 21 +++++++++---------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/db/routines/bs/procedures/clientNewBorn_recalc.sql b/db/routines/bs/procedures/clientNewBorn_recalc.sql index 1c89b5745..c56ffe49c 100644 --- a/db/routines/bs/procedures/clientNewBorn_recalc.sql +++ b/db/routines/bs/procedures/clientNewBorn_recalc.sql @@ -7,24 +7,23 @@ BLOCK1: BEGIN DECLARE vPreviousShipped DATE; DECLARE vDone boolean; DECLARE cur cursor for - - SELECT clientFk, firstShipped - FROM bs.clientNewBorn; DECLARE continue HANDLER FOR NOT FOUND SET vDone = TRUE; SET vDone := FALSE; DELETE FROM bs.clientNewBorn WHERE isModified = FALSE; - INSERT INTO clientNewBorn(clientFk, firstShipped, lastShipped) - SELECT c.id, MAX(t.shipped), MAX(t.shipped) - FROM vn.client c - JOIN vn.ticket t on t.clientFk = c.id - LEFT JOIN clientNewBorn cb on cb.clientFk = c.id - WHERE t.shipped BETWEEN TIMESTAMPADD(YEAR, -1, util.VN_CURDATE()) AND util.VN_CURDATE() AND cb.isModified is null - GROUP BY c.id; + INSERT INTO clientNewBorn(clientFk, firstShipped, lastShipped) + SELECT c.id, DATE(MAX(t.shipped)), DATE(MAX(t.shipped)) + FROM vn.client c + JOIN vn.ticket t ON t.clientFk = c.id + LEFT JOIN clientNewBorn cb ON cb.clientFk = c.id + WHERE t.shipped BETWEEN util.VN_CURDATE() - INTERVAL 1 YEAR + AND util.VN_CURDATE() + AND cb.isModified IS NULL + GROUP BY c.id; + OPEN cur; - LOOP1: LOOP SET vDone := FALSE; FETCH cur INTO vClientFk, vShipped; From e479873547e262c3a7054e4d234eaaba8c91c3d0 Mon Sep 17 00:00:00 2001 From: pablone Date: Mon, 21 Oct 2024 12:19:20 +0200 Subject: [PATCH 39/74] fix: restore cursor --- db/routines/bs/procedures/clientNewBorn_recalc.sql | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/db/routines/bs/procedures/clientNewBorn_recalc.sql b/db/routines/bs/procedures/clientNewBorn_recalc.sql index c56ffe49c..bb6b02aa7 100644 --- a/db/routines/bs/procedures/clientNewBorn_recalc.sql +++ b/db/routines/bs/procedures/clientNewBorn_recalc.sql @@ -6,7 +6,10 @@ BLOCK1: BEGIN DECLARE vShipped DATE; DECLARE vPreviousShipped DATE; DECLARE vDone boolean; - DECLARE cur cursor for + + DECLARE cur CURSOR FOR + SELECT clientFk, firstShipped + FROM bs.clientNewBorn; DECLARE continue HANDLER FOR NOT FOUND SET vDone = TRUE; SET vDone := FALSE; From 2b05e8c48e4c2dae7920fdbff21a178767d84f89 Mon Sep 17 00:00:00 2001 From: jgallego Date: Mon, 21 Oct 2024 13:29:33 +0200 Subject: [PATCH 40/74] feat: refs #7943 quitar lectura en metodos comunes --- db/routines/salix/triggers/ACL_beforeInsert.sql | 3 +++ db/versions/11314-redTulip/00-restrictedAsterisk.sql | 3 +++ 2 files changed, 6 insertions(+) create mode 100644 db/versions/11314-redTulip/00-restrictedAsterisk.sql diff --git a/db/routines/salix/triggers/ACL_beforeInsert.sql b/db/routines/salix/triggers/ACL_beforeInsert.sql index 94fb51ada..cb0b5761b 100644 --- a/db/routines/salix/triggers/ACL_beforeInsert.sql +++ b/db/routines/salix/triggers/ACL_beforeInsert.sql @@ -4,5 +4,8 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `salix`.`ACL_beforeInsert` FOR EACH ROW BEGIN SET NEW.editorFk = account.myUser_getId(); + IF NEW.`property` = '*' THEN + CALL util.throw('The property field cannot be *'); + END IF; END$$ DELIMITER ; diff --git a/db/versions/11314-redTulip/00-restrictedAsterisk.sql b/db/versions/11314-redTulip/00-restrictedAsterisk.sql new file mode 100644 index 000000000..20f1b4380 --- /dev/null +++ b/db/versions/11314-redTulip/00-restrictedAsterisk.sql @@ -0,0 +1,3 @@ +DELETE FROM `salix`.`ACL` +WHERE `model` = 'Worker' + AND `property` IN ('find', 'findById', 'findOne'); From 1efe258ea0b14c26a9035dc946d23ca394c182f6 Mon Sep 17 00:00:00 2001 From: jorgep Date: Mon, 21 Oct 2024 14:30:45 +0200 Subject: [PATCH 41/74] fix: refs #7524 filter by department --- .../vn/procedures/ticket_canAdvance.sql | 7 +++-- .../back/methods/ticket/getTicketsAdvance.js | 29 ++++--------------- 2 files changed, 10 insertions(+), 26 deletions(-) diff --git a/db/routines/vn/procedures/ticket_canAdvance.sql b/db/routines/vn/procedures/ticket_canAdvance.sql index 57c3f4235..e8fc70bba 100644 --- a/db/routines/vn/procedures/ticket_canAdvance.sql +++ b/db/routines/vn/procedures/ticket_canAdvance.sql @@ -51,7 +51,8 @@ BEGIN origin.companyFk futureCompanyFk, IFNULL(dest.nickname, origin.nickname) nickname, dest.landed, - dest.preparation + dest.preparation, + origin.departmentFk FROM ( SELECT s.ticketFk, c.salesPersonFk workerFk, @@ -71,9 +72,11 @@ BEGIN t.addressFk, t.warehouseFk, t.companyFk, - t.agencyModeFk + t.agencyModeFk, + wd.departmentFk FROM ticket t JOIN client c ON c.id = t.clientFk + JOIN workerDepartment wd ON wd.workerFk = c.salesPersonFk JOIN sale s ON s.ticketFk = t.id JOIN saleVolume sv ON sv.saleFk = s.id JOIN item i ON i.id = s.itemFk diff --git a/modules/ticket/back/methods/ticket/getTicketsAdvance.js b/modules/ticket/back/methods/ticket/getTicketsAdvance.js index 1088d357c..41f3ee79a 100644 --- a/modules/ticket/back/methods/ticket/getTicketsAdvance.js +++ b/modules/ticket/back/methods/ticket/getTicketsAdvance.js @@ -51,9 +51,9 @@ module.exports = Self => { description: 'True when lines and stock of origin are equal' }, { - arg: 'myTeam', - type: 'boolean', - description: `Whether to show only tickets for the current logged user team (currently user tickets)` + arg: 'departmentFk', + type: 'number', + description: 'Department identifier' }, { arg: 'filter', @@ -74,27 +74,11 @@ module.exports = Self => { Self.getTicketsAdvance = async(ctx, options) => { const args = ctx.args; const conn = Self.dataSource.connector; - const userId = ctx.req.accessToken.userId; const myOptions = {}; if (typeof options == 'object') Object.assign(myOptions, options); - const teamMembersId = []; - if (args.myTeam != null) { - const worker = await Self.app.models.Worker.findById(userId, { - include: { - relation: 'collegues' - } - }, myOptions); - const collegues = worker.collegues() || []; - for (let collegue of collegues) - teamMembersId.push(collegue.collegueFk); - - if (teamMembersId.length == 0) - teamMembersId.push(userId); - } - const where = buildFilter(ctx.args, (param, value) => { switch (param) { case 'id': @@ -117,11 +101,8 @@ module.exports = Self => { }; case 'isFullMovable': return {'f.isFullMovable': value}; - case 'myTeam': - if (value) - return {'workerFk': {inq: teamMembersId}}; - else - return {'workerFk': {nin: teamMembersId}}; + case 'departmentFk': + return {'f.departmentFk': value}; } }); From bf2d7541a5c956ba48a7f9a8c31553f36ce74418 Mon Sep 17 00:00:00 2001 From: guillermo Date: Mon, 21 Oct 2024 14:57:55 +0200 Subject: [PATCH 42/74] feat: refs #7266 Item label QR --- db/dump/.dump/data.sql | 2 +- loopback/locale/es.json | 4 +- .../item/{labelPdf.js => itemLabelQr.js} | 27 ++--- modules/item/back/models/item.js | 2 +- .../assets/css/import.js | 0 .../item-label-qr/assets/css/style.css | 87 ++++++++++++++ .../reports/item-label-qr/item-label-qr.html | 112 ++++++++++++++++++ .../reports/item-label-qr/item-label-qr.js | 43 +++++++ .../reports/item-label-qr/locale/es.yml | 1 + .../options.json | 2 +- .../reports/item-label-qr/sql/item.sql | 42 +++++++ .../reports/item-label/assets/css/style.css | 37 ------ .../reports/item-label/item-label.html | 37 ------ .../reports/item-label/item-label.js | 58 --------- .../reports/item-label/locale/es.yml | 1 - .../templates/reports/item-label/sql/item.sql | 14 --- .../reports/item-label/sql/itemTags.sql | 4 - 17 files changed, 298 insertions(+), 175 deletions(-) rename modules/item/back/methods/item/{labelPdf.js => itemLabelQr.js} (62%) rename print/templates/reports/{item-label => item-label-qr}/assets/css/import.js (100%) create mode 100644 print/templates/reports/item-label-qr/assets/css/style.css create mode 100644 print/templates/reports/item-label-qr/item-label-qr.html create mode 100755 print/templates/reports/item-label-qr/item-label-qr.js create mode 100644 print/templates/reports/item-label-qr/locale/es.yml rename print/templates/reports/{item-label => item-label-qr}/options.json (86%) create mode 100644 print/templates/reports/item-label-qr/sql/item.sql delete mode 100644 print/templates/reports/item-label/assets/css/style.css delete mode 100644 print/templates/reports/item-label/item-label.html delete mode 100755 print/templates/reports/item-label/item-label.js delete mode 100644 print/templates/reports/item-label/locale/es.yml delete mode 100644 print/templates/reports/item-label/sql/item.sql delete mode 100644 print/templates/reports/item-label/sql/itemTags.sql diff --git a/db/dump/.dump/data.sql b/db/dump/.dump/data.sql index ca254055b..315bfe7c5 100644 --- a/db/dump/.dump/data.sql +++ b/db/dump/.dump/data.sql @@ -1723,7 +1723,7 @@ INSERT INTO `ACL` VALUES (378,'OsTicket','osTicketReportEmail','WRITE','ALLOW',' INSERT INTO `ACL` VALUES (379,'Item','buyerWasteEmail','WRITE','ALLOW','ROLE','system',NULL); INSERT INTO `ACL` VALUES (380,'Claim','claimPickupPdf','READ','ALLOW','ROLE','employee',NULL); INSERT INTO `ACL` VALUES (381,'Claim','claimPickupEmail','WRITE','ALLOW','ROLE','claimManager',NULL); -INSERT INTO `ACL` VALUES (382,'Item','labelPdf','READ','ALLOW','ROLE','employee',NULL); +INSERT INTO `ACL` VALUES (382,'Item','itemLabelQr','READ','ALLOW','ROLE','employee',NULL); INSERT INTO `ACL` VALUES (383,'Sector','*','READ','ALLOW','ROLE','employee',NULL); INSERT INTO `ACL` VALUES (384,'Sector','*','WRITE','ALLOW','ROLE','employee',NULL); INSERT INTO `ACL` VALUES (385,'Route','driverRoutePdf','READ','ALLOW','ROLE','employee',NULL); diff --git a/loopback/locale/es.json b/loopback/locale/es.json index 6d50f634e..8e758d1ab 100644 --- a/loopback/locale/es.json +++ b/loopback/locale/es.json @@ -383,5 +383,5 @@ "No valid travel thermograph found": "No se encontró un termógrafo válido", "The quantity claimed cannot be greater than the quantity of the line": "La cantidad reclamada no puede ser mayor que la cantidad de la línea", "type cannot be blank": "Se debe rellenar el tipo", - "There are tickets for this area, delete them first": "Hay tickets para esta sección, borralos primero" -} + "There are tickets for this area, delete them first": "Hay tickets para esta sección, borralos primero" +} \ No newline at end of file diff --git a/modules/item/back/methods/item/labelPdf.js b/modules/item/back/methods/item/itemLabelQr.js similarity index 62% rename from modules/item/back/methods/item/labelPdf.js rename to modules/item/back/methods/item/itemLabelQr.js index d7a50397e..8d92d51e8 100644 --- a/modules/item/back/methods/item/labelPdf.js +++ b/modules/item/back/methods/item/itemLabelQr.js @@ -1,5 +1,5 @@ module.exports = Self => { - Self.remoteMethodCtx('labelPdf', { + Self.remoteMethodCtx('itemLabelQr', { description: 'Returns the item label pdf', accessType: 'READ', accepts: [ @@ -11,26 +11,15 @@ module.exports = Self => { http: {source: 'path'} }, { - arg: 'recipientId', + arg: 'copies', type: 'number', - description: 'The recipient id', required: false - }, - { - arg: 'warehouseId', + }, { + arg: 'userId', type: 'number', - description: 'The warehouse id', + description: 'The user id from accessToken', + http: ctx => ctx.req.accessToken.userId, required: true - }, - { - arg: 'labelNumber', - type: 'number', - required: false - }, - { - arg: 'totalLabels', - type: 'number', - required: false } ], returns: [ @@ -49,11 +38,11 @@ module.exports = Self => { } ], http: { - path: '/:id/label-pdf', + path: '/:id/item-label-qr', verb: 'GET' }, accessScopes: ['DEFAULT', 'read:multimedia'] }); - Self.labelPdf = (ctx, id) => Self.printReport(ctx, id, 'item-label'); + Self.itemLabelQr = (ctx, id) => Self.printReport(ctx, id, 'item-label-qr'); }; diff --git a/modules/item/back/models/item.js b/modules/item/back/models/item.js index e715ab431..4fb9af8fa 100644 --- a/modules/item/back/models/item.js +++ b/modules/item/back/models/item.js @@ -15,7 +15,7 @@ module.exports = Self => { require('../methods/item/getWasteByItem')(Self); require('../methods/item/createIntrastat')(Self); require('../methods/item/buyerWasteEmail')(Self); - require('../methods/item/labelPdf')(Self); + require('../methods/item/itemLabelQr')(Self); require('../methods/item/setVisibleDiscard')(Self); require('../methods/item/get')(Self); diff --git a/print/templates/reports/item-label/assets/css/import.js b/print/templates/reports/item-label-qr/assets/css/import.js similarity index 100% rename from print/templates/reports/item-label/assets/css/import.js rename to print/templates/reports/item-label-qr/assets/css/import.js diff --git a/print/templates/reports/item-label-qr/assets/css/style.css b/print/templates/reports/item-label-qr/assets/css/style.css new file mode 100644 index 000000000..b868f3966 --- /dev/null +++ b/print/templates/reports/item-label-qr/assets/css/style.css @@ -0,0 +1,87 @@ +html { + font-family: "Roboto", "Helvetica", "Arial", sans-serif; + margin-top: -7px; +} +.leftTable { + width: 47%; + font-size: 12px; + float: left; + text-align: center; +} +.leftTable img { + width: 110px; +} +.rightTable { + width: 53%; + font-size: 14px; + float: right; +} +.rightTable td { + border: 3px solid white; +} +.center { + text-align: center; +} +.cursive { + font-style: italic; +} +.bold { + font-weight: bold; +} +.black-bg { + background-color: black; + color: white; +} +.md-txt { + font-size: 20px; +} +.xl-txt { + font-size: 36px; +} +.cell { + border: 2px solid black; + box-sizing: content-box; + width: 100%; + height: 30px; + display: flex; + justify-content: center; + align-items: center; +} +.padding { + padding: 7px; +} +.md-height { + height: 60px; + max-height: 60px; +} +.xs-width { + width: 60px; + max-width: 60px; +} +.sm-width { + width: 140px; + max-width: 140px; +} +.md-width { + width: 200px; + max-width: 200px; +} +.lg-width { + width: 270px; + max-width: 270px; +} +.overflow-multiline { + max-height: inherit; + display: -webkit-box; + overflow: hidden; + word-wrap: break-word; + line-clamp: 2; + -webkit-line-clamp: 2; + -webkit-box-orient: vertical; +} +.overflow-line { + width: inherit; + max-width: inherit; + overflow: hidden; + white-space: nowrap; +} \ No newline at end of file diff --git a/print/templates/reports/item-label-qr/item-label-qr.html b/print/templates/reports/item-label-qr/item-label-qr.html new file mode 100644 index 000000000..3b61e1542 --- /dev/null +++ b/print/templates/reports/item-label-qr/item-label-qr.html @@ -0,0 +1,112 @@ + + + + + + + + + + + + + + + +
+ + + +
+ {{item.buyFk}} +
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ {{item.itemFk}} +
+
+
+ {{item.item}} +
+
+
+ {{item.size}} +
+
+
+ Color: {{item.inkFk}} +
+
+
+ {{item.packing}} +
+
+
+ {{item.stems}} +
+
+
+ Origen: {{item.origin}} +
+
+
+ Productor: {{item.producer}} +
+
+
+ Comprador: {{item.buyerName}} +
+
+
+ F: {{date}} +
+
+
+ {{`${item.labelNum} / ${totalPages}`}} +
+
+
+ Entrada: {{item.entryFk}} +
+
+
+ {{item.comment}} +
+
+ + \ No newline at end of file diff --git a/print/templates/reports/item-label-qr/item-label-qr.js b/print/templates/reports/item-label-qr/item-label-qr.js new file mode 100755 index 000000000..99744b0bd --- /dev/null +++ b/print/templates/reports/item-label-qr/item-label-qr.js @@ -0,0 +1,43 @@ +const UserError = require('vn-loopback/util/user-error'); +const moment = require('moment'); +const qrcode = require('qrcode'); + +module.exports = { + name: 'item-label-qr', + async serverPrefetch() { + this.items = await this.rawSqlFromDef('item', [this.copies || 1, this.id]); + if (!this.items.length) throw new UserError(`Empty data source`); + this.qr = await this.getQr(this.items[0].buyFk); + this.vnDate = Date.vnNew(); + this.date = moment(this.vnDate).format('YY/DD'); + this.totalPages = this.items.length; + }, + methods: { + getQr(data) { + data = { + company: 'vnl', + user: this.userId, + created: this.vnDate, + table: 'buy', + id: data + }; + return qrcode.toDataURL(JSON.stringify(data), { + margin: 0, + errorCorrectionLevel: 'H' + }); + } + }, + props: { + id: { + type: Number, + required: true, + description: 'The item id' + }, + copies: { + type: Number + }, + userId: { + type: Number + } + } +}; diff --git a/print/templates/reports/item-label-qr/locale/es.yml b/print/templates/reports/item-label-qr/locale/es.yml new file mode 100644 index 000000000..81dbc1877 --- /dev/null +++ b/print/templates/reports/item-label-qr/locale/es.yml @@ -0,0 +1 @@ +reportName: Etiqueta de artículo QR \ No newline at end of file diff --git a/print/templates/reports/item-label/options.json b/print/templates/reports/item-label-qr/options.json similarity index 86% rename from print/templates/reports/item-label/options.json rename to print/templates/reports/item-label-qr/options.json index 98c5788b1..5a3c3b1eb 100644 --- a/print/templates/reports/item-label/options.json +++ b/print/templates/reports/item-label-qr/options.json @@ -2,7 +2,7 @@ "width": "10.4cm", "height": "4.8cm", "margin": { - "top": "0cm", + "top": "0.17cm", "right": "0cm", "bottom": "0cm", "left": "0cm" diff --git a/print/templates/reports/item-label-qr/sql/item.sql b/print/templates/reports/item-label-qr/sql/item.sql new file mode 100644 index 000000000..11ee60d1a --- /dev/null +++ b/print/templates/reports/item-label-qr/sql/item.sql @@ -0,0 +1,42 @@ +WITH RECURSIVE numbers AS ( + SELECT 1 n + UNION ALL + SELECT n + 1 + FROM numbers + WHERE n < ? +) +SELECT ROW_NUMBER() OVER() labelNum, + b.id buyFk, + b.itemFk, + b.quantity, + b.packing, + b.isPickedOff, + b.entryFk, + e.sub, + o.code origin, + COALESCE(p.`name`, p.id, '') producer, + i.name item, + i.`size`, + i.category, + i.stems, + i.inkFk, + IFNULL(CONCAT(ig.longName, ' ', ig.`size`, ' ', ig.subName), i.comment) comment, + i.typeFk, + i.isLaid, + w.code buyerName, + w.code, + s.company_name companyName, + t.shipped + FROM vn.buy b + JOIN vn.item i ON i.id = b.itemFk + LEFT JOIN vn.item ig ON ig.id = b.itemOriginalFk + LEFT JOIN edi.ekt e ON e.id = b.ektFk + JOIN vn.origin o ON o.id = i.originFk + LEFT JOIN vn.producer p ON p.id = i.producerFk + JOIN vn.itemType it ON it.id = i.typeFk + JOIN vn.worker w ON w.id = it.workerFk + LEFT JOIN edi.supplier s ON s.supplier_id = e.pro + JOIN vn.entry e2 ON e2.id = b.entryFk + JOIN vn.travel t ON t.id = e2.travelFk + JOIN numbers num + WHERE b.id = ? \ No newline at end of file diff --git a/print/templates/reports/item-label/assets/css/style.css b/print/templates/reports/item-label/assets/css/style.css deleted file mode 100644 index 0dea5a9e4..000000000 --- a/print/templates/reports/item-label/assets/css/style.css +++ /dev/null @@ -1,37 +0,0 @@ -html { - font-family: "Roboto", "Helvetica", "Arial", sans-serif; - font-size: 12px; -} -table { - width: 50%; - font-size: 12px; - float: right; -} -td { - border: 3px solid white; -} -.center { - text-align: center; -} -.cursive { - font-style: italic; -} -.bold { - font-weight: bold; -} -.black { - background-color: black; - color: white; -} -.md { - font-size: 18px; -} -.xl { - font-size: 36px; -} -.border-black { - border: 2px solid #000000; -} -.regular-with { - width: 60px; -} \ No newline at end of file diff --git a/print/templates/reports/item-label/item-label.html b/print/templates/reports/item-label/item-label.html deleted file mode 100644 index e2526fc6b..000000000 --- a/print/templates/reports/item-label/item-label.html +++ /dev/null @@ -1,37 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1
EUC Cinerea60
Color: LIV150
Origen: VCL
Productor: L'Arenal
Comprador: ATJF:42/11 / 50
Entrada: 358799
E622/2
- - \ No newline at end of file diff --git a/print/templates/reports/item-label/item-label.js b/print/templates/reports/item-label/item-label.js deleted file mode 100755 index c5b9cdfd7..000000000 --- a/print/templates/reports/item-label/item-label.js +++ /dev/null @@ -1,58 +0,0 @@ -const vnReport = require('../../../core/mixins/vn-report.js'); -const qrcode = require('qrcode'); - -module.exports = { - name: 'item-label', - mixins: [vnReport], - async serverPrefetch() { - this.item = await this.findOneFromDef('item', [this.id, this.warehouseId]); - this.checkMainEntity(this.item); - this.tags = await this.fetchItemTags(this.id); - this.barcode = await this.getBarcodeBase64(this.id); - }, - - computed: { - labelPage() { - const labelNumber = this.labelNumber ? this.labelNumber : 1; - const totalLabels = this.totalLabels ? this.totalLabels : 1; - - return `${labelNumber}/${totalLabels}`; - } - }, - methods: { - fetchItemTags(id) { - return this.rawSqlFromDef('itemTags', [id]).then(rows => { - const tags = {}; - rows.forEach(row => tags[row.code] = row.value); - - return tags; - }); - }, - getBarcodeBase64(id) { - const data = String(id); - - return qrcode.toDataURL(data, {margin: 0}); - }, - packing() { - const stems = this.item.stems ? this.item.stems : 1; - return `${this.item.packing}x${stems}`; - } - }, - props: { - id: { - type: Number, - required: true, - description: 'The item id' - }, - warehouseId: { - type: Number, - required: true - }, - labelNumber: { - type: Number - }, - totalLabels: { - type: Number - } - } -}; diff --git a/print/templates/reports/item-label/locale/es.yml b/print/templates/reports/item-label/locale/es.yml deleted file mode 100644 index 278946f3e..000000000 --- a/print/templates/reports/item-label/locale/es.yml +++ /dev/null @@ -1 +0,0 @@ -reportName: Etiqueta \ No newline at end of file diff --git a/print/templates/reports/item-label/sql/item.sql b/print/templates/reports/item-label/sql/item.sql deleted file mode 100644 index 46aacc2fa..000000000 --- a/print/templates/reports/item-label/sql/item.sql +++ /dev/null @@ -1,14 +0,0 @@ -SELECT - i.id, - i.name, - i.stems, - i.size, - b.packing, - p.name as 'producer' -FROM vn.item i - JOIN cache.last_buy clb ON clb.item_id = i.id - JOIN vn.buy b ON b.id = clb.buy_id - JOIN vn.entry e ON e.id = b.entryFk - JOIN vn.producer p ON p.id = i.producerFk - -WHERE i.id = ? AND clb.warehouse_id = ? \ No newline at end of file diff --git a/print/templates/reports/item-label/sql/itemTags.sql b/print/templates/reports/item-label/sql/itemTags.sql deleted file mode 100644 index 3c20098a6..000000000 --- a/print/templates/reports/item-label/sql/itemTags.sql +++ /dev/null @@ -1,4 +0,0 @@ -SELECT t.code, t.name, it.value -FROM vn.itemTag it - JOIN vn.tag t ON t.id = it.tagFk -WHERE it.itemFk = ? \ No newline at end of file From 5162c2037b650d4c1b7dfef0d546286cbf5488e4 Mon Sep 17 00:00:00 2001 From: guillermo Date: Tue, 22 Oct 2024 08:41:46 +0200 Subject: [PATCH 43/74] feat: refs #8119 Requested changes --- db/routines/vn/procedures/itemCampaignQuantity_add.sql | 5 ++++- db/versions/11308-redCymbidium/00-firstScript.sql | 1 + 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/db/routines/vn/procedures/itemCampaignQuantity_add.sql b/db/routines/vn/procedures/itemCampaignQuantity_add.sql index ca041d2d2..6edb97c08 100644 --- a/db/routines/vn/procedures/itemCampaignQuantity_add.sql +++ b/db/routines/vn/procedures/itemCampaignQuantity_add.sql @@ -65,12 +65,15 @@ proc: BEGIN SET vDateSumFrom = vDateSumTo - INTERVAL vScopeDays DAY; - REPLACE itemCampaignQuantity(dated, itemFk, quantity, campaign) + REPLACE itemCampaignQuantity(dated, itemFk, quantity, total, campaign) SELECT DATE(s.created), s.itemFk, SUM(CASE WHEN t.shipped BETWEEN vDateSumFrom AND vDateSumTo THEN s.quantity END) quantity, + SUM(CASE WHEN t.shipped BETWEEN vDateSumFrom AND vDateSumTo + THEN s.total + END) total, vCampaign FROM sale s JOIN ticket t ON t.id = s.ticketFk diff --git a/db/versions/11308-redCymbidium/00-firstScript.sql b/db/versions/11308-redCymbidium/00-firstScript.sql index d90cd1ae6..14fad3636 100644 --- a/db/versions/11308-redCymbidium/00-firstScript.sql +++ b/db/versions/11308-redCymbidium/00-firstScript.sql @@ -3,6 +3,7 @@ CREATE TABLE IF NOT EXISTS `vn`.`itemCampaignQuantity` ( dated date NOT NULL, itemFk int(11) NOT NULL, quantity decimal(10,2) NOT NULL, + total decimal(10,2) NOT NULL, campaign varchar(100) NOT NULL, UNIQUE KEY `itemCampaignQuantity_UNIQUE` (`dated`,`itemFk`), CONSTRAINT itemCampaignQuantity_item_FK FOREIGN KEY (itemFk) REFERENCES vn.item(id) ON DELETE RESTRICT ON UPDATE CASCADE From 6ef77604985c3ea38d9e3de0843b57ce28b5cb7e Mon Sep 17 00:00:00 2001 From: sergiodt Date: Tue, 22 Oct 2024 10:06:59 +0200 Subject: [PATCH 44/74] fix: refs #6861 fixTransactionCommit --- .../collection_addWithReservation.sql | 18 +++---- .../procedures/itemShelvingSale_addBySale.sql | 49 ++++++++++--------- 2 files changed, 34 insertions(+), 33 deletions(-) diff --git a/db/routines/vn/procedures/collection_addWithReservation.sql b/db/routines/vn/procedures/collection_addWithReservation.sql index cc0b7fd9b..bb6e94a63 100644 --- a/db/routines/vn/procedures/collection_addWithReservation.sql +++ b/db/routines/vn/procedures/collection_addWithReservation.sql @@ -37,23 +37,23 @@ BEGIN WHERE t.id = vTicketFk; CALL cache.available_refresh( - vCacheAvailableFk, + vCacheAvailableFk, FALSE, - vWarehouseFk, + vWarehouseFk, util.VN_CURDATE()); SELECT available INTO vAvailable FROM cache.available - WHERE calc_id = vCacheAvailableFk + WHERE calc_id = vCacheAvailableFk AND item_id = vItemFk; - + IF vAvailable < vQuantity THEN SET vHasThrow = TRUE; ELSE SELECT `name`, - CONCAT(getUser(), ' ', DATE_FORMAT(util.VN_NOW(), '%H:%i'), ' ', name) + CONCAT(getUser(), ' ', DATE_FORMAT(util.VN_NOW(), '%H:%i'), ' ', name) INTO vItemName, vConcept - FROM item + FROM item WHERE id = vItemFk; START TRANSACTION; @@ -69,7 +69,7 @@ BEGIN CALL sale_calculateComponent(vSaleFk, NULL); CALL itemShelvingSale_addBySale(vSaleFk, vSectorFk); - + IF NOT EXISTS (SELECT TRUE FROM itemShelvingSale WHERE saleFk = vSaleFk LIMIT 1) THEN SET vHasThrow = TRUE; END IF; @@ -78,13 +78,13 @@ BEGIN IF vHasThrow THEN CALL util.throw("There is no available for the selected item"); END IF; - + IF vSaleGroupFk THEN INSERT INTO saleGroupDetail SET saleFk = vSaleFk, saleGroupFk = vSaleGroupFk; END IF; - + COMMIT; END$$ DELIMITER ; diff --git a/db/routines/vn/procedures/itemShelvingSale_addBySale.sql b/db/routines/vn/procedures/itemShelvingSale_addBySale.sql index 6625e89b8..06736732a 100644 --- a/db/routines/vn/procedures/itemShelvingSale_addBySale.sql +++ b/db/routines/vn/procedures/itemShelvingSale_addBySale.sql @@ -18,8 +18,9 @@ proc: BEGIN DECLARE vReservedQuantity INT; DECLARE vOutStanding INT; DECLARE vUserFk INT; - DECLARE vTotalReservedQuantity INT; + DECLARE vTotalReservedQuantity INT; DECLARE vSaleQuantity INT; + DECLARE vIsRequiredTx BOOL DEFAULT NOT @@in_transaction; DECLARE vItemShelvingAvailable CURSOR FOR SELECT ish.id itemShelvingFk, @@ -29,7 +30,7 @@ proc: BEGIN JOIN shelving sh ON sh.code = ish.shelvingFk JOIN parking p ON p.id = sh.parkingFk JOIN sector sc ON sc.id = p.sectorFk - JOIN productionConfig pc + JOIN productionConfig pc WHERE s.id = vSaleFk AND NOT sc.isHideForPickers AND (sc.id = vSectorFk OR vSectorFk IS NULL) @@ -44,15 +45,15 @@ proc: BEGIN DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN - ROLLBACK; + CALL util.tx_rollback(vIsRequiredTx); RESIGNAL; END; - - START TRANSACTION; - + + CALL util.tx_start(vIsRequiredTx); + SELECT id INTO vSaleFk FROM sale - WHERE id = vSaleFk + WHERE id = vSaleFk FOR UPDATE; SELECT MAX(p.pickingOrder), s.quantity - SUM(IFNULL(iss.quantity, 0)), s.quantity @@ -65,7 +66,7 @@ proc: BEGIN WHERE s.id = vSaleFk; IF vOutStanding <= 0 THEN - COMMIT; + CALL util.tx_commit(vIsRequiredTx); LEAVE proc; END IF; @@ -85,7 +86,7 @@ proc: BEGIN IF vTotalReservedQuantity <> vSaleQuantity THEN CALL util.debugAdd('itemShelvingSale_addBySale', CONCAT(vSaleFk, ' - ', vSaleQuantity,' - ', vTotalReservedQuantity,'-', vOutStanding,'-', account.myUser_getId())); - + UPDATE sale SET quantity = vTotalReservedQuantity WHERE id = vSaleFk; @@ -93,7 +94,7 @@ proc: BEGIN LEAVE l; END IF; - SELECT id INTO vItemShelvingFk + SELECT id INTO vItemShelvingFk FROM itemShelving WHERE id = vItemShelvingFk FOR UPDATE; @@ -102,19 +103,19 @@ proc: BEGIN SET vOutStanding = vOutStanding - vReservedQuantity; IF vReservedQuantity > 0 THEN - CALL util.debugAdd('itemShelvingSale_addBySale_reservedQuantity', - CONCAT(vSaleFk, ' - ', vReservedQuantity, ' - ', vOutStanding, account.myUser_getId())); - INSERT INTO itemShelvingSale( - itemShelvingFk, - saleFk, - quantity, - userFk, - isPicked) - SELECT vItemShelvingFk, - vSaleFk, - vReservedQuantity, - vUserFk, - FALSE; + CALL util.debugAdd('itemShelvingSale_addBySale_reservedQuantity', + CONCAT(vSaleFk, ' - ', vReservedQuantity, ' - ', vOutStanding, account.myUser_getId())); + INSERT INTO itemShelvingSale( + itemShelvingFk, + saleFk, + quantity, + userFk, + isPicked) + SELECT vItemShelvingFk, + vSaleFk, + vReservedQuantity, + vUserFk, + FALSE; UPDATE itemShelving SET available = available - vReservedQuantity @@ -123,6 +124,6 @@ proc: BEGIN END IF; END LOOP; CLOSE vItemShelvingAvailable; - COMMIT; + CALL util.tx_commit(vIsRequiredTx); END$$ DELIMITER ; \ No newline at end of file From 0af58b20bea4025736feb55ac286ec441237691a Mon Sep 17 00:00:00 2001 From: guillermo Date: Tue, 22 Oct 2024 12:02:04 +0200 Subject: [PATCH 45/74] feat: refs #7266 Item label QR finished --- db/routines/vn/functions/buy_getUltimate.sql | 31 +++++++++++++++++++ loopback/locale/es.json | 3 +- modules/item/back/methods/item/itemLabelQr.js | 11 +++++-- .../reports/item-label-qr/item-label-qr.html | 4 +-- .../reports/item-label-qr/item-label-qr.js | 28 ++++++++++++----- .../reports/item-label-qr/sql/company.sql | 6 ++++ .../reports/item-label-qr/sql/lastBuy.sql | 1 + 7 files changed, 72 insertions(+), 12 deletions(-) create mode 100644 db/routines/vn/functions/buy_getUltimate.sql create mode 100644 print/templates/reports/item-label-qr/sql/company.sql create mode 100644 print/templates/reports/item-label-qr/sql/lastBuy.sql diff --git a/db/routines/vn/functions/buy_getUltimate.sql b/db/routines/vn/functions/buy_getUltimate.sql new file mode 100644 index 000000000..173e6e01f --- /dev/null +++ b/db/routines/vn/functions/buy_getUltimate.sql @@ -0,0 +1,31 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`vn`@`localhost` FUNCTION `vn`.`buy_getUltimate`( + vItemFk INT, + vWarehouseFk SMALLINT, + vDated DATE +) + RETURNS int(11) + DETERMINISTIC +BEGIN +/** + * Calcula las últimas compras realizadas hasta una fecha. + * + * @param vItemFk Id del artículo + * @param vWarehouseFk Id del almacén + * @param vDated Compras hasta fecha + * @return Id de compra + */ + DECLARE vBuyFk INT; + + CALL buy_getUltimate(vItemFk, vWarehouseFk, vDated); + + SELECT buyFk INTO vBuyFk + FROM tmp.buyUltimate; + + DROP TEMPORARY TABLE IF EXISTS + tmp.buyUltimate, + tmp.buyUltimateFromInterval; + + RETURN vBuyFk; +END$$ +DELIMITER ; diff --git a/loopback/locale/es.json b/loopback/locale/es.json index 8e758d1ab..8f0869eb5 100644 --- a/loopback/locale/es.json +++ b/loopback/locale/es.json @@ -383,5 +383,6 @@ "No valid travel thermograph found": "No se encontró un termógrafo válido", "The quantity claimed cannot be greater than the quantity of the line": "La cantidad reclamada no puede ser mayor que la cantidad de la línea", "type cannot be blank": "Se debe rellenar el tipo", - "There are tickets for this area, delete them first": "Hay tickets para esta sección, borralos primero" + "There are tickets for this area, delete them first": "Hay tickets para esta sección, borralos primero", + "There is no company associated with that warehouse": "No hay ninguna empresa asociada a ese almacén" } \ No newline at end of file diff --git a/modules/item/back/methods/item/itemLabelQr.js b/modules/item/back/methods/item/itemLabelQr.js index 8d92d51e8..88d8ce950 100644 --- a/modules/item/back/methods/item/itemLabelQr.js +++ b/modules/item/back/methods/item/itemLabelQr.js @@ -9,8 +9,15 @@ module.exports = Self => { required: true, description: 'The item id', http: {source: 'path'} - }, - { + }, { + arg: 'warehouseId', + type: 'number', + required: true + }, { + arg: 'packing', + type: 'number', + required: false + }, { arg: 'copies', type: 'number', required: false diff --git a/print/templates/reports/item-label-qr/item-label-qr.html b/print/templates/reports/item-label-qr/item-label-qr.html index 3b61e1542..2ece8943e 100644 --- a/print/templates/reports/item-label-qr/item-label-qr.html +++ b/print/templates/reports/item-label-qr/item-label-qr.html @@ -52,7 +52,7 @@
- {{item.packing}} + {{packing || item.packing}}
@@ -89,7 +89,7 @@
- {{`${item.labelNum} / ${totalPages}`}} + {{`${item.labelNum}/${item.quantity / (packing || item.packing)}`}}
diff --git a/print/templates/reports/item-label-qr/item-label-qr.js b/print/templates/reports/item-label-qr/item-label-qr.js index 99744b0bd..1a0ef767b 100755 --- a/print/templates/reports/item-label-qr/item-label-qr.js +++ b/print/templates/reports/item-label-qr/item-label-qr.js @@ -5,25 +5,33 @@ const qrcode = require('qrcode'); module.exports = { name: 'item-label-qr', async serverPrefetch() { - this.items = await this.rawSqlFromDef('item', [this.copies || 1, this.id]); + this.company = await this.findOneFromDef('company', [this.warehouseId]); + if (!this.company) + throw new UserError(`There is no company associated with that warehouse`); + + this.date = Date.vnNew(); + this.lastBuy = await this.findOneFromDef('lastBuy', [ + this.id, + this.warehouseId, + this.date + ]); + this.items = await this.rawSqlFromDef('item', [this.copies || 1, this.lastBuy.id]); if (!this.items.length) throw new UserError(`Empty data source`); this.qr = await this.getQr(this.items[0].buyFk); - this.vnDate = Date.vnNew(); - this.date = moment(this.vnDate).format('YY/DD'); - this.totalPages = this.items.length; + this.date = moment(this.date).format('WW/E'); }, methods: { getQr(data) { data = { - company: 'vnl', + company: this.company, user: this.userId, - created: this.vnDate, + created: this.date, table: 'buy', id: data }; return qrcode.toDataURL(JSON.stringify(data), { margin: 0, - errorCorrectionLevel: 'H' + errorCorrectionLevel: 'L' }); } }, @@ -33,6 +41,12 @@ module.exports = { required: true, description: 'The item id' }, + warehouseId: { + type: Number + }, + packing: { + type: Number + }, copies: { type: Number }, diff --git a/print/templates/reports/item-label-qr/sql/company.sql b/print/templates/reports/item-label-qr/sql/company.sql new file mode 100644 index 000000000..e130b4033 --- /dev/null +++ b/print/templates/reports/item-label-qr/sql/company.sql @@ -0,0 +1,6 @@ +SELECT co.code + FROM warehouse w + JOIN address a ON a.id = w.addressFk + JOIN client c ON c.id = a.clientFk + JOIN company co ON co.clientFk = c.id + WHERE w.id = ? \ No newline at end of file diff --git a/print/templates/reports/item-label-qr/sql/lastBuy.sql b/print/templates/reports/item-label-qr/sql/lastBuy.sql new file mode 100644 index 000000000..d10339998 --- /dev/null +++ b/print/templates/reports/item-label-qr/sql/lastBuy.sql @@ -0,0 +1 @@ +SELECT buy_getUltimate(?, ?, ?) id \ No newline at end of file From ee0c0996f6e00507519e35368f279bee4b6b8e95 Mon Sep 17 00:00:00 2001 From: jorgep Date: Tue, 22 Oct 2024 12:16:26 +0200 Subject: [PATCH 46/74] feat: refs #7524 add e2e --- db/dump/fixtures.before.sql | 2 +- .../ticket/specs/getTicketsAdvance.spec.js | 38 +++++++++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/db/dump/fixtures.before.sql b/db/dump/fixtures.before.sql index 5076f9330..a667b6d27 100644 --- a/db/dump/fixtures.before.sql +++ b/db/dump/fixtures.before.sql @@ -403,7 +403,7 @@ INSERT INTO `vn`.`client`(`id`,`name`,`fi`,`socialName`,`contact`,`street`,`city (1112, 'Trash', NULL, 'GARBAGE MAN', 'Unknown name', 'NEW YORK CITY, UNDERGROUND', 'Gotham', 46460, 1111111111, 222222222, 1, NULL, NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1, NULL, 10, 5, util.VN_CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 0, 1, 0, NULL, 1, 0, NULL, 0, 'others','loses'); INSERT INTO `vn`.`client`(`id`, `name`, `fi`, `socialName`, `contact`, `street`, `city`, `postcode`, `isRelevant`, `email`, `iban`,`dueDay`,`accountingAccount`, `isEqualizated`, `provinceFk`, `hasToInvoice`, `credit`, `countryFk`, `isActive`, `gestdocFk`, `quality`, `payMethodFk`,`created`, `isTaxDataChecked`) - SELECT id, name, CONCAT(RPAD(CONCAT(id,9),8,id),'A'), UPPER(CONCAT(name, 'Social')), CONCAT(name, 'Contact'), CONCAT(name, 'Street'), 'GOTHAM', 46460, 1, CONCAT(name,'@mydomain.com'), NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1,NULL, 10, 5, util.VN_CURDATE(), 1 + SELECT id, name, CONCAT(RPAD(CONCAT(id,9),8,id),'A'), UPPER(CONCAT(name, 'Social')), CONCAT(name, 'Contact'), UPPER(CONCAT(name, 'Street')), 'GOTHAM', 46460, 1, CONCAT(name,'@mydomain.com'), NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1,NULL, 10, 5, util.VN_CURDATE(), 1 FROM `account`.`role` `r` WHERE `r`.`hasLogin` = 1; diff --git a/modules/ticket/back/methods/ticket/specs/getTicketsAdvance.spec.js b/modules/ticket/back/methods/ticket/specs/getTicketsAdvance.spec.js index 488cd1fc2..a941013cd 100644 --- a/modules/ticket/back/methods/ticket/specs/getTicketsAdvance.spec.js +++ b/modules/ticket/back/methods/ticket/specs/getTicketsAdvance.spec.js @@ -6,6 +6,9 @@ describe('TicketFuture getTicketsAdvance()', () => { today.setHours(0, 0, 0, 0); let tomorrow = Date.vnNew(); tomorrow.setDate(today.getDate() + 1); + const salesDeptId = 43; + const spain1DeptId = 95; + beforeAll.mockLoopBackContext(); it('should return the tickets passing the required data', async() => { const tx = await models.Ticket.beginTransaction({}); @@ -129,4 +132,39 @@ describe('TicketFuture getTicketsAdvance()', () => { throw e; } }); + + it('should return the tickets matching the right department', async() => { + const tx = await models.Ticket.beginTransaction({}); + + try { + const options = {transaction: tx}; + ctx.args = { + dateFuture: tomorrow, + dateToAdvance: today, + warehouseFk: 1, + }; + + await models.Ticket.updateAll({id: {inq: [12, 31]}}, {clientFk: 1}, options); + const client = await models.Client.findById(1, null, options); + await client.updateAttribute('salesPersonFk', 1, options); + const business = await models.Business.findById(1, null, options); + await business.updateAttributes({departmentFk: spain1DeptId}, options); + + const saleTickets = await models.Ticket.getTicketsAdvance(ctx, options); + const filteredSaleTickets = await models.Ticket.getTicketsAdvance( + {args: {...ctx.args, departmentFk: spain1DeptId}}, + options); + + expect(saleTickets.length).toBeGreaterThan(filteredSaleTickets.length); + expect(saleTickets.some(ticket => ticket.departmentFk === salesDeptId)).toBeTrue(); + expect(saleTickets.some(ticket => ticket.departmentFk === spain1DeptId)).toBeTrue(); + + expect(filteredSaleTickets.some(ticket => ticket.departmentFk === salesDeptId)).toBeFalse(); + expect(filteredSaleTickets.some(ticket => ticket.departmentFk === spain1DeptId)).toBeTrue(); + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); }); From 1c5e4f40cec2c18cbf28e266bc37cd2e50fdf225 Mon Sep 17 00:00:00 2001 From: jorgep Date: Tue, 22 Oct 2024 12:39:51 +0200 Subject: [PATCH 47/74] feat: refs #8083 add prop --- modules/ticket/back/models/expedition.json | 117 +++++++++++---------- 1 file changed, 60 insertions(+), 57 deletions(-) diff --git a/modules/ticket/back/models/expedition.json b/modules/ticket/back/models/expedition.json index 2dcca1e87..f3f912ec3 100644 --- a/modules/ticket/back/models/expedition.json +++ b/modules/ticket/back/models/expedition.json @@ -1,63 +1,66 @@ { - "name": "Expedition", - "base": "VnModel", - "mixins": { - "Loggable": true + "name": "Expedition", + "base": "VnModel", + "mixins": { + "Loggable": true + }, + "options": { + "mysql": { + "table": "expedition" + } + }, + "properties": { + "id": { + "id": true, + "type": "number", + "description": "Identifier" }, - "options": { - "mysql": { - "table": "expedition" - } + "freightItemFk": { + "type": "number" }, - "properties": { - "id": { - "id": true, - "type": "number", - "description": "Identifier" - }, - "freightItemFk": { - "type": "number" - }, - "created": { - "type": "date" - }, - "counter": { - "type": "number" - }, - "externalId": { - "type": "string" - } + "created": { + "type": "date" }, - "relations": { - "ticket": { - "type": "belongsTo", - "model": "Ticket", - "foreignKey": "ticketFk" - }, - "agencyMode": { - "type": "belongsTo", - "model": "AgencyMode", - "foreignKey": "agencyModeFk" - }, - "worker": { - "type": "belongsTo", - "model": "Worker", - "foreignKey": "workerFk" - }, - "packages": { - "type": "hasMany", - "model": "TicketPackaging", - "foreignKey": "ticketFk" - }, - "freightItem": { - "type": "belongsTo", - "model": "Item", - "foreignKey": "freightItemFk" - }, - "packaging": { - "type": "belongsTo", - "model": "Package", - "foreignKey": "packagingFk" - } + "counter": { + "type": "number" + }, + "externalId": { + "type": "string" + }, + "stateTypeFk": { + "type": "number" + } + }, + "relations": { + "ticket": { + "type": "belongsTo", + "model": "Ticket", + "foreignKey": "ticketFk" + }, + "agencyMode": { + "type": "belongsTo", + "model": "AgencyMode", + "foreignKey": "agencyModeFk" + }, + "worker": { + "type": "belongsTo", + "model": "Worker", + "foreignKey": "workerFk" + }, + "packages": { + "type": "hasMany", + "model": "TicketPackaging", + "foreignKey": "ticketFk" + }, + "freightItem": { + "type": "belongsTo", + "model": "Item", + "foreignKey": "freightItemFk" + }, + "packaging": { + "type": "belongsTo", + "model": "Package", + "foreignKey": "packagingFk" } } +} \ No newline at end of file From c3f8da52c61b7070ade2de36800d8c1c91f8f698 Mon Sep 17 00:00:00 2001 From: guillermo Date: Tue, 22 Oct 2024 13:43:54 +0200 Subject: [PATCH 48/74] feat: refs #7266 Item label barcode --- db/dump/.dump/data.sql | 1 - .../11315-grayCamellia/00-firstScript.sql | 3 + .../item/back/methods/item/labelBarcodePdf.js | 55 ++++++++++++ .../item/{itemLabelQr.js => labelQrPdf.js} | 8 +- modules/item/back/models/item.js | 3 +- .../item-label-barcode/assets/css/import.js | 12 +++ .../item-label-barcode/assets/css/style.css | 83 ++++++++++++++++++ .../item-label-barcode.html | 87 +++++++++++++++++++ .../item-label-barcode/item-label-barcode.js | 58 +++++++++++++ .../reports/item-label-barcode/locale/es.yml | 1 + .../reports/item-label-barcode/options.json | 11 +++ .../item-label-barcode/sql/company.sql | 6 ++ .../reports/item-label-barcode/sql/item.sql | 42 +++++++++ .../item-label-barcode/sql/lastBuy.sql | 1 + .../reports/item-label-qr/item-label-qr.html | 2 +- 15 files changed, 366 insertions(+), 7 deletions(-) create mode 100644 db/versions/11315-grayCamellia/00-firstScript.sql create mode 100644 modules/item/back/methods/item/labelBarcodePdf.js rename modules/item/back/methods/item/{itemLabelQr.js => labelQrPdf.js} (86%) create mode 100644 print/templates/reports/item-label-barcode/assets/css/import.js create mode 100644 print/templates/reports/item-label-barcode/assets/css/style.css create mode 100644 print/templates/reports/item-label-barcode/item-label-barcode.html create mode 100755 print/templates/reports/item-label-barcode/item-label-barcode.js create mode 100644 print/templates/reports/item-label-barcode/locale/es.yml create mode 100644 print/templates/reports/item-label-barcode/options.json create mode 100644 print/templates/reports/item-label-barcode/sql/company.sql create mode 100644 print/templates/reports/item-label-barcode/sql/item.sql create mode 100644 print/templates/reports/item-label-barcode/sql/lastBuy.sql diff --git a/db/dump/.dump/data.sql b/db/dump/.dump/data.sql index 315bfe7c5..5f464c5e2 100644 --- a/db/dump/.dump/data.sql +++ b/db/dump/.dump/data.sql @@ -1723,7 +1723,6 @@ INSERT INTO `ACL` VALUES (378,'OsTicket','osTicketReportEmail','WRITE','ALLOW',' INSERT INTO `ACL` VALUES (379,'Item','buyerWasteEmail','WRITE','ALLOW','ROLE','system',NULL); INSERT INTO `ACL` VALUES (380,'Claim','claimPickupPdf','READ','ALLOW','ROLE','employee',NULL); INSERT INTO `ACL` VALUES (381,'Claim','claimPickupEmail','WRITE','ALLOW','ROLE','claimManager',NULL); -INSERT INTO `ACL` VALUES (382,'Item','itemLabelQr','READ','ALLOW','ROLE','employee',NULL); INSERT INTO `ACL` VALUES (383,'Sector','*','READ','ALLOW','ROLE','employee',NULL); INSERT INTO `ACL` VALUES (384,'Sector','*','WRITE','ALLOW','ROLE','employee',NULL); INSERT INTO `ACL` VALUES (385,'Route','driverRoutePdf','READ','ALLOW','ROLE','employee',NULL); diff --git a/db/versions/11315-grayCamellia/00-firstScript.sql b/db/versions/11315-grayCamellia/00-firstScript.sql new file mode 100644 index 000000000..60eea0e01 --- /dev/null +++ b/db/versions/11315-grayCamellia/00-firstScript.sql @@ -0,0 +1,3 @@ +DELETE FROM salix.ACL + WHERE property = 'labelPdf' + AND model = 'Item'; diff --git a/modules/item/back/methods/item/labelBarcodePdf.js b/modules/item/back/methods/item/labelBarcodePdf.js new file mode 100644 index 000000000..3325e3da1 --- /dev/null +++ b/modules/item/back/methods/item/labelBarcodePdf.js @@ -0,0 +1,55 @@ +module.exports = Self => { + Self.remoteMethodCtx('labelBarcodePdf', { + description: 'Returns the item label pdf with barcode', + accessType: 'READ', + accepts: [ + { + arg: 'id', + type: 'number', + required: true, + description: 'The item id', + http: {source: 'path'} + }, { + arg: 'warehouseId', + type: 'number', + required: true + }, { + arg: 'packing', + type: 'number', + required: false + }, { + arg: 'copies', + type: 'number', + required: false + }, { + arg: 'userId', + type: 'number', + description: 'The user id from accessToken', + http: ctx => ctx.req.accessToken.userId, + required: true + } + ], + returns: [ + { + arg: 'body', + type: 'file', + root: true + }, { + arg: 'Content-Type', + type: 'String', + http: {target: 'header'} + }, { + arg: 'Content-Disposition', + type: 'String', + http: {target: 'header'} + } + ], + http: { + path: '/:id/label-barcode-pdf', + verb: 'GET' + }, + accessScopes: ['DEFAULT', 'read:multimedia'] + }); + + Self.labelBarcodePdf = (ctx, id) => Self.printReport(ctx, id, 'item-label-barcode'); +}; diff --git a/modules/item/back/methods/item/itemLabelQr.js b/modules/item/back/methods/item/labelQrPdf.js similarity index 86% rename from modules/item/back/methods/item/itemLabelQr.js rename to modules/item/back/methods/item/labelQrPdf.js index 88d8ce950..4d0e34528 100644 --- a/modules/item/back/methods/item/itemLabelQr.js +++ b/modules/item/back/methods/item/labelQrPdf.js @@ -1,6 +1,6 @@ module.exports = Self => { - Self.remoteMethodCtx('itemLabelQr', { - description: 'Returns the item label pdf', + Self.remoteMethodCtx('labelQrPdf', { + description: 'Returns the item label pdf with qr', accessType: 'READ', accepts: [ { @@ -45,11 +45,11 @@ module.exports = Self => { } ], http: { - path: '/:id/item-label-qr', + path: '/:id/label-qr-pdf', verb: 'GET' }, accessScopes: ['DEFAULT', 'read:multimedia'] }); - Self.itemLabelQr = (ctx, id) => Self.printReport(ctx, id, 'item-label-qr'); + Self.labelQrPdf = (ctx, id) => Self.printReport(ctx, id, 'item-label-qr'); }; diff --git a/modules/item/back/models/item.js b/modules/item/back/models/item.js index 4fb9af8fa..d39586a90 100644 --- a/modules/item/back/models/item.js +++ b/modules/item/back/models/item.js @@ -15,7 +15,8 @@ module.exports = Self => { require('../methods/item/getWasteByItem')(Self); require('../methods/item/createIntrastat')(Self); require('../methods/item/buyerWasteEmail')(Self); - require('../methods/item/itemLabelQr')(Self); + require('../methods/item/labelBarcodePdf')(Self); + require('../methods/item/labelQrPdf')(Self); require('../methods/item/setVisibleDiscard')(Self); require('../methods/item/get')(Self); diff --git a/print/templates/reports/item-label-barcode/assets/css/import.js b/print/templates/reports/item-label-barcode/assets/css/import.js new file mode 100644 index 000000000..37a98dfdd --- /dev/null +++ b/print/templates/reports/item-label-barcode/assets/css/import.js @@ -0,0 +1,12 @@ +const Stylesheet = require(`vn-print/core/stylesheet`); + +const path = require('path'); +const vnPrintPath = path.resolve('print'); + +module.exports = new Stylesheet([ + `${vnPrintPath}/common/css/spacing.css`, + `${vnPrintPath}/common/css/misc.css`, + `${vnPrintPath}/common/css/layout.css`, + `${vnPrintPath}/common/css/report.css`, + `${__dirname}/style.css`]) + .mergeStyles(); diff --git a/print/templates/reports/item-label-barcode/assets/css/style.css b/print/templates/reports/item-label-barcode/assets/css/style.css new file mode 100644 index 000000000..48b881986 --- /dev/null +++ b/print/templates/reports/item-label-barcode/assets/css/style.css @@ -0,0 +1,83 @@ +html { + font-family: "Roboto", "Helvetica", "Arial", sans-serif; + margin-top: -7px; +} +table { + width: 100%; + font-size: 14px; +} +td { + border: 6px solid white; +} +.center { + text-align: center; +} +.right { + text-align: right; +} +.cursive { + font-style: italic; +} +.bold { + font-weight: bold; +} +.black-bg { + background-color: black; + color: white; +} +.xs-txt { + font-size: 18px; +} +.md-txt { + font-size: 26px; +} +.xl-txt { + font-size: 50px; +} +.cell { + border: 2px solid black; + box-sizing: content-box; + width: 100%; + height: 30px; + display: flex; + justify-content: center; + align-items: center; +} +.padding { + padding: 7px; +} +.xs-height { + height: 50px; + max-height: 50px; +} +.md-height { + height: 60px; + max-height: 60px; +} +.sm-width { + width: 60px; + max-width: 60px; +} +.md-width { + width: 120px; + max-width: 120px; +} +.lg-width { + width: 400px; + max-width: 400px; +} +.overflow-multiline { + max-height: inherit; + display: -webkit-box; + overflow: hidden; + word-wrap: break-word; + line-clamp: 2; + -webkit-line-clamp: 2; + -webkit-box-orient: vertical; +} +.overflow-line { + width: inherit; + max-width: inherit; + overflow: hidden; + white-space: nowrap; +} \ No newline at end of file diff --git a/print/templates/reports/item-label-barcode/item-label-barcode.html b/print/templates/reports/item-label-barcode/item-label-barcode.html new file mode 100644 index 000000000..79de49411 --- /dev/null +++ b/print/templates/reports/item-label-barcode/item-label-barcode.html @@ -0,0 +1,87 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ {{item.item}} +
+
+
+ {{item.size}} +
+
+
+ {{item.comment}} +
+
+
+ {{item.producer}} +
+
+
+ {{item.inkFk}} +
+
+
+ {{item.itemFk}} +
+
+
+ {{`${(packing || item.packing)} x ${item.stems || ''}`}} +
+
+
+
+
+ {{item.entryFk}} +
+
+
+ {{item.buyerName}} +
+
+
+ {{item.origin}} +
+
+
+ {{item.buyFk}} +
+
+
+ {{date}} +
+
+
+ {{`${item.labelNum}/${item.quantity / (packing || item.packing)}`}} +
+
+ + \ No newline at end of file diff --git a/print/templates/reports/item-label-barcode/item-label-barcode.js b/print/templates/reports/item-label-barcode/item-label-barcode.js new file mode 100755 index 000000000..29a2b9ad5 --- /dev/null +++ b/print/templates/reports/item-label-barcode/item-label-barcode.js @@ -0,0 +1,58 @@ +const UserError = require('vn-loopback/util/user-error'); +const {DOMImplementation, XMLSerializer} = require('xmldom'); +const moment = require('moment'); +const jsbarcode = require('jsbarcode'); + +module.exports = { + name: 'item-label-qr', + async serverPrefetch() { + this.company = await this.findOneFromDef('company', [this.warehouseId]); + if (!this.company) + throw new UserError(`There is no company associated with that warehouse`); + + this.date = Date.vnNew(); + this.lastBuy = await this.findOneFromDef('lastBuy', [ + this.id, + this.warehouseId, + this.date + ]); + this.items = await this.rawSqlFromDef('item', [this.copies || 1, this.lastBuy.id]); + if (!this.items.length) throw new UserError(`Empty data source`); + this.date = moment(this.date).format('WW/E'); + }, + methods: { + getBarcode(data) { + const document = new DOMImplementation().createDocument('http://www.w3.org/1999/xhtml', 'html', null); + const svgNode = document.createElementNS('http://www.w3.org/2000/svg', 'svg'); + + jsbarcode(svgNode, data, { + xmlDocument: document, + format: 'code128', + displayValue: false, + width: 3.9, + height: 85, + margin: 0 + }); + return new XMLSerializer().serializeToString(svgNode); + } + }, + props: { + id: { + type: Number, + required: true, + description: 'The item id' + }, + warehouseId: { + type: Number + }, + packing: { + type: Number + }, + copies: { + type: Number + }, + userId: { + type: Number + } + } +}; diff --git a/print/templates/reports/item-label-barcode/locale/es.yml b/print/templates/reports/item-label-barcode/locale/es.yml new file mode 100644 index 000000000..3cf8d2ce8 --- /dev/null +++ b/print/templates/reports/item-label-barcode/locale/es.yml @@ -0,0 +1 @@ +reportName: Etiqueta de artículo barcode \ No newline at end of file diff --git a/print/templates/reports/item-label-barcode/options.json b/print/templates/reports/item-label-barcode/options.json new file mode 100644 index 000000000..5a3c3b1eb --- /dev/null +++ b/print/templates/reports/item-label-barcode/options.json @@ -0,0 +1,11 @@ +{ + "width": "10.4cm", + "height": "4.8cm", + "margin": { + "top": "0.17cm", + "right": "0cm", + "bottom": "0cm", + "left": "0cm" + }, + "printBackground": true +} \ No newline at end of file diff --git a/print/templates/reports/item-label-barcode/sql/company.sql b/print/templates/reports/item-label-barcode/sql/company.sql new file mode 100644 index 000000000..e130b4033 --- /dev/null +++ b/print/templates/reports/item-label-barcode/sql/company.sql @@ -0,0 +1,6 @@ +SELECT co.code + FROM warehouse w + JOIN address a ON a.id = w.addressFk + JOIN client c ON c.id = a.clientFk + JOIN company co ON co.clientFk = c.id + WHERE w.id = ? \ No newline at end of file diff --git a/print/templates/reports/item-label-barcode/sql/item.sql b/print/templates/reports/item-label-barcode/sql/item.sql new file mode 100644 index 000000000..11ee60d1a --- /dev/null +++ b/print/templates/reports/item-label-barcode/sql/item.sql @@ -0,0 +1,42 @@ +WITH RECURSIVE numbers AS ( + SELECT 1 n + UNION ALL + SELECT n + 1 + FROM numbers + WHERE n < ? +) +SELECT ROW_NUMBER() OVER() labelNum, + b.id buyFk, + b.itemFk, + b.quantity, + b.packing, + b.isPickedOff, + b.entryFk, + e.sub, + o.code origin, + COALESCE(p.`name`, p.id, '') producer, + i.name item, + i.`size`, + i.category, + i.stems, + i.inkFk, + IFNULL(CONCAT(ig.longName, ' ', ig.`size`, ' ', ig.subName), i.comment) comment, + i.typeFk, + i.isLaid, + w.code buyerName, + w.code, + s.company_name companyName, + t.shipped + FROM vn.buy b + JOIN vn.item i ON i.id = b.itemFk + LEFT JOIN vn.item ig ON ig.id = b.itemOriginalFk + LEFT JOIN edi.ekt e ON e.id = b.ektFk + JOIN vn.origin o ON o.id = i.originFk + LEFT JOIN vn.producer p ON p.id = i.producerFk + JOIN vn.itemType it ON it.id = i.typeFk + JOIN vn.worker w ON w.id = it.workerFk + LEFT JOIN edi.supplier s ON s.supplier_id = e.pro + JOIN vn.entry e2 ON e2.id = b.entryFk + JOIN vn.travel t ON t.id = e2.travelFk + JOIN numbers num + WHERE b.id = ? \ No newline at end of file diff --git a/print/templates/reports/item-label-barcode/sql/lastBuy.sql b/print/templates/reports/item-label-barcode/sql/lastBuy.sql new file mode 100644 index 000000000..d10339998 --- /dev/null +++ b/print/templates/reports/item-label-barcode/sql/lastBuy.sql @@ -0,0 +1 @@ +SELECT buy_getUltimate(?, ?, ?) id \ No newline at end of file diff --git a/print/templates/reports/item-label-qr/item-label-qr.html b/print/templates/reports/item-label-qr/item-label-qr.html index 2ece8943e..231c94818 100644 --- a/print/templates/reports/item-label-qr/item-label-qr.html +++ b/print/templates/reports/item-label-qr/item-label-qr.html @@ -1,6 +1,6 @@ - + - @@ -103,7 +103,11 @@ diff --git a/print/templates/reports/item-label-qr/sql/company.sql b/print/templates/reports/item-label-qr/sql/company.sql index e130b4033..4047786a9 100644 --- a/print/templates/reports/item-label-qr/sql/company.sql +++ b/print/templates/reports/item-label-qr/sql/company.sql @@ -1,6 +1,5 @@ SELECT co.code FROM warehouse w JOIN address a ON a.id = w.addressFk - JOIN client c ON c.id = a.clientFk - JOIN company co ON co.clientFk = c.id + JOIN company co ON co.clientFk = a.clientFk WHERE w.id = ? \ No newline at end of file diff --git a/print/templates/reports/item-label-qr/sql/item.sql b/print/templates/reports/item-label-qr/sql/item.sql index 11ee60d1a..3cb42d139 100644 --- a/print/templates/reports/item-label-qr/sql/item.sql +++ b/print/templates/reports/item-label-qr/sql/item.sql @@ -6,37 +6,29 @@ WITH RECURSIVE numbers AS ( WHERE n < ? ) SELECT ROW_NUMBER() OVER() labelNum, - b.id buyFk, - b.itemFk, - b.quantity, - b.packing, - b.isPickedOff, - b.entryFk, - e.sub, - o.code origin, - COALESCE(p.`name`, p.id, '') producer, - i.name item, - i.`size`, - i.category, - i.stems, - i.inkFk, - IFNULL(CONCAT(ig.longName, ' ', ig.`size`, ' ', ig.subName), i.comment) comment, - i.typeFk, - i.isLaid, - w.code buyerName, - w.code, - s.company_name companyName, - t.shipped - FROM vn.buy b - JOIN vn.item i ON i.id = b.itemFk - LEFT JOIN vn.item ig ON ig.id = b.itemOriginalFk - LEFT JOIN edi.ekt e ON e.id = b.ektFk - JOIN vn.origin o ON o.id = i.originFk - LEFT JOIN vn.producer p ON p.id = i.producerFk - JOIN vn.itemType it ON it.id = i.typeFk - JOIN vn.worker w ON w.id = it.workerFk - LEFT JOIN edi.supplier s ON s.supplier_id = e.pro - JOIN vn.entry e2 ON e2.id = b.entryFk - JOIN vn.travel t ON t.id = e2.travelFk - JOIN numbers num - WHERE b.id = ? \ No newline at end of file + b.itemFk, + i.name item, + b.id buyFk, + b.quantity, + b.packing, + b.entryFk, + o.code origin, + p.`name` producerName, + p.id producerFk, + i.`size`, + i.category, + i.stems, + i.inkFk, + ig.longName, + ig.subName, + i.comment, + w.code buyerName + FROM vn.buy b + JOIN vn.item i ON i.id = b.itemFk + LEFT JOIN vn.item ig ON ig.id = b.itemOriginalFk + JOIN vn.origin o ON o.id = i.originFk + LEFT JOIN vn.producer p ON p.id = i.producerFk + JOIN vn.itemType it ON it.id = i.typeFk + JOIN vn.worker w ON w.id = it.workerFk + JOIN numbers num + WHERE b.id = ? \ No newline at end of file From 070a5640df8c40bba1b96fedc90440fcd8575576 Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Thu, 24 Oct 2024 08:16:04 +0000 Subject: [PATCH 60/74] fix: recalculatePrice not working with all ids --- modules/ticket/back/methods/sale/recalculatePrice.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/ticket/back/methods/sale/recalculatePrice.js b/modules/ticket/back/methods/sale/recalculatePrice.js index fd3d6aa9b..ea71032d0 100644 --- a/modules/ticket/back/methods/sale/recalculatePrice.js +++ b/modules/ticket/back/methods/sale/recalculatePrice.js @@ -48,7 +48,7 @@ module.exports = Self => { CALL vn.sale_recalcComponent(null); DROP TEMPORARY TABLE tmp.recalculateSales;`; - const recalculation = await Self.rawSql(query, salesIds, myOptions); + const recalculation = await Self.rawSql(query, [salesIds], myOptions); if (tx) await tx.commit(); From 8569bec34ac139a3846837e278009844ed6cbaac Mon Sep 17 00:00:00 2001 From: guillermo Date: Thu, 24 Oct 2024 12:18:09 +0200 Subject: [PATCH 61/74] feat: refs #7266 Minor change --- db/versions/11321-wheatChrysanthemum/00-firstScript.sql | 3 +++ .../templates/reports/item-label-barcode/item-label-barcode.js | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) create mode 100644 db/versions/11321-wheatChrysanthemum/00-firstScript.sql diff --git a/db/versions/11321-wheatChrysanthemum/00-firstScript.sql b/db/versions/11321-wheatChrysanthemum/00-firstScript.sql new file mode 100644 index 000000000..e3ba70e2c --- /dev/null +++ b/db/versions/11321-wheatChrysanthemum/00-firstScript.sql @@ -0,0 +1,3 @@ +INSERT INTO vn.report (name, `method`) + VALUES ('LabelItemBarcode','Items/{id}/label-barcode-pdf'), + ('LabelItemQr','Items/{id}/label-qr-pdf'); diff --git a/print/templates/reports/item-label-barcode/item-label-barcode.js b/print/templates/reports/item-label-barcode/item-label-barcode.js index 8a294afc1..5f9a11ea1 100755 --- a/print/templates/reports/item-label-barcode/item-label-barcode.js +++ b/print/templates/reports/item-label-barcode/item-label-barcode.js @@ -4,7 +4,7 @@ const moment = require('moment'); const jsbarcode = require('jsbarcode'); module.exports = { - name: 'item-label-qr', + name: 'item-label-barcode', async serverPrefetch() { this.company = await this.findOneFromDef('company', [this.warehouseId]); if (!this.company) From 4da11c65bbe5de6e63ab3287dbcadea3938b23bd Mon Sep 17 00:00:00 2001 From: guillermo Date: Thu, 24 Oct 2024 12:26:03 +0200 Subject: [PATCH 62/74] fix: refs #235425 sale priceFixed update --- modules/ticket/back/methods/sale/updatePrice.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/modules/ticket/back/methods/sale/updatePrice.js b/modules/ticket/back/methods/sale/updatePrice.js index 191fd09e3..afb25c365 100644 --- a/modules/ticket/back/methods/sale/updatePrice.js +++ b/modules/ticket/back/methods/sale/updatePrice.js @@ -92,6 +92,19 @@ module.exports = Self => { }, myOptions); } await sale.updateAttributes({price: newPrice}, myOptions); + await Self.rawSql(` + UPDATE sale + SET priceFixed = ( + SELECT SUM(value) + FROM sale s + JOIN saleComponent sc ON sc.saleFk = s.id + JOIN component c ON c.id = sc.componentFk + JOIN componentType ct ON ct.id = c.typeFk + WHERE ct.isBase + AND s.id = ? + ) + WHERE id = ? + `, [id, id], myOptions); await Self.rawSql('CALL vn.manaSpellersRequery(?)', [userId], myOptions); await Self.rawSql('CALL vn.ticket_recalc(?, NULL)', [sale.ticketFk], myOptions); From 111480f7b7f84c785cc1ceac8fef2d2eaad7c543 Mon Sep 17 00:00:00 2001 From: guillermo Date: Fri, 25 Oct 2024 07:22:36 +0200 Subject: [PATCH 63/74] fix: refs #235425 Requested changes --- .../ticket/back/methods/sale/updatePrice.js | 29 ++++++++++--------- modules/ticket/back/models/sale.json | 3 ++ 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/modules/ticket/back/methods/sale/updatePrice.js b/modules/ticket/back/methods/sale/updatePrice.js index afb25c365..d4f128082 100644 --- a/modules/ticket/back/methods/sale/updatePrice.js +++ b/modules/ticket/back/methods/sale/updatePrice.js @@ -91,20 +91,21 @@ module.exports = Self => { value: componentValue }, myOptions); } - await sale.updateAttributes({price: newPrice}, myOptions); - await Self.rawSql(` - UPDATE sale - SET priceFixed = ( - SELECT SUM(value) - FROM sale s - JOIN saleComponent sc ON sc.saleFk = s.id - JOIN component c ON c.id = sc.componentFk - JOIN componentType ct ON ct.id = c.typeFk - WHERE ct.isBase - AND s.id = ? - ) - WHERE id = ? - `, [id, id], myOptions); + + const [priceFixed] = await Self.rawSql(` + SELECT SUM(value) value + FROM sale s + JOIN saleComponent sc ON sc.saleFk = s.id + JOIN component c ON c.id = sc.componentFk + JOIN componentType ct ON ct.id = c.typeFk + WHERE ct.isBase + AND s.id = ? + `, [id], myOptions); + + await sale.updateAttributes({ + price: newPrice, + priceFixed: priceFixed.value + }, myOptions); await Self.rawSql('CALL vn.manaSpellersRequery(?)', [userId], myOptions); await Self.rawSql('CALL vn.ticket_recalc(?, NULL)', [sale.ticketFk], myOptions); diff --git a/modules/ticket/back/models/sale.json b/modules/ticket/back/models/sale.json index 96a36bbc9..947115f5c 100644 --- a/modules/ticket/back/models/sale.json +++ b/modules/ticket/back/models/sale.json @@ -28,6 +28,9 @@ "discount": { "type": "number" }, + "priceFixed": { + "type": "number" + }, "reserved": { "type": "boolean" }, From 69e1df25042f03e5ae57f3a798dfdff6b2f8f3fc Mon Sep 17 00:00:00 2001 From: guillermo Date: Fri, 25 Oct 2024 08:47:43 +0200 Subject: [PATCH 64/74] fix: refs #235425 Requested changes --- .../methods/sale/specs/updatePrice.spec.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/modules/ticket/back/methods/sale/specs/updatePrice.spec.js b/modules/ticket/back/methods/sale/specs/updatePrice.spec.js index 9d1403df0..100f74bf0 100644 --- a/modules/ticket/back/methods/sale/specs/updatePrice.spec.js +++ b/modules/ticket/back/methods/sale/specs/updatePrice.spec.js @@ -85,6 +85,25 @@ describe('sale updatePrice()', () => { } }); + it('should check if priceFixed has changed', async() => { + const tx = await models.Sale.beginTransaction({}); + + try { + const options = {transaction: tx}; + + const price = 3; + const beforeUpdate = await models.Sale.findById(saleId, null, options); + await models.Sale.updatePrice(ctx, saleId, price, options); + const afterUpdate = await models.Sale.findById(saleId, null, options); + + expect(beforeUpdate.priceFixed).not.toEqual(afterUpdate.priceFixed); + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); + it('should set price as a decimal number and check the sale has the mana component changing the salesPersonMana', async() => { const tx = await models.Sale.beginTransaction({}); From 8f102607953ba587527a2122cb82537e3db0be6e Mon Sep 17 00:00:00 2001 From: jorgep Date: Fri, 25 Oct 2024 11:37:45 +0200 Subject: [PATCH 65/74] feat: refs #7943 return just the required content --- modules/worker/back/models/worker.json | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/modules/worker/back/models/worker.json b/modules/worker/back/models/worker.json index c334c0d05..53be3ebb7 100644 --- a/modules/worker/back/models/worker.json +++ b/modules/worker/back/models/worker.json @@ -204,6 +204,15 @@ ] }, "summary": { + "fields": [ + "id", + "firstName", + "lastName", + "bossFk", + "sex", + "phone", + "mobileExtension" + ], "include": [ { "relation": "user", From e775e561201d96604f0706b17948c3aeaa8af5b2 Mon Sep 17 00:00:00 2001 From: sergiodt Date: Fri, 25 Oct 2024 13:48:27 +0200 Subject: [PATCH 66/74] feat: refs #7921 refs#7921 sendLostExpedition --- loopback/locale/en.json | 7 ++- loopback/locale/es.json | 3 +- loopback/locale/fr.json | 11 ++-- loopback/locale/pt.json | 9 +-- .../specs/addExpeditionState.spec.js | 1 + .../ticket/back/models/expedition-state.js | 62 +++++++++++++++++++ 6 files changed, 80 insertions(+), 13 deletions(-) diff --git a/loopback/locale/en.json b/loopback/locale/en.json index a7e21960b..ed1f28a04 100644 --- a/loopback/locale/en.json +++ b/loopback/locale/en.json @@ -240,6 +240,7 @@ "There is already a tray with the same height": "There is already a tray with the same height", "The height must be greater than 50cm": "The height must be greater than 50cm", "The maximum height of the wagon is 200cm": "The maximum height of the wagon is 200cm", - "The quantity claimed cannot be greater than the quantity of the line": "The quantity claimed cannot be greater than the quantity of the line", - "There are tickets for this area, delete them first": "There are tickets for this area, delete them first" -} + "The quantity claimed cannot be greater than the quantity of the line": "The quantity claimed cannot be greater than the quantity of the line", + "There are tickets for this area, delete them first": "There are tickets for this area, delete them first", + "ticketLostExpedition": "The ticket [{{ticketId}}]({{{ticketUrl}}}) has the following lost expedition:{{ expeditionId }}" +} \ No newline at end of file diff --git a/loopback/locale/es.json b/loopback/locale/es.json index 9f01bd290..a31e0688b 100644 --- a/loopback/locale/es.json +++ b/loopback/locale/es.json @@ -385,5 +385,6 @@ "The quantity claimed cannot be greater than the quantity of the line": "La cantidad reclamada no puede ser mayor que la cantidad de la línea", "type cannot be blank": "Se debe rellenar el tipo", "There are tickets for this area, delete them first": "Hay tickets para esta sección, borralos primero", - "There is no company associated with that warehouse": "No hay ninguna empresa asociada a ese almacén" + "There is no company associated with that warehouse": "No hay ninguna empresa asociada a ese almacén", + "ticketLostExpedition": "El ticket [{{ticketId}}]({{{ticketUrl}}}) tiene la siguiente expedición perdida:{{ expeditionId }}" } \ No newline at end of file diff --git a/loopback/locale/fr.json b/loopback/locale/fr.json index 23bd5cc04..1c7923ab4 100644 --- a/loopback/locale/fr.json +++ b/loopback/locale/fr.json @@ -123,8 +123,8 @@ "Added sale to ticket": "J'ai ajouté la ligne suivante au ticket [{{ticketId}}]({{{ticketUrl}}}): {{{addition}}}", "Changed sale discount": "J'ai changé le rabais des lignes suivantes du ticket [{{ticketId}}]({{{ticketUrl}}}): {{{changes}}}", "Created claim": "J'ai créé la réclamation [{{claimId}}]({{{claimUrl}}}) des lignes suivantes du ticket [{{ticketId}}]({{{ticketUrl}}}): {{{changes}}}", - "Changed sale price": " le prix de [{{itemId}} {{concept}}]({{{itemUrl}}}) ({{quantity}}) de {{oldPrice}}€ ➔ *{{newPrice}}€* du ticket [{{ticketId}}]({{{ticketUrl}}})",, - "Changed sale quantity": "J'ai changé {{changes}} du ticket [{{ticketId}}]({{{ticketUrl}}})", + "Changed sale price": " le prix de [{{itemId}} {{concept}}]({{{itemUrl}}}) ({{quantity}}) de {{oldPrice}}€ ➔ *{{newPrice}}€* du ticket [{{ticketId}}]({{{ticketUrl}}})", + "Changed sale quantity": "J'ai changé {{changes}} du ticket [{{ticketId}}]({{{ticketUrl}}})", "Changes in sales": "la quantité de {{itemId}} {{concept}} de {{oldQuantity}} ➔ {{newQuantity}}", "State": "État", "regular": "normal", @@ -362,6 +362,7 @@ "The invoices have been created but the PDFs could not be generated": "La facture a été émise mais le PDF n'a pas pu être généré", "It has been invoiced but the PDF of refund not be generated": "Il a été facturé mais le PDF de remboursement n'a pas été généré", "Cannot send mail": "Impossible d'envoyer le mail", - "Original invoice not found": "Facture originale introuvable", - "The quantity claimed cannot be greater than the quantity of the line": "Le montant réclamé ne peut pas être supérieur au montant de la ligne" -} + "Original invoice not found": "Facture originale introuvable", + "The quantity claimed cannot be greater than the quantity of the line": "Le montant réclamé ne peut pas être supérieur au montant de la ligne", + "ticketLostExpedition": "Le ticket [{{ticketId}}]({{{ticketUrl}}}) a l'expédition perdue suivante : {{expeditionId}}" +} \ No newline at end of file diff --git a/loopback/locale/pt.json b/loopback/locale/pt.json index f85afd607..689449163 100644 --- a/loopback/locale/pt.json +++ b/loopback/locale/pt.json @@ -124,7 +124,7 @@ "Changed sale discount": "Desconto da venda alterado no ticket [{{ticketId}}]({{{ticketUrl}}}): {{{changes}}}", "Created claim": "Reclamação criada [{{claimId}}]({{{claimUrl}}}) no ticket [{{ticketId}}]({{{ticketUrl}}}): {{{changes}}}", "Changed sale price": "Preço da venda alterado para [{{itemId}} {{concept}}]({{{itemUrl}}}) ({{quantity}}) de {{oldPrice}}€ ➔ *{{newPrice}}€* no ticket [{{ticketId}}]({{{ticketUrl}}})", - "Changed sale quantity": "Quantidade da venda alterada para {{changes}} no ticket [{{ticketId}}]({{{ticketUrl}}})", + "Changed sale quantity": "Quantidade da venda alterada para {{changes}} no ticket [{{ticketId}}]({{{ticketUrl}}})", "Changes in sales": " [{{itemId}} {{concept}}]({{{itemUrl}}}) de {{oldQuantity}} ➔ *{{newQuantity}}* ", "State": "Estado", "regular": "normal", @@ -361,7 +361,8 @@ "It was not able to create the invoice": "Não foi possível criar a fatura", "The invoices have been created but the PDFs could not be generated": "Foi faturado, mas o PDF não pôde ser gerado", "It has been invoiced but the PDF of refund not be generated": "Foi faturado mas não foi gerado o PDF do reembolso", - "Original invoice not found": "Fatura original não encontrada", + "Original invoice not found": "Fatura original não encontrada", "Cannot send mail": "Não é possível enviar o email", - "The quantity claimed cannot be greater than the quantity of the line": "O valor reclamado não pode ser superior ao valor da linha" -} + "The quantity claimed cannot be greater than the quantity of the line": "O valor reclamado não pode ser superior ao valor da linha", + "ticketLostExpedition": "O ticket [{{ticketId}}]({{{ticketUrl}}}) tem a seguinte expedição perdida: {{expeditionId}}" +} \ No newline at end of file diff --git a/modules/ticket/back/methods/expedition-state/specs/addExpeditionState.spec.js b/modules/ticket/back/methods/expedition-state/specs/addExpeditionState.spec.js index 747352286..71bc453de 100644 --- a/modules/ticket/back/methods/expedition-state/specs/addExpeditionState.spec.js +++ b/modules/ticket/back/methods/expedition-state/specs/addExpeditionState.spec.js @@ -2,6 +2,7 @@ const models = require('vn-loopback/server/server').models; describe('expeditionState addExpeditionState()', () => { const ctx = beforeAll.getCtx(); + beforeAll.mockLoopBackContext(); it('should update the expedition states', async() => { const tx = await models.ExpeditionState.beginTransaction({}); try { diff --git a/modules/ticket/back/models/expedition-state.js b/modules/ticket/back/models/expedition-state.js index 496dd88d3..18bab580e 100644 --- a/modules/ticket/back/models/expedition-state.js +++ b/modules/ticket/back/models/expedition-state.js @@ -1,4 +1,66 @@ +const LoopBackContext = require('loopback-context'); + module.exports = function(Self) { require('../methods/expedition-state/filter')(Self); require('../methods/expedition-state/addExpeditionState')(Self); + + Self.observe('before save', async ctx => { + const models = Self.app.models; + const changes = ctx.data || ctx.instance; + const instance = ctx.currentInstance; + const loopBackContext = LoopBackContext.getCurrentContext(); + const httpCtx = {req: loopBackContext.active}; + const httpRequest = httpCtx.req.http.req; + const $t = httpRequest.__; + const myOptions = {}; + + if (ctx.options && ctx.options.transaction) + myOptions.transaction = ctx.options.transaction; + + const newStateType = changes?.typeFk; + if (newStateType == null) return; + + const expeditionId = changes?.expeditionFk || instance?.expeditionFk; + + const {code} = await models.ExpeditionStateType.findById( + newStateType, + { + fields: ['code'] + }, + myOptions); + + if (code !== 'LOST') return; + + const dataExpedition = await models.Expedition.findById( + expeditionId, { + fields: ['ticketFk'], + include: [{ + relation: 'ticket', + scope: { + fields: ['clientFk'], + include: [{ + relation: 'client', + scope: { + fields: ['name', 'salesPersonFk'] + } + }] + } + }], + + }, myOptions); + + const salesPersonFk = dataExpedition.toJSON().ticket?.client?.salesPersonFk; + + if (salesPersonFk) { + const url = await Self.app.models.Url.getUrl(); + const fullUrl = `${url}ticket/${dataExpedition.ticketFk}/expedition`; + const message = $t('ticketLostExpedition', { + ticketId: dataExpedition.ticketFk, + expeditionId: expeditionId, + url: fullUrl + }); + await models.Chat.sendCheckingPresence(httpCtx, salesPersonFk, message); + } + }); }; + From 80764b6495290a5e9090114956fc5260df53f42f Mon Sep 17 00:00:00 2001 From: guillermo Date: Fri, 25 Oct 2024 14:17:57 +0200 Subject: [PATCH 67/74] feat: refs #7006 itemTypeLog --- db/versions/11297-graySalal/01-firstScript.sql | 3 +++ modules/item/back/models/item-type.json | 6 ++++++ 2 files changed, 9 insertions(+) create mode 100644 db/versions/11297-graySalal/01-firstScript.sql diff --git a/db/versions/11297-graySalal/01-firstScript.sql b/db/versions/11297-graySalal/01-firstScript.sql new file mode 100644 index 000000000..78ce1a540 --- /dev/null +++ b/db/versions/11297-graySalal/01-firstScript.sql @@ -0,0 +1,3 @@ +ALTER TABLE vn.itemType + ADD CONSTRAINT itemType_itemPackingType_FK FOREIGN KEY (itemPackingTypeFk) + REFERENCES vn.itemPackingType(code) ON DELETE RESTRICT ON UPDATE CASCADE; diff --git a/modules/item/back/models/item-type.json b/modules/item/back/models/item-type.json index c5c920b2f..88f66899e 100644 --- a/modules/item/back/models/item-type.json +++ b/modules/item/back/models/item-type.json @@ -29,6 +29,12 @@ }, "isLaid": { "type": "boolean" + }, + "maxRefs": { + "type": "string" + }, + "isFragile": { + "type": "boolean" } }, "relations": { From 14d6eb722ee5087402b3d213a1d5f1b6399d53fe Mon Sep 17 00:00:00 2001 From: guillermo Date: Fri, 25 Oct 2024 14:24:26 +0200 Subject: [PATCH 68/74] feat: refs #7006 Requested changes --- db/versions/11297-graySalal/00-firstScript.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/versions/11297-graySalal/00-firstScript.sql b/db/versions/11297-graySalal/00-firstScript.sql index 372af804c..4d4711306 100644 --- a/db/versions/11297-graySalal/00-firstScript.sql +++ b/db/versions/11297-graySalal/00-firstScript.sql @@ -24,4 +24,4 @@ CREATE TABLE `vn`.`itemTypeLog` ( ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci `PAGE_COMPRESSED`=1; INSERT IGNORE INTO salix.ACL (model,property,principalId) - VALUES ('ItemTypeLog','*','employee'); + VALUES ('ItemTypeLog','find','employee'); From d8e241740f9e5df512c44c5fbc31ecdaa3f9f000 Mon Sep 17 00:00:00 2001 From: jorgep Date: Sun, 27 Oct 2024 13:47:52 +0100 Subject: [PATCH 69/74] feat: refs #7524 restrict fields --- modules/worker/back/models/worker.json | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/modules/worker/back/models/worker.json b/modules/worker/back/models/worker.json index 53be3ebb7..937df98c0 100644 --- a/modules/worker/back/models/worker.json +++ b/modules/worker/back/models/worker.json @@ -256,10 +256,21 @@ } }, { - "relation": "boss" + "relation": "boss", + "scope": { + "fields": [ + "id", + "name" + ] + } }, { - "relation": "client" + "relation": "client", + "scope": { + "fields": [ + "id" + ] + } }, { "relation": "sip", @@ -281,14 +292,16 @@ "fields": [ "id", "fiDueDate", - "sex", "seniority", "fi", "isFreelance", "isSsDiscounted", "hasMachineryAuthorized", "isDisable", - "birth" + "birth", + "educationLevelFk", + "originCountryFk", + "maritalStatus" ] } } From 869c7ab598ffa951a479987b6ba2946efd2aeb5a Mon Sep 17 00:00:00 2001 From: carlossa Date: Mon, 28 Oct 2024 07:37:42 +0100 Subject: [PATCH 70/74] fix: refs #6644 email and translations --- loopback/locale/en.json | 9 ++++++--- loopback/locale/es.json | 5 +++-- loopback/locale/fr.json | 3 ++- loopback/locale/pt.json | 3 ++- modules/client/back/methods/client/createWithUser.js | 3 +++ 5 files changed, 16 insertions(+), 7 deletions(-) diff --git a/loopback/locale/en.json b/loopback/locale/en.json index a7e21960b..8c1ee7bb9 100644 --- a/loopback/locale/en.json +++ b/loopback/locale/en.json @@ -240,6 +240,9 @@ "There is already a tray with the same height": "There is already a tray with the same height", "The height must be greater than 50cm": "The height must be greater than 50cm", "The maximum height of the wagon is 200cm": "The maximum height of the wagon is 200cm", - "The quantity claimed cannot be greater than the quantity of the line": "The quantity claimed cannot be greater than the quantity of the line", - "There are tickets for this area, delete them first": "There are tickets for this area, delete them first" -} + "The quantity claimed cannot be greater than the quantity of the line": "The quantity claimed cannot be greater than the quantity of the line", + "There are tickets for this area, delete them first": "There are tickets for this area, delete them first", + "null": "null", + "Invalid or expired verification code": "Invalid or expired verification code", + "Payment method is required": "Payment method is required" +} \ No newline at end of file diff --git a/loopback/locale/es.json b/loopback/locale/es.json index 9f01bd290..144046f56 100644 --- a/loopback/locale/es.json +++ b/loopback/locale/es.json @@ -385,5 +385,6 @@ "The quantity claimed cannot be greater than the quantity of the line": "La cantidad reclamada no puede ser mayor que la cantidad de la línea", "type cannot be blank": "Se debe rellenar el tipo", "There are tickets for this area, delete them first": "Hay tickets para esta sección, borralos primero", - "There is no company associated with that warehouse": "No hay ninguna empresa asociada a ese almacén" -} \ No newline at end of file + "There is no company associated with that warehouse": "No hay ninguna empresa asociada a ese almacén", + "The web user's email already exists": "El correo del usuario web ya existe" +} diff --git a/loopback/locale/fr.json b/loopback/locale/fr.json index 23bd5cc04..446c2ad0d 100644 --- a/loopback/locale/fr.json +++ b/loopback/locale/fr.json @@ -363,5 +363,6 @@ "It has been invoiced but the PDF of refund not be generated": "Il a été facturé mais le PDF de remboursement n'a pas été généré", "Cannot send mail": "Impossible d'envoyer le mail", "Original invoice not found": "Facture originale introuvable", - "The quantity claimed cannot be greater than the quantity of the line": "Le montant réclamé ne peut pas être supérieur au montant de la ligne" + "The quantity claimed cannot be greater than the quantity of the line": "Le montant réclamé ne peut pas être supérieur au montant de la ligne", + "The web user's email already exists": "L'email de l'internaute existe déjà" } diff --git a/loopback/locale/pt.json b/loopback/locale/pt.json index f85afd607..4f68dfa53 100644 --- a/loopback/locale/pt.json +++ b/loopback/locale/pt.json @@ -363,5 +363,6 @@ "It has been invoiced but the PDF of refund not be generated": "Foi faturado mas não foi gerado o PDF do reembolso", "Original invoice not found": "Fatura original não encontrada", "Cannot send mail": "Não é possível enviar o email", - "The quantity claimed cannot be greater than the quantity of the line": "O valor reclamado não pode ser superior ao valor da linha" + "The quantity claimed cannot be greater than the quantity of the line": "O valor reclamado não pode ser superior ao valor da linha", + "The web user's email already exists": "O e-mail do utilizador da web já existe." } diff --git a/modules/client/back/methods/client/createWithUser.js b/modules/client/back/methods/client/createWithUser.js index c8cd282e1..1d5e71fca 100644 --- a/modules/client/back/methods/client/createWithUser.js +++ b/modules/client/back/methods/client/createWithUser.js @@ -1,3 +1,4 @@ +/* eslint max-len: ["error", { "code": 150 }]*/ const UserError = require('vn-loopback/util/user-error'); module.exports = function(Self) { @@ -98,6 +99,8 @@ module.exports = function(Self) { return client; } catch (e) { if (tx) await tx.rollback(); + if (e.message && e.message.includes(`Email already exists`)) throw new UserError(`The web user's email already exists`); + throw e; } }; From 6efc2c340c932b1437689cf5decb30bf8b7b7d3a Mon Sep 17 00:00:00 2001 From: sergiodt Date: Mon, 28 Oct 2024 08:57:22 +0100 Subject: [PATCH 71/74] feat: refs #7921 refs#7921 sendLostExpedition --- modules/ticket/back/models/expedition-state.js | 2 +- modules/ticket/back/models/expedition-state.json | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/modules/ticket/back/models/expedition-state.js b/modules/ticket/back/models/expedition-state.js index 18bab580e..f819dc05c 100644 --- a/modules/ticket/back/models/expedition-state.js +++ b/modules/ticket/back/models/expedition-state.js @@ -49,7 +49,7 @@ module.exports = function(Self) { }, myOptions); - const salesPersonFk = dataExpedition.toJSON().ticket?.client?.salesPersonFk; + const salesPersonFk = dataExpedition.ticket()?.client()?.salesPersonFk; if (salesPersonFk) { const url = await Self.app.models.Url.getUrl(); diff --git a/modules/ticket/back/models/expedition-state.json b/modules/ticket/back/models/expedition-state.json index 159a9275e..522327031 100644 --- a/modules/ticket/back/models/expedition-state.json +++ b/modules/ticket/back/models/expedition-state.json @@ -19,7 +19,8 @@ "type": "number" }, "typeFk": { - "type": "number" + "type": "number", + "required": true }, "userFk": { "type": "number" From eb5f57285aaf242b1d54ce4a8bd881f4e69dea3b Mon Sep 17 00:00:00 2001 From: Jon Date: Mon, 28 Oct 2024 10:40:43 +0100 Subject: [PATCH 72/74] feat: refs #7193 added scope in parking model --- modules/shelving/back/models/parking.json | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/modules/shelving/back/models/parking.json b/modules/shelving/back/models/parking.json index 47a3305ae..a9393fc6a 100644 --- a/modules/shelving/back/models/parking.json +++ b/modules/shelving/back/models/parking.json @@ -38,5 +38,13 @@ "model": "Sector", "foreignKey": "sectorFk" } + }, + "scope": { + "include": { + "relation": "sector", + "scope": { + "fields": ["id", "description"] + } + } } } From 0180998683ed40e951eb4a81671bcf411dc112c0 Mon Sep 17 00:00:00 2001 From: carlossa Date: Mon, 28 Oct 2024 13:08:27 +0100 Subject: [PATCH 73/74] fix: refs #7283 item filters --- modules/item/back/methods/item/filter.js | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/modules/item/back/methods/item/filter.js b/modules/item/back/methods/item/filter.js index 909b3dff8..54dd975a4 100644 --- a/modules/item/back/methods/item/filter.js +++ b/modules/item/back/methods/item/filter.js @@ -38,13 +38,23 @@ module.exports = Self => { type: 'integer', description: 'Type id', }, + { + arg: 'producerFk', + type: 'integer', + description: 'Producer id', + }, + { + arg: 'instrastatFk', + type: 'string', + description: 'intrastat id', + }, { arg: 'isActive', type: 'boolean', description: 'Whether the item is or not active', }, { - arg: 'buyerFk', + arg: 'workerFk', type: 'integer', description: 'The buyer of the item', }, @@ -126,14 +136,16 @@ module.exports = Self => { return {'i.stemMultiplier': value}; case 'categoryFk': return {'ic.id': value}; - case 'buyerFk': + case 'workerFk': return {'it.workerFk': value}; + case 'producerFk': + return {'pr.id': value}; case 'supplierFk': return {'s.id': value}; case 'origin': return {'ori.code': value}; - case 'intrastat': - return {'intr.description': value}; + case 'intrastatFk': + return {'i.intrastatFk': value}; case 'landed': return {'lb.landed': value}; } @@ -172,6 +184,7 @@ module.exports = Self => { u.name AS userName, ori.code AS origin, ic.name AS category, + i.intrastatFk, intr.description AS intrastat, b.grouping, b.packing, From 385279b39df4c829c99bf29913b233afa5644747 Mon Sep 17 00:00:00 2001 From: carlossa Date: Mon, 28 Oct 2024 13:15:40 +0100 Subject: [PATCH 74/74] fix: refs #7283 tback --- modules/item/back/methods/item/specs/filter.spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/item/back/methods/item/specs/filter.spec.js b/modules/item/back/methods/item/specs/filter.spec.js index 14467d1d8..a8aaca786 100644 --- a/modules/item/back/methods/item/specs/filter.spec.js +++ b/modules/item/back/methods/item/specs/filter.spec.js @@ -86,7 +86,7 @@ describe('item filter()', () => { try { const filter = {}; - const ctx = {args: {filter: filter, buyerFk: 16}, req: {accessToken: {userId: 1}}}; + const ctx = {args: {filter: filter, workerFk: 16}, req: {accessToken: {userId: 1}}}; const result = await models.Item.filter(ctx, filter, options); expect(result.length).toEqual(2);
From 1afb33c3064739c0a032e7a7b09f581b7b20e602 Mon Sep 17 00:00:00 2001 From: guillermo Date: Tue, 22 Oct 2024 15:00:16 +0200 Subject: [PATCH 49/74] feat: refs #8119 Requested changes --- ...nQuantity_add.sql => itemCampaign_add.sql} | 4 +- .../procedures/itemCampaignQuantity_add.sql | 86 ------------------- .../vn/procedures/itemCampaign_add.sql | 58 +++++++++++++ .../11308-redCymbidium/00-firstScript.sql | 26 +++--- 4 files changed, 72 insertions(+), 102 deletions(-) rename db/routines/vn/events/{itemCampaignQuantity_add.sql => itemCampaign_add.sql} (72%) delete mode 100644 db/routines/vn/procedures/itemCampaignQuantity_add.sql create mode 100644 db/routines/vn/procedures/itemCampaign_add.sql diff --git a/db/routines/vn/events/itemCampaignQuantity_add.sql b/db/routines/vn/events/itemCampaign_add.sql similarity index 72% rename from db/routines/vn/events/itemCampaignQuantity_add.sql rename to db/routines/vn/events/itemCampaign_add.sql index 4deb2d556..efb2aeb11 100644 --- a/db/routines/vn/events/itemCampaignQuantity_add.sql +++ b/db/routines/vn/events/itemCampaign_add.sql @@ -1,8 +1,8 @@ DELIMITER $$ -CREATE OR REPLACE DEFINER=`vn`@`localhost` EVENT `vn`.`itemCampaignQuantity_add` +CREATE OR REPLACE DEFINER=`vn`@`localhost` EVENT `vn`.`itemCampaig_add` ON SCHEDULE EVERY 1 DAY STARTS '2024-10-18 03:00:00.000' ON COMPLETION PRESERVE ENABLE -DO CALL itemCampaignQuantity_add(NULL, NULL, NULL)$$ +DO CALL itemCampaign_add()$$ DELIMITER ; diff --git a/db/routines/vn/procedures/itemCampaignQuantity_add.sql b/db/routines/vn/procedures/itemCampaignQuantity_add.sql deleted file mode 100644 index 6edb97c08..000000000 --- a/db/routines/vn/procedures/itemCampaignQuantity_add.sql +++ /dev/null @@ -1,86 +0,0 @@ -DELIMITER $$ -CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`itemCampaignQuantity_add`( - vDateFrom DATE, - vDateTo DATE, - vCampaign VARCHAR(100) -) -proc: BEGIN -/** - * Añade registros a tabla itemCampaignQuantity. - * - * @param vDateFrom Fecha desde - * @param vDateTo Fecha hasta - * @param vCampaign Código de la campaña - */ - DECLARE vCurdate DATE; - DECLARE vYesterday DATE; - DECLARE vDefaultCampaign VARCHAR(100); - DECLARE vPreviousDaysToInsert INT; - DECLARE vDateSumFrom DATE; - DECLARE vDateSumTo DATE; - DECLARE vScopeDays INT; - - SET vCurdate = util.VN_CURDATE(); - SET vYesterday = util.yesterday(); - - IF vDateFrom IS NULL THEN - SET vDateFrom = vYesterday; - END IF; - - IF vDateTo IS NULL THEN - SET vDateTo = vYesterday; - END IF; - - IF vDateFrom > vDateTo THEN - CALL util.throw('Start date cannot be later than end date'); - END IF; - - SELECT defaultCampaign, previousDaysToInsert - INTO vDefaultCampaign, vPreviousDaysToInsert - FROM itemCampaignQuantityConfig; - - IF vCampaign IS NULL THEN - SET vCampaign = vDefaultCampaign; - END IF; - - IF vCampaign IS NULL OR vPreviousDaysToInsert IS NULL THEN - CALL util.throw('Missing values in the configuration table'); - END IF; - - SELECT dated, scopeDays INTO vDateSumTo, vScopeDays - FROM campaign - WHERE dated > vCurdate - AND code = vCampaign - ORDER BY dated - LIMIT 1; - - IF vDateSumTo IS NULL OR vScopeDays IS NULL THEN - CALL util.throw('Missing data in campaign table'); - END IF; - - IF NOT vCurdate BETWEEN vDateSumTo - INTERVAL vPreviousDaysToInsert DAY - AND vDateSumTo THEN - LEAVE proc; - END IF; - - SET vDateSumFrom = vDateSumTo - INTERVAL vScopeDays DAY; - - REPLACE itemCampaignQuantity(dated, itemFk, quantity, total, campaign) - SELECT DATE(s.created), - s.itemFk, - SUM(CASE WHEN t.shipped BETWEEN vDateSumFrom AND vDateSumTo - THEN s.quantity - END) quantity, - SUM(CASE WHEN t.shipped BETWEEN vDateSumFrom AND vDateSumTo - THEN s.total - END) total, - vCampaign - FROM sale s - JOIN ticket t ON t.id = s.ticketFk - JOIN client c ON c.id = t.clientFk - WHERE s.created BETWEEN vDateFrom AND util.dayEnd(vDateTo) - AND c.businessTypeFk <> 'worker' - GROUP BY DATE(s.created), s.itemFk - HAVING quantity; -END$$ -DELIMITER ; diff --git a/db/routines/vn/procedures/itemCampaign_add.sql b/db/routines/vn/procedures/itemCampaign_add.sql new file mode 100644 index 000000000..1e10bc619 --- /dev/null +++ b/db/routines/vn/procedures/itemCampaign_add.sql @@ -0,0 +1,58 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`itemCampaign_add`() +proc: BEGIN +/** + * Añade registros a tabla itemCampaign. + * + * @param vDateFrom Fecha desde + * @param vDateTo Fecha hasta + * @param vCampaign Código de la campaña + */ + DECLARE vCurdate DATE; + DECLARE vYesterday DATE; + DECLARE vCampaign VARCHAR(100); + DECLARE vPreviousDays INT; + DECLARE vDateSumFrom DATE; + DECLARE vDateSumTo DATE; + DECLARE vScopeDays INT; + + SET vCurdate = util.VN_CURDATE(); + + SELECT dated, code, scopeDays, previousDays + INTO vDateSumTo, vCampaign, vScopeDays, vPreviousDays + FROM campaign + WHERE dated > vCurdate + ORDER BY dated + LIMIT 1; + + IF vCampaign IS NULL THEN + CALL util.throw('Missing data in campaign table'); + END IF; + + IF NOT vCurdate BETWEEN vDateSumTo - INTERVAL vPreviousDays DAY + AND vDateSumTo THEN + LEAVE proc; + END IF; + + SET vDateSumFrom = vDateSumTo - INTERVAL vScopeDays DAY; + SET vYesterday = util.yesterday(); + + REPLACE itemCampaign(dated, itemFk, quantity, total, campaign) + SELECT DATE(s.created), + s.itemFk, + SUM(CASE WHEN t.shipped BETWEEN vDateSumFrom AND vDateSumTo + THEN s.quantity + END) quantity, + SUM(CASE WHEN t.shipped BETWEEN vDateSumFrom AND vDateSumTo + THEN (s.quantity * s.price) * (100 - s.discount) / 100 + END) total, + vCampaign + FROM sale s + JOIN ticket t ON t.id = s.ticketFk + JOIN client c ON c.id = t.clientFk + WHERE s.created BETWEEN vYesterday AND util.dayEnd(vYesterday) + AND c.typeFk = 'normal' + GROUP BY DATE(s.created), s.itemFk + HAVING quantity; +END$$ +DELIMITER ; diff --git a/db/versions/11308-redCymbidium/00-firstScript.sql b/db/versions/11308-redCymbidium/00-firstScript.sql index 14fad3636..fe76cb600 100644 --- a/db/versions/11308-redCymbidium/00-firstScript.sql +++ b/db/versions/11308-redCymbidium/00-firstScript.sql @@ -1,27 +1,25 @@ -CREATE TABLE IF NOT EXISTS `vn`.`itemCampaignQuantity` ( +CREATE TABLE IF NOT EXISTS `vn`.`itemCampaign` ( `id` int(11) NOT NULL PRIMARY KEY AUTO_INCREMENT, dated date NOT NULL, itemFk int(11) NOT NULL, quantity decimal(10,2) NOT NULL, total decimal(10,2) NOT NULL, campaign varchar(100) NOT NULL, - UNIQUE KEY `itemCampaignQuantity_UNIQUE` (`dated`,`itemFk`), - CONSTRAINT itemCampaignQuantity_item_FK FOREIGN KEY (itemFk) REFERENCES vn.item(id) ON DELETE RESTRICT ON UPDATE CASCADE + UNIQUE KEY `itemCampaign_UNIQUE` (`dated`,`itemFk`), + CONSTRAINT itemCampaign_item_FK FOREIGN KEY (itemFk) REFERENCES vn.item(id) ON DELETE RESTRICT ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Tallos confirmados por día en los días de más producción de una campaña. La tabla está pensada para que sea una foto.'; -CREATE TABLE IF NOT EXISTS `vn`.`itemCampaignQuantityConfig` ( - id int(10) unsigned NOT NULL PRIMARY KEY, - defaultCampaign varchar(100) NOT NULL COMMENT 'Campaña por defecto si se le pasa NULL', - previousDaysToInsert int(10) unsigned NOT NULL COMMENT 'Días anteriores a la fecha de fin de campaña para insertar', - CONSTRAINT `itemCampaignQuantityConfig_check` CHECK (`id` = 1) -) -ENGINE=InnoDB -DEFAULT CHARSET=utf8mb3 -COLLATE=utf8mb3_unicode_ci; +ALTER TABLE vn.campaign + ADD previousDays int(10) unsigned DEFAULT 30 NOT NULL COMMENT 'Días previos para calcular e insertar en la tabla itemCampaign'; -INSERT IGNORE INTO `vn`.`itemCampaignQuantityConfig` (id, defaultCampaign, previousDaysToInsert) - VALUES (1, 'allSaints', 90); +UPDATE vn.campaign + SET previousDays = 90 + WHERE code = 'allSaints'; + +UPDATE vn.campaign + SET previousDays = 60 + WHERE code IN ('valentinesDay', 'mothersDay'); From fe3e7342bcea4693c40146076031b939a432f873 Mon Sep 17 00:00:00 2001 From: guillermo Date: Wed, 23 Oct 2024 07:14:07 +0200 Subject: [PATCH 50/74] fix: refs #7935 version --- .../{00-firstScript copy.sql => 00-firstScript2.sql} | 0 .../{00-firstScript copy 2.sql => 00-firstScript3.sql} | 0 .../{00-firstScript copy 3.sql => 00-firstScript4.sql} | 0 .../{00-firstScript copy 4.sql => 00-firstScript5.sql} | 0 .../{00-firstScript copy 5.sql => 00-firstScript6.sql} | 0 .../{00-firstScript copy 6.sql => 00-firstScript7.sql} | 0 6 files changed, 0 insertions(+), 0 deletions(-) rename db/versions/11274-redGerbera/{00-firstScript copy.sql => 00-firstScript2.sql} (100%) rename db/versions/11274-redGerbera/{00-firstScript copy 2.sql => 00-firstScript3.sql} (100%) rename db/versions/11274-redGerbera/{00-firstScript copy 3.sql => 00-firstScript4.sql} (100%) rename db/versions/11274-redGerbera/{00-firstScript copy 4.sql => 00-firstScript5.sql} (100%) rename db/versions/11274-redGerbera/{00-firstScript copy 5.sql => 00-firstScript6.sql} (100%) rename db/versions/11274-redGerbera/{00-firstScript copy 6.sql => 00-firstScript7.sql} (100%) diff --git a/db/versions/11274-redGerbera/00-firstScript copy.sql b/db/versions/11274-redGerbera/00-firstScript2.sql similarity index 100% rename from db/versions/11274-redGerbera/00-firstScript copy.sql rename to db/versions/11274-redGerbera/00-firstScript2.sql diff --git a/db/versions/11274-redGerbera/00-firstScript copy 2.sql b/db/versions/11274-redGerbera/00-firstScript3.sql similarity index 100% rename from db/versions/11274-redGerbera/00-firstScript copy 2.sql rename to db/versions/11274-redGerbera/00-firstScript3.sql diff --git a/db/versions/11274-redGerbera/00-firstScript copy 3.sql b/db/versions/11274-redGerbera/00-firstScript4.sql similarity index 100% rename from db/versions/11274-redGerbera/00-firstScript copy 3.sql rename to db/versions/11274-redGerbera/00-firstScript4.sql diff --git a/db/versions/11274-redGerbera/00-firstScript copy 4.sql b/db/versions/11274-redGerbera/00-firstScript5.sql similarity index 100% rename from db/versions/11274-redGerbera/00-firstScript copy 4.sql rename to db/versions/11274-redGerbera/00-firstScript5.sql diff --git a/db/versions/11274-redGerbera/00-firstScript copy 5.sql b/db/versions/11274-redGerbera/00-firstScript6.sql similarity index 100% rename from db/versions/11274-redGerbera/00-firstScript copy 5.sql rename to db/versions/11274-redGerbera/00-firstScript6.sql diff --git a/db/versions/11274-redGerbera/00-firstScript copy 6.sql b/db/versions/11274-redGerbera/00-firstScript7.sql similarity index 100% rename from db/versions/11274-redGerbera/00-firstScript copy 6.sql rename to db/versions/11274-redGerbera/00-firstScript7.sql From 62f9f31279f829b204e55e4c52b2370c3a0b5244 Mon Sep 17 00:00:00 2001 From: jgallego Date: Wed, 23 Oct 2024 07:44:41 +0200 Subject: [PATCH 51/74] feat: refs #7943 usa back con permisos --- .../item/front/item-type/basic-data/index.html | 16 ++++++++-------- modules/item/front/item-type/create/index.html | 14 +++++++------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/modules/item/front/item-type/basic-data/index.html b/modules/item/front/item-type/basic-data/index.html index 1417a05ab..c3f7a57f1 100644 --- a/modules/item/front/item-type/basic-data/index.html +++ b/modules/item/front/item-type/basic-data/index.html @@ -11,26 +11,26 @@ - \ No newline at end of file + diff --git a/modules/item/front/item-type/create/index.html b/modules/item/front/item-type/create/index.html index 44cb5183d..4a199a1b1 100644 --- a/modules/item/front/item-type/create/index.html +++ b/modules/item/front/item-type/create/index.html @@ -12,26 +12,26 @@ Date: Wed, 23 Oct 2024 08:23:28 +0200 Subject: [PATCH 52/74] feat: refs #8119 Requested changes --- .../vn/procedures/itemCampaign_add.sql | 27 ++++++++----------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/db/routines/vn/procedures/itemCampaign_add.sql b/db/routines/vn/procedures/itemCampaign_add.sql index 1e10bc619..6291d6895 100644 --- a/db/routines/vn/procedures/itemCampaign_add.sql +++ b/db/routines/vn/procedures/itemCampaign_add.sql @@ -8,20 +8,19 @@ proc: BEGIN * @param vDateTo Fecha hasta * @param vCampaign Código de la campaña */ - DECLARE vCurdate DATE; DECLARE vYesterday DATE; DECLARE vCampaign VARCHAR(100); + DECLARE vScopeDays INT; DECLARE vPreviousDays INT; DECLARE vDateSumFrom DATE; DECLARE vDateSumTo DATE; - DECLARE vScopeDays INT; - SET vCurdate = util.VN_CURDATE(); + SET vYesterday = util.yesterday(); SELECT dated, code, scopeDays, previousDays INTO vDateSumTo, vCampaign, vScopeDays, vPreviousDays FROM campaign - WHERE dated > vCurdate + WHERE dated >= vYesterday ORDER BY dated LIMIT 1; @@ -29,30 +28,26 @@ proc: BEGIN CALL util.throw('Missing data in campaign table'); END IF; - IF NOT vCurdate BETWEEN vDateSumTo - INTERVAL vPreviousDays DAY + IF NOT vYesterday BETWEEN vDateSumTo - INTERVAL vPreviousDays DAY AND vDateSumTo THEN LEAVE proc; END IF; SET vDateSumFrom = vDateSumTo - INTERVAL vScopeDays DAY; - SET vYesterday = util.yesterday(); - REPLACE itemCampaign(dated, itemFk, quantity, total, campaign) - SELECT DATE(s.created), + INSERT INTO itemCampaign(dated, itemFk, quantity, total, campaign) + SELECT vYesterday, s.itemFk, - SUM(CASE WHEN t.shipped BETWEEN vDateSumFrom AND vDateSumTo - THEN s.quantity - END) quantity, - SUM(CASE WHEN t.shipped BETWEEN vDateSumFrom AND vDateSumTo - THEN (s.quantity * s.price) * (100 - s.discount) / 100 - END) total, + SUM(s.quantity) quantity, + SUM((s.quantity * s.price) * (100 - s.discount) / 100) total, vCampaign FROM sale s JOIN ticket t ON t.id = s.ticketFk JOIN client c ON c.id = t.clientFk - WHERE s.created BETWEEN vYesterday AND util.dayEnd(vYesterday) + WHERE t.shipped BETWEEN vDateSumFrom AND vDateSumTo AND c.typeFk = 'normal' - GROUP BY DATE(s.created), s.itemFk + AND NOT t.isDeleted + GROUP BY s.itemFk HAVING quantity; END$$ DELIMITER ; From 37050361c23bc5f6b84807e674f1f5af937da43c Mon Sep 17 00:00:00 2001 From: guillermo Date: Wed, 23 Oct 2024 08:26:36 +0200 Subject: [PATCH 53/74] feat: refs #8119 Requested changes --- db/routines/vn/procedures/itemCampaign_add.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/routines/vn/procedures/itemCampaign_add.sql b/db/routines/vn/procedures/itemCampaign_add.sql index 6291d6895..ff92f3b25 100644 --- a/db/routines/vn/procedures/itemCampaign_add.sql +++ b/db/routines/vn/procedures/itemCampaign_add.sql @@ -44,7 +44,7 @@ proc: BEGIN FROM sale s JOIN ticket t ON t.id = s.ticketFk JOIN client c ON c.id = t.clientFk - WHERE t.shipped BETWEEN vDateSumFrom AND vDateSumTo + WHERE t.shipped BETWEEN vDateSumFrom AND util.dayEnd(vDateSumTo) AND c.typeFk = 'normal' AND NOT t.isDeleted GROUP BY s.itemFk From 31c89538bc9d17d75b72975ecc1e3d87fcd2903e Mon Sep 17 00:00:00 2001 From: guillermo Date: Wed, 23 Oct 2024 08:27:07 +0200 Subject: [PATCH 54/74] feat: refs #8119 Requested changes --- db/routines/vn/procedures/itemCampaign_add.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/routines/vn/procedures/itemCampaign_add.sql b/db/routines/vn/procedures/itemCampaign_add.sql index ff92f3b25..6291d6895 100644 --- a/db/routines/vn/procedures/itemCampaign_add.sql +++ b/db/routines/vn/procedures/itemCampaign_add.sql @@ -44,7 +44,7 @@ proc: BEGIN FROM sale s JOIN ticket t ON t.id = s.ticketFk JOIN client c ON c.id = t.clientFk - WHERE t.shipped BETWEEN vDateSumFrom AND util.dayEnd(vDateSumTo) + WHERE t.shipped BETWEEN vDateSumFrom AND vDateSumTo AND c.typeFk = 'normal' AND NOT t.isDeleted GROUP BY s.itemFk From 3cde6b6bc65136ebfa559af9269566ef9e718fac Mon Sep 17 00:00:00 2001 From: guillermo Date: Wed, 23 Oct 2024 08:30:21 +0200 Subject: [PATCH 55/74] feat: refs #8119 Requested changes --- db/routines/vn/procedures/itemCampaign_add.sql | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/db/routines/vn/procedures/itemCampaign_add.sql b/db/routines/vn/procedures/itemCampaign_add.sql index 6291d6895..8fb40df67 100644 --- a/db/routines/vn/procedures/itemCampaign_add.sql +++ b/db/routines/vn/procedures/itemCampaign_add.sql @@ -34,6 +34,7 @@ proc: BEGIN END IF; SET vDateSumFrom = vDateSumTo - INTERVAL vScopeDays DAY; + SET vDateSumTo = vDateSumTo - INTERVAL 1 DAY; INSERT INTO itemCampaign(dated, itemFk, quantity, total, campaign) SELECT vYesterday, @@ -44,7 +45,7 @@ proc: BEGIN FROM sale s JOIN ticket t ON t.id = s.ticketFk JOIN client c ON c.id = t.clientFk - WHERE t.shipped BETWEEN vDateSumFrom AND vDateSumTo + WHERE t.shipped BETWEEN vDateSumFrom AND util.dayEnd(vDateSumTo) AND c.typeFk = 'normal' AND NOT t.isDeleted GROUP BY s.itemFk From b1a295dca450d02b03c83f4be8f72d5fe557dd6b Mon Sep 17 00:00:00 2001 From: guillermo Date: Wed, 23 Oct 2024 09:46:06 +0200 Subject: [PATCH 56/74] feat: refs #7266 Print corrections --- .../item-label-barcode/assets/css/style.css | 15 ++++++++------- .../item-label-barcode/item-label-barcode.html | 2 +- .../item-label-barcode/item-label-barcode.js | 2 +- .../reports/item-label-barcode/options.json | 4 ++-- .../reports/item-label-qr/assets/css/style.css | 18 ++++++++++-------- .../reports/item-label-qr/options.json | 4 ++-- 6 files changed, 24 insertions(+), 21 deletions(-) diff --git a/print/templates/reports/item-label-barcode/assets/css/style.css b/print/templates/reports/item-label-barcode/assets/css/style.css index 48b881986..884faef56 100644 --- a/print/templates/reports/item-label-barcode/assets/css/style.css +++ b/print/templates/reports/item-label-barcode/assets/css/style.css @@ -1,6 +1,7 @@ html { font-family: "Roboto", "Helvetica", "Arial", sans-serif; - margin-top: -7px; + margin-top: -9px; + margin-left: -6px; } table { width: 100%; @@ -51,20 +52,20 @@ td { max-height: 50px; } .md-height { - height: 60px; - max-height: 60px; + height: 75px; + max-height: 75px; } .sm-width { width: 60px; max-width: 60px; } .md-width { - width: 120px; - max-width: 120px; + width: 125px; + max-width: 125px; } .lg-width { - width: 400px; - max-width: 400px; + width: 380px; + max-width: 380px; } .overflow-multiline { max-height: inherit; diff --git a/print/templates/reports/item-label-barcode/item-label-barcode.html b/print/templates/reports/item-label-barcode/item-label-barcode.html index 79de49411..224338c2f 100644 --- a/print/templates/reports/item-label-barcode/item-label-barcode.html +++ b/print/templates/reports/item-label-barcode/item-label-barcode.html @@ -8,7 +8,7 @@ {{item.item}} +
{{item.size}}
diff --git a/print/templates/reports/item-label-barcode/item-label-barcode.js b/print/templates/reports/item-label-barcode/item-label-barcode.js index 29a2b9ad5..8a294afc1 100755 --- a/print/templates/reports/item-label-barcode/item-label-barcode.js +++ b/print/templates/reports/item-label-barcode/item-label-barcode.js @@ -29,7 +29,7 @@ module.exports = { xmlDocument: document, format: 'code128', displayValue: false, - width: 3.9, + width: 3.8, height: 85, margin: 0 }); diff --git a/print/templates/reports/item-label-barcode/options.json b/print/templates/reports/item-label-barcode/options.json index 5a3c3b1eb..1ae2630b0 100644 --- a/print/templates/reports/item-label-barcode/options.json +++ b/print/templates/reports/item-label-barcode/options.json @@ -1,9 +1,9 @@ { "width": "10.4cm", - "height": "4.8cm", + "height": "4.9cm", "margin": { "top": "0.17cm", - "right": "0cm", + "right": "0.745cm", "bottom": "0cm", "left": "0cm" }, diff --git a/print/templates/reports/item-label-qr/assets/css/style.css b/print/templates/reports/item-label-qr/assets/css/style.css index b868f3966..fe6668c9a 100644 --- a/print/templates/reports/item-label-qr/assets/css/style.css +++ b/print/templates/reports/item-label-qr/assets/css/style.css @@ -1,6 +1,7 @@ html { font-family: "Roboto", "Helvetica", "Arial", sans-serif; margin-top: -7px; + margin-left: -6px; } .leftTable { width: 47%; @@ -9,6 +10,7 @@ html { text-align: center; } .leftTable img { + margin-top: 3px; width: 110px; } .rightTable { @@ -51,24 +53,24 @@ html { padding: 7px; } .md-height { - height: 60px; - max-height: 60px; + height: 68px; + max-height: 68px; } .xs-width { width: 60px; max-width: 60px; } .sm-width { - width: 140px; - max-width: 140px; + width: 130px; + max-width: 130px; } .md-width { - width: 200px; - max-width: 200px; + width: 190px; + max-width: 190px; } .lg-width { - width: 270px; - max-width: 270px; + width: 240px; + max-width: 240px; } .overflow-multiline { max-height: inherit; diff --git a/print/templates/reports/item-label-qr/options.json b/print/templates/reports/item-label-qr/options.json index 5a3c3b1eb..c3c395040 100644 --- a/print/templates/reports/item-label-qr/options.json +++ b/print/templates/reports/item-label-qr/options.json @@ -1,9 +1,9 @@ { "width": "10.4cm", - "height": "4.8cm", + "height": "4.9cm", "margin": { "top": "0.17cm", - "right": "0cm", + "right": "0.6cm", "bottom": "0cm", "left": "0cm" }, From 3da08e3a23292353eca229b7c140898bec852cf3 Mon Sep 17 00:00:00 2001 From: sergiodt Date: Wed, 23 Oct 2024 11:33:45 +0200 Subject: [PATCH 57/74] feat: refs #8020 machineWorkerDeprecated --- .../machine-worker/specs/updateInTime.spec.js | 132 ------------------ back/methods/machine-worker/updateInTime.js | 77 ---------- back/model-config.json | 6 - back/models/machine-worker-config.json | 18 --- back/models/machine-worker.js | 3 - back/models/machine-worker.json | 33 ----- db/dump/fixtures.before.sql | 11 -- .../workerMachinery_isRegistered.sql | 23 --- .../vn/procedures/machineWorker_add.sql | 22 --- .../machineWorker_getHistorical.sql | 21 --- .../vn/procedures/machineWorker_update.sql | 38 ----- .../vn/procedures/machine_getWorkerPlate.sql | 16 --- db/routines/vn/views/workerWithoutTractor.sql | 7 +- .../11317-silverCordyline/00-firstScript.sql | 9 ++ 14 files changed, 12 insertions(+), 404 deletions(-) delete mode 100644 back/methods/machine-worker/specs/updateInTime.spec.js delete mode 100644 back/methods/machine-worker/updateInTime.js delete mode 100644 back/models/machine-worker-config.json delete mode 100644 back/models/machine-worker.js delete mode 100644 back/models/machine-worker.json delete mode 100644 db/routines/vn/functions/workerMachinery_isRegistered.sql delete mode 100644 db/routines/vn/procedures/machineWorker_add.sql delete mode 100644 db/routines/vn/procedures/machineWorker_getHistorical.sql delete mode 100644 db/routines/vn/procedures/machineWorker_update.sql delete mode 100644 db/routines/vn/procedures/machine_getWorkerPlate.sql create mode 100644 db/versions/11317-silverCordyline/00-firstScript.sql diff --git a/back/methods/machine-worker/specs/updateInTime.spec.js b/back/methods/machine-worker/specs/updateInTime.spec.js deleted file mode 100644 index f166214b0..000000000 --- a/back/methods/machine-worker/specs/updateInTime.spec.js +++ /dev/null @@ -1,132 +0,0 @@ -const {models} = require('vn-loopback/server/server'); - -describe('machineWorker updateInTime()', () => { - const itBoss = 104; - const davidCharles = 1106; - - beforeAll(async() => { - ctx = { - req: { - accessToken: {}, - headers: {origin: 'http://localhost'}, - __: value => value - } - }; - }); - - it('should throw an error if the plate does not exist', async() => { - const tx = await models.MachineWorker.beginTransaction({}); - const options = {transaction: tx}; - const plate = 'RE-123'; - ctx.req.accessToken.userId = 1106; - try { - await models.MachineWorker.updateInTime(ctx, plate, options); - await tx.rollback(); - } catch (e) { - const error = e; - - expect(error.message).toContain('the plate does not exist'); - await tx.rollback(); - } - }); - - it('should grab a machine where is not in use', async() => { - const tx = await models.MachineWorker.beginTransaction({}); - const options = {transaction: tx}; - const plate = 'RE-003'; - ctx.req.accessToken.userId = 1107; - try { - const totalBefore = await models.MachineWorker.find(null, options); - await models.MachineWorker.updateInTime(ctx, plate, options); - const totalAfter = await models.MachineWorker.find(null, options); - - expect(totalAfter.length).toEqual(totalBefore.length + 1); - await tx.rollback(); - } catch (e) { - await tx.rollback(); - } - }); - - describe('less than 12h', () => { - const plate = 'RE-001'; - it('should trow an error if it is not himself', async() => { - const tx = await models.MachineWorker.beginTransaction({}); - const options = {transaction: tx}; - ctx.req.accessToken.userId = davidCharles; - - try { - await models.MachineWorker.updateInTime(ctx, plate, options); - await tx.rollback(); - } catch (e) { - const error = e; - - expect(error.message).toContain('This machine is already in use'); - await tx.rollback(); - } - }); - - it('should throw an error if it is himself with a different machine', async() => { - const tx = await models.MachineWorker.beginTransaction({}); - const options = {transaction: tx}; - ctx.req.accessToken.userId = itBoss; - const plate = 'RE-003'; - try { - await models.MachineWorker.updateInTime(ctx, plate, options); - await tx.rollback(); - } catch (e) { - const error = e; - - expect(error.message).toEqual('You are already using a machine'); - await tx.rollback(); - } - }); - - it('should set the out time if it is himself', async() => { - const tx = await models.MachineWorker.beginTransaction({}); - const options = {transaction: tx}; - ctx.req.accessToken.userId = itBoss; - - try { - const isNotParked = await models.MachineWorker.findOne({ - where: {workerFk: itBoss} - }, options); - await models.MachineWorker.updateInTime(ctx, plate, options); - const isParked = await models.MachineWorker.findOne({ - where: {workerFk: itBoss} - }, options); - - expect(isNotParked.outTime).toBeNull(); - expect(isParked.outTime).toBeDefined(); - await tx.rollback(); - } catch (e) { - await tx.rollback(); - } - }); - }); - - describe('equal or more than 12h', () => { - const plate = 'RE-002'; - it('should set the out time and grab the machine', async() => { - const tx = await models.MachineWorker.beginTransaction({}); - const options = {transaction: tx}; - ctx.req.accessToken.userId = davidCharles; - const filter = { - where: {workerFk: davidCharles, machineFk: 2} - }; - try { - const isNotParked = await models.MachineWorker.findOne(filter, options); - const totalBefore = await models.MachineWorker.find(null, options); - await models.MachineWorker.updateInTime(ctx, plate, options); - const isParked = await models.MachineWorker.findOne(filter, options); - const totalAfter = await models.MachineWorker.find(null, options); - - expect(isNotParked.outTime).toBeNull(); - expect(isParked.outTime).toBeDefined(); - expect(totalAfter.length).toEqual(totalBefore.length + 1); - await tx.rollback(); - } catch (e) { - await tx.rollback(); - } - }); - }); -}); diff --git a/back/methods/machine-worker/updateInTime.js b/back/methods/machine-worker/updateInTime.js deleted file mode 100644 index 44fad2c05..000000000 --- a/back/methods/machine-worker/updateInTime.js +++ /dev/null @@ -1,77 +0,0 @@ -const UserError = require('vn-loopback/util/user-error'); -module.exports = Self => { - Self.remoteMethodCtx('updateInTime', { - description: 'Updates the corresponding registry if the worker has been registered in the last few hours', - accessType: 'WRITE', - accepts: [ - { - arg: 'plate', - type: 'string', - } - ], - http: { - path: `/updateInTime`, - verb: 'POST' - } - }); - - Self.updateInTime = async(ctx, plate, options) => { - const models = Self.app.models; - const userId = ctx.req.accessToken.userId; - const $t = ctx.req.__; - - let tx; - const myOptions = {}; - - if (typeof options == 'object') - Object.assign(myOptions, options); - - if (!myOptions.transaction) { - tx = await Self.beginTransaction({}); - myOptions.transaction = tx; - } - - try { - const machine = await models.Machine.findOne({ - fields: ['id', 'plate'], - where: {plate} - }, myOptions); - - if (!machine) - throw new UserError($t('the plate does not exist', {plate})); - - const machineWorker = await Self.findOne({ - where: { - or: [{machineFk: machine.id}, {workerFk: userId}], - outTime: null, - } - }, myOptions); - - const {maxHours} = await models.MachineWorkerConfig.findOne({fields: ['maxHours']}, myOptions); - const hoursDifference = (Date.vnNow() - machineWorker?.inTime?.getTime() ?? 0) / (60 * 60 * 1000); - - if (machineWorker) { - const isHimself = userId == machineWorker.workerFk; - const isSameMachine = machine.id == machineWorker.machineFk; - - if (hoursDifference < maxHours && !isHimself) - throw new UserError($t('This machine is already in use.')); - - if (hoursDifference < maxHours && isHimself && !isSameMachine) - throw new UserError($t('You are already using a machine')); - - await machineWorker.updateAttributes({ - outTime: Date.vnNew() - }, myOptions); - } - - if (!machineWorker || hoursDifference >= maxHours) - await models.MachineWorker.create({machineFk: machine.id, workerFk: userId}, myOptions); - - if (tx) await tx.commit(); - } catch (e) { - if (tx) await tx.rollback(); - throw e; - } - }; -}; diff --git a/back/model-config.json b/back/model-config.json index b6d304675..5368769fd 100644 --- a/back/model-config.json +++ b/back/model-config.json @@ -88,12 +88,6 @@ "Machine": { "dataSource": "vn" }, - "MachineWorker": { - "dataSource": "vn" - }, - "MachineWorkerConfig": { - "dataSource": "vn" - }, "MobileAppVersionControl": { "dataSource": "vn" }, diff --git a/back/models/machine-worker-config.json b/back/models/machine-worker-config.json deleted file mode 100644 index dfb77124e..000000000 --- a/back/models/machine-worker-config.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - "name": "MachineWorkerConfig", - "base": "VnModel", - "options": { - "mysql": { - "table": "vn.machineWorkerConfig" - } - }, - "properties": { - "id": { - "type": "number", - "id": true - }, - "maxHours": { - "type": "number" - } - } -} diff --git a/back/models/machine-worker.js b/back/models/machine-worker.js deleted file mode 100644 index cbc5fd53e..000000000 --- a/back/models/machine-worker.js +++ /dev/null @@ -1,3 +0,0 @@ -module.exports = Self => { - require('../methods/machine-worker/updateInTime')(Self); -}; diff --git a/back/models/machine-worker.json b/back/models/machine-worker.json deleted file mode 100644 index 2244a533f..000000000 --- a/back/models/machine-worker.json +++ /dev/null @@ -1,33 +0,0 @@ -{ - "name": "MachineWorker", - "base": "VnModel", - "options": { - "mysql": { - "table": "vn.machineWorker" - } - }, - "properties": { - "id": { - "type": "number", - "id": true - }, - "workerFk": { - "type": "number" - }, - "machineFk": { - "type": "number" - }, - "inTime": { - "type": "date", - "mysql": { - "columnName": "inTimed" - } - }, - "outTime": { - "type": "date", - "mysql": { - "columnName": "outTimed" - } - } - } -} diff --git a/db/dump/fixtures.before.sql b/db/dump/fixtures.before.sql index e93bb3b8e..4fbe16f33 100644 --- a/db/dump/fixtures.before.sql +++ b/db/dump/fixtures.before.sql @@ -2842,12 +2842,6 @@ INSERT INTO `vn`.`machine` (`plate`, `maker`, `model`, `warehouseFk`, `departmen ('RE-001', 'STILL', 'LTX-20', 60, 23, 'ELECTRIC TOW', 'Drag cars', 2020, 103, 442), ('RE-002', 'STILL', 'LTX-20', 60, 23, 'ELECTRIC TOW', 'Drag cars', 2020, 103, 442); -INSERT INTO `vn`.`machineWorker` (`workerFk`, `machineFk`, `inTimed`, `outTimed`) - VALUES - (1106, 1, util.VN_CURDATE(), util.VN_CURDATE()), - (1106, 1, DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), DATE_ADD(util.VN_CURDATE(), INTERVAL +1 DAY)), - (1106, 2, util.VN_CURDATE(), NULL), - (1106, 2, DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), DATE_ADD(util.VN_CURDATE(), INTERVAL +1 DAY)); INSERT INTO `vn`.`zoneExclusion` (`id`, `zoneFk`, `dated`, `created`, `userFk`) VALUES @@ -3831,8 +3825,6 @@ UPDATE vn.collection UPDATE vn.sale SET isPicked =FALSE; -INSERT INTO vn.machineWorkerConfig(id, maxHours) - VALUES(1, 12); INSERT INTO vn.workerAppTester(workerFk) VALUES(66); @@ -3840,9 +3832,6 @@ INSERT INTO `vn`.`machine` (`plate`, `maker`, `model`, `warehouseFk`, `departmen VALUES ('RE-003', 'IRON', 'JPH-24', 60, 23, 'ELECTRIC TOW', 'Drag cars', 2020, 103, 442); - -INSERT INTO vn.machineWorker(workerFk,machineFk,inTimed) VALUES (104,1,'2001-01-01 10:00:00.00.000'); - UPDATE vn.buy SET itemOriginalFk = 1 WHERE id = 1; UPDATE vn.saleTracking SET stateFk = 26 WHERE id = 5; diff --git a/db/routines/vn/functions/workerMachinery_isRegistered.sql b/db/routines/vn/functions/workerMachinery_isRegistered.sql deleted file mode 100644 index 60f458e9e..000000000 --- a/db/routines/vn/functions/workerMachinery_isRegistered.sql +++ /dev/null @@ -1,23 +0,0 @@ -DELIMITER $$ -CREATE OR REPLACE DEFINER=`vn`@`localhost` FUNCTION `vn`.`workerMachinery_isRegistered`(vWorkerFk VARCHAR(10)) - RETURNS tinyint(1) - NOT DETERMINISTIC - READS SQL DATA -BEGIN -/** - * Comprueba si existen registros en las últimas horas (maxHours de machineWorkerConfig) del trabajador vWorkerFk y si tiene a nulo la hora outTimed (indica la hora que deja el vehículo) - * - * @param vWorkerFk id del trabajador - * @return Devuelve TRUE/FALSE en caso de que haya o no registros - */ - IF (SELECT COUNT(*) - FROM machineWorker m - WHERE m.workerFk = vWorkerFk - AND m.inTimed >= TIMESTAMPADD(HOUR , -(SELECT maxHours from machineWorkerConfig), util.VN_NOW()) AND ISNULL(m.outTimed)) - THEN - RETURN TRUE; - ELSE - RETURN FALSE; - END IF; -END$$ -DELIMITER ; diff --git a/db/routines/vn/procedures/machineWorker_add.sql b/db/routines/vn/procedures/machineWorker_add.sql deleted file mode 100644 index 41000f556..000000000 --- a/db/routines/vn/procedures/machineWorker_add.sql +++ /dev/null @@ -1,22 +0,0 @@ -DELIMITER $$ -CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`machineWorker_add`(vPlate VARCHAR(10), vWorkerFk INT) -BEGIN - -/** - * Inserta registro si el vWorkerFk no ha registrado nada en las últimas 12 horas - * @param vPlate número de matrícula - * @param vWorkerFk id del worker - * -*/ - UPDATE vn.machineWorker mw - JOIN vn.machine m ON m.id = mw.machineFk - SET mw.outTimed = util.VN_NOW() - WHERE (mw.workerFk = vWorkerFk OR m.plate = vPlate) - AND ISNULL(mw.outTimed); - - INSERT INTO machineWorker (machineFk, workerFk) - SELECT m.id, vWorkerFk - FROM machine m - WHERE m.plate= vPlate; -END$$ -DELIMITER ; diff --git a/db/routines/vn/procedures/machineWorker_getHistorical.sql b/db/routines/vn/procedures/machineWorker_getHistorical.sql deleted file mode 100644 index 67b1971a2..000000000 --- a/db/routines/vn/procedures/machineWorker_getHistorical.sql +++ /dev/null @@ -1,21 +0,0 @@ -DELIMITER $$ -CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`machineWorker_getHistorical`(vPlate VARCHAR(20), vWorkerFk INT) -BEGIN -/** - * Obtiene historial de la matrícula vPlate que el trabajador vWorkerFk escanea, - * si es jefe de producción muestra el historial completo. - * - * @param vPlate número de matrícula - * @param vWorkerFk id del trabajador - * -*/ - DECLARE vWorkerName VARCHAR(255) DEFAULT account.user_getNameFromId(vWorkerFk); - - SELECT mw.inTimed,account.user_getNameFromId(mw.workerFk) as workerName, mw.outTimed - FROM machineWorker mw - JOIN machine m ON m.plate = vPlate - WHERE mw.machineFk = m.id - AND mw.workerFk = IF(account.user_hasRole(vWorkerName, 'coolerAssist'), mw.workerFk, vWorkerFk) - ORDER BY mw.inTimed DESC; -END$$ -DELIMITER ; diff --git a/db/routines/vn/procedures/machineWorker_update.sql b/db/routines/vn/procedures/machineWorker_update.sql deleted file mode 100644 index f1a6e40b5..000000000 --- a/db/routines/vn/procedures/machineWorker_update.sql +++ /dev/null @@ -1,38 +0,0 @@ -DELIMITER $$ -CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`machineWorker_update`(vPlate VARCHAR(10), vWorkerFk INT) -BEGIN - -/** - * Actualiza el registro correspondiente si el vWorkerFk se ha registrado en las últimas horas (campo maxHours de machineWorkerConfig) con vPlate, - * - * @param vPlate número de matrícula - * @param vWorkerFk id del trabajador - * -*/ - - DECLARE vMachineFk INT(10); - DECLARE vMaxHours INT(10); - - SELECT m.id INTO vMachineFk - FROM machine m - WHERE m.plate = vPlate; - - SELECT maxHours INTO vMaxHours - FROM machineWorkerConfig; - - IF (SELECT COUNT(*) - FROM machineWorker m - WHERE m.workerFk = vWorkerFk - AND m.inTimed >= TIMESTAMPADD(HOUR , -vMaxHours, util.VN_NOW()) AND ISNULL(m.outTimed)) THEN - - UPDATE machineWorker m - SET m.outTimed = CURRENT_TIMESTAMP() - WHERE m.workerFk = vWorkerFk - AND m.inTimed >= TIMESTAMPADD(HOUR , -vMaxHours, util.VN_NOW()) - AND ISNULL(m.outTimed) - AND m.machineFk = vMachineFk; - - END IF; - -END$$ -DELIMITER ; diff --git a/db/routines/vn/procedures/machine_getWorkerPlate.sql b/db/routines/vn/procedures/machine_getWorkerPlate.sql deleted file mode 100644 index cbb71c4cf..000000000 --- a/db/routines/vn/procedures/machine_getWorkerPlate.sql +++ /dev/null @@ -1,16 +0,0 @@ -DELIMITER $$ -CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`machine_getWorkerPlate`(vWorkerFk INT) -BEGIN -/** - * Selecciona la matrícula del vehículo del workerfk - * - * @param vWorkerFk el id del trabajador - */ - SELECT m.plate - FROM machine m - JOIN machineWorker mw ON mw.machineFk = m.id - WHERE mw.inTimed >= TIMESTAMPADD(HOUR , -12,util.VN_NOW()) - AND ISNULL(mw.outTimed) - AND mw.workerFk = vWorkerFk; -END$$ -DELIMITER ; diff --git a/db/routines/vn/views/workerWithoutTractor.sql b/db/routines/vn/views/workerWithoutTractor.sql index 205c66599..15b62d4a9 100644 --- a/db/routines/vn/views/workerWithoutTractor.sql +++ b/db/routines/vn/views/workerWithoutTractor.sql @@ -10,11 +10,10 @@ FROM ( `vn`.`collection` `c` JOIN `vn`.`client` `cl` ON(`cl`.`id` = `c`.`workerFk`) ) - LEFT JOIN `vn`.`machineWorker` `mw` ON( - `mw`.`workerFk` = `c`.`workerFk` - AND `mw`.`inTimed` > `util`.`VN_CURDATE`() + JOIN `vn`.`operator` `o` ON( + `o`.`workerFk` = `c`.`workerFk` ) ) WHERE `c`.`created` > `util`.`VN_CURDATE`() - AND `mw`.`workerFk` IS NULL + AND `o`.`machineFk` IS NULL GROUP BY `c`.`workerFk` diff --git a/db/versions/11317-silverCordyline/00-firstScript.sql b/db/versions/11317-silverCordyline/00-firstScript.sql new file mode 100644 index 000000000..35dffcd64 --- /dev/null +++ b/db/versions/11317-silverCordyline/00-firstScript.sql @@ -0,0 +1,9 @@ + +USE vn; +RENAME TABLE machineWorker TO machineWorker__; +ALTER TABLE machineWorker__ COMMENT = '@deprecated 2024-10-23 not used'; + +RENAME TABLE machineWorkerConfig TO machineWorkerConfig__; +ALTER TABLE machineWorkerConfig__ COMMENT = '@deprecated 2024-10-23 not used'; + +DELETE FROM salix.ACL WHERE model = 'MachineWorker'; From 43f8b22593574c2908fabb66f2d158807e83afdc Mon Sep 17 00:00:00 2001 From: jorgep Date: Wed, 23 Oct 2024 16:10:00 +0200 Subject: [PATCH 58/74] feat: refs #8083 add field --- modules/ticket/back/methods/expedition-state/filter.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/ticket/back/methods/expedition-state/filter.js b/modules/ticket/back/methods/expedition-state/filter.js index 1483780f7..3a4e7a87c 100644 --- a/modules/ticket/back/methods/expedition-state/filter.js +++ b/modules/ticket/back/methods/expedition-state/filter.js @@ -29,7 +29,7 @@ module.exports = Self => { Object.assign(myOptions, options); const stmt = new ParameterizedSQL( - `SELECT es.created, u.name, u.id workerFk, est.description state + `SELECT es.created, u.name, u.id workerFk, est.description state, es.isScanned FROM vn.expeditionState es JOIN vn.expeditionStateType est ON est.id = es.typeFk JOIN account.user u ON u.id = es.userFk From 4c529da620871d1c78f824aad3a781f7ea1fd0e8 Mon Sep 17 00:00:00 2001 From: guillermo Date: Thu, 24 Oct 2024 07:31:26 +0200 Subject: [PATCH 59/74] feat: refs #7266 Requested changes and query optimization --- db/routines/vn/functions/buy_getUltimate.sql | 2 +- db/routines/vn/procedures/buy_getUltimate.sql | 2 +- .../item-label-barcode.html | 8 ++- .../item-label-barcode/sql/company.sql | 3 +- .../reports/item-label-barcode/sql/item.sql | 60 ++++++++----------- .../reports/item-label-qr/item-label-qr.html | 8 ++- .../reports/item-label-qr/sql/company.sql | 3 +- .../reports/item-label-qr/sql/item.sql | 60 ++++++++----------- 8 files changed, 68 insertions(+), 78 deletions(-) diff --git a/db/routines/vn/functions/buy_getUltimate.sql b/db/routines/vn/functions/buy_getUltimate.sql index 173e6e01f..8f5e9ce59 100644 --- a/db/routines/vn/functions/buy_getUltimate.sql +++ b/db/routines/vn/functions/buy_getUltimate.sql @@ -1,7 +1,7 @@ DELIMITER $$ CREATE OR REPLACE DEFINER=`vn`@`localhost` FUNCTION `vn`.`buy_getUltimate`( vItemFk INT, - vWarehouseFk SMALLINT, + vWarehouseFk INT, vDated DATE ) RETURNS int(11) diff --git a/db/routines/vn/procedures/buy_getUltimate.sql b/db/routines/vn/procedures/buy_getUltimate.sql index 1532222ad..77e2029fc 100644 --- a/db/routines/vn/procedures/buy_getUltimate.sql +++ b/db/routines/vn/procedures/buy_getUltimate.sql @@ -1,7 +1,7 @@ DELIMITER $$ CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`buy_getUltimate`( vItemFk INT, - vWarehouseFk SMALLINT, + vWarehouseFk INT, vDated DATE ) BEGIN diff --git a/print/templates/reports/item-label-barcode/item-label-barcode.html b/print/templates/reports/item-label-barcode/item-label-barcode.html index 224338c2f..929ce5fe2 100644 --- a/print/templates/reports/item-label-barcode/item-label-barcode.html +++ b/print/templates/reports/item-label-barcode/item-label-barcode.html @@ -17,12 +17,16 @@
- {{item.comment}} + {{ + (item.longName && item.size && item.subName) + ? `${item.longName} ${item.size} ${item.subName}` + : item.comment + }}
- {{item.producer}} + {{item.producerName || item.producerFk}}
diff --git a/print/templates/reports/item-label-barcode/sql/company.sql b/print/templates/reports/item-label-barcode/sql/company.sql index e130b4033..4047786a9 100644 --- a/print/templates/reports/item-label-barcode/sql/company.sql +++ b/print/templates/reports/item-label-barcode/sql/company.sql @@ -1,6 +1,5 @@ SELECT co.code FROM warehouse w JOIN address a ON a.id = w.addressFk - JOIN client c ON c.id = a.clientFk - JOIN company co ON co.clientFk = c.id + JOIN company co ON co.clientFk = a.clientFk WHERE w.id = ? \ No newline at end of file diff --git a/print/templates/reports/item-label-barcode/sql/item.sql b/print/templates/reports/item-label-barcode/sql/item.sql index 11ee60d1a..3cb42d139 100644 --- a/print/templates/reports/item-label-barcode/sql/item.sql +++ b/print/templates/reports/item-label-barcode/sql/item.sql @@ -6,37 +6,29 @@ WITH RECURSIVE numbers AS ( WHERE n < ? ) SELECT ROW_NUMBER() OVER() labelNum, - b.id buyFk, - b.itemFk, - b.quantity, - b.packing, - b.isPickedOff, - b.entryFk, - e.sub, - o.code origin, - COALESCE(p.`name`, p.id, '') producer, - i.name item, - i.`size`, - i.category, - i.stems, - i.inkFk, - IFNULL(CONCAT(ig.longName, ' ', ig.`size`, ' ', ig.subName), i.comment) comment, - i.typeFk, - i.isLaid, - w.code buyerName, - w.code, - s.company_name companyName, - t.shipped - FROM vn.buy b - JOIN vn.item i ON i.id = b.itemFk - LEFT JOIN vn.item ig ON ig.id = b.itemOriginalFk - LEFT JOIN edi.ekt e ON e.id = b.ektFk - JOIN vn.origin o ON o.id = i.originFk - LEFT JOIN vn.producer p ON p.id = i.producerFk - JOIN vn.itemType it ON it.id = i.typeFk - JOIN vn.worker w ON w.id = it.workerFk - LEFT JOIN edi.supplier s ON s.supplier_id = e.pro - JOIN vn.entry e2 ON e2.id = b.entryFk - JOIN vn.travel t ON t.id = e2.travelFk - JOIN numbers num - WHERE b.id = ? \ No newline at end of file + b.itemFk, + i.name item, + b.id buyFk, + b.quantity, + b.packing, + b.entryFk, + o.code origin, + p.`name` producerName, + p.id producerFk, + i.`size`, + i.category, + i.stems, + i.inkFk, + ig.longName, + ig.subName, + i.comment, + w.code buyerName + FROM vn.buy b + JOIN vn.item i ON i.id = b.itemFk + LEFT JOIN vn.item ig ON ig.id = b.itemOriginalFk + JOIN vn.origin o ON o.id = i.originFk + LEFT JOIN vn.producer p ON p.id = i.producerFk + JOIN vn.itemType it ON it.id = i.typeFk + JOIN vn.worker w ON w.id = it.workerFk + JOIN numbers num + WHERE b.id = ? \ No newline at end of file diff --git a/print/templates/reports/item-label-qr/item-label-qr.html b/print/templates/reports/item-label-qr/item-label-qr.html index 231c94818..712bd6c7d 100644 --- a/print/templates/reports/item-label-qr/item-label-qr.html +++ b/print/templates/reports/item-label-qr/item-label-qr.html @@ -71,7 +71,7 @@
- Productor: {{item.producer}} + Productor: {{item.producerName || item.producerFk}}
- {{item.comment}} + {{ + (item.longName && item.size && item.subName) + ? `${item.longName} ${item.size} ${item.subName}` + : item.comment + }}