From ff459ea3be23e076474551f90d18a0fdaf158e76 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Andr=C3=A9s?= Date: Wed, 13 Mar 2024 12:18:43 +0100 Subject: [PATCH 01/10] fix: closeTicket idem salix refs #6549 --- db/routines/vn/procedures/invoiceOut_new.sql | 9 ++- .../10949-limeLaurel/00-firstScript.sql | 5 ++ .../ticket/back/methods/ticket/closeAll.js | 67 +++++++++++++++++++ .../assets/css/import.js | 11 +++ .../invoice-ticket-closure.html | 13 ++++ .../invoice-ticket-closure.js | 19 ++++++ .../invoice-ticket-closure/locale/en.yml | 5 ++ .../invoice-ticket-closure/locale/es.yml | 4 ++ 8 files changed, 131 insertions(+), 2 deletions(-) create mode 100644 db/versions/10949-limeLaurel/00-firstScript.sql create mode 100644 print/templates/email/invoice-ticket-closure/assets/css/import.js create mode 100644 print/templates/email/invoice-ticket-closure/invoice-ticket-closure.html create mode 100644 print/templates/email/invoice-ticket-closure/invoice-ticket-closure.js create mode 100644 print/templates/email/invoice-ticket-closure/locale/en.yml create mode 100644 print/templates/email/invoice-ticket-closure/locale/es.yml diff --git a/db/routines/vn/procedures/invoiceOut_new.sql b/db/routines/vn/procedures/invoiceOut_new.sql index 8c35ce75f..1b486df86 100644 --- a/db/routines/vn/procedures/invoiceOut_new.sql +++ b/db/routines/vn/procedures/invoiceOut_new.sql @@ -68,16 +68,21 @@ BEGIN DELETE ti.* FROM tmp.ticketToInvoice ti JOIN ticket t ON t.id = ti.id + LEFT JOIN address a ON a.id = t.addressFk JOIN sale s ON s.ticketFk = t.id JOIN item i ON i.id = s.itemFk JOIN supplier su ON su.id = t.companyFk JOIN client c ON c.id = t.clientFk - LEFT JOIN itemTaxCountry itc ON itc.itemFk = i.id AND itc.countryFk = su.countryFk + LEFT JOIN itemTaxCountry itc ON itc.itemFk = i.id + AND itc.countryFk = su.countryFk WHERE (YEAR(t.shipped) < 2001 AND t.isDeleted) OR c.isTaxDataChecked = FALSE OR t.isDeleted OR c.hasToInvoice = FALSE - OR itc.id IS NULL; + OR itc.id IS NULL + OR a.id IS NULL + OR (vTaxArea = 'WORLD' + AND (a.customsAgentFk IS NULL OR a.incotermsFk IS NULL)); SELECT SUM(s.quantity * s.price * (100 - s.discount)/100) <> 0 INTO vIsAnySaleToInvoice diff --git a/db/versions/10949-limeLaurel/00-firstScript.sql b/db/versions/10949-limeLaurel/00-firstScript.sql new file mode 100644 index 000000000..0e2fdaf0c --- /dev/null +++ b/db/versions/10949-limeLaurel/00-firstScript.sql @@ -0,0 +1,5 @@ +INSERT INTO util.notification (id, name, description) + SELECT MAX(id) + 1, + 'invoice-ticket-closure', + 'Tickets not invoiced during the nightly closure ticket process' + FROM util.notification; diff --git a/modules/ticket/back/methods/ticket/closeAll.js b/modules/ticket/back/methods/ticket/closeAll.js index 46c45aa92..829889e9c 100644 --- a/modules/ticket/back/methods/ticket/closeAll.js +++ b/modules/ticket/back/methods/ticket/closeAll.js @@ -58,6 +58,73 @@ module.exports = Self => { GROUP BY t.id `, [toDate, toDate]); + await Self.rawSql(` + WITH ticketNotInvoiceable AS( + SELECT JSON_OBJECT( + 'tickets', + JSON_ARRAYAGG( + JSON_OBJECT( + 'ticketId', ticketFk, + 'reason', + LEFT(reason,LENGTH(reason) - 2) + ) + ))errors + FROM ( + SELECT ticketFk, + CONCAT_WS('', + IF(hasErrorToInvoice, 'Facturar, ', ''), + IF(hasErrorTaxDataChecked, 'Datos comprobados, ', ''), + IF(hasErrorDeleted, 'Eliminado, ', ''), + IF(hasErrorItemTaxCountry, 'Impuesto no informado, ', ''), + IF(hasErrorAddress, 'Sin dirección, ', ''), + IF(hasErrorInfoTaxAreaWorld, 'Datos exportaciones, ', '')) reason + FROM ( + SELECT t.id ticketFk, + SUM(NOT c.hasToInvoice) hasErrorToInvoice, + SUM(NOT c.isTaxDataChecked) hasErrorTaxDataChecked, + SUM(t.isDeleted) hasErrorDeleted, + SUM(itc.id IS NULL) hasErrorItemTaxCountry, + SUM(a.id IS NULL) hasErrorAddress, + SUM(ios.code IS NOT NULL + AND(ad.customsAgentFk IS NULL + OR ad.incotermsFk IS NULL)) hasErrorInfoTaxAreaWorld + FROM ticket t + LEFT JOIN address ad ON ad.id = t.addressFk + JOIN sale s ON s.ticketFk = t.id + JOIN item i ON i.id = s.itemFk + JOIN supplier su ON su.id = t.companyFk + 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 + 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 + LEFT JOIN itemTaxCountry itc ON itc.itemFk = i.id + AND itc.countryFk = su.countryFk + LEFT JOIN vn.invoiceOutSerial ios ON ios.taxAreaFk = 'WORLD' + AND ios.code = invoiceSerial(t.clientFk, t.companyFk, 'M') + WHERE (al.code = 'PACKED' + OR (am.code = 'refund' AND al.code != 'delivered')) + AND DATE(t.shipped) BETWEEN DATE_ADD(?, INTERVAL -2 DAY) AND util.dayEnd(?) + AND t.refFk IS NULL + AND IFNULL(a.hasDailyInvoice, co.hasDailyInvoice) + GROUP BY ticketFk + HAVING hasErrorToInvoice + OR NOT hasErrorTaxDataChecked + OR hasErrorDeleted + OR hasErrorItemTaxCountry + OR hasErrorAddress + OR hasErrorInfoTaxAreaWorld + )sub + )sub2 + ) SELECT IF(errors = '{"tickets": null}', + 'No errors', + util.notification_send('invoice-ticket-closure', errors, NULL)) + FROM ticketNotInvoiceable`, [toDate, toDate]); + await closure(ctx, Self, tickets); await Self.rawSql(` diff --git a/print/templates/email/invoice-ticket-closure/assets/css/import.js b/print/templates/email/invoice-ticket-closure/assets/css/import.js new file mode 100644 index 000000000..4b4bb7086 --- /dev/null +++ b/print/templates/email/invoice-ticket-closure/assets/css/import.js @@ -0,0 +1,11 @@ +const Stylesheet = require(`vn-print/core/stylesheet`); + +const path = require('path'); +const vnPrintPath = path.resolve('print'); + +module.exports = new Stylesheet([ + `${vnPrintPath}/common/css/spacing.css`, + `${vnPrintPath}/common/css/misc.css`, + `${vnPrintPath}/common/css/layout.css`, + `${vnPrintPath}/common/css/email.css`]) + .mergeStyles(); diff --git a/print/templates/email/invoice-ticket-closure/invoice-ticket-closure.html b/print/templates/email/invoice-ticket-closure/invoice-ticket-closure.html new file mode 100644 index 000000000..051fa2cf8 --- /dev/null +++ b/print/templates/email/invoice-ticket-closure/invoice-ticket-closure.html @@ -0,0 +1,13 @@ + +
+
+

{{ $t('title') }} {{ $t('total') }}: {{tickets.length}}

+
+
+
+

{{ $t('ticketId') }}: {{ticket.ticketId}}

+

{{ $t('description') }}: {{ticket.description}}

+
+
+
+
\ No newline at end of file diff --git a/print/templates/email/invoice-ticket-closure/invoice-ticket-closure.js b/print/templates/email/invoice-ticket-closure/invoice-ticket-closure.js new file mode 100644 index 000000000..6d12aa247 --- /dev/null +++ b/print/templates/email/invoice-ticket-closure/invoice-ticket-closure.js @@ -0,0 +1,19 @@ +const Component = require(`vn-print/core/component`); +const emailBody = new Component(); + +module.exports = { + name: 'invoice-ticket-closure', + components: { + 'email-body': emailBody.build(), + }, + props: { + ticketId: { + type: Number, + required: true + }, + description: { + type: String, + required: true + } + } +}; diff --git a/print/templates/email/invoice-ticket-closure/locale/en.yml b/print/templates/email/invoice-ticket-closure/locale/en.yml new file mode 100644 index 000000000..70345dc81 --- /dev/null +++ b/print/templates/email/invoice-ticket-closure/locale/en.yml @@ -0,0 +1,5 @@ + +subject: Nightly ticket closing process report +title: Nightly ticket closing process report +description: Description +ticketId: Ticket No \ No newline at end of file diff --git a/print/templates/email/invoice-ticket-closure/locale/es.yml b/print/templates/email/invoice-ticket-closure/locale/es.yml new file mode 100644 index 000000000..e21332f1b --- /dev/null +++ b/print/templates/email/invoice-ticket-closure/locale/es.yml @@ -0,0 +1,4 @@ +subject: Informe proceso de cierre de tickets nocturno +title: Informe proceso de cierre de tickets nocturno +description: Descripción +ticketId: Ticket nº \ No newline at end of file From 77d1a38a87eac61c3ce19fc217b3aaf2aaa29636 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Andr=C3=A9s?= Date: Wed, 13 Mar 2024 18:51:11 +0100 Subject: [PATCH 02/10] fix: closeTicket idem salix refs #6549 --- db/versions/10949-limeLaurel/00-firstScript.sql | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/db/versions/10949-limeLaurel/00-firstScript.sql b/db/versions/10949-limeLaurel/00-firstScript.sql index 0e2fdaf0c..7b1758285 100644 --- a/db/versions/10949-limeLaurel/00-firstScript.sql +++ b/db/versions/10949-limeLaurel/00-firstScript.sql @@ -3,3 +3,12 @@ INSERT INTO util.notification (id, name, description) 'invoice-ticket-closure', 'Tickets not invoiced during the nightly closure ticket process' FROM util.notification; + +INSERT IGNORE INTO util.notificationAcl (notificationFk, roleFk) + SELECT MAX(id), 108 + FROM util.notification; + +INSERT IGNORE INTO util.notificationSubscription (notificationFk, userFk) + SELECT MAX(id), 108 + FROM util.notification; + \ No newline at end of file From 1315a854a93fc7be7c02c9eab7cf7cca503871d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Andr=C3=A9s?= Date: Mon, 18 Mar 2024 18:15:05 +0100 Subject: [PATCH 03/10] fix: closeTicket idem salix Refs: #6549 --- db/versions/10949-limeLaurel/00-firstScript.sql | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/db/versions/10949-limeLaurel/00-firstScript.sql b/db/versions/10949-limeLaurel/00-firstScript.sql index 7b1758285..ca221501e 100644 --- a/db/versions/10949-limeLaurel/00-firstScript.sql +++ b/db/versions/10949-limeLaurel/00-firstScript.sql @@ -1,14 +1,14 @@ -INSERT INTO util.notification (id, name, description) - SELECT MAX(id) + 1, - 'invoice-ticket-closure', + INSERT INTO util.notification ( name, description) + SELECT 'invoice-ticket-closure', 'Tickets not invoiced during the nightly closure ticket process' FROM util.notification; + +SET @notificationFk =LAST_INSERT_ID(); INSERT IGNORE INTO util.notificationAcl (notificationFk, roleFk) - SELECT MAX(id), 108 + SELECT @notificationFk, 108 FROM util.notification; INSERT IGNORE INTO util.notificationSubscription (notificationFk, userFk) - SELECT MAX(id), 108 - FROM util.notification; - \ No newline at end of file + SELECT @notificationFk, 108 + FROM util.notification; \ No newline at end of file From 75a4d6947fe07eb3a35da93086eb8ba2b1c66fce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Andr=C3=A9s?= Date: Thu, 4 Apr 2024 14:20:55 +0200 Subject: [PATCH 04/10] fix: closeTicket idem salix Refs: #6549 --- .../invoice-ticket-closure/invoice-ticket-closure.html | 4 ++-- .../invoice-ticket-closure/invoice-ticket-closure.js | 10 +++------- .../email/invoice-ticket-closure/locale/en.yml | 3 +-- .../email/invoice-ticket-closure/locale/es.yml | 2 +- 4 files changed, 7 insertions(+), 12 deletions(-) diff --git a/print/templates/email/invoice-ticket-closure/invoice-ticket-closure.html b/print/templates/email/invoice-ticket-closure/invoice-ticket-closure.html index 051fa2cf8..2effa8917 100644 --- a/print/templates/email/invoice-ticket-closure/invoice-ticket-closure.html +++ b/print/templates/email/invoice-ticket-closure/invoice-ticket-closure.html @@ -1,12 +1,12 @@
-

{{ $t('title') }} {{ $t('total') }}: {{tickets.length}}

