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

37 lines
1.0 KiB
JavaScript
Executable File

const vnReport = require('../../../core/mixins/vn-report.js');
module.exports = {
name: 'entry-order',
mixins: [vnReport],
async serverPrefetch() {
this.entry = await this.findOneFromDef('entry', [this.id]);
this.checkMainEntity(this.entry);
this.supplier = await this.findOneFromDef('supplier', [this.id]);
this.buys = await this.rawSqlFromDef('buys', [this.id]);
},
data() {
return {totalBalance: 0.00};
},
methods: {
getTotalBy(property) {
return this.buys.reduce((total, buy) => {
switch (property) {
case 'amount':
return total + buy.quantity * buy.buyingValue;
case 'quantity':
return total + buy.quantity;
case 'stickers':
return total + buy.stickers;
}
}, 0);
}
},
props: {
id: {
type: Number,
required: true,
description: 'The entry id'
}
}
};