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;
|
||||
minShipped.setFullYear(minShipped.getFullYear() - 1);
|
||||
|
||||
const query = `SELECT
|
||||
c.id,
|
||||
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,
|
||||
a.id addressFk
|
||||
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 client c ON c.id = t.clientFk
|
||||
WHERE ISNULL(t.refFk) AND c.id >= ?
|
||||
AND (t.clientFk <= ? OR ? IS NULL)
|
||||
AND t.shipped BETWEEN ? AND util.dayEnd(?)
|
||||
AND t.companyFk = ?
|
||||
AND c.hasToInvoice
|
||||
AND c.isTaxDataChecked
|
||||
AND c.isActive
|
||||
AND NOT t.isDeleted
|
||||
GROUP BY c.id, IF(c.hasToInvoiceByAddress,a.id,TRUE) HAVING sumAmount > 0`;
|
||||
const query = `SELECT c.id,
|
||||
c.hasToInvoiceByAddress,
|
||||
a.id addressFk,
|
||||
sum(t.totalWithVat) totalAmount
|
||||
FROM ticket t
|
||||
JOIN address a ON a.id = t.addressFk
|
||||
JOIN client c ON c.id = t.clientFk
|
||||
WHERE t.refFk IS NULL
|
||||
AND t.shipped BETWEEN ? AND util.dayEnd(?)
|
||||
AND t.companyFk = ?
|
||||
AND c.hasToInvoice
|
||||
AND c.isTaxDataChecked
|
||||
AND c.isActive
|
||||
AND NOT t.isDeleted
|
||||
GROUP BY c.id, IF(c.hasToInvoiceByAddress, a.id, TRUE)
|
||||
HAVING totalAmount > 0;`;
|
||||
|
||||
return models.InvoiceOut.rawSql(query, [
|
||||
args.fromClientId,
|
||||
args.toClientId,
|
||||
args.toClientId,
|
||||
minShipped,
|
||||
args.maxShipped,
|
||||
args.companyFk
|
||||
|
|
|
@ -127,23 +127,23 @@ module.exports = Self => {
|
|||
invoiceId = newInvoice.id;
|
||||
}
|
||||
|
||||
if (invoiceId && !invoiceOut.client().isToBeMailed) {
|
||||
const query = `CALL vn.report_print(
|
||||
'invoice',
|
||||
?,
|
||||
account.myUser_getId(),
|
||||
JSON_OBJECT('refFk', ?),
|
||||
'normal'
|
||||
);`;
|
||||
await models.InvoiceOut.rawSql(query, [args.printerFk, invoiceOut.ref], myOptions);
|
||||
}
|
||||
|
||||
if (tx) await tx.commit();
|
||||
} catch (e) {
|
||||
if (tx) await tx.rollback();
|
||||
throw e;
|
||||
}
|
||||
|
||||
if (invoiceId && !invoiceOut.client().isToBeMailed) {
|
||||
const query = `CALL vn.report_print(
|
||||
'invoice',
|
||||
?,
|
||||
account.myUser_getId(),
|
||||
JSON_OBJECT('refFk', ?),
|
||||
'normal'
|
||||
);`;
|
||||
await models.InvoiceOut.rawSql(query, [args.printerFk, invoiceOut.ref]);
|
||||
}
|
||||
|
||||
if (invoiceId && invoiceOut.client().isToBeMailed) {
|
||||
ctx.args = {
|
||||
reference: invoiceOut.ref,
|
||||
|
|
Loading…
Reference in New Issue