File: //home/cafsindia/hrms_allyindian_com/application_bk/controllers/Work_sheet.php
<?php if ( ! defined('BASEPATH')) exit('No direct script is allowed');
require_once("Action_controller.php");
class Work_sheet extends Action_controller{
public function __construct(){
parent::__construct('Work_sheet');
}
// LOAD PAGE QUICK LINK,FILTERS AND TABLE HEADERS
public function index(){
$data['key'] = $this->generateKey();
$employee_info_query = 'SELECT employee_code,emp_name FROM `cw_employees` where trans_status = 1 and prime_employees_id !=1 '.$this->role_condition;
$employee_info = $this->db->query("CALL sp_a_run ('SELECT','$employee_info_query')");
$employee_result = $employee_info->result();
$employee_info->next_result();
$employee_list[""] = "---- Select Employee ----";
foreach($employee_result as $for){
$emp_code = $for->employee_code;
$emp_name = $for->emp_name;
$employee_list[$emp_code] = $emp_code." - ".$emp_name;
}
$data['employee_list'] = $employee_list;
$this->load->view("$this->control_name/manage",$data);
}
public function check_worksheet(){
$encString = file_get_contents('php://input');
$_POST = $this->cryptoDecrypt($encString);
if(!$_POST){
echo json_encode(array('success' => false,'message' => 'Url Expired.. Please refresh the page and try again....','table_data' => ""));
exit(0);
}
$emp_code = $this->session->userdata('logged_emp_code'); // [MS 09-11-2024]
$from_month = $this->input->post('from_month');
$to_month = $this->input->post('to_month');
$start_date = "01-".$from_month;
$end_date = "01-".$to_month;
$start_date = date('Y-m-d', strtotime($start_date));
$end_date = date('Y-m-d', strtotime($end_date));
$start = strtotime($start_date);
$month = strtotime($start_date);
$end = strtotime($end_date);
$tble_line = "";
$tble_no_line = "";
$i = 0;
$j = 0;
$db_name = $this->config->item("db_name");
$emp_cat_qry = 'SELECT cw_category.category_name FROM `cw_employees` inner join cw_category on cw_category.prime_category_id = cw_employees.role where cw_employees.trans_status = 1 and cw_category.trans_status = 1 and cw_employees.employee_code = "'.$emp_code.'"';
$emp_cat_info = $this->db->query("CALL sp_a_run ('SELECT','$emp_cat_qry')");
$emp_cat_rslt = $emp_cat_info->result();
$emp_cat_info->next_result();
$category = strtolower($emp_cat_rslt[0]->category_name);
$category = str_replace(" ","_",$category);
while($month <= $end){
$work_sheet_month = date('m-Y', $month);
$work_sheet_month_name = "WSHEET_".strtoupper(date('F_Y', $month));
$file_name = $db_name."_".$emp_code."_".$work_sheet_month;
$enc_file = $this->encryptFilename($file_name,$db_name);
$enc_file_name = $enc_file."_".$emp_code;
if($db_name === "hare_hrms_db"){
$month_year = date('Y-m', $month);
$check_month = "2023-08";
if($month_year <= $check_month){
$payslip_month_name = "C0001_".strtoupper(date('F_Y', $month));
$file_path = "worksheet/$work_sheet_month_name/WSHEET_$emp_code.pdf";
}else{
$file_path = "worksheet/$category/$work_sheet_month/$enc_file_name.pdf";
}
}else{
$file_path = "worksheet/$category/$work_sheet_month/$enc_file_name.pdf";
}
if(file_exists($file_path)){
$file_path = base64_encode(base_url().$file_path);
$tble_line .= " <tr class='gradeU'>
<td>$work_sheet_month_name</td>
<td>
<a class='btn btn-primary btn-sm' onclick=pdf_viewer('$file_path')><span class='fa fa-eye' > </span> view </a>
<a class='btn btn-primary btn-sm' id='download_$work_sheet_month' onclick = download_worksheet('download_$work_sheet_month','$enc_file_name') download '><span class='fa fa-download' download> </span> Download </a>
</td>
</tr>";
$j++;
}else{
$tble_no_line = " <tr class='gradeU'>
<td colspan='2' style='text-align:center;'>No data found</td>
</tr>";
}
$month = strtotime("+1 month", $month);
$i++;
}
$tbl_body = "";
if((int)$j >= 1){
$tbl_body = $tble_line;
}else{
$tbl_body = $tble_no_line;
}
$table_data = "<table class='table table-striped table-bordered' id='emp_details'>
<thead>
<tr>
<th>Worksheet Month</th>
<th>Action</th>
</tr>
</thead>
<tbody>
$tbl_body
</tbody>
</table>";
echo json_encode(array('success' => true,'table_data' => $table_data));
}
}
?>