<?php
require_once('table-traits.php');
require_once('basic-function.php');
class interest extends basicFunction 
{
    use table_names;

    public function adder()
    {
        $packages = $this->selectAllDlt($this->package_tb);
        if(count($packages) < 1){
            return;
        }

        foreach ($packages as $e_package ) {
            $investments = $this->selectWhere2CondDlt($this->transaction_tb,'status','confirmed','plan_id',$e_package['unique_id']);
            if(count($investments) > 0){

                foreach ($investments as $e_investment ) {
                    if($e_investment['day_counter'] <= $e_package['no_of_days']){
                        // print_r($e_investment);return;

                        $day_interest = ($e_investment['amt_in_usd'] /100) * $e_package['daily_percentage'];
                        $main_interest = $e_investment['interest_in_usd'] + $day_interest;
                        $current_counter = $e_investment['day_counter']+1;
                        $fields = ['interest_in_usd','day_counter'];
                        $values = [$main_interest,$current_counter];
                        $update_interest = $this->update_tbs( $this->transaction_tb,$fields,$values,$e_investment['unique_id']);
                        if($update_interest['error'] == 1){
                            return $update_interest;
                        }
                    }
                }
            }
        }
    }
    
}
$interest = new interest();
$interest->adder();