salix/print/templates/reports/delivery-note/delivery-note.js

108 lines
3.4 KiB
JavaScript
Raw Normal View History

2019-10-31 11:43:04 +00:00
const config = require(`${appPath}/core/config`);
const db = require(`${appPath}/core/database`);
2019-10-31 11:43:04 +00:00
const Component = require(`${appPath}/core/component`);
const reportHeader = new Component('report-header');
const reportFooter = new Component('report-footer');
2019-07-23 11:41:28 +00:00
const md5 = require('md5');
2019-02-05 06:58:05 +00:00
module.exports = {
2019-10-31 11:43:04 +00:00
name: 'delivery-note',
async serverPrefetch() {
this.client = await this.fetchClient(this.ticketId);
this.ticket = await this.fetchTicket(this.ticketId);
this.sales = await this.fetchSales(this.ticketId);
this.address = await this.fetchAddress(this.ticketId);
this.services = await this.fetchServices(this.ticketId);
this.taxes = await this.fetchTaxes(this.ticketId);
this.packagings = await this.fetchPackagings(this.ticketId);
this.signature = await this.fetchSignature(this.ticketId);
2019-02-05 06:58:05 +00:00
2019-10-31 11:43:04 +00:00
if (!this.ticket)
throw new Error('Something went wrong');
2019-02-05 06:58:05 +00:00
},
data() {
return {totalBalance: 0.00};
},
2019-02-06 09:53:12 +00:00
computed: {
dmsPath() {
2019-07-23 11:41:28 +00:00
const pathHash = md5(this.signature.id.toString()).substring(0, 3);
const hostPath = `file:///${config.storage.root}/${pathHash}`;
if (this.signature && this.signature.id)
return `${hostPath}/${this.signature.id}.png`;
},
serviceTotal() {
let total = 0.00;
this.services.forEach(service => {
total += parseFloat(service.price) * service.quantity;
});
return total;
}
},
2019-02-05 06:58:05 +00:00
methods: {
2019-10-31 11:43:04 +00:00
fetchClient(ticketId) {
2020-09-25 12:45:00 +00:00
return db.findOneFromDef('getClient', [ticketId], __dirname);
2019-02-05 06:58:05 +00:00
},
2019-10-31 11:43:04 +00:00
fetchTicket(ticketId) {
2020-09-25 12:45:00 +00:00
return db.findOneFromDef('getTicket', [ticketId], __dirname);
},
2019-10-31 11:43:04 +00:00
fetchAddress(ticketId) {
2020-09-25 12:45:00 +00:00
return db.findOneFromDef(`getAddress`, [ticketId], __dirname);
},
2020-09-25 12:45:00 +00:00
fetchSignature(ticketId) {
return db.findOneFromDef('getSignature', [ticketId], __dirname);
2019-02-05 06:58:05 +00:00
},
2019-10-31 11:43:04 +00:00
fetchTaxes(ticketId) {
2020-09-25 12:45:00 +00:00
return db.findOneFromDef(`getTaxes`, [ticketId], __dirname);
},
fetchSales(ticketId) {
return db.rawSqlFromDef('getSales', [ticketId], __dirname);
},
2019-10-31 11:43:04 +00:00
fetchPackagings(ticketId) {
2020-09-25 12:45:00 +00:00
return db.rawSqlFromDef('getPackagings', [ticketId], __dirname);
},
2019-10-31 11:43:04 +00:00
fetchServices(ticketId) {
2020-09-25 12:45:00 +00:00
return db.rawSqlFromDef('getServices', [ticketId], __dirname);
},
2020-09-25 12:45:00 +00:00
getSubTotal() {
let subTotal = 0.00;
this.sales.forEach(sale => {
subTotal += sale.quantity * sale.price * (1 - sale.discount / 100);
});
return subTotal;
},
getTotalBase() {
let totalBase = 0.00;
this.taxes.forEach(tax => {
totalBase += parseFloat(tax.Base);
});
return totalBase;
},
getTotalTax() {
let totalTax = 0.00;
this.taxes.forEach(tax => {
totalTax += parseFloat(tax.tax);
});
return totalTax;
},
getTotal() {
return this.getTotalBase() + this.getTotalTax();
2020-09-25 12:45:00 +00:00
}
2019-02-05 06:58:05 +00:00
},
components: {
2019-10-31 11:43:04 +00:00
'report-header': reportHeader.build(),
'report-footer': reportFooter.build()
2019-02-05 06:58:05 +00:00
},
2019-10-31 11:43:04 +00:00
props: {
ticketId: {
type: String,
required: true
}
}
2019-02-05 06:58:05 +00:00
};