{% block body %}

<td colspan="11"  id="ligneAffichage{{ id }}">
    <article>
        
		<h5>
			{% if entete.REFUSEE|boolSql == 1  %}
			{{ 'Refusée' | trad }}
			{% elseif entete.ATT_SIG|boolSql == 1  %}
			{{ 'En attente de signature' | trad }}
			{% elseif entete.BON_A_PAY|boolSql == 1  %}
			{{ 'Signée' | trad }}
			{% endif %}
		</h5>
		
        <div class="colonne3">
            <div class="informations">
            	<p>
            		<span class="champs_label">{{ 'Créateur' | trad }}</span>
            		{% if entete.CODE == '' %}
            		<span class="resultat">{{ entete.FAC_CBY }}</span>
                	{% else %}
                	<span class="resultat">{{ entete.NOM | convert_encoding('UTF-8', 'ISO-8859-1')}} {% if entete.CODE | trim %}({{ entete.CODE }}){% endif %}</span>
                    {% endif %}
            	</p>
                <p>
                	<span class="champs_label">{{ 'Echéance' | trad }}</span>
                	<span class="resultat">{{ entete.DTAE_ECH | dateTrad }}</span>
                </p>
                <p>
                	<span class="champs_label">{{ 'Total TVA' | trad }}</span>
                	<span class="resultat">{{ (entete.TOTAL_TTC - entete.TOTAL_HT) | prix }} {{ entete.DEVISE }}</span>
                </p>
				{% if entete.DATESCAN != '00000000' %}
                <p>
                	<span class="champs_label">{{ 'Date numérisation' | trad }}</span>
                	<span class="resultat">{{ entete.DATESCAN | dateTrad }}</span>
                </p>
				{% endif %}				
            </div>
        </div>
        <div class="colonne3">
            <div class="informations">
            	<p>
            		<span class="champs_label">{{ 'Libellé comptable' | trad }}</span>
                	<span class="resultat">{{ entete.LIB_COMPT }}</span>
            	</p>
                <p>
            		<span class="champs_label">{{ 'Dernier règlement' | trad }}</span>
                	<span class="resultat">{{ entete.DTE_DERNREG | dateTrad }}</span>
            	</p>
            	<p>
                	<span class="champs_label">{{ 'Montant total réglé' | trad }}</span>
                	<span class="resultat">{{ entete.MT_TOTREG | prix }} {{ entete.DEVISE }}</span>
                </p>
            </div>
        </div>
        <div class="colonne3">
            <div class="informations">
            	<p>
            		<span class="champs_label">{{ 'Entête' | trad }}</span>
                	<span class="resultat">
                        {% if entete.ENT_COMPT|boolSql == true %}{{ 'En compta' | trad }}
                        {% elseif entete.ENT_VALID|boolSql == true %}{{ 'Validée' | trad }}
                        {% endif %}
                    </span>
            	</p>
                <p>
                	<span class="champs_label">{{ 'Affectation' | trad }}</span>
                	<span class="resultat">
                	    {% if entete.AFF_COMPT|boolSql == true %}{{ 'En compta' | trad }}
                        {% elseif entete.AFF_VALID|boolSql == true %}{{ 'Validée' | trad }}
                        {% endif %}
                   </span>
                </p>
                <p>
                	<span class="champs_label">{{ 'BAP' | trad }}</span>
                	<span class="resultat">
                	    {% if entete.BON_A_PAY|boolSql == true %}
                	        {{ entete.DATE_BAP | dateTrad }}
                	    {% endif %}
                        {% if entete.BAP_COMPT|boolSql == true %}',{{ 'En compta' | trad }}
                        {% endif %}
                   </span>
                </p>
                <p>
                	<span class="champs_label">{{ 'Cdes lues en LAD' | trad }}</span>
                	<span class="resultat">
						{{ entete.CDE_LAD |slice(1)  }}
                   </span>
                </p>
            </div>
		</div>
	</article>
	{% if CSExist('FAC_ENT') %}
	<article>
		{{ VisualisationCS('FAC_ENT', codeEnrCs, null, null, 'colonne2', entete.CODE_STE) }}
	</article>
	{% endif %}
    <table class="table table-hover">
    	<thead>
    		<tr>
				{% if easyDemat == 0 %}
    			<th scope="col">{{ 'Cde' | trad }}</th>
    			<th scope="col">{{ 'BR' | trad }}</th>
				{% endif %}
    			<th scope="col">{{ 'Code article' | trad }}</th>
    			<th scope="col">{{ 'Désignation' | trad }}</th>
				{% if easyDemat == 0 %}
					{% if params.IS_EXPE_ACTIVE %}
					<th scope="col">{{ 'Expédition !' | trad }}</th>
					{% endif %}
					{% if params.IS_TP_ACTIVE %}
					<th scope="col">{{ 'TP' | trad }}</th>
					{% endif %}
				{% endif %}
    			<th scope="col">{{ 'Quantité' | trad }}</th>
    			<th scope="col">{{ 'PU remisé' | trad }}</th>
    			<th scope="col">{{ 'Montant' | trad }}</th>
    			<th scope="col">{{ 'Section d\'imputation' | trad }}</th>
				{% if params.IS_CG_ACTIVE %}
				<th scope="col">{{ 'Code gestion' | trad }}</th>
				{% endif %}
    			<th scope="col">{{ 'Code Complémentaire' | trad }}</th>
    			<th scope="col">{{ 'Sous-Compte d\'analyse' | trad }}</th>
				<th scope="col">{{ 'Profil TVA' | trad }}</th>
            </tr>
        </thead>
        <tbody>
		{% for ligne in lignes %}
			<tr id="fac{{loop.index}}">
				{% if easyDemat == 0 %}
				<td class="montant">{{ ligne.NUM_CDE~' '~ligne.NUM_LICDE }}</td>
				<td class="montant">{{ ligne.NUM_BR~' '~ligne.NUM_LIBR  }}</td>
				{% endif %}
				<td class="ss_detail" onClick='SSDetail(this);'>
					{{- ligne.CODE_ART -}}
				</td>
				<td>{{ ligne.DESIGNAT  | convert_encoding('UTF-8', 'ISO-8859-1')}}</td>
				{% if easyDemat == 0 %}
					{% if params.IS_EXPE_ACTIVE %}
					<td>{{ ligne.NUM_EXP }}</td>
					{% endif %}
					{% if params.IS_TP_ACTIVE %}
					<td>{{ ligne.NUM_TERME }}</td>
					{% endif %}
				{% endif %}
				<td class="montant">{{ ligne.QUANTITE|number_format(3, '.', ' ') }} </td>
				<td class="montant">{{ ligne.PU_REMISE | prix }}&nbsp;{{ entete.DEVISE }} </td>
				<td class="montant">{{ ligne.MONTANT | prix }}&nbsp;{{ entete.DEVISE }}</td>
				<td class="">{{ ligne.CODE_SI }}</td>
				{% if params.IS_CG_ACTIVE %}
				<td class="">{{ ligne.CODE_AFF ?? ligne.ID_CG }}</td>
				{% endif %}
				<td class="">{{ ligne.CODE_CDC }}</td>
				<td class="">{{ ligne.CODE_SCA }}</td>
				<td class="">{{ ligne.CODE_PROFIL_TVA }}</td>
			</tr>
			<tr class="detail_ligne hide_detail" id="fac{{loop.index}}detail">
				<td colspan="99">
					<div class="colonne2">
						<div class="informations"><p>
							<p>
								<span class="champs_label">{{ 'Sous-famille' | trad }}</span>
								<span class="resultat">{{ ligne.DESIGNAT }} {{ ligne.SSFAM? '('~ligne.SSFAM~')':'' }}</span>
							</p>
						</dl>
					</div>
					{{ VisualisationCS('FAC_LIG', ligne.codeCs, null, null, 'colonne2', ligne.CODE_STE) }}
				</td>
			</tr>
		{% endfor %}
        </tbody>
    </table>
    {% if nombreEnregistrement > 1 and affichage == 'notAll' %}
    <div class="lignes_supplementaires" onclick="plusDeLignes('{{ path('Facture.ajax.ligneFacture', {numFact: id}) }}','{{ id }}')">
    	<span class="voir_plus">{{ 'Tout afficher' | trad }} ({{ nombreEnregistrement~' '~('lignes' | trad) }})</span>
    </div>
    {% endif %}
</td>
<script>
function facLigneDetail_ajustColspan(row) {
	row.setAttribute(
		'colspan',
		row
			.closest('table')
			.querySelector('thead>tr')
			.children.length
	);
}
facLigneDetail_ajustColspan(document.getElementById('ligneAffichage{{ id }}'));

function plusDeLignes(path, id)
{
	$.ajax({
	  	dataType : 'html',
  		url: path,
  		data: {'id' : id, 'affichage' : 'all'},
  		type: "POST",
  		success: function(htmlData){
  			var result = $('<div />').append(htmlData).find('#ligneAffichage'+id).html();
            $('#ligneAffichage'+id).html(result);
  		}
  	});
}

ResizableColumns();
</script>
{% endblock %}

