amélioration validation modification et copie mouvement
This commit is contained in:
parent
77b8f892cc
commit
e4ad0b6982
4 changed files with 221 additions and 151 deletions
|
|
@ -15,25 +15,25 @@
|
|||
{{:admin_header title="Modifier une %s"|args:$msg_direction current="module_equipment"}}
|
||||
|
||||
{{* récupérer les infos du mouvement à modifier *}}
|
||||
{{#load key=$_GET.key assign="mvt_modif"}}
|
||||
{{#load key=$_GET.key assign="mvt_new"}}
|
||||
{{else}}
|
||||
{{:error message="Aucune %s avec la clé %s"|args:$msg_direction:$_GET.key}}
|
||||
{{/load}}
|
||||
|
||||
{{* infos pour affichage *}}
|
||||
{{if $_GET.direction == "input"}}
|
||||
{{:assign input_init=$mvt_modif.input_nature}}
|
||||
{{:assign mvt_nature=$mvt_new.input_nature}}
|
||||
{{else}}
|
||||
{{:assign output_init=$mvt_modif.output_nature}}
|
||||
{{:assign mvt_nature=$mvt_new.output_nature}}
|
||||
{{/if}}
|
||||
|
||||
{{:assign amount_init=$mvt_modif.amount}}
|
||||
{{:assign date_init=$mvt_modif.date|date_short}}
|
||||
{{:assign key_eqpmt_init=$mvt_modif.equipment}}
|
||||
{{:assign amount_init=$mvt_new.amount}}
|
||||
{{:assign date_init=$mvt_new.date|date_short}}
|
||||
{{:assign eqpmt_key=$mvt_new.equipment}}
|
||||
|
||||
{{* récupérer les infos du matériel associé *}}
|
||||
{{#load key=$key_eqpmt_init assign="eqpmt_init"}}
|
||||
{{#load key=$eqpmt_key assign="eqpmt"}}
|
||||
{{else}}
|
||||
{{:error message="Aucun matériel avec la clé « %s »"|args:$key_eqpmt_init}}
|
||||
{{:error message="Aucun matériel avec la clé « %s »"|args:$eqpmt_key}}
|
||||
{{/load}}
|
||||
|
||||
{{* récupérer la config des entrées/sorties *}}
|
||||
|
|
@ -43,7 +43,7 @@
|
|||
{{* types d'entrées *}}
|
||||
{{#foreach from=$config.input_nature key="label" item="type"}}
|
||||
{{:assign var="input_labels.%s"|args:$label value="%s"|args:$label}}
|
||||
{{if $label == $mvt_modif.input_nature}}
|
||||
{{if $label == $mvt_new.input_nature}}
|
||||
{{:assign nature_defaut=$label}}
|
||||
{{/if}}
|
||||
{{/foreach}}
|
||||
|
|
@ -51,7 +51,7 @@
|
|||
{{* types de sorties *}}
|
||||
{{#foreach from=$config.output_nature key="label" item="type"}}
|
||||
{{:assign var="output_labels.%s"|args:$label value="%s"|args:$label}}
|
||||
{{if $label == $mvt_modif.output_nature}}
|
||||
{{if $label == $mvt_new.output_nature}}
|
||||
{{:assign nature_defaut=$label}}
|
||||
{{/if}}
|
||||
{{/foreach}}
|
||||
|
|
@ -60,32 +60,38 @@
|
|||
{{*
|
||||
-------------------- Traiter la saisie --------------------
|
||||
*}}
|
||||
{{#form on="change"}}
|
||||
{{#form on="save"}}
|
||||
{{if $_POST.amount <= 0}}
|
||||
{{:error message="La quantité (%s) doit être strictement positive !!"|args:$_POST.amount}}
|
||||
{{/if}}
|
||||
|
||||
{{* préparer le mouvement modifié *}}
|
||||
{{if $_GET.direction == "input"}}
|
||||
{{:assign var="mvt_modif.input_nature" from="input_labels.%s"|args:$_POST.nature_operation}}
|
||||
{{:assign var=type_mvt from="config.input_nature.%s"|args:$mvt_modif.input_nature}}
|
||||
{{:assign var="mvt_new.input_nature" value=$_POST.nature_operation}}
|
||||
{{:assign var="type_mvt" from="config.input_nature.%s"|args:$mvt_new.input_nature}}
|
||||
{{if $type_mvt == "temporaire"}}
|
||||
{{:assign prop=0}}
|
||||
{{else}}
|
||||
{{:assign prop=1}}
|
||||
{{/if}}
|
||||
{{else}}
|
||||
{{:assign var="mvt_modif.output_nature" from="output_labels.%s"|args:$_POST.nature_operation}}
|
||||
{{:assign var=type_mvt from="config.outut_nature.%s"|args:$mvt_modif.input_nature}}
|
||||
{{:assign var="mvt_new.output_nature" value=$_POST.nature_operation}}
|
||||
{{:assign var="type_mvt" from="config.output_nature.%s"|args:$mvt_new.output_nature}}
|
||||
{{if $type_mvt == "retour"}}
|
||||
{{:assign prop=0}}
|
||||
{{else}}
|
||||
{{:assign prop=1}}
|
||||
{{/if}}
|
||||
{{/if}}
|
||||
{{if $type_mvt == "temporaire"}}
|
||||
{{:assign prop=0}}
|
||||
{{else}}
|
||||
{{:assign prop=1}}
|
||||
{{/if}}
|
||||
{{:assign var="mvt_modif.amount" value=$_POST.amount}}
|
||||
{{:assign var="mvt_modif.equipment" value=$key_eqpmt_init}}
|
||||
{{:assign var="mvt_modif.date" value=$_POST.date|parse_date}}
|
||||
{{:assign var="mvt_modif.comment" value=$_POST.comment}}
|
||||
|
||||
{{:assign var="mvt_new.amount" value=$_POST.amount}}
|
||||
{{:assign var="mvt_new.date" value=$_POST.date|parse_date}}
|
||||
{{:assign var="mvt_new.comment" value=$_POST.comment}}
|
||||
|
||||
{{*
|
||||
lister les mouvements et remplacer le mouvement sélectionné par sa version modifiée
|
||||
en l'insérant à sa place par date croissante
|
||||
lister les mouvements
|
||||
- ignorer le mouvement à modifier
|
||||
- insérer le mvt modifié à sa place par date croissante
|
||||
*}}
|
||||
{{:assign insere=false}}
|
||||
{{#load
|
||||
|
|
@ -93,59 +99,60 @@
|
|||
$$.type = 'movement'
|
||||
AND
|
||||
$$.equipment = :eqpmt_key"
|
||||
:eqpmt_key=$key_eqpmt_init
|
||||
:eqpmt_key=$eqpmt_key
|
||||
order="$$.date"
|
||||
assign="movement"
|
||||
}}
|
||||
{{if $key != $_GET.key}}
|
||||
{{if $_GET.direction == "input" && ! $insere && $date >= $mvt_modif.date}}
|
||||
{{:assign var="movements_modif." from=mvt_modif}}
|
||||
{{:assign insere=true}}
|
||||
{{elseif $_GET.direction == "output" && ! $insere && $date > $mvt_modif.date}}
|
||||
{{:assign var="movements_modif." from=mvt_modif}}
|
||||
{{:assign insere=true}}
|
||||
{{if! $insere}}
|
||||
{{if
|
||||
$_GET.direction == "input" && $date >= $mvt_new.date ||
|
||||
$_GET.direction == "output" && $date > $mvt_new.date
|
||||
}}
|
||||
{{:assign var="movements_new." from=mvt_new}}
|
||||
{{:assign insere=true}}
|
||||
{{/if}}
|
||||
{{/if}}
|
||||
{{:assign var="movements_modif." from=movement}}
|
||||
{{:assign var="movements_new." from=movement}}
|
||||
{{/if}}
|
||||
{{/load}}
|
||||
{{if ! $insere}}
|
||||
{{:assign var="movements_modif." from=mvt_modif}}
|
||||
{{:assign var="movements_new." from=mvt_new}}
|
||||
{{/if}}
|
||||
|
||||
{{* Vérifier la cohérence des mouvements du matériel *}}
|
||||
{{:include
|
||||
file="./valider_modification.html"
|
||||
keep="erreur"
|
||||
movements=$movements_modif
|
||||
eqpmt_key=$key_eqpmt_init
|
||||
movements=$movements_new
|
||||
}}
|
||||
|
||||
{{if $erreur}}
|
||||
<p class="block error">
|
||||
Modification demandée impossible :
|
||||
{{if $_GET.direction == "input"}}
|
||||
{{$input_init}} de « {{$eqpmt_init.designation}} (qté : {{$amount_init}}) en date du {{$date_init}} » vers
|
||||
« {{$mvt_modif.input_nature}} de {{$eqpmt_init.designation}} (qté : {{$mvt_modif.amount}}) à la date du {{$mvt_modif.date|date_short}} »
|
||||
{{else}}
|
||||
{{$output_init}} de « {{$eqpmt_init.designation}} (qté : {{$amount_init}}) en date du {{$date_init}} » vers
|
||||
« {{$mvt_modif.output_nature}} de {{$eqpmt_init.designation}} (qté : {{$mvt_modif.amount}}) à la date du {{$mvt_modif.date|date_short}} »
|
||||
{{/if}}
|
||||
« {{$mvt_nature}} de {{$eqpmt.designation}} (qté : {{$amount_init}}) en date du {{$date_init}} » vers
|
||||
{{if $_GET.direction == "input"}}
|
||||
« {{$mvt_new.input_nature}}
|
||||
{{else}}
|
||||
« {{$mvt_new.output_nature}}
|
||||
{{/if}}
|
||||
de {{$eqpmt.designation}} (qté : {{$mvt_new.amount}}) à la date du {{$mvt_new.date|date_short}} »
|
||||
</p>
|
||||
{{else}}
|
||||
{{* vérification réussie : modifier le mouvement *}}
|
||||
{{* vérification réussie : enregistrer le mouvement modifié *}}
|
||||
{{:save
|
||||
key=$_GET.key
|
||||
validate_schema="./movement.schema.json"
|
||||
validate_schema="movement.schema.json"
|
||||
type="movement"
|
||||
direction=$_GET.direction
|
||||
input_nature=$mvt_modif.input_nature
|
||||
output_nature=$mvt_modif.output_nature
|
||||
amount=$mvt_modif.amount|intval
|
||||
equipment=$key_eqpmt_init
|
||||
date=$mvt_modif.date
|
||||
comment=$mvt_modif.comment
|
||||
input_nature=$mvt_new.input_nature
|
||||
output_nature=$mvt_new.output_nature
|
||||
amount=$mvt_new.amount|intval
|
||||
equipment=$eqpmt_key
|
||||
date=$mvt_new.date
|
||||
comment=$mvt_new.comment
|
||||
}}
|
||||
{{:redirect force="../historique.html?ok=1&key=%s&prop=%s&msg=modification"|args:$key_eqpmt_init:$prop}}
|
||||
{{:redirect force="../historique.html?ok=1&key=%s&prop=%s&msg=modification"|args:$eqpmt_key:$prop}}
|
||||
{{/if}}
|
||||
{{else}}
|
||||
{{:form_errors}}
|
||||
|
|
@ -155,31 +162,32 @@
|
|||
-------------------- Préparer la saisie --------------------
|
||||
*}}
|
||||
|
||||
{{* lister les catégories et matériels associés *}}
|
||||
{{#load key=$eqpmt_init.category assign="category"}}{{/load}}
|
||||
{{* récupérer les infos de la catégorie *}}
|
||||
{{#load key=$eqpmt.category assign="category"}}{{/load}}
|
||||
|
||||
{{* formulaire de modification du mouvement *}}
|
||||
<form method="post" action="">
|
||||
|
||||
<fieldset class="entree">
|
||||
<fieldset>
|
||||
{{if $_GET.direction == "input"}}
|
||||
<legend>Modifier l'entrée « {{$input_init}} {{$eqpmt_init.designation}} ({{$amount_init}}) en date du {{$date_init}} »</legend>
|
||||
<legend>Modifier l'entrée « {{$mvt_nature}} {{$eqpmt.designation}} ({{$amount_init}}) en date du {{$date_init}} »</legend>
|
||||
<dl>
|
||||
{{:input type="select" name="nature_operation" label="Type" required=true options=$input_labels default=$nature_defaut}}
|
||||
{{else}}
|
||||
<legend>Modifier la sortie « {{$output_init}} {{$eqpmt_init.designation}} ({{$amount_init}}) en date du {{$date_init}} »</legend>
|
||||
<legend>Modifier la sortie « {{$mvt_nature}} {{$eqpmt.designation}} ({{$amount_init}}) en date du {{$date_init}} »</legend>
|
||||
<dl>
|
||||
{{:input type="select" name="nature_operation" label="Type" required=true options=$output_labels default=$nature_defaut}}
|
||||
{{/if}}
|
||||
{{:input type="date" name="date" label="Date" required=true default=$mvt_modif.date}}
|
||||
{{:input type="text" name="designation" label="Matériel" disabled=true default=$eqpmt_init.designation}}
|
||||
{{:input type="date" name="date" label="Date" required=true default=$mvt_new.date}}
|
||||
{{:input type="text" name="designation" label="Matériel" disabled=true default=$eqpmt.designation}}
|
||||
{{:input type="text" name="category" label="Catégorie" disabled=true default=$category.name}}
|
||||
{{:input type="number" name="amount" label="Quantité" min=1 required=true default=$mvt_modif.amount}}
|
||||
{{:input type="textarea" name="comment" label="Remarques" cols="40", rows="3" required=false default=$mvt_modif.comment}}
|
||||
{{:input type="number" name="amount" label="Quantité" min=1 required=true default=$mvt_new.amount}}
|
||||
{{:input type="textarea" name="comment" label="Remarques" cols="40", rows="3" required=false default=$mvt_new.comment}}
|
||||
</dl>
|
||||
</fieldset>
|
||||
|
||||
<p class="submit">
|
||||
{{:button type="submit" name="change" label="Enregistrer" shape="right" class="main"}}
|
||||
{{:button type="submit" name="save" label="Enregistrer" shape="right" class="main"}}
|
||||
</p>
|
||||
|
||||
</form>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue