<?php

defined('BASEPATH') OR exit('No direct script access allowed');

class Acceuil extends CI_Controller {

    public 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 = array();
      
      // $data['conge_non_ponctuelle']=$this->Model->getRequete('SELECT * FROM `config_jours_ferrier` WHERE 1 AND FERRIER_CHAQUE_ANNEE = 0');
      // $data['conge_ponctuelle']=$this->Model->getRequete('SELECT * FROM `config_jours_ferrier` WHERE 1 AND FERRIER_CHAQUE_ANNEE = 1');
      // if ($this->session->userdata('BANCOBU_PROFIL_ID') == 0) {
        
      // $data['my_conge']= $this->Model->getRequete("SELECT conge_demande_conge.DATE_DEBUT_CONGE_ACCORDE, conge_status_conge.DESCRIPTION AS STATUS_CONGE, conge_demande_conge.DATE_SYSTEME_DEMANDE, conge_demande_conge.DATE_FIN_CONGE_ACCORDE, config_type_conge.NOM_CONGE FROM `conge_demande_conge` JOIN config_type_conge ON config_type_conge.ID_TYPE_CONGE = conge_demande_conge.ID_TYPE_CONGE LEFT JOIN conge_status_conge ON conge_status_conge.STATUS_CONGE = conge_demande_conge.STATUS_CONGE WHERE 1 AND ID_EMPLOYE = ".$this->session->userdata('ID_EMPLOYE')."");
      // $data['my_conge']= $this->Model->getRequete("SELECT conge_demande_conge.ID_DEMANDE_CONGE, conge_demande_conge.DATE_DEBUT_CONGE_ACCORDE, conge_status_conge.DESCRIPTION AS STATUS_CONGE, conge_demande_conge.DATE_SYSTEME_DEMANDE, conge_demande_conge.DATE_FIN_CONGE_ACCORDE, config_type_conge.NOM_CONGE FROM `conge_demande_conge` JOIN config_type_conge ON config_type_conge.ID_TYPE_CONGE = conge_demande_conge.ID_TYPE_CONGE LEFT JOIN conge_status_conge ON conge_status_conge.STATUS_CONGE = conge_demande_conge.STATUS_CONGE WHERE 1 AND ID_EMPLOYE = ".$this->session->userdata('ID_EMPLOYE')."");

      // $evolutions= $this->Model->getRequete("SELECT COUNT(conge_demande_conge.ID_DEMANDE_CONGE) AS NB_DEMANDE, SUM(conge_demande_conge.NB_JOURS_ACCORDE) AS NB_JOURS_ACCORDE, DATE_FORMAT(conge_demande_conge.DATE_DEBUT_CONGE_ACCORDE, '%Y-%m') AS MOIS from conge_demande_conge WHERE conge_demande_conge.DATE_DEBUT_CONGE_ACCORDE BETWEEN '2022-01-01' AND '2022-12-31' GROUP BY DATE_FORMAT(conge_demande_conge.DATE_DEBUT_CONGE_ACCORDE, '%Y-%m')");
      // $base = '';
      // $nb_demande = '';
      // $nb_jours = '';
      // foreach ($evolutions as $evolution) {
      //  $base .= "'".$evolution['MOIS']."',"; 
      //  $nb_demande .= $evolution['NB_DEMANDE'].","; 
      //  $nb_jours .= $evolution['NB_JOURS_ACCORDE'].","; 
      // }
      // $base .='|';
      // $nb_demande .='|';
      // $nb_jours .='|';

      // $data['base'] = str_replace("',|",",'",$base);
      // $data['nb_demande'] = str_replace(",|",",",$nb_demande);
      // $data['nb_jours'] = str_replace(",|",",",$nb_jours);



      // $credit= $this->Model->getRequete("SELECT NOM, PRENOM, NB_JOURS_CREDITE, NB_JOURS_RESTANT FROM `conge_credit` LEFT JOIN rh_employe ON rh_employe.ID_EMPLOYE = conge_credit.ID_EMPLOYE WHERE DEBUT_CREDIT LIKE '2022-01-01' AND FIN_CREDIT LIKE '2022-12-31'");

      // $basedeux = '';
      // $nb_jours_prise = '';
      // $nb_jours_n_prise = '';
      // foreach ($credit as $credits) {
      //  $basedeux .= "'".$credits['NOM']." ".$credits['PRENOM']."',"; 
      //  $jours_prise = $credits['NB_JOURS_CREDITE'] - $credits['NB_JOURS_RESTANT'];
      //  $nb_jours_prise .= $jours_prise.","; 
      //  $nb_jours_n_prise .= $credits['NB_JOURS_RESTANT'].","; 
      // }
      // $basedeux .='|';
      // $nb_jours_prise .='|';
      // $nb_jours_n_prise .='|';

      // $data['basedeux'] = str_replace("',|",",'",$basedeux);
      // $data['nb_jours_prise'] = str_replace(",|",",",$nb_jours_prise);
      // $data['nb_jours_n_prise'] = str_replace(",|",",",$nb_jours_n_prise);


      // $type_credit= $this->Model->getRequete("SELECT DISTINCT NOM_CONGE, COUNT(conge_demande_conge.ID_DEMANDE_CONGE) AS NB_CONGE FROM `conge_demande_conge` LEFT JOIN config_type_conge ON config_type_conge.ID_TYPE_CONGE = conge_demande_conge.ID_TYPE_CONGE WHERE conge_demande_conge.DATE_DEBUT_CONGE_ACCORDE BETWEEN '2022-01-01' AND '2022-12-31' GROUP BY NOM_CONGE ORDER BY NB_CONGE DESC");

      // $basetrois = '';
      // foreach ($type_credit as $typec) {

      //  $basetrois .= "{ name: '".$typec['NOM_CONGE']."', y: ".$typec['NB_CONGE']." },"; 
       
      // }

      // $data['basetrois'] = str_replace("',|",",'",$basetrois);
      
      // $data['stitle']='Accueil';

      //ALEXIS
      // $data['document_externe']=$this->Model->getRequeteOne("SELECT COUNT(*) NBRDOSSIER FROM doc_demande LEFT JOIN config_doc_profil_etape ON config_doc_profil_etape.STATUT_DOC_ID=doc_demande.STATUT_DOC_ID WHERE  (doc_demande.PROFIL_ID_DESIGNE IS NULL OR doc_demande.PROFIL_ID_DESIGNE=".$this->session->userdata('SOCAR_PROFIL_ID').") AND config_doc_profil_etape.PROFIL_ID=".$this->session->userdata('SOCAR_PROFIL_ID'));
      // $data['document_interne']=$this->Model->getRequeteOne("SELECT COUNT(*) AS NOMBRE FROM `doc_interne_document` JOIN doc_interne_etape on doc_interne_etape.ID_ETAPE_DOC_INTERNE = doc_interne_document.ID_ETAPE_DOC_INTERNE WHERE ID_PROFIL = ".$this->session->userdata('SOCAR_PROFIL_ID')." OR ID_EMPLOYE_DESINGE = ".$this->session->userdata('SOCAR_ID_USER')."");
      // $data['conge']=$this->Model->getRequeteOne("SELECT COUNT(ID_DEMANDE_CONGE) AS NOMBRE FROM `conge_demande_conge` WHERE STATUS_CONGE IN (1,2,5,4,7)");
      

      $this->load->view('Acceuil_View',$data);
    }




}
?>