I’m trying to do a schedule like a loan.
So I have done the following code:
function periode($var, $i2)
{
if($var=='52')
{
echo '"+ '.$i2.' week"';
}
if($var=='26')
{
echo '"+ ('.$i2.' +1) week"';
}
if($var=='12')
{
echo '"+ '.$i2.' month"';
}
if($var=='6')
{
echo '"+ ('.$i2.' +1) month"';
}
if($var=='2')
{
echo '"+ ('.$i2.' +6) month"';
}
if($var=='1')
{
echo '"+ ('.$i2.' +12) month"';
}
}
$chaine ="
<table style='width:100%'>
<tr>
<th>Capital Principal</th>
<th>Date d'échéance</th>
<th>Montant de l'échéance</th>
<th>Capital restant dû</th>
</tr>";
$i2=0;
$montant_echeance = round($montant_du / $nombre_echeances, 2);
$reste=$montant_du ;
while($i2 <= $nombre_echeances)
{
echo $date =date("d-m-Y", strtotime($debut) .periode($pay_periodicity, $i2));
if ($i2 == $nombre_echeances)
{
$montnt_echeance = $reste;
$reste = 0;
}
$chaine .= "<tr>
<td>$montant_du</td>
<td>".$date."</td>
<td>$montant_echeance</td>
<td>$reste</td></tr>'";
$reste = $reste-$montant_echeance;
$i2++;
}
$chaine .="</table>";
print "$chaine";
}
But instead of returning to me the good date, it returns to me:
"+ 0 month"11-10-2012"+ 1 month"11-10-2012"+ 2 month"11-10-2012"+ 3 month"11-10-2012"+ 4 month"11-10-2012"+ 5 month"11-10-2012"+ 6 month"11-10-2012"+ 7 month"11-10-2012"+ 8 month"11-10-2012"+ 9 month"11-10-2012"+ 10 month"11-10-2012"+ 11 month"11-10-2012"+ 12 month"11-10-2012"+ 13 month"11-10-2012"+ 14 month"11-10-2012"+ 15 month"11-10-2012"+ 16 month"11-10-2012"+ 17 month"11-10-2012"+ 18 month"11-10-2012"+ 19 month"11-10-2012"+ 20 month"11-10-2012"+ 21 month"11-10-2012"+ 22 month"11-10-2012"+ 23 month"11-10-2012"+ 24 month"11-10-2012"+ 25 month"11-10-2012"+ 26 month"11-10-2012"+ 27 month"11-10-2012"+ 28 month"11-10-2012"+ 29 month"11-10-2012"+ 30 month"11-10-2012"+ 31 month"11-10-2012"+ 32 month"11-10-2012"+ 33 month"11-10-2012"+ 34 month"11-10-2012"+ 35 month"11-10-2012"+ 36 month"11-10-2012"+ 37 month"11-10-2012"+ 38 month"11-10-2012"+ 39 month"11-10-2012"+ 40 month"11-10-2012"+ 41 month"11-10-2012"+ 42 month"11-10-2012"+ 43 month"11-10-2012"+ 44 month"11-10-2012"+ 45 month"11-10-2012"+ 46 month"11-10-2012"+ 47 month"11-10-2012"+ 48 month"11-10-2012"+ 49 month"11-10-2012"+ 50 month"11-10-2012"+ 51 month"11-10-2012"+ 52 month"11-10-2012"+ 53 month"11-10-2012"+ 54 month"11-10-2012"+ 55 month"11-10-2012"+ 56 month"11-10-2012"+ 57 month"11-10-2012"+ 58 month"11-10-2012"+ 59 month"11-10-2012"+ 60 month"11-10-2012 '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Capital Principal Date d'échéance Montant de l'échéance Capital restant dû
6210.04 11-10-2012 103.5 6210.04
6210.04 11-10-2012 103.5 6106.54
6210.04 11-10-2012 103.5 6003.04
6210.04 11-10-2012 103.5 5899.54
6210.04 11-10-2012 103.5 5796.04
6210.04 11-10-2012 103.5 5692.54
6210.04 11-10-2012 103.5 5589.04
It is really weird,
I’m a bit lost I really have no Idea of what is wrong with that function.
Any advice will be much appreciated.
Receive all my utmost Respect.
Kind Regards.
SP.
Your php code is not well written and it won’t work. Since you didn’t post the complete code, I don’t know how to help. I gave some tips & ideas that will help you:
See my below sample code: