199 lines
6.1 KiB
HTML
199 lines
6.1 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, '$.return_date') AS return_date,
|
|
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 nb_jours=0}}
|
|
{{:assign old_eqpmt_key=$eqpmt_key}}
|
|
{{:assign var="ligne.date" value=$date}}
|
|
{{:assign var="ligne.materiel" value=$eqpmt_name}}
|
|
{{:assign var="ligne.return_date" value=$return_date}}
|
|
{{:assign var="ligne.retard" value="0"}}
|
|
{{if $return_date != null}}
|
|
{{:assign ts_retour=$return_date|strtotime}}
|
|
{{:assign nb_jours="floor((%d-%d)/(60*60*24))"|math:$now:$ts_retour}}
|
|
{{:assign var="ligne.retard" value=$nb_jours}}
|
|
{{/if}}
|
|
{{/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 nb_jours=0}}
|
|
{{:assign old_eqpmt_key=$eqpmt_key}}
|
|
{{:assign var="ligne.date" value=$date}}
|
|
{{:assign var="ligne.materiel" value=$eqpmt_name}}
|
|
{{:assign var="ligne.return_date" value=$return_date}}
|
|
{{:assign var="ligne.retard" value="0"}}
|
|
{{if $return_date != null}}
|
|
{{:assign ts_retour=$return_date|strtotime}}
|
|
{{:assign nb_jours="floor((%d-%d)/(60*60*24))"|math:$now:$ts_retour}}
|
|
{{:assign var="ligne.retard" value=$nb_jours}}
|
|
{{/if}}
|
|
{{/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>
|
|
<th>Date de retour</th>
|
|
<th>Remarque</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
{{#foreach from=$lignes}}
|
|
<tr>
|
|
<td>{{$date|date_short}}</td>
|
|
<td>{{$materiel}}</td>
|
|
<td>{{$qte}}</td>
|
|
<td>{{$return_date|date_short}}</td>
|
|
<td>
|
|
{{if $retard < 0}}
|
|
{{:assign delai="abs(%d)"|math:$retard}}
|
|
{{"Reste %s jours"|args:$delai}}
|
|
{{elseif $retard >0 }}
|
|
{{:tag color="darkred" label="Retard %s jours"|args:$retard}}
|
|
{{else}}
|
|
{{:tag color="darkgreen" label="À rendre aujourdh'ui"}}
|
|
{{/if}}
|
|
</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}}
|