setActiveSheetIndex(0) ->setCellValue('A1','Employee Leave Reporting') ->setCellValue('A2','Human Capital '.$_SESSION['employeename']) ->setCellValue('A3','Date Reporting : '.date("d/m/Y H:i:s")) ->setCellValue('A4','Periode : '.$cl->FN_GETMONTHNAME($month)." $period"); if($idsubunit) { $subunitname=$cl->fn_get_fieldvalue("subunitname","select subunitname from ".DB_APORTIL.".tbl_employee_subunit where id='$idsubunit'"); $objPHPExcel->setActiveSheetIndex(0)->setCellValue('A5','Sub Unit : '.$subunitname); } // set format cell $objPHPExcel->getActiveSheet()->getStyle('A1')->getFont()->setBold(true); // Print Header $objPHPExcel->setActiveSheetIndex(0) ->setCellValue('A7','No') ->setCellValue('B7','Name') ->setCellValue('C7','Nik') ->setCellValue('D7','Position') ->setCellValue('E7','Status') ->setCellValue('F7','Leave Category') ->setCellValue('G7','Submit Date') ->setCellValue('H7','Start Date') ->setCellValue('I7','End Date') ->setCellValue('J7','Leave Days') ->setCellValue('K7','Approval 1') ->setCellValue('L7','Approval 2') ->setCellValue('M7','Excess') ; // Worksheet Name $objPHPExcel->getActiveSheet()->setTitle('LEAVEINFO_'.date("Ym")); $objPHPExcel->getActiveSheet()->getStyle('A7:M7')->getFont()->getColor()->setRGB('ffffff'); // === Set Background Cell $objPHPExcel->cellColor("A7:M7","938e8e"); // === set Column Width A $objPHPExcel->getActiveSheet()->getColumnDimension('A')->setWidth(6); // === Set auto COlumn width foreach(range('B','M') as $columnID) { $objPHPExcel->getActiveSheet()->getColumnDimension($columnID)->setAutoSize(true); } // Data $swhere=""; if($idemployee){$swhere="e.id='$idemployee' and ";} if($idsubunit){$swhere.="e.idsubunit='$idsubunit' and ";} if($month){$swhere.="month(d.startdate)='$month' and ";} $qry="select e.id idemployee,e.nik,e.fullname,e.positionname,d.id idleavedata,d.leavetype,d.startdate,d.enddate,d.hcmdurationdays, d.fullnameapproval approval1,d.fullnameapproval2 approval2,d.credit,d.status from tbl_employee e inner join tbl_hcm_leavedata d on e.id=d.idemployee where $swhere d.isdeleted=0 and d.status>=-1"; $rsrpt=$cl->selectquery($qry); if($rsrpt) { $i=8;$j=1; while($rw=$cl->data_row_array($rsrpt)) { $qry="select description from tbl_hcm_leavestatus where status='".$rw['status']."' and isdeleted=0"; $statusdescription=$cl->fn_get_fieldvalue("description",$qry); $qry="select idt dates from tbl_hcm_leavedatahistory where idheader='".$rw['idleavedata']."' and status=0 and isdeleted=0 order by id asc limit 1"; $sd=$cl->fn_get_fieldvalue("dates",$qry); $submitdate=""; if($sd&&(int)$sd!=0){$submitdate=date("Y-m-d H:i:s",strtotime($sd));} $qry="select idt dates from tbl_hcm_leavedatahistory where idheader='".$rw['idleavedata']."' and status=2 and isdeleted=0 order by id asc limit 1"; $sd=$cl->fn_get_fieldvalue("dates",$qry); $appdate1=""; if($sd&&(int)$sd!=0&&$rw['approval1']){$appdate1=date("Y-m-d H:i:s",strtotime($sd));} $qry="select idt dates from tbl_hcm_leavedatahistory where idheader='".$rw['idleavedata']."' and status=5 and isdeleted=0 order by id asc limit 1"; $sd=$cl->fn_get_fieldvalue("dates",$qry); $appdate2=""; if($sd&&(int)$sd!=0){$appdate2=date("Y-m-d H:i:s",strtotime($sd));} $objPHPExcel->setActiveSheetIndex(0)->setCellValue('A'.$i,$j) ->setCellValue('B'.$i,$rw["fullname"]) ->setCellValue('C'.$i,$rw["nik"]) ->setCellValue('D'.$i,$rw["positionname"]) ->setCellValue('E'.$i,$statusdescription) ->setCellValue('F'.$i,$rw["leavetype"]) ->setCellValue('G'.$i,$submitdate) ->setCellValue('H'.$i,date("d/m/Y",strtotime($rw['startdate']))) ->setCellValue('I'.$i,date("d/m/Y",strtotime($rw['enddate']))) ->setCellValue('J'.$i,$rw['hcmdurationdays']) ->setCellValue('K'.$i,$rw['approval1']." ".$appdate1) ->setCellValue('L'.$i,$rw['approval2']." ".$appdate2) ->setCellValue('M'.$i,$rw['credit']) ; $colors="000000"; if($rw['credit']<0){$colors="FF0000";} $phpColor = new PHPExcel_Style_Color(); $phpColor->setRGB($colors); $objPHPExcel->getActiveSheet()->getStyle('M'.$i)->getFont()->setColor($phpColor); $i+=1;$j+=1; $j+=1; } $rowcount=$j-1; } $cl->clearrecordset($rsrpt); // Set active sheet index to the first sheet, so Excel opens this as the first sheet $objPHPExcel->setActiveSheetIndex(0); // Redirect output to a web browser (Excel2007) //header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'); header('Content-Type: application/vnd.ms-excel'); header('Content-Disposition: attachment;filename="HCM_LEAVEINFO.xls"'); header('Cache-Control: max-age=0'); $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5'); $objWriter->save('php://output'); exit; ?>