equipment/_calcul_dispo.html

121 lines
3.9 KiB
HTML

{{* -*- brindille -*- *}}
{{*
Calcul des entrées/sorties de matériels à une date donnée
paramètres :
- key : clé du matériel concerné
- cat_key : clé de la catégorie des matériels concernés
- date
résultat :
- categories : tableau clé => nom
- equipments : tableau clé => { clé cat, libellé mat, stock, exter, nonproprio }
*}}
{{* liste des matériels *}}
{{:assign equipments=null}}
{{if $_GET.key}}
{{* le matériel paramètre *}}
{{#load key=$_GET.key}}
{{:assign var="equipments.%s.category"|args:$key value=$category}}
{{:assign var="equipments.%s.designation"|args:$key value=$designation}}
{{:assign var="in_equipments." value="'%s'"|args:$key}}
{{/load}}
{{elseif $_GET.cat_key}}
{{* matériels de la catégorie paramètre *}}
{{#load type="equipment" where="$$.category = :category_key" :category_key=$_GET.cat_key}}
{{:assign var="equipments.%s.category"|args:$key value=$category}}
{{:assign var="equipments.%s.designation"|args:$key value=$designation}}
{{:assign var="in_equipments." value="'%s'"|args:$key}}
{{/load}}
{{else}}
{{* tous les matériels *}}
{{#load type="equipment"}}
{{:assign var="equipments.%s.category"|args:$key value=$category}}
{{:assign var="equipments.%s.designation"|args:$key value=$designation}}
{{:assign var="in_equipments." value="'%s'"|args:$key}}
{{/load}}
{{/if}}
{{:assign in_equipments=$in_equipments|implode:","}}
{{:assign in_equipments="("|cat:$in_equipments|cat:")"}}
{{* récupérer la config des entrées/sorties *}}
{{:include file="./_get_config.html" keep="config"}}
{{* parcourir les mouvements et cumuler les entrées/sorties *}}
{{if $date == null}}
{{:assign condition="$$.equipment IN %s"|args:$in_equipments}}
{{else}}
{{:assign condition="$$.equipment IN %s AND $$.date <= '%s'"|args:$in_equipments:$date}}
{{/if}}
{{#load type="movement" where="%s"|args:$condition assign="mvt" order="$$.date ASC"}}
{{* matériel propriété de l'asso en stock *}}
{{:assign
var="stock"
from="equipments.%s.stock"|args:$mvt.equipment}}
{{if $stock == null}}
{{:assign stock=0}}
{{/if}}
{{* matériel propriété de l'asso à l'extérieur *}}
{{:assign
var="exterieur"
from="equipments.%s.exterieur"|args:$mvt.equipment}}
{{if $exterieur == null}}
{{:assign exterieur=0}}
{{/if}}
{{* matériel non propriété de l'asso *}}
{{:assign
var="nonproprio"
from="equipments.%s.nonproprio"|args:$mvt.equipment}}
{{if $nonproprio == null}}
{{:assign nonproprio=0}}
{{/if}}
{{* déterminer le type de mouvement *}}
{{:assign var="mvt_nature" from="mvt.%s_nature"|args:$mvt.direction}}
{{:assign var="type_mvt" from="config.%s_nature.%s"|args:$mvt.direction:$mvt_nature}}
{{if $mvt.direction === 'input'}}
{{if $type_mvt == 'définitif'}}
{{:assign stock="%d+%d"|math:$stock:$mvt.amount}}
{{:assign
var="equipments.%s.stock"|args:$mvt.equipment
from=stock}}
{{elseif $type_mvt == 'retour'}}
{{:assign exterieur="%d-%d"|math:$exterieur:$mvt.amount}}
{{:assign
var="equipments.%s.exterieur"|args:$mvt.equipment
from=exterieur}}
{{elseif $type_mvt == 'temporaire'}}
{{:assign nonproprio="%d+%d"|math:$nonproprio:$mvt.amount}}
{{:assign
var="equipments.%s.nonproprio"|args:$mvt.equipment
from=nonproprio}}
{{/if}}
{{elseif $mvt.direction === 'output'}}
{{if $type_mvt == 'définitif'}}
{{:assign stock="%d-%d"|math:$stock:$mvt.amount}}
{{:assign
var="equipments.%s.stock"|args:$mvt.equipment
from=stock}}
{{elseif $type_mvt == 'temporaire'}}
{{:assign exterieur="%d+%d"|math:$exterieur:$mvt.amount}}
{{:assign
var="equipments.%s.exterieur"|args:$mvt.equipment
from=exterieur}}
{{elseif $type_mvt == 'retour'}}
{{:assign nonproprio="%d-%d"|math:$nonproprio:$mvt.amount}}
{{:assign
var="equipments.%s.nonproprio"|args:$mvt.equipment
from=nonproprio}}
{{/if}}
{{/if}}
{{/load}}
{{* catégories *}}
{{#load type="category" order="$$.name"}}
{{:assign var="categories.%s"|args:$key value=$name}}
{{/load}}