ajout du dossier php pour mettre tout les fichiers php
This commit is contained in:
106
project/public/php/getAllTeamRequests.php
Normal file
106
project/public/php/getAllTeamRequests.php
Normal file
@@ -0,0 +1,106 @@
|
||||
<?php
|
||||
header("Access-Control-Allow-Origin: *");
|
||||
header("Access-Control-Allow-Methods: GET, OPTIONS");
|
||||
header("Access-Control-Allow-Headers: Content-Type");
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'OPTIONS') {
|
||||
http_response_code(200);
|
||||
exit();
|
||||
}
|
||||
|
||||
header("Content-Type: application/json");
|
||||
|
||||
ini_set('display_errors', 1);
|
||||
ini_set('display_startup_errors', 1);
|
||||
error_reporting(E_ALL);
|
||||
|
||||
// Connexion DB
|
||||
$host = "192.168.0.4";
|
||||
$dbname = "DemandeConge";
|
||||
$username = "wpuser";
|
||||
$password = "-2b/)ru5/Bi8P[7_";
|
||||
|
||||
$conn = new mysqli($host, $username, $password, $dbname);
|
||||
if ($conn->connect_error) {
|
||||
error_log("Erreur connexion DB: " . $conn->connect_error);
|
||||
echo json_encode(["success" => false, "message" => "Erreur de connexion DB"]);
|
||||
exit();
|
||||
}
|
||||
|
||||
|
||||
// Récupération ID manager
|
||||
$managerId = $_GET['SuperieurId'] ?? null;
|
||||
if (!$managerId) {
|
||||
echo json_encode(["success" => false, "message" => "Paramètre SuperieurId manquant"]);
|
||||
exit();
|
||||
}
|
||||
|
||||
$sql = "
|
||||
SELECT
|
||||
dc.Id,
|
||||
dc.DateDebut,
|
||||
dc.DateFin,
|
||||
dc.Statut,
|
||||
dc.DateDemande,
|
||||
dc.Commentaire,
|
||||
dc.DocumentJoint,
|
||||
dc.EmployeeId,
|
||||
CONCAT(u.Prenom, ' ', u.Nom) as employee_name,
|
||||
u.Email as employee_email,
|
||||
tc.Nom as type
|
||||
FROM DemandeConge dc
|
||||
JOIN Users u ON dc.EmployeeId = u.ID
|
||||
JOIN TypeConge tc ON dc.TypeCongeId = tc.Id
|
||||
JOIN HierarchieValidation hv ON hv.EmployeId = u.ID
|
||||
WHERE hv.SuperieurId = ?
|
||||
ORDER BY dc.DateDemande DESC
|
||||
";
|
||||
|
||||
$stmt = $conn->prepare($sql);
|
||||
$stmt->bind_param("i", $managerId);
|
||||
$stmt->execute();
|
||||
|
||||
// Manquant dans ton code
|
||||
$result = $stmt->get_result();
|
||||
|
||||
$requests = [];
|
||||
while ($row = $result->fetch_assoc()) {
|
||||
$startDate = new DateTime($row['DateDebut']);
|
||||
$endDate = new DateTime($row['DateFin']);
|
||||
$submittedDate = new DateTime($row['DateDemande']);
|
||||
$days = 0;
|
||||
|
||||
$tmp = clone $startDate;
|
||||
while ($tmp <= $endDate) {
|
||||
if ((int)$tmp->format('N') < 6) $days++;
|
||||
$tmp->modify('+1 day');
|
||||
}
|
||||
|
||||
$requests[] = [
|
||||
"id" => (int)$row['Id'],
|
||||
"employee_id" => (int)$row['EmployeeId'],
|
||||
"employee_name" => $row['employee_name'],
|
||||
"employee_email" => $row['employee_email'],
|
||||
"type" => $row['type'],
|
||||
"start_date" => $row['DateDebut'],
|
||||
"end_date" => $row['DateFin'],
|
||||
"date_display" => $row['DateDebut'] === $row['DateFin']
|
||||
? $startDate->format('d/m/Y')
|
||||
: $startDate->format('d/m/Y') . ' - ' . $endDate->format('d/m/Y'),
|
||||
"days" => $days,
|
||||
"status" => $row['Statut'],
|
||||
"reason" => $row['Commentaire'] ?: '',
|
||||
"file" => $row['DocumentJoint'] ?: null,
|
||||
"submitted_at" => $row['DateDemande'],
|
||||
"submitted_display" => $submittedDate->format('d/m/Y')
|
||||
];
|
||||
}
|
||||
|
||||
echo json_encode([
|
||||
"success" => true,
|
||||
"requests" => $requests
|
||||
]);
|
||||
|
||||
$stmt->close();
|
||||
$conn->close();
|
||||
?>
|
||||
148
project/public/php/getLeaveCounters.php
Normal file
148
project/public/php/getLeaveCounters.php
Normal file
@@ -0,0 +1,148 @@
|
||||
<?php
|
||||
header("Access-Control-Allow-Origin: *");
|
||||
header("Access-Control-Allow-Methods: GET, OPTIONS");
|
||||
header("Access-Control-Allow-Headers: Content-Type");
|
||||
if ($_SERVER['REQUEST_METHOD'] == 'OPTIONS') { http_response_code(200); exit(); }
|
||||
header("Content-Type: application/json");
|
||||
ini_set('display_errors',1); ini_set('display_startup_errors',1); error_reporting(E_ALL);
|
||||
|
||||
$host="192.168.0.4"; $dbname="DemandeConge"; $username="wpuser"; $password="-2b/)ru5/Bi8P[7_";
|
||||
$conn = new mysqli($host,$username,$password,$dbname);
|
||||
if ($conn->connect_error) { echo json_encode(["success"=>false,"message"=>"Erreur DB: ".$conn->connect_error]); exit(); }
|
||||
|
||||
$userId = isset($_GET['user_id']) ? (int)$_GET['user_id'] : null;
|
||||
if (!$userId) { echo json_encode(["success"=>false,"message"=>"user_id manquant"]); $conn->close(); exit(); }
|
||||
|
||||
function getLeaveYear($date=null){ $d=$date?new DateTime($date):new DateTime(); $y=(int)$d->format('Y'); return ((int)$d->format('m')<6)?$y-1:$y;}
|
||||
function getRTTYear($date=null){ $d=$date?new DateTime($date):new DateTime(); return (int)$d->format('Y');}
|
||||
function getWorkingDays($start,$end){ $c=new DateTime($start); $e=new DateTime($end); $days=0; while($c<=$e){ $n=(int)$c->format('N'); if($n<6) $days++; $c->modify('+1 day'); } return $days;}
|
||||
|
||||
// Récupérer les typeIds utiles
|
||||
function getTypeId($conn,$name){ $s=$conn->prepare("SELECT Id FROM TypeConge WHERE Nom=?"); $s->bind_param("s",$name); $s->execute(); $res=$s->get_result(); $id=null; if($r=$res->fetch_assoc()) $id=(int)$r['Id']; $s->close(); return $id; }
|
||||
$cpTypeId = getTypeId($conn,'Congé payé');
|
||||
$rttTypeId = getTypeId($conn,'RTT');
|
||||
$absTypeId = getTypeId($conn,'Congé maladie');
|
||||
|
||||
$leaveYear = getLeaveYear();
|
||||
$rttYear = getRTTYear();
|
||||
$currentDate = date('Y-m-d');
|
||||
|
||||
// --- Soldes initiaux (CompteurConges) restent inchangés ---
|
||||
$cpSolde = 0; $rttSolde = 0; $absSolde = 0;
|
||||
if ($cpTypeId !== null) {
|
||||
$q="SELECT Solde FROM CompteurConges WHERE EmployeeId=? AND TypeCongeId=? AND Annee=?";
|
||||
$s=$conn->prepare($q); $s->bind_param("iii",$userId,$cpTypeId,$leaveYear); $s->execute(); $res=$s->get_result(); if($r=$res->fetch_assoc()) $cpSolde=$r['Solde']; $s->close();
|
||||
}
|
||||
if ($rttTypeId !== null) {
|
||||
$q="SELECT Solde FROM CompteurConges WHERE EmployeeId=? AND TypeCongeId=? AND Annee=?";
|
||||
$s=$conn->prepare($q); $s->bind_param("iii",$userId,$rttTypeId,$rttYear); $s->execute(); $res=$s->get_result(); if($r=$res->fetch_assoc()) $rttSolde=$r['Solde']; $s->close();
|
||||
}
|
||||
if ($absTypeId !== null) {
|
||||
$q="SELECT Solde FROM CompteurConges WHERE EmployeeId=? AND TypeCongeId=? AND Annee=?";
|
||||
$s=$conn->prepare($q); $s->bind_param("iii",$userId,$absTypeId,$rttYear); $s->execute(); $res=$s->get_result(); if($r=$res->fetch_assoc()) $absSolde=$r['Solde']; $s->close();
|
||||
}
|
||||
|
||||
// --- Calcul CP in process : priorité DemandeCongeType, fallback = working days on DemandeConge ---
|
||||
$cpInProcess = 0;
|
||||
if ($cpTypeId !== null) {
|
||||
$sql = "
|
||||
SELECT dc.Id, dc.DateDebut, dc.DateFin, dct.NombreJours
|
||||
FROM DemandeConge dc
|
||||
LEFT JOIN DemandeCongeType dct
|
||||
ON dct.DemandeCongeId = dc.Id AND dct.TypeCongeId = ?
|
||||
WHERE dc.EmployeeId = ?
|
||||
AND dc.Statut IN ('En attente','Validée')
|
||||
AND dc.DateFin >= ?
|
||||
AND (dct.NombreJours IS NOT NULL OR FIND_IN_SET(?, dc.TypeCongeId))
|
||||
";
|
||||
$s = $conn->prepare($sql);
|
||||
$s->bind_param("iiss", $cpTypeId, $userId, $currentDate, $cpTypeId);
|
||||
$s->execute();
|
||||
$res = $s->get_result();
|
||||
while ($r = $res->fetch_assoc()) {
|
||||
if ($r['NombreJours'] !== null) {
|
||||
$cpInProcess += (float)$r['NombreJours'];
|
||||
} else {
|
||||
$cpInProcess += getWorkingDays($r['DateDebut'], $r['DateFin']);
|
||||
}
|
||||
}
|
||||
$s->close();
|
||||
}
|
||||
|
||||
// --- Calcul RTT in process (même logique) ---
|
||||
$rttInProcess = 0;
|
||||
if ($rttTypeId !== null) {
|
||||
$sql = "
|
||||
SELECT dc.Id, dc.DateDebut, dc.DateFin, dct.NombreJours
|
||||
FROM DemandeConge dc
|
||||
LEFT JOIN DemandeCongeType dct
|
||||
ON dct.DemandeCongeId = dc.Id AND dct.TypeCongeId = ?
|
||||
WHERE dc.EmployeeId = ?
|
||||
AND dc.Statut IN ('En attente','Validée')
|
||||
AND dc.DateFin >= ?
|
||||
AND (dct.NombreJours IS NOT NULL OR FIND_IN_SET(?, dc.TypeCongeId))
|
||||
";
|
||||
$s = $conn->prepare($sql);
|
||||
$s->bind_param("iiss", $rttTypeId, $userId, $currentDate, $rttTypeId);
|
||||
$s->execute();
|
||||
$res = $s->get_result();
|
||||
while ($r = $res->fetch_assoc()) {
|
||||
if ($r['NombreJours'] !== null) {
|
||||
$rttInProcess += (float)$r['NombreJours'];
|
||||
} else {
|
||||
$rttInProcess += getWorkingDays($r['DateDebut'], $r['DateFin']);
|
||||
}
|
||||
}
|
||||
$s->close();
|
||||
}
|
||||
|
||||
// --- Calcul absenteisme (validation) : priorité DemandeCongeType, fallback = DATEDIFF+1 ---
|
||||
$absenteism = 0;
|
||||
if ($absTypeId !== null) {
|
||||
$sql = "
|
||||
SELECT dc.DateDebut, dc.DateFin, dct.NombreJours
|
||||
FROM DemandeConge dc
|
||||
LEFT JOIN DemandeCongeType dct
|
||||
ON dct.DemandeCongeId = dc.Id AND dct.TypeCongeId = ?
|
||||
WHERE dc.EmployeeId = ?
|
||||
AND dc.Statut = 'Validée'
|
||||
AND (dct.NombreJours IS NOT NULL OR FIND_IN_SET(?, dc.TypeCongeId))
|
||||
";
|
||||
$s = $conn->prepare($sql);
|
||||
$s->bind_param("iii", $absTypeId, $userId, $absTypeId);
|
||||
$s->execute();
|
||||
$res = $s->get_result();
|
||||
while ($r = $res->fetch_assoc()) {
|
||||
if ($r['NombreJours'] !== null) {
|
||||
$absenteism += (float)$r['NombreJours'];
|
||||
} else {
|
||||
// fallback : DATEDIFF + 1
|
||||
$d1 = new DateTime($r['DateDebut']); $d2 = new DateTime($r['DateFin']);
|
||||
$absenteism += ($d2->diff($d1)->days + 1);
|
||||
}
|
||||
}
|
||||
$s->close();
|
||||
}
|
||||
|
||||
$availableCPCalculated = max(0, $cpSolde - $cpInProcess);
|
||||
$availableRTTCalculated = max(0, $rttSolde - $rttInProcess);
|
||||
|
||||
echo json_encode([
|
||||
"success" => true,
|
||||
"message" => "Compteurs récupérés avec succès.",
|
||||
"counters" => [
|
||||
"availableCP" => (int)$availableCPCalculated,
|
||||
"availableRTT" => (int)$availableRTTCalculated,
|
||||
"availableABS" => (int)$absSolde,
|
||||
"rttInProcess" => (int)$rttInProcess,
|
||||
"absenteism" => (int)$absenteism
|
||||
],
|
||||
"debug" => [
|
||||
"cpSolde"=>$cpSolde,"cpInProcess"=>$cpInProcess,
|
||||
"rttSolde"=>$rttSolde,"rttInProcess"=>$rttInProcess,
|
||||
"absSolde"=>$absSolde,"absenteism"=>$absenteism
|
||||
]
|
||||
]);
|
||||
|
||||
$conn->close();
|
||||
?>
|
||||
159
project/public/php/getPendingRequests.php
Normal file
159
project/public/php/getPendingRequests.php
Normal file
@@ -0,0 +1,159 @@
|
||||
<?php
|
||||
// Récupération des demandes en attente pour un manager
|
||||
header("Access-Control-Allow-Origin: *");
|
||||
header("Access-Control-Allow-Methods: GET, OPTIONS");
|
||||
header("Access-Control-Allow-Headers: Content-Type");
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] == 'OPTIONS') {
|
||||
http_response_code(200);
|
||||
exit();
|
||||
}
|
||||
|
||||
header("Content-Type: application/json");
|
||||
|
||||
// Log des erreurs pour debug
|
||||
ini_set('display_errors', 1);
|
||||
ini_set('display_startup_errors', 1);
|
||||
error_reporting(E_ALL);
|
||||
|
||||
$host = "192.168.0.4";
|
||||
$dbname = "DemandeConge";
|
||||
$username = "wpuser";
|
||||
$password = "-2b/)ru5/Bi8P[7_";
|
||||
|
||||
$conn = new mysqli($host, $username, $password, $dbname);
|
||||
|
||||
if ($conn->connect_error) {
|
||||
error_log("Erreur connexion DB getPendingRequests: " . $conn->connect_error);
|
||||
echo json_encode(["success" => false, "message" => "Erreur de connexion à la base de données"]);
|
||||
exit();
|
||||
}
|
||||
|
||||
$managerId = $_GET['manager_id'] ?? null;
|
||||
|
||||
if ($managerId === null) {
|
||||
echo json_encode(["success" => false, "message" => "ID manager manquant"]);
|
||||
exit();
|
||||
}
|
||||
|
||||
error_log("getPendingRequests - Manager ID: $managerId");
|
||||
|
||||
// Fonction pour calculer les jours ouvrés
|
||||
function getWorkingDays($startDate, $endDate) {
|
||||
$workingDays = 0;
|
||||
$current = new DateTime($startDate);
|
||||
$end = new DateTime($endDate);
|
||||
|
||||
while ($current <= $end) {
|
||||
$dayOfWeek = (int)$current->format('N');
|
||||
if ($dayOfWeek < 6) {
|
||||
$workingDays++;
|
||||
}
|
||||
$current->modify('+1 day');
|
||||
}
|
||||
return $workingDays;
|
||||
}
|
||||
|
||||
try {
|
||||
// Récupérer le service du manager
|
||||
$queryManagerService = "SELECT ServiceId FROM Users WHERE ID = ?";
|
||||
$stmtManager = $conn->prepare($queryManagerService);
|
||||
$stmtManager->bind_param("i", $managerId);
|
||||
$stmtManager->execute();
|
||||
$resultManager = $stmtManager->get_result();
|
||||
|
||||
if ($managerRow = $resultManager->fetch_assoc()) {
|
||||
$serviceId = $managerRow['ServiceId'];
|
||||
error_log("getPendingRequests - Service ID du manager: $serviceId");
|
||||
|
||||
// Récupérer les demandes en attente (multi-types)
|
||||
$queryRequests = "
|
||||
SELECT
|
||||
dc.Id,
|
||||
dc.DateDebut,
|
||||
dc.DateFin,
|
||||
dc.Statut,
|
||||
dc.DateDemande,
|
||||
dc.Commentaire,
|
||||
dc.EmployeeId,
|
||||
CONCAT(u.Prenom, ' ', u.Nom) as employee_name,
|
||||
u.Email as employee_email,
|
||||
GROUP_CONCAT(tc.Nom ORDER BY tc.Nom SEPARATOR ', ') as types
|
||||
FROM DemandeConge dc
|
||||
JOIN Users u ON dc.EmployeeId = u.ID
|
||||
JOIN TypeConge tc ON FIND_IN_SET(tc.Id, dc.TypeCongeId)
|
||||
WHERE u.ServiceId = ?
|
||||
AND dc.Statut = 'En attente'
|
||||
AND u.ID != ?
|
||||
GROUP BY
|
||||
dc.Id, dc.DateDebut, dc.DateFin, dc.Statut, dc.DateDemande,
|
||||
dc.Commentaire, dc.EmployeeId, u.Prenom, u.Nom, u.Email
|
||||
ORDER BY dc.DateDemande ASC
|
||||
";
|
||||
|
||||
$stmtRequests = $conn->prepare($queryRequests);
|
||||
$stmtRequests->bind_param("ii", $serviceId, $managerId);
|
||||
$stmtRequests->execute();
|
||||
$resultRequests = $stmtRequests->get_result();
|
||||
|
||||
$requests = [];
|
||||
while ($row = $resultRequests->fetch_assoc()) {
|
||||
$workingDays = getWorkingDays($row['DateDebut'], $row['DateFin']);
|
||||
|
||||
$startDate = new DateTime($row['DateDebut']);
|
||||
$endDate = new DateTime($row['DateFin']);
|
||||
$submittedDate = new DateTime($row['DateDemande']);
|
||||
|
||||
if ($row['DateDebut'] === $row['DateFin']) {
|
||||
$dateDisplay = $startDate->format('d/m/Y');
|
||||
} else {
|
||||
$dateDisplay = $startDate->format('d/m/Y') . ' - ' . $endDate->format('d/m/Y');
|
||||
}
|
||||
|
||||
$requests[] = [
|
||||
'id' => (int)$row['Id'],
|
||||
'employee_id' => (int)$row['EmployeeId'],
|
||||
'employee_name' => $row['employee_name'],
|
||||
'employee_email' => $row['employee_email'],
|
||||
'type' => $row['types'], // ex: "Congé payé, RTT"
|
||||
'start_date' => $row['DateDebut'],
|
||||
'end_date' => $row['DateFin'],
|
||||
'date_display' => $dateDisplay,
|
||||
'days' => $workingDays,
|
||||
'status' => $row['Statut'],
|
||||
'reason' => $row['Commentaire'] ?: '',
|
||||
'submitted_at' => $row['DateDemande'],
|
||||
'submitted_display' => $submittedDate->format('d/m/Y')
|
||||
];
|
||||
}
|
||||
|
||||
error_log("getPendingRequests - Demandes en attente trouvées: " . count($requests));
|
||||
|
||||
echo json_encode([
|
||||
"success" => true,
|
||||
"message" => "Demandes en attente récupérées avec succès",
|
||||
"requests" => $requests,
|
||||
"service_id" => $serviceId
|
||||
]);
|
||||
|
||||
$stmtRequests->close();
|
||||
} else {
|
||||
error_log("getPendingRequests - Manager non trouvé: $managerId");
|
||||
echo json_encode([
|
||||
"success" => false,
|
||||
"message" => "Manager non trouvé"
|
||||
]);
|
||||
}
|
||||
|
||||
$stmtManager->close();
|
||||
|
||||
} catch (Exception $e) {
|
||||
error_log("Erreur getPendingRequests: " . $e->getMessage());
|
||||
echo json_encode([
|
||||
"success" => false,
|
||||
"message" => "Erreur lors de la récupération des demandes: " . $e->getMessage()
|
||||
]);
|
||||
}
|
||||
|
||||
$conn->close();
|
||||
?>
|
||||
133
project/public/php/getRequests.php
Normal file
133
project/public/php/getRequests.php
Normal file
@@ -0,0 +1,133 @@
|
||||
<?php
|
||||
// En-têtes CORS et JSON
|
||||
header("Access-Control-Allow-Origin: *");
|
||||
header("Access-Control-Allow-Methods: GET, OPTIONS");
|
||||
header("Access-Control-Allow-Headers: Content-Type");
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] == 'OPTIONS') {
|
||||
http_response_code(200);
|
||||
exit();
|
||||
}
|
||||
|
||||
header("Content-Type: application/json; charset=utf-8");
|
||||
|
||||
// Affichage des erreurs PHP (utile en dev)
|
||||
ini_set('display_errors', 1);
|
||||
ini_set('display_startup_errors', 1);
|
||||
error_reporting(E_ALL);
|
||||
|
||||
// Connexion BDD
|
||||
$host = "192.168.0.4";
|
||||
$dbname = "DemandeConge";
|
||||
$username = "wpuser";
|
||||
$password = "-2b/)ru5/Bi8P[7_";
|
||||
|
||||
$conn = new mysqli($host, $username, $password, $dbname);
|
||||
if ($conn->connect_error) {
|
||||
echo json_encode(["success" => false, "message" => "Erreur connexion DB: " . $conn->connect_error]);
|
||||
exit();
|
||||
}
|
||||
|
||||
// Récup paramètre
|
||||
$userId = $_GET['user_id'] ?? null;
|
||||
if (!$userId) {
|
||||
echo json_encode(["success" => false, "message" => "ID utilisateur manquant"]);
|
||||
exit();
|
||||
}
|
||||
|
||||
// Fonction jours ouvrés
|
||||
function getWorkingDays($startDate, $endDate) {
|
||||
$workingDays = 0;
|
||||
$current = new DateTime($startDate);
|
||||
$end = new DateTime($endDate);
|
||||
while ($current <= $end) {
|
||||
$dayOfWeek = (int)$current->format('N');
|
||||
if ($dayOfWeek < 6) {
|
||||
$workingDays++;
|
||||
}
|
||||
$current->modify('+1 day');
|
||||
}
|
||||
return $workingDays;
|
||||
}
|
||||
|
||||
try {
|
||||
// Requête multi-types
|
||||
$query = "
|
||||
SELECT
|
||||
dc.Id,
|
||||
dc.DateDebut,
|
||||
dc.DateFin,
|
||||
dc.Statut,
|
||||
dc.DateDemande,
|
||||
dc.Commentaire,
|
||||
dc.Validateur,
|
||||
dc.DocumentJoint,
|
||||
GROUP_CONCAT(tc.Nom ORDER BY tc.Nom SEPARATOR ', ') AS TypeConges
|
||||
FROM DemandeConge dc
|
||||
JOIN TypeConge tc ON FIND_IN_SET(tc.Id, dc.TypeCongeId)
|
||||
WHERE dc.EmployeeId = ?
|
||||
GROUP BY
|
||||
dc.Id, dc.DateDebut, dc.DateFin, dc.Statut, dc.DateDemande,
|
||||
dc.Commentaire, dc.Validateur, dc.DocumentJoint
|
||||
ORDER BY dc.DateDemande DESC
|
||||
";
|
||||
|
||||
$stmt = $conn->prepare($query);
|
||||
if (!$stmt) {
|
||||
throw new Exception("Erreur préparation SQL : " . $conn->error);
|
||||
}
|
||||
|
||||
$stmt->bind_param("i", $userId);
|
||||
$stmt->execute();
|
||||
$result = $stmt->get_result();
|
||||
|
||||
$requests = [];
|
||||
while ($row = $result->fetch_assoc()) {
|
||||
$workingDays = getWorkingDays($row['DateDebut'], $row['DateFin']);
|
||||
|
||||
// Format dates
|
||||
$startDate = new DateTime($row['DateDebut']);
|
||||
$endDate = new DateTime($row['DateFin']);
|
||||
$submittedDate = new DateTime($row['DateDemande']);
|
||||
|
||||
$dateDisplay = ($row['DateDebut'] === $row['DateFin'])
|
||||
? $startDate->format('d/m/Y')
|
||||
: $startDate->format('d/m/Y') . ' - ' . $endDate->format('d/m/Y');
|
||||
|
||||
// Lien fichier si congé maladie
|
||||
$fileUrl = null;
|
||||
if (strpos($row['TypeConges'], 'Congé maladie') !== false && !empty($row['DocumentJoint'])) {
|
||||
$fileUrl = 'http://localhost/GTA/project/uploads/' . basename($row['DocumentJoint']);
|
||||
}
|
||||
|
||||
$requests[] = [
|
||||
'id' => (int)$row['Id'],
|
||||
'type' => $row['TypeConges'], // ex: "Congé payé, RTT"
|
||||
'startDate' => $row['DateDebut'],
|
||||
'endDate' => $row['DateFin'],
|
||||
'dateDisplay' => $dateDisplay,
|
||||
'days' => $workingDays,
|
||||
'status' => $row['Statut'],
|
||||
'reason' => $row['Commentaire'] ?: 'Aucun commentaire',
|
||||
'submittedAt' => $row['DateDemande'],
|
||||
'submittedDisplay' => $submittedDate->format('d/m/Y'),
|
||||
'validator' => $row['Validateur'] ?: null,
|
||||
'fileUrl' => $fileUrl
|
||||
];
|
||||
}
|
||||
|
||||
echo json_encode([
|
||||
"success" => true,
|
||||
"message" => "Demandes récupérées avec succès",
|
||||
"requests" => $requests,
|
||||
"total" => count($requests)
|
||||
]);
|
||||
|
||||
} catch (Exception $e) {
|
||||
echo json_encode([
|
||||
"success" => false,
|
||||
"message" => "Erreur: " . $e->getMessage()
|
||||
]);
|
||||
}
|
||||
|
||||
$conn->close();
|
||||
115
project/public/php/getTeamLeaves.php
Normal file
115
project/public/php/getTeamLeaves.php
Normal file
@@ -0,0 +1,115 @@
|
||||
<?php
|
||||
// Récupération des congés de l'équipe pour affichage dans le calendrier
|
||||
header("Access-Control-Allow-Origin: *");
|
||||
header("Access-Control-Allow-Methods: GET, OPTIONS");
|
||||
header("Access-Control-Allow-Headers: Content-Type");
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] == 'OPTIONS') {
|
||||
http_response_code(200);
|
||||
exit();
|
||||
}
|
||||
|
||||
header("Content-Type: application/json");
|
||||
|
||||
// Log des erreurs pour debug
|
||||
ini_set('display_errors', 1);
|
||||
ini_set('display_startup_errors', 1);
|
||||
error_reporting(E_ALL);
|
||||
|
||||
$host = "192.168.0.4";
|
||||
$dbname = "DemandeConge";
|
||||
$username = "wpuser";
|
||||
$password = "-2b/)ru5/Bi8P[7_";
|
||||
|
||||
$conn = new mysqli($host, $username, $password, $dbname);
|
||||
|
||||
if ($conn->connect_error) {
|
||||
error_log("Erreur connexion DB getTeamLeaves: " . $conn->connect_error);
|
||||
echo json_encode(["success" => false, "message" => "Erreur de connexion à la base de données"]);
|
||||
exit();
|
||||
}
|
||||
|
||||
$userId = $_GET['user_id'] ?? null;
|
||||
|
||||
if ($userId === null) {
|
||||
echo json_encode(["success" => false, "message" => "ID utilisateur manquant"]);
|
||||
exit();
|
||||
}
|
||||
|
||||
error_log("getTeamLeaves - User ID: $userId");
|
||||
|
||||
try {
|
||||
// Récupérer le service de l'utilisateur
|
||||
$queryUserService = "SELECT ServiceId FROM Users WHERE ID = ?";
|
||||
$stmtUser = $conn->prepare($queryUserService);
|
||||
$stmtUser->bind_param("i", $userId);
|
||||
$stmtUser->execute();
|
||||
$resultUser = $stmtUser->get_result();
|
||||
|
||||
if ($userRow = $resultUser->fetch_assoc()) {
|
||||
$serviceId = $userRow['ServiceId'];
|
||||
error_log("getTeamLeaves - Service ID: $serviceId");
|
||||
|
||||
// Récupérer les congés validés de l'équipe (même service)
|
||||
$queryLeaves = "
|
||||
SELECT
|
||||
dc.DateDebut as start_date,
|
||||
dc.DateFin as end_date,
|
||||
CONCAT(u.Prenom, ' ', u.Nom) as employee_name,
|
||||
tc.Nom as type,
|
||||
tc.CouleurHex as color
|
||||
FROM DemandeConge dc
|
||||
JOIN Users u ON dc.EmployeeId = u.ID
|
||||
JOIN TypeConge tc ON dc.TypeCongeId = tc.Id
|
||||
WHERE u.ServiceId = ?
|
||||
AND dc.Statut = 'Validée'
|
||||
AND dc.DateFin >= CURDATE() - INTERVAL 30 DAY
|
||||
ORDER BY dc.DateDebut ASC
|
||||
";
|
||||
|
||||
$stmtLeaves = $conn->prepare($queryLeaves);
|
||||
$stmtLeaves->bind_param("i", $serviceId);
|
||||
$stmtLeaves->execute();
|
||||
$resultLeaves = $stmtLeaves->get_result();
|
||||
|
||||
$leaves = [];
|
||||
while ($row = $resultLeaves->fetch_assoc()) {
|
||||
$leaves[] = [
|
||||
'start_date' => $row['start_date'],
|
||||
'end_date' => $row['end_date'],
|
||||
'employee_name' => $row['employee_name'],
|
||||
'type' => $row['type'],
|
||||
'color' => $row['color'] ?? '#3B82F6'
|
||||
];
|
||||
}
|
||||
|
||||
error_log("getTeamLeaves - Congés trouvés: " . count($leaves));
|
||||
|
||||
echo json_encode([
|
||||
"success" => true,
|
||||
"message" => "Congés de l'équipe récupérés avec succès",
|
||||
"leaves" => $leaves,
|
||||
"service_id" => $serviceId
|
||||
]);
|
||||
|
||||
$stmtLeaves->close();
|
||||
} else {
|
||||
error_log("getTeamLeaves - Utilisateur non trouvé: $userId");
|
||||
echo json_encode([
|
||||
"success" => false,
|
||||
"message" => "Utilisateur non trouvé"
|
||||
]);
|
||||
}
|
||||
|
||||
$stmtUser->close();
|
||||
|
||||
} catch (Exception $e) {
|
||||
error_log("Erreur getTeamLeaves: " . $e->getMessage());
|
||||
echo json_encode([
|
||||
"success" => false,
|
||||
"message" => "Erreur lors de la récupération des congés: " . $e->getMessage()
|
||||
]);
|
||||
}
|
||||
|
||||
$conn->close();
|
||||
?>
|
||||
116
project/public/php/getTeamMembers.php
Normal file
116
project/public/php/getTeamMembers.php
Normal file
@@ -0,0 +1,116 @@
|
||||
<?php
|
||||
// Récupération des membres de l'équipe pour un manager
|
||||
header("Access-Control-Allow-Origin: *");
|
||||
header("Access-Control-Allow-Methods: GET, OPTIONS");
|
||||
header("Access-Control-Allow-Headers: Content-Type");
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] == 'OPTIONS') {
|
||||
http_response_code(200);
|
||||
exit();
|
||||
}
|
||||
|
||||
header("Content-Type: application/json");
|
||||
|
||||
// Log des erreurs pour debug
|
||||
ini_set('display_errors', 1);
|
||||
ini_set('display_startup_errors', 1);
|
||||
error_reporting(E_ALL);
|
||||
|
||||
$host = "192.168.0.4";
|
||||
$dbname = "DemandeConge";
|
||||
$username = "wpuser";
|
||||
$password = "-2b/)ru5/Bi8P[7_";
|
||||
|
||||
$conn = new mysqli($host, $username, $password, $dbname);
|
||||
|
||||
if ($conn->connect_error) {
|
||||
error_log("Erreur connexion DB getTeamMembers: " . $conn->connect_error);
|
||||
echo json_encode(["success" => false, "message" => "Erreur de connexion à la base de données"]);
|
||||
exit();
|
||||
}
|
||||
|
||||
$managerId = $_GET['manager_id'] ?? null;
|
||||
|
||||
if ($managerId === null) {
|
||||
echo json_encode(["success" => false, "message" => "ID manager manquant"]);
|
||||
exit();
|
||||
}
|
||||
|
||||
error_log("getTeamMembers - Manager ID: $managerId");
|
||||
|
||||
try {
|
||||
// D'abord, récupérer le service du manager
|
||||
$queryManagerService = "SELECT ServiceId FROM Users WHERE ID = ?";
|
||||
$stmtManager = $conn->prepare($queryManagerService);
|
||||
$stmtManager->bind_param("i", $managerId);
|
||||
$stmtManager->execute();
|
||||
$resultManager = $stmtManager->get_result();
|
||||
|
||||
if ($managerRow = $resultManager->fetch_assoc()) {
|
||||
$serviceId = $managerRow['ServiceId'];
|
||||
error_log("getTeamMembers - Service ID du manager: $serviceId");
|
||||
|
||||
// Récupérer tous les membres du même service (sauf le manager lui-même)
|
||||
$queryTeam = "
|
||||
SELECT
|
||||
u.ID as id,
|
||||
u.Nom as nom,
|
||||
u.Prenom as prenom,
|
||||
u.Email as email,
|
||||
u.Role as role,
|
||||
u.DateEmbauche as date_embauche,
|
||||
s.Nom as service_name
|
||||
FROM Users u
|
||||
JOIN Services s ON u.ServiceId = s.Id
|
||||
WHERE u.ServiceId = ? AND u.ID != ? AND u.Actif = 1
|
||||
ORDER BY u.Prenom, u.Nom
|
||||
";
|
||||
|
||||
$stmtTeam = $conn->prepare($queryTeam);
|
||||
$stmtTeam->bind_param("ii", $serviceId, $managerId);
|
||||
$stmtTeam->execute();
|
||||
$resultTeam = $stmtTeam->get_result();
|
||||
|
||||
$teamMembers = [];
|
||||
while ($row = $resultTeam->fetch_assoc()) {
|
||||
$teamMembers[] = [
|
||||
'id' => (int)$row['id'],
|
||||
'nom' => $row['nom'],
|
||||
'prenom' => $row['prenom'],
|
||||
'email' => $row['email'],
|
||||
'role' => $row['role'],
|
||||
'date_embauche' => $row['date_embauche'],
|
||||
'service_name' => $row['service_name']
|
||||
];
|
||||
}
|
||||
|
||||
error_log("getTeamMembers - Membres trouvés: " . count($teamMembers));
|
||||
|
||||
echo json_encode([
|
||||
"success" => true,
|
||||
"message" => "Équipe récupérée avec succès",
|
||||
"team_members" => $teamMembers,
|
||||
"service_id" => $serviceId
|
||||
]);
|
||||
|
||||
$stmtTeam->close();
|
||||
} else {
|
||||
error_log("getTeamMembers - Manager non trouvé: $managerId");
|
||||
echo json_encode([
|
||||
"success" => false,
|
||||
"message" => "Manager non trouvé"
|
||||
]);
|
||||
}
|
||||
|
||||
$stmtManager->close();
|
||||
|
||||
} catch (Exception $e) {
|
||||
error_log("Erreur getTeamMembers: " . $e->getMessage());
|
||||
echo json_encode([
|
||||
"success" => false,
|
||||
"message" => "Erreur lors de la récupération de l'équipe: " . $e->getMessage()
|
||||
]);
|
||||
}
|
||||
|
||||
$conn->close();
|
||||
?>
|
||||
74
project/public/php/login.php
Normal file
74
project/public/php/login.php
Normal file
@@ -0,0 +1,74 @@
|
||||
<?php
|
||||
header("Access-Control-Allow-Origin: *");
|
||||
header("Access-Control-Allow-Methods: POST, OPTIONS");
|
||||
header("Access-Control-Allow-Headers: Content-Type");
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] == 'OPTIONS') {
|
||||
http_response_code(200);
|
||||
exit();
|
||||
}
|
||||
|
||||
header("Content-Type: application/json");
|
||||
|
||||
$host = "192.168.0.4";
|
||||
$dbname = "DemandeConge";
|
||||
$username = "wpuser";
|
||||
$password = "-2b/)ru5/Bi8P[7_";
|
||||
|
||||
$conn = new mysqli($host, $username, $password, $dbname);
|
||||
|
||||
if ($conn->connect_error) {
|
||||
die(json_encode(["success" => false, "message" => "Erreur de connexion à la base de données : " . $conn->connect_error]));
|
||||
}
|
||||
|
||||
$data = json_decode(file_get_contents('php://input'), true);
|
||||
$email = $data['email'] ?? '';
|
||||
$mot_de_passe = $data['mot_de_passe'] ?? '';
|
||||
|
||||
$query = "
|
||||
SELECT
|
||||
u.ID,
|
||||
u.Prenom,
|
||||
u.Nom,
|
||||
u.Email,
|
||||
u.Role,
|
||||
u.ServiceId,
|
||||
s.Nom AS ServiceNom
|
||||
FROM Users u
|
||||
LEFT JOIN Services s ON u.ServiceId = s.Id
|
||||
WHERE u.Email = ? AND u.MDP = ?
|
||||
";
|
||||
|
||||
$stmt = $conn->prepare($query);
|
||||
|
||||
if ($stmt === false) {
|
||||
die(json_encode(["success" => false, "message" => "Erreur de préparation de la requête : " . $conn->error]));
|
||||
}
|
||||
|
||||
$stmt->bind_param("ss", $email, $mot_de_passe);
|
||||
$stmt->execute();
|
||||
|
||||
$result = $stmt->get_result();
|
||||
|
||||
if ($result->num_rows === 1) {
|
||||
$user = $result->fetch_assoc();
|
||||
|
||||
echo json_encode([
|
||||
"success" => true,
|
||||
"message" => "Connexion réussie.",
|
||||
"user" => [
|
||||
"id" => $user['ID'],
|
||||
"prenom" => $user['Prenom'],
|
||||
"nom" => $user['Nom'],
|
||||
"email" => $user['Email'],
|
||||
"role" => $user['Role'],
|
||||
"service" => $user['ServiceNom'] ?? 'Non défini'
|
||||
]
|
||||
]);
|
||||
} else {
|
||||
echo json_encode(["success" => false, "message" => "Identifiants incorrects."]);
|
||||
}
|
||||
|
||||
$stmt->close();
|
||||
$conn->close();
|
||||
?>
|
||||
116
project/public/php/manualResetCounters.php
Normal file
116
project/public/php/manualResetCounters.php
Normal file
@@ -0,0 +1,116 @@
|
||||
<?php
|
||||
// Script manuel pour réinitialiser les compteurs
|
||||
// Accès direct via navigateur pour les administrateurs
|
||||
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<html lang="fr">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Réinitialisation des Compteurs</title>
|
||||
<style>
|
||||
body { font-family: Arial, sans-serif; max-width: 800px; margin: 50px auto; padding: 20px; }
|
||||
.container { background: #f5f5f5; padding: 30px; border-radius: 10px; }
|
||||
.warning { background: #fff3cd; border: 1px solid #ffeaa7; padding: 15px; border-radius: 5px; margin: 20px 0; }
|
||||
.success { background: #d4edda; border: 1px solid #c3e6cb; padding: 15px; border-radius: 5px; margin: 20px 0; }
|
||||
.error { background: #f8d7da; border: 1px solid #f5c6cb; padding: 15px; border-radius: 5px; margin: 20px 0; }
|
||||
button { background: #007bff; color: white; padding: 12px 24px; border: none; border-radius: 5px; cursor: pointer; font-size: 16px; }
|
||||
button:hover { background: #0056b3; }
|
||||
.danger { background: #dc3545; }
|
||||
.danger:hover { background: #c82333; }
|
||||
pre { background: #f8f9fa; padding: 15px; border-radius: 5px; overflow-x: auto; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
<h1>🔄 Réinitialisation des Compteurs de Congés</h1>
|
||||
|
||||
<div class="warning">
|
||||
<h3>⚠️ ATTENTION</h3>
|
||||
<p>Cette opération va réinitialiser TOUS les compteurs de congés selon les règles suivantes :</p>
|
||||
<ul>
|
||||
<li><strong>Congés Payés :</strong> 25 jours (exercice du 01/06 au 31/05)</li>
|
||||
<li><strong>RTT :</strong> 10 jours pour 2025 (exercice du 01/01 au 31/12)</li>
|
||||
<li><strong>Congés Maladie :</strong> 0 jours (remise à zéro)</li>
|
||||
</ul>
|
||||
<p><strong>Cette action est irréversible !</strong></p>
|
||||
</div>
|
||||
|
||||
<?php
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['confirm_reset'])) {
|
||||
// Appel du script de réinitialisation
|
||||
$resetUrl = 'http://localhost/project/public/resetLeaveCounters.php';
|
||||
|
||||
$context = stream_context_create([
|
||||
'http' => [
|
||||
'method' => 'POST',
|
||||
'header' => 'Content-Type: application/json',
|
||||
'content' => json_encode(['manual_reset' => true])
|
||||
]
|
||||
]);
|
||||
|
||||
$result = file_get_contents($resetUrl, false, $context);
|
||||
$data = json_decode($result, true);
|
||||
|
||||
if ($data && $data['success']) {
|
||||
echo '<div class="success">';
|
||||
echo '<h3>✅ Réinitialisation réussie !</h3>';
|
||||
echo '<p>Employés mis à jour : ' . $data['details']['employees_updated'] . '</p>';
|
||||
echo '<p>Exercice CP : ' . $data['details']['leave_year'] . '</p>';
|
||||
echo '<p>Année RTT : ' . $data['details']['rtt_year'] . '</p>';
|
||||
echo '<p>Date de réinitialisation : ' . $data['details']['reset_date'] . '</p>';
|
||||
|
||||
if (!empty($data['log'])) {
|
||||
echo '<details><summary>Voir le détail</summary><pre>';
|
||||
foreach ($data['log'] as $logLine) {
|
||||
echo htmlspecialchars($logLine) . "\n";
|
||||
}
|
||||
echo '</pre></details>';
|
||||
}
|
||||
echo '</div>';
|
||||
} else {
|
||||
echo '<div class="error">';
|
||||
echo '<h3>❌ Erreur lors de la réinitialisation</h3>';
|
||||
echo '<p>' . ($data['message'] ?? 'Erreur inconnue') . '</p>';
|
||||
echo '</div>';
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
<form method="POST" onsubmit="return confirm('Êtes-vous sûr de vouloir réinitialiser TOUS les compteurs ? Cette action est irréversible.');">
|
||||
<p>
|
||||
<label>
|
||||
<input type="checkbox" name="confirm_reset" value="1" required>
|
||||
Je confirme vouloir réinitialiser tous les compteurs de congés
|
||||
</label>
|
||||
</p>
|
||||
<button type="submit" class="danger">🔄 RÉINITIALISER LES COMPTEURS</button>
|
||||
</form>
|
||||
|
||||
<hr style="margin: 40px 0;">
|
||||
|
||||
<h3>📋 Informations sur les exercices</h3>
|
||||
<?php
|
||||
$currentDate = new DateTime();
|
||||
$currentYear = (int)$currentDate->format('Y');
|
||||
$currentMonth = (int)$currentDate->format('m');
|
||||
|
||||
// Calcul exercice CP
|
||||
$leaveYear = ($currentMonth < 6) ? $currentYear - 1 : $currentYear;
|
||||
$leaveYearEnd = $leaveYear + 1;
|
||||
|
||||
echo "<p><strong>Exercice Congés Payés actuel :</strong> du 01/06/$leaveYear au 31/05/$leaveYearEnd</p>";
|
||||
echo "<p><strong>Exercice RTT actuel :</strong> du 01/01/$currentYear au 31/12/$currentYear</p>";
|
||||
echo "<p><strong>Date actuelle :</strong> " . $currentDate->format('d/m/Y H:i:s') . "</p>";
|
||||
?>
|
||||
|
||||
<h3>🔗 Actions rapides</h3>
|
||||
<p>
|
||||
<a href="getLeaveCounters.php?user_id=1" target="_blank">
|
||||
<button type="button">Voir les compteurs (User ID 1)</button>
|
||||
</a>
|
||||
</p>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
228
project/public/php/resetLeaveCounters.php
Normal file
228
project/public/php/resetLeaveCounters.php
Normal file
@@ -0,0 +1,228 @@
|
||||
<?php
|
||||
// Script de réinitialisation des compteurs de congés
|
||||
// À exécuter manuellement ou via cron job
|
||||
|
||||
header("Access-Control-Allow-Origin: *");
|
||||
header("Access-Control-Allow-Methods: POST, OPTIONS");
|
||||
header("Access-Control-Allow-Headers: Content-Type");
|
||||
header("Content-Type: application/json");
|
||||
|
||||
// Gère la requête OPTIONS (pré-vol CORS)
|
||||
if ($_SERVER['REQUEST_METHOD'] == 'OPTIONS') {
|
||||
http_response_code(200);
|
||||
exit();
|
||||
}
|
||||
|
||||
// Log des erreurs pour debug
|
||||
ini_set('display_errors', 1);
|
||||
ini_set('display_startup_errors', 1);
|
||||
error_reporting(E_ALL);
|
||||
|
||||
$host = "192.168.0.4";
|
||||
$dbname = "DemandeConge";
|
||||
$username = "wpuser";
|
||||
$password = "-2b/)ru5/Bi8P[7_";
|
||||
|
||||
// Connexion à la base de données
|
||||
$conn = new mysqli($host, $username, $password, $dbname);
|
||||
|
||||
if ($conn->connect_error) {
|
||||
error_log("Erreur connexion DB reset: " . $conn->connect_error);
|
||||
echo json_encode([
|
||||
"success" => false,
|
||||
"message" => "Erreur de connexion à la base de données : " . $conn->connect_error
|
||||
]);
|
||||
exit();
|
||||
}
|
||||
|
||||
// Log de debug
|
||||
error_log("Reset counters - Début du script");
|
||||
|
||||
// Fonction pour déterminer l'exercice des congés payés (01/06 au 31/05)
|
||||
function getLeaveYear($date = null) {
|
||||
if ($date === null) {
|
||||
$date = new DateTime();
|
||||
} else {
|
||||
$date = new DateTime($date);
|
||||
}
|
||||
|
||||
$currentYear = (int)$date->format('Y');
|
||||
$currentMonth = (int)$date->format('m');
|
||||
|
||||
// Si on est avant le 1er juin, l'exercice a commencé l'année précédente
|
||||
if ($currentMonth < 6) {
|
||||
return $currentYear - 1;
|
||||
}
|
||||
// Si on est le 1er juin ou après, l'exercice a commencé cette année
|
||||
return $currentYear;
|
||||
}
|
||||
|
||||
// Fonction pour déterminer l'année RTT (01/01 au 31/12)
|
||||
function getRTTYear($date = null) {
|
||||
if ($date === null) {
|
||||
$date = new DateTime();
|
||||
} else {
|
||||
$date = new DateTime($date);
|
||||
}
|
||||
|
||||
return (int)$date->format('Y');
|
||||
}
|
||||
|
||||
try {
|
||||
$conn->begin_transaction();
|
||||
|
||||
$currentDate = new DateTime();
|
||||
$leaveYear = getLeaveYear();
|
||||
$rttYear = getRTTYear();
|
||||
|
||||
error_log("Reset counters - Exercice CP: $leaveYear, RTT: $rttYear");
|
||||
|
||||
$resetLog = [];
|
||||
|
||||
// 1. Récupérer tous les employés depuis la table Users
|
||||
$queryEmployees = "SELECT ID FROM Users";
|
||||
$resultEmployees = $conn->query($queryEmployees);
|
||||
|
||||
if (!$resultEmployees) {
|
||||
throw new Exception("Erreur lors de la récupération des employés : " . $conn->error);
|
||||
}
|
||||
|
||||
error_log("Reset counters - Nombre d'employés trouvés: " . $resultEmployees->num_rows);
|
||||
|
||||
// 2. Récupérer les IDs des types de congés
|
||||
$queryTypes = "SELECT Id, Nom FROM TypeConge WHERE Nom IN ('Congé payé', 'RTT', 'Congé maladie')";
|
||||
$resultTypes = $conn->query($queryTypes);
|
||||
|
||||
$typeIds = [];
|
||||
while ($row = $resultTypes->fetch_assoc()) {
|
||||
$typeIds[$row['Nom']] = $row['Id'];
|
||||
}
|
||||
|
||||
error_log("Reset counters - Types trouvés: " . print_r($typeIds, true));
|
||||
|
||||
if (count($typeIds) < 3) {
|
||||
throw new Exception("Types de congés manquants dans la base de données");
|
||||
}
|
||||
|
||||
// 3. Pour chaque employé, réinitialiser les compteurs
|
||||
$employeesUpdated = 0;
|
||||
while ($employee = $resultEmployees->fetch_assoc()) {
|
||||
$employeeId = $employee['ID'];
|
||||
|
||||
error_log("Reset counters - Traitement employé: $employeeId");
|
||||
|
||||
// CONGÉS PAYÉS - Exercice du 01/06 au 31/05 (25 jours)
|
||||
$queryUpdateCP = "
|
||||
INSERT INTO CompteurConges (EmployeeId, TypeCongeId, Annee, Solde, Total)
|
||||
VALUES (?, ?, ?, 25, 25)
|
||||
ON DUPLICATE KEY UPDATE
|
||||
Solde = 25,
|
||||
Total = 25
|
||||
";
|
||||
$stmtCP = $conn->prepare($queryUpdateCP);
|
||||
if (!$stmtCP) {
|
||||
throw new Exception("Erreur préparation CP: " . $conn->error);
|
||||
}
|
||||
$stmtCP->bind_param("iii", $employeeId, $typeIds['Congé payé'], $leaveYear);
|
||||
|
||||
if (!$stmtCP->execute()) {
|
||||
throw new Exception("Erreur lors de la mise à jour des CP pour l'employé $employeeId : " . $stmtCP->error);
|
||||
}
|
||||
$stmtCP->close();
|
||||
|
||||
// RTT - Année civile du 01/01 au 31/12
|
||||
// Calcul du nombre de RTT selon l'année
|
||||
$rttCount = 10; // Par défaut 10 pour 2025
|
||||
if ($rttYear == 2024) {
|
||||
$rttCount = 8; // Exemple pour 2024
|
||||
} elseif ($rttYear >= 2025) {
|
||||
$rttCount = 10; // 10 pour 2025 et après
|
||||
}
|
||||
|
||||
$queryUpdateRTT = "
|
||||
INSERT INTO CompteurConges (EmployeeId, TypeCongeId, Annee, Solde, Total)
|
||||
VALUES (?, ?, ?, ?, ?)
|
||||
ON DUPLICATE KEY UPDATE
|
||||
Solde = ?,
|
||||
Total = ?
|
||||
";
|
||||
$stmtRTT = $conn->prepare($queryUpdateRTT);
|
||||
if (!$stmtRTT) {
|
||||
throw new Exception("Erreur préparation RTT: " . $conn->error);
|
||||
}
|
||||
$stmtRTT->bind_param("iiiiiii", $employeeId, $typeIds['RTT'], $rttYear, $rttCount, $rttCount, $rttCount, $rttCount);
|
||||
|
||||
if (!$stmtRTT->execute()) {
|
||||
throw new Exception("Erreur lors de la mise à jour des RTT pour l'employé $employeeId : " . $stmtRTT->error);
|
||||
}
|
||||
$stmtRTT->close();
|
||||
|
||||
// CONGÉ MALADIE - Réinitialiser à 0 (pas de limite)
|
||||
$queryUpdateABS = "
|
||||
INSERT INTO CompteurConges (EmployeeId, TypeCongeId, Annee, Solde, Total)
|
||||
VALUES (?, ?, ?, 0, 0)
|
||||
ON DUPLICATE KEY UPDATE
|
||||
Solde = 0,
|
||||
Total = 0
|
||||
";
|
||||
$stmtABS = $conn->prepare($queryUpdateABS);
|
||||
if (!$stmtABS) {
|
||||
throw new Exception("Erreur préparation ABS: " . $conn->error);
|
||||
}
|
||||
$stmtABS->bind_param("iii", $employeeId, $typeIds['Congé maladie'], $rttYear);
|
||||
|
||||
if (!$stmtABS->execute()) {
|
||||
throw new Exception("Erreur lors de la mise à jour des ABS pour l'employé $employeeId : " . $stmtABS->error);
|
||||
}
|
||||
$stmtABS->close();
|
||||
|
||||
$resetLog[] = "Employé $employeeId : CP=$leaveYear (25j), RTT=$rttYear ({$rttCount}j), ABS=$rttYear (0j)";
|
||||
$employeesUpdated++;
|
||||
}
|
||||
|
||||
error_log("Reset counters - Employés mis à jour: $employeesUpdated");
|
||||
|
||||
// 4. Log de la réinitialisation
|
||||
$logEntry = "
|
||||
=== RÉINITIALISATION DES COMPTEURS ===
|
||||
Date: " . $currentDate->format('Y-m-d H:i:s') . "
|
||||
Exercice CP: $leaveYear (01/06/$leaveYear au 31/05/" . ($leaveYear + 1) . ")
|
||||
Année RTT: $rttYear (01/01/$rttYear au 31/12/$rttYear)
|
||||
Employés traités: $employeesUpdated
|
||||
|
||||
Détails:
|
||||
" . implode("\n ", $resetLog) . "
|
||||
";
|
||||
|
||||
// Sauvegarder le log (optionnel - créer une table de logs si nécessaire)
|
||||
error_log($logEntry, 3, "reset_counters.log");
|
||||
|
||||
$conn->commit();
|
||||
error_log("Reset counters - Transaction commitée avec succès");
|
||||
|
||||
echo json_encode([
|
||||
"success" => true,
|
||||
"message" => "Compteurs réinitialisés avec succès",
|
||||
"details" => [
|
||||
"employees_updated" => $employeesUpdated,
|
||||
"leave_year" => $leaveYear,
|
||||
"rtt_year" => $rttYear,
|
||||
"cp_days" => 25,
|
||||
"rtt_days" => $rttCount,
|
||||
"reset_date" => $currentDate->format('Y-m-d H:i:s')
|
||||
],
|
||||
"log" => $resetLog
|
||||
]);
|
||||
|
||||
} catch (Exception $e) {
|
||||
$conn->rollback();
|
||||
error_log("Erreur réinitialisation compteurs : " . $e->getMessage());
|
||||
|
||||
echo json_encode([
|
||||
"success" => false,
|
||||
"message" => "Erreur lors de la réinitialisation : " . $e->getMessage()
|
||||
]);
|
||||
}
|
||||
|
||||
$conn->close();
|
||||
?>
|
||||
100
project/public/php/submitLeaveRequest.php
Normal file
100
project/public/php/submitLeaveRequest.php
Normal file
@@ -0,0 +1,100 @@
|
||||
<?php
|
||||
// (headers, connexion, lecture FormData ou JSON — pareil que précédemment)
|
||||
ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL);
|
||||
header("Access-Control-Allow-Origin: *");
|
||||
header("Access-Control-Allow-Methods: POST, OPTIONS");
|
||||
header("Access-Control-Allow-Headers: Content-Type");
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'OPTIONS') { http_response_code(200); exit(); }
|
||||
header("Content-Type: application/json");
|
||||
|
||||
$host="192.168.0.4"; $dbname="DemandeConge"; $username="wpuser"; $password="-2b/)ru5/Bi8P[7_";
|
||||
$conn = new mysqli($host,$username,$password,$dbname);
|
||||
if ($conn->connect_error) { echo json_encode(["success"=>false,"message"=>"Erreur DB: ".$conn->connect_error]); exit(); }
|
||||
|
||||
// Lecture JSON (support FormData via $_POST['data'])
|
||||
if (isset($_POST['data'])) {
|
||||
$data = json_decode($_POST['data'], true);
|
||||
} else {
|
||||
$input = file_get_contents('php://input');
|
||||
$data = json_decode($input, true);
|
||||
}
|
||||
if ($data === null) {
|
||||
echo json_encode(["success"=>false,"message"=>"JSON invalide"]); $conn->close(); exit();
|
||||
}
|
||||
|
||||
// Vérifs minimales
|
||||
if (!isset($data['EmployeeId'],$data['DateDebut'],$data['DateFin'],$data['Repartition'],$data['NombreJours'])) {
|
||||
echo json_encode(["success"=>false,"message"=>"Données manquantes"]); $conn->close(); exit();
|
||||
}
|
||||
|
||||
$employeeId = (int)$data['EmployeeId'];
|
||||
$dateDebut = $data['DateDebut'];
|
||||
$dateFin = $data['DateFin'];
|
||||
$commentaire= $data['Commentaire'] ?? '';
|
||||
$numDays = (float)$data['NombreJours'];
|
||||
$statut = 'En attente';
|
||||
$currentDate= date('Y-m-d H:i:s');
|
||||
|
||||
// 1) Construire la liste d'IDs pour TypeCongeId (CSV) (compatibilité)
|
||||
$typeIds = [];
|
||||
foreach ($data['Repartition'] as $rep) {
|
||||
$code = $rep['TypeConge']; // CP, RTT, ABS ou texte libre
|
||||
switch ($code) {
|
||||
case 'CP': $name = 'Congé payé'; break;
|
||||
case 'RTT': $name = 'RTT'; break;
|
||||
case 'ABS': $name = 'Congé maladie'; break;
|
||||
default: $name = $code; break;
|
||||
}
|
||||
$s = $conn->prepare("SELECT Id FROM TypeConge WHERE Nom = ?");
|
||||
$s->bind_param("s", $name);
|
||||
$s->execute();
|
||||
$res = $s->get_result();
|
||||
if ($r = $res->fetch_assoc()) $typeIds[] = $r['Id'];
|
||||
$s->close();
|
||||
}
|
||||
if (empty($typeIds)) { echo json_encode(["success"=>false,"message"=>"Aucun type valide"]); $conn->close(); exit(); }
|
||||
$typeCongeIdCsv = implode(',', $typeIds);
|
||||
|
||||
// 2) Insertion unique dans DemandeConge
|
||||
$insert = $conn->prepare("INSERT INTO DemandeConge (EmployeeId, DateDebut, DateFin, TypeCongeId, Statut, DateDemande, Commentaire, Validateur, NombreJours) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)");
|
||||
$validParam = '';
|
||||
$insert->bind_param("isssssssd", $employeeId, $dateDebut, $dateFin, $typeCongeIdCsv, $statut, $currentDate, $commentaire, $validParam, $numDays);
|
||||
if (!$insert->execute()) {
|
||||
echo json_encode(["success"=>false,"message"=>"Erreur insert DemandeConge: ".$insert->error]);
|
||||
$insert->close(); $conn->close(); exit();
|
||||
}
|
||||
$demandeId = $conn->insert_id;
|
||||
$insert->close();
|
||||
|
||||
// 3) INSÉRER la répartition réelle dans DemandeCongeType (une ligne par type)
|
||||
$insertType = $conn->prepare("INSERT INTO DemandeCongeType (DemandeCongeId, TypeCongeId, NombreJours) VALUES (?, ?, ?)");
|
||||
if (!$insertType) {
|
||||
echo json_encode(["success"=>false,"message"=>"Erreur préparation DemandeCongeType: ".$conn->error]); $conn->close(); exit();
|
||||
}
|
||||
|
||||
foreach ($data['Repartition'] as $rep) {
|
||||
$code = $rep['TypeConge'];
|
||||
$jours = (float)$rep['NombreJours'];
|
||||
|
||||
switch ($code) {
|
||||
case 'CP': $name = 'Congé payé'; break;
|
||||
case 'RTT': $name = 'RTT'; break;
|
||||
case 'ABS': $name = 'Congé maladie'; break;
|
||||
default: $name = $code; break;
|
||||
}
|
||||
$s = $conn->prepare("SELECT Id FROM TypeConge WHERE Nom = ?");
|
||||
$s->bind_param("s", $name);
|
||||
$s->execute();
|
||||
$res = $s->get_result();
|
||||
if ($r = $res->fetch_assoc()) {
|
||||
$typeId = (int)$r['Id'];
|
||||
$insertType->bind_param("iid", $demandeId, $typeId, $jours); // i,i,d
|
||||
$insertType->execute();
|
||||
}
|
||||
$s->close();
|
||||
}
|
||||
$insertType->close();
|
||||
|
||||
echo json_encode(["success"=>true,"message"=>"Demande soumise", "request_id"=>$demandeId]);
|
||||
$conn->close();
|
||||
?>
|
||||
14
project/public/php/test_db.php
Normal file
14
project/public/php/test_db.php
Normal file
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
$host = "192.168.0.4";
|
||||
$dbname = "DemandeConge";
|
||||
$username = "wpuser";
|
||||
$password = "-2b/)ru5/Bi8P[7_";
|
||||
|
||||
$conn = new mysqli($host, $username, $password, $dbname);
|
||||
|
||||
if ($conn->connect_error) {
|
||||
die("❌ Connexion échouée : " . $conn->connect_error);
|
||||
}
|
||||
echo "✅ Connexion réussie à la base de données !";
|
||||
|
||||
?>
|
||||
197
project/public/php/validateRequest.php
Normal file
197
project/public/php/validateRequest.php
Normal file
@@ -0,0 +1,197 @@
|
||||
<?php
|
||||
// Validation/Refus d'une demande de congé par un manager
|
||||
header("Access-Control-Allow-Origin: *");
|
||||
header("Access-Control-Allow-Methods: POST, OPTIONS");
|
||||
header("Access-Control-Allow-Headers: Content-Type");
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] == 'OPTIONS') {
|
||||
http_response_code(200);
|
||||
exit();
|
||||
}
|
||||
|
||||
header("Content-Type: application/json");
|
||||
|
||||
// Log des erreurs pour debug
|
||||
ini_set('display_errors', 1);
|
||||
ini_set('display_startup_errors', 1);
|
||||
error_reporting(E_ALL);
|
||||
|
||||
$host = "192.168.0.4";
|
||||
$dbname = "DemandeConge";
|
||||
$username = "wpuser";
|
||||
$password = "-2b/)ru5/Bi8P[7_";
|
||||
|
||||
$conn = new mysqli($host, $username, $password, $dbname);
|
||||
|
||||
if ($conn->connect_error) {
|
||||
error_log("Erreur connexion DB validateRequest: " . $conn->connect_error);
|
||||
echo json_encode(["success" => false, "message" => "Erreur de connexion à la base de données"]);
|
||||
exit();
|
||||
}
|
||||
|
||||
// Lecture du JSON envoyé
|
||||
$input = file_get_contents('php://input');
|
||||
error_log("validateRequest - Input reçu: " . $input);
|
||||
|
||||
$data = json_decode($input, true);
|
||||
|
||||
if (!isset($data['request_id'], $data['action'], $data['validator_id'])) {
|
||||
error_log("validateRequest - Données manquantes: " . print_r($data, true));
|
||||
echo json_encode([
|
||||
"success" => false,
|
||||
"message" => "Données manquantes pour la validation"
|
||||
]);
|
||||
exit();
|
||||
}
|
||||
|
||||
$requestId = (int)$data['request_id'];
|
||||
$action = $data['action']; // 'approve' ou 'reject'
|
||||
$validatorId = (int)$data['validator_id'];
|
||||
$comment = $data['comment'] ?? '';
|
||||
|
||||
error_log("validateRequest - Request ID: $requestId, Action: $action, Validator: $validatorId");
|
||||
|
||||
try {
|
||||
$conn->begin_transaction();
|
||||
|
||||
// Vérifier que la demande existe et est en attente
|
||||
$queryCheck = "
|
||||
SELECT dc.Id, dc.EmployeeId, dc.TypeCongeId, dc.DateDebut, dc.DateFin, dc.NombreJours,
|
||||
u.Nom, u.Prenom, tc.Nom as TypeNom
|
||||
FROM DemandeConge dc
|
||||
JOIN Users u ON dc.EmployeeId = u.ID
|
||||
JOIN TypeConge tc ON dc.TypeCongeId = tc.Id
|
||||
WHERE dc.Id = ? AND dc.Statut = 'En attente'
|
||||
";
|
||||
|
||||
$stmtCheck = $conn->prepare($queryCheck);
|
||||
$stmtCheck->bind_param("i", $requestId);
|
||||
$stmtCheck->execute();
|
||||
$resultCheck = $stmtCheck->get_result();
|
||||
|
||||
if ($requestRow = $resultCheck->fetch_assoc()) {
|
||||
$employeeId = $requestRow['EmployeeId'];
|
||||
$typeCongeId = $requestRow['TypeCongeId'];
|
||||
$nombreJours = $requestRow['NombreJours'];
|
||||
$employeeName = $requestRow['Prenom'] . ' ' . $requestRow['Nom'];
|
||||
$typeNom = $requestRow['TypeNom'];
|
||||
|
||||
error_log("validateRequest - Demande trouvée: $employeeName, Type: $typeNom, Jours: $nombreJours");
|
||||
|
||||
// Déterminer le nouveau statut
|
||||
$newStatus = ($action === 'approve') ? 'Validée' : 'Refusée';
|
||||
|
||||
// Mettre à jour la demande
|
||||
$queryUpdate = "
|
||||
UPDATE DemandeConge
|
||||
SET Statut = ?,
|
||||
ValidateurId = ?,
|
||||
DateValidation = NOW(),
|
||||
CommentaireValidation = ?
|
||||
WHERE Id = ?
|
||||
";
|
||||
|
||||
$stmtUpdate = $conn->prepare($queryUpdate);
|
||||
$stmtUpdate->bind_param("sisi", $newStatus, $validatorId, $comment, $requestId);
|
||||
|
||||
if ($stmtUpdate->execute()) {
|
||||
error_log("validateRequest - Demande mise à jour avec succès");
|
||||
|
||||
// Si approuvée, déduire du solde (sauf pour congé maladie)
|
||||
if ($action === 'approve' && $typeNom !== 'Congé maladie') {
|
||||
// Déterminer l'année selon le type de congé
|
||||
$currentDate = new DateTime();
|
||||
if ($typeNom === 'Congé payé') {
|
||||
// Exercice CP: 01/06 au 31/05
|
||||
$year = ($currentDate->format('m') < 6) ? $currentDate->format('Y') - 1 : $currentDate->format('Y');
|
||||
} else {
|
||||
// RTT: année civile
|
||||
$year = $currentDate->format('Y');
|
||||
}
|
||||
|
||||
error_log("validateRequest - Déduction solde: Type=$typeNom, Année=$year, Jours=$nombreJours");
|
||||
|
||||
// Déduire du solde
|
||||
$queryDeduct = "
|
||||
UPDATE CompteurConges
|
||||
SET Solde = GREATEST(0, Solde - ?)
|
||||
WHERE EmployeeId = ? AND TypeCongeId = ? AND Annee = ?
|
||||
";
|
||||
|
||||
$stmtDeduct = $conn->prepare($queryDeduct);
|
||||
$stmtDeduct->bind_param("diii", $nombreJours, $employeeId, $typeCongeId, $year);
|
||||
|
||||
if ($stmtDeduct->execute()) {
|
||||
error_log("validateRequest - Solde déduit avec succès");
|
||||
} else {
|
||||
error_log("validateRequest - Erreur déduction solde: " . $stmtDeduct->error);
|
||||
}
|
||||
|
||||
$stmtDeduct->close();
|
||||
}
|
||||
|
||||
// Créer une notification pour l'employé
|
||||
$notificationTitle = ($action === 'approve') ? 'Demande approuvée' : 'Demande refusée';
|
||||
$notificationMessage = "Votre demande de $typeNom a été " . (($action === 'approve') ? 'approuvée' : 'refusée');
|
||||
if ($comment) {
|
||||
$notificationMessage .= ". Commentaire: $comment";
|
||||
}
|
||||
|
||||
$queryNotif = "
|
||||
INSERT INTO Notifications (UserId, Titre, Message, Type, DemandeCongeId)
|
||||
VALUES (?, ?, ?, ?, ?)
|
||||
";
|
||||
|
||||
$notifType = ($action === 'approve') ? 'Success' : 'Error';
|
||||
$stmtNotif = $conn->prepare($queryNotif);
|
||||
$stmtNotif->bind_param("isssi", $employeeId, $notificationTitle, $notificationMessage, $notifType, $requestId);
|
||||
$stmtNotif->execute();
|
||||
$stmtNotif->close();
|
||||
|
||||
// Log dans l'historique
|
||||
$actionText = ($action === 'approve') ? 'Validation congé' : 'Refus congé';
|
||||
$actionDetails = "$actionText $employeeName ($typeNom)";
|
||||
if ($comment) {
|
||||
$actionDetails .= " - $comment";
|
||||
}
|
||||
|
||||
$queryHistory = "
|
||||
INSERT INTO HistoriqueActions (UserId, Action, Details, DemandeCongeId)
|
||||
VALUES (?, ?, ?, ?)
|
||||
";
|
||||
|
||||
$stmtHistory = $conn->prepare($queryHistory);
|
||||
$stmtHistory->bind_param("issi", $validatorId, $actionText, $actionDetails, $requestId);
|
||||
$stmtHistory->execute();
|
||||
$stmtHistory->close();
|
||||
|
||||
$conn->commit();
|
||||
|
||||
echo json_encode([
|
||||
"success" => true,
|
||||
"message" => "Demande " . (($action === 'approve') ? 'approuvée' : 'refusée') . " avec succès",
|
||||
"new_status" => $newStatus
|
||||
]);
|
||||
|
||||
} else {
|
||||
throw new Exception("Erreur lors de la mise à jour: " . $stmtUpdate->error);
|
||||
}
|
||||
|
||||
$stmtUpdate->close();
|
||||
} else {
|
||||
throw new Exception("Demande non trouvée ou déjà traitée");
|
||||
}
|
||||
|
||||
$stmtCheck->close();
|
||||
|
||||
} catch (Exception $e) {
|
||||
$conn->rollback();
|
||||
error_log("Erreur validateRequest: " . $e->getMessage());
|
||||
echo json_encode([
|
||||
"success" => false,
|
||||
"message" => "Erreur lors de la validation: " . $e->getMessage()
|
||||
]);
|
||||
}
|
||||
|
||||
$conn->close();
|
||||
?>
|
||||
Reference in New Issue
Block a user