equipment/_calcul_dispo.html

135 lines
4.9 KiB
HTML
Raw Normal View History

{{*
Calcul des entrées/sorties de matériels à une date donnée
paramètres :
- liste de catégories
- date
*}}
{{* liste des catégories *}}
{{if $categories === null}}
{{#select
key
FROM module_data_equipment as cat
WHERE json_extract(cat.document, '$.type') = 'category'}}
{{:assign var="categories." value=$key}}
{{/select}}
{{/if}}
{{* date *}}
{{if $date === null}}
{{:assign date=$now|date:"Y-m-d"}}
{{/if}}
{{* :debug date=$date *}}
{{* Extraire et compiler les infos de la base *}}
{{#select
json_extract(mvt.document, '$.date') as 'date',
eqpmt.key as 'eqpmt_key',
json_extract(eqpmt.document, '$.designation') as 'designation',
cat.key as 'cat_key',
json_extract(cat.document, '$.name') as 'category',
mvt.key as 'mvt_key',
json_extract(mvt.document, '$.direction') as 'direction',
CASE json_extract(mvt.document, '$.direction')
WHEN 'entrée' THEN json_extract(mvt.document, '$.inputNature')
WHEN 'sortie' THEN json_extract(mvt.document, '$.outputNature')
END
AS 'operation',
json_extract(mvt.document, '$.amount') AS 'nombre'
FROM module_data_equipment as eqpmt
INNER JOIN module_data_equipment as cat
ON json_extract(eqpmt.document, '$.category') = cat.key
INNER JOIN module_data_equipment as mvt
ON json_extract(mvt.document, '$.equipment') = eqpmt.key
WHERE json_extract(eqpmt.document, '$.type') = "equipment"
AND !categories
AND json_extract(mvt.document, '$.date') <= :date
ORDER BY
json_extract(cat.document, '$.name'),
json_extract(eqpmt.document, '$.designation'),
json_extract(mvt.document, '$.date');
!categories='cat_key'|sql_where:'IN':$categories
:date=$date
}}
{{:assign
var="equipments.%s.name"|args:$cat_key
value=$category}}
{{:assign
var="equipments.%s.eqpmt.%s.designation"|args:$cat_key:$eqpmt_key
value=$designation}}
{{* matériel propriété de l'asso en stock *}}
{{:assign
var="stock"
from="equipments.%s.eqpmt.%s.stock"|args:$cat_key:$eqpmt_key}}
{{if $stock === null}}
{{:assign stock=0}}
{{/if}}
{{* matériel propriété de l'asso à l'extérieur *}}
{{:assign
var="exterieur"
from="equipments.%s.eqpmt.%s.exterieur"|args:$cat_key:$eqpmt_key}}
{{if $exterieur === null}}
{{:assign exterieur=0}}
{{/if}}
{{* matériel non propriété de l'asso *}}
{{:assign
var="nonproprio"
from="equipments.%s.eqpmt.%s.nonproprio"|args:$cat_key:$eqpmt_key}}
{{if $nonproprio === null}}
{{:assign nonproprio=0}}
{{/if}}
{{if $direction === 'entrée'}}
{{* chercher le type d'entrée parmi les types de la config *}}
{{#foreach from=$module.config.inputNature item="elem"}}
{{if $operation == $elem.label}}
{{if $elem.type == 'définitif'}}
{{:assign stock="%d+%d"|math:$stock:$nombre}}
{{:assign
var="equipments.%s.eqpmt.%s.stock"|args:$cat_key:$eqpmt_key
from=stock}}
{{elseif $elem.type == 'retour'}}
{{:assign exterieur="%d-%d"|math:$exterieur:$nombre}}
{{:assign
var="equipments.%s.eqpmt.%s.exterieur"|args:$cat_key:$eqpmt_key
from=exterieur}}
{{elseif $elem.type == 'temporaire'}}
{{:assign nonproprio="%d+%d"|math:$nonproprio:$nombre}}
{{:assign
var="equipments.%s.eqpmt.%s.nonproprio"|args:$cat_key:$eqpmt_key
from=nonproprio}}
{{/if}}
{{:break}}
{{/if}}
{{/foreach}}
{{elseif $direction === 'sortie'}}
{{* chercher le type de sortie parmi les types de la config *}}
{{#foreach from=$module.config.outputNature item="elem"}}
{{if $operation == $elem.label}}
{{if $elem.type == 'définitif'}}
{{:assign stock="%d-%d"|math:$stock:$nombre}}
{{:assign
var="equipments.%s.eqpmt.%s.stock"|args:$cat_key:$eqpmt_key
from=stock}}
{{elseif $elem.type == 'temporaire'}}
{{:assign exterieur="%d+%d"|math:$exterieur:$nombre}}
{{:assign
var="equipments.%s.eqpmt.%s.exterieur"|args:$cat_key:$eqpmt_key
from=exterieur}}
{{elseif $elem.type == 'retour'}}
{{:assign nonproprio="%d-%d"|math:nonproprio:$nombre}}
{{:assign
var="equipments.%s.eqpmt.%s.nonproprio"|args:$cat_key:$eqpmt_key
from=nonproprio}}
{{/if}}
{{:break}}
{{/if}}
{{/foreach}}
{{/if}}
{{/select}}