2019-10-31 11:43:04 +00:00
|
|
|
const config = require(`${appPath}/core/config`);
|
2019-11-07 10:19:05 +00:00
|
|
|
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}`;
|
|
|
|
|
2019-02-11 09:06:26 +00:00
|
|
|
if (this.signature && this.signature.id)
|
|
|
|
return `${hostPath}/${this.signature.id}.png`;
|
|
|
|
},
|
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;
|
2019-02-11 09:06:26 +00:00
|
|
|
}
|
|
|
|
},
|
2019-02-05 06:58:05 +00:00
|
|
|
methods: {
|
2019-10-31 11:43:04 +00:00
|
|
|
fetchClient(ticketId) {
|
|
|
|
return db.findOne(
|
2019-02-05 06:58:05 +00:00
|
|
|
`SELECT
|
2019-02-11 09:06:26 +00:00
|
|
|
c.id,
|
|
|
|
c.socialName,
|
2019-02-05 06:58:05 +00:00
|
|
|
c.street,
|
2019-10-31 11:43:04 +00:00
|
|
|
c.fi
|
2019-02-05 06:58:05 +00:00
|
|
|
FROM ticket t
|
|
|
|
JOIN client c ON c.id = t.clientFk
|
2019-10-31 11:43:04 +00:00
|
|
|
WHERE t.id = ?`, [ticketId]);
|
2019-02-05 06:58:05 +00:00
|
|
|
},
|
2019-10-31 11:43:04 +00:00
|
|
|
fetchTicket(ticketId) {
|
|
|
|
return db.findOne(
|
2019-02-11 09:06:26 +00:00
|
|
|
`SELECT
|
|
|
|
t.id,
|
2019-04-01 05:05:37 +00:00
|
|
|
t.shipped,
|
2019-11-21 08:33:08 +00:00
|
|
|
c.code companyCode
|
2019-02-11 09:06:26 +00:00
|
|
|
FROM ticket t
|
2019-11-21 08:33:08 +00:00
|
|
|
JOIN company c ON c.id = t.companyFk
|
2019-10-31 11:43:04 +00:00
|
|
|
WHERE t.id = ?`, [ticketId]);
|
2019-02-11 09:06:26 +00:00
|
|
|
},
|
2019-10-31 11:43:04 +00:00
|
|
|
fetchAddress(ticketId) {
|
|
|
|
return db.findOne(
|
2019-02-11 09:06:26 +00:00
|
|
|
`SELECT
|
|
|
|
a.nickname,
|
|
|
|
a.street,
|
|
|
|
a.postalCode,
|
|
|
|
a.city,
|
|
|
|
p.name province
|
|
|
|
FROM ticket t
|
|
|
|
JOIN address a ON a.clientFk = t.clientFk
|
|
|
|
LEFT JOIN province p ON p.id = a.provinceFk
|
2019-10-31 11:43:04 +00:00
|
|
|
WHERE t.id = ?`, [ticketId]);
|
2019-02-11 09:06:26 +00:00
|
|
|
},
|
|
|
|
|
2019-10-31 11:43:04 +00:00
|
|
|
fetchSales(ticketId) {
|
2019-11-18 14:04:51 +00:00
|
|
|
return db.rawSql(
|
2019-02-07 06:47:09 +00:00
|
|
|
`SELECT
|
2019-04-01 05:05:37 +00:00
|
|
|
s.id,
|
|
|
|
s.itemFk,
|
|
|
|
s.concept,
|
|
|
|
s.quantity,
|
|
|
|
s.price,
|
|
|
|
s.price - SUM(IF(ctr.id = 6,
|
|
|
|
sc.value,
|
|
|
|
0)) netPrice,
|
|
|
|
s.discount,
|
|
|
|
i.size,
|
|
|
|
i.stems,
|
|
|
|
i.category,
|
|
|
|
it.id itemTypeId,
|
|
|
|
o.code AS origin,
|
|
|
|
i.inkFk,
|
|
|
|
s.ticketFk,
|
|
|
|
tcl.code vatType,
|
|
|
|
ibwg.ediBotanic, ppa.denomination, pp.number passportNumber,
|
|
|
|
be.isProtectedZone, c.code AS countryCode,
|
|
|
|
i.tag5, i.value5,
|
|
|
|
i.tag6, i.value6, i.tag7, i.value7
|
2019-02-11 09:06:26 +00:00
|
|
|
FROM vn.sale s
|
2019-02-07 06:47:09 +00:00
|
|
|
LEFT JOIN saleComponent sc ON sc.saleFk = s.id
|
2019-09-24 11:45:54 +00:00
|
|
|
LEFT JOIN component cr ON cr.id = sc.componentFk
|
|
|
|
LEFT JOIN componentType ctr ON ctr.id = cr.typeFk
|
2019-02-07 06:47:09 +00:00
|
|
|
LEFT JOIN item i ON i.id = s.itemFk
|
|
|
|
LEFT JOIN ticket t ON t.id = s.ticketFk
|
|
|
|
LEFT JOIN origin o ON o.id = i.originFk
|
2019-02-11 09:06:26 +00:00
|
|
|
LEFT JOIN country c ON c.id = o.countryFk
|
|
|
|
LEFT JOIN supplier sp ON sp.id = t.companyFk
|
|
|
|
LEFT JOIN itemType it ON it.id = i.typeFk
|
|
|
|
LEFT JOIN itemTaxCountry itc ON itc.itemFk = i.id
|
|
|
|
AND itc.countryFk = sp.countryFk
|
|
|
|
LEFT JOIN taxClass tcl ON tcl.id = itc.taxClassFk
|
|
|
|
LEFT JOIN plantpassport pp ON pp.producerFk = i.producerFk
|
|
|
|
LEFT JOIN plantpassportAuthority ppa ON ppa.id = pp.plantpassportAuthorityFk
|
|
|
|
LEFT JOIN itemBotanicalWithGenus ibwg ON ibwg.itemFk = i.id
|
|
|
|
LEFT JOIN botanicExport be ON be.restriction = 'pasaporte fitosanitario'
|
|
|
|
LEFT JOIN ediGenus eg ON eg.id = be.ediGenusFk
|
|
|
|
LEFT JOIN ediSpecie es ON es.id = be.ediSpecieFk
|
|
|
|
AND ibwg.ediBotanic LIKE CONCAT(
|
|
|
|
IFNULL(eg.latinGenusName, ''),
|
|
|
|
IF(es.latinSpeciesName > '',
|
|
|
|
CONCAT(' ', es.latinSpeciesName), ''),
|
|
|
|
'%')
|
2019-02-07 06:47:09 +00:00
|
|
|
WHERE s.ticketFk = ?
|
|
|
|
GROUP BY s.id
|
2019-10-31 11:43:04 +00:00
|
|
|
ORDER BY (it.isPackaging), s.concept, s.itemFk`, [ticketId]);
|
2019-02-05 06:58:05 +00:00
|
|
|
},
|
2019-10-31 11:43:04 +00:00
|
|
|
fetchTaxes(ticketId) {
|
2019-11-18 14:04:51 +00:00
|
|
|
return db.rawSql(`CALL vn.ticketGetTaxAdd(?)`, [ticketId]).then(rows => {
|
2019-10-31 11:43:04 +00:00
|
|
|
return rows[0];
|
|
|
|
});
|
2019-02-11 09:06:26 +00:00
|
|
|
},
|
2019-10-31 11:43:04 +00:00
|
|
|
fetchPackagings(ticketId) {
|
2019-11-18 14:04:51 +00:00
|
|
|
return db.rawSql(
|
2019-02-11 09:06:26 +00:00
|
|
|
`SELECT
|
|
|
|
tp.quantity,
|
|
|
|
i.name,
|
|
|
|
p.itemFk
|
|
|
|
FROM ticketPackaging tp
|
|
|
|
JOIN packaging p ON p.id = tp.packagingFk
|
|
|
|
JOIN item i ON i.id = p.itemFk
|
|
|
|
WHERE tp.ticketFk = ?
|
2019-10-31 11:43:04 +00:00
|
|
|
ORDER BY itemFk`, [ticketId]);
|
2019-02-11 09:06:26 +00:00
|
|
|
},
|
2019-10-31 11:43:04 +00:00
|
|
|
fetchServices(ticketId) {
|
2019-11-18 14:04:51 +00:00
|
|
|
return db.rawSql(
|
2019-03-05 13:59:18 +00:00
|
|
|
`SELECT
|
|
|
|
tc.description taxDescription,
|
|
|
|
ts.description,
|
|
|
|
ts.quantity,
|
|
|
|
ts.price
|
|
|
|
FROM ticketService ts
|
|
|
|
JOIN taxClass tc ON tc.id = ts.taxClassFk
|
2019-10-31 11:43:04 +00:00
|
|
|
WHERE ts.ticketFk = ?`, [ticketId]);
|
2019-03-05 13:59:18 +00:00
|
|
|
},
|
2019-10-31 11:43:04 +00:00
|
|
|
fetchSignature(ticketId) {
|
|
|
|
return db.findOne(
|
2019-02-11 09:06:26 +00:00
|
|
|
`SELECT
|
|
|
|
d.id,
|
|
|
|
d.created
|
|
|
|
FROM ticket t
|
2019-05-01 17:34:08 +00:00
|
|
|
JOIN ticketDms dt ON dt.ticketFk = t.id
|
2019-02-11 09:06:26 +00:00
|
|
|
JOIN dms d ON d.id = dt.dmsFk
|
|
|
|
AND d.file LIKE '%.png'
|
2019-10-31 11:43:04 +00:00
|
|
|
WHERE t.id = ?`, [ticketId]);
|
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();
|
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
|
|
|
};
|