first commit
This commit is contained in:
417
front/payroll.period.list.php
Normal file
417
front/payroll.period.list.php
Normal file
@ -0,0 +1,417 @@
|
||||
<?php
|
||||
|
||||
ob_Start();
|
||||
|
||||
|
||||
|
||||
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", '', "", "");
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
function get_periodes() {
|
||||
|
||||
global $DB;
|
||||
|
||||
|
||||
|
||||
$query = "
|
||||
|
||||
SELECT
|
||||
|
||||
p.id,
|
||||
|
||||
p.month,
|
||||
|
||||
p.year,
|
||||
|
||||
p.start_date,
|
||||
|
||||
p.end_date,
|
||||
|
||||
concat(u.realname,' ',u.firstname) as created_by
|
||||
|
||||
FROM payroll_period p
|
||||
|
||||
LEFT JOIN glpi_users u ON p.created_by = u.id
|
||||
|
||||
WHERE p.is_deleted = FALSE
|
||||
|
||||
";
|
||||
|
||||
|
||||
|
||||
// Execute the query
|
||||
|
||||
$result = $DB->query($query);
|
||||
|
||||
|
||||
|
||||
// Check if there are results and fetch them
|
||||
|
||||
if ($result && $result->num_rows > 0) {
|
||||
|
||||
$res = [];
|
||||
|
||||
while ($row = $result->fetch_assoc()) {
|
||||
|
||||
$res[] = $row;
|
||||
|
||||
}
|
||||
|
||||
return $res;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Return null if no results
|
||||
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
$res = get_periodes() ;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
echo '
|
||||
|
||||
<div class="center">
|
||||
|
||||
<table border="0" class="tab_cadrehov" style="font-size: 12px;">
|
||||
|
||||
<thead>
|
||||
|
||||
<tr class="tab_bg_2" style="text-align: center; vertical-align: middle;">
|
||||
|
||||
<th class=""></th>
|
||||
|
||||
<th>Période</th>
|
||||
|
||||
<th>Date début</th>
|
||||
|
||||
<th>Date de fin</th>
|
||||
|
||||
<th>Créé par</th>
|
||||
|
||||
<th></th>
|
||||
|
||||
</tr>
|
||||
|
||||
</thead>
|
||||
|
||||
<tbody id="data">
|
||||
|
||||
</tbody>
|
||||
|
||||
<footer>
|
||||
|
||||
<tr class="tab_bg_2" style="text-align: center; vertical-align: middle;">
|
||||
|
||||
<th class=""></th>
|
||||
|
||||
<th>Période</th>
|
||||
|
||||
<th>Date début</th>
|
||||
|
||||
<th>Date de fin</th>
|
||||
|
||||
<th>Créé par</th>
|
||||
|
||||
<th></th>
|
||||
|
||||
</tr>
|
||||
|
||||
</footer>
|
||||
|
||||
</table>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</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 res = <?php echo json_encode($res); ?>;
|
||||
|
||||
var user = <?php echo json_encode($user); ?>;
|
||||
|
||||
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> Périodes</a></li>'+
|
||||
|
||||
'<li class="icons_block"><span><a href="'+root+'/front/payroll.period.add.php" class="pointer" title="Ajouter"><i class="fa fa-plus"></i>'+
|
||||
|
||||
'<span class="sr-only">Ajouter</span></a>'+
|
||||
|
||||
'</li>'+
|
||||
|
||||
'</ul>');
|
||||
|
||||
|
||||
|
||||
});
|
||||
|
||||
|
||||
|
||||
function loadTable(data) {
|
||||
|
||||
if (data != null && data.length > 0) {
|
||||
|
||||
for (var i = 0; i < data.length; i++) {
|
||||
|
||||
var row = data[i];
|
||||
|
||||
var currentDate = new Date();
|
||||
|
||||
var endDate = new Date(row['end_date']);
|
||||
|
||||
|
||||
|
||||
// Check if the current date is after the end_date
|
||||
|
||||
var actions = '';
|
||||
|
||||
if (true) {
|
||||
|
||||
actions =
|
||||
|
||||
'<a href="' + root + '/front/payroll.period.update.php?id=' + row['id'] + '" title="Modifier">' +
|
||||
|
||||
'<i class="fa fa-edit fa-lg" style="color: green; cursor: pointer;"></i>' +
|
||||
|
||||
'</a> ' +
|
||||
|
||||
'<i class="fa fa-trash fa-lg deleteRow" style="color: red; cursor: pointer;" title="Supprimer" data-id="' + row['id'] + '"></i>';
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
$('#data').append(
|
||||
|
||||
'<tr class="tab_bg_2" style="text-align: center; vertical-align: middle;">' +
|
||||
|
||||
'<td width="10" valign="top"></td>' +
|
||||
|
||||
'<td valign="top">' + formatMonthYear(row['month'], row['year']) + '</td>' +
|
||||
|
||||
'<td valign="top">' + row['start_date'] + '</td>' +
|
||||
|
||||
'<td valign="top">' + row['end_date'] + '</td>' +
|
||||
|
||||
'<td valign="top">' + row['created_by'] + '</td>' +
|
||||
|
||||
'<td valign="top" style="text-align: center; vertical-align: middle;">' + actions + '</td>' +
|
||||
|
||||
'</tr>'
|
||||
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
loadTable(res);
|
||||
|
||||
|
||||
|
||||
function formatMonthYear(month, year) {
|
||||
|
||||
|
||||
|
||||
var months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
var monthIndex = month - 1;
|
||||
|
||||
|
||||
|
||||
if (monthIndex >= 0 && monthIndex < 12) {
|
||||
|
||||
return months[monthIndex] + '-' + year;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
return 'Invalid Date';
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
$(document).on('click', '.deleteRow', function() {
|
||||
|
||||
var id = $(this).data('id');
|
||||
|
||||
|
||||
|
||||
if (confirm("Êtes-vous sûr de vouloir supprimer cette période de paie ?")) {
|
||||
|
||||
$.ajax({
|
||||
|
||||
url: root + '/ajax/payroll.period.php?action=delete',
|
||||
|
||||
type: 'POST',
|
||||
|
||||
data: { id: id }
|
||||
|
||||
})
|
||||
|
||||
.done(function(response) {
|
||||
|
||||
try {
|
||||
|
||||
var res = JSON.parse(response);
|
||||
|
||||
|
||||
|
||||
if (res.status === "success") {
|
||||
|
||||
console.log(res.message);
|
||||
|
||||
location.reload();
|
||||
|
||||
} else {
|
||||
|
||||
showErrorMessage(res.message || "An error occurred while adding the payroll period.");
|
||||
|
||||
// Enable the save button
|
||||
|
||||
}
|
||||
|
||||
} catch (e) {
|
||||
|
||||
console.error("Error parsing JSON response: ", e);
|
||||
|
||||
}
|
||||
|
||||
})
|
||||
|
||||
.fail(function(response) {
|
||||
|
||||
showErrorMessage("Request failed: ", response);
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
|
||||
|
||||
</script>
|
||||
|
||||
<!-- script pour liste déroulante -->
|
||||
|
||||
<script>
|
||||
|
||||
$(document).ready(function() {
|
||||
|
||||
$('.js-example-basic-single').select2();
|
||||
|
||||
});
|
||||
|
||||
</script>
|
||||
Reference in New Issue
Block a user