2024-10-21 12:21:44 +02:00
{{* -*- brindille -*- *}}
2024-10-28 09:53:29 +01:00
{{*
paramètres :
2024-12-11 15:42:11 +01:00
- key : clé du matériel à rendre
2024-10-28 09:53:29 +01:00
*}}
2023-12-05 19:17:08 +01:00
{{:admin_header title="Sortie de matériel" current="module_equipment"}}
2023-11-20 14:00:00 +01:00
2023-12-05 19:17:08 +01:00
{{if ! $dialog}}
2023-12-06 09:59:11 +01:00
{{* barre de navigation *}}
{{:include file="../../_nav.html" current="sorties"}}
2023-11-20 14:00:00 +01:00
{{/if}}
2023-11-30 18:14:46 +01:00
{{* récupérer la config des entrées/sorties *}}
2023-12-05 10:07:01 +01:00
{{:include file="../../_get_config.html" keep="config"}}
2023-11-30 18:14:46 +01:00
2023-11-20 14:00:00 +01:00
{{* types de sorties *}}
2023-12-07 17:33:49 +01:00
{{#foreach from=$config.output_nature key="label" item="type"}}
{{if $type == 'retour'}}
{{:assign var='output_labels.' value="%s"|args:$label}}
2023-12-06 09:59:11 +01:00
{{/if}}
2023-11-20 14:00:00 +01:00
{{/foreach}}
{{* Traiter l'envoi du formulaire *}}
{{#form on="save"}}
2023-12-06 09:59:11 +01:00
{{* récupérer les infos du matériel *}}
2024-11-11 14:23:58 +01:00
{{#load type="equipment" key=$_GET.key assign="equipment"}}
2023-12-06 09:59:11 +01:00
{{/load}}
2024-10-21 12:21:44 +02:00
{{:assign stock=0}}
{{:assign exterieur=0}}
{{:assign nonproprio=0}}
{{:assign insere=false}}
2023-12-06 09:59:11 +01:00
2024-10-21 12:21:44 +02:00
{{* lister tous les mouvements du matériel *}}
2024-11-11 14:23:58 +01:00
{{#load type="movement" where="$$.equipment = '%s'"|args:$_GET.key assign="mvt" order="$$.date ASC"}}
2023-12-06 09:59:11 +01:00
2024-10-21 12:21:44 +02:00
{{* traiter le nouveau mouvement *}}
{{if ! $insere & & $mvt.date > $_POST.date|parse_date}}
{{:assign insere=true}}
2024-12-11 15:42:11 +01:00
{{:assign dispo_old=$nonproprio}}
{{:assign nonproprio="%d-%d"|math:$nonproprio:$_POST.quantite}}
2024-10-21 12:21:44 +02:00
2024-12-11 15:42:11 +01:00
{{if $nonproprio < 0 } }
2024-10-21 12:21:44 +02:00
{{: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}}
2024-12-11 15:42:11 +01:00
2024-10-21 12:21:44 +02:00
{{if $dispo < 0 | | $ stock < 0 | | $ exterieur < 0 | | $ nonproprio < 0 } }
{{:assign date_err=$mvt.date|date:"d/m/Y"}}
2024-12-11 15:42:11 +01:00
{{:error message="Erreur : la quantité indiquée (%s) est incompatible avec la sortie de %s unités à la date du %s"|args:$_POST.quantite:$mvt.amount:$date_err}}
2024-10-21 12:21:44 +02:00
{{/if}}
{{/load}}
2024-12-11 15:42:11 +01:00
{{if ! $insere}}
{{:assign dispo_old=$nonproprio}}
{{:assign nonproprio="%d-%d"|math:$nonproprio:$_POST.quantite}}
{{if $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}}
2023-12-06 09:59:11 +01:00
{{* Enregistrer le mouvement *}}
{{:assign mvt_key=""|uuid}}
2023-12-07 17:33:49 +01:00
{{:assign var="operation" from="output_labels.%d|args:$_POST.type_operation}}
2023-12-06 09:59:11 +01:00
{{: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
}}
2024-12-09 16:50:09 +01:00
{{:redirect force="../../historique.html?ok=1& key=%s& prop=0& msg=sortie"|args:$_GET.key}}
2023-11-20 14:00:00 +01:00
{{else}}
2023-12-06 09:59:11 +01:00
{{:form_errors}}
2023-11-20 14:00:00 +01:00
{{/form}}
{{* Extraire et compiler les infos de la base *}}
2024-12-12 09:41:52 +01:00
{{:include file="../../_calcul_dispo.html" keep="categories,equipments"}}
2024-11-11 14:23:58 +01:00
{{:assign var=present from="equipments.%s.nonproprio"|args:$_GET.key}}
2023-11-20 14:00:00 +01:00
2024-11-11 14:23:58 +01:00
{{if $present > 0}}
{{* déterminer le matériel concerné par le mouvement *}}
2024-12-12 09:41:52 +01:00
{{#load key=$_GET.key assign="equipment"}}{{/load}}
{{:assign var=cat_name from=categories.%s|args:$equipment.category}}
2023-12-06 09:59:11 +01:00
{{* formulaire de sortie de matériel *}}
< form method = "post" action = "" >
< fieldset class = "sortie" >
2024-10-21 12:21:44 +02:00
< legend > Ajouter une sortie d'un matériel présent temporairement< / legend >
2023-12-06 09:59:11 +01:00
< dl >
2023-12-07 17:33:49 +01:00
{{:input type="select" name="type_operation" label="Type" required=true options=$output_labels}}
2023-12-06 09:59:11 +01:00
{{:input type="date" name="date" label="Date de sortie" required=true default=$now|date_short}}
2024-11-11 14:23:58 +01:00
{{:input type="text" name="equipment" label="Matériel" required=true disabled=true default=$equipment.designation}}
2024-12-12 09:41:52 +01:00
{{:input type="text" name="category" label="Catégorie" required=true disabled=true default=$cat_name}}
{{:input type="text" name="present" label="Quantité présente" disabled=true default=$present}}
2024-12-11 15:42:11 +01:00
< p > < span class = "alert" > La quantité présente est celle à la date du jour< / span > < / p >
2024-11-11 14:23:58 +01:00
{{:input type="number" name="quantite" label="Quantité" required=true default=1 min=1}}
2023-12-06 09:59:11 +01:00
{{: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 >
2023-11-30 18:14:46 +01:00
{{else}}
2023-12-07 22:21:04 +01:00
< p class = "block error" > Il n'y a aucun matériel en stock< / p >
2023-11-30 18:14:46 +01:00
{{/if}}
2023-11-20 14:00:00 +01:00
< script type = "text/javascript" >
2023-12-06 09:59:11 +01:00
// fixer la valeur maximale du champ de saisie de la quantité
function fixerValeurMax(idSelect, idNumber) {
2024-11-11 14:23:58 +01:00
let max = document.getElementById(idSelect).value;
2023-12-06 09:59:11 +01:00
let val = parseInt(document.getElementById(idNumber).value);
document.getElementById(idNumber).setAttribute("max", max);
if (val > max) {
2024-11-11 14:23:58 +01:00
document.getElementById(idNumber).value = max;
2023-12-06 09:59:11 +01:00
}
}
2024-11-11 14:23:58 +01:00
addEventListener("DOMContentLoaded", (event) => {
fixerValeurMax('f_present', 'f_quantite');
});
2023-11-20 14:00:00 +01:00
< / script >
{{:admin_footer}}