salix/print/report/rpt-delivery-note/index.js

216 lines
8.0 KiB
JavaScript
Raw Normal View History

2019-02-05 06:58:05 +00:00
const strftime = require('strftime');
const database = require(`${appPath}/lib/database`);
const UserException = require(`${appPath}/lib/exceptions/userException`);
module.exports = {
name: 'rpt-delivery-note',
async asyncData(ctx, params) {
Object.assign(this, this.methods);
2019-02-05 06:58:05 +00:00
const [[client]] = await this.fetchClient(params.ticketFk);
const [[ticket]] = await this.fetchTicket(params.ticketFk);
const [[address]] = await this.fetchAddress(params.ticketFk);
const [[signature]] = await this.fetchSignature(params.ticketFk);
const [[taxes]] = await this.fetchTaxes(params.ticketFk);
const [sales] = await this.fetchSales(params.ticketFk);
const [packagings] = await this.fetchPackagings(params.ticketFk);
2019-02-05 06:58:05 +00:00
if (!ticket)
throw new UserException('No ticket data found');
2019-02-05 06:58:05 +00:00
return {client, ticket, address, sales, taxes, packagings, signature};
2019-02-05 06:58:05 +00:00
},
created() {
if (this.client.locale)
this.$i18n.locale = this.client.locale;
2019-02-05 06:58:05 +00:00
},
data() {
return {totalBalance: 0.00};
},
2019-02-06 09:53:12 +00:00
computed: {
dmsPath() {
const hostPath = 'http://windows.verdnatura.es/signatures/tickets';
if (this.signature && this.signature.id)
return `${hostPath}/${this.signature.id}.png`;
},
shipped() {
return strftime('%d-%m-%Y', this.ticket.shipped);
}
},
filters: {
currency(input, currency = 'EUR') {
return new Intl.NumberFormat('es', {
style: 'currency', currency
}).format(parseFloat(input));
},
percent(input) {
return new Intl.NumberFormat('es', {
style: 'percent',
minimumFractionDigits: 0,
maximumFractionDigits: 0
}).format(parseFloat(input));
},
date(input) {
return strftime('%d-%m-%Y %H:%I:%S', input);
2019-02-06 09:53:12 +00:00
}
},
2019-02-05 06:58:05 +00:00
methods: {
fetchClient(ticketFk) {
return database.pool.query(
`SELECT
c.id,
2019-02-05 06:58:05 +00:00
c.email AS recipient,
c.socialName,
2019-02-05 06:58:05 +00:00
c.street,
c.fi,
u.lang locale
2019-02-05 06:58:05 +00:00
FROM ticket t
JOIN client c ON c.id = t.clientFk
JOIN account.user u ON u.id = c.id
WHERE t.id = ?`, [ticketFk]);
},
fetchTicket(ticketFk) {
return database.pool.query(
`SELECT
t.id,
t.shipped
FROM ticket t
JOIN client c ON c.id = t.clientFk
JOIN account.user u ON u.id = c.id
WHERE t.id = ?`, [ticketFk]);
},
fetchAddress(ticketFk) {
return database.pool.query(
`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
WHERE t.id = ?`, [ticketFk]);
},
2019-02-07 06:47:09 +00:00
fetchSales(ticketFk) {
2019-02-05 06:58:05 +00:00
return database.pool.query(
2019-02-07 06:47:09 +00:00
`SELECT
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,
2019-02-07 06:47:09 +00:00
ita.tag1,
ita.val1,
ita.tag2,
ita.val2,
ita.tag3,
ita.val3
FROM vn.sale s
2019-02-07 06:47:09 +00:00
LEFT JOIN saleComponent sc ON sc.saleFk = s.id
LEFT JOIN componentRate cr ON cr.id = sc.componentFk
LEFT JOIN componentTypeRate ctr ON ctr.id = cr.componentTypeRate
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
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 itemTagArranged ita ON ita.itemFk = s.itemFk
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
ORDER BY (it.isPackaging), s.concept, s.itemFk`, [ticketFk]);
2019-02-05 06:58:05 +00:00
},
fetchTaxes(ticketFk) {
return database.pool.query(
`CALL vn.ticketGetTaxAdd(?)`, [ticketFk]);
},
fetchPackagings(ticketFk) {
return database.pool.query(
`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 = ?
ORDER BY itemFk`, [ticketFk]);
},
fetchSignature(ticketFk) {
return database.pool.query(
`SELECT
d.id,
d.created
FROM ticket t
JOIN dmsTicket dt ON dt.ticketFk = t.id
JOIN dms d ON d.id = dt.dmsFk
AND d.file LIKE '%.png'
WHERE t.id = ?`, [ticketFk]);
},
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: {
'report-header': require('../report-header'),
'report-footer': require('../report-footer'),
},
};