From 79e9edcee959f42044b7328932e5a5970a861f8c Mon Sep 17 00:00:00 2001 From: vicent Date: Wed, 9 Nov 2022 09:26:28 +0100 Subject: [PATCH] delete: old code --- .../00-deleteInvoiceOutQueue.sql | 1 + .../back/methods/invoiceOut/sendQueued.js | 133 ------------------ modules/invoiceOut/back/models/invoice-out.js | 1 - 3 files changed, 1 insertion(+), 134 deletions(-) create mode 100644 db/changes/10502-november/00-deleteInvoiceOutQueue.sql delete mode 100644 modules/invoiceOut/back/methods/invoiceOut/sendQueued.js diff --git a/db/changes/10502-november/00-deleteInvoiceOutQueue.sql b/db/changes/10502-november/00-deleteInvoiceOutQueue.sql new file mode 100644 index 0000000000..87a3059a09 --- /dev/null +++ b/db/changes/10502-november/00-deleteInvoiceOutQueue.sql @@ -0,0 +1 @@ +DROP TABLE `vn`.`invoiceOutQueue`; \ No newline at end of file diff --git a/modules/invoiceOut/back/methods/invoiceOut/sendQueued.js b/modules/invoiceOut/back/methods/invoiceOut/sendQueued.js deleted file mode 100644 index a1730ac818..0000000000 --- a/modules/invoiceOut/back/methods/invoiceOut/sendQueued.js +++ /dev/null @@ -1,133 +0,0 @@ -const {Email, Report, storage} = require('vn-print'); - -module.exports = Self => { - Self.remoteMethod('sendQueued', { - description: 'Send all queued invoices', - accessType: 'WRITE', - accepts: [], - returns: { - type: 'object', - root: true - }, - http: { - path: '/send-queued', - verb: 'POST' - } - }); - - Self.sendQueued = async() => { - const invoices = await Self.rawSql(` - SELECT - io.id, - io.clientFk, - io.issued, - io.ref, - c.email recipient, - c.salesPersonFk, - c.isToBeMailed, - c.hasToInvoice, - co.hasDailyInvoice, - eu.email salesPersonEmail - FROM invoiceOutQueue ioq - JOIN invoiceOut io ON io.id = ioq.invoiceFk - JOIN client c ON c.id = io.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 status = ''`); - - let invoiceId; - for (const invoiceOut of invoices) { - try { - const tx = await Self.beginTransaction({}); - const myOptions = {transaction: tx}; - - invoiceId = invoiceOut.id; - - const args = { - reference: invoiceOut.ref, - recipientId: invoiceOut.clientFk, - recipient: invoiceOut.recipient, - replyTo: invoiceOut.salesPersonEmail - }; - - const invoiceReport = new Report('invoice', args); - const stream = await invoiceReport.toPdfStream(); - - const issued = invoiceOut.issued; - const year = issued.getFullYear().toString(); - const month = (issued.getMonth() + 1).toString(); - const day = issued.getDate().toString(); - - const fileName = `${year}${invoiceOut.ref}.pdf`; - - // Store invoice - storage.write(stream, { - type: 'invoice', - path: `${year}/${month}/${day}`, - fileName: fileName - }); - - await Self.rawSql(` - UPDATE invoiceOut - SET hasPdf = true - WHERE id = ?`, - [invoiceOut.id], myOptions); - - const isToBeMailed = invoiceOut.recipient && invoiceOut.salesPersonFk && invoiceOut.isToBeMailed; - - if (isToBeMailed) { - const mailOptions = { - overrideAttachments: true, - attachments: [] - }; - - const invoiceAttachment = { - filename: fileName, - content: stream - }; - - if (invoiceOut.serial == 'E' && invoiceOut.companyCode == 'VNL') { - const exportation = new Report('exportation', args); - const stream = await exportation.toPdfStream(); - const fileName = `CITES-${invoiceOut.ref}.pdf`; - - mailOptions.attachments.push({ - filename: fileName, - content: stream - }); - } - - mailOptions.attachments.push(invoiceAttachment); - - const email = new Email('invoice', args); - await email.send(mailOptions); - } - // Update queue status - const date = new Date(); - await Self.rawSql(` - UPDATE invoiceOutQueue - SET status = "printed", - printed = ? - WHERE invoiceFk = ?`, - [date, invoiceOut.id], myOptions); - - await tx.commit(); - } catch (error) { - await tx.rollback(); - - await Self.rawSql(` - UPDATE invoiceOutQueue - SET status = ? - WHERE invoiceFk = ?`, - [error.message, invoiceId]); - - throw e; - } - } - - return { - message: 'Success' - }; - }; -}; diff --git a/modules/invoiceOut/back/models/invoice-out.js b/modules/invoiceOut/back/models/invoice-out.js index 3648ba8498..88adae2ef0 100644 --- a/modules/invoiceOut/back/models/invoice-out.js +++ b/modules/invoiceOut/back/models/invoice-out.js @@ -13,7 +13,6 @@ module.exports = Self => { require('../methods/invoiceOut/refund')(Self); require('../methods/invoiceOut/invoiceEmail')(Self); require('../methods/invoiceOut/exportationPdf')(Self); - require('../methods/invoiceOut/sendQueued')(Self); require('../methods/invoiceOut/invoiceCsv')(Self); require('../methods/invoiceOut/invoiceCsvEmail')(Self); };