Click here to Skip to main content
15,074,394 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
2010 Total amount 200
2011 interest amount + last amount
2021 todays amount = interest + last amount

What I have tried:

latestDbAmount = $latestCurrentAmount->current_amount;
            $nowDate = Carbon::now();

            $noOfDays = $nowDate->diffInDays($latestDbDate);
            $noOfYears = $nowDate->diffInYears($latestDbDate);
            $noOfMonths = $nowDate->diffInMonths($latestDbDate);
            $gained_interest =  $latestDbAmount*($data->interest_rate**($noOfDays/365));

        //    if($noOfDays > 1){
        //         $comment = "Today's Total";
        //         DB::table('finances')->insert([
        //         'customer_id' => $data->customer_id,
        //         'country' => $data->country,
        //         'date' => Carbon::now('America/Los_Angeles')->toDateTimeString(),
        //         'current_amount' => $gained_interest,
        //         'comments' => $comment,
        //         'gained_interest' => $gained_interest-$latestDbAmount,
        //         ]);
        //     }    
Posted
Updated 12-Jul-21 7:55am
Comments
Richard Deeming 13-Jul-21 5:07am
   
That's generally not how interest is calculated. It will normally be compounded either annually, monthly, or daily.

Eg: Given 10% compounded annually on an initial principal of 100, with no payments made, the amount due at the end of year one will be 110; at the end of year two, it will be 121; by year three, 133.10; etc.

In other words, you need to remember to charge interest on the interest as well as the initial principal.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900