setActiveSheetIndex(0) ->setCellValue('A1','Employee Overtime Reporting') ->setCellValue('A2','Human Capital '.$_SESSION['employeename']) ->setCellValue('A3','Date Reporting : '.date("d/m/Y H:i:s")) ->setCellValue('A4','Periode : '.$cl->FN_GETMONTHNAME($month1)." $period1 s/d ".$cl->FN_GETMONTHNAME($month2)." $period2"); if($idunit) { $unitname=$cl->fn_get_fieldvalue("unitname","select unitname from ".DB_APORTIL.".tbl_employee_unit where id='$idunit'"); $objPHPExcel->setActiveSheetIndex(0)->setCellValue('A5','Unit : '.$unitname); } if($idsubunit) { $subunitname=$cl->fn_get_fieldvalue("subunitname","select subunitname from ".DB_APORTIL.".tbl_employee_subunit where id='$idsubunit'"); $objPHPExcel->setActiveSheetIndex(0)->setCellValue('A6','Sub Unit : '.$subunitname); } // set format cell $objPHPExcel->getActiveSheet()->getStyle('A1')->getFont()->setBold(true); // Print Header $objPHPExcel->setActiveSheetIndex(0) ->setCellValue('A7','No') ->setCellValue('B7','Nik') ->setCellValue('C7','Employee Name') ->setCellValue('D7','Position') ->setCellValue('E7','Band') ->setCellValue('F7','Hari') ->setCellValue('G7','Tgl') ->setCellValue('H7','Start') ->setCellValue('I7','End') ->setCellValue('J7','Lama Lembur ( Menit )') ->setCellValue('K7','Lama Lembur ( Jam )') //->setCellValue('L7','Over ( Jam )') ->setCellValue('L7','Hari Lembur') ->setCellValue('M7','Deskripsi') ->setCellValue('N7','User') ; // === Merge Cells //$objPHPExcel->getActiveSheet()->mergeCells('G5:H5'); //$objPHPExcel->getActiveSheet()->mergeCells('I5:J5'); $objPHPExcel->getActiveSheet()->getStyle('A7:N7')->getFont()->getColor()->setRGB('ffffff'); // Worksheet Name $objPHPExcel->getActiveSheet()->setTitle('OVERTIME_'.date("Ym")); // === Set Background Cell $objPHPExcel->cellColor("A7:N7","938e8e"); // === set Column Width A $objPHPExcel->getActiveSheet()->getColumnDimension('A')->setWidth(6); // === Set auto COlumn width foreach(range('B','N') as $columnID) { $objPHPExcel->getActiveSheet()->getColumnDimension($columnID)->setAutoSize(true); } $swhere=""; if($month1&&$month2) { $dt1=date("Y-m-d",strtotime($period1."-".$month1."-01")); $dt2=date("Y-m-d",strtotime($period2."-".((int)$month2+1)."-01")); $swhere="cast(l.overtime_date as date) between cast('$dt1' as date) and cast('$dt2' as date) and "; } if($idemployee) { $swhere.="e.id='$idemployee' and "; } if($idunit) { $swhere.="e.idunit='$idunit' and "; } if($idsubunit) { $swhere.="e.idsubunit='$idsubunit' and "; } $qry="select l.id, l.id_employee, l.nik, l.empgroup, l.fullname, l.title, l.date, l.overtime_date, l.end_date, l.start_hour, l.end_hour, l.total_duration, l.task, l.user, l.status_approval, l.description from ".DB_APORTIL.".tbl_employee e inner join ".DB_APORTIL.".tbl_hcm_lembur l on e.id=l.id_employee where $swhere l.isdeleted=0 order by l.id asc"; $rsrpt=$cl->selectquery($qry); if($rsrpt) { $i=8;$j=1; while($rw=$cl->data_row_array($rsrpt)) { $bandposition=$cl->fn_get_fieldvalue("bandposition","select bandposition from ".DB_APORTIL.".tbl_employee where id='".$rw['id_employee']."'"); $days=date("l",strtotime($rw['overtime_date'])); $colors="000000"; if(strtolower($days)!='saturday'&&strtolower($days)!='sunday') { //if(strtotime($rw->start_hour)>=strtotime("18:00:00"&&strtotime($rw->end_hour)<=strtotime("21:00:00"))) $dayscategory="Weekdays"; if(strtotime($rw['end_hour'])>strtotime("21:00:00")) { $dayscategory="Weekdays Night"; } } else { $colors="FF0000"; $dayscategory="Weekend"; } $durationmenit=$rw['total_duration']; $durationhour=round(($rw['total_duration']/60),2); $over=0; if($durationhour>5) { $over=($durationhour%5); } $phpColor = new PHPExcel_Style_Color(); $phpColor->setRGB($colors); $objPHPExcel->setActiveSheetIndex(0)->setCellValue('A'.$i,$j) ->setCellValue('B'.$i,$rw["nik"]) ->setCellValue('C'.$i,$rw["fullname"]) ->setCellValue('D'.$i,$rw["title"]) ->setCellValue('E'.$i,$bandposition) ->setCellValue('F'.$i,$days) ->setCellValue('G'.$i,date("d/m/Y",strtotime($rw['overtime_date']))) ->setCellValue('H'.$i,date("H:i",strtotime($rw['start_hour']))) ->setCellValue('I'.$i,date("H:i",strtotime($rw['end_hour']))) ->setCellValue('J'.$i,$durationmenit) ->setCellValue('K'.$i,$durationhour) // ->setCellValue('L'.$i,$over) ->setCellValue('L'.$i,$dayscategory) ->setCellValue('M'.$i,$rw['task']) ->setCellValue('N'.$i,$rw['user']) ; $objPHPExcel->getActiveSheet()->getStyle('L'.$i)->getFont()->setColor($phpColor); $i+=1;$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_OVERTIME.xls"'); header('Cache-Control: max-age=0'); $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5'); $objWriter->save('php://output'); exit; ?>