salix/print/templates/reports/supplier-campaign-metrics/supplier-campaign-metrics.js

47 lines
1.2 KiB
JavaScript
Raw Normal View History

2023-01-23 12:15:30 +00:00
const vnReport = require('../../../core/mixins/vn-report.js');
2020-12-16 07:05:41 +00:00
module.exports = {
name: 'supplier-campaign-metrics',
2023-01-23 12:15:30 +00:00
mixins: [vnReport],
2020-12-16 07:05:41 +00:00
async serverPrefetch() {
2023-01-23 12:15:30 +00:00
this.supplier = await this.findOneFromDef('supplier', [this.id]);
this.checkMainEntity(this.supplier);
let entries = await this.rawSqlFromDef('entries', [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);
2023-01-23 12:15:30 +00:00
const buys = await this.rawSqlFromDef('buys', [entriesId]);
2020-12-16 07:05:41 +00:00
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;
},
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
}
}
};