Ajout filtre par catégorie Location et Prêts en cours

This commit is contained in:
Jean-Christophe Engel 2026-01-28 13:37:11 +01:00
parent 83c2b9af80
commit 974f87e5a4
2 changed files with 116 additions and 37 deletions

View file

@ -31,20 +31,59 @@
{{/if}} {{/if}}
{{/if}} {{/if}}
<div class="shortFormLeft">
<p class="help">Prêts de matériel en cours</p>
</div>
{{* lecture config (défaut ou enregistrée) *}} {{* lecture config (défaut ou enregistrée) *}}
{{:include file="./_get_config.html" keep="config"}} {{:include file="./_get_config.html" keep="config"}}
{{* filtrer selon la catégorie *}}
{{if $_GET.cat_key == null}}
{{:assign selected_category=$module.config.loan_hist_cat_key}}
{{elseif $_GET.cat_key == -1}}
{{:assign selected_category=null}}
{{:save key="config" loan_hist_cat_key=null}}
{{else}}
{{:assign selected_category=$_GET.cat_key}}
{{:save key="config" loan_hist_cat_key=$selected_category}}
{{/if}}
{{* condition de filtrage *}}
{{if $selected_category != null}}
{{:assign cat_key=$selected_category|quote_sql}}
{{:assign cat_condition="json_extract(mat.document, '$.category') = %s"|args:$cat_key}}
{{else}}
{{:assign cat_condition=1}}
{{/if}}
{{#foreach from=$config.output_nature key="key"}} {{#foreach from=$config.output_nature key="key"}}
{{if $type == 'temporaire' && $fee != 'payant'}} {{if $type == 'temporaire' && $fee != 'payant'}}
{{:assign var="output_types." value=$key|quote_sql}} {{:assign var="out_keys." value=$key|quote_sql}}
{{/if}} {{/if}}
{{/foreach}} {{/foreach}}
{{:assign output_ops=$output_types|implode:","}} {{:assign out_keys=$out_keys|implode:","}}
{{:assign output_ops="("|cat:$output_ops|cat:")"}} {{:assign out_keys="("|cat:$out_keys|cat:")"}}
{{* sélecteur de catégorie *}}
{{:assign var="cat_options." value="" label="Toutes les catégories" href="?cat_key=-1"}}
{{#load type="category" order="$$.name"}}
{{:assign
var="cat_options."
value=$key
label=$name
href="?cat_key=%s"|args:$key
}}
{{/load}}
<fieldset class="shortFormRight">
<legend>Filtrer par catégorie</legend>
{{:dropdown
title="Filtrer par catégorie"
options=$cat_options
value="%s"|args:$selected_category
}}
</fieldset>
<div class="shortFormLeft">
<p class="help">Location de matériel en cours</p>
</div>
{{:assign premier=true}} {{:assign premier=true}}
{{#select {{#select
@ -61,29 +100,29 @@
LEFT JOIN !table AS links ON mvt.key = json_extract(links.document, '$.temp_key') LEFT JOIN !table AS links ON mvt.key = json_extract(links.document, '$.temp_key')
LEFT JOIN !table AS retour ON retour.key = json_extract(links.document, '$.return') LEFT JOIN !table AS retour ON retour.key = json_extract(links.document, '$.return')
INNER JOIN !table AS mat ON mat.key = json_extract(mvt.document, '$.equipment') INNER JOIN !table AS mat ON mat.key = json_extract(mvt.document, '$.equipment')
WHERE WHERE json_extract(mvt.document, '$.type') = 'movement'
json_extract(mvt.document, '$.type') = 'movement' AND json_extract(mvt.document, '$.operation') IN !op
AND AND !cat_condition
json_extract(mvt.document, '$.operation') IN !op
GROUP BY mvt.key GROUP BY mvt.key
HAVING remain != 0 HAVING remain != 0
ORDER BY out_date, nom ORDER BY out_date, nom
; ;
!table=$module.table !table=$module.table
!op = $output_ops !op = $out_keys
!cat_condition=$cat_condition
}} }}
{{if $premier}} {{if $premier}}
<table class="list"> <table class="list">
<thead> <thead>
<tr> <tr>
<th>Matériel</th> <td>Matériel</td>
<th>Date prêt</th> <td>Date prêt</td>
<th>Quantité</th> <td>Quantité</td>
<th>Membre</th> <td>Membre</td>
<th>Date retour</th> <td>Date retour</td>
<th>Reste à rendre</th> <td>Reste à rendre</td>
<th>Remarque</th> <td>Remarque</td>
<th class="actions"></th> <td class="actions"></td>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>

View file

@ -31,20 +31,59 @@
{{/if}} {{/if}}
{{/if}} {{/if}}
<div class="shortFormLeft">
<p class="help">Location de matériel en cours</p>
</div>
{{* lecture config (défaut ou enregistrée) *}} {{* lecture config (défaut ou enregistrée) *}}
{{:include file="./_get_config.html" keep="config"}} {{:include file="./_get_config.html" keep="config"}}
{{#foreach from=$config.output_nature key="key" item="elem"}} {{* filtrer selon la catégorie *}}
{{if $_GET.cat_key == null}}
{{:assign selected_category=$module.config.rent_hist_cat_key}}
{{elseif $_GET.cat_key == -1}}
{{:assign selected_category=null}}
{{:save key="config" rent_hist_cat_key=null}}
{{else}}
{{:assign selected_category=$_GET.cat_key}}
{{:save key="config" rent_hist_cat_key=$selected_category}}
{{/if}}
{{* condition de filtrage *}}
{{if $selected_category != null}}
{{:assign cat_key=$selected_category|quote_sql}}
{{:assign cat_condition="json_extract(mat.document, '$.category') = %s"|args:$cat_key}}
{{else}}
{{:assign cat_condition=1}}
{{/if}}
{{#foreach from=$config.output_nature key="key"}}
{{if $type == 'temporaire' && $fee == 'payant'}} {{if $type == 'temporaire' && $fee == 'payant'}}
{{:assign var="output_types." value=$key|quote_sql}} {{:assign var="out_keys." value=$key|quote_sql}}
{{/if}} {{/if}}
{{/foreach}} {{/foreach}}
{{:assign output_ops=$output_types|implode:","}} {{:assign out_keys=$out_keys|implode:","}}
{{:assign output_ops="("|cat:$output_ops|cat:")"}} {{:assign out_keys="("|cat:$out_keys|cat:")"}}
{{* sélecteur de catégorie *}}
{{:assign var="cat_options." value="" label="Toutes les catégories" href="?cat_key=-1"}}
{{#load type="category" order="$$.name"}}
{{:assign
var="cat_options."
value=$key
label=$name
href="?cat_key=%s"|args:$key
}}
{{/load}}
<fieldset class="shortFormRight">
<legend>Filtrer par catégorie</legend>
{{:dropdown
title="Filtrer par catégorie"
options=$cat_options
value="%s"|args:$selected_category
}}
</fieldset>
<div class="shortFormLeft">
<p class="help">Location de matériel en cours</p>
</div>
{{:assign premier=true}} {{:assign premier=true}}
{{#select {{#select
@ -56,20 +95,21 @@
json_extract(mvt.document, '$.amount') AS out_amount, json_extract(mvt.document, '$.amount') AS out_amount,
json_extract(mvt.document, '$.return_date') AS return_date, json_extract(mvt.document, '$.return_date') AS return_date,
json_extract(mvt.document, '$.amount') - IFNULL(SUM(json_extract(retour.document, '$.amount')), 0) AS remain json_extract(mvt.document, '$.amount') - IFNULL(SUM(json_extract(retour.document, '$.amount')), 0) AS remain
FROM {!$module.table} AS mvt FROM !table AS mvt
LEFT JOIN users ON json_extract(mvt.document, '$.user') = users.id LEFT JOIN users ON json_extract(mvt.document, '$.user') = users.id
LEFT JOIN {!$module.table} AS links ON mvt.key = json_extract(links.document, '$.temp_key') LEFT JOIN !table AS links ON mvt.key = json_extract(links.document, '$.temp_key')
LEFT JOIN {!$module.table} AS retour ON retour.key = json_extract(links.document, '$.return') LEFT JOIN !table AS retour ON retour.key = json_extract(links.document, '$.return')
INNER JOIN {!$module.table} AS mat ON mat.key = json_extract(mvt.document, '$.equipment') INNER JOIN !table AS mat ON mat.key = json_extract(mvt.document, '$.equipment')
WHERE WHERE json_extract(mvt.document, '$.type') = 'movement'
json_extract(mvt.document, '$.type') = 'movement' AND json_extract(mvt.document, '$.operation') IN !op
AND AND !cat_condition
json_extract(mvt.document, '$.operation') IN !op
GROUP BY mvt.key GROUP BY mvt.key
HAVING remain != 0 HAVING remain != 0
ORDER BY out_date, nom ORDER BY out_date, nom
; ;
!op = $output_ops !table=$module.table
!op = $out_keys
!cat_condition=$cat_condition
}} }}
{{if $premier}} {{if $premier}}
<table class="list"> <table class="list">