From 7f78286d6b6e50a9f99f5bcd15f70d5ebcd8f155 Mon Sep 17 00:00:00 2001 From: joan Date: Mon, 26 Sep 2022 13:33:27 +0200 Subject: [PATCH] Reports refactor --- db/changes/10490-august/00-ACL.sql | 11 ++- db/changes/10490-august/00-sample.sql | 30 +----- db/dump/fixtures.sql | 5 - .../client/incotermsAuthorizationEmail.js | 65 +++++++++++++ .../client/incotermsAuthorizationHtml.js | 64 +++++++++++++ modules/client/back/models/client-methods.js | 2 + modules/client/back/models/client-sample.js | 17 ++-- modules/client/back/models/sample.json | 3 - .../entry/back/methods/entry/entryOrderPdf.js | 54 +++++++++++ modules/entry/back/models/entry.js | 1 + modules/entry/front/descriptor/index.js | 4 +- .../back/methods/invoiceOut/exportationPdf.js | 54 +++++++++++ .../back/methods/invoiceOut/invoiceEmail.js | 58 ++++++++++++ modules/invoiceOut/back/models/invoice-out.js | 2 + .../invoiceOut/front/descriptor-menu/index.js | 7 +- .../methods/supplier/campaignMetricsEmail.js | 68 ++++++++++++++ .../methods/supplier/campaignMetricsPdf.js | 65 +++++++++++++ modules/supplier/back/models/supplier.js | 2 + modules/supplier/front/consumption/index.js | 7 +- .../methods/travel/extraCommunityEmail.js | 92 +++++++++++++++++++ .../back/methods/travel/extraCommunityPdf.js | 89 ++++++++++++++++++ modules/travel/back/models/travel.js | 2 + modules/travel/front/extra-community/index.js | 2 +- .../incoterms-authorization.js | 2 +- .../email/invoice/assets/css/import.js | 13 ++- print/templates/email/invoice/invoice.js | 10 +- .../assets/css/import.js | 13 ++- .../supplier-campaign-metrics.js | 4 +- .../campaign-metrics/campaign-metrics.js | 3 +- .../claim-pickup-order/claim-pickup-order.js | 3 +- .../client-debt-statement.js | 3 +- .../reports/delivery-note/delivery-note.js | 3 +- .../reports/driver-route/driver-route.js | 3 +- .../reports/entry-order/assets/css/import.js | 13 ++- .../reports/entry-order/entry-order.js | 25 ++--- .../reports/exportation/assets/css/import.js | 12 ++- .../reports/exportation/exportation.html | 6 +- .../reports/exportation/exportation.js | 15 +-- .../reports/exportation/locale/es.yml | 1 + .../reports/exportation/sql/company.sql | 9 ++ .../reports/exportation/sql/invoice.sql | 3 +- .../extra-community/assets/css/import.js | 13 ++- .../extra-community/extra-community.js | 14 ++- .../incoterms-authorization.js | 3 +- .../invoice-incoterms/assets/css/import.js | 13 ++- .../invoice-incoterms/invoice-incoterms.js | 25 ++--- .../reports/invoice/assets/css/import.js | 13 ++- print/templates/reports/invoice/invoice.js | 57 ++++++------ .../reports/item-label/assets/css/import.js | 13 ++- .../reports/item-label/item-label.js | 21 +++-- .../reports/letter-debtor/letter-debtor.js | 3 +- .../reports/receipt/assets/css/import.js | 12 ++- print/templates/reports/receipt/receipt.js | 19 ++-- .../templates/reports/sepa-core/sepa-core.js | 3 +- .../assets/css/import.js | 13 ++- .../supplier-campaign-metrics.js | 11 ++- .../reports/zone/assets/css/import.js | 12 ++- print/templates/reports/zone/zone.js | 11 ++- 58 files changed, 883 insertions(+), 218 deletions(-) create mode 100644 modules/client/back/methods/client/incotermsAuthorizationEmail.js create mode 100644 modules/client/back/methods/client/incotermsAuthorizationHtml.js create mode 100644 modules/entry/back/methods/entry/entryOrderPdf.js create mode 100644 modules/invoiceOut/back/methods/invoiceOut/exportationPdf.js create mode 100644 modules/invoiceOut/back/methods/invoiceOut/invoiceEmail.js create mode 100644 modules/supplier/back/methods/supplier/campaignMetricsEmail.js create mode 100644 modules/supplier/back/methods/supplier/campaignMetricsPdf.js create mode 100644 modules/travel/back/methods/travel/extraCommunityEmail.js create mode 100644 modules/travel/back/methods/travel/extraCommunityPdf.js create mode 100644 print/templates/reports/exportation/sql/company.sql diff --git a/db/changes/10490-august/00-ACL.sql b/db/changes/10490-august/00-ACL.sql index 633495ed2..871305709 100644 --- a/db/changes/10490-august/00-ACL.sql +++ b/db/changes/10490-august/00-ACL.sql @@ -14,4 +14,13 @@ INSERT INTO `salix`.`ACL` (model, property, accessType, permission, principalTyp ('Client', 'letterDebtorNdHtml', 'READ', 'ALLOW', 'ROLE', 'employee'), ('Client', 'letterDebtorNdEmail', 'READ', 'ALLOW', 'ROLE', 'employee'), ('Client', 'clientDebtStatementHtml', 'READ', 'ALLOW', 'ROLE', 'employee'), - ('Client', 'clientDebtStatementEmail', 'READ', 'ALLOW', 'ROLE', 'employee'); \ No newline at end of file + ('Client', 'clientDebtStatementEmail', 'READ', 'ALLOW', 'ROLE', 'employee'), + ('Client', 'incotermsAuthorizationHtml', 'READ', 'ALLOW', 'ROLE', 'employee'), + ('Client', 'incotermsAuthorizationEmail', 'WRITE', 'ALLOW', 'ROLE', 'employee'), + ('InvoiceOut', 'invoiceEmail', 'WRITE', 'ALLOW', 'ROLE', 'employee'), + ('InvoiceOut', 'exportationPdf', 'READ', 'ALLOW', 'ROLE', 'employee'), + ('Supplier', 'campaignMetricsPdf', 'READ', 'ALLOW', 'ROLE', 'employee'), + ('Supplier', 'campaignMetricsEmail', 'WRITE', 'ALLOW', 'ROLE', 'employee'), + ('Travel', 'extraCommunityPdf', 'READ', 'ALLOW', 'ROLE', 'employee'), + ('Travel', 'extraCommunityEmail', 'WRITE', 'ALLOW', 'ROLE', 'employee'), + ('Entry', 'entryOrderPdf', 'READ', 'ALLOW', 'ROLE', 'employee'); \ No newline at end of file diff --git a/db/changes/10490-august/00-sample.sql b/db/changes/10490-august/00-sample.sql index 8678d5e18..e9dd9e9a0 100644 --- a/db/changes/10490-august/00-sample.sql +++ b/db/changes/10490-august/00-sample.sql @@ -2,31 +2,5 @@ alter table `vn`.`sample` add model VARCHAR(25) null comment 'Model name in plural'; UPDATE vn.sample t - SET t.model = 'Clients' - WHERE t.id = 13; - -UPDATE vn.sample t -SET t.model = 'Clients' -WHERE t.id = 12; - -UPDATE vn.sample t -SET t.model = 'Clients' -WHERE t.id = 14; - -UPDATE vn.sample t -SET t.model = 'Clients' -WHERE t.id = 15; - -UPDATE vn.sample t -SET t.model = 'Clients' -WHERE t.id = 18; - -UPDATE vn.sample t -SET t.model = 'Clients' -WHERE t.id = 19; - -UPDATE vn.sample t -SET t.model = 'Clients' -WHERE t.id = 16; - - + SET t.model = 'Clients' + WHERE t.id IN(13, 14, 15, 16, 18, 19, 20); \ No newline at end of file diff --git a/db/dump/fixtures.sql b/db/dump/fixtures.sql index 7835b32c4..997ebf92f 100644 --- a/db/dump/fixtures.sql +++ b/db/dump/fixtures.sql @@ -1765,11 +1765,6 @@ INSERT INTO `vn`.`claimDestination`(`id`, `description`, `addressFk`) (4, 'Reclam.PRAG', 12), (5, 'Corregido', 11); -INSERT INTO `vn`.`claimResponsible`(`id`, `description`, `responsability`) - VALUES - (1, 'Buyers', 0), - (7, 'Quality', 0); - INSERT INTO `vn`.`claimDevelopment`(`id`, `claimFk`, `claimResponsibleFk`, `workerFk`, `claimReasonFk`, `claimResultFk`, `claimRedeliveryFk`, `claimDestinationFk`) VALUES (1, 1, 1, 21, 1, 1, 2, 5), diff --git a/modules/client/back/methods/client/incotermsAuthorizationEmail.js b/modules/client/back/methods/client/incotermsAuthorizationEmail.js new file mode 100644 index 000000000..2a4fe593a --- /dev/null +++ b/modules/client/back/methods/client/incotermsAuthorizationEmail.js @@ -0,0 +1,65 @@ +const {Email} = require('vn-print'); + +module.exports = Self => { + Self.remoteMethodCtx('incotermsAuthorizationEmail', { + description: 'Sends the incoterms authorization email with an attached PDF', + accessType: 'WRITE', + accepts: [ + { + arg: 'id', + type: 'number', + required: true, + description: 'The client id', + http: {source: 'path'} + }, + { + arg: 'recipient', + type: 'string', + description: 'The recipient email', + required: true, + }, + { + arg: 'replyTo', + type: 'string', + description: 'The sender email to reply to', + required: false + }, + { + arg: 'recipientId', + type: 'number', + description: 'The recipient id to send to the recipient preferred language', + required: false + }, + { + arg: 'companyId', + type: 'number', + description: 'The company id', + required: true + } + ], + returns: { + type: ['object'], + root: true + }, + http: { + path: '/:id/incoterms-authorization-email', + verb: 'POST' + } + }); + + Self.incotermsAuthorizationEmail = async ctx => { + const args = Object.assign({}, ctx.args); + const params = { + recipient: args.recipient, + lang: ctx.req.getLocale() + }; + + delete args.ctx; + for (const param in args) + params[param] = args[param]; + + const email = new Email('incoterms-authorization', params); + + return email.send(); + }; +}; diff --git a/modules/client/back/methods/client/incotermsAuthorizationHtml.js b/modules/client/back/methods/client/incotermsAuthorizationHtml.js new file mode 100644 index 000000000..f8c3e6e60 --- /dev/null +++ b/modules/client/back/methods/client/incotermsAuthorizationHtml.js @@ -0,0 +1,64 @@ +const {Email} = require('vn-print'); + +module.exports = Self => { + Self.remoteMethodCtx('incotermsAuthorizationHtml', { + description: 'Returns the incoterms authorization email preview', + accessType: 'READ', + accepts: [ + { + arg: 'id', + type: 'number', + required: true, + description: 'The client id', + http: {source: 'path'} + }, + { + arg: 'recipientId', + type: 'number', + description: 'The recipient id', + required: false + }, + { + arg: 'companyId', + type: 'number', + description: 'The company id', + required: true + } + ], + returns: [ + { + arg: 'body', + type: 'file', + root: true + }, { + arg: 'Content-Type', + type: 'String', + http: {target: 'header'} + }, { + arg: 'Content-Disposition', + type: 'String', + http: {target: 'header'} + } + ], + http: { + path: '/:id/incoterms-authorization-html', + verb: 'GET' + } + }); + + Self.incotermsAuthorizationHtml = async(ctx, id) => { + const args = Object.assign({}, ctx.args); + const params = {lang: ctx.req.getLocale()}; + + delete args.ctx; + for (const param in args) + params[param] = args[param]; + + params.isPreview = true; + + const report = new Email('incoterms-authorization', params); + const html = await report.render(); + + return [html, 'text/html', `filename="mail-${id}.pdf"`]; + }; +}; diff --git a/modules/client/back/models/client-methods.js b/modules/client/back/models/client-methods.js index ab7fb2596..c8b6389c6 100644 --- a/modules/client/back/models/client-methods.js +++ b/modules/client/back/models/client-methods.js @@ -40,4 +40,6 @@ module.exports = Self => { require('../methods/client/clientDebtStatementEmail')(Self); require('../methods/client/creditRequestHtml')(Self); require('../methods/client/creditRequestEmail')(Self); + require('../methods/client/incotermsAuthorizationHtml')(Self); + require('../methods/client/incotermsAuthorizationEmail')(Self); }; diff --git a/modules/client/back/models/client-sample.js b/modules/client/back/models/client-sample.js index c7cda2412..787cc2ad8 100644 --- a/modules/client/back/models/client-sample.js +++ b/modules/client/back/models/client-sample.js @@ -1,4 +1,5 @@ const UserError = require('vn-loopback/util/user-error'); +const LoopBackContext = require('loopback-context'); module.exports = Self => { Self.validatesPresenceOf('typeFk', { @@ -6,10 +7,10 @@ module.exports = Self => { }); Self.observe('before save', async function(ctx) { - let models = Self.app.models; - let changes = ctx.data || ctx.instance; + const models = Self.app.models; + const changes = ctx.data || ctx.instance; - let sample = await models.Sample.findById(changes.typeFk); + const sample = await models.Sample.findById(changes.typeFk); if (sample.hasCompany && !changes.companyFk) throw new UserError('Choose a company'); @@ -25,11 +26,11 @@ module.exports = Self => { // Renew mandate if (mandate) { - let mandateType = await models.MandateType.findOne({ + const mandateType = await models.MandateType.findOne({ where: {name: mandate.type} }); - let oldMandate = await models.Mandate.findOne({ + const oldMandate = await models.Mandate.findOne({ where: { clientFk: changes.clientFk, companyFk: changes.companyFk, @@ -50,10 +51,8 @@ module.exports = Self => { }); } - // Apply workerFk - let filter = {where: {userFk: ctx.options.accessToken.userId}}; - let worker = await Self.app.models.Worker.findOne(filter); + const loopBackContext = LoopBackContext.getCurrentContext(); - changes.workerFk = worker.id; + changes.userFk = loopBackContext.active.accessToken.userId; }); }; diff --git a/modules/client/back/models/sample.json b/modules/client/back/models/sample.json index fcb33a593..011e8bf24 100644 --- a/modules/client/back/models/sample.json +++ b/modules/client/back/models/sample.json @@ -32,9 +32,6 @@ }, "model": { "type": "string" - }, - "property": { - "type": "string" } }, "scopes": { diff --git a/modules/entry/back/methods/entry/entryOrderPdf.js b/modules/entry/back/methods/entry/entryOrderPdf.js new file mode 100644 index 000000000..e6d37fdb6 --- /dev/null +++ b/modules/entry/back/methods/entry/entryOrderPdf.js @@ -0,0 +1,54 @@ +const {Report} = require('vn-print'); + +module.exports = Self => { + Self.remoteMethodCtx('entryOrderPdf', { + description: 'Returns the entry order pdf', + accepts: [ + { + arg: 'id', + type: 'number', + required: true, + http: {source: 'path'} + }, + { + arg: 'recipientId', + type: 'number', + description: 'The recipient id', + required: false + } + ], + returns: [ + { + arg: 'body', + type: 'file', + root: true + }, { + arg: 'Content-Type', + type: 'String', + http: {target: 'header'} + }, { + arg: 'Content-Disposition', + type: 'String', + http: {target: 'header'} + } + ], + http: { + path: '/:id/entry-order-pdf', + verb: 'GET' + } + }); + + Self.entryOrderPdf = async(ctx, id) => { + const args = Object.assign({}, ctx.args); + const params = {lang: ctx.req.getLocale()}; + + delete args.ctx; + for (const param in args) + params[param] = args[param]; + + const report = new Report('entry-order', params); + const stream = await report.toPdfStream(); + + return [stream, 'application/pdf', `filename="doc-${id}.pdf"`]; + }; +}; diff --git a/modules/entry/back/models/entry.js b/modules/entry/back/models/entry.js index 573e5b1cb..4854bc3d3 100644 --- a/modules/entry/back/models/entry.js +++ b/modules/entry/back/models/entry.js @@ -6,4 +6,5 @@ module.exports = Self => { require('../methods/entry/importBuys')(Self); require('../methods/entry/importBuysPreview')(Self); require('../methods/entry/lastItemBuys')(Self); + require('../methods/entry/entryOrderPdf')(Self); }; diff --git a/modules/entry/front/descriptor/index.js b/modules/entry/front/descriptor/index.js index 34aa162f9..3452a6d34 100644 --- a/modules/entry/front/descriptor/index.js +++ b/modules/entry/front/descriptor/index.js @@ -86,9 +86,7 @@ class Controller extends Descriptor { } showEntryReport() { - this.vnReport.show('entry-order', { - entryId: this.entry.id - }); + this.vnReport.show(`Entries/${this.id}/entry-order-pdf`); } } diff --git a/modules/invoiceOut/back/methods/invoiceOut/exportationPdf.js b/modules/invoiceOut/back/methods/invoiceOut/exportationPdf.js new file mode 100644 index 000000000..adcee72e9 --- /dev/null +++ b/modules/invoiceOut/back/methods/invoiceOut/exportationPdf.js @@ -0,0 +1,54 @@ +const {Report} = require('vn-print'); + +module.exports = Self => { + Self.remoteMethodCtx('exportationPdf', { + description: 'Returns the exportation pdf', + accepts: [ + { + arg: 'ref', + type: 'string', + required: true, + http: {source: 'path'} + }, + { + arg: 'recipientId', + type: 'number', + description: 'The recipient id', + required: false + } + ], + returns: [ + { + arg: 'body', + type: 'file', + root: true + }, { + arg: 'Content-Type', + type: 'String', + http: {target: 'header'} + }, { + arg: 'Content-Disposition', + type: 'String', + http: {target: 'header'} + } + ], + http: { + path: '/:ref/exportation-pdf', + verb: 'GET' + } + }); + + Self.exportationPdf = async(ctx, ref) => { + const args = Object.assign({}, ctx.args); + const params = {lang: ctx.req.getLocale()}; + + delete args.ctx; + for (const param in args) + params[param] = args[param]; + + const report = new Report('exportation', params); + const stream = await report.toPdfStream(); + + return [stream, 'application/pdf', `filename="doc-${ref}.pdf"`]; + }; +}; diff --git a/modules/invoiceOut/back/methods/invoiceOut/invoiceEmail.js b/modules/invoiceOut/back/methods/invoiceOut/invoiceEmail.js new file mode 100644 index 000000000..0f8b6de7d --- /dev/null +++ b/modules/invoiceOut/back/methods/invoiceOut/invoiceEmail.js @@ -0,0 +1,58 @@ +const {Email} = require('vn-print'); + +module.exports = Self => { + Self.remoteMethodCtx('invoiceEmail', { + description: 'Sends the invoice email with an attached PDF', + accessType: 'WRITE', + accepts: [ + { + arg: 'ref', + type: 'string', + required: true, + http: {source: 'path'} + }, + { + arg: 'recipient', + type: 'string', + description: 'The recipient email', + required: true, + }, + { + arg: 'replyTo', + type: 'string', + description: 'The sender email to reply to', + required: false + }, + { + arg: 'recipientId', + type: 'number', + description: 'The recipient id to send to the recipient preferred language', + required: false + } + ], + returns: { + type: ['object'], + root: true + }, + http: { + path: '/:ref/invoice-email', + verb: 'POST' + } + }); + + Self.invoiceEmail = async ctx => { + const args = Object.assign({}, ctx.args); + const params = { + recipient: args.recipient, + lang: ctx.req.getLocale() + }; + + delete args.ctx; + for (const param in args) + params[param] = args[param]; + + const email = new Email('invoice', params); + + return email.send(); + }; +}; diff --git a/modules/invoiceOut/back/models/invoice-out.js b/modules/invoiceOut/back/models/invoice-out.js index c8c97702f..8e9e5bc7a 100644 --- a/modules/invoiceOut/back/models/invoice-out.js +++ b/modules/invoiceOut/back/models/invoice-out.js @@ -9,4 +9,6 @@ module.exports = Self => { require('../methods/invoiceOut/createManualInvoice')(Self); require('../methods/invoiceOut/globalInvoicing')(Self); require('../methods/invoiceOut/refund')(Self); + require('../methods/invoiceOut/invoiceEmail')(Self); + require('../methods/invoiceOut/exportationPdf')(Self); }; diff --git a/modules/invoiceOut/front/descriptor-menu/index.js b/modules/invoiceOut/front/descriptor-menu/index.js index 2b6d90ebf..78b2cb56e 100644 --- a/modules/invoiceOut/front/descriptor-menu/index.js +++ b/modules/invoiceOut/front/descriptor-menu/index.js @@ -92,10 +92,9 @@ class Controller extends Section { if (!$data.email) return this.vnApp.showError(this.$t(`The email can't be empty`)); - return this.vnEmail.send('invoice', { + return this.vnEmail.send(`InvoiceOuts/${this.invoiceOut.ref}/invoice-email`, { recipientId: this.invoiceOut.client.id, - recipient: $data.email, - refFk: this.invoiceOut.ref + recipient: $data.email }); } @@ -111,7 +110,7 @@ class Controller extends Section { } showExportationLetter() { - this.vnReport.show('exportation', { + this.vnReport.show(`InvoiceOuts/${this.invoiceOut.ref}/exportation-pdf`, { recipientId: this.invoiceOut.client.id, refFk: this.invoiceOut.ref }); diff --git a/modules/supplier/back/methods/supplier/campaignMetricsEmail.js b/modules/supplier/back/methods/supplier/campaignMetricsEmail.js new file mode 100644 index 000000000..4a2c843b8 --- /dev/null +++ b/modules/supplier/back/methods/supplier/campaignMetricsEmail.js @@ -0,0 +1,68 @@ +const {Email} = require('vn-print'); + +module.exports = Self => { + Self.remoteMethodCtx('campaignMetricsEmail', { + description: 'Sends the campaign metrics email with an attached PDF', + accessType: 'WRITE', + accepts: [ + { + arg: 'id', + type: 'number', + required: true, + http: {source: 'path'} + }, + { + arg: 'recipient', + type: 'string', + description: 'The recipient email', + required: true, + }, + { + arg: 'replyTo', + type: 'string', + description: 'The sender email to reply to', + required: false + }, + { + arg: 'recipientId', + type: 'number', + description: 'The recipient id to send to the recipient preferred language', + required: false + }, + { + arg: 'from', + type: 'string', + required: true + }, + { + arg: 'to', + type: 'string', + required: true + } + ], + returns: { + type: ['object'], + root: true + }, + http: { + path: '/:id/campaign-metrics-email', + verb: 'POST' + } + }); + + Self.campaignMetricsEmail = async ctx => { + const args = Object.assign({}, ctx.args); + const params = { + recipient: args.recipient, + lang: ctx.req.getLocale() + }; + + delete args.ctx; + for (const param in args) + params[param] = args[param]; + + const email = new Email('supplier-campaign-metrics', params); + + return email.send(); + }; +}; diff --git a/modules/supplier/back/methods/supplier/campaignMetricsPdf.js b/modules/supplier/back/methods/supplier/campaignMetricsPdf.js new file mode 100644 index 000000000..7bd65ffcb --- /dev/null +++ b/modules/supplier/back/methods/supplier/campaignMetricsPdf.js @@ -0,0 +1,65 @@ +const {Report} = require('vn-print'); + +module.exports = Self => { + Self.remoteMethodCtx('campaignMetricsPdf', { + description: 'Returns the campaign metrics pdf', + accessType: 'READ', + accepts: [ + { + arg: 'id', + type: 'number', + required: true, + http: {source: 'path'} + }, + { + arg: 'recipientId', + type: 'number', + description: 'The recipient id', + required: false + }, + { + arg: 'from', + type: 'string', + required: true + }, + { + arg: 'to', + type: 'string', + required: true + } + ], + returns: [ + { + arg: 'body', + type: 'file', + root: true + }, { + arg: 'Content-Type', + type: 'String', + http: {target: 'header'} + }, { + arg: 'Content-Disposition', + type: 'String', + http: {target: 'header'} + } + ], + http: { + path: '/:id/campaign-metrics-pdf', + verb: 'GET' + } + }); + + Self.campaignMetricsPdf = async(ctx, id) => { + const args = Object.assign({}, ctx.args); + const params = {lang: ctx.req.getLocale()}; + + delete args.ctx; + for (const param in args) + params[param] = args[param]; + + const report = new Report('supplier-campaign-metrics', params); + const stream = await report.toPdfStream(); + + return [stream, 'application/pdf', `filename="doc-${id}.pdf"`]; + }; +}; diff --git a/modules/supplier/back/models/supplier.js b/modules/supplier/back/models/supplier.js index c1be3488f..c9af7b297 100644 --- a/modules/supplier/back/models/supplier.js +++ b/modules/supplier/back/models/supplier.js @@ -8,6 +8,8 @@ module.exports = Self => { require('../methods/supplier/updateFiscalData')(Self); require('../methods/supplier/consumption')(Self); require('../methods/supplier/freeAgencies')(Self); + require('../methods/supplier/campaignMetricsPdf')(Self); + require('../methods/supplier/campaignMetricsEmail')(Self); Self.validatesPresenceOf('name', { message: 'The social name cannot be empty' diff --git a/modules/supplier/front/consumption/index.js b/modules/supplier/front/consumption/index.js index 21a30929d..8de6a1e71 100644 --- a/modules/supplier/front/consumption/index.js +++ b/modules/supplier/front/consumption/index.js @@ -33,7 +33,8 @@ class Controller extends Section { } showReport() { - this.vnReport.show('supplier-campaign-metrics', this.reportParams); + const path = `Suppliers/${this.supplier.id}/campaign-metrics-pdf`; + this.vnReport.show(path, this.reportParams); } sendEmail() { @@ -52,7 +53,9 @@ class Controller extends Section { const params = Object.assign({ recipient: contact.email }, this.reportParams); - this.vnEmail.send('supplier-campaign-metrics', params); + + const path = `Suppliers/${this.supplier.id}/campaign-metrics-email`; + this.vnEmail.send(path, params); } else { const message = this.$t(`This supplier doesn't have a contact with an email address`); this.vnApp.showError(message); diff --git a/modules/travel/back/methods/travel/extraCommunityEmail.js b/modules/travel/back/methods/travel/extraCommunityEmail.js new file mode 100644 index 000000000..251e64746 --- /dev/null +++ b/modules/travel/back/methods/travel/extraCommunityEmail.js @@ -0,0 +1,92 @@ +const {Email} = require('vn-print'); + +module.exports = Self => { + Self.remoteMethodCtx('extraCommunityEmail', { + description: 'Sends the extra community email with an attached PDF', + accessType: 'WRITE', + accepts: [ + { + arg: 'recipient', + type: 'string', + description: 'The recipient email', + required: true, + }, + { + arg: 'replyTo', + type: 'string', + description: 'The sender email to reply to', + required: false + }, + { + arg: 'recipientId', + type: 'number', + description: 'The recipient id to send to the recipient preferred language', + required: false + }, + { + arg: 'landedTo', + type: 'date' + }, + { + arg: 'shippedFrom', + type: 'date' + }, + { + arg: 'continent', + type: 'string' + }, + { + arg: 'ref', + type: 'string' + }, + { + arg: 'id', + type: 'number' + }, + { + arg: 'agencyModeFk', + type: 'number' + }, + { + arg: 'warehouseOutFk', + type: 'number' + }, + { + arg: 'warehouseInFk', + type: 'number' + }, + { + arg: 'totalEntries', + type: 'number' + }, + { + arg: 'cargoSupplierFk', + type: 'number' + } + ], + returns: { + type: ['object'], + root: true + }, + http: { + path: '/extra-community-email', + verb: 'POST' + } + }); + + Self.extraCommunityEmail = async ctx => { + const args = Object.assign({}, ctx.args); + const params = { + recipient: args.recipient, + lang: ctx.req.getLocale() + }; + + delete args.ctx; + for (const param in args) + params[param] = args[param]; + + const email = new Email('extra-community', params); + + return email.send(); + }; +}; diff --git a/modules/travel/back/methods/travel/extraCommunityPdf.js b/modules/travel/back/methods/travel/extraCommunityPdf.js new file mode 100644 index 000000000..61a99344d --- /dev/null +++ b/modules/travel/back/methods/travel/extraCommunityPdf.js @@ -0,0 +1,89 @@ +const {Report} = require('vn-print'); + +module.exports = Self => { + Self.remoteMethodCtx('extraCommunityPdf', { + description: 'Returns the extra community pdf', + accessType: 'READ', + accepts: [ + { + arg: 'recipientId', + type: 'number', + description: 'The recipient id', + required: false + }, + { + arg: 'landedTo', + type: 'date' + }, + { + arg: 'shippedFrom', + type: 'date' + }, + { + arg: 'continent', + type: 'string' + }, + { + arg: 'ref', + type: 'string' + }, + { + arg: 'id', + type: 'number' + }, + { + arg: 'agencyModeFk', + type: 'number' + }, + { + arg: 'warehouseOutFk', + type: 'number' + }, + { + arg: 'warehouseInFk', + type: 'number' + }, + { + arg: 'totalEntries', + type: 'number' + }, + { + arg: 'cargoSupplierFk', + type: 'number' + } + ], + returns: [ + { + arg: 'body', + type: 'file', + root: true + }, { + arg: 'Content-Type', + type: 'String', + http: {target: 'header'} + }, { + arg: 'Content-Disposition', + type: 'String', + http: {target: 'header'} + } + ], + http: { + path: '/extra-community-pdf', + verb: 'GET' + } + }); + + Self.extraCommunityPdf = async ctx => { + const args = Object.assign({}, ctx.args); + const params = {lang: ctx.req.getLocale()}; + + delete args.ctx; + for (const param in args) + params[param] = args[param]; + + const report = new Report('extra-community', params); + const stream = await report.toPdfStream(); + + return [stream, 'application/pdf', `filename="extra-community.pdf"`]; + }; +}; diff --git a/modules/travel/back/models/travel.js b/modules/travel/back/models/travel.js index 046153ee2..4bcf7b31d 100644 --- a/modules/travel/back/models/travel.js +++ b/modules/travel/back/models/travel.js @@ -10,6 +10,8 @@ module.exports = Self => { require('../methods/travel/extraCommunityFilter')(Self); require('../methods/travel/getAverageDays')(Self); require('../methods/travel/cloneWithEntries')(Self); + require('../methods/travel/extraCommunityPdf')(Self); + require('../methods/travel/extraCommunityEmail')(Self); Self.rewriteDbError(function(err) { if (err.code === 'ER_DUP_ENTRY') diff --git a/modules/travel/front/extra-community/index.js b/modules/travel/front/extra-community/index.js index 461712e9c..a4ac487e6 100644 --- a/modules/travel/front/extra-community/index.js +++ b/modules/travel/front/extra-community/index.js @@ -157,7 +157,7 @@ class Controller extends Section { } showReport() { - this.vnReport.show('extra-community', this.reportParams); + this.vnReport.show(`Travels/extra-community-pdf`, this.reportParams); } } diff --git a/print/templates/email/incoterms-authorization/incoterms-authorization.js b/print/templates/email/incoterms-authorization/incoterms-authorization.js index 051ff554b..977e62101 100755 --- a/print/templates/email/incoterms-authorization/incoterms-authorization.js +++ b/print/templates/email/incoterms-authorization/incoterms-authorization.js @@ -1,4 +1,4 @@ -const Component = require(`vn-report/core/component`); +const Component = require(`vn-print/core/component`); const emailHeader = new Component('email-header'); const emailFooter = new Component('email-footer'); const attachment = new Component('attachment'); diff --git a/print/templates/email/invoice/assets/css/import.js b/print/templates/email/invoice/assets/css/import.js index b44d6bd37..4b4bb7086 100644 --- a/print/templates/email/invoice/assets/css/import.js +++ b/print/templates/email/invoice/assets/css/import.js @@ -1,8 +1,11 @@ -const Stylesheet = require(`${appPath}/core/stylesheet`); +const Stylesheet = require(`vn-print/core/stylesheet`); + +const path = require('path'); +const vnPrintPath = path.resolve('print'); module.exports = new Stylesheet([ - `${appPath}/common/css/spacing.css`, - `${appPath}/common/css/misc.css`, - `${appPath}/common/css/layout.css`, - `${appPath}/common/css/email.css`]) + `${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/invoice/invoice.js b/print/templates/email/invoice/invoice.js index 6f6ea8683..1d6b9ed7c 100755 --- a/print/templates/email/invoice/invoice.js +++ b/print/templates/email/invoice/invoice.js @@ -1,15 +1,15 @@ -const Component = require(`${appPath}/core/component`); +const Component = require(`vn-print/core/component`); const emailHeader = new Component('email-header'); const emailFooter = new Component('email-footer'); module.exports = { name: 'invoice', async serverPrefetch() { - this.invoice = await this.fetchInvoice(this.refFk); + this.invoice = await this.fetchInvoice(this.ref); }, methods: { - fetchInvoice(refFk) { - return this.findOneFromDef('invoice', [refFk]); + fetchInvoice(ref) { + return this.findOneFromDef('invoice', [ref]); }, }, components: { @@ -17,7 +17,7 @@ module.exports = { 'email-footer': emailFooter.build() }, props: { - refFk: { + ref: { type: [Number, String], required: true } diff --git a/print/templates/email/supplier-campaign-metrics/assets/css/import.js b/print/templates/email/supplier-campaign-metrics/assets/css/import.js index b44d6bd37..4b4bb7086 100644 --- a/print/templates/email/supplier-campaign-metrics/assets/css/import.js +++ b/print/templates/email/supplier-campaign-metrics/assets/css/import.js @@ -1,8 +1,11 @@ -const Stylesheet = require(`${appPath}/core/stylesheet`); +const Stylesheet = require(`vn-print/core/stylesheet`); + +const path = require('path'); +const vnPrintPath = path.resolve('print'); module.exports = new Stylesheet([ - `${appPath}/common/css/spacing.css`, - `${appPath}/common/css/misc.css`, - `${appPath}/common/css/layout.css`, - `${appPath}/common/css/email.css`]) + `${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/supplier-campaign-metrics/supplier-campaign-metrics.js b/print/templates/email/supplier-campaign-metrics/supplier-campaign-metrics.js index 3cf290e4d..9cb9210ef 100755 --- a/print/templates/email/supplier-campaign-metrics/supplier-campaign-metrics.js +++ b/print/templates/email/supplier-campaign-metrics/supplier-campaign-metrics.js @@ -1,4 +1,4 @@ -const Component = require(`${appPath}/core/component`); +const Component = require(`vn-print/core/component`); const emailHeader = new Component('email-header'); const emailFooter = new Component('email-footer'); @@ -20,7 +20,7 @@ module.exports = { 'email-footer': emailFooter.build() }, props: { - recipientId: { + id: { type: [Number, String], required: true }, diff --git a/print/templates/reports/campaign-metrics/campaign-metrics.js b/print/templates/reports/campaign-metrics/campaign-metrics.js index da7cdd9ae..b60a2b7eb 100755 --- a/print/templates/reports/campaign-metrics/campaign-metrics.js +++ b/print/templates/reports/campaign-metrics/campaign-metrics.js @@ -26,7 +26,8 @@ module.exports = { props: { id: { type: [Number, String], - required: true + required: true, + description: 'The client id' }, from: { required: true 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 de56c2079..f7d21a2d3 100755 --- a/print/templates/reports/claim-pickup-order/claim-pickup-order.js +++ b/print/templates/reports/claim-pickup-order/claim-pickup-order.js @@ -37,7 +37,8 @@ module.exports = { props: { id: { type: [Number, String], - required: true + required: true, + description: 'The claim id' } } }; diff --git a/print/templates/reports/client-debt-statement/client-debt-statement.js b/print/templates/reports/client-debt-statement/client-debt-statement.js index dd8a30ff9..80c83b494 100755 --- a/print/templates/reports/client-debt-statement/client-debt-statement.js +++ b/print/templates/reports/client-debt-statement/client-debt-statement.js @@ -70,7 +70,8 @@ module.exports = { props: { id: { type: [Number, String], - required: true + required: true, + description: 'The client id' }, from: { required: true diff --git a/print/templates/reports/delivery-note/delivery-note.js b/print/templates/reports/delivery-note/delivery-note.js index d92329ac8..1037e5129 100755 --- a/print/templates/reports/delivery-note/delivery-note.js +++ b/print/templates/reports/delivery-note/delivery-note.js @@ -128,7 +128,8 @@ module.exports = { props: { id: { type: [Number, String], - required: true + required: true, + description: 'The ticket id' }, type: { type: String, diff --git a/print/templates/reports/driver-route/driver-route.js b/print/templates/reports/driver-route/driver-route.js index 41aa9f811..2de3d5192 100755 --- a/print/templates/reports/driver-route/driver-route.js +++ b/print/templates/reports/driver-route/driver-route.js @@ -45,7 +45,8 @@ module.exports = { props: { id: { type: [Number, String], - required: true + required: true, + description: 'The route id' } } }; diff --git a/print/templates/reports/entry-order/assets/css/import.js b/print/templates/reports/entry-order/assets/css/import.js index fd8796c2b..37a98dfdd 100644 --- a/print/templates/reports/entry-order/assets/css/import.js +++ b/print/templates/reports/entry-order/assets/css/import.js @@ -1,9 +1,12 @@ -const Stylesheet = require(`${appPath}/core/stylesheet`); +const Stylesheet = require(`vn-print/core/stylesheet`); + +const path = require('path'); +const vnPrintPath = path.resolve('print'); module.exports = new Stylesheet([ - `${appPath}/common/css/spacing.css`, - `${appPath}/common/css/misc.css`, - `${appPath}/common/css/layout.css`, - `${appPath}/common/css/report.css`, + `${vnPrintPath}/common/css/spacing.css`, + `${vnPrintPath}/common/css/misc.css`, + `${vnPrintPath}/common/css/layout.css`, + `${vnPrintPath}/common/css/report.css`, `${__dirname}/style.css`]) .mergeStyles(); diff --git a/print/templates/reports/entry-order/entry-order.js b/print/templates/reports/entry-order/entry-order.js index 52a56bf03..ff4a65e0c 100755 --- a/print/templates/reports/entry-order/entry-order.js +++ b/print/templates/reports/entry-order/entry-order.js @@ -1,13 +1,13 @@ -const Component = require(`${appPath}/core/component`); +const Component = require(`vn-print/core/component`); const reportHeader = new Component('report-header'); const reportFooter = new Component('report-footer'); module.exports = { name: 'entry-order', async serverPrefetch() { - this.supplier = await this.fetchSupplier(this.entryId); - this.entry = await this.fetchEntry(this.entryId); - this.buys = await this.fetchBuys(this.entryId); + this.supplier = await this.fetchSupplier(this.id); + this.entry = await this.fetchEntry(this.id); + this.buys = await this.fetchBuys(this.id); if (!this.entry) throw new Error('Something went wrong'); @@ -16,14 +16,14 @@ module.exports = { return {totalBalance: 0.00}; }, methods: { - fetchSupplier(entryId) { - return this.findOneFromDef('supplier', [entryId]); + fetchSupplier(id) { + return this.findOneFromDef('supplier', [id]); }, - fetchEntry(entryId) { - return this.findOneFromDef('entry', [entryId]); + fetchEntry(id) { + return this.findOneFromDef('entry', [id]); }, - fetchBuys(entryId) { - return this.rawSqlFromDef('buys', [entryId]); + fetchBuys(id) { + return this.rawSqlFromDef('buys', [id]); }, getTotal() { let total = 0.00; @@ -39,9 +39,10 @@ module.exports = { 'report-footer': reportFooter.build() }, props: { - entryId: { + id: { type: [Number, String], - required: true + required: true, + description: 'The entry id' } } }; diff --git a/print/templates/reports/exportation/assets/css/import.js b/print/templates/reports/exportation/assets/css/import.js index a2a9334cb..37a98dfdd 100644 --- a/print/templates/reports/exportation/assets/css/import.js +++ b/print/templates/reports/exportation/assets/css/import.js @@ -1,8 +1,12 @@ -const Stylesheet = require(`${appPath}/core/stylesheet`); +const Stylesheet = require(`vn-print/core/stylesheet`); + +const path = require('path'); +const vnPrintPath = path.resolve('print'); module.exports = new Stylesheet([ - `${appPath}/common/css/layout.css`, - `${appPath}/common/css/report.css`, - `${appPath}/common/css/misc.css`, + `${vnPrintPath}/common/css/spacing.css`, + `${vnPrintPath}/common/css/misc.css`, + `${vnPrintPath}/common/css/layout.css`, + `${vnPrintPath}/common/css/report.css`, `${__dirname}/style.css`]) .mergeStyles(); diff --git a/print/templates/reports/exportation/exportation.html b/print/templates/reports/exportation/exportation.html index f08af2cdb..252999467 100644 --- a/print/templates/reports/exportation/exportation.html +++ b/print/templates/reports/exportation/exportation.html @@ -31,9 +31,9 @@

({{$t('signature')}})

-

{{$t('signer.name')}}: JUAN VICENTE FERRER ROIG
-
{{$t('signer.ID')}}: 73943586N
-
{{$t('signer.position')}}: ADMINISTRADOR
+
{{$t('signer.name')}}: {{company.manager}}
+
{{$t('signer.ID')}}: {{company.managerFi}}
+
{{$t('signer.position')}}: {{$t('manager')}}

diff --git a/print/templates/reports/exportation/exportation.js b/print/templates/reports/exportation/exportation.js index a7e018c48..511b719f3 100755 --- a/print/templates/reports/exportation/exportation.js +++ b/print/templates/reports/exportation/exportation.js @@ -1,18 +1,20 @@ -const Component = require(`${appPath}/core/component`); +const Component = require(`vn-print/core/component`); const reportHeader = new Component('report-header'); const reportFooter = new Component('report-footer'); module.exports = { name: 'exportation', async serverPrefetch() { - this.invoice = await this.fetchInvoice(this.refFk); + this.invoice = await this.fetchInvoice(this.ref); if (!this.invoice) throw new Error('Something went wrong'); + + this.company = await this.findOneFromDef('company', [this.invoice.companyFk]); }, methods: { - fetchInvoice(refFk) { - return this.findOneFromDef('invoice', [refFk]); + fetchInvoice(ref) { + return this.findOneFromDef('invoice', [ref]); } }, computed: { @@ -27,9 +29,10 @@ module.exports = { 'report-footer': reportFooter.build() }, props: { - refFk: { + ref: { type: [Number, String], - required: true + required: true, + description: 'The invoice ref' } } }; diff --git a/print/templates/reports/exportation/locale/es.yml b/print/templates/reports/exportation/locale/es.yml index a689e245b..230263cb9 100644 --- a/print/templates/reports/exportation/locale/es.yml +++ b/print/templates/reports/exportation/locale/es.yml @@ -36,6 +36,7 @@ signer: name: Nombre del firmante ID: DNI del firmante position: Cargo del firmante +manager: Gerente months: - 'Enero' - 'Febrero' diff --git a/print/templates/reports/exportation/sql/company.sql b/print/templates/reports/exportation/sql/company.sql new file mode 100644 index 000000000..3ecef2071 --- /dev/null +++ b/print/templates/reports/exportation/sql/company.sql @@ -0,0 +1,9 @@ +SELECT + s.name, + s.city, + cl.name AS manager, + cl.fi AS managerFi +FROM company c + JOIN supplier s ON s.id = c.id + JOIN client cl ON cl.id = c.workerManagerFk +WHERE c.id = ? \ No newline at end of file diff --git a/print/templates/reports/exportation/sql/invoice.sql b/print/templates/reports/exportation/sql/invoice.sql index 7ea55e481..14e1568e2 100644 --- a/print/templates/reports/exportation/sql/invoice.sql +++ b/print/templates/reports/exportation/sql/invoice.sql @@ -1,7 +1,8 @@ SELECT io.id, io.ref, - io.issued + io.issued, + io.companyFk FROM invoiceOut io LEFT JOIN ticket t ON t.refFk = io.ref WHERE t.refFk = ? \ No newline at end of file diff --git a/print/templates/reports/extra-community/assets/css/import.js b/print/templates/reports/extra-community/assets/css/import.js index fd8796c2b..37a98dfdd 100644 --- a/print/templates/reports/extra-community/assets/css/import.js +++ b/print/templates/reports/extra-community/assets/css/import.js @@ -1,9 +1,12 @@ -const Stylesheet = require(`${appPath}/core/stylesheet`); +const Stylesheet = require(`vn-print/core/stylesheet`); + +const path = require('path'); +const vnPrintPath = path.resolve('print'); module.exports = new Stylesheet([ - `${appPath}/common/css/spacing.css`, - `${appPath}/common/css/misc.css`, - `${appPath}/common/css/layout.css`, - `${appPath}/common/css/report.css`, + `${vnPrintPath}/common/css/spacing.css`, + `${vnPrintPath}/common/css/misc.css`, + `${vnPrintPath}/common/css/layout.css`, + `${vnPrintPath}/common/css/report.css`, `${__dirname}/style.css`]) .mergeStyles(); diff --git a/print/templates/reports/extra-community/extra-community.js b/print/templates/reports/extra-community/extra-community.js index 4dad5dfff..9f009c234 100755 --- a/print/templates/reports/extra-community/extra-community.js +++ b/print/templates/reports/extra-community/extra-community.js @@ -1,7 +1,7 @@ -const Component = require(`${appPath}/core/component`); +const Component = require(`vn-print/core/component`); const reportHeader = new Component('report-header'); const reportFooter = new Component('report-footer'); -const db = require(`${appPath}/core/database`); +const db = require(`vn-print/core/database`); module.exports = { name: 'extra-community', @@ -82,7 +82,15 @@ module.exports = { let query = this.getSqlFromDef('travels'); query = db.merge(query, where); query = db.merge(query, 'GROUP BY t.id'); - query = db.merge(query, 'ORDER BY `shipped` ASC, `landed` ASC, `travelFk`, `loadPriority`, `agencyModeFk`, `evaNotes`'); + query = db.merge(query, ` + ORDER BY + shipped ASC, + landed ASC, + travelFk, + loadPriority, + agencyModeFk, + evaNotes + `); return this.rawSql(query); }, diff --git a/print/templates/reports/incoterms-authorization/incoterms-authorization.js b/print/templates/reports/incoterms-authorization/incoterms-authorization.js index 54f34136b..26637b8c2 100755 --- a/print/templates/reports/incoterms-authorization/incoterms-authorization.js +++ b/print/templates/reports/incoterms-authorization/incoterms-authorization.js @@ -22,7 +22,8 @@ module.exports = { props: { id: { type: [Number, String], - required: true + required: true, + description: 'The client id' }, companyId: { type: [Number, String], diff --git a/print/templates/reports/invoice-incoterms/assets/css/import.js b/print/templates/reports/invoice-incoterms/assets/css/import.js index fd8796c2b..37a98dfdd 100644 --- a/print/templates/reports/invoice-incoterms/assets/css/import.js +++ b/print/templates/reports/invoice-incoterms/assets/css/import.js @@ -1,9 +1,12 @@ -const Stylesheet = require(`${appPath}/core/stylesheet`); +const Stylesheet = require(`vn-print/core/stylesheet`); + +const path = require('path'); +const vnPrintPath = path.resolve('print'); module.exports = new Stylesheet([ - `${appPath}/common/css/spacing.css`, - `${appPath}/common/css/misc.css`, - `${appPath}/common/css/layout.css`, - `${appPath}/common/css/report.css`, + `${vnPrintPath}/common/css/spacing.css`, + `${vnPrintPath}/common/css/misc.css`, + `${vnPrintPath}/common/css/layout.css`, + `${vnPrintPath}/common/css/report.css`, `${__dirname}/style.css`]) .mergeStyles(); diff --git a/print/templates/reports/invoice-incoterms/invoice-incoterms.js b/print/templates/reports/invoice-incoterms/invoice-incoterms.js index 99a4e2e73..9c51bec11 100755 --- a/print/templates/reports/invoice-incoterms/invoice-incoterms.js +++ b/print/templates/reports/invoice-incoterms/invoice-incoterms.js @@ -1,13 +1,13 @@ -const Component = require(`${appPath}/core/component`); +const Component = require(`vn-print/core/component`); const reportHeader = new Component('report-header'); const reportFooter = new Component('report-footer'); module.exports = { name: 'invoice-incoterms', async serverPrefetch() { - this.invoice = await this.fetchInvoice(this.refFk); - this.client = await this.fetchClient(this.refFk); - this.incoterms = await this.fetchIncoterms(this.refFk); + this.invoice = await this.fetchInvoice(this.ref); + this.client = await this.fetchClient(this.ref); + this.incoterms = await this.fetchIncoterms(this.ref); if (!this.invoice) throw new Error('Something went wrong'); @@ -16,14 +16,14 @@ module.exports = { }, methods: { - fetchInvoice(refFk) { - return this.findOneFromDef('invoice', [refFk]); + fetchInvoice(ref) { + return this.findOneFromDef('invoice', [ref]); }, - fetchClient(refFk) { - return this.findOneFromDef('client', [refFk]); + fetchClient(ref) { + return this.findOneFromDef('client', [ref]); }, - fetchIncoterms(refFk) { - return this.findOneFromDef('incoterms', [refFk, refFk, refFk]); + fetchIncoterms(ref) { + return this.findOneFromDef('incoterms', [ref, ref, ref]); } }, components: { @@ -31,9 +31,10 @@ module.exports = { 'report-footer': reportFooter.build() }, props: { - refFk: { + ref: { type: [Number, String], - required: true + required: true, + description: 'The invoice ref' } } }; diff --git a/print/templates/reports/invoice/assets/css/import.js b/print/templates/reports/invoice/assets/css/import.js index fd8796c2b..37a98dfdd 100644 --- a/print/templates/reports/invoice/assets/css/import.js +++ b/print/templates/reports/invoice/assets/css/import.js @@ -1,9 +1,12 @@ -const Stylesheet = require(`${appPath}/core/stylesheet`); +const Stylesheet = require(`vn-print/core/stylesheet`); + +const path = require('path'); +const vnPrintPath = path.resolve('print'); module.exports = new Stylesheet([ - `${appPath}/common/css/spacing.css`, - `${appPath}/common/css/misc.css`, - `${appPath}/common/css/layout.css`, - `${appPath}/common/css/report.css`, + `${vnPrintPath}/common/css/spacing.css`, + `${vnPrintPath}/common/css/misc.css`, + `${vnPrintPath}/common/css/layout.css`, + `${vnPrintPath}/common/css/report.css`, `${__dirname}/style.css`]) .mergeStyles(); diff --git a/print/templates/reports/invoice/invoice.js b/print/templates/reports/invoice/invoice.js index fd4acd4b5..443d6cef7 100755 --- a/print/templates/reports/invoice/invoice.js +++ b/print/templates/reports/invoice/invoice.js @@ -1,5 +1,5 @@ -const Component = require(`${appPath}/core/component`); -const Report = require(`${appPath}/core/report`); +const Component = require(`vn-print/core/component`); +const Report = require(`vn-print/core/report`); const reportHeader = new Component('report-header'); const reportFooter = new Component('report-footer'); const invoiceIncoterms = new Report('invoice-incoterms'); @@ -7,15 +7,15 @@ const invoiceIncoterms = new Report('invoice-incoterms'); module.exports = { name: 'invoice', async serverPrefetch() { - 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.refFk); - this.hasIncoterms = await this.fetchHasIncoterms(this.refFk); + this.invoice = await this.fetchInvoice(this.ref); + this.client = await this.fetchClient(this.ref); + this.taxes = await this.fetchTaxes(this.ref); + this.intrastat = await this.fetchIntrastat(this.ref); + this.rectified = await this.fetchRectified(this.ref); + this.hasIncoterms = await this.fetchHasIncoterms(this.ref); - const tickets = await this.fetchTickets(this.refFk); - const sales = await this.fetchSales(this.refFk); + const tickets = await this.fetchTickets(this.ref); + const sales = await this.fetchSales(this.ref); const map = new Map(); @@ -65,29 +65,29 @@ module.exports = { } }, methods: { - fetchInvoice(refFk) { - return this.findOneFromDef('invoice', [refFk]); + fetchInvoice(ref) { + return this.findOneFromDef('invoice', [ref]); }, - fetchClient(refFk) { - return this.findOneFromDef('client', [refFk]); + fetchClient(ref) { + return this.findOneFromDef('client', [ref]); }, - fetchTickets(refFk) { - return this.rawSqlFromDef('tickets', [refFk]); + fetchTickets(ref) { + return this.rawSqlFromDef('tickets', [ref]); }, - fetchSales(refFk) { - return this.rawSqlFromDef('sales', [refFk, refFk]); + fetchSales(ref) { + return this.rawSqlFromDef('sales', [ref, ref]); }, - fetchTaxes(refFk) { - return this.rawSqlFromDef(`taxes`, [refFk]); + fetchTaxes(ref) { + return this.rawSqlFromDef(`taxes`, [ref]); }, - fetchIntrastat(refFk) { - return this.rawSqlFromDef(`intrastat`, [refFk, refFk, refFk]); + fetchIntrastat(ref) { + return this.rawSqlFromDef(`intrastat`, [ref, ref, ref]); }, - fetchRectified(refFk) { - return this.rawSqlFromDef(`rectified`, [refFk]); + fetchRectified(ref) { + return this.rawSqlFromDef(`rectified`, [ref]); }, - fetchHasIncoterms(refFk) { - return this.findValueFromDef(`hasIncoterms`, [refFk]); + fetchHasIncoterms(ref) { + return this.findValueFromDef(`hasIncoterms`, [ref]); }, saleImport(sale) { const price = sale.quantity * sale.price; @@ -115,8 +115,9 @@ module.exports = { 'invoice-incoterms': invoiceIncoterms.build() }, props: { - refFk: { - type: String + ref: { + type: String, + description: 'The invoice ref' } } }; diff --git a/print/templates/reports/item-label/assets/css/import.js b/print/templates/reports/item-label/assets/css/import.js index fd8796c2b..37a98dfdd 100644 --- a/print/templates/reports/item-label/assets/css/import.js +++ b/print/templates/reports/item-label/assets/css/import.js @@ -1,9 +1,12 @@ -const Stylesheet = require(`${appPath}/core/stylesheet`); +const Stylesheet = require(`vn-print/core/stylesheet`); + +const path = require('path'); +const vnPrintPath = path.resolve('print'); module.exports = new Stylesheet([ - `${appPath}/common/css/spacing.css`, - `${appPath}/common/css/misc.css`, - `${appPath}/common/css/layout.css`, - `${appPath}/common/css/report.css`, + `${vnPrintPath}/common/css/spacing.css`, + `${vnPrintPath}/common/css/misc.css`, + `${vnPrintPath}/common/css/layout.css`, + `${vnPrintPath}/common/css/report.css`, `${__dirname}/style.css`]) .mergeStyles(); diff --git a/print/templates/reports/item-label/item-label.js b/print/templates/reports/item-label/item-label.js index 730d8ad99..09bc38abc 100755 --- a/print/templates/reports/item-label/item-label.js +++ b/print/templates/reports/item-label/item-label.js @@ -1,4 +1,4 @@ -const Component = require(`${appPath}/core/component`); +const Component = require(`vn-print/core/component`); const reportHeader = new Component('report-header'); const reportFooter = new Component('report-footer'); const qrcode = require('qrcode'); @@ -6,9 +6,9 @@ const qrcode = require('qrcode'); module.exports = { name: 'item-label', async serverPrefetch() { - this.item = await this.fetchItem(this.itemId, this.warehouseId); - this.tags = await this.fetchItemTags(this.itemId); - this.barcode = await this.getBarcodeBase64(this.itemId); + this.item = await this.fetchItem(this.id, this.warehouseId); + this.tags = await this.fetchItemTags(this.id); + this.barcode = await this.getBarcodeBase64(this.id); if (!this.item) throw new Error('Something went wrong'); @@ -31,16 +31,16 @@ module.exports = { fetchItem(id, warehouseId) { return this.findOneFromDef('item', [id, warehouseId]); }, - fetchItemTags(itemId) { - return this.rawSqlFromDef('itemTags', [itemId]).then(rows => { + fetchItemTags(id) { + return this.rawSqlFromDef('itemTags', [id]).then(rows => { const tags = {}; rows.forEach(row => tags[row.code] = row.value); return tags; }); }, - getBarcodeBase64(itemId) { - return qrcode.toDataURL(itemId, {margin: 0}); + getBarcodeBase64(id) { + return qrcode.toDataURL(id, {margin: 0}); }, packing() { const stems = this.item.stems ? this.item.stems : 1; @@ -52,8 +52,9 @@ module.exports = { 'report-footer': reportFooter.build() }, props: { - itemId: { - required: true + id: { + required: true, + description: 'The item id' }, warehouseId: { required: true diff --git a/print/templates/reports/letter-debtor/letter-debtor.js b/print/templates/reports/letter-debtor/letter-debtor.js index 626596297..80d4cba9b 100755 --- a/print/templates/reports/letter-debtor/letter-debtor.js +++ b/print/templates/reports/letter-debtor/letter-debtor.js @@ -64,7 +64,8 @@ module.exports = { props: { id: { type: [Number, String], - required: true + required: true, + description: 'The client id' }, companyId: { type: [Number, String], diff --git a/print/templates/reports/receipt/assets/css/import.js b/print/templates/reports/receipt/assets/css/import.js index a2a9334cb..37a98dfdd 100644 --- a/print/templates/reports/receipt/assets/css/import.js +++ b/print/templates/reports/receipt/assets/css/import.js @@ -1,8 +1,12 @@ -const Stylesheet = require(`${appPath}/core/stylesheet`); +const Stylesheet = require(`vn-print/core/stylesheet`); + +const path = require('path'); +const vnPrintPath = path.resolve('print'); module.exports = new Stylesheet([ - `${appPath}/common/css/layout.css`, - `${appPath}/common/css/report.css`, - `${appPath}/common/css/misc.css`, + `${vnPrintPath}/common/css/spacing.css`, + `${vnPrintPath}/common/css/misc.css`, + `${vnPrintPath}/common/css/layout.css`, + `${vnPrintPath}/common/css/report.css`, `${__dirname}/style.css`]) .mergeStyles(); diff --git a/print/templates/reports/receipt/receipt.js b/print/templates/reports/receipt/receipt.js index d7f4dd6da..401aa1ef3 100755 --- a/print/templates/reports/receipt/receipt.js +++ b/print/templates/reports/receipt/receipt.js @@ -1,22 +1,22 @@ -const Component = require(`${appPath}/core/component`); +const Component = require(`vn-print/core/component`); const reportHeader = new Component('report-header'); const reportFooter = new Component('report-footer'); module.exports = { name: 'receipt', async serverPrefetch() { - this.client = await this.fetchClient(this.receiptId); - this.receipt = await this.fetchReceipt(this.receiptId); + this.client = await this.fetchClient(this.id); + this.receipt = await this.fetchReceipt(this.id); if (!this.receipt) throw new Error('Something went wrong'); }, methods: { - fetchClient(receiptId) { - return this.findOneFromDef('client', [receiptId]); + fetchClient(id) { + return this.findOneFromDef('client', [id]); }, - fetchReceipt(receiptId) { - return this.findOneFromDef('receipt', [receiptId]); + fetchReceipt(id) { + return this.findOneFromDef('receipt', [id]); } }, components: { @@ -24,9 +24,10 @@ module.exports = { 'report-footer': reportFooter.build() }, props: { - receiptId: { + id: { type: [Number, String], - required: true + required: true, + description: 'Receipt id' } } }; diff --git a/print/templates/reports/sepa-core/sepa-core.js b/print/templates/reports/sepa-core/sepa-core.js index 1537a265a..73e0beaaa 100755 --- a/print/templates/reports/sepa-core/sepa-core.js +++ b/print/templates/reports/sepa-core/sepa-core.js @@ -41,7 +41,8 @@ const rptSepaCore = { props: { id: { type: [Number, String], - required: true + required: true, + description: 'The client id' }, companyId: { type: [Number, String], diff --git a/print/templates/reports/supplier-campaign-metrics/assets/css/import.js b/print/templates/reports/supplier-campaign-metrics/assets/css/import.js index fd8796c2b..37a98dfdd 100644 --- a/print/templates/reports/supplier-campaign-metrics/assets/css/import.js +++ b/print/templates/reports/supplier-campaign-metrics/assets/css/import.js @@ -1,9 +1,12 @@ -const Stylesheet = require(`${appPath}/core/stylesheet`); +const Stylesheet = require(`vn-print/core/stylesheet`); + +const path = require('path'); +const vnPrintPath = path.resolve('print'); module.exports = new Stylesheet([ - `${appPath}/common/css/spacing.css`, - `${appPath}/common/css/misc.css`, - `${appPath}/common/css/layout.css`, - `${appPath}/common/css/report.css`, + `${vnPrintPath}/common/css/spacing.css`, + `${vnPrintPath}/common/css/misc.css`, + `${vnPrintPath}/common/css/layout.css`, + `${vnPrintPath}/common/css/report.css`, `${__dirname}/style.css`]) .mergeStyles(); diff --git a/print/templates/reports/supplier-campaign-metrics/supplier-campaign-metrics.js b/print/templates/reports/supplier-campaign-metrics/supplier-campaign-metrics.js index 1a460daa9..6a58cbd0e 100755 --- a/print/templates/reports/supplier-campaign-metrics/supplier-campaign-metrics.js +++ b/print/templates/reports/supplier-campaign-metrics/supplier-campaign-metrics.js @@ -1,12 +1,12 @@ -const Component = require(`${appPath}/core/component`); +const Component = require(`vn-print/core/component`); const reportHeader = new Component('report-header'); const reportFooter = new Component('report-footer'); module.exports = { name: 'supplier-campaign-metrics', async serverPrefetch() { - this.supplier = await this.fetchSupplier(this.recipientId); - let entries = await this.fetchEntries(this.recipientId, this.from, this.to); + this.supplier = await this.fetchSupplier(this.id); + let entries = await this.fetchEntries(this.id, this.from, this.to); const entriesId = []; @@ -48,9 +48,10 @@ module.exports = { 'report-footer': reportFooter.build() }, props: { - recipientId: { + id: { type: [Number, String], - required: true + required: true, + description: 'The supplier id' }, from: { required: true diff --git a/print/templates/reports/zone/assets/css/import.js b/print/templates/reports/zone/assets/css/import.js index a2a9334cb..37a98dfdd 100644 --- a/print/templates/reports/zone/assets/css/import.js +++ b/print/templates/reports/zone/assets/css/import.js @@ -1,8 +1,12 @@ -const Stylesheet = require(`${appPath}/core/stylesheet`); +const Stylesheet = require(`vn-print/core/stylesheet`); + +const path = require('path'); +const vnPrintPath = path.resolve('print'); module.exports = new Stylesheet([ - `${appPath}/common/css/layout.css`, - `${appPath}/common/css/report.css`, - `${appPath}/common/css/misc.css`, + `${vnPrintPath}/common/css/spacing.css`, + `${vnPrintPath}/common/css/misc.css`, + `${vnPrintPath}/common/css/layout.css`, + `${vnPrintPath}/common/css/report.css`, `${__dirname}/style.css`]) .mergeStyles(); diff --git a/print/templates/reports/zone/zone.js b/print/templates/reports/zone/zone.js index d611e1e53..bbce9df36 100755 --- a/print/templates/reports/zone/zone.js +++ b/print/templates/reports/zone/zone.js @@ -1,20 +1,21 @@ module.exports = { name: 'zone', async serverPrefetch() { - this.zone = await this.fetchZone(this.routeId); + this.zone = await this.fetchZone(this.id); if (!this.zone) throw new Error('Something went wrong'); }, methods: { - fetchZone(routeId) { - return this.findOneFromDef('zone', [routeId]); + fetchZone(id) { + return this.findOneFromDef('zone', [id]); } }, props: { - routeId: { + id: { type: [Number, String], - required: true + required: true, + description: 'The zone id' } } };