how to insert amortization schedule in mysql in laravel

291 views Asked by At

I am using Laravel 5.7. I can create amortization schedule in Laravel view simply by using while loop in php.

Here is my code:

//empty value error handling

// GETTING USER INPUTS AND ASSIGNING THEM TO VARIABLES
$amount = 98000000;
$interest = 8;
$year = 30;
$term = 12;

//creating period
$period = $term * $year;

if ($amount < 0) {
    echo "<p class='error'>Amount Can't be a Negative Value</p>";
}else if ($interest < 0) {
    echo "<p class='error'>Interest Cant't be a Negative Value</p>";
}else if ($year < 0 || $year > 50) {
    echo "<p class='error'>Loan repayment Years 1-50</p>";
}else if ($term<0) {
    echo "<p class='error'>Payment Periods can't be Negative</p>";
}else{
    $i = 0;
    $inter = ($interest / 100) / $term;
    while ($period !=0) {
        // making percentage in $interest
        //Creating the Denominator
        $deno = 1 - 1/pow((1+$inter),$period);
        
        //Payment for a period
        $payment = ($amount * $inter) / $deno;

        //Interest for a Period
        $periodInter = $amount*$inter;

        //Principal for a Period
        $principal = $payment - $periodInter;

        //Getting the Balance 
        $balance = $amount - $principal;

But I don't know how insert this loop result with multiple rows to MySQL database via controller?

0

There are 0 answers