From 9e0eab5a77dab1f8aa66ccb940cd6b69be041d95 Mon Sep 17 00:00:00 2001 From: alexm Date: Mon, 24 Oct 2022 15:15:23 +0200 Subject: [PATCH] feat(invoiceIn): email --- db/changes/10491-august/00-invoiceInPdf.sql | 4 ++ db/changes/10491-august/delete.keep | 0 .../back/methods/invoice-in/invoiceInEmail.js | 56 +++++++++++++++++++ .../back/methods/invoice-in/invoiceInPdf.js | 5 +- modules/invoiceIn/back/models/invoice-in.js | 1 + modules/invoiceIn/back/models/invoice-in.json | 5 ++ modules/invoiceIn/front/card/index.js | 8 +++ modules/invoiceIn/front/descriptor/index.html | 3 +- modules/invoiceIn/front/descriptor/index.js | 14 ++++- .../email/delivery-note-link/locale/pt.yml | 2 +- .../email/invoiceIn/assets/css/import.js | 11 ++++ .../email/invoiceIn/attachments.json | 6 ++ .../templates/email/invoiceIn/invoiceIn.html | 47 ++++++++++++++++ print/templates/email/invoiceIn/invoiceIn.js | 19 +++++++ print/templates/email/invoiceIn/locale/en.yml | 5 ++ print/templates/email/invoiceIn/locale/es.yml | 5 ++ print/templates/email/invoiceIn/locale/fr.yml | 5 ++ print/templates/email/invoiceIn/locale/pt.yml | 5 ++ .../reports/invoiceIn/invoiceIn.html | 1 + .../templates/reports/invoiceIn/locale/en.yml | 4 +- .../reports/invoiceIn/sql/invoice.sql | 3 +- 21 files changed, 199 insertions(+), 10 deletions(-) create mode 100644 db/changes/10491-august/00-invoiceInPdf.sql delete mode 100644 db/changes/10491-august/delete.keep create mode 100644 modules/invoiceIn/back/methods/invoice-in/invoiceInEmail.js create mode 100644 print/templates/email/invoiceIn/assets/css/import.js create mode 100644 print/templates/email/invoiceIn/attachments.json create mode 100644 print/templates/email/invoiceIn/invoiceIn.html create mode 100755 print/templates/email/invoiceIn/invoiceIn.js create mode 100644 print/templates/email/invoiceIn/locale/en.yml create mode 100644 print/templates/email/invoiceIn/locale/es.yml create mode 100644 print/templates/email/invoiceIn/locale/fr.yml create mode 100644 print/templates/email/invoiceIn/locale/pt.yml diff --git a/db/changes/10491-august/00-invoiceInPdf.sql b/db/changes/10491-august/00-invoiceInPdf.sql new file mode 100644 index 0000000000..d7dc038aa2 --- /dev/null +++ b/db/changes/10491-august/00-invoiceInPdf.sql @@ -0,0 +1,4 @@ +INSERT INTO `salix`.`ACL` (`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`) + VALUES + ('InvoiceIn', 'invoiceInPdf', 'READ', 'ALLOW', 'ROLE', 'administrative'), + ('InvoiceIn', 'invoiceInEmail', 'WRITE', 'ALLOW', 'ROLE', 'administrative'), diff --git a/db/changes/10491-august/delete.keep b/db/changes/10491-august/delete.keep deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/modules/invoiceIn/back/methods/invoice-in/invoiceInEmail.js b/modules/invoiceIn/back/methods/invoice-in/invoiceInEmail.js new file mode 100644 index 0000000000..b04108bd7e --- /dev/null +++ b/modules/invoiceIn/back/methods/invoice-in/invoiceInEmail.js @@ -0,0 +1,56 @@ +const {Email} = require('vn-print'); + +module.exports = Self => { + Self.remoteMethodCtx('invoiceInEmail', { + description: 'Sends the invoice in email with an attached PDF', + accessType: 'WRITE', + accepts: [ + { + arg: 'id', + type: 'number', + required: true, + description: 'The invoice id', + http: {source: 'path'} + }, + { + arg: 'recipient', + type: 'string', + description: 'The recipient email', + required: true, + }, + { + arg: 'recipientId', + type: 'number', + description: 'The recipient id to send to the recipient preferred language', + required: false + } + ], + returns: { + type: ['object'], + root: true + }, + http: { + path: '/:id/invoice-in-email', + verb: 'POST' + } + }); + + Self.invoiceInEmail = async(ctx, id) => { + const args = Object.assign({}, ctx.args); + const params = { + recipient: 'alexm@verdnatura.es', // args.recipient, + lang: ctx.req.getLocale() + }; + + console.log(id); + + delete args.ctx; + for (const param in args) + params[param] = args[param]; + console.log(params); + + const email = new Email('invoiceIn', params); + + return email.send(); + }; +}; diff --git a/modules/invoiceIn/back/methods/invoice-in/invoiceInPdf.js b/modules/invoiceIn/back/methods/invoice-in/invoiceInPdf.js index 1b7ca9c686..f1d17dce76 100644 --- a/modules/invoiceIn/back/methods/invoice-in/invoiceInPdf.js +++ b/modules/invoiceIn/back/methods/invoice-in/invoiceInPdf.js @@ -29,17 +29,16 @@ module.exports = Self => { } ], http: { - path: '/:id/invoiceInPdf', + path: '/:id/invoice-in-pdf', verb: 'GET' } }); Self.invoiceInPdf = async(ctx, id) => { - console.log(id); const args = Object.assign({}, ctx.args); const params = {lang: ctx.req.getLocale()}; delete args.ctx; - console.log(args); + for (const param in args) params[param] = args[param]; diff --git a/modules/invoiceIn/back/models/invoice-in.js b/modules/invoiceIn/back/models/invoice-in.js index e2c1326714..95ccc7b205 100644 --- a/modules/invoiceIn/back/models/invoice-in.js +++ b/modules/invoiceIn/back/models/invoice-in.js @@ -5,4 +5,5 @@ module.exports = Self => { require('../methods/invoice-in/toBook')(Self); require('../methods/invoice-in/getTotals')(Self); require('../methods/invoice-in/invoiceInPdf')(Self); + require('../methods/invoice-in/invoiceInEmail')(Self); }; diff --git a/modules/invoiceIn/back/models/invoice-in.json b/modules/invoiceIn/back/models/invoice-in.json index c6a736b06a..fa8a1d8f84 100644 --- a/modules/invoiceIn/back/models/invoice-in.json +++ b/modules/invoiceIn/back/models/invoice-in.json @@ -94,6 +94,11 @@ "model": "Supplier", "foreignKey": "supplierFk" }, + "supplierContact": { + "type": "hasMany", + "model": "SupplierContact", + "foreignKey": "supplierFk" + }, "currency": { "type": "belongsTo", "model": "Currency", diff --git a/modules/invoiceIn/front/card/index.js b/modules/invoiceIn/front/card/index.js index 582c2abb8c..c7ac08cc7e 100644 --- a/modules/invoiceIn/front/card/index.js +++ b/modules/invoiceIn/front/card/index.js @@ -8,6 +8,14 @@ class Controller extends ModuleCard { { relation: 'supplier' }, + { + relation: 'supplierContact', + scope: { + where: { + email: {neq: null} + } + } + }, { relation: 'invoiceInDueDay' }, diff --git a/modules/invoiceIn/front/descriptor/index.html b/modules/invoiceIn/front/descriptor/index.html index faff5b9765..095bbd8e71 100644 --- a/modules/invoiceIn/front/descriptor/index.html +++ b/modules/invoiceIn/front/descriptor/index.html @@ -31,7 +31,7 @@ Show Invoice as PDF Send Invoice as PDF @@ -99,7 +99,6 @@ on-accept="$ctrl.sendPdfInvoice($data)" message="Send PDF invoice"> - {{sendPdfConfirmation.data.email}} Are you sure you want to send it? this.$state.reload()) .then(() => this.vnApp.showSuccess(this.$t('InvoiceIn booked'))); } + showPdfInvoice() { - this.vnReport.show(`InvoiceIns/${this.id}/invoiceInPdf`); + this.vnReport.show(`InvoiceIns/${this.id}/invoice-in-pdf`); + } + + sendPdfInvoice($data) { + if (!$data.email) + return this.vnApp.showError(this.$t(`The email can't be empty`)); + + return this.vnEmail.send(`InvoiceIns/${this.entity.id}/invoice-in-email`, { + recipient: $data.email, + recipientId: this.entity.supplier.id + }); } } diff --git a/print/templates/email/delivery-note-link/locale/pt.yml b/print/templates/email/delivery-note-link/locale/pt.yml index 1aab4b6d8a..9a70fc4cda 100644 --- a/print/templates/email/delivery-note-link/locale/pt.yml +++ b/print/templates/email/delivery-note-link/locale/pt.yml @@ -7,4 +7,4 @@ copyLink: 'Como alternativa, podes copiar o siguinte link no teu navegador:' poll: Si o deseja, podes responder nosso questionário de satiscação para ajudar-nos a prestar-vos um melhor serviço. Tua opinião é muito importante para nós! help: Cualquer dúvida que surja, no hesites em consultar-la, Estamos aqui para atender-te! -conclusion: Obrigado por tua atenção! \ No newline at end of file +conclusion: Obrigado por tua atenção! diff --git a/print/templates/email/invoiceIn/assets/css/import.js b/print/templates/email/invoiceIn/assets/css/import.js new file mode 100644 index 0000000000..4b4bb70869 --- /dev/null +++ b/print/templates/email/invoiceIn/assets/css/import.js @@ -0,0 +1,11 @@ +const Stylesheet = require(`vn-print/core/stylesheet`); + +const path = require('path'); +const vnPrintPath = path.resolve('print'); + +module.exports = new Stylesheet([ + `${vnPrintPath}/common/css/spacing.css`, + `${vnPrintPath}/common/css/misc.css`, + `${vnPrintPath}/common/css/layout.css`, + `${vnPrintPath}/common/css/email.css`]) + .mergeStyles(); diff --git a/print/templates/email/invoiceIn/attachments.json b/print/templates/email/invoiceIn/attachments.json new file mode 100644 index 0000000000..cd23d3f924 --- /dev/null +++ b/print/templates/email/invoiceIn/attachments.json @@ -0,0 +1,6 @@ +[ + { + "filename": "invoiceIn.pdf", + "component": "invoiceIn" + } +] diff --git a/print/templates/email/invoiceIn/invoiceIn.html b/print/templates/email/invoiceIn/invoiceIn.html new file mode 100644 index 0000000000..65453ccd6d --- /dev/null +++ b/print/templates/email/invoiceIn/invoiceIn.html @@ -0,0 +1,47 @@ + + + + + + {{ $t('subject') }} + + + + + + + + +
+ +
+
+
+ +
+
+ +
+
+ +
+
+

{{ $t('title') }}

+

{{$t('dear')}},

+

+

+
+
+ +
+
+ +
+
+ +
+
+
+
+ + diff --git a/print/templates/email/invoiceIn/invoiceIn.js b/print/templates/email/invoiceIn/invoiceIn.js new file mode 100755 index 0000000000..43e95120c1 --- /dev/null +++ b/print/templates/email/invoiceIn/invoiceIn.js @@ -0,0 +1,19 @@ +const Component = require(`vn-print/core/component`); +const emailHeader = new Component('email-header'); +const emailFooter = new Component('email-footer'); + +module.exports = { + name: 'invoiceIn', + async serverPrefetch() { + this.invoice = await this.fetchInvoice(this.id); + }, + methods: { + fetchInvoice(reference) { + return this.findOneFromDef('invoice', [reference]); + }, + }, + components: { + 'email-header': emailHeader.build(), + 'email-footer': emailFooter.build() + } +}; diff --git a/print/templates/email/invoiceIn/locale/en.yml b/print/templates/email/invoiceIn/locale/en.yml new file mode 100644 index 0000000000..47ebc3966e --- /dev/null +++ b/print/templates/email/invoiceIn/locale/en.yml @@ -0,0 +1,5 @@ +subject: Your agricultural invoice +title: Your agricultural invoice +dear: Dear supplier +description: Attached you can find agricultural receipt generated from your last deliveries. Please return a signed and stamped copy to our administration department. +conclusion: Thanks for your attention! diff --git a/print/templates/email/invoiceIn/locale/es.yml b/print/templates/email/invoiceIn/locale/es.yml new file mode 100644 index 0000000000..2698763cf6 --- /dev/null +++ b/print/templates/email/invoiceIn/locale/es.yml @@ -0,0 +1,5 @@ +subject: Tu factura agrícola +title: Tu factura agrícola +dear: Estimado proveedor +description: Adjunto puede encontrar recibo agrícola generado de sus últimas entregas. Por favor, devuelva una copia firmada y sellada a nuestro de departamento de administración. +conclusion: ¡Gracias por tu atención! diff --git a/print/templates/email/invoiceIn/locale/fr.yml b/print/templates/email/invoiceIn/locale/fr.yml new file mode 100644 index 0000000000..1c38f3c25f --- /dev/null +++ b/print/templates/email/invoiceIn/locale/fr.yml @@ -0,0 +1,5 @@ +subject: Votre facture agricole +title: Votre facture agricole +dear: Cher Fournisseur +description: Vous trouverez en pièce jointe le reçu agricole généré à partir de vos dernières livraisons. Veuillez retourner une copie signée et tamponnée à notre service administratif. +conclusion: Merci pour votre attention! diff --git a/print/templates/email/invoiceIn/locale/pt.yml b/print/templates/email/invoiceIn/locale/pt.yml new file mode 100644 index 0000000000..a43e3a79da --- /dev/null +++ b/print/templates/email/invoiceIn/locale/pt.yml @@ -0,0 +1,5 @@ +subject: A sua fatura agrícola +title: A sua fatura agrícola +dear: Caro Fornecedor +description: Em anexo encontra-se o recibo agrícola gerado a partir das suas últimas entregas. Por favor, devolva uma cópia assinada e carimbada ao nosso departamento de administração. +conclusion: Obrigado pela atenção. diff --git a/print/templates/reports/invoiceIn/invoiceIn.html b/print/templates/reports/invoiceIn/invoiceIn.html index 4bc6d8ee0e..5f15e6a9a7 100644 --- a/print/templates/reports/invoiceIn/invoiceIn.html +++ b/print/templates/reports/invoiceIn/invoiceIn.html @@ -201,6 +201,7 @@ diff --git a/print/templates/reports/invoiceIn/locale/en.yml b/print/templates/reports/invoiceIn/locale/en.yml index 7a8767ad32..92d3b0c2dd 100644 --- a/print/templates/reports/invoiceIn/locale/en.yml +++ b/print/templates/reports/invoiceIn/locale/en.yml @@ -1,6 +1,6 @@ reportName: invoice -title: Agrobusiness invoice -invoiceId: Agrobusiness invoice +title: Agricultural invoice +invoiceId: Agricultural invoice supplierId: Proveedor invoiceData: Invoice data reference: Reference diff --git a/print/templates/reports/invoiceIn/sql/invoice.sql b/print/templates/reports/invoiceIn/sql/invoice.sql index fe9ef1e9e0..2f6929b2a9 100644 --- a/print/templates/reports/invoiceIn/sql/invoice.sql +++ b/print/templates/reports/invoiceIn/sql/invoice.sql @@ -6,7 +6,8 @@ SELECT s.street AS postalAddress, s.nif, s.phone, - p.name payMethod + p.name payMethod, + c.companyCode FROM invoiceIn i JOIN supplier s ON s.id = i.supplierFk JOIN company c ON c.id = i.companyFk