From cfbc3692e972dc137085f3d131ed3ec258a4e129 Mon Sep 17 00:00:00 2001 From: jorgep Date: Fri, 13 Sep 2024 11:59:28 +0200 Subject: [PATCH 001/136] feat: refs #7874 clientObservationType --- .../00-addClientObservationType.sql | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 db/versions/11230-brownEucalyptus/00-addClientObservationType.sql diff --git a/db/versions/11230-brownEucalyptus/00-addClientObservationType.sql b/db/versions/11230-brownEucalyptus/00-addClientObservationType.sql new file mode 100644 index 000000000..195c11d2f --- /dev/null +++ b/db/versions/11230-brownEucalyptus/00-addClientObservationType.sql @@ -0,0 +1,18 @@ +-- Place your SQL code here +CREATE TABLE IF NOT EXISTS vn.clientObservationType( + id tinyint(3) unsigned NOT NULL AUTO_INCREMENT, + code varchar(45) NOT NULL, + description varchar(50) NOT NULL, + PRIMARY KEY (id) +); + +ALTER TABLE vn.clientObservation ADD COLUMN typeFk tinyint(3) unsigned NOT NULL; +ALTER TABLE vn.clientObservation ADD CONSTRAINT clientObservationTypeFk FOREIGN KEY (typeFk) REFERENCES vn.clientObservationType(id); + +INSERT INTO salix.ACL + SET model = 'ClientObservationType', + property = '*', + accessType = 'READ', + permission = 'ALLOW', + principalType = 'ROLE', + principalId = 'employee'; \ No newline at end of file From 1ec8d8d5a00016b67a406db79d026c99295f3598 Mon Sep 17 00:00:00 2001 From: ivanm Date: Sun, 22 Sep 2024 07:24:21 +0200 Subject: [PATCH 002/136] feat: refs #7994 update sale.originalQuantity --- db/versions/11251-navyChrysanthemum/00-firstScript.sql | 3 +++ db/versions/11251-navyChrysanthemum/01-firstScript.sql | 1 + 2 files changed, 4 insertions(+) create mode 100644 db/versions/11251-navyChrysanthemum/00-firstScript.sql create mode 100644 db/versions/11251-navyChrysanthemum/01-firstScript.sql diff --git a/db/versions/11251-navyChrysanthemum/00-firstScript.sql b/db/versions/11251-navyChrysanthemum/00-firstScript.sql new file mode 100644 index 000000000..50409c205 --- /dev/null +++ b/db/versions/11251-navyChrysanthemum/00-firstScript.sql @@ -0,0 +1,3 @@ +UPDATE sale + SET originalQuantity = quantity + WHERE originalQuantity IS NULL diff --git a/db/versions/11251-navyChrysanthemum/01-firstScript.sql b/db/versions/11251-navyChrysanthemum/01-firstScript.sql new file mode 100644 index 000000000..e3e08e0aa --- /dev/null +++ b/db/versions/11251-navyChrysanthemum/01-firstScript.sql @@ -0,0 +1 @@ +ALTER TABLE vn.sale MODIFY COLUMN originalQuantity decimal(10,2) DEFAULT 0.00 NOT NULL COMMENT 'Se utiliza para notificar a través de rocket los cambios de quantity'; \ No newline at end of file From 753f6d786661e5dbd642c261d229d58bc7047bb2 Mon Sep 17 00:00:00 2001 From: ivanm Date: Sun, 22 Sep 2024 07:27:43 +0200 Subject: [PATCH 003/136] feat: refs #7994 add schema --- db/versions/11251-navyChrysanthemum/00-firstScript.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/versions/11251-navyChrysanthemum/00-firstScript.sql b/db/versions/11251-navyChrysanthemum/00-firstScript.sql index 50409c205..801405e59 100644 --- a/db/versions/11251-navyChrysanthemum/00-firstScript.sql +++ b/db/versions/11251-navyChrysanthemum/00-firstScript.sql @@ -1,3 +1,3 @@ -UPDATE sale +UPDATE vn.sale SET originalQuantity = quantity WHERE originalQuantity IS NULL From 6ff76fd74b4bc636d42060b851ed073aa74a14c0 Mon Sep 17 00:00:00 2001 From: jorgep Date: Mon, 23 Sep 2024 14:40:38 +0200 Subject: [PATCH 004/136] feat: refs #7207 show queue in worker summary --- back/model-config.json | 6 ++++ back/models/queue-member.json | 38 ++++++++++++++++++++++++++ back/models/queue.json | 30 ++++++++++++++++++++ db/dump/fixtures.before.sql | 19 +++++++++++++ modules/account/back/models/sip.json | 9 ++++-- modules/worker/back/models/worker.json | 22 ++++++++++++++- 6 files changed, 121 insertions(+), 3 deletions(-) create mode 100644 back/models/queue-member.json create mode 100644 back/models/queue.json diff --git a/back/model-config.json b/back/model-config.json index 20bfb06bd..dca9cb761 100644 --- a/back/model-config.json +++ b/back/model-config.json @@ -175,6 +175,12 @@ "PrintConfig": { "dataSource": "vn" }, + "QueueMember": { + "dataSource": "vn" + }, + "Queue": { + "dataSource": "vn" + }, "ViaexpressConfig": { "dataSource": "vn" }, diff --git a/back/models/queue-member.json b/back/models/queue-member.json new file mode 100644 index 000000000..93ca2ebd7 --- /dev/null +++ b/back/models/queue-member.json @@ -0,0 +1,38 @@ +{ + "name": "QueueMember", + "base": "VnModel", + "options": { + "mysql": { + "table": "pbx.queueMember" + } + }, + "properties": { + "id": { + "type": "number", + "id": true + }, + "queue": { + "type": "string" + }, + "extension": { + "type": "string" + } + }, + "relations": { + "queueRelation": { + "type": "belongsTo", + "model": "Queue", + "foreignKey": "queue", + "primaryKey": "name" + } + }, + "acls": [ + { + "property": "*", + "accessType": "READ", + "principalType": "ROLE", + "principalId": "employee", + "permission": "ALLOW" + } + ] +} \ No newline at end of file diff --git a/back/models/queue.json b/back/models/queue.json new file mode 100644 index 000000000..e7ad533ea --- /dev/null +++ b/back/models/queue.json @@ -0,0 +1,30 @@ +{ + "name": "Queue", + "base": "VnModel", + "options": { + "mysql": { + "table": "pbx.queue" + } + }, + "properties": { + "id": { + "type": "number", + "id": true + }, + "description": { + "type": "string" + }, + "name": { + "type": "string" + } + }, + "acls": [ + { + "property": "*", + "accessType": "READ", + "principalType": "ROLE", + "principalId": "employee", + "permission": "ALLOW" + } + ] +} \ No newline at end of file diff --git a/db/dump/fixtures.before.sql b/db/dump/fixtures.before.sql index 514a94506..c01a7d584 100644 --- a/db/dump/fixtures.before.sql +++ b/db/dump/fixtures.before.sql @@ -3972,3 +3972,22 @@ INSERT INTO vn.accountDetailType (id, description, code) INSERT IGNORE INTO ormConfig SET id =1, selectLimit = 1000; + +INSERT INTO pbx.queueMultiConfig + SET id = 'ring', + strategy = 20, + timeout = 2, + retry = 0, + weight = 0, + maxLen = 0, + ringInUse = 0; + +INSERT IGNORE INTO pbx.queue + SET description = 'X-men', + name = '1000', + config = 1; + +INSERT IGNORE INTO pbx.queueMember + SET queue = '1000', + extension = '1010'; + diff --git a/modules/account/back/models/sip.json b/modules/account/back/models/sip.json index f2e2221b5..dbcef3b9e 100644 --- a/modules/account/back/models/sip.json +++ b/modules/account/back/models/sip.json @@ -25,7 +25,12 @@ "type": "belongsTo", "model": "VnUser", "foreignKey": "user_id" + }, + "queueMember": { + "type": "belongsTo", + "model": "QueueMember", + "foreignKey": "extension", + "primaryKey": "extension" } } -} - \ No newline at end of file +} \ No newline at end of file diff --git a/modules/worker/back/models/worker.json b/modules/worker/back/models/worker.json index b896e775b..ae10b5198 100644 --- a/modules/worker/back/models/worker.json +++ b/modules/worker/back/models/worker.json @@ -253,7 +253,27 @@ "relation": "client" }, { - "relation": "sip" + "relation": "sip", + "scope": { + "include": { + "relation": "queueMember", + "scope": { + "fields": [ + "queue", + "extension" + ], + "include": { + "relation": "queueRelation", + "scope": { + "fields": [ + "description", + "name" + ] + } + } + } + } + } } ] }, From c6a3004d1202d4065963126eb654ae95b0e8eba5 Mon Sep 17 00:00:00 2001 From: jorgep Date: Tue, 24 Sep 2024 10:15:01 +0200 Subject: [PATCH 005/136] feat: refs #7207 allocate new queue on dept change --- db/dump/fixtures.before.sql | 15 +++++++++------ db/routines/vn/triggers/business_afterUpdate.sql | 13 +++++++++++++ 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/db/dump/fixtures.before.sql b/db/dump/fixtures.before.sql index c01a7d584..8d1943667 100644 --- a/db/dump/fixtures.before.sql +++ b/db/dump/fixtures.before.sql @@ -3982,12 +3982,15 @@ INSERT INTO pbx.queueMultiConfig maxLen = 0, ringInUse = 0; -INSERT IGNORE INTO pbx.queue - SET description = 'X-men', - name = '1000', - config = 1; +INSERT INTO pbx.queue (description, name, config) + VALUES ('X-men', '1000', 1), + ('Avengers', '2000', 1); INSERT IGNORE INTO pbx.queueMember - SET queue = '1000', - extension = '1010'; + SET queue = '1000', + extension = '1010'; + +UPDATE vn.department SET pbxQueue = '1000' WHERE name = "CAMARA"; +UPDATE vn.department SET pbxQueue = '2000' WHERE name = "VENTAS"; + diff --git a/db/routines/vn/triggers/business_afterUpdate.sql b/db/routines/vn/triggers/business_afterUpdate.sql index 888308b9a..255fdd9f5 100644 --- a/db/routines/vn/triggers/business_afterUpdate.sql +++ b/db/routines/vn/triggers/business_afterUpdate.sql @@ -3,10 +3,23 @@ CREATE OR REPLACE DEFINER=`vn`@`localhost` TRIGGER `vn`.`business_afterUpdate` AFTER UPDATE ON `business` FOR EACH ROW BEGIN + DECLARE vnIsActive INT; + DECLARE vnExtension VARCHAR(10); + DECLARE vnQueue VARCHAR(10); + CALL worker_updateBusiness(NEW.workerFk); IF NOT (OLD.workerFk <=> NEW.workerFk) THEN CALL worker_updateBusiness(OLD.workerFk); END IF; + + SELECT COUNT(*) INTO vnIsActive FROM vn.worker WHERE businessFk = NEW.id; + + IF(vnIsActive) THEN + SELECT extension INTO vnExtension FROM pbx.sip WHERE user_id = NEW.workerFk COLLATE utf8mb3_general_ci; + SELECT pbxQueue INTO vnQueue FROM vn.department WHERE id = NEW.departmentFk COLLATE utf8mb3_general_ci; + + UPDATE pbx.queueMember SET queue = vnQueue WHERE extension = vnExtension; + END IF; END$$ DELIMITER ; From 02e837ebb68cc0d2c5d673f0c0b69dd16bc88d53 Mon Sep 17 00:00:00 2001 From: jorgep Date: Tue, 24 Sep 2024 15:43:33 +0200 Subject: [PATCH 006/136] feat: refs #7207 add queue on department change --- .../vn/procedures/queueMember_updateQueue.sql | 32 +++++++++++++++++++ .../vn/procedures/worker_updateBusiness.sql | 2 ++ .../vn/triggers/business_afterUpdate.sql | 17 ++++------ 3 files changed, 41 insertions(+), 10 deletions(-) create mode 100644 db/routines/vn/procedures/queueMember_updateQueue.sql diff --git a/db/routines/vn/procedures/queueMember_updateQueue.sql b/db/routines/vn/procedures/queueMember_updateQueue.sql new file mode 100644 index 000000000..b470e909c --- /dev/null +++ b/db/routines/vn/procedures/queueMember_updateQueue.sql @@ -0,0 +1,32 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`queueMember_updateQueue`( + vBusinessFk INT +) +BEGIN +/** +* Replace the queue of a worker with the queue of the new department. +* +* @param vBusinessFk business id +*/ + DECLARE vNewQueue VARCHAR(10); + DECLARE vExtension VARCHAR(10); + DECLARE vPrevQueue VARCHAR(10); + + SELECT d.pbxQueue, s.extension, qm.queue INTO vNewQueue, vExtension, vPrevQueue + FROM business b + JOIN department d ON d.id = b.departmentFk + JOIN pbx.sip s ON s.user_id = b.workerFk + LEFT JOIN pbx.queueMember qm ON qm.extension = s.extension + WHERE b.id = vBusinessFk; + + IF vNewQueue IS NULL THEN + DELETE FROM pbx.queueMember WHERE extension = vExtension COLLATE utf8_general_ci; + ELSE + IF vPrevQueue IS NULL THEN + INSERT INTO pbx.queueMember (queue, extension) VALUES (vNewQueue, vExtension); + ELSE + UPDATE pbx.queueMember SET queue = vNewQueue WHERE extension = vExtension COLLATE utf8_general_ci; + END IF; + END IF; +END$$ +DELIMITER ; \ No newline at end of file diff --git a/db/routines/vn/procedures/worker_updateBusiness.sql b/db/routines/vn/procedures/worker_updateBusiness.sql index a160c417a..43edb0416 100644 --- a/db/routines/vn/procedures/worker_updateBusiness.sql +++ b/db/routines/vn/procedures/worker_updateBusiness.sql @@ -21,6 +21,8 @@ BEGIN SET businessFk = vNewBusinessFk WHERE id = vSelf; + CALL queueMember_updateQueue(vNewBusinessFk); + IF vOldBusinessFk IS NULL THEN CALL account.account_enable(vSelf); diff --git a/db/routines/vn/triggers/business_afterUpdate.sql b/db/routines/vn/triggers/business_afterUpdate.sql index 255fdd9f5..11aeb88b6 100644 --- a/db/routines/vn/triggers/business_afterUpdate.sql +++ b/db/routines/vn/triggers/business_afterUpdate.sql @@ -3,9 +3,8 @@ CREATE OR REPLACE DEFINER=`vn`@`localhost` TRIGGER `vn`.`business_afterUpdate` AFTER UPDATE ON `business` FOR EACH ROW BEGIN - DECLARE vnIsActive INT; - DECLARE vnExtension VARCHAR(10); - DECLARE vnQueue VARCHAR(10); + DECLARE vIsActive BOOL; + DECLARE vExtension VARCHAR(10); CALL worker_updateBusiness(NEW.workerFk); @@ -13,13 +12,11 @@ BEGIN CALL worker_updateBusiness(OLD.workerFk); END IF; - SELECT COUNT(*) INTO vnIsActive FROM vn.worker WHERE businessFk = NEW.id; - - IF(vnIsActive) THEN - SELECT extension INTO vnExtension FROM pbx.sip WHERE user_id = NEW.workerFk COLLATE utf8mb3_general_ci; - SELECT pbxQueue INTO vnQueue FROM vn.department WHERE id = NEW.departmentFk COLLATE utf8mb3_general_ci; - - UPDATE pbx.queueMember SET queue = vnQueue WHERE extension = vnExtension; + IF NOT (OLD.departmentFk <=> NEW.departmentFk) THEN + SELECT COUNT(*) INTO vIsActive FROM worker WHERE businessFk = NEW.id; + IF vIsActive THEN + CALL queueMember_updateQueue(NEW.id); + END IF; END IF; END$$ DELIMITER ; From 16b059a14ad8254424a05934873d7c1e72c964d2 Mon Sep 17 00:00:00 2001 From: jorgep Date: Tue, 24 Sep 2024 15:49:45 +0200 Subject: [PATCH 007/136] refactor: refs #7207 tab --- db/routines/vn/procedures/queueMember_updateQueue.sql | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/db/routines/vn/procedures/queueMember_updateQueue.sql b/db/routines/vn/procedures/queueMember_updateQueue.sql index b470e909c..d6f2a5d1e 100644 --- a/db/routines/vn/procedures/queueMember_updateQueue.sql +++ b/db/routines/vn/procedures/queueMember_updateQueue.sql @@ -20,12 +20,16 @@ BEGIN WHERE b.id = vBusinessFk; IF vNewQueue IS NULL THEN - DELETE FROM pbx.queueMember WHERE extension = vExtension COLLATE utf8_general_ci; + DELETE FROM pbx.queueMember + WHERE extension = vExtension COLLATE utf8_general_ci; ELSE IF vPrevQueue IS NULL THEN - INSERT INTO pbx.queueMember (queue, extension) VALUES (vNewQueue, vExtension); + INSERT INTO pbx.queueMember (queue, extension) + VALUES (vNewQueue, vExtension); ELSE - UPDATE pbx.queueMember SET queue = vNewQueue WHERE extension = vExtension COLLATE utf8_general_ci; + UPDATE pbx.queueMember + SET queue = vNewQueue + WHERE extension = vExtension COLLATE utf8_general_ci; END IF; END IF; END$$ From 1c42303a75e51e5e9539f37cb938e6572e2b2a43 Mon Sep 17 00:00:00 2001 From: jorgep Date: Wed, 25 Sep 2024 09:18:10 +0200 Subject: [PATCH 008/136] chore: refs #7207 drop useless relation --- back/model-config.json | 3 --- back/models/queue.json | 30 -------------------------- modules/worker/back/models/worker.json | 11 +--------- 3 files changed, 1 insertion(+), 43 deletions(-) delete mode 100644 back/models/queue.json diff --git a/back/model-config.json b/back/model-config.json index dca9cb761..b6d304675 100644 --- a/back/model-config.json +++ b/back/model-config.json @@ -178,9 +178,6 @@ "QueueMember": { "dataSource": "vn" }, - "Queue": { - "dataSource": "vn" - }, "ViaexpressConfig": { "dataSource": "vn" }, diff --git a/back/models/queue.json b/back/models/queue.json deleted file mode 100644 index e7ad533ea..000000000 --- a/back/models/queue.json +++ /dev/null @@ -1,30 +0,0 @@ -{ - "name": "Queue", - "base": "VnModel", - "options": { - "mysql": { - "table": "pbx.queue" - } - }, - "properties": { - "id": { - "type": "number", - "id": true - }, - "description": { - "type": "string" - }, - "name": { - "type": "string" - } - }, - "acls": [ - { - "property": "*", - "accessType": "READ", - "principalType": "ROLE", - "principalId": "employee", - "permission": "ALLOW" - } - ] -} \ No newline at end of file diff --git a/modules/worker/back/models/worker.json b/modules/worker/back/models/worker.json index ae10b5198..c334c0d05 100644 --- a/modules/worker/back/models/worker.json +++ b/modules/worker/back/models/worker.json @@ -261,16 +261,7 @@ "fields": [ "queue", "extension" - ], - "include": { - "relation": "queueRelation", - "scope": { - "fields": [ - "description", - "name" - ] - } - } + ] } } } From 3e270befa5646a8521830de52cffca2b97603f16 Mon Sep 17 00:00:00 2001 From: jorgep Date: Wed, 25 Sep 2024 12:19:12 +0200 Subject: [PATCH 009/136] chore: refs #7874 refactor table --- .../00-addClientObservationType.sql | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/db/versions/11230-brownEucalyptus/00-addClientObservationType.sql b/db/versions/11230-brownEucalyptus/00-addClientObservationType.sql index 195c11d2f..05376710a 100644 --- a/db/versions/11230-brownEucalyptus/00-addClientObservationType.sql +++ b/db/versions/11230-brownEucalyptus/00-addClientObservationType.sql @@ -1,14 +1,14 @@ --- Place your SQL code here +-- vn.clientObservationType CREATE TABLE IF NOT EXISTS vn.clientObservationType( id tinyint(3) unsigned NOT NULL AUTO_INCREMENT, - code varchar(45) NOT NULL, + clientFk int(11) NOT NULL, + observationTypeFk tinyint(3) unsigned NOT NULL, description varchar(50) NOT NULL, - PRIMARY KEY (id) + PRIMARY KEY (id), + CONSTRAINT `clientFgn` FOREIGN KEY (`clientFk`) REFERENCES `client` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, + CONSTRAINT `clientObservationFgn` FOREIGN KEY (`observationTypeFk`) REFERENCES `observationType` (`id`) ON DELETE CASCADE ON UPDATE CASCADE ); -ALTER TABLE vn.clientObservation ADD COLUMN typeFk tinyint(3) unsigned NOT NULL; -ALTER TABLE vn.clientObservation ADD CONSTRAINT clientObservationTypeFk FOREIGN KEY (typeFk) REFERENCES vn.clientObservationType(id); - INSERT INTO salix.ACL SET model = 'ClientObservationType', property = '*', From 7c23acde64977267f770e773254daf55c8d34bcb Mon Sep 17 00:00:00 2001 From: jorgep Date: Thu, 26 Sep 2024 09:08:42 +0200 Subject: [PATCH 010/136] feat: refs #7874 add observationTypeFk col --- .../00-addClientObservationType.sql | 21 +++--------------- .../back/models/client-observation.json | 22 +++++++++++++------ 2 files changed, 18 insertions(+), 25 deletions(-) diff --git a/db/versions/11230-brownEucalyptus/00-addClientObservationType.sql b/db/versions/11230-brownEucalyptus/00-addClientObservationType.sql index 05376710a..699d0bea4 100644 --- a/db/versions/11230-brownEucalyptus/00-addClientObservationType.sql +++ b/db/versions/11230-brownEucalyptus/00-addClientObservationType.sql @@ -1,18 +1,3 @@ --- vn.clientObservationType -CREATE TABLE IF NOT EXISTS vn.clientObservationType( - id tinyint(3) unsigned NOT NULL AUTO_INCREMENT, - clientFk int(11) NOT NULL, - observationTypeFk tinyint(3) unsigned NOT NULL, - description varchar(50) NOT NULL, - PRIMARY KEY (id), - CONSTRAINT `clientFgn` FOREIGN KEY (`clientFk`) REFERENCES `client` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, - CONSTRAINT `clientObservationFgn` FOREIGN KEY (`observationTypeFk`) REFERENCES `observationType` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -); - -INSERT INTO salix.ACL - SET model = 'ClientObservationType', - property = '*', - accessType = 'READ', - permission = 'ALLOW', - principalType = 'ROLE', - principalId = 'employee'; \ No newline at end of file +ALTER TABLE vn.clientObservation + ADD COLUMN observationTypeFk TINYINT(3) UNSIGNED, + ADD CONSTRAINT clientObservationTypeFk FOREIGN KEY (observationTypeFk) REFERENCES vn.observationType(id); \ No newline at end of file diff --git a/modules/client/back/models/client-observation.json b/modules/client/back/models/client-observation.json index b204ebeb4..86351862d 100644 --- a/modules/client/back/models/client-observation.json +++ b/modules/client/back/models/client-observation.json @@ -1,10 +1,10 @@ { - "name": "ClientObservation", + "name": "ClientObservation", "description": "Client notes", "base": "VnModel", - "mixins": { - "Loggable": true - }, + "mixins": { + "Loggable": true + }, "options": { "mysql": { "table": "clientObservation" @@ -26,6 +26,10 @@ "created": { "type": "date", "description": "Creation date and time" + }, + "observationTypeFk": { + "type": "number", + "description": "Type of observation" } }, "relations": { @@ -44,14 +48,18 @@ "include": { "relation": "worker", "scope": { - "fields": ["id"], + "fields": [ + "id" + ], "include": { "relation": "user", "scope": { - "fields": ["nickname"] + "fields": [ + "nickname" + ] } } } } } -} +} \ No newline at end of file From 4ebda1a06ffe0bdaf67bf4b1e5ea99a6383775e2 Mon Sep 17 00:00:00 2001 From: Jon Date: Thu, 26 Sep 2024 14:06:45 +0200 Subject: [PATCH 011/136] feat: refs #7010 added filter fields to show packing type field in ticket list --- modules/ticket/back/methods/ticket/filter.js | 96 +++++++++++--------- 1 file changed, 51 insertions(+), 45 deletions(-) diff --git a/modules/ticket/back/methods/ticket/filter.js b/modules/ticket/back/methods/ticket/filter.js index 06781c3c8..b72f224bf 100644 --- a/modules/ticket/back/methods/ticket/filter.js +++ b/modules/ticket/back/methods/ticket/filter.js @@ -228,52 +228,55 @@ module.exports = Self => { stmt = new ParameterizedSQL(` CREATE OR REPLACE TEMPORARY TABLE tmp.filter (INDEX (id)) - ENGINE = MEMORY + ENGINE = InnoDB SELECT t.id, - t.shipped, - CAST(DATE(t.shipped) AS CHAR) shippedDate, - HOUR(t.shipped) shippedHour, - t.nickname, - t.refFk, - t.routeFk, - t.warehouseFk, - t.clientFk, - t.totalWithoutVat, - t.totalWithVat, - io.id invoiceOutId, - a.provinceFk, - p.name province, - w.name warehouse, - am.name agencyMode, - am.id agencyModeFk, - st.name state, - st.classColor, - wk.lastName salesPerson, - ts.stateFk stateFk, - ts.alertLevel alertLevel, - ts.code alertLevelCode, - u.name userName, - c.salesPersonFk, - z.hour zoneLanding, - HOUR(z.hour) zoneHour, - MINUTE(z.hour) zoneMinute, - z.name zoneName, - z.id zoneFk, - CAST(z.hour AS CHAR) hour, - a.nickname addressNickname - FROM ticket t - LEFT JOIN invoiceOut io ON t.refFk = io.ref - LEFT JOIN zone z ON z.id = t.zoneFk - LEFT JOIN address a ON a.id = t.addressFk - LEFT JOIN province p ON p.id = a.provinceFk - LEFT JOIN warehouse w ON w.id = t.warehouseFk - LEFT JOIN agencyMode am ON am.id = t.agencyModeFk - LEFT JOIN ticketState ts ON ts.ticketFk = t.id - LEFT JOIN state st ON st.id = ts.stateFk - LEFT JOIN client c ON c.id = t.clientFk - LEFT JOIN worker wk ON wk.id = c.salesPersonFk - LEFT JOIN account.user u ON u.id = wk.id - LEFT JOIN route r ON r.id = t.routeFk + t.shipped, + CAST(DATE(t.shipped) AS CHAR) shippedDate, + HOUR(t.shipped) shippedHour, + t.nickname, + t.refFk, + t.routeFk, + t.warehouseFk, + t.clientFk, + t.totalWithoutVat, + t.totalWithVat, + io.id invoiceOutId, + a.provinceFk, + p.name province, + w.name warehouse, + am.name agencyMode, + am.id agencyModeFk, + st.name state, + st.classColor, + wk.lastName salesPerson, + ts.stateFk stateFk, + ts.alertLevel alertLevel, + ts.code alertLevelCode, + u.name userName, + c.salesPersonFk, + z.hour zoneLanding, + HOUR(z.hour) zoneHour, + MINUTE(z.hour) zoneMinute, + z.name zoneName, + z.id zoneFk, + CAST(z.hour AS CHAR) hour, + a.nickname addressNickname, + GROUP_CONCAT(DISTINCT i.itemPackingTypeFk ORDER BY i.itemPackingTypeFk SEPARATOR ', ') packing + FROM ticket t + LEFT JOIN invoiceOut io ON t.refFk = io.ref + LEFT JOIN zone z ON z.id = t.zoneFk + LEFT JOIN address a ON a.id = t.addressFk + LEFT JOIN province p ON p.id = a.provinceFk + LEFT JOIN warehouse w ON w.id = t.warehouseFk + LEFT JOIN agencyMode am ON am.id = t.agencyModeFk + LEFT JOIN ticketState ts ON ts.ticketFk = t.id + LEFT JOIN state st ON st.id = ts.stateFk + LEFT JOIN client c ON c.id = t.clientFk + LEFT JOIN worker wk ON wk.id = c.salesPersonFk + LEFT JOIN account.user u ON u.id = wk.id + LEFT JOIN route r ON r.id = t.routeFk + LEFT JOIN sale s ON t.id = s.ticketFk + LEFT JOIN item i ON i.id = s.itemFk `); if (args.orderFk) { @@ -292,6 +295,9 @@ module.exports = Self => { } stmt.merge(conn.makeWhere(filter.where)); + stmt.merge({ + sql: `GROUP BY t.id` + }); stmts.push(stmt); stmt = new ParameterizedSQL(` From 20e894257d6366470ce0e303d88d3ef36358d4d2 Mon Sep 17 00:00:00 2001 From: jorgep Date: Thu, 26 Sep 2024 16:07:14 +0200 Subject: [PATCH 012/136] fix: refs #7874 rollback --- .../11230-brownEucalyptus/00-addClientObservationType.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/versions/11230-brownEucalyptus/00-addClientObservationType.sql b/db/versions/11230-brownEucalyptus/00-addClientObservationType.sql index 699d0bea4..cb0849888 100644 --- a/db/versions/11230-brownEucalyptus/00-addClientObservationType.sql +++ b/db/versions/11230-brownEucalyptus/00-addClientObservationType.sql @@ -1,3 +1,3 @@ ALTER TABLE vn.clientObservation - ADD COLUMN observationTypeFk TINYINT(3) UNSIGNED, + ADD COLUMN observationTypeFk TINYINT(3) UNSIGNED NOT NULL, ADD CONSTRAINT clientObservationTypeFk FOREIGN KEY (observationTypeFk) REFERENCES vn.observationType(id); \ No newline at end of file From f3bf0b7432723721c2b933e07ad0e07114002bcf Mon Sep 17 00:00:00 2001 From: jorgep Date: Thu, 26 Sep 2024 17:20:50 +0200 Subject: [PATCH 013/136] feat: refs #7874 validate required field --- loopback/locale/es.json | 5 +++-- modules/client/back/models/client-observation.js | 9 ++++++--- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/loopback/locale/es.json b/loopback/locale/es.json index ba4b90cb5..01b7ee1ee 100644 --- a/loopback/locale/es.json +++ b/loopback/locale/es.json @@ -379,5 +379,6 @@ "The entry does not have stickers": "La entrada no tiene etiquetas", "Too many records": "Demasiados registros", "This buyer has already made a reservation for this date": "Este comprador ya ha hecho una reserva para esta fecha", - "No valid travel thermograph found": "No se encontró un termógrafo válido" -} + "No valid travel thermograph found": "No se encontró un termógrafo válido", + "type cannot be blank": "Se debe rellenar el tipo" +} \ No newline at end of file diff --git a/modules/client/back/models/client-observation.js b/modules/client/back/models/client-observation.js index e34eedca9..d022a440a 100644 --- a/modules/client/back/models/client-observation.js +++ b/modules/client/back/models/client-observation.js @@ -1,8 +1,11 @@ module.exports = function(Self) { - Self.validate('text', isEnabled, {message: 'Description cannot be blank'}); - function isEnabled(err) { + Self.validate('text', function(err) { if (!this.text) err(); - } + }, {message: 'Description cannot be blank'}); + + Self.validate('observationTypeFk', function(err) { + if (!this.observationTypeFk) err(); + }, {message: 'type cannot be blank'}); Self.observe('before save', function(ctx, next) { ctx.instance.created = Date(); From b547858820d4e42de35105611a64557f3ee678e3 Mon Sep 17 00:00:00 2001 From: Jon Date: Fri, 27 Sep 2024 08:28:12 +0200 Subject: [PATCH 014/136] perf: refs #7010 showing field correctly --- modules/ticket/back/methods/ticket/filter.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/ticket/back/methods/ticket/filter.js b/modules/ticket/back/methods/ticket/filter.js index b72f224bf..37150e6e9 100644 --- a/modules/ticket/back/methods/ticket/filter.js +++ b/modules/ticket/back/methods/ticket/filter.js @@ -261,7 +261,7 @@ module.exports = Self => { z.id zoneFk, CAST(z.hour AS CHAR) hour, a.nickname addressNickname, - GROUP_CONCAT(DISTINCT i.itemPackingTypeFk ORDER BY i.itemPackingTypeFk SEPARATOR ', ') packing + GROUP_CONCAT(DISTINCT i.itemPackingTypeFk ORDER BY i.itemPackingTypeFk SEPARATOR ',') packing FROM ticket t LEFT JOIN invoiceOut io ON t.refFk = io.ref LEFT JOIN zone z ON z.id = t.zoneFk From b55db4bdc00f0ab0e6e20604e268c7d3a0e4e73f Mon Sep 17 00:00:00 2001 From: Jon Date: Mon, 30 Sep 2024 14:09:57 +0200 Subject: [PATCH 015/136] feat: refs #7010 added subquery to avoid using group by in sql --- modules/ticket/back/methods/ticket/filter.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/modules/ticket/back/methods/ticket/filter.js b/modules/ticket/back/methods/ticket/filter.js index 37150e6e9..d7e77603b 100644 --- a/modules/ticket/back/methods/ticket/filter.js +++ b/modules/ticket/back/methods/ticket/filter.js @@ -229,7 +229,7 @@ module.exports = Self => { CREATE OR REPLACE TEMPORARY TABLE tmp.filter (INDEX (id)) ENGINE = InnoDB - SELECT t.id, + SELECT DISTINCT t.id, t.shipped, CAST(DATE(t.shipped) AS CHAR) shippedDate, HOUR(t.shipped) shippedHour, @@ -261,7 +261,11 @@ module.exports = Self => { z.id zoneFk, CAST(z.hour AS CHAR) hour, a.nickname addressNickname, - GROUP_CONCAT(DISTINCT i.itemPackingTypeFk ORDER BY i.itemPackingTypeFk SEPARATOR ',') packing + (SELECT GROUP_CONCAT(DISTINCT i2.itemPackingTypeFk ORDER BY i2.itemPackingTypeFk SEPARATOR ',') + FROM sale s2 + JOIN item i2 ON i2.id = s2.itemFk + WHERE s2.ticketFk = t.id + ) AS packing FROM ticket t LEFT JOIN invoiceOut io ON t.refFk = io.ref LEFT JOIN zone z ON z.id = t.zoneFk @@ -275,8 +279,6 @@ module.exports = Self => { LEFT JOIN worker wk ON wk.id = c.salesPersonFk LEFT JOIN account.user u ON u.id = wk.id LEFT JOIN route r ON r.id = t.routeFk - LEFT JOIN sale s ON t.id = s.ticketFk - LEFT JOIN item i ON i.id = s.itemFk `); if (args.orderFk) { @@ -295,9 +297,7 @@ module.exports = Self => { } stmt.merge(conn.makeWhere(filter.where)); - stmt.merge({ - sql: `GROUP BY t.id` - }); + stmts.push(stmt); stmt = new ParameterizedSQL(` From bbcf71619ce2f80be8dcfb8c1dff604d9b88651a Mon Sep 17 00:00:00 2001 From: sergiodt Date: Wed, 2 Oct 2024 09:56:36 +0200 Subject: [PATCH 016/136] fix: refs #6861 duplicatedTicketsInReserve --- .../vn/procedures/collection_getTickets.sql | 7 +-- .../itemShelvingSale_addBySale copy.sql | 48 +++++++++++++++++++ 2 files changed, 52 insertions(+), 3 deletions(-) create mode 100644 db/routines/vn/procedures/itemShelvingSale_addBySale copy.sql diff --git a/db/routines/vn/procedures/collection_getTickets.sql b/db/routines/vn/procedures/collection_getTickets.sql index 0f675041a..1391c27d4 100644 --- a/db/routines/vn/procedures/collection_getTickets.sql +++ b/db/routines/vn/procedures/collection_getTickets.sql @@ -46,7 +46,7 @@ BEGIN LEFT JOIN observation ob ON ob.ticketFk = t.id WHERE t.id = vParamFk AND t.shipped >= vYesterday - UNION ALL + UNION SELECT t.id ticketFk, IF(NOT(vItemPackingTypeFk <=> 'V'), cc.code, CONCAT(SUBSTRING('ABCDEFGH', tc.wagon, 1), '-', tc.`level`)) `level`, am.name agencyName, @@ -67,7 +67,7 @@ BEGIN LEFT JOIN vn.worker w ON w.id = c.salesPersonFk LEFT JOIN observation ob ON ob.ticketFk = t.id WHERE tc.collectionFk = vParamFk - UNION ALL + UNION SELECT sg.ticketFk, NULL `level`, am.name agencyName, @@ -84,6 +84,7 @@ BEGIN LEFT JOIN observation ob ON ob.ticketFk = t.id LEFT JOIN vn.client c ON c.id = t.clientFk WHERE sc.id = vParamFk - AND t.shipped >= vYesterday; + AND t.shipped >= vYesterday + GROUP BY ticketFk; END$$ DELIMITER ; diff --git a/db/routines/vn/procedures/itemShelvingSale_addBySale copy.sql b/db/routines/vn/procedures/itemShelvingSale_addBySale copy.sql new file mode 100644 index 000000000..7da1a82fa --- /dev/null +++ b/db/routines/vn/procedures/itemShelvingSale_addBySale copy.sql @@ -0,0 +1,48 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`itemShelvingSale_deleteAdded`( + vSelf INT(11) +) +proc: BEGIN +/** + * Borra una reservea devolviendo la cantidad al itemShelving + * + * @param vSelf Identificador del itemShelvingSale + */ + DECLARE vSaleFk INT; + DECLARE vHasSalesPicked BOOL; + + DECLARE EXIT HANDLER FOR SQLEXCEPTION + BEGIN + ROLLBACK; + RESIGNAL; + END; + + SELECT iss.saleFk INTO vSaleFk + FROM itemShelvingSale iss + JOIN sale s ON s.id = iss.saleFk + WHERE iss.id = vSelf AND s.isAdded ; + + IF vSaleFk IS NULL THEN + CALL util.throw('The sale can not be deleted'); + END IF; + + SELECT COUNT(*) INTO vHasSalesPicked + FROM itemShelvingSale + WHERE saleFk = vSaleFk AND isPicked; + + IF vHasSalesPicked THEN + CALL util.throw('The sale can not be deleted with sales picked'); + END IF; + + START TRANSACTION; + + UPDATE itemShelvingSale iss + JOIN itemShelving ish ON ish.id = iss.itemShelvingFk + SET ish.available = ish.available + iss.quantity + WHERE iss.saleFk = vSaleFk; + + DELETE FROM sale WHERE id = vSaleFk; + + COMMIT; +END$$ +DELIMITER ; \ No newline at end of file From fd877119a97c89660b012ceedc866ff23ef4240e Mon Sep 17 00:00:00 2001 From: jorgep Date: Thu, 3 Oct 2024 10:34:01 +0200 Subject: [PATCH 017/136] chore: refs #7874 drop useless locale --- loopback/locale/es.json | 1 - 1 file changed, 1 deletion(-) diff --git a/loopback/locale/es.json b/loopback/locale/es.json index 9308fd4ec..6c4833a77 100644 --- a/loopback/locale/es.json +++ b/loopback/locale/es.json @@ -381,6 +381,5 @@ "The entry does not have stickers": "La entrada no tiene etiquetas", "This buyer has already made a reservation for this date": "Este comprador ya ha hecho una reserva para esta fecha", "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" } \ No newline at end of file From 2071518f579e43aa07089ed83b3a2daba24986fa Mon Sep 17 00:00:00 2001 From: jorgep Date: Thu, 3 Oct 2024 10:35:04 +0200 Subject: [PATCH 018/136] fix: refs #7874 rollback --- loopback/locale/es.json | 1 + 1 file changed, 1 insertion(+) diff --git a/loopback/locale/es.json b/loopback/locale/es.json index 6c4833a77..9308fd4ec 100644 --- a/loopback/locale/es.json +++ b/loopback/locale/es.json @@ -381,5 +381,6 @@ "The entry does not have stickers": "La entrada no tiene etiquetas", "This buyer has already made a reservation for this date": "Este comprador ya ha hecho una reserva para esta fecha", "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" } \ No newline at end of file From 5416d382555164e2c58cc9d80da7f39a3dbee2e2 Mon Sep 17 00:00:00 2001 From: jorgep Date: Thu, 3 Oct 2024 15:25:56 +0200 Subject: [PATCH 019/136] feat: refs #7874 redirect to lilium --- modules/client/front/note/index/index.html | 31 ---------------------- modules/client/front/note/index/index.js | 7 ++--- 2 files changed, 4 insertions(+), 34 deletions(-) diff --git a/modules/client/front/note/index/index.html b/modules/client/front/note/index/index.html index 634a9c3ce..e69de29bb 100644 --- a/modules/client/front/note/index/index.html +++ b/modules/client/front/note/index/index.html @@ -1,31 +0,0 @@ - - - - -
- - {{::note.worker.user.nickname}} - {{::note.created | date:'dd/MM/yyyy HH:mm'}} - - - {{::note.text}} - -
-
-
- - - diff --git a/modules/client/front/note/index/index.js b/modules/client/front/note/index/index.js index ed15db671..1610bdaab 100644 --- a/modules/client/front/note/index/index.js +++ b/modules/client/front/note/index/index.js @@ -5,9 +5,10 @@ import './style.scss'; export default class Controller extends Section { constructor($element, $) { super($element, $); - this.filter = { - order: 'created DESC', - }; + } + async $onInit() { + this.$state.go('home'); + window.location.href = await this.vnApp.getUrl(`customer/${this.$params.id}/notes`); } } From 3638e9abb6f125fb04c7478083ad5d0a2daaa4a7 Mon Sep 17 00:00:00 2001 From: jorgep Date: Thu, 3 Oct 2024 16:50:31 +0200 Subject: [PATCH 020/136] refactor: refs #7207 simplify code --- .../vn/procedures/queueMember_updateQueue.sql | 36 ++++++++----------- 1 file changed, 15 insertions(+), 21 deletions(-) diff --git a/db/routines/vn/procedures/queueMember_updateQueue.sql b/db/routines/vn/procedures/queueMember_updateQueue.sql index d6f2a5d1e..b330eed66 100644 --- a/db/routines/vn/procedures/queueMember_updateQueue.sql +++ b/db/routines/vn/procedures/queueMember_updateQueue.sql @@ -1,36 +1,30 @@ DELIMITER $$ + CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`queueMember_updateQueue`( vBusinessFk INT ) BEGIN -/** -* Replace the queue of a worker with the queue of the new department. -* -* @param vBusinessFk business id -*/ + /** + * Elimina la entrada de la cola anterior y luego inserta la nueva para un trabajador. + * + * @param vBusinessFk ID del negocio + */ DECLARE vNewQueue VARCHAR(10); DECLARE vExtension VARCHAR(10); DECLARE vPrevQueue VARCHAR(10); - SELECT d.pbxQueue, s.extension, qm.queue INTO vNewQueue, vExtension, vPrevQueue + SELECT d.pbxQueue, s.extension, qm.queue + INTO vNewQueue, vExtension, vPrevQueue FROM business b JOIN department d ON d.id = b.departmentFk - JOIN pbx.sip s ON s.user_id = b.workerFk + JOIN pbx.sip s ON s.user_id = b.workerFk LEFT JOIN pbx.queueMember qm ON qm.extension = s.extension - WHERE b.id = vBusinessFk; + WHERE b.id = vBusinessFk; - IF vNewQueue IS NULL THEN - DELETE FROM pbx.queueMember - WHERE extension = vExtension COLLATE utf8_general_ci; - ELSE - IF vPrevQueue IS NULL THEN - INSERT INTO pbx.queueMember (queue, extension) - VALUES (vNewQueue, vExtension); - ELSE - UPDATE pbx.queueMember - SET queue = vNewQueue - WHERE extension = vExtension COLLATE utf8_general_ci; - END IF; - END IF; + DELETE FROM pbx.queueMember + WHERE extension = vExtension COLLATE utf8_general_ci; + + INSERT IGNORE INTO pbx.queueMember (queue, extension) + VALUES (vNewQueue, vExtension); END$$ DELIMITER ; \ No newline at end of file From 324875ec1f779f049b996b821418470378a627b0 Mon Sep 17 00:00:00 2001 From: sergiodt Date: Fri, 4 Oct 2024 10:42:33 +0200 Subject: [PATCH 021/136] fix: refs #6861 deleteAdded --- .../vn/procedures/collection_getTickets.sql | 5 ++--- ...copy.sql => itemShelvingSale_deleteAdded.sql} | 16 ++++++++-------- 2 files changed, 10 insertions(+), 11 deletions(-) rename db/routines/vn/procedures/{itemShelvingSale_addBySale copy.sql => itemShelvingSale_deleteAdded.sql} (85%) diff --git a/db/routines/vn/procedures/collection_getTickets.sql b/db/routines/vn/procedures/collection_getTickets.sql index 1391c27d4..fed7a3eb6 100644 --- a/db/routines/vn/procedures/collection_getTickets.sql +++ b/db/routines/vn/procedures/collection_getTickets.sql @@ -21,9 +21,8 @@ BEGIN SELECT tob.ticketFk, tob.description FROM vn.ticketObservation tob JOIN vn.ticketCollection tc ON tc.ticketFk = tob.ticketFk - LEFT JOIN vn.observationType ot ON ot.id = tob.observationTypeFk - WHERE ot.`code` = 'itemPicker' - AND tc.collectionFk = vParamFk + JOIN vn.observationType ot ON ot.id = tob.observationTypeFk AND ot.`code` = 'itemPicker' + WHERE tc.collectionFk = vParamFk OR tc.ticketFk = vParamFk ) SELECT t.id ticketFk, IF(!(vItemPackingTypeFk <=> 'V'), cc.code, CONCAT(SUBSTRING('ABCDEFGH', tc.wagon, 1), '-', tc.`level`)) `level`, diff --git a/db/routines/vn/procedures/itemShelvingSale_addBySale copy.sql b/db/routines/vn/procedures/itemShelvingSale_deleteAdded.sql similarity index 85% rename from db/routines/vn/procedures/itemShelvingSale_addBySale copy.sql rename to db/routines/vn/procedures/itemShelvingSale_deleteAdded.sql index 7da1a82fa..0de523127 100644 --- a/db/routines/vn/procedures/itemShelvingSale_addBySale copy.sql +++ b/db/routines/vn/procedures/itemShelvingSale_deleteAdded.sql @@ -12,15 +12,17 @@ proc: BEGIN DECLARE vHasSalesPicked BOOL; DECLARE EXIT HANDLER FOR SQLEXCEPTION - BEGIN - ROLLBACK; - RESIGNAL; - END; + BEGIN + ROLLBACK; + RESIGNAL; + END; + + START TRANSACTION; SELECT iss.saleFk INTO vSaleFk FROM itemShelvingSale iss JOIN sale s ON s.id = iss.saleFk - WHERE iss.id = vSelf AND s.isAdded ; + WHERE iss.id = vSelf AND s.isAdded; IF vSaleFk IS NULL THEN CALL util.throw('The sale can not be deleted'); @@ -31,11 +33,9 @@ proc: BEGIN WHERE saleFk = vSaleFk AND isPicked; IF vHasSalesPicked THEN - CALL util.throw('The sale can not be deleted with sales picked'); + CALL util.throw('A sale with picked sales cannot be deleted'); END IF; - START TRANSACTION; - UPDATE itemShelvingSale iss JOIN itemShelving ish ON ish.id = iss.itemShelvingFk SET ish.available = ish.available + iss.quantity From 5d7d9f8d9e4e9c4e5a6562c49b6a48adc45e038e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Andr=C3=A9s?= Date: Fri, 4 Oct 2024 13:07:54 +0200 Subject: [PATCH 022/136] fix: refs #6861 deleteAdded --- db/routines/vn/procedures/itemShelvingSale_deleteAdded.sql | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/db/routines/vn/procedures/itemShelvingSale_deleteAdded.sql b/db/routines/vn/procedures/itemShelvingSale_deleteAdded.sql index 0de523127..9b15e82d1 100644 --- a/db/routines/vn/procedures/itemShelvingSale_deleteAdded.sql +++ b/db/routines/vn/procedures/itemShelvingSale_deleteAdded.sql @@ -22,9 +22,10 @@ proc: BEGIN SELECT iss.saleFk INTO vSaleFk FROM itemShelvingSale iss JOIN sale s ON s.id = iss.saleFk - WHERE iss.id = vSelf AND s.isAdded; + WHERE iss.id = vSelf AND s.isAdded + FOR UPDATE; - IF vSaleFk IS NULL THEN + IF vSaleFk IS NULL THEN CALL util.throw('The sale can not be deleted'); END IF; @@ -32,7 +33,7 @@ proc: BEGIN FROM itemShelvingSale WHERE saleFk = vSaleFk AND isPicked; - IF vHasSalesPicked THEN + IF vHasSalesPicked THEN CALL util.throw('A sale with picked sales cannot be deleted'); END IF; From 52e8bac168830e72f9df7e5be41cbaf9893df6ea Mon Sep 17 00:00:00 2001 From: sergiodt Date: Fri, 4 Oct 2024 13:34:04 +0200 Subject: [PATCH 023/136] fix: refs #7524 backSuppliersPackaging --- .../back/methods/supplier/getWithPackaging.js | 40 +++++++++++++++++++ .../supplier/specs/getWithPackaging.spec.js | 32 +++++++++++++++ modules/supplier/back/models/supplier.js | 1 + 3 files changed, 73 insertions(+) create mode 100644 modules/supplier/back/methods/supplier/getWithPackaging.js create mode 100644 modules/supplier/back/methods/supplier/specs/getWithPackaging.spec.js diff --git a/modules/supplier/back/methods/supplier/getWithPackaging.js b/modules/supplier/back/methods/supplier/getWithPackaging.js new file mode 100644 index 000000000..658b0696c --- /dev/null +++ b/modules/supplier/back/methods/supplier/getWithPackaging.js @@ -0,0 +1,40 @@ +module.exports = Self => { + Self.remoteMethod('getWithPackaging', { + description: 'Returns the list of suppliers with an entry of type packaging', + accessType: 'READ', + returns: { + type: 'object', + root: true + }, + http: { + path: `/getWithPackaging`, + verb: 'GET' + }, + nolimit: true + }); + Self.getWithPackaging = async options => { + const models = Self.app.models; + const myOptions = {}; + + if (typeof options == 'object') + Object.assign(myOptions, options); + + const entries = await models.Entry.find({ + where: {typeFk: 'packaging'}, + include: { + relation: 'supplier', + scope: { + fields: ['id', 'name'] + } + }, + fields: {supplierFk: true} + }, myOptions); + + const result = entries.map(item => ({ + id: item.supplier().id, + name: item.supplier().name + })); + return Array.from(new Map(result.map(entry => [entry.id, entry])).values()); + }; +}; + diff --git a/modules/supplier/back/methods/supplier/specs/getWithPackaging.spec.js b/modules/supplier/back/methods/supplier/specs/getWithPackaging.spec.js new file mode 100644 index 000000000..f73d20f84 --- /dev/null +++ b/modules/supplier/back/methods/supplier/specs/getWithPackaging.spec.js @@ -0,0 +1,32 @@ +const {models} = require('vn-loopback/server/server'); + +describe('Supplier getWithPackaging()', () => { + it('should return a list of suppliers with an entry of type packaging', async() => { + const typeFk = 'packaging'; + + const tx = await models.Supplier.beginTransaction({}); + const myOptions = {transaction: tx}; + + try { + const entry = await models.Entry.findOne( + { + where: { + id: 1 + }, + myOptions + }); + + await entry.updateAttributes({ + typeFk: typeFk, + }); + + const result = await models.Supplier.getWithPackaging(myOptions); + + expect(result.length).toEqual(1); + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); +}); diff --git a/modules/supplier/back/models/supplier.js b/modules/supplier/back/models/supplier.js index 2d3ffef3e..7e6908d57 100644 --- a/modules/supplier/back/models/supplier.js +++ b/modules/supplier/back/models/supplier.js @@ -12,6 +12,7 @@ module.exports = Self => { require('../methods/supplier/campaignMetricsEmail')(Self); require('../methods/supplier/newSupplier')(Self); require('../methods/supplier/getItemsPackaging')(Self); + require('../methods/supplier/getWithPackaging')(Self); Self.validatesPresenceOf('name', { message: 'The social name cannot be empty' From 9f97de021a79d96a2dfeb017496d4b38bc6e3182 Mon Sep 17 00:00:00 2001 From: jorgep Date: Fri, 4 Oct 2024 16:04:31 +0200 Subject: [PATCH 024/136] chore: refs #7874 fix e2e --- e2e/paths/02-client/08_add_notes.spec.js | 42 ------------------------ e2e/paths/02-client/21_defaulter.spec.js | 15 ++------- 2 files changed, 3 insertions(+), 54 deletions(-) delete mode 100644 e2e/paths/02-client/08_add_notes.spec.js diff --git a/e2e/paths/02-client/08_add_notes.spec.js b/e2e/paths/02-client/08_add_notes.spec.js deleted file mode 100644 index d0c483a11..000000000 --- a/e2e/paths/02-client/08_add_notes.spec.js +++ /dev/null @@ -1,42 +0,0 @@ -import selectors from '../../helpers/selectors'; -import getBrowser from '../../helpers/puppeteer'; - -describe('Client Add notes path', () => { - let browser; - let page; - beforeAll(async() => { - browser = await getBrowser(); - page = browser.page; - await page.loginAndModule('employee', 'client'); - await page.accessToSearchResult('Bruce Banner'); - await page.accessToSection('client.card.note.index'); - }); - - afterAll(async() => { - await browser.close(); - }); - - it(`should reach the notes index`, async() => { - await page.waitForState('client.card.note.index'); - }); - - it(`should click on the add note button`, async() => { - await page.waitToClick(selectors.clientNotes.addNoteFloatButton); - await page.waitForState('client.card.note.create'); - }); - - it(`should create a note`, async() => { - await page.waitForSelector(selectors.clientNotes.note); - await page.type(`${selectors.clientNotes.note} textarea`, 'Meeting with Black Widow 21st 9am'); - await page.waitToClick(selectors.clientNotes.saveButton); - const message = await page.waitForSnackbar(); - - expect(message.text).toContain('Data saved!'); - }); - - it('should confirm the note was created', async() => { - const result = await page.waitToGetProperty(selectors.clientNotes.firstNoteText, 'innerText'); - - expect(result).toEqual('Meeting with Black Widow 21st 9am'); - }); -}); diff --git a/e2e/paths/02-client/21_defaulter.spec.js b/e2e/paths/02-client/21_defaulter.spec.js index 2bb3d6254..01f394bc8 100644 --- a/e2e/paths/02-client/21_defaulter.spec.js +++ b/e2e/paths/02-client/21_defaulter.spec.js @@ -28,12 +28,12 @@ describe('Client defaulter path', () => { const salesPersonName = await page.waitToGetProperty(selectors.clientDefaulter.firstSalesPersonName, 'innerText'); - expect(clientName).toEqual('Bruce Banner'); - expect(salesPersonName).toEqual('developer'); + expect(clientName).toEqual('Ororo Munroe'); + expect(salesPersonName).toEqual('salesperson'); }); it('should first observation not changed', async() => { - const expectedObservation = 'Meeting with Black Widow 21st 9am'; + const expectedObservation = 'Madness, as you know, is like gravity, all it takes is a little push'; const result = await page.waitToGetProperty(selectors.clientDefaulter.firstObservation, 'value'); expect(result).toContain(expectedObservation); @@ -62,13 +62,4 @@ describe('Client defaulter path', () => { await page.write(selectors.clientDefaulter.observation, 'My new observation'); await page.waitToClick(selectors.clientDefaulter.saveButton); }); - - it('should first observation changed', async() => { - const message = await page.waitForSnackbar(); - await page.waitForSelector(selectors.clientDefaulter.firstObservation); - const result = await page.waitToGetProperty(selectors.clientDefaulter.firstObservation, 'value'); - - expect(message.text).toContain('Observation saved!'); - expect(result).toContain('My new observation'); - }); }); From e0d0b6696393fa7132321dfdc4518ca82d9187cf Mon Sep 17 00:00:00 2001 From: jorgep Date: Fri, 4 Oct 2024 16:48:38 +0200 Subject: [PATCH 025/136] feat: refs #7207 add transaction --- .../vn/procedures/queueMember_updateQueue.sql | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/db/routines/vn/procedures/queueMember_updateQueue.sql b/db/routines/vn/procedures/queueMember_updateQueue.sql index b330eed66..c3207e663 100644 --- a/db/routines/vn/procedures/queueMember_updateQueue.sql +++ b/db/routines/vn/procedures/queueMember_updateQueue.sql @@ -11,14 +11,18 @@ BEGIN */ DECLARE vNewQueue VARCHAR(10); DECLARE vExtension VARCHAR(10); - DECLARE vPrevQueue VARCHAR(10); + DECLARE exit handler FOR SQLEXCEPTION + BEGIN + ROLLBACK; + END; - SELECT d.pbxQueue, s.extension, qm.queue - INTO vNewQueue, vExtension, vPrevQueue + START TRANSACTION; + + SELECT d.pbxQueue, s.extension + INTO vNewQueue, vExtension FROM business b JOIN department d ON d.id = b.departmentFk JOIN pbx.sip s ON s.user_id = b.workerFk - LEFT JOIN pbx.queueMember qm ON qm.extension = s.extension WHERE b.id = vBusinessFk; DELETE FROM pbx.queueMember @@ -26,5 +30,7 @@ BEGIN INSERT IGNORE INTO pbx.queueMember (queue, extension) VALUES (vNewQueue, vExtension); + + COMMIT; END$$ DELIMITER ; \ No newline at end of file From e90d48c7774a2ad504bce6cc698c1cffe5178c45 Mon Sep 17 00:00:00 2001 From: sergiodt Date: Mon, 7 Oct 2024 08:00:34 +0200 Subject: [PATCH 026/136] fix: refs #7524 backSuppliersPackaging --- modules/supplier/back/methods/supplier/getWithPackaging.js | 7 ++++++- .../back/methods/supplier/specs/getWithPackaging.spec.js | 1 + 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/modules/supplier/back/methods/supplier/getWithPackaging.js b/modules/supplier/back/methods/supplier/getWithPackaging.js index 658b0696c..07e563412 100644 --- a/modules/supplier/back/methods/supplier/getWithPackaging.js +++ b/modules/supplier/back/methods/supplier/getWithPackaging.js @@ -15,12 +15,17 @@ module.exports = Self => { Self.getWithPackaging = async options => { const models = Self.app.models; const myOptions = {}; + const oneYearAgo = new Date(); + oneYearAgo.setFullYear(oneYearAgo.getFullYear() - 1); if (typeof options == 'object') Object.assign(myOptions, options); const entries = await models.Entry.find({ - where: {typeFk: 'packaging'}, + where: { + typeFk: 'packaging', + created: {gte: oneYearAgo} + }, include: { relation: 'supplier', scope: { diff --git a/modules/supplier/back/methods/supplier/specs/getWithPackaging.spec.js b/modules/supplier/back/methods/supplier/specs/getWithPackaging.spec.js index f73d20f84..bd30d7437 100644 --- a/modules/supplier/back/methods/supplier/specs/getWithPackaging.spec.js +++ b/modules/supplier/back/methods/supplier/specs/getWithPackaging.spec.js @@ -18,6 +18,7 @@ describe('Supplier getWithPackaging()', () => { await entry.updateAttributes({ typeFk: typeFk, + created: new Date() }); const result = await models.Supplier.getWithPackaging(myOptions); From de769efc0fe5a37bf2ec18e4b31d6dd7f05a3251 Mon Sep 17 00:00:00 2001 From: Pako Date: Mon, 7 Oct 2024 09:05:03 +0200 Subject: [PATCH 027/136] feat: refs #8075 autoupdating --- db/routines/vn/triggers/itemShelving_beforeUpdate.sql | 3 +++ 1 file changed, 3 insertions(+) diff --git a/db/routines/vn/triggers/itemShelving_beforeUpdate.sql b/db/routines/vn/triggers/itemShelving_beforeUpdate.sql index fabdf8efb..e22713a58 100644 --- a/db/routines/vn/triggers/itemShelving_beforeUpdate.sql +++ b/db/routines/vn/triggers/itemShelving_beforeUpdate.sql @@ -9,5 +9,8 @@ BEGIN SET NEW.userFk = account.myUser_getId(); END IF; + IF NEW.shelvingFk <> OLD.shelvingFk THEN + SET NEW.isMoving = FALSE; + END IF; END$$ DELIMITER ; From e105fba227f1828b3d957623434580f75cc3c4f5 Mon Sep 17 00:00:00 2001 From: Pako Date: Mon, 7 Oct 2024 13:46:56 +0200 Subject: [PATCH 028/136] feat: refs #8075 itemShelving new field movingState --- db/routines/vn/triggers/itemShelving_beforeUpdate.sql | 2 +- db/versions/11285-orangeErica/00-firstScript.sql | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) create mode 100644 db/versions/11285-orangeErica/00-firstScript.sql diff --git a/db/routines/vn/triggers/itemShelving_beforeUpdate.sql b/db/routines/vn/triggers/itemShelving_beforeUpdate.sql index e22713a58..53f85de01 100644 --- a/db/routines/vn/triggers/itemShelving_beforeUpdate.sql +++ b/db/routines/vn/triggers/itemShelving_beforeUpdate.sql @@ -10,7 +10,7 @@ BEGIN END IF; IF NEW.shelvingFk <> OLD.shelvingFk THEN - SET NEW.isMoving = FALSE; + SET NEW.movingState = NULL; END IF; END$$ DELIMITER ; diff --git a/db/versions/11285-orangeErica/00-firstScript.sql b/db/versions/11285-orangeErica/00-firstScript.sql new file mode 100644 index 000000000..c13571f3a --- /dev/null +++ b/db/versions/11285-orangeErica/00-firstScript.sql @@ -0,0 +1,3 @@ +-- Place your SQL code here +ALTER TABLE vn.itemShelving DROP COLUMN IF EXISTS isMoving; +ALTER TABLE vn.itemShelving ADD IF NOT EXISTS movingState ENUM('selected','printed') NULL; From 22719820fde2af9852ccef33994d8be752e1ae10 Mon Sep 17 00:00:00 2001 From: Pako Date: Mon, 7 Oct 2024 14:21:18 +0200 Subject: [PATCH 029/136] feat: refs #8069 overStocking protocol --- .../orderRow_updateOverstocking.sql | 52 +++++++++++++++++++ .../procedures/order_confirmWithUser.sql | 15 ++++++ .../hedera/triggers/orderRow_afterInsert.sql | 10 ++++ .../11287-azureRaphis/00-firstScript.sql | 3 ++ 4 files changed, 80 insertions(+) create mode 100644 db/routines/hedera/procedures/orderRow_updateOverstocking.sql create mode 100644 db/routines/hedera/triggers/orderRow_afterInsert.sql create mode 100644 db/versions/11287-azureRaphis/00-firstScript.sql diff --git a/db/routines/hedera/procedures/orderRow_updateOverstocking.sql b/db/routines/hedera/procedures/orderRow_updateOverstocking.sql new file mode 100644 index 000000000..e919ff922 --- /dev/null +++ b/db/routines/hedera/procedures/orderRow_updateOverstocking.sql @@ -0,0 +1,52 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`vn`@`localhost` +PROCEDURE `hedera`.`orderRow_updateOverstocking`(vOrderFk INT) +BEGIN +/** +* Set amount = 0 to avoid overbooking sales +* +* @param vOrderFk hedera.order.id +*/ + DECLARE vCalcFk INT; + DECLARE vDone BOOL; + DECLARE vWarehouseFk INT; + + DECLARE cWarehouses CURSOR FOR + SELECT DISTINCT warehouseFk + FROM orderRow + WHERE orderFk = vOrderFk + AND shipment = util.VN_CURDATE(); + + DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; + + DECLARE EXIT HANDLER FOR SQLEXCEPTION + BEGIN + ROLLBACK; + RESIGNAL; + END; + + OPEN cWarehouses; + checking: LOOP + SET vDone = FALSE; + + FETCH cWarehouses INTO vWarehouseFk; + + IF vDone THEN + LEAVE checking; + END IF; + + CALL cache.available_refresh(vCalcFk, FALSE, vWarehouseFk, util.VN_CURDATE()); + + UPDATE orderRow r + JOIN `order` o ON o.id = r.orderFk + JOIN orderConfig oc + JOIN cache.available a ON a.calc_id = vCalcFk AND a.item_id = r.itemFk + SET r.amount = 0 + WHERE ADDTIME(o.rowUpdated, oc.reserveTime) < util.VN_NOW() + AND a.available <= 0 + AND r.warehouseFk = vWarehouseFk + AND r.orderFk = vOrderFk; + END LOOP; + CLOSE cWarehouses; +END$$ +DELIMITER ; \ No newline at end of file diff --git a/db/routines/hedera/procedures/order_confirmWithUser.sql b/db/routines/hedera/procedures/order_confirmWithUser.sql index 2b033b704..a0c5c5667 100644 --- a/db/routines/hedera/procedures/order_confirmWithUser.sql +++ b/db/routines/hedera/procedures/order_confirmWithUser.sql @@ -13,6 +13,7 @@ BEGIN */ DECLARE vHasRows BOOL; DECLARE vDone BOOL; + DECLARE vHas0Amount BOOL; DECLARE vWarehouseFk INT; DECLARE vShipment DATE; DECLARE vShipmentDayEnd DATETIME; @@ -97,6 +98,20 @@ BEGIN SELECT employeeFk INTO vUserFk FROM orderConfig; END IF; + CALL orderRow_updateOverstocking(vSelf); + + -- Check if any product has a quantity of 0 + SELECT EXISTS ( + SELECT id + FROM orderRow + WHERE orderFk = vSelf + AND amount = 0 + ) INTO vHas0Amount; + + IF vHas0Amount THEN + CALL util.throw('Remove lines with quantity = 0 before confirming'); + END IF; + START TRANSACTION; CALL order_checkEditable(vSelf); diff --git a/db/routines/hedera/triggers/orderRow_afterInsert.sql b/db/routines/hedera/triggers/orderRow_afterInsert.sql new file mode 100644 index 000000000..525e5d4d2 --- /dev/null +++ b/db/routines/hedera/triggers/orderRow_afterInsert.sql @@ -0,0 +1,10 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `hedera`.`orderRow_afterInsert` + AFTER INSERT ON `orderRow` + FOR EACH ROW +BEGIN + UPDATE `order` + SET rowUpdated = NOW() + WHERE id = NEW.orderFk; +END$$ +DELIMITER ; \ No newline at end of file diff --git a/db/versions/11287-azureRaphis/00-firstScript.sql b/db/versions/11287-azureRaphis/00-firstScript.sql new file mode 100644 index 000000000..77d60eb40 --- /dev/null +++ b/db/versions/11287-azureRaphis/00-firstScript.sql @@ -0,0 +1,3 @@ +-- Place your SQL code here +ALTER TABLE hedera.`order` ADD IF NOT EXISTS rowUpdated DATETIME NULL + COMMENT 'Timestamp for last updated record in orderRow table'; \ No newline at end of file From 33a4061058c234ed29e55abca6c8758ec24ba29f Mon Sep 17 00:00:00 2001 From: Pako Date: Mon, 7 Oct 2024 14:24:55 +0200 Subject: [PATCH 030/136] feat: refs #8069 8069-overStocking --- .../orderRow_updateOverstocking.sql | 52 +++++++++++++++++++ .../hedera/triggers/orderRow_afterInsert.sql | 10 ++++ .../11288-purpleFern/00-firstScript.sql | 3 ++ 3 files changed, 65 insertions(+) create mode 100644 db/routines/hedera/procedures/orderRow_updateOverstocking.sql create mode 100644 db/routines/hedera/triggers/orderRow_afterInsert.sql create mode 100644 db/versions/11288-purpleFern/00-firstScript.sql diff --git a/db/routines/hedera/procedures/orderRow_updateOverstocking.sql b/db/routines/hedera/procedures/orderRow_updateOverstocking.sql new file mode 100644 index 000000000..e919ff922 --- /dev/null +++ b/db/routines/hedera/procedures/orderRow_updateOverstocking.sql @@ -0,0 +1,52 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`vn`@`localhost` +PROCEDURE `hedera`.`orderRow_updateOverstocking`(vOrderFk INT) +BEGIN +/** +* Set amount = 0 to avoid overbooking sales +* +* @param vOrderFk hedera.order.id +*/ + DECLARE vCalcFk INT; + DECLARE vDone BOOL; + DECLARE vWarehouseFk INT; + + DECLARE cWarehouses CURSOR FOR + SELECT DISTINCT warehouseFk + FROM orderRow + WHERE orderFk = vOrderFk + AND shipment = util.VN_CURDATE(); + + DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; + + DECLARE EXIT HANDLER FOR SQLEXCEPTION + BEGIN + ROLLBACK; + RESIGNAL; + END; + + OPEN cWarehouses; + checking: LOOP + SET vDone = FALSE; + + FETCH cWarehouses INTO vWarehouseFk; + + IF vDone THEN + LEAVE checking; + END IF; + + CALL cache.available_refresh(vCalcFk, FALSE, vWarehouseFk, util.VN_CURDATE()); + + UPDATE orderRow r + JOIN `order` o ON o.id = r.orderFk + JOIN orderConfig oc + JOIN cache.available a ON a.calc_id = vCalcFk AND a.item_id = r.itemFk + SET r.amount = 0 + WHERE ADDTIME(o.rowUpdated, oc.reserveTime) < util.VN_NOW() + AND a.available <= 0 + AND r.warehouseFk = vWarehouseFk + AND r.orderFk = vOrderFk; + END LOOP; + CLOSE cWarehouses; +END$$ +DELIMITER ; \ No newline at end of file diff --git a/db/routines/hedera/triggers/orderRow_afterInsert.sql b/db/routines/hedera/triggers/orderRow_afterInsert.sql new file mode 100644 index 000000000..525e5d4d2 --- /dev/null +++ b/db/routines/hedera/triggers/orderRow_afterInsert.sql @@ -0,0 +1,10 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `hedera`.`orderRow_afterInsert` + AFTER INSERT ON `orderRow` + FOR EACH ROW +BEGIN + UPDATE `order` + SET rowUpdated = NOW() + WHERE id = NEW.orderFk; +END$$ +DELIMITER ; \ No newline at end of file diff --git a/db/versions/11288-purpleFern/00-firstScript.sql b/db/versions/11288-purpleFern/00-firstScript.sql new file mode 100644 index 000000000..77d60eb40 --- /dev/null +++ b/db/versions/11288-purpleFern/00-firstScript.sql @@ -0,0 +1,3 @@ +-- Place your SQL code here +ALTER TABLE hedera.`order` ADD IF NOT EXISTS rowUpdated DATETIME NULL + COMMENT 'Timestamp for last updated record in orderRow table'; \ No newline at end of file From 20836d734c6fdcdd8714e9d2f6b8fc6c4675f2b3 Mon Sep 17 00:00:00 2001 From: Pako Date: Mon, 7 Oct 2024 14:25:46 +0200 Subject: [PATCH 031/136] fix: refs #8069 order_confirmWithUser --- .../hedera/procedures/order_confirmWithUser.sql | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/db/routines/hedera/procedures/order_confirmWithUser.sql b/db/routines/hedera/procedures/order_confirmWithUser.sql index 2b033b704..a0c5c5667 100644 --- a/db/routines/hedera/procedures/order_confirmWithUser.sql +++ b/db/routines/hedera/procedures/order_confirmWithUser.sql @@ -13,6 +13,7 @@ BEGIN */ DECLARE vHasRows BOOL; DECLARE vDone BOOL; + DECLARE vHas0Amount BOOL; DECLARE vWarehouseFk INT; DECLARE vShipment DATE; DECLARE vShipmentDayEnd DATETIME; @@ -97,6 +98,20 @@ BEGIN SELECT employeeFk INTO vUserFk FROM orderConfig; END IF; + CALL orderRow_updateOverstocking(vSelf); + + -- Check if any product has a quantity of 0 + SELECT EXISTS ( + SELECT id + FROM orderRow + WHERE orderFk = vSelf + AND amount = 0 + ) INTO vHas0Amount; + + IF vHas0Amount THEN + CALL util.throw('Remove lines with quantity = 0 before confirming'); + END IF; + START TRANSACTION; CALL order_checkEditable(vSelf); From 952f8f3dfcb6976b98d33ba3ab5da5286f8de632 Mon Sep 17 00:00:00 2001 From: alexm Date: Mon, 7 Oct 2024 15:14:03 +0200 Subject: [PATCH 032/136] feat(Docuware): refs #8066 use oath --- back/methods/docuware/core.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/back/methods/docuware/core.js b/back/methods/docuware/core.js index 74d922236..760909aa3 100644 --- a/back/methods/docuware/core.js +++ b/back/methods/docuware/core.js @@ -8,12 +8,22 @@ module.exports = Self => { * @return {object} - The headers */ Self.getOptions = async() => { - const docuwareConfig = await Self.app.models.DocuwareConfig.findOne(); + const {url, username, password} = await Self.app.models.DocuwareConfig.findOne(); + const {IdentityServiceUrl} = await axios.get(`${url}/Home/IdentityServiceInfo`); + const {token_endpoint} = await axios.get(`${IdentityServiceUrl}/.well-known/openid-configuration`); + const {access_token} = await axios.post(token_endpoint, { + grant_type: 'password', + scope: 'docuware.platform', + client_id: 'docuware.platform.net.client', + username, // falta añadirlos + password // falta añadirlos + }); + const headers = { headers: { 'Accept': 'application/json', 'Content-Type': 'application/json', - 'Cookie': docuwareConfig.cookie + 'access_token': access_token } }; From d164cccee511a6cb9246ecf2a647b51b6d55f182 Mon Sep 17 00:00:00 2001 From: sergiodt Date: Mon, 7 Oct 2024 16:14:16 +0200 Subject: [PATCH 033/136] fix: refs #6861 assignCollection --- back/methods/collection/assignCollection.js | 11 +- .../vn/procedures/collection_getAssigned.sql | 171 +++++++++++------- 2 files changed, 114 insertions(+), 68 deletions(-) diff --git a/back/methods/collection/assignCollection.js b/back/methods/collection/assignCollection.js index 2ff37ab59..2a7ec9ad5 100644 --- a/back/methods/collection/assignCollection.js +++ b/back/methods/collection/assignCollection.js @@ -19,8 +19,15 @@ module.exports = Self => { if (typeof options == 'object') Object.assign(myOptions, options); - const [info, info2, [{'@vCollectionFk': collectionFk}]] = await Self.rawSql( - 'CALL vn.collection_getAssigned(?, @vCollectionFk);SELECT @vCollectionFk', [userId], myOptions); + + const randStr = Math.random().toString(36).substring(3); + const result = await Self.rawSql(` + CALL vn.collection_getAssigned(?, @vCollectionFk); + SELECT @vCollectionFk ? + `, [userId, randStr], myOptions); + + const collectionFk = result.find(item => item[0]?.[randStr] !== undefined)?.[0]?.[randStr]; + if (!collectionFk) throw new UserError('There are not picking tickets'); await Self.rawSql('CALL vn.collection_printSticker(?, NULL)', [collectionFk], myOptions); diff --git a/db/routines/vn/procedures/collection_getAssigned.sql b/db/routines/vn/procedures/collection_getAssigned.sql index 518e2dd7b..7151129bf 100644 --- a/db/routines/vn/procedures/collection_getAssigned.sql +++ b/db/routines/vn/procedures/collection_getAssigned.sql @@ -5,100 +5,139 @@ CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`collection_getAssigne ) BEGIN /** - * Comprueba si existen colecciones libres que se ajustan al perfil del usuario - * y le asigna la más antigua. - * Añade un registro al semillero de colecciones y hace la reserva para la colección - * + * Comprueba si existen colecciones libres que se ajustan + * al perfil del usuario y le asigna la más antigua. + * Añade un registro al semillero de colecciones. + * * @param vUserFk Id de usuario * @param vCollectionFk Id de colección */ DECLARE vHasTooMuchCollections BOOL; - DECLARE vItemPackingTypeFk VARCHAR(1); - DECLARE vWarehouseFk INT; - DECLARE vLockName VARCHAR(215); - DECLARE vLockTime INT DEFAULT 30; + DECLARE vDone BOOL DEFAULT FALSE; + DECLARE vCollectionWorker INT; + DECLARE vMaxNotAssignedCollectionLifeTime TIME; + + DECLARE vCollections CURSOR FOR + WITH collections AS ( + SELECT tc.collectionFk, + SUM(sv.volume) volume, + c.saleTotalCount, + c.itemPackingTypeFk, + c.trainFk, + c.warehouseFk, + c.wagons + FROM vn.ticketCollection tc + JOIN vn.collection c ON c.id = tc.collectionFk + JOIN vn.saleVolume sv ON sv.ticketFk = tc.ticketFk + WHERE c.workerFk IS NULL + AND sv.shipped >= util.VN_CURDATE() + GROUP BY tc.collectionFk + ) SELECT c.collectionFk + FROM collections c + JOIN vn.operator o + WHERE o.workerFk = vUserFk + AND (c.saleTotalCount <= o.linesLimit OR o.linesLimit IS NULL) + AND (c.itemPackingTypeFk = o.itemPackingTypeFk OR o.itemPackingTypeFk IS NULL) + AND o.numberOfWagons = c.wagons + AND o.trainFk = c.trainFk + AND o.warehouseFk = c.warehouseFk; + + DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; + -- Si hay colecciones sin terminar, sale del proceso DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN - IF vLockName IS NOT NULL THEN - DO RELEASE_LOCK(vLockName); - END IF; - + ROLLBACK; RESIGNAL; END; - -- Si hay colecciones sin terminar, sale del proceso CALL collection_get(vUserFk); - SELECT (pc.maxNotReadyCollections - COUNT(*)) <= 0, - pc.collection_assign_lockname - INTO vHasTooMuchCollections, - vLockName - FROM tmp.collection c - JOIN productionConfig pc; + SELECT (pc.maxNotReadyCollections - COUNT(*)) <= 0, pc.maxNotAssignedCollectionLifeTime + INTO vHasTooMuchCollections, vMaxNotAssignedCollectionLifeTime + FROM productionConfig pc + LEFT JOIN tmp.collection ON TRUE; DROP TEMPORARY TABLE tmp.collection; IF vHasTooMuchCollections THEN - CALL util.throw('There are pending collections'); - END IF; - - SELECT warehouseFk, itemPackingTypeFk - INTO vWarehouseFk, vItemPackingTypeFk - FROM operator - WHERE workerFk = vUserFk; - - SET vLockName = CONCAT_WS('/', - vLockName, - vWarehouseFk, - vItemPackingTypeFk - ); - - IF NOT GET_LOCK(vLockName, vLockTime) THEN - CALL util.throw(CONCAT('Cannot get lock: ', vLockName)); + CALL util.throw('Hay colecciones pendientes'); END IF; -- Se eliminan las colecciones sin asignar que estan obsoletas - INSERT INTO ticketTracking(stateFk, ticketFk) - SELECT s.id, tc.ticketFk - FROM collection c - JOIN ticketCollection tc ON tc.collectionFk = c.id - JOIN state s ON s.code = 'PRINTED_AUTO' - JOIN productionConfig pc - WHERE c.workerFk IS NULL - AND TIMEDIFF(util.VN_NOW(), c.created) > pc.maxNotAssignedCollectionLifeTime; - DELETE c - FROM collection c - JOIN productionConfig pc - WHERE c.workerFk IS NULL - AND TIMEDIFF(util.VN_NOW(), c.created) > pc.maxNotAssignedCollectionLifeTime; + INSERT INTO ticketTracking(stateFk, ticketFk) + SELECT s.id, tc.ticketFk + FROM `collection` c + JOIN ticketCollection tc ON tc.collectionFk = c.id + JOIN `state` s ON s.code = 'PRINTED_AUTO' + WHERE c.workerFk IS NULL + AND TIMEDIFF(util.VN_NOW(), c.created) > vMaxNotAssignedCollectionLifeTime; + + DELETE FROM `collection` + WHERE workerFk IS NULL + AND TIMEDIFF(util.VN_NOW(), created) > vMaxNotAssignedCollectionLifeTime; -- Se añade registro al semillero - INSERT INTO collectionHotbed - SET userFk = vUserFk; + + INSERT INTO collectionHotbed(userFk) VALUES(vUserFk); -- Comprueba si hay colecciones disponibles que se ajustan a su configuracion - SELECT MIN(c.id) INTO vCollectionFk - FROM collection c - JOIN operator o ON (o.itemPackingTypeFk = c.itemPackingTypeFk - OR c.itemPackingTypeFk IS NULL) - AND o.numberOfWagons = c.wagons - AND o.trainFk = c.trainFk - AND o.warehouseFk = c.warehouseFk - AND c.workerFk IS NULL - WHERE o.workerFk = vUserFk; + + OPEN vCollections; + l: LOOP + SET vDone = FALSE; + FETCH vCollections INTO vCollectionFk; + + IF vDone THEN + LEAVE l; + END IF; + + BEGIN + DECLARE EXIT HANDLER FOR SQLEXCEPTION + BEGIN + ROLLBACK; + SET vCollectionFk = NULL; + RESIGNAL; + END; + + START TRANSACTION; + + SELECT workerFk INTO vCollectionWorker + FROM `collection` + WHERE id = vCollectionFk FOR UPDATE; + + IF vCollectionWorker IS NULL THEN + UPDATE `collection` + SET workerFk = vUserFk + WHERE id = vCollectionFk; + + COMMIT; + LEAVE l; + END IF; + + ROLLBACK; + END; + END LOOP; + CLOSE vCollections; IF vCollectionFk IS NULL THEN CALL collection_new(vUserFk, vCollectionFk); + + START TRANSACTION; + + SELECT workerFk INTO vCollectionWorker + FROM `collection` + WHERE id = vCollectionFk FOR UPDATE; + + IF vCollectionWorker IS NULL THEN + UPDATE `collection` + SET workerFk = vUserFk + WHERE id = vCollectionFk; + END IF; + + COMMIT; END IF; - - UPDATE collection - SET workerFk = vUserFk - WHERE id = vCollectionFk; - CALL itemShelvingSale_addByCollection(vCollectionFk); - - DO RELEASE_LOCK(vLockName); END$$ DELIMITER ; \ No newline at end of file From 330c1f3de69f1e41caa19f1cf02aee7c02060e3e Mon Sep 17 00:00:00 2001 From: jorgep Date: Mon, 7 Oct 2024 17:50:36 +0200 Subject: [PATCH 034/136] chore: refs #7207 drop transaction --- db/routines/vn/procedures/queueMember_updateQueue.sql | 7 ------- 1 file changed, 7 deletions(-) diff --git a/db/routines/vn/procedures/queueMember_updateQueue.sql b/db/routines/vn/procedures/queueMember_updateQueue.sql index c3207e663..5af44da4f 100644 --- a/db/routines/vn/procedures/queueMember_updateQueue.sql +++ b/db/routines/vn/procedures/queueMember_updateQueue.sql @@ -12,11 +12,6 @@ BEGIN DECLARE vNewQueue VARCHAR(10); DECLARE vExtension VARCHAR(10); DECLARE exit handler FOR SQLEXCEPTION - BEGIN - ROLLBACK; - END; - - START TRANSACTION; SELECT d.pbxQueue, s.extension INTO vNewQueue, vExtension @@ -30,7 +25,5 @@ BEGIN INSERT IGNORE INTO pbx.queueMember (queue, extension) VALUES (vNewQueue, vExtension); - - COMMIT; END$$ DELIMITER ; \ No newline at end of file From 023842ac33a75a016f29930d85d77e290656c3c8 Mon Sep 17 00:00:00 2001 From: guillermo Date: Tue, 8 Oct 2024 08:33:04 +0200 Subject: [PATCH 035/136] feat: refs #7994 comment changes --- db/versions/11251-navyChrysanthemum/00-firstScript.sql | 2 ++ db/versions/11251-navyChrysanthemum/01-firstScript.sql | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/db/versions/11251-navyChrysanthemum/00-firstScript.sql b/db/versions/11251-navyChrysanthemum/00-firstScript.sql index 801405e59..6ec0a66bb 100644 --- a/db/versions/11251-navyChrysanthemum/00-firstScript.sql +++ b/db/versions/11251-navyChrysanthemum/00-firstScript.sql @@ -1,3 +1,5 @@ +/* UPDATE vn.sale SET originalQuantity = quantity WHERE originalQuantity IS NULL +*/ diff --git a/db/versions/11251-navyChrysanthemum/01-firstScript.sql b/db/versions/11251-navyChrysanthemum/01-firstScript.sql index e3e08e0aa..c942e0400 100644 --- a/db/versions/11251-navyChrysanthemum/01-firstScript.sql +++ b/db/versions/11251-navyChrysanthemum/01-firstScript.sql @@ -1 +1 @@ -ALTER TABLE vn.sale MODIFY COLUMN originalQuantity decimal(10,2) DEFAULT 0.00 NOT NULL COMMENT 'Se utiliza para notificar a través de rocket los cambios de quantity'; \ No newline at end of file +-- ALTER TABLE vn.sale MODIFY COLUMN originalQuantity decimal(10,2) DEFAULT 0.00 NOT NULL COMMENT 'Se utiliza para notificar a través de rocket los cambios de quantity'; \ No newline at end of file From b4dc5276ddf9f16678cbdc4664b890d563d6e263 Mon Sep 17 00:00:00 2001 From: carlossa Date: Tue, 8 Oct 2024 08:36:17 +0200 Subject: [PATCH 036/136] fix: refs #7986 create fk --- db/versions/11290-blackOrchid/00-firstScript.sql | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 db/versions/11290-blackOrchid/00-firstScript.sql diff --git a/db/versions/11290-blackOrchid/00-firstScript.sql b/db/versions/11290-blackOrchid/00-firstScript.sql new file mode 100644 index 000000000..e573e9e32 --- /dev/null +++ b/db/versions/11290-blackOrchid/00-firstScript.sql @@ -0,0 +1,6 @@ + +ALTER TABLE `vn`.`worker` +ADD COLUMN `motoFk` INT(11) UNSIGNED DEFAULT NULL; + +ALTER TABLE `vn`.`worker` +ADD CONSTRAINT `worker_machineFk` FOREIGN KEY (`motoFk`) REFERENCES `machine` (`id`) ON UPDATE CASCADE ON DELETE SET NULL; From 9695fea48f30207dffe9897993af2446acb23b9a Mon Sep 17 00:00:00 2001 From: alexm Date: Tue, 8 Oct 2024 12:05:19 +0200 Subject: [PATCH 037/136] feat(Docuware): refs #8066 add username and password --- back/methods/docuware/core.js | 25 ++++++++++--------- back/models/docuware-config.json | 17 ++++++------- .../11291-purpleChico/00-firstScript.sql | 2 ++ 3 files changed, 22 insertions(+), 22 deletions(-) create mode 100644 db/versions/11291-purpleChico/00-firstScript.sql diff --git a/back/methods/docuware/core.js b/back/methods/docuware/core.js index 760909aa3..9545cd878 100644 --- a/back/methods/docuware/core.js +++ b/back/methods/docuware/core.js @@ -9,15 +9,16 @@ module.exports = Self => { */ Self.getOptions = async() => { const {url, username, password} = await Self.app.models.DocuwareConfig.findOne(); - const {IdentityServiceUrl} = await axios.get(`${url}/Home/IdentityServiceInfo`); - const {token_endpoint} = await axios.get(`${IdentityServiceUrl}/.well-known/openid-configuration`); - const {access_token} = await axios.post(token_endpoint, { + const {data: {IdentityServiceUrl}} = await axios.get(`${url}/Home/IdentityServiceInfo`); + const {data: {token_endpoint}} = await axios.get(`${IdentityServiceUrl}/.well-known/openid-configuration`); + const data = await axios.post(token_endpoint, JSON.stringify({ grant_type: 'password', scope: 'docuware.platform', client_id: 'docuware.platform.net.client', - username, // falta añadirlos - password // falta añadirlos - }); + username, + password + })); + console.log('data: ', data); const headers = { headers: { @@ -42,8 +43,8 @@ module.exports = Self => { * @return {number} - The fileCabinet id */ Self.getDialog = async(code, action, fileCabinetId) => { - if (!process.env.NODE_ENV) - return Math.floor(Math.random() + 100); + // if (!process.env.NODE_ENV) + // return Math.floor(Math.random() + 100); const docuwareInfo = await Self.app.models.Docuware.findOne({ where: { @@ -69,8 +70,8 @@ module.exports = Self => { * @return {number} - The fileCabinet id */ Self.getFileCabinet = async code => { - if (!process.env.NODE_ENV) - return Math.floor(Math.random() + 100); + // if (!process.env.NODE_ENV) + // return Math.floor(Math.random() + 100); const options = await Self.getOptions(); const docuwareInfo = await Self.app.models.Docuware.findOne({ @@ -95,7 +96,7 @@ module.exports = Self => { * @return {object} - The data */ Self.get = async(code, filter, parse) => { - if (!process.env.NODE_ENV) return; + // if (!process.env.NODE_ENV) return; const options = await Self.getOptions(); const fileCabinetId = await Self.getFileCabinet(code); @@ -118,7 +119,7 @@ module.exports = Self => { * @return {object} - The data */ Self.getById = async(code, id, parse) => { - if (!process.env.NODE_ENV) return; + // if (!process.env.NODE_ENV) return; const docuwareInfo = await Self.app.models.Docuware.findOne({ fields: ['findById'], diff --git a/back/models/docuware-config.json b/back/models/docuware-config.json index 9d06c4874..244ae2790 100644 --- a/back/models/docuware-config.json +++ b/back/models/docuware-config.json @@ -18,15 +18,12 @@ }, "cookie": { "type": "string" + }, + "username": { + "type": "string" + }, + "password": { + "type": "string" } - }, - "acls": [ - { - "property": "*", - "accessType": "*", - "principalType": "ROLE", - "principalId": "$everyone", - "permission": "ALLOW" - } - ] + } } diff --git a/db/versions/11291-purpleChico/00-firstScript.sql b/db/versions/11291-purpleChico/00-firstScript.sql new file mode 100644 index 000000000..db66c4c98 --- /dev/null +++ b/db/versions/11291-purpleChico/00-firstScript.sql @@ -0,0 +1,2 @@ +ALTER TABLE vn.docuwareConfig ADD IF NOT EXISTS username varchar(100) NULL; +ALTER TABLE vn.docuwareConfig ADD IF NOT EXISTS password varchar(100) NULL; From 02adc6473a985038c2f28c8ae705e5bf0c475705 Mon Sep 17 00:00:00 2001 From: alexm Date: Tue, 8 Oct 2024 12:22:47 +0200 Subject: [PATCH 038/136] fix: duplicate variable --- db/routines/hedera/procedures/order_confirmWithUser.sql | 1 - 1 file changed, 1 deletion(-) diff --git a/db/routines/hedera/procedures/order_confirmWithUser.sql b/db/routines/hedera/procedures/order_confirmWithUser.sql index 690e7ff34..6e4087ad8 100644 --- a/db/routines/hedera/procedures/order_confirmWithUser.sql +++ b/db/routines/hedera/procedures/order_confirmWithUser.sql @@ -14,7 +14,6 @@ BEGIN DECLARE vHasRows BOOL; DECLARE vHas0Amount BOOL; DECLARE vDone BOOL; - DECLARE vHas0Amount BOOL; DECLARE vWarehouseFk INT; DECLARE vShipment DATE; DECLARE vShipmentDayEnd DATETIME; From d497ffc781c68e5be4a060ee442ab3ffeca6dd5b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Andr=C3=A9s?= Date: Tue, 8 Oct 2024 13:32:57 +0000 Subject: [PATCH 039/136] Actualizar modules/ticket/back/methods/ticket/closure.js --- modules/ticket/back/methods/ticket/closure.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/modules/ticket/back/methods/ticket/closure.js b/modules/ticket/back/methods/ticket/closure.js index a75596bac..945406ab4 100644 --- a/modules/ticket/back/methods/ticket/closure.js +++ b/modules/ticket/back/methods/ticket/closure.js @@ -22,6 +22,8 @@ module.exports = async function(ctx, Self, tickets, options) { const failedtickets = []; for (const ticket of tickets) { try { + await Self.rawSql(`CALL util.debugAdd('invoicingTicket', ?)`, [ticket.id], {userId}); + await Self.app.models.InvoiceOut.getSerial(ticket.clientFk, ticket.companyFk, ticket.addressFk, 'quick'); await Self.rawSql( `CALL vn.ticket_closeByTicket(?)`, @@ -149,6 +151,11 @@ module.exports = async function(ctx, Self, tickets, options) { myOptions); } } catch (error) { + await Self.rawSql(` + INSERT INTO util.debug (variable, value) + VALUES ('invoicingTicketError', ?) + `, [ticket.id + ' - ' + error]); + if (error.responseCode == 450) { await invalidEmail(ticket); continue; From 39e808bca764d2283994b18758413a6882e44283 Mon Sep 17 00:00:00 2001 From: carlossa Date: Tue, 8 Oct 2024 16:06:38 +0200 Subject: [PATCH 040/136] fix: refs #7986 fix model --- db/versions/11290-blackOrchid/00-firstScript.sql | 9 +++------ modules/worker/back/models/operator.json | 14 +++++++++++--- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/db/versions/11290-blackOrchid/00-firstScript.sql b/db/versions/11290-blackOrchid/00-firstScript.sql index e573e9e32..e0c0e391c 100644 --- a/db/versions/11290-blackOrchid/00-firstScript.sql +++ b/db/versions/11290-blackOrchid/00-firstScript.sql @@ -1,6 +1,3 @@ - -ALTER TABLE `vn`.`worker` -ADD COLUMN `motoFk` INT(11) UNSIGNED DEFAULT NULL; - -ALTER TABLE `vn`.`worker` -ADD CONSTRAINT `worker_machineFk` FOREIGN KEY (`motoFk`) REFERENCES `machine` (`id`) ON UPDATE CASCADE ON DELETE SET NULL; +ALTER TABLE `vn`.`operator` +ADD COLUMN `machineFk` int(11) DEFAULT NULL, +ADD CONSTRAINT `operator_machine_FK` FOREIGN KEY (`machineFk`) REFERENCES `vn`.`machine` (`id`) ON DELETE SET NULL ON UPDATE CASCADE; diff --git a/modules/worker/back/models/operator.json b/modules/worker/back/models/operator.json index d4832bccf..9933babc6 100644 --- a/modules/worker/back/models/operator.json +++ b/modules/worker/back/models/operator.json @@ -30,7 +30,10 @@ "isOnReservationMode": { "type": "boolean", "required": true - } + }, + "machineFk": { + "type": "number" + } }, "relations": { "sector": { @@ -53,6 +56,11 @@ "model": "ItemPackingType", "foreignKey": "itemPackingTypeFk", "primaryKey": "code" - } + }, + "machine": { + "type": "belongsTo", + "model": "Machine", + "foreignKey": "machineFk" + } } -} \ No newline at end of file +} From 3cf7591206eb6ee02c3c3ab846f9e2e49d377dde Mon Sep 17 00:00:00 2001 From: alexm Date: Tue, 8 Oct 2024 17:03:27 +0200 Subject: [PATCH 041/136] fix(closeAll): not use transaction --- modules/ticket/back/methods/ticket/closeAll.js | 2 +- modules/ticket/back/methods/ticket/closure.js | 14 ++++++++++---- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/modules/ticket/back/methods/ticket/closeAll.js b/modules/ticket/back/methods/ticket/closeAll.js index 143c0a3f0..8869f9464 100644 --- a/modules/ticket/back/methods/ticket/closeAll.js +++ b/modules/ticket/back/methods/ticket/closeAll.js @@ -54,7 +54,7 @@ module.exports = Self => { JOIN country co ON co.id = p.countryFk LEFT JOIN account.emailUser eu ON eu.userFk = c.salesPersonFk WHERE (al.code = 'PACKED' OR (am.code = 'refund' AND al.code <> 'delivered')) - AND DATE(t.shipped) BETWEEN ? - INTERVAL 2 DAY AND util.dayEnd(?) + AND DATE(t.shipped) BETWEEN ? - INTERVAL 7 DAY AND util.dayEnd(?) AND t.refFk IS NULL GROUP BY t.id `, [toDate, toDate]); diff --git a/modules/ticket/back/methods/ticket/closure.js b/modules/ticket/back/methods/ticket/closure.js index a75596bac..892c1ddc6 100644 --- a/modules/ticket/back/methods/ticket/closure.js +++ b/modules/ticket/back/methods/ticket/closure.js @@ -12,16 +12,18 @@ module.exports = async function(ctx, Self, tickets, options) { Object.assign(myOptions, options); let tx; - if (!myOptions.transaction) { - tx = await Self.beginTransaction({}); - myOptions.transaction = tx; - } + // if (!myOptions.transaction) { + // tx = await Self.beginTransaction({}); + // myOptions.transaction = tx; + // } if (tickets.length == 0) return; const failedtickets = []; for (const ticket of tickets) { try { + await Self.rawSql(`CALL util.debugAdd('invoicingTicket', ?)`, [ticket.id], {userId}); + await Self.app.models.InvoiceOut.getSerial(ticket.clientFk, ticket.companyFk, ticket.addressFk, 'quick'); await Self.rawSql( `CALL vn.ticket_closeByTicket(?)`, @@ -149,6 +151,10 @@ module.exports = async function(ctx, Self, tickets, options) { myOptions); } } catch (error) { + await Self.rawSql(` + INSERT INTO util.debug (variable, value) + VALUES ('invoicingTicketError', ?) + `, [ticket.id + ' - ' + error]); if (error.responseCode == 450) { await invalidEmail(ticket); continue; From 040304d04f5e587b77b1235733d3d914e3ee589b Mon Sep 17 00:00:00 2001 From: alexm Date: Tue, 8 Oct 2024 17:10:19 +0200 Subject: [PATCH 042/136] fix: merge --- modules/ticket/back/methods/ticket/closure.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/modules/ticket/back/methods/ticket/closure.js b/modules/ticket/back/methods/ticket/closure.js index 4797d47da..d20c83304 100644 --- a/modules/ticket/back/methods/ticket/closure.js +++ b/modules/ticket/back/methods/ticket/closure.js @@ -155,10 +155,7 @@ module.exports = async function(ctx, Self, tickets, options) { INSERT INTO util.debug (variable, value) VALUES ('invoicingTicketError', ?) `, [ticket.id + ' - ' + error]); -<<<<<<< HEAD -======= ->>>>>>> 087818e39d86256ae1e166112b0f648a7a0ff239 if (error.responseCode == 450) { await invalidEmail(ticket); continue; From 5eda0af20f84f609fe9d992ca45d788c605822fe Mon Sep 17 00:00:00 2001 From: Pako Date: Wed, 9 Oct 2024 07:24:34 +0200 Subject: [PATCH 043/136] feat: refs #8075 itemShelvingMoving --- db/routines/vn/triggers/itemShelving_beforeUpdate.sql | 3 +++ db/versions/11294-azureFern/00-firstScript.sql | 3 +++ 2 files changed, 6 insertions(+) create mode 100644 db/versions/11294-azureFern/00-firstScript.sql diff --git a/db/routines/vn/triggers/itemShelving_beforeUpdate.sql b/db/routines/vn/triggers/itemShelving_beforeUpdate.sql index fabdf8efb..53f85de01 100644 --- a/db/routines/vn/triggers/itemShelving_beforeUpdate.sql +++ b/db/routines/vn/triggers/itemShelving_beforeUpdate.sql @@ -9,5 +9,8 @@ BEGIN SET NEW.userFk = account.myUser_getId(); END IF; + IF NEW.shelvingFk <> OLD.shelvingFk THEN + SET NEW.movingState = NULL; + END IF; END$$ DELIMITER ; diff --git a/db/versions/11294-azureFern/00-firstScript.sql b/db/versions/11294-azureFern/00-firstScript.sql new file mode 100644 index 000000000..2d6ed3a5b --- /dev/null +++ b/db/versions/11294-azureFern/00-firstScript.sql @@ -0,0 +1,3 @@ +-- Place your SQL code here +ALTER TABLE vn.itemShelving DROP COLUMN IF EXISTS isMoving; +ALTER TABLE vn.itemShelving ADD IF NOT EXISTS movingState ENUM('selected','printed') NULL; \ No newline at end of file From 679773b33eb8961ec18f7e58e49cbd553cfdbbdb Mon Sep 17 00:00:00 2001 From: Pako Date: Wed, 9 Oct 2024 07:26:22 +0200 Subject: [PATCH 044/136] feat: refs #8075 itemShelvingMoving --- db/routines/vn/triggers/itemShelving_beforeUpdate.sql | 3 +++ db/versions/11295-brownLaurel/00-firstScript.sql | 3 +++ 2 files changed, 6 insertions(+) create mode 100644 db/versions/11295-brownLaurel/00-firstScript.sql diff --git a/db/routines/vn/triggers/itemShelving_beforeUpdate.sql b/db/routines/vn/triggers/itemShelving_beforeUpdate.sql index fabdf8efb..53f85de01 100644 --- a/db/routines/vn/triggers/itemShelving_beforeUpdate.sql +++ b/db/routines/vn/triggers/itemShelving_beforeUpdate.sql @@ -9,5 +9,8 @@ BEGIN SET NEW.userFk = account.myUser_getId(); END IF; + IF NEW.shelvingFk <> OLD.shelvingFk THEN + SET NEW.movingState = NULL; + END IF; END$$ DELIMITER ; diff --git a/db/versions/11295-brownLaurel/00-firstScript.sql b/db/versions/11295-brownLaurel/00-firstScript.sql new file mode 100644 index 000000000..2d6ed3a5b --- /dev/null +++ b/db/versions/11295-brownLaurel/00-firstScript.sql @@ -0,0 +1,3 @@ +-- Place your SQL code here +ALTER TABLE vn.itemShelving DROP COLUMN IF EXISTS isMoving; +ALTER TABLE vn.itemShelving ADD IF NOT EXISTS movingState ENUM('selected','printed') NULL; \ No newline at end of file From 4eab12dd0453218a0298427534f3d00650797f62 Mon Sep 17 00:00:00 2001 From: Pako Date: Wed, 9 Oct 2024 07:41:43 +0200 Subject: [PATCH 045/136] fix: refs #8069 throw message in spanish --- db/routines/hedera/procedures/order_confirmWithUser.sql | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/db/routines/hedera/procedures/order_confirmWithUser.sql b/db/routines/hedera/procedures/order_confirmWithUser.sql index a0c5c5667..b7ed500d7 100644 --- a/db/routines/hedera/procedures/order_confirmWithUser.sql +++ b/db/routines/hedera/procedures/order_confirmWithUser.sql @@ -109,8 +109,8 @@ BEGIN ) INTO vHas0Amount; IF vHas0Amount THEN - CALL util.throw('Remove lines with quantity = 0 before confirming'); - END IF; + CALL util.throw('Hay líneas vacías. Por favor, elimínelas'); + END IF; START TRANSACTION; From 208869bd306565cc31bb90a7b09e5c9f2596a9ea Mon Sep 17 00:00:00 2001 From: Pako Date: Thu, 10 Oct 2024 08:20:41 +0200 Subject: [PATCH 046/136] fix: refs #8069 removed obsolete variables --- db/routines/hedera/procedures/order_confirmWithUser.sql | 2 -- db/routines/hedera/triggers/orderRow_afterInsert.sql | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/db/routines/hedera/procedures/order_confirmWithUser.sql b/db/routines/hedera/procedures/order_confirmWithUser.sql index b7ed500d7..44da9d071 100644 --- a/db/routines/hedera/procedures/order_confirmWithUser.sql +++ b/db/routines/hedera/procedures/order_confirmWithUser.sql @@ -22,7 +22,6 @@ BEGIN DECLARE vItemFk INT; DECLARE vConcept VARCHAR(30); DECLARE vAmount INT; - DECLARE vAvailable INT; DECLARE vPrice DECIMAL(10,2); DECLARE vSaleFk INT; DECLARE vRowFk INT; @@ -32,7 +31,6 @@ BEGIN DECLARE vClientFk INT; DECLARE vCompanyFk INT; DECLARE vAgencyModeFk INT; - DECLARE vCalcFk INT; DECLARE vIsTaxDataChecked BOOL; DECLARE vDates CURSOR FOR diff --git a/db/routines/hedera/triggers/orderRow_afterInsert.sql b/db/routines/hedera/triggers/orderRow_afterInsert.sql index 525e5d4d2..d0da043e7 100644 --- a/db/routines/hedera/triggers/orderRow_afterInsert.sql +++ b/db/routines/hedera/triggers/orderRow_afterInsert.sql @@ -4,7 +4,7 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `hedera`.`orderRow_afterIns FOR EACH ROW BEGIN UPDATE `order` - SET rowUpdated = NOW() + SET rowUpdated = util.VN_NOW() WHERE id = NEW.orderFk; END$$ DELIMITER ; \ No newline at end of file From 295c31a5f078a41e1cdb5dc29af3f232977956e7 Mon Sep 17 00:00:00 2001 From: jorgep Date: Thu, 10 Oct 2024 11:01:25 +0200 Subject: [PATCH 047/136] feat: refs #7874 add finance obs type --- db/dump/fixtures.before.sql | 3 ++- .../11230-brownEucalyptus/00-addClientObservationType.sql | 2 +- db/versions/11230-brownEucalyptus/01-addNewObservation.vn.sql | 3 +++ 3 files changed, 6 insertions(+), 2 deletions(-) create mode 100644 db/versions/11230-brownEucalyptus/01-addNewObservation.vn.sql diff --git a/db/dump/fixtures.before.sql b/db/dump/fixtures.before.sql index d475ef02f..7f7e50dd3 100644 --- a/db/dump/fixtures.before.sql +++ b/db/dump/fixtures.before.sql @@ -546,7 +546,8 @@ INSERT INTO `vn`.`observationType`(`id`,`description`, `code`) (6, 'Weight', 'weight'), (7, 'InvoiceOut', 'invoiceOut'), (8, 'DropOff', 'dropOff'), - (9, 'Sustitución', 'substitution'); + (9, 'Sustitución', 'substitution'), + (10, 'Finance', 'finance'); INSERT INTO `vn`.`addressObservation`(`id`,`addressFk`,`observationTypeFk`,`description`) VALUES diff --git a/db/versions/11230-brownEucalyptus/00-addClientObservationType.sql b/db/versions/11230-brownEucalyptus/00-addClientObservationType.sql index cb0849888..53a737bc5 100644 --- a/db/versions/11230-brownEucalyptus/00-addClientObservationType.sql +++ b/db/versions/11230-brownEucalyptus/00-addClientObservationType.sql @@ -1,3 +1,3 @@ ALTER TABLE vn.clientObservation ADD COLUMN observationTypeFk TINYINT(3) UNSIGNED NOT NULL, - ADD CONSTRAINT clientObservationTypeFk FOREIGN KEY (observationTypeFk) REFERENCES vn.observationType(id); \ No newline at end of file + ADD CONSTRAINT clientObservationTypeFk FOREIGN KEY (observationTypeFk) REFERENCES vn.observationType(id); \ No newline at end of file diff --git a/db/versions/11230-brownEucalyptus/01-addNewObservation.vn.sql b/db/versions/11230-brownEucalyptus/01-addNewObservation.vn.sql new file mode 100644 index 000000000..983419111 --- /dev/null +++ b/db/versions/11230-brownEucalyptus/01-addNewObservation.vn.sql @@ -0,0 +1,3 @@ +INSERT IGNORE INTO vn.observationType + SET description = 'Finance', + code = 'finance'; \ No newline at end of file From 770c604d6b9e758745a4087305d7fa45fbdb2b12 Mon Sep 17 00:00:00 2001 From: jorgep Date: Thu, 10 Oct 2024 16:30:04 +0200 Subject: [PATCH 048/136] chore: refs #7919 delete if ticketRefund --- db/routines/vn/triggers/ticket_afterUpdate.sql | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/db/routines/vn/triggers/ticket_afterUpdate.sql b/db/routines/vn/triggers/ticket_afterUpdate.sql index f6c5e6523..e849c1faa 100644 --- a/db/routines/vn/triggers/ticket_afterUpdate.sql +++ b/db/routines/vn/triggers/ticket_afterUpdate.sql @@ -12,5 +12,10 @@ BEGIN CALL ticket_doCmr(NEW.id); END IF; END IF; + + IF NEW.isDeleted THEN + DELETE FROM ticketRefund + WHERE refundTicketFk = NEW.id; + END IF; END$$ DELIMITER ; From 4ee6a46bd567cfbc7660d78daae1b88af76fce6a Mon Sep 17 00:00:00 2001 From: Jon Date: Mon, 14 Oct 2024 11:29:49 +0200 Subject: [PATCH 049/136] feat: added new filter param --- .../back/methods/ticket-request/filter.js | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/modules/ticket/back/methods/ticket-request/filter.js b/modules/ticket/back/methods/ticket-request/filter.js index 5364cef9a..ad000036b 100644 --- a/modules/ticket/back/methods/ticket-request/filter.js +++ b/modules/ticket/back/methods/ticket-request/filter.js @@ -59,6 +59,11 @@ module.exports = Self => { arg: 'state', type: 'string', description: `Search request by request state` + }, + { + arg: 'myTeam', + type: 'boolean', + description: `Team partners` } ], returns: { @@ -75,6 +80,24 @@ module.exports = Self => { const conn = Self.dataSource.connector; const userId = ctx.req.accessToken.userId; const myOptions = {}; + const models = Self.app.models; + const args = ctx.args; + + // Apply filter by team + const teamMembersId = []; + if (args.myTeam != null) { + const worker = await models.Worker.findById(userId, { + include: { + relation: 'collegues' + } + }, myOptions); + const collegues = worker.collegues() || []; + for (let collegue of collegues) + teamMembersId.push(collegue.collegueFk); + + if (teamMembersId.length == 0) + teamMembersId.push(userId); + } if (typeof options == 'object') Object.assign(myOptions, options); @@ -113,6 +136,11 @@ module.exports = Self => { return {'w.id': value}; case 'salesPersonFk': return {'c.salesPersonFk': value}; + case 'myTeam': + if (value) + return {'c.salesPersonFk': {inq: teamMembersId}}; + else + return {'c.salesPersonFk': {nin: teamMembersId}}; } }); From 06b7d568376923fe50388cd42ce0672031ab5c9c Mon Sep 17 00:00:00 2001 From: sergiodt Date: Mon, 14 Oct 2024 13:01:30 +0200 Subject: [PATCH 050/136] fix: refs #6861 assignCollection&isOnReservationMode --- db/versions/11289-azureAralia/00-firstScript.sql | 2 ++ modules/shelving/back/models/sector.json | 5 ++++- modules/worker/back/methods/device/handle-user.js | 2 +- 3 files changed, 7 insertions(+), 2 deletions(-) create mode 100644 db/versions/11289-azureAralia/00-firstScript.sql diff --git a/db/versions/11289-azureAralia/00-firstScript.sql b/db/versions/11289-azureAralia/00-firstScript.sql new file mode 100644 index 000000000..ab091f53f --- /dev/null +++ b/db/versions/11289-azureAralia/00-firstScript.sql @@ -0,0 +1,2 @@ + +ALTER TABLE vn.sector ADD isOnReservationMode tinyint(1) DEFAULT FALSE NULL; diff --git a/modules/shelving/back/models/sector.json b/modules/shelving/back/models/sector.json index 61d8d0628..16aa0ba6a 100644 --- a/modules/shelving/back/models/sector.json +++ b/modules/shelving/back/models/sector.json @@ -59,6 +59,9 @@ "isReserve": { "type": "boolean", "required": true + }, + "isOnReservationMode": { + "type": "boolean" } } -} +} \ No newline at end of file diff --git a/modules/worker/back/methods/device/handle-user.js b/modules/worker/back/methods/device/handle-user.js index 55302c1cb..abafffd55 100644 --- a/modules/worker/back/methods/device/handle-user.js +++ b/modules/worker/back/methods/device/handle-user.js @@ -87,7 +87,7 @@ module.exports = Self => { { relation: 'sector', scope: { - fields: ['warehouseFk', 'description'], + fields: ['warehouseFk', 'description', 'isOnReservationMode'], } }, { relation: 'printer', From 07849ebeb8234172072b027317ad8517dc34cfe4 Mon Sep 17 00:00:00 2001 From: Jon Date: Mon, 14 Oct 2024 13:25:09 +0200 Subject: [PATCH 051/136] fix: myTeam param --- modules/ticket/back/methods/ticket-request/filter.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/ticket/back/methods/ticket-request/filter.js b/modules/ticket/back/methods/ticket-request/filter.js index ad000036b..2e1d2fbae 100644 --- a/modules/ticket/back/methods/ticket-request/filter.js +++ b/modules/ticket/back/methods/ticket-request/filter.js @@ -138,9 +138,9 @@ module.exports = Self => { return {'c.salesPersonFk': value}; case 'myTeam': if (value) - return {'c.salesPersonFk': {inq: teamMembersId}}; + return {'tr.requesterFk': {inq: teamMembersId}}; else - return {'c.salesPersonFk': {nin: teamMembersId}}; + return {'tr.requesterFk': {nin: teamMembersId}}; } }); From f3b5a70b673de493a110257cd0fae9c4081160da Mon Sep 17 00:00:00 2001 From: jorgep Date: Mon, 14 Oct 2024 14:41:25 +0200 Subject: [PATCH 052/136] feat: refs #7323 show right error --- modules/worker/back/methods/worker/new.js | 1 + 1 file changed, 1 insertion(+) diff --git a/modules/worker/back/methods/worker/new.js b/modules/worker/back/methods/worker/new.js index bb43fba99..7da8a8da2 100644 --- a/modules/worker/back/methods/worker/new.js +++ b/modules/worker/back/methods/worker/new.js @@ -217,6 +217,7 @@ module.exports = Self => { const code = e.code; const message = e.sqlMessage; + if (e.message && e.message.includes('Invalid email')) throw new UserError('Invalid email'); if (e.message && e.message.includes(`Email already exists`)) throw new UserError(`This personal mail already exists`); if (code === 'ER_DUP_ENTRY' && message.includes(`CodigoTrabajador_UNIQUE`)) throw new UserError(`This worker code already exists`); if (code === 'ER_DUP_ENTRY' && message.includes(`PRIMARY`)) throw new UserError(`This worker already exists`); From ccf9dbde8e1f8e8612ec3276a49cc7c9d62541c2 Mon Sep 17 00:00:00 2001 From: jorgep Date: Mon, 14 Oct 2024 17:11:12 +0200 Subject: [PATCH 053/136] feat: refs #7919 test --- .../methods/ticket/specs/setDeleted.spec.js | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/modules/ticket/back/methods/ticket/specs/setDeleted.spec.js b/modules/ticket/back/methods/ticket/specs/setDeleted.spec.js index 782c31c02..4e858af8e 100644 --- a/modules/ticket/back/methods/ticket/specs/setDeleted.spec.js +++ b/modules/ticket/back/methods/ticket/specs/setDeleted.spec.js @@ -113,5 +113,25 @@ describe('ticket setDeleted()', () => { expect(error.message).not.toContain('Tickets with associated refunds'); }); + + it('should delete a refund ticket from ticketRefund table', async() => { + const tx = await models.Ticket.beginTransaction({}); + try { + const options = {transaction: tx}; + + const ticketId = 24; + const refundTicket = await models.TicketRefund.findOne({where: {refundTicketFk: ticketId}}, options); + + expect(refundTicket).toBeTruthy(); + + await models.Ticket.setDeleted(ctx, ticketId, options); + const isRemoved = await models.TicketRefund.findOne({where: {refundTicketFk: ticketId}}, options); + + expect(isRemoved).toBeNull(); + await tx.rollback(); + } catch (e) { + await tx.rollback(); + } + }); }); }); From a35208d903f3c3329451da3141a159b66a2a13c3 Mon Sep 17 00:00:00 2001 From: jorgep Date: Mon, 14 Oct 2024 17:14:01 +0200 Subject: [PATCH 054/136] feat: refs #7919 test --- modules/ticket/back/methods/ticket/specs/setDeleted.spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/ticket/back/methods/ticket/specs/setDeleted.spec.js b/modules/ticket/back/methods/ticket/specs/setDeleted.spec.js index 4e858af8e..088487f3a 100644 --- a/modules/ticket/back/methods/ticket/specs/setDeleted.spec.js +++ b/modules/ticket/back/methods/ticket/specs/setDeleted.spec.js @@ -114,7 +114,7 @@ describe('ticket setDeleted()', () => { expect(error.message).not.toContain('Tickets with associated refunds'); }); - it('should delete a refund ticket from ticketRefund table', async() => { + it('should delete the refund - original ticket relation', async() => { const tx = await models.Ticket.beginTransaction({}); try { const options = {transaction: tx}; From 6d4c71d465bf40cd8bf592bfd9e4ffde24293210 Mon Sep 17 00:00:00 2001 From: jorgep Date: Mon, 14 Oct 2024 17:14:40 +0200 Subject: [PATCH 055/136] feat: refs #7919 test --- modules/ticket/back/methods/ticket/specs/setDeleted.spec.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/modules/ticket/back/methods/ticket/specs/setDeleted.spec.js b/modules/ticket/back/methods/ticket/specs/setDeleted.spec.js index 088487f3a..b70c94cee 100644 --- a/modules/ticket/back/methods/ticket/specs/setDeleted.spec.js +++ b/modules/ticket/back/methods/ticket/specs/setDeleted.spec.js @@ -125,9 +125,11 @@ describe('ticket setDeleted()', () => { expect(refundTicket).toBeTruthy(); await models.Ticket.setDeleted(ctx, ticketId, options); - const isRemoved = await models.TicketRefund.findOne({where: {refundTicketFk: ticketId}}, options); + const removedRefundTicket = await models.TicketRefund.findOne({ + where: {refundTicketFk: ticketId}}, + options); - expect(isRemoved).toBeNull(); + expect(removedRefundTicket).toBeNull(); await tx.rollback(); } catch (e) { await tx.rollback(); From 3c881d5e483b904dfcb0be489e313345099c755a Mon Sep 17 00:00:00 2001 From: alexm Date: Tue, 15 Oct 2024 08:00:19 +0200 Subject: [PATCH 056/136] refactor(docuware): refs #8066 use Authorization --- back/methods/docuware/core.js | 42 ++++++++++++------- back/methods/docuware/upload.js | 2 +- back/models/docuware-config.json | 5 ++- .../11291-purpleChico/00-firstScript.sql | 2 + 4 files changed, 35 insertions(+), 16 deletions(-) diff --git a/back/methods/docuware/core.js b/back/methods/docuware/core.js index 9545cd878..6d3bb58ed 100644 --- a/back/methods/docuware/core.js +++ b/back/methods/docuware/core.js @@ -4,32 +4,45 @@ module.exports = Self => { /** * Returns basic headers * - * @param {string} cookie - The docuware cookie * @return {object} - The headers */ Self.getOptions = async() => { - const {url, username, password} = await Self.app.models.DocuwareConfig.findOne(); - const {data: {IdentityServiceUrl}} = await axios.get(`${url}/Home/IdentityServiceInfo`); - const {data: {token_endpoint}} = await axios.get(`${IdentityServiceUrl}/.well-known/openid-configuration`); - const data = await axios.post(token_endpoint, JSON.stringify({ - grant_type: 'password', - scope: 'docuware.platform', - client_id: 'docuware.platform.net.client', - username, - password - })); - console.log('data: ', data); + const docuwareConfig = await Self.app.models.DocuwareConfig.findOne(); + const now = new Date().getTime(); + let {url, username, password, token, expired} = docuwareConfig; + + if (!expired || expired < now + 60) { + const {data: {IdentityServiceUrl}} = await axios.get(`${url}/Home/IdentityServiceInfo`); + const {data: {token_endpoint}} = await axios.get(`${IdentityServiceUrl}/.well-known/openid-configuration`); + const {data} = await axios.post(token_endpoint, { + grant_type: 'password', + scope: 'docuware.platform', + client_id: 'docuware.platform.net.client', + username, + password + }, {headers: { + 'Accept': 'application/json', + 'Content-Type': 'application/x-www-form-urlencoded' + }}); + + const newToken = data.access_token; + token = data.token_type + ' ' + newToken; + await docuwareConfig.updateAttributes({ + token, + expired: now + data.expires_in + }); + } const headers = { headers: { 'Accept': 'application/json', 'Content-Type': 'application/json', - 'access_token': access_token + 'Authorization': token } }; return { - url: docuwareConfig.url, + url, headers }; }; @@ -80,6 +93,7 @@ module.exports = Self => { } }); + console.log('options.headers: ', options.headers); const fileCabinetResponse = await axios.get(`${options.url}/FileCabinets`, options.headers); const fileCabinets = fileCabinetResponse.data.FileCabinet; const fileCabinetId = fileCabinets.find(fileCabinet => fileCabinet.Name === docuwareInfo.fileCabinetName).Id; diff --git a/back/methods/docuware/upload.js b/back/methods/docuware/upload.js index 0102911e0..5b35b7598 100644 --- a/back/methods/docuware/upload.js +++ b/back/methods/docuware/upload.js @@ -143,7 +143,7 @@ module.exports = Self => { headers: { 'Content-Type': 'multipart/form-data', 'X-File-ModifiedDate': Date.vnNew(), - 'Cookie': docuwareOptions.headers.headers.Cookie, + 'Authorization': docuwareOptions.headers.headers.Authorization, ...data.getHeaders() }, }; diff --git a/back/models/docuware-config.json b/back/models/docuware-config.json index 244ae2790..b15cb4c03 100644 --- a/back/models/docuware-config.json +++ b/back/models/docuware-config.json @@ -16,7 +16,7 @@ "url": { "type": "string" }, - "cookie": { + "token": { "type": "string" }, "username": { @@ -24,6 +24,9 @@ }, "password": { "type": "string" + }, + "expired":{ + "type": "number" } } } diff --git a/db/versions/11291-purpleChico/00-firstScript.sql b/db/versions/11291-purpleChico/00-firstScript.sql index db66c4c98..e60b90376 100644 --- a/db/versions/11291-purpleChico/00-firstScript.sql +++ b/db/versions/11291-purpleChico/00-firstScript.sql @@ -1,2 +1,4 @@ ALTER TABLE vn.docuwareConfig ADD IF NOT EXISTS username varchar(100) NULL; ALTER TABLE vn.docuwareConfig ADD IF NOT EXISTS password varchar(100) NULL; +ALTER TABLE vn.docuwareConfig ADD IF NOT EXISTS token text NULL; +ALTER TABLE vn.docuwareConfig ADD IF NOT EXISTS expired int(11) NULL; From f2d1aa5f1659e70e188d08e77d568119fb1ce6ac Mon Sep 17 00:00:00 2001 From: jgallego Date: Tue, 15 Oct 2024 08:17:03 +0200 Subject: [PATCH 057/136] feat: refs #8098 closureDaysAgo --- db/versions/11298-wheatIvy/00-closure.sql | 3 +++ .../ticket/back/methods/ticket/closeAll.js | 21 ++++++++++--------- modules/ticket/back/methods/ticket/closure.js | 5 +---- .../back/methods/ticket/specs/closure.spec.js | 4 ++-- 4 files changed, 17 insertions(+), 16 deletions(-) create mode 100644 db/versions/11298-wheatIvy/00-closure.sql diff --git a/db/versions/11298-wheatIvy/00-closure.sql b/db/versions/11298-wheatIvy/00-closure.sql new file mode 100644 index 000000000..7b33939cf --- /dev/null +++ b/db/versions/11298-wheatIvy/00-closure.sql @@ -0,0 +1,3 @@ +ALTER TABLE `vn`.`ticketConfig` +ADD COLUMN `closureDaysAgo` int(11) NOT NULL DEFAULT 2 COMMENT 'Number of days to look back for ticket closure', +ADD CONSTRAINT `closureDaysAgo_check` CHECK (`closureDaysAgo` > 0); diff --git a/modules/ticket/back/methods/ticket/closeAll.js b/modules/ticket/back/methods/ticket/closeAll.js index 8869f9464..4ae83b647 100644 --- a/modules/ticket/back/methods/ticket/closeAll.js +++ b/modules/ticket/back/methods/ticket/closeAll.js @@ -45,17 +45,18 @@ module.exports = Self => { eu.email salesPersonEmail, t.addressFk FROM ticket t - JOIN agencyMode am ON am.id = t.agencyModeFk - JOIN warehouse wh ON wh.id = t.warehouseFk AND wh.hasComission - JOIN ticketState ts ON ts.ticketFk = t.id - JOIN alertLevel al ON al.id = ts.alertLevel - JOIN client c ON c.id = t.clientFk - JOIN province p ON p.id = c.provinceFk - JOIN country co ON co.id = p.countryFk - LEFT JOIN account.emailUser eu ON eu.userFk = c.salesPersonFk + JOIN agencyMode am ON am.id = t.agencyModeFk + JOIN warehouse wh ON wh.id = t.warehouseFk AND wh.hasComission + JOIN ticketState ts ON ts.ticketFk = t.id + JOIN alertLevel al ON al.id = ts.alertLevel + JOIN client c ON c.id = t.clientFk + JOIN province p ON p.id = c.provinceFk + JOIN country co ON co.id = p.countryFk + LEFT JOIN account.emailUser eu ON eu.userFk = c.salesPersonFk + JOIN ticketConfig tc ON TRUE WHERE (al.code = 'PACKED' OR (am.code = 'refund' AND al.code <> 'delivered')) - AND DATE(t.shipped) BETWEEN ? - INTERVAL 7 DAY AND util.dayEnd(?) - AND t.refFk IS NULL + AND DATE(t.shipped) BETWEEN ? - INTERVAL tc.closureDaysAgo DAY AND util.dayEnd(?) + AND t.refFk IS NULL GROUP BY t.id `, [toDate, toDate]); const ticketIds = tickets.map(ticket => ticket.id); diff --git a/modules/ticket/back/methods/ticket/closure.js b/modules/ticket/back/methods/ticket/closure.js index d20c83304..56bd6eccd 100644 --- a/modules/ticket/back/methods/ticket/closure.js +++ b/modules/ticket/back/methods/ticket/closure.js @@ -12,10 +12,7 @@ module.exports = async function(ctx, Self, tickets, options) { Object.assign(myOptions, options); let tx; - // if (!myOptions.transaction) { - // tx = await Self.beginTransaction({}); - // myOptions.transaction = tx; - // } + // IMPORTANT: Due to its high cost in production, wrapping this process in a transaction may cause timeouts. if (tickets.length == 0) return; diff --git a/modules/ticket/back/methods/ticket/specs/closure.spec.js b/modules/ticket/back/methods/ticket/specs/closure.spec.js index 303c38233..cafe178cb 100644 --- a/modules/ticket/back/methods/ticket/specs/closure.spec.js +++ b/modules/ticket/back/methods/ticket/specs/closure.spec.js @@ -50,9 +50,9 @@ describe('Ticket closure functionality', () => { expect(ticketStateBefore.code).not.toBe(ticketStateAfter.code); - const ticketAfter = await models.TicketState.findById(ticketId, null, options); + const ticketAfter = await models.Ticket.findById(ticketId, null, options); - expect(ticketAfter.refFk).toBeUndefined(); + expect(ticketAfter.refFk).toBeNull(); }); it('should send Incoterms authorization email on first order', async() => { From 63f062a06925fb12dc25612003e1eab8851f5515 Mon Sep 17 00:00:00 2001 From: alexm Date: Tue, 15 Oct 2024 08:19:35 +0200 Subject: [PATCH 058/136] fix(renewToken): refs #8093 test & fix(sql) addClientObservationType --- back/methods/vn-user/specs/renew-token.spec.js | 4 ++-- .../11230-brownEucalyptus/00-addClientObservationType.sql | 6 +++--- 2 files changed, 5 insertions(+), 5 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); }); diff --git a/db/versions/11230-brownEucalyptus/00-addClientObservationType.sql b/db/versions/11230-brownEucalyptus/00-addClientObservationType.sql index 53a737bc5..1542ff28a 100644 --- a/db/versions/11230-brownEucalyptus/00-addClientObservationType.sql +++ b/db/versions/11230-brownEucalyptus/00-addClientObservationType.sql @@ -1,3 +1,3 @@ -ALTER TABLE vn.clientObservation - ADD COLUMN observationTypeFk TINYINT(3) UNSIGNED NOT NULL, - ADD CONSTRAINT clientObservationTypeFk FOREIGN KEY (observationTypeFk) REFERENCES vn.observationType(id); \ No newline at end of file +ALTER TABLE vn.clientObservation + ADD COLUMN IF NOT EXISTS observationTypeFk TINYINT(3) UNSIGNED NOT NULL, + ADD CONSTRAINT clientObservationTypeFk FOREIGN KEY (observationTypeFk) REFERENCES vn.observationType(id); From 4526873bbe7e94debe793b9f1143e899e5e8c365 Mon Sep 17 00:00:00 2001 From: jgallego Date: Tue, 15 Oct 2024 08:24:13 +0200 Subject: [PATCH 059/136] feat: refs #8098 without Date --- modules/ticket/back/methods/ticket/closeAll.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/modules/ticket/back/methods/ticket/closeAll.js b/modules/ticket/back/methods/ticket/closeAll.js index 4ae83b647..4e2f4ef3c 100644 --- a/modules/ticket/back/methods/ticket/closeAll.js +++ b/modules/ticket/back/methods/ticket/closeAll.js @@ -55,7 +55,7 @@ module.exports = Self => { LEFT JOIN account.emailUser eu ON eu.userFk = c.salesPersonFk JOIN ticketConfig tc ON TRUE WHERE (al.code = 'PACKED' OR (am.code = 'refund' AND al.code <> 'delivered')) - AND DATE(t.shipped) BETWEEN ? - INTERVAL tc.closureDaysAgo DAY AND util.dayEnd(?) + AND t.shipped BETWEEN ? - INTERVAL tc.closureDaysAgo DAY AND util.dayEnd(?) AND t.refFk IS NULL GROUP BY t.id `, [toDate, toDate]); @@ -109,6 +109,7 @@ module.exports = Self => { JOIN alertLevel al ON al.id = ts.alertLevel JOIN client c ON c.id = t.clientFk JOIN province p ON p.id = c.provinceFk + JOIN ticketConfig tc ON TRUE LEFT JOIN autonomy a ON a.id = p.autonomyFk JOIN country co ON co.id = p.countryFk LEFT JOIN account.emailUser eu ON eu.userFk = c.salesPersonFk @@ -117,7 +118,7 @@ module.exports = Self => { LEFT JOIN vn.invoiceOutSerial ios ON ios.taxAreaFk = 'WORLD' AND ios.code = invoiceSerial(t.clientFk, t.companyFk, 'multiple') WHERE (al.code = 'PACKED' OR (am.code = 'refund' AND al.code <> 'delivered')) - AND DATE(t.shipped) BETWEEN ? - INTERVAL 2 DAY AND util.dayEnd(?) + AND t.shipped BETWEEN ? - INTERVAL tc.closureDaysAgo DAY AND util.dayEnd(?) AND t.refFk IS NULL AND IFNULL(a.hasDailyInvoice, co.hasDailyInvoice) GROUP BY ticketFk @@ -142,9 +143,10 @@ module.exports = Self => { JOIN alertLevel al ON al.id = ts.alertLevel JOIN agencyMode am ON am.id = t.agencyModeFk JOIN deliveryMethod dm ON dm.id = am.deliveryMethodFk + JOIN ticketConfig tc ON TRUE LEFT JOIN ticketObservation tob ON tob.ticketFk = t.id SET t.routeFk = NULL - WHERE DATE(t.shipped) BETWEEN ? - INTERVAL 2 DAY AND util.dayEnd(?) + WHERE t.shipped BETWEEN ? - INTERVAL tc.closureDaysAgo DAY AND util.dayEnd(?) AND al.code NOT IN ('DELIVERED', 'PACKED') AND NOT t.packages AND tob.id IS NULL From 976e50b566ff70d7542f33888d9397ee2fa73cdd Mon Sep 17 00:00:00 2001 From: jgallego Date: Tue, 15 Oct 2024 08:25:53 +0200 Subject: [PATCH 060/136] feat: refs #8098 identation --- .../ticket/back/methods/ticket/closeAll.js | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/modules/ticket/back/methods/ticket/closeAll.js b/modules/ticket/back/methods/ticket/closeAll.js index 4e2f4ef3c..4fd72d454 100644 --- a/modules/ticket/back/methods/ticket/closeAll.js +++ b/modules/ticket/back/methods/ticket/closeAll.js @@ -45,18 +45,18 @@ module.exports = Self => { eu.email salesPersonEmail, t.addressFk FROM ticket t - JOIN agencyMode am ON am.id = t.agencyModeFk - JOIN warehouse wh ON wh.id = t.warehouseFk AND wh.hasComission - JOIN ticketState ts ON ts.ticketFk = t.id - JOIN alertLevel al ON al.id = ts.alertLevel - JOIN client c ON c.id = t.clientFk - JOIN province p ON p.id = c.provinceFk - JOIN country co ON co.id = p.countryFk - LEFT JOIN account.emailUser eu ON eu.userFk = c.salesPersonFk - JOIN ticketConfig tc ON TRUE + JOIN agencyMode am ON am.id = t.agencyModeFk + JOIN warehouse wh ON wh.id = t.warehouseFk AND wh.hasComission + JOIN ticketState ts ON ts.ticketFk = t.id + JOIN alertLevel al ON al.id = ts.alertLevel + JOIN client c ON c.id = t.clientFk + JOIN province p ON p.id = c.provinceFk + JOIN country co ON co.id = p.countryFk + LEFT JOIN account.emailUser eu ON eu.userFk = c.salesPersonFk + JOIN ticketConfig tc ON TRUE WHERE (al.code = 'PACKED' OR (am.code = 'refund' AND al.code <> 'delivered')) - AND t.shipped BETWEEN ? - INTERVAL tc.closureDaysAgo DAY AND util.dayEnd(?) - AND t.refFk IS NULL + AND t.shipped BETWEEN ? - INTERVAL tc.closureDaysAgo DAY AND util.dayEnd(?) + AND t.refFk IS NULL GROUP BY t.id `, [toDate, toDate]); const ticketIds = tickets.map(ticket => ticket.id); From c5f987d04c9f4054aa2d9d0fdff9d5243435f331 Mon Sep 17 00:00:00 2001 From: jgallego Date: Tue, 15 Oct 2024 08:44:08 +0200 Subject: [PATCH 061/136] fix: refs #8098 renew token test fixed --- back/methods/vn-user/specs/renew-token.spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/back/methods/vn-user/specs/renew-token.spec.js b/back/methods/vn-user/specs/renew-token.spec.js index 8f1bb54c1..929c2f38d 100644 --- a/back/methods/vn-user/specs/renew-token.spec.js +++ b/back/methods/vn-user/specs/renew-token.spec.js @@ -72,7 +72,7 @@ describe('Renew Token', () => { } expect(error).toBeDefined(); - const query = 'SELECT * FROM util.debug'; + const query = 'SELECT * FROM util.debug WHERE variable = "renewToken"'; const debugLog = await models.Application.rawSql(query, null); From 52e573501ad4d5fa120291b24f1ba9cf53dfaea0 Mon Sep 17 00:00:00 2001 From: robert Date: Tue, 15 Oct 2024 08:46:43 +0200 Subject: [PATCH 062/136] feat: refs #8108 create tables itemTag --- .../11300-limeMedeola/00-firstScript.sql | 85 +++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 db/versions/11300-limeMedeola/00-firstScript.sql diff --git a/db/versions/11300-limeMedeola/00-firstScript.sql b/db/versions/11300-limeMedeola/00-firstScript.sql new file mode 100644 index 000000000..21920b692 --- /dev/null +++ b/db/versions/11300-limeMedeola/00-firstScript.sql @@ -0,0 +1,85 @@ +CREATE TABLE IF NOT EXISTS `vn`.`itemFarmingTag` ( + `id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT, + `name` varchar(50) DEFAULT NULL, + PRIMARY KEY (`id`), + UNIQUE KEY `name_UNIQUE` (`name`) +) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT + CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; + +INSERT IGNORE INTO `vn`.`itemFarmingTag` (`name`) VALUES ('Enraizado'); + +UPDATE vn.tag + SET isFree=0, + sourceTable='itemFarmingTag' + WHERE name= 'cultivo'; + + + +CREATE TABLE IF NOT EXISTS `vn`.`itemWrappingTag` ( + `id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT, + `name` varchar(50) DEFAULT NULL, + PRIMARY KEY (`id`), + UNIQUE KEY `name_UNIQUE` (`name`) +) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT + CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; + +INSERT IGNORE INTO `vn`.`itemWrappingTag` (`name`) VALUES ('Bolsa'); +INSERT IGNORE INTO `vn`.`itemWrappingTag` (`name`) VALUES ('Caja cartón'); +INSERT IGNORE INTO `vn`.`itemWrappingTag` (`name`) VALUES ('Caja decorativa'); +INSERT IGNORE INTO `vn`.`itemWrappingTag` (`name`) VALUES ('Celofán'); +INSERT IGNORE INTO `vn`.`itemWrappingTag` (`name`) VALUES ('Papel kraft'); +INSERT IGNORE INTO `vn`.`itemWrappingTag` (`name`) VALUES ('Plástico'); +INSERT IGNORE INTO `vn`.`itemWrappingTag` (`name`) VALUES ('Variable'); + +UPDATE vn.tag + SET isFree=0, + sourceTable='itemWrappingTag' + WHERE name= 'Envoltorio'; + + + +CREATE TABLE IF NOT EXISTS `vn`.`itemLanguageTag` ( + `id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT, + `name` varchar(50) DEFAULT NULL, + PRIMARY KEY (`id`), + UNIQUE KEY `name_UNIQUE` (`name`) +) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT + CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; + +INSERT IGNORE INTO `vn`.`itemLanguageTag` (`name`) VALUES ('Castellano'); +INSERT IGNORE INTO `vn`.`itemLanguageTag` (`name`) VALUES ('Catalán'); +INSERT IGNORE INTO `vn`.`itemLanguageTag` (`name`) VALUES ('Euskera'); +INSERT IGNORE INTO `vn`.`itemLanguageTag` (`name`) VALUES ('Francés'); +INSERT IGNORE INTO `vn`.`itemLanguageTag` (`name`) VALUES ('Gallego'); +INSERT IGNORE INTO `vn`.`itemLanguageTag` (`name`) VALUES ('Inglés'); +INSERT IGNORE INTO `vn`.`itemLanguageTag` (`name`) VALUES ('Portugués'); + +UPDATE vn.tag + SET isFree=0, + sourceTable='itemLanguageTag' + WHERE name= 'Idioma'; + + + +CREATE TABLE IF NOT EXISTS `vn`.`itemStemTag` ( + `id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT, + `name` varchar(50) DEFAULT NULL, + PRIMARY KEY (`id`), + UNIQUE KEY `name_UNIQUE` (`name`) +) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT + CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; + +INSERT IGNORE INTO `vn`.`itemStemTag` (`name`) VALUES ('Natural'); +INSERT IGNORE INTO `vn`.`itemStemTag` (`name`) VALUES ('Seminatural'); +INSERT IGNORE INTO `vn`.`itemStemTag` (`name`) VALUES ('Sintético'); + +UPDATE vn.tag + SET isFree=0, + sourceTable='itemStemTag' + WHERE name= 'Tronco'; + + +GRANT SELECT, UPDATE, INSERT, DELETE ON TABLE vn.itemFarmingTag TO logisticAssist; +GRANT SELECT, UPDATE, INSERT, DELETE ON TABLE vn.itemWrappingTag TO logisticAssist; +GRANT SELECT, UPDATE, INSERT, DELETE ON TABLE vn.itemLanguageTag TO logisticAssist; +GRANT SELECT, UPDATE, INSERT, DELETE ON TABLE vn.itemStemTag TO logisticAssist; \ No newline at end of file From a2b9a59eb532267e1084348b30b9badd9c4b1a98 Mon Sep 17 00:00:00 2001 From: alexm Date: Tue, 15 Oct 2024 08:58:57 +0200 Subject: [PATCH 063/136] fix(sql): addClientObservationType --- .../11230-brownEucalyptus/00-addClientObservationType.sql | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/db/versions/11230-brownEucalyptus/00-addClientObservationType.sql b/db/versions/11230-brownEucalyptus/00-addClientObservationType.sql index 1542ff28a..b4486f9d4 100644 --- a/db/versions/11230-brownEucalyptus/00-addClientObservationType.sql +++ b/db/versions/11230-brownEucalyptus/00-addClientObservationType.sql @@ -1,3 +1,2 @@ -ALTER TABLE vn.clientObservation - ADD COLUMN IF NOT EXISTS observationTypeFk TINYINT(3) UNSIGNED NOT NULL, - ADD CONSTRAINT clientObservationTypeFk FOREIGN KEY (observationTypeFk) REFERENCES vn.observationType(id); +ALTER TABLE vn.clientObservation ADD COLUMN IF NOT EXISTS observationTypeFk TINYINT(3) UNSIGNED NOT NULL; +ALTER TABLE vn.clientObservation ADD CONSTRAINT clientObservationTypeFk FOREIGN KEY IF NOT EXISTS (observationTypeFk) REFERENCES vn.observationType(id); From e334152acc901fb1357a59d9da85c317b9b29548 Mon Sep 17 00:00:00 2001 From: Jon Date: Tue, 15 Oct 2024 09:03:15 +0200 Subject: [PATCH 064/136] refactor: deleted comment --- .../ticket/back/methods/ticket-request/filter.js | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/modules/ticket/back/methods/ticket-request/filter.js b/modules/ticket/back/methods/ticket-request/filter.js index 2e1d2fbae..53f90b98f 100644 --- a/modules/ticket/back/methods/ticket-request/filter.js +++ b/modules/ticket/back/methods/ticket-request/filter.js @@ -83,7 +83,12 @@ module.exports = Self => { const models = Self.app.models; const args = ctx.args; - // Apply filter by team + if (typeof options == 'object') + Object.assign(myOptions, options); + + if (ctx.args.mine) + ctx.args.attenderFk = userId; + const teamMembersId = []; if (args.myTeam != null) { const worker = await models.Worker.findById(userId, { @@ -99,12 +104,6 @@ module.exports = Self => { teamMembersId.push(userId); } - if (typeof options == 'object') - Object.assign(myOptions, options); - - if (ctx.args.mine) - ctx.args.attenderFk = userId; - let where = buildFilter(ctx.args, (param, value) => { switch (param) { case 'search': From 8ff06d63c58e39628f8e9dae3e72d4356b491ea2 Mon Sep 17 00:00:00 2001 From: alexm Date: Tue, 15 Oct 2024 09:16:07 +0200 Subject: [PATCH 065/136] fix(sql): addClientObservationType --- .../11230-brownEucalyptus/00-addClientObservationType.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/versions/11230-brownEucalyptus/00-addClientObservationType.sql b/db/versions/11230-brownEucalyptus/00-addClientObservationType.sql index b4486f9d4..935758b8d 100644 --- a/db/versions/11230-brownEucalyptus/00-addClientObservationType.sql +++ b/db/versions/11230-brownEucalyptus/00-addClientObservationType.sql @@ -1,2 +1,2 @@ -ALTER TABLE vn.clientObservation ADD COLUMN IF NOT EXISTS observationTypeFk TINYINT(3) UNSIGNED NOT NULL; +ALTER TABLE vn.clientObservation ADD COLUMN IF NOT EXISTS observationTypeFk TINYINT(3) UNSIGNED NULL; ALTER TABLE vn.clientObservation ADD CONSTRAINT clientObservationTypeFk FOREIGN KEY IF NOT EXISTS (observationTypeFk) REFERENCES vn.observationType(id); From cf78a12f3a50cac8dc3f4df4fee31cf12146e69b Mon Sep 17 00:00:00 2001 From: alexm Date: Tue, 15 Oct 2024 09:18:20 +0200 Subject: [PATCH 066/136] fix(sql): addClientObservationType --- .../11230-brownEucalyptus/00-addClientObservationType.sql | 1 + 1 file changed, 1 insertion(+) diff --git a/db/versions/11230-brownEucalyptus/00-addClientObservationType.sql b/db/versions/11230-brownEucalyptus/00-addClientObservationType.sql index 935758b8d..f69e20611 100644 --- a/db/versions/11230-brownEucalyptus/00-addClientObservationType.sql +++ b/db/versions/11230-brownEucalyptus/00-addClientObservationType.sql @@ -1,2 +1,3 @@ +ALTER TABLE vn.clientObservation DROP COLUMN IF EXISTS observationTypeFk; ALTER TABLE vn.clientObservation ADD COLUMN IF NOT EXISTS observationTypeFk TINYINT(3) UNSIGNED NULL; ALTER TABLE vn.clientObservation ADD CONSTRAINT clientObservationTypeFk FOREIGN KEY IF NOT EXISTS (observationTypeFk) REFERENCES vn.observationType(id); From 85f8b6fd20d8001d8d8a9b40e97514448569f469 Mon Sep 17 00:00:00 2001 From: alexm Date: Tue, 15 Oct 2024 09:29:38 +0200 Subject: [PATCH 067/136] build: init version 24.44 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 32c1f21d8..767ec231e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "salix-back", - "version": "24.42.0", + "version": "24.44.0", "author": "Verdnatura Levante SL", "description": "Salix backend", "license": "GPL-3.0", From c73fd51a9ca6ff5a5cf1d7490a2ba83b1f566d85 Mon Sep 17 00:00:00 2001 From: carlossa Date: Tue, 15 Oct 2024 09:45:14 +0200 Subject: [PATCH 068/136] fix: refs #7986 add acl --- db/versions/11290-blackOrchid/00-firstScript.sql | 3 +++ 1 file changed, 3 insertions(+) diff --git a/db/versions/11290-blackOrchid/00-firstScript.sql b/db/versions/11290-blackOrchid/00-firstScript.sql index e0c0e391c..fe568ed6e 100644 --- a/db/versions/11290-blackOrchid/00-firstScript.sql +++ b/db/versions/11290-blackOrchid/00-firstScript.sql @@ -1,3 +1,6 @@ ALTER TABLE `vn`.`operator` ADD COLUMN `machineFk` int(11) DEFAULT NULL, ADD CONSTRAINT `operator_machine_FK` FOREIGN KEY (`machineFk`) REFERENCES `vn`.`machine` (`id`) ON DELETE SET NULL ON UPDATE CASCADE; + +INSERT INTO salix.ACL (model,property,accessType,permission,principalType,principalId) + VALUES ('Machine','*','*','ALLOW','ROLE','productionBoss'); From b1b36a33a0eb7fb2215305ef56bb3e12c650ca8b Mon Sep 17 00:00:00 2001 From: alexm Date: Tue, 15 Oct 2024 09:47:39 +0200 Subject: [PATCH 069/136] chore(docuware_core): refs #8066 add returns --- back/methods/docuware/core.js | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/back/methods/docuware/core.js b/back/methods/docuware/core.js index 6d3bb58ed..391a8b4ab 100644 --- a/back/methods/docuware/core.js +++ b/back/methods/docuware/core.js @@ -56,8 +56,8 @@ module.exports = Self => { * @return {number} - The fileCabinet id */ Self.getDialog = async(code, action, fileCabinetId) => { - // if (!process.env.NODE_ENV) - // return Math.floor(Math.random() + 100); + if (!process.env.NODE_ENV) + return Math.floor(Math.random() + 100); const docuwareInfo = await Self.app.models.Docuware.findOne({ where: { @@ -83,8 +83,8 @@ module.exports = Self => { * @return {number} - The fileCabinet id */ Self.getFileCabinet = async code => { - // if (!process.env.NODE_ENV) - // return Math.floor(Math.random() + 100); + if (!process.env.NODE_ENV) + return Math.floor(Math.random() + 100); const options = await Self.getOptions(); const docuwareInfo = await Self.app.models.Docuware.findOne({ @@ -93,7 +93,6 @@ module.exports = Self => { } }); - console.log('options.headers: ', options.headers); const fileCabinetResponse = await axios.get(`${options.url}/FileCabinets`, options.headers); const fileCabinets = fileCabinetResponse.data.FileCabinet; const fileCabinetId = fileCabinets.find(fileCabinet => fileCabinet.Name === docuwareInfo.fileCabinetName).Id; @@ -110,7 +109,7 @@ module.exports = Self => { * @return {object} - The data */ Self.get = async(code, filter, parse) => { - // if (!process.env.NODE_ENV) return; + if (!process.env.NODE_ENV) return; const options = await Self.getOptions(); const fileCabinetId = await Self.getFileCabinet(code); @@ -133,7 +132,7 @@ module.exports = Self => { * @return {object} - The data */ Self.getById = async(code, id, parse) => { - // if (!process.env.NODE_ENV) return; + if (!process.env.NODE_ENV) return; const docuwareInfo = await Self.app.models.Docuware.findOne({ fields: ['findById'], From da55fffef02385c03945fb5ca30b0f42a8961161 Mon Sep 17 00:00:00 2001 From: robert Date: Tue, 15 Oct 2024 11:18:04 +0200 Subject: [PATCH 070/136] feat: refs #8108 addMoreTablesTag --- db/routines/vn/procedures/entry_transfer.sql | 121 ++++++++++++++++++ .../11300-limeMedeola/00-firstScript.sql | 72 ++++++++++- 2 files changed, 189 insertions(+), 4 deletions(-) create mode 100644 db/routines/vn/procedures/entry_transfer.sql diff --git a/db/routines/vn/procedures/entry_transfer.sql b/db/routines/vn/procedures/entry_transfer.sql new file mode 100644 index 000000000..6d7da2b37 --- /dev/null +++ b/db/routines/vn/procedures/entry_transfer.sql @@ -0,0 +1,121 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`entry_transfer`(vOriginalEntry INT, OUT vNewEntry INT) +BEGIN +/** +* Adelanta a mañana la mercancia de una entrada a partir de lo que hay ubicado en el almacén +* +* @param vOriginalEntry entrada que se quiera adelantar +*/ + + DECLARE vNewEntryFk INT; + DECLARE vTravelFk INT; + DECLARE vWarehouseFk INT; + + DECLARE EXIT HANDLER FOR SQLEXCEPTION + BEGIN + ROLLBACK; + RESIGNAL; + END; + + -- Clonar la entrada + CALL entry_clone(vOriginalEntry,vNewEntryFk); + + START TRANSACTION; + + -- Hay que crear un nuevo travel, con salida hoy y llegada mañana y asignar la entrada nueva al nuevo travel. + INSERT INTO travel( + shipped, + landed, + warehouseInFk, + warehouseOutFk, + `ref`, + isReceived, + agencyModeFk) + SELECT util.VN_CURDATE(), + util.VN_CURDATE() + INTERVAL 1 DAY, + t.warehouseInFk, + t.warehouseInFk, + t.`ref`, + t.isReceived, + t.agencyModeFk + FROM travel t + JOIN entry e ON e.travelFk = t.id + WHERE e.id = vOriginalEntry; + + SET vTravelFk = LAST_INSERT_ID(); + + UPDATE entry + SET travelFk = vTravelFk + WHERE id = vNewEntryFk; + + -- Poner a 0 las cantidades + UPDATE buy b + SET b.quantity = 0, b.stickers = 0 + WHERE b.entryFk = vNewEntryFk; + + -- Eliminar duplicados + DELETE b.* + FROM buy b + LEFT JOIN (SELECT b.id, b.itemFk + FROM buy b + WHERE b.entryFk = vNewEntryFk + GROUP BY b.itemFk) tBuy ON tBuy.id = b.id + WHERE b.entryFk = vNewEntryFk + AND tBuy.id IS NULL; + + SELECT t.warehouseInFk INTO vWarehouseFk + FROM travel t + JOIN entry e ON e.travelFk = t.id + WHERE e.id = vOriginalEntry; + + -- Actualizar la nueva entrada con lo que no está ubicado HOY, descontando lo vendido HOY de esas ubicaciones + CREATE OR REPLACE TEMPORARY TABLE tBuy + ENGINE = MEMORY + SELECT tBuy.itemFk, IFNULL(iss.visible,0) visible, tBuy.totalQuantity, IFNULL(sales.sold,0) sold + FROM (SELECT b.itemFk, SUM(b.quantity) totalQuantity + FROM buy b + WHERE b.entryFk = vOriginalEntry + GROUP BY b.itemFk + ) tBuy + LEFT JOIN ( + SELECT ish.itemFk, SUM(visible) visible + FROM itemShelving ish + JOIN shelving sh ON sh.code = ish.shelvingFk + JOIN parking p ON p.id = sh.parkingFk + JOIN sector s ON s.id = p.sectorFk + WHERE s.warehouseFk = vWarehouseFk + AND sh.parked = util.VN_CURDATE() + GROUP BY ish.itemFk) iss ON tBuy.itemFk = iss.itemFk + LEFT JOIN ( + SELECT s.itemFk, SUM(s.quantity) sold + FROM ticket t + JOIN sale s ON s.ticketFk = t.id + JOIN itemShelvingSale iss ON iss.saleFk = s.id + JOIN itemShelving is2 ON is2.id = iss.itemShelvingFk + JOIN shelving s2 ON s2.code = is2.shelvingFk + WHERE t.shipped BETWEEN util.VN_CURDATE() AND util.dayend(util.VN_CURDATE()) + AND s2.parked = util.VN_CURDATE() + GROUP BY s.itemFk) sales ON sales.itemFk = tBuy.itemFk + WHERE visible = tBuy.totalQuantity + OR iss.itemFk IS NULL; + + UPDATE buy b + JOIN (SELECT * FROM tBuy) sub ON sub.itemFk = b.itemFk + SET b.quantity = sub.totalQuantity - sub.visible - sub.sold + WHERE b.entryFk = vNewEntryFk; + + -- Limpia la nueva entrada + DELETE b.* + FROM buy b + WHERE b.entryFk = vNewEntryFk + AND b.quantity = 0; + + COMMIT; + + SET vNewEntry = vNewEntryFk; + + CALL cache.visible_refresh(@c,TRUE,7); + CALL cache.available_refresh(@c, TRUE, 7, util.VN_CURDATE()); + +END$$ +DELIMITER ; diff --git a/db/versions/11300-limeMedeola/00-firstScript.sql b/db/versions/11300-limeMedeola/00-firstScript.sql index 21920b692..313a65e81 100644 --- a/db/versions/11300-limeMedeola/00-firstScript.sql +++ b/db/versions/11300-limeMedeola/00-firstScript.sql @@ -79,7 +79,71 @@ UPDATE vn.tag WHERE name= 'Tronco'; -GRANT SELECT, UPDATE, INSERT, DELETE ON TABLE vn.itemFarmingTag TO logisticAssist; -GRANT SELECT, UPDATE, INSERT, DELETE ON TABLE vn.itemWrappingTag TO logisticAssist; -GRANT SELECT, UPDATE, INSERT, DELETE ON TABLE vn.itemLanguageTag TO logisticAssist; -GRANT SELECT, UPDATE, INSERT, DELETE ON TABLE vn.itemStemTag TO logisticAssist; \ No newline at end of file +CREATE TABLE IF NOT EXISTS `vn`.`itemBreederTag` ( + `id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT, + `name` varchar(50) DEFAULT NULL, + PRIMARY KEY (`id`), + UNIQUE KEY `name_UNIQUE` (`name`) +) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT + CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; + +INSERT IGNORE INTO `vn`.`itemBreederTag` (`name`) VALUES ('David Austin'); + +UPDATE vn.tag + SET isFree=0, + sourceTable='itemBreederTag' + WHERE name= 'Obtentor'; + + + +CREATE TABLE IF NOT EXISTS `vn`.`itemBaseTag` ( + `id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT, + `name` varchar(50) DEFAULT NULL, + PRIMARY KEY (`id`), + UNIQUE KEY `name_UNIQUE` (`name`) +) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT + CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; + +INSERT IGNORE INTO `vn`.`itemBaseTag` (`name`) VALUES ('Biodegradable'); +INSERT IGNORE INTO `vn`.`itemBaseTag` (`name`) VALUES ('Caballete'); +INSERT IGNORE INTO `vn`.`itemBaseTag` (`name`) VALUES ('Cerámica'); +INSERT IGNORE INTO `vn`.`itemBaseTag` (`name`) VALUES ('Cristal'); +INSERT IGNORE INTO `vn`.`itemBaseTag` (`name`) VALUES ('Plástico por inyección'); +INSERT IGNORE INTO `vn`.`itemBaseTag` (`name`) VALUES ('Madera'); +INSERT IGNORE INTO `vn`.`itemBaseTag` (`name`) VALUES ('Plástico'); +INSERT IGNORE INTO `vn`.`itemBaseTag` (`name`) VALUES ('Rígido'); +INSERT IGNORE INTO `vn`.`itemBaseTag` (`name`) VALUES ('Ruedas'); +INSERT IGNORE INTO `vn`.`itemBaseTag` (`name`) VALUES ('Sin soporte rígido'); + +UPDATE vn.tag + SET isFree=0, + sourceTable='itemBaseTag' + WHERE name= 'Soporte'; + + + +CREATE TABLE IF NOT EXISTS `vn`.`itemVatRateTag` ( + `id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT, + `name` varchar(50) DEFAULT NULL, + PRIMARY KEY (`id`), + UNIQUE KEY `name_UNIQUE` (`name`) +) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT + CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; + +INSERT IGNORE INTO `vn`.`itemVatRateTag` (`name`) VALUES ('General'); +INSERT IGNORE INTO `vn`.`itemVatRateTag` (`name`) VALUES ('Reducido'); + + +UPDATE vn.tag + SET isFree=0, + sourceTable='itemVatRateTag' + WHERE name= 'Tipo de IVA'; + + +GRANT SELECT, UPDATE, INSERT, DELETE ON TABLE vn.itemFarmingTag TO logisticAssist; +GRANT SELECT, UPDATE, INSERT, DELETE ON TABLE vn.itemWrappingTag TO logisticAssist; +GRANT SELECT, UPDATE, INSERT, DELETE ON TABLE vn.itemLanguageTag TO logisticAssist; +GRANT SELECT, UPDATE, INSERT, DELETE ON TABLE vn.itemStemTag TO logisticAssist; +GRANT SELECT, UPDATE, INSERT, DELETE ON TABLE vn.itemWrappingTag TO logisticAssist; +GRANT SELECT, UPDATE, INSERT, DELETE ON TABLE vn.itemBaseTag TO logisticAssist; +GRANT SELECT, UPDATE, INSERT, DELETE ON TABLE vn.itemBreederTag TO logisticAssist; \ No newline at end of file From 8da005f08ab1c0775c1cfee83bbdbadff3ca0cfa Mon Sep 17 00:00:00 2001 From: robert Date: Tue, 15 Oct 2024 11:19:08 +0200 Subject: [PATCH 071/136] feat: refs #8108 refs #9108 --- db/routines/vn/procedures/entry_transfer.sql | 121 ------------------- 1 file changed, 121 deletions(-) delete mode 100644 db/routines/vn/procedures/entry_transfer.sql diff --git a/db/routines/vn/procedures/entry_transfer.sql b/db/routines/vn/procedures/entry_transfer.sql deleted file mode 100644 index 6d7da2b37..000000000 --- a/db/routines/vn/procedures/entry_transfer.sql +++ /dev/null @@ -1,121 +0,0 @@ -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`entry_transfer`(vOriginalEntry INT, OUT vNewEntry INT) -BEGIN -/** -* Adelanta a mañana la mercancia de una entrada a partir de lo que hay ubicado en el almacén -* -* @param vOriginalEntry entrada que se quiera adelantar -*/ - - DECLARE vNewEntryFk INT; - DECLARE vTravelFk INT; - DECLARE vWarehouseFk INT; - - DECLARE EXIT HANDLER FOR SQLEXCEPTION - BEGIN - ROLLBACK; - RESIGNAL; - END; - - -- Clonar la entrada - CALL entry_clone(vOriginalEntry,vNewEntryFk); - - START TRANSACTION; - - -- Hay que crear un nuevo travel, con salida hoy y llegada mañana y asignar la entrada nueva al nuevo travel. - INSERT INTO travel( - shipped, - landed, - warehouseInFk, - warehouseOutFk, - `ref`, - isReceived, - agencyModeFk) - SELECT util.VN_CURDATE(), - util.VN_CURDATE() + INTERVAL 1 DAY, - t.warehouseInFk, - t.warehouseInFk, - t.`ref`, - t.isReceived, - t.agencyModeFk - FROM travel t - JOIN entry e ON e.travelFk = t.id - WHERE e.id = vOriginalEntry; - - SET vTravelFk = LAST_INSERT_ID(); - - UPDATE entry - SET travelFk = vTravelFk - WHERE id = vNewEntryFk; - - -- Poner a 0 las cantidades - UPDATE buy b - SET b.quantity = 0, b.stickers = 0 - WHERE b.entryFk = vNewEntryFk; - - -- Eliminar duplicados - DELETE b.* - FROM buy b - LEFT JOIN (SELECT b.id, b.itemFk - FROM buy b - WHERE b.entryFk = vNewEntryFk - GROUP BY b.itemFk) tBuy ON tBuy.id = b.id - WHERE b.entryFk = vNewEntryFk - AND tBuy.id IS NULL; - - SELECT t.warehouseInFk INTO vWarehouseFk - FROM travel t - JOIN entry e ON e.travelFk = t.id - WHERE e.id = vOriginalEntry; - - -- Actualizar la nueva entrada con lo que no está ubicado HOY, descontando lo vendido HOY de esas ubicaciones - CREATE OR REPLACE TEMPORARY TABLE tBuy - ENGINE = MEMORY - SELECT tBuy.itemFk, IFNULL(iss.visible,0) visible, tBuy.totalQuantity, IFNULL(sales.sold,0) sold - FROM (SELECT b.itemFk, SUM(b.quantity) totalQuantity - FROM buy b - WHERE b.entryFk = vOriginalEntry - GROUP BY b.itemFk - ) tBuy - LEFT JOIN ( - SELECT ish.itemFk, SUM(visible) visible - FROM itemShelving ish - JOIN shelving sh ON sh.code = ish.shelvingFk - JOIN parking p ON p.id = sh.parkingFk - JOIN sector s ON s.id = p.sectorFk - WHERE s.warehouseFk = vWarehouseFk - AND sh.parked = util.VN_CURDATE() - GROUP BY ish.itemFk) iss ON tBuy.itemFk = iss.itemFk - LEFT JOIN ( - SELECT s.itemFk, SUM(s.quantity) sold - FROM ticket t - JOIN sale s ON s.ticketFk = t.id - JOIN itemShelvingSale iss ON iss.saleFk = s.id - JOIN itemShelving is2 ON is2.id = iss.itemShelvingFk - JOIN shelving s2 ON s2.code = is2.shelvingFk - WHERE t.shipped BETWEEN util.VN_CURDATE() AND util.dayend(util.VN_CURDATE()) - AND s2.parked = util.VN_CURDATE() - GROUP BY s.itemFk) sales ON sales.itemFk = tBuy.itemFk - WHERE visible = tBuy.totalQuantity - OR iss.itemFk IS NULL; - - UPDATE buy b - JOIN (SELECT * FROM tBuy) sub ON sub.itemFk = b.itemFk - SET b.quantity = sub.totalQuantity - sub.visible - sub.sold - WHERE b.entryFk = vNewEntryFk; - - -- Limpia la nueva entrada - DELETE b.* - FROM buy b - WHERE b.entryFk = vNewEntryFk - AND b.quantity = 0; - - COMMIT; - - SET vNewEntry = vNewEntryFk; - - CALL cache.visible_refresh(@c,TRUE,7); - CALL cache.available_refresh(@c, TRUE, 7, util.VN_CURDATE()); - -END$$ -DELIMITER ; From 536c2fa5b5228cc0858f47229021d6bea3290d52 Mon Sep 17 00:00:00 2001 From: ivanm Date: Tue, 15 Oct 2024 13:54:02 +0200 Subject: [PATCH 072/136] feat: refs #7994 update sale.originalQuantity --- db/versions/11251-navyChrysanthemum/00-firstScript.sql | 2 -- db/versions/11251-navyChrysanthemum/01-firstScript.sql | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/db/versions/11251-navyChrysanthemum/00-firstScript.sql b/db/versions/11251-navyChrysanthemum/00-firstScript.sql index 6ec0a66bb..801405e59 100644 --- a/db/versions/11251-navyChrysanthemum/00-firstScript.sql +++ b/db/versions/11251-navyChrysanthemum/00-firstScript.sql @@ -1,5 +1,3 @@ -/* UPDATE vn.sale SET originalQuantity = quantity WHERE originalQuantity IS NULL -*/ diff --git a/db/versions/11251-navyChrysanthemum/01-firstScript.sql b/db/versions/11251-navyChrysanthemum/01-firstScript.sql index c942e0400..e3e08e0aa 100644 --- a/db/versions/11251-navyChrysanthemum/01-firstScript.sql +++ b/db/versions/11251-navyChrysanthemum/01-firstScript.sql @@ -1 +1 @@ --- ALTER TABLE vn.sale MODIFY COLUMN originalQuantity decimal(10,2) DEFAULT 0.00 NOT NULL COMMENT 'Se utiliza para notificar a través de rocket los cambios de quantity'; \ No newline at end of file +ALTER TABLE vn.sale MODIFY COLUMN originalQuantity decimal(10,2) DEFAULT 0.00 NOT NULL COMMENT 'Se utiliza para notificar a través de rocket los cambios de quantity'; \ No newline at end of file From 099fe8f9502164570079c8a718249b03b9761a95 Mon Sep 17 00:00:00 2001 From: carlossa Date: Tue, 15 Oct 2024 14:42:35 +0200 Subject: [PATCH 073/136] fix: refs #7986 fix model --- modules/worker/back/models/operator.json | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/modules/worker/back/models/operator.json b/modules/worker/back/models/operator.json index 9933babc6..b75bf6732 100644 --- a/modules/worker/back/models/operator.json +++ b/modules/worker/back/models/operator.json @@ -24,6 +24,9 @@ "warehouseFk": { "type": "number" }, + "sectorFk": { + "type": "number" + }, "labelerFk": { "type": "number" }, @@ -33,6 +36,15 @@ }, "machineFk": { "type": "number" + }, + "linesLimit": { + "type": "number" + }, + "volumeLimit": { + "type": "number" + }, + "sizeLimit": { + "type": "number" } }, "relations": { From 4a88ba5078132adee8e7f24657ee29da0445f873 Mon Sep 17 00:00:00 2001 From: jgallego Date: Tue, 15 Oct 2024 15:43:12 +0200 Subject: [PATCH 074/136] feat: refs #7744 closeAll Test --- db/dump/fixtures.before.sql | 24 ++++-- loopback/locale/es.json | 1 + loopback/locale/fr.json | 1 + loopback/locale/pt.json | 1 + modules/invoiceOut/back/models/invoice-out.js | 2 + modules/ticket/back/methods/sale/usesMana.js | 2 +- .../ticket/back/methods/ticket/closeAll.js | 44 +++++----- modules/ticket/back/methods/ticket/closure.js | 10 ++- .../methods/ticket/specs/closeAll.spec.js | 80 +++++++++++++++++++ 9 files changed, 136 insertions(+), 29 deletions(-) create mode 100644 modules/ticket/back/methods/ticket/specs/closeAll.spec.js diff --git a/db/dump/fixtures.before.sql b/db/dump/fixtures.before.sql index 7f7e50dd3..6007b73e0 100644 --- a/db/dump/fixtures.before.sql +++ b/db/dump/fixtures.before.sql @@ -632,14 +632,21 @@ INSERT INTO vn.invoiceOutConfig SET id = 1, parallelism = 8; -INSERT INTO `vn`.`invoiceOutSerial` (`code`, `description`, `isTaxed`, `taxAreaFk`, `isCEE`, `type`) +INSERT INTO `vn`.`invoiceOutSerial` + (`code`,`description`, `isTaxed`, `taxAreaFk`, `isCEE`, `type`) VALUES - ('A', 'Global nacional', 1, 'NATIONAL', 0, 'global'), - ('T', 'Española rapida', 1, 'NATIONAL', 0, 'quick'), - ('V', 'Intracomunitaria global', 0, 'CEE', 1, 'global'), - ('M', 'Múltiple nacional', 1, 'NATIONAL', 0, 'multiple'), - ('R', 'Rectificativa', 1, 'NATIONAL', 0, NULL), - ('E', 'Exportación rápida', 0, 'WORLD', 0, 'quick'); + ('A', 'Global nacional', 1, 'NATIONAL', 0, 'global'), + ('T', 'Española rapida', 1, 'NATIONAL', 0, 'quick'), + ('V', 'Intracomunitaria global', 0, 'CEE', 1, 'global'), + ('M', 'Múltiple nacional', 1, 'NATIONAL', 0, 'multiple'), + ('R', 'Rectificativa', 1, 'NATIONAL', 0, NULL), + ('E', 'Exportación rápida', 0, 'WORLD', 0, 'quick'), + ('H', 'Intracomunitaria rápida', 0, 'CEE', 1, 'quick'), + ('P', 'Factura simplificada', 1, 'NATIONAL', 0, NULL), + ('PE', 'COOPERATIE FLORAHOLLAND UA', 0, 'CEE', 1, NULL), + ('S', 'Simplificada', 1, 'NATIONAL', 0, NULL), + ('X', 'Exportación global', 0, 'WORLD', 0, 'global'), + ('N', 'Múltiple Intracomunitaria', 0, 'CEE', 1, 'multiple'); INSERT INTO `vn`.`invoiceOut`(`id`, `serial`, `amount`, `issued`,`clientFk`, `created`, `companyFk`, `dued`, `booked`, `bankFk`, `hasPdf`) VALUES @@ -2911,7 +2918,8 @@ INSERT INTO `util`.`notification` (`id`, `name`, `description`) (6, 'book-entry-deleted', 'accounting entries deleted'), (7, 'zone-included','An email to notify zoneCollisions'), (8, 'backup-printer-selected','A backup printer has been selected'), - (9, 'mrw-deadline','The MRW deadline has passed'); + (9, 'mrw-deadline','The MRW deadline has passed'), + (10,'invoice-ticket-closure','Tickets not invoiced during the nightly closure ticket process'); TRUNCATE `util`.`notificationAcl`; INSERT INTO `util`.`notificationAcl` (`notificationFk`, `roleFk`) diff --git a/loopback/locale/es.json b/loopback/locale/es.json index 9308fd4ec..0349fa8fb 100644 --- a/loopback/locale/es.json +++ b/loopback/locale/es.json @@ -350,6 +350,7 @@ "Cmr file does not exist": "El archivo del cmr no existe", "You are not allowed to modify the alias": "No estás autorizado a modificar el alias", "The address of the customer must have information about Incoterms and Customs Agent": "El consignatario del cliente debe tener informado Incoterms y Agente de aduanas", + "No invoice series found for these parameters": "No se encontró una serie para estos parámetros", "The line could not be marked": "La linea no puede ser marcada", "Through this procedure, it is not possible to modify the password of users with verified email": "Mediante este procedimiento, no es posible modificar la contraseña de usuarios con correo verificado", "They're not your subordinate": "No es tu subordinado/a.", diff --git a/loopback/locale/fr.json b/loopback/locale/fr.json index a6648b186..23bd5cc04 100644 --- a/loopback/locale/fr.json +++ b/loopback/locale/fr.json @@ -350,6 +350,7 @@ "Cmr file does not exist": "Le fichier cmr n'existe pas", "You are not allowed to modify the alias": "Vous n'êtes pas autorisé à modifier l'alias", "The address of the customer must have information about Incoterms and Customs Agent": "L'adresse du client doit contenir des informations sur les Incoterms et l'agent des douanes", + "No invoice series found for these parameters": "Aucune série de facture trouvée pour ces paramètres", "The line could not be marked": "La ligne ne peut pas être marquée", "This password can only be changed by the user themselves": "Ce mot de passe ne peut être modifié que par l'utilisateur lui-même", "They're not your subordinate": "Ce n'est pas votre subordonné.", diff --git a/loopback/locale/pt.json b/loopback/locale/pt.json index a43f0e780..f85afd607 100644 --- a/loopback/locale/pt.json +++ b/loopback/locale/pt.json @@ -350,6 +350,7 @@ "Cmr file does not exist": "O arquivo CMR não existe", "You are not allowed to modify the alias": "Você não tem permissão para modificar o alias", "The address of the customer must have information about Incoterms and Customs Agent": "O endereço do cliente deve ter informações sobre Incoterms e Agente Aduaneiro", + "No invoice series found for these parameters": "Nenhuma série de fatura encontrada para esses parâmetros", "The line could not be marked": "A linha não pôde ser marcada", "This password can only be changed by the user themselves": "Esta senha só pode ser alterada pelo próprio usuário", "They're not your subordinate": "Eles não são seus subordinados.", diff --git a/modules/invoiceOut/back/models/invoice-out.js b/modules/invoiceOut/back/models/invoice-out.js index bab1fa375..f8fc8cdbf 100644 --- a/modules/invoiceOut/back/models/invoice-out.js +++ b/modules/invoiceOut/back/models/invoice-out.js @@ -79,6 +79,8 @@ module.exports = Self => { type ], myOptions); + if (!serial) + throw new UserError('No invoice series found for these parameters'); const invoiceOutSerial = await Self.app.models.InvoiceOutSerial.findById(serial); if (invoiceOutSerial?.taxAreaFk == 'WORLD') { diff --git a/modules/ticket/back/methods/sale/usesMana.js b/modules/ticket/back/methods/sale/usesMana.js index 31beb3a4c..b4768d80a 100644 --- a/modules/ticket/back/methods/sale/usesMana.js +++ b/modules/ticket/back/methods/sale/usesMana.js @@ -31,6 +31,6 @@ module.exports = Self => { const usesMana = departments.find(department => department.id == workerDepartment.departmentFk); - return usesMana ? true : false; + return !!usesMana; }; }; diff --git a/modules/ticket/back/methods/ticket/closeAll.js b/modules/ticket/back/methods/ticket/closeAll.js index 4fd72d454..1b3f84295 100644 --- a/modules/ticket/back/methods/ticket/closeAll.js +++ b/modules/ticket/back/methods/ticket/closeAll.js @@ -1,11 +1,17 @@ -const UserError = require('vn-loopback/util/user-error'); const closure = require('./closure'); module.exports = Self => { Self.remoteMethodCtx('closeAll', { description: 'Makes the closure process from all warehouses', accessType: 'WRITE', - accepts: [], + accepts: [ + { + arg: 'options', + type: 'object', + http: {source: 'body'}, + description: 'Optional parameters, including transaction.' + } + ], returns: { type: 'object', root: true @@ -16,21 +22,20 @@ module.exports = Self => { } }); - Self.closeAll = async ctx => { + Self.closeAll = async(ctx, options) => { + const userId = ctx.req.accessToken.userId; + const myOptions = {userId}; + + if (typeof options == 'object') + Object.assign(myOptions, options); + + let tx; + // IMPORTANT: Due to its high cost in production, wrapping this process in a transaction may cause timeouts. + const toDate = Date.vnNew(); toDate.setHours(0, 0, 0, 0); toDate.setDate(toDate.getDate() - 1); - const todayMinDate = Date.vnNew(); - todayMinDate.setHours(0, 0, 0, 0); - - const todayMaxDate = Date.vnNew(); - todayMaxDate.setHours(23, 59, 59, 59); - - // Prevent closure for current day - if (toDate >= todayMinDate && toDate <= todayMaxDate) - throw new UserError('You cannot close tickets for today'); - const tickets = await Self.rawSql(` SELECT t.id, t.clientFk, @@ -58,12 +63,12 @@ module.exports = Self => { AND t.shipped BETWEEN ? - INTERVAL tc.closureDaysAgo DAY AND util.dayEnd(?) AND t.refFk IS NULL GROUP BY t.id - `, [toDate, toDate]); + `, [toDate, toDate], myOptions); const ticketIds = tickets.map(ticket => ticket.id); await Self.rawSql(` INSERT INTO util.debug (variable, value) VALUES ('nightInvoicing', ?) - `, [ticketIds.join(',')]); + `, [ticketIds.join(',')], myOptions); await Self.rawSql(` WITH ticketNotInvoiceable AS( @@ -133,9 +138,9 @@ module.exports = Self => { ) SELECT IF(errors = '{"tickets": null}', 'No errors', util.notification_send('invoice-ticket-closure', errors, NULL)) - FROM ticketNotInvoiceable`, [toDate, toDate]); + FROM ticketNotInvoiceable`, [toDate, toDate], myOptions); - await closure(ctx, Self, tickets); + await closure(ctx, Self, tickets, myOptions); await Self.rawSql(` UPDATE ticket t @@ -150,7 +155,10 @@ module.exports = Self => { AND al.code NOT IN ('DELIVERED', 'PACKED') AND NOT t.packages AND tob.id IS NULL - AND t.routeFk`, [toDate, toDate], {userId: ctx.req.accessToken.userId}); + AND t.routeFk`, [toDate, toDate], myOptions); + + if (tx) + await tx.commit(); return { message: 'Success' diff --git a/modules/ticket/back/methods/ticket/closure.js b/modules/ticket/back/methods/ticket/closure.js index 56bd6eccd..64f198834 100644 --- a/modules/ticket/back/methods/ticket/closure.js +++ b/modules/ticket/back/methods/ticket/closure.js @@ -19,9 +19,15 @@ module.exports = async function(ctx, Self, tickets, options) { const failedtickets = []; for (const ticket of tickets) { try { - await Self.rawSql(`CALL util.debugAdd('invoicingTicket', ?)`, [ticket.id], {userId}); + await Self.rawSql(`CALL util.debugAdd('invoicingTicket', ?)`, [ticket.id], {userId}, + myOptions); - await Self.app.models.InvoiceOut.getSerial(ticket.clientFk, ticket.companyFk, ticket.addressFk, 'quick'); + await Self.app.models.InvoiceOut.getSerial( + ticket.clientFk, + ticket.companyFk, + ticket.addressFk, + 'quick', + myOptions); await Self.rawSql( `CALL vn.ticket_closeByTicket(?)`, [ticket.id], diff --git a/modules/ticket/back/methods/ticket/specs/closeAll.spec.js b/modules/ticket/back/methods/ticket/specs/closeAll.spec.js new file mode 100644 index 000000000..4b067ce7e --- /dev/null +++ b/modules/ticket/back/methods/ticket/specs/closeAll.spec.js @@ -0,0 +1,80 @@ +const models = require('vn-loopback/server/server').models; +const LoopBackContext = require('loopback-context'); + +fdescribe('Ticket Closure - closeAll function', () => { + let ctx = { + req: { + getLocale: () => 'es', + accessToken: {userId: 1106}, + headers: {origin: 'http://localhost'}, + __: value => value, + }, + args: {} + }; + let options; + let tx; + let originalVnNew; + + beforeEach(async() => { + spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({active: ctx.req}); + tx = await models.Ticket.beginTransaction({}); + options = {transaction: tx}; + originalVnNew = Date.vnNew; + spyOn(Date, 'vnNew').and.callFake(() => { + const mockDate = originalVnNew(); + mockDate.setDate(mockDate.getDate() + 1); + return mockDate; + }); + }); + + afterEach(async() => { + if (tx) + await tx.rollback(); + }); + + xit('should successfully close all tickets when conditions are met', async() => { + const ticketsBefore = await models.Ticket.find({ + where: { + packages: {neq: 0} + } + }, options); + const packedTicketsIds = ticketsBefore.map(ticket => ticket.id); + + const packedTicketsBefore = await models.TicketLastState.find({ + where: { + ticketFk: {inq: packedTicketsIds}, + lastState: 'Encajado' + } + }, options); + + await models.Ticket.closeAll(ctx, options); + + const packedTicketsAfter = await models.TicketLastState.find({ + where: { + ticketFk: {inq: packedTicketsIds}, + lastState: 'Encajado' + } + }, options); + + expect(packedTicketsBefore.length).toBeGreaterThan(packedTicketsAfter.length); + }); + + fit('should set routeFk to NULL when conditions are met', async() => { + const ticketsBefore = await models.Ticket.find({ + where: { + routeFk: {neq: null} + } + }, options); + + await models.Ticket.closeAll(ctx, options); + + const ticketsAfter = await models.Ticket.find({ + where: { + id: {inq: ticketsBefore.map(ticket => ticket.id)}, + routeFk: {neq: null} + } + }, options); + + expect(ticketsBefore.length).toBeGreaterThan(ticketsAfter.length); + }); +}); From b592ccc1624542e0f9efc1c9dedca4d12566f3bd Mon Sep 17 00:00:00 2001 From: sergiodt Date: Tue, 15 Oct 2024 17:01:09 +0200 Subject: [PATCH 075/136] fix: refs #6861 getTickets --- back/methods/collection/getTickets.js | 6 ++++-- db/routines/vn/triggers/itemShelvingSale_afterInsert.sql | 4 ++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/back/methods/collection/getTickets.js b/back/methods/collection/getTickets.js index 2a2b67524..48301a366 100644 --- a/back/methods/collection/getTickets.js +++ b/back/methods/collection/getTickets.js @@ -62,7 +62,8 @@ module.exports = Self => { p.code parkingCodePrevia, p.pickingOrder pickingOrderPrevia, iss.id itemShelvingSaleFk, - iss.isPicked + iss.isPicked, + iss.itemShelvingFk FROM ticketCollection tc LEFT JOIN collection c ON c.id = tc.collectionFk JOIN sale s ON s.ticketFk = tc.ticketFk @@ -102,7 +103,8 @@ module.exports = Self => { p.code, p.pickingOrder, iss.id itemShelvingSaleFk, - iss.isPicked + iss.isPicked, + iss.itemShelvingFk FROM sectorCollection sc JOIN sectorCollectionSaleGroup ss ON ss.sectorCollectionFk = sc.id JOIN saleGroup sg ON sg.id = ss.saleGroupFk diff --git a/db/routines/vn/triggers/itemShelvingSale_afterInsert.sql b/db/routines/vn/triggers/itemShelvingSale_afterInsert.sql index 3531b094c..5ad83d289 100644 --- a/db/routines/vn/triggers/itemShelvingSale_afterInsert.sql +++ b/db/routines/vn/triggers/itemShelvingSale_afterInsert.sql @@ -3,10 +3,10 @@ CREATE OR REPLACE DEFINER=`vn`@`localhost` TRIGGER `vn`.`itemShelvingSale_afterI AFTER INSERT ON `itemShelvingSale` FOR EACH ROW BEGIN - UPDATE sale s JOIN operator o ON o.workerFk = account.myUser_getId() - SET s.isPicked = IF(o.isOnReservationMode, s.isPicked, TRUE) + JOIN sector se ON s.id = o.sectorFk + SET s.isPicked = IF((se.isOnReservationMode IS NULL AND o.isOnReservationMode) OR se.isOnReservationMode, s.isPicked, TRUE) WHERE id = NEW.saleFk; END$$ DELIMITER ; \ No newline at end of file From 2adc424ccb3814a51a87e3b1cdfba0ca86b4da5e Mon Sep 17 00:00:00 2001 From: sergiodt Date: Tue, 15 Oct 2024 17:07:35 +0200 Subject: [PATCH 076/136] fix: refs #6861 getTickets --- db/routines/vn/triggers/itemShelvingSale_afterInsert.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/routines/vn/triggers/itemShelvingSale_afterInsert.sql b/db/routines/vn/triggers/itemShelvingSale_afterInsert.sql index 5ad83d289..1980691b5 100644 --- a/db/routines/vn/triggers/itemShelvingSale_afterInsert.sql +++ b/db/routines/vn/triggers/itemShelvingSale_afterInsert.sql @@ -5,7 +5,7 @@ CREATE OR REPLACE DEFINER=`vn`@`localhost` TRIGGER `vn`.`itemShelvingSale_afterI BEGIN UPDATE sale s JOIN operator o ON o.workerFk = account.myUser_getId() - JOIN sector se ON s.id = o.sectorFk + JOIN sector se ON se.id = o.sectorFk SET s.isPicked = IF((se.isOnReservationMode IS NULL AND o.isOnReservationMode) OR se.isOnReservationMode, s.isPicked, TRUE) WHERE id = NEW.saleFk; END$$ From d57f4fc44a7711b891b65b19c7ec8a9b6104abbf Mon Sep 17 00:00:00 2001 From: jorgep Date: Tue, 15 Oct 2024 17:24:14 +0200 Subject: [PATCH 077/136] chore: refs #7919 refactor, drop relation on back --- db/routines/vn/triggers/ticket_afterUpdate.sql | 5 ----- modules/ticket/back/methods/ticket/setDeleted.js | 5 ++++- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/db/routines/vn/triggers/ticket_afterUpdate.sql b/db/routines/vn/triggers/ticket_afterUpdate.sql index e849c1faa..f6c5e6523 100644 --- a/db/routines/vn/triggers/ticket_afterUpdate.sql +++ b/db/routines/vn/triggers/ticket_afterUpdate.sql @@ -12,10 +12,5 @@ BEGIN CALL ticket_doCmr(NEW.id); END IF; END IF; - - IF NEW.isDeleted THEN - DELETE FROM ticketRefund - WHERE refundTicketFk = NEW.id; - END IF; END$$ DELIMITER ; diff --git a/modules/ticket/back/methods/ticket/setDeleted.js b/modules/ticket/back/methods/ticket/setDeleted.js index a684e1cbc..e868e9258 100644 --- a/modules/ticket/back/methods/ticket/setDeleted.js +++ b/modules/ticket/back/methods/ticket/setDeleted.js @@ -49,9 +49,12 @@ module.exports = Self => { where: {originalTicketFk: id} }, myOptions); + const isRefund = !!ticketRefunds?.length; + const allDeleted = ticketRefunds.every(refund => refund.refundTicket().isDeleted); - if (ticketRefunds?.length && !allDeleted) { + if (!isRefund) await models.TicketRefund.destroyAll({refundTicketFk: id}, myOptions); + if (isRefund && !allDeleted) { const notDeleted = []; for (const refund of ticketRefunds) if (!refund.refundTicket().isDeleted) notDeleted.push(refund.refundTicket().id); From 12abca0a2d2819e559e4d64a8ee147a89c278c00 Mon Sep 17 00:00:00 2001 From: sergiodt Date: Tue, 15 Oct 2024 18:12:07 +0200 Subject: [PATCH 078/136] fix: refs #6861 getTickets --- db/routines/vn/triggers/itemShelvingSale_afterInsert.sql | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/db/routines/vn/triggers/itemShelvingSale_afterInsert.sql b/db/routines/vn/triggers/itemShelvingSale_afterInsert.sql index 1980691b5..ad4a6f670 100644 --- a/db/routines/vn/triggers/itemShelvingSale_afterInsert.sql +++ b/db/routines/vn/triggers/itemShelvingSale_afterInsert.sql @@ -6,7 +6,7 @@ BEGIN UPDATE sale s JOIN operator o ON o.workerFk = account.myUser_getId() JOIN sector se ON se.id = o.sectorFk - SET s.isPicked = IF((se.isOnReservationMode IS NULL AND o.isOnReservationMode) OR se.isOnReservationMode, s.isPicked, TRUE) - WHERE id = NEW.saleFk; + SET s.isPicked = IF(IFNULL(se.isOnReservationMode, o.isOnReservationMode), s.isPicked, TRUE) + WHERE s.id = NEW.saleFk; END$$ DELIMITER ; \ No newline at end of file From 46e657675b1ce8ae70c1742c41d17746892978e9 Mon Sep 17 00:00:00 2001 From: carlossa Date: Wed, 16 Oct 2024 08:26:39 +0200 Subject: [PATCH 079/136] fix: refs #7906 remake method --- loopback/locale/en.json | 3 ++- loopback/locale/es.json | 5 +++-- modules/zone/back/methods/zone/deleteZone.js | 4 +++- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/loopback/locale/en.json b/loopback/locale/en.json index ea84cb6eb..a7e21960b 100644 --- a/loopback/locale/en.json +++ b/loopback/locale/en.json @@ -240,5 +240,6 @@ "There is already a tray with the same height": "There is already a tray with the same height", "The height must be greater than 50cm": "The height must be greater than 50cm", "The maximum height of the wagon is 200cm": "The maximum height of the wagon is 200cm", - "The quantity claimed cannot be greater than the quantity of the line": "The quantity claimed cannot be greater than the quantity of the line" + "The quantity claimed cannot be greater than the quantity of the line": "The quantity claimed cannot be greater than the quantity of the line", + "There are tickets for this area, delete them first": "There are tickets for this area, delete them first" } diff --git a/loopback/locale/es.json b/loopback/locale/es.json index 9308fd4ec..6d50f634e 100644 --- a/loopback/locale/es.json +++ b/loopback/locale/es.json @@ -382,5 +382,6 @@ "This buyer has already made a reservation for this date": "Este comprador ya ha hecho una reserva para esta fecha", "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" -} \ No newline at end of file + "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" +} diff --git a/modules/zone/back/methods/zone/deleteZone.js b/modules/zone/back/methods/zone/deleteZone.js index a75302703..34ab177ac 100644 --- a/modules/zone/back/methods/zone/deleteZone.js +++ b/modules/zone/back/methods/zone/deleteZone.js @@ -1,3 +1,4 @@ +const UserError = require('vn-loopback/util/user-error'); module.exports = Self => { Self.remoteMethodCtx('deleteZone', { description: 'Delete a zone', @@ -57,7 +58,8 @@ module.exports = Self => { where: {id: userId} }, myOptions); - await models.Ticket.rawSql('UPDATE ticket SET zoneFk = NULL WHERE zoneFk = ?', [id], myOptions); + if (ticketList.length > 0) + throw new UserError('There are tickets for this area, delete them first'); for (ticket of ticketList) { if (ticket.ticketState().alertLevel == 0) { From c6e764b478b9481376f187c32c9c73b5b26cb23d Mon Sep 17 00:00:00 2001 From: jgallego Date: Wed, 16 Oct 2024 08:32:10 +0200 Subject: [PATCH 080/136] feat: refs #7348 hasDailyInvoice from client --- back/models/autonomy.json | 6 +- back/models/country.json | 4 + back/models/province.json | 5 +- db/routines/vn/procedures/client_create.sql | 10 +- db/routines/vn/procedures/ticket_close.sql | 7 +- .../11302-limeTulip/00-firstScript.sql | 13 ++ .../back/methods/client/createWithUser.js | 20 ++- .../client/specs/createWithUser.spec.js | 143 +++++++++++------- .../ticket/back/methods/ticket/closeAll.js | 4 +- .../back/methods/ticket/closeByTicket.js | 4 +- 10 files changed, 145 insertions(+), 71 deletions(-) create mode 100644 db/versions/11302-limeTulip/00-firstScript.sql diff --git a/back/models/autonomy.json b/back/models/autonomy.json index 8c9d82936..214061cf5 100644 --- a/back/models/autonomy.json +++ b/back/models/autonomy.json @@ -16,6 +16,10 @@ "name": { "type": "string", "required": true + }, + "hasDailyInvoice": { + "type": "boolean", + "description": "Indicates if the autonomy has daily invoice enabled" } }, "relations": { @@ -40,4 +44,4 @@ "permission": "ALLOW" } ] -} \ No newline at end of file +} diff --git a/back/models/country.json b/back/models/country.json index 5b9d842a8..80d456702 100644 --- a/back/models/country.json +++ b/back/models/country.json @@ -28,6 +28,10 @@ }, "continentFk": { "type": "number" + }, + "hasDailyInvoice": { + "type": "boolean", + "description": "Indicates if the autonomy has daily invoice enabled" } }, "relations": { diff --git a/back/models/province.json b/back/models/province.json index 77e0b24a6..61a1574d7 100644 --- a/back/models/province.json +++ b/back/models/province.json @@ -16,6 +16,9 @@ "name": { "type": "string", "required": true + }, + "autonomyFk": { + "type": "number" } }, "relations": { @@ -55,4 +58,4 @@ "permission": "ALLOW" } ] -} \ No newline at end of file +} diff --git a/db/routines/vn/procedures/client_create.sql b/db/routines/vn/procedures/client_create.sql index 3df3df905..fad01c107 100644 --- a/db/routines/vn/procedures/client_create.sql +++ b/db/routines/vn/procedures/client_create.sql @@ -34,22 +34,19 @@ BEGIN DECLARE vIsTaxDataChecked TINYINT(1); DECLARE vHasCoreVnl BOOLEAN; DECLARE vMandateTypeFk INT; - DECLARE vHasDailyInvoice BOOLEAN; SELECT cc.defaultPayMethodFk, cc.defaultDueDay, cc.defaultCredit, cc.defaultIsTaxDataChecked, cc.defaultHasCoreVnl, - cc.defaultMandateTypeFk, - c.hasDailyInvoice + cc.defaultMandateTypeFk INTO vPayMethodFk, vDueDay, vDefaultCredit, vIsTaxDataChecked, vHasCoreVnl, - vMandateTypeFk, - vHasDailyInvoice + vMandateTypeFk FROM clientConfig cc LEFT JOIN province p ON p.id = vProvinceFk LEFT JOIN country c ON c.id = p.countryFk; @@ -70,8 +67,7 @@ BEGIN credit = vDefaultCredit, isTaxDataChecked = vIsTaxDataChecked, hasCoreVnl = vHasCoreVnl, - isEqualizated = FALSE, - hasDailyInvoice = vHasDailyInvoice + isEqualizated = FALSE ON duplicate KEY UPDATE payMethodFk = vPayMethodFk, dueDay = vDueDay, diff --git a/db/routines/vn/procedures/ticket_close.sql b/db/routines/vn/procedures/ticket_close.sql index 0da001ffa..e2dcef9a5 100644 --- a/db/routines/vn/procedures/ticket_close.sql +++ b/db/routines/vn/procedures/ticket_close.sql @@ -43,7 +43,7 @@ BEGIN c.isTaxDataChecked, t.companyFk, t.shipped, - IFNULL(a.hasDailyInvoice, co.hasDailyInvoice), + c.hasDailyInvoice, w.isManaged, c.hasToInvoice INTO vClientFk, @@ -55,9 +55,6 @@ BEGIN vHasToInvoice FROM ticket t JOIN `client` c ON c.id = t.clientFk - JOIN province p ON p.id = c.provinceFk - LEFT JOIN autonomy a ON a.id = p.autonomyFk - JOIN country co ON co.id = p.countryFk JOIN warehouse w ON w.id = t.warehouseFk WHERE t.id = vCurTicketFk; @@ -85,7 +82,7 @@ BEGIN IF(vHasDailyInvoice) AND vHasToInvoice THEN SELECT invoiceSerial(vClientFk, vCompanyFk, 'quick') INTO vSerial; - IF vSerial IS NULL THEN + IF vSerial IS NULL THEN CALL util.throw('Cannot booking without a serial'); END IF; diff --git a/db/versions/11302-limeTulip/00-firstScript.sql b/db/versions/11302-limeTulip/00-firstScript.sql new file mode 100644 index 000000000..7bda31b64 --- /dev/null +++ b/db/versions/11302-limeTulip/00-firstScript.sql @@ -0,0 +1,13 @@ + +UPDATE `vn`.`client` c + JOIN `vn`.`country` co ON co.id=c.countryFk +SET c.hasDailyInvoice = co.hasDailyInvoice +WHERE co.hasDailyInvoice IS NOT NULL + AND c.hasDailyInvoice = FALSE; + +UPDATE `vn`.`client` c + JOIN `vn`.`province` p ON p.id=c.provinceFk + JOIN `vn`.`autonomy` a ON a.id = p.autonomyFk +SET c.hasDailyInvoice = a.hasDailyInvoice +WHERE a.hasDailyInvoice IS NOT NULL + AND c.hasDailyInvoice = FALSE; diff --git a/modules/client/back/methods/client/createWithUser.js b/modules/client/back/methods/client/createWithUser.js index 06b885ab8..c8cd282e1 100644 --- a/modules/client/back/methods/client/createWithUser.js +++ b/modules/client/back/methods/client/createWithUser.js @@ -43,6 +43,23 @@ module.exports = function(Self) { }; try { + const province = await models.Province.findOne({ + where: {id: data.provinceFk}, + fields: ['autonomyFk'] + }); + + const autonomy = province ? await models.Autonomy.findOne({ + where: {id: province.autonomyFk}, + fields: ['hasDailyInvoice'] + }) : null; + + const country = await models.Country.findOne({ + where: {id: data.countryFk}, + fields: ['hasDailyInvoice'] + }); + + const hasDailyInvoice = (autonomy?.hasDailyInvoice ?? country?.hasDailyInvoice) || false; + const account = await models.VnUser.create(user, myOptions); const client = await Self.create({ id: account.id, @@ -57,7 +74,8 @@ module.exports = function(Self) { provinceFk: data.provinceFk, countryFk: data.countryFk, isEqualizated: data.isEqualizated, - businessTypeFk: data.businessTypeFk + businessTypeFk: data.businessTypeFk, + hasDailyInvoice: hasDailyInvoice }, myOptions); const address = await models.Address.create({ diff --git a/modules/client/back/methods/client/specs/createWithUser.spec.js b/modules/client/back/methods/client/specs/createWithUser.spec.js index 5b1ff5da9..f47c24087 100644 --- a/modules/client/back/methods/client/specs/createWithUser.spec.js +++ b/modules/client/back/methods/client/specs/createWithUser.spec.js @@ -1,67 +1,79 @@ const models = require('vn-loopback/server/server').models; + describe('Client Create', () => { - const newAccount = { - userName: 'deadpool', - email: 'deadpool@marvel.com', - fi: '16195279J', - name: 'Wade', - socialName: 'DEADPOOL MARVEL', - street: 'WALL STREET', - city: 'New York', - businessTypeFk: 'florist', - provinceFk: 1 - }; - const newAccountWithoutEmail = JSON.parse(JSON.stringify(newAccount)); - delete newAccountWithoutEmail.email; + let options; + let tx; beforeAll.mockLoopBackContext(); - it(`should not find deadpool as he's not created yet`, async() => { - const tx = await models.Client.beginTransaction({}); + beforeEach(async() => { + tx = await models.Client.beginTransaction({}); + options = {transaction: tx}; + }); + afterEach(async() => await tx.rollback()); + + it('should not find deadpool as he is not created yet', async() => { try { - const options = {transaction: tx}; + const account = await models.VnUser.findOne({where: {name: 'deadpool'}}, options); + const client = await models.Client.findOne({where: {name: 'Wade'}}, options); - const account = await models.VnUser.findOne({where: {name: newAccount.userName}}, options); - const client = await models.Client.findOne({where: {name: newAccount.name}}, options); - - expect(account).toEqual(null); - expect(client).toEqual(null); - - await tx.rollback(); + expect(account).toBeNull(); + expect(client).toBeNull(); } catch (e) { await tx.rollback(); throw e; } }); - it('should not create a new account', async() => { - const tx = await models.Client.beginTransaction({}); - + it('should throw an error when creating a new account without email', async() => { let error; + const newAccountWithoutEmail = { + userName: 'deadpool', + fi: '16195279J', + name: 'Wade', + socialName: 'DEADPOOL MARVEL', + street: 'WALL STREET', + city: 'New York', + businessTypeFk: 'florist', + provinceFk: 1 + }; + try { - const options = {transaction: tx}; await models.Client.createWithUser(newAccountWithoutEmail, options); - - await tx.rollback(); + fail('shapoifaspodifa spdofij'); } catch (e) { - error = e.message; - - await tx.rollback(); + error = e; } - expect(error).toEqual(`An email is necessary`); + expect(error.message).toEqual('An email is necessary'); }); - it('should create a new account', async() => { - const tx = await models.Client.beginTransaction({}); + it('should create a new account with dailyInvoice', async() => { + const newAccount = { + userName: 'deadpool', + email: 'deadpool@marvel.com', + fi: '16195279J', + name: 'Wade', + socialName: 'DEADPOOL MARVEL', + street: 'WALL STREET', + city: 'New York', + businessTypeFk: 'florist', + provinceFk: 1 + }; try { - const options = {transaction: tx}; + const province = await models.Province.findById(newAccount.provinceFk, { + fields: ['id', 'name', 'autonomyFk'], + include: { + relation: 'autonomy' + } + }, options); const client = await models.Client.createWithUser(newAccount, options); const account = await models.VnUser.findOne({where: {name: newAccount.userName}}, options); + expect(province.autonomy().hasDailyInvoice).toBeTruthy(); expect(account.name).toEqual(newAccount.userName); expect(client.id).toEqual(account.id); expect(client.name).toEqual(newAccount.name); @@ -69,8 +81,38 @@ describe('Client Create', () => { expect(client.fi).toEqual(newAccount.fi); expect(client.socialName).toEqual(newAccount.socialName); expect(client.businessTypeFk).toEqual(newAccount.businessTypeFk); - + expect(client.hasDailyInvoice).toBeTruthy(); + } catch (e) { await tx.rollback(); + throw e; + } + }); + + it('should create a new account without dailyInvoice', async() => { + const newAccount = { + userName: 'deadpool', + email: 'deadpool@marvel.com', + fi: '16195279J', + name: 'Wade', + socialName: 'DEADPOOL MARVEL', + street: 'WALL STREET', + city: 'New York', + businessTypeFk: 'florist', + provinceFk: 3 + }; + + try { + const province = await models.Province.findById(newAccount.provinceFk, { + fields: ['id', 'name', 'autonomyFk'], + include: { + relation: 'autonomy' + } + }, options); + + const client = await models.Client.createWithUser(newAccount, options); + + expect(province.autonomy.hasDailyInvoice).toBeFalsy(); + expect(client.hasDailyInvoice).toBeFalsy(); } catch (e) { await tx.rollback(); throw e; @@ -78,26 +120,25 @@ describe('Client Create', () => { }); it('should not be able to create a user if exists', async() => { - const tx = await models.Client.beginTransaction({}); - let error; - + const newAccount = { + userName: 'deadpool', + email: 'deadpool@marvel.com', + fi: '16195279J', + name: 'Wade', + socialName: 'DEADPOOL MARVEL', + street: 'WALL STREET', + city: 'New York', + businessTypeFk: 'florist', + provinceFk: 1 + }; try { - const options = {transaction: tx}; - await models.Client.createWithUser(newAccount, options); - const client = await models.Client.createWithUser(newAccount, options); - - expect(client).toBeNull(); - - await tx.rollback(); + await models.Client.createWithUser(newAccount, options); } catch (e) { - await tx.rollback(); error = e; } - const errorName = error.details.codes.name[0]; - - expect(errorName).toEqual('uniqueness'); + expect(error.message).toContain('already exists'); }); }); diff --git a/modules/ticket/back/methods/ticket/closeAll.js b/modules/ticket/back/methods/ticket/closeAll.js index 4fd72d454..b9060d2f2 100644 --- a/modules/ticket/back/methods/ticket/closeAll.js +++ b/modules/ticket/back/methods/ticket/closeAll.js @@ -41,7 +41,7 @@ module.exports = Self => { c.salesPersonFk, c.isToBeMailed, c.hasToInvoice, - co.hasDailyInvoice, + c.hasDailyInvoice, eu.email salesPersonEmail, t.addressFk FROM ticket t @@ -120,7 +120,7 @@ module.exports = Self => { WHERE (al.code = 'PACKED' OR (am.code = 'refund' AND al.code <> 'delivered')) AND t.shipped BETWEEN ? - INTERVAL tc.closureDaysAgo DAY AND util.dayEnd(?) AND t.refFk IS NULL - AND IFNULL(a.hasDailyInvoice, co.hasDailyInvoice) + AND c.hasDailyInvoice GROUP BY ticketFk HAVING hasErrorToInvoice OR hasErrorTaxDataChecked diff --git a/modules/ticket/back/methods/ticket/closeByTicket.js b/modules/ticket/back/methods/ticket/closeByTicket.js index 40fe048a5..8a21267b6 100644 --- a/modules/ticket/back/methods/ticket/closeByTicket.js +++ b/modules/ticket/back/methods/ticket/closeByTicket.js @@ -50,7 +50,7 @@ module.exports = Self => { c.salesPersonFk, c.isToBeMailed, c.hasToInvoice, - co.hasDailyInvoice, + c.hasDailyInvoice, eu.email salesPersonEmail, t.addressFk FROM expedition e @@ -58,8 +58,6 @@ module.exports = Self => { JOIN ticketState ts ON ts.ticketFk = t.id JOIN alertLevel al ON al.id = ts.alertLevel JOIN client c ON c.id = t.clientFk - JOIN province p ON p.id = c.provinceFk - JOIN country co ON co.id = p.countryFk LEFT JOIN account.emailUser eu ON eu.userFk = c.salesPersonFk WHERE al.code = 'PACKED' AND t.id = ? From aac4dd0a6d1719ccc9937faa67871b5dd205bc78 Mon Sep 17 00:00:00 2001 From: jgallego Date: Wed, 16 Oct 2024 08:52:27 +0200 Subject: [PATCH 081/136] feat: refs #7348 minor bug --- modules/client/back/methods/client/specs/createWithUser.spec.js | 1 - 1 file changed, 1 deletion(-) diff --git a/modules/client/back/methods/client/specs/createWithUser.spec.js b/modules/client/back/methods/client/specs/createWithUser.spec.js index f47c24087..8cff96ac5 100644 --- a/modules/client/back/methods/client/specs/createWithUser.spec.js +++ b/modules/client/back/methods/client/specs/createWithUser.spec.js @@ -41,7 +41,6 @@ describe('Client Create', () => { try { await models.Client.createWithUser(newAccountWithoutEmail, options); - fail('shapoifaspodifa spdofij'); } catch (e) { error = e; } From c355fcfece4c201ae7ab183d4c1237530f26f755 Mon Sep 17 00:00:00 2001 From: alexm Date: Wed, 16 Oct 2024 09:03:47 +0200 Subject: [PATCH 082/136] test(docuware_core): refs #8066 adapt --- back/methods/docuware/core.js | 4 +- back/methods/docuware/specs/core.spec.js | 164 ++++++++++++----------- 2 files changed, 86 insertions(+), 82 deletions(-) diff --git a/back/methods/docuware/core.js b/back/methods/docuware/core.js index 391a8b4ab..3de33b786 100644 --- a/back/methods/docuware/core.js +++ b/back/methods/docuware/core.js @@ -8,10 +8,10 @@ module.exports = Self => { */ Self.getOptions = async() => { const docuwareConfig = await Self.app.models.DocuwareConfig.findOne(); - const now = new Date().getTime(); + const now = Date.vnNow(); let {url, username, password, token, expired} = docuwareConfig; - if (!expired || expired < now + 60) { + if (process.env.NODE_ENV && (!expired || expired < now + 60)) { const {data: {IdentityServiceUrl}} = await axios.get(`${url}/Home/IdentityServiceInfo`); const {data: {token_endpoint}} = await axios.get(`${IdentityServiceUrl}/.well-known/openid-configuration`); const {data} = await axios.post(token_endpoint, { diff --git a/back/methods/docuware/specs/core.spec.js b/back/methods/docuware/specs/core.spec.js index cdf8a3b62..47580483d 100644 --- a/back/methods/docuware/specs/core.spec.js +++ b/back/methods/docuware/specs/core.spec.js @@ -2,87 +2,54 @@ const axios = require('axios'); const models = require('vn-loopback/server/server').models; describe('Docuware core', () => { - beforeAll(() => { + const fileCabinetCode = 'deliveryNote'; + beforeAll(async() => { process.env.NODE_ENV = 'testing'; - }); - afterAll(() => { - delete process.env.NODE_ENV; - }); - - describe('getOptions()', () => { - it('should return url and headers', async() => { - const result = await models.Docuware.getOptions(); - - expect(result.url).toBeDefined(); - expect(result.headers).toBeDefined(); + const docuwareInfo = await models.Docuware.findOne({ + where: { + code: fileCabinetCode + } }); - }); - describe('getDialog()', () => { - it('should return dialogId', async() => { - const dialogs = { - data: { - Dialog: [ - { - DisplayName: 'find', - Id: 'getDialogTest' - } - ] - } - }; - spyOn(axios, 'get').and.returnValue(new Promise(resolve => resolve(dialogs))); - const result = await models.Docuware.getDialog('deliveryNote', 'find', 'randomFileCabinetId'); + spyOn(axios, 'get').and.callFake(url => { + if (url.includes('IdentityServiceInfo')) return {data: {IdentityServiceUrl: 'IdentityServiceUrl'}}; + if (url.includes('IdentityServiceUrl')) return {data: {token_endpoint: 'token_endpoint'}}; + if (url.includes('dialogs')) { + return { + data: { + Dialog: [ + { + DisplayName: 'find', + Id: 'getDialogTest' + } + ] + } + }; + } - expect(result).toEqual('getDialogTest'); - }); - }); - - describe('getFileCabinet()', () => { - it('should return fileCabinetId', async() => { - const code = 'deliveryNote'; - const docuwareInfo = await models.Docuware.findOne({ - where: { - code - } - }); - const dialogs = { - data: { + if (url.includes('FileCabinets')) { + return {data: { FileCabinet: [ { Name: docuwareInfo.fileCabinetName, Id: 'getFileCabinetTest' } ] - } - }; - spyOn(axios, 'get').and.returnValue(new Promise(resolve => resolve(dialogs))); - const result = await models.Docuware.getFileCabinet(code); - - expect(result).toEqual('getFileCabinetTest'); - }); - }); - - describe('get()', () => { - it('should return data without parse', async() => { - spyOn(models.Docuware, 'getFileCabinet').and.returnValue((new Promise(resolve => resolve(Math.random())))); - spyOn(models.Docuware, 'getDialog').and.returnValue((new Promise(resolve => resolve(Math.random())))); - const data = { - data: { - id: 1 - } - }; - spyOn(axios, 'post').and.returnValue(new Promise(resolve => resolve(data))); - const result = await models.Docuware.get('deliveryNote'); - - expect(result.id).toEqual(1); + }}; + } }); - it('should return data with parse', async() => { - spyOn(models.Docuware, 'getFileCabinet').and.returnValue((new Promise(resolve => resolve(Math.random())))); - spyOn(models.Docuware, 'getDialog').and.returnValue((new Promise(resolve => resolve(Math.random())))); - const data = { - data: { + spyOn(axios, 'post').and.callFake(url => { + if (url.includes('token_endpoint')) { + return {data: { + access_token: 'access_token', + token_type: 'bearer', + expires_in: 10000 + }}; + } + if (url.includes('DialogExpression')) { + return {data: { Items: [{ Fields: [ { @@ -103,12 +70,52 @@ describe('Docuware core', () => { ] }] } - }; + }; + } + }); + }); + + afterAll(() => { + delete process.env.NODE_ENV; + }); + + describe('getOptions()', () => { + it('should return url and headers', async() => { + const result = await models.Docuware.getOptions(); + + expect(result.url).toBeDefined(); + expect(result.headers).toBeDefined(); + }); + }); + + describe('Dialog()', () => { + it('should return dialogId', async() => { + const result = await models.Docuware.getDialog('deliveryNote', 'find', 'randomFileCabinetId'); + + expect(result).toEqual('getDialogTest'); + }); + }); + + describe('getFileCabinet()', () => { + it('should return fileCabinetId', async() => { + const result = await models.Docuware.getFileCabinet(fileCabinetCode); + + expect(result).toEqual('getFileCabinetTest'); + }); + }); + + describe('get()', () => { + it('should return data without parse', async() => { + const [result] = await models.Docuware.get('deliveryNote'); + + expect(result.firstRequiredField).toEqual(1); + }); + + it('should return data with parse', async() => { const parse = { 'firstRequiredField': 'id', 'secondRequiredField': 'name', }; - spyOn(axios, 'post').and.returnValue(new Promise(resolve => resolve(data))); const [result] = await models.Docuware.get('deliveryNote', null, parse); expect(result.id).toEqual(1); @@ -119,17 +126,14 @@ describe('Docuware core', () => { describe('getById()', () => { it('should return data', async() => { - spyOn(models.Docuware, 'getFileCabinet').and.returnValue((new Promise(resolve => resolve(Math.random())))); - spyOn(models.Docuware, 'getDialog').and.returnValue((new Promise(resolve => resolve(Math.random())))); - const data = { - data: { - id: 1 - } - }; - spyOn(axios, 'post').and.returnValue(new Promise(resolve => resolve(data))); - const result = await models.Docuware.getById('deliveryNote', 1); + spyOn(models.Docuware, 'get'); + await models.Docuware.getById('deliveryNote', 1); - expect(result.id).toEqual(1); + expect(models.Docuware.get).toHaveBeenCalledWith( + 'deliveryNote', + {condition: [Object({DBName: 'N__ALBAR_N', Value: [1]})]}, + undefined + ); }); }); }); From 8ca097d4a9fc979fe14e4a25e4b3e0df503d1daf Mon Sep 17 00:00:00 2001 From: jorgep Date: Wed, 16 Oct 2024 09:23:39 +0200 Subject: [PATCH 083/136] chore: refs #7919 change var name --- modules/ticket/back/methods/ticket/setDeleted.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/ticket/back/methods/ticket/setDeleted.js b/modules/ticket/back/methods/ticket/setDeleted.js index e868e9258..fcab95ee2 100644 --- a/modules/ticket/back/methods/ticket/setDeleted.js +++ b/modules/ticket/back/methods/ticket/setDeleted.js @@ -49,12 +49,12 @@ module.exports = Self => { where: {originalTicketFk: id} }, myOptions); - const isRefund = !!ticketRefunds?.length; + const hasRefund = !!ticketRefunds?.length; const allDeleted = ticketRefunds.every(refund => refund.refundTicket().isDeleted); - if (!isRefund) await models.TicketRefund.destroyAll({refundTicketFk: id}, myOptions); - if (isRefund && !allDeleted) { + if (!hasRefund) await models.TicketRefund.destroyAll({refundTicketFk: id}, myOptions); + if (hasRefund && !allDeleted) { const notDeleted = []; for (const refund of ticketRefunds) if (!refund.refundTicket().isDeleted) notDeleted.push(refund.refundTicket().id); From c5aa7dc44e4bac9148b226420e9a687054c037fa Mon Sep 17 00:00:00 2001 From: carlossa Date: Wed, 16 Oct 2024 09:30:37 +0200 Subject: [PATCH 084/136] fix: refs #7906 edit test --- .../zone/back/methods/zone/specs/deleteZone.spec.js | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/modules/zone/back/methods/zone/specs/deleteZone.spec.js b/modules/zone/back/methods/zone/specs/deleteZone.spec.js index 08dafd181..60e704161 100644 --- a/modules/zone/back/methods/zone/specs/deleteZone.spec.js +++ b/modules/zone/back/methods/zone/specs/deleteZone.spec.js @@ -8,7 +8,7 @@ describe('zone deletezone()', () => { __: value => value }; const ctx = {req: activeCtx}; - const zoneId = 9; + const zoneId = 4; let ticketIDs; let originalTicketStates; @@ -35,18 +35,8 @@ describe('zone deletezone()', () => { await models.Zone.deleteZone(ctx, zoneId, options); const updatedZone = await models.Zone.findById(zoneId, null, options); - const anUpdatedTicket = await models.Ticket.findById(ticketIDs[0], null, options); - - const updatedTicketStates = await models.TicketState.find({ - where: { - ticketFk: {inq: ticketIDs}, - code: 'FIXING' - } - }, options); expect(updatedZone).toBeNull(); - expect(anUpdatedTicket.zoneFk).toBeNull(); - expect(updatedTicketStates.length).toBeGreaterThan(originalTicketStates.length); await tx.rollback(); } catch (e) { From 8f01e4d110ad040c33674bb5b51664d0e3dd93be Mon Sep 17 00:00:00 2001 From: jorgep Date: Wed, 16 Oct 2024 09:32:15 +0200 Subject: [PATCH 085/136] fix: refs #7353 redirect to lilium --- modules/monitor/front/locale/es.yml | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 modules/monitor/front/locale/es.yml diff --git a/modules/monitor/front/locale/es.yml b/modules/monitor/front/locale/es.yml new file mode 100644 index 000000000..01b26b70c --- /dev/null +++ b/modules/monitor/front/locale/es.yml @@ -0,0 +1,16 @@ +Tickets monitor: Monitor de tickets +Clients on website: Clientes activos en la web +Recent order actions: Acciones recientes en pedidos +Search tickets: Buscar tickets +Delete selected elements: Eliminar los elementos seleccionados +All the selected elements will be deleted. Are you sure you want to continue?: Todos los elementos seleccionados serán eliminados. ¿Seguro que quieres continuar? +Component lack: Faltan componentes +Ticket too little: Ticket demasiado pequeño +Minimize/Maximize: Minimizar/Maximizar +Problems: Problemas +Theoretical: Teórica +Practical: Práctica +Preparation: Preparación +Auto-refresh: Auto-refresco +Toggle auto-refresh every 2 minutes: Conmuta el refresco automático cada 2 minutos +Is fragile: Es frágil \ No newline at end of file From a28217001642d8a44c25ebce4c64f7cc85a2e10d Mon Sep 17 00:00:00 2001 From: carlossa Date: Wed, 16 Oct 2024 11:36:48 +0200 Subject: [PATCH 086/136] fix: refs #7906 fix method --- modules/zone/back/methods/zone/deleteZone.js | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/modules/zone/back/methods/zone/deleteZone.js b/modules/zone/back/methods/zone/deleteZone.js index 34ab177ac..5b0fe11f4 100644 --- a/modules/zone/back/methods/zone/deleteZone.js +++ b/modules/zone/back/methods/zone/deleteZone.js @@ -53,23 +53,10 @@ module.exports = Self => { const promises = []; const ticketList = await models.Ticket.find(filter, myOptions); - const fixingState = await models.State.findOne({where: {code: 'FIXING'}}, myOptions); - const worker = await models.Worker.findOne({ - where: {id: userId} - }, myOptions); if (ticketList.length > 0) throw new UserError('There are tickets for this area, delete them first'); - for (ticket of ticketList) { - if (ticket.ticketState().alertLevel == 0) { - promises.push(models.Ticket.state(ctx, { - ticketFk: ticket.id, - stateFk: fixingState.id, - userFk: worker.id - }, myOptions)); - } - } await Promise.all(promises); await models.Zone.destroyById(id, myOptions); From 3e443ad5ced8090ee005bfa79add11e60c30a654 Mon Sep 17 00:00:00 2001 From: carlossa Date: Wed, 16 Oct 2024 12:22:57 +0200 Subject: [PATCH 087/136] fix: refs #7230 producer fix --- print/templates/reports/delivery-note/delivery-note.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/print/templates/reports/delivery-note/delivery-note.html b/print/templates/reports/delivery-note/delivery-note.html index c1701e084..ccf2fbfb4 100644 --- a/print/templates/reports/delivery-note/delivery-note.html +++ b/print/templates/reports/delivery-note/delivery-note.html @@ -58,6 +58,7 @@ {{$t('reference')}} {{$t('quantity')}} {{$t('concept')}} + {{$t('producer')}} {{$t('price')}} {{$t('discount')}} {{$t('vat')}} @@ -69,7 +70,7 @@ {{sale.itemFk}} {{sale.quantity}} {{sale.concept}} - {{sale.price | currency('EUR', $i18n.locale)}} + {{sale.subName}} {{(sale.discount / 100) | percentage}} {{sale.vatType}} @@ -81,7 +82,6 @@ {{sale.tag5}} {{sale.value5}} {{sale.tag6}} {{sale.value6}} {{sale.tag7}} {{sale.value7}} - {{$t('producer')}} {{ sale.subName }} From 5de4a11e8b2a236bb4055253fa1c19dd9ae04e80 Mon Sep 17 00:00:00 2001 From: carlossa Date: Wed, 16 Oct 2024 13:53:20 +0200 Subject: [PATCH 088/136] fix: refs #7230 fix line --- print/templates/reports/delivery-note/delivery-note.html | 1 + 1 file changed, 1 insertion(+) diff --git a/print/templates/reports/delivery-note/delivery-note.html b/print/templates/reports/delivery-note/delivery-note.html index ccf2fbfb4..89bc07488 100644 --- a/print/templates/reports/delivery-note/delivery-note.html +++ b/print/templates/reports/delivery-note/delivery-note.html @@ -71,6 +71,7 @@ {{sale.quantity}} {{sale.concept}} {{sale.subName}} + {{sale.price | currency('EUR', $i18n.locale)}} {{(sale.discount / 100) | percentage}} {{sale.vatType}} From 3f3b93625583f6366a9cd6b4f9d6008b81016645 Mon Sep 17 00:00:00 2001 From: carlossa Date: Wed, 16 Oct 2024 13:56:42 +0200 Subject: [PATCH 089/136] fix: refs #7906 remove code --- modules/zone/back/methods/zone/deleteZone.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/modules/zone/back/methods/zone/deleteZone.js b/modules/zone/back/methods/zone/deleteZone.js index 5b0fe11f4..ffe23c9b9 100644 --- a/modules/zone/back/methods/zone/deleteZone.js +++ b/modules/zone/back/methods/zone/deleteZone.js @@ -50,14 +50,12 @@ module.exports = Self => { } } }; - const promises = []; const ticketList = await models.Ticket.find(filter, myOptions); if (ticketList.length > 0) throw new UserError('There are tickets for this area, delete them first'); - await Promise.all(promises); await models.Zone.destroyById(id, myOptions); if (tx) await tx.commit(); From 681f82a3ae934f7834d1122ef2821241242f1771 Mon Sep 17 00:00:00 2001 From: jgallego Date: Wed, 16 Oct 2024 16:09:53 +0200 Subject: [PATCH 090/136] feat: refs #7744 test back ok --- .../back/methods/invoiceOut/delete.js | 8 ++--- modules/ticket/back/methods/ticket/closure.js | 3 +- .../methods/ticket/specs/closeAll.spec.js | 32 ++----------------- 3 files changed, 8 insertions(+), 35 deletions(-) diff --git a/modules/invoiceOut/back/methods/invoiceOut/delete.js b/modules/invoiceOut/back/methods/invoiceOut/delete.js index d6efd9961..1ab9a582b 100644 --- a/modules/invoiceOut/back/methods/invoiceOut/delete.js +++ b/modules/invoiceOut/back/methods/invoiceOut/delete.js @@ -37,7 +37,7 @@ module.exports = Self => { const tickets = await models.Ticket.find({ where: {refFk: invoiceOut.ref} }, myOptions); - + const [bookEntry] = await models.Xdiario.find({ where: { SERIE: invoiceOut.ref[0], @@ -55,13 +55,13 @@ module.exports = Self => { if (bookEntry) { if (bookEntry.enlazadoSage) { const params = { - bookEntry: bookEntry.ASIEN, + bookEntry: bookEntry.ASIEN, invoiceOutRef: invoiceOut.ref - } + }; await Self.rawSql(`SELECT util.notification_send('book-entry-deleted', ?, NULL)`, [JSON.stringify(params)], myOptions); - }; + } await models.Xdiario.destroyAll({ ASIEN: bookEntry.ASIEN diff --git a/modules/ticket/back/methods/ticket/closure.js b/modules/ticket/back/methods/ticket/closure.js index 64f198834..e4cb49007 100644 --- a/modules/ticket/back/methods/ticket/closure.js +++ b/modules/ticket/back/methods/ticket/closure.js @@ -19,8 +19,7 @@ module.exports = async function(ctx, Self, tickets, options) { const failedtickets = []; for (const ticket of tickets) { try { - await Self.rawSql(`CALL util.debugAdd('invoicingTicket', ?)`, [ticket.id], {userId}, - myOptions); + await Self.rawSql(`CALL util.debugAdd('invoicingTicket', ?)`, [ticket.id], myOptions); await Self.app.models.InvoiceOut.getSerial( ticket.clientFk, diff --git a/modules/ticket/back/methods/ticket/specs/closeAll.spec.js b/modules/ticket/back/methods/ticket/specs/closeAll.spec.js index 4b067ce7e..f01541eec 100644 --- a/modules/ticket/back/methods/ticket/specs/closeAll.spec.js +++ b/modules/ticket/back/methods/ticket/specs/closeAll.spec.js @@ -1,7 +1,7 @@ const models = require('vn-loopback/server/server').models; const LoopBackContext = require('loopback-context'); -fdescribe('Ticket Closure - closeAll function', () => { +describe('Ticket Closure - closeAll function', () => { let ctx = { req: { getLocale: () => 'es', @@ -17,6 +17,7 @@ fdescribe('Ticket Closure - closeAll function', () => { beforeEach(async() => { spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({active: ctx.req}); + tx = await models.Ticket.beginTransaction({}); options = {transaction: tx}; originalVnNew = Date.vnNew; @@ -32,34 +33,7 @@ fdescribe('Ticket Closure - closeAll function', () => { await tx.rollback(); }); - xit('should successfully close all tickets when conditions are met', async() => { - const ticketsBefore = await models.Ticket.find({ - where: { - packages: {neq: 0} - } - }, options); - const packedTicketsIds = ticketsBefore.map(ticket => ticket.id); - - const packedTicketsBefore = await models.TicketLastState.find({ - where: { - ticketFk: {inq: packedTicketsIds}, - lastState: 'Encajado' - } - }, options); - - await models.Ticket.closeAll(ctx, options); - - const packedTicketsAfter = await models.TicketLastState.find({ - where: { - ticketFk: {inq: packedTicketsIds}, - lastState: 'Encajado' - } - }, options); - - expect(packedTicketsBefore.length).toBeGreaterThan(packedTicketsAfter.length); - }); - - fit('should set routeFk to NULL when conditions are met', async() => { + it('should set routeFk to NULL when conditions are met', async() => { const ticketsBefore = await models.Ticket.find({ where: { routeFk: {neq: null} From de0fe37ffe978118101fdd2c34615b103ec84da7 Mon Sep 17 00:00:00 2001 From: jorgep Date: Wed, 16 Oct 2024 16:16:51 +0200 Subject: [PATCH 091/136] feat: refs #8083 add prop --- modules/ticket/back/models/expedition.json | 117 +++++++++++---------- 1 file changed, 60 insertions(+), 57 deletions(-) diff --git a/modules/ticket/back/models/expedition.json b/modules/ticket/back/models/expedition.json index 2dcca1e87..f3f912ec3 100644 --- a/modules/ticket/back/models/expedition.json +++ b/modules/ticket/back/models/expedition.json @@ -1,63 +1,66 @@ { - "name": "Expedition", - "base": "VnModel", - "mixins": { - "Loggable": true + "name": "Expedition", + "base": "VnModel", + "mixins": { + "Loggable": true + }, + "options": { + "mysql": { + "table": "expedition" + } + }, + "properties": { + "id": { + "id": true, + "type": "number", + "description": "Identifier" }, - "options": { - "mysql": { - "table": "expedition" - } + "freightItemFk": { + "type": "number" }, - "properties": { - "id": { - "id": true, - "type": "number", - "description": "Identifier" - }, - "freightItemFk": { - "type": "number" - }, - "created": { - "type": "date" - }, - "counter": { - "type": "number" - }, - "externalId": { - "type": "string" - } + "created": { + "type": "date" }, - "relations": { - "ticket": { - "type": "belongsTo", - "model": "Ticket", - "foreignKey": "ticketFk" - }, - "agencyMode": { - "type": "belongsTo", - "model": "AgencyMode", - "foreignKey": "agencyModeFk" - }, - "worker": { - "type": "belongsTo", - "model": "Worker", - "foreignKey": "workerFk" - }, - "packages": { - "type": "hasMany", - "model": "TicketPackaging", - "foreignKey": "ticketFk" - }, - "freightItem": { - "type": "belongsTo", - "model": "Item", - "foreignKey": "freightItemFk" - }, - "packaging": { - "type": "belongsTo", - "model": "Package", - "foreignKey": "packagingFk" - } + "counter": { + "type": "number" + }, + "externalId": { + "type": "string" + }, + "stateTypeFk": { + "type": "number" + } + }, + "relations": { + "ticket": { + "type": "belongsTo", + "model": "Ticket", + "foreignKey": "ticketFk" + }, + "agencyMode": { + "type": "belongsTo", + "model": "AgencyMode", + "foreignKey": "agencyModeFk" + }, + "worker": { + "type": "belongsTo", + "model": "Worker", + "foreignKey": "workerFk" + }, + "packages": { + "type": "hasMany", + "model": "TicketPackaging", + "foreignKey": "ticketFk" + }, + "freightItem": { + "type": "belongsTo", + "model": "Item", + "foreignKey": "freightItemFk" + }, + "packaging": { + "type": "belongsTo", + "model": "Package", + "foreignKey": "packagingFk" } } +} \ No newline at end of file From 999cb2dbb44361f20471532e39e52b94a4dee038 Mon Sep 17 00:00:00 2001 From: guillermo Date: Thu, 17 Oct 2024 10:08:27 +0200 Subject: [PATCH 092/136] 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 093/136] 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 094/136] 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 095/136] 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 096/136] 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 097/136] 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 098/136] 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 a188efb1e33d24e5a70f6301f6b739b3d93de12b Mon Sep 17 00:00:00 2001 From: guillermo Date: Thu, 17 Oct 2024 11:45:13 +0200 Subject: [PATCH 099/136] refactor: refs #7930 Deleted HEALTHCHECK of back dockerfile --- back/Dockerfile | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/back/Dockerfile b/back/Dockerfile index 363192a0b..3e2a90c58 100644 --- a/back/Dockerfile +++ b/back/Dockerfile @@ -55,7 +55,4 @@ COPY \ README.md \ ./ -CMD ["pm2-runtime", "./back/process.yml"] - -HEALTHCHECK --interval=15s --timeout=10s \ - CMD curl -f http://localhost:3000/api/Applications/status || exit 1 +CMD ["pm2-runtime", "./back/process.yml"] \ No newline at end of file From faecbbb3735034876e7544891fc63702e089b0ad Mon Sep 17 00:00:00 2001 From: robert Date: Thu, 17 Oct 2024 13:08:58 +0200 Subject: [PATCH 100/136] feat: refs #8108 saltos de linea --- db/versions/11300-limeMedeola/00-firstScript.sql | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/db/versions/11300-limeMedeola/00-firstScript.sql b/db/versions/11300-limeMedeola/00-firstScript.sql index 313a65e81..28b033b4a 100644 --- a/db/versions/11300-limeMedeola/00-firstScript.sql +++ b/db/versions/11300-limeMedeola/00-firstScript.sql @@ -13,8 +13,6 @@ UPDATE vn.tag sourceTable='itemFarmingTag' WHERE name= 'cultivo'; - - CREATE TABLE IF NOT EXISTS `vn`.`itemWrappingTag` ( `id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT, `name` varchar(50) DEFAULT NULL, @@ -36,8 +34,6 @@ UPDATE vn.tag sourceTable='itemWrappingTag' WHERE name= 'Envoltorio'; - - CREATE TABLE IF NOT EXISTS `vn`.`itemLanguageTag` ( `id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT, `name` varchar(50) DEFAULT NULL, @@ -59,8 +55,6 @@ UPDATE vn.tag sourceTable='itemLanguageTag' WHERE name= 'Idioma'; - - CREATE TABLE IF NOT EXISTS `vn`.`itemStemTag` ( `id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT, `name` varchar(50) DEFAULT NULL, @@ -94,8 +88,6 @@ UPDATE vn.tag sourceTable='itemBreederTag' WHERE name= 'Obtentor'; - - CREATE TABLE IF NOT EXISTS `vn`.`itemBaseTag` ( `id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT, `name` varchar(50) DEFAULT NULL, @@ -120,8 +112,6 @@ UPDATE vn.tag sourceTable='itemBaseTag' WHERE name= 'Soporte'; - - CREATE TABLE IF NOT EXISTS `vn`.`itemVatRateTag` ( `id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT, `name` varchar(50) DEFAULT NULL, @@ -133,13 +123,11 @@ CREATE TABLE IF NOT EXISTS `vn`.`itemVatRateTag` ( INSERT IGNORE INTO `vn`.`itemVatRateTag` (`name`) VALUES ('General'); INSERT IGNORE INTO `vn`.`itemVatRateTag` (`name`) VALUES ('Reducido'); - UPDATE vn.tag SET isFree=0, sourceTable='itemVatRateTag' WHERE name= 'Tipo de IVA'; - GRANT SELECT, UPDATE, INSERT, DELETE ON TABLE vn.itemFarmingTag TO logisticAssist; GRANT SELECT, UPDATE, INSERT, DELETE ON TABLE vn.itemWrappingTag TO logisticAssist; GRANT SELECT, UPDATE, INSERT, DELETE ON TABLE vn.itemLanguageTag TO logisticAssist; From cb539624056c6d88d182b27745daec7334c40eb9 Mon Sep 17 00:00:00 2001 From: sergiodt Date: Thu, 17 Oct 2024 13:58:21 +0200 Subject: [PATCH 101/136] fix: refs #6861 saleTrackingAdd --- ...saleTracking_sectorCollectionAddPrevOK.sql | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 db/routines/vn/procedures/saleTracking_sectorCollectionAddPrevOK.sql diff --git a/db/routines/vn/procedures/saleTracking_sectorCollectionAddPrevOK.sql b/db/routines/vn/procedures/saleTracking_sectorCollectionAddPrevOK.sql new file mode 100644 index 000000000..3ac31752a --- /dev/null +++ b/db/routines/vn/procedures/saleTracking_sectorCollectionAddPrevOK.sql @@ -0,0 +1,26 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`saleTracking_sectorCollectionAddPrevOK`(vSectorCollectionFk INT) +BEGIN +/** + * Inserta los registros de sectorCollection con el estado PREVIA OK si la reserva está picked + * + * @param vSectorCollectionFk Identificador de vn.sectorCollection + */ + REPLACE saleTracking( + saleFk, + isChecked, + workerFk, + stateFk + ) + SELECT sgd.saleFk, + TRUE, + sc.userFk, + s.id + FROM vn.sectorCollection sc + JOIN sectorCollectionSaleGroup scsg ON scsg.sectorCollectionFk = sc.id + JOIN saleGroupDetail sgd ON sgd.saleGroupFk = scsg.saleGroupFk + JOIN state s ON s.code = 'OK PREVIOUS' + JOIN itemShelvingSale iss ON iss.saleFk = sgd.saleFk + WHERE sc.id = vSectorCollectionFk AND iss.isPicked; +END$$ +DELIMITER ; From 28e957fecd9ba5e5c71088d00cdcdf7d47032232 Mon Sep 17 00:00:00 2001 From: guillermo Date: Thu, 17 Oct 2024 14:46:19 +0200 Subject: [PATCH 102/136] refactor: refs #8106 refs #1406 Optimized ticket_getTax --- db/routines/vn/procedures/ticket_getTax.sql | 56 ++++++++++++------- .../back/methods/invoiceOut/negativeBases.js | 18 +++--- 2 files changed, 45 insertions(+), 29 deletions(-) diff --git a/db/routines/vn/procedures/ticket_getTax.sql b/db/routines/vn/procedures/ticket_getTax.sql index 947c45806..fc266f978 100644 --- a/db/routines/vn/procedures/ticket_getTax.sql +++ b/db/routines/vn/procedures/ticket_getTax.sql @@ -1,5 +1,7 @@ DELIMITER $$ -CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`ticket_getTax`(IN vTaxArea VARCHAR(25)) +CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`ticket_getTax`( + vTaxArea VARCHAR(25) +) BEGIN /** * Calcula la base imponible, el IVA y el recargo de equivalencia para @@ -33,30 +35,44 @@ BEGIN CREATE OR REPLACE TEMPORARY TABLE tmp.ticketTax (PRIMARY KEY (ticketFk, code, rate)) ENGINE = MEMORY - SELECT * FROM ( - SELECT tmpTicket.ticketFk, + WITH sales AS ( + SELECT s.id, + s.ticketFk, + s.itemFk, + s.quantity * s.price * (100 - s.discount) / 100 total, + t.companyFk, + t.addressFk, + su.countryFk, + ata.areaFk, + itc.taxClassFk + FROM vn.sale s + JOIN tmp.ticket tmp ON tmp.ticketFk = s.ticketFk + JOIN vn.ticket t ON t.id = s.ticketFk + JOIN vn.supplier su ON su.id = t.companyFk + JOIN tmp.addressTaxArea ata ON ata.addressFk = t.addressFk + AND ata.companyFk = t.companyFk + JOIN vn.itemTaxCountry itc ON itc.itemFk = s.itemFk + AND itc.countryFk = su.countryFk + HAVING total + ), + ticketTax AS ( + SELECT s.ticketFk, bp.pgcFk, - SUM(s.quantity * s.price * (100 - s.discount) / 100 ) taxableBase, + SUM(s.total) taxableBase, pgc.rate, tc.code, bp.priority - FROM tmp.ticket tmpTicket - JOIN sale s ON s.ticketFk = tmpTicket.ticketFk - JOIN item i ON i.id = s.itemFk - JOIN ticket t ON t.id = tmpTicket.ticketFk - JOIN supplier su ON su.id = t.companyFk - JOIN tmp.addressTaxArea ata ON ata.addressFk = t.addressFk - AND ata.companyFk = t.companyFk - JOIN itemTaxCountry itc ON itc.itemFk = i.id - AND itc.countryFk = su.countryFk - JOIN bookingPlanner bp ON bp.countryFk = su.countryFk - AND bp.taxAreaFk = ata.areaFk - AND bp.taxClassFk = itc.taxClassFk - JOIN pgc ON pgc.code = bp.pgcFk - JOIN taxClass tc ON tc.id = bp.taxClassFk - GROUP BY tmpTicket.ticketFk, pgc.code, pgc.rate + FROM sales s + JOIN vn.bookingPlanner bp ON bp.countryFk = s.countryFk + AND bp.taxAreaFk = s.areaFk + AND bp.taxClassFk = s.taxClassFk + JOIN vn.pgc ON pgc.code = bp.pgcFk + JOIN vn.taxClass tc ON tc.id = bp.taxClassFk + GROUP BY s.ticketFk, pgc.code, pgc.rate HAVING taxableBase - ) t3 + ) + SELECT * + FROM ticketTax ORDER BY priority; CREATE OR REPLACE TEMPORARY TABLE tmp.ticketServiceTax diff --git a/modules/invoiceOut/back/methods/invoiceOut/negativeBases.js b/modules/invoiceOut/back/methods/invoiceOut/negativeBases.js index 76ef29604..9e491b35c 100644 --- a/modules/invoiceOut/back/methods/invoiceOut/negativeBases.js +++ b/modules/invoiceOut/back/methods/invoiceOut/negativeBases.js @@ -48,13 +48,13 @@ module.exports = Self => { let stmt; stmts.push(new ParameterizedSQL( `CREATE OR REPLACE TEMPORARY TABLE tmp.ticket - (KEY (ticketFk)) + (INDEX (ticketFk)) ENGINE = MEMORY SELECT id ticketFk - FROM ticket t + FROM ticket WHERE shipped BETWEEN ? AND util.dayEnd(?) AND refFk IS NULL`, [args.from, args.to])); - stmts.push(`CALL vn.ticket_getTax(NULL)`); + stmts.push(`CALL ticket_getTax(NULL)`); stmts.push(new ParameterizedSQL( `CREATE OR REPLACE TEMPORARY TABLE tmp.filter ENGINE = MEMORY @@ -71,12 +71,12 @@ module.exports = Self => { c.isTaxDataChecked, w.id comercialId, u.name workerName - FROM vn.ticket t - JOIN vn.company co ON co.id = t.companyFk - JOIN vn.sale s ON s.ticketFk = t.id - JOIN vn.client c ON c.id = t.clientFk - JOIN vn.country cou ON cou.id = c.countryFk - LEFT JOIN vn.worker w ON w.id = c.salesPersonFk + FROM ticket t + JOIN company co ON co.id = t.companyFk + JOIN sale s ON s.ticketFk = t.id + JOIN client c ON c.id = t.clientFk + JOIN country cou ON cou.id = c.countryFk + LEFT JOIN worker w ON w.id = c.salesPersonFk JOIN account.user u ON u.id = w.id LEFT JOIN ( SELECT ticketFk, taxableBase From 63c0ec308f3231fbc276c7e3ee365cdc2464d5c7 Mon Sep 17 00:00:00 2001 From: sergiodt Date: Thu, 17 Oct 2024 17:01:44 +0200 Subject: [PATCH 103/136] fix: refs #6861 saleTrackingAdd --- ...saleTracking_sectorCollectionAddPrevOK.sql | 24 ++++++++++--------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/db/routines/vn/procedures/saleTracking_sectorCollectionAddPrevOK.sql b/db/routines/vn/procedures/saleTracking_sectorCollectionAddPrevOK.sql index 3ac31752a..a5d34c2d6 100644 --- a/db/routines/vn/procedures/saleTracking_sectorCollectionAddPrevOK.sql +++ b/db/routines/vn/procedures/saleTracking_sectorCollectionAddPrevOK.sql @@ -1,5 +1,7 @@ DELIMITER $$ -CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`saleTracking_sectorCollectionAddPrevOK`(vSectorCollectionFk INT) +CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`saleTracking_sectorCollectionAddPrevOK`( + vSectorCollectionFk INT + ) BEGIN /** * Inserta los registros de sectorCollection con el estado PREVIA OK si la reserva está picked @@ -12,15 +14,15 @@ BEGIN workerFk, stateFk ) - SELECT sgd.saleFk, - TRUE, - sc.userFk, - s.id - FROM vn.sectorCollection sc - JOIN sectorCollectionSaleGroup scsg ON scsg.sectorCollectionFk = sc.id - JOIN saleGroupDetail sgd ON sgd.saleGroupFk = scsg.saleGroupFk - JOIN state s ON s.code = 'OK PREVIOUS' - JOIN itemShelvingSale iss ON iss.saleFk = sgd.saleFk - WHERE sc.id = vSectorCollectionFk AND iss.isPicked; + SELECT sgd.saleFk, + TRUE, + sc.userFk, + s.id + FROM sectorCollection sc + JOIN sectorCollectionSaleGroup scsg ON scsg.sectorCollectionFk = sc.id + JOIN saleGroupDetail sgd ON sgd.saleGroupFk = scsg.saleGroupFk + JOIN state s ON s.code = 'OK PREVIOUS' + JOIN itemShelvingSale iss ON iss.saleFk = sgd.saleFk + WHERE sc.id = vSectorCollectionFk AND iss.isPicked; END$$ DELIMITER ; From 7dc35458e8973188cf4b968f335c438b378e85e5 Mon Sep 17 00:00:00 2001 From: ivanm Date: Thu, 17 Oct 2024 17:05:08 +0200 Subject: [PATCH 104/136] refactor: refs #7865 delete client.gestdocFk from TPV --- db/dump/fixtures.before.sql | 30 +++++++++---------- db/routines/vn2008/views/Clientes.sql | 1 - db/versions/11311-tealFern/00-firstScript.sql | 1 + 3 files changed, 16 insertions(+), 16 deletions(-) create mode 100644 db/versions/11311-tealFern/00-firstScript.sql diff --git a/db/dump/fixtures.before.sql b/db/dump/fixtures.before.sql index 7f7e50dd3..a6852be7e 100644 --- a/db/dump/fixtures.before.sql +++ b/db/dump/fixtures.before.sql @@ -388,23 +388,23 @@ INSERT INTO `vn`.`contactChannel`(`id`, `name`) (4, 'GCN Channel'), (5, 'The Newspaper'); -INSERT INTO `vn`.`client`(`id`,`name`,`fi`,`socialName`,`contact`,`street`,`city`,`postcode`,`phone`,`mobile`,`isRelevant`,`email`,`iban`,`dueDay`,`accountingAccount`,`isEqualizated`,`provinceFk`,`hasToInvoice`,`credit`,`countryFk`,`isActive`,`gestdocFk`,`quality`,`payMethodFk`,`created`,`isToBeMailed`,`contactChannelFk`,`hasSepaVnl`,`hasCoreVnl`,`hasCoreVnh`,`riskCalculated`, `hasToInvoiceByAddress`,`isTaxDataChecked`,`isFreezed`,`creditInsurance`,`isCreatedAsServed`,`hasInvoiceSimplified`,`salesPersonFk`,`isVies`,`businessTypeFk`,`typeFk`) +INSERT INTO `vn`.`client`(`id`,`name`,`fi`,`socialName`,`contact`,`street`,`city`,`postcode`,`phone`,`mobile`,`isRelevant`,`email`,`iban`,`dueDay`,`accountingAccount`,`isEqualizated`,`provinceFk`,`hasToInvoice`,`credit`,`countryFk`,`isActive`,`quality`,`payMethodFk`,`created`,`isToBeMailed`,`contactChannelFk`,`hasSepaVnl`,`hasCoreVnl`,`hasCoreVnh`,`riskCalculated`, `hasToInvoiceByAddress`,`isTaxDataChecked`,`isFreezed`,`creditInsurance`,`isCreatedAsServed`,`hasInvoiceSimplified`,`salesPersonFk`,`isVies`,`businessTypeFk`,`typeFk`) VALUES - (1101, 'Bruce Wayne', '84612325V', 'BATMAN', 'Alfred', '1007 MOUNTAIN DRIVE, GOTHAM', 'Gotham', 46460, 1111111111, 222222222, 1, 'BruceWayne@mydomain.com', NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1, NULL, 10, 5, util.VN_CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, 1, 0, NULL, 0, 0, 18, 0, 'florist','normal'), - (1102, 'Petter Parker', '87945234L', 'SPIDER MAN', 'Aunt May', '20 INGRAM STREET, QUEENS, USA', 'Gotham', 46460, 1111111111, 222222222, 1, 'PetterParker@mydomain.com', NULL, 0, 1234567890, 0, 2, 1, 300, 1, 1, NULL, 10, 5, util.VN_CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, 1, 0, NULL, 0, 0, 18, 0, 'florist','normal'), - (1103, 'Clark Kent', '06815934E', 'SUPER MAN', 'lois lane', '344 CLINTON STREET, APARTAMENT 3-D', 'Gotham', 46460, 1111111111, 222222222, 1, 'ClarkKent@mydomain.com', NULL, 0, 1234567890, 0, 3, 1, 0, 19, 1, NULL, 10, 5, util.VN_CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, 1, 0, NULL, 0, 0, 18, 0, 'florist','normal'), - (1104, 'Tony Stark', '06089160W', 'IRON MAN', 'Pepper Potts', '10880 MALIBU POINT, 90265', 'Gotham', 46460, 1111111111, 222222222, 1, 'TonyStark@mydomain.com', NULL, 0, 1234567890, 0, 2, 1, 300, 1, 1, NULL, 10, 5, util.VN_CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, 1, 0, NULL, 0, 0, 18, 0, 'florist','normal'), - (1105, 'Max Eisenhardt', '251628698', 'MAGNETO', 'Rogue', 'UNKNOWN WHEREABOUTS', 'Gotham', 46460, 1111111111, 222222222, 1, 'MaxEisenhardt@mydomain.com', NULL, 0, 1234567890, 0, 3, 1, 300, 8, 1, NULL, 10, 5, util.VN_CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, 1, 1, NULL, 0, 0, 18, 0, 'florist','normal'), - (1106, 'DavidCharlesHaller', '53136686Q', 'LEGION', 'Charles Xavier', 'CITY OF NEW YORK, NEW YORK, USA', 'Gotham', 46460, 1111111111, 222222222, 1, 'DavidCharlesHaller@mydomain.com', NULL, 0, 1234567890, 0, 1, 1, 300, 1, 0, NULL, 10, 5, util.VN_CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, 1, 0, NULL, 0, 0, 19, 0, 'florist','normal'), - (1107, 'Hank Pym', '09854837G', 'ANT MAN', 'Hawk', 'ANTHILL, SAN FRANCISCO, CALIFORNIA', 'Gotham', 46460, 1111111111, 222222222, 1, 'HankPym@mydomain.com', NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1, NULL, 10, 5, util.VN_CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, 0, 0, NULL, 0, 0, 19, 0, 'florist','normal'), - (1108, 'Charles Xavier', '22641921P', 'PROFESSOR X', 'Beast', '3800 VICTORY PKWY, CINCINNATI, OH 45207, USA', 'Gotham', 46460, 1111111111, 222222222, 1, 'CharlesXavier@mydomain.com', NULL, 0, 1234567890, 0, 5, 1, 300, 13, 1, NULL, 10, 5, util.VN_CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, 1, 1, NULL, 0, 0, 19, 0, 'florist','normal'), - (1109, 'Bruce Banner', '16104829E', 'HULK', 'Black widow', 'SOMEWHERE IN NEW YORK', 'Gotham', 46460, 1111111111, 222222222, 1, 'BruceBanner@mydomain.com', NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1, NULL, 10, 5, util.VN_CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, 0, 0, NULL, 0, 0, 9, 0, 'florist','normal'), - (1110, 'Jessica Jones', '58282869H', 'JESSICA JONES', 'Luke Cage', 'NYCC 2015 POSTER', 'Gotham', 46460, 1111111111, 222222222, 1, 'JessicaJones@mydomain.com', NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1, NULL, 10, 5, util.VN_CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, 1, 0, NULL, 0, 0, NULL, 1, 'florist','normal'), - (1111, 'Missing', NULL, 'MISSING MAN', 'Anton', 'THE SPACE, UNIVERSE FAR AWAY', 'Gotham', 46460, 1111111111, 222222222, 1, NULL, NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1, NULL, 10, 5, util.VN_CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 0, 1, 0, NULL, 1, 0, NULL, 0, 'others','loses'), - (1112, 'Trash', NULL, 'GARBAGE MAN', 'Unknown name', 'NEW YORK CITY, UNDERGROUND', 'Gotham', 46460, 1111111111, 222222222, 1, NULL, NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1, NULL, 10, 5, util.VN_CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 0, 1, 0, NULL, 1, 0, NULL, 0, 'others','loses'); + (1101, 'Bruce Wayne', '84612325V', 'BATMAN', 'Alfred', '1007 MOUNTAIN DRIVE, GOTHAM', 'Gotham', 46460, 1111111111, 222222222, 1, 'BruceWayne@mydomain.com', NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1, 10, 5, util.VN_CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, 1, 0, NULL, 0, 0, 18, 0, 'florist','normal'), + (1102, 'Petter Parker', '87945234L', 'SPIDER MAN', 'Aunt May', '20 INGRAM STREET, QUEENS, USA', 'Gotham', 46460, 1111111111, 222222222, 1, 'PetterParker@mydomain.com', NULL, 0, 1234567890, 0, 2, 1, 300, 1, 1, 10, 5, util.VN_CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, 1, 0, NULL, 0, 0, 18, 0, 'florist','normal'), + (1103, 'Clark Kent', '06815934E', 'SUPER MAN', 'lois lane', '344 CLINTON STREET, APARTAMENT 3-D', 'Gotham', 46460, 1111111111, 222222222, 1, 'ClarkKent@mydomain.com', NULL, 0, 1234567890, 0, 3, 1, 0, 19, 1, 10, 5, util.VN_CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, 1, 0, NULL, 0, 0, 18, 0, 'florist','normal'), + (1104, 'Tony Stark', '06089160W', 'IRON MAN', 'Pepper Potts', '10880 MALIBU POINT, 90265', 'Gotham', 46460, 1111111111, 222222222, 1, 'TonyStark@mydomain.com', NULL, 0, 1234567890, 0, 2, 1, 300, 1, 1, 10, 5, util.VN_CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, 1, 0, NULL, 0, 0, 18, 0, 'florist','normal'), + (1105, 'Max Eisenhardt', '251628698', 'MAGNETO', 'Rogue', 'UNKNOWN WHEREABOUTS', 'Gotham', 46460, 1111111111, 222222222, 1, 'MaxEisenhardt@mydomain.com', NULL, 0, 1234567890, 0, 3, 1, 300, 8, 1, 10, 5, util.VN_CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, 1, 1, NULL, 0, 0, 18, 0, 'florist','normal'), + (1106, 'DavidCharlesHaller', '53136686Q', 'LEGION', 'Charles Xavier', 'CITY OF NEW YORK, NEW YORK, USA', 'Gotham', 46460, 1111111111, 222222222, 1, 'DavidCharlesHaller@mydomain.com', NULL, 0, 1234567890, 0, 1, 1, 300, 1, 0, 10, 5, util.VN_CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, 1, 0, NULL, 0, 0, 19, 0, 'florist','normal'), + (1107, 'Hank Pym', '09854837G', 'ANT MAN', 'Hawk', 'ANTHILL, SAN FRANCISCO, CALIFORNIA', 'Gotham', 46460, 1111111111, 222222222, 1, 'HankPym@mydomain.com', NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1, 10, 5, util.VN_CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, 0, 0, NULL, 0, 0, 19, 0, 'florist','normal'), + (1108, 'Charles Xavier', '22641921P', 'PROFESSOR X', 'Beast', '3800 VICTORY PKWY, CINCINNATI, OH 45207, USA', 'Gotham', 46460, 1111111111, 222222222, 1, 'CharlesXavier@mydomain.com', NULL, 0, 1234567890, 0, 5, 1, 300, 13, 1, 10, 5, util.VN_CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, 1, 1, NULL, 0, 0, 19, 0, 'florist','normal'), + (1109, 'Bruce Banner', '16104829E', 'HULK', 'Black widow', 'SOMEWHERE IN NEW YORK', 'Gotham', 46460, 1111111111, 222222222, 1, 'BruceBanner@mydomain.com', NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1, 10, 5, util.VN_CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, 0, 0, NULL, 0, 0, 9, 0, 'florist','normal'), + (1110, 'Jessica Jones', '58282869H', 'JESSICA JONES', 'Luke Cage', 'NYCC 2015 POSTER', 'Gotham', 46460, 1111111111, 222222222, 1, 'JessicaJones@mydomain.com', NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1, 10, 5, util.VN_CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, 1, 0, NULL, 0, 0, NULL, 1, 'florist','normal'), + (1111, 'Missing', NULL, 'MISSING MAN', 'Anton', 'THE SPACE, UNIVERSE FAR AWAY', 'Gotham', 46460, 1111111111, 222222222, 1, NULL, NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1, 10, 5, util.VN_CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 0, 1, 0, NULL, 1, 0, NULL, 0, 'others','loses'), + (1112, 'Trash', NULL, 'GARBAGE MAN', 'Unknown name', 'NEW YORK CITY, UNDERGROUND', 'Gotham', 46460, 1111111111, 222222222, 1, NULL, NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1, 10, 5, util.VN_CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 0, 1, 0, NULL, 1, 0, NULL, 0, 'others','loses'); -INSERT INTO `vn`.`client`(`id`, `name`, `fi`, `socialName`, `contact`, `street`, `city`, `postcode`, `isRelevant`, `email`, `iban`,`dueDay`,`accountingAccount`, `isEqualizated`, `provinceFk`, `hasToInvoice`, `credit`, `countryFk`, `isActive`, `gestdocFk`, `quality`, `payMethodFk`,`created`, `isTaxDataChecked`) - SELECT id, name, CONCAT(RPAD(CONCAT(id,9),8,id),'A'), UPPER(CONCAT(name, 'Social')), CONCAT(name, 'Contact'), CONCAT(name, 'Street'), 'GOTHAM', 46460, 1, CONCAT(name,'@mydomain.com'), NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1,NULL, 10, 5, util.VN_CURDATE(), 1 +INSERT INTO `vn`.`client`(`id`, `name`, `fi`, `socialName`, `contact`, `street`, `city`, `postcode`, `isRelevant`, `email`, `iban`,`dueDay`,`accountingAccount`, `isEqualizated`, `provinceFk`, `hasToInvoice`, `credit`, `countryFk`, `isActive`, `quality`, `payMethodFk`,`created`, `isTaxDataChecked`) + SELECT id, name, CONCAT(RPAD(CONCAT(id,9),8,id),'A'), UPPER(CONCAT(name, 'Social')), CONCAT(name, 'Contact'), CONCAT(name, 'Street'), 'GOTHAM', 46460, 1, CONCAT(name,'@mydomain.com'), NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1, 10, 5, util.VN_CURDATE(), 1 FROM `account`.`role` `r` WHERE `r`.`hasLogin` = 1; diff --git a/db/routines/vn2008/views/Clientes.sql b/db/routines/vn2008/views/Clientes.sql index 153d875bc..9f8ef712e 100644 --- a/db/routines/vn2008/views/Clientes.sql +++ b/db/routines/vn2008/views/Clientes.sql @@ -22,7 +22,6 @@ AS SELECT `c`.`id` AS `id_cliente`, `c`.`credit` AS `credito`, `c`.`countryFk` AS `Id_Pais`, `c`.`isActive` AS `activo`, - `c`.`gestdocFk` AS `gestdoc_id`, `c`.`quality` AS `calidad`, `c`.`payMethodFk` AS `pay_met_id`, `c`.`created` AS `created`, diff --git a/db/versions/11311-tealFern/00-firstScript.sql b/db/versions/11311-tealFern/00-firstScript.sql new file mode 100644 index 000000000..909747f3c --- /dev/null +++ b/db/versions/11311-tealFern/00-firstScript.sql @@ -0,0 +1 @@ +ALTER TABLE vn.client CHANGE gestdocFk gestdocFk__ int(11) DEFAULT NULL NULL COMMENT '@deprecated 2024-10-17'; \ No newline at end of file From 34630360866759b5bce57227b5581d203abf98ed Mon Sep 17 00:00:00 2001 From: sergiodt Date: Thu, 17 Oct 2024 17:20:21 +0200 Subject: [PATCH 105/136] fix: refs #6861 saleTrackingAdd --- .../saleTracking_sectorCollectionAddPrevOK.sql | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/db/routines/vn/procedures/saleTracking_sectorCollectionAddPrevOK.sql b/db/routines/vn/procedures/saleTracking_sectorCollectionAddPrevOK.sql index a5d34c2d6..003168ec8 100644 --- a/db/routines/vn/procedures/saleTracking_sectorCollectionAddPrevOK.sql +++ b/db/routines/vn/procedures/saleTracking_sectorCollectionAddPrevOK.sql @@ -1,23 +1,15 @@ DELIMITER $$ CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`saleTracking_sectorCollectionAddPrevOK`( vSectorCollectionFk INT - ) +) BEGIN /** * Inserta los registros de sectorCollection con el estado PREVIA OK si la reserva está picked * * @param vSectorCollectionFk Identificador de vn.sectorCollection */ - REPLACE saleTracking( - saleFk, - isChecked, - workerFk, - stateFk - ) - SELECT sgd.saleFk, - TRUE, - sc.userFk, - s.id + REPLACE saleTracking(saleFk, isChecked, workerFk, stateFk) + SELECT sgd.saleFk, TRUE, sc.userFk, s.id FROM sectorCollection sc JOIN sectorCollectionSaleGroup scsg ON scsg.sectorCollectionFk = sc.id JOIN saleGroupDetail sgd ON sgd.saleGroupFk = scsg.saleGroupFk From 865da7bba2b6d071bcbfd8432ea8bfcf091e784c Mon Sep 17 00:00:00 2001 From: guillermo Date: Fri, 18 Oct 2024 07:15:26 +0200 Subject: [PATCH 106/136] refactor: refs #8106 Requested changes --- db/routines/vn/procedures/ticket_getTax.sql | 35 +++++++++------------ 1 file changed, 15 insertions(+), 20 deletions(-) diff --git a/db/routines/vn/procedures/ticket_getTax.sql b/db/routines/vn/procedures/ticket_getTax.sql index fc266f978..cb9dc09d9 100644 --- a/db/routines/vn/procedures/ticket_getTax.sql +++ b/db/routines/vn/procedures/ticket_getTax.sql @@ -36,8 +36,7 @@ BEGIN (PRIMARY KEY (ticketFk, code, rate)) ENGINE = MEMORY WITH sales AS ( - SELECT s.id, - s.ticketFk, + SELECT s.ticketFk, s.itemFk, s.quantity * s.price * (100 - s.discount) / 100 total, t.companyFk, @@ -54,25 +53,21 @@ BEGIN JOIN vn.itemTaxCountry itc ON itc.itemFk = s.itemFk AND itc.countryFk = su.countryFk HAVING total - ), - ticketTax AS ( - SELECT s.ticketFk, - bp.pgcFk, - SUM(s.total) taxableBase, - pgc.rate, - tc.code, - bp.priority - FROM sales s - JOIN vn.bookingPlanner bp ON bp.countryFk = s.countryFk - AND bp.taxAreaFk = s.areaFk - AND bp.taxClassFk = s.taxClassFk - JOIN vn.pgc ON pgc.code = bp.pgcFk - JOIN vn.taxClass tc ON tc.id = bp.taxClassFk - GROUP BY s.ticketFk, pgc.code, pgc.rate - HAVING taxableBase ) - SELECT * - FROM ticketTax + SELECT s.ticketFk, + bp.pgcFk, + SUM(s.total) taxableBase, + pgc.rate, + tc.code, + bp.priority + FROM sales s + JOIN vn.bookingPlanner bp ON bp.countryFk = s.countryFk + AND bp.taxAreaFk = s.areaFk + AND bp.taxClassFk = s.taxClassFk + JOIN vn.pgc ON pgc.code = bp.pgcFk + JOIN vn.taxClass tc ON tc.id = bp.taxClassFk + GROUP BY s.ticketFk, pgc.code, pgc.rate + HAVING taxableBase ORDER BY priority; CREATE OR REPLACE TEMPORARY TABLE tmp.ticketServiceTax From 4bd28c62b9ffc43470ec2f883ee1d4d3b8328872 Mon Sep 17 00:00:00 2001 From: guillermo Date: Fri, 18 Oct 2024 07:35:36 +0200 Subject: [PATCH 107/136] 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 108/136] 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 93494c3eb05ad06cab9102cc06ebdebac06dab85 Mon Sep 17 00:00:00 2001 From: guillermo Date: Fri, 18 Oct 2024 08:02:06 +0200 Subject: [PATCH 109/136] refactor: refs #7811 Deleted pm2 --- back/Dockerfile | 5 ++--- back/process.yml | 7 ------- 2 files changed, 2 insertions(+), 10 deletions(-) delete mode 100644 back/process.yml diff --git a/back/Dockerfile b/back/Dockerfile index 3e2a90c58..0f75f6949 100644 --- a/back/Dockerfile +++ b/back/Dockerfile @@ -32,8 +32,7 @@ RUN apt-get update \ RUN apt-get update \ && apt-get install -y --no-install-recommends \ samba-common-bin samba-dsdb-modules\ - && rm -rf /var/lib/apt/lists/* \ - && npm -g install pm2 + && rm -rf /var/lib/apt/lists/* # Salix @@ -55,4 +54,4 @@ COPY \ README.md \ ./ -CMD ["pm2-runtime", "./back/process.yml"] \ No newline at end of file +CMD ["node", "--tls-min-v1.0", "--openssl-legacy-provider", "./loopback/server/server.js"] \ No newline at end of file diff --git a/back/process.yml b/back/process.yml deleted file mode 100644 index 94072b57d..000000000 --- a/back/process.yml +++ /dev/null @@ -1,7 +0,0 @@ -apps: - - script: ./loopback/server/server.js - name: salix-back - instances: 1 - max_restarts: 0 - autorestart: false - node_args: --tls-min-v1.0 --openssl-legacy-provider From 02dc9520244f673d143eddcce2e176b88bc5695a Mon Sep 17 00:00:00 2001 From: carlossa Date: Fri, 18 Oct 2024 08:28:08 +0200 Subject: [PATCH 110/136] fix: refs #7906 add test --- .../back/methods/zone/specs/deleteZone.spec.js | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/modules/zone/back/methods/zone/specs/deleteZone.spec.js b/modules/zone/back/methods/zone/specs/deleteZone.spec.js index 60e704161..14cb303ea 100644 --- a/modules/zone/back/methods/zone/specs/deleteZone.spec.js +++ b/modules/zone/back/methods/zone/specs/deleteZone.spec.js @@ -9,8 +9,8 @@ describe('zone deletezone()', () => { }; const ctx = {req: activeCtx}; const zoneId = 4; + const zoneId2 = 3; let ticketIDs; - let originalTicketStates; beforeAll(async() => { spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({ @@ -44,4 +44,19 @@ describe('zone deletezone()', () => { throw e; } }); + + it('should not delete the zone if it has tickets', async() => { + const tx = await models.Zone.beginTransaction({}); + + try { + const options = {transaction: tx}; + await models.Zone.deleteZone(ctx, zoneId2, options); + + expect(e.message).toEqual('There are tickets for this area, delete them first'); + + await tx.rollback(); + } catch (e) { + await tx.rollback(); + } + }); }); From 1273e895afa18d89fabc9a16590b1b63cd73544f Mon Sep 17 00:00:00 2001 From: carlossa Date: Fri, 18 Oct 2024 09:27:43 +0200 Subject: [PATCH 111/136] fix: refs #7906 fix test back --- modules/zone/back/methods/zone/specs/deleteZone.spec.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/modules/zone/back/methods/zone/specs/deleteZone.spec.js b/modules/zone/back/methods/zone/specs/deleteZone.spec.js index 14cb303ea..aef7fd290 100644 --- a/modules/zone/back/methods/zone/specs/deleteZone.spec.js +++ b/modules/zone/back/methods/zone/specs/deleteZone.spec.js @@ -48,15 +48,16 @@ describe('zone deletezone()', () => { it('should not delete the zone if it has tickets', async() => { const tx = await models.Zone.beginTransaction({}); + let error; try { const options = {transaction: tx}; await models.Zone.deleteZone(ctx, zoneId2, options); - - expect(e.message).toEqual('There are tickets for this area, delete them first'); - await tx.rollback(); } catch (e) { + error = e.message; await tx.rollback(); } + + expect(error).toEqual('There are tickets for this area, delete them first'); }); }); From 46993ad10324b839f25b90476dacbb7dbae15803 Mon Sep 17 00:00:00 2001 From: Jon Date: Fri, 18 Oct 2024 09:29:01 +0200 Subject: [PATCH 112/136] refactor: refs #7010 deleted distinct --- modules/ticket/back/methods/ticket/filter.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/ticket/back/methods/ticket/filter.js b/modules/ticket/back/methods/ticket/filter.js index d7e77603b..d3e53c702 100644 --- a/modules/ticket/back/methods/ticket/filter.js +++ b/modules/ticket/back/methods/ticket/filter.js @@ -229,7 +229,7 @@ module.exports = Self => { CREATE OR REPLACE TEMPORARY TABLE tmp.filter (INDEX (id)) ENGINE = InnoDB - SELECT DISTINCT t.id, + SELECT t.id, t.shipped, CAST(DATE(t.shipped) AS CHAR) shippedDate, HOUR(t.shipped) shippedHour, From b8e782d3a569f935aeb7d55ce65ecde345a7d93b Mon Sep 17 00:00:00 2001 From: carlossa Date: Sun, 20 Oct 2024 15:59:24 +0200 Subject: [PATCH 113/136] fix: refs #6831 filter observation --- modules/client/back/methods/defaulter/filter.js | 3 ++- modules/client/back/methods/defaulter/observationEmail.js | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/modules/client/back/methods/defaulter/filter.js b/modules/client/back/methods/defaulter/filter.js index 9f19dee0a..5359ce4a7 100644 --- a/modules/client/back/methods/defaulter/filter.js +++ b/modules/client/back/methods/defaulter/filter.js @@ -74,7 +74,8 @@ module.exports = Self => { pm.name payMethod, r.finished IS NULL hasRecovery, dp.id departmentFk, - dp.name departmentName + dp.name departmentName, + dp.notificationEmail departmentEmail FROM defaulter d JOIN client c ON c.id = d.clientFk JOIN country cn ON cn.id = c.countryFk diff --git a/modules/client/back/methods/defaulter/observationEmail.js b/modules/client/back/methods/defaulter/observationEmail.js index c06d1d3d0..797e88f74 100644 --- a/modules/client/back/methods/defaulter/observationEmail.js +++ b/modules/client/back/methods/defaulter/observationEmail.js @@ -47,7 +47,7 @@ module.exports = Self => { await models.Mail.create({ subject: $t('Comment added to client', {clientFk: defaulter.clientFk}), body: body, - receiver: `${defaulter.salesPersonName}@verdnatura.es`, + receiver: `${defaulter.departmentEmail}`, replyTo: `${user.name}@verdnatura.es` }, myOptions); } From b88dc1c70fc956920b292f6d16a8e270d85667f6 Mon Sep 17 00:00:00 2001 From: carlossa Date: Sun, 20 Oct 2024 16:23:24 +0200 Subject: [PATCH 114/136] fix: refs #6850 remove notifyPickUp --- modules/claim/back/methods/claim/updateClaim.js | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/modules/claim/back/methods/claim/updateClaim.js b/modules/claim/back/methods/claim/updateClaim.js index 326192385..927e27622 100644 --- a/modules/claim/back/methods/claim/updateClaim.js +++ b/modules/claim/back/methods/claim/updateClaim.js @@ -119,18 +119,4 @@ module.exports = Self => { }); await models.Chat.sendCheckingPresence(ctx, workerId, message); } - - async function notifyPickUp(ctx, workerId, claim) { - const models = Self.app.models; - const url = await models.Url.getUrl(); - const $t = ctx.req.__; // $translate - - const message = $t('Claim will be picked', { - claimId: claim.id, - clientName: claim.client().name, - claimUrl: `${url}claim/${claim.id}/summary`, - claimPickup: $t(claim.pickup) - }); - await models.Chat.sendCheckingPresence(ctx, workerId, message); - } }; From 19fbb836a60f6dd6478f24cf04a54e2c801b4cf7 Mon Sep 17 00:00:00 2001 From: carlossa Date: Mon, 21 Oct 2024 08:30:39 +0200 Subject: [PATCH 115/136] fix: refs #6850 fix model --- modules/claim/back/methods/claim/updateClaim.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/modules/claim/back/methods/claim/updateClaim.js b/modules/claim/back/methods/claim/updateClaim.js index 927e27622..f2f3f9050 100644 --- a/modules/claim/back/methods/claim/updateClaim.js +++ b/modules/claim/back/methods/claim/updateClaim.js @@ -86,9 +86,6 @@ module.exports = Self => { const salesPerson = claim.client().salesPersonUser(); if (salesPerson) { - if (changedPickup && updatedClaim.pickup) - await notifyPickUp(ctx, salesPerson.id, claim); - if (args.claimStateFk) { const newState = await models.ClaimState.findById(args.claimStateFk, null, myOptions); await notifyStateChange(ctx, salesPerson.id, claim, newState.description); From bbc17d1ff886898b90cb2a75d33d8598665fcb27 Mon Sep 17 00:00:00 2001 From: guillermo Date: Mon, 21 Oct 2024 08:33:16 +0200 Subject: [PATCH 116/136] fix: refs #230926 item_getSimilar --- db/routines/vn/procedures/item_getSimilar.sql | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/db/routines/vn/procedures/item_getSimilar.sql b/db/routines/vn/procedures/item_getSimilar.sql index 537f53848..336f3521e 100644 --- a/db/routines/vn/procedures/item_getSimilar.sql +++ b/db/routines/vn/procedures/item_getSimilar.sql @@ -24,6 +24,7 @@ BEGIN CALL cache.available_refresh(vAvailableCalcFk, FALSE, vWarehouseFk, vDated); CALL cache.visible_refresh(vVisibleCalcFk, FALSE, vWarehouseFk); + CALL buy_getUltimate(NULL, vWarehouseFk, vDated); WITH itemTags AS ( SELECT i.id, @@ -74,14 +75,13 @@ BEGIN AND a.calc_id = vAvailableCalcFk LEFT JOIN cache.visible v ON v.item_id = i.id AND v.calc_id = vVisibleCalcFk - LEFT JOIN cache.last_buy lb ON lb.item_id = i.id - AND lb.warehouse_id = vWarehouseFk + LEFT JOIN tmp.buyUltimate bu ON bu.itemFk = i.id LEFT JOIN vn.itemProposal ip ON ip.mateFk = i.id AND ip.itemFk = vSelf LEFT JOIN vn.itemTag it ON it.itemFk = i.id AND it.priority = vPriority LEFT JOIN vn.tag t ON t.id = it.tagFk - LEFT JOIN vn.buy b ON b.id = lb.buy_id + LEFT JOIN vn.buy b ON b.id = bu.buyFk JOIN itemTags its WHERE a.available > 0 AND (i.typeFk = its.typeFk OR NOT vShowType) @@ -98,5 +98,7 @@ BEGIN (i.tag8 = its.tag8) DESC, match8 DESC LIMIT 100; + + DROP TEMPORARY TABLE tmp.buyUltimate; END$$ DELIMITER ; From eea09a9d4ae250a351d90e0fe65030da882c6cd2 Mon Sep 17 00:00:00 2001 From: carlossa Date: Mon, 21 Oct 2024 09:24:53 +0200 Subject: [PATCH 117/136] fix: refs #6850 add code --- modules/claim/back/methods/claim/updateClaim.js | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/modules/claim/back/methods/claim/updateClaim.js b/modules/claim/back/methods/claim/updateClaim.js index f2f3f9050..563b5b53d 100644 --- a/modules/claim/back/methods/claim/updateClaim.js +++ b/modules/claim/back/methods/claim/updateClaim.js @@ -85,13 +85,11 @@ module.exports = Self => { const updatedClaim = await claim.updateAttributes(args, myOptions); const salesPerson = claim.client().salesPersonUser(); - if (salesPerson) { - if (args.claimStateFk) { - const newState = await models.ClaimState.findById(args.claimStateFk, null, myOptions); - await notifyStateChange(ctx, salesPerson.id, claim, newState.description); - if (newState.code == 'canceled') - await notifyStateChange(ctx, claim.workerFk, claim, newState.description); - } + if (salesPerson && args.claimStateFk) { + const newState = await models.ClaimState.findById(args.claimStateFk, null, myOptions); + await notifyStateChange(ctx, salesPerson.id, claim, newState.description); + if (newState.code == 'canceled') + await notifyStateChange(ctx, claim.workerFk, claim, newState.description); } if (tx) await tx.commit(); From 288dc1c598b7cc4ff2457c9bfc9bc683ffce5086 Mon Sep 17 00:00:00 2001 From: jorgep Date: Mon, 21 Oct 2024 10:05:58 +0200 Subject: [PATCH 118/136] feat: refs #7524 myteam filter wip --- .../back/methods/ticket/getTicketsAdvance.js | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/modules/ticket/back/methods/ticket/getTicketsAdvance.js b/modules/ticket/back/methods/ticket/getTicketsAdvance.js index 1bd5f83de..4585c5d61 100644 --- a/modules/ticket/back/methods/ticket/getTicketsAdvance.js +++ b/modules/ticket/back/methods/ticket/getTicketsAdvance.js @@ -50,6 +50,11 @@ module.exports = Self => { type: 'boolean', description: 'True when lines and stock of origin are equal' }, + { + arg: 'myTeam', + type: 'boolean', + description: `Whether to show only tickets for the current logged user team (currently user tickets)` + }, { arg: 'filter', type: 'object', @@ -69,11 +74,27 @@ module.exports = Self => { Self.getTicketsAdvance = async(ctx, options) => { const args = ctx.args; const conn = Self.dataSource.connector; + const userId = ctx.req.accessToken.userId; const myOptions = {}; if (typeof options == 'object') Object.assign(myOptions, options); + const teamMembersId = []; + if (args.myTeam != null) { + const worker = await models.Worker.findById(userId, { + include: { + relation: 'collegues' + } + }, myOptions); + const collegues = worker.collegues() || []; + for (let collegue of collegues) + teamMembersId.push(collegue.collegueFk); + + if (teamMembersId.length == 0) + teamMembersId.push(userId); + } + const where = buildFilter(ctx.args, (param, value) => { switch (param) { case 'id': @@ -96,6 +117,11 @@ module.exports = Self => { }; case 'isFullMovable': return {'f.isFullMovable': value}; + case 'myTeam': + if (value) + return {'c.salesPersonFk': {inq: teamMembersId}}; + else + return {'c.salesPersonFk': {nin: teamMembersId}}; } }); From cb4e8355ba3f21d05c202ded792f3588d1f5bf65 Mon Sep 17 00:00:00 2001 From: jorgep Date: Mon, 21 Oct 2024 10:58:36 +0200 Subject: [PATCH 119/136] feat: refs #7524 myteam filter --- modules/ticket/back/methods/ticket/getTicketsAdvance.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/ticket/back/methods/ticket/getTicketsAdvance.js b/modules/ticket/back/methods/ticket/getTicketsAdvance.js index 4585c5d61..1088d357c 100644 --- a/modules/ticket/back/methods/ticket/getTicketsAdvance.js +++ b/modules/ticket/back/methods/ticket/getTicketsAdvance.js @@ -82,7 +82,7 @@ module.exports = Self => { const teamMembersId = []; if (args.myTeam != null) { - const worker = await models.Worker.findById(userId, { + const worker = await Self.app.models.Worker.findById(userId, { include: { relation: 'collegues' } @@ -119,9 +119,9 @@ module.exports = Self => { return {'f.isFullMovable': value}; case 'myTeam': if (value) - return {'c.salesPersonFk': {inq: teamMembersId}}; + return {'workerFk': {inq: teamMembersId}}; else - return {'c.salesPersonFk': {nin: teamMembersId}}; + return {'workerFk': {nin: teamMembersId}}; } }); From e38c061debb71120f5aefc19f1e91a43531c7765 Mon Sep 17 00:00:00 2001 From: pablone Date: Mon, 21 Oct 2024 11:36:44 +0200 Subject: [PATCH 120/136] fix: add date format on insert data --- .../bs/procedures/clientNewBorn_recalc.sql | 21 +++++++++---------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/db/routines/bs/procedures/clientNewBorn_recalc.sql b/db/routines/bs/procedures/clientNewBorn_recalc.sql index 1c89b5745..c56ffe49c 100644 --- a/db/routines/bs/procedures/clientNewBorn_recalc.sql +++ b/db/routines/bs/procedures/clientNewBorn_recalc.sql @@ -7,24 +7,23 @@ BLOCK1: BEGIN DECLARE vPreviousShipped DATE; DECLARE vDone boolean; DECLARE cur cursor for - - SELECT clientFk, firstShipped - FROM bs.clientNewBorn; DECLARE continue HANDLER FOR NOT FOUND SET vDone = TRUE; SET vDone := FALSE; DELETE FROM bs.clientNewBorn WHERE isModified = FALSE; - INSERT INTO clientNewBorn(clientFk, firstShipped, lastShipped) - SELECT c.id, MAX(t.shipped), MAX(t.shipped) - FROM vn.client c - JOIN vn.ticket t on t.clientFk = c.id - LEFT JOIN clientNewBorn cb on cb.clientFk = c.id - WHERE t.shipped BETWEEN TIMESTAMPADD(YEAR, -1, util.VN_CURDATE()) AND util.VN_CURDATE() AND cb.isModified is null - GROUP BY c.id; + INSERT INTO clientNewBorn(clientFk, firstShipped, lastShipped) + SELECT c.id, DATE(MAX(t.shipped)), DATE(MAX(t.shipped)) + FROM vn.client c + JOIN vn.ticket t ON t.clientFk = c.id + LEFT JOIN clientNewBorn cb ON cb.clientFk = c.id + WHERE t.shipped BETWEEN util.VN_CURDATE() - INTERVAL 1 YEAR + AND util.VN_CURDATE() + AND cb.isModified IS NULL + GROUP BY c.id; + OPEN cur; - LOOP1: LOOP SET vDone := FALSE; FETCH cur INTO vClientFk, vShipped; From e479873547e262c3a7054e4d234eaaba8c91c3d0 Mon Sep 17 00:00:00 2001 From: pablone Date: Mon, 21 Oct 2024 12:19:20 +0200 Subject: [PATCH 121/136] fix: restore cursor --- db/routines/bs/procedures/clientNewBorn_recalc.sql | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/db/routines/bs/procedures/clientNewBorn_recalc.sql b/db/routines/bs/procedures/clientNewBorn_recalc.sql index c56ffe49c..bb6b02aa7 100644 --- a/db/routines/bs/procedures/clientNewBorn_recalc.sql +++ b/db/routines/bs/procedures/clientNewBorn_recalc.sql @@ -6,7 +6,10 @@ BLOCK1: BEGIN DECLARE vShipped DATE; DECLARE vPreviousShipped DATE; DECLARE vDone boolean; - DECLARE cur cursor for + + DECLARE cur CURSOR FOR + SELECT clientFk, firstShipped + FROM bs.clientNewBorn; DECLARE continue HANDLER FOR NOT FOUND SET vDone = TRUE; SET vDone := FALSE; From 2b05e8c48e4c2dae7920fdbff21a178767d84f89 Mon Sep 17 00:00:00 2001 From: jgallego Date: Mon, 21 Oct 2024 13:29:33 +0200 Subject: [PATCH 122/136] feat: refs #7943 quitar lectura en metodos comunes --- db/routines/salix/triggers/ACL_beforeInsert.sql | 3 +++ db/versions/11314-redTulip/00-restrictedAsterisk.sql | 3 +++ 2 files changed, 6 insertions(+) create mode 100644 db/versions/11314-redTulip/00-restrictedAsterisk.sql diff --git a/db/routines/salix/triggers/ACL_beforeInsert.sql b/db/routines/salix/triggers/ACL_beforeInsert.sql index 94fb51ada..cb0b5761b 100644 --- a/db/routines/salix/triggers/ACL_beforeInsert.sql +++ b/db/routines/salix/triggers/ACL_beforeInsert.sql @@ -4,5 +4,8 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `salix`.`ACL_beforeInsert` FOR EACH ROW BEGIN SET NEW.editorFk = account.myUser_getId(); + IF NEW.`property` = '*' THEN + CALL util.throw('The property field cannot be *'); + END IF; END$$ DELIMITER ; diff --git a/db/versions/11314-redTulip/00-restrictedAsterisk.sql b/db/versions/11314-redTulip/00-restrictedAsterisk.sql new file mode 100644 index 000000000..20f1b4380 --- /dev/null +++ b/db/versions/11314-redTulip/00-restrictedAsterisk.sql @@ -0,0 +1,3 @@ +DELETE FROM `salix`.`ACL` +WHERE `model` = 'Worker' + AND `property` IN ('find', 'findById', 'findOne'); From 1efe258ea0b14c26a9035dc946d23ca394c182f6 Mon Sep 17 00:00:00 2001 From: jorgep Date: Mon, 21 Oct 2024 14:30:45 +0200 Subject: [PATCH 123/136] fix: refs #7524 filter by department --- .../vn/procedures/ticket_canAdvance.sql | 7 +++-- .../back/methods/ticket/getTicketsAdvance.js | 29 ++++--------------- 2 files changed, 10 insertions(+), 26 deletions(-) diff --git a/db/routines/vn/procedures/ticket_canAdvance.sql b/db/routines/vn/procedures/ticket_canAdvance.sql index 57c3f4235..e8fc70bba 100644 --- a/db/routines/vn/procedures/ticket_canAdvance.sql +++ b/db/routines/vn/procedures/ticket_canAdvance.sql @@ -51,7 +51,8 @@ BEGIN origin.companyFk futureCompanyFk, IFNULL(dest.nickname, origin.nickname) nickname, dest.landed, - dest.preparation + dest.preparation, + origin.departmentFk FROM ( SELECT s.ticketFk, c.salesPersonFk workerFk, @@ -71,9 +72,11 @@ BEGIN t.addressFk, t.warehouseFk, t.companyFk, - t.agencyModeFk + t.agencyModeFk, + wd.departmentFk FROM ticket t JOIN client c ON c.id = t.clientFk + JOIN workerDepartment wd ON wd.workerFk = c.salesPersonFk JOIN sale s ON s.ticketFk = t.id JOIN saleVolume sv ON sv.saleFk = s.id JOIN item i ON i.id = s.itemFk diff --git a/modules/ticket/back/methods/ticket/getTicketsAdvance.js b/modules/ticket/back/methods/ticket/getTicketsAdvance.js index 1088d357c..41f3ee79a 100644 --- a/modules/ticket/back/methods/ticket/getTicketsAdvance.js +++ b/modules/ticket/back/methods/ticket/getTicketsAdvance.js @@ -51,9 +51,9 @@ module.exports = Self => { description: 'True when lines and stock of origin are equal' }, { - arg: 'myTeam', - type: 'boolean', - description: `Whether to show only tickets for the current logged user team (currently user tickets)` + arg: 'departmentFk', + type: 'number', + description: 'Department identifier' }, { arg: 'filter', @@ -74,27 +74,11 @@ module.exports = Self => { Self.getTicketsAdvance = async(ctx, options) => { const args = ctx.args; const conn = Self.dataSource.connector; - const userId = ctx.req.accessToken.userId; const myOptions = {}; if (typeof options == 'object') Object.assign(myOptions, options); - const teamMembersId = []; - if (args.myTeam != null) { - const worker = await Self.app.models.Worker.findById(userId, { - include: { - relation: 'collegues' - } - }, myOptions); - const collegues = worker.collegues() || []; - for (let collegue of collegues) - teamMembersId.push(collegue.collegueFk); - - if (teamMembersId.length == 0) - teamMembersId.push(userId); - } - const where = buildFilter(ctx.args, (param, value) => { switch (param) { case 'id': @@ -117,11 +101,8 @@ module.exports = Self => { }; case 'isFullMovable': return {'f.isFullMovable': value}; - case 'myTeam': - if (value) - return {'workerFk': {inq: teamMembersId}}; - else - return {'workerFk': {nin: teamMembersId}}; + case 'departmentFk': + return {'f.departmentFk': value}; } }); From 5162c2037b650d4c1b7dfef0d546286cbf5488e4 Mon Sep 17 00:00:00 2001 From: guillermo Date: Tue, 22 Oct 2024 08:41:46 +0200 Subject: [PATCH 124/136] feat: refs #8119 Requested changes --- db/routines/vn/procedures/itemCampaignQuantity_add.sql | 5 ++++- db/versions/11308-redCymbidium/00-firstScript.sql | 1 + 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/db/routines/vn/procedures/itemCampaignQuantity_add.sql b/db/routines/vn/procedures/itemCampaignQuantity_add.sql index ca041d2d2..6edb97c08 100644 --- a/db/routines/vn/procedures/itemCampaignQuantity_add.sql +++ b/db/routines/vn/procedures/itemCampaignQuantity_add.sql @@ -65,12 +65,15 @@ proc: BEGIN SET vDateSumFrom = vDateSumTo - INTERVAL vScopeDays DAY; - REPLACE itemCampaignQuantity(dated, itemFk, quantity, campaign) + REPLACE itemCampaignQuantity(dated, itemFk, quantity, total, campaign) SELECT DATE(s.created), s.itemFk, SUM(CASE WHEN t.shipped BETWEEN vDateSumFrom AND vDateSumTo THEN s.quantity END) quantity, + SUM(CASE WHEN t.shipped BETWEEN vDateSumFrom AND vDateSumTo + THEN s.total + END) total, vCampaign FROM sale s JOIN ticket t ON t.id = s.ticketFk diff --git a/db/versions/11308-redCymbidium/00-firstScript.sql b/db/versions/11308-redCymbidium/00-firstScript.sql index d90cd1ae6..14fad3636 100644 --- a/db/versions/11308-redCymbidium/00-firstScript.sql +++ b/db/versions/11308-redCymbidium/00-firstScript.sql @@ -3,6 +3,7 @@ CREATE TABLE IF NOT EXISTS `vn`.`itemCampaignQuantity` ( dated date NOT NULL, itemFk int(11) NOT NULL, quantity decimal(10,2) NOT NULL, + total decimal(10,2) NOT NULL, campaign varchar(100) NOT NULL, UNIQUE KEY `itemCampaignQuantity_UNIQUE` (`dated`,`itemFk`), CONSTRAINT itemCampaignQuantity_item_FK FOREIGN KEY (itemFk) REFERENCES vn.item(id) ON DELETE RESTRICT ON UPDATE CASCADE From 6ef77604985c3ea38d9e3de0843b57ce28b5cb7e Mon Sep 17 00:00:00 2001 From: sergiodt Date: Tue, 22 Oct 2024 10:06:59 +0200 Subject: [PATCH 125/136] fix: refs #6861 fixTransactionCommit --- .../collection_addWithReservation.sql | 18 +++---- .../procedures/itemShelvingSale_addBySale.sql | 49 ++++++++++--------- 2 files changed, 34 insertions(+), 33 deletions(-) diff --git a/db/routines/vn/procedures/collection_addWithReservation.sql b/db/routines/vn/procedures/collection_addWithReservation.sql index cc0b7fd9b..bb6e94a63 100644 --- a/db/routines/vn/procedures/collection_addWithReservation.sql +++ b/db/routines/vn/procedures/collection_addWithReservation.sql @@ -37,23 +37,23 @@ BEGIN WHERE t.id = vTicketFk; CALL cache.available_refresh( - vCacheAvailableFk, + vCacheAvailableFk, FALSE, - vWarehouseFk, + vWarehouseFk, util.VN_CURDATE()); SELECT available INTO vAvailable FROM cache.available - WHERE calc_id = vCacheAvailableFk + WHERE calc_id = vCacheAvailableFk AND item_id = vItemFk; - + IF vAvailable < vQuantity THEN SET vHasThrow = TRUE; ELSE SELECT `name`, - CONCAT(getUser(), ' ', DATE_FORMAT(util.VN_NOW(), '%H:%i'), ' ', name) + CONCAT(getUser(), ' ', DATE_FORMAT(util.VN_NOW(), '%H:%i'), ' ', name) INTO vItemName, vConcept - FROM item + FROM item WHERE id = vItemFk; START TRANSACTION; @@ -69,7 +69,7 @@ BEGIN CALL sale_calculateComponent(vSaleFk, NULL); CALL itemShelvingSale_addBySale(vSaleFk, vSectorFk); - + IF NOT EXISTS (SELECT TRUE FROM itemShelvingSale WHERE saleFk = vSaleFk LIMIT 1) THEN SET vHasThrow = TRUE; END IF; @@ -78,13 +78,13 @@ BEGIN IF vHasThrow THEN CALL util.throw("There is no available for the selected item"); END IF; - + IF vSaleGroupFk THEN INSERT INTO saleGroupDetail SET saleFk = vSaleFk, saleGroupFk = vSaleGroupFk; END IF; - + COMMIT; END$$ DELIMITER ; diff --git a/db/routines/vn/procedures/itemShelvingSale_addBySale.sql b/db/routines/vn/procedures/itemShelvingSale_addBySale.sql index 6625e89b8..06736732a 100644 --- a/db/routines/vn/procedures/itemShelvingSale_addBySale.sql +++ b/db/routines/vn/procedures/itemShelvingSale_addBySale.sql @@ -18,8 +18,9 @@ proc: BEGIN DECLARE vReservedQuantity INT; DECLARE vOutStanding INT; DECLARE vUserFk INT; - DECLARE vTotalReservedQuantity INT; + DECLARE vTotalReservedQuantity INT; DECLARE vSaleQuantity INT; + DECLARE vIsRequiredTx BOOL DEFAULT NOT @@in_transaction; DECLARE vItemShelvingAvailable CURSOR FOR SELECT ish.id itemShelvingFk, @@ -29,7 +30,7 @@ proc: BEGIN JOIN shelving sh ON sh.code = ish.shelvingFk JOIN parking p ON p.id = sh.parkingFk JOIN sector sc ON sc.id = p.sectorFk - JOIN productionConfig pc + JOIN productionConfig pc WHERE s.id = vSaleFk AND NOT sc.isHideForPickers AND (sc.id = vSectorFk OR vSectorFk IS NULL) @@ -44,15 +45,15 @@ proc: BEGIN DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN - ROLLBACK; + CALL util.tx_rollback(vIsRequiredTx); RESIGNAL; END; - - START TRANSACTION; - + + CALL util.tx_start(vIsRequiredTx); + SELECT id INTO vSaleFk FROM sale - WHERE id = vSaleFk + WHERE id = vSaleFk FOR UPDATE; SELECT MAX(p.pickingOrder), s.quantity - SUM(IFNULL(iss.quantity, 0)), s.quantity @@ -65,7 +66,7 @@ proc: BEGIN WHERE s.id = vSaleFk; IF vOutStanding <= 0 THEN - COMMIT; + CALL util.tx_commit(vIsRequiredTx); LEAVE proc; END IF; @@ -85,7 +86,7 @@ proc: BEGIN IF vTotalReservedQuantity <> vSaleQuantity THEN CALL util.debugAdd('itemShelvingSale_addBySale', CONCAT(vSaleFk, ' - ', vSaleQuantity,' - ', vTotalReservedQuantity,'-', vOutStanding,'-', account.myUser_getId())); - + UPDATE sale SET quantity = vTotalReservedQuantity WHERE id = vSaleFk; @@ -93,7 +94,7 @@ proc: BEGIN LEAVE l; END IF; - SELECT id INTO vItemShelvingFk + SELECT id INTO vItemShelvingFk FROM itemShelving WHERE id = vItemShelvingFk FOR UPDATE; @@ -102,19 +103,19 @@ proc: BEGIN SET vOutStanding = vOutStanding - vReservedQuantity; IF vReservedQuantity > 0 THEN - CALL util.debugAdd('itemShelvingSale_addBySale_reservedQuantity', - CONCAT(vSaleFk, ' - ', vReservedQuantity, ' - ', vOutStanding, account.myUser_getId())); - INSERT INTO itemShelvingSale( - itemShelvingFk, - saleFk, - quantity, - userFk, - isPicked) - SELECT vItemShelvingFk, - vSaleFk, - vReservedQuantity, - vUserFk, - FALSE; + CALL util.debugAdd('itemShelvingSale_addBySale_reservedQuantity', + CONCAT(vSaleFk, ' - ', vReservedQuantity, ' - ', vOutStanding, account.myUser_getId())); + INSERT INTO itemShelvingSale( + itemShelvingFk, + saleFk, + quantity, + userFk, + isPicked) + SELECT vItemShelvingFk, + vSaleFk, + vReservedQuantity, + vUserFk, + FALSE; UPDATE itemShelving SET available = available - vReservedQuantity @@ -123,6 +124,6 @@ proc: BEGIN END IF; END LOOP; CLOSE vItemShelvingAvailable; - COMMIT; + CALL util.tx_commit(vIsRequiredTx); END$$ DELIMITER ; \ No newline at end of file From ee0c0996f6e00507519e35368f279bee4b6b8e95 Mon Sep 17 00:00:00 2001 From: jorgep Date: Tue, 22 Oct 2024 12:16:26 +0200 Subject: [PATCH 126/136] feat: refs #7524 add e2e --- db/dump/fixtures.before.sql | 2 +- .../ticket/specs/getTicketsAdvance.spec.js | 38 +++++++++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/db/dump/fixtures.before.sql b/db/dump/fixtures.before.sql index 5076f9330..a667b6d27 100644 --- a/db/dump/fixtures.before.sql +++ b/db/dump/fixtures.before.sql @@ -403,7 +403,7 @@ INSERT INTO `vn`.`client`(`id`,`name`,`fi`,`socialName`,`contact`,`street`,`city (1112, 'Trash', NULL, 'GARBAGE MAN', 'Unknown name', 'NEW YORK CITY, UNDERGROUND', 'Gotham', 46460, 1111111111, 222222222, 1, NULL, NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1, NULL, 10, 5, util.VN_CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 0, 1, 0, NULL, 1, 0, NULL, 0, 'others','loses'); INSERT INTO `vn`.`client`(`id`, `name`, `fi`, `socialName`, `contact`, `street`, `city`, `postcode`, `isRelevant`, `email`, `iban`,`dueDay`,`accountingAccount`, `isEqualizated`, `provinceFk`, `hasToInvoice`, `credit`, `countryFk`, `isActive`, `gestdocFk`, `quality`, `payMethodFk`,`created`, `isTaxDataChecked`) - SELECT id, name, CONCAT(RPAD(CONCAT(id,9),8,id),'A'), UPPER(CONCAT(name, 'Social')), CONCAT(name, 'Contact'), CONCAT(name, 'Street'), 'GOTHAM', 46460, 1, CONCAT(name,'@mydomain.com'), NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1,NULL, 10, 5, util.VN_CURDATE(), 1 + SELECT id, name, CONCAT(RPAD(CONCAT(id,9),8,id),'A'), UPPER(CONCAT(name, 'Social')), CONCAT(name, 'Contact'), UPPER(CONCAT(name, 'Street')), 'GOTHAM', 46460, 1, CONCAT(name,'@mydomain.com'), NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1,NULL, 10, 5, util.VN_CURDATE(), 1 FROM `account`.`role` `r` WHERE `r`.`hasLogin` = 1; diff --git a/modules/ticket/back/methods/ticket/specs/getTicketsAdvance.spec.js b/modules/ticket/back/methods/ticket/specs/getTicketsAdvance.spec.js index 488cd1fc2..a941013cd 100644 --- a/modules/ticket/back/methods/ticket/specs/getTicketsAdvance.spec.js +++ b/modules/ticket/back/methods/ticket/specs/getTicketsAdvance.spec.js @@ -6,6 +6,9 @@ describe('TicketFuture getTicketsAdvance()', () => { today.setHours(0, 0, 0, 0); let tomorrow = Date.vnNew(); tomorrow.setDate(today.getDate() + 1); + const salesDeptId = 43; + const spain1DeptId = 95; + beforeAll.mockLoopBackContext(); it('should return the tickets passing the required data', async() => { const tx = await models.Ticket.beginTransaction({}); @@ -129,4 +132,39 @@ describe('TicketFuture getTicketsAdvance()', () => { throw e; } }); + + it('should return the tickets matching the right department', async() => { + const tx = await models.Ticket.beginTransaction({}); + + try { + const options = {transaction: tx}; + ctx.args = { + dateFuture: tomorrow, + dateToAdvance: today, + warehouseFk: 1, + }; + + await models.Ticket.updateAll({id: {inq: [12, 31]}}, {clientFk: 1}, options); + const client = await models.Client.findById(1, null, options); + await client.updateAttribute('salesPersonFk', 1, options); + const business = await models.Business.findById(1, null, options); + await business.updateAttributes({departmentFk: spain1DeptId}, options); + + const saleTickets = await models.Ticket.getTicketsAdvance(ctx, options); + const filteredSaleTickets = await models.Ticket.getTicketsAdvance( + {args: {...ctx.args, departmentFk: spain1DeptId}}, + options); + + expect(saleTickets.length).toBeGreaterThan(filteredSaleTickets.length); + expect(saleTickets.some(ticket => ticket.departmentFk === salesDeptId)).toBeTrue(); + expect(saleTickets.some(ticket => ticket.departmentFk === spain1DeptId)).toBeTrue(); + + expect(filteredSaleTickets.some(ticket => ticket.departmentFk === salesDeptId)).toBeFalse(); + expect(filteredSaleTickets.some(ticket => ticket.departmentFk === spain1DeptId)).toBeTrue(); + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); }); From 1c5e4f40cec2c18cbf28e266bc37cd2e50fdf225 Mon Sep 17 00:00:00 2001 From: jorgep Date: Tue, 22 Oct 2024 12:39:51 +0200 Subject: [PATCH 127/136] feat: refs #8083 add prop --- modules/ticket/back/models/expedition.json | 117 +++++++++++---------- 1 file changed, 60 insertions(+), 57 deletions(-) diff --git a/modules/ticket/back/models/expedition.json b/modules/ticket/back/models/expedition.json index 2dcca1e87..f3f912ec3 100644 --- a/modules/ticket/back/models/expedition.json +++ b/modules/ticket/back/models/expedition.json @@ -1,63 +1,66 @@ { - "name": "Expedition", - "base": "VnModel", - "mixins": { - "Loggable": true + "name": "Expedition", + "base": "VnModel", + "mixins": { + "Loggable": true + }, + "options": { + "mysql": { + "table": "expedition" + } + }, + "properties": { + "id": { + "id": true, + "type": "number", + "description": "Identifier" }, - "options": { - "mysql": { - "table": "expedition" - } + "freightItemFk": { + "type": "number" }, - "properties": { - "id": { - "id": true, - "type": "number", - "description": "Identifier" - }, - "freightItemFk": { - "type": "number" - }, - "created": { - "type": "date" - }, - "counter": { - "type": "number" - }, - "externalId": { - "type": "string" - } + "created": { + "type": "date" }, - "relations": { - "ticket": { - "type": "belongsTo", - "model": "Ticket", - "foreignKey": "ticketFk" - }, - "agencyMode": { - "type": "belongsTo", - "model": "AgencyMode", - "foreignKey": "agencyModeFk" - }, - "worker": { - "type": "belongsTo", - "model": "Worker", - "foreignKey": "workerFk" - }, - "packages": { - "type": "hasMany", - "model": "TicketPackaging", - "foreignKey": "ticketFk" - }, - "freightItem": { - "type": "belongsTo", - "model": "Item", - "foreignKey": "freightItemFk" - }, - "packaging": { - "type": "belongsTo", - "model": "Package", - "foreignKey": "packagingFk" - } + "counter": { + "type": "number" + }, + "externalId": { + "type": "string" + }, + "stateTypeFk": { + "type": "number" + } + }, + "relations": { + "ticket": { + "type": "belongsTo", + "model": "Ticket", + "foreignKey": "ticketFk" + }, + "agencyMode": { + "type": "belongsTo", + "model": "AgencyMode", + "foreignKey": "agencyModeFk" + }, + "worker": { + "type": "belongsTo", + "model": "Worker", + "foreignKey": "workerFk" + }, + "packages": { + "type": "hasMany", + "model": "TicketPackaging", + "foreignKey": "ticketFk" + }, + "freightItem": { + "type": "belongsTo", + "model": "Item", + "foreignKey": "freightItemFk" + }, + "packaging": { + "type": "belongsTo", + "model": "Package", + "foreignKey": "packagingFk" } } +} \ No newline at end of file From 1afb33c3064739c0a032e7a7b09f581b7b20e602 Mon Sep 17 00:00:00 2001 From: guillermo Date: Tue, 22 Oct 2024 15:00:16 +0200 Subject: [PATCH 128/136] feat: refs #8119 Requested changes --- ...nQuantity_add.sql => itemCampaign_add.sql} | 4 +- .../procedures/itemCampaignQuantity_add.sql | 86 ------------------- .../vn/procedures/itemCampaign_add.sql | 58 +++++++++++++ .../11308-redCymbidium/00-firstScript.sql | 26 +++--- 4 files changed, 72 insertions(+), 102 deletions(-) rename db/routines/vn/events/{itemCampaignQuantity_add.sql => itemCampaign_add.sql} (72%) delete mode 100644 db/routines/vn/procedures/itemCampaignQuantity_add.sql create mode 100644 db/routines/vn/procedures/itemCampaign_add.sql diff --git a/db/routines/vn/events/itemCampaignQuantity_add.sql b/db/routines/vn/events/itemCampaign_add.sql similarity index 72% rename from db/routines/vn/events/itemCampaignQuantity_add.sql rename to db/routines/vn/events/itemCampaign_add.sql index 4deb2d556..efb2aeb11 100644 --- a/db/routines/vn/events/itemCampaignQuantity_add.sql +++ b/db/routines/vn/events/itemCampaign_add.sql @@ -1,8 +1,8 @@ DELIMITER $$ -CREATE OR REPLACE DEFINER=`vn`@`localhost` EVENT `vn`.`itemCampaignQuantity_add` +CREATE OR REPLACE DEFINER=`vn`@`localhost` EVENT `vn`.`itemCampaig_add` ON SCHEDULE EVERY 1 DAY STARTS '2024-10-18 03:00:00.000' ON COMPLETION PRESERVE ENABLE -DO CALL itemCampaignQuantity_add(NULL, NULL, NULL)$$ +DO CALL itemCampaign_add()$$ DELIMITER ; diff --git a/db/routines/vn/procedures/itemCampaignQuantity_add.sql b/db/routines/vn/procedures/itemCampaignQuantity_add.sql deleted file mode 100644 index 6edb97c08..000000000 --- a/db/routines/vn/procedures/itemCampaignQuantity_add.sql +++ /dev/null @@ -1,86 +0,0 @@ -DELIMITER $$ -CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`itemCampaignQuantity_add`( - vDateFrom DATE, - vDateTo DATE, - vCampaign VARCHAR(100) -) -proc: BEGIN -/** - * Añade registros a tabla itemCampaignQuantity. - * - * @param vDateFrom Fecha desde - * @param vDateTo Fecha hasta - * @param vCampaign Código de la campaña - */ - DECLARE vCurdate DATE; - DECLARE vYesterday DATE; - DECLARE vDefaultCampaign VARCHAR(100); - DECLARE vPreviousDaysToInsert INT; - DECLARE vDateSumFrom DATE; - DECLARE vDateSumTo DATE; - DECLARE vScopeDays INT; - - SET vCurdate = util.VN_CURDATE(); - SET vYesterday = util.yesterday(); - - IF vDateFrom IS NULL THEN - SET vDateFrom = vYesterday; - END IF; - - IF vDateTo IS NULL THEN - SET vDateTo = vYesterday; - END IF; - - IF vDateFrom > vDateTo THEN - CALL util.throw('Start date cannot be later than end date'); - END IF; - - SELECT defaultCampaign, previousDaysToInsert - INTO vDefaultCampaign, vPreviousDaysToInsert - FROM itemCampaignQuantityConfig; - - IF vCampaign IS NULL THEN - SET vCampaign = vDefaultCampaign; - END IF; - - IF vCampaign IS NULL OR vPreviousDaysToInsert IS NULL THEN - CALL util.throw('Missing values in the configuration table'); - END IF; - - SELECT dated, scopeDays INTO vDateSumTo, vScopeDays - FROM campaign - WHERE dated > vCurdate - AND code = vCampaign - ORDER BY dated - LIMIT 1; - - IF vDateSumTo IS NULL OR vScopeDays IS NULL THEN - CALL util.throw('Missing data in campaign table'); - END IF; - - IF NOT vCurdate BETWEEN vDateSumTo - INTERVAL vPreviousDaysToInsert DAY - AND vDateSumTo THEN - LEAVE proc; - END IF; - - SET vDateSumFrom = vDateSumTo - INTERVAL vScopeDays DAY; - - REPLACE itemCampaignQuantity(dated, itemFk, quantity, total, campaign) - SELECT DATE(s.created), - s.itemFk, - SUM(CASE WHEN t.shipped BETWEEN vDateSumFrom AND vDateSumTo - THEN s.quantity - END) quantity, - SUM(CASE WHEN t.shipped BETWEEN vDateSumFrom AND vDateSumTo - THEN s.total - END) total, - vCampaign - FROM sale s - JOIN ticket t ON t.id = s.ticketFk - JOIN client c ON c.id = t.clientFk - WHERE s.created BETWEEN vDateFrom AND util.dayEnd(vDateTo) - AND c.businessTypeFk <> 'worker' - GROUP BY DATE(s.created), s.itemFk - HAVING quantity; -END$$ -DELIMITER ; diff --git a/db/routines/vn/procedures/itemCampaign_add.sql b/db/routines/vn/procedures/itemCampaign_add.sql new file mode 100644 index 000000000..1e10bc619 --- /dev/null +++ b/db/routines/vn/procedures/itemCampaign_add.sql @@ -0,0 +1,58 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`itemCampaign_add`() +proc: BEGIN +/** + * Añade registros a tabla itemCampaign. + * + * @param vDateFrom Fecha desde + * @param vDateTo Fecha hasta + * @param vCampaign Código de la campaña + */ + DECLARE vCurdate DATE; + DECLARE vYesterday DATE; + DECLARE vCampaign VARCHAR(100); + DECLARE vPreviousDays INT; + DECLARE vDateSumFrom DATE; + DECLARE vDateSumTo DATE; + DECLARE vScopeDays INT; + + SET vCurdate = util.VN_CURDATE(); + + SELECT dated, code, scopeDays, previousDays + INTO vDateSumTo, vCampaign, vScopeDays, vPreviousDays + FROM campaign + WHERE dated > vCurdate + ORDER BY dated + LIMIT 1; + + IF vCampaign IS NULL THEN + CALL util.throw('Missing data in campaign table'); + END IF; + + IF NOT vCurdate BETWEEN vDateSumTo - INTERVAL vPreviousDays DAY + AND vDateSumTo THEN + LEAVE proc; + END IF; + + SET vDateSumFrom = vDateSumTo - INTERVAL vScopeDays DAY; + SET vYesterday = util.yesterday(); + + REPLACE itemCampaign(dated, itemFk, quantity, total, campaign) + SELECT DATE(s.created), + s.itemFk, + SUM(CASE WHEN t.shipped BETWEEN vDateSumFrom AND vDateSumTo + THEN s.quantity + END) quantity, + SUM(CASE WHEN t.shipped BETWEEN vDateSumFrom AND vDateSumTo + THEN (s.quantity * s.price) * (100 - s.discount) / 100 + END) total, + vCampaign + FROM sale s + JOIN ticket t ON t.id = s.ticketFk + JOIN client c ON c.id = t.clientFk + WHERE s.created BETWEEN vYesterday AND util.dayEnd(vYesterday) + AND c.typeFk = 'normal' + GROUP BY DATE(s.created), s.itemFk + HAVING quantity; +END$$ +DELIMITER ; diff --git a/db/versions/11308-redCymbidium/00-firstScript.sql b/db/versions/11308-redCymbidium/00-firstScript.sql index 14fad3636..fe76cb600 100644 --- a/db/versions/11308-redCymbidium/00-firstScript.sql +++ b/db/versions/11308-redCymbidium/00-firstScript.sql @@ -1,27 +1,25 @@ -CREATE TABLE IF NOT EXISTS `vn`.`itemCampaignQuantity` ( +CREATE TABLE IF NOT EXISTS `vn`.`itemCampaign` ( `id` int(11) NOT NULL PRIMARY KEY AUTO_INCREMENT, dated date NOT NULL, itemFk int(11) NOT NULL, quantity decimal(10,2) NOT NULL, total decimal(10,2) NOT NULL, campaign varchar(100) NOT NULL, - UNIQUE KEY `itemCampaignQuantity_UNIQUE` (`dated`,`itemFk`), - CONSTRAINT itemCampaignQuantity_item_FK FOREIGN KEY (itemFk) REFERENCES vn.item(id) ON DELETE RESTRICT ON UPDATE CASCADE + UNIQUE KEY `itemCampaign_UNIQUE` (`dated`,`itemFk`), + CONSTRAINT itemCampaign_item_FK FOREIGN KEY (itemFk) REFERENCES vn.item(id) ON DELETE RESTRICT ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Tallos confirmados por día en los días de más producción de una campaña. La tabla está pensada para que sea una foto.'; -CREATE TABLE IF NOT EXISTS `vn`.`itemCampaignQuantityConfig` ( - id int(10) unsigned NOT NULL PRIMARY KEY, - defaultCampaign varchar(100) NOT NULL COMMENT 'Campaña por defecto si se le pasa NULL', - previousDaysToInsert int(10) unsigned NOT NULL COMMENT 'Días anteriores a la fecha de fin de campaña para insertar', - CONSTRAINT `itemCampaignQuantityConfig_check` CHECK (`id` = 1) -) -ENGINE=InnoDB -DEFAULT CHARSET=utf8mb3 -COLLATE=utf8mb3_unicode_ci; +ALTER TABLE vn.campaign + ADD previousDays int(10) unsigned DEFAULT 30 NOT NULL COMMENT 'Días previos para calcular e insertar en la tabla itemCampaign'; -INSERT IGNORE INTO `vn`.`itemCampaignQuantityConfig` (id, defaultCampaign, previousDaysToInsert) - VALUES (1, 'allSaints', 90); +UPDATE vn.campaign + SET previousDays = 90 + WHERE code = 'allSaints'; + +UPDATE vn.campaign + SET previousDays = 60 + WHERE code IN ('valentinesDay', 'mothersDay'); From fe3e7342bcea4693c40146076031b939a432f873 Mon Sep 17 00:00:00 2001 From: guillermo Date: Wed, 23 Oct 2024 07:14:07 +0200 Subject: [PATCH 129/136] fix: refs #7935 version --- .../{00-firstScript copy.sql => 00-firstScript2.sql} | 0 .../{00-firstScript copy 2.sql => 00-firstScript3.sql} | 0 .../{00-firstScript copy 3.sql => 00-firstScript4.sql} | 0 .../{00-firstScript copy 4.sql => 00-firstScript5.sql} | 0 .../{00-firstScript copy 5.sql => 00-firstScript6.sql} | 0 .../{00-firstScript copy 6.sql => 00-firstScript7.sql} | 0 6 files changed, 0 insertions(+), 0 deletions(-) rename db/versions/11274-redGerbera/{00-firstScript copy.sql => 00-firstScript2.sql} (100%) rename db/versions/11274-redGerbera/{00-firstScript copy 2.sql => 00-firstScript3.sql} (100%) rename db/versions/11274-redGerbera/{00-firstScript copy 3.sql => 00-firstScript4.sql} (100%) rename db/versions/11274-redGerbera/{00-firstScript copy 4.sql => 00-firstScript5.sql} (100%) rename db/versions/11274-redGerbera/{00-firstScript copy 5.sql => 00-firstScript6.sql} (100%) rename db/versions/11274-redGerbera/{00-firstScript copy 6.sql => 00-firstScript7.sql} (100%) diff --git a/db/versions/11274-redGerbera/00-firstScript copy.sql b/db/versions/11274-redGerbera/00-firstScript2.sql similarity index 100% rename from db/versions/11274-redGerbera/00-firstScript copy.sql rename to db/versions/11274-redGerbera/00-firstScript2.sql diff --git a/db/versions/11274-redGerbera/00-firstScript copy 2.sql b/db/versions/11274-redGerbera/00-firstScript3.sql similarity index 100% rename from db/versions/11274-redGerbera/00-firstScript copy 2.sql rename to db/versions/11274-redGerbera/00-firstScript3.sql diff --git a/db/versions/11274-redGerbera/00-firstScript copy 3.sql b/db/versions/11274-redGerbera/00-firstScript4.sql similarity index 100% rename from db/versions/11274-redGerbera/00-firstScript copy 3.sql rename to db/versions/11274-redGerbera/00-firstScript4.sql diff --git a/db/versions/11274-redGerbera/00-firstScript copy 4.sql b/db/versions/11274-redGerbera/00-firstScript5.sql similarity index 100% rename from db/versions/11274-redGerbera/00-firstScript copy 4.sql rename to db/versions/11274-redGerbera/00-firstScript5.sql diff --git a/db/versions/11274-redGerbera/00-firstScript copy 5.sql b/db/versions/11274-redGerbera/00-firstScript6.sql similarity index 100% rename from db/versions/11274-redGerbera/00-firstScript copy 5.sql rename to db/versions/11274-redGerbera/00-firstScript6.sql diff --git a/db/versions/11274-redGerbera/00-firstScript copy 6.sql b/db/versions/11274-redGerbera/00-firstScript7.sql similarity index 100% rename from db/versions/11274-redGerbera/00-firstScript copy 6.sql rename to db/versions/11274-redGerbera/00-firstScript7.sql From 62f9f31279f829b204e55e4c52b2370c3a0b5244 Mon Sep 17 00:00:00 2001 From: jgallego Date: Wed, 23 Oct 2024 07:44:41 +0200 Subject: [PATCH 130/136] feat: refs #7943 usa back con permisos --- .../item/front/item-type/basic-data/index.html | 16 ++++++++-------- modules/item/front/item-type/create/index.html | 14 +++++++------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/modules/item/front/item-type/basic-data/index.html b/modules/item/front/item-type/basic-data/index.html index 1417a05ab..c3f7a57f1 100644 --- a/modules/item/front/item-type/basic-data/index.html +++ b/modules/item/front/item-type/basic-data/index.html @@ -11,26 +11,26 @@ - \ No newline at end of file + diff --git a/modules/item/front/item-type/create/index.html b/modules/item/front/item-type/create/index.html index 44cb5183d..4a199a1b1 100644 --- a/modules/item/front/item-type/create/index.html +++ b/modules/item/front/item-type/create/index.html @@ -12,26 +12,26 @@ Date: Wed, 23 Oct 2024 08:23:28 +0200 Subject: [PATCH 131/136] 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 132/136] 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 133/136] 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 134/136] 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 3da08e3a23292353eca229b7c140898bec852cf3 Mon Sep 17 00:00:00 2001 From: sergiodt Date: Wed, 23 Oct 2024 11:33:45 +0200 Subject: [PATCH 135/136] 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 136/136] 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