mise en place de stats
This commit is contained in:
@@ -421,6 +421,11 @@ export_offers:
|
||||
defaults: { _controller: App\Controller\ExportController:export_offers }
|
||||
|
||||
|
||||
#== Export ======================================================================================================
|
||||
app_stat_view:
|
||||
path: /user/stat
|
||||
defaults: { _controller: App\Controller\StatController:view }
|
||||
|
||||
#== API ===========================================================================================================
|
||||
app_api:
|
||||
path: /api/{key}
|
||||
|
135
src/schedule-2.0/src/Controller/StatController.php
Executable file
135
src/schedule-2.0/src/Controller/StatController.php
Executable file
@@ -0,0 +1,135 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controller;
|
||||
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Form\FormError;
|
||||
use Knp\Bundle\SnappyBundle\Snappy\Response\PdfResponse;
|
||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||
|
||||
use App\Entity\Service as Entity;
|
||||
use App\Form\ServiceType as Form;
|
||||
|
||||
class StatController extends AbstractController
|
||||
{
|
||||
private $knpSnappy;
|
||||
public function __construct(\Knp\Snappy\Pdf $knpSnappy) { $this->knpSnappy = $knpSnappy; }
|
||||
|
||||
public function view(Request $request)
|
||||
{
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
|
||||
$natures = $em->getRepository("App:Nature")->findAll();
|
||||
$tbnatures=[];
|
||||
foreach($natures as $nature) {
|
||||
$tbnatures[$nature->getId()]=[
|
||||
"id"=>$nature->getId(),
|
||||
"name"=>$nature->getName(),
|
||||
"totalmonth"=> 0,
|
||||
"totalservice"=> 0,
|
||||
"totalnature" => 0,
|
||||
];
|
||||
}
|
||||
|
||||
$services = $em->getRepository("App:Service")->findAll();
|
||||
$tbservices=[];
|
||||
foreach($services as $service) {
|
||||
$tbservices[$service->getId()] = [
|
||||
"id"=>$service->getId(),
|
||||
"name"=>$service->getName(),
|
||||
"natures"=>$tbnatures,
|
||||
];
|
||||
}
|
||||
|
||||
$tbmonths=[];
|
||||
$now=new \Datetime("now");
|
||||
//$now->add(new \DateInterval('P3M'));
|
||||
$yend= $now->format("Y");
|
||||
$ystart=$yend-2;
|
||||
for($i=$ystart;$i<=$yend;$i++) {
|
||||
for($j=1;$j<=12;$j++) {
|
||||
$id=$i.str_pad($j, 2, '0', STR_PAD_LEFT);
|
||||
$name=$i."-".str_pad($j, 2, '0', STR_PAD_LEFT);
|
||||
$tbmonths[$id]= [
|
||||
"id"=>$id,
|
||||
"name"=>$name,
|
||||
"services"=>$tbservices,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
foreach($tbmonths as $keymonth => $month) {
|
||||
$start=new \Datetime($month["id"]."01");
|
||||
$end=new \Datetime($month["id"]."01");
|
||||
$end->add(new \DateInterval('P1M'));
|
||||
|
||||
$events = $em
|
||||
->createQueryBuilder('event')
|
||||
->select('SUM(event.duration) as somme')
|
||||
->from('App:Event','event')
|
||||
->andWhere('event.start >=:start')
|
||||
->andWhere('event.end <:end')
|
||||
->setParameter('start',$start)
|
||||
->setParameter('end',$end)
|
||||
->getQuery()->getResult();
|
||||
$totalmonth=($events[0]["somme"]?$events[0]["somme"]:0);
|
||||
|
||||
foreach($month["services"] as $keyservice => $service) {
|
||||
$events = $em
|
||||
->createQueryBuilder('event')
|
||||
->select('SUM(event.duration) as somme')
|
||||
->from('App:Event','event')
|
||||
->from('App:User','user')
|
||||
->andWhere('event.start >=:start')
|
||||
->andWhere('event.end <:end')
|
||||
->andWhere('event.user=user')
|
||||
->andWhere('user.service=:service')
|
||||
->setParameter('start',$start)
|
||||
->setParameter('end',$end)
|
||||
->setParameter('service',$service["id"])
|
||||
->getQuery()->getResult();
|
||||
$totalservice=($events[0]["somme"]?$events[0]["somme"]:0);
|
||||
|
||||
foreach($service["natures"] as $keynature => $nature) {
|
||||
$events = $em
|
||||
->createQueryBuilder('event')
|
||||
->select('SUM(event.duration) as somme')
|
||||
->from('App:Task','task')
|
||||
->from('App:Event','event')
|
||||
->from('App:User','user')
|
||||
->andWhere('task.nature=:nature')
|
||||
->andWhere('event.task=task')
|
||||
->andWhere('event.start >=:start')
|
||||
->andWhere('event.end <:end')
|
||||
->andWhere('event.user=user')
|
||||
->andWhere('user.service=:service')
|
||||
->setParameter('nature',$nature["id"])
|
||||
->setParameter('start',$start)
|
||||
->setParameter('end',$end)
|
||||
->setParameter('service',$service["id"])
|
||||
->getQuery()->getResult();
|
||||
|
||||
//echo $keymonth." ".$service["id"]." ".$service["name"]." ".$nature["name"]." = ".$events[0]["somme"]."<br>";
|
||||
|
||||
$tbmonths[$keymonth]["services"][$keyservice]["natures"][$keynature]["totalnature"]=($events[0]["somme"]?$events[0]["somme"]:0);
|
||||
$tbmonths[$keymonth]["services"][$keyservice]["natures"][$keynature]["totalmonth"]=$totalmonth;
|
||||
$tbmonths[$keymonth]["services"][$keyservice]["natures"][$keynature]["totalservice"]=$totalservice;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//return new JsonResponse($tbmonths);
|
||||
return $this->render('Stat/view.html.twig',[
|
||||
"useheader" => true,
|
||||
"usesidebar" => true,
|
||||
"tbmonths" => $tbmonths,
|
||||
"tbnatures" => $tbnatures,
|
||||
"tbservices" => $tbservices,
|
||||
]);
|
||||
|
||||
|
||||
}
|
||||
}
|
114
src/schedule-2.0/templates/Stat/view.html.twig
Normal file
114
src/schedule-2.0/templates/Stat/view.html.twig
Normal file
@@ -0,0 +1,114 @@
|
||||
|
||||
{% extends 'base.html.twig' %}
|
||||
|
||||
{% block body %}
|
||||
<h1 class="page-header">
|
||||
STATISTIQUES
|
||||
</h1>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-md-6">
|
||||
<div class="card homecard" style="width: 100%; height: 600px;">
|
||||
<div class="card-header">
|
||||
DEV
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<div id="chart-1" style="height: 250px;"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="col-md-6">
|
||||
<div class="card homecard" style="width: 100%; height: 600px;">
|
||||
<div class="card-header">
|
||||
CSS
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<div id="chart-3" style="height: 250px;"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{% endblock %}
|
||||
|
||||
{% block localjavascript %}
|
||||
$(document).ready(function() {
|
||||
|
||||
graphDEV();
|
||||
graphCSS();
|
||||
});
|
||||
|
||||
|
||||
function graphDEV() {
|
||||
|
||||
new Morris.Line({
|
||||
element: 'chart-1',
|
||||
xkey: 'month',
|
||||
ykeys: [
|
||||
'Total',
|
||||
{% for nature in tbnatures %}
|
||||
'{{ nature.name }}',
|
||||
{% endfor %}
|
||||
],
|
||||
data: [
|
||||
{% for month in tbmonths %}
|
||||
{ month: '{{ month.name }}',
|
||||
{% for nature in month.services[1].natures %}
|
||||
{% if loop.first %}
|
||||
'Total': {{ nature.totalservice }},
|
||||
{% endif %}
|
||||
|
||||
'{{ nature.name }}': {{ nature.totalnature }},
|
||||
{% endfor %}
|
||||
},
|
||||
{% endfor %}
|
||||
],
|
||||
labels: [
|
||||
'Total',
|
||||
{% for nature in tbnatures %}
|
||||
'{{ nature.name }}',
|
||||
{% endfor %}
|
||||
]
|
||||
});
|
||||
}
|
||||
|
||||
function graphCSS() {
|
||||
new Morris.Line({
|
||||
element: 'chart-3',
|
||||
xkey: 'month',
|
||||
ymax: 160,
|
||||
ykeys: [
|
||||
'Total',
|
||||
{% for nature in tbnatures %}
|
||||
'{{ nature.name }}',
|
||||
{% endfor %}
|
||||
],
|
||||
data: [
|
||||
{% for month in tbmonths %}
|
||||
{ month: '{{ month.name }}',
|
||||
{% for nature in month.services[3].natures %}
|
||||
{% if loop.first %}
|
||||
'Total': {{ nature.totalservice }},
|
||||
{% endif %}
|
||||
'{{ nature.name }}': {{ nature.totalnature }},
|
||||
{% endfor %}
|
||||
},
|
||||
{% endfor %}
|
||||
],
|
||||
labels: [
|
||||
'Total',
|
||||
{% for nature in tbnatures %}
|
||||
'{{ nature.name }}',
|
||||
{% endfor %}
|
||||
]
|
||||
});
|
||||
}
|
||||
|
||||
{% endblock %}
|
||||
|
||||
{% block localexternalscript %}
|
||||
<script src="//cdnjs.cloudflare.com/ajax/libs/raphael/2.1.0/raphael-min.js"></script>
|
||||
<script src="//cdnjs.cloudflare.com/ajax/libs/morris.js/0.5.1/morris.min.js"></script>
|
||||
{% endblock %}
|
||||
|
@@ -372,6 +372,12 @@
|
||||
</a>
|
||||
</li>
|
||||
|
||||
<li>
|
||||
<a href="{{path("app_stat_view")}}">
|
||||
<i class="fas fa-chart-line"></i>Statistiques
|
||||
</a>
|
||||
</li>
|
||||
|
||||
<li class="last">
|
||||
<a href="{{path("app_export_view")}}">
|
||||
<i class="fa fa-file-download"></i>Exports
|
||||
|
Reference in New Issue
Block a user