From 638855e6fc534387deec1a22208ec2b717506ce2 Mon Sep 17 00:00:00 2001 From: Jean-Christophe Engel Date: Mon, 21 Apr 2025 11:07:39 +0200 Subject: [PATCH] correction erreur modification mouvement --- historique.html | 17 ++- mouvements/dupliquer_mouvement.html | 67 +++++----- mouvements/modifier_mouvement.html | 200 ++++++++++++++-------------- 3 files changed, 148 insertions(+), 136 deletions(-) diff --git a/historique.html b/historique.html index bb96ee3..7c46dbf 100644 --- a/historique.html +++ b/historique.html @@ -180,8 +180,7 @@ THEN (SELECT $$.name FROM @TABLE as storage WHERE storage.key = @TABLE.$$.storage) ELSE '' END AS 'Stockage'; - $$.comment AS 'Commentaire'; - id AS 'Id' + $$.comment AS 'Commentaire' "|args:$config.user_fields.name_sql equipment=$equipment_key order=1 @@ -218,11 +217,15 @@ target="_dialog"}} {{/if}} {{/if}} + {{if $direction == "input" && $type_mvt == "retour"}} + {{* interdire dupliquer *}} + {{else}} {{:linkbutton - label="Dupliquer" - href="mouvements/dupliquer_mouvement.html?key=%s&prop=%s"|args:$key:$_GET.prop - shape="plus" - target="_dialog"}} + label="Dupliquer" + href="mouvements/dupliquer_mouvement.html?key=%s&prop=%s"|args:$key:$_GET.prop + shape="plus" + target="_dialog"}} + {{/if}} {{:linkbutton label="Modifier" 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 shape="delete" target="_dialog"}} - {{/if}} + {{/if}} {{/if}} diff --git a/mouvements/dupliquer_mouvement.html b/mouvements/dupliquer_mouvement.html index 4b43acc..660284e 100644 --- a/mouvements/dupliquer_mouvement.html +++ b/mouvements/dupliquer_mouvement.html @@ -75,12 +75,14 @@ {{:error message="Impossible de saisir une date dans le futur (%s)"|args:$_POST.date}} {{/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"}} {{/if}} + {{if $_POST.user|count > 1}} {{:error message="Un membre au plus peut être associé à une sortie"}} {{/if}} + {{#foreach from=$_POST.user key="id" item="name"}} {{:assign var="user.id" value=$id}} {{:assign var="user.name" value=$name}} @@ -115,8 +117,13 @@ {{:assign var="movements_new." from=mvt_new}} {{:assign insere=true}} {{elseif $mvt_new.direction == "output" && $type_mvt == "temporaire"}} - {{:assign var="movements_new." from=mvt_new}} - {{:assign insere=true}} + {{if $movement.direction == "input"}} + {{: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}} @@ -160,33 +167,33 @@ {{/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 - }} - {{* vérification réussie : enregistrer le mouvement modifié *}} - {{:assign mvt_key=""|uuid}} - {{:save - key=$mvt_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 - }} - {{:redirect force="../historique.html?ok=1&key=%s&prop=%s&msg=copie"|args:$eqpmt_key:$prop}} - {{/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 + }} + {{* vérification réussie : enregistrer le nouveau mouvement *}} + {{:assign mvt_key=""|uuid}} + {{:save + key=$mvt_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=copie"|args:$eqpmt_key:$prop}} {{/form}} {{:admin_header title="Dupliquer un mouvement" current="module_equipment"}} diff --git a/mouvements/modifier_mouvement.html b/mouvements/modifier_mouvement.html index d671507..a199dd9 100644 --- a/mouvements/modifier_mouvement.html +++ b/mouvements/modifier_mouvement.html @@ -15,6 +15,7 @@ {{* récupérer la config des entrées/sorties *}} {{: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}} + {{if $mvt_new.direction == "input"}} {{if $type_mvt == "temporaire"}} {{:assign prop=0}} @@ -87,7 +88,6 @@ - insérer le mvt modifié à sa place par date croissante *}} {{:assign insere=false}} - {{:assign entree_def=false}} {{#load where=" $$.type = 'movement' @@ -107,8 +107,13 @@ {{:assign var="movements_new." from=mvt_new}} {{:assign insere=true}} {{elseif $mvt_new.direction == "output" && $type_mvt == "temporaire"}} - {{:assign var="movements_new." from=mvt_new}} - {{:assign insere=true}} + {{if $movement.direction == "input"}} + {{: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}} @@ -128,103 +133,100 @@ {{if $erreur}} {{:assign var="new_op_label" from="config.%s_nature.%s.label"|args:$mvt_new.direction:$mvt_new.operation}} -

- Modification demandée impossible : - « {{$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}} » -

- {{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}} + {{:assign new_date=$mvt_new.date|date_short}} + {{: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}} {{/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}} {{:admin_header title="Modifier un mouvement" current="module_equipment"}}