<?php include('../../../includes/config.php');
$title = "View IPD Reports";
isAdminLoggedIn();
ini_set('max_execution_time', 18000);
$ipd_name = isset($_GET['ipd_name'])?trim($_GET['ipd_name']):'';
$opd_no = isset($_GET['opd_no'])?trim($_GET['opd_no']):'';
$ipd_no = isset($_GET['ipd_no'])?trim($_GET['ipd_no']):'';
$department_id_fk = isset($_GET['department_id_fk'])?trim($_GET['department_id_fk']):'';
$opd_gender = isset($_GET['opd_gender'])?trim($_GET['opd_gender']):'';
$ipd_admit_date = isset($_GET['ipd_admit_date'])?trim($_GET['ipd_admit_date']):'';
$ipd_discharge_date = isset($_GET['ipd_discharge_date'])?trim($_GET['ipd_discharge_date']):'';
$ipd_month_wise = isset($_GET['ipd_month_wise'])?trim($_GET['ipd_month_wise']):'';
$ipd_bed_word = isset($_GET['ipd_bed_word'])?trim($_GET['ipd_bed_word']):'';
$ipd_bednumber = isset($_GET['ipd_bednumber'])?trim($_GET['ipd_bednumber']):'';
$ipd_bed_realse = isset($_GET['ipd_bed_realse'])?trim($_GET['ipd_bed_realse']):'';

$report_start_date = isset($_GET['report_start_date'])?trim($_GET['report_start_date']):'';
$report_end_date = isset($_GET['report_end_date'])?trim($_GET['report_end_date']):'';

