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

127 lines
4.7 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) {
const promises = [];
const data = {};
if (!params.ticketFk)
throw new UserException('No ticket id specified');
promises.push(this.methods.fetchClient(params.ticketFk));
2019-02-07 06:47:09 +00:00
promises.push(this.methods.fetchSales(params.ticketFk));
2019-02-05 06:58:05 +00:00
return Promise.all(promises).then(result => {
const [[client]] = result[0];
2019-02-07 06:47:09 +00:00
const [sales] = result[1];
2019-02-05 06:58:05 +00:00
if (!client)
throw new UserException('No client data found');
2019-02-07 06:47:09 +00:00
Object.assign(data, client, {sales});
2019-02-05 06:58:05 +00:00
return data;
});
},
created() {
if (this.locale)
this.$i18n.locale = this.locale;
},
data() {
return {totalBalance: 0.00};
},
2019-02-06 09:53:12 +00:00
computed: {
dmsPath() {
return `http://windows.verdnatura.es/signatures/tickets/1161229.png`;
}
},
2019-02-05 06:58:05 +00:00
methods: {
fetchClient(ticketFk) {
return database.pool.query(
`SELECT
c.id clientId,
2019-02-06 09:53:12 +00:00
t.id ticketId,
2019-02-05 06:58:05 +00:00
u.lang locale,
c.email AS recipient,
c.socialName AS clientName,
c.street,
c.postcode,
c.city,
c.fi,
p.name AS province,
2019-02-06 09:53:12 +00:00
ct.country,
dt.dmsFk,
d.created AS dmsCreated
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
JOIN country ct ON ct.id = c.countryFk
LEFT JOIN province p ON p.id = c.provinceFk
2019-02-06 09:53:12 +00:00
LEFT JOIN dmsTicket dt ON dt.ticketFk = t.id
LEFT JOIN dms d ON d.id = dt.dmsFk
2019-02-05 06:58:05 +00:00
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,
ic.type taxType,
i.category,
it.id itemTypeId,
o.code AS origin,
i.inkFk,
s.ticketFk,
ita.tag1,
ita.val1,
ita.tag2,
ita.val2,
ita.tag3,
ita.val3
FROM sale s
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
INNER JOIN supplier sp ON sp.id = t.companyFk
INNER JOIN itemType it ON it.id = i.typeFk
LEFT JOIN
(SELECT *
FROM
(SELECT tt.countryFk, tcc.taxClassFk, tc.type
FROM taxClassCode tcc
JOIN taxCode tc ON tc.id = tcc.taxCodeFk
JOIN taxType tt ON tt.id = tc.taxTypeFk
WHERE tcc.effectived <= '2019-01-29 13:00:00'
ORDER BY tcc.effectived DESC) tx
GROUP BY tx.countryFk, tx.taxClassFk) ic ON ic.countryFk = sp.countryFk
AND ic.taxClassFk = i.taxClassFk
JOIN vn.itemTagArranged ita ON ita.itemFk = s.itemFk
WHERE s.ticketFk = ?
GROUP BY s.id
ORDER BY (it.isPackaging), s.concept, s.itemFk`, [ticketFk]);
2019-02-05 06:58:05 +00:00
},
dated: () => {
return strftime('%d-%m-%Y', new Date());
},
},
components: {
'report-header': require('../report-header'),
'report-footer': require('../report-footer'),
},
};