diff --git a/modules/claim/front/descriptor/index.html b/modules/claim/front/descriptor/index.html index 52561b1d0..dcd103247 100644 --- a/modules/claim/front/descriptor/index.html +++ b/modules/claim/front/descriptor/index.html @@ -2,11 +2,11 @@ module="claim" description="$ctrl.claim.client.name"> - Show Pickup order - + diff --git a/modules/claim/front/descriptor/index.js b/modules/claim/front/descriptor/index.js index ea7784f72..5b09b1886 100644 --- a/modules/claim/front/descriptor/index.js +++ b/modules/claim/front/descriptor/index.js @@ -12,7 +12,7 @@ class Controller extends Descriptor { showPickupOrder() { this.showReport('claim-pickup-order', { - clientId: this.claim.clientFk, + recipientId: this.claim.clientFk, claimId: this.claim.id }); } @@ -20,7 +20,7 @@ class Controller extends Descriptor { sendPickupOrder() { return this.sendEmail('claim-pickup-order', { recipient: this.claim.client.email, - clientId: this.claim.clientFk, + recipientId: this.claim.clientFk, claimId: this.claim.id }); } diff --git a/modules/client/back/models/client.js b/modules/client/back/models/client.js index 417370e9e..cf3ded2f8 100644 --- a/modules/client/back/models/client.js +++ b/modules/client/back/models/client.js @@ -257,7 +257,7 @@ module.exports = Self => { if (!instance.email) return; const params = { authorization: authorization, - clientId: instance.id, + recipientId: instance.id, recipient: instance.email }; await request.get(`${origin}/api/email/payment-update`, { diff --git a/modules/client/front/descriptor/index.js b/modules/client/front/descriptor/index.js index 9948eab43..d079b38da 100644 --- a/modules/client/front/descriptor/index.js +++ b/modules/client/front/descriptor/index.js @@ -42,7 +42,7 @@ class Controller extends Descriptor { onConsumerReportAccept() { this.showReport('campaign-metrics', { - clientId: this.id, + recipientId: this.id, from: this.from, to: this.to, }); diff --git a/modules/client/front/sample/create/index.js b/modules/client/front/sample/create/index.js index bfb0fd287..d1dfd3ff5 100644 --- a/modules/client/front/sample/create/index.js +++ b/modules/client/front/sample/create/index.js @@ -61,7 +61,7 @@ class Controller extends Section { send(isPreview, cb) { const sampleType = this.$.sampleType.selection; const params = { - clientId: this.$params.id, + recipientId: this.$params.id, recipient: this.clientSample.recipient }; diff --git a/modules/entry/front/descriptor/index.js b/modules/entry/front/descriptor/index.js index 81b7946d1..c84d0144d 100644 --- a/modules/entry/front/descriptor/index.js +++ b/modules/entry/front/descriptor/index.js @@ -37,7 +37,6 @@ class Controller extends Descriptor { showEntryReport() { this.showReport('entry-order', { - clientId: this.vnConfig.storage.currentUserWorkerId, entryId: this.entry.id }); } diff --git a/modules/route/front/descriptor/index.js b/modules/route/front/descriptor/index.js index 0fbc3a5e6..c14035015 100644 --- a/modules/route/front/descriptor/index.js +++ b/modules/route/front/descriptor/index.js @@ -12,19 +12,16 @@ class Controller extends Descriptor { showRouteReport() { this.showReport('driver-route', { - clientId: this.vnConfig.storage.currentUserWorkerId, routeId: this.id }); } sendRouteReport() { - const params = { - recipient: user.emailUser.email, - clientId: this.vnConfig.storage.currentUserWorkerId, + const workerUser = this.route.worker.user; + this.sendEmail('driver-route', { + recipient: workerUser.emailUser.email, routeId: this.id - }; - return this.$http.get(`email/driver-route`, {params}) - .then(() => this.vnApp.showSuccess(this.$t('Report sent'))); + }); } updateVolume() { diff --git a/modules/ticket/front/descriptor/index.js b/modules/ticket/front/descriptor/index.js index 1b9048bd7..546c5bec7 100644 --- a/modules/ticket/front/descriptor/index.js +++ b/modules/ticket/front/descriptor/index.js @@ -102,15 +102,15 @@ class Controller extends Descriptor { showDeliveryNote() { this.showReport('delivery-note', { - clientId: this.ticket.client.id, + recipientId: this.ticket.client.id, ticketId: this.id, }); } sendDeliveryNote() { return this.sendEmail('delivery-note', { + recipientId: this.ticket.client.id, recipient: this.ticket.client.email, - clientId: this.ticket.client.id, ticketId: this.id }); } diff --git a/print/core/component.js b/print/core/component.js index 1b88ac292..4f439f1a9 100644 --- a/print/core/component.js +++ b/print/core/component.js @@ -107,8 +107,6 @@ class Component { * @return {Promise} Rendered component */ async render() { - const c = this.component(); - console.log(c); return renderer.renderToString( this.component() ); diff --git a/print/core/components/attachment/attachment.js b/print/core/components/attachment/attachment.js index 1975320cf..0f2a6d103 100755 --- a/print/core/components/attachment/attachment.js +++ b/print/core/components/attachment/attachment.js @@ -15,10 +15,10 @@ module.exports = { const props = this.args; let query = ''; for (let param in props) { - if (param instanceof Object) return; - if (query != '') - query += '&'; - query += `${param}=${props[param]}`; + if (!(props[param] instanceof Object)) { + if (query != '') query += '&'; + query += `${param}=${props[param]}`; + } } return query; diff --git a/print/core/email.js b/print/core/email.js index 27a457a92..cf6f8b663 100644 --- a/print/core/email.js +++ b/print/core/email.js @@ -1,9 +1,8 @@ const path = require('path'); const smtp = require('./smtp'); +const config = require('./config'); const Component = require('./component'); const Report = require('./report'); -// const db = require('./database'); -const config = require('./config'); if (!process.env.OPENSSL_CONF) process.env.OPENSSL_CONF = '/etc/ssl/'; @@ -20,32 +19,26 @@ class Email extends Component { } async getSubject() { - const lang = this.args.auth.lang; - const locale = this.locale.messages; - const userLocale = locale[lang]; + const component = await this.component(); + let locale = this.args.auth.locale; - if (!userLocale) { + if (this.args.recipientId) + locale = await component.getLocale(this.args.recipientId); + + const messages = this.locale.messages; + const userTranslations = messages[locale]; + + if (!userTranslations) { const fallbackLocale = config.i18n.fallbackLocale; - return locale[fallbackLocale].subject; + return messages[fallbackLocale].subject; } - return userLocale.subject; + return userTranslations.subject; } - /* async getLang() { - const clientId = this.args.clientId; - const lang = await db.findOne(` - SELECT lang FROM account.user - WHERE id = ?`, [clientId]).then(rows => { - return rows.lang; - }); - this.lang = lang; - } */ - async send() { const instance = this.build(); - const component = this.component(); const rendered = await this.render(); const attachments = []; const getAttachments = async(componentPath, files) => { @@ -78,8 +71,6 @@ class Email extends Component { if (this.attachments) await getAttachments(this.path, this.attachments); - console.log(await component.getLang(101)); - const localeSubject = await this.getSubject(); const options = { to: this.args.recipient, diff --git a/print/core/mixins/user-locale.js b/print/core/mixins/user-locale.js index 7d5b0cea7..0e4727334 100644 --- a/print/core/mixins/user-locale.js +++ b/print/core/mixins/user-locale.js @@ -4,33 +4,27 @@ const config = require('../config'); const fallbackLocale = config.i18n.fallbackLocale; const userLocale = { async serverPrefetch() { - /* if (this.clientId) - this.locale = await this.getLocale(this.clientId); */ + if (this.auth) + this.$i18n.locale = this.auth.locale; - if (this.clientLang) { - if (this.auth) - this.$i18n.locale = this.auth.lang; - } + if (this.recipientId) + this.$i18n.locale = await this.getLocale(this.recipientId); }, methods: { - getLang(clientId) { + getLocale(recipientId) { return db.findOne(` SELECT IF(u.lang IS NOT NULL, u.lang, LOWER(ct.code)) lang FROM client c JOIN country ct ON ct.id = c.countryFk JOIN account.user u ON u.id = c.id - WHERE c.id = ?`, [clientId]).then(rows => { + WHERE c.id = ?`, [recipientId]).then(rows => { if (rows) return rows.lang; else return fallbackLocale; }); - }, - - setLocale() { - this.$i18n.locale = this.auth.lang; } }, - props: ['auth', 'clientId'] + props: ['auth', 'recipientId'] }; Vue.mixin(userLocale); diff --git a/print/core/router.js b/print/core/router.js index efb5d9520..feaea214b 100644 --- a/print/core/router.js +++ b/print/core/router.js @@ -40,7 +40,7 @@ module.exports = app => { userId: auth.userId, token: auth.id, email: auth.email, - lang: auth.lang + locale: auth.lang }; next(); diff --git a/print/methods/closure.js b/print/methods/closure.js index 05490609d..901dce790 100644 --- a/print/methods/closure.js +++ b/print/methods/closure.js @@ -29,7 +29,7 @@ module.exports = app => { const args = { ticketId: ticket.id, - clientId: ticket.clientFk, + recipientId: ticket.clientFk, recipient: ticket.recipient }; const email = new Email('delivery-note-link', args); diff --git a/print/templates/email/buyer-week-waste/buyer-week-waste.html b/print/templates/email/buyer-week-waste/buyer-week-waste.html index 1183e0ac2..9f6b22968 100644 --- a/print/templates/email/buyer-week-waste/buyer-week-waste.html +++ b/print/templates/email/buyer-week-waste/buyer-week-waste.html @@ -43,9 +43,9 @@ {{waste.buyer}} - {{(waste.percentage / 100) | percentage(2, 2, locale)}} - {{waste.dwindle | currency('EUR', locale)}} - {{waste.total | currency('EUR', locale)}} + {{(waste.percentage / 100) | percentage(2, 2, $i18n.locale)}} + {{waste.dwindle | currency('EUR', $i18n.locale)}} + {{waste.total | currency('EUR', $i18n.locale)}} diff --git a/print/templates/email/campaign-metrics/campaign-metrics.js b/print/templates/email/campaign-metrics/campaign-metrics.js index cb01ca09e..51d2ebb44 100755 --- a/print/templates/email/campaign-metrics/campaign-metrics.js +++ b/print/templates/email/campaign-metrics/campaign-metrics.js @@ -10,7 +10,7 @@ module.exports = { 'email-footer': emailFooter.build() }, props: { - clientId: { + recipientId: { required: true }, from: { diff --git a/print/templates/email/client-welcome/client-welcome.js b/print/templates/email/client-welcome/client-welcome.js index 35b373bc4..194c133bd 100755 --- a/print/templates/email/client-welcome/client-welcome.js +++ b/print/templates/email/client-welcome/client-welcome.js @@ -6,7 +6,7 @@ const emailFooter = new Component('email-footer'); module.exports = { name: 'client-welcome', async serverPrefetch() { - this.client = await this.fetchClient(this.clientId); + this.client = await this.fetchClient(this.recipientId); }, methods: { fetchClient(clientId) { @@ -29,7 +29,7 @@ module.exports = { 'email-footer': emailFooter.build() }, props: { - clientId: { + recipientId: { required: true } } 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 b2809ac28..be7768608 100755 --- a/print/templates/email/letter-debtor-nd/letter-debtor-nd.js +++ b/print/templates/email/letter-debtor-nd/letter-debtor-nd.js @@ -8,7 +8,7 @@ const attachments = require('./attachments.json'); module.exports = { name: 'letter-debtor-nd', async serverPrefetch() { - this.debtor = await this.fetchDebtor(this.clientId, this.companyId); + this.debtor = await this.fetchDebtor(this.recipientId, this.companyId); if (!this.debtor) throw new Error('Something went wrong'); @@ -40,7 +40,7 @@ module.exports = { authorization: { required: true }, - clientId: { + recipientId: { required: true }, companyId: { 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 8914c8320..51ed8b2ff 100755 --- a/print/templates/email/letter-debtor-st/letter-debtor-st.js +++ b/print/templates/email/letter-debtor-st/letter-debtor-st.js @@ -8,7 +8,7 @@ const attachments = require('./attachments.json'); module.exports = { name: 'letter-debtor-st', async serverPrefetch() { - this.debtor = await this.fetchDebtor(this.clientId, this.companyId); + this.debtor = await this.fetchDebtor(this.recipientId, this.companyId); if (!this.debtor) throw new Error('Something went wrong'); @@ -37,7 +37,7 @@ module.exports = { 'attachment': attachment.build() }, props: { - clientId: { + recipientId: { required: true }, companyId: { diff --git a/print/templates/email/payment-update/payment-update.js b/print/templates/email/payment-update/payment-update.js index 4479deb81..c74cf8694 100755 --- a/print/templates/email/payment-update/payment-update.js +++ b/print/templates/email/payment-update/payment-update.js @@ -6,7 +6,7 @@ const emailFooter = new Component('email-footer'); module.exports = { name: 'payment-update', async serverPrefetch() { - this.payMethod = await this.fetchPayMethod(this.clientId); + this.payMethod = await this.fetchPayMethod(this.recipientId); if (!this.payMethod) throw new Error('Something went wrong'); @@ -34,7 +34,7 @@ module.exports = { 'email-footer': emailFooter.build() }, props: { - clientId: { + recipientId: { required: true } } diff --git a/print/templates/email/printer-setup/printer-setup.js b/print/templates/email/printer-setup/printer-setup.js index 320ce8cbd..4aa63587f 100755 --- a/print/templates/email/printer-setup/printer-setup.js +++ b/print/templates/email/printer-setup/printer-setup.js @@ -8,33 +8,27 @@ const attachments = require('./attachments.json'); module.exports = { name: 'printer-setup', async serverPrefetch() { - this.client = await this.fetchClient(this.clientId); + this.client = await this.fetchClient(this.recipientId); }, data() { return {attachments}; }, - getClient() { - return this.clientId; - }, 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]); - }, - getClient() { - return this.clientId; + 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]); } }, components: { @@ -43,7 +37,7 @@ module.exports = { 'attachment': attachment.build() }, props: { - clientId: { + recipientId: { required: true } } diff --git a/print/templates/email/sepa-core/sepa-core.js b/print/templates/email/sepa-core/sepa-core.js index 31afb1115..76f8d842f 100755 --- a/print/templates/email/sepa-core/sepa-core.js +++ b/print/templates/email/sepa-core/sepa-core.js @@ -15,7 +15,7 @@ module.exports = { 'attachment': attachment.build() }, props: { - clientId: { + recipientId: { required: true }, companyId: { diff --git a/print/templates/reports/campaign-metrics/campaign-metrics.js b/print/templates/reports/campaign-metrics/campaign-metrics.js index f72069260..ef1d735de 100755 --- a/print/templates/reports/campaign-metrics/campaign-metrics.js +++ b/print/templates/reports/campaign-metrics/campaign-metrics.js @@ -9,9 +9,8 @@ module.exports = { this.to = new Date(this.to); this.from = new Date(this.from); - this.client = await this.fetchClient(this.clientId); - - this.sales = await this.fetchSales(this.clientId, this.from, this.to); + this.client = await this.fetchClient(this.recipientId); + this.sales = await this.fetchSales(this.recipientId, this.from, this.to); if (!this.client) throw new Error('Something went wrong'); @@ -63,7 +62,7 @@ module.exports = { 'report-footer': reportFooter.build() }, props: { - clientId: { + recipientId: { required: true }, from: { diff --git a/print/templates/reports/delivery-note/delivery-note.html b/print/templates/reports/delivery-note/delivery-note.html index 9505cce29..913946196 100644 --- a/print/templates/reports/delivery-note/delivery-note.html +++ b/print/templates/reports/delivery-note/delivery-note.html @@ -88,10 +88,10 @@ {{sale.itemFk}} {{sale.quantity}} {{sale.concept}} - {{sale.price | currency('EUR', locale)}} + {{sale.price | currency('EUR', $i18n.locale)}} {{(sale.discount / 100) | percentage}} {{sale.vatType}} - {{sale.price * sale.quantity * (1 - sale.discount / 100) | currency('EUR', locale)}} + {{sale.price * sale.quantity * (1 - sale.discount / 100) | currency('EUR', $i18n.locale)}} @@ -125,7 +125,7 @@ {{$t('subtotal')}} - {{getSubTotal() | currency('EUR', locale)}} + {{getSubTotal() | currency('EUR', $i18n.locale)}} @@ -149,13 +149,13 @@ {{service.description}} {{service.quantity}} {{service.taxDescription}} - {{service.price | currency('EUR', locale)}} + {{service.price | currency('EUR', $i18n.locale)}} - {{$t('total')}} {{serviceTotal | currency('EUR', locale)}} + {{$t('total')}} {{serviceTotal | currency('EUR', $i18n.locale)}} @@ -180,24 +180,24 @@ {{tax.name}} - {{tax.Base | currency('EUR', locale)}} + {{tax.Base | currency('EUR', $i18n.locale)}} {{tax.vatPercent | percentage}} - {{tax.tax | currency('EUR', locale)}} + {{tax.tax | currency('EUR', $i18n.locale)}} {{$t('subtotal')}} - {{getTotalBase() | currency('EUR', locale)}} + {{getTotalBase() | currency('EUR', $i18n.locale)}} - {{getTotalTax()| currency('EUR', locale)}} + {{getTotalTax()| currency('EUR', $i18n.locale)}} {{$t('total')}} - {{getTotal() | currency('EUR', locale)}} + {{getTotal() | currency('EUR', $i18n.locale)}} diff --git a/print/templates/reports/driver-route/driver-route.html b/print/templates/reports/driver-route/driver-route.html index 6ad027d83..919ed0679 100644 --- a/print/templates/reports/driver-route/driver-route.html +++ b/print/templates/reports/driver-route/driver-route.html @@ -141,7 +141,7 @@ {{$t('import')}} - {{ticket.import | currency('EUR', locale)}} + {{ticket.import | currency('EUR', $i18n.locale)}} diff --git a/print/templates/reports/entry-order/entry-order.html b/print/templates/reports/entry-order/entry-order.html index fa8ad41a9..3c1cdbd33 100644 --- a/print/templates/reports/entry-order/entry-order.html +++ b/print/templates/reports/entry-order/entry-order.html @@ -77,8 +77,8 @@ {{buy.packing}} {{buy.itemName}} {{buy.quantity | number}} - {{buy.buyingValue | currency('EUR', locale)}} - {{buy.buyingValue * buy.quantity | currency('EUR', locale)}} + {{buy.buyingValue | currency('EUR', $i18n.locale)}} + {{buy.buyingValue * buy.quantity | currency('EUR', $i18n.locale)}} @@ -106,7 +106,7 @@ {{$t('total')}} - {{getTotal() | currency('EUR', locale)}} + {{getTotal() | currency('EUR', $i18n.locale)}} diff --git a/print/templates/reports/letter-debtor/letter-debtor.js b/print/templates/reports/letter-debtor/letter-debtor.js index f099c1869..7da1b438c 100755 --- a/print/templates/reports/letter-debtor/letter-debtor.js +++ b/print/templates/reports/letter-debtor/letter-debtor.js @@ -6,8 +6,8 @@ const reportFooter = new Component('report-footer'); module.exports = { name: 'letter-debtor', async serverPrefetch() { - this.client = await this.fetchClient(this.clientId); - this.sales = await this.fetchSales(this.clientId, this.companyId); + this.client = await this.fetchClient(this.recipientId); + this.sales = await this.fetchSales(this.recipientId, this.companyId); if (!this.client) throw new Error('Something went wrong'); @@ -79,7 +79,7 @@ module.exports = { 'report-footer': reportFooter.build() }, props: { - clientId: { + recipientId: { required: true }, companyId: { diff --git a/print/templates/reports/sepa-core/sepa-core.js b/print/templates/reports/sepa-core/sepa-core.js index de3a2983d..a63b5b704 100755 --- a/print/templates/reports/sepa-core/sepa-core.js +++ b/print/templates/reports/sepa-core/sepa-core.js @@ -6,8 +6,8 @@ const reportFooter = new Component('report-footer'); const rptSepaCore = { name: 'sepa-core', async serverPrefetch() { - this.client = await this.fetchClient(this.clientId, this.companyId); - this.supplier = await this.fetchSupplier(this.clientId, this.companyId); + this.client = await this.fetchClient(this.recipientId, this.companyId); + this.supplier = await this.fetchSupplier(this.recipientId, this.companyId); if (!this.client) throw new Error('Something went wrong'); @@ -67,7 +67,7 @@ const rptSepaCore = { 'report-footer': reportFooter.build() }, props: { - clientId: { + recipientId: { required: true }, companyId: { @@ -76,5 +76,4 @@ const rptSepaCore = { } }; - module.exports = rptSepaCore;