2019-11-27 15:00:42 +00:00
|
|
|
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() {
|
2020-05-22 13:20:55 +00:00
|
|
|
this.client = await this.fetchClient(this.recipientId);
|
|
|
|
this.sales = await this.fetchSales(this.recipientId, this.from, this.to);
|
2019-11-27 15:00:42 +00:00
|
|
|
|
|
|
|
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
|
2020-06-12 07:18:19 +00:00
|
|
|
ORDER BY i.typeFk , i.name`, [clientId, from, to]);
|
2019-11-27 15:00:42 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
components: {
|
|
|
|
'report-header': reportHeader.build(),
|
|
|
|
'report-footer': reportFooter.build()
|
|
|
|
},
|
|
|
|
props: {
|
2020-05-22 13:20:55 +00:00
|
|
|
recipientId: {
|
2019-11-27 15:00:42 +00:00
|
|
|
required: true
|
|
|
|
},
|
|
|
|
from: {
|
2020-06-12 07:18:19 +00:00
|
|
|
required: true
|
2019-11-27 15:00:42 +00:00
|
|
|
},
|
|
|
|
to: {
|
2020-06-12 07:18:19 +00:00
|
|
|
required: true
|
2019-11-27 15:00:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|