$reportview = isset($_GET['reportview'])?trim($_GET['reportview']):'';
if($ipd_month_wise!=''){
    $select_all_standard_and_stream = 'select 
    ipddetails.ipd_no,
    ipddetails.ipd_admit_date,
    ipddetails.ipd_discharge_date,    
    ipddetails.ipd_bednumber,
    ipddetails.ipd_bed_word,
    ipddetails.ipd_entry_doctor,
    ipddetails.ipd_id_pk,
    ipddetails.ipd_total_bed_occupiday,
    dept.department_name as departmentname,  
    diagnosis.diagnosis_name as diagnosisname,
    opd.opd_no as opd_no,
    opd.opd_reffer_doctor as ipd_refferdoctor_name,    
    opd.opd_name as ipd_name,
    opd.opd_address as ipd_address,
    opd.opd_age as ipd_age,
    opd.opd_gender as ipd_gender,
    opd.opd_religion as ipd_religion
    from hp_ipd as ipddetails ';
    $select_all_standard_and_stream .=' LEFT JOIN hp_department as dept on ipddetails.ipd_bed_department=dept.department_id ';
    $select_all_standard_and_stream .=' LEFT JOIN hp_ipd_other_details as other on ipddetails.ipd_no=other.ipd_no';
    $select_all_standard_and_stream .=' LEFT JOIN hp_diagnosis as diagnosis on other.ipd_diagnosis=diagnosis.diagnosis_id ';
    $select_all_standard_and_stream .=' LEFT JOIN hp_opd as opd on ipddetails.opd_id_fk=opd.opd_id';
    $select_all_standard_and_stream .=' where ipddetails.ipd_is_delete=0';
    $select_all_standard_and_stream .=" and other.ipd_date between '".date('Y').'-'.$ipd_month_wise.'-1'."' and '".date('Y').'-'.$ipd_month_wise.'-31'."'";
    $select_all_standard_and_stream .=" Group by other.ipd_no order by ipddetails.ipd_id_pk ASC";
    $row = $db->selectAll($select_all_standard_and_stream); 
    
}else{
    $select_all_standard_and_stream = 'select 
    ipddetails.ipd_no,
    ipddetails.ipd_admit_date,
    ipddetails.ipd_discharge_date,    
    ipddetails.ipd_bednumber,
    ipddetails.ipd_bed_word,
    ipddetails.ipd_entry_doctor,
    ipddetails.ipd_id_pk,
    ipddetails.ipd_total_bed_occupiday,
    dept.department_name as departmentname,  
    diagnosis.diagnosis_name as diagnosisname,
    opd.opd_no as opd_no,
    opd.opd_reffer_doctor as ipd_refferdoctor_name,    
    opd.opd_name as ipd_name,
    opd.opd_address as ipd_address,
    opd.opd_age as ipd_age,
    opd.opd_gender as ipd_gender,
    opd.opd_religion as ipd_religion
    from hp_ipd as ipddetails ';
    $select_all_standard_and_stream .=' LEFT JOIN hp_department as dept on ipddetails.ipd_bed_department=dept.department_id ';
    $select_all_standard_and_stream .=' LEFT JOIN hp_ipd_other_details as other on ipddetails.ipd_no=other.ipd_no';
    $select_all_standard_and_stream .=' LEFT JOIN hp_diagnosis as diagnosis on other.ipd_diagnosis=diagnosis.diagnosis_id ';
    $select_all_standard_and_stream .=' LEFT JOIN hp_opd as opd on ipddetails.opd_id_fk=opd.opd_id';
    $select_all_standard_and_stream .= " where ipddetails.ipd_is_delete=0";
    if($ipd_name!=''){
        $select_all_standard_and_stream .= " and opd.opd_name like ' %".$ipd_name."%'";
    }
    if($opd_no!=''){
        $select_all_standard_and_stream .= " and opd.opd_no ='".$opd_no."'";
    }
    if($ipd_no!=''){
        $select_all_standard_and_stream .=" and ipddetails.ipd_no='".$ipd_no."'";
    }
    if($department_id_fk!=''){
        $select_all_standard_and_stream .=" and ipddetails.ipd_bed_department='".$department_id_fk."'";
    }
    if($opd_gender!=''){
        $select_all_standard_and_stream .=" and opd.opd_gender='".$opd_gender."'";
    }
    if($ipd_admit_date!=''){
        $select_all_standard_and_stream .=" and ipddetails.ipd_admit_date='".$ipd_admit_date."'";
    }
    if($ipd_discharge_date!=''){
        $select_all_standard_and_stream .=" and ipddetails.ipd_discharge_date='".$ipd_discharge_date."'";
    }
    if($ipd_bed_word!=''){
        $select_all_standard_and_stream .= " and ipddetails.ipd_bed_word like ' %".$ipd_bed_word."%'";
    }
    if($ipd_bednumber!=''){
        $select_all_standard_and_stream .=" and ipddetails.ipd_bednumber='".$ipd_bednumber."'";
    }
    if($ipd_bed_realse!=''){
        $select_all_standard_and_stream .=" and ipddetails.ipd_bed_realse='".$ipd_bed_realse."'";
    }
    if($report_start_date!='' and $report_end_date!=''){
        // $select_all_standard_and_stream .=" and other.ipddate ='".$report_start_date."'";
        $select_all_standard_and_stream .=" and  other.ipd_date between'".$report_start_date."' and '".$report_end_date."'";
       
    }
     $select_all_standard_and_stream .=" Group by other.ipd_no";
    //echo $select_all_standard_and_stream;
    $select_all_standard_and_stream .=" order by ipddetails.ipd_id_pk ASC";
    $row = $db->selectAll($select_all_standard_and_stream);
}

