Compare commits

...
Sign in to create a new pull request.

2 commits

Author SHA1 Message Date
Jean-Christophe Engel
71646c9dcd Paramétrisation nom table dans les requêtes 2026-01-27 17:00:24 +01:00
Jean-Christophe Engel
a2c343956c Amélioration filtre par catégorie 2026-01-22 10:44:51 +01:00
9 changed files with 113 additions and 66 deletions

View file

@ -4,12 +4,34 @@
inventaire des entrées/sorties des matériels permanents inventaire des entrées/sorties des matériels permanents
*}} *}}
{{* filtrer selon la catégorie *}}
{{if $_GET.cat_key == null}}
{{:assign selected_category=$module.config.stock_cat_key}}
{{if $module.config.stock_cat_key != null}}
{{:assign cat_key=$selected_category|quote_sql}}
{{/if}}
{{elseif $_GET.cat_key == -1}}
{{:assign selected_category=null}}
{{:save key="config" stock_cat_key=null}}
{{else}}
{{:assign selected_category=$_GET.cat_key}}
{{:assign cat_key=$selected_category|quote_sql}}
{{:save key="config" stock_cat_key=$selected_category}}
{{/if}}
{{* condition de filtrage *}}
{{if $selected_category != null}}
{{:assign cat_condition="$$.category = %s"|args:$cat_key}}
{{else}}
{{:assign cat_condition="1"}}
{{/if}}
{{* Sélecteur catégories *}} {{* Sélecteur catégories *}}
{{:assign var="options." value="" label="Toutes les catégories" href="?prop=1"}} {{:assign var="cat_options." value="" label="Toutes les catégories" href="?cat_key=-1&prop=1"}}
{{#load type="category" order="$$.name"}} {{#load type="category" order="$$.name"}}
{{:assign var="categories.%s"|args:$key value=$name}} {{:assign var="categories.%s"|args:$key value=$name}}
{{:assign {{:assign
var="options." var="cat_options."
value=$key value=$key
label=$name label=$name
href="?cat_key=%s&prop=1"|args:$key href="?cat_key=%s&prop=1"|args:$key
@ -20,8 +42,8 @@
<legend>Filtrer par catégorie</legend> <legend>Filtrer par catégorie</legend>
{{:dropdown {{:dropdown
title="Filtrer par catégorie" title="Filtrer par catégorie"
options=$options options=$cat_options
value="%s"|args:$_GET.cat_key value="%s"|args:$selected_category
}} }}
</fieldset> </fieldset>
@ -29,14 +51,6 @@
<p class="help">Inventaire des matériels propriété de l'association</p> <p class="help">Inventaire des matériels propriété de l'association</p>
</div> </div>
{{* filtrer selon la catégorie *}}
{{if $_GET.cat_key == null}}
{{:assign condition="1"}}
{{else}}
{{:assign cat_key=$_GET.cat_key|quote_sql}}
{{:assign condition="$$.category = %s"|args:$cat_key}}
{{/if}}
{{#list {{#list
select=" select="
$$.name AS 'Matériel' ; $$.name AS 'Matériel' ;
@ -48,7 +62,7 @@
(SELECT $$.stock - $$.out) AS 'Disponible' (SELECT $$.stock - $$.out) AS 'Disponible'
" "
type="equipment" type="equipment"
where="$$.status <> 'archived' AND $$.stock NOT NULL AND %s"|args:$condition where="$$.status <> 'archived' AND $$.stock NOT NULL AND %s"|args:$cat_condition
order=1 order=1
}} }}
{{:assign var=cat_name from=categories.%s|args:$category}} {{:assign var=cat_name from=categories.%s|args:$category}}

View file

@ -4,12 +4,34 @@
inventaire des entrées/sorties des matériels temporaires inventaire des entrées/sorties des matériels temporaires
*}} *}}
{{* filtrer selon la catégorie *}}
{{if $_GET.cat_key == null}}
{{:assign selected_category=$module.config.temp_cat_key}}
{{if $module.config.temp_cat_key != null}}
{{:assign cat_key=$selected_category|quote_sql}}
{{/if}}
{{elseif $_GET.cat_key == -1}}
{{:assign selected_category=null}}
{{:save key="config" temp_cat_key=null}}
{{else}}
{{:assign selected_category=$_GET.cat_key}}
{{:assign cat_key=$selected_category|quote_sql}}
{{:save key="config" temp_cat_key=$selected_category}}
{{/if}}
{{* condition de filtrage *}}
{{if $selected_category != null}}
{{:assign cat_condition="$$.category = %s"|args:$cat_key}}
{{else}}
{{:assign cat_condition="1"}}
{{/if}}
{{* Sélecteur catégories *}} {{* Sélecteur catégories *}}
{{:assign var="options." value="" label="Toutes les catégories" href="?prop=0"}} {{:assign var="cat_options." value="" label="Toutes les catégories" href="?cat_key=-1&prop=0"}}
{{#load type="category" order="$$.name"}} {{#load type="category" order="$$.name"}}
{{:assign var="categories.%s"|args:$key value=$name}} {{:assign var="categories.%s"|args:$key value=$name}}
{{:assign {{:assign
var="options." var="cat_options."
value=$key value=$key
label=$name label=$name
href="?cat_key=%s&prop=0"|args:$key href="?cat_key=%s&prop=0"|args:$key
@ -20,8 +42,8 @@
<legend>Filtrer par catégorie</legend> <legend>Filtrer par catégorie</legend>
{{:dropdown {{:dropdown
title="Filtrer par catégorie" title="Filtrer par catégorie"
options=$options options=$cat_options
value="%s"|args:$_GET.cat_key value="%s"|args:$selected_category
}} }}
</fieldset> </fieldset>
@ -29,14 +51,6 @@
<p class="help">Inventaire des matériels empruntés ou loués</p> <p class="help">Inventaire des matériels empruntés ou loués</p>
</div> </div>
{{* filtrer selon la catégorie *}}
{{if $_GET.cat_key == null}}
{{:assign condition="1"}}
{{else}}
{{:assign cat_key=$_GET.cat_key|quote_sql}}
{{:assign condition="$$.category = %s"|args:$cat_key}}
{{/if}}
{{#list {{#list
select=" select="
$$.name AS 'Matériel' ; $$.name AS 'Matériel' ;
@ -46,7 +60,7 @@
$$.notowned AS 'Quantité' $$.notowned AS 'Quantité'
" "
type="equipment" type="equipment"
where="$$.status <> 'archived' AND $$.notowned != 0 AND %s"|args:$condition where="$$.status <> 'archived' AND $$.notowned != 0 AND %s"|args:$cat_condition
order=1 order=1
}} }}
{{:assign var=cat_name from=categories.%s|args:$category}} {{:assign var=cat_name from=categories.%s|args:$category}}

View file

@ -147,14 +147,15 @@
{{#select {{#select
mvt.key AS mvt_key, mvt.key AS mvt_key,
json_extract(mvt.document, '$.amount') - IFNULL(SUM(json_extract(mvt2.document, '$.amount')), 0) AS reste json_extract(mvt.document, '$.amount') - IFNULL(SUM(json_extract(mvt2.document, '$.amount')), 0) AS reste
FROM {!$module.table} AS mvt FROM !table AS mvt
LEFT JOIN {!$module.table} AS link ON mvt.key = json_extract(link.document, '$.temp_key') LEFT JOIN !table AS link ON mvt.key = json_extract(link.document, '$.temp_key')
LEFT JOIN {!$module.table} AS mvt2 ON mvt2.key = json_extract(link.document, '$.return') LEFT JOIN !table AS mvt2 ON mvt2.key = json_extract(link.document, '$.return')
WHERE WHERE
json_extract(mvt.document, '$.operation') IN !op json_extract(mvt.document, '$.operation') IN !op
AND json_extract(mvt.document, '$.equipment') = :eqpmt_key AND json_extract(mvt.document, '$.equipment') = :eqpmt_key
GROUP by mvt.key GROUP by mvt.key
; ;
!table=$module.table
!op = $operations !op = $operations
:eqpmt_key = $_GET.key :eqpmt_key = $_GET.key
}} }}
@ -250,14 +251,15 @@
{{#select {{#select
mvt.key AS mvt_key, mvt.key AS mvt_key,
json_extract(mvt.document, '$.amount') - IFNULL(SUM(json_extract(mvt2.document, '$.amount')), 0) AS present json_extract(mvt.document, '$.amount') - IFNULL(SUM(json_extract(mvt2.document, '$.amount')), 0) AS present
FROM {!$module.table} AS mvt FROM !table AS mvt
LEFT JOIN {!$module.table} AS link ON mvt.key = json_extract(link.document, '$.temp_key') LEFT JOIN !table AS link ON mvt.key = json_extract(link.document, '$.temp_key')
LEFT JOIN {!$module.table} AS mvt2 ON mvt2.key = json_extract(link.document, '$.return') LEFT JOIN !table AS mvt2 ON mvt2.key = json_extract(link.document, '$.return')
WHERE WHERE
json_extract(mvt.document, '$.operation') IN !op json_extract(mvt.document, '$.operation') IN !op
AND json_extract(mvt.document, '$.equipment') = :eqpmt_key AND json_extract(mvt.document, '$.equipment') = :eqpmt_key
GROUP by mvt.key GROUP by mvt.key
; ;
!table=$module.table
!op = $operations !op = $operations
:eqpmt_key = $_GET.key :eqpmt_key = $_GET.key
}} }}

