diff --git a/mouvements/sorties/_calcul_dispo.html b/mouvements/sorties/_calcul_dispo.html new file mode 100644 index 0000000..2591d77 --- /dev/null +++ b/mouvements/sorties/_calcul_dispo.html @@ -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}} diff --git a/mouvements/sorties/stock_disponible.html b/mouvements/sorties/stock_disponible.html index 3faffb8..133b505 100644 --- a/mouvements/sorties/stock_disponible.html +++ b/mouvements/sorties/stock_disponible.html @@ -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}} - {{:assign var="equipments.%s.%s"|args:$nom_cat:$equipment.key value="%s (dispo : %d)"|args:$equipment.designation:$dispo}} + {{: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 @@ {{: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}}
{{:button type="submit" name="save" label="Enregistrer" shape="right" class="main"}} - {{* :button type="submit" name="cancel" label="Annuler" shape="delete" class="main" *}}
+ + {{:admin_footer}}