refactor: actuializada consulta par obtener los clientes a facturar. Excluido impresion pdfs de la transaccion
gitea/salix/pipeline/head There was a failure building this commit
Details
gitea/salix/pipeline/head There was a failure building this commit
Details
This commit is contained in:
parent
4754dc7bda
commit
5b22096567
|
@ -150,38 +150,24 @@ module.exports = Self => {
|
||||||
const args = ctx.args;
|
const args = ctx.args;
|
||||||
minShipped.setFullYear(minShipped.getFullYear() - 1);
|
minShipped.setFullYear(minShipped.getFullYear() - 1);
|
||||||
|
|
||||||
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,
|
|
||||||
c.hasToInvoiceByAddress,
|
c.hasToInvoiceByAddress,
|
||||||
c.email,
|
a.id addressFk,
|
||||||
c.isToBeMailed,
|
sum(t.totalWithVat) totalAmount
|
||||||
a.id addressFk
|
|
||||||
FROM ticket t
|
FROM ticket t
|
||||||
LEFT JOIN sale s ON s.ticketFk = t.id
|
|
||||||
LEFT JOIN ticketService ts ON ts.ticketFk = t.id
|
|
||||||
JOIN address a ON a.id = t.addressFk
|
JOIN address a ON a.id = t.addressFk
|
||||||
JOIN client c ON c.id = t.clientFk
|
JOIN client c ON c.id = t.clientFk
|
||||||
WHERE ISNULL(t.refFk) AND c.id >= ?
|
WHERE t.refFk IS NULL
|
||||||
AND (t.clientFk <= ? OR ? IS NULL)
|
|
||||||
AND t.shipped BETWEEN ? AND util.dayEnd(?)
|
AND t.shipped BETWEEN ? AND util.dayEnd(?)
|
||||||
AND t.companyFk = ?
|
AND t.companyFk = ?
|
||||||
AND c.hasToInvoice
|
AND c.hasToInvoice
|
||||||
AND c.isTaxDataChecked
|
AND c.isTaxDataChecked
|
||||||
AND c.isActive
|
AND c.isActive
|
||||||
AND NOT t.isDeleted
|
AND NOT t.isDeleted
|
||||||
GROUP BY c.id, IF(c.hasToInvoiceByAddress,a.id,TRUE) HAVING sumAmount > 0`;
|
GROUP BY c.id, IF(c.hasToInvoiceByAddress, a.id, TRUE)
|
||||||
|
HAVING totalAmount > 0;`;
|
||||||
|
|
||||||
return models.InvoiceOut.rawSql(query, [
|
return models.InvoiceOut.rawSql(query, [
|
||||||
args.fromClientId,
|
|
||||||
args.toClientId,
|
|
||||||
args.toClientId,
|
|
||||||
minShipped,
|
minShipped,
|
||||||
args.maxShipped,
|
args.maxShipped,
|
||||||
args.companyFk
|
args.companyFk
|
||||||
|
|
|
@ -127,6 +127,12 @@ module.exports = Self => {
|
||||||
invoiceId = newInvoice.id;
|
invoiceId = newInvoice.id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (tx) await tx.commit();
|
||||||
|
} catch (e) {
|
||||||
|
if (tx) await tx.rollback();
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
|
||||||
if (invoiceId && !invoiceOut.client().isToBeMailed) {
|
if (invoiceId && !invoiceOut.client().isToBeMailed) {
|
||||||
const query = `CALL vn.report_print(
|
const query = `CALL vn.report_print(
|
||||||
'invoice',
|
'invoice',
|
||||||
|
@ -135,13 +141,7 @@ module.exports = Self => {
|
||||||
JSON_OBJECT('refFk', ?),
|
JSON_OBJECT('refFk', ?),
|
||||||
'normal'
|
'normal'
|
||||||
);`;
|
);`;
|
||||||
await models.InvoiceOut.rawSql(query, [args.printerFk, invoiceOut.ref], myOptions);
|
await models.InvoiceOut.rawSql(query, [args.printerFk, invoiceOut.ref]);
|
||||||
}
|
|
||||||
|
|
||||||
if (tx) await tx.commit();
|
|
||||||
} catch (e) {
|
|
||||||
if (tx) await tx.rollback();
|
|
||||||
throw e;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (invoiceId && invoiceOut.client().isToBeMailed) {
|
if (invoiceId && invoiceOut.client().isToBeMailed) {
|
||||||
|
|
Loading…
Reference in New Issue