+

{{ $t('title') }}


{{ $t('ticketId') }}: {{ticket.ticketId}}

-

{{ $t('description') }}: {{ticket.description}}

+

{{ $t('reason') }}: {{ticket.reason}}


diff --git a/print/templates/email/invoice-ticket-closure/invoice-ticket-closure.js b/print/templates/email/invoice-ticket-closure/invoice-ticket-closure.js index 6d12aa247..31690ecbd 100644 --- a/print/templates/email/invoice-ticket-closure/invoice-ticket-closure.js +++ b/print/templates/email/invoice-ticket-closure/invoice-ticket-closure.js @@ -1,5 +1,5 @@ const Component = require(`vn-print/core/component`); -const emailBody = new Component(); +const emailBody = new Component('email-body'); module.exports = { name: 'invoice-ticket-closure', @@ -7,13 +7,9 @@ module.exports = { 'email-body': emailBody.build(), }, props: { - ticketId: { - type: Number, + tickets: { + type: Array, required: true }, - description: { - type: String, - required: true - } } }; diff --git a/print/templates/email/invoice-ticket-closure/locale/en.yml b/print/templates/email/invoice-ticket-closure/locale/en.yml index 70345dc81..844dada7a 100644 --- a/print/templates/email/invoice-ticket-closure/locale/en.yml +++ b/print/templates/email/invoice-ticket-closure/locale/en.yml @@ -1,5 +1,4 @@ - subject: Nightly ticket closing process report title: Nightly ticket closing process report -description: Description +reason: Reason ticketId: Ticket No \ No newline at end of file diff --git a/print/templates/email/invoice-ticket-closure/locale/es.yml b/print/templates/email/invoice-ticket-closure/locale/es.yml index e21332f1b..a8e67f18f 100644 --- a/print/templates/email/invoice-ticket-closure/locale/es.yml +++ b/print/templates/email/invoice-ticket-closure/locale/es.yml @@ -1,4 +1,4 @@ subject: Informe proceso de cierre de tickets nocturno title: Informe proceso de cierre de tickets nocturno -description: Descripción +reason: Motivo ticketId: Ticket nº \ No newline at end of file From 9fcad457a70fb0d127669e49980350e0236395bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Andr=C3=A9s?= Date: Thu, 4 Apr 2024 14:46:51 +0200 Subject: [PATCH 05/10] fix: closeTicket idem salix Refs: #6549 --- .../ticket/back/methods/ticket/closeAll.js | 38 +++++++++---------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/modules/ticket/back/methods/ticket/closeAll.js b/modules/ticket/back/methods/ticket/closeAll.js index 61de1cd04..c14f33346 100644 --- a/modules/ticket/back/methods/ticket/closeAll.js +++ b/modules/ticket/back/methods/ticket/closeAll.js @@ -62,14 +62,15 @@ module.exports = Self => { await Self.rawSql(` WITH ticketNotInvoiceable AS( SELECT JSON_OBJECT( - 'tickets', - JSON_ARRAYAGG( - JSON_OBJECT( - 'ticketId', ticketFk, - 'reason', - LEFT(reason,LENGTH(reason) - 2) + 'tickets', + JSON_ARRAYAGG( + JSON_OBJECT( + 'ticketId', ticketFk, + 'reason', + LEFT(reason,LENGTH(reason) - 2) + ) ) - ))errors + )errors FROM ( SELECT ticketFk, CONCAT_WS('', @@ -87,8 +88,8 @@ module.exports = Self => { SUM(itc.id IS NULL) hasErrorItemTaxCountry, SUM(a.id IS NULL) hasErrorAddress, SUM(ios.code IS NOT NULL - AND(ad.customsAgentFk IS NULL - OR ad.incotermsFk IS NULL)) hasErrorInfoTaxAreaWorld + AND(ad.customsAgentFk IS NULL + OR ad.incotermsFk IS NULL)) hasErrorInfoTaxAreaWorld FROM ticket t LEFT JOIN address ad ON ad.id = t.addressFk JOIN sale s ON s.ticketFk = t.id @@ -107,14 +108,13 @@ module.exports = Self => { AND itc.countryFk = su.countryFk LEFT JOIN vn.invoiceOutSerial ios ON ios.taxAreaFk = 'WORLD' AND ios.code = invoiceSerial(t.clientFk, t.companyFk, 'M') - WHERE (al.code = 'PACKED' - OR (am.code = 'refund' AND al.code != 'delivered')) - AND DATE(t.shipped) BETWEEN DATE_ADD(?, INTERVAL -2 DAY) AND util.dayEnd(?) + WHERE (al.code = 'PACKED' OR (am.code = 'refund' AND al.code <> 'delivered')) + AND DATE(t.shipped) BETWEEN DATE_ADD(?, INTERVAL -2 DAY) AND util.dayEnd(?) AND t.refFk IS NULL AND IFNULL(a.hasDailyInvoice, co.hasDailyInvoice) GROUP BY ticketFk HAVING hasErrorToInvoice - OR NOT hasErrorTaxDataChecked + OR hasErrorTaxDataChecked OR hasErrorDeleted OR hasErrorItemTaxCountry OR hasErrorAddress @@ -130,12 +130,12 @@ module.exports = Self => { await Self.rawSql(` UPDATE ticket t - JOIN ticketState ts ON t.id = ts.ticketFk - 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 zone z ON z.id = t.zoneFk - SET t.routeFk = NULL + JOIN ticketState ts ON t.id = ts.ticketFk + 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 zone z ON z.id = t.zoneFk + SET t.routeFk = NULL WHERE DATE(t.shipped) BETWEEN DATE_ADD(?, INTERVAL -2 DAY) AND util.dayEnd(?) AND al.code NOT IN('DELIVERED','PACKED') From fe0afe30bf91c78a5629fcc071de3fd40c99f73f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Andr=C3=A9s?= Date: Thu, 4 Apr 2024 17:50:39 +0200 Subject: [PATCH 06/10] fix: closeTicket idem salix Refs: #6549 --- .../10949-limeLaurel/00-firstScript.sql | 12 +++++---- .../ticket/back/methods/ticket/closeAll.js | 26 +++++++++---------- .../invoice-ticket-closure/locale/en.yml | 2 +- .../invoice-ticket-closure/locale/es.yml | 2 +- 4 files changed, 21 insertions(+), 21 deletions(-) diff --git a/db/versions/10949-limeLaurel/00-firstScript.sql b/db/versions/10949-limeLaurel/00-firstScript.sql index ca221501e..58d50e125 100644 --- a/db/versions/10949-limeLaurel/00-firstScript.sql +++ b/db/versions/10949-limeLaurel/00-firstScript.sql @@ -6,9 +6,11 @@ SET @notificationFk =LAST_INSERT_ID(); INSERT IGNORE INTO util.notificationAcl (notificationFk, roleFk) - SELECT @notificationFk, 108 - FROM util.notification; - + SELECT @notificationFk,id + FROM account.role + WHERE name ='administrative'; + INSERT IGNORE INTO util.notificationSubscription (notificationFk, userFk) - SELECT @notificationFk, 108 - FROM util.notification; \ No newline at end of file + SELECT @notificationFk, id + FROM account.`user` + WHERE `name` = 'admon'; diff --git a/modules/ticket/back/methods/ticket/closeAll.js b/modules/ticket/back/methods/ticket/closeAll.js index c14f33346..3e35c5ebc 100644 --- a/modules/ticket/back/methods/ticket/closeAll.js +++ b/modules/ticket/back/methods/ticket/closeAll.js @@ -53,8 +53,8 @@ module.exports = Self => { 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' OR (am.code = 'refund' AND al.code != 'delivered')) - AND DATE(t.shipped) BETWEEN DATE_ADD(?, INTERVAL -2 DAY) AND util.dayEnd(?) + 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.refFk IS NULL GROUP BY t.id `, [toDate, toDate]); @@ -66,20 +66,19 @@ module.exports = Self => { JSON_ARRAYAGG( JSON_OBJECT( 'ticketId', ticketFk, - 'reason', - LEFT(reason,LENGTH(reason) - 2) + 'reason', reason ) ) )errors FROM ( SELECT ticketFk, - CONCAT_WS('', - IF(hasErrorToInvoice, 'Facturar, ', ''), - IF(hasErrorTaxDataChecked, 'Datos comprobados, ', ''), - IF(hasErrorDeleted, 'Eliminado, ', ''), - IF(hasErrorItemTaxCountry, 'Impuesto no informado, ', ''), - IF(hasErrorAddress, 'Sin dirección, ', ''), - IF(hasErrorInfoTaxAreaWorld, 'Datos exportaciones, ', '')) reason + CONCAT_WS(', ', + IF(hasErrorToInvoice, 'Facturar', NULL), + IF(hasErrorTaxDataChecked, 'Datos comprobados', NULL), + IF(hasErrorDeleted, 'Eliminado', NULL), + IF(hasErrorItemTaxCountry, 'Impuesto no informado', NULL), + IF(hasErrorAddress, 'Sin dirección', NULL), + IF(hasErrorInfoTaxAreaWorld, 'Datos exportaciones', NULL)) reason FROM ( SELECT t.id ticketFk, SUM(NOT c.hasToInvoice) hasErrorToInvoice, @@ -109,7 +108,7 @@ module.exports = Self => { LEFT JOIN vn.invoiceOutSerial ios ON ios.taxAreaFk = 'WORLD' AND ios.code = invoiceSerial(t.clientFk, t.companyFk, 'M') WHERE (al.code = 'PACKED' OR (am.code = 'refund' AND al.code <> 'delivered')) - AND DATE(t.shipped) BETWEEN DATE_ADD(?, INTERVAL -2 DAY) AND util.dayEnd(?) + AND DATE(t.shipped) BETWEEN ? - INTERVAL 2 DAY AND util.dayEnd(?) AND t.refFk IS NULL AND IFNULL(a.hasDailyInvoice, co.hasDailyInvoice) GROUP BY ticketFk @@ -136,8 +135,7 @@ module.exports = Self => { JOIN deliveryMethod dm ON dm.id = am.deliveryMethodFk JOIN zone z ON z.id = t.zoneFk SET t.routeFk = NULL - WHERE DATE(t.shipped) BETWEEN DATE_ADD(?, INTERVAL -2 DAY) - AND util.dayEnd(?) + WHERE DATE(t.shipped) BETWEEN ? - INTERVAL 2 DAY AND util.dayEnd(?) AND al.code NOT IN('DELIVERED','PACKED') AND t.routeFk AND z.name LIKE '%MADRID%'`, [toDate, toDate], {userId: ctx.req.accessToken.userId}); diff --git a/print/templates/email/invoice-ticket-closure/locale/en.yml b/print/templates/email/invoice-ticket-closure/locale/en.yml index 844dada7a..fef73d23f 100644 --- a/print/templates/email/invoice-ticket-closure/locale/en.yml +++ b/print/templates/email/invoice-ticket-closure/locale/en.yml @@ -1,4 +1,4 @@ subject: Nightly ticket closing process report title: Nightly ticket closing process report reason: Reason -ticketId: Ticket No \ No newline at end of file +ticketId: Ticket \ No newline at end of file diff --git a/print/templates/email/invoice-ticket-closure/locale/es.yml b/print/templates/email/invoice-ticket-closure/locale/es.yml index a8e67f18f..7d146b83d 100644 --- a/print/templates/email/invoice-ticket-closure/locale/es.yml +++ b/print/templates/email/invoice-ticket-closure/locale/es.yml @@ -1,4 +1,4 @@ subject: Informe proceso de cierre de tickets nocturno title: Informe proceso de cierre de tickets nocturno reason: Motivo -ticketId: Ticket nº \ No newline at end of file +ticketId: Ticket \ No newline at end of file From cedfdbb421f2dbfacc1855a5bf4d12092551d008 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Andr=C3=A9s?= Date: Fri, 5 Apr 2024 13:22:54 +0200 Subject: [PATCH 07/10] fix: closeTicket idem salix Refs: #6549 --- .../10949-limeLaurel/00-firstScript.sql | 27 +++++++++---------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/db/versions/10949-limeLaurel/00-firstScript.sql b/db/versions/10949-limeLaurel/00-firstScript.sql index 58d50e125..cc0bcc96b 100644 --- a/db/versions/10949-limeLaurel/00-firstScript.sql +++ b/db/versions/10949-limeLaurel/00-firstScript.sql @@ -1,16 +1,15 @@ - INSERT INTO util.notification ( name, description) - SELECT 'invoice-ticket-closure', - 'Tickets not invoiced during the nightly closure ticket process' - FROM util.notification; - -SET @notificationFk =LAST_INSERT_ID(); + INSERT INTO util.notification ( name, description) + SELECT 'invoice-ticket-closure', + 'Tickets not invoiced during the nightly closure ticket process'; + + SET @notificationFk =LAST_INSERT_ID(); -INSERT IGNORE INTO util.notificationAcl (notificationFk, roleFk) - SELECT @notificationFk,id - FROM account.role - WHERE name ='administrative'; + INSERT IGNORE INTO util.notificationAcl (notificationFk, roleFk) + SELECT @notificationFk,id + FROM account.role + WHERE name ='administrative'; -INSERT IGNORE INTO util.notificationSubscription (notificationFk, userFk) - SELECT @notificationFk, id - FROM account.`user` - WHERE `name` = 'admon'; + INSERT IGNORE INTO util.notificationSubscription (notificationFk, userFk) + SELECT @notificationFk, id + FROM account.`user` + WHERE `name` = 'admon'; From 0b96471c7de81e81b932a63ac8d141e38c350f33 Mon Sep 17 00:00:00 2001 From: guillermo Date: Mon, 8 Apr 2024 09:27:07 +0200 Subject: [PATCH 08/10] feat: refs #6714 Added businessType zone_getAddresses --- db/routines/vn/procedures/zone_getAddresses.sql | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/db/routines/vn/procedures/zone_getAddresses.sql b/db/routines/vn/procedures/zone_getAddresses.sql index 1412c7ab3..ce7b0204e 100644 --- a/db/routines/vn/procedures/zone_getAddresses.sql +++ b/db/routines/vn/procedures/zone_getAddresses.sql @@ -28,7 +28,7 @@ BEGIN SELECT c.id clientFk, c.name, c.phone, - c.mobile, + bt.description, c.salesPersonFk, u.name username, aai.invoiced, @@ -44,10 +44,11 @@ BEGIN LEFT JOIN bs.clientNewBorn cnb ON cnb.clientFk = c.id LEFT JOIN vn.annualAverageInvoiced aai ON aai.clientFk = c.id JOIN vn.clientType ct ON ct.code = c.typeFk + JOIN vn.businessType bt ON bt.code = c.businessTypeFk WHERE a.isActive AND c.isActive AND ct.code = 'normal' - AND c.businessTypeFk <> 'worker' + AND bt.code <> 'worker' GROUP BY c.id; DROP TEMPORARY TABLE tmp.zoneNodes; From ccc644c298460f48bb6a129bc18d1c31968e89e1 Mon Sep 17 00:00:00 2001 From: Juan Ferrer Toribio Date: Mon, 8 Apr 2024 13:07:04 +0200 Subject: [PATCH 09/10] fix: refs #6021 dump, floranet schema added --- db/dump/.dump/data.sql | 6 +- db/dump/.dump/privileges.sql | 1 + db/dump/.dump/structure.sql | 419 ++++++++++++++++++++++++++++++++++- db/dump/.dump/triggers.sql | 8 +- myt.config.yml | 1 + 5 files changed, 430 insertions(+), 5 deletions(-) diff --git a/db/dump/.dump/data.sql b/db/dump/.dump/data.sql index 3779a5812..8b6a01c61 100644 --- a/db/dump/.dump/data.sql +++ b/db/dump/.dump/data.sql @@ -3,7 +3,7 @@ USE `util`; /*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; /*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */; -INSERT INTO `version` VALUES ('vn-database','10970','7ea917dc4db761955007c73bbd4667a0e44b8e9c','2024-04-05 07:49:24','10981'); +INSERT INTO `version` VALUES ('vn-database','10970','273507d3b711f272078e83880802d0ef7278d062','2024-04-05 10:33:29','10983'); INSERT INTO `versionLog` VALUES ('vn-database','10107','00-firstScript.sql','jenkins@10.0.2.69','2022-04-23 10:53:53',NULL,NULL); INSERT INTO `versionLog` VALUES ('vn-database','10112','00-firstScript.sql','jenkins@10.0.2.69','2022-05-09 09:14:53',NULL,NULL); @@ -762,7 +762,7 @@ INSERT INTO `role` VALUES (1,'employee','Empleado básico',1,'2017-05-19 09:04:5 INSERT INTO `role` VALUES (2,'customer','Privilegios básicos de un cliente',1,'2017-05-19 09:04:58','2023-06-02 22:33:28',NULL); INSERT INTO `role` VALUES (3,'agency','Consultar tablas de predicciones de bultos',1,'2017-05-19 09:04:58','2017-05-19 09:04:58',NULL); INSERT INTO `role` VALUES (5,'administrative','Tareas relacionadas con la contabilidad',1,'2017-05-19 09:04:58','2017-05-19 09:04:58',NULL); -INSERT INTO `role` VALUES (6,'guest','Privilegios para usuarios sin cuenta',1,'2017-05-19 09:04:58','2017-05-19 09:04:58',NULL); +INSERT INTO `role` VALUES (6,'guest','Privilegios para usuarios no autenticados',1,'2017-05-19 09:04:58','2024-04-06 12:05:08',1437); INSERT INTO `role` VALUES (9,'developer','Desarrollador raso',1,'2017-05-19 09:04:58','2024-03-27 14:14:58',1437); INSERT INTO `role` VALUES (11,'account','Privilegios relacionados con el login',0,'2017-05-19 09:04:58','2017-09-20 19:06:35',NULL); INSERT INTO `role` VALUES (13,'teamBoss','Jefe de equipo/departamento',1,'2017-05-19 09:04:58','2021-06-30 15:29:30',NULL); @@ -1819,7 +1819,7 @@ INSERT INTO `ACL` VALUES (819,'Ticket','addSaleByCode','WRITE','ALLOW','ROLE','p INSERT INTO `ACL` VALUES (820,'TicketCollection','*','READ','ALLOW','ROLE','production'); INSERT INTO `ACL` VALUES (821,'Ticket','clone','WRITE','ALLOW','ROLE','administrative'); INSERT INTO `ACL` VALUES (822,'SupplierDms','*','*','ALLOW','ROLE','employee'); -INSERT INTO `ACL` VALUES (823,'MailAlias','*','*','ALLOW','ROLE','developer'); +INSERT INTO `ACL` VALUES (823,'MailAlias','*','*','ALLOW','ROLE','developerBoss'); INSERT INTO `fieldAcl` VALUES (1,'Client','name','update','employee'); INSERT INTO `fieldAcl` VALUES (2,'Client','contact','update','employee'); diff --git a/db/dump/.dump/privileges.sql b/db/dump/.dump/privileges.sql index 8293cc74c..491459986 100644 --- a/db/dump/.dump/privileges.sql +++ b/db/dump/.dump/privileges.sql @@ -1378,6 +1378,7 @@ INSERT IGNORE INTO `tables_priv` VALUES ('','vn','maintenanceBos','machineDetai INSERT IGNORE INTO `tables_priv` VALUES ('','vn','deliveryBoss','vehicleState','jgallego@db-proxy2.servers.dc.verdnatura.es','0000-00-00 00:00:00','Select',''); INSERT IGNORE INTO `tables_priv` VALUES ('','srt','grafana','expeditionState','guillermo@db-proxy2.servers.dc.verdnatura.es','0000-00-00 00:00:00','Select',''); INSERT IGNORE INTO `tables_priv` VALUES ('','vn','buyer','specialPrice','jgallego@db-proxy1.servers.dc.verdnatura.es','0000-00-00 00:00:00','Select,Insert,Update,Delete',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','grafana','claimRatio','guillermo@db-proxy2.servers.dc.verdnatura.es','0000-00-00 00:00:00','Select',''); /*!40000 ALTER TABLE `tables_priv` ENABLE KEYS */; /*!40000 ALTER TABLE `columns_priv` DISABLE KEYS */; diff --git a/db/dump/.dump/structure.sql b/db/dump/.dump/structure.sql index 5cc320fd4..023a997d3 100644 --- a/db/dump/.dump/structure.sql +++ b/db/dump/.dump/structure.sql @@ -11740,6 +11740,417 @@ DELIMITER ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; +-- +-- Current Database: `floranet` +-- + +CREATE DATABASE /*!32312 IF NOT EXISTS*/ `floranet` /*!40100 DEFAULT CHARACTER SET utf8mb3 COLLATE utf8mb3_unicode_ci */; + +USE `floranet`; + +-- +-- Table structure for table `addressPostCode` +-- + +DROP TABLE IF EXISTS `addressPostCode`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `addressPostCode` ( + `id` int(10) unsigned NOT NULL AUTO_INCREMENT, + `addressFk` int(11) NOT NULL, + `postCode` varchar(30) NOT NULL, + `hoursInAdvance` int(10) unsigned NOT NULL DEFAULT 24, + `dayOfWeek` int(10) unsigned NOT NULL, + `deliveryCost` decimal(10,2) NOT NULL DEFAULT 0.00, + PRIMARY KEY (`id`), + UNIQUE KEY `addressPostCode_unique` (`postCode`,`addressFk`,`dayOfWeek`), + KEY `addressPostCode_address_FK` (`addressFk`), + CONSTRAINT `addressPostCode_address_FK` FOREIGN KEY (`addressFk`) REFERENCES `vn`.`address` (`id`) ON DELETE CASCADE ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='Client''s address registered for floranet network'; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `builder` +-- + +DROP TABLE IF EXISTS `builder`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `builder` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `itemFk` int(11) NOT NULL, + `elementFk` int(11) NOT NULL, + `quantity` int(10) unsigned NOT NULL DEFAULT 1, + PRIMARY KEY (`id`), + KEY `builder_FK` (`itemFk`), + KEY `builder_FK_1` (`elementFk`), + CONSTRAINT `builder_FK` FOREIGN KEY (`itemFk`) REFERENCES `vn`.`item` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, + CONSTRAINT `builder_FK_1` FOREIGN KEY (`elementFk`) REFERENCES `element` (`itemFk`) ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='Links handmade products with their elements'; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `catalogue` +-- + +DROP TABLE IF EXISTS `catalogue`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `catalogue` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `name` varchar(50) DEFAULT NULL, + `price` decimal(10,2) NOT NULL, + `itemFk` int(11) NOT NULL, + `dated` date DEFAULT NULL, + `postalCode` varchar(12) DEFAULT NULL, + `type` varchar(50) DEFAULT NULL, + `image` varchar(255) DEFAULT NULL, + `description` text DEFAULT NULL, + `created` timestamp NULL DEFAULT current_timestamp(), + `payed` datetime DEFAULT NULL, + PRIMARY KEY (`id`), + KEY `itemFk` (`itemFk`), + CONSTRAINT `catalogue_ibfk_1` FOREIGN KEY (`itemFk`) REFERENCES `vn`.`item` (`id`) ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `element` +-- + +DROP TABLE IF EXISTS `element`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `element` ( + `itemFk` int(11) NOT NULL, + `typeFk` smallint(5) unsigned DEFAULT NULL, + `size` int(11) DEFAULT NULL, + `inkFk` char(3) CHARACTER SET utf8mb3 COLLATE utf8mb3_unicode_ci DEFAULT NULL, + `originFk` tinyint(2) unsigned DEFAULT NULL, + `name` varchar(30) DEFAULT NULL, + `quantity` int(11) NOT NULL DEFAULT 1, + PRIMARY KEY (`itemFk`), + KEY `element_FK` (`itemFk`), + KEY `element_FK_1` (`typeFk`), + KEY `element_FK_2` (`inkFk`), + KEY `element_FK_3` (`originFk`), + CONSTRAINT `element_FK` FOREIGN KEY (`itemFk`) REFERENCES `vn`.`item` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, + CONSTRAINT `element_FK_1` FOREIGN KEY (`typeFk`) REFERENCES `vn`.`itemType` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, + CONSTRAINT `element_FK_2` FOREIGN KEY (`inkFk`) REFERENCES `vn`.`ink` (`id`) ON UPDATE CASCADE, + CONSTRAINT `element_FK_3` FOREIGN KEY (`originFk`) REFERENCES `vn`.`origin` (`id`) ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='Filtro para localizar posibles items que coincidan con la descripción'; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `order` +-- + +DROP TABLE IF EXISTS `order`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `order` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `catalogueFk` int(11) DEFAULT NULL, + `customerName` varchar(100) DEFAULT NULL, + `email` varchar(100) DEFAULT NULL, + `customerPhone` varchar(15) DEFAULT NULL, + `message` varchar(255) DEFAULT NULL, + `deliveryName` varchar(100) DEFAULT NULL, + `address` varchar(200) DEFAULT NULL, + `deliveryPhone` varchar(100) DEFAULT NULL, + `isPaid` tinyint(1) NOT NULL DEFAULT 0, + `payed` datetime DEFAULT NULL, + `created` timestamp NULL DEFAULT current_timestamp(), + PRIMARY KEY (`id`), + UNIQUE KEY `catalogueFk` (`catalogueFk`), + CONSTRAINT `order_ibfk_1` FOREIGN KEY (`catalogueFk`) REFERENCES `catalogue` (`id`) ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Dumping events for database 'floranet' +-- +/*!50106 SET @save_time_zone= @@TIME_ZONE */ ; +/*!50106 DROP EVENT IF EXISTS `clean` */; +DELIMITER ;; +/*!50003 SET @saved_cs_client = @@character_set_client */ ;; +/*!50003 SET @saved_cs_results = @@character_set_results */ ;; +/*!50003 SET @saved_col_connection = @@collation_connection */ ;; +/*!50003 SET character_set_client = utf8mb4 */ ;; +/*!50003 SET character_set_results = utf8mb4 */ ;; +/*!50003 SET collation_connection = utf8mb4_unicode_ci */ ;; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ;; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ;; +/*!50003 SET @saved_time_zone = @@time_zone */ ;; +/*!50003 SET time_zone = 'SYSTEM' */ ;; +/*!50106 CREATE*/ /*!50117 DEFINER=`root`@`localhost`*/ /*!50106 EVENT `clean` ON SCHEDULE EVERY 1 DAY STARTS '2024-01-01 23:00:00' ON COMPLETION PRESERVE ENABLE DO BEGIN + DELETE + FROM `order` + WHERE created < CURDATE() + AND isPaid = FALSE; + + DELETE c.* + FROM catalogue c + LEFT JOIN `order` o ON o.catalogueFk = c.id + WHERE c.created < CURDATE() + AND o.id IS NULL; +END */ ;; +/*!50003 SET time_zone = @saved_time_zone */ ;; +/*!50003 SET sql_mode = @saved_sql_mode */ ;; +/*!50003 SET character_set_client = @saved_cs_client */ ;; +/*!50003 SET character_set_results = @saved_cs_results */ ;; +/*!50003 SET collation_connection = @saved_col_connection */ ;; +DELIMITER ; +/*!50106 SET TIME_ZONE= @save_time_zone */ ; + +-- +-- Dumping routines for database 'floranet' +-- +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `catalogue_get` */; +/*!50003 SET @saved_cs_client = @@character_set_client */ ; +/*!50003 SET @saved_cs_results = @@character_set_results */ ; +/*!50003 SET @saved_col_connection = @@collation_connection */ ; +/*!50003 SET character_set_client = utf8mb4 */ ; +/*!50003 SET character_set_results = utf8mb4 */ ; +/*!50003 SET collation_connection = utf8mb4_unicode_ci */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `catalogue_get`(vLanded DATE, vPostalCode VARCHAR(15)) + READS SQL DATA +BEGIN +/** + * Returns list, price and all the stuff regarding the floranet items + * + * @param vLanded Delivery date + * @param vPostalCode Delivery address postal code + */ + DECLARE vLastCatalogueFk INT; + + START TRANSACTION; + + SELECT * FROM catalogue FOR UPDATE; + + SELECT MAX(id) INTO vLastCatalogueFk + FROM catalogue; + + INSERT INTO catalogue( + name, + price, + itemFk, + dated, + postalCode, + `type`, + image, + description + ) + SELECT i.name, + i.`size`, + i.id, + vLanded, + vPostalCode, + it.name, + CONCAT('https://cdn.verdnatura.es/image/catalog/1600x900/', i.image), + i.description + FROM vn.item i + JOIN vn.itemType it ON it.id = i.typeFk + WHERE it.code IN ('FNR','FNP'); + + SELECT * + FROM catalogue + WHERE id > IFNULL(vLastCatalogueFk,0); + + COMMIT; + +END ;; +DELIMITER ; +/*!50003 SET sql_mode = @saved_sql_mode */ ; +/*!50003 SET character_set_client = @saved_cs_client */ ; +/*!50003 SET character_set_results = @saved_cs_results */ ; +/*!50003 SET collation_connection = @saved_col_connection */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `contact_request` */; +/*!50003 SET @saved_cs_client = @@character_set_client */ ; +/*!50003 SET @saved_cs_results = @@character_set_results */ ; +/*!50003 SET @saved_col_connection = @@collation_connection */ ; +/*!50003 SET character_set_client = utf8mb4 */ ; +/*!50003 SET character_set_results = utf8mb4 */ ; +/*!50003 SET collation_connection = utf8mb4_unicode_ci */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `contact_request`( + vName VARCHAR(100), + vPhone VARCHAR(15), + vEmail VARCHAR(100), + vMessage TEXT) + READS SQL DATA +BEGIN +/** + * Set actions for contact request. + * + * @param vPostalCode Delivery address postal code + */ + +END ;; +DELIMITER ; +/*!50003 SET sql_mode = @saved_sql_mode */ ; +/*!50003 SET character_set_client = @saved_cs_client */ ; +/*!50003 SET character_set_results = @saved_cs_results */ ; +/*!50003 SET collation_connection = @saved_col_connection */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `deliveryDate_get` */; +/*!50003 SET @saved_cs_client = @@character_set_client */ ; +/*!50003 SET @saved_cs_results = @@character_set_results */ ; +/*!50003 SET @saved_col_connection = @@collation_connection */ ; +/*!50003 SET character_set_client = utf8mb4 */ ; +/*!50003 SET character_set_results = utf8mb4 */ ; +/*!50003 SET collation_connection = utf8mb4_unicode_ci */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `deliveryDate_get`(vPostalCode VARCHAR(15)) + READS SQL DATA +BEGIN +/** + * Returns available dates for this postalCode, in the next seven days + * + * @param vPostalCode Delivery address postal code + */ + DECLARE vCurrentDayOfWeek INT; + + SET vCurrentDayOfWeek = DAYOFWEEK(NOW()); + + SELECT DISTINCT nextDay + FROM ( + SELECT CURDATE() + INTERVAL IF( + apc.dayOfWeek >= vCurrentDayOfWeek, + apc.dayOfWeek - vCurrentDayOfWeek, + 7 - apc.dayOfWeek + ) DAY nextDay, + NOW() + INTERVAL apc.hoursInAdvance - 12 HOUR minDeliveryTime + FROM addressPostCode apc + WHERE apc.postCode = vPostalCode + HAVING nextDay > minDeliveryTime) sub; +END ;; +DELIMITER ; +/*!50003 SET sql_mode = @saved_sql_mode */ ; +/*!50003 SET character_set_client = @saved_cs_client */ ; +/*!50003 SET character_set_results = @saved_cs_results */ ; +/*!50003 SET collation_connection = @saved_col_connection */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `order_confirm` */; +/*!50003 SET @saved_cs_client = @@character_set_client */ ; +/*!50003 SET @saved_cs_results = @@character_set_results */ ; +/*!50003 SET @saved_col_connection = @@collation_connection */ ; +/*!50003 SET character_set_client = utf8mb4 */ ; +/*!50003 SET character_set_results = utf8mb4 */ ; +/*!50003 SET collation_connection = utf8mb4_unicode_ci */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `order_confirm`(vCatalogueFk INT) + READS SQL DATA +BEGIN +/** Update order.isPaid field + * + * @param vCatalogueFk floranet.catalogue.id + * + * @returns floranet.order.isPaid + */ + UPDATE `order` + SET isPaid = TRUE, + payed = NOW() + WHERE catalogueFk = vCatalogueFk; + + SELECT isPaid + FROM `order` + WHERE catalogueFk = vCatalogueFk; +END ;; +DELIMITER ; +/*!50003 SET sql_mode = @saved_sql_mode */ ; +/*!50003 SET character_set_client = @saved_cs_client */ ; +/*!50003 SET character_set_results = @saved_cs_results */ ; +/*!50003 SET collation_connection = @saved_col_connection */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `order_put` */; +/*!50003 SET @saved_cs_client = @@character_set_client */ ; +/*!50003 SET @saved_cs_results = @@character_set_results */ ; +/*!50003 SET @saved_col_connection = @@collation_connection */ ; +/*!50003 SET character_set_client = utf8mb4 */ ; +/*!50003 SET character_set_results = utf8mb4 */ ; +/*!50003 SET collation_connection = utf8mb4_unicode_ci */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `order_put`(vOrder JSON) + READS SQL DATA +BEGIN +/** + * Get and process an order + * + * @param vOrder Data of the order + * + * Customer data: , , + * + * Item data: , + * + * Delivery data: ,
, + * + */ + INSERT IGNORE INTO `order`( + catalogueFk, + customerName, + email, + customerPhone, + message, + deliveryName, + address, + deliveryPhone + ) + VALUES (JSON_UNQUOTE(JSON_EXTRACT(vOrder,'$.catalogueFk')), + JSON_UNQUOTE(JSON_EXTRACT(vOrder,'$.customerName')), + JSON_UNQUOTE(JSON_EXTRACT(vOrder,'$.email')), + JSON_UNQUOTE(JSON_EXTRACT(vOrder,'$.customerPhone')), + JSON_UNQUOTE(JSON_EXTRACT(vOrder,'$.message')), + JSON_UNQUOTE(JSON_EXTRACT(vOrder,'$.deliveryName')), + JSON_UNQUOTE(JSON_EXTRACT(vOrder,'$.address')), + JSON_UNQUOTE(JSON_EXTRACT(vOrder,'$.deliveryPhone')) + ); + + SELECT LAST_INSERT_ID() orderFk; +END ;; +DELIMITER ; +/*!50003 SET sql_mode = @saved_sql_mode */ ; +/*!50003 SET character_set_client = @saved_cs_client */ ; +/*!50003 SET character_set_results = @saved_cs_results */ ; +/*!50003 SET collation_connection = @saved_col_connection */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `sliders_get` */; +/*!50003 SET @saved_cs_client = @@character_set_client */ ; +/*!50003 SET @saved_cs_results = @@character_set_results */ ; +/*!50003 SET @saved_col_connection = @@collation_connection */ ; +/*!50003 SET character_set_client = utf8mb4 */ ; +/*!50003 SET character_set_results = utf8mb4 */ ; +/*!50003 SET collation_connection = utf8mb4_unicode_ci */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `sliders_get`() + READS SQL DATA +BEGIN +/** + * Returns list of url for sliders + */ + SELECT + CONCAT('https://cdn.verdnatura.es/image/catalog/1600x900/', i.image) url, + i.longName + FROM vn.item i + JOIN vn.itemType it ON it.id = i.typeFk + WHERE it.code IN ('FNR','FNP'); + +END ;; +DELIMITER ; +/*!50003 SET sql_mode = @saved_sql_mode */ ; +/*!50003 SET character_set_client = @saved_cs_client */ ; +/*!50003 SET character_set_results = @saved_cs_results */ ; +/*!50003 SET collation_connection = @saved_col_connection */ ; + -- -- Current Database: `hedera` -- @@ -86045,6 +86456,12 @@ USE `edi`; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; +-- +-- Current Database: `floranet` +-- + +USE `floranet`; + -- -- Current Database: `hedera` -- @@ -91244,4 +91661,4 @@ USE `vn2008`; /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; --- Dump completed on 2024-04-05 7:59:52 +-- Dump completed on 2024-04-08 7:13:58 diff --git a/db/dump/.dump/triggers.sql b/db/dump/.dump/triggers.sql index fd73baf16..cdf611d5b 100644 --- a/db/dump/.dump/triggers.sql +++ b/db/dump/.dump/triggers.sql @@ -820,6 +820,12 @@ DELIMITER ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; +-- +-- Current Database: `floranet` +-- + +USE `floranet`; + -- -- Current Database: `hedera` -- @@ -10991,4 +10997,4 @@ USE `vn2008`; /*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; --- Dump completed on 2024-04-05 8:00:14 +-- Dump completed on 2024-04-08 7:14:22 diff --git a/myt.config.yml b/myt.config.yml index d7d1ad181..2ac8b8e5e 100755 --- a/myt.config.yml +++ b/myt.config.yml @@ -11,6 +11,7 @@ schemas: - cache - dipole - edi + - floranet - hedera - pbx - psico From 2eb229adf72819078e9a241048c40508f780f26d Mon Sep 17 00:00:00 2001 From: Pako Date: Mon, 8 Apr 2024 14:30:46 +0200 Subject: [PATCH 10/10] catalogue fixed --- .../floranet/procedures/catalogue_get.sql | 20 +++++++++++++++---- .../floranet/procedures/sliders_get.sql | 3 ++- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/db/routines/floranet/procedures/catalogue_get.sql b/db/routines/floranet/procedures/catalogue_get.sql index b6ec61522..e45fa7ddf 100644 --- a/db/routines/floranet/procedures/catalogue_get.sql +++ b/db/routines/floranet/procedures/catalogue_get.sql @@ -4,7 +4,7 @@ DELIMITER $$ $$ CREATE DEFINER=`root`@`localhost` PROCEDURE floranet.catalogue_get(vLanded DATE, vPostalCode VARCHAR(15)) READS SQL DATA -BEGIN +proc:BEGIN /** * Returns list, price and all the stuff regarding the floranet items * @@ -12,10 +12,22 @@ BEGIN * @param vPostalCode Delivery address postal code */ DECLARE vLastCatalogueFk INT; + DECLARE vLockName VARCHAR(20); + DECLARE vLockTime INT; - START TRANSACTION; + DECLARE EXIT HANDLER FOR SQLEXCEPTION + BEGIN + DO RELEASE_LOCK(vLockName); - SELECT * FROM catalogue FOR UPDATE; + RESIGNAL; + END; + + SET vLockName = 'catalogue_get'; + SET vLockTime = 15; + + IF NOT GET_LOCK(vLockName, vLockTime) THEN + LEAVE proc; + END IF; SELECT MAX(id) INTO vLastCatalogueFk FROM catalogue; @@ -46,7 +58,7 @@ BEGIN FROM catalogue WHERE id > IFNULL(vLastCatalogueFk,0); - COMMIT; + DO RELEASE_LOCK(vLockName); END$$ DELIMITER ; diff --git a/db/routines/floranet/procedures/sliders_get.sql b/db/routines/floranet/procedures/sliders_get.sql index 2f77b8534..bd791dec7 100644 --- a/db/routines/floranet/procedures/sliders_get.sql +++ b/db/routines/floranet/procedures/sliders_get.sql @@ -13,7 +13,8 @@ BEGIN i.longName FROM vn.item i JOIN vn.itemType it ON it.id = i.typeFk - WHERE it.code IN ('FNR','FNP'); + WHERE it.code IN ('FNR','FNP') + LIMIT 3; END$$ DELIMITER ; \ No newline at end of file