diff --git a/db/changes/10451-april/00-invoiceOut_queue.sql b/db/changes/10451-april/00-invoiceOut_queue.sql new file mode 100644 index 0000000000..80f6aed40a --- /dev/null +++ b/db/changes/10451-april/00-invoiceOut_queue.sql @@ -0,0 +1,13 @@ +create table `vn`.`invoiceOut_queue` +( + invoiceFk int(10) unsigned not null, + dated datetime default now() null, + printed tinyint(1) default 0 null, + constraint invoiceOut_queue_pk + primary key (invoiceFk), + constraint invoiceOut_queue_invoiceOut_id_fk + foreign key (invoiceFk) references invoiceOut (id) + on update cascade on delete cascade +) + comment 'Queue for PDF invoicing'; + diff --git a/modules/invoiceOut/back/methods/invoiceOut/globalInvoicing.js b/modules/invoiceOut/back/methods/invoiceOut/globalInvoicing.js index 6b901872e5..f2c988909f 100644 --- a/modules/invoiceOut/back/methods/invoiceOut/globalInvoicing.js +++ b/modules/invoiceOut/back/methods/invoiceOut/globalInvoicing.js @@ -140,6 +140,9 @@ module.exports = Self => { if (newInvoice.id) { await Self.rawSql('CALL invoiceOutBooking(?)', [newInvoice.id], myOptions); + query = `INSERT IGNORE INTO invoiceOut_queue(invoiceFk) VALUES(?)`; + await Self.rawSql(query, [newInvoice.id], myOptions); + invoicesIds.push(newInvoice.id); } } catch (e) { @@ -161,8 +164,8 @@ module.exports = Self => { } // Print invoices PDF - for (let invoiceId of invoicesIds) - await Self.createPdf(ctx, invoiceId); + // for (let invoiceId of invoicesIds) + // await Self.createPdf(ctx, invoiceId); return invoicesIds; }; diff --git a/modules/item/back/methods/item/specs/lastEntriesFilter.spec.js b/modules/item/back/methods/item/specs/lastEntriesFilter.spec.js index 6c692848b0..6db3d433e5 100644 --- a/modules/item/back/methods/item/specs/lastEntriesFilter.spec.js +++ b/modules/item/back/methods/item/specs/lastEntriesFilter.spec.js @@ -1,6 +1,6 @@ const models = require('vn-loopback/server/server').models; -describe('item lastEntriesFilter()', () => { +fdescribe('item lastEntriesFilter()', () => { const minDate = new Date(value); minHour.setHours(0, 0, 0, 0); const maxDate = new Date(value); diff --git a/print/methods/notify/invocing.js b/print/methods/notify/invocing.js new file mode 100644 index 0000000000..1172ef0eae --- /dev/null +++ b/print/methods/notify/invocing.js @@ -0,0 +1,45 @@ +const db = require('vn-print/core/database'); +const Email = require('vn-print/core/email'); + +module.exports = async function(request, response, next) { + try { + const reqArgs = request.body; + + if (!reqArgs.clientIds) + throw new Error('The argument clientIds is required'); + if (!reqArgs.from) + throw new Error('The argument from is required'); + if (!reqArgs.to) + throw new Error('The argument to is required'); + + response.status(200).json({ + message: 'Success' + }); + + const invoices = await db.rawSql(` + SELECT + * FROM invoiceOut_queue + WHERE status = 'PENDING'`); + + // const clientData = new Map(); + // for (const client of clients) + // clientData.set(client.id, client); + + // for (const clientId of reqArgs.clientIds) { + // const client = clientData.get(clientId); + + // if (client) { + // const args = Object.assign({ + // recipientId: clientId, + // recipient: client.email, + // replyTo: client.salesPersonEmail + // }, response.locals); + + // const email = new Email('campaign-metrics', args); + // await email.send(); + // } + // } + } catch (error) { + next(error); + } +};