{% extends 'base.html.twig' %}
{% block title %}Rendez-vous{% endblock %}
{% block body %}
{% include 'breadcrumb.html.twig' with {level1: 'Planning', level2: 'Edition'} %}
<div class="page-header">
<h1>{% if rdv.client %}
{{ rdv.client.civilite }} {{ rdv.client.lastname|capitalize }} {{ rdv.client.roomNumber }}
{% endif %}
{% for product in rdv.rdvProducts %}
{{ product.product.ui }},
{% endfor %}
</h1>
<div>
Référence contrat : {{ rdv.contract ? rdv.contract.id : '' }}
</div>
<div>
Batiment / Étage / Numéro de chambre : {{ rdv.client.roomNumber }}
</div>
</div>
{% if rdv.status == 'validated' and canBill %}
<div style="padding: 20px">
<a class="btn btn-success " href="{{ path('billing_new_rdv', {id : rdv.id}) }}">Facturer</a>
</div>
{% endif %}
<input type="hidden" id="minuteIncrement" value="{{ minuteIncrement }}" />
{{ include('planning/_form.html.twig', {'button_label': 'Update'}) }}
<a class="btn btn-outline-info back-button" href="{{ path('app_planning_site') }}">Revenir au planning</a>
{% if not is_granted('ROLE_COIFFEUR') %}
{{ include('planning/_delete_form.html.twig') }}
{% endif %}
<style>
#rdv_products {
height: 200px;
}
{% if rdv.status == 'validated' %}
select.form-control{
background-color: green;
color:white;
}
{% endif %}
{% if rdv.status == 'cancel' %}
select.form-control{
background-color: red;
color:white;
}
{% endif %}
</style>
{% endblock %}
{% block javascripts %}
{{ parent() }}
<script type="text/javascript">
// Pass the role information to JavaScript
var isCoiffeur = {{ is_granted('ROLE_COIFFEUR') ? 'true' : 'false' }};
</script>
<script type="text/javascript">
jQuery.fn.preventDoubleSubmission = function() {
$(this).on('submit',function(e){
var $form = $(this);
if ($form.data('submitted') === true) {
// Previously submitted - don't submit again
e.preventDefault();
} else {
// Mark it so that the next submit can be ignored
$form.data('submitted', true);
}
});
// Keep chainability
return this;
};
$('#edit_form_rdv').preventDoubleSubmission();
$('#save-edit').on('click', (e) => {
e.preventDefault();
notie.confirm({
text: 'Etes vous sur de vouloir enregister?',
submitText: 'Confirmer', // optional, default = 'Yes'
cancelText: 'Annuler', // optional, default = 'Cancel'
submitCallback: function () {
if($('#rdv_cancelReason').val() == '1' || $('#rdv_cancelReason').val() == '8') {
const text = $('#rdv_cancelReason').val() == '1' ? 'Cette action entrainera la suppression de tous les RDV à venir et l’envoi d’une lettre de condoléance' : 'Cette action entrainera la suppression de tous les RDV à venir.';
notie.confirm({
text: text,
submitText: 'Confirmer', // optional, default = 'Yes'
cancelText: 'Annuler', // optional, default = 'Cancel'
submitCallback: function () {
$('#edit_form_rdv').unbind();
$('#edit_form_rdv').submit();
},
cancelCallback: function () {
return false;
}
});
}
else {
$('#edit_form_rdv').unbind();
$('#edit_form_rdv').submit();
}
}, // optional
cancelCallback: function () {
return false;
} // optional
});
})
$('#rdv_products').select2({ width: '100%' });
var flatpickrConfig = {
'dateFormat' : 'Y-m-d H:i',
'altFormat' : 'd-m-Y H:i',
'altInput': true,
'enableTime': true,
"locale": "fr",
minuteIncrement: jQuery('#minuteIncrement').val(),
};
function restrictFutureDates(selectedDates, dateStr, instance) {
console.log(selectedDates[0]);
var selectedDate = selectedDates[0];
if(selectedDate){
selectedDate.setHours(0, 0, 0, 0);
}
var today = new Date();
today.setHours(0, 0, 0, 0);
if (selectedDate && selectedDate > today) {
// Prevent selecting future dates
instance.clear(); // Clear the selected date
alert("Vous ne pouvez pas sélectionner une date dans le futur.");
}
}
if (isCoiffeur) {
var today = new Date();
var tomorrow = new Date(today);
flatpickrConfig['onChange'] = restrictFutureDates;
}
$('#rdv_start').flatpickr(flatpickrConfig);
$('#rdv_end').flatpickr(flatpickrConfig);
if($('#rdv_status').val() !== 'cancel') {
$('#rdv_cancelReason').parent('.form-group').hide();
}
$('#rdv_status').on('change', function () {
if($('#rdv_status').val() !== 'cancel') {
$('#rdv_cancelReason').parent('.form-group').hide();
} else {
$('#rdv_cancelReason').parent('.form-group').show();
}
})
$('#rdv_cancelReason').on('change',function (){
if($('#rdv_cancelReason').val() == '12') {
alert('Attention le RDV ne sera pas replanifié');
}
});
document.addEventListener('DOMContentLoaded', function() {
// Prevent changing the select field
document.querySelector('select[name="rdv[client]"]').addEventListener('mousedown', function(event) {
event.preventDefault(); // Prevent any interaction
});
document.querySelector('select[name="rdv[salon]"]').addEventListener('mousedown', function(event) {
event.preventDefault(); // Prevent any interaction
});
});
document.addEventListener('DOMContentLoaded', function() {
const chequeReceptionField = document.getElementById('rdv_chequeReception');
const infoChequeField = document.getElementById('rdv_infoCheque');
// Function to send AJAX request to save the field
function autoSaveField(field, value) {
fetch('{{ path('rdv_auto_save') }}', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-Requested-With': 'XMLHttpRequest',
'X-CSRF-Token': '{{ csrf_token('rdv_auto_save') }}' // Ensure CSRF token is valid
},
body: JSON.stringify({
field: field,
value: value,
rdvId: '{{ rdv.id }}' // Pass the RDV ID if needed
})
})
.then(response => response.json())
.then(data => {
if (data.success) {
console.log(`${field} auto-saved.`);
} else {
console.error(`Failed to auto-save ${field}.`);
}
})
.catch(error => console.error('Error:', error));
}
// Event listeners for changes on the fields
function addAutoSaveEventListener(field, fieldName) {
// Handle checkboxes separately
if (field.type === 'checkbox') {
field.addEventListener('change', (event) => {
autoSaveField(fieldName, event.target.checked ? 1 : 0); // Save as 1 for checked, 0 for unchecked
});
} else {
field.addEventListener('input', (event) => {
autoSaveField(fieldName, event.target.value);
});
}
}
addAutoSaveEventListener(chequeReceptionField, 'chequeReception');
addAutoSaveEventListener(infoChequeField, 'infoCheque');
});
</script>
{% endblock %}