{% extends 'base.html.twig' %}
{% block title %}{{ title }}{% endblock %}
{% block stylesheets %}
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/timepicker/1.3.5/jquery.timepicker.min.css">
<style>
#kt_datatable_row_grouping tr.group {
--bs-table-accent-bg: var(--bs-table-striped-bg) !important;
}
#kt_datatable_row_grouping tr.even, #kt_datatable_row_grouping tr.odd {
--bs-table-accent-bg: white !important;
}
#logDate {
text-align: center;
font-size: 25px;
font-weight: bold;
}
</style>
{% endblock %}
{% block body %}
<div class="card mb-5 mb-xl-10">
<div class="card-body fs-6 py-15 px-10 py-lg-15 px-lg-15 text-gray-700">
<div class="pb-10 row g-6 g-xl-9">
<div class="col-md-4"></div>
<div class="col-md-4"><input id="logDate" type="text" class="form-control form-control-solid"
autocomplete="false"></div>
<div class="col-md-2">
<button id="exportLogSheet" class="btn btn-primary">Exporter la fiche d'absence</button>
</div>
<div class="col-md-2"></div>
</div>
<!--begin::Wrapper-->
<div class="d-flex flex-stack flex-wrap mb-5">
<!--begin::Search-->
<div class="d-flex align-items-center position-relative my-1 mb-2 mb-md-0">
<!--begin::Svg Icon | path: icons/duotune/general/gen021.svg-->
<span class="svg-icon svg-icon-1 position-absolute ms-6">
<svg width="24" height="24" viewBox="0 0 24 24" fill="none"
xmlns="http://www.w3.org/2000/svg">
<rect opacity="0.5" x="17.0365" y="15.1223" width="8.15546"
height="2" rx="1"
transform="rotate(45 17.0365 15.1223)"
fill="currentColor"/>
<path d="M11 19C6.55556 19 3 15.4444 3 11C3 6.55556 6.55556 3 11 3C15.4444 3 19 6.55556 19 11C19 15.4444 15.4444 19 11 19ZM11 5C7.53333 5 5 7.53333 5 11C5 14.4667 7.53333 17 11 17C14.4667 17 17 14.4667 17 11C17 7.53333 14.4667 5 11 5Z"
fill="currentColor"/>
</svg>
</span>
<!--end::Svg Icon-->
<input type="text" data-table-filter="search" class="form-control form-control-solid w-250px ps-15"
placeholder="Search"/>
</div>
<!--end::Search-->
</div>
<!--end::Wrapper-->
<table id="kt_datatable_row_grouping"
class="table table-row-bordered gy-5 gs-7 border rounded w-100">
<thead>
<tr>
<th>Département</th>
<th>Poste</th>
<th>Nom Complet</th>
<th>Historique</th>
<th>Type</th>
<th>Heure</th>
<th>#</th>
</tr>
</thead>
<tbody>
{% for employee in employees %}
<tr data-employee-id="{{ employee.id }}">
<th>{{ employee.department }}</th>
<th>{{ employee.position }}</th>
<th><a href="{{ path('employee_show', {'id': employee.id}) }}">{{ employee.fullName }}</a></th>
<th>
<div class="history">{{ employee.historyHtml | raw }}</div>
</th>
<th>
<select class="form-select form-select-solid in_out no-select" size="1" autocomplete="off">
{% set InOut = enum('App\\Enum\\EmployeeHourLog\\InOut') %}
<option value="" selected>Séléctionner le type</option>
{% for type in InOut.cases() %}
<option value="{{ type.value }}">
{{ type.title() }}
</option>
{% endfor %}
</select>
</th>
<th>
<input type="text" class="form-control form-control-solid logTime">
</th>
<th>
<button type="button" class="btn btn-primary btn-success me-10 logTimeValidate">
<span class="indicator-label">Valider</span>
<span class="indicator-progress">Pointage en cours... <span
class="spinner-border spinner-border-sm align-middle ms-2"></span></span>
</button>
</th>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
{% endblock %}
{% block javascripts %}
<script src="//cdnjs.cloudflare.com/ajax/libs/timepicker/1.3.5/jquery.timepicker.min.js"></script>
<script>
var groupColumn = 0;
var table = $("#kt_datatable_row_grouping").DataTable({
columnDefs: [
{
targets: groupColumn,
visible: false,
},
{
targets: 1,
width: "15%"
},
{
targets: 2,
width: "15%"
},
{
targets: 3,
width: "20%"
}
],
order: [
[
groupColumn, "asc"
]
],
displayLength: 500,
drawCallback: function (settings) {
var api = this.api();
var rows = api.rows({
page: "current"
}).nodes();
var last = null;
api.column(groupColumn, {
page: "current"
}).data().each(function (group, i) {
if (last !== group) {
$(rows).eq(i).before(
"<tr class=\"group fs-5 fw-bolder\"><td colspan=\"5\">" + group + "</td></tr>"
);
last = group;
}
});
}
});
$("#kt_datatable_row_grouping tbody").on("click", "tr.group", function () {
var currentOrder = table.order()[0];
if (currentOrder[0] === groupColumn && currentOrder[1] === "asc") {
table.order([groupColumn, "desc"]).draw();
} else {
table.order([groupColumn, "asc"]).draw();
}
});
handleSearchDatatable(table);
var today = new Date();
$('.logTime').timepicker({
timeFormat: 'HH:mm',
interval: 15,
minTime: '6:00am',
maxTime: '11:00pm',
defaultTime: new Date(today.getFullYear(), today.getMonth(), today.getDate(), today.getHours(), 0, 0),
startTime: '06:00am',
dynamic: false,
dropdown: true,
scrollbar: true
});
$(".logTimeValidate").on('click', function () {
let element = $(this);
element.attr('data-kt-indicator', 'on');
var tr = $(this).parents('tr');
let date = $("#logDate").val();
let time = tr.find('.logTime').val();
let employeeId = tr.attr('data-employee-id');
let inOut = tr.find('.in_out').val();
if (typeof inOut === 'undefined' || inOut === '') {
Swal.fire("Erreur!", "Le type est obligatoire !", "error");
element.removeAttr('data-kt-indicator');
return false;
}
var data = {
'employeeId': employeeId,
'inOut': inOut,
'logDate': date,
'logTime': time,
}
$.ajax({
url: '{{ path('employee_log_hour_add') }}',
data: data,
dataType: 'json',
type: "POST",
success: function (response) {
if (response.status) {
toastr["success"]('MAJ', response.message);
} else {
Swal.fire("Erreur!", response.message, "error")
}
tr.find('.history').html(response.historyHtml);
element.removeAttr('data-kt-indicator');
tr.find('.in_out').val('');
},
error: function (error) {
Swal.fire("Erreur!", "Une erreur s'est produite, Prière de contacter la direction !", "error")
}
});
//element.removeAttr('data-kt-indicator');
});
window.date = '{{ date }}';
var logDate = $('#logDate');
logDate.daterangepicker({
singleDatePicker: true,
showDropdowns: true,
autoUpdateInput: true,
startDate: window.date,
locale: {
format: "DD/MM/YYYY",
applyLabel: "Appliquer",
cancelLabel: "Annuler",
weekLabel: "W",
firstDay: 1,
}
});
logDate.on('apply.daterangepicker', function (ev, picker) {
Swal.fire({
text: 'Attention: la page va se raffraichir',
icon: "info",
confirmButtonText: "Confirmer !",
customClass: {
confirmButton: "btn btn-danger font-weight-bold btn-pill",
cancelButton: "btn btn-secondary font-weight-bold btn-pill"
},
cancelButtonText: 'Annuler',
showCancelButton: true
}).then((result) => {
if (result.isConfirmed) {
let date = picker.startDate.format("DD/MM/YYYY");
$(this).val(date);
window.location.href = window.location.href.replace(/[\?#].*|$/, "?date=" + date);
}
$(this).val(window.date);
})
});
logDate.on('cancel.daterangepicker', function (ev, picker) {
$(this).val(window.date);
});
$('#exportLogSheet').on('click', function (e) {
e.preventDefault();
var url = '{{ path('employee_log_sheet') }}';
window.open(url.replace(/[\?#].*|$/, "?date=" + $('#logDate').val()));
})
</script>
{% endblock %}