-{{/list}}
+ {{#select
+ mvt.key AS mvt_key,
+ json_extract(mvt.document, '$.amount') - IFNULL(SUM(json_extract(mvt2.document, '$.amount')), 0) AS present
+ FROM {!$module.table} AS mvt
+ LEFT JOIN {!$module.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')
+ WHERE
+ json_extract(mvt.document, '$.operation') IN !op
+ AND json_extract(mvt.document, '$.equipment') = :eqpmt_key
+ GROUP by mvt.key
+ ;
+ !op = $operations
+ :eqpmt_key = $_GET.key
+ }}
+ {{:assign var="present.%s"|args:$mvt_key value=$present}}
+ {{/select}}
-{{if $dispo_final == 0 && $stock > 0 && $current != "archives"}}
- Il n'y a aucun matériel disponible, il n'est donc pas possible d'effectuer une sortie
+ {{#list
+ type="movement"
+ select="($$.date || '_' || substr('000000' || id, -6, 6)) AS 'Date';
+ CASE $$.direction WHEN 'input' THEN 'Entrée' WHEN 'output' THEN 'Sortie' END AS 'Mouvement';
+ $$.operation AS 'Opération';
+ $$.amount AS 'Quantité';
+ "" as 'Présent';
+ CASE WHEN $$.storage NOT NULL
+ THEN (SELECT $$.name FROM @TABLE as storage WHERE storage.key = @TABLE.$$.storage)
+ ELSE ''
+ END as 'Stockage';
+ '' AS 'Documents';
+ $$.transactions AS 'Écritures'
+ "
+ equipment=$equipment_key
+ order=1
+ }}
+ {{:assign var="type_mvt" from="config.%s_nature.%s.type"|args:$direction:$col3}}
+ {{:assign var="op_label" from="config.%s_nature.%s.label"|args:$direction:$operation}}
+
+ {{if $direction === "input" && $op_label|in:$input_types ||
+ $direction === "output"&& $op_label|in:$output_types
+ }}
+ {{:assign var="stock" from="quantites.%s.nonproprio"|args:$id}}
+
+ {{:assign file_path="%s/%s/"|args:$module.storage_root:$key}}
+ {{:assign file_path=$file_path|cat:"%"}}
+ {{#select count(*) AS nb FROM files WHERE path LIKE :file_path ; :file_path=$file_path}}
+ {{:assign nb_files=$nb}}
+ {{/select}}
+
{{* lecture config (défaut ou enregistrée) *}}
{{:include file="./_get_config.html" keep="config"}}
{{#foreach from=$config.output_nature key="key"}}
- {{if $type == 'temporaire' && $fee != 'payant'}}
+ {{if $type == 'temporaire'}}
{{:assign var="output_types." value=$key|quote_sql}}
{{/if}}
{{/foreach}}
@@ -56,11 +56,11 @@
json_extract(mvt.document, '$.amount') AS out_amount,
json_extract(mvt.document, '$.return_date') AS return_date,
json_extract(mvt.document, '$.amount') - IFNULL(SUM(json_extract(retour.document, '$.amount')), 0) AS remain
- FROM !table AS mvt
+ FROM {!$module.table} AS mvt
LEFT JOIN users ON json_extract(mvt.document, '$.user') = users.id
- 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')
- INNER JOIN !table AS mat ON mat.key = json_extract(mvt.document, '$.equipment')
+ LEFT JOIN {!$module.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')
+ INNER JOIN {!$module.table} AS mat ON mat.key = json_extract(mvt.document, '$.equipment')
WHERE
json_extract(mvt.document, '$.type') = 'movement'
AND
@@ -69,7 +69,6 @@
HAVING remain != 0
ORDER BY out_date, nom
;
- !table=$module.table
!op = $output_ops
}}
{{if $premier}}
diff --git a/loan_movements.html b/loan_movements.html
deleted file mode 100644
index 4425b03..0000000
--- a/loan_movements.html
+++ /dev/null
@@ -1,185 +0,0 @@
-{{* -*- brindille -*- *}}
-
-{{#restrict block=true section="accounting" level="write"}}{{/restrict}}
-
-{{*
- Afficher l'historique des prêts
-*}}
-
-{{:admin_header title="Historique des prêts" custom_css="./style.css" current="module_equipment"}}
-
-{{:include file="./_nav.html" current="prêts" subcurrent="historique"}}
-
-{{* récupérer la config des entrées/sorties *}}
-{{:include file="./_get_config.html" keep="config"}}
-
-{{* filtrer selon la catégorie *}}
-{{if $_GET.cat_key == null}}
- {{:assign selected_category=$module.config.loan_cat_key}}
-{{elseif $_GET.cat_key == -1}}
- {{:assign selected_category=null}}
- {{:save key="config" loan_cat_key=null}}
-{{else}}
- {{:assign selected_category=$_GET.cat_key}}
- {{:save key="config" loan_cat_key=$selected_category}}
-{{/if}}
-
-{{* condition de filtrage *}}
-{{if $selected_category != null}}
- {{:assign cat_key=$selected_category|quote_sql}}
- {{:assign cat_condition="category = %s"|args:$cat_key}}
-{{else}}
- {{:assign cat_condition=1}}
-{{/if}}
-
-{{* déterminer les types de mouvements *}}
-{{#foreach from=$config.output_nature key="key"}}
- {{if $type == 'temporaire' && $fee != 'payant'}}
- {{:assign var="out_keys." value=$key|quote_sql}}
- {{/if}}
-{{/foreach}}
-{{:assign out_keys=$out_keys|implode:","}}
-{{: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}}
-
-
-
-
-
Historique des prêts
-
-
-{{* lister les mouvements *}}
-{{:assign premier=true}}
-{{#select * FROM
- (WITH
- sorties AS
- (SELECT
- mvt.key,
- json_extract(mvt.document, '$.date') AS date,
- json_extract(mvt.document, '$.direction') AS direction,
- json_extract(mvt.document, '$.operation') AS operation,
- json_extract(mat.document, '$.name') AS materiel,
- json_extract(mat.document, '$.category') AS category,
- json_extract(mvt.document, '$.amount') AS amount,
- users.id AS user_id,
- users.nom AS user,
- json_extract(storage.document, '$.name') AS stockage,
- json_extract(mvt.document, '$.transactions') AS transactions,
- json_extract(mvt.document, '$.comment') AS comment,
- json_extract(mvt.document, '$.return_date') AS return_date
- FROM !table AS mvt
- INNER JOIN !table AS mat ON mat.key = json_extract(mvt.document, '$.equipment')
- LEFT JOIN users ON users.id = json_extract(mvt.document, '$.user')
- LEFT JOIN !table AS storage ON storage.key = json_extract(mvt.document, '$.storage')
- WHERE
- json_extract(mvt.document, '$.type') = 'movement'
- AND
- json_extract(mvt.document, '$.operation') IN !op
- AND
- !cat_condition
- ),
- entrees AS
- (SELECT
- mvt.key,
- json_extract(mvt.document, '$.date') AS date,
- json_extract(mvt.document, '$.direction') AS direction,
- json_extract(mvt.document, '$.operation') AS operation,
- json_extract(mat.document, '$.name') AS materiel,
- json_extract(mat.document, '$.category') AS category,
- json_extract(mvt.document, '$.amount') AS amount,
- users.id AS user_id,
- users.nom AS user,
- json_extract(storage.document, '$.name') AS stockage,
- json_extract(mvt.document, '$.transactions') AS transactions,
- json_extract(mvt.document, '$.comment') AS comment,
- json_extract(mvt.document, '$.return_date') AS return_date
- FROM !table AS mvt
- INNER JOIN !table AS mat ON mat.key = json_extract(mvt.document, '$.equipment')
- LEFT JOIN users ON users.id = json_extract(mvt.document, '$.user')
- LEFT JOIN !table AS storage ON storage.key = json_extract(mvt.document, '$.storage')
- INNER JOIN (
- SELECT json_extract(links.document, '$.return') AS return_key
- FROM !table AS links
- INNER JOIN sorties ON json_extract(links.document, '$.temp_key') = sorties.key
- ) AS filtered_links ON filtered_links.return_key = mvt.key
- WHERE !cat_condition
- )
- SELECT * FROM sorties UNION SELECT * FROM entrees
- )
- ORDER BY date
- ;
- !table=$module.table
- !op = $out_keys
- !cat_condition=$cat_condition
- assign="mvts."
-}}
- {{:assign var="op_label" from="config.%s_nature.%s.label"|args:$direction:$operation}}
- {{:assign file_path="%s/%s/"|args:$module.storage_root:$key}}
- {{:assign file_path=$file_path|cat:"%"}}
- {{#select count(*) AS nb FROM files WHERE path LIKE :file_path ; :file_path=$file_path}}
- {{:assign nb_files=$nb}}
- {{/select}}
-
- {{if $premier}}
-
-{{:admin_footer}}
diff --git a/member_history.html b/member_history.html
index cf47264..bf44103 100644
--- a/member_history.html
+++ b/member_history.html
@@ -51,13 +51,13 @@
json_extract(mvt.document, '$.amount') as amount,
COALESCE((SELECT
json_extract(links.document, '$.temp_key')
- FROM !table AS links
+ FROM {!$module.table} AS links
WHERE json_extract(links.document, '$.temp_key') = mvt.key
OR json_extract(links.document, '$.return') = mvt.key), mvt.key)
AS out_temp_key
- FROM !table AS mvt
+ FROM {!$module.table} AS mvt
INNER JOIN users ON json_extract(mvt.document, '$.user') = users.id
- INNER JOIN !table AS eqpmt
+ INNER JOIN {!$module.table} AS eqpmt
ON json_extract(mvt.document, '$.equipment') = eqpmt.key
WHERE users.id = :user
AND eqpmt.key = :eqpmt_key
@@ -65,7 +65,6 @@
OR json_extract(mvt.document, '$.operation') IN !input_types)
ORDER BY out_temp_key, date
;
- !table=$module.table
:user = $_GET.id
:eqpmt_key = $_GET.key|trim
!output_types=$output_types.temporaire
diff --git a/movements/input_return.html b/movements/input_return.html
index 4512516..c4601b3 100644
--- a/movements/input_return.html
+++ b/movements/input_return.html
@@ -34,15 +34,14 @@
{{#select
json_extract(mvt.document, '$.amount') - IFNULL(SUM(json_extract(mvt2.document, '$.amount')), 0) AS present
- FROM !table AS mvt
- LEFT JOIN !table AS link ON mvt.key = json_extract(link.document, '$.temp_key')
- LEFT JOIN !table AS mvt2 ON mvt2.key = json_extract(link.document, '$.return')
+ FROM {!$module.table} AS mvt
+ LEFT JOIN {!$module.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')
WHERE
json_extract(mvt.document, '$.operation') IN !op
AND mvt.key = :mvt_key
GROUP by mvt.key
;
- !table=$module.table
!op = $operations
:mvt_key = $_GET.key
}}
diff --git a/movements/output_return.html b/movements/output_return.html
index 162fc37..430f745 100644
--- a/movements/output_return.html
+++ b/movements/output_return.html
@@ -34,15 +34,14 @@
{{#select
json_extract(mvt.document, '$.amount') - IFNULL(SUM(json_extract(mvt2.document, '$.amount')), 0) AS exterieur
- FROM !table AS mvt
- LEFT JOIN !table AS link ON mvt.key = json_extract(link.document, '$.temp_key')
- LEFT JOIN !table AS mvt2 ON mvt2.key = json_extract(link.document, '$.return')
+ FROM {!$module.table} AS mvt
+ LEFT JOIN {!$module.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')
WHERE
json_extract(mvt.document, '$.operation') IN !op
AND mvt.key = :mvt_key
GROUP by mvt.key
;
- !table=$module.table
!op = $operations
:mvt_key = $_GET.key
}}
diff --git a/rent_history.html b/rent_history.html
deleted file mode 100644
index ac4e5a1..0000000
--- a/rent_history.html
+++ /dev/null
@@ -1,140 +0,0 @@
-{{* -*- brindille -*- *}}
-
-{{#restrict block=true section="accounting" level="write"}}{{/restrict}}
-
-{{:admin_header title="Locations en cours" custom_css="../style.css" current="module_equipment"}}
-{{:include file="./_nav.html" current="location" subcurrent="encours"}}
-
-{{*
- 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}}
-{{if $_GET.ok}}
- {{if $_GET.msg == "modification"}}
-
-
-{{* lister les mouvements *}}
-{{:assign premier=true}}
-{{#select * FROM
- (WITH
- sorties AS
- (SELECT
- mvt.key,
- json_extract(mvt.document, '$.date') AS date,
- json_extract(mvt.document, '$.direction') AS direction,
- json_extract(mvt.document, '$.operation') AS operation,
- json_extract(mat.document, '$.name') AS materiel,
- json_extract(mat.document, '$.category') AS category,
- json_extract(mvt.document, '$.amount') AS amount,
- users.id AS user_id,
- users.nom AS user,
- json_extract(storage.document, '$.name') AS stockage,
- json_extract(mvt.document, '$.transactions') AS transactions,
- json_extract(mvt.document, '$.comment') AS comment,
- json_extract(mvt.document, '$.return_date') AS return_date
- FROM !table AS mvt
- INNER JOIN !table AS mat ON mat.key = json_extract(mvt.document, '$.equipment')
- LEFT JOIN users ON users.id = json_extract(mvt.document, '$.user')
- LEFT JOIN !table AS storage ON storage.key = json_extract(mvt.document, '$.storage')
- WHERE
- json_extract(mvt.document, '$.type') = 'movement'
- AND
- json_extract(mvt.document, '$.operation') IN !op
- AND
- !cat_condition
- ),
- entrees AS
- (SELECT
- mvt.key,
- json_extract(mvt.document, '$.date') AS date,
- json_extract(mvt.document, '$.direction') AS direction,
- json_extract(mvt.document, '$.operation') AS operation,
- json_extract(mat.document, '$.name') AS materiel,
- json_extract(mat.document, '$.category') AS category,
- json_extract(mvt.document, '$.amount') AS amount,
- users.id AS user_id,
- users.nom AS user,
- json_extract(storage.document, '$.name') AS stockage,
- json_extract(mvt.document, '$.transactions') AS transactions,
- json_extract(mvt.document, '$.comment') AS comment,
- json_extract(mvt.document, '$.return_date') AS return_date
- FROM !table AS mvt
- INNER JOIN !table AS mat ON mat.key = json_extract(mvt.document, '$.equipment')
- LEFT JOIN users ON users.id = json_extract(mvt.document, '$.user')
- LEFT JOIN !table AS storage ON storage.key = json_extract(mvt.document, '$.storage')
- INNER JOIN (
- SELECT json_extract(links.document, '$.return') AS return_key
- FROM !table AS links
- INNER JOIN sorties ON json_extract(links.document, '$.temp_key') = sorties.key
- ) AS filtered_links ON filtered_links.return_key = mvt.key
- WHERE !cat_condition
- )
- SELECT * FROM sorties UNION SELECT * FROM entrees
- )
- ORDER BY date
- ;
- !table=$module.table
- !op = $out_keys
- !cat_condition=$cat_condition
- assign="mvts."
-}}
- {{:assign var="op_label" from="config.%s_nature.%s.label"|args:$direction:$operation}}
- {{:assign file_path="%s/%s/"|args:$module.storage_root:$key}}
- {{:assign file_path=$file_path|cat:"%"}}
- {{#select count(*) AS nb FROM files WHERE path LIKE :file_path ; :file_path=$file_path}}
- {{:assign nb_files=$nb}}
- {{/select}}
-
- {{if $premier}}
-
-{{:admin_footer}}
diff --git a/snippets/_details.html b/snippets/_details.html
index 9ab9458..00a6e0b 100644
--- a/snippets/_details.html
+++ b/snippets/_details.html
@@ -44,9 +44,9 @@
json_extract(mvt.document, '$.amount') AS qte,
json_extract(mvt.document, '$.return_date') AS return_date,
json_extract(mvt.document, '$.operation') AS operation
- FROM !table AS mvt
+ FROM {!$module.table} AS mvt
INNER JOIN users ON json_extract(mvt.document, '$.user') = users.id
- INNER JOIN !table AS eqpmt ON json_extract(mvt.document, '$.equipment') = eqpmt.key
+ INNER JOIN {!$module.table} AS eqpmt ON json_extract(mvt.document, '$.equipment') = eqpmt.key
WHERE
users.id = :user
AND
@@ -57,7 +57,6 @@
json_extract(mvt.document, '$.operation') IN !input_types)
ORDER BY eqpmt_name, date
;
- !table=$module.table
:user = $user.id
!output_types=$output_types.temporaire
!input_types=$input_types.retour
@@ -166,16 +165,15 @@
json_extract(mvt.document, '$.operation') as operation,
MIN(json_extract(mvt.document, '$.date')) as date,
SUM(json_extract(mvt.document, '$.amount')) as amount
- FROM !table AS mvt
+ FROM {!$module.table} AS mvt
INNER JOIN users ON json_extract(mvt.document, '$.user') = users.id
- INNER JOIN !table AS eqpmt
+ 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
;
- !table=$module.table
:user = $user.id
!output_types=$output_types.définitif
assign="def_mat."