From 999cb2dbb44361f20471532e39e52b94a4dee038 Mon Sep 17 00:00:00 2001 From: guillermo Date: Thu, 17 Oct 2024 10:08:27 +0200 Subject: [PATCH 01/24] 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 02/24] 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 03/24] 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 04/24] 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 05/24] 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 06/24] 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 07/24] 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 4bd28c62b9ffc43470ec2f883ee1d4d3b8328872 Mon Sep 17 00:00:00 2001 From: guillermo Date: Fri, 18 Oct 2024 07:35:36 +0200 Subject: [PATCH 08/24] 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 09/24] 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 10/24] 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 bf2d7541a5c956ba48a7f9a8c31553f36ce74418 Mon Sep 17 00:00:00 2001 From: guillermo Date: Mon, 21 Oct 2024 14:57:55 +0200 Subject: [PATCH 11/24] 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 12/24] 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 0af58b20bea4025736feb55ac286ec441237691a Mon Sep 17 00:00:00 2001 From: guillermo Date: Tue, 22 Oct 2024 12:02:04 +0200 Subject: [PATCH 13/24] 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 c3f8da52c61b7070ade2de36800d8c1c91f8f698 Mon Sep 17 00:00:00 2001 From: guillermo Date: Tue, 22 Oct 2024 13:43:54 +0200 Subject: [PATCH 14/24] 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 8569bec34ac139a3846837e278009844ed6cbaac Mon Sep 17 00:00:00 2001 From: guillermo Date: Thu, 24 Oct 2024 12:18:09 +0200 Subject: [PATCH 24/24] 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 1afb33c3064739c0a032e7a7b09f581b7b20e602 Mon Sep 17 00:00:00 2001 From: guillermo Date: Tue, 22 Oct 2024 15:00:16 +0200 Subject: [PATCH 15/24] 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 baec188ff5a784db066fb3f042433cfa57b9fd7d Mon Sep 17 00:00:00 2001 From: guillermo Date: Wed, 23 Oct 2024 08:23:28 +0200 Subject: [PATCH 16/24] 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 17/24] 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 18/24] 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 19/24] 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 20/24] 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 21/24] 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 22/24] 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 23/24] 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 + }}