Subversion Repositories Applications.gtt

Rev

Rev 90 | Rev 103 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
90 jpm 1
<?php
2
class GttCtrlActionStatTableauCharge extends aControlleurAction {
3
 
4
	public function __construct(Registre $Registre)
5
    {
6
    	$Registre->ajouterEspace('StatTableauCharge', 'stat_tableau_charge');
7
    	$Registre->ajouterSquelette('stat_tableau_charge', 'stat_tableau_charge.tpl.html');
8
    }
9
 
10
    public function executer()
11
    {
12
   		$aso_stat = array();
13
    	$this->getRegistre()->setTitre('Plan de charge');
14
 
15
    	//+-------------------------------------------------------------------------------------------------+
16
		// GESTION DES PARAMÊTRE de l'URL
17
		//+-------------------------------------------------------------------------------------------------+
18
		// Initialisation des variables
19
		if (!isset($_GET['annee'])) {
20
			$_GET['annee'] = date('Y');
21
		}
22
		if (!isset($_GET['mois'])) {
23
			$_GET['mois'] = date('m');
24
		}
25
		if (!isset($_GET['uid'])) {// ID de l'utilisateur à afficher
26
			$_GET['uid'] = null;
27
		}
28
		//+-------------------------------------------------------------------------------------------------+
29
		// GESTION DES UTILISATEURS
30
		//+-------------------------------------------------------------------------------------------------+
31
		$DaoUtilsateur = new Utilisateur();
32
    	$utilisateurs = $DaoUtilsateur->consulter(Utilisateur::GU_TOUS_AFFICHABLE);
33
    	if (is_object($utilisateurs)) {
34
    		$utilisateurs[0] = $utilisateurs;
35
    	}
36
    	$UtilisateurCourant = null;
37
    	foreach ($utilisateurs as $Utilisateur) {
38
	    	// Récupération des infos sur l'utilisateur
39
	 		$aso_stat['utilisateurs'][$Utilisateur->getIdUtilisateur()]['courant'] = false;
40
	 		$aso_stat['utilisateurs'][$Utilisateur->getIdUtilisateur()]['nom'] = $Utilisateur->getPrenom().' '.$Utilisateur->getNom();
41
	 		if (	(!is_null($_GET['uid']) && $Utilisateur->getIdUtilisateur() == $_GET['uid'])
42
	 			||	(is_null($_GET['uid']) && $Utilisateur->getIdUtilisateur() == $GLOBALS['_GTT_']['Utilisateur']->getIdUtilisateur()) ) {
43
	 			$UtilisateurCourant = clone $Utilisateur;
44
	 			$aso_stat['utilisateurs'][$Utilisateur->getIdUtilisateur()]['courant'] = true;
45
	 			$aso_stat['utilisateur_courant'] = $Utilisateur->getPrenom().' '.$Utilisateur->getNom();
46
	 			$_GET['uid'] = $Utilisateur->getIdUtilisateur();
47
	 		}
48
    	}
49
    	$aso_stat['etre_admin'] = $GLOBALS['_GTT_']['Utilisateur']->getMarkAdmin();
50
		$Utilisateur = $UtilisateurCourant;
51
 
52
		//+-------------------------------------------------------------------------------------------------+
53
		// GESTION DES CALENDRIERS
54
		//+-------------------------------------------------------------------------------------------------+
55
 
56
		// Construction du Calendrier
57
		$Calendrier = new Calendrier();
58
		$tab_jours_feries = $Calendrier->getListeFeries();
59
 
60
		// Construction de l'objet mois
61
		$Month = new Calendar_Month_Weeks($_GET['annee'], $_GET['mois']);
62
		$Month->build();
63
 
64
		// Récupération des jours du mois
65
		while ($Week = $Month->fetch()) {
66
			$Week->build();
67
			//echo '<pre>'.print_r($Month, true).'</pre>';
68
			$tab_semaine_jours = $Week->fetchAll();
69
			foreach ($tab_semaine_jours as $num => $Day) {
70
				// Nous prenons en compte uniquement les jours du mois courant
71
				if ($Day->thisMonth() == $_GET['mois']) {
72
					$element = array();
73
					$element['jour'] = $Day->thisDay();
74
					$element['jour_nom'] = $Calendrier->getNomJours($num);
75
					$element['class'] = 'jour';
76
					// Nous vérifions le type de jour
77
					// Jour courrant
78
					if ($Day->isSelected()) {
79
						$element['class'] .= ' jour_courrant';
80
					}
81
					// Jour n'appartenant pas au moins courrant
82
					if ($Day->isEmpty()) {
83
						$element['class'] .= ' jour_vide';
84
					}
85
					// Jour férié
86
					foreach ($tab_jours_feries as $jour_ferie) {
87
						if ($Day->thisDay(true) ==  $jour_ferie) {
88
							$element['class'] .= ' jour_ferie';
89
						}
90
					}
91
					// Jour de week-end
92
					if ($element['jour_nom'] == GESTION_DIM_L || $element['jour_nom'] == GESTION_SAM_L) {
93
						$element['class'] .= ' jour_we';
94
					}
95
					$id = date('Y-m-d', mktime(0, 0, 0, $Day->thisMonth(), $Day->thisDay(), $Day->thisYear()));
96
					$aso_stat['elements'][$id] = $element;
97
				}
98
			}
99
		}
100
 
101
		// Construction de l'url pour les mois précédent/suivant/courant et paramêtres pour le formulaire utilisateur
102
		$aso_stat['form_url'] = 'index.php';
103
		$aso_stat['form_param']['action'] = GTT_ACTION_STAT_TAB_CHARGE;
104
		$aso_stat['form_param']['annee'] = $Month->thisYear();
105
		$aso_stat['form_param']['mois'] = $Month->thisMonth();
106
		$PMonth = $Month->prevMonth('object');
107
		$aso_stat['url_mois_precedent'] = 'index.php?action='.GTT_ACTION_STAT_TAB_CHARGE.'&amp;annee='.$PMonth->thisYear().'&amp;mois='.$PMonth->thisMonth().'&amp;uid='.$_GET['uid'];
108
		$NMonth = $Month->nextMonth('object');
109
		$aso_stat['url_mois_suivant'] = 'index.php?action='.GTT_ACTION_STAT_TAB_CHARGE.'&amp;annee='.$NMonth->thisYear().'&amp;mois='.$NMonth->thisMonth().'&amp;uid='.$_GET['uid'];
110
		$aso_stat['mois']['mois'] = $Calendrier->getNomMois($Month->thisMonth());
111
		$aso_stat['mois']['annee'] = $Month->thisYear();
112
		$mois_courant_j1 = $Month->thisYear().'-'.sprintf("%02s", $Month->thisMonth()).'-'.sprintf("%02s", $Month->thisDay()).' 00:00:00';
113
		$mois_courant_j36 = date('Y-m-d H:i:s', mktime(0, 0, 0, $NMonth->thisMonth(), 0, $NMonth->thisYear()));
114
 
115
		//+-------------------------------------------------------------------------------------------------+
116
		// GESTION DES PROJETS
117
		//+-------------------------------------------------------------------------------------------------+
118
    	// Récupération du temps de travail pour un utilisateur pour le mois donné
119
    	$TravailProjet = new TravailProjet();
120
		$cmd = TravailProjet::GTP_ID_UTILISATEUR_DATE_DEB_FIN;
121
		$param = array($Utilisateur->getIdUtilisateur(), $mois_courant_j1, $mois_courant_j36);
122
		$tab_tp = $TravailProjet->consulter($cmd, $param);
123
 
124
		if ($tab_tp != false) {
125
			$tab_projet_id = array();
126
			foreach ($tab_tp as $utp) {
127
    			$tab_projet_id[] = $utp->getIdProjet();
128
    		}
129
			// Nous vérifions qu'il y a des données pour l'utilisateur courant pour le mois donné
130
			// Récupération des infos sur les projets de l'utilisateur
131
	    	$Projet = new Projet();
132
	    	$tab_p = $Projet->consulter(Projet::GP_ID_LIST, array(implode(',', $tab_projet_id)));
133
			foreach ($tab_p as $Projet) {
134
				// Récupération de la catégorie du projet
135
				$ProjetCategorie = new ProjetCategorie();
136
				$cmd = ProjetCategorie::GPC_ID;
137
				$param = $Projet->getCeCategorie();
101 jpm 138
				$Categorie = current($ProjetCategorie->consulter($cmd, $param));
90 jpm 139
 
140
				// Nous vérifions le temps de travail pour ce projet
141
				$aso_tps_w = 0;
142
				if ($tab_tp) {
143
					foreach ($tab_tp as $TP) {
144
						$j = date('Y-m-d', strtotime($TP->getIdDateTravail()));
145
						if ($TP->getIdProjet() == $Projet->getIdProjet()) {
146
							// Récupération des infos sur les catégories
147
							if (!isset($aso_stat['categorie_totaux'][$Categorie->getLibelle()][$j])) {
148
								$aso_stat['categorie_totaux'][$Categorie->getLibelle()][$j] = 0;
149
							}
150
							$aso_stat['categorie_totaux'][$Categorie->getLibelle()][$j] += $TP->getDuree();
151
							// Récupération des infos sur les projets
152
							if (!isset($aso_stat['projets'][$Categorie->getLibelle()][$Projet->getIdProjet()])) {
153
								$aso_stat['projets'][$Categorie->getLibelle()][$Projet->getIdProjet()] = array(
154
									'id' => $Projet->getIdProjet(),
155
									'nom' => $Projet->getNom(),
156
									'duree' => array());
157
							}
158
							$aso_stat['projets'][$Categorie->getLibelle()][$Projet->getIdProjet()]['duree'][$j] = $TP->getDuree();
159
						}
160
					}
161
				}
162
			}
163
		} else {
164
			$aso_stat['messages'][] = 'Aucune information sur le travail en '.$aso_stat['mois']['mois'].' '.$aso_stat['mois']['annee'];
165
		}
166
 
167
		//+-------------------------------------------------------------------------------------------------+
168
		// GESTION DES ABSENCES
169
		//+-------------------------------------------------------------------------------------------------+
170
		// Récupération des motifs d'absence
171
		$AbsenceMotif = new AbsenceMotif();
172
		$cmd = AbsenceMotif::GAM_TOUS;
173
		$tab_am = $AbsenceMotif->consulter($cmd);
174
 
175
		// Récupération des absences pour un utilisateur à une date donnée
176
    	$Absence = new Absence();
177
		$cmd = Absence::GA_ID_UTILISATEUR_DATE_DEB_FIN;
178
		$param = array($Utilisateur->getIdUtilisateur(), $mois_courant_j1, $mois_courant_j36);
179
		$tab_a = $Absence->consulter($cmd, $param);
180
		if ($tab_a != false) {
181
			$aso_stat['ab_total'] = '';
182
			if ($tab_am) {
183
				foreach ($tab_am as $AM) {
184
					$aso_stat['absences'][$AM->getIdAbsenceMotif()] = $AM->getLibelle();
185
					//$aso_gestion['ab'][$AM->getIdAbsenceMotif()] = 0;
186
					if ($tab_a) {
187
						foreach ($tab_a as $A) {
188
							if ($A->getIdAbsenceMotif() == $AM->getIdAbsenceMotif() && $A->getDuree() != 0) {
189
								$j = date('Y-m-d', strtotime($A->getIdDateAbsence()));
190
								// Récupération des infos sur les absences
191
								$aso_stat['ab'][$AM->getIdAbsenceMotif()][$j] = $A->getDuree();
192
								// Récupération du total des absences
193
								if (!isset($aso_stat['ab_total'][$j])) {
194
									$aso_stat['ab_total'][$j] = 0;
195
								}
196
								$aso_stat['ab_total'][$j] += $A->getDuree();
197
							}
198
						}
199
					}
200
				}
201
			}
202
		} else {
203
			$aso_stat['messages'][] = 'Aucune absence de mentionnée en '.$aso_stat['mois']['mois'].' '.$aso_stat['mois']['annee'];
204
		}
205
 
206
 
207
		trigger_error('<pre>'.print_r($aso_stat, true).'</pre>', E_USER_NOTICE);
208
		$this->getRegistre()->ajouterDonnee('stat_tableau_charge', $aso_stat);
209
    }
210
}
211
?>