File: /home/cafsindia/hrms_cafsinfotech_in/application_bk14FEB2026/controllers/Home_cadd.php
<?php
/**********************************************************
Filename: Home
Description: Chart view and Chart control logic developed, highchart integration based on role.
Author: Jaffer Sathik
Created on: 10-DEC-2018
Reviewed by: Udhayakumar Anandhan (REVIEW PENDING)
Reviewed on:
Approved by:
Approved on:
-------------------------------------------------------
Modification Details: HIGHCHARTS
Modification Date: 06/12/2019
Changed by: SVK AND NEHA
Change Info: HIGHCHARTS
-------------------------------------------------------
***********************************************************/
if ( ! defined('BASEPATH')) exit('No direct script access allowed');
require_once("Action_controller.php");
class Home extends Action_controller {
public function __construct(){
parent::__construct();
$this->load->model("Homemodel");
$this->logged_id = $this->session->userdata('logged_id');
$this->logged_role = $this->session->userdata('logged_role');
}
public function logout(){
$this->session->sess_destroy();
redirect('login');
}
public function index(){
if(!$this->Appconfig->isAppvalid()){
redirect('config');
}
$data['encKey'] = $this->generateKey();
$logged_id = $this->session->userdata('logged_id');
$logged_user_role = $this->session->userdata('logged_user_role');
$data['quick_header_menu'] = $this->Homemodel->get_header_menu($logged_id);
$data['quick_report_menu'] = $this->Homemodel->get_report_menu($logged_user_role);
//$data = "";
$this->load->view('home',$data);
}
// FUNCTION FOR BRAND WISE NETPAY
public function brand_netpay_info(){
$start_date = $this->db->escape(date("Y-m-d",strtotime($this->input->post('start_date'))));
$end_date = $this->db->escape(date("Y-m-d",strtotime($this->input->post('end_date'))));
$brand_netpay_data = $this->db->query("CALL sp_a_run ('SELECT','SELECT SUM(cw_transactions.net_pay)AS net_pay,cw_brand.brand FROM cw_transactions INNER JOIN cw_employees ON cw_employees.employee_code = cw_transactions.employee_code INNER JOIN cw_brand ON cw_brand.prime_brand_id = cw_employees.brand WHERE cw_employees.trans_status = 1 and date_format(str_to_date(concat(\"01-\",cw_transactions.transactions_month),\"%d-%m-%Y\"),\"%Y-%m-%d\") BETWEEN '$start_date' AND '$end_date' GROUP BY cw_employees.brand')");
$brand_netpay_rlst = $brand_netpay_data->result();
$brand_netpay_data->next_result();
$rows = array();
$rows['name'] = "Brand";
foreach($brand_netpay_rlst as $rlst){
$net_pay = $rlst->net_pay;
$brand = $rlst->brand;
$rows['data'][] = array("name"=>$brand,"y"=>$net_pay);
}
$department = array();
array_push($department,$rows);
echo json_encode(array('series' => $department),JSON_NUMERIC_CHECK);
}
// FUNCTION FOR BRAND WISE EMPLOYEE COUNT
public function get_brandwise_employee_count_info(){
$start_date = date("d-m-Y",strtotime($this->input->post('start_date')));
$end_date = date("d-m-Y",strtotime($this->input->post('end_date')));
$query = 'SELECT COUNT(cw_employees.employee_code) AS employee_count,cw_brand.brand FROM cw_transactions INNER JOIN cw_employees ON cw_employees.employee_code = cw_transactions.employee_code INNER JOIN cw_brand ON cw_brand.prime_brand_id = cw_employees.brand WHERE cw_employees.trans_status = 1 and cw_employees.termination_status=0 GROUP BY cw_employees.brand';
$brand_emp_count_info = $this->db->query("CALL sp_a_run ('SELECT','$query')");
$brand_emp_count_rlst = $brand_emp_count_info->result();
$brand_emp_count_info->next_result();
$rows = array();
$rows1 = array();
$rows['name'] = 'TOTAL EMPLOYEES';
$rows1['name'] = 'BRAND';
foreach($brand_emp_count_rlst as $rlst){
$count = $rlst->employee_count;
$brand = $rlst->brand;
$rows['data'][] = $brand;
$rows1['data'][] = $count;
}
$designation_info = array();
array_push($designation_info,$rows);
array_push($designation_info,$rows1);
echo json_encode($designation_info,JSON_NUMERIC_CHECK);
}
// FUNCTION FOR LOCATION WISE EMPLOYEE COUNT
public function employees_count_chart(){
$start_date = date("Y-m-d",strtotime($this->input->get('start_date')));
$end_date = date("Y-m-d",strtotime($this->input->get('end_date')));
//echo "BSK $start_date :: $end_date"; die;
$view_data = $this->db->query("CALL sp_a_run ('SELECT','SELECT COUNT(cw_employees.employee_code)AS employee_count,cw_location.location FROM cw_employees INNER JOIN cw_location ON cw_location.prime_location_id = cw_employees.location INNER JOIN cw_transactions ON cw_transactions.employee_code = cw_employees.employee_code and cw_employees.termination_status=0 and date_format(cw_employees.date_of_joining,\"%Y-%m-%d\") BETWEEN \"$start_date\" AND \"$end_date\" GROUP BY cw_location.location')");
$view_result = $view_data->result_array();
$view_data->next_result();
$total_emp['name'] = 'Total Employees';
$series1['name'] = 'Location';
foreach($view_result as $key => $value){
$employees = $value['employee_count'];
$location = $value['location'];
$total_emp['data'][] = $location;
$series1['data'][] = $employees;
}
$result = array();
array_push($result,$total_emp);
array_push($result,$series1);
print json_encode($result,JSON_NUMERIC_CHECK);
}
// FUNCTION FOR GENDER WISE COUNT AND PERCENTAGE
public function gen_distribution_chart(){
$start_date = date("Y-m-d",strtotime($this->input->post('start_date')));
$end_date = date("Y-m-d",strtotime($this->input->post('end_date')));
$view_data = $this->db->query("CALL sp_a_run ('SELECT','SELECT COUNT(cw_gender.gender) AS gender_count,cw_gender.gender FROM cw_employees INNER join cw_gender on cw_employees.gender = cw_gender.prime_gender_id where cw_employees.trans_status = 1 and cw_employees.termination_status=0 GROUP BY cw_gender.gender')");
$view_result = $view_data->result();
$view_data->next_result();
$rows = array();
$rows['name'] = "Gender";
foreach($view_result as $rlst){
$gender = $rlst->gender;
$emp_count = $rlst->gender_count;
$rows['data'][] = array("name"=>$gender,"y"=>$emp_count);
}
$gender = array();
array_push($gender,$rows);
echo json_encode(array('series' => $gender),JSON_NUMERIC_CHECK);
}
// FUNCTIO FOR LOCATION WISE NETPAY
public function get_netpay_loc_chart(){
$start_date = $this->db->escape(date("Y-m-d",strtotime($this->input->post('start_date'))));
$end_date = $this->db->escape(date("Y-m-d",strtotime($this->input->post('end_date'))));
$dept_salary_info = $this->db->query("CALL sp_a_run ('SELECT','SELECT SUM(cw_transactions.net_pay)AS net_pay,cw_location.location FROM cw_transactions INNER JOIN cw_employees ON cw_employees.employee_code = cw_transactions.employee_code INNER JOIN cw_location ON cw_location.prime_location_id = cw_employees.location where cw_employees.trans_status =1 and date_format(str_to_date(concat(\"01-\",cw_transactions.transactions_month),\"%d-%m-%Y\"),\"%Y-%m-%d\") BETWEEN '$start_date' AND '$end_date' GROUP BY cw_location.location')");
$dept_salary_rlst = $dept_salary_info->result();
$dept_salary_info->next_result();
$rows = array();
$rows['name'] = "Location";
foreach($dept_salary_rlst as $rlst){
$net_pay = $rlst->net_pay;
$location = $rlst->location;
$rows['data'][] = array("name"=>$location,"y"=>$net_pay);
}
$department = array();
array_push($department,$rows);
echo json_encode(array('series' => $department),JSON_NUMERIC_CHECK);
}
//FUNCTION FOR AGE WISE EMPLOYEE COUNT
public function age_wise_emp_count(){
$start_date = $this->db->escape(date('Y-m-d',strtotime($this->input->post('start_date'))));
$end_date = $this->db->escape(date('Y-m-d',strtotime($this->input->post('end_date'))));
$view_data = $this->db->query("CALL sp_a_run ('SELECT','SELECT cw_employees.emp_age,COUNT(cw_employees.employee_code) AS emp_count FROM cw_employees WHERE cw_employees.trans_status=1 GROUP BY cw_employees.emp_age')");
$view_result = $view_data->result_array();
$view_data->next_result();
$total_pay['name'] = 'Employee Count';
$series1['name'] = 'Age';
foreach($view_result as $key => $value){
$count = $value['emp_count'];
$age = strval($value['emp_age']);
$total_pay['data'][] = $count;
$series1['data'][] = $age;
}
$result = array();
array_push($result,$series1);
array_push($result,$total_pay);
print json_encode($result,JSON_NUMERIC_CHECK);
}
}
?>