stats.ctp
6.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
<?php
//use SebastianBergmann\CodeCoverage\Report\PHP;
/*
$avg['CREATED'] = 10;
$avg['VALIDATED'] = 7;
$avg['ARCHIVED'] = 1;
$tot['CREATED'] = 100;
$tot['VALIDATED'] = 70;
$tot['TOBEARCHIVED'] = 10;
$tot['ARCHIVED'] = 10;
$year = 2020;
$years = [];
for ($y=$year ; $y>$year-5 ; $y--) {
$years[$y]['created'] = 8;
$years[$y]['validated'] = 8;
$years[$y]['archived'] = 8;
}
$suivis = [];
$prets = [];
$suivis['tot'] = 100;
$suivis['avg'] = 10;
for ($y=$current_year ; $y>=$year_min ; $y--) $suivis[$y] = 8;
$prets = $suivis;
*/
// Parameters passed by controller
$current_year = $current_year;
$year_min = $year_min;
$nbyears = $nbyears;
$avg = $avg;
$tot = $tot;
//$tot2 = $tot2;
$years = $years;
//debug($suivis);
function echoAsPctAndBold($nbelem, $total=null, $is_bold=false) {
if ($is_bold) echo '<b>';
//if ($total !== null && $total>0) {
if ($total !== null) {
// Eviter division par zero
if ($nbelem==0) $total=1;
$pct = round( ($nbelem / $total) * 100 , 1 );
$nbelem = "$pct% ($nbelem)";
//$nbelem = "$nbelem ($pct%)";
//$nbelem = "$pct%";
}
echo $nbelem;
if ($is_bold) echo '</b>';
}
// LIGNE VIDE DE SÉPARATION
function displayEmptyLine() {
echo "
<tr style='height:5px ; background-color:black'>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>";
}
//function displayStatsLine($title, $line, $suivis, $prets, $bold=false, $year_prev=null, $avg=null) {
function displayStatsLine($title, $line, $is_bold=false, $year_prev=null, $avg=null) {
//debug($line);
?>
<tr>
<!-- Titre -->
<td><b><?=$title?></b></td>
<!-- Evolution \N-1 et \avg -->
<?php
$total = $line['CREATED'];
$evol_from_year_prev = '/';
$evol_from_avg = '/';
if ($year_prev) {
$evol_from_year_prev = round (($total-$year_prev['CREATED'])/$year_prev['CREATED'] * 100);
if ($evol_from_year_prev>=0) $evol_from_year_prev = '+'.$evol_from_year_prev;
$evol_from_year_prev .= '%';
}
if ($avg) {
$evol_from_avg = round (($total-$avg['CREATED'])/$avg['CREATED'] * 100);
if ($evol_from_avg>=0) $evol_from_avg = '+'.$evol_from_avg;
$evol_from_avg .= '%';
}
?>
<td><?=$evol_from_year_prev?></td>
<td><?=$evol_from_avg?></td>
<!-- TOTAL -->
<td><?=echoAsPctAndBold($total, null, $is_bold)?></td>
<!-- VALIDATED -->
<td><?=echoAsPctAndBold($line['VALIDATED'], $total, $is_bold)?></td>
<!-- TBA -->
<!--
<td><echoAsPctAndBold($line['TOBEARCHIVED'], null, $is_bold)></td>
-->
<td><?=echoAsPctAndBold($line['TOBEARCHIVED'], $total, $is_bold)?></td>
<!-- ARCHIVED -->
<td><?=echoAsPctAndBold($line['ARCHIVED'], $total, $is_bold)?></td>
<!-- SUIVIS -->
<td><?=echoAsPctAndBold($line['suivis'], $total, $is_bold)?></td>
<!-- EMPRUNTS -->
<td><?=echoAsPctAndBold($line['prets'], $total, $is_bold)?></td>
</tr>
<?php
}
?>
<!--
----------------------------------------
-------------- PAGE WEB HTML -----------
----------------------------------------
-->
<style>
table.stats {
border: 5px solid #333;
}
table.stats td {
border: 2px solid #333;
}
table.stats thead th {
border: 2px solid #333;
text-align: center;
#background-color: blue;
#color: white;
}
</style>
<h2>
<!--
<i class="icon-print"></i>
-->
<center>STATISTIQUES SUR LES MATÉRIELS</center>
</h2>
<p>
<table>
<tr>
<td><b>Prendre en compte les</b></td>
<td>
<?php
echo $this->Form->create('Statistiques', [
'type' => 'get',
]);
//echo '<input name="s_all_2" class="search-input" type="text" id="MaterielSAll">';
echo $this->Form->control('nbyears', [
'id' => 'nby',
//'class' => 'search-input',
'label' => '',
//'type' => 'text',
'default' => $nbyears
]);
/*
echo $this->Form->submit('Chercher', [
'name' => 'MaterielSAll',
'id' => 'MaterielSAll',
'style' => 'margin: 0px;'
]);
*/
echo $this->Form->end();
?>
</td>
<td><b>dernières années (<?=$current_year.'-'.$year_min?>)</b></td>
</tr>
</table>
</p>
<table class="stats">
<!-- TITRES COLONNES sur 2 lignes -->
<thead>
<!--
<tr>
<th> </th>
<th>Evolution \ N-1</th>
<th>Evolution \ moyenne</th>
<th>Matériels acquis</th>
<th>Validés</th>
<th>En demande d'archivage</th>
<th>Archivés</th>
<th>Matériels suivis</th>
<th>Matériels empruntés</th>
</tr>
-->
<tr>
<th> </th>
<th colspan="3" align="center">Matériels acquis</th>
<!--
<th></th>
<th></th>
-->
<th colspan="3">Répartition par statut</th>
<!--
<th></th>
<th></th>
-->
<th colspan="2">Suivis et Emprunts</th>
</tr>
<tr>
<th> </th>
<th>Evol. \ N-1</th>
<th>Evol. \ moyenne</th>
<th>Total</th>
<th>Validés</th>
<th>A archiver</th>
<th>Archivés</th>
<th>Matériels suivis</th>
<th>Matériels prêtés</th>
</tr>
</thead>
<!-- LIGNES DATA -->
<tbody>
<?php
displayEmptyLine();
displayStatsLine("Moyenne annuelle", $avg, true);
//displayStatsLine("Moyenne annuelle (sur les $nbyears dernières années)", $avg, true);
//displayStatsLine("Moyenne annuelle (sur toutes les années sauf 1ère et dernière)", $avg, true);
displayStatsLine('Total Général', $tot, true);
//displayStatsLine('Total Sauf 1ère et dernière années', $tot2, true);
// LIGNE VIDE DE SÉPARATION
displayEmptyLine();
// DATA, ANNÉE PAR ANNÉE (1 ligne par année)
/*
foreach ($years as $y=>$val) {
$year_title = $y;
if ($y==$year) $year_title = "Année en cours ($y)";
displayStatsLine($year_title, $val);
}
*/
for ($y=$current_year ; $y>=$year_min ; $y--) {
$val = $years[$y];
$year_title = $y;
if ($y==$current_year) $year_title = "Année en cours ($y)";
$year_prev = $y==$year_min ? null : $years[$y-1];
displayStatsLine($year_title, $val, false, $year_prev, $avg);
}
?>
</tbody>
</table>
<?php
?>