(description) * @version GIT: $Id$ * @since Version 0.0.1 * @filesource * */ class Employee extends Admin_Controller { /** * [__construct description] * * @method __construct */ public function __construct() { // To inherit directly the attributes of the parent class. parent::__construct(); ### Syntax : $this->load->model('Model Path' , 'Alias name'); ### The second parameter (optional) is used to call the method. $this->load->model('MY_Model','MY_Model'); $this->load->model('Employee_model','Emp_model'); $this->load->model('Audit/Audit_model','audit_model'); $this->load->helper(array('form', 'url')); $this->load->library('email'); } public function index() { $this->layout->set('users', "gowtham"); $this->layout->buffer('main_content', 'Asset/index'); $this->layout->render('Employee_Layout'); } public function empList() { $emp_list = $this->Emp_model->get_employee(user()->business_id); $this->layout->set('tableData', $emp_list); $this->layout->buffer('main_content', 'Employee/emp_list'); $this->layout->render('Employee_Layout'); } public function addEmployee($businessId = 0) { $get_group_list = $this->Emp_model->get_group_list(user()->business_id); $manager = $this->Emp_model->get_employee(user()->business_id); $ModuleData = $this->Emp_model->get_modules(user()->business_id); $this->layout->set('get_group_list', $get_group_list); $this->layout->set('ModuleData', $ModuleData); $this->layout->set('manager', $manager); $this->layout->set('departmentData', $this->MY_Model->select_by_department_data('department_master',user()->business_id)); $this->layout->buffer('main_content', 'Employee/add_emp'); $this->layout->render('Employee_Layout'); } public function createEmp() { //insert in users table $data = array( 'business_id' => user()->business_id, 'name' => $this->input->post('name'), 'email' => $this->input->post('email'), 'user_name' => $this->input->post('user_name'), 'mobile' => $this->input->post('mobile'), 'is_active'=> 1, 'password' => hash_password($this->input->post('password')) ); $table="users"; $create_user = $this->MY_Model->insert($data,$table); $user_insert_id = $this->db->insert_id(); //audit if($create_user) { //set id $ table name for audit history $this->audit->set('id',$create_user); $this->audit->set('table',$table); //fetch new_data after post data insert $this->audit->fetch('new_data'); //audit history generation for insert $test = $this->audit->create_history('insert'); } //file upload confic $config['upload_path'] = APPPATH. '../assets/uploads/'; $config['allowed_types'] = 'gif|jpg|png|jpeg'; $config['max_size'] = 80000; //upload $this->load->library('upload', $config); $this->upload->initialize($config); if ( ! $this->upload->do_upload('image')) { $error = array('error' => $this->upload->display_errors()); } $upload_image = $this->upload->data(); //insert in employees table if($create_user == true) { $data=$this->input->post(); unset($data['name']); unset($data['email']); unset($data['user_name']); unset($data['mobile']); unset($data['password']); unset($data['confirm_password']); unset($data['group_id']); $data['user_id'] = $create_user; $data['profile_pic'] = $upload_image['file_name']; $data['business_id'] = user()->business_id; $table="employees"; $create_emp_details = $this->MY_Model->insert($data,$table); //print_r($this->db->last_query()); $emp_insert_id = $this->db->insert_id(); $joining_year = date('Y', strtotime($this->input->post('j_date'))); $joining_month = date('m', strtotime($this->input->post('j_date'))); $all_leave_count = $this->Emp_model->get_leave_type(user()->business_id); $joining_month_total = (12 - $joining_month) + 1 ; foreach ($all_leave_count as $key => $value) { $remaining_days = ceil(((int)$value->days / 12) * $joining_month_total); if($value->id != '9'){ $days['remaining_days'] = $remaining_days; $days['business_id'] = user()->business_id; $days['emp_id'] = $user_insert_id; $days['total_days'] = $remaining_days; $days['type'] = $value->id; $days['year'] = $joining_year; $this->MY_Model->insert($days,'emp_leave_days'); } } } if(!empty($this->input->post('group_id'))) { if($create_user == true) { for($i=0;$iinput->post('group_id'));$i++) { $group['emp_id']=$create_user; $group['business_id']=user()->business_id; $group['group_id']=$this->input->post('group_id')[$i]; $group['is_active']=1; $this->MY_Model->insert($group,'group_membership'); } } } //audit if($create_emp_details) { //set id $ table name for audit history $this->audit->set('id',$create_user); $this->audit->set('table',$table); //fetch new_data after post data insert $this->audit->fetch('new_data'); //audit history generation for insert $test = $this->audit->create_history('insert'); } redirect('Employee/empList'); } public function add_employee_file() { // print_r($this->input->post());die(); $data=$this->input->post(); $data['business_id'] = user()->business_id; // $data['emp_id'] = $this->input->post('emp_id'); //file upload confic $config['upload_path'] = APPPATH. '../assets/uploads/'; $config['allowed_types'] = 'gif|jpg|png|pdf|jpeg'; $config['max_size'] = 80000; //upload $this->load->library('upload', $config); $this->upload->initialize($config); if ( ! $this->upload->do_upload('file_name')) { $error = array('error' => $this->upload->display_errors()); } else{ $upload_image = $this->upload->data(); $data['file_name'] = $upload_image['file_name']; } $table="employee_doc"; unset($data['image1']); $create_user = $this->MY_Model->insert($data,$table); //audit if($create_user) { //set id $ table name for audit history $this->audit->set('id',$create_user); $this->audit->set('table',$table); //fetch new_data after post data insert $this->audit->fetch('new_data'); //audit history generation for insert $test = $this->audit->create_history('insert'); } redirect('Employee/editEmployee/'.md5($this->input->post('emp_id'))); } public function editEmployee($id) { $images = $this->Emp_model->get_data(user()->business_id , $id , 'employee_doc'); //984647 , 1 $add_education = $this->Emp_model->get_data(user()->business_id , $id , 'employee_qualification'); $employee_history = $this->Emp_model->get_data(user()->business_id , $id , 'employee_history'); $empData = $this->Emp_model->get_emp_by_md5_id($id,user()->business_id); $manager_name = $this->Emp_model->get_manager_name($empData->manager); $manager = $this->Emp_model->get_employee(user()->business_id); $data = array( 'submit_button_title' => 'update' , 'heading' => 'Edit' , 'id' => $empData->user_id , 'images' => $images, 'add_education' => $add_education, 'employee_history' => $employee_history ); $emp_sub_list_htmlPage = $this->load->view('emp_sub_list.php',$data,true); $get_group_list = $this->Emp_model->get_group_list(user()->business_id); $get_members_list = $this->Emp_model->get_members_list($id,user()->business_id); // print_r($get_group_list); // echo"
";
        // print_r($get_members_list); die;
        $this->layout->set('get_members_list', $get_members_list);
        $this->layout->set('get_group_list', $get_group_list);
        $this->layout->set('manager', $manager);
        $this->layout->set('manager_name', $manager_name);
        $this->layout->set('departmentData', $this->MY_Model->select_by_department_data('department_master',user()->business_id));
        $this->layout->set('emp_sub_list_htmlPage', $emp_sub_list_htmlPage);
		$this->layout->set('editData', $empData);
        $this->layout->buffer('main_content', 'Employee/edit_emp');
        $this->layout->render('Employee_Layout');
   
    }


    public function editEmployees()
    {  
      $table = "users";  
      $id = $this->input->post('user_id');

         //set id $ table name for audit history
         $this->audit->set('id',$this->input->post('id'));
         $this->audit->set('table',$table);
         //fetch old_data before new_data update
         $this->audit->fetch('old_data');
      
      $action = array(
            'name' => $this->input->post('name'),
            'email' => $this->input->post('email'),
            'mobile' => $this->input->post('mobile'),
      );
       //set id $ table name for audit history
         $this->audit->set('id',$this->input->post('user_id'));
         $this->audit->set('table',$table);
         //fetch old_data before new_data update
         $this->audit->fetch('old_data');
          //update new data 
      $empuserData = $this->MY_Model->edit_option($action, $id, $table);
       if($empuserData)
         {
         //fetch new_data after post data update
         $this->audit->fetch('new_data');
         //audit history generation for update 
         $test = $this->audit->create_history('update');
         }


        $table="employees";
        $action = $this->input->post();    
        unset($action['name']);
        unset($action['email']); 
        unset($action['mobile']);
        unset($action['group_id']);

                //file upload confic
                $config['upload_path']          = APPPATH. '../assets/uploads/';
                $config['allowed_types']        = 'gif|jpg|png|jpeg';
                $config['max_size']             = 80000;
                //upload
                $this->load->library('upload', $config);
                $this->upload->initialize($config);
                if ( ! $this->upload->do_upload('image'))
                   {
                     $error = array('error' => $this->upload->display_errors());
                    
                      unset($action['asset_img']);
                   } else{
                    $upload_image = $this->upload->data();
                    $action['profile_pic'] = $upload_image['file_name'];
                     
                   }
        
        $id = $this->input->post('id');
        $get_membership = $this->Emp_model->get_members_details($this->input->post('user_id'), user()->business_id);
       // print_r($get_membership); die();
       if(count($get_membership) != 0) 
        {
        $DbData = [];
        foreach($get_membership as $key => $val){
           array_push($DbData,$val->group_id);
        }
        
        if($this->input->post('group_id') == null)
        {
            $module_id_array = [];
        }else{
            $module_id_array = $this->input->post('group_id');
        }

        // Find the values unique to array1 (not in array2)
        $differentValues1 = array_diff($module_id_array , $DbData);

        // Find the values unique to array2 (not in array1)
        $differentValues2 = array_diff($DbData , $module_id_array);

        // Merge the two results to get all the different values from both arrays
        $final_array = array_merge($differentValues1, $differentValues2);
        // echo "
";
        // print_r($DbData); print_r($this->input->post('group_id')); print_r($final_array);
        // echo "
";
        //  die;

        if(count($final_array) != 0)
        {
            foreach($final_array as $key => $value){
                $check_if_exist = $this->Emp_model->get_group_module_data_by_id($this->input->post('user_id') , $value); 
                if($check_if_exist)
                {
                   $this->Emp_model->delete_group_module_data_by_id($this->input->post('user_id') , $value); 
                }else{
                    $group['emp_id']=$this->input->post('user_id');
                    $group['business_id']=user()->business_id;
                    $group['group_id']=$value;
                    $group['is_active']=1;
                    $this->MY_Model->insert($group,'group_membership');
                }
                    
                }
        }
       }
        else
        {       
             if(!empty($this->input->post('group_id')))
          {
            for($i=0;$iinput->post('group_id'));$i++)
                 {
                    $group['emp_id']=$this->input->post('user_id');
                    $group['business_id']=user()->business_id;
                    $group['group_id']=$this->input->post('group_id')[$i];
                    $group['is_active']=1;
                    $this->MY_Model->insert($group,'group_membership');
                 } 
          }      
        }               
        








         //set id $ table name for audit history
         $this->audit->set('id',$this->input->post('id'));
         $this->audit->set('table',$table);
         //fetch old_data before new_data update
         $this->audit->fetch('old_data');
         //update new data 
        $empData = $this->MY_Model->edit_option($action, $id, $table);
        if($empData)
         {
         //fetch new_data after post data update
         $this->audit->fetch('new_data');
         //audit history generation for update 
         $test = $this->audit->create_history('update');
         }
        redirect('Employee/empList');
  
    }

    public function getDeleteConfirmationPopup()
	{
	    $data = array();
	    $htmlPage = $this->load->view('confirmation_popup.php',$data,true);
	    echo json_encode($htmlPage); 
	}

    public function deleteEmp()
    {
	    $id = $this->input->post('id');
        $Data = $this->Emp_model->delete_emp_by_md5_id($id,user()->business_id);
	    redirect('Employee/empList');
	}

    public function deleteEmpImage()
    {
	    $id = $this->input->post('id');
        $empData = $this->Emp_model->get_emp_by_md5_id($this->input->post('id'),user()->business_id,'employees');
        $Data = $this->Emp_model->delete_emp_by_md5_id($id,user()->business_id,'employee_doc');
	    redirect('Employee/editEmployee/'.md5($empData->emp_id));
	}

    public function deleteEmpQualification()
    {
	    $id = $this->input->post('id');
        $empData = $this->Emp_model->get_emp_by_md5_id($this->input->post('id'),user()->business_id,'employee_qualification');
        $Data = $this->Emp_model->delete_emp_by_md5_id($id,user()->business_id,'employee_qualification');
	    redirect('Employee/editEmployee/'.md5($empData->emp_id));
	}

    public function deleteEmpHistory()
    {
	    $id = $this->input->post('id');
        $empData = $this->Emp_model->get_emp_by_md5_id($this->input->post('id'),user()->business_id,'employee_history');
        $Data = $this->Emp_model->delete_emp_by_md5_id($id,user()->business_id,'employee_history');
	    redirect('Employee/editEmployee/'.md5($empData->emp_id));
	}

    public function view_emp_history($id)
    {
        $table = 'employees';
        $user_history = $this->audit_model->get_history( $id , $table , user()->business_id);
        $data = array('title'=> "Employee History" , 'name' => 'Employee' , 'user_history'=> $user_history );
        $htmlPage = $this->load->view('view_history.php',$data,true);
        echo json_encode($htmlPage);
    }

    public function editEmp_qualification($id)
    {
        $table = 'employee_qualification';
        $data = $this->Emp_model->get_data(user()->business_id , $id , $table);
        echo json_encode($data);
    }

    public function editEmp_history($id)
    {
        $table = 'employee_history';
        $data = $this->Emp_model->get_data(user()->business_id , $id , $table);
        echo json_encode($data);
    }


    public function add_employee_education()
    {

        $id = $this->input->post('id');
        if ($id) {
            $data = $this->input->post();
            // $id = $this->input->post('id');
            $data['business_id'] = user()->business_id;
            $table="employee_qualification";
            $create_user = $this->MY_Model->update_md5($data,md5($id),$table);
            redirect('Employee/editEmployee/'.md5($this->input->post('emp_id')));
        }
        else{
            $data = $this->input->post();
            // $id = $this->input->post('id');
            $data['business_id'] = user()->business_id;
            $table="employee_qualification";
            $create_user = $this->MY_Model->insert($data,$table);
            redirect('Employee/editEmployee/'.md5($this->input->post('emp_id')));
        }

    
    }

    public function add_employee_history()
    {
        $id = $this->input->post('id');
        if ($id) {
            $data = $this->input->post();
            // $id = $this->input->post('id');
            $data['business_id'] = user()->business_id;
            $table="employee_history";
            $create_user = $this->MY_Model->update_md5($data,md5($id),$table);
            redirect('Employee/editEmployee/'.md5($this->input->post('emp_id')));
        }
        else{
            $data = $this->input->post();
            // $id = $this->input->post('id');
            $data['business_id'] = user()->business_id;
            $table="employee_history";
            $create_user = $this->MY_Model->insert($data,$table);
            redirect('Employee/editEmployee/'.md5($this->input->post('emp_id')));
        }
    
    }

    public function checkUniqueValue()
    {
      $data = $this->input->get('value');
      $table = 'users';
      $where = $this->input->get('name');
      $result = $this->MY_Model->checkUniqueValueInDataBase($table, $where, $data);
      if(count($result)){
          $this->output->set_output(true);
      }else{ 
          $this->output->set_output(false);
      }
    }

    public function sendemail(){

        $to = "suseendhiran13@gmail.com";
        $cc = 'venkateshraman786@gmail.com';
        $body = $body = "
        
        
            

Someone has contacted you!



Sender Details


Name
Suseendhiran
"; $subject ="test email"; $result = send_emails($to, $subject, $body); if ($result === true) { echo 'Email sent successfully'; } else { echo 'Errors: ' . $result; } } }