2022-09-16 21:13:37 +00:00
|
|
|
const config = require(`vn-print/core/config`);
|
2023-01-23 12:15:30 +00:00
|
|
|
const vnReport = require('../../../core/mixins/vn-report.js');
|
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',
|
2023-01-23 12:15:30 +00:00
|
|
|
mixins: [vnReport],
|
2019-10-31 11:43:04 +00:00
|
|
|
async serverPrefetch() {
|
2023-01-23 12:15:30 +00:00
|
|
|
this.ticket = await this.findOneFromDef('ticket', [this.id]);
|
|
|
|
this.checkMainEntity(this.ticket);
|
|
|
|
this.client = await this.findOneFromDef('client', [this.id]);
|
|
|
|
this.sales = await this.rawSqlFromDef('sales', [this.id]);
|
|
|
|
this.address = await this.findOneFromDef(`address`, [this.id]);
|
|
|
|
this.services = await this.rawSqlFromDef('services', [this.id]);
|
2023-02-09 12:30:52 +00:00
|
|
|
this.taxes = await this.findOneFromDef('taxes', [this.id]);
|
2023-01-23 12:15:30 +00:00
|
|
|
this.packagings = await this.rawSqlFromDef('packagings', [this.id]);
|
|
|
|
this.signature = await this.findOneFromDef('signature', [this.id]);
|
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}`;
|
2022-10-25 13:03:09 +00:00
|
|
|
},
|
|
|
|
hasObservations() {
|
|
|
|
return this.ticket.description !== null;
|
2019-02-11 09:06:26 +00:00
|
|
|
}
|
|
|
|
},
|
2019-02-05 06:58:05 +00:00
|
|
|
methods: {
|
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(', ');
|
2020-09-25 12:45:00 +00:00
|
|
|
}
|
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-10-28 13:53:57 +00:00
|
|
|
type: Number,
|
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
|
|
|
};
|