=str_to_date('" . $start_date . "','%d-%m-%Y') "; } if (isset($end_date) && $end_date != '') { $qry_date1 .= " and date(checkup_date) <=str_to_date('" . $end_date . "','%d-%m-%Y') "; } if (isset($month) && $month != '') { $qry_date1 .= " and month(checkup_date) in (" . $month . ")"; } $i = 0; $record = array(); if (isset($year) && $year != '' && sizeof($year1) > 1) { $designation_query = "select designation_id, designation_name from designation $qry_filter1"; $result_dept = mysqli_query($conn, $designation_query); $percentage_emp_per_dept = 0; $total = 0; while ($designation_row = mysqli_fetch_assoc($result_dept)) { for ($j = 0; $j < sizeof($year1); $j++) { $qry_date = ""; $qry_doj = ""; $qry_date .= " and year(checkup_date) ='" . $year1[$j] . "'"; $qry_doj .= " and year(doj) <= '" . $year1[$j] . "'"; $count_query = "select count(*) as total FROM patient_master where status = 'Active' and designation_id = '" . $designation_row['designation_id'] . "' $qry_filter $qry_doj"; $count_result = mysqli_query($conn, $count_query); error_log("count_query::" . $count_query); $row_count = mysqli_fetch_assoc($count_result); $count_health_index = "SELECT max(checkup_id),health_index from checkup_form where emp_id in (SELECT id FROM patient_master where designation_id = '" . $designation_row['designation_id'] . "' and status='Active' $qry_filter $qry_doj ORDER by id asc) $qry_date1 $qry_date GROUP by emp_id"; $health_index_result = mysqli_query($conn, $count_health_index); error_log("count_health_index::" . $count_health_index); $k = 0; $data = []; if (mysqli_num_rows($health_index_result)) { while ($row_health_index = mysqli_fetch_assoc($health_index_result)) { $data[$k] = $row_health_index['health_index']; $k++; } } $avg = 0; if (count($data)) { $avg = round(array_sum($data) / count($data), 2); } error_log("avg:" . $avg); $record[$designation_row['designation_name']][$year1[$j]]['health_index'] = $avg; } } } else { if (isset($year2) && $year2 != '') { $qry_date .= " and year(checkup_date) ='" . $year2 . "'"; $qry_filter .= " and year(doj) <= '" . $year2 . "'"; } $designation_query = "select designation_id, designation_name from designation $qry_filter1"; $result_dept = mysqli_query($conn, $designation_query); $total = 0; while ($designation_row = mysqli_fetch_assoc($result_dept)) { $count_query = "select count(*) as total FROM patient_master where status = 'Active' and designation_id = '" . $designation_row['designation_id'] . "' $qry_filter"; $count_result = mysqli_query($conn, $count_query); error_log("count_query::" . $count_query); if (mysqli_num_rows($count_result) > 0) { $row_count = mysqli_fetch_assoc($count_result); $record[$i]['key'] = $designation_row['designation_name']; $record[$i]['total'] = $row_count['total']; } $count_health_index = "SELECT max(checkup_id),health_index from checkup_form where emp_id in (SELECT id FROM patient_master where designation_id = '" . $designation_row['designation_id'] . "' and status='Active' $qry_filter ORDER by id asc) $qry_date1 $qry_date GROUP by emp_id"; $health_index_result = mysqli_query($conn, $count_health_index); error_log("count_health_index::" . $count_health_index); $j = 0; $data = []; if (mysqli_num_rows($health_index_result)) { while ($row_health_index = mysqli_fetch_assoc($health_index_result)) { $data[$j] = $row_health_index['health_index']; $j++; } } $avg = 0; if (count($data)) { $avg = round(array_sum($data) / count($data), 2); } error_log("avg:" . $avg); $record[$i]['health_index_total'] = $avg; $i++; } } echo json_encode($record);