'$today' AND `work_time_table`.`from_date_time` < '$Next' AND `work_time_table`.`activation_id` = 2");
$time_work = array();
while ($get_time_work = mysqli_fetch_assoc($get_emplyee_time_work)) {
$from = $get_time_work['fromTime'][0] . $get_time_work['fromTime'][1];
$to = $get_time_work['toTime'][0] . $get_time_work['toTime'][1];
for ($from; $from <= $to; $from++) {
$push_time_work = $from . ":00:00";
array_push($time_work, $push_time_work);
}
}
$get_tretment_details_sql_state = mysqli_query($db,
"SELECT
`bd`.`day_date`,
`bd`.`day_time`,
`bd`.`branch_id`,
`bd`.`emplyee_id`,
`bd`.`status_id`,
`bd`.`date_time`,
`bd`.`book_id`,
`services`.`name`,
`book`.`id` AS `mom`,
`book`.`tretment_id`,
`book`.`notes`,
`book`.`date_time` AS `user_date`,
`user`.`name` AS `user_book`,
`tretment`.`name` AS `tr_name`,
`tretment`.`number`
FROM `book_details` AS `bd`
LEFT JOIN `book` ON `bd`.`book_id` = `book`.`id`
LEFT JOIN `tretment` ON `book`.`tretment_id` = `tretment`.`id`
LEFT JOIN `user` ON `book`.`user_id` = `user`.`id`
LEFT JOIN `services` ON `bd`.`services_id` = `services`.`id`
LEFT JOIN `emplyee` ON `bd`.`emplyee_id` = `emplyee`.`id`
WHERE `emplyee`.`activation_id`=2
AND `bd`.`day_date`='$today'
AND (`bd`.`day_time` >= '$start_today_time_sql' AND `bd`.`day_time` <= '$end_today_time_sql')
AND `bd`.`emplyee_id`='$emp_id'
AND `bd`.$branch_sql
AND `bd`.`status_id` != 25
AND `bd`.`id` IN (SELECT MAX(`book_details`.`id`)
FROM `book_details`
WHERE `book_details`.`book_id` = `bd`.`book_id` -- must make all like that
GROUP BY `book_details`.`book_id`
)
GROUP BY `bd`.`day_time`
ORDER BY `bd`.`day_time`, `bd`.`date_time`
");
$tretment_details_state_temp = array();
while ($get_tretment_details_state = mysqli_fetch_assoc($get_tretment_details_sql_state)) {
array_push($tretment_details_state, $get_tretment_details_state);
array_push($tretment_details_state_temp, $get_tretment_details_state);
}
$get_table_sql_state = mysqli_query($db,
"SELECT
`user`.`id`,
`user`.`name`,
`table`.`day_date`,
`table`.`day_time`,
`table`.`notes`,
`table`.`branch_id`,
`table`.`emplyee_id`,
`table`.`status_id`,
`table`.`date_time` AS `time`
FROM `table`
LEFT JOIN `user` ON `user`.`id` = `table`.`user_id`
WHERE `table`.`day_date` = '$today'
AND (`table`.`day_time` >= '$start_today_time_sql' AND `table`.`day_time` <= '$end_today_time_sql')
AND `table`.$branch_sql AND `table`.`emplyee_id` = '$emp_id'
AND `table`.`id` IN (SELECT MAX(`tb`.`id`) FROM `table` AS `tb` WHERE `tb`.`day_date` = '$today'
AND `tb`.`emplyee_id` = '$emp_id' GROUP BY `tb`.`day_time`)
ORDER BY `table`.`day_time` ASC"
);
$open_close_temp = array();
while ($get_table_state = mysqli_fetch_assoc($get_table_sql_state)) {
array_push($open_close_temp, $get_table_state);
}
if ($end_today_time > 23) { // greter than 24 hour
$end_today_time_sql = "23:59:59";
$how_many_left = ($end_today_time - 23) - 1 . ":59:59";
$get_tretment_details_sql_state2 = mysqli_query($db,
"SELECT
`bd`.`day_date`,
`bd`.`day_time`,
`bd`.`branch_id`,
`bd`.`emplyee_id`,
`bd`.`status_id`,
`bd`.`date_time`,
`bd`.`book_id`,
`services`.`name`,
`book`.`id` AS `mom`,
`book`.`tretment_id`,
`book`.`notes`,
`book`.`date_time` AS `user_date`,
`user`.`name` AS `user_book`,
`tretment`.`name` AS `tr_name`,
`tretment`.`number`
FROM `book_details` AS `bd`
LEFT JOIN `book` ON `bd`.`book_id` = `book`.`id`
LEFT JOIN `tretment` ON `book`.`tretment_id` = `tretment`.`id`
LEFT JOIN `user` ON `book`.`user_id` = `user`.`id`
LEFT JOIN `services` ON `bd`.`services_id` = `services`.`id`
LEFT JOIN `emplyee` ON `bd`.`emplyee_id` = `emplyee`.`id`
WHERE `emplyee`.`activation_id`=2
AND `bd`.`day_date` = '$Next'
AND `bd`.`day_time` <= '$how_many_left'
AND `bd`.`emplyee_id`='$emp_id'
AND `bd`.$branch_sql
AND `bd`.`status_id` != 25
AND `bd`.`id` IN (SELECT MAX(`book_details`.`id`) FROM `book_details` GROUP BY `book_details`.`book_id`)
GROUP BY `bd`.`day_time`
ORDER BY `bd`.`day_time`, `bd`.`date_time`
");
while ($get_tretment_details_state2 = mysqli_fetch_assoc($get_tretment_details_sql_state2)) {
array_push($tretment_details_state, $get_tretment_details_state2);
array_push($tretment_details_state_temp, $get_tretment_details_state2);
}
$get_table_sql_state2 = mysqli_query($db,
"SELECT
`user`.`id`,
`user`.`name`,
`table`.`day_date`,
`table`.`day_time`,
`table`.`notes`,
`table`.`branch_id`,
`table`.`emplyee_id`,
`table`.`status_id`,
`table`.`date_time` AS `time`
FROM `table`
LEFT JOIN `user` ON `user`.`id` = `table`.`user_id`
WHERE `table`.`day_date` = '$Next'
AND `table`.`day_time` <= '$how_many_left'
AND `table`.$branch_sql
AND `table`.`emplyee_id` = '$emp_id'
AND `table`.`id` IN (SELECT MAX(`tb`.`id`) FROM `table` AS `tb` WHERE `tb`.`day_date` = '$Next'
AND `tb`.`emplyee_id` = '$emp_id' GROUP BY `tb`.`day_time`)
ORDER BY `table`.`day_time` ASC"
);
while ($get_table_state2 = mysqli_fetch_assoc($get_table_sql_state2)) {
array_push($open_close_temp, $get_table_state2);
}
}
$branch_id = $get_emplyee['branch_id'];
$open_close_count= 0;
$temp_count = 0;
for ($start_today_time; $start_today_time <= $end_today_time; $start_today_time++) {
$restart_temp = $start_today_time;
if ($start_today_time > 23) {
$restart_temp = $start_today_time - 24;
}
if ($restart_temp < 10) {
$start_today_time_temp = "0" . $restart_temp . ":00:00";
} else {
$start_today_time_temp = $restart_temp . ":00:00";
}
$today_temp = $today;
if ($start_today_time > 23) {
$today_temp = $Next;
}
if (($tretment_details_state_temp[$temp_count]['day_time']) == ($start_today_time_temp) && $tretment_details_state_temp[$temp_count]['emplyee_id'] == $emp_id) {
switch ($tretment_details_state_temp[$temp_count]['status_id']) {
case 4: case 5:
// انتظار
?>