?php session_start(); include('debtcalcfiles/functions.php'); // Clear Values if ($_POST['action'] == "clear_values") { $_SESSION['compare_list'] = ''; } // Set the session variables if ($_POST['action'] == "calculate_1") { $_SESSION['loan_num_years'] = $_POST['loan_num_years']; $_SESSION['loan_payment_amount'] = $_POST['loan_payment_amount']; $_SESSION['loan_amount'] = $_POST['loan_amount']; $_SESSION['loan_percent'] = $_POST['loan_percent']; } // If calculating a payment amount if ($_POST['action'] == "calculate_1") { if (!checkValidChars($_SESSION['loan_amount'],"0123456789.")) { $error_div .= getResultDiv('Please enter only numbers for your debt amount'); } elseif (strlen($_SESSION['loan_amount']) < 1) { $error_div .= getResultDiv('Please enter a debt amount'); } if (!checkValidChars($_SESSION['loan_percent'],"0123456789.")) { $error_div .= getResultDiv('Please enter only numbers for the interest rate'); } elseif (strlen($_SESSION['loan_percent']) < 1) { $error_div .= getResultDiv('Please enter an interest rate'); } if (strlen($_SESSION['loan_payment_amount']) < 1 && strlen($_SESSION['loan_num_years']) < 1) { $error_div .= getResultDiv('Please enter either the number of years or a payment amount'); } if (!checkValidChars($_SESSION['loan_payment_amount'],"0123456789.")) { $error_div .= getResultDiv('Please enter only numbers for the payment amount'); } if (!checkValidChars($_SESSION['loan_num_years'],"0123456789.")) { $error_div .= getResultDiv('Please enter only numbers for the number of years'); } } $result_div .= $error_div; // If no errors, go ahead and perform calculations if ($error_div == '') { if ($_POST['action'] == "calculate_1" && $_POST['loan_num_years'] != '') { $rate = $_POST['loan_percent'] / 12; $months = $_POST['loan_num_years']*12; $p = $_POST['loan_amount']; $j = $_POST['loan_percent']/(12*100); $n = $_POST['loan_num_years'] * 12; $payment = $p * ($j / (1-pow((1+$j),-$n))); $_SESSION['compare_list'] = $_POST['loan_amount'] . '::' . $_POST['loan_percent'] . '::' . $_POST['loan_num_years'] . '::' . round($payment,2) . ';' . $_SESSION['compare_list']; // If calculating the number of years } elseif ($_POST['action'] == "calculate_1" && $_POST['loan_payment_amount'] != '') { $p = $_POST['loan_amount']; $m = $_POST['loan_payment_amount']; $r = $_POST['loan_percent']/100; if ((($p/$m)*($r/12)) > 1) { $num_payments = 'Infinite'; } else { $num_payments = 1/12 * -(log(1-($p/$m)*($r/12)))/log(1+($r/12)); $num_payments = round($num_payments,2); } $_SESSION['compare_list'] = $_POST['loan_amount'] . '::' . $_POST['loan_percent'] . '::' . $num_payments . '::' . $_POST['loan_payment_amount'] . ';' . $_SESSION['compare_list']; } } // Create the result table if ($_SESSION['compare_list'] != '') { $compare_array = explode(';',$_SESSION['compare_list']); $compare_i = 0; while ($compare_array[$compare_i] != '') { $row_array = explode('::',$compare_array[$compare_i]); $row_style = ternary($row_style,'odd','even'); $compare_table .= ' $' . $row_array[0] . ' at ' . $row_array[1] . '% for ' . $row_array[2] . ' years = $' . $row_array[3] . ' '; $compare_i++; } // Finish constructing table $compare_table = '

' . $compare_table . '
Amount % Years Payment
'; // Show initial paragraph } else { $compare_table = '

Your different scenarios will display here each time you hit the "Calculate" button to the left.

'; } ?> Prostko & Santillán, LLC Attorneys at Law
Pittsburgh Law Firm

Chapter 7

Chapter 13

Before Bankruptcy

News

Articles

Calculator

Debt Test

Glossary

Relevant Case Law

Debt Payment Comparison Calculator



Fill out the calculator form, then click "calculate" to start comparing different debt payment scenarios. Note that you can either select the number of years to pay the debt off, or you can select the desired monthly payment. When you are done generating values, click on the rows under the "Compare" heading to change their color. That way, you can group your options together for easy viewing.