From 0c0ae1426393f47ae1e3e4d1eb0e6b8206debb48 Mon Sep 17 00:00:00 2001 From: Carlos Jimenez Ruiz Date: Wed, 27 Nov 2019 16:00:42 +0100 Subject: [PATCH] =?UTF-8?q?#1903=20informe=20consumo=20campa=C3=B1a?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- print/common/css/layout.css | 2 +- print/core/filters/date.js | 1 + print/core/filters/index.js | 1 + print/core/filters/uppercase.js | 5 + .../email/campaign-metrics/attachments.json | 4 + .../campaign-metrics/assets/css/import.js | 9 ++ .../campaign-metrics/assets/css/style.css | 11 ++ .../campaign-metrics/campaign-metrics.html | 100 ++++++++++++++++++ .../campaign-metrics/campaign-metrics.js | 85 +++++++++++++++ .../reports/campaign-metrics/locale/es.yml | 13 +++ 10 files changed, 230 insertions(+), 1 deletion(-) create mode 100644 print/core/filters/uppercase.js create mode 100644 print/templates/reports/campaign-metrics/assets/css/import.js create mode 100644 print/templates/reports/campaign-metrics/assets/css/style.css create mode 100644 print/templates/reports/campaign-metrics/campaign-metrics.html create mode 100755 print/templates/reports/campaign-metrics/campaign-metrics.js create mode 100644 print/templates/reports/campaign-metrics/locale/es.yml diff --git a/print/common/css/layout.css b/print/common/css/layout.css index 8a3e79219..6be065a14 100644 --- a/print/common/css/layout.css +++ b/print/common/css/layout.css @@ -4,7 +4,7 @@ */ .grid { - font-family: Helvetica, Arial, sans-serif; + font-family: Arial, sans-serif; font-size: 16px !important; width: 100% } diff --git a/print/core/filters/date.js b/print/core/filters/date.js index 37b9dd16f..5762905e2 100644 --- a/print/core/filters/date.js +++ b/print/core/filters/date.js @@ -2,5 +2,6 @@ const Vue = require('vue'); const strftime = require('strftime'); Vue.filter('date', function(value, specifiers) { + console.log(value); return strftime(specifiers, value); }); diff --git a/print/core/filters/index.js b/print/core/filters/index.js index 96bfde72b..1d2eb182c 100644 --- a/print/core/filters/index.js +++ b/print/core/filters/index.js @@ -1,4 +1,5 @@ // Import global filters require('./date'); +require('./uppercase'); require('./currency'); require('./percentage'); diff --git a/print/core/filters/uppercase.js b/print/core/filters/uppercase.js new file mode 100644 index 000000000..a4a826070 --- /dev/null +++ b/print/core/filters/uppercase.js @@ -0,0 +1,5 @@ +const Vue = require('vue'); + +Vue.filter('uppercase', function(value) { + return value.toUpperCase(); +}); diff --git a/print/templates/email/campaign-metrics/attachments.json b/print/templates/email/campaign-metrics/attachments.json index 32960f8ce..3f6a93bb5 100644 --- a/print/templates/email/campaign-metrics/attachments.json +++ b/print/templates/email/campaign-metrics/attachments.json @@ -1,2 +1,6 @@ [ + { + "filename": "campaing-metrics", + "component": "campaign-metrics" + } ] \ No newline at end of file diff --git a/print/templates/reports/campaign-metrics/assets/css/import.js b/print/templates/reports/campaign-metrics/assets/css/import.js new file mode 100644 index 000000000..fd8796c2b --- /dev/null +++ b/print/templates/reports/campaign-metrics/assets/css/import.js @@ -0,0 +1,9 @@ +const Stylesheet = require(`${appPath}/core/stylesheet`); + +module.exports = new Stylesheet([ + `${appPath}/common/css/spacing.css`, + `${appPath}/common/css/misc.css`, + `${appPath}/common/css/layout.css`, + `${appPath}/common/css/report.css`, + `${__dirname}/style.css`]) + .mergeStyles(); diff --git a/print/templates/reports/campaign-metrics/assets/css/style.css b/print/templates/reports/campaign-metrics/assets/css/style.css new file mode 100644 index 000000000..6e730869e --- /dev/null +++ b/print/templates/reports/campaign-metrics/assets/css/style.css @@ -0,0 +1,11 @@ +.column-oriented { + margin-top: 50px !important; +} + +.bottom-line > tr { + border-bottom: 1px solid #ccc; +} + +.bottom-line tr:nth-last-child() { + border-bottom: none; +} diff --git a/print/templates/reports/campaign-metrics/campaign-metrics.html b/print/templates/reports/campaign-metrics/campaign-metrics.html new file mode 100644 index 000000000..5ab7c894b --- /dev/null +++ b/print/templates/reports/campaign-metrics/campaign-metrics.html @@ -0,0 +1,100 @@ + + + + + + + + + +
+ +
+
+ +
+
+ +
+
+
+
+
+

