Jump to content

[SOLVED] Monthly Payments Calculator


Recommended Posts

I know there are many calculators out there that calculate monthly payments, etc.. but I just need a simple one that calculates (in a table) the Monthly payments for a vehicle over certain months at different money down at a set interest amount.

 

Example: 8lztsybjbv.jpg

 

If I knew where to start that would be super helpful. I am more than willing to build it myself, but I don't even understand the payments myself (not the best Accountant here)

 

Any ideas?

Link to comment
Share on other sites

Depends on how accurate the calculations need to be.

 

Javascript would be convenient and relatively easy, should the calculations be ok if they are pretty close.

 

PHP with the BC math extension would give more exacting results, and you could use Ajax to make it more user friendly (read: no page refreshing).

 

You only need to figure out the formula, PHP can do the rest.  Javascript can handle a lot as well.

Link to comment
Share on other sites

I would love to use PHP as I am quickly becoming much better at it and the possibilities of PHP are endless from what I have seen.

I'm looking into these math functions and they should work.

 

I'll probably have a couple <input> fields that need to be multiplied, shouldn't require anything but multiplication.. although the actual Amortization formula is much more complex and requires ^ (to the power of) values also.

 

I imagine I will easily find the answer while googling in the morning, but I assume there is a way to set input forms to $variables without much hassle?

 

Thanks for all your help, this is the best learning experience I've had in coding since I read HTML For Dummies front to back :)

Link to comment
Share on other sites

Here is a payment calculator I wrote for car payments ...... you need to input the amounts in PHP but it works great

 

<?php

/*
* Fixed Rate Interest Loan Calulator
*/

// Do you pay on the amount at time of loan purchase?
// Or do you pay on the amount of the that you currently owe?
// Options
// ---------------------
// amountOwed | timeofPur
$loanType = 'amountOwed';

//Interest Rate
//  1-.00
$rate = '.23';
$rateYr = $rate / 365.5;
// Amount Of Loan
$amount = 10750;

// Pay Cycle In Days
$payLength = 14;

$paymentAmounts = 176;

$currentDay = 0;
$totalDays = 0;
$totalInterest = 0;
$totalInterestPayments = array();
$totalAmountPaid = 0;
$totalAmountOwed = $amount;
$lastPayment = 0;
$totalPayments = 0;
echo '<span style="font-size: 10px;">';
// Start calulating the total length
while ($totalAmountOwed > 0)
{
    // Are we adding interest?
    if ($currentDay == 365) {
        // Add in loan interest
        $interestAdd = ($loanType == 'amountOwed') ? $rate * $totalAmountOwed : $rate * $amount;
        $totalAmountOwed += $interestAdd;
        $totalInterest += $interestAdd;
        $currentDay = 0;
echo ' ------------------------------- <br /><br /> INTEREST ADDING <br /><br />';
echo '<strong>Added Interest : </strong> $'.round($interestAdd, 2).' Loan Balance is now $'.round( $totalAmountOwed, 2).' <br /><br />';
echo '<br /><br /> ------------------------------- <br /><br />';
    } else {
        $currentDay++;
    }
    
    if ($lastPayment == $payLength)
    {
if ($totalAmountOwed < $paymentAmounts)
        {
	$finalPaymentAmount = $totalAmountOwed;
                $paymentAmounts = $totalAmountOwed;
}
        // Get the total amount we are paying in interest add to array
        $interestPaid = $payLength * $rateYr * $totalAmountOwed;
        $totalPayments++;
        $totalInterestPayments[] = $interestPaid;
        $totalAmountPaid += $paymentAmounts;
        $totalAmountOwed = $totalAmountOwed - $paymentAmounts;
        $lastPayment = 0;
if ($finalPaymentAmount)
{
	echo '<strong>Making final payment of $'.round($paymentAmounts, 2).' and $'.round($interestPaid, 2).' of it is interest <br /><br /> ------------------------------- <br /><br /> LOAN IS PAID IN FULL <br /><br /> ------------------------------- <br /><br />';
}
else
{
	echo '<strong>Making a payment of $'.round($paymentAmounts, 2).' and $'.round($interestPaid, 2).' of it is interest loan balance is now $'.round($totalAmountOwed, 2).' <br /><br />';
}
    }
    else
    {
        $lastPayment++;
    }
    
    $totalDays++;
}

$interestAddedCount = count($totalInterestPayments);
foreach ($totalInterestPayments as $k => $v)
{
    $a++;
    $interestTotal += $v;
}
$interestToward = $interestTotal / $interestAddedCount;

$yearDay = 0;
$year = 0;
$monthCount = 0;
while( $totalDays != 0)
{
    if ($yearDay == 365) {
        $year++;
        $yearDay = 0;
    } else {
        $yearDay++;
    }

    if ($totalDays < 365) {
        if ($dayMonth != 30) {
            $dayMonth++;
        } else {
            $monthCount++;
            $dayMonth = 0;
        }
    }
    
    $totalDays--;
}

$interestPercentage = round(($interestToward / $paymentAmounts) * 100);

// Breakdown some stats!
echo 'Total Payments : '.$totalPayments.' <br />';
echo 'Final Payment Amount : $'.round($finalPaymentAmount,2).' <br />';
echo 'Loan Length : '.$year.' Year(s) '.$monthCount.' Month(s) '.$dayMonth.' Day(s) <br />';
echo 'Interest Paid : $'.round($totalInterest, 2).' <br />';
echo 'Total Cost of Loan : $'.round($totalInterest + $amount, 2).' <br />';
echo 'On Average You will be paying : $'.round($interestToward, 2).' towards interest each payment or '.$interestPercentage.'% of each payment is interest';
?>
</span>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

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.   Restore formatting

  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.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.