Enregistrement quantités avec matériel
This commit is contained in:
parent
bea3a2f0e8
commit
c10ff02403
11 changed files with 291 additions and 201 deletions
|
|
@ -24,9 +24,9 @@
|
|||
{{* Traiter l'envoi du formulaire *}}
|
||||
{{#form on="save"}}
|
||||
|
||||
{{* vérifier la quantité saisie (UTILE ? : fait par la navigateur) *}}
|
||||
{{if $_POST.quantite <= 0}}
|
||||
{{:error message="La quantité (%s) doit être strictement positive !!"|args:$_POST.quantite}}
|
||||
{{* vérifier la quantité saisie *}}
|
||||
{{if $_POST.amount <= 0}}
|
||||
{{:error message="La quantité (%s) doit être strictement positive !!"|args:$_POST.amount}}
|
||||
{{/if}}
|
||||
|
||||
{{* interdire date dans le futur *}}
|
||||
|
|
@ -35,25 +35,26 @@
|
|||
{{/if}}
|
||||
|
||||
{{* vérifier l'existence d'un matériel de même nom *}}
|
||||
{{#load type="equipment" where="$$.name = :name COLLATE U_NOCASE" :name=$_POST.name|trim limit=1}}}}
|
||||
{{:assign equipment_key=$key}}
|
||||
{{:assign var=nom_cat from="categories.%s"|args:$category}}
|
||||
{{#load type="equipment" where="$$.name = :name COLLATE U_NOCASE" :name=$_POST.name|trim limit=1 assign="equipment"}}
|
||||
{{:assign present=true}}
|
||||
{{/load}}
|
||||
{{:assign var=nom_cat from="categories.%s"|args:$equipment.category}}
|
||||
{{:assign var=post_cat from="categories.%s"|args:$_POST.category}}
|
||||
|
||||
{{:assign post_mat=$_POST.name|trim|tolower|ucfirst}}
|
||||
{{:assign var="type_mvt" from="config.input_nature.%s.type"|args:$_POST.operation}}
|
||||
|
||||
{{if $present}}
|
||||
{{* voir si le matériel existe dans une autre catégorie *}}
|
||||
{{if $nom_cat != $post_cat}}
|
||||
{{:error message="Le matériel « %s » est déjà présent dans la catégorie « %s » ..."|args:$post_mat:$nom_cat}}
|
||||
{{/if}}
|
||||
{{* utiliser la clé du matériel trouvé *}}
|
||||
|
||||
{{else}}
|
||||
{{* nouveau matériel => nouvelle clé *}}
|
||||
{{:assign equipment_key=""|uuid}}
|
||||
{{* enregistrer un nouveau matériel *}}
|
||||
{{* calculer la nouvelle quantité du matériel *}}
|
||||
{{if $type_mvt == 'définitif'}}
|
||||
{{:assign var="equipment.stock" value="%d+%d"|math:$equipment.stock:$_POST.amount|intval}}
|
||||
{{elseif $type_mvt == 'temporaire'}}
|
||||
{{:assign var="equipment.notowned" value="%d+%d"|math:$equipment.notowned:$_POST.amount|intval}}
|
||||
{{/if}}
|
||||
{{:assign equipment_key=$equipment.key}}
|
||||
{{:save
|
||||
key=$equipment_key
|
||||
validate_schema="../equipment.schema.json"
|
||||
|
|
@ -61,9 +62,32 @@
|
|||
category=$_POST.category
|
||||
name=$post_mat
|
||||
status="available"
|
||||
stock=$equipment.stock
|
||||
out=$equipment.out
|
||||
notowned=$equipment.notowned
|
||||
}}
|
||||
{{else}}
|
||||
{{* enregistrer un nouveau matériel *}}
|
||||
{{:assign equipment_key=""|uuid}}
|
||||
{{if $type_mvt == 'définitif'}}
|
||||
{{:assign stock=$_POST.amount|intval}}
|
||||
{{:assign notowned=0}}
|
||||
{{elseif $type_mvt == 'temporaire'}}
|
||||
{{:assign notowned=$_POST.amount|intval}}
|
||||
{{:assign stock=0}}
|
||||
{{/if}}
|
||||
{{:save
|
||||
key=$equipment_key
|
||||
validate_schema="../equipment.schema.json"
|
||||
type="equipment"
|
||||
category=$_POST.category
|
||||
name=$post_mat
|
||||
status="available"
|
||||
stock=$stock
|
||||
out=0
|
||||
notowned=$notowned
|
||||
}}
|
||||
{{/if}}
|
||||
|
||||
{{* Enregistrer le mouvement *}}
|
||||
{{:assign mvt_key=""|uuid}}
|
||||
{{:assign var="operation" from="input_labels.%d"|args:$_POST.type_operation}}
|
||||
|
|
@ -73,14 +97,13 @@
|
|||
type="movement"
|
||||
direction="input"
|
||||
operation=$_POST.operation
|
||||
amount=$_POST.quantite|intval
|
||||
amount=$_POST.amount|intval
|
||||
equipment=$equipment_key
|
||||
date=$_POST.date|parse_date
|
||||
comment=$_POST.remarques|trim
|
||||
}}
|
||||
|
||||
{{:assign var=entree from="config.input_nature.%s"|args:$_POST.operation}}
|
||||
{{if $entree.type == "temporaire"}}
|
||||
{{if $type_mvt == "temporaire"}}
|
||||
{{:assign prop=0}}
|
||||
{{else}}
|
||||
{{:assign prop=1}}
|
||||
|
|
@ -100,7 +123,7 @@
|
|||
<dl>
|
||||
{{:input type="select" name="operation" label="Type" required=true default_empty="— Aucun —" options=$input_labels|sort}}
|
||||
{{:input type="date" name="date" label="Date" required=true default=$now|date_short}}
|
||||
{{:input type="number" name="quantite" label="Quantité" min=1 required=true default=1}}
|
||||
{{:input type="number" name="amount" label="Quantité" min=1 required=true default=1}}
|
||||
</dl>
|
||||
</fieldset>
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue