Your IP : 216.73.216.26


Current Path : /home2/wtmwscom/www/admin/images/
Upload File :
Current File : /home2/wtmwscom/www/admin/images/test_2.php

<?php
include '../../connection.php';
include '../../function_lib.php';

$start_date = date('2018-09-19');
$no_of_days=1;
$start_date_obj = new DateTime($start_date);
  $end_date =     '2018-11-01'; 
while(true){
     $start_date_obj->modify("+ 1 day");
     
     $date =  $start_date_obj->format('Y-m-d');
     $datetime = $date." 23:59:59";
    
     //code goes here begin

//$datetime = date('Y-m-d H:i:s');
//$date = date('Y-m-d');
$today_datetime = new DateTime($date);
//$income_rate_array = array(0 => 0, 1 => 1, 2 => 1, 3 => 1, 4 => 1, 5 => 1, 6 => 1, 7 => 1, 8 => 1, 9 => 1);
//$income_rate_by_type_array = array(0 => 1, 1 => 1.2, 2 => 1.2,);

//$today_day = date('l');
//$today_day = date('l', strtotime('tomorrow'));
//echo "today day ".$today_day;
//$counter=0;
//if ($today_day == "Monday" || $today_day == "Tuesday" || $today_day == "Wednesday" || $today_day == "Thursday" || $today_day == "Friday") {
    $result = mysqli_query($connection, "SELECT t1.id as product_sale_id, t1.amount as amount, date(t1.datetime) as topup_date, t2.uid as uid, t2.plan_type as plan_type, t2.type AS type FROM referral_matching t1 INNER JOIN user t2 ON t1.uid = t2.uid WHERE t2.status = 0 AND t2.is_paid=1  AND DATE(t1.datetime) <= '$date' ");
    while ($row_user = mysqli_fetch_object($result)) {

        $uid = $row_user->uid;
        

         
            $is_growth = FALSE;
        $sql_invest = "SELECT id, DATE(datetime) as create_date FROM `invest_growth` WHERE `uid`='$uid' AND `product_sale_id` ='$row_user->product_sale_id' ORDER BY `id` DESC LIMIT 1 ";    
        //echo $sql_invest;
        $result_invest_growth = mysqli_query($connection, $sql_invest);
        if(mysqli_num_rows($result_invest_growth) == 0){
            // if type_update_date > topup_date then create date = type_update_date else  topup_date
            $create_date = new DateTime( $row_user->topup_date);
            //echo "create date: ".$create_date->format('Y-m-d'). " | ";
            //$create_date = new DateTime($row->topup_date);
        } else{
            $growth_row = mysqli_fetch_object($result_invest_growth);
            $create_date = new DateTime($growth_row->create_date);
        }
       $differece_in_day = $today_datetime->diff($create_date)->format("%a");
       //echo "uid: $uid | differece_in_day: $differece_in_day <br/>";
       if($differece_in_day >= 7){
           $is_growth = TRUE;
       }
        if ($is_growth) {
            $amount = ($row_user->amount * 15) / 100;
            if($amount){
               mysqli_query($connection, "INSERT INTO `invest_growth` (`uid`, `product_sale_id`, `amount`, `datetime`, `status`) VALUES "
                    . "('$uid', '$row_user->product_sale_id', '$amount', '$datetime', '0')");
            mysqli_query($connection, "INSERT INTO `income` (`uid`, `amount`, `income_type`, `datetime`, `status`) VALUES "
                    . "('$uid', '$amount', '7', '" . $datetime . "', '0');"); 
            }
            
        }
    }
//}

//echo " counter = $counter ";
//if (count($income_id_array) > 0) {
//    mysqli_query($connection, "UPDATE income SET status = 1, closing_date = '$date' WHERE id IN ( " . implode(", ", $income_id_array) . " )");
//}
     
    //code ends here





$no_of_days++;
if($date == $end_date){
    break;
}
}
echo "no of days =====================".$no_of_days;
?>