correction erreur modification mouvement

This commit is contained in:
Jean-Christophe Engel 2025-04-21 11:07:39 +02:00
parent 467a094b14
commit 638855e6fc
3 changed files with 148 additions and 136 deletions

View File

@ -180,8 +180,7 @@
THEN (SELECT $$.name FROM @TABLE as storage WHERE storage.key = @TABLE.$$.storage) THEN (SELECT $$.name FROM @TABLE as storage WHERE storage.key = @TABLE.$$.storage)
ELSE '' ELSE ''
END AS 'Stockage'; END AS 'Stockage';
$$.comment AS 'Commentaire'; $$.comment AS 'Commentaire'
id AS 'Id'
"|args:$config.user_fields.name_sql "|args:$config.user_fields.name_sql
equipment=$equipment_key equipment=$equipment_key
order=1 order=1
@ -218,11 +217,15 @@
target="_dialog"}} target="_dialog"}}
{{/if}} {{/if}}
{{/if}} {{/if}}
{{if $direction == "input" && $type_mvt == "retour"}}
{{* interdire dupliquer *}}
{{else}}
{{:linkbutton {{:linkbutton
label="Dupliquer" label="Dupliquer"
href="mouvements/dupliquer_mouvement.html?key=%s&prop=%s"|args:$key:$_GET.prop href="mouvements/dupliquer_mouvement.html?key=%s&prop=%s"|args:$key:$_GET.prop
shape="plus" shape="plus"
target="_dialog"}} target="_dialog"}}
{{/if}}
{{:linkbutton {{:linkbutton
label="Modifier" label="Modifier"
href="mouvements/modifier_mouvement.html?key=%s"|args:$key href="mouvements/modifier_mouvement.html?key=%s"|args:$key
@ -233,7 +236,7 @@
href="mouvements/supprimer_mouvement.html?key=%s&prop=%s"|args:$key:$_GET.prop href="mouvements/supprimer_mouvement.html?key=%s&prop=%s"|args:$key:$_GET.prop
shape="delete" shape="delete"
target="_dialog"}} target="_dialog"}}
{{/if}} {{/if}}
</td> </td>
</tr> </tr>
{{/if}} {{/if}}

View File

