{{* -*- brindille -*- *}}

{{*
	inventaire des entrées/sorties des matériels temporaires
	paramètres
	- category_keys : catégories dont on veut faire l'inventaire
*}}

{{:admin_header title="Gestion des matériels" custom_css=$custom_css current="module_equipment"}}

{{* barre de navigation *}}
{{:include file="_nav.html" current="index" subcurrent="nonproprio"}}

{{* Extraire et compiler les infos de la base *}}
{{:include file="./_calcul_dispo.html" keep="cumul_mvt,category_keys,equipments"}}

{{* Afficher les résultats *}}
{{if $equipments === null}}
	<p class="block alert">Aucun matériel.</p>
{{else}}
	{{* Vérifier s'il y a au moins un matériel non propriété de l'asso *}}
	{{:assign mat_non_prop=false}}
	{{#foreach from=$equipments key=key item=eqpmt}}
		{{if $eqpmt|has_key:"nonproprio"}}
			{{:assign mat_non_prop=true}}
			{{:break}}
		{{/if}}
	{{/foreach}}

	{{if $mat_non_prop}}
		<h2>Matériels dont l'association n'est pas propriétaire</h2>

		<fieldset>
			{{* itérer sur les catégories *}}
			{{#foreach from=$cumul_mvt key="cat_key" item="cat_elem"}}

				{{* vérifier s'il y a des matériels dans cette catégorie *}}
				{{:assign present=false}}
				{{if $cat_elem|keys|has:"eqpmt"}}
					{{#foreach from=$cat_elem.eqpmt key="eqpmt_key" item="eqpmt"}}
						{{if $eqpmt.nonproprio !== null && $eqpmt.nonproprio !== 0}}
							{{:assign present=true}}
							{{:break}}
						{{/if}}
					{{/foreach}}
				{{/if}}

				{{if $present}}
					<h3>{{$cat_elem.name}}</h3>

					<table class="list">
						<thead>
							<tr>
								<th>Désignation</th>
								<th>Quantité</th>
								<th class="actions"></th>
							</tr>
						</thead>
						<tbody>

							{{* itérer sur les matériels de la catégorie *}}
							{{#foreach from=$cat_elem.eqpmt key="eqpmt_key" item="eqpmt"}}
								{{:assign keys=$eqpmt|keys}}
								{{if "nonproprio"|in:$keys && $eqpmt.nonproprio !== 0}}
									{{:assign dispo="%d-%d"|math:$eqpmt.stock:$eqpmt.exterieur}}
									<tr>
										<td>{{$eqpmt.designation}}</td>
										<td>{{$eqpmt.nonproprio}}</td>
										<td class="actions">
											{{if $eqpmt.nonproprio > 0}}
												{{:linkbutton
												label="Retour"
												href="mouvements/sorties/emprunte.html?key=%s&prop=0"|args:$eqpmt_key
												shape="history"
												target="_dialog"}}
											{{/if}}
											{{:linkbutton
											label="Entrée"
											shape="plus"
											href="mouvements/entrees/repertorie.html?key=%s&prop=0"|args:$eqpmt_key
											target="_dialog"}}
											{{:linkbutton
											label="Mouvements"
											href="%shistorique.html?key=%s&prop=0"|args:$module.url:$eqpmt_key
											shape="table"}}
											{{:linkbutton
											label="Modifier"
											href="modifier_materiel.html?key=%s&prop=0"|args:$eqpmt_key
											shape="edit"
											target="_dialog"}}
										</td>
									</tr>
								{{/if}}
							{{else}}
								<p class="block alert">Il n'y a aucun matériel dans cette catégorie.</p>
							{{/foreach}}
						</tbody>
					</table>
				{{/if}}
			{{/foreach}}
		</fieldset>
	{{/if}}
{{/if}}