salix/print/templates/reports/entry-order/entry-order.js

49 lines
1.3 KiB
JavaScript
Executable File

const db = require(`${appPath}/core/database`);
const Component = require(`${appPath}/core/component`);
const reportHeader = new Component('report-header');
const reportFooter = new Component('report-footer');
module.exports = {
name: 'entry-order',
async serverPrefetch() {
this.supplier = await this.fetchSupplier(this.entryId);
this.entry = await this.fetchEntry(this.entryId);
this.buys = await this.fetchBuys(this.entryId);
if (!this.entry)
throw new Error('Something went wrong');
},
data() {
return {totalBalance: 0.00};
},
methods: {
fetchSupplier(entryId) {
return db.findOneFromDef('supplier', [entryId], __dirname);
},
fetchEntry(entryId) {
return db.findOneFromDef('entry', [entryId], __dirname);
},
fetchBuys(entryId) {
return db.rawSqlFromDef('buys', [entryId], __dirname);
},
getTotal() {
let total = 0.00;
this.buys.forEach(buy => {
total += buy.quantity * buy.buyingValue;
});
return total;
}
},
components: {
'report-header': reportHeader.build(),
'report-footer': reportFooter.build()
},
props: {
entryId: {
type: String,
required: true
}
}
};