161 lines
5.7 KiB
HTML
161 lines
5.7 KiB
HTML
{{* -*- brindille -*- *}}
|
|
|
|
{{*
|
|
paramètres :
|
|
- key : clé du matériel à modifier
|
|
|
|
TODO : simplifier
|
|
*}}
|
|
|
|
{{:admin_header title="Sortie de matériel" current="module_equipment"}}
|
|
|
|
{{if ! $dialog}}
|
|
{{* barre de navigation *}}
|
|
{{:include file="../../_nav.html" current="sorties"}}
|
|
{{/if}}
|
|
|
|
{{* récupérer la config des entrées/sorties *}}
|
|
{{:include file="../../_get_config.html" keep="config"}}
|
|
|
|
{{* types de sorties *}}
|
|
{{#foreach from=$config.output_nature key="label" item="type"}}
|
|
{{if $type == 'retour'}}
|
|
{{:assign var='output_labels.' value="%s"|args:$label}}
|
|
{{/if}}
|
|
{{/foreach}}
|
|
|
|
{{* Traiter l'envoi du formulaire *}}
|
|
{{#form on="save"}}
|
|
{{* récupérer les infos du matériel *}}
|
|
{{#load type="equipment" key=$_GET.key assign="equipment"}}
|
|
{{:assign designation=$equipment.designation}}
|
|
{{/load}}
|
|
|
|
{{:assign stock=0}}
|
|
{{:assign exterieur=0}}
|
|
{{:assign nonproprio=0}}
|
|
{{:assign insere=false}}
|
|
|
|
{{* lister tous les mouvements du matériel *}}
|
|
{{#load type="movement" where="$$.equipment = '%s'"|args:$_GET.key assign="mvt" order="$$.date ASC"}}
|
|
|
|
{{* traiter le nouveau mouvement *}}
|
|
{{if ! $insere && $mvt.date > $_POST.date|parse_date}}
|
|
{{:assign var="operation" from="output_labels.%s|args:$_POST.type_operation}}
|
|
{{:assign var="type_mvt" from="config.output_nature.%s"|args:$operation}}
|
|
{{:assign dispo_old=$nonproprio}}
|
|
|
|
{{if $type_mvt == 'définitif'}}
|
|
{{:assign stock="%d-%d"|math:$stock:$_POST.quantite}}
|
|
{{elseif $type_mvt == 'temporaire'}}
|
|
{{:assign exterieur="%d+%d"|math:$exterieur:$_POST.quantite}}
|
|
{{elseif $type_mvt == 'retour'}}
|
|
{{:assign nonproprio="%d-%d"|math:$nonproprio:$_POST.quantite}}
|
|
{{/if}}
|
|
|
|
{{:assign insere=true}}
|
|
{{:assign dispo="%d-%d"|math:$stock:$exterieur}}
|
|
|
|
{{if $dispo < 0 || $stock < 0 || $exterieur < 0 || $nonproprio < 0}}
|
|
{{:assign date_err=$_POST.date|date:"d/m/Y"}}
|
|
{{:error message="Erreur : la quantité indiquée (%s) est supérieure à celle disponible (%d) à la date du %s"|args:$_POST.quantite:$dispo_old:$date_err}}
|
|
{{/if}}
|
|
{{/if}}
|
|
|
|
{{* traiter le mouvement courant *}}
|
|
{{:assign var="mvt_nature" from="mvt.%s_nature"|args:$mvt.direction}}
|
|
{{:assign var="type_mvt" from="config.%s_nature.%s"|args:$mvt.direction:$mvt_nature}}
|
|
|
|
{{if $mvt.direction === 'input'}}
|
|
{{if $type_mvt == 'définitif'}}
|
|
{{:assign stock="%d+%d"|math:$stock:$mvt.amount}}
|
|
{{elseif $type_mvt == 'retour'}}
|
|
{{:assign exterieur="%d-%d"|math:$exterieur:$mvt.amount}}
|
|
{{elseif $type_mvt == 'temporaire'}}
|
|
{{:assign nonproprio="%d+%d"|math:$nonproprio:$mvt.amount}}
|
|
{{/if}}
|
|
{{elseif $mvt.direction === 'output'}}
|
|
{{if $type_mvt == 'définitif'}}
|
|
{{:assign stock="%d-%d"|math:$stock:$mvt.amount}}
|
|
{{elseif $type_mvt == 'temporaire'}}
|
|
{{:assign exterieur="%d+%d"|math:$exterieur:$mvt.amount}}
|
|
{{elseif $type_mvt == 'retour'}}
|
|
{{:assign nonproprio="%d-%d"|math:$nonproprio:$mvt.amount}}
|
|
{{/if}}
|
|
{{/if}}
|
|
|
|
{{:assign dispo="%d-%d"|math:$stock:$exterieur}}
|
|
{{if $dispo < 0 || $stock < 0 || $exterieur < 0 || $nonproprio < 0}}
|
|
{{:assign date_err=$mvt.date|date:"d/m/Y"}}
|
|
{{:error message="Erreur : la quantité indiquée (%s) est incompatible avec la sortie « %s : %s » à la date du %s"|args:$_POST.quantite:$designation:$mvt.amount:$date_err}}
|
|
{{/if}}
|
|
{{/load}}
|
|
|
|
{{* Enregistrer le mouvement *}}
|
|
|
|
{{:assign mvt_key=""|uuid}}
|
|
{{:assign var="operation" from="output_labels.%d|args:$_POST.type_operation}}
|
|
{{:save
|
|
key=$mvt_key
|
|
validate_schema="../movement.schema.json"
|
|
type="movement"
|
|
direction="output"
|
|
output_nature=$operation
|
|
amount=$_POST.quantite|intval
|
|
equipment=$equipment.key
|
|
date=$_POST.date|parse_date
|
|
comment=$_POST.remarques|trim
|
|
}}
|
|
{{:redirect force="../../historique.html?ok=1&key=%s&prop=0&msg=sortie"|args:$_GET.key}}
|
|
{{else}}
|
|
{{:form_errors}}
|
|
{{/form}}
|
|
|
|
{{* Extraire et compiler les infos de la base *}}
|
|
{{:include file="../../_calcul_dispo.html" keep="cumul_mvt,equipments"}}
|
|
{{:assign var=present from="equipments.%s.nonproprio"|args:$_GET.key}}
|
|
|
|
{{if $present > 0}}
|
|
{{* déterminer le matériel concerné par le mouvement *}}
|
|
{{#load key=$_GET.key assign="equipment"}}
|
|
{{/load}}
|
|
|
|
{{* formulaire de sortie de matériel *}}
|
|
<form method="post" action="">
|
|
<fieldset class="sortie">
|
|
<legend>Ajouter une sortie d'un matériel présent temporairement</legend>
|
|
<dl>
|
|
{{:input type="select" name="type_operation" label="Type" required=true options=$output_labels}}
|
|
{{:input type="date" name="date" label="Date de sortie" required=true default=$now|date_short}}
|
|
{{:input type="text" name="equipment" label="Matériel" required=true disabled=true default=$equipment.designation}}
|
|
{{:input type="text" name="present" label="Qté présente" disabled=true default=$present}}
|
|
<p><span class="alert">La quantité indiquée est celle à la date du jour</span></p>
|
|
{{:input type="number" name="quantite" label="Quantité" required=true default=1 min=1}}
|
|
{{:input type="textarea" name="remarques" label="Remarques" cols="40" rows="3" required=false}}
|
|
</dl>
|
|
</fieldset>
|
|
<p class="submit">
|
|
{{:button type="submit" name="save" label="Enregistrer" shape="right" class="main"}}
|
|
</p>
|
|
</form>
|
|
{{else}}
|
|
<p class="block error">Il n'y a aucun matériel en stock</p>
|
|
{{/if}}
|
|
|
|
<script type="text/javascript">
|
|
// fixer la valeur maximale du champ de saisie de la quantité
|
|
function fixerValeurMax(idSelect, idNumber) {
|
|
let max = document.getElementById(idSelect).value;
|
|
let val = parseInt(document.getElementById(idNumber).value);
|
|
document.getElementById(idNumber).setAttribute("max", max);
|
|
if (val > max) {
|
|
document.getElementById(idNumber).value = max;
|
|
}
|
|
}
|
|
addEventListener("DOMContentLoaded", (event) => {
|
|
fixerValeurMax('f_present', 'f_quantite');
|
|
});
|
|
</script>
|
|
|
|
{{:admin_footer}}
|