début nouvelle config types ES

This commit is contained in:
Jean-Christophe Engel 2025-02-17 08:56:57 +01:00
parent b6de0c59c0
commit b19904b05b
10 changed files with 122 additions and 74 deletions

View File

@ -73,11 +73,14 @@
{{: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'}}
{{* déterminer le type de mouvement *}}
{{#foreach from=$config.input_nature}}
{{if $key == $mvt.operation}}
{{:assign type_mvt=$type}}
{{:break}}
{{/if}}
{{/foreach}}
{{if $type_mvt == 'définitif'}}
{{:assign stock="%d+%d"|math:$stock:$mvt.amount}}
{{:assign
@ -95,6 +98,13 @@
from=nonproprio}}
{{/if}}
{{elseif $mvt.direction === 'output'}}
{{* déterminer le type de mouvement *}}
{{#foreach from=config.output_nature}}
{{if $key == $mvt.operation}}
{{:assign type_mvt=$type}}
{{:break}}
{{/if}}
{{/foreach}}
{{if $type_mvt == 'définitif'}}
{{:assign stock="%d-%d"|math:$stock:$mvt.amount}}
{{:assign

View File

@ -8,29 +8,41 @@
{{* config par défaut *}}
{{:read file="./defaut.json" assign="config_defaut"}}
{{:assign config_defaut=$config_defaut|json_decode}}
{{*:debug config_defaut=$config_defaut*}}
{{if $module.config.input_nature != null}}
{{*:debug module.config.input_nature=$module.config.input_nature*}}
{{#foreach from=$module.config.input_nature item="elem"}}
{{:assign var="config.input_nature.%s"|args:$elem.label value=$elem.type}}
{{#foreach from=$elem key=label item=value}}
{{:assign var="in.%s"|args:$label value=$value}}
{{/foreach}}
{{:assign var="config.input_nature." from="in"}}
{{/foreach}}
{{else}}
{{* pas de config enregistrée : utiliser la config par défaut *}}
{{#foreach from=$config_defaut.inputs item="elem"}}
{{#foreach from=$elem key=label item=value}}
{{:assign var="config.input_nature.%s"|args:$label value=$value}}
{{:assign var="in.%s"|args:$label value=$value}}
{{/foreach}}
{{:assign var="config.input_nature." from="in"}}
{{/foreach}}
{{/if}}
{{*:debug config.input_nature=$config.input_nature*}}
{{if $module.config.output_nature != null}}
{{*:debug module.config.output_nature=$module.config.output_nature*}}
{{#foreach from=$module.config.output_nature item="elem"}}
{{:assign var="config.output_nature.%s"|args:$elem.label value=$elem.type}}
{{#foreach from=$elem key=label item=value}}
{{:assign var="out.%s"|args:$label value=$value}}
{{/foreach}}
{{:assign var="config.output_nature." from="out"}}
{{/foreach}}
{{else}}
{{* pas de config enregistrée : utiliser la config par défaut *}}
{{#foreach from=$config_defaut.outputs item="elem"}}
{{#foreach from=$elem key=label item=value}}
{{:assign var="config.output_nature.%s"|args:$label value=$value}}
{{:assign var="out.%s"|args:$label value=$value}}
{{/foreach}}
{{:assign var="config.output_nature." from="out"}}
{{/foreach}}
{{/if}}

View File

@ -11,22 +11,13 @@
{{* lecture config (défaut ou enregistrée) *}}
{{:include file="./_get_config.html" keep="config"}}
{{* types d'entrées *}}
{{#foreach from=$config.input_nature key="label" item="type"}}
{{:assign var='input_types.%s'|args:$type value=$type}}
{{/foreach}}
{{*:debug config.in=$config.input_nature config.out=$config.output_nature*}}
{{* types d'entrées qui ne peuvent être supprimées *}}
{{#load type="movement" where="$$.direction='input'" group="$$.input_nature"}}
{{:assign var="locked_inputs." value=$input_nature}}
{{/load}}
{{* types de sorties *}}
{{#foreach from=$config.output_nature key="label" item="type"}}
{{:assign var='output_types.%s'|args:$type value=$type}}
{{/foreach}}
{{* types de sorties qui ne peuvent être supprimées *}}
{{#load type="movement" where="$$.direction='output'" group="$$.output_nature"}}
{{:assign var="locked_outputs." value=$output_nature}}
@ -42,7 +33,7 @@
</tr>
</thead>
<tbody>
{{#foreach from=$config.input_nature key="label" item="type"}}
{{#foreach from=$config.input_nature}}
<tr>
<td>{{$label}}</td>
<td>{{$type}}</td>
@ -67,7 +58,7 @@
</tr>
</thead>
<tbody>
{{#foreach from=$config.output_nature key="label" item="type"}}
{{#foreach from=$config.output_nature}}
<tr>
<td>{{$label}}</td>
<td>{{$type}}</td>

View File

@ -8,6 +8,9 @@
"items": {
"type": "object",
"properties": {
"key" : {
"type" : "string"
},
"label" : {
"type" : "string"
},
@ -24,6 +27,9 @@
"items": {
"type": "object",
"properties": {
"key" : {
"type" : "string"
},
"label" : {
"type" : "string"
},

View File

@ -11,38 +11,41 @@
{{:include file="../_get_config.html" keep="config"}}
{{#form on="save"}}
{{* vérifier l'existence d'une entrée de même nom et générer le résultat *}}
{{#foreach from=$config.input_nature key="label" item="type"}}
{{#foreach from=$config.input_nature item=elem}}
{{if $label|trim|tolower == $_POST.input_fields.label|trim|tolower}}
{{:error message="Ce libellé d'entrée est déjà présent"}}
{{/if}}
{{:assign var="input_nature.label" value=$label}}
{{:assign var="input_nature.type" value=$type}}
{{:assign var="input_natures." from=input_nature}}
{{#foreach from=$elem key=label item=value}}
{{:assign var="in.%s"|args:$label value=$value}}
{{/foreach}}
{{:assign var="input_natures." from="in"}}
{{/foreach}}
{{* ajouter la nouvelle entrée *}}
{{if $_GET.dir == 'input'}}
{{:assign input_label=$_POST.input_fields.label|trim|tolower|ucfirst}}
{{:assign var="input_nature.key" value=""|uuid}}
{{:assign var="input_nature.label" value=$_POST.input_fields.label|trim|tolower|ucfirst}}
{{:assign var="input_nature.type" value=$_POST.input_fields.type}}
{{:assign var="input_natures." from=input_nature}}
{{/if}}
{{* vérifier l'existence d'une sortie de même nom et générer le résultat *}}
{{#foreach from=$config.output_nature key="label" item="type"}}
{{#foreach from=$config.output_nature item=elem}}
{{if $label|trim|tolower == $_POST.output_fields.label|trim|tolower}}
{{:error message="Ce libellé de sortie est déjà présent"}}
{{/if}}
{{:assign var="output_nature.label" value=$label}}
{{:assign var="output_nature.type" value=$type}}
{{:assign var="output_natures." from=output_nature}}
{{#foreach from=$elem key=label item=value}}
{{:assign var="out.%s"|args:$label value=$value}}
{{/foreach}}
{{:assign var="output_natures." from="out"}}
{{/foreach}}
{{* ajouter la nouvelle sortie *}}
{{if $_GET.dir == 'output'}}
{{:assign output_label=$_POST.output_fields.label|trim|tolower|ucfirst}}
{{:assign var="output_nature.key" value=""|uuid}}
{{:assign var="output_nature.label" value=$_POST.output_fields.label|trim|tolower|ucfirst}}
{{:assign var="output_nature.type" value=$_POST.output_fields.type}}
{{:assign var="output_natures." from=output_nature}}
@ -62,10 +65,9 @@
{{if $_GET.dir == 'input'}}
{{* types d'entrées *}}
{{#foreach from=$config.input_nature key="label" item="type"}}
{{#foreach from=$config.input_nature}}
{{:assign var='input_types.%s'|args:$type value=$type}}
{{/foreach}}
<form method="post" action="">
<fieldset>
<legend>Type d'entrée</legend>
@ -102,7 +104,7 @@
</form>
{{else}}
{{* types de sorties *}}
{{#foreach from=$config.output_nature key="label" item="type"}}
{{#foreach from=$config.output_nature}}
{{:assign var='output_types.%s'|args:$type value=$type}}
{{/foreach}}

View File

@ -15,21 +15,25 @@
{{:include file="../_get_config.html" keep="config"}}
{{#form on="delete"}}
{{#foreach from=$config.input_nature key="label" item="type"}}
{{#foreach from=$config.input_nature item=elem}}
{{if $_GET.dir == 'input' && $label|trim|tolower != $_GET.mvt|trim|tolower ||
$_GET.dir == 'output'}}
{{:assign var="input_nature.label" value=$label}}
{{:assign var="input_nature.type" value=$type}}
{{:assign var="input_natures." from=input_nature}}
$_GET.dir == 'output'
}}
{{#foreach from=$elem key=label item=value}}
{{:assign var="in.%s"|args:$label value=$value}}
{{/foreach}}
{{:assign var="input_natures." from="in"}}
{{/if}}
{{/foreach}}
{{#foreach from=$config.output_nature key="label" item="type"}}
{{#foreach from=$config.output_nature item=elem}}
{{if $_GET.dir == 'output' && $label|trim|tolower != $_GET.mvt|trim|tolower ||
$_GET.dir == 'input'}}
{{:assign var="output_nature.label" value=$label}}
{{:assign var="output_nature.type" value=$type}}
{{:assign var="output_natures." from=output_nature}}
$_GET.dir == 'input'
}}
{{#foreach from=$elem key=label item=value}}
{{:assign var="out.%s"|args:$label value=$value}}
{{/foreach}}
{{:assign var="output_natures." from="out"}}
{{/if}}
{{/foreach}}

View File

@ -1,12 +1,37 @@
{
"inputs": [
{ "Achat" : "définitif" },
{ "Location" : "temporaire" },
{ "Retour de Location/Prêt" : "retour" }
{
"key": "c3a955e3-4e6e-414e-90f4-ede7ac3e9e33",
"label": "Achat",
"type": "définitif"
},
{
"key": "9e909c25-14dc-4e02-b97e-73c34ab2ee9b",
"label" : "Location",
"type": "temporaire"
},
{
"key": "30eb854c-f89a-4c19-85e4-baa5e34a0317",
"label" : "Retour de Location/Prêt",
"type" : "retour"
}
],
"outputs": [
{ "Vente" : "définitif" },
{ "Prêt" : "temporaire" },
{ "Retour de Location/Emprunt" : "retour" }
{
"key": "f0eb189b-0b72-46c7-8b48-c23eed7e9672",
"label" : "Vente",
"type" : "définitif"
},
{
"key" : "c9ba00d9-26ee-448b-9f02-73e479ec2980",
"label" : "Prêt",
"type" : "temporaire"
},
{
"key" : "fefefa51-1a85-46ca-ab78-b594b10390ff",
"label" : "Retour de Location/Emprunt",
"type" : "retour"
}
]
}

View File

@ -52,32 +52,35 @@
{{* récupérer la config des entrées/sorties *}}
{{:include file="./_get_config.html" keep="config"}}
{{:debug config.input_nature=$config.input_nature}}
{{* déterminer les types de mouvements selon l'affection du matériel *}}
{{#foreach from=$config.input_nature key=mvt item=type_mvt}}
{{#foreach from=$config.input_nature}}
{{:debug key=$key label=$label type=$type}}
{{if $_GET.prop}}
{{* matériel propriété de l'asso *}}
{{if $type_mvt != 'temporaire'}}
{{:assign var="input_types." value=$mvt}}
{{if $type != 'temporaire'}}
{{:assign var="input_types." value=$label}}
{{/if}}
{{else}}
{{* matériel non propriété de l'asso *}}
{{if $type_mvt == 'temporaire'}}
{{:assign var="input_types." value=$mvt}}
{{if $type == 'temporaire'}}
{{:assign var="input_types." value=$label}}
{{/if}}
{{/if}}
{{/foreach}}
{{:debug input_types=$input_types}}
{{#foreach from=$config.output_nature key=mvt item=type_mvt}}
{{#foreach from=$config.output_nature}}
{{if $_GET.prop}}
{{* matériel propriété de l'asso *}}
{{if $type_mvt != 'retour'}}
{{:assign var="output_types." value=$mvt}}
{{if $type != 'retour'}}
{{:assign var="output_types." value=$label}}
{{/if}}
{{else}}
{{* matériel non propriété de l'asso *}}
{{if $type_mvt == 'retour'}}
{{:assign var="output_types." value=$mvt}}
{{if $type == 'retour'}}
{{:assign var="output_types." value=$label}}
{{/if}}
{{/if}}
{{/foreach}}

View File

@ -9,9 +9,9 @@
{{:include file="../_get_config.html" keep="config"}}
{{* types d'entrées *}}
{{#foreach from=$config.input_nature key="label" item="type"}}
{{#foreach from=$config.input_nature}} {{* key="label" item="type"*}}
{{if $type != 'retour'}}
{{:assign var='input_labels.' value="%s"|args:$label}}
{{:assign var="input_labels.%s"|args:$key value="%s"|args:$label}}
{{/if}}
{{/foreach}}
@ -62,13 +62,12 @@
{{* Enregistrer le mouvement *}}
{{:assign mvt_key=""|uuid}}
{{:assign var="operation" from="input_labels.%d"|args:$_POST.type_operation}}
{{:save
key=$mvt_key
validate_schema="./movement.schema.json"
type="movement"
direction="input"
input_nature=$operation
operation=$_POST.operation
amount=$_POST.quantite|intval
equipment=$equipment_key
date=$_POST.date|parse_date
@ -95,7 +94,7 @@
<fieldset class="entree">
<legend>Ajouter une entrée de matériel</legend>
<dl>
{{:input type="select" name="type_operation" label="Type" required=true options=$input_labels}}
{{:input type="select" name="operation" label="Type" required=true options=$input_labels}}
{{:input type="date" name="date" label="Date" required=true default=$now|date_short}}
{{:input type="number" name="quantite" label="Quantité" min=1 required=true default=1}}
</dl>

View File

@ -11,13 +11,9 @@
"type": "string",
"enum": ["input", "output"]
},
"input_nature": {
"description": "Nature de l'entrée",
"type": ["null", "string"]
},
"output_nature": {
"description": "Nature de la sortie",
"type": ["null", "string"]
"operation": {
"description": "clé de l'opération",
"type": "string"
},
"amount": {
"description": "Quantité ajoutée ou retirée",
@ -38,5 +34,5 @@
"type": ["null", "string"]
}
},
"required": ["type", "direction", "amount", "equipment", "date", "comment"]
"required": ["type", "direction", "operation", "amount", "equipment", "date", "comment"]
}