=str_to_date('" . $start_date . "','%d-%m-%Y') "; } if (isset($end_date) && $end_date != '') { $qry_date1 .= " and date(doj) <=str_to_date('" . $end_date . "','%d-%m-%Y') "; } if (isset($month) && $month != '') { $qry_date1 .= " and month(doj) in (" . $month . ")"; } $i = 0; $record = array(); if (isset($year) && $year != '' && sizeof($year1) > 1) { $dept_query = "select designation_id, designation_name from designation $qry_filter1"; $result_dept = mysqli_query($conn, $dept_query); $percentage_emp_per_dept = 0; $total = 0; while ($dept_row = mysqli_fetch_assoc($result_dept)) { for ($j = 0; $j < sizeof($year1); $j++) { $qry_date = ""; $qry_date .= " and year(doj) <='" . $year1[$j] . "'"; $count_query = "select count(*) as total FROM patient_master where status = 'Active' and designation_id = '" . $dept_row['designation_id'] . "' $qry_filter $qry_date"; $count_result = mysqli_query($conn, $count_query); error_log("count_query::" . $count_query); $row_count = mysqli_fetch_assoc($count_result); $total_emp = "select count(*) as total_emp from patient_master where status='Active' $qry_filter $qry_date"; $total_count_result = mysqli_query($conn, $total_emp); error_log("total count query: " . $total_emp); $row_total_count = mysqli_fetch_assoc($total_count_result); $emp_sum = $row_total_count['total_emp']; $percentage_emp_per_dept = ($row_count['total'] / $emp_sum) * 100; error_log("per desg wise dis:".$percentage_emp_per_dept); $record[$dept_row['designation_name']][$year1[$j]]['per'] = round($percentage_emp_per_dept, 2); } } } else { if (isset($year2) && $year2 != '') { $qry_filter .= " and year(doj) <='" . $year2 . "'"; } $dept_query = "select designation_id, designation_name from designation $qry_filter1"; $result_dept = mysqli_query($conn, $dept_query); $total = 0; while ($dept_row = mysqli_fetch_assoc($result_dept)) { $count_query = "select count(*) as total FROM patient_master where status = 'Active' and designation_id = '" . $dept_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); if ($row_count['total'] > 0) { $record[$i]['key'] = $dept_row['designation_name']; $record[$i]['total'] = $row_count['total']; $i++; } } } // $total_emp = "select count(*) as total_emp from patient_master where status='Active' $qry_filter"; // $total_count_result = mysqli_query($conn, $total_emp); // error_log("total count query: " . $total_emp); // if (mysqli_num_rows($total_count_result) > 0) { // $row_total_count = mysqli_fetch_assoc($total_count_result); // $record['total_emp'] = $row_total_count['total_emp']; // } } echo json_encode($record);