Invoice queue

This commit is contained in:
Joan Sanchez 2022-05-02 09:51:49 +02:00
parent fea7df269c
commit ea6b1abdd8
6 changed files with 28 additions and 33 deletions

View File

@ -1,7 +1,8 @@
create table `vn`.`invoiceOut_queue`
(
invoiceFk int(10) unsigned not null,
dated datetime default now() null,
queued datetime default now() not null,
printed datetime null,
`status` VARCHAR(50) default '' null,
constraint invoiceOut_queue_pk
primary key (invoiceFk),

View File

@ -161,10 +161,6 @@ module.exports = Self => {
throw e;
}
// Print invoices PDF
// for (let invoiceId of invoicesIds)
// await Self.createPdf(ctx, invoiceId);
return invoicesIds;
};
@ -213,7 +209,13 @@ module.exports = Self => {
const query = `SELECT
c.id,
SUM(IFNULL(s.quantity * s.price * (100-s.discount)/100, 0) + IFNULL(ts.quantity * ts.price,0)) AS sumAmount,
SUM(IFNULL
(
s.quantity *
s.price * (100-s.discount)/100,
0)
+ IFNULL(ts.quantity * ts.price,0)
) AS sumAmount,
c.hasToInvoiceByAddress,
c.email,
c.isToBeMailed,

View File

@ -19,7 +19,7 @@
ng-if="$ctrl.isInvoicing">
<vn-horizontal>
<vn-icon vn-none icon="warning"></vn-icon>
<span vn-none translate>Invoicing in progress...</span>
<span vn-none translate>Adding invoices to queue...</span>
</vn-horizontal>
</div>
<vn-horizontal>
@ -66,5 +66,5 @@
</tpl-body>
<tpl-buttons>
<input type="button" response="cancel" translate-attr="{value: 'Cancel'}"/>
<button response="accept" translate vn-focus>Make invoice</button>
<button response="accept" translate vn-focus>Invoice</button>
</tpl-buttons>

View File

@ -1,7 +1,7 @@
Create global invoice: Crear factura global
Some fields are required: Algunos campos son obligatorios
Max date: Fecha límite
Invoicing in progress...: Facturación en progreso...
Adding invoices to queue...: Añadiendo facturas a la cola...
Invoice date: Fecha de factura
From client: Desde el cliente
To client: Hasta el cliente

View File

@ -15,6 +15,7 @@ module.exports = app => {
WHERE at.id = ?`;
const auth = await db.findOne(query, [token]);
console.log(auth);
if (!auth || isTokenExpired(auth.created, auth.ttl))
throw new Error('Invalid authorization token');
@ -31,6 +32,8 @@ module.exports = app => {
locale: auth.lang
};
console.log(response.locals.auth);
next();
} catch (error) {
next(error);

View File

@ -5,8 +5,6 @@ const storage = require('vn-print/core/storage');
module.exports = async function(request, response, next) {
try {
const reqArgs = request.body;
response.status(200).json({
message: 'Success'
});
@ -29,17 +27,18 @@ module.exports = async function(request, response, next) {
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 {
invoiceId = invoiceOut.id;
const args = Object.assign({
invoiceId: invoiceOut.id,
recipientId: invoiceOut.clientFk,
recipient: invoiceOut.recipient,
replyTo: invoiceOut.salesPersonEmail
}, reqArgs);
}, response.locals);
const invoiceReport = new Report('invoice', args);
const stream = await invoiceReport.toPdfStream();
@ -89,29 +88,19 @@ module.exports = async function(request, response, next) {
const email = new Email('invoice', args);
await email.send(mailOptions);
}
// Update queue status
sql = `UPDATE invoiceOut_queue
SET status = "printed",
printed = NOW()
WHERE invoiceFk = ?`;
await db.rawSql(sql, [invoiceOut.id]);
} catch (error) {
console.log(error);
sql = `UPDATE invoiceOut_queue
SET status = ?
WHERE invoiceFk = ?`;
await db.rawSql(sql, [error.message, invoiceId]);
}
}
// 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);
}