templates/client/edit.html.twig line 1

Open in your IDE?
  1. {% extends 'base.html.twig' %}
  2. {% block title %}Edition Client{% endblock %}
  3. {% block body %}
  4.     {% include 'breadcrumb.html.twig' with {level1: 'Client', level2: ''} %}
  5.     <div style="display: inline-block   ">
  6.         <h1>{{ client.firstname|capitalize }} {{ client.lastname|capitalize }}</h1>
  7.         <div >Identifier : {{ client.identifier }}</div>
  8.     </div>
  9.     <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>
  10.     {{ include('client/_form.html.twig', {'button_label': 'Update'}) }}
  11.     <a href="{{ path('client_index') }}" class="btn-outline-info btn back-button">Revenir</a>
  12.     {{ include('client/_delete_form.html.twig') }}
  13.     {{ include('client/modal_envoi_facture.html.twig') }}
  14.     <div>
  15.         <div>Crée le : {{ client.created|date('d/m/Y H:m:s', "Europe/Paris") }}</div>
  16.         <div>Compte création : {% if client.creator %} {{ client.creator.email }} {% endif %}</div>
  17.         <div>Maj le : {{ client.updated|date('d/m/Y H:m:s', "Europe/Paris") }}</div>
  18.         <div>Compte Maj : {% if client.maj %}{{ client.maj.email }}  {% endif %}</div>
  19.     </div>
  20. {% endblock %}
  21. {% block javascripts %}
  22.     {{ parent() }}
  23.     <script type="application/javascript">
  24.         $('#filter_status').select2( {width: '250px' });
  25.         $('#filter_statut').select2( {width: '250px' });
  26.         $('#filter_mode').select2( {width: '200px' });
  27.         function addTagForm($collectionHolder) {
  28.             // Get the data-prototype explained earlier
  29.             var prototype = $collectionHolder.data('prototype');
  30.             // get the new index
  31.             var index = $collectionHolder.data('index');
  32.             var newForm = prototype;
  33.             // You need this only if you didn't set 'label' => false in your tags field in TaskType
  34.             // Replace '__name__label__' in the prototype's HTML to
  35.             // instead be a number based on how many items we have
  36.             // newForm = newForm.replace(/__name__label__/g, index);
  37.             // Replace '__name__' in the prototype's HTML to
  38.             // instead be a number based on how many items we have
  39.             newForm = newForm.replace(/__name__/g, index);
  40.             // increase the index with one for the next item
  41.             $collectionHolder.data('index', index + 1);
  42.             // Display the form in the page in an li, before the "Add a tag" link li
  43.             var $newFormLi = $('<div></div>').append(newForm);
  44.             $collectionHolder.after($newFormLi);
  45.             $(".protoypeDate input").flatpickr({
  46.                 'dateFormat' : 'd-m-Y',
  47.                 "locale": "fr"
  48.             });
  49.             $('.hourPicker:not(.flatpickr-input):not(.input)').flatpickr({
  50.                 enableTime: true,
  51.                 noCalendar: true,
  52.                 dateFormat: "H:i",
  53.                 time_24hr: true,
  54.                 locale: "fr"
  55.             });
  56.         }
  57.         jQuery(document).ready(function() {
  58.             $('#client_site').select2({ width: '100%' });
  59.             $('.select2jours').select2({ width: '100%' });
  60.             var $collectionHolder;
  61.             const $addTagButton = jQuery('.btnAddContrat');
  62.             $collectionHolder = jQuery('ul.contratList');
  63.             const $addFamilyButton = jQuery('.btnAddFamily');
  64.             const $familyList = jQuery('.familyList');
  65.             $('.select-product').select2({ width: '100%' });
  66.             // count the current form inputs we have (e.g. 2), use that as the new
  67.             // index when inserting a new item (e.g. 2)
  68.             $collectionHolder.data('index', $collectionHolder.find(':input').length);
  69.             $familyList.data('index', $collectionHolder.find(':input').length);
  70.             $addTagButton.on('click', function(e) {
  71.                 // add a new tag form (see next code block)
  72.                 addTagForm($collectionHolder);
  73.                 $('.select-product').select2({ width: '100%' });
  74.             });
  75.             $addFamilyButton.on('click', function(e) {
  76.                 // add a new tag form (see next code block)
  77.                 addTagForm($familyList);
  78.             });
  79.             // DELETE CONTRACT
  80.             $(document).on('click','.btnDeleteContract', function(e) {
  81.                 // add a new tag form (see next code block)
  82.                 $(e.target).parents('.contract-item').remove();
  83.                 var index = $collectionHolder.data('index');
  84.                 $collectionHolder.data('index', index - 1);
  85.             });
  86.             // DELETE FAMILY
  87.             $(document).on('click','.btnDeleteFamily', function(e) {
  88.                 // add a new tag form (see next code block)
  89.                 console.log($(e.target).parents('.family-item'));
  90.                 $(e.target).parents('.family-item').remove();
  91.                 var index = $familyList.data('index');
  92.                 $familyList.data('index', index - 1);
  93.             });
  94.             $('#form_client').submit( function(e) {
  95.                 e.preventDefault();
  96.                 if(($('#client_billingInfos_sendMode').val() === '' || $('#client_billingInfos_sendMode').val() === 'email') && $('#client_billingInfos_email').val() === ''){
  97.                     notie.alert({
  98.                         text: 'Veuillez entrer un email de facturation',
  99.                     });
  100.                     return false;
  101.                 }
  102.                 if($('#client_deathday').val()) {
  103.                     notie.confirm({
  104.                         text: 'Vous avez entré une date de décès êtes vous sur de continuer ?',
  105.                         submitText: 'Confirmer', // optional, default = 'Yes'
  106.                         cancelText: 'Annuler', // optional, default = 'Cancel'
  107.                         submitCallback: function () {
  108.                             $(this).unbind();
  109.                             $(this).submit();
  110.                         }, // optional
  111.                         cancelCallback: function () {
  112.                             return false;
  113.                         } // optional
  114.                     });
  115.                 }
  116.                 $(this).unbind();
  117.                 $(this).submit();
  118.             });
  119.         });
  120.         $('.open-envoi-facture').on('click', function(e){
  121.             e.preventDefault();
  122.             $('#modalEnvoiFacture').modal('toggle');
  123.         })
  124.         // filter products
  125.         $(document).on('change', '.tag', function (e) {
  126.             console.log('tag changed');
  127.             const val = $(e.target).val();
  128.             var url = '{{ path("app_client_ajaxgetproducts", {'id': 'salon_id'}) }}';
  129.             url = url.replace("salon_id", val);
  130.             $.ajax({
  131.                 url: url,
  132.                 type: 'get',
  133.                 success: function (data) {
  134.                     console.log(data);
  135.                     for (var i = 0; i < data.length; i++) {
  136.                         var item = data[i];
  137.                         $(e.target).parents('.contract-item').find('.select-product').empty();
  138.                         $(e.target).parents('.contract-item').find('.select-product').append('<option value="' + item.id + '">' + item.name + '</option>');
  139.                     }
  140.                 }
  141.             });
  142.         });
  143.         $('#client_billingInfos_payMode').on('change', function () {
  144.             const val = $('#client_billingInfos_payMode').val();
  145.             if(val === 'sepa') {
  146.                 $('.hide').each(function (e) {
  147.                     $( this ).removeClass('hide');
  148.                 })
  149.             }
  150.             else {
  151.                 $('.hiddenFields').each(function (e) {
  152.                     $( this ).addClass('hide');
  153.                 });
  154.             }
  155.         });
  156.         $('.hourPicker:not(.flatpickr-input):not(.input)').flatpickr({
  157.             enableTime: true,
  158.             noCalendar: true,
  159.             dateFormat: "H:i",
  160.             time_24hr: true,
  161.             locale: "fr"
  162.         });
  163.         //const availableDates = ""dates|json_encode|raw"";
  164. //enable: availableDates,
  165.         <!-- recurrence -->
  166.         $('#dateDebut').flatpickr({
  167.             'dateFormat': 'Y-m-d',
  168.             "locale": "fr",
  169.         });
  170.         let productCount = 0;
  171.         const products = {{ products | json_encode() | raw }};
  172.         console.log(products);
  173.         function addProductField() {
  174.             productCount++;
  175.             // Create a new container div for the product and frequency fields
  176.             const container = document.createElement('div');
  177.             container.className = 'row align-items-center mb-2';
  178.             // Create a Bootstrap column for product selection
  179.             const productCol = document.createElement('div');
  180.             productCol.className = 'col-md-6';
  181.             // Create a select element for product selection
  182.             const productSelect = document.createElement('select');
  183.             productSelect.name = `products[${productCount}]`;
  184.             productSelect.className = 'form-control select2';
  185.             // Populate product options from the Twig array
  186.             for (const product of products) {
  187.                 const option = document.createElement('option');
  188.                 option.value = product.id;
  189.                 option.text = product.name;
  190.                 productSelect.appendChild(option);
  191.             }
  192.             // Append the product select to the product column
  193.             productCol.appendChild(productSelect);
  194.             // Create a Bootstrap column for frequency selection
  195.             const frequencyCol = document.createElement('div');
  196.             frequencyCol.className = 'col-md-4 ml-2';
  197.             // Create a select element for frequency selection
  198.             const frequencySelect = document.createElement('select');
  199.             frequencySelect.name = `frequencies[${productCount}]`;
  200.             frequencySelect.className = 'form-control';
  201.             // Add options to the frequency select element as needed
  202.             // Example:
  203.             const optionA = document.createElement('option');
  204.             optionA.value = 'every';
  205.             optionA.text = 'À chaque RDV';
  206.             frequencySelect.appendChild(optionA);
  207.             const optionB = document.createElement('option');
  208.             optionB.value = 'every_other';
  209.             optionB.text = '1 RDV sur 2';
  210.             frequencySelect.appendChild(optionB);
  211.             // Add more options as needed
  212.             // Append the frequency select to the frequency column
  213.             frequencyCol.appendChild(frequencySelect);
  214.             // Create a button to delete the product and frequency fields
  215.             const deleteButton = document.createElement('button');
  216.             deleteButton.textContent = 'Supprimer';
  217.             deleteButton.className = 'btn btn-danger col-md-2 ml-2';
  218.             deleteButton.type = 'button';
  219.             deleteButton.addEventListener('click', () => {
  220.                 container.remove();
  221.             });
  222.             // Append the product column, frequency column, and delete button to the container div
  223.             container.appendChild(productCol);
  224.             container.appendChild(frequencyCol);
  225.             container.appendChild(deleteButton);
  226.             // Append the container div to the 'productFields' div
  227.             const productFields = document.getElementById('productFields');
  228.             productFields.appendChild(container);
  229.             $('.select2').select2();
  230.         }
  231.         $('.btn-valid').on('click', function (e) {
  232.             e.preventDefault();
  233.             if($('#client_statusProspect').val() == 'Inactif' || $('#client_statusProspect').val() == 'Parti' ) {
  234.                 notie.confirm({
  235.                     text: "Cette action entrainera la suppression de tous les RDV à venir",
  236.                     submitText: 'Confirmer', // optional, default = 'Yes'
  237.                     cancelText: 'Annuler', // optional, default = 'Cancel'
  238.                     position: 'top', // optional, default = 'top', enum: ['top', 'bottom']
  239.                     submitCallback: function () {
  240.                         $('#form_client').unbind();
  241.                         $('#form_client').submit();
  242.                     }, // optional
  243.                     cancelCallback: function () {
  244.                     } // optional
  245.                 }, function () {
  246.                 }, function () {
  247.                 })
  248.             }
  249.             else {
  250.                 $(this).unbind();
  251.                 $(this).submit();
  252.             }
  253.         });
  254.         $('#envoiFacture').on('click', function(e) {
  255.             e.preventDefault();
  256.             var selectedFactures = [];
  257.             $('.calcul').each(function() {
  258.                 if ($(this).is(':checked')) {
  259.                     selectedFactures.push($(this).data('billing'));
  260.                 }
  261.             });
  262.             if (selectedFactures.length > 0) {
  263.                 $.ajax({
  264.                     url: '{{ path("client_send_billing_multiple") }}',
  265.                     type: 'POST',
  266.                     contentType: 'application/json',
  267.                     data: JSON.stringify({ factures: selectedFactures }),
  268.                     success: function(response) {
  269.                         alert('Factures envoyées avec succès.');
  270.                     },
  271.                     error: function(xhr, status, error) {
  272.                         console.error('Error:', error);
  273.                         alert('Une erreur est survenue lors de l\'envoi des factures.');
  274.                     }
  275.                 });
  276.             } else {
  277.                 alert('Veuillez sélectionner au moins une facture.');
  278.             }
  279.         });
  280.     </script>
  281. {% endblock %}