Compare commits

...

2 Commits

3 changed files with 22 additions and 29 deletions

View File

@ -935,17 +935,17 @@ class TallydayController extends AbstractController
$f->add($interval);
$f->sub(new \DateInterval('PT7H'));
$f->add($capital);
$interval = $e->diff($f);
$newcapital = $interval->format("%R").(($interval->days*24) + $interval->h).":".sprintf("%02s",$interval->i);
}
// Si la journée n'est pas encore validé : on ajoute la journée à la simulation
else if($data && (!$data->getValidateuser()||!$data->getValidateuser())) {
$f = new \DateTime('00:00');
$f->add($interval);
$f->sub(new \DateInterval('PT7H'));
$f->add($capital);
$interval=$em->getRepository("App:Tallyday")->getCapitaltimeinterval($this->getUser(),true);
$newcapital = $interval->format("%R").(($interval->days*24) + $interval->h).":".sprintf("%02s",$interval->i);
}
$interval = $e->diff($f);
$newcapital = $interval->format("%R").(($interval->days*24) + $interval->h).":".sprintf("%02s",$interval->i);
return new JsonResponse([
'success' => true,

View File

@ -69,7 +69,7 @@ class Tallyday
$f = clone $e;
if($this->datestart && $this->dateend)
$e->add(date_diff($this->dateend, $this->datestart));
$e->add(date_diff($this->datestart, $this->dateend));
return $f->diff($e);

View File

@ -51,43 +51,36 @@ class TallydayRepository extends ServiceEntityRepository
return $datas;
}
public function getCapitaltimeinterval($user) {
public function getCapitaltimeinterval($user,$getnovalidate=false) {
$datenow=new \DateTime('00:00');
$datas = $this->_em->getRepository('App:Tallyday')->findBy(["user"=>$user],["datestart"=>"DESC"]);
$tbweek=[];
$tbdays=[];
$ework = new \DateTime('00:00');
$idweeknow=$datenow->format("Y").$datenow->format("W");
$lastdayvalidate=false;
foreach($datas as $data) {
if($data->getDateof()<$datenow) {
$idweek=$data->getDateof()->format("Y").$data->getDateof()->format("W");
if(!in_array($idweek,$tbweek)&&$idweek!=$idweeknow) array_push($tbweek,$idweek);
$iddayweek=$data->getDateof()->format("w");
if($iddayweek>=1&&$iddayweek<=5) {
if(!in_array($data->getDateof(),$tbdays)) array_push($tbdays,$data->getDateof());
}
$ework->add($data->getTimeday());
}
if($data->getDateof()==$datenow&&($data->getValidateuser()||$data->getValidatemaster())) {
$lastdayvalidate=true;
$idweek=$data->getDateof()->format("Y").$data->getDateof()->format("W");
if(!in_array($idweek,$tbweek)&&$idweek!=$idweeknow) array_push($tbweek,$idweek);
if($data->getDateof()==$datenow&&($getnovalidate||$data->getValidateuser()||$data->getValidatemaster())) {
$iddayweek=$data->getDateof()->format("w");
if($iddayweek>=1&&$iddayweek<=5) {
if(!in_array($data->getDateof(),$tbdays)) array_push($tbdays,$data->getDateof());
}
$ework->add($data->getTimeday());
}
}
// Nbday worked
$nbdaywork=count($tbweek)*5;
if($datenow->format("w")==6||$datenow->format("w")==7)
$nbdaywork+=5;
else {
$nbdaywork+=$datenow->format("w");
if(!$lastdayvalidate) $nbdaywork--;
}
if($nbdaywork<0) $nbdaywork=0;
$nbdaywork=count($tbdays);
$etowork = new \DateTime('00:00');
$etowork->sub(new \DateInterval("PT".($nbdaywork*7)."H"));
$interval = $ework->diff($etowork);
$etowork->add(new \DateInterval("PT".($nbdaywork*7)."H"));
$interval = $etowork->diff($ework);
return $interval;
}