1
I’m making a code that calculates interest and fines on PHP based on the amount of days past due. However, I’m having trouble getting the date and making this calculation.
$databx = new DateTime();
$datavc = new DateTime($bxgst->getDatavencto()); //2018-10-30
$diasatraso = $databx->diff($datavc)->format('%a');
$vm = (($vlprogramado * $vlmulta) / 100);
$vj = (((($pjuros / 30) / 100) * $diasatraso) * 500) + 500;
In this case, today it shows 11 days, and shows as if it was delay, but it is not, it is 11 days in advance, not late.
What would be the best solution?
You can replace the
if
forformat('%r%a')
that he will return the correct signal.– Woss
I tested it here, but it keeps showing as if it were days late. Displayed 11.
– JB_
Thanks for the @Andersoncarloswoss :D tip
– Alvaro Alves
@JB_ if it is advanced, will the value change? If not, you need to find out if the amount received is negative, otherwise the price will be lower by paying in advance.
– Woss
In this condition if pay in advance, the amount does not change, but if pay late there is interest and fines based on the amount of days late.
– JB_
@JB_ I think I understand what you need, I’ll change the code
– Alvaro Alves
If the customer pays until maturity, need to be 0 the days of delay, only if there are delays that enters interest and fines based on the amount of days late.
– JB_
Thank you for the reply
– JB_