{% extends 'base.html.twig' %}
{% block title %}Edition Client{% endblock %}
{% block body %}
{% include 'breadcrumb.html.twig' with {level1: 'Client', level2: ''} %}
<div style="display: inline-block ">
<h1>{{ client.firstname|capitalize }} {{ client.lastname|capitalize }}</h1>
<div >Identifier : {{ client.identifier }}</div>
</div>
<div style="font-size:20px;float:right;background: {%if client.solde <= 0%}green{%else%}red{%endif%};padding:5px;color:white">Solde client : {{ client.solde }} €</div>
{{ include('client/_form.html.twig', {'button_label': 'Update'}) }}
<a href="{{ path('client_index') }}" class="btn-outline-info btn back-button">Revenir</a>
{{ include('client/_delete_form.html.twig') }}
{{ include('client/modal_envoi_facture.html.twig') }}
<div>
<div>Crée le : {{ client.created|date('d/m/Y H:m:s', "Europe/Paris") }}</div>
<div>Compte création : {% if client.creator %} {{ client.creator.email }} {% endif %}</div>
<div>Maj le : {{ client.updated|date('d/m/Y H:m:s', "Europe/Paris") }}</div>
<div>Compte Maj : {% if client.maj %}{{ client.maj.email }} {% endif %}</div>
</div>
{% endblock %}
{% block javascripts %}
{{ parent() }}
<script type="application/javascript">
$('#filter_status').select2( {width: '250px' });
$('#filter_statut').select2( {width: '250px' });
$('#filter_mode').select2( {width: '200px' });
function addTagForm($collectionHolder) {
// Get the data-prototype explained earlier
var prototype = $collectionHolder.data('prototype');
// get the new index
var index = $collectionHolder.data('index');
var newForm = prototype;
// You need this only if you didn't set 'label' => false in your tags field in TaskType
// Replace '__name__label__' in the prototype's HTML to
// instead be a number based on how many items we have
// newForm = newForm.replace(/__name__label__/g, index);
// Replace '__name__' in the prototype's HTML to
// instead be a number based on how many items we have
newForm = newForm.replace(/__name__/g, index);
// increase the index with one for the next item
$collectionHolder.data('index', index + 1);
// Display the form in the page in an li, before the "Add a tag" link li
var $newFormLi = $('<div></div>').append(newForm);
$collectionHolder.after($newFormLi);
$(".protoypeDate input").flatpickr({
'dateFormat' : 'd-m-Y',
"locale": "fr"
});
$('.hourPicker:not(.flatpickr-input):not(.input)').flatpickr({
enableTime: true,
noCalendar: true,
dateFormat: "H:i",
time_24hr: true,
locale: "fr"
});
}
jQuery(document).ready(function() {
$('#client_site').select2({ width: '100%' });
$('.select2jours').select2({ width: '100%' });
var $collectionHolder;
const $addTagButton = jQuery('.btnAddContrat');
$collectionHolder = jQuery('ul.contratList');
const $addFamilyButton = jQuery('.btnAddFamily');
const $familyList = jQuery('.familyList');
$('.select-product').select2({ width: '100%' });
// count the current form inputs we have (e.g. 2), use that as the new
// index when inserting a new item (e.g. 2)
$collectionHolder.data('index', $collectionHolder.find(':input').length);
$familyList.data('index', $collectionHolder.find(':input').length);
$addTagButton.on('click', function(e) {
// add a new tag form (see next code block)
addTagForm($collectionHolder);
$('.select-product').select2({ width: '100%' });
});
$addFamilyButton.on('click', function(e) {
// add a new tag form (see next code block)
addTagForm($familyList);
});
// DELETE CONTRACT
$(document).on('click','.btnDeleteContract', function(e) {
// add a new tag form (see next code block)
$(e.target).parents('.contract-item').remove();
var index = $collectionHolder.data('index');
$collectionHolder.data('index', index - 1);
});
// DELETE FAMILY
$(document).on('click','.btnDeleteFamily', function(e) {
// add a new tag form (see next code block)
console.log($(e.target).parents('.family-item'));
$(e.target).parents('.family-item').remove();
var index = $familyList.data('index');
$familyList.data('index', index - 1);
});
$('#form_client').submit( function(e) {
e.preventDefault();
if(($('#client_billingInfos_sendMode').val() === '' || $('#client_billingInfos_sendMode').val() === 'email') && $('#client_billingInfos_email').val() === ''){
notie.alert({
text: 'Veuillez entrer un email de facturation',
});
return false;
}
if($('#client_deathday').val()) {
notie.confirm({
text: 'Vous avez entré une date de décès êtes vous sur de continuer ?',
submitText: 'Confirmer', // optional, default = 'Yes'
cancelText: 'Annuler', // optional, default = 'Cancel'
submitCallback: function () {
$(this).unbind();
$(this).submit();
}, // optional
cancelCallback: function () {
return false;
} // optional
});
}
$(this).unbind();
$(this).submit();
});
});
$('.open-envoi-facture').on('click', function(e){
e.preventDefault();
$('#modalEnvoiFacture').modal('toggle');
})
// filter products
$(document).on('change', '.tag', function (e) {
console.log('tag changed');
const val = $(e.target).val();
var url = '{{ path("app_client_ajaxgetproducts", {'id': 'salon_id'}) }}';
url = url.replace("salon_id", val);
$.ajax({
url: url,
type: 'get',
success: function (data) {
console.log(data);
for (var i = 0; i < data.length; i++) {
var item = data[i];
$(e.target).parents('.contract-item').find('.select-product').empty();
$(e.target).parents('.contract-item').find('.select-product').append('<option value="' + item.id + '">' + item.name + '</option>');
}
}
});
});
$('#client_billingInfos_payMode').on('change', function () {
const val = $('#client_billingInfos_payMode').val();
if(val === 'sepa') {
$('.hide').each(function (e) {
$( this ).removeClass('hide');
})
}
else {
$('.hiddenFields').each(function (e) {
$( this ).addClass('hide');
});
}
});
$('.hourPicker:not(.flatpickr-input):not(.input)').flatpickr({
enableTime: true,
noCalendar: true,
dateFormat: "H:i",
time_24hr: true,
locale: "fr"
});
//const availableDates = ""dates|json_encode|raw"";
//enable: availableDates,
<!-- recurrence -->
$('#dateDebut').flatpickr({
'dateFormat': 'Y-m-d',
"locale": "fr",
});
let productCount = 0;
const products = {{ products | json_encode() | raw }};
console.log(products);
function addProductField() {
productCount++;
// Create a new container div for the product and frequency fields
const container = document.createElement('div');
container.className = 'row align-items-center mb-2';
// Create a Bootstrap column for product selection
const productCol = document.createElement('div');
productCol.className = 'col-md-6';
// Create a select element for product selection
const productSelect = document.createElement('select');
productSelect.name = `products[${productCount}]`;
productSelect.className = 'form-control select2';
// Populate product options from the Twig array
for (const product of products) {
const option = document.createElement('option');
option.value = product.id;
option.text = product.name;
productSelect.appendChild(option);
}
// Append the product select to the product column
productCol.appendChild(productSelect);
// Create a Bootstrap column for frequency selection
const frequencyCol = document.createElement('div');
frequencyCol.className = 'col-md-4 ml-2';
// Create a select element for frequency selection
const frequencySelect = document.createElement('select');
frequencySelect.name = `frequencies[${productCount}]`;
frequencySelect.className = 'form-control';
// Add options to the frequency select element as needed
// Example:
const optionA = document.createElement('option');
optionA.value = 'every';
optionA.text = 'À chaque RDV';
frequencySelect.appendChild(optionA);
const optionB = document.createElement('option');
optionB.value = 'every_other';
optionB.text = '1 RDV sur 2';
frequencySelect.appendChild(optionB);
// Add more options as needed
// Append the frequency select to the frequency column
frequencyCol.appendChild(frequencySelect);
// Create a button to delete the product and frequency fields
const deleteButton = document.createElement('button');
deleteButton.textContent = 'Supprimer';
deleteButton.className = 'btn btn-danger col-md-2 ml-2';
deleteButton.type = 'button';
deleteButton.addEventListener('click', () => {
container.remove();
});
// Append the product column, frequency column, and delete button to the container div
container.appendChild(productCol);
container.appendChild(frequencyCol);
container.appendChild(deleteButton);
// Append the container div to the 'productFields' div
const productFields = document.getElementById('productFields');
productFields.appendChild(container);
$('.select2').select2();
}
$('.btn-valid').on('click', function (e) {
e.preventDefault();
if($('#client_statusProspect').val() == 'Inactif' || $('#client_statusProspect').val() == 'Parti' ) {
notie.confirm({
text: "Cette action entrainera la suppression de tous les RDV à venir",
submitText: 'Confirmer', // optional, default = 'Yes'
cancelText: 'Annuler', // optional, default = 'Cancel'
position: 'top', // optional, default = 'top', enum: ['top', 'bottom']
submitCallback: function () {
$('#form_client').unbind();
$('#form_client').submit();
}, // optional
cancelCallback: function () {
} // optional
}, function () {
}, function () {
})
}
else {
$(this).unbind();
$(this).submit();
}
});
$('#envoiFacture').on('click', function(e) {
e.preventDefault();
var selectedFactures = [];
$('.calcul').each(function() {
if ($(this).is(':checked')) {
selectedFactures.push($(this).data('billing'));
}
});
if (selectedFactures.length > 0) {
$.ajax({
url: '{{ path("client_send_billing_multiple") }}',
type: 'POST',
contentType: 'application/json',
data: JSON.stringify({ factures: selectedFactures }),
success: function(response) {
alert('Factures envoyées avec succès.');
},
error: function(xhr, status, error) {
console.error('Error:', error);
alert('Une erreur est survenue lors de l\'envoi des factures.');
}
});
} else {
alert('Veuillez sélectionner au moins une facture.');
}
});
</script>
{% endblock %}