2022-09-16 21:13:37 +00:00
|
|
|
const config = require(`vn-print/core/config`);
|
|
|
|
const Component = require(`vn-print/core/component`);
|
2019-10-31 11:43:04 +00:00
|
|
|
const reportHeader = new Component('report-header');
|
|
|
|
const reportFooter = new Component('report-footer');
|
2019-07-23 11:41:28 +00:00
|
|
|
const md5 = require('md5');
|
2020-10-19 06:10:32 +00:00
|
|
|
const fs = require('fs-extra');
|
2019-02-05 06:58:05 +00:00
|
|
|
|
|
|
|
module.exports = {
|
2019-10-31 11:43:04 +00:00
|
|
|
name: 'delivery-note',
|
|
|
|
async serverPrefetch() {
|
2022-09-22 06:48:29 +00:00
|
|
|
this.client = await this.fetchClient(this.id);
|
|
|
|
this.ticket = await this.fetchTicket(this.id);
|
|
|
|
this.sales = await this.fetchSales(this.id);
|
|
|
|
this.address = await this.fetchAddress(this.id);
|
|
|
|
this.services = await this.fetchServices(this.id);
|
|
|
|
this.taxes = await this.fetchTaxes(this.id);
|
|
|
|
this.packagings = await this.fetchPackagings(this.id);
|
|
|
|
this.signature = await this.fetchSignature(this.id);
|
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() {
|
2020-10-19 06:10:32 +00:00
|
|
|
if (!this.signature) return;
|
2019-07-23 11:41:28 +00:00
|
|
|
|
2020-10-19 06:10:32 +00:00
|
|
|
const hash = md5(this.signature.id.toString()).substring(0, 3);
|
|
|
|
const file = `${config.storage.root}/${hash}/${this.signature.id}.png`;
|
2021-10-01 10:41:31 +00:00
|
|
|
|
|
|
|
if (!fs.existsSync(file)) return null;
|
|
|
|
|
2020-10-19 06:10:32 +00:00
|
|
|
const src = fs.readFileSync(file);
|
|
|
|
const base64 = Buffer.from(src, 'utf8').toString('base64');
|
|
|
|
|
|
|
|
return `data:image/png;base64, ${base64}`;
|
2019-02-11 09:06:26 +00:00
|
|
|
},
|
2022-09-21 11:18:32 +00:00
|
|
|
deliverNoteType() {
|
|
|
|
return this.type ? this.type : 'deliveryNote';
|
|
|
|
},
|
2019-03-05 13:59:18 +00:00
|
|
|
serviceTotal() {
|
|
|
|
let total = 0.00;
|
|
|
|
this.services.forEach(service => {
|
|
|
|
total += parseFloat(service.price) * service.quantity;
|
|
|
|
});
|
|
|
|
|
|
|
|
return total;
|
2022-03-23 08:46:44 +00:00
|
|
|
},
|
|
|
|
showPrices() {
|
2022-09-21 11:18:32 +00:00
|
|
|
return this.deliverNoteType != 'withoutPrices';
|
2022-03-23 11:31:38 +00:00
|
|
|
},
|
2022-03-23 08:48:09 +00:00
|
|
|
footerType() {
|
2022-09-21 11:18:32 +00:00
|
|
|
const translatedType = this.$t(this.deliverNoteType);
|
2022-09-22 06:48:29 +00:00
|
|
|
return `${translatedType} ${this.id}`;
|
2019-02-11 09:06:26 +00:00
|
|
|
}
|
2022-10-25 11:27:04 +00:00
|
|
|
|
2019-02-11 09:06:26 +00:00
|
|
|
},
|
2019-02-05 06:58:05 +00:00
|
|
|
methods: {
|
2022-09-22 06:48:29 +00:00
|
|
|
fetchClient(id) {
|
|
|
|
return this.findOneFromDef('client', [id]);
|
2019-02-05 06:58:05 +00:00
|
|
|
},
|
2022-09-22 06:48:29 +00:00
|
|
|
fetchTicket(id) {
|
|
|
|
return this.findOneFromDef('ticket', [id]);
|
2019-02-11 09:06:26 +00:00
|
|
|
},
|
2022-09-22 06:48:29 +00:00
|
|
|
fetchAddress(id) {
|
|
|
|
return this.findOneFromDef(`address`, [id]);
|
2019-02-11 09:06:26 +00:00
|
|
|
},
|
2022-09-22 06:48:29 +00:00
|
|
|
fetchSignature(id) {
|
|
|
|
return this.findOneFromDef('signature', [id]);
|
2019-02-05 06:58:05 +00:00
|
|
|
},
|
2022-09-22 06:48:29 +00:00
|
|
|
fetchTaxes(id) {
|
|
|
|
return this.findOneFromDef(`taxes`, [id]);
|
2020-09-25 12:45:00 +00:00
|
|
|
},
|
2022-09-22 06:48:29 +00:00
|
|
|
fetchSales(id) {
|
|
|
|
return this.rawSqlFromDef('sales', [id]);
|
2019-02-11 09:06:26 +00:00
|
|
|
},
|
2022-09-22 06:48:29 +00:00
|
|
|
fetchPackagings(id) {
|
|
|
|
return this.rawSqlFromDef('packagings', [id]);
|
2019-02-11 09:06:26 +00:00
|
|
|
},
|
2022-09-22 06:48:29 +00:00
|
|
|
fetchServices(id) {
|
|
|
|
return this.rawSqlFromDef('services', [id]);
|
2019-02-11 09:06:26 +00:00
|
|
|
},
|
2020-09-25 12:45:00 +00:00
|
|
|
|
2019-02-11 09:06:26 +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-12-16 08:24:11 +00:00
|
|
|
},
|
|
|
|
getBotanical() {
|
|
|
|
let phytosanitary = [];
|
|
|
|
this.sales.forEach(sale => {
|
2021-01-19 13:43:40 +00:00
|
|
|
if (sale.botanical)
|
|
|
|
phytosanitary.push(sale.botanical);
|
2020-12-16 08:24:11 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
return phytosanitary.filter((item, index) =>
|
|
|
|
phytosanitary.indexOf(item) == index
|
|
|
|
).join(', ');
|
2022-10-25 11:27:04 +00:00
|
|
|
},
|
|
|
|
hasObservations() {
|
|
|
|
return this.ticket.code == 'deliveryNote' && this.ticket.description != null;
|
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: {
|
2022-09-22 06:48:29 +00:00
|
|
|
id: {
|
2022-01-17 11:44:43 +00:00
|
|
|
type: [Number, String],
|
2022-09-26 11:33:27 +00:00
|
|
|
required: true,
|
|
|
|
description: 'The ticket id'
|
2022-03-22 14:13:34 +00:00
|
|
|
},
|
|
|
|
type: {
|
|
|
|
type: String,
|
2022-05-02 10:28:17 +00:00
|
|
|
required: false
|
2019-10-31 11:43:04 +00:00
|
|
|
}
|
|
|
|
}
|
2019-02-05 06:58:05 +00:00
|
|
|
};
|