<?php

include 'includes/conn.php'; 

/*$currentDate = new DateTime();  
$currentDate->add(new DateInterval('P1Y'));  // Add 1 year to the current date

$newDate = $currentDate->format('Y-m-d');  // Format the resulting date as YYYY-MM-DD*/
$currentDates = date('Y-m-d');


$select_query = "SELECT * FROM users WHERE status='Active'";
$result = $conn->query($select_query);
$row = $result->fetch_assoc();
        $mfs_return_date = $row['mfs_return_date'];

        if ($mfs_return_date == $currentDates) {
            echo '<script type="text/javascript">

            window.onload = function () { alert("Already Added!!!"); 
            window.location.href = "home.php"; 
   }

			</script>';
        } else {
            $user_update = "UPDATE users SET mfs_return = mfs_return + 10, mfs_return_date = '$currentDates' WHERE status = 'Active'";
            if (mysqli_query($conn, $user_update)) {
                
                $return_history="INSERT INTO mfs_return_history(username,date) VALUES('0','$currentDates')";
                 if (mysqli_query($conn, $return_history)) {
                
                  echo '<script type="text/javascript">

            window.onload = function () { alert("Daily Profit added!!!"); 
            window.location.href = "home.php"; 
   }

            </script>';
             
            }
            }
        }
    



?>