AJout vérification quantité sortie inférieure à quantité disponible

This commit is contained in:
Jean-Christophe Engel 2023-10-26 19:09:59 +02:00
parent 52fcf204bc
commit 0206238b23
2 changed files with 38 additions and 15 deletions

View File

@ -0,0 +1,9 @@
{{* cumuler les entrées et les sorties de ce matériel *}}
{{:assign var="dispo" value=0}}
{{#load type="movement" where="$$.equipment = :eqpmt_key" :eqpmt_key=$equipment.key assign="movement"}}
{{if $movement.direction === 'entrée'}}
{{:assign dispo="%d+%d"|math:$dispo:$movement.amount}}
{{else}}
{{:assign dispo="%d-%d"|math:$dispo:$movement.amount}}
{{/if}}
{{/load}}

View File

@ -15,6 +15,14 @@
{{#load type="equipment" key=$_POST.equipment assign="equipment"}}
{{/load}}
{{* TODO vérifier si qté sortie <= dispo *}}
{{:include file="./_calcul_dispo.html" keep="dispo" }}
{{* cumuler les entrées et les sorties de ce matériel *}}
{{if $_POST.quantite|intval > $dispo}}
{{:error message="Erreur : la quantité indiquée (%s) est supérieure à celle disponible (%d)"|args:$_POST.quantite:$dispo}}
{{/if}}
{{* Enregistrer le mouvement *}}
{{:assign mvt_key=""|uuid}}
{{:assign var="operation" from="types_sorties.%d|args:$_POST.type_operation}}
@ -41,19 +49,13 @@
{{:assign nom_cat=$category.name}}
{{#load type="equipment" where="$$.category = :key" :key=$category.key assign="equipment" order="$$.designation"}}
{{:assign var="dispo" value=0}}
{{* cumuler les entrées et les sorties de ce matériel *}}
{{#load type="movement" where="$$.equipment = :eqpmt_key" :eqpmt_key=$equipment.key assign="movement"}}
{{if $movement.direction === 'entrée'}}
{{:assign dispo="%d+%d"|math:$dispo:$movement.amount}}
{{else}}
{{:assign dispo="%d-%d"|math:$dispo:$movement.amount}}
{{/if}}
{{else}}
{{:error message="pas de mouvement pour la clé=%s"|args:$equipment.key}}
{{/load}}
{{:include file="./_calcul_dispo.html" keep="dispo" }}
{{if $dispo > 0}}
{{:assign var="equipments.%s.%s"|args:$nom_cat:$equipment.key value="%s (dispo : %d)"|args:$equipment.designation:$dispo}}
{{/if}}
{{/load}}
{{/load}}
@ -65,20 +67,32 @@
<legend>Ajouter une sortie d'un matériel disponible en stock</legend>
{{:input type="select" name="type_operation" label="Type" required=true options=$types_sorties}}
{{:input type="date" name="date" label="Date de sortie" required=true default=$now|date_short}}
{{:input type="number" name="quantite" label="Quantité" required=true default=1}}
{{:input type="number" name="quantite" label="Quantité" required=true default=1 min=1}}
<fieldset>
<legend>Matériel</legend>
{{:input type="select_groups" name="equipment" label="Matériel" required=true options=$equipments}}
{{:input type="textarea" name="remarques" label="Remarques" cols="40", rows="3" required=false}}
{{:input type="select_groups" name="equipment" label="Matériel" required=true options=$equipments onchange="fixerValeurMax('f_equipment', 'f_quantite')"}}
{{:input type="textarea" name="remarques" label="Remarques" cols="40" rows="3" required=false}}
</fieldset>
</fieldset>
<p class="submit">
{{:button type="submit" name="save" label="Enregistrer" shape="right" class="main"}}
{{* :button type="submit" name="cancel" label="Annuler" shape="delete" class="main" *}}
</p>
</form>
<script type="text/javascript">
// fixer la valeur maximale du champ de saisie de la quantité
function fixerValeurMax(idSelect, idNumber) {
let option = document.getElementById(idSelect).selectedOptions[0];
let max = parseInt(option.label.match(/\(dispo : ([0-9]+)\)/)[1]);
let val = parseInt(document.getElementById(idNumber).value);
document.getElementById(idNumber).setAttribute("max", max);
if (val > max) {
document.getElementById(idNumber).value = max;
}
}
</script>
{{:admin_footer}}