Files
MYSOPHAL/front/payroll.period.update.php
2025-08-07 13:15:31 +01:00

214 lines
8.3 KiB
PHP

<?php
use Glpi\Event;
include ('../inc/includes.php');
Session::checkLoginUser();
if (Session::getCurrentInterface() == "helpdesk") {
Html::helpHeader("Période de paie", '', $_SESSION["glpiname"]);
} else {
Html::header("Période de paie", '', "", "");
}
$currentYear = date('Y');
$startYear = $currentYear - 1; // Start 5 years before the current year
$endYear = $currentYear + 1; // End 5 years after the current year
function get_period($id){
global $DB;
$stmt = $DB->prepare("SELECT * FROM `payroll_period` WHERE id = ? ");
$stmt->bind_param("i", $id);
$stmt->execute();
$result = $stmt->get_result();
if ($result->num_rows > 0) {
return $result->fetch_array(MYSQLI_ASSOC);
}
return null;
}
if(filter_var($_GET['id'], FILTER_VALIDATE_INT) === FALSE) Html::redirect($CFG_GLPI["root_doc"]."/front/ticket.php");
$res = get_period($_GET['id']);
if (!$res) {
Html::redirect($CFG_GLPI["root_doc"]."/front/payroll.period.list.php");
}
echo "
<div id='tabs1216654411' class='center vertical ui-tabs ui-corner-all ui-widget ui-widget-content ui-tabs-vertical ui-helper-clearfix ui-corner-left'>
<div id='ui-id-3' aria-live='polite' aria-labelledby='ui-id-2' role='tabpanel' class='ui-tabs-panel ui-corner-bottom ui-widget-content' aria-hidden='false'>
<br>
<form id='form' name='form' method='post' action='".$CFG_GLPI["root_doc"]."/ajax/payroll.period.php' enctype='multipart/form-data'>
<input type='hidden' name='id' value='".$res['id']."' />
<div class='spaced' id='tabsbody'>
<table class='tab_cadre_fixe' id='mainformtable'>
<tbody>
<tr class='headerRow'>
<th colspan='4' class='center'>Période de paie</th>
</tr>
<tr>
<td width='20%'>L'année : <span style='color:red'>*</span></td>
<td width='30%'>
<select style='width:95%;' id='year' name='year' required>
<option value='' disabled selected>-- Sélectionnez une année --</option>";
for ($year = $startYear; $year <= $endYear; $year++) {
echo "<option value='$year'"; if($res['year'] == $year) echo"selected"; echo " >$year</option>" ;
}
echo "
</select>
</td>
<td width='20%'>Mois : <span style='color:red'>*</span></td>
<td width='30%'>
<select style='width:95%;' id='month' name='month' required>
<option value='' disabled selected>-- Sélectionnez un mois --</option>
<option value='01' ".($res['month'] == '01' ? 'selected' : '').">Janvier</option>
<option value='02' ".($res['month'] == '02' ? 'selected' : '').">Février</option>
<option value='03' ".($res['month'] == '03' ? 'selected' : '').">Mars</option>
<option value='04' ".($res['month'] == '04' ? 'selected' : '').">Avril</option>
<option value='05' ".($res['month'] == '05' ? 'selected' : '').">Mai</option>
<option value='06' ".($res['month'] == '06' ? 'selected' : '').">Juin</option>
<option value='07' ".($res['month'] == '07' ? 'selected' : '').">Juillet</option>
<option value='08' ".($res['month'] == '08' ? 'selected' : '').">Août</option>
<option value='09' ".($res['month'] == '09' ? 'selected' : '').">Septembre</option>
<option value='10' ".($res['month'] == '10' ? 'selected' : '').">Octobre</option>
<option value='11' ".($res['month'] == '11' ? 'selected' : '').">Novembre</option>
<option value='12' ".($res['month'] == '12' ? 'selected' : '').">Décembre</option>
</select>
</td>
</tr>
<tr>
<td>Date début : <span style='color:red'>*</span></td>
<td>
<input style='width:95%;' id='start_date' type='date' name='start_date' value='".$res['start_date']."' required>
</td>
<td>Date fin : <span style='color:red'>*</span></td>
<td>
<input style='width:95%;' id='end_date' type='date' name='end_date' value='".$res['end_date']."' required>
</td>
</tr>
</tbody>
</table>
<div class='center' style='margin-top: 20px;'>
<button name='save' class='vsubmit' style='padding: 10px;'>Mettre à jour</button>
<a href='".$CFG_GLPI["root_doc"]."/front/payroll.period.list.php' class='vsubmit' style='margin-left: 15px; background-color: #eba696; padding: 10px; text-decoration: none;'>Annuler</a>
</div>
</div>
</form>
</div>
</div>";
if (Session::getCurrentInterface() == "helpdesk") {
Html::helpFooter();
} else {
Html::footer();
}
$link=$CFG_GLPI["root_doc"]."/front/ticket.php";
$root = $CFG_GLPI["root_doc"];
$user = Session::getCurrentInterface();
?>
<script>
var root = <?php echo json_encode($root); ?>;
var user = <?php echo json_encode($user); ?>;
function supprimer(e){
$(e).parents("tr").remove();
}
$("button[name='save']").click(function( event ) {
if($("#form")[0].checkValidity()) {
event.preventDefault();
$("button[name='save']").attr("disabled", "disabled");
$.ajax({
type: "POST",
url: root + "/ajax/payroll.period.php?action=update",
data: $('#form').serialize()
})
.done(function(response) {
try {
var res = JSON.parse(response);
if (res.status === "success") {
window.location = root + "/front/payroll.period.list.php";
} else {
showErrorMessage(res.message || "An error occurred while adding the payroll period.");
// Enable the save button
$("button[name='save']").removeAttr("disabled");
}
} catch (e) {
console.error("Error parsing JSON response: ", e);
// Enable the save button if JSON parsing fails
$("button[name='save']").removeAttr("disabled");
}
})
.fail(function(response) {
console.log("Request failed: ", response);
$("button[name='save']").removeAttr("disabled");
});
}
});
// Function to display error messages
function showErrorMessage(message) {
var errorMessageElement = $('<div class="error-message">' + message + '</div>');
// Append the error message to the body or a designated container
$("body").append(errorMessageElement);
// Optionally, style it for visibility
errorMessageElement.css({
"background-color": "#f8d7da",
"color": "#721c24",
"border": "1px solid #f5c6cb",
"padding": "10px",
"border-radius": "5px",
"margin": "10px 0"
});
// Optionally, fade out and remove the error message after a few seconds
setTimeout(function() {
errorMessageElement.fadeOut(500, function() {
$(this).remove();
});
}, 4000);
}
var userlink;
if(user == "helpdesk"){
userlink ='<li class="breadcrumb_item"><a href="'+root+'/front/helpdesk.public.php" title="Accueil">Accueil</a></li>';
}else{
userlink = '<li class="breadcrumb_item"><a href="'+root+'/front/central.php" title="Accueil">Accueil</a></li>';
}
$(document).ready(function(){
$("#c_ssmenu2").html('<ul>'+
userlink+
'<li class="breadcrumb_item"><a href="" title="">Administration</a></li>'+
'<li class="breadcrumb_item"><a href="'+root+'/front/payroll.period.list.php" class="here" title="Période"><i class="far fa-sticky-note"></i>&nbsp;Périodes</a></li>'+
'<span class="sr-only">Ajouter</span></a>'+
'</li>'+
'</ul>');
});
</script>
<!-- script pour liste déroulante -->
<script>
$(document).ready(function() {
$('.js-example-basic-single').select2();
});
</script>