equipment/_calcul_dispo.html

121 lines
3.9 KiB
HTML
Raw Permalink Normal View History

2024-10-28 09:53:29 +01:00
{{* -*- brindille -*- *}}
{{*
2023-12-06 09:59:11 +01:00
Calcul des entrées/sorties de matériels à une date donnée
paramètres :
2024-12-10 15:05:50 +01:00
- 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 }
*}}
2024-12-10 15:05:50 +01:00
{{* 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}}
2024-12-10 15:05:50 +01:00
{{* 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}}
2023-12-06 09:59:11 +01:00
{{/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"}}
2023-12-06 09:59:11 +01:00
{{* matériel propriété de l'asso en stock *}}
{{:assign
var="stock"
from="equipments.%s.stock"|args:$mvt.equipment}}
{{if $stock == null}}
2023-12-06 09:59:11 +01:00
{{:assign stock=0}}
{{/if}}
2023-12-06 09:59:11 +01:00
{{* matériel propriété de l'asso à l'extérieur *}}
{{:assign
var="exterieur"
from="equipments.%s.exterieur"|args:$mvt.equipment}}
{{if $exterieur == null}}
2023-12-06 09:59:11 +01:00
{{:assign exterieur=0}}
{{/if}}
2023-12-06 09:59:11 +01:00
{{* matériel non propriété de l'asso *}}
{{:assign
var="nonproprio"
from="equipments.%s.nonproprio"|args:$mvt.equipment}}
{{if $nonproprio == null}}
2023-12-06 09:59:11 +01:00
{{: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}}
2023-12-06 09:59:11 +01:00
{{/if}}
{{/load}}
2024-12-10 15:05:50 +01:00
{{* catégories *}}
{{#load type="category" order="$$.name"}}
{{:assign var="categories.%s"|args:$key value=$name}}
{{/load}}