Ajout modification entrée
This commit is contained in:
parent
128f76e8f8
commit
10dcb47d86
|
@ -50,13 +50,11 @@
|
|||
href="delete_entree.html?key=%s"|args:$mvt_key
|
||||
shape="delete"
|
||||
target="_dialog"}}
|
||||
{{*
|
||||
{{:linkbutton
|
||||
label="Supprimer"
|
||||
href="../delete_movement.html?key=%s&mvt=entrée&caller=%s"|args:$mvt_key:$request_url
|
||||
shape="delete"
|
||||
label="Modifier"
|
||||
href="modifier_entree.html?key=%s"|args:$mvt_key
|
||||
shape="edit"
|
||||
target="_dialog"}}
|
||||
*}}
|
||||
</td>
|
||||
</tr>
|
||||
{{/list}}
|
||||
|
|
|
@ -0,0 +1,220 @@
|
|||
{{#restrict section="config" level="admin" block=true}}{{/restrict}}
|
||||
{{:admin_header title="Modifier une entrée" current="module_equipment"}}
|
||||
|
||||
{{*
|
||||
************************************************************************
|
||||
TEST
|
||||
************************************************************************
|
||||
*}}
|
||||
|
||||
{{* achat 1 caméra 30/10/23 *}}
|
||||
{{:assign key_mvt= 91b794f5-5cb7-449e-9378-d1813a436b46 }}
|
||||
|
||||
{{* Emprunt 13 chaises 15/06/22 *}}
|
||||
{{:assign key_mvt=6fcc2787-9d0e-497d-b4dd-c23bc3a3e0f6}}
|
||||
|
||||
{{* achat 1 micro 30/10/23 *}}
|
||||
{{:assign key_mvt=93b46b27-577a-4f81-a0bf-f183887b7567}}
|
||||
|
||||
{{* achat 4 micros 5/10/22 *}}
|
||||
{{:assign key_mvt=98e68d24-473c-4188-a0e9-f020f943c7f2}}
|
||||
|
||||
{{* achat 2 canapés 2/11/22 *}}
|
||||
{{:assign key_mvt=445c6f0d-d4eb-4981-ba8f-432e68c36ff2}}
|
||||
|
||||
{{*
|
||||
************************************************************************
|
||||
/TEST
|
||||
************************************************************************
|
||||
*}}
|
||||
|
||||
{{:assign key_mvt=$_GET.key}}
|
||||
|
||||
{{* récupérer les infos du mouvement à modifier *}}
|
||||
{{#load key=$key_mvt assign="mvt_modif"}}
|
||||
{{else}}
|
||||
{{:error message="Aucune entrée avec la clé %s"|args:$key_mvt}}
|
||||
{{/load}}
|
||||
{{:assign entree_modif=$mvt_modif.inputNature}}
|
||||
{{:assign amount_modif=$mvt_modif.amount}}
|
||||
{{:assign date_modif=$mvt_modif.date|date_short}}
|
||||
{{:assign key_eqpmt_modif=$mvt_modif.equipment}}
|
||||
|
||||
{{* types d'entrées *}}
|
||||
{{:assign rang=0}}
|
||||
{{#foreach from=$module.config.inputNature item="elem"}}
|
||||
{{* if $elem.type != 'retour' *}}
|
||||
{{:assign var='types_entrees.' value="%s"|args:$elem.label}}
|
||||
{{if $elem.label == $mvt_modif.inputNature}}
|
||||
{{:assign type_defaut=$rang}}
|
||||
{{/if}}
|
||||
{{:assign rang="%d+1"|math:$rang}}
|
||||
{{* /if *}}
|
||||
{{/foreach}}
|
||||
{{* :debug types_entrees=$types_entrees *}}
|
||||
|
||||
{{* récupérer les infos du matériel associé *}}
|
||||
{{#load key=$key_eqpmt_modif assign="eqpmt_modif"}}
|
||||
{{else}}
|
||||
{{:error message="Aucun matériel avec la clé « %s »"|args:$key_eqpmt_modif}}
|
||||
{{/load}}
|
||||
|
||||
{{#form on="change"}}
|
||||
{{* préparer le mouvement modifié *}}
|
||||
{{:assign var="operation" from="types_entrees.%d"|args:$_POST.type_operation}}
|
||||
{{:assign var="mvt_modif.inputNature" from="types_entrees.%d"|args:$_POST.type_operation}}
|
||||
{{:assign var="mvt_modif.amount" value=$_POST.amount}}
|
||||
{{:assign var="mvt_modif.equipment" value=$_POST.equipment}}
|
||||
{{:assign var="mvt_modif.date" value=$_POST.date|parse_date}}
|
||||
{{:assign var="mvt_modif.comment" value=$_POST.comment}}
|
||||
|
||||
{{* lister les mouvements *}}
|
||||
{{#select
|
||||
id, key,
|
||||
json_extract(document, '$.type') as 'type',
|
||||
json_extract(document, '$.direction') as 'direction',
|
||||
json_extract(document, '$.inputNature') as 'inputNature',
|
||||
json_extract(document, '$.outputNature') as 'outputNature',
|
||||
json_extract(document, '$.amount') as 'amount',
|
||||
json_extract(document, '$.equipment') as 'equipment',
|
||||
json_extract(document, '$.date') as 'date',
|
||||
json_extract(document, '$.comment') as 'comment'
|
||||
FROM module_data_equipment
|
||||
WHERE json_extract(document, '$.type') = 'movement'
|
||||
ORDER BY json_extract(document, '$.date')
|
||||
;
|
||||
assign="movements."
|
||||
}}
|
||||
{{/select}}
|
||||
|
||||
{{*
|
||||
remplacer le mouvement sélectionné par sa version modifiée
|
||||
en l'insérant à sa place par date croissante
|
||||
*}}
|
||||
{{:assign insere=false}}
|
||||
{{#foreach from=$movements item="movement"}}
|
||||
{{if $movement.key != $key_mvt}}
|
||||
{{if $movement.date > $mvt_modif.date && ! $insere}}
|
||||
{{:assign var=movements_mod." from=mvt_modif}}
|
||||
{{:assign insere=true}}
|
||||
{{/if}}
|
||||
{{:assign var=movements_mod." from=movement}}
|
||||
{{/if}}
|
||||
{{/foreach}}
|
||||
{{if ! $insere}}
|
||||
{{:assign var=movements_mod." from=mvt_modif}}
|
||||
{{/if}}
|
||||
|
||||
{{*
|
||||
Vérifier la cohérence des opérations :
|
||||
- si le matériel n'a pas changé, vérifier les E/S de ce matériel
|
||||
- si le matériel a changé, vérifier les E/S de l'ancien et du nouveau matériel !!!
|
||||
*}}
|
||||
|
||||
{{* Vérifier la cohérence des opérations de l'ancien matériel *}}
|
||||
{{:include file="./valider_operation.html" keep="erreur" movements=$movements_mod eqpmt_key=$key_eqpmt_modif}}
|
||||
{{* :debug erreur1=$erreur *}}
|
||||
{{*
|
||||
{{:assign erreur = false}}
|
||||
{{:assign stock=0}}
|
||||
{{:assign exterieur=0}}
|
||||
{{:assign nonprop=0}}
|
||||
{{#foreach from=$movements_mod item="movement"}}
|
||||
{{if $movement.direction == 'entrée'}}
|
||||
{{* chercher le type d'entrée parmi les types de la config *}}
|
||||
{{*
|
||||
{{#foreach from=$module.config.inputNature item="elem"}}
|
||||
{{if $movement.inputNature == $elem.label}}
|
||||
{{if $elem.type == 'définitif'}}
|
||||
{{:assign stock="%d+%d"|math:$stock:$movement.amount}}
|
||||
{{elseif $elem.type == 'retour'}}
|
||||
{{:assign exterieur="%d-%d"|math:$exterieur:$movement.amount}}
|
||||
{{elseif $elem.type == 'temporaire'}}
|
||||
{{:assign nonprop="%d+%d"|math:$nonprop:$movement.amount}}
|
||||
{{/if}}
|
||||
{{/if}}
|
||||
{{/foreach}}
|
||||
{{elseif $movement.direction == 'sortie'}}
|
||||
{{* chercher le type de sortie parmi les types de la config *}}
|
||||
{{*
|
||||
{{#foreach from=$module.config.outputNature item="elem"}}
|
||||
{{if $movement.outputNature == $elem.label}}
|
||||
{{if $elem.type == 'définitif'}}
|
||||
{{:assign stock="%d-%d"|math:$stock:$movement.amount}}
|
||||
{{elseif $elem.type == 'temporaire'}}
|
||||
{{:assign exterieur="%d+%d"|math:$exterieur:$movement.amount}}
|
||||
{{elseif $elem.type == 'retour'}}
|
||||
{{:assign nonprop="%d-%d"|math:$nonprop:$movement.amount}}
|
||||
{{/if}}
|
||||
{{/if}}
|
||||
{{/foreach}}
|
||||
{{/if}}
|
||||
|
||||
{{if $stock < 0 || $exterieur < 0 || $nonprop < 0}}
|
||||
{{#load key=$mvt_modif.equipment assign="eqpmt"}}{{/load}}
|
||||
<p class="block error">
|
||||
Modification demandée impossible :
|
||||
« {{$entree_modif}} de {{$eqpmt_modif.designation}} (qté : {{$amount_modif}}) en date du {{$date_modif}} » vers
|
||||
« {{$mvt_modif.inputNature}} de {{$eqpmt.designation}} (qté : {{$mvt_modif.amount}}) à la date du {{$mvt_modif.date|date_short}} »
|
||||
</p>
|
||||
{{:assign erreur=true}}
|
||||
{{:break}}
|
||||
{{/if}}
|
||||
{{/foreach}}
|
||||
*}}
|
||||
|
||||
{{* Vérifier la cohérence des opérations du nouveau matériel *}}
|
||||
{{if ! $erreur && $key_eqpmt_modif != $_POST.equipment}}
|
||||
{{:include file="./valider_operation.html" keep="erreur" movements=$movements_mod eqpmt_key=$_POST.equipment}}
|
||||
{{* :debug erreur2=$erreur *}}
|
||||
{{/if}}
|
||||
|
||||
{{#load key=$mvt_modif.equipment assign="eqpmt"}}{{/load}}
|
||||
{{if $erreur}}
|
||||
<p class="block error">
|
||||
Modification demandée impossible :
|
||||
« {{$entree_modif}} de {{$eqpmt_modif.designation}} (qté : {{$amount_modif}}) en date du {{$date_modif}} » vers
|
||||
« {{$mvt_modif.inputNature}} de {{$eqpmt.designation}} (qté : {{$mvt_modif.amount}}) à la date du {{$mvt_modif.date|date_short}} »
|
||||
</p>
|
||||
{{else}}
|
||||
<p class="block confirm">
|
||||
La modification de
|
||||
« {{$entree_modif}} de {{$eqpmt_modif.designation}} (qté : {{$amount_modif}}) en date du {{$date_modif}} » vers
|
||||
« {{$mvt_modif.inputNature}} de {{$eqpmt.designation}} (qté : {{$mvt_modif.amount}}) à la date du {{$mvt_modif.date|date_short}} » est possible
|
||||
</p>
|
||||
{{/if}}
|
||||
|
||||
{{/form}}
|
||||
|
||||
|
||||
{{* lister les catégories et matériels associés *}}
|
||||
{{#load type="category" assign="category" order="$$.name"}}
|
||||
{{:assign nom_cat=$category.name}}
|
||||
{{#load type="equipment" where="$$.category = :key" :key=$category.key assign="equipment"}}
|
||||
{{:assign var="equipments.%s.%s"|args:$nom_cat:$equipment.key value=$equipment.designation}}
|
||||
{{/load}}
|
||||
{{/load}}
|
||||
|
||||
{{* formulaire de modification du mouvement *}}
|
||||
<form method="post" action="">
|
||||
|
||||
<fieldset class="entree">
|
||||
<legend>Modifier l'entrée « {{$mvt_modif.inputNature}} {{$eqpmt_modif.designation}} ({{$mvt_modif.amount}}) en date du {{$date_modif}} »</legend>
|
||||
{{:input type="select" name="type_operation" label="Type" required=true options=$types_entrees default=$type_defaut}}
|
||||
{{:input type="date" name="date" label="Date" required=true default=$mvt_modif.date}}
|
||||
{{:input type="number" name="amount" label="Quantité" required=true default=$mvt_modif.amount}}
|
||||
|
||||
<fieldset>
|
||||
<legend>Matériel</legend>
|
||||
{{:input type="select_groups" name="equipment" label="Matériel" required=true options=$equipments default=$key_eqpmt_modif}}
|
||||
{{:input type="textarea" name="comment" label="Remarques" cols="40", rows="3" required=false default=$mvt_modif.comment}}
|
||||
</fieldset>
|
||||
</fieldset>
|
||||
|
||||
<p class="submit">
|
||||
{{:button type="submit" name="change" label="Enregistrer" shape="right" class="main"}}
|
||||
</p>
|
||||
|
||||
</form>
|
||||
|
||||
{{:admin_footer}}
|
|
@ -0,0 +1,54 @@
|
|||
{{*
|
||||
Vérifier la cohérence des E/S d'un matériel
|
||||
- paramètres :
|
||||
- movements : liste de mouvements
|
||||
- eqpmt_key : clé du matériel à vérifier
|
||||
*}}
|
||||
|
||||
{{* :debug movements=$movements *}}
|
||||
{{* :debug eqpmt_key=$eqpmt_key *}}
|
||||
|
||||
{{:assign erreur = false}}
|
||||
{{:assign stock=0}}
|
||||
{{:assign exterieur=0}}
|
||||
{{:assign nonprop=0}}
|
||||
{{#foreach from=$movements item="movement"}}
|
||||
{{if $movement.equipment == $eqpmt_key}}
|
||||
{{* :debug movement=$movement *}}
|
||||
{{if $movement.direction == 'entrée'}}
|
||||
{{* chercher le type d'entrée parmi les types de la config *}}
|
||||
{{#foreach from=$module.config.inputNature item="elem"}}
|
||||
{{if $movement.inputNature == $elem.label}}
|
||||
{{if $elem.type == 'définitif'}}
|
||||
{{:assign stock="%d+%d"|math:$stock:$movement.amount}}
|
||||
{{elseif $elem.type == 'retour'}}
|
||||
{{:assign exterieur="%d-%d"|math:$exterieur:$movement.amount}}
|
||||
{{elseif $elem.type == 'temporaire'}}
|
||||
{{:assign nonprop="%d+%d"|math:$nonprop:$movement.amount}}
|
||||
{{/if}}
|
||||
{{/if}}
|
||||
{{/foreach}}
|
||||
{{elseif $movement.direction == 'sortie'}}
|
||||
{{* chercher le type de sortie parmi les types de la config *}}
|
||||
{{#foreach from=$module.config.outputNature item="elem"}}
|
||||
{{if $movement.outputNature == $elem.label}}
|
||||
{{if $elem.type == 'définitif'}}
|
||||
{{:assign stock="%d-%d"|math:$stock:$movement.amount}}
|
||||
{{elseif $elem.type == 'temporaire'}}
|
||||
{{:assign exterieur="%d+%d"|math:$exterieur:$movement.amount}}
|
||||
{{elseif $elem.type == 'retour'}}
|
||||
{{:assign nonprop="%d-%d"|math:$nonprop:$movement.amount}}
|
||||
{{/if}}
|
||||
{{/if}}
|
||||
{{/foreach}}
|
||||
{{/if}}
|
||||
{{* :debug stock=$stock *}}
|
||||
{{* :debug exter=$exterieur *}}
|
||||
{{* :debug nonprop=$nonprop *}}
|
||||
{{:assign dispo="%d-%d"|math:$stock:$exterieur}}
|
||||
{{if $dispo < 0 || $stock < 0 || $exterieur < 0 || $nonprop < 0}}
|
||||
{{:assign erreur=true}}
|
||||
{{:break}}
|
||||
{{/if}}
|
||||
{{/if}}
|
||||
{{/foreach}}
|
Loading…
Reference in New Issue