<?php
class Budget_Annuelle  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['title']='Budge Annuelle';
      $data['exercices']=$this->Model->getRequete('SELECT * FROM `config_exercice` order by DESCRIPTION');
      $data['type_budge']=$this->Model->getRequete('SELECT * FROM `req_externe_type_budge` order by DESCRIPTION');
      
      $this->load->view('Budget_Annuelle_Add_View',$data);

    }




      public function add()
    {          
            
      
      $ID_TYPE_BUDGE=$this->input->post('ID_TYPE_BUDGE');
      $RUBRIQUE=$this->input->post('RUBRIQUE');
      $DESCRIPTION=$this->input->post('DESCRIPTION');
      $BUDGE_PREVU=$this->input->post('BUDGE_PREVU');
      $ID_EXERCICE=$this->input->post('ID_EXERCICE');


      $this->form_validation->set_rules('ID_TYPE_BUDGE', 'Type de Budge', 'required');
      $this->form_validation->set_rules('RUBRIQUE', 'Rubrique', 'required');
      $this->form_validation->set_rules('BUDGE_PREVU', 'Budge', 'required');
      $this->form_validation->set_rules('ID_EXERCICE', 'Exercice;', 'required');
     
  

   if ($this->form_validation->run() == FALSE){
    $message = "<div class='alert alert-danger'>
                              Budge non enregistr&eacute;
                            <button type='button' class='close' data-dismiss='alert'>&times;</button>
                      </div>";
    $this->session->set_flashdata(array('message'=>$message));
    $data['title']='Demande interne';
       
      $data['NUM_GENERATED']=$NUM_GENERATED;
      $data['responsabilite']=$this->Model->getRequete('SELECT * FROM `rh_responsabilite` order by DESCRIPTION');
      $data['direction']=$this->Model->getRequete('SELECT * FROM `organigramme_direction` order by DESCRIPTION');
      $data['departement']=$this->Model->getRequete('SELECT * FROM `organigramme_section` order by DESCRIPTION');
      $data['type_doc']=$this->Model->getRequete('SELECT * FROM `doc_interne_type` order by DESCRIPTION');
      $data['rh']=$this->Model->getRequete('SELECT * FROM `rh_employe` order by NOM');
      
      $this->load->view('Budget_Annuelle_Add_View',$data);

      
    // $this->load->view('Demande_Conge_Add_View',$data);
   }
   else{

    $data_conge=array(
      'ID_TYPE_BUDGE'=>$ID_TYPE_BUDGE,
      'RUBRIQUE'=>$RUBRIQUE,
      'DESCRIPTION'=>$DESCRIPTION,
      'BUDGE_PREVU'=>$BUDGE_PREVU,
      'BUDGE_CONSOME'=>0,
      'BUDGE_DISPONIBLE'=>$BUDGE_PREVU,
      'ID_EXERCICE'=>$ID_EXERCICE,
    );

    $this->Model->insert_last_id('req_externe_budge_plannifie',$data_conge);

    $message = "<div class='alert alert-success' id='message'>
                            Budget Annuel enregistr&eacute; avec succés
                            <button type='button' class='close' data-dismiss='alert'>&times;</button>
                      </div>";
    $this->session->set_flashdata(array('message'=>$message));
      redirect(base_url('requisition_externe/Budget_Annuelle/listing'));  
   }

    }


      public function listing()
    {

     

            
       $statusc = ' ';
              



      $data['resultat']=$this->Model->getRequete('SELECT req_externe_budge_plannifie.ID_BUDGE_PLANNIFIE, req_externe_type_budge.DESCRIPTION AS TYPE_BUGDE, req_externe_budge_plannifie.RUBRIQUE, req_externe_budge_plannifie.DESCRIPTION, req_externe_budge_plannifie.BUDGE_PREVU,req_externe_budge_plannifie.BUDGE_CONSOME, req_externe_budge_plannifie.BUDGE_DISPONIBLE, config_exercice.DESCRIPTION AS EXERCICE, req_externe_budge_plannifie.STATUS FROM `req_externe_budge_plannifie` JOIN req_externe_type_budge ON req_externe_type_budge.ID_TYPE_BUDGE = req_externe_budge_plannifie.ID_TYPE_BUDGE JOIN config_exercice ON config_exercice.ID_EXERCICE = req_externe_budge_plannifie.ID_EXERCICE');



      $data['title']='Budge Annuelle';
      $this->load->view('Budget_Annuelle_List_View',$data);
            

    }


    public function index_update($ID_BUDGE_PLANNIFIE)
    {

      $data['title']='Budge Annuelle'; 
      $data['data']=$this->Model->getRequeteOne('SELECT * FROM `req_externe_budge_plannifie` WHERE 1 AND ID_BUDGE_PLANNIFIE = '.$ID_BUDGE_PLANNIFIE.''); 
      $data['exercices']=$this->Model->getRequete('SELECT * FROM `config_exercice` order by DESCRIPTION');
      $data['type_budge']=$this->Model->getRequete('SELECT * FROM `req_externe_type_budge` order by DESCRIPTION');
      $this->load->view('Budget_Annuelle_Update_View',$data);

    }

    public function update()
    {          
            
      
      $ID_BUDGE_PLANNIFIE=$this->input->post('ID_BUDGE_PLANNIFIE');
      $ID_TYPE_BUDGE=$this->input->post('ID_TYPE_BUDGE');
      $RUBRIQUE=$this->input->post('RUBRIQUE');
      $DESCRIPTION=$this->input->post('DESCRIPTION');
      $BUDGE_PREVU=$this->input->post('BUDGE_PREVU');
      $ID_EXERCICE=$this->input->post('ID_EXERCICE');


      $this->form_validation->set_rules('ID_TYPE_BUDGE', 'Type de Budge', 'required');
      $this->form_validation->set_rules('RUBRIQUE', 'Rubrique', 'required');
      $this->form_validation->set_rules('BUDGE_PREVU', 'Budge', 'required');
      $this->form_validation->set_rules('ID_EXERCICE', 'Exercice;', 'required');
     
  

   if ($this->form_validation->run() == FALSE){
    $message = "<div class='alert alert-danger'>
                              Budge non enregistr&eacute;
                            <button type='button' class='close' data-dismiss='alert'>&times;</button>
                      </div>";
    $this->session->set_flashdata(array('message'=>$message));
    $data['title']='Demande interne';
       
      $data['NUM_GENERATED']=$NUM_GENERATED;
      $data['responsabilite']=$this->Model->getRequete('SELECT * FROM `rh_responsabilite` order by DESCRIPTION');
      $data['direction']=$this->Model->getRequete('SELECT * FROM `organigramme_direction` order by DESCRIPTION');
      $data['departement']=$this->Model->getRequete('SELECT * FROM `organigramme_section` order by DESCRIPTION');
      $data['type_doc']=$this->Model->getRequete('SELECT * FROM `doc_interne_type` order by DESCRIPTION');
      $data['rh']=$this->Model->getRequete('SELECT * FROM `rh_employe` order by NOM');
      
      $this->load->view('Budget_Annuelle_Add_View',$data);

   }
   else{

    $data_conge=array(
      'ID_TYPE_BUDGE'=>$ID_TYPE_BUDGE,
      'RUBRIQUE'=>$RUBRIQUE,
      'DESCRIPTION'=>$DESCRIPTION,
      'BUDGE_PREVU'=>$BUDGE_PREVU,
      'BUDGE_CONSOME'=>0,
      'BUDGE_DISPONIBLE'=>$BUDGE_PREVU,
      'ID_EXERCICE'=>$ID_EXERCICE,
    );

    $this->Model->update('req_externe_budge_plannifie',array('ID_BUDGE_PLANNIFIE'=>$ID_BUDGE_PLANNIFIE),$data_conge);

    $message = "<div class='alert alert-success' id='message'>
                            Budget Annuel modifi&eacute; avec succés
                            <button type='button' class='close' data-dismiss='alert'>&times;</button>
                      </div>";
    $this->session->set_flashdata(array('message'=>$message));
      redirect(base_url('requisition_externe/Budget_Annuelle/listing'));  
   }

    }


    public function desactiver($id)
    {
      $this->Model->update('req_externe_budge_plannifie',array('ID_BUDGE_PLANNIFIE'=>$id),array('STATUS'=>0));
      
      $message = "<div class='alert alert-primary' id='message'>
                            Budge désactivé avec succés
                            <button type='button' class='close' data-dismiss='alert'>&times;</button>
                      </div>";
      $this->session->set_flashdata(array('message'=>$message));
      redirect(base_url('requisition_externe/Budget_Annuelle/listing'));  
    }

  public function reactiver($id)
    {
      $this->Model->update('req_externe_budge_plannifie',array('ID_BUDGE_PLANNIFIE'=>$id),array('STATUS'=>1));
      $message = "<div class='alert alert-primary' id='message'>
                            Budge Réactivé avec succés
                            <button type='button' class='close' data-dismiss='alert'>&times;</button>
                      </div>";
      $this->session->set_flashdata(array('message'=>$message));
      redirect(base_url('requisition_externe/Budget_Annuelle/listing'));  
    }

}