equipment/snippets/user_details.html
2025-10-27 12:11:29 +01:00

169 lines
4.9 KiB
HTML

{{* -*- brindille -*- *}}
{{#restrict section="users" level="read"}}{{/restrict}}
{{* lecture config (défaut ou enregistrée) *}}
{{:include file="../_get_config.html" keep="config, directions"}}
{{#foreach from=$directions key="direction"}}
{{:assign var="nature" from="config.%s_nature"|args:$direction}}
{{#foreach from=$nature key=key}}
{{:assign var="types.%s.%s."|args:$direction:$type value=$key|quote_sql}}
{{/foreach}}
{{:assign var="io_types" from="types.%s"|args:$direction}}
{{#foreach from=$io_types key=key}}
{{:assign var=elem from="io_types.%s"|args:$key}}
{{:assign elem=$elem|implode:","}}
{{:assign elem="("|cat:$elem|cat:")"}}
{{:assign var="%s_types.%s"|args:$direction:$key value=$elem}}
{{/foreach}}
{{/foreach}}
{{*
vérifier l'existence de la table du module
eh oui, il se peut qu'elle ne soit pas encore créée si aucune donnée n'a été ajoutée dedans
*}}
{{#load limit="1"}}
{{:assign table_presente=true}}
{{else}}
{{:assign table_presente=false}}
{{/load}}
{{if $table_presente}}
{{* Matériels attribués temporairement *}}
{{* vérifier la présence des types d'entrées et de sorties requis *}}
{{if $output_types|has_key:"temporaire" && $input_types|has_key:"retour"}}
{{*
Calculer les quantités de matériel en prêt
*}}
{{:assign premier=true}}
{{#select
json_extract(mvt.document, '$.direction') AS direction,
json_extract(mvt.document, '$.date') AS date,
eqpmt.key as eqpmt_key,
json_extract(eqpmt.document, '$.name') AS eqpmt_name,
json_extract(mvt.document, '$.amount') AS qte,
json_extract(mvt.document, '$.operation') AS operation
FROM {!$module.table} AS mvt
INNER JOIN users ON json_extract(mvt.document, '$.user') = users.id
INNER JOIN {!$module.table} AS eqpmt ON json_extract(mvt.document, '$.equipment') = eqpmt.key
WHERE
users.id = :user
AND
json_extract(mvt.document, '$.type') = 'movement'
AND
(json_extract(mvt.document, '$.operation') IN !output_types
OR
json_extract(mvt.document, '$.operation') IN !input_types)
ORDER BY eqpmt_name, date
;
:user = $user.id
!output_types=$output_types.temporaire
!input_types=$input_types.retour
}}
{{if $premier}}
{{:assign premier=false}}
{{:assign total=0}}
{{:assign old_eqpmt_key=$eqpmt_key}}
{{:assign var="ligne.date" value=$date}}
{{:assign var="ligne.materiel" value=$eqpmt_name}}
{{/if}}
{{if $eqpmt_key != $old_eqpmt_key}}
{{if $total > 0}}
{{:assign var="ligne.qte" value=$total}}
{{:assign var="lignes." value=$ligne}}
{{/if}}
{{:assign total=0}}
{{:assign old_eqpmt_key=$eqpmt_key}}
{{:assign var="ligne.date" value=$date}}
{{:assign var="ligne.materiel" value=$eqpmt_name}}
{{/if}}
{{if $direction == "output"}}
{{:assign total="%d+%d"|math:$total:$qte}}
{{else}}
{{:assign total="%d-%d"|math:$total:$qte}}
{{/if}}
{{/select}}
{{if $total > 0}}
{{:assign var="ligne.qte" value=$total}}
{{:assign var="lignes." value=$ligne}}
{{/if}}
{{if $lignes|count > 0}}
<h3 class="ruler">Matériels attribués temporairement</h3>
<table class="list" id="liste_temporaires">
<thead>
<tr>
<th>Date</th>
<th>Matériel</th>
<th>Quantité</th>
</tr>
</thead>
<tbody>
{{#foreach from=$lignes}}
<tr>
<td>{{$date|date_short}}</td>
<td>{{$materiel}}</td>
<td>{{$qte}}</td>
</tr>
{{/foreach}}
</tbody>
</table>
{{/if}}
{{/if}}
{{* Matériels attribués définitivement *}}
{{* vérifier la présence des types de sorties requis *}}
{{if $output_types|has_key:"définitif"}}
{{#select
eqpmt.key as eqpmt_key,
json_extract(eqpmt.document, '$.name') as eqpmt_name,
json_extract(mvt.document, '$.direction') as direction,
json_extract(mvt.document, '$.operation') as operation,
MIN(json_extract(mvt.document, '$.date')) as date,
SUM(json_extract(mvt.document, '$.amount')) as amount
FROM {!$module.table} AS mvt
INNER JOIN users ON json_extract(mvt.document, '$.user') = users.id
INNER JOIN {!$module.table} AS eqpmt
ON json_extract(mvt.document, '$.equipment') = eqpmt.key
WHERE users.id = :user
AND json_extract(mvt.document, '$.operation') IN !output_types
GROUP BY eqpmt_key, operation
ORDER BY eqpmt_name, date
;
:user = $user.id
!output_types=$output_types.définitif
assign="def_mat."
}}
{{/select}}
{{/if}}
{{if $def_mat|count != 0}}
<h3 class="ruler">Matériels attribués définitivement</h3>
<table class="list">
<thead>
<tr>
<th>Date</th>
<th>Matériel</th>
<th>Opération</th>
<th>Quantité</th>
</tr>
</thead>
<tbody>
{{#foreach from=$def_mat}}
{{:assign var="op_label" from="config.%s_nature.%s.label"|args:$direction:$operation}}
<tr>
<td>{{$date|date_short}}</td>
<td>{{$eqpmt_name}}</td>
<td>{{$op_label}}</td>
<td>{{$amount}}</td>
</tr>
{{/foreach}}
</tbody>
</table>
{{/if}}
{{/if}}