From b215c05763690f87a579af487f77438f24246715 Mon Sep 17 00:00:00 2001 From: Jean-Christophe Engel Date: Mon, 23 Feb 2026 11:02:58 +0100 Subject: [PATCH] balance_sheet_exit : amortissement multi-lignes --- balance_sheet_exit.html | 82 ++++++++++++++++++++++++++++------------- 1 file changed, 57 insertions(+), 25 deletions(-) diff --git a/balance_sheet_exit.html b/balance_sheet_exit.html index 636a525..e06588f 100644 --- a/balance_sheet_exit.html +++ b/balance_sheet_exit.html @@ -56,43 +56,75 @@ {{:assign var="ligne_immo.montant" value="%d-%d"|math:$ligne_immo.montant:$total_credits}} {{* chercher des écritures d'amortissement liées à l'immobilisation *}} +{{:assign total_amort=0}} +{{:assign amort_number=0}} {{#select - SUM(l_amort.credit) as amort_amount, + l_amort.credit as amort_amount, + l_amort.id as amort_line_id, CASE WHEN links.id_related = t_immo.id THEN links.id_transaction ELSE links.id_related END as amort_trans_id, - MAX(trans.date) as last_amort_date, - MIN(trans.date) as first_amort_date, - COUNT(trans.id) as amort_number + trans.date FROM acc_transactions_lines as l_immo INNER JOIN acc_transactions as t_immo on t_immo.id = l_immo.id_transaction INNER JOIN acc_transactions_links as links - ON (t_immo.id = links.id_transaction OR t_immo.id = links.id_related) + ON (t_immo.id = links.id_transaction OR t_immo.id = links.id_related) INNER JOIN acc_transactions_lines as l_amort on amort_trans_id = l_amort.id_transaction INNER join acc_transactions as trans on l_amort.id_transaction = trans.id INNER JOIN acc_accounts AS account ON l_amort.id_account = account.id WHERE l_immo.id = :line_id AND account.code LIKE '28%' - LIMIT 1; + ; :line_id = $_GET.immo_id|intval - assign=amort_line + assign="amort_line" }} + + {{#load type="link" + where="$$.immo_line_id = :immo_line_id AND $$.amort_trans_id = :amort_trans_id" + assign="line" + :immo_line_id=$_GET.immo_id|intval :amort_trans_id=$amort_line.amort_trans_id + }} + {{if $line.amort_line_id == $amort_line.amort_line_id}} + {{:assign amort_number="%d+1"|math:$amort_number}} + {{:assign total_amort="%d+%d"|math:$total_amort:$amort_line.amort_amount}} + {{if $first_amort_date == null}} + {{:assign first_amort_date=$amort_line.date}} + {{elseif $amort_line.date < $first_amort_date}} + {{:assign first_amort_date=$amort_line.date}} + {{/if}} + {{if $last_amort_date == null}} + {{:assign last_amort_date=$amort_line.date}} + {{elseif $amort_line.date > $last_amort_date}} + {{:assign last_amort_date=$amort_line.date}} + {{/if}} + {{/if}} + {{else}} + {{:assign amort_number="%d+1"|math:$amort_number}} + {{:assign total_amort="%d+%d"|math:$total_amort:$amort_line.amort_amount}} + {{if $first_amort_date == null}} + {{:assign first_amort_date=$amort_line.date}} + {{elseif $amort_line.date < $first_amort_date}} + {{:assign first_amort_date=$amort_line.date}} + {{/if}} + {{if $last_amort_date == null}} + {{:assign last_amort_date=$amort_line.date}} + {{elseif $amort_line.date > $last_amort_date}} + {{:assign last_amort_date=$amort_line.date}} + {{/if}} + {{/load}} {{/select}} -{{if $amort_line.amort_number == 0}} +{{if $total_amort == 0}} {{if $info_immo.status == "amortized"}} - {{:assign amort_amount=$ligne_immo.montant}} - {{else}} - {{:assign amort_amount=0}} - {{/if}} + {{:assign total_amort=$ligne_immo.montant}} + {{/if}} {{else}} - {{:assign amort_amount=$amort_line.amort_amount}} - {{:assign date_debut=$amort_line.last_amort_date|strtotime}} + {{:assign date_debut=$last_amort_date|strtotime}} {{:assign date_debut="%d+(60*60*24)"|math:$date_debut|date:"Y-m-d"}} {{/if}} {{:assign ts_debut=$date_debut|strtotime}} -{{:assign valeur_nette="%f-%f"|math:$ligne_immo.montant:$amort_amount}} +{{:assign valeur_nette="%f-%f"|math:$ligne_immo.montant:$total_amort}} {{* lister les exercices ouverts dont la date de fin est postérieure à la date du dernier amortissment @@ -125,9 +157,9 @@ {{* vérifier la validité de la date de mise en service *}} {{if $_POST.date_mes != null}} {{:assign ts_mes=$_POST.date_mes|parse_date|strtotime}} - {{if $ts_mes < $ligne_immo.date_achat|strtotime || $ts_mes > $amort_line.first_amort_date|strtotime}} + {{if $ts_mes < $ligne_immo.date_achat|strtotime || $ts_mes > $first_amort_date|strtotime}} {{:assign immo_date=$ligne_immo.date_achat|date_short}} - {{:assign amort_date=$amort_line.first_amort_date|date_short}} + {{:assign amort_date=$first_amort_date|date_short}} {{:error message="La date de mise en service doit être postérieure à la date d'acquisition de l'immobilisation (%s) et antérieure à la date du premier amortissement (%s)"|args:$immo_date:$amort_date}} {{/if}} {{/if}} @@ -137,8 +169,8 @@ {{if $info_immo.duration == null}} {{if $_POST.duree == null}} {{:error message="Vous devez renseigner la durée de l'immobilisation"}} - {{elseif $_POST.duree < $amort_line.amort_number}} - {{:error message="La durée de l'amortissement ne peut être inférieure au nombre d'écritures d'amortissement (%d)"|args:$amort_line.amort_number}} + {{elseif $_POST.duree < $amort_number}} + {{:error message="La durée de l'amortissement ne peut être inférieure au nombre d'écritures d'amortissement (%d)"|args:$amort_number}} {{else}} {{:assign duree_amort=$_POST.duree}} {{/if}} @@ -159,9 +191,9 @@ {{: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_line.amort_number != 0 && $_POST.date_sortie|parse_date <= $amort_line.last_amort_date}} - {{:assign last_amort_date=$amort_line.last_amort_date|date_short}} - {{:error message="La date de sortie doit être postérieure à la date de la dernière immobilisation (%s)"|args:$last_amort_date}} + {{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}} {{/if}} {{* vérifier que la date de sortie est située dans un exercice ouvert *}} @@ -178,7 +210,7 @@ {{/if}} {{* voir si des amortissements ont été oubliés *}} - {{if $valeur_nette > 0 && $info_immo.status != "amortized" && $start_date|strtotime > $amort_line.last_amort_date|strtotime && $end_date|strtotime < $now}} + {{if $valeur_nette > 0 && $info_immo.status != "amortized" && $start_date|strtotime > $last_amort_date|strtotime && $end_date|strtotime < $now}} {{:assign debut=$start_date|date_short}} {{:assign fin=$end_date|date_short}} {{:assign msg_amort=$msg_amort|cat:"\n"|cat:" - "|cat:$label|cat:" : du "|cat:$debut|cat:" au "|cat:$fin}} @@ -191,7 +223,7 @@ {{:error message="Vous devez d'abord enregistrer les amortissements des exercices suivants : %s"|args:$msg_amort}} {{/if}} - {{:redirect to="compute_exit_data.html?immo_id=%s&amort_amount=%s&year=%s&date_mes=%s&date_debut=%s&exit_date=%s&duree_amort=%s"|args:$_GET.immo_id:$amort_amount:$selected_year:$ts_mes:$ts_debut:$ts_exit:$duree_amort}} + {{:redirect to="compute_exit_data.html?immo_id=%s&amort_amount=%s&year=%s&date_mes=%s&date_debut=%s&exit_date=%s&duree_amort=%s"|args:$_GET.immo_id:$total_amort:$selected_year:$ts_mes:$ts_debut:$ts_exit:$duree_amort}} {{/form}} {{:admin_header title="Sortie de bilan" custom_css="./style.css" current="module_amortization"}} @@ -221,7 +253,7 @@
{{$info_immo.duration}} ans
{{/if}}
Montant des amortissements
-
{{$amort_amount|money_currency_html:false|raw}} (à la date de début de l'exercice)
+
{{$total_amort|money_currency_html:false|raw}} (à la date de début de l'exercice)
Valeur nette résiduelle
{{$valeur_nette|money_currency_html:false|raw}} (à la date de début de l'exercice)