MOON
Server: Apache
System: Linux nserver.cafsindia.com 4.18.0-553.104.1.lve.el8.x86_64 #1 SMP Tue Feb 10 20:07:30 UTC 2026 x86_64
User: cafsindia (1002)
PHP: 8.2.30
Disabled: NONE
Upload Files
File: /home/cafsindia/hrms_cafsinfotech_in/OLD/ZRM/application/controllers/Timecard_generation.php
<?php if ( ! defined('BASEPATH')) exit('No direct script is allowed');
require_once("Action_controller.php");
require('./application/libraries/dompdf/autoload.inc.php');
use Dompdf\Dompdf;
use DOMDocument;
class Timecard_generation  extends Action_controller{	
	private $emp_data_rslt;
	public function __construct(){
		parent::__construct('timecard_generation');
		$emp_data_qry = 'SELECT employee_code,emp_name,date_of_birth,date_of_joining FROM cw_employees WHERE cw_employees.trans_status = 1';
		$emp_data     = $this->db->query("CALL sp_a_run ('SELECT','$emp_data_qry')");
		$empresult = $emp_data->result_array();
		$emp_data->next_result();
		$this->emp_data_rslt = array_reduce($empresult, function ($result, $arr) {		
			    $result[$arr['employee_code']] = $arr;
			    return $result;
			}, array());	
	}
	
