2022-09-26 11:33:27 +00:00
|
|
|
const Component = require(`vn-print/core/component`);
|
2020-12-16 07:05:41 +00:00
|
|
|
const reportHeader = new Component('report-header');
|
|
|
|
const reportFooter = new Component('report-footer');
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
name: 'supplier-campaign-metrics',
|
|
|
|
async serverPrefetch() {
|
2022-09-26 11:33:27 +00:00
|
|
|
this.supplier = await this.fetchSupplier(this.id);
|
|
|
|
let entries = await this.fetchEntries(this.id, this.from, this.to);
|
2020-12-16 07:05:41 +00:00
|
|
|
|
|
|
|
const entriesId = [];
|
|
|
|
|
|
|
|
for (let entry of entries)
|
|
|
|
entriesId.push(entry.id);
|
|
|
|
|
|
|
|
const buys = await this.fetchBuys(entriesId);
|
|
|
|
|
|
|
|
const entriesMap = new Map();
|
|
|
|
for (let entry of entries)
|
|
|
|
entriesMap.set(entry.id, entry);
|
|
|
|
|
|
|
|
for (let buy of buys) {
|
|
|
|
const entry = entriesMap.get(buy.entryFk);
|
|
|
|
if (entry) {
|
|
|
|
if (!entry.buys) entry.buys = [];
|
|
|
|
|
|
|
|
entry.buys.push(buy);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
this.entries = entries;
|
|
|
|
if (!this.supplier)
|
|
|
|
throw new Error('Something went wrong');
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
fetchSupplier(supplierId) {
|
|
|
|
return this.findOneFromDef('supplier', [supplierId]);
|
|
|
|
},
|
|
|
|
fetchEntries(supplierId, from, to) {
|
|
|
|
return this.rawSqlFromDef('entries', [supplierId, from, to]);
|
|
|
|
},
|
|
|
|
fetchBuys(entriesId) {
|
2021-04-27 08:29:09 +00:00
|
|
|
return this.rawSqlFromDef('buys', [entriesId]);
|
2020-12-16 07:05:41 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
components: {
|
|
|
|
'report-header': reportHeader.build(),
|
|
|
|
'report-footer': reportFooter.build()
|
|
|
|
},
|
|
|
|
props: {
|
2022-09-26 11:33:27 +00:00
|
|
|
id: {
|
2022-10-28 13:53:57 +00:00
|
|
|
type: Number,
|
2022-09-26 11:33:27 +00:00
|
|
|
required: true,
|
|
|
|
description: 'The supplier id'
|
2020-12-16 07:05:41 +00:00
|
|
|
},
|
|
|
|
from: {
|
|
|
|
required: true
|
|
|
|
},
|
|
|
|
to: {
|
|
|
|
required: true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|