diff --git a/_nav.html b/_nav.html
index f8b6023..5430e64 100644
--- a/_nav.html
+++ b/_nav.html
@@ -4,7 +4,7 @@
{{if $subcurrent == null}}
{{if $current == "managed" || $current == "amortized" || $current == "archived"}}
{{/if}}
{{/if}}
diff --git a/_upgrade_to042.tpl b/_upgrade_to042.tpl
index 445015d..95fef92 100644
--- a/_upgrade_to042.tpl
+++ b/_upgrade_to042.tpl
@@ -13,7 +13,7 @@
{{:assign line_id=$type|cat:"_line_id"}}
{{#load type=$link_type assign="link"}}
{{:assign new_link=null}}
- {{:assign var="new_link.key value=$link.key}}
+ {{:assign var="new_link.key" value=$link.key}}
{{:assign var="new_link.type" value=$link.type}}
{{:assign var="new_link.immo_doc_id" value=$link.immo_doc_id}}
{{:assign var="new_link.line_id" from="link.%s"|args:$line_id}}
diff --git a/add_asset.html b/add_asset.html
index 6473370..a704dea 100644
--- a/add_asset.html
+++ b/add_asset.html
@@ -20,6 +20,12 @@
{{* Traiter l'envoi du formulaire *}}
{{#form on="add"}}
{{* vérifier que la date d'achat est située dans un l'exercice sélectionné *}}
+ {{if $_POST.date_achat|parse_date === false}}
+ {{:error message="Erreur : la date d'achat (%s) est invalide"|args:$_POST.date_achat}}
+ {{/if}}
+ {{if $_POST.date_mes|parse_date === false}}
+ {{:error message="Erreur : la date de mise en service (%s) est invalide"|args:$_POST.date_mes}}
+ {{/if}}
{{:assign ts_date = $_POST.date_achat|parse_date|strtotime}}
{{:assign ok=false}}
{{#foreach from=$years}}
@@ -93,7 +99,12 @@
{{:assign da=$_POST.date_achat|date_short}}
{{:error message="Erreur : la date de mise en service (%s) ne peut être antérieure à la date d'acquisition (%s)"|args:$dd:$da}}
{{/if}}
+
{{:assign duration=$_POST.duree|intval}}
+ {{if $duration <= 0}}
+ {{:error message="Erreur : la durée d'amortissement doit être strictement positive"}}
+ {{/if}}
+
{{:assign status="managed"}}
{{if $_POST.date_mes == null || $_POST.date_mes == $_POST.date_achat}}
{{:assign date_mes=null}}
@@ -151,7 +162,7 @@
{{* barre de navigation *}}
{{if ! $dialog}}
- {{:linkbutton href="index.html" label="Retour" shape="left"}}
+ {{:linkbutton href="index.html?type_immo=%s"|args:$_GET.from label="Retour" shape="left"}}
{{/if}}
{{:form_errors}}
diff --git a/add_infos.html b/add_infos.html
index d2a4874..cac3115 100644
--- a/add_infos.html
+++ b/add_infos.html
@@ -73,6 +73,12 @@
{{:redirect force="exit_step1.html?immo_doc_id=%s&from=exit"|args:$immo_doc_id}}
{{else}}
{{* immobilisation amortissable *}}
+ {{if $_POST.date_achat|parse_date === false}}
+ {{:error message="Erreur : la date d'achat (%s) est invalide"|args:$_POST.date_achat}}
+ {{/if}}
+ {{if $_POST.date_mes|parse_date === false}}
+ {{:error message="Erreur : la date de mise en service (%s) est invalide"|args:$_POST.date_mes}}
+ {{/if}}
{{if $_POST.date_achat|parse_date > $ligne_immo.date_achat}}
{{:assign da=$ligne_immo.date_achat|date_short}}
{{:error message="Erreur : la date d'achat (%s) ne peut être postérieure à la date de l'écriture d'immobilisation (%s)"|args:$_POST.date_achat:$da}}
diff --git a/attach_credit.html b/attach_credit.html
index b1adb99..26ba567 100644
--- a/attach_credit.html
+++ b/attach_credit.html
@@ -61,7 +61,7 @@
{{* Traiter l'envoi du formulaire *}}
{{#form on="save"}}
- {{if $_POST.montant == null}}
+ {{if $_POST.montant == null || $_POST.montant == 0}}
{{if $montant_affecte == 0}}
{{:assign saved_credit=null}}
{{:assign montant_credit=$credit_line.amount}}
diff --git a/balance_sheet_exit.html b/balance_sheet_exit.html
index 4043c5d..b6b4d5a 100644
--- a/balance_sheet_exit.html
+++ b/balance_sheet_exit.html
@@ -35,9 +35,6 @@
{{:assign amort_number=$linked_amort|count}}
{{#foreach from=$linked_amort|ksort item="line"}}
- {{if $first_amort_date == null}}
- {{:assign first_amort_date=$line.date}}
- {{/if}}
{{if $last_amort_date == null}}
{{:assign last_amort_date=$line.date}}
{{elseif $line.date > $last_amort_date}}
@@ -82,11 +79,15 @@
{{* Traiter l'envoi du formulaire *}}
{{#form on="proceed"}}
+ {{* vérifier la validité de la date de sortie *}}
{{if $_POST.date_sortie == null}}
{{:error message="Vous devez renseigner la date de sortie"}}
{{/if}}
- {{* vérifier la validité de la date de sortie *}}
+ {{if $_POST.date_sortie|parse_date === false}}
+ {{:error message="Erreur : la date de sortie (%s) est invalide"|args:$_POST.date_sortie}}
+ {{/if}}
+
{{if $info_immo.date_mes != null}}
{{if $_POST.date_sortie|parse_date < $info_immo.date_mes}}
{{:assign immo_date=$info_immo.date_mes|date_short}}
@@ -96,6 +97,7 @@
{{:assign immo_date=$ligne_immo.date_achat|date_short}}
{{:error message="La date de sortie doit être postérieure à la date d'acquisition de l'immobilisation (%s)"|args:$immo_date}}
{{/if}}
+
{{if $amort_number != 0 && $_POST.date_sortie|parse_date <= $last_amort_date}}
{{:assign last_amort_date=$last_amort_date|date_short}}
{{:error message="La date de sortie doit être postérieure à la date du dernier amortissement (%s)"|args:$last_amort_date}}
@@ -103,6 +105,7 @@
{{:assign ts_exit = $_POST.date_sortie|parse_date|strtotime}}
{{:assign exercice_ok=false}}
+
{{* vérifier que la date de sortie est dans l'exercice choisi *}}
{{#foreach from=$years item="current_year"}}
{{if $current_year.id == $_POST.id_year}}
diff --git a/index.html b/index.html
index 06ab7e4..aee4165 100644
--- a/index.html
+++ b/index.html
@@ -7,9 +7,7 @@
{{:assign type_immo=$_GET.type_immo}}
{{/if}}
-{{if $type_immo == "managed"}}
- {{:admin_header title="Immobilisations en cours d'amortissement" custom_css="./style.css" current="module_amortization"}}
-{{elseif $type_immo == "amortized"}}
+{{if $type_immo == "amortized"}}
{{:admin_header title="Immobilisations amorties" custom_css="./style.css" current="module_amortization"}}
{{elseif $type_immo == "archived"}}
{{:admin_header title="Immobilisations archivées" custom_css="./style.css" current="module_amortization"}}
@@ -17,6 +15,9 @@
{{:admin_header title="Immobilisations à classer" custom_css="./style.css" current="module_amortization"}}
{{elseif $type_immo == "unfinished"}}
{{:admin_header title="Immobilisations en cours de constitution" custom_css="./style.css" current="module_amortization" subcurrent="unfinished"}}
+{{else}}
+ {{:assign type_immo="managed"}}
+ {{:admin_header title="Immobilisations en cours d'amortissement" custom_css="./style.css" current="module_amortization"}}
{{/if}}
{{:include file="_nav.html" current=$type_immo}}
@@ -46,7 +47,7 @@
{{:include file="_archives.html"}}
{{elseif $type_immo == "unfinished"}}
{{:include file="_unfinished.html"}}
-{{elseif $type_immo == "managed" || $type_immo == "amortized"}}
+{{else}}
{{:include file="_immobilisations.html"}}
{{/if}}
{{:admin_footer}}
diff --git a/modify_infos.html b/modify_infos.html
index 2e056e5..4830d7c 100644
--- a/modify_infos.html
+++ b/modify_infos.html
@@ -34,6 +34,18 @@
{{* traiter la saisie *}}
{{#form on="save"}}
+ {{if $_POST.date_achat == null || $_POST.date_achat|parse_date == $ligne_immo.date_achat}}
+ {{:assign date_achat=null}}
+ {{else}}
+ {{:assign date_achat=$_POST.date_achat|parse_date}}
+ {{/if}}
+
+ {{if $_POST.date_mes == null || $_POST.date_mes == $_POST.date_achat}}
+ {{:assign date_mes=null}}
+ {{else}}
+ {{:assign date_mes=$_POST.date_mes|parse_date}}
+ {{/if}}
+
{{if $_POST.date_achat|parse_date > $ligne_immo.date_achat}}
{{:assign da=$ligne_immo.date_achat|date_short}}
{{:error message="Erreur : la date d'achat (%s) ne peut être postérieure à la date de l'écriture d'immobilisation (%s)"|args:$_POST.date_achat:$da}}
diff --git a/module.ini b/module.ini
index 73633af..515fdfd 100644
--- a/module.ini
+++ b/module.ini
@@ -1,5 +1,5 @@
name="Amortissements"
-description="Immobilisations et amortissements\nversion 0.42"
+description="Immobilisations et amortissements\nversion 0.42.2"
author="Jean-Christophe Engel"
author_url="https://gitea.zaclys.com/lesanges"
home_button=false
diff --git a/save_amort.html b/save_amort.html
index 0226760..3e871a7 100644
--- a/save_amort.html
+++ b/save_amort.html
@@ -93,6 +93,9 @@
{{* Traiter l'envoi du formulaire *}}
{{#form on="save"}}
{{* vérifier que la date est située dans un exercice compatible *}}
+ {{if $_POST.date_amort|parse_date === false}}
+ {{:error message="Erreur : la date d'amortissement (%s) est invalide"|args:$_POST.date_amort}}
+ {{/if}}
{{:assign ts_date = $_POST.date_amort|parse_date|strtotime}}
{{:assign ok=false}}
{{#foreach from=$years}}
diff --git a/transfer.html b/transfer.html
index 3017036..151d4e7 100644
--- a/transfer.html
+++ b/transfer.html
@@ -69,6 +69,9 @@
{{* Traiter l'envoi du formulaire *}}
{{#form on="transfer"}}
{{* vérifier que la date de mise en service est postérieure aux dates d'acquisition *}}
+ {{if $_POST.date_mes|parse_date === false}}
+ {{:error message="Erreur : la date de mise en service (%s) est invalide"|args:$_POST.date_mes}}
+ {{/if}}
{{if $_POST.date_mes|parse_date < $max_date}}
{{:assign dacq=$max_date|date_short}}
{{:error message="La date de mise en service (%s) doit être postérieure à la date d'acquisition d'immobilisation la plus récente (%s) !"|args:$_POST.date_mes:$dacq}}
@@ -96,6 +99,9 @@
{{:assign status="ignored"}}
{{else}}
{{:assign duration=$_POST.duree|intval}}
+ {{if $duration <= 0}}
+ {{:error message="Erreur : la durée d'amortissement doit être strictement positive"}}
+ {{/if}}
{{:assign status="managed"}}
{{/if}}
diff --git a/write_exit.html b/write_exit.html
index e9033d0..a62fb9c 100644
--- a/write_exit.html
+++ b/write_exit.html
@@ -320,6 +320,8 @@
:year_id = $_GET.year
}}
{{:assign chart_id=$id}}
+{{else}}
+ {{:error message="Pas de plan comptable pour l'exercice %s"|args:$_GET.year}}
{{/select}}
{{#select