Paramétrisation nom table dans les requêtes

This commit is contained in:
Jean-Christophe Engel 2026-01-27 17:00:24 +01:00
parent a2c343956c
commit 71646c9dcd
6 changed files with 31 additions and 23 deletions

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

@ -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."