4
I’m having trouble putting together a script, I’m not knowing how to calculate date interaction with javascript, I was thinking of making a screen that calculates interest, but returns the values in real time in the inputs that are disabled
follows code:
<fieldset>
<legend>Calcular Juros</legend>
<label>Data de Vencimento:</label>
<input id="datavenc" type="date"/><br />
<label>Data de Pagamento: </label>
<input id="datapag" type="date"/><br />
<label>Valor do Titulo: </label>
<input id="valortitulo" type="text"/><br />
<label>Outras Despesas: </label>
<input id="despesas" type="text"/><br /><br />
<label>Dias em Atraso: </label>
<input id="diasematraso" type="text" disabled/><br />
<label>Juros: </label>
<input id="juros" type="text" disabled/><br />
<label>Valor Total a Pagar: </label>
<input id="valortotal" type="text" disabled/><br />
</fieldset>
For example,
Due date = 01/09/2017
payment date = 30/09/2017
value of the title = 2000
other expenditure = 100
days late = 29
interest = 96,67
total value payable= 2.196,67
Days late = due date - payment date
Interest = (value of security * 5%)/30*days late
Other expenditure = expenditure
Amount payable = Security value + interest + expenses
I think there must be something wrong with these accounts... hehe
– viana
In querySelectorAll you are repeating datavenc twice;
– viana
@acklay Oops, thanks lol, hadn’t even noticed.
– Isac
@acklay It was also missing to calculate, but also already put. The rest seems to me correct.
– Isac
The date is reversed as well. By the logic of the question, that would be exactly a late interest calculation. Generally the payment date would be after maturity.
– viana
@acklay This I did purposefully, for the example of the AP. If it is as you say it becomes negative. But I can always convert to positive, that maybe it’s better
– Isac
Are you sure that your logic is as it should be?! I’m picking on you because I was making an answer and you were faster. After I erased that I saw that there was a lot of error in yours. ehuehuhe but let’s work on it there to help the guy;
– viana
@acklay But you can put yours without problem. I logic I have limited myself to following the accounts that the AP wants to do. And in this sense it seems to coincide with the calculations in the question. Even the values coincide with the result he expected.
– Isac
I already blacked out! heuheuheuh laziness. But test for you see, something is still going wrong.
– viana