Compare commits

..

No commits in common. "5416f122d51624f49889801db7d46c3b5a4d78d2" and "e180def44b250a551d3ba25c318f5ad724a43922" have entirely different histories.

3 changed files with 29 additions and 22 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())) {
$interval=$em->getRepository("App:Tallyday")->getCapitaltimeinterval($this->getUser(),true);
$newcapital = $interval->format("%R").(($interval->days*24) + $interval->h).":".sprintf("%02s",$interval->i);
$f = new \DateTime('00:00');
$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);
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->datestart, $this->dateend));
$e->add(date_diff($this->dateend, $this->datestart));
return $f->diff($e);

View File

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