	// LOAD PAGE QUICK LINK,FILTERS AND TABLE HEADERS
	public function index(){
		//Get Category
		$role_info   = $this->db->query("CALL sp_a_run ('SELECT','SELECT * FROM `cw_category` where trans_status = 1 and prime_category_id !=1')");
		$role_result = $role_info->result();
		$role_info->next_result();
		$category_list[""] = "---- Select Category ----";
		foreach($role_result as $for){
			$role_id                 = $for->prime_category_id;
			$category_name           = $for->category_name;
			$category_list[$role_id] = $category_name;
		}
		$data['category_list'] = $category_list;

		//Get filter
		$from_query = 'select * from cw_form_setting where prime_module_id = "employees" and field_show = "1" ORDER BY input_for,field_sort asc';
		$form_data   = $this->db->query("CALL sp_a_run ('SELECT','$from_query')");
		$form_result = $form_data->result();
		$form_data->next_result();
		$fliter_list = $this->get_filter_data($form_result);
		$data['fliter_list']  = $fliter_list;

		$this->load->view("$this->control_name/manage",$data);
	}
	//PROVIDE QUERY AND DROPDOWN VALUES 
	public function get_filter_data($form_result){
		$filter = array();
		foreach($form_result as $setting){
			$prime_form_id      = (int)$setting->prime_form_id;
			$prime_module_id    = $setting->prime_module_id;
			$input_view_type    = (int)$setting->input_view_type;
			$input_for          = (int)$setting->input_for;
			$field_type         = (int)$setting->field_type;
			$label_id           = $setting->label_name;
			$label_name         = ucwords($setting->view_name);
			$field_length       = $setting->field_length;
			$field_decimals     = $setting->field_decimals;
			$pick_list_type     = (int)$setting->pick_list_type;
			$pick_list          = $setting->pick_list;
			$pick_table         = $setting->pick_table;
			$auto_prime_id      = $setting->auto_prime_id;
			$auto_dispaly_value = $setting->auto_dispaly_value;
			$field_isdefault    = (int)$setting->field_isdefault;
			$file_type          = (int)$setting->file_type;
			$mandatory_field    = (int)$setting->mandatory_field;
			$unique_field       = (int)$setting->unique_field;
			$search_show        = (int)$setting->search_show;
			$array_list = array();
			if($label_id != 'role' && $label_id != 'employee_code' && $label_id != 'emp_name'){
				if(($field_type === 5) || ($field_type === 7)){
					if($pick_list_type === 1){
						$pick_list_val   = explode(",",$pick_list);
						$pick_list_val_1 = $pick_list_val[0];
						$pick_list_val_2 = $pick_list_val[1];
						if($pick_table == "cw_category"){
							$qry = " and prime_category_id != 1";
							}else{
							$qry = "";
						}
						if($pick_table == "cw_payroll_formula"){
							$pick_query = "select $pick_list from $pick_table where trans_status = 1";
							$pick_data   = $this->db->query("CALL sp_a_run ('SELECT','$pick_query')");
							$pick_result = $pick_data->result();
							$pick_data->next_result();
							$array_list[""] = "---- $label_name ----";
							foreach($pick_result as $pick){
								$pick_key = $pick->$pick_list_val_1;
								$pick_val = ucwords(str_replace("_"," ",$pick->$pick_list_val_2));
								$array_list[$pick_key] = $pick_val;
							}
						}else{
							if($label_id === "excemption_component"){
								$pick_query = "select $pick_list from $pick_table where trans_status = 1 and tax_section = 1 $qry";
								}else{
								$pick_query = "select $pick_list from $pick_table where trans_status = 1 $qry";
							}
							$pick_data   = $this->db->query("CALL sp_a_run ('SELECT','$pick_query')");
							$pick_result = $pick_data->result();
							$pick_data->next_result();
							
							$array_list[""] = "---- $label_name ----";
							foreach($pick_result as $pick){
								$pick_key = $pick->$pick_list_val_1;
								$pick_val = $pick->$pick_list_val_2;
								$array_list[$pick_key] = $pick_val;
							}
						}
					}else
					if($pick_list_type === 2){ 
						$pick_list_val_1 = $pick_table."_id";
						$pick_list_val_2 = $pick_table."_value";
						$pick_list_val_3 = $pick_table."_status";
						
						$pick_query = "select $pick_list_val_1,$pick_list_val_2 from $pick_table where $pick_list_val_3 = 1";
						$pick_data   = $this->db->query("CALL sp_a_run ('SELECT','$pick_query')");
						$pick_result = $pick_data->result();
						$pick_data->next_result();
						
						$array_list[""] = "---- $label_name ----";
						foreach($pick_result as $pick){
							$pick_key = $pick->$pick_list_val_1;
							$pick_val = $pick->$pick_list_val_2;
							$array_list[$pick_key] = $pick_val;
						}
					}
				}		
				if(($input_view_type === 1) || ($input_view_type === 2)){
					$filter[] = array('label_id'=> $label_id, 'field_isdefault'=> $field_isdefault, 'array_list'=> $array_list, 'field_type'=> $field_type);
				}
			}
		}
		return $filter;
	}
	// Get Employee Code
	public function get_employees_list(){
		$category          = $this->input->post('category');
		$timecard_month    = $this->input->post('timecard_month');
		$emp_detail_query  = 'SELECT CONCAT("<option value =",cw_employees.employee_code," >",cw_employees.emp_name," - ",cw_employees.employee_code,"</option>") as result_data FROM cw_employees WHERE cw_employees.role in ('.$category.') ';
		$emp_detail_info   = $this->db->query("CALL sp_a_run ('SELECT','$emp_detail_query')");
		$emp_detail_result = $emp_detail_info->result();
		$emp_detail_info->next_result();
		$result_data       = array_column($emp_detail_result,'result_data');
    
		$option            = "<option value=''>---- Select Employee ----</option>".implode('',$result_data);		
		if(empty($emp_detail_result)){
			echo json_encode(array('success'=>FALSE,'message'=>"No Data Found for this Month"));
		}else{
			echo json_encode(array('success'=>TRUE,'option'=>$option));
		}	
	}
	// Pdf Generate
	public function timecard_generation(){
		$category            = $this->input->post('category');
		$timecard_month      = $this->input->post('timecard_month');
		$fliter_label        = $this->input->post('fliter_label');
		$fliter_type         = $this->input->post('fliter_type');
		$filter_cond         = $this->input->post('filter_cond');
		$fliter_val          = $this->input->post('fliter_val');
		$input_field_type    = $this->input->post('input_field_type');
		$process_by          = $this->input->post('process_by');
		$process_mode  		 = $this->input->post('process_mode');
		$filter_count        = count($fliter_label);
		$fliter_query        = "";
		$search_count        = 0;
		//Get from date & to date to generate timecard design
		$salary_arr          = $this->tos_sal_strt_end_info("4",$timecard_month);
		$timecard_start_date = date("Y-m-d",strtotime($salary_arr['salary_start_date']));
		$timecard_end_date   = date("Y-m-d",strtotime($salary_arr['salary_end_date']));
	
		for($i=0;$i<=(int)$filter_count;$i++){
			$db_name     = $fliter_label[$i];
			$table_name  = $fliter_type[$i];
			$db_cond     = $filter_cond[$i];
			$db_value    = $fliter_val[$i];
			$field_type  = $field_type[$i];
			if(($db_cond) && ($db_value)){
				$search_count++;
				if((int)$field_type === 4){
					$search_val = date("Y-m-d",strtotime($db_value));
				}else{
					$search_val = $db_value;
				}
				if($db_cond === "LIKE"){ $search_val = "$db_value%"; }
				if((int)$table_name === 1){ 
					$fliter_query .= ' and cw_employees.'. $db_name ." ". $db_cond .' "'.$search_val.'"';
				}
			}			
		}

		$category_info   = $this->db->query("CALL sp_a_run ('SELECT','SELECT category_name FROM `cw_category` where trans_status = 1 and prime_category_id = $category')");
		$category_result = $category_info->result();
		$category_info->next_result();
		$category_name   = $category_result[0]->category_name;
		$category_name   = strtolower(str_replace(" ","_",$category_name));

		$month_day_qry         = 'SELECT category,day_conditions,day_count,day_start,day_end from cw_month_day where cw_month_day.category = "'.$category.'" and cw_month_day.trans_status = 1';
		$month_day_info        = $this->db->query("CALL sp_a_run ('SELECT','$month_day_qry')");
        $month_day_result      = $month_day_info->result_array();
        $month_day_info->next_result();
        if($month_day_result){
			$role           = $month_day_result['category'];
			$day_conditions = $month_day_result['day_conditions'];
			$day_count      = $month_day_result['day_count'];
			$day_start      = $month_day_result['day_start'];
			$day_end        = $month_day_result['day_end'];
			if((int)$day_conditions === 3){
				$sal_start = $day_start;
				//For Current month between days increment
				$date = new DateTime("01-$timecard_month 00:00:00");
				$date->modify('-1 month');
				$salary_start_date = $date->format("Y-m-$sal_start");	
				$salary_end_date   = date("Y-m-d",strtotime($day_end."-".$timecard_month));
			}else{
				$sal_start = '01';
				$date = new DateTime("01-$timecard_month 00:00:00");
				$salary_start_date = $date->format("Y-m-$sal_start");	
				if((int)$day_conditions === 2){
					$salary_end_date   = date("Y-m-d",strtotime($day_end."-".$timecard_month));
				}else{
					$salary_end_date   = date("Y-m-t",strtotime($day_end."-".$timecard_month));
				}
			}        	
        }

        if((int)$process_by === 1){
			$emp_code_arr 		= $this->input->post('pdf_block_employees');
		}else{
			if($fliter_query){
				$qry = $fliter_query;
			}else{
				$qry = '';
			}
			$emp_qry 	= 'SELECT prime_employees_id,emp_name,employee_code FROM cw_employees where trans_status = 1 and role = "'.$category.'"'.$qry;
			$emp_info   = $this->db->query("CALL sp_a_run ('SELECT','$emp_qry')");
			$emp_rslt 	= $emp_info->result_array();
			$emp_info->next_result();

			foreach($emp_rslt as $arr){
				$result[$arr['employee_code']] = $arr;
			}
			$emp_code_arr = array_values(array_column($result, 'employee_code'));
		}		
		$table_data = $this->get_timecard_design($emp_code_arr,$timecard_start_date,$timecard_end_date,$category_name,$timecard_month);
		if($table_data){
			echo json_encode(array('success' => true,'message' => 'Timecard Successfully Generated', 'table_data' =>$table_data));
		}else{
			echo json_encode(array('success' => false,'message' => 'Please Try After Sometime', 'table_data' =>$table_data));
		}		
	}
	public function get_timecard_design($emp_code_arr,$salary_start_date,$salary_end_date,$category_name,$timecard_month){
		$salary_start = date("d-m-Y",strtotime($salary_start_date));
		$salary_end   = date("d-m-Y",strtotime($salary_end_date));

		$time_qry 	= 'SELECT employee_code,att_date,punch_in,punch_out,total_work_hours,total_late_hours,total_excess_hours,whole_day_status,total_permission FROM cw_time_entry where cw_time_entry.trans_status = 1 and att_date between "'.$salary_start_date.'" and "'.$salary_end_date.'"';
		$time_info   = $this->db->query("CALL sp_a_run ('SELECT','$time_qry')");
		$time_rslt 	= $time_info->result_array();
		$time_info->next_result();

		$time_rslt = array_reduce($time_rslt, function ($result, $arr) {
		    $result[$arr['employee_code']][$arr['att_date']] = $arr;
		    return $result;
		}, array());

		$time_wrong_qry 	= 'SELECT employee_code,att_date,punch_in,punch_out,record_type FROM cw_time_wrong_entry where cw_time_wrong_entry.trans_status = 1 and att_date between "'.$salary_start_date.'" and "'.$salary_end_date.'"';
		$time_wrong_info    = $this->db->query("CALL sp_a_run ('SELECT','$time_wrong_qry')");
		$time_wrong_rslt 	= $time_wrong_info->result_array();
		$time_wrong_info->next_result();

		$time_wrong_rslt = array_reduce($time_wrong_rslt, function ($result, $arr) {
		    $result[$arr['employee_code']][$arr['att_date']] = $arr;
		    return $result;
		}, array());
		//Get Shift Result
		$shift_qry 	= 'SELECT employee_code,att_date,short_name FROM cw_time_entry inner join cw_shift_master on cw_shift_master.prime_shift_master_id = cw_time_entry.shift_id where cw_time_entry.trans_status = 1 and att_date between "'.$salary_start_date.'" and "'.$salary_end_date.'"';
		$shift_info   = $this->db->query("CALL sp_a_run ('SELECT','$shift_qry')");
		$shift_rslt 	= $shift_info->result_array();
		$shift_info->next_result();

		$shift_rslt = array_reduce($shift_rslt, function ($result, $arr) {
		    $result[$arr['employee_code']][$arr['att_date']] = $arr;
		    return $result;
		}, array());

		$holiday_qry 	= 'SELECT holiday_date FROM cw_holiday_entry inner join cw_holiday_entry_holiday_data on cw_holiday_entry_holiday_data.prime_holiday_entry_id = cw_holiday_entry.prime_holiday_entry_id where cw_holiday_entry_holiday_data.trans_status = 1 and holiday_date between "'.$salary_start_date.'" and "'.$salary_end_date.'"';
		$holiday_info   = $this->db->query("CALL sp_a_run ('SELECT','$holiday_qry')");
		$holiday_rslt 	= $holiday_info->result_array();
		$holiday_info->next_result();

		$holiday_rslt = array_reduce($holiday_rslt, function ($result, $arr) {		
		    $result[$arr['holiday_date']] = $arr;
		    return $result;
		}, array());

		$weekoff_qry 	= 'SELECT employee_code,weekoff_date,weekoff_type FROM cw_weekoff_import where cw_weekoff_import.trans_status = 1 and weekoff_date between "'.$salary_start_date.'" and "'.$salary_end_date.'"';
		$weekoff_info   = $this->db->query("CALL sp_a_run ('SELECT','$weekoff_qry')");
		$weekoff_rslt 	= $weekoff_info->result_array();
		$weekoff_info->next_result();

		$weekoff_rslt = array_reduce($weekoff_rslt, function ($result, $arr) {
		    $result[$arr['employee_code']][$arr['weekoff_date']] = $arr;
		    return $result;
		}, array());

		//Get Date Period Between Two Dats
		$date_period = new DatePeriod(
		     new DateTime($salary_start_date),
		     new DateInterval('P1D'),
		     new DateTime(date("Y-m-d",strtotime("+1 days",strtotime($salary_end_date))))
		);
		$leave_arr         = array("L"=>1,"FL"=>0.5,"SL"=>0.5,"LP"=>0.5,"PL"=>0.5,"LM"=>0.5,"ML"=>0.5,"OL"=>0.5,"LO"=>0.5,"LL"=>1,"WL"=>0.5,"LW"=>0.5,"UL"=>0.5,"LU"=>0.5,"IL"=>0.5,"LI"=>0.5);
		$present_arr       = array("P"=>1,"FP"=>0.5,"SP"=>0.5,"LP"=>0.5,"PL"=>0.5,"PM"=>0.5,"MP"=>0.5,"OP"=>0.5,"PO"=>0.5,"PP"=>1,"IP"=>0.5,"PI"=>0.5,"PU"=>0.5,"UP"=>0.5);
		$onduty_arr        = array("O"=>1,"FO"=>0.5,"SO"=>0.5,"OP"=>0.5,"PO"=>0.5,"OM"=>0.5,"MO"=>0.5,"OL"=>0.5,"LO"=>0.5,"OO"=>1,"WO"=>0.5,"OW"=>0.5,"UO"=>0.5,"OU"=>0.5,"IO"=>0.5,"OI"=>0.5);
		$mpunch_arr        = array("M"=>1,"FM"=>0.5,"SM"=>0.5,"MP"=>0.5,"PM"=>0.5,"OM"=>0.5,"MO"=>0.5,"ML"=>0.5,"LM"=>0.5,"MM"=>1,"WM"=>0.5,"MW"=>0.5,"UM"=>0.5,"MU"=>0.5,"IM"=>0.5,"MI"=>0.5);
		$weekoff_arr       = array("W"=>1,"WL"=>0.5,"LW"=>0.5,"WO"=>0.5,"OW"=>0.5,"WM"=>0.5,"MW"=>0.5);
		$unpunch_arr       = array("U"=>1,"UL"=>0.5,"LU"=>0.5,"UO"=>0.5,"OU"=>0.5,"UM"=>0.5,"MU"=>0.5,"UP"=>0.5,"PU"=>0.5,"FP"=>0.5,"SP"=>0.5,"IU"=>0.5,"UI"=>0.5,"FL"=>0.5,"SL"=>0.5);
		$invalid_arr       = array("I"=>1,"IL"=>0.5,"LI"=>0.5,"IO"=>0.5,"OI"=>0.5,"IM"=>0.5,"MI"=>0.5,"IU"=>0.5,"UI"=>0.5,"IP"=>0.5,"PI"=>0.5);
		$folder 	       = "./timecard/$category_name/".$timecard_month;
		foreach($emp_code_arr as $emp_code){
			$tr_line       = "";
			$woff_count    = 0;
			$present_count = 0;
			$late_count    = 0;
			$leave_count   = 0;
			$onduty_count  = 0;
			$holiday_count  = 0;
			$holiday_work_count  = 0;
			$holiday_work_mins  = 0;
			$woff_work_count  = 0;
			$woff_work_mins  = 0;
			foreach ($date_period as $key => $value){
			    $att_day  = $value->format('D');
			    $att_date = $value->format('Y-m-d');
			    $dis_date = $value->format('d-m-Y');

			    if($time_rslt[$emp_code][$att_date]['punch_in']){
			    	$punch_in   		= date("H:i",strtotime($time_rslt[$emp_code][$att_date]['punch_in']));
			    }else
			    if($time_wrong_rslt[$emp_code][$att_date]['punch_in']){
			    	$punch_in   		= date("H:i",strtotime($time_wrong_rslt[$emp_code][$att_date]['punch_in']));
			    }else{
			    	$punch_in   		= "-";
			    }
			    if($time_rslt[$emp_code][$att_date]['punch_out']){
			    	$punch_out  		= date("H:i",strtotime($time_rslt[$emp_code][$att_date]['punch_out']));
			    }else
			    if($time_wrong_rslt[$emp_code][$att_date]['punch_out']){
			    	$punch_out   		= date("H:i",strtotime($time_wrong_rslt[$emp_code][$att_date]['punch_out']));
			    }else{
			    	$punch_out  		= "-";
			    }
			    if($shift_rslt[$emp_code][$att_date]['short_name']){
			    	$shift_name         = $shift_rslt[$emp_code][$att_date]['short_name'];
			    }else{
			    	$shift_name  		= "-";
			    }
			    if($time_rslt[$emp_code][$att_date]['total_work_hours']){
			    	$minutes = $time_rslt[$emp_code][$att_date]['total_work_hours'];
			    	$total_work_hours   = intdiv($minutes, 60).':'. ($minutes % 60);
			    	$total_work_hours   = number_format((float)$total_work_hours, 2, '.', '');
			    }else{
			    	$total_work_hours   = "-";
			    }
			    if($time_rslt[$emp_code][$att_date]['total_late_hours']){
			    	$minutes = $time_rslt[$emp_code][$att_date]['total_late_hours'];
			    	$total_late_hours   = intdiv($minutes, 60).':'. ($minutes % 60);
			    	//$total_late_hours   = number_format((float)$total_late_hours, 2, '.', '');
			    	$late_count = $late_count +1;
			    }else{
			    	$total_late_hours  	= "-";
			    }
			    if($time_rslt[$emp_code][$att_date]['total_excess_hours']){
			    	$minutes = $time_rslt[$emp_code][$att_date]['total_excess_hours'];
			    	$total_excess_hours   = intdiv($minutes, 60).':'. ($minutes % 60);
			    	//$total_excess_hours   = number_format((float)$total_excess_hours, 2, '.', '');
			    }else{
			    	$total_excess_hours = "-";
			    }
			    if($time_rslt[$emp_code][$att_date]['approved_ot_mins']){
			    	$minutes = $time_rslt[$emp_code][$att_date]['approved_ot_mins'];
			    	$approved_ot_mins   = intdiv($minutes, 60).':'. ($minutes % 60);
			    	//$approved_ot_mins   = number_format((float)$approved_ot_mins, 2, '.', '');
			    }else{
			    	$approved_ot_mins  	= "-";
			    }
			    if($time_rslt[$emp_code][$att_date]['whole_day_status']){ // MODIFIED BY [MS 21-09-2024]
			    	$whole_day_status   = $time_rslt[$emp_code][$att_date]['whole_day_status'];
			    	if($present_arr[$whole_day_status]){   // PRESENT
			    		$present_count = $present_count + $present_arr[$whole_day_status];
			    	}
			    	if($leave_arr[$whole_day_status]){     // LEAVE OR ABSENT
			    		$leave_count = $leave_count + $leave_arr[$whole_day_status];
			    	}
			    	if($onduty_arr[$whole_day_status]){ //ONDUTY
						$onduty_count       = $onduty_count + $onduty_arr[$whole_day_status];
						// $present_count      = $onduty_count + $present_arr[$whole_day_status];
					}
			    	if($mpunch_arr[$whole_day_status]){    // MANUAL PUNCH
			    		$present_count = $present_count + $mpunch_arr[$whole_day_status];
			    	}
			    	if($whole_day_status === "H"){ // HOLIDAY
			    		$holiday_count          = $holiday_count + 1; 	
			    	}
			    	
			    	if($weekoff_arr[$whole_day_status]){	 // WEEKOFF		    		
			    		$woff_count             = $woff_count + $weekoff_arr[$whole_day_status];
			    	} 
			    	if($unpunch_arr[$whole_day_status]){   // UNPUNCH
			    		$present_count = $present_count + $unpunch_arr[$whole_day_status];
			    	}
			    	if($invalid_arr[$whole_day_status]){   // INVALID 
			    		$present_count = $present_count + $invalid_arr[$whole_day_status];
			    	}
			    }else
			    if($time_wrong_rslt[$emp_code][$att_date]['record_type']){
			    	$whole_day_status   = "IP";
			    }else
			    if($holiday_rslt[$att_date]){
			    	$woff_count = $woff_count + 1;
			    	$whole_day_status   = "H";
			    }else
			    if($weekoff_rslt[$emp_code][$att_date]){
			    	$woff_count = $woff_count + 1;
			    	$whole_day_status   = "W";
			    }else{
			    	$whole_day_status  	= "-";
			    }
			    if($time_rslt[$emp_code][$att_date]['total_permission']){
			    	$total_permission   = $time_rslt[$emp_code][$att_date]['total_permission'];
			    }else{
			    	$total_permission  	= "-";
			    }
			    
			    $tr_line .= "<tr><td style='text-align:left;border-top: 1px solid black;border-right: 1px solid black;padding: 5px;'>$dis_date $att_day</td style='text-align:center;border-top: 1px solid black;border-right: 1px solid black;padding: 5px;'><td style='text-align:center;border-top: 1px solid black;border-right: 1px solid black;padding: 5px;'>$punch_in</td><td style='text-align:center;border-top: 1px solid black;border-right: 1px solid black;padding: 5px;'>$punch_out</td><td style='text-align:center;border-top: 1px solid black;border-right: 1px solid black;padding: 5px;'>$shift_name</td><td style='text-align:center;border-top: 1px solid black;border-right: 1px solid black;padding: 5px;'>$total_work_hours</td><td style='text-align:center;border-top: 1px solid black;border-right: 1px solid black;padding: 5px;'>$total_late_hours</td><td style='text-align:center;border-top: 1px solid black;border-right: 1px solid black;padding: 5px;'>$total_permission</td><td style='text-align:center;border-top: 1px solid black;border-right: 1px solid black;padding: 5px;'>$total_excess_hours</td><td style='text-align:center;border-top: 1px solid black;border-right: 1px solid black;padding: 5px;'>$approved_ot_mins</td><td style='text-align:center;border-top: 1px solid black;padding: 5px;'>$whole_day_status</td></tr>";
			} 
			$woff_hday     = $woff_count + $holiday_count;
			$emp_name      = $this->emp_data_rslt[$emp_code]['emp_name'];
			$department    = $this->emp_data_rslt[$emp_code]['department'];
			$company_info  = $this->company_info();
			$table_content = "<table style='width: 100%;border:1px solid #000000;'>
								<tbody>
									<tr>
										<td style='width: 16.0585%;'><img src='".$company_info[0]->company_logo."' style='width: 300px;' class='fr-fic fr-dib'></td>
										<td style='width: 83.862%;'>
											<p style='text-align: center;'><b>".$company_info[0]->company_name."<br>".$company_info[0]->address.",".$company_info[0]->city.",".$company_info[0]->state."<br> .&nbsp;</b></p>
											<p style='text-align: center;'><b>TIMECARD REPORT</b></p>
											<p style='text-align: center;'><b>Employee Attendance For $salary_start - $salary_end </b></p>
											<p style='text-align: center;'> (Prescribed under Rules 103-B of the Factories Rules,1950) </p>
											<div style='text-align: right;'><b>Form- 25B</b></div>
										</td>
									</tr>
							</table>
							<table style='width: 100%;border:1px solid #000000;'>
							<tbody>
								<tr>
									<td><b>Employee Code</b> :</td>
									<td> $emp_code </td>
									<td style='text-align:center;'><b>Department</b> :</td>
									<td style='text-align:center;'> $department </td>
								</tr>

							</tbody>
							</tbody>
							</table>
						<table class='table table-striped table-bordered' id='attendance_report' style='width:100%;border:1px solid #000;'>
						<thead>
							<tr>
								<th style='text-align:center;padding: 5px;border-right: 1px solid black;'>Date</th>
								<th style='text-align:center;padding: 5px;border-right: 1px solid black;'>In Time</th>
								<th style='text-align:center;padding: 5px;border-right: 1px solid black;'>Out Time</th>
								<th style='text-align:center;padding: 5px;border-right: 1px solid black;'>Shift</th>
								<th style='text-align:center;padding: 5px;border-right: 1px solid black;'>Wrk. Hrs</th>
								<th style='text-align:center;padding: 5px;border-right: 1px solid black;'>Late</th>
								<th style='text-align:center;padding: 5px;border-right: 1px solid black;'>Permission</th>
								<th style='text-align:center;padding: 5px;border-right: 1px solid black;'>OT</th>
								<th style='text-align:center;padding: 5px;border-right: 1px solid black;'>Ex Hours</th>
								<th style='text-align:center;padding: 5px;'>Day Status</th>
							</tr>
						</thead>
						<tbody>
							$tr_line
						</tbody>
					</table><br/>
					<table style='width: 100%;'>
						<tbody>
							<tr>
								<td><b>Total Present</b></td>
								<td> $present_count </td>
								<td ><b>Total Absent</b></td>
								<td > $leave_count </td>
								<td ><b>Onduty Count</b></td>
								<td > $onduty_count </td>
								<td><b>Total Weekoff and Holiday</b></td>
								<td> $woff_hday </td>
								<td ><b>Total Late Count</b></td>
								<td > $late_count </td>
							</tr>
						</tbody>
					</table>";
			$path = $this->generate_pdf_bulk($table_content,$folder,$emp_code);		
		}
		return $this->view_emp_details($emp_code_arr,$category_name,$timecard_month);		
	}

