diff --git a/_get_config.html b/_get_config.html
index 095dff9..119a20b 100644
--- a/_get_config.html
+++ b/_get_config.html
@@ -28,3 +28,9 @@
{{/foreach}}
{{/if}}
{{/foreach}}
+
+{{if $module.config.loan_duration != null}}
+ {{:assign loan_duration=$module.config.loan_duration}}
+{{else}}
+ {{:assign loan_duration=$config_defaut.loan_duration}}
+{{/if}}
diff --git a/_nav.html b/_nav.html
index 4e69986..8ea688e 100644
--- a/_nav.html
+++ b/_nav.html
@@ -29,6 +29,11 @@
Historique — {{$eqpmt}} ({{$category}})
{{/if}}
+ {{elseif $current == 'historique'}}
+
{{elseif $current == 'archives'}}
{{if $subsubcurrent == 'historique'}}
{{/if}}
diff --git a/default.json b/default.json
index 07a9c10..b9906b7 100644
--- a/default.json
+++ b/default.json
@@ -33,5 +33,6 @@
"label" : "Retour de Location/Emprunt",
"type" : "retour"
}
- ]
+ ],
+ "loan_duration" : "30"
}
diff --git a/global_history.html b/global_history.html
index 8f98f16..5eb69c1 100644
--- a/global_history.html
+++ b/global_history.html
@@ -6,7 +6,7 @@
{{:admin_header title="Historique des mouvements" custom_css="./style.css" current="module_equipment"}}
-{{:include file="./_nav.html" current="historique"}}
+{{:include file="./_nav.html" current="historique" subcurrent="tous"}}
{{* récupérer la config des entrées/sorties *}}
{{:include file="./_get_config.html" keep="config"}}
diff --git a/loan_history.html b/loan_history.html
new file mode 100644
index 0000000..28a246c
--- /dev/null
+++ b/loan_history.html
@@ -0,0 +1,97 @@
+{{* -*- brindille -*- *}}
+
+{{:admin_header title="Matériels hors de l'asso" custom_css="../style.css" current="module_equipment"}}
+{{:include file="./_nav.html" current="historique" subcurrent="prêts"}}
+
+{{* lecture config (défaut ou enregistrée) *}}
+{{:include file="./_get_config.html" keep="config"}}
+
+{{#foreach from=$config.output_nature key="key"}}
+ {{if $type == 'temporaire'}}
+ {{:assign var="output_types." value=$key|quote_sql}}
+ {{/if}}
+{{/foreach}}
+{{:assign output_ops=$output_types|implode:","}}
+{{:assign output_ops="("|cat:$output_ops|cat:")"}}
+
+{{:assign premier=true}}
+{{#select
+ users.nom AS nom,
+ users.id AS user,
+ mvt.key AS mvt_key,
+ json_extract(mat.document, '$.name') AS mat_name,
+ json_extract(mvt.document, '$.date') AS out_date,
+ 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 module_data_equipment AS mvt
+ INNER JOIN users ON json_extract(mvt.document, '$.user') = users.id
+ 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 mat ON mat.key = json_extract(mvt.document, '$.equipment')
+ WHERE
+ json_extract(mvt.document, '$.type') = 'movement'
+ AND
+ json_extract(mvt.document, '$.operation') IN !op
+ GROUP BY mvt.key
+ HAVING remain != 0
+ ORDER BY out_date, nom
+ ;
+ !op = $output_ops
+}}
+ {{if $premier}}
+
+
+
+ | Matériel |
+ Date sortie |
+ Quantité |
+ Membre |
+ Date retour |
+ Reste à rendre |
+ Remarque |
+ |
+
+
+
+ {{:assign premier=false}}
+ {{/if}}
+
+ {{if $return_date != null}}
+ {{:assign ts_retour=$return_date|strtotime}}
+ {{:assign nb_jours="floor((%d-%d)/(60*60*24))"|math:$now:$ts_retour}}
+ {{/if}}
+
+ | {{$mat_name}} |
+ {{$out_date|date_short}} |
+ {{$out_amount}} |
+ {{:link href="/admin/users/details.php?id=%s"|args:$user label="%s"|args:$nom}} |
+ {{$return_date|date_short}} |
+ {{$remain}} |
+
+ {{if $return_date != null}}
+ {{if $nb_jours > 0}}
+ {{:tag color="darkred" label="Retard %s jours"|args:$nb_jours}}
+ {{elseif $nb_jours < 0}}
+ {{:assign delai="abs(%d)"|math:$nb_jours}}
+ {{"Reste %s jours"|args:$delai}}
+ {{else}}
+ {{:tag color="darkgreen" label="À rendre aujourdh'ui"}}
+ {{/if}}
+ {{/if}}
+ |
+
+ {{:linkbutton
+ label="Retour"
+ href="movements/output_return.html?key=%s&prop=1"|args:$mvt_key
+ shape="reset"
+ target="_dialog"}}
+ |
+
+{{else}}
+ Aucun mouvement.
+{{/select}}
+
+
+
+{{:admin_footer}}
diff --git a/movements/copy_movement.html b/movements/copy_movement.html
index 459cde5..29539ea 100644
--- a/movements/copy_movement.html
+++ b/movements/copy_movement.html
@@ -14,7 +14,7 @@
{{/load}}
{{* récupérer la config des entrées/sorties *}}
-{{:include file="../_get_config.html" keep="config, directions"}}
+{{:include file="../_get_config.html" keep="config, directions, loan_duration"}}
{{:assign var="type_mvt" from="config.%s_nature.%s.type"|args:$mvt_new.direction:$mvt_new.operation}}
{{* interdire de dupliquer un retour => utiliser le bouton « Retour » *}}
@@ -93,6 +93,11 @@
{{:assign var="mvt_new.amount" value=$_POST.amount}}
{{:assign var="mvt_new.date" value=$_POST.date|parse_date}}
{{:assign var="mvt_new.comment" value=$_POST.comment}}
+ {{if $_POST.set_return_date != null}}
+ {{:assign return_date=$_POST.return_date}}
+ {{else}}
+ {{:assign return_date=null}}
+ {{/if}}
{{*
lister les mouvements
@@ -198,6 +203,7 @@
user=$user.id
storage=$_POST.storage
transactions=$transactions
+ return_date=$return_date|parse_date
}}
{{:redirect force="../equipment_history.html?ok=1&key=%s&prop=%s&msg=copie"|args:$eqpmt_key:$prop}}
{{/form}}
@@ -272,6 +278,22 @@
{{/if}}
{{/if}}
{{:input type="textarea" name="comment" label="Remarques" cols="40", rows="3" required=false default=$mvt_new.comment}}
+ {{if $mvt_new.direction == "output" && $type_mvt == "temporaire"}}
+ {{if $mvt_new.return_date != null}}
+ {{:assign checked="checked"}}
+ {{:assign visibility="visible"}}
+ {{:assign return_date=$mvt_new.return_date}}
+ {{else}}
+ {{:assign visibility="hidden"}}
+ {{:assign ts_sortie=$mvt_new.date|strtotime}}
+ {{:assign ts_retour="%d+%d*(60*60*24)"|math:$ts_sortie:$loan_duration}}
+ {{:assign return_date=$ts_retour|date_short}}
+ {{/if}}
+ {{:input id="set_return_date" type="checkbox" value=1 name="set_return_date" label="Fixer une date de retour" help="Cocher pour fixer une date de retour" checked="%s"|args:$checked}}
+
+ {{:input type="date" name="return_date" label="Date de retour" default=$return_date}}
+
+ {{/if}}
@@ -282,3 +304,14 @@
{{:admin_footer}}
+
+
+
diff --git a/movements/modify_movement.html b/movements/modify_movement.html
index e737d9d..2139e4d 100644
--- a/movements/modify_movement.html
+++ b/movements/modify_movement.html
@@ -13,7 +13,7 @@
{{/load}}
{{* récupérer la config des entrées/sorties *}}
-{{:include file="../_get_config.html" keep="config, directions"}}
+{{:include file="../_get_config.html" keep="config, directions, loan_duration"}}
{{:assign var="type_mvt" from="config.%s_nature.%s.type"|args:$mvt_new.direction:$mvt_new.operation}}
{{if $mvt_new.direction == "input"}}
@@ -84,6 +84,11 @@
{{:assign var="mvt_new.amount" value=$_POST.amount}}
{{:assign var="mvt_new.date" value=$_POST.date|parse_date}}
{{:assign var="mvt_new.comment" value=$_POST.comment}}
+ {{if $_POST.set_return_date != null}}
+ {{:assign return_date=$_POST.return_date}}
+ {{else}}
+ {{:assign return_date=null}}
+ {{/if}}
{{*
lister les mouvements
@@ -215,6 +220,7 @@
user=$user_id
storage=$_POST.storage
transactions=$transactions
+ return_date=$return_date|parse_date
}}
{{:redirect force="../equipment_history.html?ok=1&key=%s&prop=%s&msg=modification"|args:$eqpmt_key:$prop}}
{{/form}}
@@ -298,6 +304,23 @@
{{/if}}
{{/if}}
{{:input type="textarea" name="comment" label="Remarques" cols="40", rows="3" required=false default=$mvt_new.comment}}
+ {{if $mvt_new.direction == "output" && $type_mvt == "temporaire"}}
+ {{if $mvt_new.return_date != null}}
+ {{:assign checked="checked"}}
+ {{:assign visibility="visible"}}
+ {{:assign return_date=$mvt_new.return_date}}
+ {{else}}
+ {{:assign visibility="hidden"}}
+ {{:assign ts_sortie=$mvt_new.date|strtotime}}
+ {{:assign ts_retour="%d+%d*(60*60*24)"|math:$ts_sortie:$loan_duration}}
+ {{:assign return_date=$ts_retour|date_short}}
+ {{/if}}
+ {{:input id="set_return_date" type="checkbox" value=1 name="set_return_date" label="Fixer une date de retour" help="Cocher pour fixer une date de retour" checked="%s"|args:$checked}}
+
+ {{:input type="date" name="return_date" label="Date de retour" default=$return_date}}
+
+
+ {{/if}}
@@ -308,3 +331,22 @@
{{:admin_footer}}
+
+
+
diff --git a/movements/movement.schema.json b/movements/movement.schema.json
index bd27c1c..eaebdb3 100644
--- a/movements/movement.schema.json
+++ b/movements/movement.schema.json
@@ -46,6 +46,11 @@
"items": {
"type": "integer"
}
+ },
+ "return_date" : {
+ "description": "Date de retour du matériel",
+ "type" : ["null", "string"],
+ "format" : "date"
}
},
"required": ["type", "direction", "operation", "amount", "equipment", "date", "comment"]
diff --git a/movements/movement_details.html b/movements/movement_details.html
index 16a170f..f25fca7 100644
--- a/movements/movement_details.html
+++ b/movements/movement_details.html
@@ -101,6 +101,10 @@
{{else}}—
{{/if}}
+ {{if $mvt.return_date != null}}
+ Date de retour
+ {{$mvt.return_date|date_short}}
+ {{/if}}