@ -75,12 +75,14 @@
{{:error message="Impossible de saisir une date dans le futur (%s)"|args:$_POST.date}} {{:error message="Impossible de saisir une date dans le futur (%s)"|args:$_POST.date}}
{{/if}} {{/if}}
{{if $mvt_new.direction != "output" && $_POST.user != null}} {{if $mvt_new.direction == "input" && $_POST.user != null}}
{{:error message="Un membre ne peut être associé qu'à une sortie"}} {{:error message="Un membre ne peut être associé qu'à une sortie"}}
{{/if}} {{/if}}
{{if $_POST.user|count > 1}} {{if $_POST.user|count > 1}}
{{:error message="Un membre au plus peut être associé à une sortie"}} {{:error message="Un membre au plus peut être associé à une sortie"}}
{{/if}} {{/if}}
{{#foreach from=$_POST.user key="id" item="name"}} {{#foreach from=$_POST.user key="id" item="name"}}
{{:assign var="user.id" value=$id}} {{:assign var="user.id" value=$id}}
{{:assign var="user.name" value=$name}} {{:assign var="user.name" value=$name}}
@ -115,8 +117,13 @@
{{:assign var="movements_new." from=mvt_new}} {{:assign var="movements_new." from=mvt_new}}
{{:assign insere=true}} {{:assign insere=true}}
{{elseif $mvt_new.direction == "output" && $type_mvt == "temporaire"}} {{elseif $mvt_new.direction == "output" && $type_mvt == "temporaire"}}
{{:assign var="movements_new." from=mvt_new}} {{if $movement.direction == "input"}}
{{:assign insere=true}} {{:assign var="type_mvt_crt" from="config.input_nature.%s.type"|args::$movement.operation}}
{{if $type_mvt_crt == "retour"}}
{{:assign var="movements_new." from=mvt_new}}
{{:assign insere=true}}
{{/if}}
{{/if}}
{{/if}} {{/if}}
{{/if}} {{/if}}
{{/if}} {{/if}}
@ -160,33 +167,33 @@
{{/if}} {{/if}}
{{/if}} {{/if}}
{{:save {{:save
key=$equipment.key key=$equipment.key
validate_schema="../equipment.schema.json" validate_schema="../equipment.schema.json"
type="equipment" type="equipment"
category=$equipment.category category=$equipment.category
name=$equipment.name name=$equipment.name
status="available" status="available"
stock=$equipment.stock stock=$equipment.stock
out=$equipment.out out=$equipment.out
notowned=$equipment.notowned notowned=$equipment.notowned
}} }}
{{* vérification réussie : enregistrer le mouvement modifié *}} {{* vérification réussie : enregistrer le nouveau mouvement *}}
{{:assign mvt_key=""|uuid}} {{:assign mvt_key=""|uuid}}
{{:save {{:save
key=$mvt_key key=$mvt_key
validate_schema="movement.schema.json" validate_schema="movement.schema.json"
type="movement" type="movement"
direction=$mvt_new.direction direction=$mvt_new.direction
operation=$_POST.operation operation=$_POST.operation
amount=$mvt_new.amount|intval amount=$mvt_new.amount|intval
equipment=$eqpmt_key equipment=$eqpmt_key
date=$mvt_new.date date=$mvt_new.date
comment=$mvt_new.comment comment=$mvt_new.comment
user=$user.id user=$user.id
}} storage=$_POST.storage
{{:redirect force="../historique.html?ok=1&key=%s&prop=%s&msg=copie"|args:$eqpmt_key:$prop}} }}
{{/if}} {{:redirect force="../historique.html?ok=1&key=%s&prop=%s&msg=copie"|args:$eqpmt_key:$prop}}
{{/form}} {{/form}}
{{:admin_header title="Dupliquer un mouvement" current="module_equipment"}} {{:admin_header title="Dupliquer un mouvement" current="module_equipment"}}

View File

@ -15,6 +15,7 @@
{{* récupérer la config des entrées/sorties *}} {{* récupérer la config des entrées/sorties *}}
{{:include file="../_get_config.html" keep="config, directions"}} {{:include file="../_get_config.html" keep="config, directions"}}
{{:assign var="type_mvt" from="config.%s_nature.%s.type"|args:$mvt_new.direction:$mvt_new.operation}} {{:assign var="type_mvt" from="config.%s_nature.%s.type"|args:$mvt_new.direction:$mvt_new.operation}}
{{if $mvt_new.direction == "input"}} {{if $mvt_new.direction == "input"}}
{{if $type_mvt == "temporaire"}} {{if $type_mvt == "temporaire"}}
{{:assign prop=0}} {{:assign prop=0}}
@ -87,7 +88,6 @@
- insérer le mvt modifié à sa place par date croissante - insérer le mvt modifié à sa place par date croissante
*}} *}}
{{:assign insere=false}} {{:assign insere=false}}
{{:assign entree_def=false}}
{{#load {{#load
where=" where="
$$.type = 'movement' $$.type = 'movement'
@ -107,8 +107,13 @@
{{:assign var="movements_new." from=mvt_new}} {{:assign var="movements_new." from=mvt_new}}
{{:assign insere=true}} {{:assign insere=true}}
{{elseif $mvt_new.direction == "output" && $type_mvt == "temporaire"}} {{elseif $mvt_new.direction == "output" && $type_mvt == "temporaire"}}
{{:assign var="movements_new." from=mvt_new}} {{if $movement.direction == "input"}}
{{:assign insere=true}} {{:assign var="type_mvt_crt" from="config.input_nature.%s.type"|args::$movement.operation}}
{{if $type_mvt_crt == "retour"}}
{{:assign var="movements_new." from=mvt_new}}
{{:assign insere=true}}
{{/if}}
{{/if}}
{{/if}} {{/if}}
{{/if}} {{/if}}
{{/if}} {{/if}}
@ -128,103 +133,100 @@
{{if $erreur}} {{if $erreur}}
{{:assign var="new_op_label" from="config.%s_nature.%s.label"|args:$mvt_new.direction:$mvt_new.operation}} {{:assign var="new_op_label" from="config.%s_nature.%s.label"|args:$mvt_new.direction:$mvt_new.operation}}
<p class="block error"> {{:assign new_date=$mvt_new.date|date_short}}
Modification demandée impossible : {{:error message="Modification impossible : « %s de %s (qté : %s) en date du %s » vers « %s de %s (qté : %s) à la date du %s »"|args:$op_label:$equipment.name:$amount_init:$date_init:$new_op_label:$equipment.name:$mvt_new.amount:$new_date}}
« {{$op_label}} de {{$equipment.name}} (qté : {{$amount_init}}) en date du {{$date_init}} » vers
« {{$new_op_label}}
de {{$equipment.name}} (qté : {{$mvt_new.amount}}) à la date du {{$mvt_new.date|date_short}} »
</p>
{{else}}
{{* calculer la nouvelle quantité du matériel *}}
{{:assign var="type_mvt_init" from="config.%s_nature.%s.type"|args:$mvt_new.direction:$operation_init}}
{{:assign var="type_mvt_final" from="config.%s_nature.%s.type"|args:$mvt_new.direction:$mvt_new.operation}}
{{if $mvt_new.direction == 'input'}}
{{if $type_mvt_init == 'définitif'}}
{{:assign var="equipment.stock" value="%d-%d"|math:$equipment.stock:$amount_init}}
{{elseif $type_mvt_init == 'temporaire'}}
{{:assign var="equipment.notowned" value="%d-%d"|math:$equipment.notowned:$amount_init}}
{{elseif $type_mvt_init == 'retour'}}
{{:assign var="equipment.out" value="%d+%d"|math:$equipment.out:$amount_init}}
{{/if}}
{{if $type_mvt_final == 'définitif'}}
{{:assign var="equipment.stock" value="%d+%d"|math:$equipment.stock:$mvt_new.amount|intval}}
{{elseif $type_mvt_final == 'temporaire'}}
{{:assign var="equipment.notowned" value="%d+%d"|math:$equipment.notowned:$mvt_new.amount|intval}}
{{elseif $type_mvt_final == 'retour'}}
{{:assign var="equipment.out" value="%d-%d"|math:$equipment.out:$mvt_new.amount|intval}}
{{/if}}
{{else}}
{{if $type_mvt_init == 'définitif'}}
{{:assign var="equipment.stock" value="%d+%d"|math:$equipment.stock:$amount_init}}
{{elseif $type_mvt_init == 'temporaire'}}
{{:assign var="equipment.out" value="%d-%d"|math:$equipment.out:$amount_init}}
{{elseif $type_mvt_init == 'retour'}}
{{:assign var="equipment.notowned" value="%d+%d"|math:$equipment.notowned:$amount_init}}
{{/if}}
{{if $type_mvt_final == 'définitif'}}
{{:assign var="equipment.stock" value="%d-%d"|math:$equipment.stock:$mvt_new.amount|intval}}
{{elseif $type_mvt_final == 'temporaire'}}
{{:assign var="equipment.out" value="%d+%d"|math:$equipment.out:$mvt_new.amount|intval}}
{{elseif $type_mvt_final == 'retour'}}
{{:assign var="equipment.notowned" value="%d-%d"|math:$equipment.notowned:$mvt_new.amount|intval}}
{{/if}}
{{/if}}
{{if $equipment.stock == 0}}
{{* vérifier s'il y a au moins une entrée définitive *}}
{{#foreach from=$config.input_nature key=key}}
{{if $type == 'définitif'}}
{{:assign var="input_types." value=$key}}
{{/if}}
{{/foreach}}
{{#foreach from=$movements_new}}
{{if $operation|in:$input_types}}
{{:assign entree_def=true}}
{{:break}}
{{/if}}
{{/foreach}}
{{if ! $entree_def}}
{{:assign var="equipment.stock" value=null}}
{{/if}}
{{/if}}
{{:save
key=$equipment.key
validate_schema="../equipment.schema.json"
type="equipment"
category=$equipment.category
name=$equipment.name
status="available"
stock=$equipment.stock
out=$equipment.out
notowned=$equipment.notowned
}}
{{* enregistrer le mouvement modifié *}}
{{if $user == null}}
{{:assign user_id=$mvt_new.user}}
{{else}}
{{:assign user_id=$user.id}}
{{/if}}
{{:save
key=$_GET.key
validate_schema="movement.schema.json"
type="movement"
direction=$mvt_new.direction
operation=$_POST.operation
amount=$mvt_new.amount|intval
equipment=$eqpmt_key
date=$mvt_new.date
comment=$mvt_new.comment
user=$user_id
storage=$_POST.storage
}}
{{:redirect force="../historique.html?ok=1&key=%s&prop=%s&msg=modification"|args:$eqpmt_key:$prop}}
{{/if}} {{/if}}
{{* calculer la nouvelle quantité du matériel *}}
{{:assign var="type_mvt_init" from="config.%s_nature.%s.type"|args:$mvt_new.direction:$operation_init}}
{{:assign var="type_mvt_final" from="config.%s_nature.%s.type"|args:$mvt_new.direction:$mvt_new.operation}}
{{if $mvt_new.direction == 'input'}}
{{if $type_mvt_init == 'définitif'}}
{{:assign var="equipment.stock" value="%d-%d"|math:$equipment.stock:$amount_init}}
{{elseif $type_mvt_init == 'temporaire'}}
{{:assign var="equipment.notowned" value="%d-%d"|math:$equipment.notowned:$amount_init}}
{{elseif $type_mvt_init == 'retour'}}
{{:assign var="equipment.out" value="%d+%d"|math:$equipment.out:$amount_init}}
{{/if}}
{{if $type_mvt_final == 'définitif'}}
{{:assign var="equipment.stock" value="%d+%d"|math:$equipment.stock:$mvt_new.amount|intval}}
{{elseif $type_mvt_final == 'temporaire'}}
{{:assign var="equipment.notowned" value="%d+%d"|math:$equipment.notowned:$mvt_new.amount|intval}}
{{elseif $type_mvt_final == 'retour'}}
{{:assign var="equipment.out" value="%d-%d"|math:$equipment.out:$mvt_new.amount|intval}}
{{/if}}
{{else}}
{{if $type_mvt_init == 'définitif'}}
{{:assign var="equipment.stock" value="%d+%d"|math:$equipment.stock:$amount_init}}
{{elseif $type_mvt_init == 'temporaire'}}
{{:assign var="equipment.out" value="%d-%d"|math:$equipment.out:$amount_init}}
{{elseif $type_mvt_init == 'retour'}}
{{:assign var="equipment.notowned" value="%d+%d"|math:$equipment.notowned:$amount_init}}
{{/if}}
{{if $type_mvt_final == 'définitif'}}
{{:assign var="equipment.stock" value="%d-%d"|math:$equipment.stock:$mvt_new.amount|intval}}
{{elseif $type_mvt_final == 'temporaire'}}
{{:assign var="equipment.out" value="%d+%d"|math:$equipment.out:$mvt_new.amount|intval}}
{{elseif $type_mvt_final == 'retour'}}
{{:assign var="equipment.notowned" value="%d-%d"|math:$equipment.notowned:$mvt_new.amount|intval}}
{{/if}}
{{/if}}
{{if $equipment.stock == 0}}
{{* vérifier s'il y a au moins une entrée définitive *}}
{{:assign entree_def=false}}
{{#foreach from=$config.input_nature key=key}}
{{if $type == 'définitif'}}
{{:assign var="input_types." value=$key}}
{{/if}}
{{/foreach}}
{{#foreach from=$movements_new}}
{{if $operation|in:$input_types}}
{{:assign entree_def=true}}
{{:break}}
{{/if}}
{{/foreach}}
{{if ! $entree_def}}
{{:assign var="equipment.stock" value=null}}
{{/if}}
{{/if}}
{{:save
key=$equipment.key
validate_schema="../equipment.schema.json"
type="equipment"
category=$equipment.category
name=$equipment.name
status="available"
stock=$equipment.stock
out=$equipment.out
notowned=$equipment.notowned
}}
{{* enregistrer le mouvement modifié *}}
{{if $user == null}}
{{:assign user_id=$mvt_new.user}}
{{else}}
{{:assign user_id=$user.id}}
{{/if}}
{{:save
key=$_GET.key
validate_schema="movement.schema.json"
type="movement"
direction=$mvt_new.direction
operation=$_POST.operation
amount=$mvt_new.amount|intval
equipment=$eqpmt_key
date=$mvt_new.date
comment=$mvt_new.comment
user=$user_id
storage=$_POST.storage
}}
{{:redirect force="../historique.html?ok=1&key=%s&prop=%s&msg=modification"|args:$eqpmt_key:$prop}}
{{/form}} {{/form}}
{{:admin_header title="Modifier un mouvement" current="module_equipment"}} {{:admin_header title="Modifier un mouvement" current="module_equipment"}}