Advertisement
Guest User

Untitled

a guest
May 21st, 2018
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 58.09 KB | None | 0 0
  1. <?php defined('BASEPATH') OR exit('No direct script access allowed');
  2.  
  3. class DownloadReport extends CI_Controller
  4. {
  5.     protected $_container = array();
  6.     protected $_total_list = array();
  7.     protected $_total_time = "00.00";
  8.     protected $_total_late= "00.00";
  9.     protected $_overload = "00.00";
  10.     protected $_undertime = "00.00";
  11.     protected $_total_absent= "00.00";
  12.     private $_count_late=0;
  13.     private $_count_absent=0;
  14.     private $_count_present=0;
  15.     private $_count_undertime=0;
  16.     private $_count_overload=0;
  17.    
  18.    
  19.     function __construct()
  20.     {
  21.         parent::__construct();
  22.         $this->load->model('SmartEntryModel');
  23.         $this->load->model('ConverterModel');
  24.     }
  25.    
  26.     public function generateReport()
  27.     {
  28.         ini_set('max_execution_time',0);
  29.         ini_set('memory_limit', '1024M');
  30.        
  31.         $employee_id = $this->input->post('device_number');
  32.         $fname = $this->input->post('device_name');
  33.         $minitial = $this->input->post('minitial');
  34.         $lname = $this->input->post('lname');
  35.         $group = $this->input->post('group');
  36.         $emp_position = $this->input->post('emp_position');
  37.         $emp_type = $this->input->post('emp_type');
  38.         $department = $this->input->post('department');
  39.         $arrange_by_1 = $this->input->post('arrange_by_1');
  40.         $arrange_by_2 = $this->input->post('arrange_by_2');
  41.         //show details
  42.         $hrs_work = $this->input->post('show_hours_work');
  43.         $late = $this->input->post('show_late');
  44.         $undertime = $this->input->post('show_undertime');
  45.         $overload = $this->input->post('show_overload');
  46.         $absent = $this->input->post('show_absent');
  47.         $show_department = $this->input->post('show_department');
  48.         $show_remarks = $this->input->post('show_remarks');
  49.         $show_time_sheet = $this->input->post('show_time_sheet');
  50.         $show_sub_total = $this->input->post('show_sub_total');
  51.         $classification = $this->input->post('show_classification');
  52.         $download_type = $this->input->post('download_type');
  53.         $summary = $this->input->post('summary');
  54.        
  55.         $report_type = "original_report";
  56.        
  57.         $show_array_result = array($hrs_work,$late,$undertime,$overload,$absent,$show_time_sheet,$show_sub_total,$classification,$show_department);
  58.        
  59.         $daterange = $this->input->post('daterange');
  60.        
  61.         if($daterange==''):
  62.            $date_end  = date('Y-m-d');
  63.            $date_end  = date('Y-m-d',strtotime('02/28/2018'));
  64.            $date_start = date('Y-m-d',strtotime('02/18/2018'));
  65.         else:
  66.             $date = explode('-',$daterange);
  67.             $date_start = date('Y-m-d',strtotime(trim($date[0])));
  68.             $date_end = date('Y-m-d',strtotime(trim($date[1])));
  69.         endif;
  70.        
  71.         if($download_type=='0')
  72.         {
  73.             $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);
  74.         }
  75.         else if($download_type=='1')
  76.         {
  77.             $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);
  78.         }
  79.         else if($download_type=='2')
  80.         {
  81.             $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);
  82.         }
  83.         else
  84.         {
  85.             redirect('smartentry/monthlyReport');
  86.         }
  87.        
  88.         echo '../download/'.$filename;
  89.     }
  90.    
  91.     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)
  92.     {
  93.         $data_container = array();
  94.         $data_holder=array();
  95.        
  96.         $emp_info = array('Emp ID', 'Emp Name', 'Date');
  97.        
  98.         if($show_array_result[count($show_array_result)-1]=="on"):
  99.             $department_S[]='Department';
  100.             $emp_info = array_merge($emp_info,$department_S);
  101.         endif;
  102.         if($show_array_result[count($show_array_result)-2]=="on"):
  103.             $classification_s[]='Classification';
  104.             $emp_info = array_merge($emp_info,$classification_s);
  105.         endif;
  106.        
  107.        
  108.         if($show_array_result[3]=="on"):
  109.             $overload_s[]='OverLoad (Hours)';
  110.             $emp_info = array_merge($emp_info,$overload_s);
  111.         endif;
  112.         $data_container[] = $emp_info;
  113.        
  114.         $html = '';
  115.         $emp_list_response = $this->SmartEntryModel->employeeList2($employee_id,$fname,$minitial,$lname,$group,$department,$arrange_by_1,$arrange_by_2,$emp_type,$emp_position);
  116.        
  117.         foreach($emp_list_response->result() as $emp_list)
  118.         {
  119.             $emp_no = $emp_list->employee_student_no;
  120.            
  121.             $department_name = $this->getDepartment($emp_list);
  122.             $classification_name = $this->getClassification($emp_list);
  123.            
  124.             $result = $this->SmartEntryModel->getAllAccessRecords2($emp_no,$date_start,$date_end);
  125.             $dates = $this->ConverterModel->DatePeriod_start_end($date_start,$date_end);
  126.            
  127.             if($result->num_rows()>0)
  128.             {
  129.                 foreach($dates as $date)
  130.                 {
  131.                     $time_record = $this->computeCollegeRecord($emp_no,$date,$result,$emp_list->message);
  132.                    
  133.                     $emp_data = array($emp_no,strtoupper($emp_list->lname.", ".$emp_list->fname." ".$emp_list->minitial),date('M d Y',strtotime($date)));
  134.                    
  135.                     if($show_array_result[count($show_array_result)-1]=="on"):
  136.                         $emp_data = array_merge($emp_data,array($department_name));
  137.                     endif;
  138.                     if($show_array_result[count($show_array_result)-2]=="on"):
  139.                         $emp_data = array_merge($emp_data,array($classification_name));
  140.                     endif;
  141.                    
  142.                     if($show_array_result[3]=="on"):
  143.                         $emp_data = array_merge($emp_data,array($time_record['overload']));
  144.                     endif;
  145.                     $data_body = $emp_data;
  146.                     $data_container[] = $data_body;
  147.                 }
  148.             }
  149.             else
  150.             {
  151.                 foreach($dates as $date)
  152.                 {
  153.                    
  154.                     $emp_data = array($emp_no,strtoupper($emp_list->lname.", ".$emp_list->fname." ".$emp_list->minitial),date('M d Y',strtotime($date)));
  155.                    
  156.                     if($show_array_result[count($show_array_result)-1]=="on"):
  157.                         $emp_data = array_merge($emp_data,array($department_name));
  158.                     endif;
  159.                     if($show_array_result[count($show_array_result)-2]=="on"):
  160.                         $emp_data = array_merge($emp_data,array($classification_name));
  161.                     endif;
  162.                    
  163.                     if($show_array_result[3]=="on"):
  164.                         $emp_data = array_merge($emp_data,array(0));
  165.                     endif;
  166.                     $data_body = $emp_data;
  167.                     $data_container[] = $data_body;
  168.                    
  169.                     $data_holder[] = $emp_no;
  170.                 }
  171.             }
  172.            
  173.         }
  174.        
  175.         $filename = 'substitution_report.csv';
  176.        
  177.         $response = $this->generateCsvFile($filename,$data_container);
  178.        
  179.         return $filename;
  180.     }
  181.    
  182.     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)
  183.     {
  184.         $data_container = array();
  185.         $data_holder=array();
  186.         $emp_info = array('Emp ID', 'Emp Name', 'Date');
  187.         $emp_info = $this->headerTimeDownload($show_array_result,$emp_info,$show_remarks);
  188.         $data_container[] = $emp_info;
  189.  
  190.         $html = '';
  191.         $emp_list_response = $this->SmartEntryModel->employeeList2($employee_id,$fname,$minitial,$lname,$group,$department,$arrange_by_1,$arrange_by_2,$emp_type,$emp_position);
  192.        
  193.         foreach($emp_list_response->result() as $emp_list)
  194.         {
  195.             $emp_no = $emp_list->employee_student_no;
  196.            
  197.            
  198.             $department_name = $this->getDepartment($emp_list);
  199.             $classification_name = $this->getClassification($emp_list);
  200.            
  201.             $result = $this->SmartEntryModel->getAllAccessRecords2($emp_no,$date_start,$date_end);
  202.             $dates = $this->ConverterModel->DatePeriod_start_end($date_start,$date_end);
  203.            
  204.             if($result->num_rows()>0)
  205.             {
  206.                 foreach($dates as $date)
  207.                 {
  208.                     $time_record = $this->computeCollegeRecord($emp_no,$date,$result,$emp_list->message);
  209.                     $emp_data = array($emp_no,strtoupper($emp_list->lname.", ".$emp_list->fname." ".$emp_list->minitial),date('M d Y',strtotime($date)));
  210.                    
  211.                     $emp_data = $this->timeKepper($show_array_result,$emp_data,$department_name,$classification_name,$time_record,$emp_list,$show_remarks);
  212.                    
  213.                     $data_body = $emp_data;
  214.                     $data_container[] = $data_body;
  215.                 }
  216.             }
  217.             else
  218.             {
  219.                 foreach($dates as $date)
  220.                 {
  221.                     $emp_data = array($emp_no,strtoupper($emp_list->lname.", ".$emp_list->fname." ".$emp_list->minitial),date('M d Y',strtotime($date)));
  222.                    
  223.                     $emp_data = $this->timeKepperZero($show_array_result,$emp_data,$department_name,$classification_name,$show_remarks);
  224.                    
  225.                     $data_container[] = $emp_data;
  226.                    
  227.                     $data_holder[] = $emp_no;
  228.                 }
  229.             }
  230.            
  231.         }
  232.        
  233.         $filename = 'college_report.csv';
  234.        
  235.         $this->generateCsvFile($filename,$data_container);
  236.        
  237.         return $filename;
  238.     }
  239.    
  240.     private function timeKepper($show_array_result,$emp_data,$department_name,$classification_name,$time_record,$emp_list,$show_remarks)
  241.     {      
  242.         if($show_array_result[count($show_array_result)-1]=="on"):
  243.             $emp_data = array_merge($emp_data,array($department_name));
  244.         endif;
  245.        
  246.         if($show_array_result[count($show_array_result)-2]=="on"):
  247.             $emp_data = array_merge($emp_data,array($classification_name));
  248.         endif;
  249.        
  250.         if($show_array_result[0]=="on"):
  251.             $emp_data = array_merge($emp_data,array($time_record['reghrs']));
  252.         endif;
  253.        
  254.         if($show_array_result[4]=="on"):
  255.             $emp_data = array_merge($emp_data,array($time_record['absent']));
  256.         endif;
  257.        
  258.         if($show_array_result[1]=="on"):
  259.             $emp_data = array_merge($emp_data,array($time_record['late']));
  260.         endif;
  261.        
  262.         if($show_array_result[2]=="on"):
  263.             $emp_data = array_merge($emp_data,array($time_record['undertime']));
  264.         endif;
  265.        
  266.         if($show_remarks=="on"):
  267.             $emp_data = array_merge($emp_data,array($emp_list->message));
  268.         endif;
  269.        
  270.         if($show_array_result[3]=="on"):
  271.             $emp_data = array_merge($emp_data,array($time_record['overload']));
  272.         endif;
  273.        
  274.         return $emp_data;
  275.     }
  276.    
  277.     private function timeKepperZero($show_array_result,$emp_data,$department_name,$classification_name,$show_remarks)
  278.     {      
  279.         if($show_array_result[count($show_array_result)-1]=="on"):
  280.             $emp_data = array_merge($emp_data,array($department_name));
  281.         endif;
  282.        
  283.         if($show_array_result[count($show_array_result)-2]=="on"):
  284.             $emp_data = array_merge($emp_data,array($classification_name));
  285.         endif;
  286.        
  287.         if($show_array_result[0]=="on"):
  288.             $emp_data = array_merge($emp_data,array(0));
  289.         endif;
  290.        
  291.         if($show_array_result[4]=="on"):
  292.             $emp_data = array_merge($emp_data,array(0));
  293.         endif;
  294.        
  295.         if($show_array_result[1]=="on"):
  296.             $emp_data = array_merge($emp_data,array(0));
  297.         endif;
  298.        
  299.         if($show_array_result[2]=="on"):
  300.             $emp_data = array_merge($emp_data,array(0));
  301.         endif;
  302.        
  303.         if($show_remarks=="on"):
  304.             $emp_data = array_merge($emp_data,array(''));
  305.         endif;
  306.        
  307.         if($show_array_result[3]=="on"):
  308.             $emp_data = array_merge($emp_data,array(0));
  309.         endif;
  310.        
  311.         return $emp_data;
  312.     }
  313.    
  314.     private function headerTimeDownload($show_array_result,$emp_info,$show_remarks)
  315.     {
  316.         if($show_array_result[count($show_array_result)-1]=="on"):
  317.             $department_S[]='Department';
  318.             $emp_info = array_merge($emp_info,$department_S);
  319.         endif;
  320.        
  321.         if($show_array_result[count($show_array_result)-2]=="on"):
  322.             $classification_s[]='Classification';
  323.             $emp_info = array_merge($emp_info,$classification_s);
  324.         endif;
  325.        
  326.         if($show_array_result[0]=="on"):
  327.             $reghrs[]='RegHrs (Hours)';
  328.             $emp_info = array_merge($emp_info,$reghrs);
  329.         endif;
  330.        
  331.         if($show_array_result[4]=="on"):
  332.             $absent[]='Absent (Hours)';
  333.             $emp_info = array_merge($emp_info,$absent);
  334.         endif;
  335.        
  336.         if($show_array_result[1]=="on"):
  337.             $late[]='Late (Minutes)';
  338.             $emp_info = array_merge($emp_info,$late);
  339.         endif;
  340.        
  341.         if($show_array_result[2]=="on"):
  342.             $undertime[]='Under (Minutes)';
  343.             $emp_info = array_merge($emp_info,$undertime);
  344.         endif;
  345.        
  346.         if($show_remarks=="on"):
  347.             $remarks[]='Remarks';
  348.             $emp_info = array_merge($emp_info,$remarks);
  349.         endif;
  350.        
  351.         if($show_array_result[3]=="on"):
  352.             $overload_s[]='OverLoad (Hours)';
  353.             $emp_info = array_merge($emp_info,$overload_s);
  354.         endif;
  355.        
  356.         return $emp_info;
  357.     }
  358.    
  359.     private function employeeTimeCollector($emp_no,$date)
  360.     {
  361.         $this->load->model('ScheduleModel');
  362.         $time_collector = array();
  363.         $index = 0;
  364.         $index_2 = 0;
  365.         $day = $this->selectDay($date);
  366.         //echo json_encode($day)."<hr>";
  367.         $response = $this->ScheduleModel->getEmployeeTimeListReport($emp_no,$day);
  368.         if($response->num_rows()>0)
  369.         {
  370.             foreach($response->result() as $time)
  371.             {
  372.                 $decode = json_decode($time->time_list);
  373.                 for($i=0;$i<count($decode);$i++)
  374.                 {
  375.                     if(($i%2)==0)
  376.                     {
  377.                         $data['start'][] = $decode[$i];
  378.                     }
  379.                     else
  380.                     {
  381.                         $data['end'][] = $decode[$i];  
  382.                     }
  383.                 }
  384.             }
  385.            
  386.             for($x=0;$x<count($data['start']);$x++)
  387.             {
  388.                 $time_collector[] = array(
  389.                                                 'start_time' => $data['start'][$x],
  390.                                                 'end_time' => $data['end'][$x]
  391.                                             );
  392.             }
  393.         }
  394.        
  395.         return $time_collector;
  396.     }
  397.    
  398.     private function computeCollegeRecord($emp_id,$date,$result,$message)
  399.     {
  400.         $total_absent=0;
  401.         $total_undertime=0;
  402.         $overload_time_in = '';
  403.         $total_overload=0;
  404.        
  405.         $allowance = $this->getTimeAllowance($emp_id);
  406.         $grace_period = $this->getGracePeriod($emp_id);
  407.        
  408.         $time_setup = $this->employeeTimeCollector($emp_id,$date);
  409.         $time_list = array();
  410.        
  411.         $record_logs = array();
  412.        
  413.         if($result->num_rows()>0)
  414.         {
  415.             foreach($result->result() as $time)
  416.             {
  417.                 $access_time = date('H:i',strtotime($time->access_time));
  418.                 if($time->server_created_date==$date)
  419.                 {
  420.                     if(count($time_setup)>0)
  421.                     {
  422.                         $record_logs[] = array(
  423.                                                 'access_time' => $access_time,
  424.                                                 'access_type' => $time->access_type
  425.                                                );
  426.                     }
  427.                     else
  428.                     {
  429.                         $time_list['overload'][] = array(
  430.                                                             'access_time' => $access_time,
  431.                                                             'access_type' => $time->access_type
  432.                                                         ); 
  433.                     }
  434.                 }
  435.                
  436.             }
  437.            
  438.             if(count($time_setup)>0):
  439.                 $time_list = $this->timeRecord($record_logs,$time_setup,$emp_id);
  440.             endif;
  441.            
  442.             $total_overload = $this->computeOverload($time_list,$date);
  443.             $total_undertime = $this->computeUndertime($time_setup,$time_list,$date);
  444.             $total_absent = $this->computeAbsent($time_setup,$time_list,$date);
  445.         }
  446.         else
  447.         {
  448.             $total_overload = $this->computeOverload($time_list,$date);
  449.             $total_undertime = $this->computeUndertime($time_setup,$time_list,$date);
  450.             $total_absent = $this->computeAbsent($time_setup,$time_list,$date);
  451.         }
  452.        
  453.         $total_hrs = $this->computeTimeRecord($time_list,$time_setup,$date,$grace_period);
  454.        
  455.         $data = array(
  456.                       'reghrs'=>$total_hrs['reghrs'],
  457.                       'absent'=>$total_absent,
  458.                       'late'=> $this->getDeductionTime($total_hrs['late']),
  459.                       'undertime'=>$this->getDeductionTime($total_undertime),
  460.                       'message'=>$message,
  461.                       'overload' =>$total_overload
  462.                     );
  463.        
  464.         return $data;
  465.     }
  466.    
  467.     private function getDeductionTime($time)
  468.     {
  469.         $floor = floor($time/30);
  470.         $remainder = $time%30;
  471.        
  472.         if($remainder!=0):
  473.             $remainder = 30;
  474.         endif;
  475.        
  476.         $total = ($floor*30) + $remainder;
  477.        
  478.         return $total;
  479.     }
  480.    
  481.     private function getTimeAllowance($emp_id)
  482.     {
  483.         $row = $this->SmartEntryModel->getEmployeeExtInfo($emp_id);
  484.         if(count($row)>0)
  485.         {
  486.             $classification_id = $row->classification_id;
  487.             $row_time_allowance = $this->SmartEntryModel->checkStatusPeriod($classification_id);
  488.             $time_out_allowance_status = $row_time_allowance->timeout_allowance_status;
  489.             if($time_out_allowance_status==1)
  490.             {
  491.                 $time_row_period = $this->SmartEntryModel->getGracePeriodData();
  492.                 $timeout_allowance = $time_row_period->timeout_allowance;
  493.             }
  494.             else
  495.             {
  496.                 $timeout_allowance = 0;
  497.             }  
  498.         }
  499.         else
  500.         {
  501.             $timeout_allowance = 0;
  502.         }
  503.        
  504.         return $timeout_allowance;
  505.     }
  506.    
  507.     private function getGracePeriod($emp_id)
  508.     {
  509.         $row = $this->SmartEntryModel->getEmployeeExtInfo($emp_id);
  510.         if(count($row)>0)
  511.         {
  512.             $classification_id = $row->classification_id;
  513.             $row_time_allowance = $this->SmartEntryModel->checkStatusPeriod($classification_id);
  514.             $grace_period_status = $row_time_allowance->grace_period_status;
  515.             if($grace_period_status==1)
  516.             {
  517.                 $time_row_period = $this->SmartEntryModel->getGracePeriodData();
  518.                 $grace_period = $time_row_period->timeout_allowance;
  519.             }
  520.             else
  521.             {
  522.                 $grace_period = 0;
  523.             }
  524.         }
  525.         else
  526.         {
  527.             $grace_period = 0;
  528.         }
  529.        
  530.         return $grace_period;
  531.     }
  532.    
  533.     private function timeRecord($record_logs,$time_setup,$emp_id)
  534.     {
  535.         $time_list = array();
  536.        
  537.         $timeout_allowance = $this->getTimeAllowance($emp_id);
  538.        
  539.         for($n=0;$n<count($time_setup);$n++)
  540.         {
  541.             $boolean = true;
  542.             $end_time_with_allowance = date('H:i',strtotime($time_setup[$n]['end_time']." + ".$timeout_allowance."mins"));
  543.             $start_time = $time_setup[$n]['start_time'];
  544.             $end_time = $time_setup[$n]['end_time'];
  545.            
  546.             for($i=0;$i<count($record_logs);$i++)
  547.             {
  548.                 $access_time = $record_logs[$i]['access_time'];
  549.                 $access_type = $record_logs[$i]['access_type'];
  550.                            
  551.                 if(isset($time_setup[$n-1]))
  552.                 {
  553.                     if(strtotime($access_time) > strtotime($time_setup[$n-1]['end_time']) && strtotime($access_time) < strtotime($time_setup[$n]['start_time'])&&$access_type!='2'):
  554.                         $time_list[$start_time][] = array(
  555.                                                             'access_time' => $access_time,
  556.                                                             'access_type' => $access_type
  557.                                                         );
  558.                     endif;
  559.                 }
  560.                 else
  561.                 {
  562.                     if(strtotime($access_time)<strtotime($start_time)):
  563.                         $time_list[$start_time][] = array(
  564.                                                             'access_time' => $access_time,
  565.                                                             'access_type' => $access_type
  566.                                                         );
  567.                     endif;
  568.                 }
  569.                
  570.                 if(strtotime($access_time)>=strtotime($start_time)&&strtotime($access_time)<=strtotime($end_time_with_allowance))
  571.                 {
  572.                     if(strtotime($access_time)>strtotime($end_time) && strtotime($access_time)<=strtotime($end_time_with_allowance) && $access_type=='2'):
  573.                         $time_list[$start_time][] = array(
  574.                                                             'access_time' => $access_time,
  575.                                                             'access_type' => $access_type
  576.                                                         );
  577.                     endif;
  578.                    
  579.                    
  580.                     if(strtotime($access_time)>=strtotime($start_time) && strtotime($access_time)<=strtotime($end_time)):
  581.                         $boolean = $this->pickTimeAllowanceStatus($boolean,$record_logs,$i);
  582.                         if($boolean==false):
  583.                             $time_list[$start_time][] = array(
  584.                                                                 'access_time' => $access_time,
  585.                                                                 'access_type' => $access_type
  586.                                                             );
  587.                         endif;
  588.                     endif;
  589.                    
  590.                    
  591.                 }
  592.                 else if(!isset($time_setup[$i+1]) && strtotime($access_time)>strtotime($time_setup[count($time_setup)-1]['end_time']) && count($time_setup)==($n+1))
  593.                 {
  594.                     if($access_type!='2'):
  595.                         $overload_time_in=true;
  596.                     endif;
  597.                    
  598.                     if($overload_time_in!=true):
  599.                         $time_list[$start_time][] = array(
  600.                                                             'access_time' => $access_time,
  601.                                                             'access_type' => $access_type
  602.                                                         );
  603.                     endif;
  604.                    
  605.                     if($overload_time_in==true):
  606.                         $time_list['overload'][] = array(
  607.                                                             'access_time' => $access_time,
  608.                                                             'access_type' => $access_type
  609.                                                         );
  610.                     endif;
  611.                    
  612.                 }
  613.             }
  614.         }
  615.        
  616.         return $time_list;
  617.     }
  618.    
  619.     private function pickTimeAllowanceStatus($boolean,$record_logs,$i)
  620.     {
  621.         if($boolean==true && $record_logs[$i]['access_type']=='2')
  622.         {
  623.             $boolean=true;
  624.         }
  625.         else
  626.         {
  627.             $boolean=false;
  628.         }
  629.        
  630.         return $boolean;
  631.     }
  632.    
  633.     private function computeOverload($time_list,$date)
  634.     {
  635.         $ctr=0;
  636.         $access_type_holder = '';
  637.         $time_container = array();
  638.         $total_overload = 0;
  639.         if(isset($time_list['overload']))
  640.         {
  641.             for($i=0;$i<count($time_list['overload']);$i++)
  642.             {
  643.                 $time_container[$ctr][] = array(
  644.                                                     'access_time' => $time_list['overload'][$i]['access_time'],
  645.                                                     'access_type' => $time_list['overload'][$i]['access_type']
  646.                                                 );
  647.                
  648.                 if(isset($time_list['overload'][$i+1])):
  649.                     if($time_list['overload'][$i]['access_type']=='2' && $time_list['overload'][$i+1]['access_type']!='2'):
  650.                         $ctr++;
  651.                     endif;
  652.                 endif;
  653.                
  654.             }
  655.         }
  656.        
  657.         if(count($time_container)>0)
  658.         {
  659.             for($n=0;$n<count($time_container);$n++)
  660.             {
  661.                 $start_time = $time_container[$n][0]['access_time'];
  662.                 $start_end = $time_container[$n][count($time_container[$n])-1]['access_time'];
  663.                 $total_partial = $this->ConverterModel->dateTimeComuptation($start_time,$start_end,$date);
  664.                
  665.                 $total_overload += $this->sumTotalTime($total_partial,'hrs');
  666.                
  667.                 $this->_count_overload = $this->_count_overload + 1;
  668.             }
  669.         }
  670.         else
  671.         {
  672.             $total_overload=0;
  673.             $this->_count_overload = 0;
  674.         }
  675.        
  676.         return $total_overload;
  677.     }
  678.    
  679.     private function sumTotalTime($total_time,$time_type)
  680.     {
  681.         $hrs = $this->showTimeSelector($total_time,'hrs');
  682.         $mins = $this->showTimeSelector($total_time,'mins');
  683.         $ext_mns=0;
  684.         $ext_hrs=0;
  685.         $total = 0;
  686.        
  687.         if($time_type == 'hrs')
  688.         {
  689.             //if($mins>=60):
  690.             //  $ext_mns = floor($mins/60);
  691.             //endif;
  692.             $total = $hrs;
  693.         }
  694.         else
  695.         {
  696.             if($hrs>0):
  697.                 $ext_hrs = $hrs*60;
  698.             endif;
  699.             $total = $mins + $ext_hrs;
  700.         }
  701.        
  702.         return $total;
  703.     }
  704.    
  705.     private function computeAbsent($time_setup,$time_list,$date)
  706.     {
  707.         $total_absent=0;
  708.         //get total absent
  709.         for($i=0;$i<count($time_setup);$i++)
  710.         {
  711.             if(!isset($time_list[$time_setup[$i]['start_time']]) || count($time_list[$time_setup[$i]['start_time']])<2 || count($time_list)==0)
  712.             {
  713.                 $time_setup_start = $time_setup[$i]['start_time'];
  714.                 $time_setup_end = $time_setup[$i]['end_time'];
  715.                
  716.                 $total_absent += $this->collegeAccumulatedAbsent($time_setup_start,$time_setup_end,$date);
  717.                 $this->_count_absent = $this->_count_absent + 1;
  718.             }
  719.         }
  720.        
  721.         return $total_absent;
  722.     }
  723.    
  724.     private function computeTimeRecord($time_list,$time_setup,$date,$grace_period)
  725.     {
  726.         $data['reghrs'] = 0;
  727.         $data['late'] = 0;
  728.         if(count($time_list)>0)
  729.         {
  730.             for($i=0;$i<count($time_setup);$i++)
  731.             {
  732.                 $time_setup_start=$time_setup[$i]['start_time'];
  733.                 $time_setup_end=$time_setup[$i]['end_time'];
  734.                
  735.                 if(isset($time_list[$time_setup_start]))
  736.                 {
  737.                     if(count($time_list[$time_setup_start])>1)
  738.                     {
  739.                         $start_time = $time_list[$time_setup_start][0]['access_time'];
  740.                         $end_time = $time_list[$time_setup_start][count($time_list[$time_setup_start])-1]['access_time'];
  741.                         $reghrs = $this->collegeAccumulatedTime($time_list,$time_setup_start,$time_setup_end,$date,$start_time,$end_time);
  742.                         $late = $this->collegeAccumulatedLate($start_time,$end_time,$time_setup_start,$date,$grace_period);
  743.                         $data['reghrs'] = $data['reghrs'] + $reghrs;
  744.                         $data['late'] = $data['late'] + $late;
  745.                     }
  746.                     else
  747.                     {
  748.                         $data['reghrs'] = 0;
  749.                         $data['late'] = 0;
  750.                     }  
  751.                 }
  752.                
  753.             }  
  754.         }
  755.         else
  756.         {
  757.             $data['reghrs'] = 0;
  758.             $data['late'] = 0;
  759.         }
  760.        
  761.         return $data;
  762.     }
  763.    
  764.     private function computeUndertime($time_setup,$time_list,$date)
  765.     {
  766.         $total_undertime="0";
  767.         //get total Undertime
  768.         for($i=0;$i<count($time_setup);$i++)
  769.         {
  770.             if(isset($time_list[$time_setup[$i]['start_time']]))
  771.             {
  772.                 $time_setup_start = $time_setup[$i]['start_time'];
  773.                 $time_setup_end = $time_setup[$i]['end_time'];
  774.                
  775.                 $last_access_time = $time_list[$time_setup[$i]['start_time']][count($time_list[$time_setup[$i]['start_time']])-1]['access_time'];
  776.                
  777.                 if(strtotime($last_access_time)<strtotime($time_setup_end)):
  778.                     $total_undertime += $this->collegeAccumulatedUndertime($last_access_time,$time_setup_end,$date);
  779.                     $this->_count_undertime = $this->_count_undertime + 1;
  780.                 endif;
  781.                
  782.             }
  783.         }
  784.        
  785.         return $total_undertime;
  786.     }
  787.    
  788.     private function collegeAccumulatedUndertime($time_setup_start,$time_setup_end,$date)
  789.     {
  790.         $undertime = $this->ConverterModel->dateTimeComuptation($time_setup_start,$time_setup_end,$date);
  791.        
  792.         $total_undertime = $this->sumTotalTime($undertime,'mins');
  793.         return $total_undertime;
  794.     }
  795.    
  796.     private function collegeAccumulatedAbsent($time_setup_start,$time_setup_end,$date)
  797.     {
  798.         $absent = $this->ConverterModel->dateTimeComuptation($time_setup_start,$time_setup_end,$date);
  799.         $total_absent = $this->sumTotalTime($absent,'hrs');
  800.         return $total_absent;
  801.     }
  802.    
  803.     private function collegeAccumulatedLate($start_time,$end_time,$start,$date,$grace_period)
  804.     {
  805.         $late = "00.00";
  806.        
  807.         if(strtotime(date('H:i',strtotime($start_time)))>strtotime(date('H:i',strtotime($start." +'.$grace_period.'mins"))))
  808.         {
  809.             $late = $this->ConverterModel->dateTimeComuptation($start,$start_time,$date);
  810.             $this->_count_late = $this->_count_late + 1;
  811.         }
  812.        
  813.         $total_late = $this->sumTotalTime($late,'mins');
  814.         return $total_late;
  815.     }
  816.    
  817.     private function gracePeriodData()
  818.     {
  819.         $num_rows = $this->SmartEntryModel->checkGracePeriod();
  820.         if($num_rows>0)
  821.         {
  822.             $row = $this->SmartEntryModel->getGracePeriodData();
  823.             $grace_period['gp_time'] = $row->grace_period_time;
  824.             $grace_period['gp_id'] = $row->id;
  825.         }
  826.         else
  827.         {
  828.             $grace_period['gp_time'] = 0;
  829.             $grace_period['gp_id'] = '';
  830.         }
  831.        
  832.         return $grace_period;
  833.     }
  834.    
  835.     private function collegeAccumulatedTime($time_list,$start,$end,$date,$start_time,$end_time)
  836.     {
  837.         if(strtolower($start_time)<=strtotime($start)):
  838.             $start_time = $start;
  839.         endif;
  840.        
  841.         if(strtolower($start_time)>=strtotime($end)):
  842.             $end_time = $end;
  843.         endif;
  844.        
  845.         if($start_time!=''||$end_time!=''):
  846.             $this->_count_present = $this->_count_present + 1;
  847.         endif;
  848.        
  849.         $total_time = $this->ConverterModel->dateTimeComuptation($start_time,$end_time,$date);
  850.        
  851.         $total_time = $this->sumTotalTime($total_time,'hrs');
  852.        
  853.         //computer break
  854.         $break = $this->getBreakReturn($time_list,'3',$start);
  855.         $return = $this->getBreakReturn($time_list,'4',$start);
  856.        
  857.         if($break!='' && $return!='')
  858.         {
  859.             $total_break = $this->ConverterModel->dateTimeComuptation($break,$return,$date);
  860.            
  861.             $total_break = $this->sumTotalTime($total_break,'hrs');
  862.         }
  863.         else
  864.         {
  865.             $total_break = 0;
  866.         }
  867.        
  868.         $total = max($total_time - $total_break,0);
  869.        
  870.         return  $total;
  871.     }
  872.    
  873.     private function showTimeSelector($time,$type)
  874.     {
  875.         $time_keeper = '';
  876.         $time_container = explode('.',$time);
  877.         if($type=='hrs')
  878.         {
  879.             $time_keeper = $time_container[0];
  880.         }
  881.         else
  882.         {
  883.             $time_keeper = $time_container[1];
  884.         }
  885.        
  886.         return $time_keeper;
  887.     }
  888.    
  889.     private function getBreakReturn($time_list,$type,$start_time)
  890.     {
  891.         $drd='';
  892.        
  893.         for($i=0;$i<count($time_list[$start_time]);$i++)
  894.         {
  895.             if($time_list[$start_time][$i]['access_type']==$type):
  896.                 $drd[] = $time_list[$start_time][$i]['access_time'];
  897.             endif;
  898.         }
  899.        
  900.         if($type=="3")
  901.         {
  902.             if(isset($drd[0]))
  903.             {
  904.                 $drd=$drd[0];
  905.             }
  906.         }
  907.         else
  908.         {
  909.             if(isset($drd[count($drd)-1]))
  910.             {
  911.                 $drd=$drd[count($drd)-1];
  912.             }
  913.            
  914.         }
  915.         return $drd;
  916.     }
  917.    
  918.     private function recordEmployeeTime($emp_no,$date)
  919.     {
  920.         $this->load->model('ScheduleModel');
  921.         $time_collector = array();
  922.         $index = 0;
  923.         $index_2 = 0;
  924.         $day = $this->selectDay($date);
  925.        
  926.         $response = $this->ScheduleModel->getEmployeeTimeList($emp_no,$day);
  927.         if($response->num_rows()>0)
  928.         {
  929.             foreach($response->result() as $time)
  930.             {
  931.                 $decode = json_decode($time->time_list);
  932.                 for($i=0;$i<count($decode);$i++)
  933.                 {
  934.                     if(($i%2)==0)
  935.                     {
  936.                         $data['start'][] = $decode[$i];
  937.                     }
  938.                     else
  939.                     {
  940.                         $data['end'][] = $decode[$i];  
  941.                     }
  942.                 }
  943.             }
  944.            
  945.             for($x=0;$x<count($data['start']);$x++)
  946.             {
  947.                 $time_collector[] = array(
  948.                                                 'start_time' => $data['start'][$x],
  949.                                                 'end_time' => $data['end'][$x]
  950.                                             );
  951.             }
  952.         }
  953.        
  954.         return $time_collector;
  955.     }
  956.    
  957.     private function selectDay($date)
  958.     {
  959.         $day = date("l",strtotime($date));
  960.        
  961.         $convert='';
  962.         switch($day)
  963.         {
  964.             case "Monday" : $convert="1"; break;
  965.             case "Tuesday" : $convert="2"; break;
  966.             case "Wednesday" : $convert="3"; break;
  967.             case "Thursday" : $convert="4"; break;
  968.             case "Friday" : $convert="5"; break;
  969.             case "Saturday" : $convert="6"; break;
  970.             case "Sunday" : $convert="7"; break;
  971.         }
  972.        
  973.         return $convert;
  974.     }
  975.    
  976.    
  977.     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)
  978.     {
  979.         $data_holder = array();
  980.         $data_container = array();
  981.        
  982.         $data_container[] = array('Daily Time Record');
  983.        
  984.         $data_container[] = array('Start Date: ', date('M d Y',strtotime($date_start)));
  985.        
  986.         $data_container[] = array('End Date: ', date('M d Y',strtotime($date_end)));
  987.        
  988.         $data_container[] = array('');
  989.         $htitle = '';
  990.         $html = '';
  991.         $emp_list_response = $this->SmartEntryModel->employeeList2($employee_id,$fname,$minitial,$lname,$group,$department,$arrange_by_1,$arrange_by_2,$emp_type,$emp_position);
  992.         $iter = 0;
  993.        
  994.         foreach($emp_list_response->result() as $emp_list)
  995.         {
  996.             $emp_no = $emp_list->employee_student_no;
  997.            
  998.             $header = array('Name: ',strtoupper($emp_list->lname.", ".$emp_list->fname." ".$emp_list->minitial));
  999.             //echo $emp_no." | ".$emp_list->lname.", ".$emp_list->fname." ".$emp_list->minitial."<br>";
  1000.             $data_container[] = $header;
  1001.            
  1002.             $department_name = $this->getDepartment($emp_list);
  1003.             $classification_name = $this->getClassification($emp_list);
  1004.            
  1005.             $department_label = $this->departmentLabel($emp_list,$show_department,$department_name);
  1006.             $hdepartment = array("Employee ID: ",$emp_no,"Department: ",$department_name,'Classification:',$classification_name);
  1007.            
  1008.             $data_container[] = $hdepartment;
  1009.            
  1010.             $result = $this->SmartEntryModel->getAllAccessRecords2($emp_no,$date_start,$date_end);
  1011.            
  1012.             if($show_array[5]=="on")
  1013.             {
  1014.                 $subject_header = $this->headerLengthDisplay($emp_no,$date_start,$date_end,$result);
  1015.             }
  1016.             else
  1017.             {
  1018.                 $subject_header = array();
  1019.             }
  1020.            
  1021.             $extension_label = $this->extensionLabel($show_array,$show_remarks);
  1022.            
  1023.             if($show_array[count($show_array)-1]=="on" && $show_array[count($show_array)-2]=="on")
  1024.             {
  1025.                 $htitle = array_merge(array_merge(array('Date'),$subject_header),$extension_label);
  1026.             }
  1027.             else if($show_array[count($show_array)-1]=="on")
  1028.             {
  1029.                 $htitle = array_merge(array('Date'),$extension_label); 
  1030.             }
  1031.             else if($show_array[count($show_array)-2]=="on")
  1032.             {
  1033.                 $htitle = array_merge(array('Date'),$subject_header);  
  1034.             }
  1035.            
  1036.             $data_container[] = $htitle;
  1037.            
  1038.             $dates = $this->ConverterModel->DatePeriod_start_end($date_start,$date_end);
  1039.            
  1040.             if($result->num_rows()>0)
  1041.             {
  1042.                 foreach($dates as $date)
  1043.                 {
  1044.                     $total_report_list = $this->computeCollegeRecord($emp_no,$date,$result,$emp_list->message);
  1045.                    
  1046.                     //if($this->_count_present==0&&$this->_count_absent==0&&$this->_count_late==0&&$this->_count_undertime==0&&$this->_count_overload==0):
  1047.                     //  $this->_count_absent=1;
  1048.                     //endif;
  1049.                    
  1050.                     $count_container = array($this->_count_present,$this->_count_absent,$this->_count_late,$this->_count_undertime,$emp_list->message,$this->_count_overload);
  1051.                     if($show_array[count($show_array)-2]=="on")
  1052.                     {
  1053.                         $data_rows = $this->attendance($emp_no,$date,$emp_list->division,$show_array,$report_type,$result);
  1054.                        
  1055.                         if($show_array[count($show_array)-1]=="on")
  1056.                         {
  1057.                             $total_time_list = array_merge($this->bindFields($data_rows,$subject_header));
  1058.                         }
  1059.                         else
  1060.                         {
  1061.                             $total_time_list = array();
  1062.                         }
  1063.                        
  1064.                         $data_body = array_merge(array_merge(array_merge(array(date('M d Y',strtotime($date))),$data_rows),$total_time_list));
  1065.                        
  1066.                         if($show_array[5]=="on")
  1067.                         {
  1068.                             $data_body = array_merge($data_body,$count_container);
  1069.                         }
  1070.                         else
  1071.                         {
  1072.                             $data_body = array_merge(array(date('M d Y',strtotime($date))),$count_container);
  1073.                         }
  1074.                        
  1075.                     }
  1076.                     else
  1077.                     {
  1078.                         $this->attendance($emp_no,$date,$emp_list->division,$show_array,$report_type,$result);
  1079.                        
  1080.                         $data_body = array_merge(array(date('M d Y',strtotime($date))),$this->_total_list);
  1081.                     }
  1082.                     $data_container[] = $data_body;
  1083.                    
  1084.                     $this->_total_list = array();
  1085.                    
  1086.        
  1087.                     $this->_count_absent=0;
  1088.                     $this->_count_late=0;
  1089.                     $this->_count_present=0;
  1090.                     $this->_count_undertime=0;
  1091.                     $this->_count_overload=0;
  1092.                 }  
  1093.             }
  1094.             else
  1095.             {
  1096.                 foreach($dates as $date)
  1097.                 {
  1098.                     if($show_array[count($show_array)-2]=="on")
  1099.                     {
  1100.                        
  1101.                         if($show_array[5]=="on")
  1102.                         {
  1103.                             $data_container[] = array(date('M d Y',strtotime($date)),'','','','',0,1,0,0,'',0);
  1104.                         }
  1105.                         else
  1106.                         {
  1107.                             $data_container[] = array(date('M d Y',strtotime($date)),0,1,0,0,'',0);
  1108.                         }
  1109.                     }
  1110.                     else
  1111.                     {
  1112.                         $data_container[] = array(date('M d Y',strtotime($date)),'','','','');
  1113.                     }
  1114.                    
  1115.                 }
  1116.             }
  1117.            
  1118.             //$a= $iter/$emp_list_response->num_rows();
  1119.             //echo "Progress: ".($a * 100)."%<br>";
  1120.             //$this->session->set_userdata('progress',($a * 100).'%');
  1121.            
  1122.             $this->_container = '';
  1123.             $iter++;
  1124.         }
  1125.             //echo "Progress: 100%<br>";
  1126.             //$this->session->set_userdata('progress',($a * 100).'%'); 
  1127.         //echo "<pre>".json_encode($data_container,JSON_PRETTY_PRINT)."</pre>";
  1128.        
  1129.         $response = $this->generateCsvFile('report.csv',$data_container);
  1130.        
  1131.         return 'report.csv';
  1132.     }
  1133.    
  1134.     private function getDepartment($emp_list)
  1135.     {
  1136.         $check_department = $this->SmartEntryModel->checkDepartmentNameEmp($emp_list->department_id);
  1137.         if($check_department==0)
  1138.         {
  1139.             $department_name = '';
  1140.         }
  1141.         else
  1142.         {
  1143.             $department_name = $this->SmartEntryModel->getDepartmentNameEmp($emp_list->department_id);
  1144.         }
  1145.        
  1146.         return $department_name;
  1147.     }
  1148.    
  1149.     private function getClassification($emp_list)
  1150.     {
  1151.         $check_classification = $this->SmartEntryModel->checkClassificationNameEmp($emp_list->classification_id);
  1152.         if($check_classification==0)
  1153.         {
  1154.             $classification_name = '';
  1155.         }
  1156.         else
  1157.         {
  1158.             $classification_name = $this->SmartEntryModel->getClassificationNameEmp($emp_list->classification_id);
  1159.         }
  1160.        
  1161.         return $classification_name;
  1162.     }
  1163.    
  1164.     public function loading()
  1165.     {
  1166.         $session_progress = $this->session->userdata('progress');
  1167.         echo 'Progress: '.($session_progress==''? '0%':$session_progress);
  1168.     }
  1169.    
  1170.     private function generateCsvFile($filename,$data)
  1171.     {
  1172.         $dir = 'download/';
  1173.        
  1174.         if(!is_dir($dir)):
  1175.             mkdir('download');
  1176.         endif;
  1177.        
  1178.         $fp = fopen($_SERVER['DOCUMENT_ROOT'].'/jru/'.$dir.$filename,'w+');
  1179.        
  1180.         foreach($data as $key=>$val)
  1181.         {
  1182.             $array = (array) $val;
  1183.             fputcsv($fp,$array);
  1184.         }
  1185.        
  1186.         fclose($fp);
  1187.        
  1188.         return 'success';
  1189.     }
  1190.    
  1191.     private function departmentLabel($emp_list,$show_department,$department_name)
  1192.     {
  1193.         if($show_department=="on"){
  1194.             $department_label[] = '';
  1195.             $department_label[] = 'Department:';
  1196.             $department_label[] = $department_name;
  1197.         }else{
  1198.             $department_label[] = '';
  1199.         }
  1200.        
  1201.         return $department_label;
  1202.     }
  1203.    
  1204.     private function extensionLabel($show_array,$show_remarks)
  1205.     {
  1206.         $extension_label = $this->extensionHeader($show_array,$show_remarks);
  1207.            
  1208.         return $extension_label;
  1209.     }
  1210.    
  1211.     private function footerTotal($subject_header,$show_array)
  1212.     {
  1213.         $footer = array();
  1214.         $footer_total = array();
  1215.         for($n=0;$n<count($subject_header);$n++)
  1216.         {
  1217.             $footer_total[] = '';
  1218.         }
  1219.        
  1220.         if($show_array[0]=="on"):
  1221.             $footer[] = $this->_total_time;
  1222.         endif;
  1223.         if($show_array[1]=="on"):
  1224.             $footer[] = $this->_total_late;
  1225.         endif;
  1226.         if($show_array[2]=="on"):
  1227.             $footer[] = $this->_undertime;
  1228.         endif;
  1229.         if($show_array[3]=="on"):
  1230.             $footer[] = $this->_overload;
  1231.         endif;
  1232.         if($show_array[4]=="on"):
  1233.             $footer[] = $this->_total_absent;
  1234.         endif;
  1235.        
  1236.         $footertitle = array_merge(array_merge(array(""),$footer_total),$footer);
  1237.    
  1238.         return $footertitle;
  1239.     }
  1240.    
  1241.    
  1242.     private function hederLayout($emp_list,$date_start,$date_end)
  1243.     {
  1244.         $header_label[] = "Time In";
  1245.         $header_label[] = "Break";
  1246.         $header_label[] = "Return";
  1247.         $header_label[] = "Time Out";
  1248.        
  1249.         return $header_label;
  1250.     }
  1251.    
  1252.     private function configBreakTime($record,$break_type)
  1253.     {
  1254.         $time_container = array();
  1255.         $mod_value = ($break_type=='break'? 1 : 2);
  1256.         $flag=0;
  1257.        
  1258.         for($i=0;$i<count($record);$i++)
  1259.         {
  1260.             $mod = $i%4;
  1261.            
  1262.             if($mod==$mod_value):
  1263.                 if($flag==0):
  1264.                     $time_container[] = $record[$i];
  1265.                     $flag=1;
  1266.                 endif;
  1267.                
  1268.                 if(isset($record[$i+1]))
  1269.                 {
  1270.                     if($record[$i+1]!=''):  
  1271.                         $flag=0;
  1272.                     endif;
  1273.                 }
  1274.                
  1275.                 if($break_type=='break'):
  1276.                     if(isset($record[$i+2]))
  1277.                     {
  1278.                         if($record[$i+2]!=''):
  1279.                             $flag=0;
  1280.                         endif; 
  1281.                     }
  1282.                    
  1283.                 endif;
  1284.                
  1285.                
  1286.             endif;
  1287.         }
  1288.        
  1289.         return $time_container;
  1290.     }
  1291.    
  1292.     private function attendance($emp_no,$date,$department,$show_array,$report_type,$result_access_time)
  1293.     {
  1294.         $start_container = array();
  1295.         $end_container = array();
  1296.         $overload_container_in = array();
  1297.         $overload_container_out = array();
  1298.         $record_total_list = array();
  1299.        
  1300.         $response = $this->SmartEntryModel->getTimeSetup($department);
  1301.        
  1302.         if($response->num_rows()==1)
  1303.         {
  1304.             $record = $this->showTimeBody($result_access_time,$date);
  1305.             $break = $this->configBreakTime($record,'break');
  1306.             $return = $this->configBreakTime($record,'return');
  1307.             if(isset($return[count($return)-1]) && isset($break[0]))
  1308.             {
  1309.                 if($return[count($return)-1]!='' && $break[0]!='')
  1310.                 {
  1311.                     $accumulated_break = $this->accumulatedTime($break[0],$return[count($return)-1],$date,$emp_no);
  1312.                 }
  1313.                 else
  1314.                 {
  1315.                     $accumulated_break = "00.00";
  1316.                 }  
  1317.             }
  1318.             else
  1319.             {
  1320.                 $accumulated_break = "00.00";
  1321.             }
  1322.            
  1323.             foreach($response->result() as $time_record)
  1324.             {
  1325.                 $mts = strtotime($time_record->start_time);
  1326.                 $mte = strtotime($time_record->end_time);
  1327.                 if(count($record)>1)
  1328.                 {
  1329.                     for($i=0;$i<count($record);$i++)
  1330.                     {
  1331.                         $mod_in = $i%4;
  1332.                         if($mod_in==0)
  1333.                         {
  1334.                             if(strtotime($record[$i])>=$mts && strtotime($record[$i])<=$mte){
  1335.                                 $start_container[] = $record[$i];
  1336.                             }else if($record[$i]!=''){
  1337.                                 $overload_container_in[] = $record[$i];
  1338.                             }
  1339.                         }
  1340.                         else if($mod_in==3)
  1341.                         {
  1342.                             if(strtotime($record[$i])>=$mts && strtotime($record[$i])<=$mte){
  1343.                                 $end_container[] = $record[$i];
  1344.                             }else if($record[$i]!=''){
  1345.                                 $overload_container_out[] = $record[$i];
  1346.                             }
  1347.                         }
  1348.                     }  
  1349.                
  1350.                     $process_time_in = (isset($start_container[0])?$start_container[0]:'');
  1351.                     $process_time_out = (isset($end_container[count($end_container)-1])?$end_container[count($end_container)-1]:'');
  1352.                    
  1353.                     if(strtotime($process_time_out)>strtotime($time_record->end_time)):
  1354.                         $process_time_out = $time_record->end_time;
  1355.                     endif;
  1356.                    
  1357.                     $process_overload_in = (isset($overload_container_in[0])?$overload_container_in[0]:'');
  1358.                     $process_overload_out = (isset($overload_container_out[count($overload_container_out)-1])?$overload_container_out[count($overload_container_out)-1]:'');
  1359.                     if($process_time_in!='' || $process_time_out!='')
  1360.                     {
  1361.                         $accumulated_time = $this->accumulatedTime($process_time_in,$process_time_out,$date,$emp_no);
  1362.                         if($process_overload_in!=''&&$process_overload_out!='')
  1363.                         {
  1364.                             $accumulated_overload = $this->accumulatedTime($overload_container_in[0],$overload_container_out[count($overload_container_out)-1],$date,$emp_no);
  1365.                         }
  1366.                         else
  1367.                         {
  1368.                             $accumulated_overload = "00.00";
  1369.                         }
  1370.                        
  1371.                        
  1372.                         if($show_array[0]=="on"):
  1373.                             if($process_time_out!='')
  1374.                             {
  1375.                                 if($accumulated_break!="00.00")
  1376.                                 {
  1377.                                     $accumulated_time = $this->ConverterModel->subTractBreakTime($accumulated_break,$accumulated_time);
  1378.                                     $this->_total_list[] = $accumulated_time;
  1379.                                 }
  1380.                                 else
  1381.                                 {
  1382.                                     $this->_total_list[] = $accumulated_time;
  1383.                                 }
  1384.                                 $this->_total_time = $this->ConverterModel->sumTime($this->_total_time,$accumulated_time);
  1385.                             }
  1386.                             else
  1387.                             {
  1388.                                 $this->_total_list[] = "00.00";
  1389.                             }
  1390.                            
  1391.                         endif;
  1392.                        
  1393.                         if($show_array[1]=="on"):
  1394.                             if($process_time_in!='')
  1395.                             {
  1396.                                 $p_time_late = strtotime(date("h:i A",strtotime($process_time_in." -".$time_record->grace_period." mins")));
  1397.                                
  1398.                                 if($p_time_late>strtotime($time_record->start_time))
  1399.                                 {
  1400.                                     $accumulated_late = $this->accumulatedTime(date("h:i A",$p_time_late),$time_record->start_time,$date,$emp_no);
  1401.                                     $this->_total_list[] = $accumulated_late;
  1402.                                     $this->_total_late = $this->ConverterModel->sumTime($this->_total_late,$accumulated_late);
  1403.                                 }
  1404.                                 else
  1405.                                 {
  1406.                                     $this->_total_list[] = "00.00";
  1407.                                 }
  1408.                             }
  1409.                             else
  1410.                             {
  1411.                                 $this->_total_list[] = "00.00";
  1412.                             }
  1413.                         endif;
  1414.                        
  1415.                         if($show_array[2]=="on"):
  1416.                             if($process_time_out!='')
  1417.                             {
  1418.                                 if(strtotime($process_time_out)<strtotime($time_record->end_time))
  1419.                                 {
  1420.                                     $accumulated_undertime = $this->accumulatedTime($process_time_out,$time_record->end_time,$date,$emp_no);
  1421.                                     $this->_total_list[] = $accumulated_undertime;
  1422.                                     $this->_undertime = $this->ConverterModel->sumTime($this->_undertime,$accumulated_undertime);
  1423.                                 }
  1424.                                 else
  1425.                                 {
  1426.                                     $this->_total_list[] = "00.00";
  1427.                                 }  
  1428.                             }
  1429.                             else
  1430.                             {
  1431.                                 $this->_total_list[] = "00.00";
  1432.                             }
  1433.                            
  1434.                         endif;
  1435.                        
  1436.                         if($show_array[3]=="on"):
  1437.                             if($process_overload_out!='' || $process_overload_in !='')
  1438.                             {
  1439.                                 $this->_total_list[] = $accumulated_overload;
  1440.                                 $this->_overload = $this->ConverterModel->sumTime($this->_overload,$accumulated_overload);
  1441.                             }
  1442.                             else
  1443.                             {
  1444.                                 $this->_total_list[] = "00.00";
  1445.                             }
  1446.                         endif;
  1447.                        
  1448.                         if($show_array[4]=="on"):
  1449.                             $this->_total_list[] = "00.00";
  1450.                         endif;
  1451.                     }
  1452.                     else
  1453.                     {
  1454.                        
  1455.                         if($show_array[0]=="on"):
  1456.                             $this->_total_list[] = "00.00";
  1457.                         endif;
  1458.                         if($show_array[1]=="on"):
  1459.                             $this->_total_list[] = "00.00";
  1460.                         endif;
  1461.                         if($show_array[2]=="on"):
  1462.                             $this->_total_list[] = "00.00";
  1463.                         endif;
  1464.                         if($show_array[3]=="on"):
  1465.                             $this->_total_list[] = "00.00";
  1466.                         endif;
  1467.                         if($show_array[4]=="on"):
  1468.                             $accumulated_absent = $this->accumulatedTime($time_record->start_time,$time_record->end_time,$date,$emp_no);
  1469.                             //echo "Absent: ".$this->accumulatedTime($time_record->start_time,$time_record->end_time,$date,$emp_no)."<br>";
  1470.                             $this->_total_list[] = $accumulated_absent;
  1471.                             $this->_total_absent = $this->ConverterModel->sumTime($this->_total_absent,$accumulated_absent);
  1472.                         endif;
  1473.                        
  1474.                     }
  1475.                 }
  1476.                 else
  1477.                 {
  1478.                     if($show_array[0]=="on"):
  1479.                         $this->_total_list[] = "00.00";
  1480.                     endif;
  1481.                     if($show_array[1]=="on"):
  1482.                         $this->_total_list[] = "00.00";
  1483.                     endif;
  1484.                     if($show_array[2]=="on"):
  1485.                         $this->_total_list[] = "00.00";
  1486.                     endif;
  1487.                     if($show_array[3]=="on"):
  1488.                         $this->_total_list[] = "00.00";
  1489.                     endif;
  1490.                     if($show_array[4]=="on"):
  1491.                         $accumulated_absent = $this->accumulatedTime($time_record->start_time,$time_record->end_time,$date,$emp_no);
  1492.                         $this->_total_list[] = $accumulated_absent;
  1493.                         $this->_total_absent = $this->ConverterModel->sumTime($this->_total_absent,$accumulated_absent);
  1494.                     endif;
  1495.                 }
  1496.                
  1497.             }
  1498.         }
  1499.         else
  1500.         {
  1501.             $record = $this->showTimeBody($result_access_time,$date);
  1502.         }
  1503.        
  1504.         return $record;
  1505.     }
  1506.    
  1507.     private function timeSummary($record)
  1508.     {
  1509.         $time = array();
  1510.         $flag=0;
  1511.         for($i=0;$i<count($record);$i++)
  1512.         {
  1513.             $iter = $i;
  1514.             $mod = $i%2;
  1515.             if($mod==1)
  1516.             {
  1517.                 if(isset($record[$i+1]))
  1518.                 {
  1519.                     if($flag==0)
  1520.                     {
  1521.                         if($i==1)
  1522.                         {
  1523.                             $time[] = $record[$i-1];
  1524.                             $flag=1;   
  1525.                         }
  1526.                     }
  1527.                    
  1528.                     if($record[$i]!="" && $record[$i+1]!="")
  1529.                     {
  1530.                         $time[] = $record[$i];
  1531.                         $time[] = $record[$i+1];
  1532.                         $flag=0;
  1533.                     }  
  1534.                 }
  1535.                 else
  1536.                 {
  1537.                     if(count($record)==2)
  1538.                     {
  1539.                         $time[] = $record[$i-1];
  1540.                         $time[] = $record[$i];
  1541.                     }
  1542.                     else
  1543.                     {
  1544.                         $time[] = $record[$i];
  1545.                     }
  1546.                 }
  1547.             }
  1548.         }
  1549.        
  1550.         return $time;
  1551.     }
  1552.    
  1553.     private function removeNullValueArray($array)
  1554.     {
  1555.         $data_container = array();
  1556.         for($i=0;$i<count($array);$i++)
  1557.         {
  1558.             if($array[$i] != '')
  1559.             {
  1560.                 $data_container[] = $array[$i];
  1561.             }
  1562.         }
  1563.        
  1564.         return $data_container;
  1565.     }
  1566.    
  1567.     private function showTimeBody($result_access_time,$date)
  1568.     {
  1569.         $time_type_container = array();
  1570.        
  1571.         foreach($result_access_time->result() as $access_info)
  1572.         {
  1573.             if($access_info->server_created_date==$date):
  1574.                 $time_type_container[] = array(
  1575.                                                 'access_time' => date('h:i A',strtotime($access_info->access_time)),
  1576.                                                 'access_type' => $access_info->access_type
  1577.                                                );
  1578.             endif;
  1579.         }
  1580.        
  1581.         $time_content_setup = $this->timeContentSetup($time_type_container);
  1582.        
  1583.         return $time_content_setup;
  1584.     }
  1585.    
  1586.     private function timeContentSetup($time_type_container)
  1587.     {
  1588.         //echo "<hr><pre>".json_encode($time_type_container,JSON_PRETTY_PRINT)."</pre><hr>";
  1589.         if(count($time_type_container) == 0)
  1590.         {
  1591.             $time_body[] = '';
  1592.         }
  1593.         else
  1594.         {
  1595.             for($i=0;$i<count($time_type_container);$i++)
  1596.             {
  1597.                 switch($time_type_container[$i]['access_type'])
  1598.                 {
  1599.                     case "1" :
  1600.                        
  1601.                         $time_body[] = $time_type_container[$i]['access_time'];
  1602.                        
  1603.                         if(isset($time_type_container[$i+1])):
  1604.                             if($time_type_container[$i+1]['access_type']==2):
  1605.                                 $time_body[] = '';
  1606.                                 $time_body[] = '';
  1607.                             endif;
  1608.                            
  1609.                             if($time_type_container[$i+1]['access_type']==4):
  1610.                                 $time_body[] = '';
  1611.                             endif;
  1612.                            
  1613.                             if($time_type_container[$i+1]['access_type']==1):
  1614.                                 $time_body[] = '';
  1615.                                 $time_body[] = '';
  1616.                                 $time_body[] = '';
  1617.                             endif;
  1618.                         else:
  1619.                             $time_body[] = '';
  1620.                             $time_body[] = '';
  1621.                             $time_body[] = '';
  1622.                         endif;
  1623.                        
  1624.                         break;
  1625.                    
  1626.                     case "2" :
  1627.                        
  1628.                         if(!isset($time_type_container[$i-1])):
  1629.                             $time_body[] = '';
  1630.                             $time_body[] = '';
  1631.                             $time_body[] = '';
  1632.                         endif;
  1633.                        
  1634.                         $time_body[] = $time_type_container[$i]['access_time'];
  1635.                        
  1636.                         if(isset($time_type_container[$i+1])):
  1637.                             if($time_type_container[$i+1]['access_type']==2):
  1638.                                 $time_body[] = '';
  1639.                                 $time_body[] = '';
  1640.                                 $time_body[] = '';
  1641.                             endif;
  1642.                            
  1643.                             if($time_type_container[$i+1]['access_type']==3):
  1644.                                 $time_body[] = '';
  1645.                             endif;
  1646.                            
  1647.                             if($time_type_container[$i+1]['access_type']==4):
  1648.                                 $time_body[] = '';
  1649.                                 $time_body[] = '';
  1650.                             endif;
  1651.                         endif;
  1652.                         break;
  1653.                     case "3" :
  1654.                         if(isset($time_type_container[$i-1])):
  1655.                             if($time_type_container[$i-1]['access_type']!=1):
  1656.                                 $time_body[] = '';
  1657.                             endif;
  1658.                         else:
  1659.                             $time_body[] = '';
  1660.                         endif;
  1661.                        
  1662.                         $time_body[] = $time_type_container[$i]['access_time'];
  1663.                        
  1664.                         //if(isset($time_type_container[$i+1])):
  1665.                         //  if($time_type_container[$i+1]['access_type']!=4):
  1666.                         //      $time_body[] = 'return';
  1667.                         //  endif;
  1668.                         //else:
  1669.                         //  $time_body[] = 'return';
  1670.                         //endif;
  1671.                         //
  1672.                         if(isset($time_type_container[$i+1])):
  1673.                             if($time_type_container[$i+1]['access_type']==2):
  1674.                                 $time_body[] = '';
  1675.                             endif;
  1676.                             if($time_type_container[$i+1]['access_type']==3):
  1677.                                 $time_body[] = '';
  1678.                                 $time_body[] = '';
  1679.                             endif;
  1680.                         else:
  1681.                             $time_body[] = '';
  1682.                         endif;
  1683.                        
  1684.                         break;
  1685.                     case "4" :
  1686.                        
  1687.                         if(isset($time_type_container[$i-1]))
  1688.                         {
  1689.                             if($time_type_container[$i-1]['access_type']==2):
  1690.                                 $time_body[] = '';
  1691.                                 $time_body[] = '';
  1692.                             endif;
  1693.                         }
  1694.                         else
  1695.                         {
  1696.                             if(isset($time_type_container[$i-1])):
  1697.                                 if($time_type_container[$i-1]['access_type']==1):
  1698.                                     $time_body[] = '';
  1699.                                 endif;
  1700.                             else:
  1701.                                 $time_body[] = '';
  1702.                             endif;
  1703.                            
  1704.                             if(isset($time_type_container[$i-1])):
  1705.                                 if($time_type_container[$i-1]['access_type']!=3):
  1706.                                     $time_body[] = '';
  1707.                                 endif;
  1708.                             else:
  1709.                                 $time_body[] = '';
  1710.                             endif;
  1711.                         }
  1712.                        
  1713.                         if(isset($time_type_container[$i-1])):
  1714.                             if($time_type_container[$i-1]['access_type']==4):
  1715.                                 $time_body[] = '';
  1716.                                 $time_body[] = '';
  1717.                             endif;
  1718.                         endif;
  1719.                        
  1720.                         $time_body[] = $time_type_container[$i]['access_time'];
  1721.                        
  1722.                         if(isset($time_type_container[$i+1])):
  1723.                             if($time_type_container[$i+1]['access_type']!=2):
  1724.                                 $time_body[] = '';
  1725.                             endif;
  1726.                         else:
  1727.                             $time_body[] = '';
  1728.                         endif;
  1729.                        
  1730.                         break;
  1731.                 }
  1732.             }  
  1733.         }
  1734.        
  1735.         return $time_body;
  1736.     }
  1737.    
  1738.     private function checkTimeInFormat($access_container,$i)
  1739.     {
  1740.         $time_body = array();
  1741.         if($access_container[$i+1]['access_type']==2):
  1742.             $time_body[] = '';
  1743.             $time_body[] = '';
  1744.         endif;
  1745.        
  1746.         if($access_container[$i+1]['access_type']==4):
  1747.             $time_body[] = '';
  1748.         endif;
  1749.        
  1750.         return $time_body;
  1751.     }
  1752.    
  1753.     private function checkTimeOutFormat($access_container,$i)
  1754.     {
  1755.         $time_body = array();
  1756.         if(isset($access_container[$i-1]))
  1757.         {
  1758.             if($access_container[$i-1]['access_type']==2):
  1759.                 $time_body[] = '';
  1760.                 $time_body[] = '';
  1761.             endif;
  1762.            
  1763.             if($access_container[$i+1]['access_type']==4):
  1764.                 $time_body[] = '';
  1765.             endif; 
  1766.         }
  1767.         else
  1768.         {
  1769.             $time_body[] = '';
  1770.             $time_body[] = '';
  1771.             $time_body[] = '';
  1772.         }
  1773.        
  1774.         return $time_body;
  1775.     }
  1776.    
  1777.    
  1778.     private function headerLengthDisplay($emp_no,$date_start,$date_end,$result)
  1779.     {
  1780.         $response = $this->getAccessType($emp_no,$date_start,$date_end,$result);
  1781.         $max = 0;
  1782.         $max_iter = 0;
  1783.         $header = array();
  1784.        
  1785.         for($i=0;$i<count($response);$i++)
  1786.         {
  1787.             if(count($response[$i])>=$max):
  1788.                 $max_iter = $i;
  1789.                 $max=count($response[$i]);
  1790.             endif;
  1791.         }
  1792.        
  1793.         if(count($response[$max_iter])>0)
  1794.         {
  1795.             $iter =0;
  1796.             for($x=0;$x<count($response[$max_iter]);$x++)
  1797.             {
  1798.                 $access_type = $response[$max_iter][$x];
  1799.                
  1800.                 switch($access_type)
  1801.                 {
  1802.                     case "1" :
  1803.                        
  1804.                         $header[] = "Time In";
  1805.                        
  1806.                         if(isset($response[$max_iter][$x+1])):
  1807.                             if($response[$max_iter][$x+1]==2):
  1808.                                 $header[] = 'Break';
  1809.                                 $header[] = 'Return';
  1810.                             endif;
  1811.                            
  1812.                             if($response[$max_iter][$x+1]==4):
  1813.                                 $header[] = 'Break';
  1814.                             endif;
  1815.                            
  1816.                             if($response[$max_iter][$x+1]==1):
  1817.                                 $header[] = 'Break';
  1818.                                 $header[] = 'Return';
  1819.                                 $header[] = 'Time Out';
  1820.                             endif;
  1821.                         else:
  1822.                             $header[] = 'Break';
  1823.                             $header[] = 'Return';
  1824.                             $header[] = 'Time Out';
  1825.                         endif;
  1826.                        
  1827.                         break;
  1828.                    
  1829.                     case "2" :
  1830.                        
  1831.                         if(!isset($response[$max_iter][$x-1])):
  1832.                             $header[] = 'Time In';
  1833.                             $header[] = 'Break';
  1834.                             $header[] = 'Return';
  1835.                         endif;
  1836.                        
  1837.                         $header[] = "Time Out";
  1838.                        
  1839.                         if(isset($response[$max_iter][$x+1])):
  1840.                             if($response[$max_iter][$x+1]==2):
  1841.                                 $header[] = 'Time In';
  1842.                                 $header[] = 'Break';
  1843.                                 $header[] = 'Return';
  1844.                             endif;
  1845.                            
  1846.                             if($response[$max_iter][$x+1]==3):
  1847.                                 $header[] = 'Time In';
  1848.                             endif;
  1849.                            
  1850.                             if($response[$max_iter][$x+1]==4):
  1851.                                 $header[] = 'Time In';
  1852.                                 $header[] = 'Break';
  1853.                             endif;
  1854.                         endif;
  1855.                         break;
  1856.                     case "3" :
  1857.                         if(isset($response[$max_iter][$x-1])):
  1858.                             if($response[$max_iter][$x-1]!=1):
  1859.                                 $header[] = 'Time In';
  1860.                             endif;
  1861.                         else:
  1862.                             $header[] = 'Time In';
  1863.                         endif;
  1864.                        
  1865.                         $header[] = "Break";
  1866.                        
  1867.                         //if(isset($time_type_container[$i+1])):
  1868.                         //  if($time_type_container[$i+1]['access_type']!=4):
  1869.                         //      $time_body[] = 'return';
  1870.                         //  endif;
  1871.                         //else:
  1872.                         //  $time_body[] = 'return';
  1873.                         //endif;
  1874.                         //
  1875.                         if(isset($response[$max_iter][$x+1])):
  1876.                             if($response[$max_iter][$x+1]==2):
  1877.                                 $header[] = 'Return';
  1878.                             endif;
  1879.                             if($response[$max_iter][$x+1]==3):
  1880.                                 $header[] = 'Return';
  1881.                                 $header[] = 'Time Out';
  1882.                             endif;
  1883.                         else:
  1884.                             $header[] = 'Return';
  1885.                         endif;
  1886.                        
  1887.                         break;
  1888.                     case "4" :
  1889.                        
  1890.                         if(isset($response[$max_iter][$x-1]))
  1891.                         {
  1892.                             if($response[$max_iter][$x-1]==2):
  1893.                                 $header[] = 'Time In';
  1894.                                 $header[] = 'Break';
  1895.                             endif;
  1896.                         }
  1897.                         else
  1898.                         {
  1899.                             if(isset($response[$max_iter][$x-1])):
  1900.                                 if($response[$max_iter][$x-1]==1):
  1901.                                     $header[] = 'Time In';
  1902.                                 endif;
  1903.                             else:
  1904.                                 $header[] = 'Time In';
  1905.                             endif;
  1906.                            
  1907.                             if(isset($response[$max_iter][$x-1])):
  1908.                                 if($response[$max_iter][$x-1]!=3):
  1909.                                     $header[] = 'Break';
  1910.                                 endif;
  1911.                             else:
  1912.                                 $header[] = 'Break';
  1913.                             endif;
  1914.                         }
  1915.                        
  1916.                         if(isset($response[$max_iter][$x-1])):
  1917.                             if($response[$max_iter][$x-1]==4):
  1918.                                 $header[] = 'Time In';
  1919.                                 $header[] = 'Break';
  1920.                             endif;
  1921.                         endif;
  1922.                        
  1923.                         $header[] = "Return";
  1924.                        
  1925.                         if(isset($response[$max_iter][$x+1])):
  1926.                             if($response[$max_iter][$x+1]!=2):
  1927.                                 $header[] = 'Time Out';
  1928.                             endif;
  1929.                         else:
  1930.                             $header[] = 'Time Out';
  1931.                         endif;
  1932.                        
  1933.                         break;
  1934.                 }
  1935.             }
  1936.         }
  1937.         else
  1938.         {
  1939.             $header[] = 'Time In';
  1940.             $header[] = 'Break';
  1941.             $header[] = 'Return';
  1942.             $header[] = 'Time Out';
  1943.         }
  1944.        
  1945.         return $header;
  1946.     }
  1947.    
  1948.     private function getAccessType($emp_no,$date_start,$date_end,$result)
  1949.     {
  1950.         $iter = 1;
  1951.         $previous_type = '';
  1952.         $header = array();
  1953.         $_container = array();
  1954.        
  1955.         $dates = $this->ConverterModel->DatePeriod_start_end($date_start,$date_end);
  1956.        
  1957.         foreach($dates as $date)
  1958.         {
  1959.             $date = date('Y-m-d',strtotime($date));
  1960.            
  1961.             if($result->num_rows()>0):
  1962.            
  1963.                 foreach($result->result() as $logs)
  1964.                 {
  1965.                     if($logs->server_created_date == $date):
  1966.                         $_container[] = $logs->access_type;
  1967.                     endif;
  1968.                 }
  1969.  
  1970.             endif;
  1971.            
  1972.             $this->_container[] = $_container;
  1973.            
  1974.             $_container = array();
  1975.         }
  1976.        
  1977.         return $this->_container;
  1978.     }
  1979.    
  1980.     private function bindFields($data_rows,$subject_header)
  1981.     {
  1982.         for($i=0;$i<count($data_rows);$i++)
  1983.         {
  1984.             if(isset($subject_header[$i]))
  1985.             {
  1986.                 unset($subject_header[$i]);
  1987.             }
  1988.         }
  1989.        
  1990.         return $this->changeArrayValue($subject_header,$data_rows);
  1991.     }
  1992.    
  1993.     private function changeArrayValue($subject_header,$data_rows)
  1994.     {
  1995.         $iter = count($subject_header)+count($data_rows);
  1996.         for($i=count($data_rows);$i<$iter;$i++)
  1997.         {
  1998.             if($i<$iter)
  1999.             {
  2000.                 $subject_header[$i] = "";
  2001.             }
  2002.            
  2003.         }
  2004.        
  2005.         return $subject_header;
  2006.     }
  2007.    
  2008.     public function generateRawData()
  2009.     {
  2010.         $employee_id = $this->input->get('device_number');
  2011.         $fname = $this->input->get('device_name');
  2012.         $minitial = $this->input->get('minitial');
  2013.         $lname = $this->input->get('lname');
  2014.         $group = $this->input->get('group');
  2015.         $emp_position = $this->input->get('emp_position');
  2016.         $emp_type = $this->input->get('emp_type');
  2017.         $department = $this->input->get('department');
  2018.         $arrange_by_1 = $this->input->get('arrange_by_1');
  2019.         $arrange_by_2 = $this->input->get('arrange_by_2');
  2020.        
  2021.        
  2022.         $daterange = $this->input->get('daterange');
  2023.        
  2024.         if($daterange==''):
  2025.            $date_end  = date('Y-m-d');
  2026.            $date_end  = date('Y-m-d',strtotime($date_end));
  2027.            $date_start = date('Y-m-d',strtotime($date_end." -30 days"));
  2028.         else:
  2029.             $date = explode('-',$daterange);
  2030.             $date_start = date('Y-m-d',strtotime(trim($date[0])));
  2031.             $date_end = date('Y-m-d',strtotime(trim($date[1])));
  2032.         endif;
  2033.        
  2034.         $content = '';
  2035.         $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);
  2036.         // output headers so that the file is downloaded rather than displayed
  2037.         header('Content-Type: text/plain; charset=utf-8');
  2038.         header('Content-Disposition: attachment; filename='.date('mdY').'.txt');
  2039.        
  2040.         foreach($result->result() as $records)
  2041.         {
  2042.             //$content .= $records->employee_student_no.",".date('m/d/Y',strtotime($records->server_created_date))." ".$records->access_time." ".$records->access_type." ".
  2043.             //$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";
  2044.             $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";
  2045.         }
  2046.        
  2047.         echo $content;
  2048.     }
  2049.    
  2050.     private function accessTypeFormat($access_type)
  2051.     {
  2052.         $access_format= '';
  2053.         switch($access_type)
  2054.         {
  2055.             case "1" : $access_format = ">"; break;
  2056.             case "2" : $access_format = "<"; break;
  2057.             case "3" : $access_format = "<"; break;
  2058.             case "4" : $access_format = ">"; break;
  2059.         }
  2060.        
  2061.         return $access_format;
  2062.     }
  2063.    
  2064.     //For applicable users only
  2065.    
  2066.     public function lateOrEarlyComing($time,$employee_id,$start_time)
  2067.     {
  2068.         $today = date('Y-m-d');
  2069.        
  2070.         if($time=='')
  2071.         {
  2072.             $time = "00.00";
  2073.         }
  2074.         else
  2075.         {
  2076.             if(strtotime($time) > strtotime($start_time))
  2077.             {
  2078.                 $formated_time=$this->ConverterModel->dateTimeComuptation($start_time,$time,$today);
  2079.                 $time =  $formated_time;
  2080.                
  2081.                 $this->_late += 1;
  2082.             }
  2083.             else
  2084.             {
  2085.                 $time = "00.00";
  2086.             }  
  2087.         }
  2088.        
  2089.         return $time;
  2090.     }
  2091.    
  2092.     private function accumulatedTime($start_time,$end_time,$date,$employee_id)
  2093.     {
  2094.         if($start_time=='' && $end_time=='')
  2095.         {
  2096.             $formated_time = "00.00";
  2097.         }
  2098.         else
  2099.         {
  2100.             $formated_time = $this->ConverterModel->dateTimeComuptation($start_time,$end_time,$date);
  2101.         }
  2102.        
  2103.         return $formated_time;
  2104.     }
  2105.    
  2106.     public function summaryExtensionHeader($show_array)
  2107.     {
  2108.         $header = array();
  2109.         if($show_array[0] == "on"):
  2110.             $header[] = 'Day Present';
  2111.         endif;
  2112.        
  2113.         if($show_array[1]=="on"):
  2114.             $header[] = 'Late';
  2115.         endif;
  2116.        
  2117.         if($show_array[2] == "on"):
  2118.             $header[] = 'Undertime';
  2119.         endif;
  2120.        
  2121.         if($show_array[3] == "on"):
  2122.             $header[] = 'Overload';
  2123.         endif;
  2124.        
  2125.         if($show_array[4]=="on"):
  2126.             $header[] = 'Day Absent';
  2127.         endif;
  2128.        
  2129.         return $header;
  2130.     }
  2131.    
  2132.     public function extensionHeader($show_array,$show_remarks)
  2133.     {
  2134.         $header = array();
  2135.         if($show_array[0] == "on"):
  2136.             $header[] = 'Present';
  2137.         endif;
  2138.        
  2139.         if($show_array[4]=="on"):
  2140.             $header[] = 'Absent';
  2141.         endif;
  2142.        
  2143.         if($show_array[1]=="on"):
  2144.             $header[] = 'Late';
  2145.         endif;
  2146.        
  2147.         if($show_array[2] == "on"):
  2148.             $header[] = 'Undertime';
  2149.         endif;
  2150.        
  2151.         if($show_remarks=="on"):
  2152.             $header[] = 'Remarks';
  2153.         endif;
  2154.        
  2155.         if($show_array[3] == "on"):
  2156.             $header[] = 'Overload';
  2157.         endif;
  2158.        
  2159.         return $header;
  2160.     }
  2161. }
  2162.  
  2163. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement