var path = require('path'); var database = require(path.join(__dirname, '../../database.js')); let strftime = require('strftime'); module.exports = class ClaimPickup { async getData(params, cb) { let qryData = ` SELECT c.id clientId, cl.id claimId, LOWER(ct.code) AS countryCode, c.email AS recipient, c.socialName, c.name AS clientName, c.street, c.postcode, c.city, c.fi, p.name AS province, ct.country FROM claim cl JOIN client c ON c.id = cl.clientFk JOIN country ct ON ct.id = c.countryFk LEFT JOIN province p ON p.id = c.provinceFk WHERE cl.id = ?`; let qryLines = ` SELECT s.id, s.quantity, s.concept, cb.quantity claimQuantity FROM claimBeginning cb JOIN sale s ON s.id = cb.saleFk WHERE cb.claimFk = ?`; try { let [data] = await database.pool.query(qryData, [params.claimId]); if (!data) throw new Error('No body data found'); let [lines] = await database.pool.query(qryLines, [params.claimId]); Object.assign(this, data[0]); this.lines = lines; cb(); } catch (e) { cb(e); } } get currentDate() { return strftime('%d-%m-%Y', new Date()); } };