if($department_id_fk!=''){
    $report_title =getdepartmentname($department_id_fk)." IPD REGISTER";
}else{
    $report_title = " CENTRAL IPD REGISTER";
}
if(!empty($row)) {
    if($reportview=="View Report"){
        require_once('tcpdf_include.php');
        class MYPDF extends TCPDF {

            //Page header
            public function Header() {
               
            }

            // Page footer
            public function Footer() {
                // Position at 15 mm from bottom
                $this->SetY(-15);
                // Set font
                $this->SetFont('helvetica', '', 8);
                // Page number infinitylogo.png
                
                
                $this->Cell(0, 10,'  Print On:   '.date('d-M-y h:i:s A').'', 0, false, 'L', 0, '', 0, false, 'T', 'M');
                $this->Cell(0, 10, 'Page '.$this->getAliasNumPage().' of '.$this->getAliasNbPages(), 0, false, 'R', 0, '', 0, false, 'T', 'M');
            }
            public function ColoredTable($header,$data) {
                // Colors, line width and bold font
                $this->SetFillColor(128,128,128);
                $this->SetTextColor(255);
                
                $this->SetLineWidth(0.3);
                $this->SetFont('', 'B');
                // Header
                $w = array(40, 35, 40, 45);
                $num_headers = count($header);
                for($i = 0; $i < $num_headers; ++$i) {
                    $this->Cell($w[$i], 7, $header[$i], 1, 0, 'C', 1);
                }
                $this->Ln();
                // Color and font restoration
                $this->SetFillColor(224, 235, 255);
                $this->SetTextColor(0);
                $this->SetFont('');
                // Data
                $fill = 0;
                foreach($data as $row) {
                    $this->Cell($w[0], 6, $row[0], 'LR', 0, 'L', $fill);
                    $this->Cell($w[1], 6, $row[1], 'LR', 0, 'L', $fill);
                    $this->Cell($w[2], 6, $row[2], 'LR', 0, 'R', $fill);
                    $this->Cell($w[3], 6, $row[3], 'LR', 0, 'R', $fill);
                    $this->Ln();
                    $fill=!$fill;
                }
                $this->Cell(array_sum($w), 0, '', 'T');
            }
            function plot_table($widths, $lineheight, $table, $border=1, $aligns=array(), $fills=array(), $links=array()){
                $func = function($text, $c_width){
                    $len=strlen($text);
                    $twidth = $this->GetStringWidth($text);
                    $split = floor($c_width * $len / $twidth);
                    $w_text = explode( "\n", wordwrap( $text, $split, "\n", true));
                    return $w_text;
                };
                foreach ($table as $line){
                    $line = array_map($func, $line, $widths);
                    $maxlines = max(array_map("count", $line));
                    foreach ($line as $key => $cell){
                        $x_axis = $this->getx();
                        $height = $lineheight * $maxlines / count($cell);
                        $len = count($line);
                        $width = (isset($widths[$key]) === TRUE ? $widths[$key] : $widths / count($line));
                        $align = (isset($aligns[$key]) === TRUE ? $aligns[$key] : '');
                        $fill = (isset($fills[$key]) === TRUE ? $fills[$key] : false);
                        $link = (isset($links[$key]) === TRUE ? $links[$key] : '');
                        foreach ($cell as $textline){
                            $this->cell($widths[$key],$height,$textline,0,0,$align,$fill,$link);
                            $height += 2 * $lineheight * $maxlines / count($cell);
                            $this->SetX($x_axis);
                        }
                        if($key == $len - 1){
                            $lbreak=1;
                        }
                        else{
                            $lbreak = 0;
                        }
                        $this->cell($widths[$key],$lineheight * $maxlines, '',$border,$lbreak);
                    }
                }
            }
        }
        ob_clean();
        $pdf = new MYPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
        // add a page
        $pdf->AddPage();
        // Title
        $pdf->SetFont('times','',7);
        $html = '<table  border="0"  align="center" width="100%">';
            $html .= '<tr>';
                $html .= '<td align="left" colspan="2" style="font-weight: bold;">';
                        if($ipd_month_wise!=''){
                            $html .= 'MONTH : '.date("F", mktime(null, null, null, $ipd_month_wise));;
                            $html .= '<br>';
                        }
                        if($ipd_admit_date!=''){
                            $html .= 'ADMIT DATE :'.date('d-M-Y',strtotime($ipd_admit_date));
                            $html .= '<br>';
                        }
                         if($ipd_discharge_date!=''){
                            $html .= 'DISCHARGE DATE :'.date('d-M-Y',strtotime($ipd_discharge_date));
                            $html .= '<br>';
                        }
                        if($department_id_fk!=''){
                            $html .= 'Department :'.getdepartmentname($department_id_fk);
                            $html .= '<br>';
                        }
                        
                        if(!empty($row)){
                            $html .= 'Total  :'.count($row);
                        }
                $html .='</td>';
                $html .='<td colspan="8" align="center">';
                   $html .='<h3 class="panel-title">'.$report_title.'</h3>';
                $html .='</td>';
                $html .='<td align="right" height="50">';
                   $html .='<img src="'.SITE.'/img/logo.jpg" height="50">';
                $html .='</td>';
            $html .='</tr>';
        $html .= '</table>';
        $html .= '<table  border="1" cellpadding="1" cellspacing="0" width="100%">';
           $html .='<tr align="center" style="font-weight:bold;">';
                $html .='<th width="15px">Sr.No</th>';
                $html .='<th width="25px">IPD NO </th>';
                $html .='<th width="25px">OPD NO </th>';
                $html .='<th width="150px">Name</th>';
                $html .='<th width="20px">Age</th>';
                $html .='<th width="42px">Gender</th>';
                $html .='<th width="50px">Department</th>';
                $html .='<th width="75px">Address</th>';
                $html .='<th width="45px">D.O.A.</th>';
                $html .='<th width="45px">D.O.D.</th>';
                $html .='<th width="20px">B.D.O.</th>';
                $html .='<th width="45px">WARD</th>';
            $html .='</tr>';
            $i = 1;
            $totalbeddays = 0;
            foreach ($row as $key => $student_info) {
                $startmonth = date('M-Y',strtotime($student_info['ipd_admit_date']));
                if($student_info['ipd_discharge_date']!=''){
                    $endmonth = date('M-Y',strtotime($student_info['ipd_discharge_date'])); 
                }else{
                    $endmonth =date('M-Y');
                }
                $html .='<tr align="center">';
                    $html .='<td width="15px">'.($key+1).'</td>';
                    $html .='<td width="25px" align="right">'.ucwords($student_info['ipd_no']).'</td>';
                    $html .='<td width="25px" align="right">'.ucwords($student_info['opd_no']).'</td>';
                    $html .='<td width="150px" align="left">'.ucwords($student_info['ipd_name']).'</td>';
                    $html .='<td width="20px" align="right">'.$student_info['ipd_age'].'</td>';
                    $html .='<td width="42px" align="left">'.strtoupper($student_info['ipd_gender']).'</td>';
                    $html .='<td width="50px" align="left">'.strtoupper($student_info['departmentname']).'</td>';
                    $html .='<td width="75px" align="left">'.ucwords($student_info['ipd_address']).'</td>';

                    $html .='<td width="45px">'.ucwords(date('d-M-Y',strtotime($student_info['ipd_admit_date']))).'</td>';
                    if($student_info['ipd_discharge_date']!=''){
                        $html .='<td width="45px">'.ucwords(date('d-M-Y',strtotime($student_info['ipd_discharge_date']))).'</td>';
                    }else{
                        $html .='<td width="45px"></td>';
                    }
                    $html .='<td width="20px" align="right">';
                            if($ipd_month_wise!=''){
                               $monthday_query = 'select count(ipd_o_id) as totaldays from hp_ipd_other_details where ipd_no="'.$student_info['ipd_no'].'" and ipd_id_fk="'.$student_info['ipd_id_pk'].'"';
                               $monthday_query .=" and ipd_date between '".date('Y').'-'.$ipd_month_wise.'-1'."' and '".date('Y').'-'.$ipd_month_wise.'-31'."'";
                               $count_total_day = $db->selectOne($monthday_query); 
                               if($count_total_day['totaldays']!=''){
                                    $totalbeddays =$totalbeddays+($count_total_day['totaldays']-1);

                                    $html .=($count_total_day['totaldays']-1);
                                   
                                   
                               }

                            }else{
                                $admitmonth = date("m",strtotime($student_info['ipd_admit_date']));
                                if($student_info['ipd_discharge_date']!=''){
                                    $dischargemonth = date("m",strtotime($student_info['ipd_discharge_date']));
                                }else{
                                    $dischargemonth = '';
                                }
                                if($admitmonth!='' and $dischargemonth!='' and $ipd_month_wise==''){
                                    $html .= $student_info['ipd_total_bed_occupiday'];
                                }else{
                                    $admitdate = $student_info['ipd_admit_date'];
                                    $date_last_day_of_month = date("Y-m-d");
                                    $admitdateconvert = strtotime($admitdate);
                                    $enddateconvert = strtotime($date_last_day_of_month);
                                    $days_between = ceil(abs($enddateconvert - $admitdateconvert) / 86400);
                                    $html .= $days_between." * ";
                                    
                                }
                                
                            }
                    $html .='</td>';
                    $html .='<td width="45px" align="right">'.$student_info['ipd_bed_word'].'</td>';
                $html .='</tr>';
            }
        $html .='</table>';
        $pdf->writeHTML($html, false, 0, false, 0);
        $html ='<table border="1" cellpadding="5" align="center" width="100%" >';
            $html .='<tr>';
                if(!empty($row)){
                    $html .='<th width="65px" colspan="2">TOTAL CASE</th>';
                    $html .='<th width="150px" colspan="2">TOTAL GENDER</th>';
                    $html .='<th width="112px">BED OCCUPANCY</th>';
                    $html .='<th width="230px">TOTAL DEPARTMENT</th>';
                }
            $html .='</tr>';
            $html .='<tr>';
                if(!empty($row)){
                    $html .= '<th width="65px"> '.count($row).'</th>';
                    $html .= '<th width="150px"> ';
                        $gendercounting = array_count_values(array_filter(array_column($row, 'ipd_gender')));
                        if(!empty($gendercounting)){
                            foreach ($gendercounting as $gendercountingkey => $gendercountingvalue) {
                                $html .= $gendercountingkey. "=". $gendercountingvalue."<br>";
                            }
                        }
                    $html .= '</th>';
                    $html .= '<th width="112px">'.$totalbeddays.'</th>';
                    $html .= '<th width="230px">';
                        $gendercounting = array_count_values(array_column($row, 'departmentname'));
                        if(!empty($gendercounting)){
                            foreach ($gendercounting as $gendercountingkey => $gendercountingvalue) {
                                $html .= strtoupper($gendercountingkey). "=". $gendercountingvalue."<br>";
                            }
                        }
                    $html .= '</th>';
                }
            $html .='</tr>';
        $html .='</table>';
        $pdf->writeHTML($html, false, 0, false, 0);
        $pdf->lastPage();
        $pdf->Output('ipdreport.pdf', 'I');
    }else{ 
        header("Content-type: application/vnd-ms-excel");
        header("Content-Disposition: attachment; filename=ipdreport.xls");
        $html = '<table  border="0"  align="center" width="100%">';
            $html .= '<tr>';
                $html .= '<td align="left" colspan="2" style="font-weight: bold;">';
                        if($ipd_month_wise!=''){
                            $html .= 'MONTH : '.date("F", mktime(null, null, null, $ipd_month_wise));;
                            $html .= '<br>';
                        }
                        if($ipd_admit_date!=''){
                            $html .= 'ADMIT DATE :'.date('d-M-Y',strtotime($ipd_admit_date));
                            $html .= '<br>';
                        }
                         if($ipd_discharge_date!=''){
                            $html .= 'DISCHARGE DATE :'.date('d-M-Y',strtotime($ipd_discharge_date));
                            $html .= '<br>';
                        }
                        if($department_id_fk!=''){
                            $html .= 'Department :'.getdepartmentname($department_id_fk);
                            $html .= '<br>';
                        }
                        
                        if(!empty($row)){
                            $html .= 'Total  :'.count($row);
                        }
                $html .='</td>';
                $html .='<td colspan="8" align="center">';
                   $html .='<h3 class="panel-title">'.$report_title.'</h3>';
                $html .='</td>';
                $html .='<td align="right" height="50">';
                   $html .='<img src="'.SITE.'/img/logo.jpg" height="50">';
                $html .='</td>';
            $html .='</tr>';
        $html .= '</table>';
        $html .= '<table  border="1" cellpadding="1" cellspacing="0" width="100%">';
           $html .='<tr align="center" style="font-weight:bold;">';
                $html .='<th width="15px">Sr.No</th>';
                $html .='<th width="25px">IPD NO </th>';
                $html .='<th width="25px">OPD NO </th>';
                $html .='<th width="150px">Name</th>';
                $html .='<th width="20px">Age</th>';
                $html .='<th width="42px">Gender</th>';
                $html .='<th width="50px">Department</th>';
                $html .='<th width="75px">Address</th>';
                $html .='<th width="45px">D.O.A.</th>';
                $html .='<th width="45px">D.O.D.</th>';
                $html .='<th width="20px">B.D.O.</th>';
                $html .='<th width="45px">WARD</th>';
            $html .='</tr>';
            $i = 1;
            $totalbeddays = 0;
            foreach ($row as $key => $student_info) {
                $startmonth = date('M-Y',strtotime($student_info['ipd_admit_date']));
                if($student_info['ipd_discharge_date']!=''){
                    $endmonth = date('M-Y',strtotime($student_info['ipd_discharge_date'])); 
                }else{
                    $endmonth =date('M-Y');
                }
                $html .='<tr align="center">';
                    $html .='<td width="15px">'.($key+1).'</td>';
                    $html .='<td width="25px" align="right">'.ucwords($student_info['ipd_no']).'</td>';
                    $html .='<td width="25px" align="right">'.ucwords($student_info['opd_no']).'</td>';
                    $html .='<td width="150px" align="left">'.ucwords($student_info['ipd_name']).'</td>';
                    $html .='<td width="20px" align="right">'.$student_info['ipd_age'].'</td>';
                    $html .='<td width="42px" align="left">'.strtoupper($student_info['ipd_gender']).'</td>';
                    $html .='<td width="50px" align="left">'.strtoupper($student_info['departmentname']).'</td>';
                    $html .='<td width="75px" align="left">'.ucwords($student_info['ipd_address']).'</td>';

                    $html .='<td width="45px">'.ucwords(date('d-M-Y',strtotime($student_info['ipd_admit_date']))).'</td>';
                    if($student_info['ipd_discharge_date']!=''){
                        $html .='<td width="45px">'.ucwords(date('d-M-Y',strtotime($student_info['ipd_discharge_date']))).'</td>';
                    }else{
                        $html .='<td width="45px"></td>';
                    }
                    $html .='<td width="20px" align="right">';
                            if($ipd_month_wise!=''){
                               $monthday_query = 'select count(ipd_o_id) as totaldays from hp_ipd_other_details where ipd_no="'.$student_info['ipd_no'].'" and ipd_id_fk="'.$student_info['ipd_id_pk'].'"';
                               $monthday_query .=" and ipd_date between '".date('Y').'-'.$ipd_month_wise.'-1'."' and '".date('Y').'-'.$ipd_month_wise.'-31'."'";
                               $count_total_day = $db->selectOne($monthday_query); 
                               if($count_total_day['totaldays']!=''){
                                    $totalbeddays =$totalbeddays+($count_total_day['totaldays']-1);

                                    $html .=($count_total_day['totaldays']-1);
                                   
                                   
                               }

                            }else{
                                $admitmonth = date("m",strtotime($student_info['ipd_admit_date']));
                                if($student_info['ipd_discharge_date']!=''){
                                    $dischargemonth = date("m",strtotime($student_info['ipd_discharge_date']));
                                }else{
                                    $dischargemonth = '';
                                }
                                if($admitmonth!='' and $dischargemonth!='' and $ipd_month_wise==''){
                                    $html .= $student_info['ipd_total_bed_occupiday'];
                                }else{
                                    $admitdate = $student_info['ipd_admit_date'];
                                    $date_last_day_of_month = date("Y-m-d");
                                    $admitdateconvert = strtotime($admitdate);
                                    $enddateconvert = strtotime($date_last_day_of_month);
                                    $days_between = ceil(abs($enddateconvert - $admitdateconvert) / 86400);
                                    $html .= $days_between." * ";
                                    
                                }
                                
                            }
                    $html .='</td>';
                    $html .='<td width="45px" align="right">'.$student_info['ipd_bed_word'].'</td>';
                $html .='</tr>';
            }
        $html .='</table>';
        $html .='<table border="1" cellpadding="5" align="center" width="100%" >';
            $html .='<tr>';
                if(!empty($row)){
                    $html .='<th colspan="2">TOTAL CASE</th>';
                    $html .='<th colspan="2">TOTAL GENDER</th>';
                    $html .='<th colspan="3">BED OCCUPANCY</th>';
                    $html .='<th colspan="5">TOTAL DEPARTMENT</th>';
                }
            $html .='</tr>';
            $html .='<tr>';
                if(!empty($row)){
                    $html .= '<th colspan="2"> '.count($row).'</th>';
                    $html .= '<th colspan="2"> ';
                        $gendercounting = array_count_values(array_filter(array_column($row, 'ipd_gender')));
                        if(!empty($gendercounting)){
                            foreach ($gendercounting as $gendercountingkey => $gendercountingvalue) {
                                $html .= $gendercountingkey. "=". $gendercountingvalue."<br>";
                            }
                        }
                    $html .= '</th>';
                    $html .= '<th  colspan="3">'.$totalbeddays.'</th>';
                    $html .= '<th  colspan="5">';
                        $gendercounting = array_count_values(array_column($row, 'departmentname'));
                        if(!empty($gendercounting)){
                            foreach ($gendercounting as $gendercountingkey => $gendercountingvalue) {
                                $html .= strtoupper($gendercountingkey). "=". $gendercountingvalue."<br>";
                            }
                        }
                    $html .= '</th>';
                }
            $html .='</tr>';
        $html .='</table>';
        echo $html;
    }
}
?> 
