Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php defined('BASEPATH') OR exit('No direct script access allowed');
- class DownloadReport extends CI_Controller
- {
- protected $_container = array();
- protected $_total_list = array();
- protected $_total_time = "00.00";
- protected $_total_late= "00.00";
- protected $_overload = "00.00";
- protected $_undertime = "00.00";
- protected $_total_absent= "00.00";
- private $_count_late=0;
- private $_count_absent=0;
- private $_count_present=0;
- private $_count_undertime=0;
- private $_count_overload=0;
- function __construct()
- {
- parent::__construct();
- $this->load->model('SmartEntryModel');
- $this->load->model('ConverterModel');
- }
- public function generateReport()
- {
- ini_set('max_execution_time',0);
- ini_set('memory_limit', '1024M');
- $employee_id = $this->input->post('device_number');
- $fname = $this->input->post('device_name');
- $minitial = $this->input->post('minitial');
- $lname = $this->input->post('lname');
- $group = $this->input->post('group');
- $emp_position = $this->input->post('emp_position');
- $emp_type = $this->input->post('emp_type');
- $department = $this->input->post('department');
- $arrange_by_1 = $this->input->post('arrange_by_1');
- $arrange_by_2 = $this->input->post('arrange_by_2');
- //show details
- $hrs_work = $this->input->post('show_hours_work');
- $late = $this->input->post('show_late');
- $undertime = $this->input->post('show_undertime');
- $overload = $this->input->post('show_overload');
- $absent = $this->input->post('show_absent');
- $show_department = $this->input->post('show_department');
- $show_remarks = $this->input->post('show_remarks');
- $show_time_sheet = $this->input->post('show_time_sheet');
- $show_sub_total = $this->input->post('show_sub_total');
- $classification = $this->input->post('show_classification');
- $download_type = $this->input->post('download_type');
- $summary = $this->input->post('summary');
- $report_type = "original_report";
- $show_array_result = array($hrs_work,$late,$undertime,$overload,$absent,$show_time_sheet,$show_sub_total,$classification,$show_department);
- $daterange = $this->input->post('daterange');
- if($daterange==''):
- $date_end = date('Y-m-d');
- $date_end = date('Y-m-d',strtotime('02/28/2018'));
- $date_start = date('Y-m-d',strtotime('02/18/2018'));
- else:
- $date = explode('-',$daterange);
- $date_start = date('Y-m-d',strtotime(trim($date[0])));
- $date_end = date('Y-m-d',strtotime(trim($date[1])));
- endif;
- if($download_type=='0')
- {
- $filename = $this->reportContent($employee_id,$fname,$date_start,$date_end,$minitial,$lname,$group,$department,$show_array_result,$show_department,$show_remarks,$arrange_by_1,$arrange_by_2,$report_type,$emp_type,$emp_position);
- }
- else if($download_type=='1')
- {
- $filename = $this->college($employee_id,$fname,$date_start,$date_end,$minitial,$lname,$group,$department,$show_array_result,$show_department,$show_remarks,$arrange_by_1,$arrange_by_2,$report_type,$emp_type,$emp_position);
- }
- else if($download_type=='2')
- {
- $filename = $this->downloadSubstitute($employee_id,$fname,$date_start,$date_end,$minitial,$lname,$group,$department,$show_array_result,$show_department,$show_remarks,$arrange_by_1,$arrange_by_2,$report_type,$emp_type,$emp_position);
- }
- else
- {
- redirect('smartentry/monthlyReport');
- }
- echo '../download/'.$filename;
- }
- public function downloadSubstitute($employee_id,$fname,$date_start,$date_end,$minitial,$lname,$group,$department,$show_array_result,$show_department,$show_remarks,$arrange_by_1,$arrange_by_2,$report_type,$emp_type,$emp_position)
- {
- $data_container = array();
- $data_holder=array();
- $emp_info = array('Emp ID', 'Emp Name', 'Date');
- if($show_array_result[count($show_array_result)-1]=="on"):
- $department_S[]='Department';
- $emp_info = array_merge($emp_info,$department_S);
- endif;
- if($show_array_result[count($show_array_result)-2]=="on"):
- $classification_s[]='Classification';
- $emp_info = array_merge($emp_info,$classification_s);
- endif;
- if($show_array_result[3]=="on"):
- $overload_s[]='OverLoad (Hours)';
- $emp_info = array_merge($emp_info,$overload_s);
- endif;
- $data_container[] = $emp_info;
- $html = '';
- $emp_list_response = $this->SmartEntryModel->employeeList2($employee_id,$fname,$minitial,$lname,$group,$department,$arrange_by_1,$arrange_by_2,$emp_type,$emp_position);
- foreach($emp_list_response->result() as $emp_list)
- {
- $emp_no = $emp_list->employee_student_no;
- $department_name = $this->getDepartment($emp_list);
- $classification_name = $this->getClassification($emp_list);
- $result = $this->SmartEntryModel->getAllAccessRecords2($emp_no,$date_start,$date_end);
- $dates = $this->ConverterModel->DatePeriod_start_end($date_start,$date_end);
- if($result->num_rows()>0)
- {
- foreach($dates as $date)
- {
- $time_record = $this->computeCollegeRecord($emp_no,$date,$result,$emp_list->message);
- $emp_data = array($emp_no,strtoupper($emp_list->lname.", ".$emp_list->fname." ".$emp_list->minitial),date('M d Y',strtotime($date)));
- if($show_array_result[count($show_array_result)-1]=="on"):
- $emp_data = array_merge($emp_data,array($department_name));
- endif;
- if($show_array_result[count($show_array_result)-2]=="on"):
- $emp_data = array_merge($emp_data,array($classification_name));
- endif;
- if($show_array_result[3]=="on"):
- $emp_data = array_merge($emp_data,array($time_record['overload']));
- endif;
- $data_body = $emp_data;
- $data_container[] = $data_body;
- }
- }
- else
- {
- foreach($dates as $date)
- {
- $emp_data = array($emp_no,strtoupper($emp_list->lname.", ".$emp_list->fname." ".$emp_list->minitial),date('M d Y',strtotime($date)));
- if($show_array_result[count($show_array_result)-1]=="on"):
- $emp_data = array_merge($emp_data,array($department_name));
- endif;
- if($show_array_result[count($show_array_result)-2]=="on"):
- $emp_data = array_merge($emp_data,array($classification_name));
- endif;
- if($show_array_result[3]=="on"):
- $emp_data = array_merge($emp_data,array(0));
- endif;
- $data_body = $emp_data;
- $data_container[] = $data_body;
- $data_holder[] = $emp_no;
- }
- }
- }
- $filename = 'substitution_report.csv';
- $response = $this->generateCsvFile($filename,$data_container);
- return $filename;
- }
- private function college($employee_id,$fname,$date_start,$date_end,$minitial,$lname,$group,$department,$show_array_result,$show_department,$show_remarks,$arrange_by_1,$arrange_by_2,$report_type,$emp_type,$emp_position)
- {
- $data_container = array();
- $data_holder=array();
- $emp_info = array('Emp ID', 'Emp Name', 'Date');
- $emp_info = $this->headerTimeDownload($show_array_result,$emp_info,$show_remarks);
- $data_container[] = $emp_info;
- $html = '';
- $emp_list_response = $this->SmartEntryModel->employeeList2($employee_id,$fname,$minitial,$lname,$group,$department,$arrange_by_1,$arrange_by_2,$emp_type,$emp_position);
- foreach($emp_list_response->result() as $emp_list)
- {
- $emp_no = $emp_list->employee_student_no;
- $department_name = $this->getDepartment($emp_list);
- $classification_name = $this->getClassification($emp_list);
- $result = $this->SmartEntryModel->getAllAccessRecords2($emp_no,$date_start,$date_end);
- $dates = $this->ConverterModel->DatePeriod_start_end($date_start,$date_end);
- if($result->num_rows()>0)
- {
- foreach($dates as $date)
- {
- $time_record = $this->computeCollegeRecord($emp_no,$date,$result,$emp_list->message);
- $emp_data = array($emp_no,strtoupper($emp_list->lname.", ".$emp_list->fname." ".$emp_list->minitial),date('M d Y',strtotime($date)));
- $emp_data = $this->timeKepper($show_array_result,$emp_data,$department_name,$classification_name,$time_record,$emp_list,$show_remarks);
- $data_body = $emp_data;
- $data_container[] = $data_body;
- }
- }
- else
- {
- foreach($dates as $date)
- {
- $emp_data = array($emp_no,strtoupper($emp_list->lname.", ".$emp_list->fname." ".$emp_list->minitial),date('M d Y',strtotime($date)));
- $emp_data = $this->timeKepperZero($show_array_result,$emp_data,$department_name,$classification_name,$show_remarks);
- $data_container[] = $emp_data;
- $data_holder[] = $emp_no;
- }
- }
- }
- $filename = 'college_report.csv';
- $this->generateCsvFile($filename,$data_container);
- return $filename;
- }
- private function timeKepper($show_array_result,$emp_data,$department_name,$classification_name,$time_record,$emp_list,$show_remarks)
- {
- if($show_array_result[count($show_array_result)-1]=="on"):
- $emp_data = array_merge($emp_data,array($department_name));
- endif;
- if($show_array_result[count($show_array_result)-2]=="on"):
- $emp_data = array_merge($emp_data,array($classification_name));
- endif;
- if($show_array_result[0]=="on"):
- $emp_data = array_merge($emp_data,array($time_record['reghrs']));
- endif;
- if($show_array_result[4]=="on"):
- $emp_data = array_merge($emp_data,array($time_record['absent']));
- endif;
- if($show_array_result[1]=="on"):
- $emp_data = array_merge($emp_data,array($time_record['late']));
- endif;
- if($show_array_result[2]=="on"):
- $emp_data = array_merge($emp_data,array($time_record['undertime']));
- endif;
- if($show_remarks=="on"):
- $emp_data = array_merge($emp_data,array($emp_list->message));
- endif;
- if($show_array_result[3]=="on"):
- $emp_data = array_merge($emp_data,array($time_record['overload']));
- endif;
- return $emp_data;
- }
- private function timeKepperZero($show_array_result,$emp_data,$department_name,$classification_name,$show_remarks)
- {
- if($show_array_result[count($show_array_result)-1]=="on"):
- $emp_data = array_merge($emp_data,array($department_name));
- endif;
- if($show_array_result[count($show_array_result)-2]=="on"):
- $emp_data = array_merge($emp_data,array($classification_name));
- endif;
- if($show_array_result[0]=="on"):
- $emp_data = array_merge($emp_data,array(0));
- endif;
- if($show_array_result[4]=="on"):
- $emp_data = array_merge($emp_data,array(0));
- endif;
- if($show_array_result[1]=="on"):
- $emp_data = array_merge($emp_data,array(0));
- endif;
- if($show_array_result[2]=="on"):
- $emp_data = array_merge($emp_data,array(0));
- endif;
- if($show_remarks=="on"):
- $emp_data = array_merge($emp_data,array(''));
- endif;
- if($show_array_result[3]=="on"):
- $emp_data = array_merge($emp_data,array(0));
- endif;
- return $emp_data;
- }
- private function headerTimeDownload($show_array_result,$emp_info,$show_remarks)
- {
- if($show_array_result[count($show_array_result)-1]=="on"):
- $department_S[]='Department';
- $emp_info = array_merge($emp_info,$department_S);
- endif;
- if($show_array_result[count($show_array_result)-2]=="on"):
- $classification_s[]='Classification';
- $emp_info = array_merge($emp_info,$classification_s);
- endif;
- if($show_array_result[0]=="on"):
- $reghrs[]='RegHrs (Hours)';
- $emp_info = array_merge($emp_info,$reghrs);
- endif;
- if($show_array_result[4]=="on"):
- $absent[]='Absent (Hours)';
- $emp_info = array_merge($emp_info,$absent);
- endif;
- if($show_array_result[1]=="on"):
- $late[]='Late (Minutes)';
- $emp_info = array_merge($emp_info,$late);
- endif;
- if($show_array_result[2]=="on"):
- $undertime[]='Under (Minutes)';
- $emp_info = array_merge($emp_info,$undertime);
- endif;
- if($show_remarks=="on"):
- $remarks[]='Remarks';
- $emp_info = array_merge($emp_info,$remarks);
- endif;
- if($show_array_result[3]=="on"):
- $overload_s[]='OverLoad (Hours)';
- $emp_info = array_merge($emp_info,$overload_s);
- endif;
- return $emp_info;
- }
- private function employeeTimeCollector($emp_no,$date)
- {
- $this->load->model('ScheduleModel');
- $time_collector = array();
- $index = 0;
- $index_2 = 0;
- $day = $this->selectDay($date);
- //echo json_encode($day)."<hr>";
- $response = $this->ScheduleModel->getEmployeeTimeListReport($emp_no,$day);
- if($response->num_rows()>0)
- {
- foreach($response->result() as $time)
- {
- $decode = json_decode($time->time_list);
- for($i=0;$i<count($decode);$i++)
- {
- if(($i%2)==0)
- {
- $data['start'][] = $decode[$i];
- }
- else
- {
- $data['end'][] = $decode[$i];
- }
- }
- }
- for($x=0;$x<count($data['start']);$x++)
- {
- $time_collector[] = array(
- 'start_time' => $data['start'][$x],
- 'end_time' => $data['end'][$x]
- );
- }
- }
- return $time_collector;
- }
- private function computeCollegeRecord($emp_id,$date,$result,$message)
- {
- $total_absent=0;
- $total_undertime=0;
- $overload_time_in = '';
- $total_overload=0;
- $allowance = $this->getTimeAllowance($emp_id);
- $grace_period = $this->getGracePeriod($emp_id);
- $time_setup = $this->employeeTimeCollector($emp_id,$date);
- $time_list = array();
- $record_logs = array();
- if($result->num_rows()>0)
- {
- foreach($result->result() as $time)
- {
- $access_time = date('H:i',strtotime($time->access_time));
- if($time->server_created_date==$date)
- {
- if(count($time_setup)>0)
- {
- $record_logs[] = array(
- 'access_time' => $access_time,
- 'access_type' => $time->access_type
- );
- }
- else
- {
- $time_list['overload'][] = array(
- 'access_time' => $access_time,
- 'access_type' => $time->access_type
- );
- }
- }
- }
- if(count($time_setup)>0):
- $time_list = $this->timeRecord($record_logs,$time_setup,$emp_id);
- endif;
- $total_overload = $this->computeOverload($time_list,$date);
- $total_undertime = $this->computeUndertime($time_setup,$time_list,$date);
- $total_absent = $this->computeAbsent($time_setup,$time_list,$date);
- }
- else
- {
- $total_overload = $this->computeOverload($time_list,$date);
- $total_undertime = $this->computeUndertime($time_setup,$time_list,$date);
- $total_absent = $this->computeAbsent($time_setup,$time_list,$date);
- }
- $total_hrs = $this->computeTimeRecord($time_list,$time_setup,$date,$grace_period);
- $data = array(
- 'reghrs'=>$total_hrs['reghrs'],
- 'absent'=>$total_absent,
- 'late'=> $this->getDeductionTime($total_hrs['late']),
- 'undertime'=>$this->getDeductionTime($total_undertime),
- 'message'=>$message,
- 'overload' =>$total_overload
- );
- return $data;
- }
- private function getDeductionTime($time)
- {
- $floor = floor($time/30);
- $remainder = $time%30;
- if($remainder!=0):
- $remainder = 30;
- endif;
- $total = ($floor*30) + $remainder;
- return $total;
- }
- private function getTimeAllowance($emp_id)
- {
- $row = $this->SmartEntryModel->getEmployeeExtInfo($emp_id);
- if(count($row)>0)
- {
- $classification_id = $row->classification_id;
- $row_time_allowance = $this->SmartEntryModel->checkStatusPeriod($classification_id);
- $time_out_allowance_status = $row_time_allowance->timeout_allowance_status;
- if($time_out_allowance_status==1)
- {
- $time_row_period = $this->SmartEntryModel->getGracePeriodData();
- $timeout_allowance = $time_row_period->timeout_allowance;
- }
- else
- {
- $timeout_allowance = 0;
- }
- }
- else
- {
- $timeout_allowance = 0;
- }
- return $timeout_allowance;
- }
- private function getGracePeriod($emp_id)
- {
- $row = $this->SmartEntryModel->getEmployeeExtInfo($emp_id);
- if(count($row)>0)
- {
- $classification_id = $row->classification_id;
- $row_time_allowance = $this->SmartEntryModel->checkStatusPeriod($classification_id);
- $grace_period_status = $row_time_allowance->grace_period_status;
- if($grace_period_status==1)
- {
- $time_row_period = $this->SmartEntryModel->getGracePeriodData();
- $grace_period = $time_row_period->timeout_allowance;
- }
- else
- {
- $grace_period = 0;
- }
- }
- else
- {
- $grace_period = 0;
- }
- return $grace_period;
- }
- private function timeRecord($record_logs,$time_setup,$emp_id)
- {
- $time_list = array();
- $timeout_allowance = $this->getTimeAllowance($emp_id);
- for($n=0;$n<count($time_setup);$n++)
- {
- $boolean = true;
- $end_time_with_allowance = date('H:i',strtotime($time_setup[$n]['end_time']." + ".$timeout_allowance."mins"));
- $start_time = $time_setup[$n]['start_time'];
- $end_time = $time_setup[$n]['end_time'];
- for($i=0;$i<count($record_logs);$i++)
- {
- $access_time = $record_logs[$i]['access_time'];
- $access_type = $record_logs[$i]['access_type'];
- if(isset($time_setup[$n-1]))
- {
- if(strtotime($access_time) > strtotime($time_setup[$n-1]['end_time']) && strtotime($access_time) < strtotime($time_setup[$n]['start_time'])&&$access_type!='2'):
- $time_list[$start_time][] = array(
- 'access_time' => $access_time,
- 'access_type' => $access_type
- );
- endif;
- }
- else
- {
- if(strtotime($access_time)<strtotime($start_time)):
- $time_list[$start_time][] = array(
- 'access_time' => $access_time,
- 'access_type' => $access_type
- );
- endif;
- }
- if(strtotime($access_time)>=strtotime($start_time)&&strtotime($access_time)<=strtotime($end_time_with_allowance))
- {
- if(strtotime($access_time)>strtotime($end_time) && strtotime($access_time)<=strtotime($end_time_with_allowance) && $access_type=='2'):
- $time_list[$start_time][] = array(
- 'access_time' => $access_time,
- 'access_type' => $access_type
- );
- endif;
- if(strtotime($access_time)>=strtotime($start_time) && strtotime($access_time)<=strtotime($end_time)):
- $boolean = $this->pickTimeAllowanceStatus($boolean,$record_logs,$i);
- if($boolean==false):
- $time_list[$start_time][] = array(
- 'access_time' => $access_time,
- 'access_type' => $access_type
- );
- endif;
- endif;
- }
- else if(!isset($time_setup[$i+1]) && strtotime($access_time)>strtotime($time_setup[count($time_setup)-1]['end_time']) && count($time_setup)==($n+1))
- {
- if($access_type!='2'):
- $overload_time_in=true;
- endif;
- if($overload_time_in!=true):
- $time_list[$start_time][] = array(
- 'access_time' => $access_time,
- 'access_type' => $access_type
- );
- endif;
- if($overload_time_in==true):
- $time_list['overload'][] = array(
- 'access_time' => $access_time,
- 'access_type' => $access_type
- );
- endif;
- }
- }
- }
- return $time_list;
- }
- private function pickTimeAllowanceStatus($boolean,$record_logs,$i)
- {
- if($boolean==true && $record_logs[$i]['access_type']=='2')
- {
- $boolean=true;
- }
- else
- {
- $boolean=false;
- }
- return $boolean;
- }
- private function computeOverload($time_list,$date)
- {
- $ctr=0;
- $access_type_holder = '';
- $time_container = array();
- $total_overload = 0;
- if(isset($time_list['overload']))
- {
- for($i=0;$i<count($time_list['overload']);$i++)
- {
- $time_container[$ctr][] = array(
- 'access_time' => $time_list['overload'][$i]['access_time'],
- 'access_type' => $time_list['overload'][$i]['access_type']
- );
- if(isset($time_list['overload'][$i+1])):
- if($time_list['overload'][$i]['access_type']=='2' && $time_list['overload'][$i+1]['access_type']!='2'):
- $ctr++;
- endif;
- endif;
- }
- }
- if(count($time_container)>0)
- {
- for($n=0;$n<count($time_container);$n++)
- {
- $start_time = $time_container[$n][0]['access_time'];
- $start_end = $time_container[$n][count($time_container[$n])-1]['access_time'];
- $total_partial = $this->ConverterModel->dateTimeComuptation($start_time,$start_end,$date);
- $total_overload += $this->sumTotalTime($total_partial,'hrs');
- $this->_count_overload = $this->_count_overload + 1;
- }
- }
- else
- {
- $total_overload=0;
- $this->_count_overload = 0;
- }
- return $total_overload;
- }
- private function sumTotalTime($total_time,$time_type)
- {
- $hrs = $this->showTimeSelector($total_time,'hrs');
- $mins = $this->showTimeSelector($total_time,'mins');
- $ext_mns=0;
- $ext_hrs=0;
- $total = 0;
- if($time_type == 'hrs')
- {
- //if($mins>=60):
- // $ext_mns = floor($mins/60);
- //endif;
- $total = $hrs;
- }
- else
- {
- if($hrs>0):
- $ext_hrs = $hrs*60;
- endif;
- $total = $mins + $ext_hrs;
- }
- return $total;
- }
- private function computeAbsent($time_setup,$time_list,$date)
- {
- $total_absent=0;
- //get total absent
- for($i=0;$i<count($time_setup);$i++)
- {
- if(!isset($time_list[$time_setup[$i]['start_time']]) || count($time_list[$time_setup[$i]['start_time']])<2 || count($time_list)==0)
- {
- $time_setup_start = $time_setup[$i]['start_time'];
- $time_setup_end = $time_setup[$i]['end_time'];
- $total_absent += $this->collegeAccumulatedAbsent($time_setup_start,$time_setup_end,$date);
- $this->_count_absent = $this->_count_absent + 1;
- }
- }
- return $total_absent;
- }
- private function computeTimeRecord($time_list,$time_setup,$date,$grace_period)
- {
- $data['reghrs'] = 0;
- $data['late'] = 0;
- if(count($time_list)>0)
- {
- for($i=0;$i<count($time_setup);$i++)
- {
- $time_setup_start=$time_setup[$i]['start_time'];
- $time_setup_end=$time_setup[$i]['end_time'];
- if(isset($time_list[$time_setup_start]))
- {
- if(count($time_list[$time_setup_start])>1)
- {
- $start_time = $time_list[$time_setup_start][0]['access_time'];
- $end_time = $time_list[$time_setup_start][count($time_list[$time_setup_start])-1]['access_time'];
- $reghrs = $this->collegeAccumulatedTime($time_list,$time_setup_start,$time_setup_end,$date,$start_time,$end_time);
- $late = $this->collegeAccumulatedLate($start_time,$end_time,$time_setup_start,$date,$grace_period);
- $data['reghrs'] = $data['reghrs'] + $reghrs;
- $data['late'] = $data['late'] + $late;
- }
- else
- {
- $data['reghrs'] = 0;
- $data['late'] = 0;
- }
- }
- }
- }
- else
- {
- $data['reghrs'] = 0;
- $data['late'] = 0;
- }
- return $data;
- }
- private function computeUndertime($time_setup,$time_list,$date)
- {
- $total_undertime="0";
- //get total Undertime
- for($i=0;$i<count($time_setup);$i++)
- {
- if(isset($time_list[$time_setup[$i]['start_time']]))
- {
- $time_setup_start = $time_setup[$i]['start_time'];
- $time_setup_end = $time_setup[$i]['end_time'];
- $last_access_time = $time_list[$time_setup[$i]['start_time']][count($time_list[$time_setup[$i]['start_time']])-1]['access_time'];
- if(strtotime($last_access_time)<strtotime($time_setup_end)):
- $total_undertime += $this->collegeAccumulatedUndertime($last_access_time,$time_setup_end,$date);
- $this->_count_undertime = $this->_count_undertime + 1;
- endif;
- }
- }
- return $total_undertime;
- }
- private function collegeAccumulatedUndertime($time_setup_start,$time_setup_end,$date)
- {
- $undertime = $this->ConverterModel->dateTimeComuptation($time_setup_start,$time_setup_end,$date);
- $total_undertime = $this->sumTotalTime($undertime,'mins');
- return $total_undertime;
- }
- private function collegeAccumulatedAbsent($time_setup_start,$time_setup_end,$date)
- {
- $absent = $this->ConverterModel->dateTimeComuptation($time_setup_start,$time_setup_end,$date);
- $total_absent = $this->sumTotalTime($absent,'hrs');
- return $total_absent;
- }
- private function collegeAccumulatedLate($start_time,$end_time,$start,$date,$grace_period)
- {
- $late = "00.00";
- if(strtotime(date('H:i',strtotime($start_time)))>strtotime(date('H:i',strtotime($start." +'.$grace_period.'mins"))))
- {
- $late = $this->ConverterModel->dateTimeComuptation($start,$start_time,$date);
- $this->_count_late = $this->_count_late + 1;
- }
- $total_late = $this->sumTotalTime($late,'mins');
- return $total_late;
- }
- private function gracePeriodData()
- {
- $num_rows = $this->SmartEntryModel->checkGracePeriod();
- if($num_rows>0)
- {
- $row = $this->SmartEntryModel->getGracePeriodData();
- $grace_period['gp_time'] = $row->grace_period_time;
- $grace_period['gp_id'] = $row->id;
- }
- else
- {
- $grace_period['gp_time'] = 0;
- $grace_period['gp_id'] = '';
- }
- return $grace_period;
- }
- private function collegeAccumulatedTime($time_list,$start,$end,$date,$start_time,$end_time)
- {
- if(strtolower($start_time)<=strtotime($start)):
- $start_time = $start;
- endif;
- if(strtolower($start_time)>=strtotime($end)):
- $end_time = $end;
- endif;
- if($start_time!=''||$end_time!=''):
- $this->_count_present = $this->_count_present + 1;
- endif;
- $total_time = $this->ConverterModel->dateTimeComuptation($start_time,$end_time,$date);
- $total_time = $this->sumTotalTime($total_time,'hrs');
- //computer break
- $break = $this->getBreakReturn($time_list,'3',$start);
- $return = $this->getBreakReturn($time_list,'4',$start);
- if($break!='' && $return!='')
- {
- $total_break = $this->ConverterModel->dateTimeComuptation($break,$return,$date);
- $total_break = $this->sumTotalTime($total_break,'hrs');
- }
- else
- {
- $total_break = 0;
- }
- $total = max($total_time - $total_break,0);
- return $total;
- }
- private function showTimeSelector($time,$type)
- {
- $time_keeper = '';
- $time_container = explode('.',$time);
- if($type=='hrs')
- {
- $time_keeper = $time_container[0];
- }
- else
- {
- $time_keeper = $time_container[1];
- }
- return $time_keeper;
- }
- private function getBreakReturn($time_list,$type,$start_time)
- {
- $drd='';
- for($i=0;$i<count($time_list[$start_time]);$i++)
- {
- if($time_list[$start_time][$i]['access_type']==$type):
- $drd[] = $time_list[$start_time][$i]['access_time'];
- endif;
- }
- if($type=="3")
- {
- if(isset($drd[0]))
- {
- $drd=$drd[0];
- }
- }
- else
- {
- if(isset($drd[count($drd)-1]))
- {
- $drd=$drd[count($drd)-1];
- }
- }
- return $drd;
- }
- private function recordEmployeeTime($emp_no,$date)
- {
- $this->load->model('ScheduleModel');
- $time_collector = array();
- $index = 0;
- $index_2 = 0;
- $day = $this->selectDay($date);
- $response = $this->ScheduleModel->getEmployeeTimeList($emp_no,$day);
- if($response->num_rows()>0)
- {
- foreach($response->result() as $time)
- {
- $decode = json_decode($time->time_list);
- for($i=0;$i<count($decode);$i++)
- {
- if(($i%2)==0)
- {
- $data['start'][] = $decode[$i];
- }
- else
- {
- $data['end'][] = $decode[$i];
- }
- }
- }
- for($x=0;$x<count($data['start']);$x++)
- {
- $time_collector[] = array(
- 'start_time' => $data['start'][$x],
- 'end_time' => $data['end'][$x]
- );
- }
- }
- return $time_collector;
- }
- private function selectDay($date)
- {
- $day = date("l",strtotime($date));
- $convert='';
- switch($day)
- {
- case "Monday" : $convert="1"; break;
- case "Tuesday" : $convert="2"; break;
- case "Wednesday" : $convert="3"; break;
- case "Thursday" : $convert="4"; break;
- case "Friday" : $convert="5"; break;
- case "Saturday" : $convert="6"; break;
- case "Sunday" : $convert="7"; break;
- }
- return $convert;
- }
- private function reportContent($employee_id,$fname,$date_start,$date_end,$minitial,$lname,$group,$department,$show_array,$show_department,$show_remarks,$arrange_by_1,$arrange_by_2,$report_type,$emp_type,$emp_position)
- {
- $data_holder = array();
- $data_container = array();
- $data_container[] = array('Daily Time Record');
- $data_container[] = array('Start Date: ', date('M d Y',strtotime($date_start)));
- $data_container[] = array('End Date: ', date('M d Y',strtotime($date_end)));
- $data_container[] = array('');
- $htitle = '';
- $html = '';
- $emp_list_response = $this->SmartEntryModel->employeeList2($employee_id,$fname,$minitial,$lname,$group,$department,$arrange_by_1,$arrange_by_2,$emp_type,$emp_position);
- $iter = 0;
- foreach($emp_list_response->result() as $emp_list)
- {
- $emp_no = $emp_list->employee_student_no;
- $header = array('Name: ',strtoupper($emp_list->lname.", ".$emp_list->fname." ".$emp_list->minitial));
- //echo $emp_no." | ".$emp_list->lname.", ".$emp_list->fname." ".$emp_list->minitial."<br>";
- $data_container[] = $header;
- $department_name = $this->getDepartment($emp_list);
- $classification_name = $this->getClassification($emp_list);
- $department_label = $this->departmentLabel($emp_list,$show_department,$department_name);
- $hdepartment = array("Employee ID: ",$emp_no,"Department: ",$department_name,'Classification:',$classification_name);
- $data_container[] = $hdepartment;
- $result = $this->SmartEntryModel->getAllAccessRecords2($emp_no,$date_start,$date_end);
- if($show_array[5]=="on")
- {
- $subject_header = $this->headerLengthDisplay($emp_no,$date_start,$date_end,$result);
- }
- else
- {
- $subject_header = array();
- }
- $extension_label = $this->extensionLabel($show_array,$show_remarks);
- if($show_array[count($show_array)-1]=="on" && $show_array[count($show_array)-2]=="on")
- {
- $htitle = array_merge(array_merge(array('Date'),$subject_header),$extension_label);
- }
- else if($show_array[count($show_array)-1]=="on")
- {
- $htitle = array_merge(array('Date'),$extension_label);
- }
- else if($show_array[count($show_array)-2]=="on")
- {
- $htitle = array_merge(array('Date'),$subject_header);
- }
- $data_container[] = $htitle;
- $dates = $this->ConverterModel->DatePeriod_start_end($date_start,$date_end);
- if($result->num_rows()>0)
- {
- foreach($dates as $date)
- {
- $total_report_list = $this->computeCollegeRecord($emp_no,$date,$result,$emp_list->message);
- //if($this->_count_present==0&&$this->_count_absent==0&&$this->_count_late==0&&$this->_count_undertime==0&&$this->_count_overload==0):
- // $this->_count_absent=1;
- //endif;
- $count_container = array($this->_count_present,$this->_count_absent,$this->_count_late,$this->_count_undertime,$emp_list->message,$this->_count_overload);
- if($show_array[count($show_array)-2]=="on")
- {
- $data_rows = $this->attendance($emp_no,$date,$emp_list->division,$show_array,$report_type,$result);
- if($show_array[count($show_array)-1]=="on")
- {
- $total_time_list = array_merge($this->bindFields($data_rows,$subject_header));
- }
- else
- {
- $total_time_list = array();
- }
- $data_body = array_merge(array_merge(array_merge(array(date('M d Y',strtotime($date))),$data_rows),$total_time_list));
- if($show_array[5]=="on")
- {
- $data_body = array_merge($data_body,$count_container);
- }
- else
- {
- $data_body = array_merge(array(date('M d Y',strtotime($date))),$count_container);
- }
- }
- else
- {
- $this->attendance($emp_no,$date,$emp_list->division,$show_array,$report_type,$result);
- $data_body = array_merge(array(date('M d Y',strtotime($date))),$this->_total_list);
- }
- $data_container[] = $data_body;
- $this->_total_list = array();
- $this->_count_absent=0;
- $this->_count_late=0;
- $this->_count_present=0;
- $this->_count_undertime=0;
- $this->_count_overload=0;
- }
- }
- else
- {
- foreach($dates as $date)
- {
- if($show_array[count($show_array)-2]=="on")
- {
- if($show_array[5]=="on")
- {
- $data_container[] = array(date('M d Y',strtotime($date)),'','','','',0,1,0,0,'',0);
- }
- else
- {
- $data_container[] = array(date('M d Y',strtotime($date)),0,1,0,0,'',0);
- }
- }
- else
- {
- $data_container[] = array(date('M d Y',strtotime($date)),'','','','');
- }
- }
- }
- //$a= $iter/$emp_list_response->num_rows();
- //echo "Progress: ".($a * 100)."%<br>";
- //$this->session->set_userdata('progress',($a * 100).'%');
- $this->_container = '';
- $iter++;
- }
- //echo "Progress: 100%<br>";
- //$this->session->set_userdata('progress',($a * 100).'%');
- //echo "<pre>".json_encode($data_container,JSON_PRETTY_PRINT)."</pre>";
- $response = $this->generateCsvFile('report.csv',$data_container);
- return 'report.csv';
- }
- private function getDepartment($emp_list)
- {
- $check_department = $this->SmartEntryModel->checkDepartmentNameEmp($emp_list->department_id);
- if($check_department==0)
- {
- $department_name = '';
- }
- else
- {
- $department_name = $this->SmartEntryModel->getDepartmentNameEmp($emp_list->department_id);
- }
- return $department_name;
- }
- private function getClassification($emp_list)
- {
- $check_classification = $this->SmartEntryModel->checkClassificationNameEmp($emp_list->classification_id);
- if($check_classification==0)
- {
- $classification_name = '';
- }
- else
- {
- $classification_name = $this->SmartEntryModel->getClassificationNameEmp($emp_list->classification_id);
- }
- return $classification_name;
- }
- public function loading()
- {
- $session_progress = $this->session->userdata('progress');
- echo 'Progress: '.($session_progress==''? '0%':$session_progress);
- }
- private function generateCsvFile($filename,$data)
- {
- $dir = 'download/';
- if(!is_dir($dir)):
- mkdir('download');
- endif;
- $fp = fopen($_SERVER['DOCUMENT_ROOT'].'/jru/'.$dir.$filename,'w+');
- foreach($data as $key=>$val)
- {
- $array = (array) $val;
- fputcsv($fp,$array);
- }
- fclose($fp);
- return 'success';
- }
- private function departmentLabel($emp_list,$show_department,$department_name)
- {
- if($show_department=="on"){
- $department_label[] = '';
- $department_label[] = 'Department:';
- $department_label[] = $department_name;
- }else{
- $department_label[] = '';
- }
- return $department_label;
- }
- private function extensionLabel($show_array,$show_remarks)
- {
- $extension_label = $this->extensionHeader($show_array,$show_remarks);
- return $extension_label;
- }
- private function footerTotal($subject_header,$show_array)
- {
- $footer = array();
- $footer_total = array();
- for($n=0;$n<count($subject_header);$n++)
- {
- $footer_total[] = '';
- }
- if($show_array[0]=="on"):
- $footer[] = $this->_total_time;
- endif;
- if($show_array[1]=="on"):
- $footer[] = $this->_total_late;
- endif;
- if($show_array[2]=="on"):
- $footer[] = $this->_undertime;
- endif;
- if($show_array[3]=="on"):
- $footer[] = $this->_overload;
- endif;
- if($show_array[4]=="on"):
- $footer[] = $this->_total_absent;
- endif;
- $footertitle = array_merge(array_merge(array(""),$footer_total),$footer);
- return $footertitle;
- }
- private function hederLayout($emp_list,$date_start,$date_end)
- {
- $header_label[] = "Time In";
- $header_label[] = "Break";
- $header_label[] = "Return";
- $header_label[] = "Time Out";
- return $header_label;
- }
- private function configBreakTime($record,$break_type)
- {
- $time_container = array();
- $mod_value = ($break_type=='break'? 1 : 2);
- $flag=0;
- for($i=0;$i<count($record);$i++)
- {
- $mod = $i%4;
- if($mod==$mod_value):
- if($flag==0):
- $time_container[] = $record[$i];
- $flag=1;
- endif;
- if(isset($record[$i+1]))
- {
- if($record[$i+1]!=''):
- $flag=0;
- endif;
- }
- if($break_type=='break'):
- if(isset($record[$i+2]))
- {
- if($record[$i+2]!=''):
- $flag=0;
- endif;
- }
- endif;
- endif;
- }
- return $time_container;
- }
- private function attendance($emp_no,$date,$department,$show_array,$report_type,$result_access_time)
- {
- $start_container = array();
- $end_container = array();
- $overload_container_in = array();
- $overload_container_out = array();
- $record_total_list = array();
- $response = $this->SmartEntryModel->getTimeSetup($department);
- if($response->num_rows()==1)
- {
- $record = $this->showTimeBody($result_access_time,$date);
- $break = $this->configBreakTime($record,'break');
- $return = $this->configBreakTime($record,'return');
- if(isset($return[count($return)-1]) && isset($break[0]))
- {
- if($return[count($return)-1]!='' && $break[0]!='')
- {
- $accumulated_break = $this->accumulatedTime($break[0],$return[count($return)-1],$date,$emp_no);
- }
- else
- {
- $accumulated_break = "00.00";
- }
- }
- else
- {
- $accumulated_break = "00.00";
- }
- foreach($response->result() as $time_record)
- {
- $mts = strtotime($time_record->start_time);
- $mte = strtotime($time_record->end_time);
- if(count($record)>1)
- {
- for($i=0;$i<count($record);$i++)
- {
- $mod_in = $i%4;
- if($mod_in==0)
- {
- if(strtotime($record[$i])>=$mts && strtotime($record[$i])<=$mte){
- $start_container[] = $record[$i];
- }else if($record[$i]!=''){
- $overload_container_in[] = $record[$i];
- }
- }
- else if($mod_in==3)
- {
- if(strtotime($record[$i])>=$mts && strtotime($record[$i])<=$mte){
- $end_container[] = $record[$i];
- }else if($record[$i]!=''){
- $overload_container_out[] = $record[$i];
- }
- }
- }
- $process_time_in = (isset($start_container[0])?$start_container[0]:'');
- $process_time_out = (isset($end_container[count($end_container)-1])?$end_container[count($end_container)-1]:'');
- if(strtotime($process_time_out)>strtotime($time_record->end_time)):
- $process_time_out = $time_record->end_time;
- endif;
- $process_overload_in = (isset($overload_container_in[0])?$overload_container_in[0]:'');
- $process_overload_out = (isset($overload_container_out[count($overload_container_out)-1])?$overload_container_out[count($overload_container_out)-1]:'');
- if($process_time_in!='' || $process_time_out!='')
- {
- $accumulated_time = $this->accumulatedTime($process_time_in,$process_time_out,$date,$emp_no);
- if($process_overload_in!=''&&$process_overload_out!='')
- {
- $accumulated_overload = $this->accumulatedTime($overload_container_in[0],$overload_container_out[count($overload_container_out)-1],$date,$emp_no);
- }
- else
- {
- $accumulated_overload = "00.00";
- }
- if($show_array[0]=="on"):
- if($process_time_out!='')
- {
- if($accumulated_break!="00.00")
- {
- $accumulated_time = $this->ConverterModel->subTractBreakTime($accumulated_break,$accumulated_time);
- $this->_total_list[] = $accumulated_time;
- }
- else
- {
- $this->_total_list[] = $accumulated_time;
- }
- $this->_total_time = $this->ConverterModel->sumTime($this->_total_time,$accumulated_time);
- }
- else
- {
- $this->_total_list[] = "00.00";
- }
- endif;
- if($show_array[1]=="on"):
- if($process_time_in!='')
- {
- $p_time_late = strtotime(date("h:i A",strtotime($process_time_in." -".$time_record->grace_period." mins")));
- if($p_time_late>strtotime($time_record->start_time))
- {
- $accumulated_late = $this->accumulatedTime(date("h:i A",$p_time_late),$time_record->start_time,$date,$emp_no);
- $this->_total_list[] = $accumulated_late;
- $this->_total_late = $this->ConverterModel->sumTime($this->_total_late,$accumulated_late);
- }
- else
- {
- $this->_total_list[] = "00.00";
- }
- }
- else
- {
- $this->_total_list[] = "00.00";
- }
- endif;
- if($show_array[2]=="on"):
- if($process_time_out!='')
- {
- if(strtotime($process_time_out)<strtotime($time_record->end_time))
- {
- $accumulated_undertime = $this->accumulatedTime($process_time_out,$time_record->end_time,$date,$emp_no);
- $this->_total_list[] = $accumulated_undertime;
- $this->_undertime = $this->ConverterModel->sumTime($this->_undertime,$accumulated_undertime);
- }
- else
- {
- $this->_total_list[] = "00.00";
- }
- }
- else
- {
- $this->_total_list[] = "00.00";
- }
- endif;
- if($show_array[3]=="on"):
- if($process_overload_out!='' || $process_overload_in !='')
- {
- $this->_total_list[] = $accumulated_overload;
- $this->_overload = $this->ConverterModel->sumTime($this->_overload,$accumulated_overload);
- }
- else
- {
- $this->_total_list[] = "00.00";
- }
- endif;
- if($show_array[4]=="on"):
- $this->_total_list[] = "00.00";
- endif;
- }
- else
- {
- if($show_array[0]=="on"):
- $this->_total_list[] = "00.00";
- endif;
- if($show_array[1]=="on"):
- $this->_total_list[] = "00.00";
- endif;
- if($show_array[2]=="on"):
- $this->_total_list[] = "00.00";
- endif;
- if($show_array[3]=="on"):
- $this->_total_list[] = "00.00";
- endif;
- if($show_array[4]=="on"):
- $accumulated_absent = $this->accumulatedTime($time_record->start_time,$time_record->end_time,$date,$emp_no);
- //echo "Absent: ".$this->accumulatedTime($time_record->start_time,$time_record->end_time,$date,$emp_no)."<br>";
- $this->_total_list[] = $accumulated_absent;
- $this->_total_absent = $this->ConverterModel->sumTime($this->_total_absent,$accumulated_absent);
- endif;
- }
- }
- else
- {
- if($show_array[0]=="on"):
- $this->_total_list[] = "00.00";
- endif;
- if($show_array[1]=="on"):
- $this->_total_list[] = "00.00";
- endif;
- if($show_array[2]=="on"):
- $this->_total_list[] = "00.00";
- endif;
- if($show_array[3]=="on"):
- $this->_total_list[] = "00.00";
- endif;
- if($show_array[4]=="on"):
- $accumulated_absent = $this->accumulatedTime($time_record->start_time,$time_record->end_time,$date,$emp_no);
- $this->_total_list[] = $accumulated_absent;
- $this->_total_absent = $this->ConverterModel->sumTime($this->_total_absent,$accumulated_absent);
- endif;
- }
- }
- }
- else
- {
- $record = $this->showTimeBody($result_access_time,$date);
- }
- return $record;
- }
- private function timeSummary($record)
- {
- $time = array();
- $flag=0;
- for($i=0;$i<count($record);$i++)
- {
- $iter = $i;
- $mod = $i%2;
- if($mod==1)
- {
- if(isset($record[$i+1]))
- {
- if($flag==0)
- {
- if($i==1)
- {
- $time[] = $record[$i-1];
- $flag=1;
- }
- }
- if($record[$i]!="" && $record[$i+1]!="")
- {
- $time[] = $record[$i];
- $time[] = $record[$i+1];
- $flag=0;
- }
- }
- else
- {
- if(count($record)==2)
- {
- $time[] = $record[$i-1];
- $time[] = $record[$i];
- }
- else
- {
- $time[] = $record[$i];
- }
- }
- }
- }
- return $time;
- }
- private function removeNullValueArray($array)
- {
- $data_container = array();
- for($i=0;$i<count($array);$i++)
- {
- if($array[$i] != '')
- {
- $data_container[] = $array[$i];
- }
- }
- return $data_container;
- }
- private function showTimeBody($result_access_time,$date)
- {
- $time_type_container = array();
- foreach($result_access_time->result() as $access_info)
- {
- if($access_info->server_created_date==$date):
- $time_type_container[] = array(
- 'access_time' => date('h:i A',strtotime($access_info->access_time)),
- 'access_type' => $access_info->access_type
- );
- endif;
- }
- $time_content_setup = $this->timeContentSetup($time_type_container);
- return $time_content_setup;
- }
- private function timeContentSetup($time_type_container)
- {
- //echo "<hr><pre>".json_encode($time_type_container,JSON_PRETTY_PRINT)."</pre><hr>";
- if(count($time_type_container) == 0)
- {
- $time_body[] = '';
- }
- else
- {
- for($i=0;$i<count($time_type_container);$i++)
- {
- switch($time_type_container[$i]['access_type'])
- {
- case "1" :
- $time_body[] = $time_type_container[$i]['access_time'];
- if(isset($time_type_container[$i+1])):
- if($time_type_container[$i+1]['access_type']==2):
- $time_body[] = '';
- $time_body[] = '';
- endif;
- if($time_type_container[$i+1]['access_type']==4):
- $time_body[] = '';
- endif;
- if($time_type_container[$i+1]['access_type']==1):
- $time_body[] = '';
- $time_body[] = '';
- $time_body[] = '';
- endif;
- else:
- $time_body[] = '';
- $time_body[] = '';
- $time_body[] = '';
- endif;
- break;
- case "2" :
- if(!isset($time_type_container[$i-1])):
- $time_body[] = '';
- $time_body[] = '';
- $time_body[] = '';
- endif;
- $time_body[] = $time_type_container[$i]['access_time'];
- if(isset($time_type_container[$i+1])):
- if($time_type_container[$i+1]['access_type']==2):
- $time_body[] = '';
- $time_body[] = '';
- $time_body[] = '';
- endif;
- if($time_type_container[$i+1]['access_type']==3):
- $time_body[] = '';
- endif;
- if($time_type_container[$i+1]['access_type']==4):
- $time_body[] = '';
- $time_body[] = '';
- endif;
- endif;
- break;
- case "3" :
- if(isset($time_type_container[$i-1])):
- if($time_type_container[$i-1]['access_type']!=1):
- $time_body[] = '';
- endif;
- else:
- $time_body[] = '';
- endif;
- $time_body[] = $time_type_container[$i]['access_time'];
- //if(isset($time_type_container[$i+1])):
- // if($time_type_container[$i+1]['access_type']!=4):
- // $time_body[] = 'return';
- // endif;
- //else:
- // $time_body[] = 'return';
- //endif;
- //
- if(isset($time_type_container[$i+1])):
- if($time_type_container[$i+1]['access_type']==2):
- $time_body[] = '';
- endif;
- if($time_type_container[$i+1]['access_type']==3):
- $time_body[] = '';
- $time_body[] = '';
- endif;
- else:
- $time_body[] = '';
- endif;
- break;
- case "4" :
- if(isset($time_type_container[$i-1]))
- {
- if($time_type_container[$i-1]['access_type']==2):
- $time_body[] = '';
- $time_body[] = '';
- endif;
- }
- else
- {
- if(isset($time_type_container[$i-1])):
- if($time_type_container[$i-1]['access_type']==1):
- $time_body[] = '';
- endif;
- else:
- $time_body[] = '';
- endif;
- if(isset($time_type_container[$i-1])):
- if($time_type_container[$i-1]['access_type']!=3):
- $time_body[] = '';
- endif;
- else:
- $time_body[] = '';
- endif;
- }
- if(isset($time_type_container[$i-1])):
- if($time_type_container[$i-1]['access_type']==4):
- $time_body[] = '';
- $time_body[] = '';
- endif;
- endif;
- $time_body[] = $time_type_container[$i]['access_time'];
- if(isset($time_type_container[$i+1])):
- if($time_type_container[$i+1]['access_type']!=2):
- $time_body[] = '';
- endif;
- else:
- $time_body[] = '';
- endif;
- break;
- }
- }
- }
- return $time_body;
- }
- private function checkTimeInFormat($access_container,$i)
- {
- $time_body = array();
- if($access_container[$i+1]['access_type']==2):
- $time_body[] = '';
- $time_body[] = '';
- endif;
- if($access_container[$i+1]['access_type']==4):
- $time_body[] = '';
- endif;
- return $time_body;
- }
- private function checkTimeOutFormat($access_container,$i)
- {
- $time_body = array();
- if(isset($access_container[$i-1]))
- {
- if($access_container[$i-1]['access_type']==2):
- $time_body[] = '';
- $time_body[] = '';
- endif;
- if($access_container[$i+1]['access_type']==4):
- $time_body[] = '';
- endif;
- }
- else
- {
- $time_body[] = '';
- $time_body[] = '';
- $time_body[] = '';
- }
- return $time_body;
- }
- private function headerLengthDisplay($emp_no,$date_start,$date_end,$result)
- {
- $response = $this->getAccessType($emp_no,$date_start,$date_end,$result);
- $max = 0;
- $max_iter = 0;
- $header = array();
- for($i=0;$i<count($response);$i++)
- {
- if(count($response[$i])>=$max):
- $max_iter = $i;
- $max=count($response[$i]);
- endif;
- }
- if(count($response[$max_iter])>0)
- {
- $iter =0;
- for($x=0;$x<count($response[$max_iter]);$x++)
- {
- $access_type = $response[$max_iter][$x];
- switch($access_type)
- {
- case "1" :
- $header[] = "Time In";
- if(isset($response[$max_iter][$x+1])):
- if($response[$max_iter][$x+1]==2):
- $header[] = 'Break';
- $header[] = 'Return';
- endif;
- if($response[$max_iter][$x+1]==4):
- $header[] = 'Break';
- endif;
- if($response[$max_iter][$x+1]==1):
- $header[] = 'Break';
- $header[] = 'Return';
- $header[] = 'Time Out';
- endif;
- else:
- $header[] = 'Break';
- $header[] = 'Return';
- $header[] = 'Time Out';
- endif;
- break;
- case "2" :
- if(!isset($response[$max_iter][$x-1])):
- $header[] = 'Time In';
- $header[] = 'Break';
- $header[] = 'Return';
- endif;
- $header[] = "Time Out";
- if(isset($response[$max_iter][$x+1])):
- if($response[$max_iter][$x+1]==2):
- $header[] = 'Time In';
- $header[] = 'Break';
- $header[] = 'Return';
- endif;
- if($response[$max_iter][$x+1]==3):
- $header[] = 'Time In';
- endif;
- if($response[$max_iter][$x+1]==4):
- $header[] = 'Time In';
- $header[] = 'Break';
- endif;
- endif;
- break;
- case "3" :
- if(isset($response[$max_iter][$x-1])):
- if($response[$max_iter][$x-1]!=1):
- $header[] = 'Time In';
- endif;
- else:
- $header[] = 'Time In';
- endif;
- $header[] = "Break";
- //if(isset($time_type_container[$i+1])):
- // if($time_type_container[$i+1]['access_type']!=4):
- // $time_body[] = 'return';
- // endif;
- //else:
- // $time_body[] = 'return';
- //endif;
- //
- if(isset($response[$max_iter][$x+1])):
- if($response[$max_iter][$x+1]==2):
- $header[] = 'Return';
- endif;
- if($response[$max_iter][$x+1]==3):
- $header[] = 'Return';
- $header[] = 'Time Out';
- endif;
- else:
- $header[] = 'Return';
- endif;
- break;
- case "4" :
- if(isset($response[$max_iter][$x-1]))
- {
- if($response[$max_iter][$x-1]==2):
- $header[] = 'Time In';
- $header[] = 'Break';
- endif;
- }
- else
- {
- if(isset($response[$max_iter][$x-1])):
- if($response[$max_iter][$x-1]==1):
- $header[] = 'Time In';
- endif;
- else:
- $header[] = 'Time In';
- endif;
- if(isset($response[$max_iter][$x-1])):
- if($response[$max_iter][$x-1]!=3):
- $header[] = 'Break';
- endif;
- else:
- $header[] = 'Break';
- endif;
- }
- if(isset($response[$max_iter][$x-1])):
- if($response[$max_iter][$x-1]==4):
- $header[] = 'Time In';
- $header[] = 'Break';
- endif;
- endif;
- $header[] = "Return";
- if(isset($response[$max_iter][$x+1])):
- if($response[$max_iter][$x+1]!=2):
- $header[] = 'Time Out';
- endif;
- else:
- $header[] = 'Time Out';
- endif;
- break;
- }
- }
- }
- else
- {
- $header[] = 'Time In';
- $header[] = 'Break';
- $header[] = 'Return';
- $header[] = 'Time Out';
- }
- return $header;
- }
- private function getAccessType($emp_no,$date_start,$date_end,$result)
- {
- $iter = 1;
- $previous_type = '';
- $header = array();
- $_container = array();
- $dates = $this->ConverterModel->DatePeriod_start_end($date_start,$date_end);
- foreach($dates as $date)
- {
- $date = date('Y-m-d',strtotime($date));
- if($result->num_rows()>0):
- foreach($result->result() as $logs)
- {
- if($logs->server_created_date == $date):
- $_container[] = $logs->access_type;
- endif;
- }
- endif;
- $this->_container[] = $_container;
- $_container = array();
- }
- return $this->_container;
- }
- private function bindFields($data_rows,$subject_header)
- {
- for($i=0;$i<count($data_rows);$i++)
- {
- if(isset($subject_header[$i]))
- {
- unset($subject_header[$i]);
- }
- }
- return $this->changeArrayValue($subject_header,$data_rows);
- }
- private function changeArrayValue($subject_header,$data_rows)
- {
- $iter = count($subject_header)+count($data_rows);
- for($i=count($data_rows);$i<$iter;$i++)
- {
- if($i<$iter)
- {
- $subject_header[$i] = "";
- }
- }
- return $subject_header;
- }
- public function generateRawData()
- {
- $employee_id = $this->input->get('device_number');
- $fname = $this->input->get('device_name');
- $minitial = $this->input->get('minitial');
- $lname = $this->input->get('lname');
- $group = $this->input->get('group');
- $emp_position = $this->input->get('emp_position');
- $emp_type = $this->input->get('emp_type');
- $department = $this->input->get('department');
- $arrange_by_1 = $this->input->get('arrange_by_1');
- $arrange_by_2 = $this->input->get('arrange_by_2');
- $daterange = $this->input->get('daterange');
- if($daterange==''):
- $date_end = date('Y-m-d');
- $date_end = date('Y-m-d',strtotime($date_end));
- $date_start = date('Y-m-d',strtotime($date_end." -30 days"));
- else:
- $date = explode('-',$daterange);
- $date_start = date('Y-m-d',strtotime(trim($date[0])));
- $date_end = date('Y-m-d',strtotime(trim($date[1])));
- endif;
- $content = '';
- $result = $this->SmartEntryModel->getAllEmployeeRecords($employee_id,$fname,$date_start,$date_end,$minitial,$lname,$group,$department,$arrange_by_1,$arrange_by_2,$emp_type,$emp_position);
- // output headers so that the file is downloaded rather than displayed
- header('Content-Type: text/plain; charset=utf-8');
- header('Content-Disposition: attachment; filename='.date('mdY').'.txt');
- foreach($result->result() as $records)
- {
- //$content .= $records->employee_student_no.",".date('m/d/Y',strtotime($records->server_created_date))." ".$records->access_time." ".$records->access_type." ".
- //$records->flag.","."0".date('mdY',strtotime($records->server_created_date)).str_replace(':','',$records->access_type).$records->employee_student_no.$this->accessTypeFormat($records->access_type)."\r\n";
- $content .= "01".date('dmy',strtotime($records->server_created_date)).date('Hi',strtotime($records->access_time)).$records->employee_student_no.$this->accessTypeFormat($records->access_type)."\r\n";
- }
- echo $content;
- }
- private function accessTypeFormat($access_type)
- {
- $access_format= '';
- switch($access_type)
- {
- case "1" : $access_format = ">"; break;
- case "2" : $access_format = "<"; break;
- case "3" : $access_format = "<"; break;
- case "4" : $access_format = ">"; break;
- }
- return $access_format;
- }
- //For applicable users only
- public function lateOrEarlyComing($time,$employee_id,$start_time)
- {
- $today = date('Y-m-d');
- if($time=='')
- {
- $time = "00.00";
- }
- else
- {
- if(strtotime($time) > strtotime($start_time))
- {
- $formated_time=$this->ConverterModel->dateTimeComuptation($start_time,$time,$today);
- $time = $formated_time;
- $this->_late += 1;
- }
- else
- {
- $time = "00.00";
- }
- }
- return $time;
- }
- private function accumulatedTime($start_time,$end_time,$date,$employee_id)
- {
- if($start_time=='' && $end_time=='')
- {
- $formated_time = "00.00";
- }
- else
- {
- $formated_time = $this->ConverterModel->dateTimeComuptation($start_time,$end_time,$date);
- }
- return $formated_time;
- }
- public function summaryExtensionHeader($show_array)
- {
- $header = array();
- if($show_array[0] == "on"):
- $header[] = 'Day Present';
- endif;
- if($show_array[1]=="on"):
- $header[] = 'Late';
- endif;
- if($show_array[2] == "on"):
- $header[] = 'Undertime';
- endif;
- if($show_array[3] == "on"):
- $header[] = 'Overload';
- endif;
- if($show_array[4]=="on"):
- $header[] = 'Day Absent';
- endif;
- return $header;
- }
- public function extensionHeader($show_array,$show_remarks)
- {
- $header = array();
- if($show_array[0] == "on"):
- $header[] = 'Present';
- endif;
- if($show_array[4]=="on"):
- $header[] = 'Absent';
- endif;
- if($show_array[1]=="on"):
- $header[] = 'Late';
- endif;
- if($show_array[2] == "on"):
- $header[] = 'Undertime';
- endif;
- if($show_remarks=="on"):
- $header[] = 'Remarks';
- endif;
- if($show_array[3] == "on"):
- $header[] = 'Overload';
- endif;
- return $header;
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement