185 lines
5.6 KiB
HTML
185 lines
5.6 KiB
HTML
{{* -*- 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}}
|
|
|
|
<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">Historique des prêts</p>
|
|
</div>
|
|
|
|
{{* 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}}
|
|
<table class="list">
|
|
<thead>
|
|
<tr>
|
|
<td>Date</td>
|
|
<td>Mouvement</td>
|
|
<td>Opération</td>
|
|
<td>Matériel</td>
|
|
<td class="num">Quantité</td>
|
|
<td>Dépositaire</td>
|
|
<td>Stockage</td>
|
|
<td>Documents</td>
|
|
<td>Écritures</td>
|
|
<td>Remarques</td>
|
|
<td class="actions"></td>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
{{:assign premier=false}}
|
|
{{/if}}
|
|
|
|
<tr>
|
|
<td>{{$date|date_short}}</td>
|
|
<td>{{if $direction == "input"}}Entrée{{else}}Sortie{{/if}}</td>
|
|
<td>{{$op_label}}</td>
|
|
<td>{{$materiel}}</td>
|
|
<td class="num">{{$amount}}</td>
|
|
<td>{{:link href="/admin/users/details.php?id=%s"|args:$user_id label="%s"|args:$user}}</td>
|
|
<td>{{$stockage}}</td>
|
|
<td class="num">{{if $nb_files > 0}}{{:icon shape="attach"}}{{/if}}</td>
|
|
<td class="num">{{if $transactions != null}}{{:icon shape="money"}}{{/if}}</td>
|
|
<td>{{$comment}}</td>
|
|
<td class="actions">
|
|
{{:linkbutton
|
|
label="Détails"
|
|
href="movements/movement_details.html?key=%s"|args:$key
|
|
shape="eye"
|
|
}}
|
|
</td>
|
|
</tr>
|
|
{{else}}
|
|
<p class="block alert">Aucun mouvement.</p>
|
|
{{/select}}
|
|
</tbody>
|
|
</table>
|
|
{{:admin_footer}}
|