booking/work/files/book/data_test.php

113 lines
4.0 KiB
PHP
Executable File

<?php
require_once('fixed/config/go_con.php');
$today = date("Y-m-d");
if (!empty($_GET['date'])) {
$today = $_GET['date'];
if (DateTime::createFromFormat('Y-m-d', $today) == false) {
$today = date("Y-m-d");
}
}
$data = array(
"status" => array(
"last_id" => 0
),
"2" => array(
"book_exceptions" => array(),
),
"3" => array(
"book_exceptions" => array(),
),
"4" => array(
"book_exceptions" => array(),
),
"5" => array(
"book_exceptions" => array(),
),
);
while (true) {
sleep(5);
$get_emplyee_sql = mysqli_query($db, "SELECT
`emplyee`.`id`,
`emplyee`.`name`,
`holi_days`.`day`,
`emplyee`.`branch_id`
FROM `occupation`
LEFT JOIN `emplyee` ON `emplyee`.`occupation_id` = `occupation`.`id`
LEFT JOIN `branch` ON `emplyee`.`branch_id` = `branch`.`id`
LEFT JOIN `holi_days` ON `emplyee`.`holi_days_id` = `holi_days`.`id`
LEFT JOIN `table_postion` ON `emplyee`.`id` = `table_postion`.`emplyee_id`
WHERE `occupation`.`show_in_table_id` = 2
AND `emplyee`.`activation_id` = 2
ORDER BY -`table_postion`.`postion` DESC, `emplyee`.`id` ASC
");
while ($get_emplyee = mysqli_fetch_assoc($get_emplyee_sql)) {
$data[$get_emplyee['branch_id']]['workers'][$get_emplyee['id']] = array(
"emp_s" => array(
"name" => $get_emplyee['name'],
"holi_days" => $get_emplyee['day']
),
"emp_books" => array()
);
}
$get_MAX_id_sql = mysqli_query($db, "SELECT
MAX(`bd`.`id`) AS `m_id`
FROM `book_details` AS `bd`
");
while ($get_MAX_id = mysqli_fetch_assoc($get_MAX_id_sql)) {
$data['status']['last_id'] = $get_MAX_id['m_id'];
}
$get_data_book_sql = 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`.`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`.`status_id` NOT IN (25,26)
AND `bd`.`id` IN (SELECT MAX(`book_details`.`id`)
FROM `book_details`
WHERE `book_details`.`book_id` = `bd`.`book_id`
GROUP BY `book_details`.`book_id`
)
ORDER BY `bd`.`day_time`, `bd`.`date_time`
");
while ($get_data_book = mysqli_fetch_assoc($get_data_book_sql)) {
if (array_key_exists($get_data_book['emplyee_id'], $data[$get_data_book['branch_id']]['workers'])) {
array_push($data[$get_data_book['branch_id']]['workers'][$get_data_book['emplyee_id']]['emp_books'], $get_data_book);
} else {
array_push($data[$get_data_book['branch_id']]['book_exceptions'], $get_data_book);
}
}
$myfile = fopen("file_test.json", "w") or die("Unable to open file!");
$json = json_encode($data);
fwrite($myfile, $json);
fclose($myfile);
}