stats.ctp 5.68 KB
<?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>';
}



//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 ----------- 
----------------------------------------
-->

<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 border=2>

	<thead>
	<!-- TITRES COLONNES sur 2 lignes -->
	<!-- 
	<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 
	
	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 -->
	<tr>
		<td></td>
		<td></td>
		<td></td>
		<td></td>
		<td></td>
		<td></td>
		<td></td>
		<td></td>
	</tr>

	<!-- ANNÉE PAR ANNÉE (1 ligne par année) -->
	<?php 
	/*
	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 

?>