salix/services/print/application/util/format.js

60 lines
1.8 KiB
JavaScript
Raw Normal View History

2017-11-27 14:08:18 +00:00
let database = require('../database.js');
module.exports = {
/**
* Devuelve el iban
* @param {String} addressNumber - Dirección de cuenta bancaria
* @param {Object} cb - Callback
*/
accountAddressIban: function(addressNumber, cb) {
database.pool.query('SELECT vn2008.cc_to_iban(?) AS iban', [addressNumber], function(error, result) {
cb(result[0].iban);
});
},
/**
* Obtiene el numero de cuenta completo incluyendo iban
* @param {String} addressNumber - Dirección de cuenta bancaria
* @return {String} Cuenta bancaria formateada
*/
accountAddress: function(addressNumber) {
var formattedAccountAddress = addressNumber.replace(/(.{4})/g, '$1-');
return formattedAccountAddress.substring(0, formattedAccountAddress.length - 1);
},
/**
* Devuelve el numero de cuenta mostrando únicamente los últimos 4 dígitos.
* @param {String} addressNumber - Dirección de cuenta bancaria
* @return {String} Cuenta bancaria formateada
*/
partialAccountAddress: function(addressNumber) {
let address = this.accountAddress(addressNumber);
return address.substring(0, 19).replace(/[0-9]/g, 'X') + address.substring(19, 24);
},
phone: function(number) {
return number;
},
/**
* Format date dd-mm-yyyy
* @param {Object} date - Date object
* @param {String} delimiter - Date delimiter
* @return {String} Formatted date
*/
date: function(date, delimiter = '-') {
let day = date.getDate();
let month = date.getMonth() + 1;
let year = date.getFullYear();
if (day < 10)
day = `0${day}`
if (month < 10)
month = `0${month}`
return day + delimiter + month + delimiter + year;
}
};