	public function generate_pdf_bulk($table_content,$folder,$file_name){
	        $pdf = new DOMPDF(array('enable_remote' => true,"enable_font_subsetting" => true));
			// Load HTML content 
			$pdf->loadHtml($table_content);
			// (Optional) Setup the paper size and orientation
			//$pdf->setPaper($paper_size, $set_paper);
			$pdf->setPaper('A3', 'portrait');
			// Render the HTML as PDF			
			$pdf->render();

			if($pdf_set_password === "1"){
				//SET Production
				$dob = date("d-m-Y",strtotime($this->emp_data_rslt[$file_name]['date_of_birth']));
				$doj = date("d-m-Y",strtotime($this->emp_data_rslt[$file_name]['date_of_joining']));
				$password = $dob."@".$doj;
				$password = str_replace("-", "", $password);
				$pdf->get_canvas()->get_cpdf()->setEncryption($password, $password);
			}        
			// Output the generated PDF (1 = download and 0 = preview)
			$final_html 	= $pdf->output();
			$oldmask 	= umask(0);
			if (!file_exists($folder)){
				mkdir($folder, 0777, true);
			}
			//File write
			file_put_contents($folder."/".$file_name.".pdf" , $final_html);
			chmod($folder."/".$file_name.$file_type, 0777);
			umask($oldmask);		
			$path = $folder."/".$file_name.".pdf";
			return $path;
	}
	
