Subversion Repositories Applications.gtt

Rev

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