{{$t('title')}}

+ + + + + + + + + + + + + + + +
{{$t('Client')}}{{client.id}}
{{$t('From')}}{{from | date('%d-%m-%Y')}}
{{$t('To')}}{{to | date('%d-%m-%Y')}}
+
+
+
+
+
{{$t('clientData')}}
+
+

{{client.socialName}}

+
+ {{client.street}} +
+
+ {{client.postcode}}, {{client.city}} ({{client.province}}) +
+
+ {{client.country}} +
+
+
+
+
+ + + + + + + + + + + + + + + +
{{$t('Code')}}{{$t('Quantity')}}{{$t('Concept')}}
{{sale.itemFk}}{{Math.trunc(sale.subtotal)}} + {{sale.concept}} {{sale.subName | uppercase}} +
+ {{sale.tag5}} + {{sale.value5}} + {{sale.tag6}} + {{sale.value6}} + {{sale.tag7}} + {{sale.value7}} +
+
+
+
+ +
+
+ + +
+
+
+ + \ No newline at end of file diff --git a/print/templates/reports/campaign-metrics/campaign-metrics.js b/print/templates/reports/campaign-metrics/campaign-metrics.js new file mode 100755 index 000000000..81eede809 --- /dev/null +++ b/print/templates/reports/campaign-metrics/campaign-metrics.js @@ -0,0 +1,85 @@ +const Component = require(`${appPath}/core/component`); +const db = require(`${appPath}/core/database`); +const reportHeader = new Component('report-header'); +const reportFooter = new Component('report-footer'); + +module.exports = { + name: 'campaign-metrics', + async serverPrefetch() { + // // te delete once form inputs get date ranges + // this.from = new Date(); + // this.from.setMonth(0); + // this.from.setDate(1); + // this.to = new Date(); + // this.to.setMonth(11); + // this.to.setDate(31); + // this.clientId = 101; + // // end of delete + + + this.client = await this.fetchClient(this.clientId); + + console.log(this.from, this.to); + this.sales = await this.fetchSales(this.clientId, this.from, this.to); + + if (!this.client) + throw new Error('Something went wrong'); + }, + methods: { + fetchClient(clientId) { + return db.findOne( + `SELECT + c.street, + c.socialName, + c.city, + c.postcode, + c.id, + c.name AS clientName, + p.name AS province, + co.country + FROM client c + JOIN province p ON c.provinceFk = p.id + JOIN country co ON c.countryFk = co.id + WHERE + c.id = ?`, [clientId]); + }, + fetchSales(clientId, from, to) { + return db.rawSql( + `SELECT + SUM(s.quantity) AS subtotal, + s.itemFk, + s.concept, + i.subName, + i.tag5, + i.value5, + i.tag6, + i.value6, + i.tag7, + i.value7 + FROM sale s + JOIN ticket t ON t.id = s.ticketFk + JOIN item i ON i.id = s.itemFk + JOIN itemType it ON it.id = i.typeFk + WHERE + t.clientFk = ? AND it.isPackaging = FALSE + AND DATE(t.shipped) BETWEEN ? AND ? + GROUP BY s.itemFk + ORDER BY i.typeFk , i.name , i.size`, [clientId, from, to]); + }, + }, + components: { + 'report-header': reportHeader.build(), + 'report-footer': reportFooter.build() + }, + props: { + clientId: { + required: true + }, + from: { + required: true + }, + to: { + required: true + } + } +}; diff --git a/print/templates/reports/campaign-metrics/locale/es.yml b/print/templates/reports/campaign-metrics/locale/es.yml new file mode 100644 index 000000000..67f65a652 --- /dev/null +++ b/print/templates/reports/campaign-metrics/locale/es.yml @@ -0,0 +1,13 @@ +title: Consumo de campaña +Client: Cliente +clientData: Datos del cliente +dated: Fecha +From: Desde +To: Hasta +concept: Concepto +client: Cliente {0} +Code: Código +Quantity: Cantidad +Stems: Tallos +Concept: Concepto +Tags: Etiquetas \ No newline at end of file