From edde5819e3b5c2a204c9c75a2622eec6ab9cd1a3 Mon Sep 17 00:00:00 2001 From: alexm Date: Wed, 10 Jan 2024 15:39:35 +0100 Subject: [PATCH] =?UTF-8?q?refs=20#6660=20feat:=20update=20mariadb=20versi?= =?UTF-8?q?on=2010.7.7=E2=86=9210.11.6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- db/Dockerfile | 2 +- .../240401/00-fixInvoiceOutBeforeInsert.sql | 58 +++++++++++++++++++ .../methods/worker-time-control/getClockIn.js | 2 +- 3 files changed, 60 insertions(+), 2 deletions(-) create mode 100644 db/changes/240401/00-fixInvoiceOutBeforeInsert.sql diff --git a/db/Dockerfile b/db/Dockerfile index 8eeed35e5..0020e8950 100644 --- a/db/Dockerfile +++ b/db/Dockerfile @@ -1,4 +1,4 @@ -FROM mariadb:10.7.7 +FROM mariadb:10.11.6 ENV MYSQL_ROOT_PASSWORD root ENV TZ Europe/Madrid diff --git a/db/changes/240401/00-fixInvoiceOutBeforeInsert.sql b/db/changes/240401/00-fixInvoiceOutBeforeInsert.sql new file mode 100644 index 000000000..10e8d6356 --- /dev/null +++ b/db/changes/240401/00-fixInvoiceOutBeforeInsert.sql @@ -0,0 +1,58 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`invoiceOut_beforeInsert` + BEFORE INSERT ON `invoiceOut` + FOR EACH ROW +BEGIN +/** + * Reference format: + * - 0: Serial [A-Z] + * - 1: Sage company id + * - 2-3: Last two digits of issued year + * - 4-8: Autoincrement identifier + **/ + DECLARE vNewRef INT DEFAULT 0; + DECLARE vCompanyCode INT; + DECLARE vLastRef VARCHAR(255); + DECLARE vRefStr VARCHAR(255); + DECLARE vRefLen INT DEFAULT 5; + DECLARE vYearLen INT DEFAULT 2; + DECLARE vPrefixLen INT; + + SELECT companyCode INTO vCompanyCode + FROM company + WHERE id = NEW.companyFk; + + IF vCompanyCode IS NULL THEN + CALL util.throw('sageCompanyNotDefined'); + END IF; + + SELECT MAX(i.ref) INTO vLastRef + FROM invoiceOut i + WHERE i.serial = NEW.serial + AND i.issued BETWEEN util.firstDayOfYear(NEW.issued) AND util.dayEnd(util.lastDayOfYear(NEW.issued)) + AND i.companyFk = NEW.companyFk; + + IF vLastRef IS NOT NULL THEN + SET vPrefixLen = LENGTH(NEW.serial) + LENGTH(vCompanyCode) + vYearLen; + SET vRefLen = LENGTH(vLastRef) - vPrefixLen; + SET vRefStr = SUBSTRING(vLastRef, vPrefixLen + 1); + SET vNewRef = vRefStr + 1; + + IF LENGTH(vNewRef) > vRefLen THEN + CALL util.throw('refLenExceeded'); + END IF; + + SET NEW.ref = CONCAT( + SUBSTRING(vLastRef, 1, vPrefixLen), + LPAD(vNewRef, LENGTH(vRefStr), '0') + ); + ELSE + SET NEW.ref = CONCAT( + NEW.serial, + vCompanyCode, + RIGHT(YEAR(NEW.issued), vYearLen), + LPAD(1, vRefLen, '0') + ); + END IF; +END$$ +DELIMITER ; diff --git a/modules/worker/back/methods/worker-time-control/getClockIn.js b/modules/worker/back/methods/worker-time-control/getClockIn.js index 470700643..458cadafb 100644 --- a/modules/worker/back/methods/worker-time-control/getClockIn.js +++ b/modules/worker/back/methods/worker-time-control/getClockIn.js @@ -5,7 +5,7 @@ module.exports = Self => { accepts: [ { arg: 'workerFk', - type: 'int', + type: 'number', required: true, },