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

class Dashboard_Employe extends CI_Controller
{
  function index()
  {

$DATE1=$this->input->post('DATE_DEBUT');
$DATE2=$this->input->post('DATE_FIN');

$data['report']=""; 
$TOTALEMPLOYEDIRECTION=0;


//DIRECTION
$directionlist=$this->Model->getRequete('SELECT `ID_DIRECTION` AS DIR,STATUS AS STAT,DESCRIPTION,(SELECT COUNT(*) FROM `rh_employe_affectation` JOIN organigramme_direction ON organigramme_direction.ID_DIRECTION = rh_employe_affectation.ID_DIRECTION WHERE rh_employe_affectation.ID_DIRECTION=DIR AND STAT=1) AS NBR_EMPL FROM organigramme_direction ORDER BY NBR_EMPL DESC'); 

foreach ($directionlist as $key)
 {



    $TOTALEMPLOYEDIRECTION=$TOTALEMPLOYEDIRECTION+$key['NBR_EMPL'];
    $data['report'] .="{y: ".$key['NBR_EMPL'].",name:'".str_replace("'", "\'",$key['DESCRIPTION'])."',key:'".$key['NBR_EMPL']."'},";  

 }
      
    
    $data['title']="Nombre d\'employé par direction";
    $data['TOTALEMPLOYEDIRECTION']=number_format($TOTALEMPLOYEDIRECTION,0,"."," ");


    //DEPARTEMENT

  $data['report_dep']=""; 
$TOTALEMPLDEPART=0;
$departlist=$this->Model->getRequete('SELECT `ID_DEPARTEMENT` AS DEP,STATUS AS STAT,DESCRIPTION,(SELECT COUNT(*) FROM `rh_employe_affectation` JOIN organigramme_departement ON organigramme_departement.ID_DEPARTEMENT = rh_employe_affectation.ID_DEPARTEMENT WHERE rh_employe_affectation.ID_DEPARTEMENT=DEP AND STAT=1) AS NBR_EMPL FROM organigramme_departement ORDER BY NBR_EMPL DESC'); 

foreach ($departlist as $key)
 {



    $TOTALEMPLDEPART=$TOTALEMPLDEPART+$key['NBR_EMPL'];
    $data['report_dep'] .="{y: ".$key['NBR_EMPL'].",name:'".str_replace("'", "\'",$key['DESCRIPTION'])."',key:'".$key['NBR_EMPL']."'},";  

 }
      
    
    $data['titledepart']="Nombre d\'employé par département";
    $data['TOTALEMPLDEPART']=number_format($TOTALEMPLDEPART,0,"."," ");



    //DEPARTEMENT

  $data['raport_serv']=""; 
$TOTALSERV=0;
$listservice=$this->Model->getRequete('SELECT `ID_SERVICE` AS SERV,STATUS AS STAT,DESCRIPTION,(SELECT COUNT(*) FROM `rh_employe_affectation` JOIN organigramme_service ON organigramme_service.ID_SERVICE = rh_employe_affectation.ID_SERVICE WHERE rh_employe_affectation.ID_SERVICE=SERV AND STAT=1) AS NBR_EMPL FROM organigramme_service ORDER BY NBR_EMPL DESC'); 

foreach ($listservice as $key)
 {



    $TOTALSERV=$TOTALSERV+$key['NBR_EMPL'];
    $data['raport_serv'] .="{y: ".$key['NBR_EMPL'].",name:'".str_replace("'", "\'",$key['DESCRIPTION'])."',key:'".$key['NBR_EMPL']."'},";  

 }
      
    
    $data['titleservice']="Nombre d\'employé par service";
    $data['TOTALSERV']=number_format($TOTALSERV,0,"."," ");



//EMPLAYE PAR SEXE

$data['raport_sex']=""; 
$TOTALEMPL_SEX=0;
$LISTEMPLSEXE=$this->Model->getRequete('SELECT `ID_SEXE` AS SEX,DESCRIPTION,(SELECT COUNT(*) FROM `rh_employe` JOIN rh_sexe ON rh_sexe.ID_SEXE = rh_employe.ID_SEXE WHERE rh_employe.ID_SEXE=SEX) AS NBR_EMPL FROM rh_sexe ORDER BY NBR_EMPL DESC'); 

foreach ($LISTEMPLSEXE as $key)
 {



    $TOTALEMPL_SEX=$TOTALEMPL_SEX+$key['NBR_EMPL'];
    $data['raport_sex'] .="{y: ".$key['NBR_EMPL'].",name:'".str_replace("'", "\'",$key['DESCRIPTION'])."',key:'".$key['NBR_EMPL']."'},";  

 }
      
    
    $data['titleempsex']="Nombre d\'employé par sexe";
    $data['TOTALEMPL_SEX']=number_format($TOTALEMPL_SEX,0,"."," ");



    $data['titre']='Rapport du '.date('Y-m-d');
    $this->load->view("Dashboard_Employe_View",$data);

  }


}