View file

@ -13,12 +13,34 @@
{{* récupérer la config des entrées/sorties *}} {{* récupérer la config des entrées/sorties *}}
{{: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.hist_cat_key}}
{{elseif $_GET.cat_key == -1}}
{{:assign selected_category=null}}
{{:save key="config" hist_cat_key=null}}
{{else}}
{{:assign selected_category=$_GET.cat_key}}
{{:save key="config" hist_cat_key=$selected_category}}
{{/if}}
{{* condition de filtrage *}}
{{if $selected_category != null}}
{{:assign cat_condition="(SELECT key
FROM @TABLE AS cat
WHERE cat.key = (SELECT $$.category
FROM @TABLE AS mat
WHERE mat.key = @TABLE.$$.equipment)) = '%s'"|args:$selected_category}}
{{else}}
{{:assign cat_condition=1}}
{{/if}}
{{* Sélecteur catégories *}} {{* Sélecteur catégories *}}
{{:assign var="options." value="" label="Toutes les catégories" href="?"}} {{:assign var="cat_options." value="" label="Toutes les catégories" href="?cat_key=-1"}}
{{#load type="category" order="$$.name"}} {{#load type="category" order="$$.name"}}
{{:assign var="categories.%s"|args:$key value=$name}} {{:assign var="categories.%s"|args:$key value=$name}}
{{:assign {{:assign
var="options." var="cat_options."
value=$key value=$key
label=$name label=$name
href="?cat_key=%s"|args:$key href="?cat_key=%s"|args:$key
@ -29,8 +51,8 @@
<legend>Filtrer par catégorie</legend> <legend>Filtrer par catégorie</legend>
{{:dropdown {{:dropdown
title="Filtrer par catégorie" title="Filtrer par catégorie"
options=$options options=$cat_options
value="%s"|args:$_GET.cat_key value="%s"|args:$selected_category
}} }}
</fieldset> </fieldset>
@ -38,18 +60,7 @@
<p class="help">Historique de tous les mouvements de matériel</p> <p class="help">Historique de tous les mouvements de matériel</p>
</div> </div>
{{* condition de filtrage *}} {{* lister les mouvements *}}
{{if $_GET.cat_key != null}}
{{:assign condition="(SELECT key
FROM @TABLE AS cat
WHERE cat.key = (SELECT $$.category
FROM @TABLE AS mat
WHERE mat.key = @TABLE.$$.equipment)) = '%s'"|args:$_GET.cat_key}}
{{else}}
{{:assign condition=1}}
{{/if}}
{{* lister tous les mouvements *}}
{{#list {{#list
type="movement" type="movement"
select="($$.date || '_' || substr('000000' || id, -6, 6)) AS 'Date'; select="($$.date || '_' || substr('000000' || id, -6, 6)) AS 'Date';
@ -69,7 +80,7 @@
END as 'Stockage'; END as 'Stockage';
$$.comment AS 'Commentaire' $$.comment AS 'Commentaire'
"|args:$config.user_fields.name_sql "|args:$config.user_fields.name_sql
where="%s"|args:$condition where="%s"|args:$cat_condition
order=1 order=1
max=50 max=50
desc=true desc=true

View file

@ -56,11 +56,11 @@
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 AND
@ -69,6 +69,7 @@
HAVING remain != 0 HAVING remain != 0
ORDER BY out_date, nom ORDER BY out_date, nom
; ;
!table=$module.table
!op = $output_ops !op = $output_ops
}} }}
{{if $premier}} {{if $premier}}

View file

@ -51,13 +51,13 @@
json_extract(mvt.document, '$.amount') as amount, json_extract(mvt.document, '$.amount') as amount,
COALESCE((SELECT COALESCE((SELECT
json_extract(links.document, '$.temp_key') json_extract(links.document, '$.temp_key')
FROM {!$module.table} AS links FROM !table AS links
WHERE json_extract(links.document, '$.temp_key') = mvt.key WHERE json_extract(links.document, '$.temp_key') = mvt.key
OR json_extract(links.document, '$.return') = mvt.key), mvt.key) OR json_extract(links.document, '$.return') = mvt.key), mvt.key)
AS out_temp_key AS out_temp_key
FROM {!$module.table} AS mvt FROM !table AS mvt
INNER JOIN users ON json_extract(mvt.document, '$.user') = users.id INNER JOIN users ON json_extract(mvt.document, '$.user') = users.id
INNER JOIN {!$module.table} AS eqpmt INNER JOIN !table AS eqpmt
ON json_extract(mvt.document, '$.equipment') = eqpmt.key ON json_extract(mvt.document, '$.equipment') = eqpmt.key
WHERE users.id = :user WHERE users.id = :user
AND eqpmt.key = :eqpmt_key AND eqpmt.key = :eqpmt_key
@ -65,6 +65,7 @@
OR json_extract(mvt.document, '$.operation') IN !input_types) OR json_extract(mvt.document, '$.operation') IN !input_types)
ORDER BY out_temp_key, date ORDER BY out_temp_key, date
; ;
!table=$module.table
:user = $_GET.id :user = $_GET.id
:eqpmt_key = $_GET.key|trim :eqpmt_key = $_GET.key|trim
!output_types=$output_types.temporaire !output_types=$output_types.temporaire

View file

@ -34,14 +34,15 @@
{{#select {{#select
json_extract(mvt.document, '$.amount') - IFNULL(SUM(json_extract(mvt2.document, '$.amount')), 0) AS present json_extract(mvt.document, '$.amount') - IFNULL(SUM(json_extract(mvt2.document, '$.amount')), 0) AS present
FROM {!$module.table} AS mvt FROM !table AS mvt
LEFT JOIN {!$module.table} AS link ON mvt.key = json_extract(link.document, '$.temp_key') LEFT JOIN !table AS link ON mvt.key = json_extract(link.document, '$.temp_key')
LEFT JOIN {!$module.table} AS mvt2 ON mvt2.key = json_extract(link.document, '$.return') LEFT JOIN !table AS mvt2 ON mvt2.key = json_extract(link.document, '$.return')
WHERE WHERE
json_extract(mvt.document, '$.operation') IN !op json_extract(mvt.document, '$.operation') IN !op
AND mvt.key = :mvt_key AND mvt.key = :mvt_key
GROUP by mvt.key GROUP by mvt.key
; ;
!table=$module.table
!op = $operations !op = $operations
:mvt_key = $_GET.key :mvt_key = $_GET.key
}} }}

View file

@ -34,14 +34,15 @@
{{#select {{#select
json_extract(mvt.document, '$.amount') - IFNULL(SUM(json_extract(mvt2.document, '$.amount')), 0) AS exterieur json_extract(mvt.document, '$.amount') - IFNULL(SUM(json_extract(mvt2.document, '$.amount')), 0) AS exterieur
FROM {!$module.table} AS mvt FROM !table AS mvt
LEFT JOIN {!$module.table} AS link ON mvt.key = json_extract(link.document, '$.temp_key') LEFT JOIN !table AS link ON mvt.key = json_extract(link.document, '$.temp_key')
LEFT JOIN {!$module.table} AS mvt2 ON mvt2.key = json_extract(link.document, '$.return') LEFT JOIN !table AS mvt2 ON mvt2.key = json_extract(link.document, '$.return')
WHERE WHERE
json_extract(mvt.document, '$.operation') IN !op json_extract(mvt.document, '$.operation') IN !op
AND mvt.key = :mvt_key AND mvt.key = :mvt_key
GROUP by mvt.key GROUP by mvt.key
; ;
!table=$module.table
!op = $operations !op = $operations
:mvt_key = $_GET.key :mvt_key = $_GET.key
}} }}

