160 lines
5.5 KiB
HTML
160 lines
5.5 KiB
HTML
{{* -*- brindille -*- *}}
|
|
|
|
|
|
{{if $_GET.direction == "input"}}
|
|
{{:assign msg_direction="entrée"}}
|
|
{{else}}
|
|
{{:assign msg_direction="sortie"}}
|
|
{{/if}}
|
|
{{:admin_header title="Dupliquer une %s"|args:$msg_direction current="module_equipment"}}
|
|
|
|
{{:assign direction=$_GET.direction}}
|
|
{{:assign mvt_key=$_GET.key}}
|
|
|
|
{{* récupérer les infos du mouvement à dupliquer *}}
|
|
{{#load key=$mvt_key assign="mvt_copie"}}
|
|
{{else}}
|
|
{{:error message="Aucune %s avec la clé %s"|args:$msg_direction:$mvt_key}}
|
|
{{/load}}
|
|
{{if $direction == "input"}}
|
|
{{:assign input_init=$mvt_copie.input_nature}}
|
|
{{:assign url="entrees/index.html"}}
|
|
{{else}}
|
|
{{:assign output_init=$mvt_copie.output_nature}}
|
|
{{:assign url="sorties/index.html"}}
|
|
{{/if}}
|
|
{{:assign amount_init=$mvt_copie.amount}}
|
|
{{:assign date_init=$mvt_copie.date|date_short}}
|
|
{{:assign key_eqpmt_init=$mvt_copie.equipment}}
|
|
|
|
{{* récupérer la config des entrées/sorties *}}
|
|
{{:include file="../_get_config.html" keep="config"}}
|
|
|
|
{{if $direction == "input"}}
|
|
{{* 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_copie.input_nature}}
|
|
{{:assign type_defaut=$label}}
|
|
{{/if}}
|
|
{{/foreach}}
|
|
{{else}}
|
|
{{* 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_copie.output_nature}}
|
|
{{:assign type_defaut=$label}}
|
|
{{/if}}
|
|
{{/foreach}}
|
|
{{/if}}
|
|
|
|
{{* récupérer les infos du matériel associé *}}
|
|
{{#load key=$key_eqpmt_init assign="eqpmt_init"}}
|
|
{{else}}
|
|
{{:error message="Aucun matériel avec la clé « %s »"|args:$key_eqpmt_init}}
|
|
{{/load}}
|
|
|
|
{{*
|
|
-------------------- Traiter la saisie --------------------
|
|
*}}
|
|
{{#form on="save"}}
|
|
{{* récupérer les infos de la catégorie *}}
|
|
{{#load type="category" key=$_POST.category assign="category"}}
|
|
{{/load}}
|
|
|
|
{{* vérifier l'existence d'un matériel du même nom *}}
|
|
{{#load type="equipment" where="lower($$.designation) = :name" :name=$_POST.designation|trim|tolower}}
|
|
{{* utiliser la clé du matériel trouvé *}}
|
|
{{:assign equipment_key=$key}}
|
|
{{else}}
|
|
{{* nouveau matériel => nouvelle clé *}}
|
|
{{:assign equipment_key=""|uuid}}
|
|
|
|
{{* enregistrer un nouveau matériel *}}
|
|
{{*:debug key=$equipment_key category=$category.key designation=$_POST.designation|trim*}}
|
|
{{:save
|
|
key=$equipment_key
|
|
validate_schema="../equipment.schema.json"
|
|
type="equipment"
|
|
category=$category.key
|
|
designation=$_POST.designation|trim
|
|
}}
|
|
{{/load}}
|
|
|
|
{{* préparer le mouvement copié *}}
|
|
{{if $direction == "input"}}
|
|
{{:assign var="mvt_copie.input_nature" from="input_labels.%s"|args:$_POST.type_operation}}
|
|
{{else}}
|
|
{{:assign var="mvt_copie.output_nature" from="output_labels.%s"|args:$_POST.type_operation}}
|
|
{{/if}}
|
|
{{:assign var="mvt_copie.amount" value=$_POST.amount}}
|
|
{{:assign var="mvt_copie.date" value=$_POST.date|parse_date}}
|
|
{{:assign var="mvt_copie.comment" value=$_POST.comment}}
|
|
|
|
{{* Enregistrer le mouvement *}}
|
|
{{:assign mvt_key=""|uuid}}
|
|
{{:save
|
|
key=$mvt_key
|
|
validate_schema="movement.schema.json"
|
|
type="movement"
|
|
direction=$direction
|
|
input_nature=$mvt_copie.input_nature
|
|
output_nature=$mvt_copie.output_nature
|
|
amount=$mvt_copie.amount|intval
|
|
equipment=$equipment_key
|
|
date=$mvt_copie.date
|
|
comment=$mvt_copie.comment
|
|
}}
|
|
{{:redirect force="../historique.html?ok=1&key=%s&prop=%s&msg=%s"|args:$key_eqpmt_init:$_GET.prop:$msg_direction}}
|
|
{{/form}}
|
|
|
|
{{:form_errors}}
|
|
|
|
{{*
|
|
-------------------- Préparer la saisie --------------------
|
|
*}}
|
|
|
|
{{* lister les catégories et matériels associés *}}
|
|
{{#load type="category" assign="category" order="$$.name"}}
|
|
{{:assign nom_cat=$category.name}}
|
|
{{:assign var="categories.%s"|args:$category.key value=$category.name}}
|
|
{{#load type="equipment" where="$$.category = :key" :key=$category.key assign="equipment"}}
|
|
{{:assign var="equipments.%s.%s"|args:$nom_cat:$equipment.key value=$equipment.designation}}
|
|
{{/load}}
|
|
{{/load}}
|
|
|
|
{{* formulaire de copie du mouvement *}}
|
|
<form method="post" action="">
|
|
|
|
<fieldset class="%s"|args:direction>
|
|
{{if $direction == "input"}}
|
|
<legend>Créer une copie de l'entrée « {{$input_init}} {{$eqpmt_init.designation}} ({{$amount_init}}) en date du {{$date_init}} »</legend>
|
|
<dl>
|
|
{{:input type="select" name="type_operation" label="Type" required=true options=$input_labels default=$type_defaut}}
|
|
{{else}}
|
|
<legend>Créer une copie de la sortie « {{$output_init}} {{$eqpmt_init.designation}} ({{$amount_init}}) en date du {{$date_init}} »</legend>
|
|
<dl>
|
|
{{:input type="select" name="type_operation" label="Type" required=true options=$output_labels default=$type_defaut}}
|
|
{{/if}}
|
|
{{:input type="date" name="date" label="Date" required=true default=$mvt_copie.date}}
|
|
{{:input type="number" name="amount" label="Quantité" required=true default=$mvt_copie.amount}}
|
|
</dl>
|
|
</fieldset>
|
|
|
|
<fieldset>
|
|
<legend>Matériel</legend>
|
|
<dl>
|
|
{{:input type="select" name="category" label="Catégorie" required=true options=$categories default=$eqpmt_init.category}}
|
|
{{:input type="text" name="designation" label="Désignation" required=true default=$eqpmt_init.designation}}
|
|
{{:input type="textarea" name="comment" label="Remarques" cols="40", rows="3" required=false default=$mvt_copie.comment}}
|
|
</dl>
|
|
</fieldset>
|
|
|
|
<p class="submit">
|
|
{{:button type="submit" name="save" label="Enregistrer" shape="right" class="main"}}
|
|
</p>
|
|
|
|
</form>
|
|
|
|
{{:admin_footer}}
|