diff --git a/loopback/locale/es.json b/loopback/locale/es.json index 2c1a08f46..4b3bb95f8 100644 --- a/loopback/locale/es.json +++ b/loopback/locale/es.json @@ -253,5 +253,5 @@ "This receipt was not compensated": "Este recibo no ha sido compensado", "Client's email was not found": "No se encontró el email del cliente", "Aplicación bloqueada por el usuario 9": "Aplicación bloqueada por el usuario 9", - "Negative basis": "Negative basis" -} \ No newline at end of file + "Negative basis": "Base negativa" +} diff --git a/modules/invoiceOut/back/methods/invoiceOut/clientsToInvoice.js b/modules/invoiceOut/back/methods/invoiceOut/clientsToInvoice.js index d42184ae5..5b65a7565 100644 --- a/modules/invoiceOut/back/methods/invoiceOut/clientsToInvoice.js +++ b/modules/invoiceOut/back/methods/invoiceOut/clientsToInvoice.js @@ -60,9 +60,9 @@ module.exports = Self => { try { query = ` SELECT MAX(issued) issued - FROM vn.invoiceOut io - JOIN vn.time t ON t.dated = io.issued - WHERE io.serial = 'A' + FROM vn.invoiceOut io + JOIN vn.time t ON t.dated = io.issued + WHERE io.serial = 'A' AND t.year = YEAR(?) AND io.companyFk = ?`; const [maxIssued] = await Self.rawSql(query, [ @@ -103,7 +103,6 @@ module.exports = Self => { return { clientId: invoiceableClient.id, addressId: invoiceableClient.addressFk - }; } ); @@ -131,11 +130,11 @@ module.exports = Self => { const models = Self.app.models; const args = ctx.args; const query = `SELECT DISTINCT clientFk AS id - FROM ticket t + FROM ticket t JOIN ticketPackaging tp ON t.id = tp.ticketFk JOIN client c ON c.id = t.clientFk WHERE t.shipped BETWEEN '2017-11-21' AND ? - AND t.clientFk >= ? + AND t.clientFk >= ? AND (t.clientFk <= ? OR ? IS NULL) AND c.isActive`; return models.InvoiceOut.rawSql(query, [ @@ -156,9 +155,9 @@ module.exports = Self => { c.id, SUM(IFNULL ( - s.quantity * + s.quantity * s.price * (100-s.discount)/100, - 0) + 0) + IFNULL(ts.quantity * ts.price,0) ) AS sumAmount, c.hasToInvoiceByAddress, @@ -170,11 +169,14 @@ module.exports = Self => { 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 >= ? + 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 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`; return models.InvoiceOut.rawSql(query, [