Skip to content

Instantly share code, notes, and snippets.

@makamo
Created February 6, 2015 11:56
Show Gist options
  • Save makamo/075a7e8917f781952169 to your computer and use it in GitHub Desktop.
Save makamo/075a7e8917f781952169 to your computer and use it in GitHub Desktop.
<?php
namespace App\Controller;
use Carbon\Carbon;
use Core\Flash\Flash;
use App\Entity\EmployeeEntity;
class CalculesController extends AppController
{
public function __construct()
{
parent::__construct();
$this->loadModel('Contrat');
$this->loadModel('Equipement');
$this->loadModel('Employee');
$this->loadModel('Tache');
}
public function index()
{
$contrats = $this->Contrat->all();
$this->render('calcules.index', compact("contrats"));
}
public function show()
{
if(empty($_GET)) {
Flash::setFlash("Faite une selection en premier");
header('Location: index.php?p=calcules.index');
}
$equipement = $this->Equipement->find($_GET["equipement"]);
$contrat = $equipement->contrat;
$start = $_GET["start"];
$end = $_GET["end"];
$quart = $_GET["quart"];
$superviseur = $this->Employee->getSuperviseurByContrat($contrat->id, $start, $end, $quart);
if ($superviseur=== null) {
$superviseur = new EmployeeEntity();
$superviseur->name="N\\D";
}
$listeDesEquipements = $this->Equipement->findByContrat($contrat->id, $start, $end, $quart);
$listeEquipements = [];
foreach ($listeDesEquipements as $dataEquipement) {
if (!in_array($dataEquipement->id, $listeEquipements)) {
$listeEquipements[] = $dataEquipement->id;
}
}
$rangeDeDate = $this->__getRangeDate($start, $end);
$listeForeures = $this->Employee->getForeureByEquipement($equipement->id, $start, $end, $quart);
$data["Foreures"] = $this->__getHeureByEquipement($listeForeures, $rangeDeDate, $equipement, $start, $end, $quart);
$listeHelpers = $this->Employee->getHelperByEquipement($equipement->id, $start, $end, $quart);
$data["Helpers"] = $this->__getHeureByEquipement($listeHelpers, $rangeDeDate, $equipement, $start, $end, $quart);
$listeForemans = $this->Employee->getForemanByContrat($equipement->id, $start, $end, $quart);
$data["Foremans"] = $this->__getHeureByContrat($listeForemans, $rangeDeDate, $contrat, $start, $end, $quart);
$this->render('calcules.show',compact(
"listeEquipements",
"equipement",
"contrat",
"superviseur",
"rangeDeDate",
"data"
));
}
/**
* @param $debut
* @param $fin
* @return array
*/
private function __getRangeDate($debut,$fin)
{
$range= [];
$debut= explode("-",$debut);
$fin= explode("-",$fin);
$debut = Carbon::create($debut[0],$debut[1],$debut[2]);
$fin = Carbon::create($fin[0],$fin[1],$fin[2]);
$range[] = Carbon::createFromTimestamp($debut->timestamp);
for($i=0;$debut != $fin;$i++){
$range[] = Carbon::createFromTimestamp($debut->addDay()->timestamp);
}
return $range;
}
/**
* @param $listeForeures
* @param $rangeDeDate
* @param $equipement
* @param $start
* @param $end
* @param $quart
* @return array
*/
private function __getHeureByEquipement($listeForeures, $rangeDeDate, $equipement, $start, $end, $quart)
{
$data = [];
foreach ($listeForeures as $employe):
foreach ($rangeDeDate as $Date):
$active = "";
$content = "&nbsp;";
foreach ($this->Tache->getHeureParEmployeParEquipement($equipement->id, $start, $end, $quart, $employe->id, $employe->fonction) as $heure):
if ($Date->toDateString() == $heure->date->toDateString()):
$active = "bg-warning";
$content = $heure->heure;
$employe->heureTotal += $heure->heure;
endif;
endforeach;
$employe->rangeDate[] = ["date" => $Date,"active" => $active, "content" => $content];
endforeach;
$data[] = $employe;
endforeach;
return $data;
}
/**
* @param $listeForeures
* @param $rangeDeDate
* @param $equipement
* @param $start
* @param $end
* @param $quart
* @return array
*/
private function __getHeureByContrat($listeForeures, $rangeDeDate, $contrat, $start, $end, $quart)
{
$data = [];
foreach ($listeForeures as $employe):
foreach ($rangeDeDate as $Date):
$active = "";
$content = "&nbsp;";
foreach ($this->Tache->getHeureParEmployeParContrat($contrat->id, $start, $end, $quart, $employe->id, $employe->fonction) as $heure):
if ($Date->toDateString() == $heure->date->toDateString()):
$active = "bg-warning";
$content = $heure->heure;
$employe->heureTotal += $heure->heure;
endif;
endforeach;
$employe->rangeDate[] = ["date" => $Date,"active" => $active, "content" => $content];
endforeach;
$data[] = $employe;
endforeach;
return $data;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment