From f9deb9f52dfc590bcc09e87483ea0d4b5b9a0863 Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Tue, 19 Nov 2019 11:53:01 +0100 Subject: [PATCH] send closure error by email --- db/dump/fixtures.sql | 12 ++++----- print/methods/closure.js | 21 ++++++++++----- .../reports/delivery-note/locale/fr.yml | 26 +++++++++++++++++++ 3 files changed, 46 insertions(+), 13 deletions(-) create mode 100644 print/templates/reports/delivery-note/locale/fr.yml diff --git a/db/dump/fixtures.sql b/db/dump/fixtures.sql index 04878be69..7f7305133 100644 --- a/db/dump/fixtures.sql +++ b/db/dump/fixtures.sql @@ -62,13 +62,13 @@ INSERT INTO `vn`.`country`(`id`, `country`, `isUeeMember`, `code`, `currencyFk`, (19,'Francia', 1, 'FR', 1, 27), (30,'Canarias', 1, 'IC', 1, 24); -INSERT INTO `vn`.`warehouse`(`id`, `name`, `isComparative`, `isInventory`, `hasAvailable`, `isManaged`, `hasStowaway`, `hasDms`) +INSERT INTO `vn`.`warehouse`(`id`, `name`, `isComparative`, `isInventory`, `hasAvailable`, `isManaged`, `hasStowaway`, `hasDms`, `hasComission`) VALUES - (1, 'Warehouse One', 1, 1, 1, 1, 1, 1), - (2, 'Warehouse Two', 1, 1, 1, 1, 0, 0), - (3, 'Warehouse Three', 1, 1, 1, 1, 0, 0), - (4, 'Warehouse Four', 1, 1, 1, 1, 0, 0), - (5, 'Warehouse Five', 1, 1, 1, 1, 0, 0); + (1, 'Warehouse One', 1, 1, 1, 1, 1, 1, 1), + (2, 'Warehouse Two', 1, 1, 1, 1, 0, 0, 1), + (3, 'Warehouse Three', 1, 1, 1, 1, 0, 0, 0), + (4, 'Warehouse Four', 1, 1, 1, 1, 0, 0, 0), + (5, 'Warehouse Five', 1, 1, 1, 1, 0, 0, 0); INSERT INTO `vn`.`sector`(`id`, `description`, `warehouseFk`, `isPreviousPreparedByPacking`, `code`, `pickingPlacement`, `path`) VALUES diff --git a/print/methods/closure.js b/print/methods/closure.js index c12dd07b0..4b25c5abc 100644 --- a/print/methods/closure.js +++ b/print/methods/closure.js @@ -16,8 +16,7 @@ module.exports = app => { JOIN client c ON c.id = t.clientFk JOIN warehouse w ON w.id = t.warehouseFk AND hasComission LEFT JOIN ticketState ts ON ts.ticketFk = t.id - WHERE - ts.alertLevel = 2 + WHERE ts.code = 'PACKED' AND DATE(t.shipped) BETWEEN DATE_ADD(CURDATE(), INTERVAL -2 DAY) AND CURDATE() AND t.refFk IS NULL GROUP BY e.ticketFk`); @@ -37,22 +36,30 @@ module.exports = app => { await email.send(); } catch (error) { // Save tickets on a list of failed ids - failedtickets.push(ticket.id); + failedtickets.push({ + id: ticket.id, + stacktrace: error + }); } } // Send email with failed tickets if (failedtickets.length > 0) { - const ticketList = failedtickets.join(', '); + let body = 'This following tickets has failed:

'; + + for (ticket of failedtickets) { + body += `Ticket: ${ticket.id} +
${ticket.stacktrace}

`; + } + smtp.send({ to: config.app.reportEmail, - subject: 'Nightly ticket closure has failed', - text: `This following tickets has failed: ${ticketList}` + subject: '[API] Nightly ticket closure has failed', + html: body }); } res.status(200).json({ - statusCode: 200, message: 'Closure executed successfully' }); }); diff --git a/print/templates/reports/delivery-note/locale/fr.yml b/print/templates/reports/delivery-note/locale/fr.yml new file mode 100644 index 000000000..98b1264b1 --- /dev/null +++ b/print/templates/reports/delivery-note/locale/fr.yml @@ -0,0 +1,26 @@ +title: Bon de livraison +ticketId: Bon de livraison +clientId: Client +deliveryAddress: Addresse de livraison +fiscalData: Datos fiscales +saleLines: Líneas de pedido +date: Date +reference: Ref. +quantity: Cant. +concept: Concepto +price: PVP/u +discount: Dto. +vat: IVA +amount: Importe +type: Tipo +taxBase: Base imp. +tax: Tasa +fee: Cuota +total: Total +subtotal: Subtotal +taxBreakdown: Répartition de la taxe +packagings: Seaux et emballages +services: Servicios +vatType: Tipo de IVA +digitalSignature: Firma digital +ticket: Albarán {0} \ No newline at end of file