Эх сурвалжийг харах

- Employee : Fix affichage heure travaillées par jour

Théo LECOQ 2 жил өмнө
parent
commit
5910df3ab6
1 өөрчлөгдсөн 64 нэмэгдсэн , 64 устгасан
  1. 64 64
      plugin/employee/action.php

+ 64 - 64
plugin/employee/action.php

@@ -7,12 +7,12 @@
 		require_once(__DIR__.SLASH.'Employee.class.php');
 		require_once(__DIR__.SLASH.'EmployeeWorkTime.class.php');
 		require_once(__DIR__.SLASH.'EmployeeContract.class.php');
-		
+
 
 
 		// OPTIONS DE RECHERCHE, A ACTIVER POUR UNE RECHERCHE AVANCEE
-		$query = 'SELECT main.*, '.Employee::joinString('man').' 
-		FROM '.Employee::tableName().' main  
+		$query = 'SELECT main.*, '.Employee::joinString('man').'
+		FROM '.Employee::tableName().' main
 		LEFT JOIN '.Employee::tableName().' man ON man.id = main.manager  WHERE 1';
 
 		$data = array();
@@ -43,7 +43,7 @@
 
 			if(empty($hierarchy)) $hierarchy[] = 0;
 			$query .= ' AND (main.manager IN ('.implode(',',array_fill(0,count($hierarchy),'?')).') OR (main.manager IN (NULL,"") AND main.creator=?))';
-			
+
 			$data[] = $myUser->login;
 		}
 
@@ -60,11 +60,11 @@
 		$response['pagination'] = Employee::paginate($itemPerPage,(!empty($_['page'])?$_['page']:0),$query,$data,'main');
 
 		$employees = Employee::staticQuery($query,$data,true,1);
-		
+
 		$hardwares = Dictionnary::slugToArray('employee_employee_hardware',true);
 
 		$jobs = Dictionnary::slugToArray('employee_employee_job',true);
-		
+
 		$response['rows'] = array();
 
 
@@ -72,8 +72,8 @@
 			$row = $employee->toArray();
 
 			$row['photo'] = $employee->photo();
-			$row['jobDescription'] = html_entity_decode($row['jobDescription']); 
-			$row['comment'] = html_entity_decode($row['comment']); 
+			$row['jobDescription'] = html_entity_decode($row['jobDescription']);
+			$row['comment'] = html_entity_decode($row['comment']);
 
 			$row['hardware'] = array();
 			$employeeHardwares = json_decode($employee->hardware,true);
@@ -89,12 +89,12 @@
 				$row['manager'] = $manager->toArray();
 				$row['manager']['photo'] = $manager->photo();
 			}
-			
 
-			$user = User::byLogin($row['account']); 
-			$row['account'] = $user->toArray(); 
-			$row['account']['fullname'] = $user->fullname(); 
-			$row['account']['avatar'] = $user->getAvatar(); 
+
+			$user = User::byLogin($row['account']);
+			$row['account'] = $user->toArray();
+			$row['account']['fullname'] = $user->fullname();
+			$row['account']['avatar'] = $user->getAvatar();
 
 			$row['job']= !empty($row['job']) && isset($jobs[$row['job']]) ? $jobs[$row['job']] : new Dictionnary();
 
@@ -105,30 +105,30 @@
 				$row['jobDescription'] = strip_tags(str_replace(array('<br>','<br/>','<p>'),PHP_EOL,$row['jobDescription']));
 				$row['comment'] = strip_tags(str_replace(array('<br>','<br/>','<p>'),PHP_EOL,$row['comment']));
 				$row['job'] = $row['job']->label;
-				
+
 			}
-			
+
 
 			if($row['birthName'] == $row['name']) unset($row['birthName']);
 
 			$response['rows'][] = $row;
 		}
-		
+
 		if($_['export'] == 'true'){
 			if(empty($response['rows'])) $response['rows'][] = array('Vide'=>'Aucune données');
 			$fieldsMapping = array();
-			foreach (Employee::fields(false) as $key => $value) 
+			foreach (Employee::fields(false) as $key => $value)
 				$fieldsMapping[$value['label']] = $key;
 			$stream = Excel::exportArray($response['rows'],$fieldsMapping ,'Export');
 			File::downloadStream($stream,'export-employes-'.date('d-m-Y').'.xlsx');
 			exit();
 		}
-		
-	
-		
+
+
+
 	});
-	
-	
+
+
 	//Ajout ou modification d'élément fiche employé
 	Action::register('employee_save',function(&$response){
 		global $_,$conf,$myUser;
@@ -178,7 +178,7 @@
 		}
 
 	});
