Subversion Repositories Applications.gtt

Rev

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