<?php
class Conge_IT_Activation  extends CI_Controller{
    function __construct() {
        parent::__construct();
        $this->Is_Connected();

      }

      public function Is_Connected()
       {
       if (empty($this->session->userdata('SOCAR_ID_USER')))
        {
         redirect(base_url('Login/'));
        }
       }

        
       public function index()
       {

       
         $data['debut_conge']=$this->Model->getRequete(' SELECT conge_demande_conge.ID_DEMANDE_CONGE, rh_employe.NOM, rh_employe.PRENOM, DATE_DEBUT_CONGE_ACCORDE, DATE_FIN_CONGE_ACCORDE, organigramme_service.DESCRIPTION AS SERVICE, organigramme_section.DESCRIPTION AS DEPARTEMENT, organigramme_direction.DESCRIPTION AS DIRECTION FROM `conge_demande_conge` LEFT JOIN rh_employe ON rh_employe.ID_EMPLOYE = conge_demande_conge.ID_EMPLOYE LEFT JOIN rh_employe_affectation ON rh_employe_affectation.ID_EMPLOYE = rh_employe.ID_EMPLOYE LEFT JOIN organigramme_service ON organigramme_service.ID_SERVICE = rh_employe_affectation.ID_SERVICE LEFT JOIN organigramme_section ON organigramme_section.ID_SECTION = rh_employe_affectation.ID_SECTION LEFT JOIN organigramme_direction ON organigramme_direction.ID_DIRECTION = rh_employe_affectation.ID_DIRECTION WHERE `STATUS_CONGE` = 10 AND ID_DEMANDE_CONGE NOT IN (SELECT ID_DEMANDE_CONGE FROM conge_desactivation_it)');
         

         $tabledata=array();
   
         $data['title']='Cong&eacute;s Accord&eacute;';
           $this->load->view('Conge_IT_Activation_List_View',$data);
   
       }


       public function listing()
       {

       
         $data['debut_conge']=$this->Model->getRequete(' SELECT conge_demande_conge.ID_DEMANDE_CONGE, rh_employe.NOM, rh_employe.PRENOM, DATE_DEBUT_CONGE_ACCORDE, DATE_FIN_CONGE_ACCORDE, organigramme_service.DESCRIPTION AS SERVICE, organigramme_section.DESCRIPTION AS DEPARTEMENT, organigramme_direction.DESCRIPTION AS DIRECTION, conge_desactivation_it.ID_CONGE_DESACTIVATION, conge_desactivation_it.STATUS, DATE_REACTIVATION FROM `conge_demande_conge` LEFT JOIN rh_employe ON rh_employe.ID_EMPLOYE = conge_demande_conge.ID_EMPLOYE LEFT JOIN rh_employe_affectation ON rh_employe_affectation.ID_EMPLOYE = rh_employe.ID_EMPLOYE LEFT JOIN organigramme_service ON organigramme_service.ID_SERVICE = rh_employe_affectation.ID_SERVICE LEFT JOIN organigramme_section ON organigramme_section.ID_SECTION = rh_employe_affectation.ID_SECTION LEFT JOIN organigramme_direction ON organigramme_direction.ID_DIRECTION = rh_employe_affectation.ID_DIRECTION LEFT JOIN conge_desactivation_it ON conge_desactivation_it.ID_DEMANDE_CONGE = conge_demande_conge.ID_DEMANDE_CONGE WHERE `STATUS_CONGE` = 10 AND conge_demande_conge.ID_DEMANDE_CONGE IN (SELECT ID_DEMANDE_CONGE FROM conge_desactivation_it)');
         

         $tabledata=array();
   
         $data['title']='Cong&eacute;s Accord&eacute;';
           $this->load->view('Conge_IT_Desactivation_List_View',$data);
   
       }

       

       public function desactiver($id)
    {

      $this->Model->insert_last_id('conge_desactivation_it',array('ID_DEMANDE_CONGE'=>$id));
      // $this->Model->update('rh_employe_affectation',array('ID_EMPLOYE'=>$id,'STATUS_AFFECTATION'=>1),array('STATUS_AFFECTATION'=>1));
      $message = "<div class='alert alert-success' id='message'>
                            Employé désactiver avec succés
                            <button type='button' class='close' data-dismiss='alert'>&times;</button>
                      </div>";
      $this->session->set_flashdata(array('message'=>$message));
      redirect(base_url('conge/Conge_IT_Activation'));  
    }


      public function reactiver($id)
    {

      $this->Model->update('conge_desactivation_it',array('ID_DEMANDE_CONGE'=>$id),array('STATUS'=>0,'DATE_REACTIVATION'=>date('Y-m-d h-i')));
      // $this->Model->update('rh_employe_affectation',array('ID_EMPLOYE'=>$id,'STATUS_AFFECTATION'=>1),array('STATUS_AFFECTATION'=>1));
      $message = "<div class='alert alert-success' id='message'>
                            Employé désactiver avec succés
                            <button type='button' class='close' data-dismiss='alert'>&times;</button>
                      </div>";
      $this->session->set_flashdata(array('message'=>$message));
      redirect(base_url('conge/Conge_IT_Activation/listing'));  
    }


}