diff --git a/src/schedule-2.0/config/routes.yaml b/src/schedule-2.0/config/routes.yaml index b693d49..60334f7 100644 --- a/src/schedule-2.0/config/routes.yaml +++ b/src/schedule-2.0/config/routes.yaml @@ -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} diff --git a/src/schedule-2.0/src/Controller/StatController.php b/src/schedule-2.0/src/Controller/StatController.php new file mode 100755 index 0000000..8384457 --- /dev/null +++ b/src/schedule-2.0/src/Controller/StatController.php @@ -0,0 +1,135 @@ +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"]."
"; + + $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, + ]); + + + } +} diff --git a/src/schedule-2.0/templates/Stat/view.html.twig b/src/schedule-2.0/templates/Stat/view.html.twig new file mode 100644 index 0000000..515a3bb --- /dev/null +++ b/src/schedule-2.0/templates/Stat/view.html.twig @@ -0,0 +1,114 @@ + +{% extends 'base.html.twig' %} + +{% block body %} +

+STATISTIQUES +

+ +
+
+
+
+ DEV +
+
+
+
+
+
+ +
+
+
+ CSS +
+
+
+
+
+
+
+ +{% 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 %} + + +{% endblock %} + diff --git a/src/schedule-2.0/templates/base.html.twig b/src/schedule-2.0/templates/base.html.twig index febe2b1..4579789 100644 --- a/src/schedule-2.0/templates/base.html.twig +++ b/src/schedule-2.0/templates/base.html.twig @@ -372,7 +372,13 @@ -
  • +
  • + + Statistiques + +
  • + +
  • Exports