refactor(invoicing): send invoice to print queue
gitea/salix/pipeline/head This commit looks good Details

This commit is contained in:
Joan Sanchez 2022-04-28 08:14:33 +02:00
parent c58272fefc
commit c923526342
4 changed files with 64 additions and 3 deletions

View File

@ -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';

View File

@ -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;
};

View File

@ -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);

View File

@ -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);
}
};