{% extends 'layout.twig' %}

{% block body %}

<section class="contenu">

	<h1>{{ 'Signature' | trad }}</h1>
	
	{{ ariane() }}

	{{ onFocus('signCde') }}

	{% if delegAbs %}
		<script>
			ajaxPopup('{{path('GlobalApplication.Delegation.popupDelegEnCours')}}', '');
		</script>
	{% endif %}
	
	<form method="post" name="form_main" id="form_main">
		<div class="bs-row flex-y-center">

			{% if signataire %}
				<h2>{{ 'Commandes à signer de' }} : {{ convertLibelleGlobal('Hastutil', '', signataire, true) }}</h2>
			{% else %}
            	<h2>{{ 'Vos commandes à signer' | trad }}</h2>
			{% endif %}

            <div class="bs-col flex-y-center text-right fade-in" data-toolbox style="display: none">
                {# TODO : show/hide depending on table row selection #}
                <button type="button" class="secondaire" onclick="popupSign('R')">{{- 'Refuser' | trad -}}</button>
                <button type="button" class="principal mr-0" onclick="popupSign('S')">{{- 'Signer' | trad -}}</button>
            </div>
        </div>

		<table class="table table-hover">
			<thead class="thead-dark">
				<tr>
					<th scope="col" width="100px">{{ triTable('NO_CDE',  infoPagination.filter.tri_NO_CDE, 'Numéro' | trad, '', '', 'form_main') }}</th>
					<th scope="col" width='15%'>{{ triTable('CODE_FOU',  infoPagination.filter.tri_CODE_FOU, 'Fournisseur' | trad, '', '', '', 'form_main') }}</th>
					<th scope="col" width='100px'>{{ triTable('CODE_STE',  infoPagination.filter.tri_CODE_STE, 'Société' | trad, '', '', 'form_main') }}</th>
					<th scope="col">{{ triTable('ACH',  infoPagination.filter.tri_ACH, 'Acheteur' | trad, '', '', 'form_main') }}</th>
					{% if param.SI_VISIBLE %}
						<th scope="col">{{ triTable('SECTIMP',  post.tri_SECTIMP, 'Section d\'imputation' | trad, '', '', 'filtre_suivi') }}</th>
					{% endif %}
					<th scope="col">{{ triTable('OBJET_CA',  infoPagination.filter.tri_OBJET_CA, 'Objet' | trad, '', '', 'form_main') }}</th>
					<th scope="col" width='110px'>{{ triTable('DTE_CREAT',  infoPagination.filter.tri_DTE_CREAT, 'Date création' | trad, '', '', 'form_main') }}</th>
					<th colspan="2" scope="col" width='8%'>{{ triTable('TOT_CDEHT',  infoPagination.filter.tri_TOT_CDEHT, 'Total HT' | trad, '', '', 'form_main') }}</th>
					<th colspan="2" scope="col" width='8%'>{{ triTable('TOT_TTC',  infoPagination.filter.tri_TOT_TTC, 'Total TTC' | trad, '', '', 'form_main') }}</th>
					<th scope="col" width="60px">{{ 'Infos' | trad }}</th>
					<th scope="col" width="1%">
						<span class="infos_tooltip left">
                            {{ 'Tout sélectionner' | trad }}
                        </span>
                        <input type="checkbox"
                            class="form-control checkbox"
                            data-checkall-input="main"
                        />
					</th>
					<th scope="col" width="100px" ></th>
					<th scope="col" width="40px" >{{ 'Actions' | trad }}</th>
				</tr>
			</thead>
			<tbody>
				<tr class="recherche">
					<td>{{ filterTable('NO_CDE', infoPagination.filter.filter_NO_CDE, '', '', '', 'form_main', '', '') }}</td>
					<td>{{ zoomFilter('CODE_FOU'~spliter()~'RS', infoPagination.filter['filter_CODE_FOU'~spliter()~'RS'], '', 'form_main', path('Ajax.liste.fournisseur'), 'Liste des fournisseurs' | trad, '','', 'Fournisseur' | trad,'','','libelle_Fourniss') }}</td>
					<td>{{ zoomFilter('egal_CODE_STE'~spliter()~'RAIS_SOC', infoPagination.filter['filter_egal_CODE_STE'~spliter()~'RAIS_SOC'], '', 'form_main', path('Ajax.liste.societe'),'Liste des sociétés' | trad, '','','Société' | trad,'','','libelle_Societe') }}</td>
					<td>{{ zoomFilter('ACH'~spliter()~'NOM', infoPagination.filter['filter_ACH'~spliter()~'NOM'], '', 'form_main', path('Ajax.liste.utilisateur'), 'Liste des acheteurs' | trad, '','', 'Acheteur' | trad,'','','Hastutil') }}</td>
					{% if param.SI_VISIBLE %}
						<td>{{ zoomFilter('SECTIMP', post['filter_SECTIMP'], '', 'filtre_suivi', path('Ajax.liste.si'),'Liste des sections d\'imputation' | trad |e('js')|raw, '','','sections d\'imputation' | trad |e('js')|raw,'','','Sectimpu') }}</td>
					{% endif %}
					<td>{{ filterTable('OBJET_CA', infoPagination.filter.filter_OBJET_CA, '', '', '', 'form_main', '', '') }}</td>
					<td>{{ filterTable('date_DTE_CREAT', infoPagination.filter.filter_date_DTE_CREAT, '', '', '','form_main', 'date','Créer le') }}</td>
					<td colspan="2">{{ filterTable('TOT_CDEHT', infoPagination.filter.filter_TOT_CDEHT, '', '', '', 'form_main', '', '') }}</td>
					<td colspan="2">{{ filterTable('TOT_TTC', infoPagination.filter.filter_TOT_TTC, '', '', '', 'form_main', '', '') }}</td>
					<td>{# Info #}</td>
					<td colspan="2">{# Signer #}</td>
					<td>{# Actions #}</td>
				</tr>
			</tbody>
			{% for commande in listeCde %}
				<tr id="commande{{ loop.index }}" class="signCde{{commande.NO_CDE}}focus">
					<td class="montant toggleSlide code align-right" onclick="toggleSlide('{{ path('Suivi.SuiviCde.ajaxDetails', {idDoc : commande.NO_CDE, source : 'CDE', 'context' : 'signature'}) }}','commande{{ loop.index }}detail')"
					>{{ commande.NO_CDE }} {% if commande.AVENANT %}- {{ commande.AVENANT }}{% endif %}</td>
					<td style="cursor:pointer;" 
						onclick="activeLoader();document.location.href='{{ path('Commande.Commande.article', {idCommande : commande.NO_CDE}) }}'"
					>{{ commande.RS }} ({{ commande.CODE_FOU }})</td>
					<td>
						<span class="white-tooltip">
							{{ commande.CODE_STE }}
							<span class="infos_tooltip top-left">
								{{commande.Societe_RAIS_SOC}}
							</span>
						</span>
					</td>
					
					<td>{{ commande.NOM }} ({{ commande.ACH }})</td>
					{% if param.SI_VISIBLE %}
						<td>
						{% if commande.SECTIMP %}
						<span class="white-tooltip">
							{{ commande.SECTIMP }}
							<span class="infos_tooltip top-left">
								{{commande.LIB_SI}}
							</span>
						</span>
						{% endif %}
						</td>
					{% endif %}
					<td>{{ shortLibelle(commande.OBJET_CA,20) }}</td>
					<td>{{ commande.DTE_CREAT | dateTrad }}</td>
					<td class="montant">{{ commande.TOT_CDEHT | tva}}</td>
					<td>{{ commande.DEVISE }}</td>
					<td class="montant">{{ commande.TOT_TTC | tva}}</td>
					<td>{{ commande.DEVISE }}</td>
					<td class="text-center">
						{% if commande.DOC_ATT>0 %}    	
							<a href="{{ path('GlobalApplication.DocumentRattaches.document', {MODULE:'Commande',id:commande.NO_CDE}) }}" class="documents_attaches white-tooltip">
								<span class="infos_tooltip top-left">
									{{ 'Présence de documents rattachés pour cette commande. Cliquer pour les visualiser' | trad }}
								</span>
							</a>
						{% endif %}
						{% if commande.PJ>0 %}    	
							<a href="{{ path('Commande.PieceJointe.index', {idCommande:commande.NO_CDE}) }}" class="pieces_jointes white-tooltip">
								<span class="infos_tooltip top-left">
									{{ 'Présence de pièces-jointes pour cette commande. Cliquer pour les visualiser.' | trad }}
								</span>
							</a>
						{% endif %}
					</td>
					<td>
						<input class="form-control checkbox" type="checkbox" name="selection[]" value="{{ commande.NO_CDE }}" data-checkall="main"/>						
					</td>
					<td>
						<button class="principal" type="button" onclick="popupSign('S', '{{ commande.NO_CDE }}')">{{ 'Signer' | trad }}</button>
					</td>
					<td class="parametrage">
                        {{ menuContextuel('commande'~loop.index, false, commande.menuContextuel, 8) }}
					</td>
				</tr>
				<tr id="commande{{ loop.index }}detail" class="detail_ligne hide_detail">
				</tr>
			{% endfor %}
		</table>
		{{ paginations('',infoPagination.nombreDePage, infoPagination.page, infoPagination.post, '') }}
	
	</form>

</section>
<script>
// Show/hide toolbox
document.addEventListener('change', function(event) {
	let toolbox = document.querySelector('[data-toolbox]');
	// Case : at least one row is selected
	if (document.querySelectorAll('[name="selection[]"]:checked').length != 0) {
		toolbox.style.display = '';
	} else {
		toolbox.style.display = 'none';
	}
});
</script>

{% include '@signature/global/_script.twig' with {
    'pathS' : path('Signature.SignatureCde.popupSignature',{mode:'S', 'signataire' : signataire}),
	'pathR' : path('Signature.SignatureCde.popupSignature',{mode:'R', 'signataire' : signataire})
	
} %}

{% endblock %}