equipment/mouvements/modifier_mouvement.html

196 lines
6.0 KiB
HTML
Raw Permalink Normal View History

2024-03-25 20:57:19 +01:00
{{* -*- brindille -*- *}}
2024-10-28 09:53:29 +01:00
{{*
2024-11-19 15:18:09 +01:00
Modifier un mouvement
2024-10-28 09:53:29 +01:00
paramètres :
- key : clé du mouvement à modifier
2024-11-19 15:18:09 +01:00
- direction : du mouvement à modifier
2024-10-28 09:53:29 +01:00
*}}
2024-03-25 20:57:19 +01:00
{{if $_GET.direction == "input"}}
2024-03-26 17:58:24 +01:00
{{:assign msg_direction="entrée"}}
2024-03-25 20:57:19 +01:00
{{else}}
2024-03-26 17:58:24 +01:00
{{:assign msg_direction="sortie"}}
2024-03-25 20:57:19 +01:00
{{/if}}
2024-03-26 17:58:24 +01:00
{{: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_new"}}
{{else}}
2024-11-19 15:18:09 +01:00
{{:error message="Aucune %s avec la clé %s"|args:$msg_direction:$_GET.key}}
{{/load}}
{{* infos pour affichage *}}
2024-11-19 15:18:09 +01:00
{{if $_GET.direction == "input"}}
{{:assign mvt_nature=$mvt_new.input_nature}}
{{else}}
{{:assign mvt_nature=$mvt_new.output_nature}}
{{/if}}
{{: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=$eqpmt_key assign="eqpmt"}}
{{else}}
{{:error message="Aucun matériel avec la clé « %s »"|args:$eqpmt_key}}
{{/load}}
{{* récupérer la config des entrées/sorties *}}
2023-12-05 10:07:01 +01:00
{{:include file="../_get_config.html" keep="config"}}
2024-11-19 15:18:09 +01:00
{{if $_GET.direction == "input"}}
2023-12-06 09:59:11 +01:00
{{* 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_new.input_nature}}
2024-11-19 15:18:09 +01:00
{{:assign nature_defaut=$label}}
2023-12-06 09:59:11 +01:00
{{/if}}
{{/foreach}}
{{else}}
2023-12-06 09:59:11 +01:00
{{* 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_new.output_nature}}
2024-11-19 15:18:09 +01:00
{{:assign nature_defaut=$label}}
2023-12-06 09:59:11 +01:00
{{/if}}
{{/foreach}}
{{/if}}
{{*
2023-12-06 09:59:11 +01:00
-------------------- Traiter la saisie --------------------
*}}
{{#form on="save"}}
2024-10-29 14:52:34 +01:00
{{if $_POST.amount <= 0}}
{{:error message="La quantité (%s) doit être strictement positive !!"|args:$_POST.amount}}
{{/if}}
2023-12-06 09:59:11 +01:00
{{* préparer le mouvement modifié *}}
2024-11-19 15:18:09 +01:00
{{if $_GET.direction == "input"}}
{{: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}}
2024-11-19 15:18:09 +01:00
{{else}}
{{: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}}
2023-12-06 09:59:11 +01:00
{{/if}}
{{: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}}
2023-12-06 09:59:11 +01:00
{{*
lister les mouvements
- ignorer le mouvement à modifier
- insérer le mvt modifié à sa place par date croissante
2023-12-06 09:59:11 +01:00
*}}
{{:assign insere=false}}
{{#load
where="
$$.type = 'movement'
2023-12-06 09:59:11 +01:00
AND
2024-11-19 15:18:09 +01:00
$$.equipment = :eqpmt_key"
:eqpmt_key=$eqpmt_key
order="$$.date"
2023-12-06 09:59:11 +01:00
assign="movement"
}}
2024-11-19 15:18:09 +01:00
{{if $key != $_GET.key}}
{{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}}
2023-12-06 09:59:11 +01:00
{{/if}}
{{:assign var="movements_new." from=movement}}
2023-12-06 09:59:11 +01:00
{{/if}}
{{/load}}
2023-12-06 09:59:11 +01:00
{{if ! $insere}}
{{:assign var="movements_new." from=mvt_new}}
2023-12-06 09:59:11 +01:00
{{/if}}
2024-11-19 15:18:09 +01:00
{{* Vérifier la cohérence des mouvements du matériel *}}
2023-12-06 09:59:11 +01:00
{{:include
file="./valider_modification.html"
keep="erreur"
movements=$movements_new
2023-12-06 09:59:11 +01:00
}}
{{if $erreur}}
<p class="block error">
2024-10-17 12:20:23 +02:00
Modification demandée impossible :
« {{$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}} »
2023-12-06 09:59:11 +01:00
</p>
{{else}}
{{* vérification réussie : enregistrer le mouvement modifié *}}
2023-12-06 09:59:11 +01:00
{{:save
2024-11-19 15:18:09 +01:00
key=$_GET.key
validate_schema="movement.schema.json"
2023-12-06 09:59:11 +01:00
type="movement"
2024-11-19 15:18:09 +01:00
direction=$_GET.direction
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
2023-12-06 09:59:11 +01:00
}}
{{:redirect force="../historique.html?ok=1&key=%s&prop=%s&msg=modification"|args:$eqpmt_key:$prop}}
2023-12-06 09:59:11 +01:00
{{/if}}
2024-10-29 14:52:34 +01:00
{{else}}
{{:form_errors}}
{{/form}}
{{*
2023-12-06 09:59:11 +01:00
-------------------- Préparer la saisie --------------------
*}}
{{* 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>
2024-11-19 15:18:09 +01:00
{{if $_GET.direction == "input"}}
<legend>Modifier l'entrée « {{$mvt_nature}} {{$eqpmt.designation}} ({{$amount_init}}) en date du {{$date_init}} »</legend>
2023-12-06 09:59:11 +01:00
<dl>
2024-11-19 15:18:09 +01:00
{{:input type="select" name="nature_operation" label="Type" required=true options=$input_labels default=$nature_defaut}}
2023-12-06 09:59:11 +01:00
{{else}}
<legend>Modifier la sortie « {{$mvt_nature}} {{$eqpmt.designation}} ({{$amount_init}}) en date du {{$date_init}} »</legend>
2023-12-06 09:59:11 +01:00
<dl>
2024-11-19 15:18:09 +01:00
{{:input type="select" name="nature_operation" label="Type" required=true options=$output_labels default=$nature_defaut}}
2023-12-06 09:59:11 +01:00
{{/if}}
{{: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}}
2024-11-19 15:18:09 +01:00
{{: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_new.amount}}
{{:input type="textarea" name="comment" label="Remarques" cols="40", rows="3" required=false default=$mvt_new.comment}}
2023-12-06 09:59:11 +01:00
</dl>
</fieldset>
2023-12-06 09:59:11 +01:00
<p class="submit">
{{:button type="submit" name="save" label="Enregistrer" shape="right" class="main"}}
2023-12-06 09:59:11 +01:00
</p>
</form>
{{:admin_footer}}