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

55 lines
2.1 KiB
JavaScript
Raw Normal View History

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 {
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 = ?`;
database.pool.query(query, [params.clientId], (error, result) => {
if (error || result.length == 0)
return cb(new Error('No template data found'));
Object.assign(this, result[0]);
cb();
});
}
// 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(), '/');
}
};