{% extends 'layout.twig' %}

{% block body %}

<script type="text/javascript" src="{{ baseUrl('js/Modules/DemandeAchat/Signature.js') }}"></script>
<div class="contenu clearfix"  id="signatureDA">

	<h1>{{ 'Signature' | trad }}</h1>

	
	{{ ariane() }}

	{{ onFocus('signDA') }}

	{% if delegAbs %}
		<script>
			ajaxPopup('{{path('GlobalApplication.Delegation.popupDelegEnCours')}}', '');
		</script>
	{% endif %}

	<form method="post" name="filtre_demandeAchat" id="filtre_demandeAchat">

		<div class="bs-row flex-y-center">

				{% if signataire %}
					<h2>{{ 'Demandes d\'achat à signer de' }} : {{ convertLibelleGlobal('Hastutil', '', signataire, true) }}</h2>
				{% else %}
					<h2>{{ 'Vos demandes d\'achat à signer' | trad }}</h2>
				{% endif %}

			<div class="bs-col flex-y-center text-right" data-toolbox style="display: none">
				<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>
	
	
		<input type="hidden" name="listDA" id="listDA" value="" />                             
		<input type="hidden" name="DELEG" id="DELEG" value="{{ post.DELEG }}" />                             
		<table class="table table-hover">
			<thead class="thead-dark">
				<tr>
					<th scope="col" width="100px">{{ triTable('NO_DA',  infoPagination.filter.tri_NO_DA, 'Numéro' | trad, '', '', 'filtre_demandeAchat') }}</th>
					<th scope="col" width="15%">{{ triTable('FOU',  infoPagination.filter.tri_FOU, 'Fournisseur' | trad, '', '', 'filtre_demandeAchat') }}</th>
					<th scope="col" width="100px">{{ triTable('CODE_STE',  infoPagination.filter.tri_CODE_STE, 'Société' | trad, '', '', 'filtre_demandeAchat') }}</th>
					<th scope="col">{{ triTable('NO_DEM',  infoPagination.filter.tri_NO_DEM, 'Demandeur' | trad, '', '', 'filtre_demandeAchat') }}</th>
					{% if param.SI_VISIBLE %}
						<th scope="col">{{ triTable('SECTIMP',  post.tri_SECTIMP, 'Section d\'imputation' | trad, '', '', 'filtre_suivi') }}</th>
					{% endif %}
					<th class="align-center" scope="col" width="110px">{{ triTable('DTE_EMISS',  infoPagination.filter.tri_DTE_EMISS, 'Date émission' | trad, '', '', 'filtre_demandeAchat') }}</th>
					<th class="align-right" scope="col" width="8%">{{ triTable('TOTAL_DA',  infoPagination.filter.tri_TOTAL_DA, 'Total HT' | trad, '', '', 'filtre_demandeAchat') }}</th>
					<th class="align-right" scope="col" width="8%">{{ triTable('TOTAL_DA_TTC',  infoPagination.filter.tri_TOTAL_DA_TTC, 'Total TTC' | trad, '', '', 'filtre_demandeAchat') }}</th>
					<th width="60px">{{ 'Infos' | trad }}</th>
					<th scope="col" class="align-center white-tooltip" 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 width="100px"></th>
					<th scope="col" width="40px">{{ 'Actions' | trad }}</th>
				</tr>
			</thead>
			<tbody>
				<tr class="recherche">
					<td>{{ filterTable('NO_DA', infoPagination.filter.filter_NO_DA, '', '', '', 'filtre_demandeAchat', '', '') }}</td>
					<td>{{ zoomFilter('FOU', infoPagination.filter['filter_FOU'], '', 'filtre_demandeAchat', path('Ajax.liste.fournisseur'), 'Liste des fournisseurs', '','','','','','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('NO_DEM', infoPagination.filter['filter_NO_DEM'], '', 'filtre_demandeAchat', path('Ajax.liste.demandeur'),'Liste des demandeurs', '','','','','','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('date_DTE_EMISS', infoPagination.filter.filter_date_DTE_EMISS, '', '', '', 'filtre_demandeAchat', 'date', '') }}</td>
					<td>{{ filterTable('TOTAL_DA', infoPagination.filter.filter_TOTAL_DA, '', '', '', 'filtre_demandeAchat', '', '') }}</td>
					<td>{{ filterTable('TOTAL_DA_TTC', infoPagination.filter.filter_TOTAL_DA_TTC, '', '', '', 'filtre_demandeAchat', '', '') }}</td>
					<td></td>
					<td></td>
					<td></td>
					<td></td>
				</tr>
			{% for demandeAchat in listeDA %}
				<tr id="demandeAchat{{ loop.index }}"  class="signDA{{demandeAchat.NO_DA}}focus">
					<td class="toggleSlide align-right code" onclick="toggleSlide('{{ path('Suivi.SuiviDa.ajaxDetails', {idDoc : demandeAchat.NO_DA, source : 'DA', 'context' : 'signature'}) }}' , 'demandeAchat{{ loop.index }}detail');">{{ demandeAchat.NO_DA }}</td>
					<td>{{ demandeAchat.RS }} {% if demandeAchat.FOU | trim %}({{ demandeAchat.FOU }}){% endif %}</td>
					<td>
						<span class="white-tooltip">
							{{ demandeAchat.CODE_STE }}
							<span class="infos_tooltip top-left">
								{{demandeAchat.RAIS_SOC}}
							</span>
						</span>
					</td>
					<td>{{ demandeAchat.demandeur }} {% if demandeAchat.NO_DEM | trim %}({{ demandeAchat.NO_DEM }}){% endif %}</td>
					{% if param.SI_VISIBLE %}
						<td>{% if demandeAchat.SECTIMP %}{{ demandeAchat.LIB_SI }} ({{ demandeAchat.SECTIMP }}){% endif %}</td>
					{% endif %}
					<td class="align-center">{{ demandeAchat.DTE_EMISS| dateTrad }}</td>
					<td class="align-right">{{ demandeAchat.TOTAL_DA | prix }} {{ demandeAchat.DEVISE }}</td>
					<td class="align-right">{{ demandeAchat.TOTAL_DA_TTC | prix }} {{ demandeAchat.DEVISE }}</td>
					<td>
						{% if demandeAchat.DOC_ATT>0 %}    	
							<a href="{{ path('GlobalApplication.DocumentRattaches.document', {MODULE:'DemandeAchat',id:demandeAchat.NO_DA}) }}" class="documents_attaches white-tooltip">
								<span class="infos_tooltip top-left">
									{{ 'Présence de documents rattachés pour cette demande d\'achat. Cliquer pour les visualiser' | trad }}
								</span>
							</a>
						{% endif %}
						{% if demandeAchat.PJ>0 %}    	
							<a href="{{ path('DemandeAchat.PieceJointe.index', {idDA:demandeAchat.NO_DA}) }}" class="pieces_jointes white-tooltip">
								<span class="infos_tooltip top-left">
									{{ 'Présence de pièces-jointes pour cette demande d\'achat. Cliquer pour les visualiser.' | trad }}
								</span>
							</a>
						{% endif %}
					</td>
					<td class="align-center">
						<input class="form-control checkbox" type="checkbox" name="selection[]" value="{{ demandeAchat.NO_DA }}"data-checkall="main"/>
					</td>
					<td>
						<a style="cursor:pointer;" class="button principal " onclick="popupSign('S', '{{ demandeAchat.NO_DA }}')">{{ 'Signer' | trad }}</a>
					</td>
					<td class="text-center parametrage">
						{{ menuContextuel('demandeAchat'~loop.index, false, demandeAchat.menuContextuel) }}
					</td>
				</tr>
				<tr id="demandeAchat{{ loop.index }}detail" class="detail_ligne hide_detail">
				</tr>
			{% endfor %}
			</tbody>
		</table>
		
		{{ paginations(path('Signature.SignatureDa.listeDoc', {'signataire' : signataire }),infoPagination.nombreDePage, infoPagination.page, infoPagination.post, '') }}
	</form>
</div>
<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.SignatureDa.popupSignature',{mode:'S', 'signataire' : signataire}),
	'pathR' : path('Signature.SignatureDa.popupSignature',{mode:'R', 'signataire' : signataire}),
} %}
{% endblock %}