86 lines
2.5 KiB
JavaScript
Executable File
86 lines
2.5 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.findOne(
|
|
`SELECT
|
|
s.name,
|
|
s.street,
|
|
s.nif,
|
|
s.postCode,
|
|
s.city,
|
|
p.name province
|
|
FROM supplier s
|
|
JOIN entry e ON e.supplierFk = s.id
|
|
LEFT JOIN province p ON p.id = s.provinceFk
|
|
WHERE e.id = ?`, [entryId]);
|
|
},
|
|
fetchEntry(entryId) {
|
|
return db.findOne(
|
|
`SELECT
|
|
e.id,
|
|
e.ref,
|
|
e.notes,
|
|
c.code companyCode,
|
|
t.landed
|
|
FROM entry e
|
|
JOIN travel t ON t.id = e.travelFk
|
|
JOIN company c ON c.id = e.companyFk
|
|
WHERE e.id = ?`, [entryId]);
|
|
},
|
|
fetchBuys(entryId) {
|
|
return db.rawSql(
|
|
`SELECT
|
|
b.itemFk,
|
|
b.quantity,
|
|
b.buyingValue,
|
|
b.stickers box,
|
|
b.packing,
|
|
i.name itemName,
|
|
i.tag5,
|
|
i.value5,
|
|
i.tag6,
|
|
i.value6,
|
|
i.tag7,
|
|
i.value7
|
|
FROM buy b
|
|
JOIN item i ON i.id = b.itemFk
|
|
WHERE b.entryFk = ?`, [entryId]);
|
|
},
|
|
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
|
|
}
|
|
}
|
|
};
|