File: /home/cafsindia/cloud_cafsinfotech_in/application/controllers/Payslip_view.php
<?php if ( ! defined('BASEPATH')) exit('No direct script is allowed');
require_once("Action_controller.php");
class Payslip_view extends Action_controller{
public function __construct(){
parent::__construct('payslip_view');
}
// LOAD PAGE QUICK LINK,FILTERS AND TABLE HEADERS
public function index(){
//PAGE INFO FUNCTION
$this->load->view("$this->control_name/manage");
}
public function check_payslip(){
$cat_id = $this->input->post('category');
$emp_code = $this->input->post('emp_code');
$from_month = $this->input->post('from_month');
$to_month = $this->input->post('last_month');
$company_info = $this->company_info();
$payslip_based_on = $company_info[0]->payslip_based_on;
if(!$payslip_based_on){
echo json_encode(array('success' => false,'message' => 'In Company Information Please should add User Rights in Payslip Based Input ','table_data' => $table_data));
exit(0);
}else{
$emp_qry = 'select '.$payslip_based_on.' from cw_employees where trans_status = 1 and employee_code = "'.$emp_code.'"';
$emp_info = $this->db->query("CALL sp_a_run ('SELECT','$emp_qry')");
$emp_rslt = $emp_info->result();
$emp_info->next_result();
$payslip_based_val = $emp_rslt[0]->$payslip_based_on;
$pdf_name_query = 'select prime_print_info_id,print_info_module_id,print_info_name from cw_print_info where pdf_design_for REGEXP "(^|,)('.$payslip_based_val.')(,|$)" and print_info_module_id = "employees" and print_type = 1 and trans_status = 1';
$pdf_name_info = $this->db->query("CALL sp_a_run ('SELECT','$pdf_name_query')");
$pdf_name_result = $pdf_name_info->result();
$pdf_name_info->next_result();
$module_name = $pdf_name_result[0]->print_info_module_id;
$template_design = strtolower(str_replace(' ', '_', $pdf_name_result[0]->print_info_name));
$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;
while($month <= $end){
$payslip_month = date('m-Y', $month);
$payslip_month_name = date('F Y', $month);
$file_path = "./pdf_generation/".$module_name."/".$template_design."/".$payslip_month.'/'.$payslip_based_on."_".$payslip_based_val.'/'.$emp_code.'.pdf';
if(file_exists($file_path)){
$file_path = base_url().$file_path;
$filename = dirname(__FILE__).$file_path;
$filename = str_replace("application\controllers","",$filename);
$tble_line .= " <tr class='gradeU'>
<td>$payslip_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_$payslip_month' href='$file_path' 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>Payslip Month</th>
<th>Action</th>
</tr>
</thead>
<tbody>
$tbl_body
</tbody>
</table>";
echo json_encode(array('success' => true,'message' => 'Payslip Details','table_data' => $table_data));
}
}
}
?>