-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCalculadora_2_MF.html
More file actions
282 lines (247 loc) · 9.27 KB
/
Copy pathCalculadora_2_MF.html
File metadata and controls
282 lines (247 loc) · 9.27 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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
<!DOCTYPE html>
<html lang="es-DO">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Calculadora de Préstamos RD</title>
<style>
body {
font-family: Arial, sans-serif;
max-width: 1000px;
margin: 20px auto;
padding: 20px;
background-color: #f5f5f5;
}
.calculadora {
background-color: white;
padding: 25px;
border-radius: 10px;
box-shadow: 0 0 10px rgba(0,0,0,0.1);
}
.form-row {
display: flex;
gap: 15px;
margin-bottom: 15px;
}
.form-col {
flex: 1;
}
label {
display: block;
margin-bottom: 5px;
font-weight: bold;
}
input, select {
width: 100%;
padding: 8px;
border: 1px solid #ddd;
border-radius: 4px;
}
button {
background-color: #4CAF50;
color: white;
padding: 10px 20px;
border: none;
border-radius: 4px;
cursor: pointer;
transition: background-color 0.3s;
}
button:hover {
background-color: #45a049;
}
#resultado {
margin-top: 20px;
display: none;
}
.resumen-columnas {
display: flex;
gap: 15px;
margin-bottom: 20px;
flex-wrap: wrap;
}
.columna-resumen {
flex: 1;
min-width: 200px;
background-color: #4CAF50;
color: white;
padding: 15px;
border-radius: 8px;
text-align: center;
box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}
#tablaAmortizacion {
margin-top: 20px;
width: 100%;
border-collapse: collapse;
display: none;
}
#tablaAmortizacion th, #tablaAmortizacion td {
border: 1px solid #ddd;
padding: 8px;
text-align: center;
font-size: 0.9em;
}
#tablaAmortizacion th {
background-color: #4CAF50;
color: white;
}
</style>
</head>
<body>
<div class="calculadora">
<h2>Calculadora de Préstamos RD</h2>
<!-- Campos de cliente -->
<div class="form-row">
<div class="form-col">
<label for="cedula">Cédula</label>
<input type="text" id="cedula" required
placeholder="320-1236549-5">
</div>
<div class="form-col">
<label for="nombre">Nombre completo</label>
<input type="text" id="nombre" required>
</div>
</div>
<!-- Formulario principal -->
<form id="formularioPrestamo">
<div class="form-row">
<div class="form-col">
<label for="monto">Monto del préstamo (RD$)</label>
<input type="text" id="monto" required
placeholder="1,000,000.00"
pattern="^\d{1,3}(,\d{3})*(\.\d+)?$">
</div>
<div class="form-col">
<label for="tasa">Tasa de interés mensual (%)</label>
<input type="number" id="tasa" step="0.01" required>
</div>
</div>
<div class="form-row">
<div class="form-col">
<label for="plazo">Plazo (meses)</label>
<input type="number" id="plazo" min="1" max="12" required>
</div>
<div class="form-col">
<label for="frecuencia">Frecuencia de pagos</label>
<select id="frecuencia" required>
<option value="1">Mensual</option>
<option value="2">Quincenal</option>
<option value="4">Semanal</option>
</select>
</div>
</div>
<div class="form-row" style="gap: 10px; margin-top: 20px;">
<button type="button" onclick="calcularPrestamo()">Calcular</button>
<button type="button" onclick="guardarInformacion()" style="background-color: #2196F3;">Guardar</button>
</div>
</form>
<!-- Resultados -->
<div id="resultado">
<div class="resumen-columnas">
<div class="columna-resumen">
<h3>Monto del préstamo</h3>
<p id="montoResumen">RD$0.00</p>
</div>
<div class="columna-resumen">
<h3>Total a pagar</h3>
<p id="total">RD$0.00</p>
</div>
<div class="columna-resumen">
<h3>Intereses totales</h3>
<p id="intereses">RD$0.00</p>
</div>
</div>
</div>
<!-- Tabla de amortización -->
<table id="tablaAmortizacion">
<thead>
<tr>
<th>Pago #</th>
<th>Capital</th>
<th>Interés</th>
<th>Total Pago</th>
<th>Balance</th>
</tr>
</thead>
<tbody id="cuerpoTabla">
</tbody>
</table>
</div>
<script>
// Función de formato RD
function formatoRD(numero) {
return new Intl.NumberFormat('es-DO', {
style: 'currency',
currency: 'DOP',
minimumFractionDigits: 2,
maximumFractionDigits: 2
}).format(numero);
}
// Formatear monto al escribir
document.getElementById('monto').addEventListener('input', function(e) {
let value = e.target.value.replace(/,/g, '');
if(!isNaN(value) && value !== '') {
e.target.value = parseFloat(value).toLocaleString('es-DO');
}
});
function calcularPrestamo() {
// Obtener y validar valores
const monto = parseFloat(document.getElementById('monto').value.replace(/,/g, ''));
const tasaMensual = parseFloat(document.getElementById('tasa').value) / 100;
const plazo = parseInt(document.getElementById('plazo').value);
const frecuencia = parseInt(document.getElementById('frecuencia').value);
if (!monto || !tasaMensual || !plazo || plazo < 1 || plazo > 12) {
alert("Complete todos los campos correctamente (Plazo 1-12 meses)");
return;
}
// Cálculos con interés simple
const totalPagos = plazo * frecuencia;
const interesTotal = monto * tasaMensual * plazo;
const totalPagar = monto + interesTotal;
// Mostrar resultados
document.getElementById('resultado').style.display = 'block';
document.getElementById('montoResumen').textContent = formatoRD(monto);
document.getElementById('total').textContent = formatoRD(totalPagar);
document.getElementById('intereses').textContent = formatoRD(interesTotal);
// Generar tabla de amortización decreciente
generarTablaAmortizacion(monto, tasaMensual, plazo, frecuencia);
}
function generarTablaAmortizacion(monto, tasaMensual, plazo, frecuencia) {
const cuerpoTabla = document.getElementById('cuerpoTabla');
const tabla = document.getElementById('tablaAmortizacion');
cuerpoTabla.innerHTML = '';
tabla.style.display = 'table';
let saldo = monto;
const totalPagos = plazo * frecuencia;
const pagoCapital = monto / totalPagos;
const interesPorPeriodo = (monto * tasaMensual) / frecuencia;
for (let i = 1; i <= totalPagos; i++) {
const totalPago = pagoCapital + interesPorPeriodo;
saldo -= pagoCapital;
const fila = document.createElement('tr');
fila.innerHTML = `
<td>${i}</td>
<td>${formatoRD(pagoCapital)}</td>
<td>${formatoRD(interesPorPeriodo)}</td>
<td>${formatoRD(totalPago)}</td>
<td>${formatoRD(saldo > 0 ? saldo : 0)}</td>
`;
cuerpoTabla.appendChild(fila);
}
}
function guardarInformacion() {
// Lógica para guardar (ejemplo básico)
const data = {
cedula: document.getElementById('cedula').value,
nombre: document.getElementById('nombre').value,
monto: document.getElementById('monto').value,
tasa: document.getElementById('tasa').value,
plazo: document.getElementById('plazo').value,
frecuencia: document.getElementById('frecuencia').value
};
console.log("Datos guardados:", data);
alert("Información guardada en consola");
}
</script>
</body>
</html>