
{% extends '@ajax-layout/layout.twig' %}

{% block body %}

<script type="text/javascript" src="{{ baseUrl('js/Modules/GlobalApplication/Planning.js') }}"></script>
<script>

function sendForm(id)
{
	activeLoader();
    $.ajax({
    	url : '{{ path('GlobalApplication.Planning.validationLigne') }}',
        type: 'POST',
        dataType : 'JSON',
        data: $("#form_planning").serialize(),
        success: function (data) {
    		desactiveLoader();
            if(data.statut == 'O'){
                $('#ligne_planning').val(data.ligne_planning);
                $('#ligne_DTELIVSOU').val(data.ligne_DTELIVSOU);
        	    desactivePopup ();
            }else{
                $('#message_erreur_popup').show().html(data.erreur);
            }
        }
    });
}
</script>
	<div class="modal-body">
        <div class="tab-content">
            <div id="message_erreur_popup" class="error displayNone clearfix" ></div>
        	<div class="padding15">
                <div class="colonne2">
                    <div class="informations">
                        <p>
                            <span class="champs_label">{{ texteNoDoc }}</span>
                            <span class="resultat">{{ id }}</span>
                        </p>
                        <p>
                            <span class="champs_label">{{ 'Début contrat' | trad }}</span>
                            <span class="resultat">{{ ligneDocument.DATEDEBCONT | dateTrad }}</span>
                        </p>
                        <p>
                            <span class="champs_label">{{ 'Périodicité' | trad }}</span>
                            <span class="resultat">{{ tabPeriodicite[ligneDocument.CONTRAT_PERIOD] }}</span>
                        </p>
                        <p>
                            <span class="champs_label">{{ 'Jour d\'application' | trad }}</span>
                            <span class="resultat">{% if MODULE == 'DA' %}{{ ligneDocument.DALI_RECEPAUTO_JOUR }}{% endif %}
                            </span>
                        </p>
                    </div>
                </div>
                <div class="colonne2 last">
                    <div class="informations">
                        <p>
                            <span class="champs_label">{{ 'Ligne' | trad }}</span>
                            <span class="resultat">{{ noPo}}</span>
                        </p>
                        <p>
                            <span class="champs_label">{{ 'Fin contrat' | trad }}</span>
                            <span class="resultat">{{ ligneDocument.DATEFINCONT | dateTrad }}</span>
                        </p>
                        <p>
                            <span class="champs_label">{{ 'Période' | trad }}</span>
                            <span class="resultat">{{ tabPeriode[ligneDocument.FIN_DEB_PER] }}</span>
                        </p>
                        <p id="resteACadencer" class="textVert">
                            <span class="champs_label">{{ 'Reste à cadencer' | trad }}</span>
                            <span class="resultat">{{ '0' | number_format(3, '.', ' ') }}</span>
                        </p>
                    </div>
                </div>
            </div>
        </div>
        <div class="clearfix">        
            <form method="post" name="form_planning" id="form_planning" class="box-form">
                <table class="table table-hover tableForm" id='lignesPlanning'>
                    <thead class="thead-dark">
                        <tr>
                            <th scope="col">{{ 'Date' | trad }}</th>
                            <th scope="col">{{ 'Quantité' | trad }}</th>                            
                            {% if action == 'modif' %}
                            <th scope="col" width="65px">{{ 'Actions' | trad }}</th>
                            {% endif %}
                        </tr>
                    </thead>
                    
                    <tbody>
                        {% set index = 0 %}
                        {% for ligne in listePlanning %}
                            {% set index = loop.index %}
                            {% if action == 'visu' %}
                                {% include '@GlobalApplication/Planning/ligneNonModifiable.twig' %}
                            {% endif %}
                            {% if action == 'modif' %}
                                {% include '@GlobalApplication/Planning/ligne.twig' %}
                            {% endif %}
                        {% endfor %}
                        
                        {% if action == 'modif' %}
                        <tr class="static">
                            <td colspan="2"></td>
                            <td class="parametrage">
                                {{ Button('',1,'', "ajoutLignePlanning('"~path('GlobalApplication.Planning.ajaxAjoutLigne', {id: id, MODULE : MODULE})~"')", {}, true, 'ajout', '','addLignePlanning', 'padding: 10px 10px 10px 10px;background-position: 4px 3px;margin-left: 5px;') }}
                            </td>
                        </tr>
                        {% endif %}
                    </tbody>
                </table>
                <div class="modal-footer">
                    <input type="hidden" name="planning_QTE_DEM" id="planning_QTE_DEM" value="{{ ligneDocument.QTE_DEM }}" />
                    <input type="hidden" name="planning_QteConditionnement" id="planning_QteConditionnement" value="{{ ligneDocument.QteConditionnement }}" />
                    <input type="hidden" name="planning_ValeurUniteDAArticle" id="planning_ValeurUniteDAArticle" value="{{ ligneDocument.ValeurUniteDAArticle }}" />
                    <input type="hidden" name="planning_UNITE" id="planning_UNITE" value="{{ ligneDocument.UNITE }}" />
                    <input type="hidden" name="planning_uniteArticle" id="planning_uniteArticle" value="{{ ligneDocument.uniteArticle }}" />
                    <input type="hidden" name="planning_dateDebContrat" id="planning_dateDebContrat" value="{{ ligneDocument.DATEDEBCONT }}" />
                    <input type="hidden" name="planning_dateFinContrat" id="planning_dateFinContrat" value="{{ ligneDocument.DATEFINCONT }}" />
                    <input type="hidden" name="planning_ReceptionAuto" id="planning_ReceptionAuto" value="{{ ligneDocument.RECEP_AUTO | boolSql }}" />
                    <input type="hidden" id="lastIndex" value="{{ index }}" />
                    <button type="button" class="button secondaire" data-dismiss="modal" onclick="desactivePopup ();">{{ 'Annuler' | trad }}</button>
                    <button type="button" class="button principal" id="btnEnreg"  onclick="sendForm('form_bloc_notes');">{{ 'Enregistrer' | trad }}</button>
                </div>
            </form>
	    </div>
	</div>
    

{% endblock %}