salix/services/print/application/template/letter-debtor/letter-debtor.js

60 lines
2.1 KiB
JavaScript

var path = require('path');
var database = require(path.join(__dirname, '../../database.js'));
var format = require(path.join(__dirname, '../../util/format.js'));
module.exports = class LetterDebtor {
async getData(params, cb) {
let query = `SELECT
c.id clientId,
m.code mandateCode,
LOWER(ct.code) AS countryCode,
c.email AS recipient,
c.socialName AS clientName,
c.street AS clientStreet,
c.postcode AS clientPostCode,
c.city AS clientCity,
p.name AS clientProvince,
ct.country AS clientCountry,
s.name AS supplierName,
s.street AS supplierStreet,
sc.country AS supplierCountry,
s.postCode AS supplierPostCode,
s.city AS supplierCity,
sp.name AS supplierProvince
FROM client c
JOIN country ct ON ct.id = c.countryFk
LEFT JOIN province p ON p.id = c.provinceFk
LEFT JOIN mandate m ON m.clientFk = c.id AND m.finished IS NULL
LEFT JOIN supplier s ON s.id = m.companyFk
LEFT JOIN country sc ON sc.id = s.countryFk
LEFT JOIN province sp ON sp.id = s.provinceFk
WHERE c.id = ?`;
try {
let [result] = await database.pool.query(query, [params.clientId]);
if (!result)
throw new Error('No body data found');
Object.assign(this, result);
cb();
} catch (e) {
cb(e);
}
}
// Swift BIC fields
get swiftFields() {
return new Array(11);
}
// Account number fields
get accountNumberFields() {
return new Array(23);
}
get currentDate() {
return format.date(new Date(), '/');
}
};