<?php
require_once "../config.php";
require_once "../mail/sendMail.php";

// $today_date = date("Y-m");
// $q = mysqli_query($db,"SELECT t1.employee_id, t2.name as l_name, t2.email as l_email, t1.name as e_name, t1.email as e_email, t1.dob, t1.joining_date, t1.probation_date FROM users t1, users t2 WHERE t1.leader=t2.employee_id and (COALESCE(t1.working_status_date,'')='' or DATE_FORMAT(STR_TO_DATE(t1.working_status_date, '%Y-%m-%d'),'%Y-%m')>='$today_date') ORDER BY e_name asc");

$today_date = date("Y-m-d");
// $q = mysqli_query($db,"SELECT t1.employee_id, t2.name as l_name, t2.email as l_email, t1.name as e_name, t1.email as e_email, t1.dob, t1.joining_date, t1.probation_date FROM users t1, users t2 WHERE t1.leader=t2.employee_id and (COALESCE(t1.working_status_date,'')='' or STR_TO_DATE(t1.working_status_date, '%Y-%m-%d')>='$today_date') ORDER BY e_name asc");
$q = mysqli_query($db,"SELECT t1.employee_id, t2.name as l_name, t2.email as l_email, t1.name as e_name, t1.email as e_email, t1.dob, t1.joining_date, t1.probation_date, t1.working_status_date FROM users t1, users t2 WHERE t1.leader=t2.employee_id ORDER BY e_name asc");

$today = date("d-m");
// echo $today;
while($row = mysqli_fetch_assoc($q)){

    $dob = date("d-m",strtotime($row['dob']));
    $joining_date = date("d-m",strtotime($row['joining_date']));
    $probation_date = date("d-m",strtotime($row['probation_date']));


    // Birthday Mail
    if(!empty($row['dob']) && $today==$dob){
        birthday($row);
    }

    // and (COALESCE(t1.working_status_date,'')='' or STR_TO_DATE(t1.working_status_date, '%Y-%m-%d')>='$today_date')
    if(empty($row['working_status_date']) || date("Y-m-d", strtotime($row['working_status_date']))==$today_date){
        
        // year completion
        if(!empty($row['joining_date']) && $today==$joining_date){
            yearComplete($row);
        }
        // probation
        if(!empty($row['probation_date']) && $today==$probation_date){
            probation($row);
        }

    }

}

?>