-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
182 lines (129 loc) · 5.28 KB
/
index.html
File metadata and controls
182 lines (129 loc) · 5.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>EJEMPLO LECTURA ARCHIVO NORMA 43</title>
<style>
body {
font-size: 1.1rem;
font-family: sans-serif;
}
table, tr, td {
border: 1px solid gray;
font-size: 0.8rem;
}
#transactionsContainer div {
background-color: #0e0505;
color: tomato;
padding: 1rem;
}
.amount, .balance, .order {
text-align: right;
}
.amount, .balance {
width: 150px;
}
.bookingDate {
width: 120px;
}
.info {
width: 880px;
overflow:hidden;
}
</style>
</head>
<body>
<!-- Selector de archivo -->
<label for="file" style="font-size: 1rem; color: tomato">Seleccione un archivo de norma 43:</label><br /><br />
<input type="file" id="file" title="Cargar archivo norma 43" accept="text/plain" onchange="LoadFile(this.files);" /><br /><br />
<!-- Contenedor para la tabla de transacciones -->
<div id="transactionsContainer"></div>
<!-- Script N43 -->
<script src="N43.0.0.2.js"></script>
<!-- Ejemplo de uso -->
<script>
/**
* Manejador del evento change de #file.
* @param {Object} files Archivos seleccionados.
* */
function LoadFile(files) {
ClearTable();
for (var i = 0; i < files.length; i++) {
var file = files[i];
var reader = new FileReader();
reader.onload = function (e) {
var textFileContent = e.target.result;
var transactionResults = GetTransactionResult(textFileContent);
transactionResults.forEach((transactionResult) => { ShowTable(transactionResult); })
};
reader.readAsText(file, "ASCII");
}
};
/**
* Procesa un archivo de texto de norma 43.
* @param {string} fileText Texto con el
* contenido del archivo de norma 43.
* */
function GetTransactionResult(fileText){
// Creamos el objeto N43.File
var fileN43 = new N43.File({ Text: fileText });
// Devolvemos el resultado procesado
return fileN43.GetTransactions();
};
/**
* Formatea un número.
* @param number Número a formatear.
* @param decimals Número de decimales
* @param decimalSeparator Separador de decimales.
* @param thousandSeparator Separador de miles.
*/
function ToAmountFormat (number, decimals, decimalSeparator, thousandSeparator) {
var abs = Math.abs(number);
var input = abs.toFixed(decimals);
var cleared = input.replace(/[^\d]/, "");
var decimal = cleared.substring(cleared.length - decimals, cleared.length);
var whole = cleared.substring(0, cleared.length - decimals);
var wholeResult = "";
for (var w = whole.length - 1; w > -1; w--) {
if ((whole.length - w) % 3 === 0 && w !== 0)
wholeResult = thousandSeparator + whole[w] + wholeResult;
else
wholeResult = whole[w] + wholeResult;
}
return (number < 0 ? "-" : "") + wholeResult + decimalSeparator + decimal;
};
/**
* Muestra las transacciones de un archivo
* de norma 43 procesado.
* @param {Array} transactions Transacciones
* de un archivo de norma 43 procesado.
* */
function ShowTable(transactionResult){
var html = `<br /><br /><div>Banco: ${transactionResult.BankId}` +
` - Cuenta: ${transactionResult.AccountId} - Moneda: ${transactionResult.Currency}` +
` - Moneda: ${transactionResult.Currency}` +
` - Saldo inicial: ${ToAmountFormat(transactionResult.BalanceStart, 2, ",", ".")}`+
` - Saldo final: ${ToAmountFormat(transactionResult.BalanceEnd, 2, ",", ".")}</div><br/>`;
transactions = transactionResult.Transactions;
for (var t = 0; t < transactions.length; t++) {
var transaction = transactions[t];
html += `<tr>` +
`<td class="order">${transaction.Order}</td>` +
`<td class="bookingDate">${transaction.BookingDate.toISOString().substr(0, 10)}</td>` +
`<td class="info">${transaction.RemittanceInformationUnstructured}</td>` +
`<td class="amount">${ToAmountFormat(transaction.Amount, 2, ",", ".")}</td>` +
`<td class="balance">${ToAmountFormat(transaction.Balance, 2, ",", ".")}</td>` +
`</tr>`;
}
html = `<table cellspacing=0 cellpadding=4>\n${html}\n</table>`;
document.getElementById("transactionsContainer").innerHTML += html;
};
/**
* Limpia datos anteriores.
* */
function ClearTable() {
document.getElementById("transactionsContainer").innerHTML = "";
};
</script>
</body>
</html>