View file

@ -44,9 +44,9 @@
json_extract(mvt.document, '$.amount') AS qte, json_extract(mvt.document, '$.amount') AS qte,
json_extract(mvt.document, '$.return_date') AS return_date, json_extract(mvt.document, '$.return_date') AS return_date,
json_extract(mvt.document, '$.operation') AS operation json_extract(mvt.document, '$.operation') AS operation
FROM {!$module.table} AS mvt FROM !table AS mvt
INNER JOIN users ON json_extract(mvt.document, '$.user') = users.id 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 INNER JOIN !table AS eqpmt ON json_extract(mvt.document, '$.equipment') = eqpmt.key
WHERE WHERE
users.id = :user users.id = :user
AND AND
@ -57,6 +57,7 @@
json_extract(mvt.document, '$.operation') IN !input_types) json_extract(mvt.document, '$.operation') IN !input_types)
ORDER BY eqpmt_name, date ORDER BY eqpmt_name, date
; ;
!table=$module.table
:user = $user.id :user = $user.id
!output_types=$output_types.temporaire !output_types=$output_types.temporaire
!input_types=$input_types.retour !input_types=$input_types.retour
@ -165,15 +166,16 @@
json_extract(mvt.document, '$.operation') as operation, json_extract(mvt.document, '$.operation') as operation,
MIN(json_extract(mvt.document, '$.date')) as date, MIN(json_extract(mvt.document, '$.date')) as date,
SUM(json_extract(mvt.document, '$.amount')) as amount SUM(json_extract(mvt.document, '$.amount')) as amount
FROM {!$module.table} AS mvt FROM !table AS mvt
INNER JOIN users ON json_extract(mvt.document, '$.user') = users.id INNER JOIN users ON json_extract(mvt.document, '$.user') = users.id
INNER JOIN {!$module.table} AS eqpmt INNER JOIN !table AS eqpmt
ON json_extract(mvt.document, '$.equipment') = eqpmt.key ON json_extract(mvt.document, '$.equipment') = eqpmt.key
WHERE users.id = :user WHERE users.id = :user
AND json_extract(mvt.document, '$.operation') IN !output_types AND json_extract(mvt.document, '$.operation') IN !output_types
GROUP BY eqpmt_key, operation GROUP BY eqpmt_key, operation
ORDER BY eqpmt_name, date ORDER BY eqpmt_name, date
; ;
!table=$module.table
:user = $user.id :user = $user.id
!output_types=$output_types.définitif !output_types=$output_types.définitif
assign="def_mat." assign="def_mat."