2020-02-20 08:31:09 +00:00
|
|
|
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) {
|
2020-09-28 11:54:02 +00:00
|
|
|
return this.findOneFromDef('supplier', [entryId]);
|
2020-02-20 08:31:09 +00:00
|
|
|
},
|
|
|
|
fetchEntry(entryId) {
|
2020-09-28 11:54:02 +00:00
|
|
|
return this.findOneFromDef('entry', [entryId]);
|
2020-02-20 08:31:09 +00:00
|
|
|
},
|
|
|
|
fetchBuys(entryId) {
|
2020-09-28 11:54:02 +00:00
|
|
|
return this.rawSqlFromDef('buys', [entryId]);
|
2020-02-20 08:31:09 +00:00
|
|
|
},
|
|
|
|
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
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|