diff --git a/modules/invoiceOut/front/locale/es.yml b/modules/invoiceOut/front/locale/es.yml index 9856dccfb..d21c9c23c 100644 --- a/modules/invoiceOut/front/locale/es.yml +++ b/modules/invoiceOut/front/locale/es.yml @@ -1,3 +1,2 @@ -Invoice out: Facturas -invoiceOut: factura +InvoiceOut: Facturas Search invoices by reference: Buscar facturas por referencia \ No newline at end of file diff --git a/modules/invoiceOut/front/routes.json b/modules/invoiceOut/front/routes.json index 8f828a634..7b733e29b 100644 --- a/modules/invoiceOut/front/routes.json +++ b/modules/invoiceOut/front/routes.json @@ -22,7 +22,7 @@ "url": "/index?q", "state": "invoiceOut.index", "component": "vn-invoice-out-index", - "description": "Invoice out" + "description": "InvoiceOut" }, { "url": "/summary", diff --git a/print/core/database.js b/print/core/database.js index a2e6e9573..578ae86d6 100644 --- a/print/core/database.js +++ b/print/core/database.js @@ -1,5 +1,7 @@ const mysql = require('mysql2/promise'); const config = require('./config.js'); +const fs = require('fs-extra'); +const path = require('path'); module.exports = { init() { @@ -10,6 +12,7 @@ module.exports = { }); } }, + /** * Makes a query from a raw sql * @param {String} query - The raw SQL query @@ -22,6 +25,22 @@ module.exports = { return rows; }); }, + + /** + * Makes a query from a SQL file + * @param {String} queryName - The SQL file name + * @param {Object} params - Parameterized values + * @param {Object} dirname - Referenced path + * + * @return {Object} - Result promise + */ + rawSqlFromDef(queryName, params, dirname = '.') { + const sqlPath = path.join(dirname, 'sql', `${queryName}.sql`); + const query = fs.readFileSync(sqlPath, 'utf8'); + + return this.rawSql(query, params); + }, + /** * Returns the first row from a given raw sql * @param {String} query - The raw SQL query @@ -32,6 +51,20 @@ module.exports = { findOne(query, params) { return this.rawSql(query, params).then(([row]) => row); }, + + /** + * Returns the first row from a given SQL file + * @param {String} queryName - The SQL file name + * @param {Object} params - Parameterized values + * @param {Object} dirname - Referenced path + * + * @return {Object} - Result promise + */ + findOneFromDef(queryName, params, dirname) { + return this.rawSqlFromDef(queryName, params, dirname) + .then(([row]) => row); + }, + /** * Returns the first property from a given raw sql * @param {String} query - The raw SQL query @@ -44,7 +77,42 @@ module.exports = { return Object.values(row)[0]; }); }, - findFromDef() { + /** + * Returns the first property from a given SQL file + * @param {String} queryName - The SQL file name + * @param {Object} params - Parameterized values + * @param {Object} dirname - Referenced path + * + * @return {Object} - Result promise + */ + findValueFromDef(queryName, params, dirname) { + return this.findOneFromDef(queryName, params, dirname).then(row => { + return Object.values(row)[0]; + }); + }, + + getCaller() { + let originalFunc = Error.prepareStackTrace; + let callerfile; + try { + const err = new Error(); + + Error.prepareStackTrace = function(err, stack) { + return stack; + }; + + const currentfile = err.stack.shift().getFileName(); + + while (err.stack.length) { + callerfile = err.stack.shift().getFileName(); + + if (currentfile !== callerfile) break; + } + } catch (e) {} + + Error.prepareStackTrace = originalFunc; + + return path.dirname(callerfile); } }; diff --git a/print/templates/email/client-welcome/client-welcome.js b/print/templates/email/client-welcome/client-welcome.js index 194c133bd..1a0624548 100755 --- a/print/templates/email/client-welcome/client-welcome.js +++ b/print/templates/email/client-welcome/client-welcome.js @@ -10,18 +10,7 @@ module.exports = { }, methods: { fetchClient(clientId) { - return db.findOne(` - SELECT - c.id, - u.name AS userName, - CONCAT(w.lastName, ' ', w.firstName) salesPersonName, - w.phone AS salesPersonPhone, - CONCAT(wu.name, '@verdnatura.es') AS salesPersonEmail - FROM client c - JOIN account.user u ON u.id = c.id - LEFT JOIN worker w ON w.id = c.salesPersonFk - LEFT JOIN account.user wu ON wu.id = w.userFk - WHERE c.id = ?`, [clientId]); + return db.findOneFromDef('client', [clientId], __dirname); }, }, components: { diff --git a/print/templates/email/client-welcome/sql/client.sql b/print/templates/email/client-welcome/sql/client.sql new file mode 100644 index 000000000..49e1d4bf6 --- /dev/null +++ b/print/templates/email/client-welcome/sql/client.sql @@ -0,0 +1,11 @@ +SELECT + c.id, + u.name AS userName, + CONCAT(w.lastName, ' ', w.firstName) salesPersonName, + w.phone AS salesPersonPhone, + CONCAT(wu.name, '@verdnatura.es') AS salesPersonEmail +FROM client c + JOIN account.user u ON u.id = c.id + LEFT JOIN worker w ON w.id = c.salesPersonFk + LEFT JOIN account.user wu ON wu.id = w.userFk +WHERE c.id = ? \ No newline at end of file diff --git a/print/templates/email/letter-debtor-nd/letter-debtor-nd.js b/print/templates/email/letter-debtor-nd/letter-debtor-nd.js index be7768608..fa10eaaaf 100755 --- a/print/templates/email/letter-debtor-nd/letter-debtor-nd.js +++ b/print/templates/email/letter-debtor-nd/letter-debtor-nd.js @@ -18,17 +18,7 @@ module.exports = { }, methods: { fetchDebtor(clientId, companyId) { - return db.findOne(` - SELECT - c.dueDay, - c.iban, - sa.iban, - be.name AS bankName - FROM client c - JOIN company AS cny - JOIN supplierAccount AS sa ON sa.id = cny.supplierAccountFk - JOIN bankEntity be ON be.id = sa.bankEntityFk - WHERE c.id = ? AND cny.id = ?`, [clientId, companyId]); + return db.findOneFromDef('client', [clientId, companyId], __dirname); } }, components: { diff --git a/print/templates/email/letter-debtor-nd/sql/client.sql b/print/templates/email/letter-debtor-nd/sql/client.sql new file mode 100644 index 000000000..1f672879b --- /dev/null +++ b/print/templates/email/letter-debtor-nd/sql/client.sql @@ -0,0 +1,10 @@ +SELECT + c.dueDay, + c.iban, + sa.iban, + be.name AS bankName +FROM client c + JOIN company AS cny + JOIN supplierAccount AS sa ON sa.id = cny.supplierAccountFk + JOIN bankEntity be ON be.id = sa.bankEntityFk +WHERE c.id = ? AND cny.id = ?` \ No newline at end of file diff --git a/print/templates/email/letter-debtor-st/letter-debtor-st.js b/print/templates/email/letter-debtor-st/letter-debtor-st.js index 51ed8b2ff..3f9039d17 100755 --- a/print/templates/email/letter-debtor-st/letter-debtor-st.js +++ b/print/templates/email/letter-debtor-st/letter-debtor-st.js @@ -18,17 +18,7 @@ module.exports = { }, methods: { fetchDebtor(clientId, companyId) { - return db.findOne(` - SELECT - c.dueDay, - c.iban, - sa.iban, - be.name AS bankName - FROM client c - JOIN company AS cny - JOIN supplierAccount AS sa ON sa.id = cny.supplierAccountFk - JOIN bankEntity be ON be.id = sa.bankEntityFk - WHERE c.id = ? AND cny.id = ?`, [clientId, companyId]); + return db.findOneFromDef('client', [clientId, companyId], __dirname); } }, components: { diff --git a/print/templates/email/letter-debtor-st/sql/client.sql b/print/templates/email/letter-debtor-st/sql/client.sql new file mode 100644 index 000000000..aad907a4b --- /dev/null +++ b/print/templates/email/letter-debtor-st/sql/client.sql @@ -0,0 +1,10 @@ +SELECT + c.dueDay, + c.iban, + sa.iban, + be.name AS bankName +FROM client c + JOIN company AS cny + JOIN supplierAccount AS sa ON sa.id = cny.supplierAccountFk + JOIN bankEntity be ON be.id = sa.bankEntityFk +WHERE c.id = ? AND cny.id = ? \ No newline at end of file diff --git a/print/templates/email/payment-update/payment-update.js b/print/templates/email/payment-update/payment-update.js index c74cf8694..249fb917f 100755 --- a/print/templates/email/payment-update/payment-update.js +++ b/print/templates/email/payment-update/payment-update.js @@ -18,15 +18,7 @@ module.exports = { }, methods: { fetchPayMethod(clientId) { - return db.findOne( - `SELECT - c.dueDay, - c.iban, - pm.name, - pm.code - FROM client c - JOIN payMethod pm ON pm.id = c.payMethodFk - WHERE c.id = :clientId`, {clientId: clientId}); + return db.findOneFromDef('payMethod', {clientId: clientId}, __dirname); } }, components: { diff --git a/print/templates/email/payment-update/sql/payMethod.sql b/print/templates/email/payment-update/sql/payMethod.sql new file mode 100644 index 000000000..775af01f1 --- /dev/null +++ b/print/templates/email/payment-update/sql/payMethod.sql @@ -0,0 +1,8 @@ +SELECT + c.dueDay, + c.iban, + pm.name, + pm.code +FROM client c + JOIN payMethod pm ON pm.id = c.payMethodFk +WHERE c.id = :clientId \ No newline at end of file diff --git a/print/templates/email/printer-setup/printer-setup.js b/print/templates/email/printer-setup/printer-setup.js index 4aa63587f..b15e14474 100755 --- a/print/templates/email/printer-setup/printer-setup.js +++ b/print/templates/email/printer-setup/printer-setup.js @@ -15,20 +15,7 @@ module.exports = { }, methods: { fetchClient(clientId) { - return db.findOne(` - SELECT - c.id, - u.lang locale, - u.name AS userName, - c.email recipient, - CONCAT(w.lastName, ' ', w.firstName) salesPersonName, - w.phone AS salesPersonPhone, - CONCAT(wu.name, '@verdnatura.es') AS salesPersonEmail - FROM client c - JOIN account.user u ON u.id = c.id - LEFT JOIN worker w ON w.id = c.salesPersonFk - LEFT JOIN account.user wu ON wu.id = w.userFk - WHERE c.id = ?`, [clientId]); + return db.findOneFromDef('client', [clientId], __dirname); } }, components: { diff --git a/print/templates/email/printer-setup/sql/client.sql b/print/templates/email/printer-setup/sql/client.sql new file mode 100644 index 000000000..2a8a751e0 --- /dev/null +++ b/print/templates/email/printer-setup/sql/client.sql @@ -0,0 +1,12 @@ +SELECT + c.id, + u.name AS userName, + c.email recipient, + CONCAT(w.lastName, ' ', w.firstName) salesPersonName, + w.phone AS salesPersonPhone, + CONCAT(wu.name, '@verdnatura.es') AS salesPersonEmail +FROM client c + JOIN account.user u ON u.id = c.id + LEFT JOIN worker w ON w.id = c.salesPersonFk + LEFT JOIN account.user wu ON wu.id = w.userFk +WHERE c.id = ? \ No newline at end of file diff --git a/print/templates/reports/campaign-metrics/campaign-metrics.js b/print/templates/reports/campaign-metrics/campaign-metrics.js index 420c1ffb1..e8bd317e8 100755 --- a/print/templates/reports/campaign-metrics/campaign-metrics.js +++ b/print/templates/reports/campaign-metrics/campaign-metrics.js @@ -14,44 +14,10 @@ module.exports = { }, methods: { fetchClient(clientId) { - return db.findOne( - `SELECT - c.street, - c.socialName, - c.city, - c.postcode, - c.id, - c.name AS clientName, - p.name AS province, - co.country - FROM client c - JOIN province p ON c.provinceFk = p.id - JOIN country co ON c.countryFk = co.id - WHERE - c.id = ?`, [clientId]); + return db.findOneFromDef('client', [clientId], __dirname); }, fetchSales(clientId, from, to) { - return db.rawSql( - `SELECT - SUM(s.quantity) AS subtotal, - s.itemFk, - s.concept, - i.subName, - i.tag5, - i.value5, - i.tag6, - i.value6, - i.tag7, - i.value7 - FROM sale s - JOIN ticket t ON t.id = s.ticketFk - JOIN item i ON i.id = s.itemFk - JOIN itemType it ON it.id = i.typeFk - WHERE - t.clientFk = ? AND it.isPackaging = FALSE - AND DATE(t.shipped) BETWEEN ? AND ? - GROUP BY s.itemFk - ORDER BY i.typeFk , i.name`, [clientId, from, to]); + return db.rawSqlFromDef('sales', [clientId, from, to], __dirname); }, }, components: { diff --git a/print/templates/reports/campaign-metrics/sql/client.sql b/print/templates/reports/campaign-metrics/sql/client.sql new file mode 100644 index 000000000..9f392c97e --- /dev/null +++ b/print/templates/reports/campaign-metrics/sql/client.sql @@ -0,0 +1,13 @@ +SELECT + c.street, + c.socialName, + c.city, + c.postcode, + c.id, + c.name AS clientName, + p.name AS province, + co.country +FROM client c + JOIN province p ON c.provinceFk = p.id + JOIN country co ON c.countryFk = co.id +WHERE c.id = ? \ No newline at end of file diff --git a/print/templates/reports/campaign-metrics/sql/sales.sql b/print/templates/reports/campaign-metrics/sql/sales.sql new file mode 100644 index 000000000..2daa72aaa --- /dev/null +++ b/print/templates/reports/campaign-metrics/sql/sales.sql @@ -0,0 +1,20 @@ +SELECT + SUM(s.quantity) AS subtotal, + s.itemFk, + s.concept, + i.subName, + i.tag5, + i.value5, + i.tag6, + i.value6, + i.tag7, + i.value7 +FROM sale s + JOIN ticket t ON t.id = s.ticketFk + JOIN item i ON i.id = s.itemFk + JOIN itemType it ON it.id = i.typeFk +WHERE + t.clientFk = ? AND it.isPackaging = FALSE + AND DATE(t.shipped) BETWEEN ? AND ? +GROUP BY s.itemFk +ORDER BY i.typeFk , i.name \ No newline at end of file diff --git a/print/templates/reports/claim-pickup-order/claim-pickup-order.js b/print/templates/reports/claim-pickup-order/claim-pickup-order.js index a18e6d0e0..fc25db35f 100755 --- a/print/templates/reports/claim-pickup-order/claim-pickup-order.js +++ b/print/templates/reports/claim-pickup-order/claim-pickup-order.js @@ -21,37 +21,10 @@ module.exports = { }, methods: { fetchClient(claimId) { - return db.findOne( - `SELECT - c.id, - c.socialName, - c.name, - c.fi, - a.city, - a.postalCode, - a.street, - a.nickname, - p.name AS province, - ct.country - FROM claim cl - JOIN client c ON c.id = cl.clientFk - JOIN account.user u ON u.id = c.id - JOIN country ct ON ct.id = c.countryFk - JOIN ticket t ON t.id = cl.ticketFk - JOIN address a ON a.id = t.addressFk - LEFT JOIN province p ON p.id = c.provinceFk - WHERE cl.id = ?`, [claimId]); + return db.findOneFromDef('client', [claimId], __dirname); }, fetchSales(claimId) { - return db.rawSql( - `SELECT - s.id, - s.quantity, - s.concept, - cb.quantity claimQuantity - FROM claimBeginning cb - JOIN sale s ON s.id = cb.saleFk - WHERE cb.claimFk = ?`, [claimId]); + return db.rawSqlFromDef('sales', [claimId], __dirname); }, }, components: { diff --git a/print/templates/reports/claim-pickup-order/sql/client.sql b/print/templates/reports/claim-pickup-order/sql/client.sql new file mode 100644 index 000000000..249857433 --- /dev/null +++ b/print/templates/reports/claim-pickup-order/sql/client.sql @@ -0,0 +1,19 @@ +SELECT + c.id, + c.socialName, + c.name, + c.fi, + a.city, + a.postalCode, + a.street, + a.nickname, + p.name AS province, + ct.country +FROM claim cl + JOIN client c ON c.id = cl.clientFk + JOIN account.user u ON u.id = c.id + JOIN country ct ON ct.id = c.countryFk + JOIN ticket t ON t.id = cl.ticketFk + JOIN address a ON a.id = t.addressFk + LEFT JOIN province p ON p.id = c.provinceFk +WHERE cl.id = ? \ No newline at end of file diff --git a/print/templates/reports/claim-pickup-order/sql/sales.sql b/print/templates/reports/claim-pickup-order/sql/sales.sql new file mode 100644 index 000000000..3257a559c --- /dev/null +++ b/print/templates/reports/claim-pickup-order/sql/sales.sql @@ -0,0 +1,8 @@ +SELECT + s.id, + s.quantity, + s.concept, + cb.quantity claimQuantity +FROM claimBeginning cb + JOIN sale s ON s.id = cb.saleFk +WHERE cb.claimFk = ? \ No newline at end of file diff --git a/print/templates/reports/delivery-note/assets/css/style.css b/print/templates/reports/delivery-note/assets/css/style.css index 04474d4c8..c6d2ab2bf 100644 --- a/print/templates/reports/delivery-note/assets/css/style.css +++ b/print/templates/reports/delivery-note/assets/css/style.css @@ -16,4 +16,8 @@ h3 { font-weight: 100; color: #555 +} + +.ticket-info { + font-size: 20px } \ No newline at end of file diff --git a/print/templates/reports/delivery-note/delivery-note.html b/print/templates/reports/delivery-note/delivery-note.html index 5c8dac8eb..22ce0eaa8 100644 --- a/print/templates/reports/delivery-note/delivery-note.html +++ b/print/templates/reports/delivery-note/delivery-note.html @@ -16,7 +16,7 @@

{{$t('title')}}

- +
diff --git a/print/templates/reports/delivery-note/delivery-note.js b/print/templates/reports/delivery-note/delivery-note.js index cdf355f60..e4ef9e26e 100755 --- a/print/templates/reports/delivery-note/delivery-note.js +++ b/print/templates/reports/delivery-note/delivery-note.js @@ -42,132 +42,30 @@ module.exports = { }, methods: { fetchClient(ticketId) { - return db.findOne( - `SELECT - c.id, - c.socialName, - c.street, - c.fi - FROM ticket t - JOIN client c ON c.id = t.clientFk - WHERE t.id = ?`, [ticketId]); + return db.findOneFromDef('getClient', [ticketId], __dirname); }, fetchTicket(ticketId) { - return db.findOne( - `SELECT - t.id, - t.shipped, - c.code companyCode - FROM ticket t - JOIN company c ON c.id = t.companyFk - WHERE t.id = ?`, [ticketId]); + return db.findOneFromDef('getTicket', [ticketId], __dirname); }, fetchAddress(ticketId) { - return db.findOne( - `SELECT - a.nickname, - a.street, - a.postalCode, - a.city, - p.name province - FROM ticket t - JOIN address a ON a.clientFk = t.clientFk - AND a.id = t.addressFk - LEFT JOIN province p ON p.id = a.provinceFk - WHERE t.id = ?`, [ticketId]); - }, - - fetchSales(ticketId) { - return db.rawSql( - `SELECT - s.id, - s.itemFk, - s.concept, - s.quantity, - s.price, - s.price - SUM(IF(ctr.id = 6, - sc.value, - 0)) netPrice, - s.discount, - i.size, - i.stems, - i.category, - it.id itemTypeId, - o.code AS origin, - i.inkFk, - s.ticketFk, - tcl.code vatType, - ibwg.ediBotanic, ppa.denomination, pp.number passportNumber, - be.isProtectedZone, c.code AS countryCode, - i.tag5, i.value5, - i.tag6, i.value6, i.tag7, i.value7 - FROM vn.sale s - LEFT JOIN saleComponent sc ON sc.saleFk = s.id - LEFT JOIN component cr ON cr.id = sc.componentFk - LEFT JOIN componentType ctr ON ctr.id = cr.typeFk - LEFT JOIN item i ON i.id = s.itemFk - LEFT JOIN ticket t ON t.id = s.ticketFk - LEFT JOIN origin o ON o.id = i.originFk - LEFT JOIN country c ON c.id = o.countryFk - LEFT JOIN supplier sp ON sp.id = t.companyFk - LEFT JOIN itemType it ON it.id = i.typeFk - LEFT JOIN itemTaxCountry itc ON itc.itemFk = i.id - AND itc.countryFk = sp.countryFk - LEFT JOIN taxClass tcl ON tcl.id = itc.taxClassFk - LEFT JOIN plantpassport pp ON pp.producerFk = i.producerFk - LEFT JOIN plantpassportAuthority ppa ON ppa.id = pp.plantpassportAuthorityFk - LEFT JOIN itemBotanicalWithGenus ibwg ON ibwg.itemFk = i.id - LEFT JOIN botanicExport be ON be.restriction = 'pasaporte fitosanitario' - LEFT JOIN ediGenus eg ON eg.id = be.ediGenusFk - LEFT JOIN ediSpecie es ON es.id = be.ediSpecieFk - AND ibwg.ediBotanic LIKE CONCAT( - IFNULL(eg.latinGenusName, ''), - IF(es.latinSpeciesName > '', - CONCAT(' ', es.latinSpeciesName), ''), - '%') - WHERE s.ticketFk = ? - GROUP BY s.id - ORDER BY (it.isPackaging), s.concept, s.itemFk`, [ticketId]); - }, - fetchTaxes(ticketId) { - return db.rawSql(`CALL vn.ticketGetTaxAdd(?)`, [ticketId]).then(rows => { - return rows[0]; - }); - }, - fetchPackagings(ticketId) { - return db.rawSql( - `SELECT - tp.quantity, - i.name, - p.itemFk - FROM ticketPackaging tp - JOIN packaging p ON p.id = tp.packagingFk - JOIN item i ON i.id = p.itemFk - WHERE tp.ticketFk = ? - ORDER BY itemFk`, [ticketId]); - }, - fetchServices(ticketId) { - return db.rawSql( - `SELECT - tc.description taxDescription, - ts.description, - ts.quantity, - ts.price - FROM ticketService ts - JOIN taxClass tc ON tc.id = ts.taxClassFk - WHERE ts.ticketFk = ?`, [ticketId]); + return db.findOneFromDef(`getAddress`, [ticketId], __dirname); }, fetchSignature(ticketId) { - return db.findOne( - `SELECT - d.id, - d.created - FROM ticket t - JOIN ticketDms dt ON dt.ticketFk = t.id - JOIN dms d ON d.id = dt.dmsFk - AND d.file LIKE '%.png' - WHERE t.id = ?`, [ticketId]); + return db.findOneFromDef('getSignature', [ticketId], __dirname); }, + fetchTaxes(ticketId) { + return db.findOneFromDef(`getTaxes`, [ticketId], __dirname); + }, + fetchSales(ticketId) { + return db.rawSqlFromDef('getSales', [ticketId], __dirname); + }, + fetchPackagings(ticketId) { + return db.rawSqlFromDef('getPackagings', [ticketId], __dirname); + }, + fetchServices(ticketId) { + return db.rawSqlFromDef('getServices', [ticketId], __dirname); + }, + getSubTotal() { let subTotal = 0.00; this.sales.forEach(sale => { @@ -194,7 +92,7 @@ module.exports = { }, getTotal() { return this.getTotalBase() + this.getTotalTax(); - }, + } }, components: { 'report-header': reportHeader.build(), diff --git a/print/templates/reports/delivery-note/sql/getAddress.sql b/print/templates/reports/delivery-note/sql/getAddress.sql new file mode 100644 index 000000000..86414635a --- /dev/null +++ b/print/templates/reports/delivery-note/sql/getAddress.sql @@ -0,0 +1,11 @@ +SELECT + a.nickname, + a.street, + a.postalCode, + a.city, + p.name province +FROM ticket t + JOIN address a ON a.clientFk = t.clientFk + AND a.id = t.addressFk + LEFT JOIN province p ON p.id = a.provinceFk +WHERE t.id = ? \ No newline at end of file diff --git a/print/templates/reports/delivery-note/sql/getClient.sql b/print/templates/reports/delivery-note/sql/getClient.sql new file mode 100644 index 000000000..5318a98c7 --- /dev/null +++ b/print/templates/reports/delivery-note/sql/getClient.sql @@ -0,0 +1,8 @@ +SELECT + c.id, + c.socialName, + c.street, + c.fi +FROM ticket t + JOIN client c ON c.id = t.clientFk +WHERE t.id = ? \ No newline at end of file diff --git a/print/templates/reports/delivery-note/sql/getPackagings.sql b/print/templates/reports/delivery-note/sql/getPackagings.sql new file mode 100644 index 000000000..75a82a0aa --- /dev/null +++ b/print/templates/reports/delivery-note/sql/getPackagings.sql @@ -0,0 +1,9 @@ +SELECT + tp.quantity, + i.name, + p.itemFk +FROM ticketPackaging tp + JOIN packaging p ON p.id = tp.packagingFk + JOIN item i ON i.id = p.itemFk +WHERE tp.ticketFk = ? +ORDER BY itemFk \ No newline at end of file diff --git a/print/templates/reports/delivery-note/sql/getSales.sql b/print/templates/reports/delivery-note/sql/getSales.sql new file mode 100644 index 000000000..a563c19f0 --- /dev/null +++ b/print/templates/reports/delivery-note/sql/getSales.sql @@ -0,0 +1,53 @@ +SELECT + s.id, + s.itemFk, + s.concept, + s.quantity, + s.price, + s.price - SUM(IF(ctr.id = 6, sc.value, 0)) netPrice, + s.discount, + i.size, + i.stems, + i.category, + it.id itemTypeId, + o.code AS origin, + i.inkFk, + s.ticketFk, + tcl.code vatType, + ibwg.ediBotanic, + ppa.denomination, + pp.number passportNumber, + be.isProtectedZone, c.code AS countryCode, + i.tag5, + i.value5, + i.tag6, + i.value6, + i.tag7, + i.value7 +FROM vn.sale s + LEFT JOIN saleComponent sc ON sc.saleFk = s.id + LEFT JOIN component cr ON cr.id = sc.componentFk + LEFT JOIN componentType ctr ON ctr.id = cr.typeFk + LEFT JOIN item i ON i.id = s.itemFk + LEFT JOIN ticket t ON t.id = s.ticketFk + LEFT JOIN origin o ON o.id = i.originFk + LEFT JOIN country c ON c.id = o.countryFk + LEFT JOIN supplier sp ON sp.id = t.companyFk + LEFT JOIN itemType it ON it.id = i.typeFk + LEFT JOIN itemTaxCountry itc ON itc.itemFk = i.id + AND itc.countryFk = sp.countryFk + LEFT JOIN taxClass tcl ON tcl.id = itc.taxClassFk + LEFT JOIN plantpassport pp ON pp.producerFk = i.producerFk + LEFT JOIN plantpassportAuthority ppa ON ppa.id = pp.plantpassportAuthorityFk + LEFT JOIN itemBotanicalWithGenus ibwg ON ibwg.itemFk = i.id + LEFT JOIN botanicExport be ON be.restriction = 'pasaporte fitosanitario' + LEFT JOIN ediGenus eg ON eg.id = be.ediGenusFk + LEFT JOIN ediSpecie es ON es.id = be.ediSpecieFk + AND ibwg.ediBotanic LIKE CONCAT( + IFNULL(eg.latinGenusName, ''), + IF(es.latinSpeciesName > '', + CONCAT(' ', es.latinSpeciesName), ''), + '%') +WHERE s.ticketFk = ? +GROUP BY s.id +ORDER BY (it.isPackaging), s.concept, s.itemFk \ No newline at end of file diff --git a/print/templates/reports/delivery-note/sql/getServices.sql b/print/templates/reports/delivery-note/sql/getServices.sql new file mode 100644 index 000000000..fbb4a53c4 --- /dev/null +++ b/print/templates/reports/delivery-note/sql/getServices.sql @@ -0,0 +1,8 @@ +SELECT + tc.description taxDescription, + ts.description, + ts.quantity, + ts.price +FROM ticketService ts + JOIN taxClass tc ON tc.id = ts.taxClassFk +WHERE ts.ticketFk = ? \ No newline at end of file diff --git a/print/templates/reports/delivery-note/sql/getSignature.sql b/print/templates/reports/delivery-note/sql/getSignature.sql new file mode 100644 index 000000000..2eb83b3ac --- /dev/null +++ b/print/templates/reports/delivery-note/sql/getSignature.sql @@ -0,0 +1,8 @@ +SELECT + d.id, + d.created +FROM ticket t + JOIN ticketDms dt ON dt.ticketFk = t.id + JOIN dms d ON d.id = dt.dmsFk + AND d.file LIKE '%.png' +WHERE t.id = ? \ No newline at end of file diff --git a/print/templates/reports/delivery-note/sql/getTaxes.sql b/print/templates/reports/delivery-note/sql/getTaxes.sql new file mode 100644 index 000000000..47e3b825f --- /dev/null +++ b/print/templates/reports/delivery-note/sql/getTaxes.sql @@ -0,0 +1 @@ +CALL vn.ticketGetTaxAdd(?) \ No newline at end of file diff --git a/print/templates/reports/delivery-note/sql/getTicket.sql b/print/templates/reports/delivery-note/sql/getTicket.sql new file mode 100644 index 000000000..ccc3f9d25 --- /dev/null +++ b/print/templates/reports/delivery-note/sql/getTicket.sql @@ -0,0 +1,7 @@ +SELECT + t.id, + t.shipped, + c.code companyCode +FROM ticket t + JOIN company c ON c.id = t.companyFk +WHERE t.id = ? \ No newline at end of file diff --git a/print/templates/reports/driver-route/driver-route.js b/print/templates/reports/driver-route/driver-route.js index 0f8461046..a3f906864 100755 --- a/print/templates/reports/driver-route/driver-route.js +++ b/print/templates/reports/driver-route/driver-route.js @@ -28,60 +28,10 @@ module.exports = { }, methods: { fetchRoutes(routesId) { - return db.rawSql( - `SELECT - r.id, - r.m3, - r.created, - r.time, - u.nickName userNickName, - v.tradeMark vehicleTradeMark, - v.model vehicleModel, - v.numberPlate plateNumber, - am.name agencyName - FROM route r - LEFT JOIN vehicle v ON v.id = r.vehicleFk - LEFT JOIN worker w ON w.id = r.workerFk - LEFT JOIN account.user u ON u.id = w.userFk - LEFT JOIN agencyMode am ON am.id = r.agencyModeFk - WHERE r.id IN(:routesId)`, {routesId}); + return db.rawSqlFromDef('routes', {routesId}, __dirname); }, fetchTickets(routesId) { - return db.rawSql( - `SELECT - t.nickname addressName, - t.packages, - t.priority, - t.id, - t.clientFk, - t.companyFk, - t.routeFk, - if(a.phone, a.phone, c.phone) AS phone, - if(a.mobile, a.mobile, c.mobile) AS mobile, - wh.name warehouseName, - a.city, - a.street, - a.postalCode, - LPAD(a.id, 5, '0') AS addressFk, - p.name province, - 0 AS import, - am.name ticketAgency, - tob.description, - s.shipFk, - u.nickName salesPersonName - FROM route r - LEFT JOIN ticket t ON t.routeFk = r.id - LEFT JOIN address a ON a.id = t.addressFk - LEFT JOIN client c ON c.id = t.clientFk - LEFT JOIN worker w ON w.id = client_getSalesPerson(t.clientFk, CURDATE()) - LEFT JOIN account.user u ON u.id = w.userFk - LEFT JOIN ticketObservation tob ON tob.ticketFk = t.id AND tob.observationTypeFk = 3 - LEFT JOIN province p ON a.provinceFk = p.id - LEFT JOIN warehouse wh ON wh.id = t.warehouseFk - LEFT JOIN agencyMode am ON am.id = t.agencyModeFk - LEFT JOIN stowaway s ON s.id = t.id - WHERE r.id IN(:routesId) - ORDER BY t.priority, t.id`, {routesId}); + return db.rawSqlFromDef('tickets', {routesId}, __dirname); } }, components: { diff --git a/print/templates/reports/driver-route/sql/routes.sql b/print/templates/reports/driver-route/sql/routes.sql new file mode 100644 index 000000000..7c5278d01 --- /dev/null +++ b/print/templates/reports/driver-route/sql/routes.sql @@ -0,0 +1,16 @@ +SELECT + r.id, + r.m3, + r.created, + r.time, + u.nickName userNickName, + v.tradeMark vehicleTradeMark, + v.model vehicleModel, + v.numberPlate plateNumber, + am.name agencyName +FROM route r + LEFT JOIN vehicle v ON v.id = r.vehicleFk + LEFT JOIN worker w ON w.id = r.workerFk + LEFT JOIN account.user u ON u.id = w.userFk + LEFT JOIN agencyMode am ON am.id = r.agencyModeFk +WHERE r.id IN(:routesId) \ No newline at end of file diff --git a/print/templates/reports/driver-route/sql/tickets.sql b/print/templates/reports/driver-route/sql/tickets.sql new file mode 100644 index 000000000..910a1ed55 --- /dev/null +++ b/print/templates/reports/driver-route/sql/tickets.sql @@ -0,0 +1,34 @@ +SELECT + t.nickname addressName, + t.packages, + t.priority, + t.id, + t.clientFk, + t.companyFk, + t.routeFk, + if(a.phone, a.phone, c.phone) AS phone, + if(a.mobile, a.mobile, c.mobile) AS mobile, + wh.name warehouseName, + a.city, + a.street, + a.postalCode, + LPAD(a.id, 5, '0') AS addressFk, + p.name province, + 0 AS import, + am.name ticketAgency, + tob.description, + s.shipFk, + u.nickName salesPersonName +FROM route r + LEFT JOIN ticket t ON t.routeFk = r.id + LEFT JOIN address a ON a.id = t.addressFk + LEFT JOIN client c ON c.id = t.clientFk + LEFT JOIN worker w ON w.id = client_getSalesPerson(t.clientFk, CURDATE()) + LEFT JOIN account.user u ON u.id = w.userFk + LEFT JOIN ticketObservation tob ON tob.ticketFk = t.id AND tob.observationTypeFk = 3 + LEFT JOIN province p ON a.provinceFk = p.id + LEFT JOIN warehouse wh ON wh.id = t.warehouseFk + LEFT JOIN agencyMode am ON am.id = t.agencyModeFk + LEFT JOIN stowaway s ON s.id = t.id +WHERE r.id IN(:routesId) +ORDER BY t.priority, t.id \ No newline at end of file diff --git a/print/templates/reports/entry-order/entry-order.js b/print/templates/reports/entry-order/entry-order.js index 55492fbaf..654ba3460 100755 --- a/print/templates/reports/entry-order/entry-order.js +++ b/print/templates/reports/entry-order/entry-order.js @@ -18,50 +18,13 @@ module.exports = { }, methods: { fetchSupplier(entryId) { - return db.findOne( - `SELECT - s.name, - s.street, - s.nif, - s.postCode, - s.city, - p.name province - FROM supplier s - JOIN entry e ON e.supplierFk = s.id - LEFT JOIN province p ON p.id = s.provinceFk - WHERE e.id = ?`, [entryId]); + return db.findOneFromDef('supplier', [entryId], __dirname); }, fetchEntry(entryId) { - return db.findOne( - `SELECT - e.id, - e.ref, - e.notes, - c.code companyCode, - t.landed - FROM entry e - JOIN travel t ON t.id = e.travelFk - JOIN company c ON c.id = e.companyFk - WHERE e.id = ?`, [entryId]); + return db.findOneFromDef('entry', [entryId], __dirname); }, fetchBuys(entryId) { - return db.rawSql( - `SELECT - b.itemFk, - b.quantity, - b.buyingValue, - b.stickers box, - b.packing, - i.name itemName, - i.tag5, - i.value5, - i.tag6, - i.value6, - i.tag7, - i.value7 - FROM buy b - JOIN item i ON i.id = b.itemFk - WHERE b.entryFk = ?`, [entryId]); + return db.rawSqlFromDef('buys', [entryId], __dirname); }, getTotal() { let total = 0.00; diff --git a/print/templates/reports/entry-order/sql/buys.sql b/print/templates/reports/entry-order/sql/buys.sql new file mode 100644 index 000000000..5bf9f2dfe --- /dev/null +++ b/print/templates/reports/entry-order/sql/buys.sql @@ -0,0 +1,16 @@ +SELECT + b.itemFk, + b.quantity, + b.buyingValue, + b.stickers box, + b.packing, + i.name itemName, + i.tag5, + i.value5, + i.tag6, + i.value6, + i.tag7, + i.value7 +FROM buy b + JOIN item i ON i.id = b.itemFk +WHERE b.entryFk = ? \ No newline at end of file diff --git a/print/templates/reports/entry-order/sql/entry.sql b/print/templates/reports/entry-order/sql/entry.sql new file mode 100644 index 000000000..44feaae01 --- /dev/null +++ b/print/templates/reports/entry-order/sql/entry.sql @@ -0,0 +1,10 @@ +SELECT + e.id, + e.ref, + e.notes, + c.code companyCode, + t.landed +FROM entry e + JOIN travel t ON t.id = e.travelFk + JOIN company c ON c.id = e.companyFk +WHERE e.id = ? \ No newline at end of file diff --git a/print/templates/reports/entry-order/sql/supplier.sql b/print/templates/reports/entry-order/sql/supplier.sql new file mode 100644 index 000000000..11a2bc602 --- /dev/null +++ b/print/templates/reports/entry-order/sql/supplier.sql @@ -0,0 +1,11 @@ +SELECT + s.name, + s.street, + s.nif, + s.postCode, + s.city, + p.name province +FROM supplier s + JOIN entry e ON e.supplierFk = s.id + LEFT JOIN province p ON p.id = s.provinceFk +WHERE e.id = ? \ No newline at end of file diff --git a/print/templates/reports/item-label/item-label.js b/print/templates/reports/item-label/item-label.js index 60139bbb2..111d5a4a0 100755 --- a/print/templates/reports/item-label/item-label.js +++ b/print/templates/reports/item-label/item-label.js @@ -30,26 +30,10 @@ module.exports = { }, methods: { fetchItem(id, warehouseId) { - return db.findOne( - `SELECT - i.id, - i.name, - i.stems, - i.size, - b.packing - FROM vn.item i - JOIN cache.last_buy clb ON clb.item_id = i.id - JOIN vn.buy b ON b.id = clb.buy_id - JOIN vn.entry e ON e.id = b.entryFk - WHERE i.id = ? AND clb.warehouse_id = ?`, [id, warehouseId]); + return db.findOneFromDef('item', [id, warehouseId], __dirname); }, fetchItemTags(itemId) { - return db.rawSql( - `SELECT t.code, t.name, it.value - FROM vn.itemTag it - JOIN vn.tag t ON t.id = it.tagFk - WHERE it.itemFk = ? - `, [itemId]).then(rows => { + return db.rawSqlFromDef('itemTags', [itemId], __dirname).then(rows => { const tags = {}; rows.forEach(row => tags[row.code] = row.value); diff --git a/print/templates/reports/item-label/sql/item.sql b/print/templates/reports/item-label/sql/item.sql new file mode 100644 index 000000000..4b042c320 --- /dev/null +++ b/print/templates/reports/item-label/sql/item.sql @@ -0,0 +1,11 @@ +SELECT + i.id, + i.name, + i.stems, + i.size, + b.packing +FROM vn.item i + JOIN cache.last_buy clb ON clb.item_id = i.id + JOIN vn.buy b ON b.id = clb.buy_id + JOIN vn.entry e ON e.id = b.entryFk +WHERE i.id = ? AND clb.warehouse_id = ? \ No newline at end of file diff --git a/print/templates/reports/item-label/sql/itemTags.sql b/print/templates/reports/item-label/sql/itemTags.sql new file mode 100644 index 000000000..3c20098a6 --- /dev/null +++ b/print/templates/reports/item-label/sql/itemTags.sql @@ -0,0 +1,4 @@ +SELECT t.code, t.name, it.value +FROM vn.itemTag it + JOIN vn.tag t ON t.id = it.tagFk +WHERE it.itemFk = ? \ No newline at end of file diff --git a/print/templates/reports/letter-debtor/letter-debtor.js b/print/templates/reports/letter-debtor/letter-debtor.js index 7da1b438c..2afc96b46 100755 --- a/print/templates/reports/letter-debtor/letter-debtor.js +++ b/print/templates/reports/letter-debtor/letter-debtor.js @@ -24,29 +24,13 @@ module.exports = { }, methods: { fetchClient(clientId) { - return db.findOne( - `SELECT - c.id, - c.socialName, - c.street, - c.postcode, - c.city, - c.fi, - p.name AS province, - ct.country - FROM client c - JOIN country ct ON ct.id = c.countryFk - LEFT JOIN province p ON p.id = c.provinceFk - WHERE c.id = ?`, [clientId]); + return db.findOneFromDef('client', [clientId], __dirname); }, fetchSales(clientId, companyId) { - return db.rawSql( - `CALL vn.clientGetDebtDiary(:clientId, :companyId)`, { - clientId: clientId, - companyId: companyId, - }).then(rows => { - return rows[0]; - }); + return db.findOneFromDef('sales', { + clientId: clientId, + companyId: companyId, + }, __dirname); }, getBalance(sale) { if (sale.debtOut) diff --git a/print/templates/reports/letter-debtor/sql/client.sql b/print/templates/reports/letter-debtor/sql/client.sql new file mode 100644 index 000000000..d675cf168 --- /dev/null +++ b/print/templates/reports/letter-debtor/sql/client.sql @@ -0,0 +1,13 @@ +SELECT + c.id, + c.socialName, + c.street, + c.postcode, + c.city, + c.fi, + p.name AS province, + ct.country +FROM client c + JOIN country ct ON ct.id = c.countryFk + LEFT JOIN province p ON p.id = c.provinceFk +WHERE c.id = ? \ No newline at end of file diff --git a/print/templates/reports/letter-debtor/sql/sales.sql b/print/templates/reports/letter-debtor/sql/sales.sql new file mode 100644 index 000000000..3bf7db965 --- /dev/null +++ b/print/templates/reports/letter-debtor/sql/sales.sql @@ -0,0 +1 @@ +CALL vn.clientGetDebtDiary(:clientId, :companyId) \ No newline at end of file diff --git a/print/templates/reports/receipt/receipt.js b/print/templates/reports/receipt/receipt.js index 1b220bdda..7ba7f5afe 100755 --- a/print/templates/reports/receipt/receipt.js +++ b/print/templates/reports/receipt/receipt.js @@ -14,27 +14,10 @@ module.exports = { }, methods: { fetchClient(receiptId) { - return db.findOne( - `SELECT - c.id, - c.socialName, - u.lang locale - FROM receipt r - JOIN client c ON c.id = r.clientFk - JOIN account.user u ON u.id = c.id - WHERE r.id = ?`, [receiptId]); + return db.findOneFromDef('client', [receiptId], __dirname); }, fetchReceipt(receiptId) { - return db.findOne( - `SELECT - r.id, - r.amountPaid, - r.amountUnpaid, - r.payed, - r.companyFk - FROM receipt r - JOIN client c ON c.id = r.clientFk - WHERE r.id = ?`, [receiptId]); + return db.findOneFromDef('receipt', [receiptId], __dirname); } }, components: { diff --git a/print/templates/reports/receipt/sql/client.sql b/print/templates/reports/receipt/sql/client.sql new file mode 100644 index 000000000..e4029170e --- /dev/null +++ b/print/templates/reports/receipt/sql/client.sql @@ -0,0 +1,8 @@ +SELECT + c.id, + c.socialName, + u.lang locale +FROM receipt r + JOIN client c ON c.id = r.clientFk + JOIN account.user u ON u.id = c.id +WHERE r.id = ? \ No newline at end of file diff --git a/print/templates/reports/receipt/sql/receipt.sql b/print/templates/reports/receipt/sql/receipt.sql new file mode 100644 index 000000000..9b3919495 --- /dev/null +++ b/print/templates/reports/receipt/sql/receipt.sql @@ -0,0 +1,9 @@ +SELECT + r.id, + r.amountPaid, + r.amountUnpaid, + r.payed, + r.companyFk +FROM receipt r + JOIN client c ON c.id = r.clientFk +WHERE r.id = ? \ No newline at end of file diff --git a/print/templates/reports/sepa-core/sepa-core.js b/print/templates/reports/sepa-core/sepa-core.js index 0c6020210..f315397c2 100755 --- a/print/templates/reports/sepa-core/sepa-core.js +++ b/print/templates/reports/sepa-core/sepa-core.js @@ -21,46 +21,10 @@ const rptSepaCore = { }, methods: { fetchClient(clientId, companyId) { - return db.findOne( - `SELECT - c.id, - m.code mandateCode, - c.socialName, - c.street, - c.postcode, - c.city, - c.fi, - p.name AS province, - ct.country, - ct.code AS countryCode, - ct.ibanLength AS ibanLength - FROM client c - JOIN country ct ON ct.id = c.countryFk - LEFT JOIN mandate m ON m.clientFk = c.id - AND m.companyFk = :companyId AND m.finished IS NULL - LEFT JOIN province p ON p.id = c.provinceFk - WHERE (m.companyFk = :companyId OR m.companyFk IS NULL) AND c.id = :clientId - ORDER BY m.created DESC LIMIT 1`, {companyId, clientId}); + return db.findOneFromDef('client', {companyId, clientId}, __dirname); }, fetchSupplier(clientId, companyId) { - return db.findOne( - `SELECT - m.code mandateCode, - s.name, - s.street, - sc.country, - s.postCode, - s.city, - sp.name province - FROM client c - LEFT JOIN mandate m ON m.clientFk = c.id - AND m.companyFk = :companyId AND m.finished IS NULL - LEFT JOIN supplier s ON s.id = m.companyFk - LEFT JOIN country sc ON sc.id = s.countryFk - LEFT JOIN province sp ON sp.id = s.provinceFk - LEFT JOIN province p ON p.id = c.provinceFk - WHERE (m.companyFk = :companyId OR m.companyFk IS NULL) AND c.id = :clientId - ORDER BY m.created DESC LIMIT 1`, {companyId, clientId}); + return db.findOneFromDef('supplier', {companyId, clientId}, __dirname); } }, components: { diff --git a/print/templates/reports/sepa-core/sql/client.sql b/print/templates/reports/sepa-core/sql/client.sql new file mode 100644 index 000000000..d00120f89 --- /dev/null +++ b/print/templates/reports/sepa-core/sql/client.sql @@ -0,0 +1,19 @@ +SELECT + c.id, + m.code mandateCode, + c.socialName, + c.street, + c.postcode, + c.city, + c.fi, + p.name AS province, + ct.country, + ct.code AS countryCode, + ct.ibanLength AS ibanLength +FROM client c + JOIN country ct ON ct.id = c.countryFk + LEFT JOIN mandate m ON m.clientFk = c.id + AND m.companyFk = :companyId AND m.finished IS NULL + LEFT JOIN province p ON p.id = c.provinceFk +WHERE (m.companyFk = :companyId OR m.companyFk IS NULL) AND c.id = :clientId +ORDER BY m.created DESC LIMIT 1 \ No newline at end of file diff --git a/print/templates/reports/sepa-core/sql/supplier.sql b/print/templates/reports/sepa-core/sql/supplier.sql new file mode 100644 index 000000000..390c3494a --- /dev/null +++ b/print/templates/reports/sepa-core/sql/supplier.sql @@ -0,0 +1,17 @@ +SELECT + m.code mandateCode, + s.name, + s.street, + sc.country, + s.postCode, + s.city, + sp.name province +FROM client c + LEFT JOIN mandate m ON m.clientFk = c.id + AND m.companyFk = :companyId AND m.finished IS NULL + LEFT JOIN supplier s ON s.id = m.companyFk + LEFT JOIN country sc ON sc.id = s.countryFk + LEFT JOIN province sp ON sp.id = s.provinceFk + LEFT JOIN province p ON p.id = c.provinceFk +WHERE (m.companyFk = :companyId OR m.companyFk IS NULL) AND c.id = :clientId +ORDER BY m.created DESC LIMIT 1 \ No newline at end of file diff --git a/print/templates/reports/zone/sql/zone.sql b/print/templates/reports/zone/sql/zone.sql new file mode 100644 index 000000000..088438a8d --- /dev/null +++ b/print/templates/reports/zone/sql/zone.sql @@ -0,0 +1,9 @@ +SELECT + r.id, + r.time, + am.name agencyName, + v.numberPlate plateNumber +FROM route r + JOIN agencyMode am ON am.id = r.agencyModeFk + JOIN vehicle v ON v.id = r.vehicleFk +WHERE r.id = :routeId \ No newline at end of file diff --git a/print/templates/reports/zone/zone.js b/print/templates/reports/zone/zone.js index 458762563..3bd0c473a 100755 --- a/print/templates/reports/zone/zone.js +++ b/print/templates/reports/zone/zone.js @@ -10,16 +10,7 @@ module.exports = { }, methods: { fetchZone(routeId) { - return db.findOne( - `SELECT - r.id, - r.time, - am.name agencyName, - v.numberPlate plateNumber - FROM route r - JOIN agencyMode am ON am.id = r.agencyModeFk - JOIN vehicle v ON v.id = r.vehicleFk - WHERE r.id = :routeId`, {routeId}); + return db.findOneFromDef('zone', {routeId}, __dirname); } }, props: {
{{$t('clientId')}}