Jump to content

Calculations, Interest, Diff between two days


Recommended Posts

First, I would like to thank JUSTSOMEGUY for his extensive assistance with one hurdle on my report page. Now I need to do the calculations. Since I need my calculations to operate within 3 different IF statements and within the WHILE loop, I just guessed to put all the calculations after the beginning of the WHILE statement and before the first IF statement. Here is the code from WHILE statement to the first line of the report. However, NONE of the calculations are let someone live with them...ugh!

while($monthStart <= $today){$payment_found = false;  foreach ($payments as $payment)  {	$p = .08;  //Percentage$dp = .08/365; // Returns Daily Percentage$datetime1 = new DateTime(strtotime('$monthStart')); //Get/Set Date 1$datetime2 = new DateTime(strtotime('$monthEnd')); // Get/Set Date 2//If first line of report, there won't be a $monthEndif (strtotime($monthEnd) <= 0) {  $interval = 0;} else {$interval = $datetime1->diff($datetime2);}$dayslate = date('d', strtotime($interval));$intacc = ($dp * $dayslate) * $pmtamt;$appint = 1 * $intacc;$appprinc = $pmtamt - $appint;$bal = $pmtamt - ($appint + $appprinc);if (strtotime($payment['pmt_date']) >= $monthStart && strtotime($payment['pmt_date']) < $monthEnd) {		  $payment_found = true;if (strtotime($payment['pmt_date']) > $monthStart) {echo '<tr><td style="border-bottom-color:#3105b0; border-bottom-style:dashed; border-bottom-width:thin;"><center>'. date("m.d.Y", $monthStart) . '</center></td>';

There's NO output in any fields, except "Days Late". (I added a Days Late column to my output table to see if it returns any values...it ONLY returns "31") Any suggestions....? (Not sure what I was trying to say before I edited that)

Edited by aarontbarksdale
Link to post
Share on other sites
  • Replies 75
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Popular Posts

start using: echo var_dump($your_var);exit; to target the problem.

Don't forget to move the script fragment through the script. You can also use javascript to do the same thing.

See the difference? <?php$p = .08;$row2['pmt_amt'] = 30;$dayslate = -2592000; $intacc = $dayslate * $row2['pmt_amt'] * ($p/365) ; //Calculates Interest Accruedecho var_dump($intacc);?> This

start using: echo var_dump($your_var);exit; to target the problem.

  • Like 1
Link to post
Share on other sites

Don't forget to move the script fragment through the script. You can also use javascript to do the same thing.

  • Like 1
Link to post
Share on other sites
Don't forget to move the script fragment through the script. You can also use javascript to do the same thing.
Okay, so I added
echo var_dump($var);

after every variable in the above code and found that the lines:

$monthStart = strtotime($monthStart);$monthEnd = strtotime($monthEnd);

it returns

bool(false) bool(false)
which leads me to believe that the code is wrong there...any suggestions?
Link to post
Share on other sites

okay...so here's everything for my calculations:

 $p = .08;  //Percentageecho var_dump($p) ."</br>";$dp = .08/365; // Returns Daily Percentageecho var_dump($dp) ."</br>";echo var_dump($monthStart) ."</br>";$monthEnd = strtotime("-1 month", $monthStart);echo var_dump($monthEnd) ."</br>";echo date('m.d.Y', $monthEnd) ."</br>";$interval = $monthEnd - $monthStart;echo var_dump($interval) ."</br>";$dayslate = ($interval/(24*60*60))*-1;echo var_dump($dayslate) ."</br>";echo var_dump($row2['pmt_amt']) ."</br>";$intacc = $dayslate * $row2['pmt_amt'] * ($p/365) ."</br>"; //Calculates Interest Accruedecho var_dump($intacc) ."</br>";$appint = 1 * $intacc; //Calculates how much of payment is applied to Interestecho var_dump($appint) ."</br>";$appprinc = $row2['pmt_amt'] - $appint; // Calculates how much of payment is applied to Principleecho var_dump($appprinc) ."</br>";$bal = $row['supportamount'] + (-1 * $appint) + (-1 * $appprinc); //Calculates the balanceecho var_dump($bal) ."</br>";exit; 

Here's the output:

float(0.08) float(0.000219178082192) int(1272697200) int(1270105200) 04.01.2010int(-2592000) int(30) NULL string(6) "0" int(0) int(0) int(500)
I don't understand why it is not calculating the $intacc It's returning NULL for $pmtamt...which is $row2['pmt_amt'] which is within an array, this could be the problem...any suggestions??? Edited by aarontbarksdale
Link to post
Share on other sites

See the difference?

<?php$p = .08;$row2['pmt_amt'] = 30;$dayslate = -2592000; $intacc = $dayslate * $row2['pmt_amt'] * ($p/365) ; //Calculates Interest Accruedecho var_dump($intacc);?>

This script says $intacc = float(-17043.287671233)

Edited by niche
  • Like 1
Link to post
Share on other sites
See the difference?
<?php$p = .08;$row2['pmt_amt'] = 30;$dayslate = -2592000; $intacc = $dayslate * $row2['pmt_amt'] * ($p/365) ; //Calculates Interest Accruedecho var_dump($intacc);?>

This script says $intacc = float(-17043.287671233)

I need to be able to find the difference between the due dates and any payments. If the balance is zero then there won't be any interest until a balance is generated.So the script will need to find whatever date it is outputting and figure out the days late. If there are no payments between due dates then of course its how many days late that that month has...but if there is a payment then it will also need to determine the difference between due date and payment date...and any remainder balance after payment and between the next due date...it could be easier to determine the interest based on days past between payments...but I would rather show the monthly interest accrued...
Link to post
Share on other sites

Is the original problem solved ($intacc not calculating)? If so, you have to work on your formula.

  • Like 1
Link to post
Share on other sites

Yes, the original formula IS calculating. Okay...so here's what I have thus far:

//...At the very beginning $data = mysql_query("SELECT * FROM clients WHERE client_id = ". $_SESSION['clientid'] ."") or die(mysql_error());$row = mysql_fetch_assoc($data);$monthStart = strtotime($row['datestart']);$today = strtotime('now');$amtdue = $row['supportamount'];//Data from Payments table and variables associated$data2 = mysql_query("SELECT * FROM payments WHERE client_id = ". $_SESSION['clientid'] ." ORDER BY YEAR(pmt_date) ASC") or die(mysql_error());$payments = array();while ($row2 = mysql_fetch_assoc($data2)){  $payments[] = $row2;}$pmtdate = $row2['pmt_date'];$pmtamt = $row2['pmt_amt'];//....Main portion of the pagewhile($monthStart <= $today){  $p = .08;  //Percentage  $dp = .08/365; // Returns Daily Percentage  $monthEnd = strtotime("-1 month", $monthStart);  $interval = $monthEnd - $monthStart;  //If first line of report, there won't be a $monthEnd  if ($monthEnd <= $row['datestart']) {  	$dayslate = 0;	} else {	$dayslate = ($interval/(24*60*60))*-1;	}  $intacc = $dayslate * $amtdue * ($p/365) ."</br>"; //Calculates Interest Accrued  if ($pmtamt > 0) {	$appint = 0;	$appprinc = 0;	$bal = $amtdue;	} else {	  if ($pmtamt < $intacc) {	  $appint = $intacc - $pmtamt;	  $appprinc = 0;	  $bal = $amtdue + $appint;	  } else {	  $appint = $intacc; //Calculates how much of payment is applied to Interest	  $appprinc = $pmtamt - $appint; // Calculates how much of payment is applied to Principle	  $bal = ($appint + $appprinc); //Calculates the balance	  }	}  $due = $amtdue + $bal;  $payment_found = false;  foreach ($payments as $payment)  {	if (strtotime($payment['pmt_date']) >= $monthStart && strtotime($payment['pmt_date']) < $monthEnd) {	  $payment_found = true;	  if (strtotime($payment['pmt_date']) > $monthStart) {		echo '<tr><td><center>'. date("m.d.Y", $monthStart) . '</center></td>';		echo '<td><center>'. "$";		if ($monthStart > strtotime($row['datestart'])) {		   $english_format_number = number_format($amtdue, 2, '.',',');		   } else {		  $english_format_number = number_format($due, 2, '.',',');	   }	   echo "</center></td>";	   echo '<td><center>$0.00</center></td>';	   echo '<td><center>'. "$". $english_format_number = number_format($intacc, 2, '.',',') . '</center></td>';	   echo '<td><center>'. "$". $english_format_number = number_format($appint, 2, '.',',') . '</center></td>';	   echo '<td><center>'. "$". $english_format_number = number_format($appprinc, 2, '.',',') . '</center></td>';	   echo '<td><center>'. "$". $english_format_number = number_format($bal, 2, '.',',') . '</center></td>';	   echo '<td><center>'. $dayslate .'</center></td></tr>';	   }	 echo '<tr><td><center>'. date("m.d.Y", strtotime($payment['pmt_date'])) .'</center></td>';	 echo '<td><center>$0.00</center></td>';	 echo '<td><center>'. "$". $english_format_number = number_format($payment['pmt_amt'], 2, '.',',') . '</center></td>';	 echo '<td><center>'. "$". $english_format_number = number_format($intacc, 2, '.',',') . '</center></td>';	 echo '<td><center>'. "$". $english_format_number = number_format($appint, 2, '.',',') . '</center></td>';	 echo '<td><center>'. "$". $english_format_number = number_format($appprinc, 2, '.',',') . '</center></td>';	 echo '<td><center>'. "$". $english_format_number = number_format($bal, 2, '.',',') . '</center></td>;	 echo '<td><center>'. $dayslate .'</center></td></tr>';	 }  }  if (!$payment_found)  {	 echo '<tr><td><center>'. date("m.d.Y", $monthStart) . '</center></td>';	 echo '<td><center>'. "$". $english_format_number = number_format($due, 2, '.',',') .'</center></td>';	 echo '<td><center>$0.00</center></td>';	 echo '<td><center>'. "$". $english_format_number = number_format($intacc, 2, '.',',') . '</center></td>';	 echo '<td><center>'. "$". $english_format_number = number_format($appint, 2, '.',',') . '</center></td>';	 echo '<td><center>'. "$". $english_format_number = number_format($appprinc, 2, '.',',') . '</center></td>';	 echo '<td><center>'. "$". $english_format_number = number_format($bal, 2, '.',',') . '</center></td>';	 echo '<td><center>'. $dayslate .'</center></td></tr>';	 }$monthStart = strtotime('+1 month', $monthStart);$monthEnd = strtotime('+1 month', $monthStart);}

Date | Amt Due | Amt Pd | Int Acc | Applied to Int | Applied to Princ | Bal | Late 05.01.2010 $1,003.29 $0.00 $3.29 $3.29 $0.00 $503.29 30 06.01.2010 $1,003.40 $0.00 $3.40 $3.40 $0.00 $503.40 31 07.01.2010 $1,003.29 $0.00 $3.29 $3.29 $0.00 $503.29 30
First, as you can see, the first entry should only be $500, Int. Accumulated should be there but nothing until Balance...THENThe balance and intacc from one line needs to be applied to the $amtdue of the following line. The end result should be like this:
Date | Amt Due | Amt Pd | Int Acc | Applied to Int | Applied to Princ | Bal | Late 05.01.2010 $500.00 $0.00 $3.29 $0.00 $0.00 $503.29 30 06.01.2010 $1,003.29 $0.00 $6.60 $0.00 $0.00 $1,009.89 31 07.01.2010 $1,509.89 $0.00 $10.26 $0.00 $0.00 $1,520.15 30 07.15.2010 $1,520.15 $650.00 $3.12 $23.27 $626.73 $873.27 15 08.01.2010 $873.27 $0.00 $2.87 $0.00 $0.00 $876.14 15
And so on...sorry for the loss formatting on the table outputs...but hopefully you see what I'm going for...please help... Edited by aarontbarksdale
Link to post
Share on other sites

You have a duty to make sure you have a valid formula. Assuming you do, which iteration is throwing the NEXT problem and what is it SPECIFICALLY?

Edited by niche
  • Like 1
Link to post
Share on other sites

I told you, the formula works...even with the numbers you hard coded...it works...what's NOT working is the output table... I lined out exactly what I needed it to do, I THINK I have it set up correctly...but clearly I don't, just wondering if you might know WHERE the output table coding is messed up. To show you that the code works do it by hand: 30 x -2592000 x 0.000219 = -17,029.44...so, yes, the formula WORKS...the math is there... Sorry...tired, not trying to be a ######.

Edited by aarontbarksdale
Link to post
Share on other sites
if you might know WHERE the output table coding is messed up.
That's what I'm trying to teach you. I don't have access to your data set so you'll have to find it yourself. Mistakes are easy to find simply by echoing ALL THE input/output for each iteration. Which iteration is giving you a problem? Where's the first echo that's giving you trouble?
  • Like 1
Link to post
Share on other sites

After double-checking everything, it appears the math is correct. Let me see if I can break this down another way with regards to the output table. Starting Month needs to display the Amount Due ONLY, since no interest will be due on this line (since it's reflective of the first due date. IF there is a payment made within that month, Amount Due does not need to be shown, but the Payment Amount that corresponds with that date shown in the corresponding column, along with any interest accrued from Due Date to payment date. Then the balance (amount due - amount paid) in it's corresponding column.IF payment was less than amount due, on the next due date line, interest from the day after payment was made to the new due date should be calculated and added to the balance...And ALWAYS, any balance should always be carried over and added with the regular monthly payment... Hope this helps.

Link to post
Share on other sites

Which line in your #10 post fails to produce the expected value? BTW, '<br/>' is back in $intacc.

Edited by niche
  • Like 1
Link to post
Share on other sites

I would say it almost starts to break down at the while loop. What I have there the code does this:Table Line 1: Doubles the Amount Due and adds Interest (that shouldn't be there)...has balance with interest (that shouldn't be there)Table Line 2: Correct in that the Amount Due has the Balance added...but again, interest shouldn't be there YET...then incorrect balance. Interest IS correct.Payment line: Doesn't show up using code from post #10, but doesn't accurately show the right balance at the end.Updated Code:

while($monthStart <= $today){$payment_found = false;    foreach ($payments as $payment)    {    if (strtotime($payment['pmt_date']) >= $monthStart && strtotime($payment['pmt_date']) < $monthEnd) {          $payment_found = true;if (strtotime($payment['pmt_date']) > $monthStart) {echo '<tr><td style="border-bottom-color:#3105b0; border-bottom-style:dashed; border-bottom-width:thin;"><center>'. date("m.d.Y", $monthStart) . '</center></td>';echo '<td style="border-bottom-color:#3105b0; border-bottom-style:dashed; border-bottom-width:thin;"><center>'. "$". $english_format_number = number_format($due + $bal, 2, '.', ',') .'</center></td>';echo '<td style="border-bottom-color:#3105b0; border-bottom-style:dashed; border-bottom-width:thin;"><center>$0.00</center></td>'; echo '<td style="border-bottom-color:#3105b0; border-bottom-style:dashed; border-bottom-width:thin;"><center>'. "$". $english_format_number = number_format($intacc, 2, '.',',') . '</center></td>';echo '<td style="border-bottom-color:#3105b0; border-bottom-style:dashed; border-bottom-width:thin;"><center>'. "$". $english_format_number = number_format($appint, 2, '.',',') . '</center></td>';echo '<td style="border-bottom-color:#3105b0; border-bottom-style:dashed; border-bottom-width:thin;"><center>'. "$". $english_format_number = number_format($appprinc, 2, '.',',') . '</center></td>';echo '<td style="border-bottom-color:#3105b0; border-bottom-style:dashed; border-bottom-width:thin;"><center>'. "$". $english_format_number = number_format($bal, 2, '.',',') . '</center></td></td>';echo '<td style="border-bottom-color:#3105b0; border-bottom-style:dashed;border-left-style:dashed; border-right-style:dashed; border-width:thin;"><center>'. $dayslate .'</center></td></tr>';}echo '<tr><td style="border-bottom-color:#3105b0; border-bottom-style:dashed; border-bottom-width:thin;"><center>'. date("m.d.Y", strtotime($payment['pmt_date'])) .'</center></td>';echo '<td style="border-bottom-color:#3105b0; border-bottom-style:dashed; border-bottom-width:thin;"><center>$0.00</center></td>';echo '<td style="border-bottom-color:#3105b0; border-bottom-style:dashed; border-bottom-width:thin;"><center>'. "$". $english_format_number = number_format($payment['pmt_amt'], 2, '.',',') . '</center></td>'; echo '<td style="border-bottom-color:#3105b0; border-bottom-style:dashed; border-bottom-width:thin;"><center>'. "$". $english_format_number = number_format($intacc, 2, '.',',') . '</center></td>';echo '<td style="border-bottom-color:#3105b0; border-bottom-style:dashed; border-bottom-width:thin;"><center>'. "$". $english_format_number = number_format($appint, 2, '.',',') . '</center></td>';echo '<td style="border-bottom-color:#3105b0; border-bottom-style:dashed; border-bottom-width:thin;"><center>'. "$". $english_format_number = number_format($appprinc, 2, '.',',') . '</center></td>';echo '<td style="border-bottom-color:#3105b0; border-bottom-style:dashed; border-bottom-width:thin;"><center>'. "$". $english_format_number = number_format($bal, 2, '.',',') . '</center></td></td>';echo '<td style="border-bottom-color:#3105b0; border-bottom-style:dashed;border-left-style:dashed; border-right-style:dashed; border-width:thin;"><center>'. $dayslate .'</center></td></tr>';}  }  if (!$payment_found)  {echo '<tr><td style="border-bottom-color:#3105b0; border-bottom-style:dashed; border-bottom-width:thin;"><center>'. date("m.d.Y", $monthStart) . '</center></td>';echo '<td style="border-bottom-color:#3105b0; border-bottom-style:dashed; border-bottom-width:thin;"><center>'. "$". $english_format_number = number_format($due, 2, '.',',') .'</center></td>';echo '<td style="border-bottom-color:#3105b0; border-bottom-style:dashed; border-bottom-width:thin;"><center>$0.00</center></td>'; echo '<td style="border-bottom-color:#3105b0; border-bottom-style:dashed; border-bottom-width:thin;"><center>'. "$". $english_format_number = number_format($intacc, 2, '.',',') . '</center></td>';echo '<td style="border-bottom-color:#3105b0; border-bottom-style:dashed; border-bottom-width:thin;"><center>'. "$". $english_format_number = number_format($appint, 2, '.',',') . '</center></td>';echo '<td style="border-bottom-color:#3105b0; border-bottom-style:dashed; border-bottom-width:thin;"><center>'. "$". $english_format_number = number_format($appprinc, 2, '.',',') . '</center></td>';echo '<td style="border-bottom-color:#3105b0; border-bottom-style:dashed; border-bottom-width:thin;"><center>'. "$". $english_format_number = number_format($bal, 2, '.',',') . '</center></td></td>';echo '<td style="border-bottom-color:#3105b0; border-bottom-style:dashed;border-left-style:dashed; border-right-style:dashed; border-width:thin;"><center>'. $dayslate .'</center></td></tr>';}$monthStart = strtotime('+1 month', $monthStart);$monthEnd = strtotime('+1 month', $monthStart);echo var_dump($bal) ."<br/>";$i++;//exit;}

Below is a screenshot of the output...maybe this will helpscreenshot.jpg

Link to post
Share on other sites

I need you to be clear about the bogus output so we can focus on one problem at a time. Else everything gets too complicated given the limitations of the forum. What's the first value that's incorrect for the date 04/01/2013?

Edited by niche
  • Like 1
Link to post
Share on other sites

Okay...just saw this TODAY, sorry...here's the thing...I played around last night and here's the updated code and output:

while($monthStart <= $today){$p = .08;  //Percentageif (empty($monthEnd)){$monthEnd = strtotime("-1 Month", $monthStart);}if (isset($monthEnd)){$monthEnd = $monthEnd;}if (isset($pmtamt)){$interval = $monthEnd - $pmtdate;}$interval = $monthEnd - $monthStart;//If first line of report, there won't be a $monthEndif ($monthEnd <= $row['datestart']) {  $dayslate = 0;} else {$dayslate = ($interval/(24*60*60))*-1;}$intacc = $dayslate * $amtdue * ($p/365); //Calculates Interest Accruedif (empty($newint)) {$newint = 0;}$totint = $intacc + $newint;echo var_dump($pmtamt) ."<br/>";echo var_dump($dayslate) ."<br/>";echo var_dump($intacc) ."<br/>";echo var_dump($totint) ."<br/>";echo var_dump($appint) ."<br/>";echo var_dump($appprinc) ."<br/>";echo var_dump($bal) ."<br/>";echo var_dump($amtdue) ."<br/>"; $payment_found = false;	foreach ($payments as $payment)	{	if (strtotime($payment['pmt_date']) >= $monthStart && strtotime($payment['pmt_date']) < $monthEnd) {		  $payment_found = true;if (strtotime($payment['pmt_date']) > $monthStart) {echo '<tr><td style="border-bottom-color:#3105b0; border-bottom-style:dashed; border-bottom-width:thin;"><center>'. date("m.d.Y", $monthStart) . '</center></td>';echo '<td style="border-bottom-color:#3105b0; border-bottom-style:dashed; border-bottom-width:thin;"><center>'. "$";$due = $amtdue + $bal;echo $english_format_number = number_format($due, 2, '.', ',') .'</center></td>';echo '<td style="border-bottom-color:#3105b0; border-bottom-style:dashed; border-bottom-width:thin;"><center>$0.00</center></td>';echo '<td style="border-bottom-color:#3105b0; border-bottom-style:dashed; border-bottom-width:thin;"><center>'. "$";if (empty($newint)) {$newint = 0;}$totint = $intacc + $newint;echo $english_format_number = number_format($totint, 2, '.',',') . '</center></td>';echo '<td style="border-bottom-color:#3105b0; border-bottom-style:dashed; border-bottom-width:thin;"><center>'. "$";$ai = $pmtamt - $totint;if ($pmtamt > $totint) {$appint = $pmtamt - $ai; //Calculates how much of payment is applied to Interest} else {$appint = $totint - $pmtamt;}echo $english_format_number = number_format($appint, 2, '.',',') . '</center></td>';echo '<td style="border-bottom-color:#3105b0; border-bottom-style:dashed; border-bottom-width:thin;"><center>'. "$";if ($pmtamt > $totint) {$appprinc = $pmtamt - ($pmtamt - $ai);} else {$appprinc = 0;}$english_format_number = number_format($appprinc, 2, '.',',') . '</center></td>';echo '<td style="border-bottom-color:#3105b0; border-bottom-style:dashed; border-bottom-width:thin;"><center>'. "$";$bal = $amtdue - ($amtdue - $totint);echo $english_format_number = number_format($bal, 2, '.',',') . '</center></td></td>';echo '<td style="border-bottom-color:#3105b0; border-bottom-style:dashed;border-left-style:dashed; border-right-style:dashed; border-width:thin;"><center>'. $dayslate .'</center></td></tr>';}$interval = strtotime($payment['pmt_date']) - $monthStart;echo '<tr><td style="border-bottom-color:#3105b0; border-bottom-style:dashed; border-bottom-width:thin;"><center>'. date("m.d.Y", strtotime($payment['pmt_date'])) .'</center></td>';echo '<td style="border-bottom-color:#3105b0; border-bottom-style:dashed; border-bottom-width:thin;"><center>'. "$";$due = $amtdue + $bal;echo $english_format_number = number_format($due, 2, '.',',') . '</center></td>';echo '<td style="border-bottom-color:#3105b0; border-bottom-style:dashed; border-bottom-width:thin;"><center>'. "$". $english_format_number = number_format($payment['pmt_amt'], 2, '.',',') . '</center></td>';echo '<td style="border-bottom-color:#3105b0; border-bottom-style:dashed; border-bottom-width:thin;"><center>'. "$";$intacc = $dayslate * $amtdue * ($p/365); //Calculates Interest Accruedif (empty($newint)) {$newint = 0;}$totint = $intacc + $newint;echo $english_format_number = number_format($totint , 2, '.',',') . '</center></td>';echo '<td style="border-bottom-color:#3105b0; border-bottom-style:dashed; border-bottom-width:thin;"><center>'. "$";$ai = $pmtamt - $totint;if ($pmtamt > $totint) {$appint = $pmtamt - $ai; //Calculates how much of payment is applied to Interest} else {$appint = $totint - $pmtamt;}echo $english_format_number = number_format($appint , 2, '.',',') . '</center></td>';echo '<td style="border-bottom-color:#3105b0; border-bottom-style:dashed; border-bottom-width:thin;"><center>'. "$";if ($pmtamt > $totint) {$appprinc = $pmtamt - ($pmtamt - $ai);} else {$appprinc = 0;}echo $english_format_number = number_format($appprinc, 2, '.',',') . '</center></td>';echo '<td style="border-bottom-color:#3105b0; border-bottom-style:dashed; border-bottom-width:thin;"><center>'. "$";$bal = $amtdue - ($amtdue - $totint);echo $english_format_number = number_format($bal, 2, '.',',') . '</center></td></td>';echo '<td style="border-bottom-color:#3105b0; border-bottom-style:dashed;border-left-style:dashed; border-right-style:dashed; border-width:thin;"><center>'. $dayslate .'</center></td></tr>';}  }  if (!$payment_found)  {echo '<tr><td style="border-bottom-color:#3105b0; border-bottom-style:dashed; border-bottom-width:thin;"><center>'. date("m.d.Y", $monthStart) . '</center></td>';echo '<td style="border-bottom-color:#3105b0; border-bottom-style:dashed; border-bottom-width:thin;"><center>'. "$";$due = $amtdue + $bal;echo $english_format_number = number_format($due, 2, '.',',') .'</center></td>';echo '<td style="border-bottom-color:#3105b0; border-bottom-style:dashed; border-bottom-width:thin;"><center>$0.00</center></td>';echo '<td style="border-bottom-color:#3105b0; border-bottom-style:dashed; border-bottom-width:thin;"><center>'. "$";$intacc = $dayslate * $amtdue * ($p/365); //Calculates Interest Accruedif (empty($newint)) {$newint = 0;}$totint = $intacc + $newint;echo $english_format_number = number_format($totint, 2, '.',',') . '</center></td>';echo '<td style="border-bottom-color:#3105b0; border-bottom-style:dashed; border-bottom-width:thin;"><center>'. "$";$ai = $pmtamt - $totint;if ($pmtamt > $totint) {$appint = $pmtamt - $ai; //Calculates how much of payment is applied to Interest} else {$appint = $totint - $pmtamt;}echo $english_format_number = number_format($appint, 2, '.',',') . '</center></td>';echo '<td style="border-bottom-color:#3105b0; border-bottom-style:dashed; border-bottom-width:thin;"><center>'. "$";if ($pmtamt > $totint) {$appprinc = $pmtamt - ($pmtamt - $ai);} else {$appprinc = 0;}echo $english_format_number = number_format($appprinc, 2, '.',',') . '</center></td>';echo '<td style="border-bottom-color:#3105b0; border-bottom-style:dashed; border-bottom-width:thin;"><center>'. "$";$bal = $amtdue - ($amtdue - $totint);echo $english_format_number = number_format($bal, 2, '.',',') . '</center></td></td>';echo '<td style="border-bottom-color:#3105b0; border-bottom-style:dashed;border-left-style:dashed; border-right-style:dashed; border-width:thin;"><center>'. $dayslate .'</center></td></tr>';}$monthStart = strtotime('+1 month', $monthStart);$monthEnd = strtotime('+1 month', $monthStart);$newint = $totint;$amtdue = $due;}

While it's MUCH longer, I've added the calculations AT the entry line for the purpose of finding where I've gone wrong...this has led a bit to a few issues...but I will answer your question none the less.screenshot2.jpgOkay, I got the CORRECT Amount Due added:{A} Interest Accumulated should not be IF no payment is made within the month. {B} Applied to Interest should ONLY be here when a payment has been made.{C} Balance should be $500.00 (or same as amount due), Int. Accumulated is NOT included in the balance.

Edited by aarontbarksdale
Link to post
Share on other sites

Your script is functioning properly? Just looking at the output, I would not expect that the Interest Accumulated for 5/1/13 would be zero. IMO.

  • Like 1
Link to post
Share on other sites

The interest for the month should show up in the following month...OR on the payment line when the payment comes in. So, yes, the Interest for 5/1 should NOT be zero, it should be $3.40.And no, it's still not functioning properly since the unpaid balance is no longer showing up in the balance column.

Edited by aarontbarksdale
Link to post
Share on other sites

$bal is the variable for the balance. When I went to copy/paste the calculation...I realized what happened and fixed it. However,screenshot3.jpgthe interest is still there, the applied to int is still there, but the balance is correct...the due date on the next line is correct as well, but there's no Interest...and the balance is wrong...

Link to post
Share on other sites

per post #18, the interest doesn't appear to be updating either.

Edited by niche
  • Like 1
Link to post
Share on other sites

Okay guys, I cleaned up my code using CSS to eliminate all the individual styles on EACH <TD> tag. Perhaps this will be easier to read. ALSO, for a couple of "if (isset($))" or "if (empty($))" I treated as "if...else" statements to control how the code functioned better. With that, I got the first line correct! YAY!!! Now on to the second (and subsequent DUE lines)...

while($monthStart <= $today){$p = .08;  //Percentageif (empty($monthEnd)){$interval = $monthStart - $monthEnd;} else {$interval = $monthEnd - $monthStart;}if (isset($pmtamt)){$interval = $pmtdate - $monthStart;} else {$interval = $monthEnd - $monthStart;}//If first line of report, there won't be a $monthEndif ($monthEnd <= $row['datestart']) {  $dayslate = 0;} else {$dayslate = ($interval/(24*60*60))*1;}$intacc = $dayslate * $bal * ($p/365); //Calculates Interest Accruedif (empty($newint)) {$newint = 0;}$totint = $intacc + $newint;echo var_dump($pmtamt) ."= 'pmtamt'<br/>";echo var_dump($dayslate) ."= 'dayslate'<br/>";echo var_dump($intacc) ."= 'intacc'<br/>";echo var_dump($totint) ."= 'totint'<br/>";echo var_dump($appint) ."= 'appint'<br/>";echo var_dump($appprinc) ."= 'appprinc'<br/>";echo var_dump($bal) ."= 'bal'<br/>";echo var_dump($amtdue) ."= 'amtdue'<br/>";echo "<br/>"; $payment_found = false;    foreach ($payments as $payment)    {    if (strtotime($payment['pmt_date']) >= $monthStart && strtotime($payment['pmt_date']) < $monthEnd) {          $payment_found = true; //This segment displays the month's due date line if payment is made within that month if (strtotime($payment['pmt_date']) > $monthStart) {echo '<tr><td>'. date("m.d.Y", $monthStart) . '</td>';echo '<td>'. "$";$due = $amtdue + $bal; echo $english_format_number = number_format($due, 2, '.', ',') .'</td>';echo '<td>$0.00</td>'; echo '<td>'. "$";if (empty($newint)) {$newint = 0;}$totint = 0;if(isset($monthEnd)){$totint = $intacc + $newint;} echo $english_format_number = number_format($totint, 2, '.',',') . '</td>';echo '<td>'. "$";$ai = $pmtamt - $totint;if ($pmtamt > $totint) {$appint = $pmtamt - $ai; //Calculates how much of payment is applied to Interest} else {$appint = $totint - $pmtamt;}echo $english_format_number = number_format($appint, 2, '.',',') . '</td>';echo '<td>'. "$";if ($pmtamt > $totint) {$appprinc = $pmtamt - $ai;} else {$appprinc = 0; }$english_format_number = number_format($appprinc, 2, '.',',') . '</td>';echo '<td>'. "$";$bal = $amtdue;echo $english_format_number = number_format($bal, 2, '.',',') . '</td></td>';echo '<td>'. $dayslate .'</td></tr>';} //End Segment//This segment displays the Payment Line$interval = strtotime($payment['pmt_date']) - $monthStart;echo '<tr><td>'. date("m.d.Y", strtotime($payment['pmt_date'])) .'</td>';echo '<td>'. "$";$due = $amtdue + $bal; echo $english_format_number = number_format($due, 2, '.',',') . '</td>';echo '<td>'. "$". $english_format_number = number_format($payment['pmt_amt'], 2, '.',',') . '</td>'; echo '<td>'. "$";$intacc = $dayslate * $amtdue * ($p/365); //Calculates Interest Accruedif (empty($newint)) {$newint = 0;}$totint = $intacc + $newint;echo $english_format_number = number_format($totint , 2, '.',',') . ' </td>';echo '<td>'. "$";$ai = $pmtamt - $totint;if ($pmtamt > $totint) {$appint = $pmtamt - $ai; //Calculates how much of payment is applied to Interest} else {$appint = $totint - $pmtamt;}echo $english_format_number = number_format($appint , 2, '.',',') . ' </td>';echo '<td>'. "$";if ($pmtamt > $totint) {$appprinc = $pmtamt - ($pmtamt - $ai);} else {$appprinc = 0; }echo $english_format_number = number_format($appprinc, 2, '.',',') . ' </td>';echo '<td>'. "$";$bal = $amtdue - $totint;echo $english_format_number = number_format($bal, 2, '.',',') . ' </td>';echo '<td>'. $dayslate .'</td></tr>';}//End Payment Line Segment  }  if (!$payment_found) //This segment is the Due Date Line.  {echo '<tr><td>'. date("m.d.Y", $monthStart) . ' </td>';echo '<td>'. "$";$due = $amtdue + $bal; echo $english_format_number = number_format($due, 2, '.',',') .' </td>';echo '<td>$0.00 </td>'; echo '<td>'. "$";$intacc = $dayslate * $amtdue * ($p/365); //Calculates Interest Accruedif (empty($newint)) {$newint = 0;}$totint = $intacc + $newint;echo $english_format_number = number_format($totint, 2, '.',',') . ' </td>';echo '<td>'. "$";$ai = $pmtamt - $totint;if ($pmtamt > $totint) {$appint = $pmtamt - $ai; //Calculates how much of payment is applied to Interest} else {$appint = $totint - $pmtamt;}echo $english_format_number = number_format($appint, 2, '.',',') . ' </td>';echo '<td>'. "$";if ($pmtamt > $totint) {$appprinc = $pmtamt - ($pmtamt - $ai);} else {$appprinc = 0; }echo $english_format_number = number_format($appprinc, 2, '.',',') . ' </td>';echo '<td>'. "$";$bal = $amtdue;echo $english_format_number = number_format($bal, 2, '.',',') . ' </td>';echo '<td>'. $dayslate .' </td></tr>';}$monthStart = strtotime('+1 month', $monthStart);$monthEnd = strtotime('+1 month', $monthStart);$newint = $totint;$amtdue = $due; 

Here's the new Output:screenshot4.jpgSecond Line (Date 05.01.2013): As you can see, the "Amount Due" added correctly. It also added the "Interest Accumulated" is correct from the previous month. However, the "Applied to Interest" shouldn't be there, and it appears that "Applied to Principle" is NULL or not formatted correctly...Then the balance should be equal to the "Amount Due" (NO INTEREST INCLUDED HERE). I'm focused on getting the SECOND LINE here fixed before I worry about the payment line. Any suggestions you may have...WONDERFUL and thank you.@Justsomeguy: If this were compounded interest, yes, we would include the interest, and that balance with interest would be subject to interest...however, this is SIMPLE interest.@niche Does this correct the error you were looking at?

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...