diff --git a/snippets/user_details.html b/snippets/user_details.html
index b288eb2..ae4b346 100644
--- a/snippets/user_details.html
+++ b/snippets/user_details.html
@@ -30,83 +30,126 @@
{{/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, retourné et restant
+ *}}
+ {{:assign premier=true}}
{{#select
- eqpmt.key as eqpmt_key,
- json_extract(eqpmt.document, '$.name') as eqpmt_name,
mvt.key AS mvt_key,
- json_extract(mvt.document, '$.direction') as direction,
- json_extract(mvt.document, '$.operation') as operation,
- json_extract(mvt.document, '$.date') as date,
- json_extract(mvt.document, '$.amount') as amount
+ json_extract(mvt.document, '$.date') AS out_date,
+ json_extract(eqpmt.document, '$.name') AS eqpmt_name,
+ json_extract(mvt.document, '$.amount') AS qte,
+ IFNULL(SUM(json_extract(retour.document, '$.amount')), 0) AS return_amount,
+ json_extract(mvt.document, '$.operation') AS operation
FROM module_data_equipment AS mvt
INNER JOIN users ON json_extract(mvt.document, '$.user') = users.id
- INNER JOIN module_data_equipment AS eqpmt
- ON json_extract(mvt.document, '$.equipment') = eqpmt.key
- WHERE users.id = :user
- AND (json_extract(mvt.document, '$.operation') IN !output_types
- OR json_extract(mvt.document, '$.operation') IN !input_types)
- ORDER BY date
+ LEFT JOIN module_data_equipment AS links ON mvt.key = json_extract(links.document, '$.temp_key')
+ LEFT JOIN module_data_equipment AS retour ON retour.key = json_extract(links.document, '$.return')
+ INNER JOIN module_data_equipment 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
+ GROUP BY mvt.key
+ ORDER BY eqpmt_name, json_extract(mvt.document, '$.date')
;
:user = $user.id
!output_types=$output_types.temporaire
- !input_types=$input_types.retour
- assign="temp_mat."
}}
- {{/select}}
- {{/if}}
+ {{:assign reste="%d-%d"|math:$qte:$return_amount}}
+ {{if $reste > 0}}
+ {{:assign class=""}}
+ {{else}}
+ {{:assign class="r0"}}
+ {{/if}}
+ {{:assign var="op_label" from="config.output_nature.%s.label"|args:$operation}}
+ {{:assign total=$qte}}
+ {{if $premier}}
+ {{:assign premier=false}}
+
Matériels attribués temporairement
+
+
+
+
+ | Date |
+ Matériel |
+ Opération |
+ Quantité |
+ Total |
+ |
+
+
+
+ {{/if}}
+ {{* Sortie temporaire *}}
+
+ | {{$out_date|date_short}} |
+ {{$eqpmt_name}} |
+ {{$op_label}} |
+ {{$qte}} |
+ {{$total}} |
+
+ {{if $reste > 0}}
+ {{if $reste > 1}}
+ {{:assign msg_reste="Reste %s unités"|args:$reste}}
+ {{else}}
+ {{:assign msg_reste="Reste %s unité"|args:$reste}}
+ {{/if}}
- {{if $temp_mat|count != 0}}
- Matériels attribués temporairement
-
-
-
- | Date |
- Opération |
- Matériel |
- Quantité |
- Total |
+ {{:linkbutton
+ label="Retour"
+ href="%smovements/output_return.html?key=%s&prop=0&user=%s"|args:$module.url:$mvt_key:$user.id
+ shape="history"
+ title=$msg_reste
+ target="_dialog"}}
+ {{/if}}
+
+
+
+ {{* chercher les retours *}}
+ {{#select
+ json_extract(links.document, '$.return') AS return_key,
+ json_extract(return_mvt.document, '$.amount') AS return_amount,
+ json_extract(return_mvt.document, '$.date') AS return_date,
+ json_extract(return_mvt.document, '$.operation') AS operation
+ FROM module_data_equipment AS links
+ INNER JOIN module_data_equipment AS return_mvt ON return_mvt.key = return_key
+ WHERE json_extract(links.document, '$.temp_key') = :mvt_key
+ ORDER BY return_date
+ ;
+ :mvt_key=$mvt_key
+ }}
+ {{:assign var="op_label" from="config.input_nature.%s.label"|args:$operation}}
+ {{:assign total="%d-%d"|math:$total:$return_amount}}
+
+ {{* retour de sortie temporaire *}}
+
+ | {{$return_date|date_short}} |
+ {{$eqpmt_name}} |
+ {{$op_label}} |
+ {{$return_amount}} |
+ {{$total}} |
|
-
-
- {{#foreach from=$temp_mat}}
- {{:assign var="type_mvt" from="config.%s_nature.%s.type"|args:$direction:$operation}}
- {{:assign var="op_label" from="config.%s_nature.%s.label"|args:$direction:$operation}}
- {{:assign var="total" from="reste.%s"|args:$eqpmt_key}}
- {{if $total == null}}
- {{:assign total=0}}
- {{/if}}
- {{if $direction == 'input' && $type_mvt == 'retour'}}
- {{:assign var="reste.%s"|args:$eqpmt_key value="%d-%d"|math:$total:$amount}}
- {{elseif $direction == 'output' && $type_mvt == 'temporaire'}}
- {{:assign var="reste.%s"|args:$eqpmt_key value="%d+%d"|math:$total:$amount}}
- {{/if}}
- {{:assign var="total" from="reste.%s"|args:$eqpmt_key}}
-
- | {{$date|date_short}} |
- {{$op_label}} |
- {{$eqpmt_name}} |
- {{$amount}} |
- {{$total}} |
-
- {{if $direction == "output" && $type_mvt == "temporaire"}}
- {{:linkbutton
- label="Retour"
- href="%smovements/output_return.html?key=%s&prop=0&user=%s"|args:$module.url:$mvt_key:$user.id
- shape="history"
- target="_dialog"}}
- {{/if}}
- |
-
- {{/foreach}}
+ {{/select}}
+ {{/select}}
{{/if}}
- {{* vérifier la présence des types d'entrées et de sorties requis *}}
- {{ if $output_types|has_key:"définitif"}}
+ {{* 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,
@@ -134,11 +177,11 @@
- | Date |
- Opération |
- Matériel |
- Quantité |
- Total |
+ Date |
+ Matériel |
+ Opération |
+ Quantité |
+ Total |
@@ -155,8 +198,8 @@
{{:assign var="total" from="reste.%s"|args:$eqpmt_key}}
| {{$date|date_short}} |
- {{$op_label}} |
{{$eqpmt_name}} |
+ {{$op_label}} |
{{$amount}} |
{{$total}} |
@@ -165,3 +208,23 @@
{{/if}}
{{/if}}
+
+
|