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

{% block body %}
	<div id="genetableau">
		<center>
			<div>
				<form method="POST" id='formulaireListeSociete'>
					<input type="hidden" name="divCode" value="{{ post.divCode }}" />
					<input type="hidden" name="divLibelle" value="{{ post.divLibelle }}" />
					<table class="table" id="tableau">
						<thead class="thead-dark">
						<tr>
							<th>{{ triTable('CODE_STE',  infoPagination.filter.tri_CODE_STE, 'Code' | trad, 'genetableau', path('Ajax.liste.societe', {action:action}), 'formulaireListeSociete') }}</th>
							<th>{{ triTable('RAIS_SOC',  infoPagination.filter.tri_RAIS_SOC, 'Raison Sociale' | trad,'genetableau', path('Ajax.liste.societe', {action:action}), 'formulaireListeSociete') }}</th>
						</tr>
						</thead>
						<tbody>
							<tr>
								<th>{{ filterTable('CODE_STE', infoPagination.filter.filter_CODE_STE, '', 'genetableau', path('Ajax.liste.societe', {action:action}), 'formulaireListeSociete') }}</th>
								<th>{{ filterTable('RAIS_SOC', infoPagination.filter.filter_RAIS_SOC, '', 'genetableau', path('Ajax.liste.societe', {action:action}), 'formulaireListeSociete') }}</th>
							</tr>
							{% for societe in societes %}
								{% if action == 'changementSte' %}

									{% set onClick=attrJs('ajaxPopupV2', [
										path('Utilisateur.MaSession.ajaxChangementSociete', {codeSte:societe.CODE_STE}),
										'',
									]) %}
								{% else %}
									{% set dataAttr = {} 
										| merge((societe.ca_modenum is defined 
											? {'ca_modenum': societe.ca_modenum} 
											: {}))
										| merge((societe.da_modenum is defined 
											? {'da_modenum': societe.da_modenum} 
											: {}))
									%}
									{% set onClick=attrJs('changeCodeLibelleSoc', [
													post.divCode,
													societe.CODE_STE, 
													post.divLibelle,
													societe.RAIS_SOC~' ('~societe.CODE_STE~')',
													dataAttr
												])  %}
								{% endif %}
						
								<tr onclick="{{ onClick | raw }}">
									<td id ="{{societe.CODE_STE}}">{{ societe.CODE_STE   | convert_encoding('UTF-8', 'ISO-8859-1') }}</td>
									<td>{{ societe.RAIS_SOC  | convert_encoding('UTF-8', 'ISO-8859-1') }}
								
									</td>
				
								</tr>
							{% endfor %}
						</tbody>
					</table>
				</form>
				{{ paginations(path('Ajax.liste.societe', {action:action}),infoPagination.nombreDePage, infoPagination.page, infoPagination.post, 'modal-body') }}
			</div>
		</center>
		<script>
			function changementSociete(codeValue)
			{

			}
			function changeCodeLibelleSoc(inputId, codeValue, divLibelle, libelleValue, mapAttr)
			{
				let target = document.getElementById(inputId);
				for(k in mapAttr) {
					target.setAttribute('data-'+k, mapAttr[ k ]);
				}

				changeCodeLibelle(inputId, codeValue, divLibelle, libelleValue);
				desactivePopup();
			}
		</script>
	</div>

{% endblock %}
