Campaign metrics
This commit is contained in:
parent
5a43bdb6c9
commit
8105c12a18
|
@ -0,0 +1,6 @@
|
||||||
|
INSERT INTO `salix`.`ACL` (model, property, accessType, permission, principalType, principalId)
|
||||||
|
VALUES
|
||||||
|
('Ticket', 'deliveryNotePdf', 'READ', 'ALLOW', 'ROLE', 'employee'),
|
||||||
|
('Ticket', 'deliveryNoteEmail', 'READ', 'ALLOW', 'ROLE', 'employee'),
|
||||||
|
('Client', 'campaignMetricsPdf', 'READ', 'ALLOW', 'ROLE', 'employee'),
|
||||||
|
('Client', 'campaignMetricsEmail', 'READ', 'ALLOW', 'ROLE', 'employee');
|
|
@ -14,8 +14,8 @@ class Email {
|
||||||
* @param {Object} params The email parameters
|
* @param {Object} params The email parameters
|
||||||
* @return {Promise} Promise resolved when it's sent
|
* @return {Promise} Promise resolved when it's sent
|
||||||
*/
|
*/
|
||||||
send(url, params) {
|
send(path, params) {
|
||||||
return this.$http.post(url, params)
|
return this.$http.post(path, params)
|
||||||
.then(() => this.vnApp.showMessage(this.$t('Notification sent!')));
|
.then(() => this.vnApp.showMessage(this.$t('Notification sent!')));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -13,12 +13,12 @@ class Report {
|
||||||
* @param {String} report The report name
|
* @param {String} report The report name
|
||||||
* @param {Object} params The report parameters
|
* @param {Object} params The report parameters
|
||||||
*/
|
*/
|
||||||
show(url, params) {
|
show(path, params) {
|
||||||
params = Object.assign({
|
params = Object.assign({
|
||||||
access_token: this.vnToken.token
|
access_token: this.vnToken.token
|
||||||
}, params);
|
}, params);
|
||||||
const serializedParams = this.$httpParamSerializer(params);
|
const serializedParams = this.$httpParamSerializer(params);
|
||||||
window.open(`api/${url}?${serializedParams}`);
|
window.open(`api/${path}?${serializedParams}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -232,6 +232,5 @@
|
||||||
"Fichadas impares": "Fichadas impares",
|
"Fichadas impares": "Fichadas impares",
|
||||||
"Descanso diario 12h.": "Descanso diario 12h.",
|
"Descanso diario 12h.": "Descanso diario 12h.",
|
||||||
"Descanso semanal 36h. / 72h.": "Descanso semanal 36h. / 72h.",
|
"Descanso semanal 36h. / 72h.": "Descanso semanal 36h. / 72h.",
|
||||||
"Dirección incorrecta": "Dirección incorrecta",
|
"Dirección incorrecta": "Dirección incorrecta"
|
||||||
"deliveryNote": "albaran-{{ticketId}}"
|
|
||||||
}
|
}
|
|
@ -0,0 +1,68 @@
|
||||||
|
const {Report, Email, smtp} = require('vn-print');
|
||||||
|
|
||||||
|
module.exports = Self => {
|
||||||
|
Self.remoteMethodCtx('campaignMetricsEmail', {
|
||||||
|
description: 'Sends the campaign metrics email with an attached PDF',
|
||||||
|
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: '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, id) => {
|
||||||
|
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('campaign-metrics', params);
|
||||||
|
|
||||||
|
return email.send();
|
||||||
|
};
|
||||||
|
};
|
|
@ -0,0 +1,65 @@
|
||||||
|
const { Report } = require('vn-print');
|
||||||
|
|
||||||
|
module.exports = Self => {
|
||||||
|
Self.remoteMethodCtx('campaignMetricsPdf', {
|
||||||
|
description: 'Returns the delivery note pdf',
|
||||||
|
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: '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('campaign-metrics', params);
|
||||||
|
const stream = await report.toPdfStream();
|
||||||
|
|
||||||
|
return [stream, 'application/pdf', `filename="doc-${id}.pdf"`];
|
||||||
|
};
|
||||||
|
};
|
|
@ -34,6 +34,8 @@ module.exports = Self => {
|
||||||
require('../methods/client/updatePortfolio')(Self);
|
require('../methods/client/updatePortfolio')(Self);
|
||||||
require('../methods/client/updateUser')(Self);
|
require('../methods/client/updateUser')(Self);
|
||||||
require('../methods/client/uploadFile')(Self);
|
require('../methods/client/uploadFile')(Self);
|
||||||
|
require('../methods/client/campaignMetricsPdf')(Self);
|
||||||
|
require('../methods/client/campaignMetricsEmail')(Self);
|
||||||
|
|
||||||
// Validations
|
// Validations
|
||||||
|
|
||||||
|
|
|
@ -45,11 +45,13 @@ class Controller extends Section {
|
||||||
}
|
}
|
||||||
|
|
||||||
showReport() {
|
showReport() {
|
||||||
this.vnReport.show('campaign-metrics', this.reportParams);
|
const path = `Clients/${this.client.id}/campaign-metrics-pdf`;
|
||||||
|
this.vnReport.show(path, this.reportParams);
|
||||||
}
|
}
|
||||||
|
|
||||||
sendEmail() {
|
sendEmail() {
|
||||||
this.vnEmail.send('campaign-metrics', this.reportParams);
|
const path = `Clients/${this.client.id}/campaign-metrics-email`;
|
||||||
|
this.vnEmail.send(path, this.reportParams);
|
||||||
}
|
}
|
||||||
|
|
||||||
changeGrouped(value) {
|
changeGrouped(value) {
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
const {Report, Email, smtp} = require('vn-print');
|
const { Email } = require('vn-print');
|
||||||
|
|
||||||
module.exports = Self => {
|
module.exports = Self => {
|
||||||
Self.remoteMethodCtx('deliveryNoteEmail', {
|
Self.remoteMethodCtx('deliveryNoteEmail', {
|
||||||
description: '',
|
description: 'Sends the delivery note email with an attached PDF',
|
||||||
accepts: [
|
accepts: [
|
||||||
{
|
{
|
||||||
arg: 'id',
|
arg: 'id',
|
||||||
|
@ -47,22 +47,15 @@ module.exports = Self => {
|
||||||
});
|
});
|
||||||
|
|
||||||
Self.deliveryNoteEmail = async(ctx, id) => {
|
Self.deliveryNoteEmail = async(ctx, id) => {
|
||||||
const args = ctx.args;
|
const args = Object.assign({}, ctx.args);
|
||||||
|
|
||||||
const params = {
|
const params = {
|
||||||
ticketId: id,
|
|
||||||
recipient: args.recipient,
|
recipient: args.recipient,
|
||||||
lang: ctx.req.getLocale()
|
lang: ctx.req.getLocale()
|
||||||
};
|
};
|
||||||
|
|
||||||
if (args.recipientId)
|
delete args.ctx;
|
||||||
params.recipientId = args.recipientId;
|
for (const param in args)
|
||||||
|
params[param] = args[param];
|
||||||
if (args.replyTo)
|
|
||||||
params.replyTo = args.replyTo;
|
|
||||||
|
|
||||||
if (args.type)
|
|
||||||
params.type = args.type;
|
|
||||||
|
|
||||||
const email = new Email('delivery-note', params);
|
const email = new Email('delivery-note', params);
|
||||||
|
|
||||||
|
|
|
@ -46,25 +46,16 @@ module.exports = Self => {
|
||||||
});
|
});
|
||||||
|
|
||||||
Self.deliveryNotePdf = async(ctx, id) => {
|
Self.deliveryNotePdf = async(ctx, id) => {
|
||||||
const args = ctx.args;
|
const args = Object.assign({}, ctx.args);
|
||||||
const $t = ctx.req.__;
|
const params = {lang: ctx.req.getLocale()};
|
||||||
|
|
||||||
const params = {
|
delete args.ctx;
|
||||||
ticketId: id,
|
for (const param in args)
|
||||||
lang: ctx.req.getLocale()
|
params[param] = args[param];
|
||||||
};
|
|
||||||
|
|
||||||
if (args.recipientId)
|
|
||||||
params.recipientId = args.recipientId;
|
|
||||||
|
|
||||||
if (args.type)
|
|
||||||
params.type = args.type;
|
|
||||||
|
|
||||||
const report = new Report('delivery-note', params);
|
const report = new Report('delivery-note', params);
|
||||||
const stream = await report.toPdfStream();
|
const stream = await report.toPdfStream();
|
||||||
|
|
||||||
const fileName = $t('deliveryNote', {ticketId: id});
|
return [stream, 'application/pdf', `filename="doc-${id}.pdf"`];
|
||||||
|
|
||||||
return [stream, 'application/pdf', `filename="${fileName}.pdf"`];
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
@ -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([
|
module.exports = new Stylesheet([
|
||||||
`${appPath}/common/css/spacing.css`,
|
`${vnPrintPath}/common/css/spacing.css`,
|
||||||
`${appPath}/common/css/misc.css`,
|
`${vnPrintPath}/common/css/misc.css`,
|
||||||
`${appPath}/common/css/layout.css`,
|
`${vnPrintPath}/common/css/layout.css`,
|
||||||
`${appPath}/common/css/email.css`])
|
`${vnPrintPath}/common/css/email.css`])
|
||||||
.mergeStyles();
|
.mergeStyles();
|
|
@ -1,4 +1,4 @@
|
||||||
const Component = require(`${appPath}/core/component`);
|
const Component = require(`vn-print/core/component`);
|
||||||
const emailHeader = new Component('email-header');
|
const emailHeader = new Component('email-header');
|
||||||
const emailFooter = new Component('email-footer');
|
const emailFooter = new Component('email-footer');
|
||||||
|
|
||||||
|
@ -20,7 +20,7 @@ module.exports = {
|
||||||
'email-footer': emailFooter.build()
|
'email-footer': emailFooter.build()
|
||||||
},
|
},
|
||||||
props: {
|
props: {
|
||||||
recipientId: {
|
id: {
|
||||||
type: [Number, String],
|
type: [Number, String],
|
||||||
required: true
|
required: true
|
||||||
},
|
},
|
||||||
|
|
|
@ -25,7 +25,7 @@
|
||||||
<div class="grid-block vn-pa-ml">
|
<div class="grid-block vn-pa-ml">
|
||||||
<h1>{{ $t('title') }}</h1>
|
<h1>{{ $t('title') }}</h1>
|
||||||
<p>{{$t('dear')}},</p>
|
<p>{{$t('dear')}},</p>
|
||||||
<p v-html="$t('description', [ticketId])"></p>
|
<p v-html="$t('description', [id])"></p>
|
||||||
<p v-html="$t('poll')"></p>
|
<p v-html="$t('poll')"></p>
|
||||||
<p v-html="$t('help')"></p>
|
<p v-html="$t('help')"></p>
|
||||||
<p v-html="$t('conclusion')"></p>
|
<p v-html="$t('conclusion')"></p>
|
||||||
|
|
|
@ -9,7 +9,7 @@ module.exports = {
|
||||||
'email-footer': emailFooter.build()
|
'email-footer': emailFooter.build()
|
||||||
},
|
},
|
||||||
props: {
|
props: {
|
||||||
ticketId: {
|
id: {
|
||||||
type: [Number, String],
|
type: [Number, String],
|
||||||
required: true
|
required: true
|
||||||
}
|
}
|
||||||
|
|
|
@ -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([
|
module.exports = new Stylesheet([
|
||||||
`${appPath}/common/css/spacing.css`,
|
`${vnPrintPath}/common/css/spacing.css`,
|
||||||
`${appPath}/common/css/misc.css`,
|
`${vnPrintPath}/common/css/misc.css`,
|
||||||
`${appPath}/common/css/layout.css`,
|
`${vnPrintPath}/common/css/layout.css`,
|
||||||
`${appPath}/common/css/report.css`,
|
`${vnPrintPath}/common/css/report.css`,
|
||||||
`${__dirname}/style.css`])
|
`${__dirname}/style.css`])
|
||||||
.mergeStyles();
|
.mergeStyles();
|
||||||
|
|
|
@ -1,22 +1,22 @@
|
||||||
const Component = require(`${appPath}/core/component`);
|
const Component = require(`vn-print/core/component`);
|
||||||
const reportHeader = new Component('report-header');
|
const reportHeader = new Component('report-header');
|
||||||
const reportFooter = new Component('report-footer');
|
const reportFooter = new Component('report-footer');
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
name: 'campaign-metrics',
|
name: 'campaign-metrics',
|
||||||
async serverPrefetch() {
|
async serverPrefetch() {
|
||||||
this.client = await this.fetchClient(this.recipientId);
|
this.client = await this.fetchClient(this.id);
|
||||||
this.sales = await this.fetchSales(this.recipientId, this.from, this.to);
|
this.sales = await this.fetchSales(this.id, this.from, this.to);
|
||||||
|
|
||||||
if (!this.client)
|
if (!this.client)
|
||||||
throw new Error('Something went wrong');
|
throw new Error('Something went wrong');
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
fetchClient(clientId) {
|
fetchClient(id) {
|
||||||
return this.findOneFromDef('client', [clientId]);
|
return this.findOneFromDef('client', [id]);
|
||||||
},
|
},
|
||||||
fetchSales(clientId, from, to) {
|
fetchSales(id, from, to) {
|
||||||
return this.rawSqlFromDef('sales', [clientId, from, to]);
|
return this.rawSqlFromDef('sales', [id, from, to]);
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
components: {
|
components: {
|
||||||
|
@ -24,7 +24,7 @@ module.exports = {
|
||||||
'report-footer': reportFooter.build()
|
'report-footer': reportFooter.build()
|
||||||
},
|
},
|
||||||
props: {
|
props: {
|
||||||
recipientId: {
|
id: {
|
||||||
type: [Number, String],
|
type: [Number, String],
|
||||||
required: true
|
required: true
|
||||||
},
|
},
|
||||||
|
|
|
@ -8,14 +8,14 @@ const fs = require('fs-extra');
|
||||||
module.exports = {
|
module.exports = {
|
||||||
name: 'delivery-note',
|
name: 'delivery-note',
|
||||||
async serverPrefetch() {
|
async serverPrefetch() {
|
||||||
this.client = await this.fetchClient(this.ticketId);
|
this.client = await this.fetchClient(this.id);
|
||||||
this.ticket = await this.fetchTicket(this.ticketId);
|
this.ticket = await this.fetchTicket(this.id);
|
||||||
this.sales = await this.fetchSales(this.ticketId);
|
this.sales = await this.fetchSales(this.id);
|
||||||
this.address = await this.fetchAddress(this.ticketId);
|
this.address = await this.fetchAddress(this.id);
|
||||||
this.services = await this.fetchServices(this.ticketId);
|
this.services = await this.fetchServices(this.id);
|
||||||
this.taxes = await this.fetchTaxes(this.ticketId);
|
this.taxes = await this.fetchTaxes(this.id);
|
||||||
this.packagings = await this.fetchPackagings(this.ticketId);
|
this.packagings = await this.fetchPackagings(this.id);
|
||||||
this.signature = await this.fetchSignature(this.ticketId);
|
this.signature = await this.fetchSignature(this.id);
|
||||||
|
|
||||||
if (!this.ticket)
|
if (!this.ticket)
|
||||||
throw new Error('Something went wrong');
|
throw new Error('Something went wrong');
|
||||||
|
@ -53,33 +53,33 @@ module.exports = {
|
||||||
},
|
},
|
||||||
footerType() {
|
footerType() {
|
||||||
const translatedType = this.$t(this.deliverNoteType);
|
const translatedType = this.$t(this.deliverNoteType);
|
||||||
return `${translatedType} ${this.ticketId}`;
|
return `${translatedType} ${this.id}`;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
fetchClient(ticketId) {
|
fetchClient(id) {
|
||||||
return this.findOneFromDef('client', [ticketId]);
|
return this.findOneFromDef('client', [id]);
|
||||||
},
|
},
|
||||||
fetchTicket(ticketId) {
|
fetchTicket(id) {
|
||||||
return this.findOneFromDef('ticket', [ticketId]);
|
return this.findOneFromDef('ticket', [id]);
|
||||||
},
|
},
|
||||||
fetchAddress(ticketId) {
|
fetchAddress(id) {
|
||||||
return this.findOneFromDef(`address`, [ticketId]);
|
return this.findOneFromDef(`address`, [id]);
|
||||||
},
|
},
|
||||||
fetchSignature(ticketId) {
|
fetchSignature(id) {
|
||||||
return this.findOneFromDef('signature', [ticketId]);
|
return this.findOneFromDef('signature', [id]);
|
||||||
},
|
},
|
||||||
fetchTaxes(ticketId) {
|
fetchTaxes(id) {
|
||||||
return this.findOneFromDef(`taxes`, [ticketId]);
|
return this.findOneFromDef(`taxes`, [id]);
|
||||||
},
|
},
|
||||||
fetchSales(ticketId) {
|
fetchSales(id) {
|
||||||
return this.rawSqlFromDef('sales', [ticketId]);
|
return this.rawSqlFromDef('sales', [id]);
|
||||||
},
|
},
|
||||||
fetchPackagings(ticketId) {
|
fetchPackagings(id) {
|
||||||
return this.rawSqlFromDef('packagings', [ticketId]);
|
return this.rawSqlFromDef('packagings', [id]);
|
||||||
},
|
},
|
||||||
fetchServices(ticketId) {
|
fetchServices(id) {
|
||||||
return this.rawSqlFromDef('services', [ticketId]);
|
return this.rawSqlFromDef('services', [id]);
|
||||||
},
|
},
|
||||||
|
|
||||||
getSubTotal() {
|
getSubTotal() {
|
||||||
|
@ -126,7 +126,7 @@ module.exports = {
|
||||||
'report-footer': reportFooter.build()
|
'report-footer': reportFooter.build()
|
||||||
},
|
},
|
||||||
props: {
|
props: {
|
||||||
ticketId: {
|
id: {
|
||||||
type: [Number, String],
|
type: [Number, String],
|
||||||
required: true
|
required: true
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue