From 699f19b0d4800488df42ed303473f34e15ef7ce1 Mon Sep 17 00:00:00 2001 From: vicent Date: Thu, 21 Jul 2022 10:05:37 +0200 Subject: [PATCH] refactor: change invoice id by refFk --- .../back/methods/invoiceOut/createPdf.js | 1 - .../invoiceOut/front/descriptor-menu/index.js | 8 ++-- print/methods/closure/closure.js | 4 +- print/methods/csv/invoice/download.js | 10 ++-- print/methods/csv/invoice/send.js | 14 +++--- print/methods/csv/invoice/sql/invoice.sql | 3 +- print/methods/csv/invoice/sql/sales.sql | 2 +- print/methods/schedule/invoice.js | 2 +- print/templates/email/invoice/invoice.js | 8 ++-- print/templates/email/invoice/sql/invoice.sql | 2 +- .../reports/exportation/exportation.js | 8 ++-- .../reports/exportation/sql/invoice.sql | 3 +- .../invoice-incoterms/invoice-incoterms.js | 20 ++++---- .../reports/invoice-incoterms/sql/client.sql | 3 +- .../invoice-incoterms/sql/incoterms.sql | 7 +-- .../reports/invoice-incoterms/sql/invoice.sql | 3 +- print/templates/reports/invoice/invoice.js | 46 +++++++++---------- .../templates/reports/invoice/sql/client.sql | 3 +- .../reports/invoice/sql/hasIncoterms.sql | 2 +- .../templates/reports/invoice/sql/invoice.sql | 3 +- .../reports/invoice/sql/rectified.sql | 3 +- print/templates/reports/invoice/sql/sales.sql | 4 +- print/templates/reports/invoice/sql/taxes.sql | 5 +- .../templates/reports/invoice/sql/tickets.sql | 2 +- 24 files changed, 85 insertions(+), 81 deletions(-) diff --git a/modules/invoiceOut/back/methods/invoiceOut/createPdf.js b/modules/invoiceOut/back/methods/invoiceOut/createPdf.js index 854c5d9e1..c2fdbcbba 100644 --- a/modules/invoiceOut/back/methods/invoiceOut/createPdf.js +++ b/modules/invoiceOut/back/methods/invoiceOut/createPdf.js @@ -61,7 +61,6 @@ module.exports = Self => { responseType: 'stream', params: { authorization: auth.id, - invoiceId: id, refFk: invoiceOut.ref } }).then(async response => { diff --git a/modules/invoiceOut/front/descriptor-menu/index.js b/modules/invoiceOut/front/descriptor-menu/index.js index 8d8a052cf..2b6d90ebf 100644 --- a/modules/invoiceOut/front/descriptor-menu/index.js +++ b/modules/invoiceOut/front/descriptor-menu/index.js @@ -84,7 +84,7 @@ class Controller extends Section { showCsvInvoice() { this.vnReport.showCsv('invoice', { recipientId: this.invoiceOut.client.id, - invoiceId: this.id + refFk: this.invoiceOut.ref }); } @@ -95,7 +95,7 @@ class Controller extends Section { return this.vnEmail.send('invoice', { recipientId: this.invoiceOut.client.id, recipient: $data.email, - invoiceId: this.id + refFk: this.invoiceOut.ref }); } @@ -106,14 +106,14 @@ class Controller extends Section { return this.vnEmail.sendCsv('invoice', { recipientId: this.invoiceOut.client.id, recipient: $data.email, - invoiceId: this.id + refFk: this.invoiceOut.ref }); } showExportationLetter() { this.vnReport.show('exportation', { recipientId: this.invoiceOut.client.id, - invoiceId: this.id + refFk: this.invoiceOut.ref }); } diff --git a/print/methods/closure/closure.js b/print/methods/closure/closure.js index c87a8e007..67a2538e8 100644 --- a/print/methods/closure/closure.js +++ b/print/methods/closure/closure.js @@ -31,7 +31,7 @@ module.exports = { if (invoiceOut) { const args = Object.assign({ - invoiceId: invoiceOut.id, + refFk: invoiceOut.ref, recipientId: ticket.clientFk, recipient: ticket.recipient, replyTo: ticket.salesPersonEmail @@ -118,7 +118,7 @@ module.exports = { await db.rawSql(` INSERT INTO clientSample (clientFk, typeFk, companyFk) VALUES(?, ?, ?) - `, [ticket.clientFk, sample.id, ticket.companyFk]) + `, [ticket.clientFk, sample.id, ticket.companyFk]); } } catch (error) { // Domain not found diff --git a/print/methods/csv/invoice/download.js b/print/methods/csv/invoice/download.js index 593d2d8d0..9cca99f2d 100644 --- a/print/methods/csv/invoice/download.js +++ b/print/methods/csv/invoice/download.js @@ -7,13 +7,13 @@ const sqlPath = path.join(__dirname, 'sql'); module.exports = async function(request, response, next) { try { const reqArgs = request.query; - if (!reqArgs.invoiceId) - throw new Error('The argument invoiceId is required'); + if (!reqArgs.refFk) + throw new Error('The argument refFk is required'); - const invoiceId = reqArgs.invoiceId; - const sales = await db.rawSqlFromDef(`${sqlPath}/sales`, [invoiceId]); + const refFk = reqArgs.refFk; + const sales = await db.rawSqlFromDef(`${sqlPath}/sales`, [refFk]); const content = toCSV(sales); - const fileName = `invoice_${invoiceId}.csv`; + const fileName = `invoice_${refFk}.csv`; response.setHeader('Content-type', 'text/csv'); response.setHeader('Content-Disposition', `inline; filename="${fileName}"`); diff --git a/print/methods/csv/invoice/send.js b/print/methods/csv/invoice/send.js index 919d7aeb1..2729e4a2b 100644 --- a/print/methods/csv/invoice/send.js +++ b/print/methods/csv/invoice/send.js @@ -8,22 +8,22 @@ const sqlPath = path.join(__dirname, 'sql'); module.exports = async function(request, response, next) { try { const reqArgs = request.query; - if (!reqArgs.invoiceId) - throw new Error('The argument invoiceId is required'); + if (!reqArgs.refFk) + throw new Error('The argument refFk is required'); - const invoiceId = reqArgs.invoiceId; - const invoice = await db.findOneFromDef(`${sqlPath}/invoice`, [invoiceId]); - const sales = await db.rawSqlFromDef(`${sqlPath}/sales`, [invoiceId]); + const refFk = reqArgs.refFk; + const invoice = await db.findOneFromDef(`${sqlPath}/invoice`, [refFk]); + const sales = await db.rawSqlFromDef(`${sqlPath}/sales`, [refFk]); const args = Object.assign({ - invoiceId: (String(invoice.id)), + refFk: invoice.refFk, recipientId: invoice.clientFk, recipient: invoice.recipient, replyTo: invoice.salesPersonEmail }, response.locals); const content = toCSV(sales); - const fileName = `invoice_${invoiceId}.csv`; + const fileName = `invoice_${refFk}.csv`; const email = new Email('invoice', args); await email.send({ overrideAttachments: true, diff --git a/print/methods/csv/invoice/sql/invoice.sql b/print/methods/csv/invoice/sql/invoice.sql index 853aaddc0..d484766a0 100644 --- a/print/methods/csv/invoice/sql/invoice.sql +++ b/print/methods/csv/invoice/sql/invoice.sql @@ -6,4 +6,5 @@ SELECT FROM invoiceOut io JOIN client c ON c.id = io.clientFk LEFT JOIN account.emailUser eu ON eu.userFk = c.salesPersonFk -WHERE io.id = ? \ No newline at end of file + LEFT JOIN ticket t ON t.refFk = io.ref +WHERE t.refFk = ? \ No newline at end of file diff --git a/print/methods/csv/invoice/sql/sales.sql b/print/methods/csv/invoice/sql/sales.sql index 34b5af1f7..33fe62476 100644 --- a/print/methods/csv/invoice/sql/sales.sql +++ b/print/methods/csv/invoice/sql/sales.sql @@ -31,5 +31,5 @@ FROM sale s AND itc.countryFk = s2.countryFk JOIN taxClass tc ON tc.id = itc.taxClassFk JOIN invoiceOut io ON io.ref = t.refFk -WHERE io.id = ? +WHERE t.refFk = ? ORDER BY s.ticketFk, s.created \ No newline at end of file diff --git a/print/methods/schedule/invoice.js b/print/methods/schedule/invoice.js index 7128cebbd..87c696075 100644 --- a/print/methods/schedule/invoice.js +++ b/print/methods/schedule/invoice.js @@ -38,7 +38,7 @@ module.exports = async function(request, response, next) { connection.query('START TRANSACTION'); const args = Object.assign({ - invoiceId: invoiceOut.id, + refFk: invoiceOut.ref, recipientId: invoiceOut.clientFk, recipient: invoiceOut.recipient, replyTo: invoiceOut.salesPersonEmail diff --git a/print/templates/email/invoice/invoice.js b/print/templates/email/invoice/invoice.js index d92b65cb3..6f6ea8683 100755 --- a/print/templates/email/invoice/invoice.js +++ b/print/templates/email/invoice/invoice.js @@ -5,11 +5,11 @@ const emailFooter = new Component('email-footer'); module.exports = { name: 'invoice', async serverPrefetch() { - this.invoice = await this.fetchInvoice(this.invoiceId); + this.invoice = await this.fetchInvoice(this.refFk); }, methods: { - fetchInvoice(invoiceId) { - return this.findOneFromDef('invoice', [invoiceId]); + fetchInvoice(refFk) { + return this.findOneFromDef('invoice', [refFk]); }, }, components: { @@ -17,7 +17,7 @@ module.exports = { 'email-footer': emailFooter.build() }, props: { - invoiceId: { + refFk: { type: [Number, String], required: true } diff --git a/print/templates/email/invoice/sql/invoice.sql b/print/templates/email/invoice/sql/invoice.sql index 195621a36..b6f845fb0 100644 --- a/print/templates/email/invoice/sql/invoice.sql +++ b/print/templates/email/invoice/sql/invoice.sql @@ -4,4 +4,4 @@ SELECT FROM invoiceOut io JOIN ticket t ON t.refFk = io.ref JOIN client c ON c.id = io.clientFk -WHERE io.id = ? \ No newline at end of file +WHERE t.refFk = ? \ No newline at end of file diff --git a/print/templates/reports/exportation/exportation.js b/print/templates/reports/exportation/exportation.js index fbf663249..a7e018c48 100755 --- a/print/templates/reports/exportation/exportation.js +++ b/print/templates/reports/exportation/exportation.js @@ -5,14 +5,14 @@ const reportFooter = new Component('report-footer'); module.exports = { name: 'exportation', async serverPrefetch() { - this.invoice = await this.fetchInvoice(this.invoiceId); + this.invoice = await this.fetchInvoice(this.refFk); if (!this.invoice) throw new Error('Something went wrong'); }, methods: { - fetchInvoice(invoiceId) { - return this.findOneFromDef('invoice', [invoiceId]); + fetchInvoice(refFk) { + return this.findOneFromDef('invoice', [refFk]); } }, computed: { @@ -27,7 +27,7 @@ module.exports = { 'report-footer': reportFooter.build() }, props: { - invoiceId: { + refFk: { type: [Number, String], required: true } diff --git a/print/templates/reports/exportation/sql/invoice.sql b/print/templates/reports/exportation/sql/invoice.sql index 8e92333dd..7ea55e481 100644 --- a/print/templates/reports/exportation/sql/invoice.sql +++ b/print/templates/reports/exportation/sql/invoice.sql @@ -3,4 +3,5 @@ SELECT io.ref, io.issued FROM invoiceOut io -WHERE io.id = ? \ No newline at end of file + LEFT JOIN ticket t ON t.refFk = io.ref +WHERE t.refFk = ? \ No newline at end of file diff --git a/print/templates/reports/invoice-incoterms/invoice-incoterms.js b/print/templates/reports/invoice-incoterms/invoice-incoterms.js index 99e23e15f..99a4e2e73 100755 --- a/print/templates/reports/invoice-incoterms/invoice-incoterms.js +++ b/print/templates/reports/invoice-incoterms/invoice-incoterms.js @@ -5,9 +5,9 @@ const reportFooter = new Component('report-footer'); module.exports = { name: 'invoice-incoterms', async serverPrefetch() { - this.invoice = await this.fetchInvoice(this.invoiceId); - this.client = await this.fetchClient(this.invoiceId); - this.incoterms = await this.fetchIncoterms(this.invoiceId); + this.invoice = await this.fetchInvoice(this.refFk); + this.client = await this.fetchClient(this.refFk); + this.incoterms = await this.fetchIncoterms(this.refFk); if (!this.invoice) throw new Error('Something went wrong'); @@ -16,14 +16,14 @@ module.exports = { }, methods: { - fetchInvoice(invoiceId) { - return this.findOneFromDef('invoice', [invoiceId]); + fetchInvoice(refFk) { + return this.findOneFromDef('invoice', [refFk]); }, - fetchClient(invoiceId) { - return this.findOneFromDef('client', [invoiceId]); + fetchClient(refFk) { + return this.findOneFromDef('client', [refFk]); }, - fetchIncoterms(invoiceId) { - return this.findOneFromDef('incoterms', [invoiceId, invoiceId, invoiceId]); + fetchIncoterms(refFk) { + return this.findOneFromDef('incoterms', [refFk, refFk, refFk]); } }, components: { @@ -31,7 +31,7 @@ module.exports = { 'report-footer': reportFooter.build() }, props: { - invoiceId: { + refFk: { type: [Number, String], required: true } diff --git a/print/templates/reports/invoice-incoterms/sql/client.sql b/print/templates/reports/invoice-incoterms/sql/client.sql index dd6035222..3e66c15c9 100644 --- a/print/templates/reports/invoice-incoterms/sql/client.sql +++ b/print/templates/reports/invoice-incoterms/sql/client.sql @@ -9,4 +9,5 @@ FROM vn.invoiceOut io JOIN vn.country cty ON cty.id = c.countryFk LEFT JOIN vn.invoiceOutSerial ios ON ios.code = io.serial AND ios.taxAreaFk = 'CEE' -WHERE io.id = ? \ No newline at end of file + LEFT JOIN ticket t ON t.refFk = io.ref +WHERE t.refFk = ? \ No newline at end of file diff --git a/print/templates/reports/invoice-incoterms/sql/incoterms.sql b/print/templates/reports/invoice-incoterms/sql/incoterms.sql index 5d894a4b2..6bb895129 100644 --- a/print/templates/reports/invoice-incoterms/sql/incoterms.sql +++ b/print/templates/reports/invoice-incoterms/sql/incoterms.sql @@ -51,7 +51,7 @@ SELECT io.issued, FROM vn.invoiceOut io JOIN vn.ticket t ON t.refFk = io.ref JOIN vn.saleVolume sv ON sv.ticketFk = t.id - WHERE io.id = ? + WHERE t.refFk = ? ) sub2 ON TRUE JOIN vn.itemTaxCountry itc ON itc.countryFk = su.countryFk AND itc.itemFk = s.itemFk JOIN vn.taxClass tc ON tc.id = itc.taxClassFk @@ -66,6 +66,7 @@ SELECT io.issued, JOIN vn.sale s ON t.id = s.ticketFk JOIN vn.item i ON i.id = s.itemFk JOIN vn.intrastat ir ON ir.id = i.intrastatFk - WHERE io.id = ? + WHERE t.refFk = ? )sub3 ON TRUE - WHERE io.id = ? + WHERE t.refFk = ? + diff --git a/print/templates/reports/invoice-incoterms/sql/invoice.sql b/print/templates/reports/invoice-incoterms/sql/invoice.sql index b9a929183..571ea2af3 100644 --- a/print/templates/reports/invoice-incoterms/sql/invoice.sql +++ b/print/templates/reports/invoice-incoterms/sql/invoice.sql @@ -14,4 +14,5 @@ FROM invoiceOut io JOIN company cny ON cny.id = io.companyFk JOIN supplierAccount sa ON sa.id = cny.supplierAccountFk LEFT JOIN invoiceOutSerial ios ON ios.code = io.serial -WHERE io.id = ? \ No newline at end of file + LEFT JOIN ticket t ON t.refFk = io.ref +WHERE t.refFk = ? \ No newline at end of file diff --git a/print/templates/reports/invoice/invoice.js b/print/templates/reports/invoice/invoice.js index 4571da0ff..fd4acd4b5 100755 --- a/print/templates/reports/invoice/invoice.js +++ b/print/templates/reports/invoice/invoice.js @@ -7,15 +7,15 @@ const invoiceIncoterms = new Report('invoice-incoterms'); module.exports = { name: 'invoice', async serverPrefetch() { - this.invoice = await this.fetchInvoice(this.invoiceId); - this.client = await this.fetchClient(this.invoiceId); - this.taxes = await this.fetchTaxes(this.invoiceId); + this.invoice = await this.fetchInvoice(this.refFk); + this.client = await this.fetchClient(this.refFk); + this.taxes = await this.fetchTaxes(this.refFk); this.intrastat = await this.fetchIntrastat(this.refFk); - this.rectified = await this.fetchRectified(this.invoiceId); - this.hasIncoterms = await this.fetchHasIncoterms(this.invoiceId); + this.rectified = await this.fetchRectified(this.refFk); + this.hasIncoterms = await this.fetchHasIncoterms(this.refFk); - const tickets = await this.fetchTickets(this.invoiceId); - const sales = await this.fetchSales(this.invoiceId); + const tickets = await this.fetchTickets(this.refFk); + const sales = await this.fetchSales(this.refFk); const map = new Map(); @@ -65,29 +65,29 @@ module.exports = { } }, methods: { - fetchInvoice(invoiceId) { - return this.findOneFromDef('invoice', [invoiceId]); + fetchInvoice(refFk) { + return this.findOneFromDef('invoice', [refFk]); }, - fetchClient(invoiceId) { - return this.findOneFromDef('client', [invoiceId]); + fetchClient(refFk) { + return this.findOneFromDef('client', [refFk]); }, - fetchTickets(invoiceId) { - return this.rawSqlFromDef('tickets', [invoiceId]); + fetchTickets(refFk) { + return this.rawSqlFromDef('tickets', [refFk]); }, - fetchSales(invoiceId) { - return this.rawSqlFromDef('sales', [invoiceId, invoiceId]); + fetchSales(refFk) { + return this.rawSqlFromDef('sales', [refFk, refFk]); }, - fetchTaxes(invoiceId) { - return this.rawSqlFromDef(`taxes`, [invoiceId]); + fetchTaxes(refFk) { + return this.rawSqlFromDef(`taxes`, [refFk]); }, fetchIntrastat(refFk) { return this.rawSqlFromDef(`intrastat`, [refFk, refFk, refFk]); }, - fetchRectified(invoiceId) { - return this.rawSqlFromDef(`rectified`, [invoiceId]); + fetchRectified(refFk) { + return this.rawSqlFromDef(`rectified`, [refFk]); }, - fetchHasIncoterms(invoiceId) { - return this.findValueFromDef(`hasIncoterms`, [invoiceId]); + fetchHasIncoterms(refFk) { + return this.findValueFromDef(`hasIncoterms`, [refFk]); }, saleImport(sale) { const price = sale.quantity * sale.price; @@ -115,10 +115,6 @@ module.exports = { 'invoice-incoterms': invoiceIncoterms.build() }, props: { - invoiceId: { - type: [Number, String], - required: true - }, refFk: { type: String } diff --git a/print/templates/reports/invoice/sql/client.sql b/print/templates/reports/invoice/sql/client.sql index dd6035222..4c35838f2 100644 --- a/print/templates/reports/invoice/sql/client.sql +++ b/print/templates/reports/invoice/sql/client.sql @@ -9,4 +9,5 @@ FROM vn.invoiceOut io JOIN vn.country cty ON cty.id = c.countryFk LEFT JOIN vn.invoiceOutSerial ios ON ios.code = io.serial AND ios.taxAreaFk = 'CEE' -WHERE io.id = ? \ No newline at end of file + LEFT JOIN vn.ticket t ON t.refFk = io.ref +WHERE t.refFk = ? \ No newline at end of file diff --git a/print/templates/reports/invoice/sql/hasIncoterms.sql b/print/templates/reports/invoice/sql/hasIncoterms.sql index 27f61f57c..40a6db384 100644 --- a/print/templates/reports/invoice/sql/hasIncoterms.sql +++ b/print/templates/reports/invoice/sql/hasIncoterms.sql @@ -3,6 +3,6 @@ SELECT IF(incotermsFk IS NULL, FALSE, TRUE) AS hasIncoterms JOIN invoiceOut io ON io.ref = t.refFk JOIN client c ON c.id = t.clientFk JOIN address a ON a.id = t.addressFk - WHERE io.id = ? + WHERE t.refFk = ? AND IF(c.hasToinvoiceByAddress = FALSE, c.defaultAddressFk, TRUE) LIMIT 1 \ No newline at end of file diff --git a/print/templates/reports/invoice/sql/invoice.sql b/print/templates/reports/invoice/sql/invoice.sql index aacbb0016..0f12e4f53 100644 --- a/print/templates/reports/invoice/sql/invoice.sql +++ b/print/templates/reports/invoice/sql/invoice.sql @@ -13,4 +13,5 @@ FROM invoiceOut io JOIN company cny ON cny.id = io.companyFk JOIN supplierAccount sa ON sa.id = cny.supplierAccountFk LEFT JOIN invoiceOutSerial ios ON ios.code = io.serial -WHERE io.id = ? \ No newline at end of file + LEFT JOIN ticket t ON t.refFk = io.ref +WHERE t.refFk = ? \ No newline at end of file diff --git a/print/templates/reports/invoice/sql/rectified.sql b/print/templates/reports/invoice/sql/rectified.sql index 1255b973c..ea814a05a 100644 --- a/print/templates/reports/invoice/sql/rectified.sql +++ b/print/templates/reports/invoice/sql/rectified.sql @@ -6,4 +6,5 @@ SELECT FROM vn.invoiceCorrection ic JOIN vn.invoiceOut io ON io.id = ic.correctedFk JOIN vn.invoiceCorrectionType ict ON ict.id = ic.invoiceCorrectionTypeFk -where ic.correctingFk = ? \ No newline at end of file + LEFT JOIN ticket t ON t.refFk = io.ref +WHERE t.refFk = ? \ No newline at end of file diff --git a/print/templates/reports/invoice/sql/sales.sql b/print/templates/reports/invoice/sql/sales.sql index cff8794db..f5721a594 100644 --- a/print/templates/reports/invoice/sql/sales.sql +++ b/print/templates/reports/invoice/sql/sales.sql @@ -37,7 +37,7 @@ SELECT JOIN vn.itemTaxCountry itc ON itc.countryFk = su.countryFk AND itc.itemFk = s.itemFk JOIN vn.taxClass tc ON tc.id = itc.taxClassFk - WHERE io.id = ? + WHERE t.refFk = ? UNION ALL SELECT io.ref, @@ -69,4 +69,4 @@ SELECT JOIN vn.company co ON co.id = io.companyFk JOIN vn.supplierAccount sa ON sa.id = co.supplierAccountFk JOIN vn.taxClass tc ON tc.id = ts.taxClassFk - WHERE io.id = ? \ No newline at end of file + WHERE t.refFk = ? \ No newline at end of file diff --git a/print/templates/reports/invoice/sql/taxes.sql b/print/templates/reports/invoice/sql/taxes.sql index 19b1cc00e..2203d8b8a 100644 --- a/print/templates/reports/invoice/sql/taxes.sql +++ b/print/templates/reports/invoice/sql/taxes.sql @@ -6,6 +6,7 @@ SELECT FROM invoiceOutTax iot JOIN pgc ON pgc.code = iot.pgcFk LEFT JOIN pgcEqu pe ON pe.equFk = pgc.code - JOIN invoiceOut io ON io.id = iot.invoiceOutFk - WHERE invoiceOutFk = ? + JOIN invoiceOut io ON io.id = iot.invoiceOutFk + LEFT JOIN ticket t ON t.refFk = io.ref + WHERE t.refFk = ? ORDER BY iot.id \ No newline at end of file diff --git a/print/templates/reports/invoice/sql/tickets.sql b/print/templates/reports/invoice/sql/tickets.sql index 7d135bd03..162f043e2 100644 --- a/print/templates/reports/invoice/sql/tickets.sql +++ b/print/templates/reports/invoice/sql/tickets.sql @@ -4,5 +4,5 @@ SELECT t.nickname FROM invoiceOut io JOIN ticket t ON t.refFk = io.ref -WHERE io.id = ? +WHERE t.refFk = ? ORDER BY t.shipped \ No newline at end of file