<?php
include("dbConfig.php");

$taked_dates = array();
$mm = array();

$sql_taked = "SELECT * FROM hr_takeed_hodor_ensraf_tbl WHERE employ_id='284641'";
$result_taked = $conn->query($sql_taked);

if ($result_taked->num_rows > 0) {
    while ($row_taked = $result_taked->fetch_assoc()) {
        $begin = new DateTime($row_taked["date_from"]);
        $end = new DateTime($row_taked["date_to"]);
        $end->modify('+1 day');
        $daterange = new DatePeriod($begin, new DateInterval('P1D'), $end);

        foreach ($daterange as $date) {
            array_push($taked_dates, $date->format("Y-m-d"));
        }
    }
}

$ids_datess = "'" . join("','", $taked_dates) . "'";
$shift_ids = array();

$sql_takedd = "SELECT * FROM hr_takeed_hodor_ensraf_tbl WHERE employ_id='284641' AND (date_from IN ($ids_datess) OR date_to IN ($ids_datess))";
$result_takedd = $conn->query($sql_takedd);

if ($result_takedd->num_rows > 0) {
    while ($row_takedd = $result_takedd->fetch_assoc()) {
        $shift_id = $row_takedd["shift_id"];
        $date_from = $row_takedd["date_from"];
        $date_to = $row_takedd["date_to"];
        $sum_salary = $row_takedd["sum_salary"];

        $begin = new DateTime($date_from);
        $end = new DateTime($date_to);
        $end->modify('+1 day');
        $daterange = new DatePeriod($begin, new DateInterval('P1D'), $end);

        foreach ($daterange as $date) {
            echo $shift_id . "/" . $date->format("Y-m-d") . "</br>";
        

        $sql_sh = "SELECT * FROM hr_shift_tbl WHERE shift_id='$shift_id' AND stop='0' AND deleted='0'";
        $result_sh = $conn->query($sql_sh);

        if ($result_sh->num_rows > 0) {
            while ($row_sh = $result_sh->fetch_assoc()) {
                if ($lang == 'ar') {
                    $shift_name = $row_sh['shift_name_ar'];
                } else {
                    $shift_name = $row_sh['shift_name_en'];
                }
                echo $shift_name;
                $min_start_time = $row_sh['min_start_time'];
                $start_time = $row_sh['start_time'];
                $max_start_time1 = $row_sh['max_start_time'];
                $allowed_minutes = $row_sh['allowed_minutes'];
                $ddate = strtotime("+$allowed_minutes minutes", strtotime($max_start_time1));
                $max_start_time = date('h:i', $ddate);
                $min_end_time = $row_sh['min_end_time'];
                $end_time = $row_sh['end_time'];
                $max_end_time = $row_sh['max_end_time'];
                $number_hours = $row_sh['number_hours_calculated'];
                $number_hours1 += $row_sh['number_hours_calculated'];
                $num_hour_init = ($number_hours * 60);
                $num_hoursinit = floor($num_hour_init / 60) . '.' . ($num_hour_init - floor($num_hour_init / 60) * 60);
                $num_hoursvinit = (float) $num_hoursinit;

                if ($num_hoursvinit != 0) {
                    $salary_minut1 = (($sum_salary / 30) / $number_hours) / 60;
                    $salary_minut = $salary_minut + ((($sum_salary / 30) / $number_hours) / 60);
                }

                $sat = $row_sh['sat'];
                $sun = $row_sh['sun'];
                $mon = $row_sh['mon'];
                $tue = $row_sh['tue'];
                $we = $row_sh['we'];
                $thu = $row_sh['thu'];
                $fr = $row_sh['fr'];

                $flexible_working = $row_sh['flexible_working'];
                $hodoor_ghyab = $row_sh['hodoor_ghyab'];
            }
        }
    }
}
}
?>