Merge branch 'master' into dist/eole/2.8.1/master

This commit is contained in:
Arnaud Fornerot 2022-03-29 09:35:51 +02:00
commit 5416f122d5
3 changed files with 22 additions and 29 deletions

View File

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

View File

@ -69,7 +69,7 @@ class Tallyday
$f = clone $e; $f = clone $e;
if($this->datestart && $this->dateend) 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); return $f->diff($e);

View File

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