119 lines
3.7 KiB
HTML
119 lines
3.7 KiB
HTML
{{*
|
|
Calcul des entrées/sorties de matériels à une date donnée
|
|
paramètres :
|
|
- liste de clés de catégories
|
|
- date
|
|
résultat : cumul_mvt
|
|
*}}
|
|
|
|
{{* liste des catégories *}}
|
|
{{if $category_keys === null}}
|
|
{{#load type="category"}}
|
|
{{:assign var="cumul_mvt.%s.name"|args:$key value=$name}}
|
|
{{/load}}
|
|
{{else}}
|
|
{{#load type="category" where="key"|sql_where:'IN':$category_keys}}
|
|
{{:assign var="cumul_mvt.%s.name"|args:$key value=$name}}
|
|
{{/load}}
|
|
{{/if}}
|
|
|
|
{{#foreach from=$cumul_mvt key="cat_key" item="elem"}}
|
|
{{:assign var="in_categories." value="'%s'"|args:$cat_key}}
|
|
{{/foreach}}
|
|
|
|
{{:assign in_categories=$in_categories|implode:","}}
|
|
{{:assign in_categories="("|cat:$in_categories|cat:")"}}
|
|
|
|
{{* liste des matériels dans les catégories passées en paramètre *}}
|
|
{{#load type="equipment" where="$$.category IN %s"|args:$in_categories}}
|
|
{{: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}}
|
|
{{: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}}
|
|
|
|
{{* grouper les résultats par catégorie *}}
|
|
{{#foreach from=$equipments key="eqpmt_key" item="eqpmt"}}
|
|
{{:assign
|
|
var="cumul_mvt.%s.eqpmt.%s"|args:$eqpmt.category:$eqpmt_key
|
|
value=$eqpmt}}
|
|
{{/foreach}}
|