Complete the for with the payment dates

0

Since I could not solve my doubts, in this question I cover a little more what I need to see if they can help me.

I have this function:

function getAmortizacion(monto, tasa, cuotas, periodo, tasa_tipo) {
 var valor_de_cuota = getValorDeCuotaFija(monto, tasa, cuotas, periodo, tasa_tipo);
 var saldo_al_capital = monto;
 var items = new Array();
 for (i=0; i < cuotas; i++) {
  interes = saldo_al_capital * getTasa(tasa, tasa_tipo, periodo);
  abono_al_capital = valor_de_cuota - interes;
  saldo_al_capital -= abono_al_capital;
  numero = i + 1;
  interes = interes.toFixed(2);
  abono_al_capital = abono_al_capital.toFixed(2);
  saldo_al_capital = saldo_al_capital.toFixed(2);
  totalCredito = cuotas * valor_de_cuota;
  item = [numero, interes, abono_al_capital, valor_de_cuota, saldo_al_capital];
  items.push(item);
 }
 var div2 = document.getElementById("input-value-total");
 totalCredito = totalCredito;
 div2.innerHTML = totalCredito;

 return items;
}

All this I paint in a table:

<table id="table-2" class="table table-striped table-sm">
 <thead>
  <tr class="text-center">
   <th>Cuota No.</th>
   <th>Interés</th>
   <th>Abono al capital</th>
   <th>Valor de la cuota</th>
   <th>Saldo al capital</th>
  </tr>
 </thead>
 <tbody id="tbody_1" class="text-center"></tbody>
</table>

Until there all good, but no matter how hard I look for solutions, none adapts to what I need; add a field in the table that indicates the dates of payment, these can be monthly (30 days) or biweekly (15 days):

<label for="select-interests">Intereses</label><select id="select-periods" class="form-control" name="selectPeriods"><option value="mensual">Mensual</option><option value="quincenal">Quincenal</option></select>

... until the amount of fees entered is completed ...

<label for="select-dues">Cuotas</label><input id="select-dues" type="text" placeholder="Cuotas" required class="form-control" name="dues">

and the initial date (first quota) is entered in an input:

<label>Fecha de primer pago</label><input id="input-date" type="date" name="dateFirstPayment" class="form-control">

Thank you very much.

    
asked by Jhojan Guerrero 23.08.2018 в 15:26
source

1 answer

0

I'll give you a basic example here link As I understand the key is that in for you have to make fee * amount_of_days and that He is giving you the dates you need. You can start with a date that is not today as well.

for (i=0; i < CantidadDecuotas; i++) {

     var fecha = diaQueComienza.agregarDias(i*periodoEnDiasEntreCuotas)

 }

I leave a bonus, which is, in addition to adding days, how to change the format of the date as we are used to the non-Anglo-Saxon:

Date.prototype.agregarDias = function(dias) {
    var fecha = new Date(this.valueOf());
    fecha.setDate(fecha.getDate() + dias);
    var options = { year: 'numeric', month: 'numeric', day: 'numeric' };
    return fecha.toLocaleDateString('es-ES', options);
}
    
answered by 23.08.2018 в 17:55