-	
+
 	//Suppression d'élement fiche employé
 	Action::register('employee_delete',function(&$response){
 		global $_,$myUser;
@@ -188,7 +188,7 @@
 
 		$item = Employee::provide();
 		if($item->id==0) return $response;
-		
+
 		if(!$myUser->can('employee','configure')){
 			$myEmployee = Employee::load(array('account'=>$myUser->login));
 			if(!$myEmployee->can($item,'edit')) throw new Exception('Vous n\'avez pas la permission d\'enregistrer cette fiche');
@@ -197,7 +197,7 @@
 		$item->state = Employee::INACTIVE;
 		$item->save();
 	});
-	
+
 	//Employee : Gestion upload Photo
 	Action::register('employee_employee_photo',function(&$response){
 			File::handle_component(array(
@@ -237,7 +237,7 @@
 				$conf->put($key,$value);
 		}
 	});
-	
+
 	/* COMPOSANT*/
 	//recherche autocomplete
 	Action::register('employee_autocomplete',function(&$response){
@@ -251,7 +251,7 @@
 			$query = 'SELECT c.* FROM '.Employee::tableName().' c WHERE (c.name LIKE ? OR c.firstname LIKE ?) ';
 			$query .= ' LIMIT 10';
 
-        
+
         	$devices = Employee::staticQuery($query,$data,true);
         	foreach($devices as $item){
                 $response['rows'][] = array(
@@ -260,20 +260,20 @@
 				);
         	}
         });
-    
+
 
 	//Récuperation valeur composant depuis l'uid
     Action::register('employee_by_uid',function(&$response){
         global $myUser,$_;
     	if (!$myUser->connected()) throw new Exception("Vous devez être connecté",401);
     	require_once(__DIR__.SLASH.'Employee.class.php');
-    	
+
     	$response['items'] = array();
-    	
+
     	$query = 'SELECT main.* FROM '.Employee::tableName().' main  WHERE main.id IN(';
     	$query .= implode(',', array_fill(0, count($_['items']), '?'));
     	$query .= ')';
-    	
+
 	    foreach(Employee::staticQuery($query,$_['items'],true) as  $item) {
 	       $row = array(); //on ne met pas toArray car certaines infos sont confidentielles
     	   $row['label'] =  html_entity_decode($item->fullname(), ENT_QUOTES);
@@ -281,34 +281,34 @@
     	   $row['job'] =  $item->id;
     	   $response['items'][$row['id']] = $row;
 	    }
-        
+
     });
 
-	
+
 	/** EMPLOYEEWORKTIME / TEMPS DE TRAVAIL EMPOYé **/
 	//Récuperation d'une liste de temps de travail empoyé
 	Action::register('employee_employee_work_time_search',function(&$response){
 		global $_;
 		User::check_access('employee','read');
 		require_once(__DIR__.SLASH.'EmployeeWorkTime.class.php');
-		
+
 		$employeeworktimes = EmployeeWorkTime::loadAll();
 		$response['rows'] = array();
 		foreach($employeeworktimes as $employeeworktime){
 			$row = $employeeworktime->toArray();
-			$row['recovertype'] = EmployeeWorkTime::recovertypes($row['recovertype']); 
-			
+			$row['recovertype'] = EmployeeWorkTime::recovertypes($row['recovertype']);
+
 			$hourByDay = json_decode($row['hourByDay']);
 			$row['hourByDay'] = array();
 			for($i=1;$i<8;$i++){
-				$row['hourByDay'][] = array('day'=>day_name($i),'hours'=>isset($hourByDay[$i])? $hourByDay[$i-1] :0 );
+				$row['hourByDay'][] = array('day'=>day_name($i),'hours'=>isset($hourByDay[$i-1])? $hourByDay[$i-1] :0 );
 			}
 			$response['rows'][] = $row;
 		}
-		
+
 	});
-	
-	
+
+
 	//Ajout ou modification d'élément temps de travail empoyé
 	Action::register('employee_employee_work_time_save',function(&$response){
 		global $_;
@@ -324,7 +324,7 @@
 
 		$response = $item->toArray();
 	});
-	
+
 	//Récuperation ou edition d'élément temps de travail empoyé
 	Action::register('employee_employee_work_time_edit',function(&$response){
 		global $_;
@@ -332,7 +332,7 @@
 		require_once(__DIR__.SLASH.'EmployeeWorkTime.class.php');
 		$response = EmployeeWorkTime::getById($_['id'],0)->toArray();
 	});
-	
+
 
 	//Suppression d'élement temps de travail empoyé
 	Action::register('employee_employee_work_time_delete',function(&$response){
@@ -356,7 +356,7 @@
 		require_once(__DIR__.SLASH.'EmployeeContract.class.php');
 		require_once(__ROOT__.SLASH.'plugin/employee/Employee.class.php');
 		require_once(__ROOT__.SLASH.'plugin/employee/EmployeeWorkTime.class.php');
-		
+
 		$employee = Employee::getById($_['employee']);
 		if(!$employee) throw new Exception('Employé inexistant');
 
@@ -370,10 +370,10 @@
 		$query = 'SELECT main.*,main.id as id, '.Employee::joinString('Employee').', '.EmployeeWorkTime::joinString('EmployeeWorkTime').' FROM '.EmployeeContract::tableName().' main  LEFT JOIN '.Employee::tableName().' Employee ON main.employee=Employee.id  LEFT JOIN '.EmployeeWorkTime::tableName().' EmployeeWorkTime ON main.worktime=EmployeeWorkTime.id  WHERE 1';
 		$data = array();
 		//Recherche simple
-	
+
 		$query .= ' AND main.employee = ?';
 		$data[] = $employee->id;
-		
+
 
 		//Recherche avancée
 		if(isset($_['filters']['advanced'])) filter_secure_query($_['filters']['advanced'],array('main.employee','main.start','main.end','main.type','main.statute','main.salary','main.worktime','main.comment'),$query,$data);
@@ -388,11 +388,11 @@
 		$itemPerPage = !empty($_['itemPerPage']) ? $_['itemPerPage'] : 20;
 		//force le nombre de page max a 50 coté serveur
 		$itemPerPage = $itemPerPage>50 ? 50 : $itemPerPage;
-		
+
 		$response['pagination'] = EmployeeContract::paginate($itemPerPage,(!empty($_['page'])?$_['page']:0),$query,$data,'main');
 
 		$employeecontracts = EmployeeContract::staticQuery($query,$data,true,1);
-		
+
 
 		$typeList = Dictionnary::slugToArray('employee_employeecontract_type',true);
 		$statuteList = Dictionnary::slugToArray('employee_employeecontract_statute',true);
@@ -402,20 +402,20 @@
 			$row = $employeecontract->toArray();
 			$row['employee'] = $employeecontract->join('employee')->toArray();
 			$row['worktime'] = $employeecontract->join('worktime')->toArray();
-			$row['start-readable'] = date('d/m/Y',$row['start']); 
-			if(!empty($row['end'])) $row['end-readable'] = date('d/m/Y',$row['end']); 
-			
-			$row['type'] = isset($typeList[$row['type']]) ? $typeList[$row['type']] : new Dictionnary(); 
-			$row['statute'] = isset($statuteList[$row['statute']]) ? $statuteList[$row['statute']] : new Dictionnary(); 
-			$row['comment'] = html_entity_decode($row['comment']); 
+			$row['start-readable'] = date('d/m/Y',$row['start']);
+			if(!empty($row['end'])) $row['end-readable'] = date('d/m/Y',$row['end']);
+
+			$row['type'] = isset($typeList[$row['type']]) ? $typeList[$row['type']] : new Dictionnary();
+			$row['statute'] = isset($statuteList[$row['statute']]) ? $statuteList[$row['statute']] : new Dictionnary();
+			$row['comment'] = html_entity_decode($row['comment']);
 			$response['rows'][] = $row;
 		}
-		
-	
-		
+
+
+
 	});
-	
-	
+
+
 	//Ajout ou modification d'élément contrat employé
 	Action::register('employee_employee_contract_save',function(&$response){
 		global $_,$myUser;
@@ -441,7 +441,7 @@
 		//Vérification qu'aucun autre contrat n'est actif si celui si est le "en cours"
 		if(empty($item->end) || $item->end > time() ){
 			$currentContract = Employee::getById($_['employee'])->currentContract();
-			
+
 			if($currentContract->id!=0 && $currentContract->id!=$item->id ) throw new Exception('Vous ne pouvez enregistrer deux contrats actifs en même temps, veuillez vérifier les dates de départ et d\'arrivée');
 		}
 
@@ -455,8 +455,8 @@
 
 		$response = $item->toArray();
 	});
-	
-	
+
+
 
 	//Edition d'élément contrat employé
 	Action::register('employee_employee_contract_edit',function(&$response){
@@ -479,10 +479,10 @@
 		}
 
 		$row = $item->toArray();
-		$row['start'] = date('d/m/Y',$row['start']); 
-		
+		$row['start'] = date('d/m/Y',$row['start']);
+
 		if(!empty($row['end'])) {
-			$row['end'] = date('d/m/Y',$row['end']); 
+			$row['end'] = date('d/m/Y',$row['end']);
 		}else{
 			$row['end'] = '';
 		}