60 lines
2.1 KiB
PHP
60 lines
2.1 KiB
PHP
<?php
|
|
include('includes/config/config.php');
|
|
$xaxis = array();
|
|
|
|
$date = date("Y-m-d");
|
|
|
|
$default_start_date = date('Y-m-d', strtotime($date . ' -7 days'));
|
|
|
|
$default_end_date = date('Y-m-d', strtotime($date));
|
|
|
|
error_log("date ." . $default_start_date . " " . $default_end_date);
|
|
|
|
if (!empty($_POST['start_date'])) {
|
|
$default_start_date = date('Y-m-d', strtotime($_POST['start_date']));
|
|
}
|
|
if (!empty($_POST['end_date'])) {
|
|
$default_end_date = date('Y-m-d', strtotime($_POST['end_date']));
|
|
}
|
|
|
|
error_log("date after filter ." . $default_start_date . " " . $default_end_date);
|
|
|
|
$total_injury_class_name = array();
|
|
$total_injury_class = array();
|
|
|
|
$sql = "select * from injury_class";
|
|
$result = mysqli_query($conn, $sql);
|
|
while ($row = mysqli_fetch_assoc($result)) {
|
|
array_push($total_injury_class_name, '"' . $row['inj_class_name'] . '"');
|
|
array_push($total_injury_class, $row['inj_class_id']);
|
|
}
|
|
|
|
error_log("total injury " . print_r($total_injury_class, true));
|
|
|
|
$injury_data = array();
|
|
$date_data = array();
|
|
for ($i = 0; $i < sizeof($total_injury_class); $i++) {
|
|
$query = "select count(appointment_id) from employee_appointment where date(appointment_date) >= '" . $default_start_date . "' and date(appointment_date) <= '" . $default_end_date . "' and injury_classes_new ='" . $total_injury_class[$i] . "' or injury_classes_new like '%," . $total_injury_class[$i] . "' or injury_classes_new like '" . $total_injury_class[$i] . ",%' or injury_classes_new like '%," . $total_injury_class[$i] . ",%' ";
|
|
error_log(" injury query " . $query);
|
|
|
|
if (!$result = @mysqli_query($conn, $query)) {
|
|
error_log("error in injury chart" . mysqli_error($conn));
|
|
exit();
|
|
}
|
|
if (mysqli_num_rows($result) > 0) {
|
|
while ($row = @mysqli_fetch_array($result)) {
|
|
array_push($injury_data, $row[0]);
|
|
// array_push($date_data, $row[1]);
|
|
}
|
|
} else {
|
|
array_push($injury_data, 0);
|
|
}
|
|
}
|
|
error_log("injury data trend " . print_r($injury_data, true));
|
|
$data = array(
|
|
'injury_data' => ($injury_data),
|
|
'injury_class_name' => ($total_injury_class_name),
|
|
);
|
|
|
|
echo json_encode($data);
|