3327 - Invoicing queue #961
|
@ -1,7 +1,8 @@
|
||||||
create table `vn`.`invoiceOut_queue`
|
create table `vn`.`invoiceOut_queue`
|
||||||
(
|
(
|
||||||
invoiceFk int(10) unsigned not null,
|
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,
|
`status` VARCHAR(50) default '' null,
|
||||||
constraint invoiceOut_queue_pk
|
constraint invoiceOut_queue_pk
|
||||||
primary key (invoiceFk),
|
primary key (invoiceFk),
|
||||||
|
|
|
@ -161,10 +161,6 @@ module.exports = Self => {
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Print invoices PDF
|
|
||||||
// for (let invoiceId of invoicesIds)
|
|
||||||
// await Self.createPdf(ctx, invoiceId);
|
|
||||||
|
|
||||||
return invoicesIds;
|
return invoicesIds;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -213,7 +209,13 @@ module.exports = Self => {
|
||||||
|
|
||||||
const query = `SELECT
|
const query = `SELECT
|
||||||
c.id,
|
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.hasToInvoiceByAddress,
|
||||||
c.email,
|
c.email,
|
||||||
c.isToBeMailed,
|
c.isToBeMailed,
|
||||||
|
|
|
@ -19,7 +19,7 @@
|
||||||
ng-if="$ctrl.isInvoicing">
|
ng-if="$ctrl.isInvoicing">
|
||||||
<vn-horizontal>
|
<vn-horizontal>
|
||||||
<vn-icon vn-none icon="warning"></vn-icon>
|
<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>
|
</vn-horizontal>
|
||||||
</div>
|
</div>
|
||||||
<vn-horizontal>
|
<vn-horizontal>
|
||||||
|
@ -66,5 +66,5 @@
|
||||||
</tpl-body>
|
</tpl-body>
|
||||||
<tpl-buttons>
|
<tpl-buttons>
|
||||||
<input type="button" response="cancel" translate-attr="{value: 'Cancel'}"/>
|
<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>
|
</tpl-buttons>
|
|
@ -1,7 +1,7 @@
|
||||||
Create global invoice: Crear factura global
|
Create global invoice: Crear factura global
|
||||||
Some fields are required: Algunos campos son obligatorios
|
Some fields are required: Algunos campos son obligatorios
|
||||||
Max date: Fecha límite
|
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
|
Invoice date: Fecha de factura
|
||||||
From client: Desde el cliente
|
From client: Desde el cliente
|
||||||
To client: Hasta el cliente
|
To client: Hasta el cliente
|
||||||
|
|
|
@ -15,6 +15,7 @@ module.exports = app => {
|
||||||
WHERE at.id = ?`;
|
WHERE at.id = ?`;
|
||||||
|
|
||||||
const auth = await db.findOne(query, [token]);
|
const auth = await db.findOne(query, [token]);
|
||||||
|
console.log(auth);
|
||||||
|
|
||||||
if (!auth || isTokenExpired(auth.created, auth.ttl))
|
if (!auth || isTokenExpired(auth.created, auth.ttl))
|
||||||
throw new Error('Invalid authorization token');
|
throw new Error('Invalid authorization token');
|
||||||
|
@ -31,6 +32,8 @@ module.exports = app => {
|
||||||
locale: auth.lang
|
locale: auth.lang
|
||||||
};
|
};
|
||||||
|
|
||||||
|
console.log(response.locals.auth);
|
||||||
|
|
||||||
next();
|
next();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
next(error);
|
next(error);
|
||||||
|
|
|
@ -5,8 +5,6 @@ const storage = require('vn-print/core/storage');
|
||||||
|
|
||||||
module.exports = async function(request, response, next) {
|
module.exports = async function(request, response, next) {
|
||||||
try {
|
try {
|
||||||
const reqArgs = request.body;
|
|
||||||
|
|
||||||
response.status(200).json({
|
response.status(200).json({
|
||||||
message: 'Success'
|
message: 'Success'
|
||||||
});
|
});
|
||||||
|
@ -29,17 +27,18 @@ module.exports = async function(request, response, next) {
|
||||||
JOIN province p ON p.id = c.provinceFk
|
JOIN province p ON p.id = c.provinceFk
|
||||||
JOIN country co ON co.id = p.countryFk
|
JOIN country co ON co.id = p.countryFk
|
||||||
LEFT JOIN account.emailUser eu ON eu.userFk = c.salesPersonFk
|
LEFT JOIN account.emailUser eu ON eu.userFk = c.salesPersonFk
|
||||||
|
|
||||||
WHERE status = ''`);
|
WHERE status = ''`);
|
||||||
|
|
||||||
|
let invoiceId;
|
||||||
for (const invoiceOut of invoices) {
|
for (const invoiceOut of invoices) {
|
||||||
try {
|
try {
|
||||||
|
invoiceId = invoiceOut.id;
|
||||||
const args = Object.assign({
|
const args = Object.assign({
|
||||||
invoiceId: invoiceOut.id,
|
invoiceId: invoiceOut.id,
|
||||||
recipientId: invoiceOut.clientFk,
|
recipientId: invoiceOut.clientFk,
|
||||||
recipient: invoiceOut.recipient,
|
recipient: invoiceOut.recipient,
|
||||||
replyTo: invoiceOut.salesPersonEmail
|
replyTo: invoiceOut.salesPersonEmail
|
||||||
}, reqArgs);
|
}, response.locals);
|
||||||
|
|
||||||
const invoiceReport = new Report('invoice', args);
|
const invoiceReport = new Report('invoice', args);
|
||||||
const stream = await invoiceReport.toPdfStream();
|
const stream = await invoiceReport.toPdfStream();
|
||||||
|
@ -89,29 +88,19 @@ module.exports = async function(request, response, next) {
|
||||||
const email = new Email('invoice', args);
|
const email = new Email('invoice', args);
|
||||||
await email.send(mailOptions);
|
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) {
|
} 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) {
|
} catch (error) {
|
||||||
next(error);
|
next(error);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue