Compare commits

...

2 commits

Author SHA1 Message Date
Jean-Christophe Engel
f5526c1147 save_amort : cas des amortissements multi-lignes 2026-03-03 09:38:59 +01:00
Jean-Christophe Engel
61d67e5622 Améliorations interaction 2026-03-03 09:36:36 +01:00
5 changed files with 92 additions and 43 deletions

View file

@ -174,12 +174,14 @@
<td class="money">{{"%d-%d"|math:$montant_immo:$amort_amount|money_html:false|raw}}</td>
<td><a href={{$compte_url}}>{{$account_code}}</a></td>
<td class="actions">
{{:linkbutton
label="Paramètres"
href="add_infos.html?immo_id=%s&type_immo=%s"|args:$immo_line_id:$type_immo
shape="settings"
target="_dialog"
}}
{{if ! $exist_amort || $status == "unknown"}}
{{:linkbutton
label="Paramètres"
href="add_infos.html?immo_id=%s&type_immo=%s"|args:$immo_line_id:$type_immo
shape="settings"
target="_dialog"
}}
{{/if}}
{{:linkbutton
label="Amortissements"
href="amortization.html?immo_id=%s&type_immo=%s"|args:$immo_line_id:$type_immo

View file

@ -3,7 +3,7 @@
<nav class="tabs">
{{if $current == "index" && $subsubcurrent == null}}
<aside>
{{:linkbutton label="Ajouter une immobilisation" shape="plus" href="add_asset.html" target="_dialog"}}
{{:linkbutton label="Ajouter une immobilisation" shape="plus" href="add_asset.html"}}
</aside>
{{elseif $subsubcurrent == "amortization" && $type_immo == null || $type_immo == "managed" || $type_immo == "other"}}
<aside>
@ -11,7 +11,7 @@
{{:linkbutton label="Rattacher une écriture" href="other_amortizations.html?immo_id=%s"|args:$_GET.immo_id shape="link" target="_dialog"}}
{{/if}}
{{:linkbutton label="Enregistrer un amortissement" shape="plus"
href="save_amort.html?immo_id=%s"|args:$_GET.immo_id target="_dialog"}}
href="save_amort.html?immo_id=%s"|args:$_GET.immo_id}}
</aside>
{{/if}}

View file

@ -160,7 +160,7 @@
{{:admin_header title="Ajout immobilisation" current="module_amortization"}}
{{* barre de navigation *}}
{{if ! $dialog}}
{{:include file="_nav.html" current="index"}}
{{:include file="_nav.html" current="index" subcurrent="managed"}}
{{/if}}
{{:form_errors}}

View file

@ -1,5 +1,5 @@
name="Amortissements"
description="Immobilisations et amortissements\nversion 0.30"
description="Immobilisations et amortissements\nversion 0.31"
author="Jean-Christophe Engel"
author_url="https://gitea.zaclys.com/lesanges"
home_button=false

View file

@ -7,20 +7,16 @@
{{* Infos de l'immobilisation *}}
{{#select
line.id as immo_id,
line.id_account as account_id,
line.debit as montant,
line.id_project as project_id,
trans.id as trans_id,
trans.label,
trans.date,
y.id as year_id,
y.start_date,
y.end_date,
project.label as project_label
account.code as account_code
FROM acc_transactions_lines AS line
INNER JOIN acc_transactions AS trans ON line.id_transaction = trans.id
INNER JOIN acc_years AS y ON trans.id_year = y.id
INNER JOIN acc_accounts AS account ON line.id_account = account.id
LEFT JOIN acc_projects AS project ON line.id_project = project.id
WHERE line.id = :line_id;
:line_id = $_GET.immo_id|intval
@ -30,28 +26,54 @@
{{:error message="Immobilisation %s non trouvée"|args:$_GET.immo_id}}
{{/select}}
{{:assign date_debut=$ligne_immo.date}}
{{:assign var="amort_label" value="Amortissement %s"|args:$ligne_immo.label}}
{{#load type="immo" where="$$.line = :line_id" :line_id=$_GET.immo_id|intval}}
{{:assign duree=$duration}}
{{:assign date_debut=$date}}
{{if $amount != null}}
{{:assign var="ligne_immo.montant" value=$amount}}
{{/if}}
{{:assign status=$status}}
{{else}}
{{:error message="Vous devez renseigner la date de mise en service et la durée d'immobilisation"}}
{{/load}}
{{if $status == "amortized" || $status == "archived"}}
{{:error message="Cette immobilisation est complètement amortie ; il est impossible d'ajouter une écriture d'amortissement"}}
{{/if}}
{{* chercher des écritures liées à l'immo courante au crédit du même compte
et déduire leur montant de celui de l'immo
*}}
{{:assign total_credits=0}}
{{#select
CASE links.id_related = :immo_id
WHEN true THEN links.id_transaction
WHEN false THEN links.id_related
END as other_id,
line.credit
FROM acc_transactions AS trans
INNER JOIN acc_transactions_links as links
ON (trans.id = links.id_transaction OR trans.id = links.id_related)
INNER JOIN acc_transactions_lines AS line on line.id_transaction = other_id
INNER JOIN acc_accounts AS acc ON line.id_account = acc.id
WHERE trans.id = :immo_id AND line.credit > 0 AND acc.code = :account;
:immo_id=$ligne_immo.trans_id
:account=$ligne_immo.account_code
}}
{{:assign total_credits="%d+%d"|math:$total_credits:$credit}}
{{/select}}
{{:assign var="ligne_immo.montant" value="%d-%d"|math:$ligne_immo.montant:$total_credits}}
{{:assign solde=$ligne_immo.montant}}
{{* chercher des écritures d'amortissement liées à l'immobilisation *}}
{{#select
SUM(l_amort.credit) as amort_amount,
l_amort.credit as amort_amount,
l_amort.label as amort_label,
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 amort_date,
COUNT(trans.id) as amort_number,
trans.date as amort_date,
trans.label as trans_label,
trans.id_year as amort_year,
account.id as account_id,
@ -60,20 +82,48 @@
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%'
ORDER BY trans.date DESC LIMIT 1;
WHERE
l_immo.id = :line_id
AND account.code LIKE '28%'
ORDER BY trans.date;
: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"
order="$$.date"
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 var="linked_amort." value=$amort_line}}
{{/if}}
{{else}}
{{:assign var="linked_amort." value=$amort_line}}
{{/load}}
{{/select}}
{{if $amort_line.amort_number == 0}}
{{:assign total_amort=0}}
{{:assign valeur_residuelle=$ligne_immo.montant}}
{{#foreach from=$linked_amort}}
{{:assign valeur_residuelle="%d-%d"|math:$valeur_residuelle:$amort_amount}}
{{:assign total_amort="%d+%d"|math:$total_amort:$amort_amount}}
{{:assign date_debut=$amort_date}}
{{:assign code_amort=$account_code}}
{{:assign amort_account_label=$account_label}}
{{:assign amort_label=$amort_label}}
{{/foreach}}
{{if $valeur_residuelle == 0}}
{{:error message="Cette immobilisation est complètement amortie ; il est impossible d'ajouter une écriture d'amortissement"}}
{{/if}}
{{if $total_amort == 0}}
{{* 1er amortissement *}}
{{* déterminer le compte d'amortissement en fonction du compte d'immobilisation *}}
{{#select code, label from acc_accounts where id = :id; :id=$ligne_immo.account_id assign=amort_account}}
@ -83,15 +133,12 @@
code_immo=$amort_account.code
keep="code_amort"
}}
{{:assign var=amort_label value="Amortissement %s"|args:$amort_account.label}}
{{:assign var="amort_account_label" value="Amortissement %s"|args:$amort_account.label}}
{{:assign var=libelle value="Amortissement %s"|args:$ligne_immo.label}}
{{else}}
{{* amortissements suivants *}}
{{:assign date_debut=$amort_line.amort_date|strtotime}}
{{:assign date_debut=$date_debut|strtotime}}
{{:assign date_debut="%d+(60*60*24)"|math:$date_debut|date:"Y-m-d"}}
{{:assign var=code_amort value=$amort_line.account_code}}
{{:assign var=amort_label value=$amort_line.account_label}}
{{:assign var=libelle value=$amort_line.amort_label}}
{{/if}}
{{*
@ -101,7 +148,7 @@
{{:assign msg_years=""}}
{{#years closed=false order="start_date" where="start_date <= :debut AND :debut <= end_date"
:debut=$date_debut assign=years.}}
{{if $amort_line.amort_number == 0}}
{{if $total_amort == 0}}
{{:assign ts_debut=$date_debut|strtotime}}
{{else}}
{{:assign ts_debut=$start_date|strtotime}}
@ -174,7 +221,7 @@
{{/if}}
{{* vérifier que le montant ne dépasse pas le solde restant *}}
{{:assign solde="%d-%d"|math:$ligne_immo.montant:$amort_line.amort_amount}}
{{:assign solde="%d-%d"|math:$ligne_immo.montant:$total_amort}}
{{if $_POST.montant|trim|money_int > $solde|intval}}
{{:assign solde=$solde|money_raw}}
{{:error message="Le montant indiqué « %s » dépasse le solde à amortir « %s »"|args:$_POST.montant:$solde}}
@ -185,14 +232,14 @@
var="lines."
debit=$_POST.montant
account=$debit_account|keys|value:0
id_project=$_GET.project_id
id_project=$ligne_immo.project_id
label=$_POST.designation
}}
{{:assign
var="lines."
credit=$_POST.montant
account=$credit_account|keys|value:0
id_project=$_GET.project_id
id_project=$ligne_immo.project_id
label=$_POST.designation
}}
{{:api
@ -211,7 +258,7 @@
{{:redirect force="amortization.html?immo_id=%s&ok=1&msg=amortissement"|args:$_GET.immo_id}}
{{/form}}
{{:admin_header title="Ajout amortissement" current="module_amortization"}}
{{:admin_header title="Ajout amortissement" custom_css="./style.css" current="module_amortization"}}
{{* barre de navigation *}}
{{if ! $dialog}}
@ -226,9 +273,9 @@
{{* montant de l'amortissement *}}
{{:assign montant_amort="%f/%f/365*%d"|math:$ligne_immo.montant:$duree:$nbjours|intval}}
{{:assign montant_amort="min(%f, %d-%d)"|math:$montant_amort:$ligne_immo.montant:$amort_line.amort_amount}}
{{:assign montant_amort="min(%f, %d-%d)"|math:$montant_amort:$ligne_immo.montant:$total_amort}}
{{:assign var="debit_account.6811" value="6811 — Dot. aux amortissements des immobilisations"}}
{{:assign var="credit_account.%s"|args:$code_amort value="%s — "|args:$code_amort|cat:$amort_label}}
{{:assign var="credit_account.%s"|args:$code_amort value="%s — "|args:$code_amort|cat:$amort_account_label}}
{{* -------------------------------------------------------------------------------- *}}
@ -242,7 +289,7 @@
<dl>
{{:input type="select" default=$selected_year name="id_year" label="Exercice" required=true default_empty="— Faire un choix —" options=$open_years}}
{{:input type="date" name="date_amort" label="Date" required=true default=$date_amort|date_short}}
{{:input type="text" name="designation" label="Libellé" required=true default=$libelle}}
{{:input type="text" name="designation" label="Libellé" required=true default=$amort_label}}
{{:input type="money" name="montant" label="Montant" required=true default=$montant_amort}}
{{:input
type="list"
@ -263,7 +310,7 @@
<div id="donnees" class="hidden">
{{:input type="text" name="montant_immo" default=$ligne_immo.montant}}
{{:input type="text" name="duree_amort" default=$duree}}
{{:input type="text" name="somme_amort" default=$amort_line.amort_amount}}
{{:input type="text" name="somme_amort" default=$total_amort}}
{{:input type="select" name="years_data" options=$years_data}}
</div>
</dl>