	public function view_emp_details($emp_code_arr,$category_name,$timecard_month){
		$tble_line = "";
		foreach ($emp_code_arr as $key => $emp_code) {
			$emp_name 		   = $this->emp_data_rslt[$emp_code]['emp_name'];
			$file_path         = "timecard/".$category_name."/".$timecard_month."/".$emp_code.".pdf";
			$exist_file 	   = "timecard/".$category_name."/".$timecard_month."/".$emp_code.".pdf";
			$exist_process 	   = true;  
			if((int)$process_mode === 2){
				if(file_exists($exist_file)){
					$exist_process = true;
				}else{
					$exist_process = false;
				}
			}
			$file_path   	   = base_url().$file_path;
			$enc_path    	   = base64_encode($file_path);
			$filename    	   = dirname(__FILE__).$file_path;
			$filename    	   = str_replace("application\controllers","",$filename);
			if($exist_process){
				$tble_line .= "	<tr class='gradeU'>
								<td>$emp_code</td>
								<td>$emp_name</td>
								<td>
									<a class='btn btn-primary btn-sm' onclick=pdf_viewer('$enc_path')><span class='fa fa-eye' >&nbsp;</span> view </a>
									<a class='btn btn-primary btn-sm' onclick=download_timecard('download_$emp_code','$enc_path') id='download_$emp_code' download '><span class='fa fa-download' download>&nbsp;</span> Download </a>
								</td>
							</tr>";
			}
		}
		if((int)$process_by === 2){
			$tfoot_list ="<tfoot>
						<tr class='gradeU'><td></td><td style='text-align:center;'><a class='btn btn-primary btn-sm' onclick = download_zip('$dw_all') ><span class='fa fa-download' >&nbsp;</span> Download All </a></td><td></td></tr>
					</tfoot>";
		}else{
			$tfoot_list ="";
		}
		$table_data = "	<table class='table table-striped table-bordered' id='emp_details'>
						<thead>
							<tr>
							<th>Employee Code</th>
							<th>Employee Name</th>
							<th>Action</th>
							</tr>
						</thead>
						<tbody>
							$tble_line
						</tbody>
							$tfoot_list
					</table>";
		return $table_data;
	}
}
?>