2024-02-23 09:24:47 +01:00
{{* -*- brindille -*- *}}
2024-02-27 11:26:08 +01:00
{{:admin_header title="Liste des amortissements" custom_css="./style.css" current="module_amortissement"}}
2024-02-15 14:23:03 +01:00
{{* barre de navigation *}}
2024-02-16 11:54:50 +01:00
{{:include file="_nav.html" current="amortization"}}
2024-02-15 14:23:03 +01:00
2024-02-27 11:26:08 +01:00
{{if $_GET.ok}}
2024-02-29 19:07:52 +01:00
{{if $_GET.msg|match:"attach"}}
{{:assign msg="Attachement effectué"}}
{{elseif $_GET.msg|match:"detach"}}
{{:assign msg="Attachement supprimé"}}
{{elseif $_GET.msg|match:"amortissement"}}
{{:assign msg="Amortissement enregistré"}}
{{/if}}
< p class = "block confirm" > {{$msg}}< / p >
2024-02-27 11:26:08 +01:00
{{elseif $_GET.err}}
2024-02-29 19:07:52 +01:00
{{if $_GET.msg|match:"attach"}}
{{:assign msg="Échec attachement"}}
{{elseif $_GET.msg|match:"amortissement"}}
{{:assign msg="Échec enregistrement amortissement"}}
{{/if}}
< p class = "block error" > {{$msg}}< / p >
2024-02-27 11:26:08 +01:00
{{/if}}
2024-02-15 14:23:03 +01:00
{{* récupérer les infos de l'immobilisation *}}
2024-03-14 18:34:45 +01:00
{{#load type="immo" assign="info_immo" where="$$.line = :line_id" :line_id=$_GET.immo_id|intval}}
{{else}}
{{:assign message="Pas d'info concernant l'immobilisation %s"|args:$_GET.immo_id}}
{{:error message=$message}}
2024-02-29 19:07:52 +01:00
{{/load}}
2024-03-14 18:34:45 +01:00
{{:assign var="duree" from="info_immo.duration"|args:$_GET.immo_id}}
2024-02-29 19:07:52 +01:00
2024-02-15 14:23:03 +01:00
{{#select
2024-03-14 18:34:45 +01:00
line.id as immo_id,
2024-02-16 11:54:50 +01:00
line.id_account as account_id,
2024-02-17 19:00:24 +01:00
line.id_project as project_id,
2024-02-15 14:23:03 +01:00
line.debit as montant,
2024-02-29 19:07:52 +01:00
trans.id as trans_id,
2024-02-15 14:23:03 +01:00
trans.label as label,
trans.date as date_achat,
2024-02-16 11:54:50 +01:00
y.id as year_id,
2024-03-15 20:53:59 +01:00
y.end_date as date_amort,
2024-02-17 19:00:24 +01:00
project.label as project_label
2024-02-15 14:23:03 +01:00
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
2024-02-17 19:00:24 +01:00
left join acc_projects AS project ON line.id_project = project.id
2024-02-15 14:23:03 +01:00
where line.id = :line_id;
2024-03-14 18:34:45 +01:00
:line_id = $_GET.immo_id|intval
2024-02-15 14:23:03 +01:00
assign=ligne_immo
}}
2024-02-29 19:07:52 +01:00
< h2 > Amortissement de « {{$label}} » d'un montant de {{"%f"|math:$montant|money_currency}} en date du {{$date_achat|date_short}} sur {{$duree}} ans< / h2 >
2024-02-15 14:23:03 +01:00
{{else}}
2024-03-14 18:34:45 +01:00
{{:assign message="Immobilisation %s non trouvée"|args:$_GET.immo_id}}
2024-02-15 14:23:03 +01:00
{{:error message=$message}}
{{/select}}
2024-02-29 19:07:52 +01:00
{{* chercher des écritures d'amortissement liées à l'immobilisation *}}
2024-02-16 11:54:50 +01:00
{{#select
2024-02-29 19:07:52 +01:00
l_amort.credit as amort_amount,
l_amort.label as amort_label,
l_amort.id as amort_line,
2024-03-14 18:34:45 +01:00
CASE links.id_related = t_immo.id
WHEN true THEN links.id_transaction
WHEN false THEN links.id_related
END as amort_trans_id,
2024-02-29 19:07:52 +01:00
trans.date as amort_date,
trans.label as trans_label,
trans.id_year as amort_year,
2024-02-27 11:26:08 +01:00
acc.code as account_code,
2024-02-29 19:07:52 +01:00
acc.label as account_name,
"vrai" as linked
2024-03-14 18:34:45 +01:00
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
)
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 acc on l_amort.id_account = acc.id
WHERE
l_immo.id = :line_id
AND
l_amort.credit < > 0
ORDER BY trans.date;
:line_id = $_GET.immo_id|intval
2024-02-29 19:07:52 +01:00
assign=linked_lines.
2024-02-16 11:54:50 +01:00
}}
2024-02-29 19:07:52 +01:00
{{:assign var="amort_years." value=$amort_year}}
2024-02-16 11:54:50 +01:00
{{/select}}
2024-02-29 19:07:52 +01:00
{{* montant de l'annuité théorique *}}
{{:assign montant="%f"|math:$ligne_immo.montant}}
{{:assign annuite="%f/%f"|math:$montant:$duree}}
2024-02-16 11:54:50 +01:00
2024-02-15 14:23:03 +01:00
{{* première annuité *}}
{{:assign date_achat=$ligne_immo.date_achat|date_short}}
2024-03-14 18:34:45 +01:00
{{:assign date_amort=$ligne_immo.date_amort|date_short}}
{{:include file="_calcul_dates.html" date_debut=$date_achat date_fin=$date_amort keep="nbjours"}}
2024-02-16 11:54:50 +01:00
{{:assign annuite_1="%f/360*%d"|math:$annuite:$nbjours|intval}}
2024-02-15 14:23:03 +01:00
{{:assign annuite_courante=$annuite_1}}
2024-02-16 11:54:50 +01:00
{{:assign current_year=$ligne_immo.year_id}}
2024-02-29 19:07:52 +01:00
{{:assign solde=$ligne_immo.montant}}
{{:assign nbamort=0}}
{{if $linked_lines != null}}
< section class = "amortissement" >
< h3 class = "ruler" >
Amortissements attachés à « < a class = "num"
href={{"%s/acc/transactions/details.php?id=%s"|args:$admin_url:$ligne_immo.trans_id}}>{{$ligne_immo.trans_id}}< / a >
{{$ligne_immo.label}} »
({{"%f"|math:$ligne_immo.montant|money_currency}}, {{$ligne_immo.date_achat|date_short}})
< / h3 >
< table class = "list" >
< thead >
< tr >
< th > N°< / th >
< th > Date< / th >
2024-03-19 15:24:01 +01:00
< th class = "nombre" > Montant< / th >
< th class = "nombre" " > Solde< / th >
2024-02-29 19:07:52 +01:00
< th > Libellé< / th >
< th > N° compte< / th >
< th > Compte< / th >
< th class = "actions" > < / th >
< / tr >
< / thead >
< tbody >
{{#foreach from=$linked_lines item="line"}}
{{* données de l'écriture *}}
{{:assign trans_url="%s/acc/transactions/details.php?id=%s"|args:$admin_url:$line.amort_trans_id}}
{{:assign solde="%f-%d"|math:$solde:$line.amort_amount}}
{{:assign date_amort=$line.amort_date}}
{{:assign current_year=$line.amort_year}}
< tr >
< td class = "num" > < a href = {{$trans_url}} > #{{$line.amort_trans_id}}< / a > < / td >
< td > {{$line.amort_date|date_short}}< / td >
< td class = "money" > {{"%f"|math:$line.amort_amount|money}}< / td >
< td class = "money" > {{"%f"|math:$solde|money}}< / td >
< td >
{{if $line.amort_label == null}}
{{$line.trans_label}}
{{else}}
{{$line.amort_label}}
{{/if}}
< / td >
< td > {{$line.account_code}}< / td >
< td > {{$line.account_name}}< / td >
< td >
{{if $line.linked == null}}
2024-03-14 18:34:45 +01:00
{{:linkbutton label="Détacher" href="detach_amort.html?amort_id=%d& immo_id=%d"|args:$line.amort_line:$ligne_immo.immo_id shape="plus"}}
2024-02-29 19:07:52 +01:00
{{else}}
{{:linkbutton label="Détacher" href="" shape="lock" class="disabled"}}
{{/if}}
< / td >
< / tr >
{{:assign annuite_courante=$annuite}}
{{:assign jour=$date_amort|date:"d"}}
{{:assign mois=$date_amort|date:"m"}}
{{:assign annee=$date_amort|date:"Y"}}
{{:assign annee="%d+1"|math:$annee}}
{{:assign date_amort="%s/%s/%s"|args:$jour:$mois:$annee|parse_date|date_short}}
{{:assign nbamort="%d+1"|math:$nbamort}}
{{/foreach}}
< / tbody >
< / table >
< / section >
{{/if}}
2024-02-17 19:00:24 +01:00
{{:assign project_id=$ligne_immo.project_id}}
{{:assign project_label=$ligne_immo.project_label}}
2024-02-29 19:07:52 +01:00
{{:assign nbamort="%d-%d"|math:$duree:$nbamort}}
2024-02-15 14:23:03 +01:00
< section class = "amortissement" >
2024-02-29 19:07:52 +01:00
< h3 class = "ruler" > Amortissements à enregistrer< / h3 >
2024-02-15 14:23:03 +01:00
< table class = "list" >
< thead >
< tr >
< th > N°< / th >
< th > Date< / th >
2024-03-19 15:24:01 +01:00
< th class = "nombre" > Montant< / th >
< th class = "nombre" > Solde< / th >
2024-02-15 14:23:03 +01:00
< th > Libellé< / th >
< th class = "actions" > < / th >
< / tr >
< / thead >
< tbody >
2024-02-29 19:07:52 +01:00
{{#foreach count="%d+1"|math:$nbamort key="num"}}
{{:assign solde="%f-%d"|math:$solde:$annuite_courante}}
2024-03-14 18:34:45 +01:00
{{#select id from acc_years where :amort_date >= start_date and :amort_date < = end_date and closed = 0; :amort_date=$date_amort|parse_date}}
2024-02-29 19:07:52 +01:00
{{:assign enregistrer=1}}
2024-03-12 17:50:51 +01:00
{{:assign current_year=$id}}
2024-02-29 19:07:52 +01:00
{{else}}
{{:assign enregistrer=0}}
{{/select}}
< tr >
< td class = "num" > {{"%d+1"|math:$num}}< / td >
< td > {{$date_amort}}< / td >
< td class = "money" > {{"%f"|math:$annuite_courante|money}}< / td >
< td class = "money" > {{if $solde == 0}}0,00{{else}}{{"%f"|math:$solde|money}}{{/if}}< / td >
< td >
{{if $libelle == null}}
{{:assign libelle="Amortissement "|cat:$ligne_immo.label}}
{{/if}}
{{$libelle}}
< / td >
< td class = "actions" >
{{if $enregistrer == 1}}
{{:linkbutton
label="Enregistrer"
2024-03-14 18:34:45 +01:00
href="save_amort.html?amount=%d& account=%s& year=%s& trans_id=%d& immo_id=%s& project_id=%d& label=%s"|args:$annuite_courante:$ligne_immo.account_id:$current_year:$ligne_immo.trans_id:$_GET.immo_id:$project_id:$libelle
2024-02-29 19:07:52 +01:00
shape="right"
2024-03-12 17:09:40 +01:00
target="_dialog"
2024-02-29 19:07:52 +01:00
}}
{{else}}
{{:linkbutton label="Enregistrer" href="" shape="lock" class="disabled"}}
{{/if}}
< / td >
< / tr >
{{:assign jour=$date_amort|date:"d"}}
{{:assign mois=$date_amort|date:"m"}}
{{:assign annee=$date_amort|date:"Y"}}
{{:assign annee="%d+1"|math:$annee}}
{{:assign date_amort="%s/%s/%s"|args:$jour:$mois:$annee|parse_date|date_short}}
{{:assign annuite_courante="min(%f,%f)"|math:$annuite:$solde}}
{{if $solde == 0}}{{:break}}{{/if}}
{{/foreach}}
< / tbody >
< / table >
< / section >
< section class = "amortissement" >
< h3 class = "ruler" > Autres amortissements non rattachés< / h3 >
< table class = "list" >
< thead >
< tr >
< th > N°< / th >
< th > Date< / th >
2024-03-19 15:24:01 +01:00
< th class = "nombre" > Montant< / th >
2024-02-29 19:07:52 +01:00
< th > Libellé< / th >
< th > N° compte< / th >
< th > Compte< / th >
< th class = "actions" > < / th >
< / tr >
< / thead >
< tbody >
2024-02-16 11:54:50 +01:00
2024-02-29 19:07:52 +01:00
{{#select
li.id as l_id,
li.id_transaction as t_id,
li.credit as montant,
li.reference,
li.label as l_label,
trans.date as t_date,
trans.label as t_label,
acc.code as a_code,
acc.label as a_label,
y.label as y_label
from acc_transactions_lines as li
inner join acc_accounts as acc on acc.id = li.id_account
inner join acc_transactions as trans on trans.id = li.id_transaction
inner join acc_years as y on y.id = trans.id_year
where acc.code like "28%"
order by trans.date, trans.label
}}
{{:assign linked="false"}}
{{#select
id_transaction,
id_related
from acc_transactions_links
2024-03-19 15:24:01 +01:00
where id_transaction = :id_amort or id_related = :id_amort;
2024-02-29 19:07:52 +01:00
:id_amort=$t_id}}
{{:assign linked="true"}}
{{/select}}
2024-02-16 11:54:50 +01:00
2024-03-19 15:24:01 +01:00
{{if $linked != "true"}}
2024-02-29 19:07:52 +01:00
{{:assign trans_url="%s/acc/transactions/details.php?id=%s"|args:$admin_url:$t_id}}
2024-02-16 11:54:50 +01:00
< tr >
2024-02-29 19:07:52 +01:00
< td class = "num" > < a href = {{$trans_url}} > #{{$t_id}}< / a > < / td >
< td > {{$t_date|date_short}}< / td >
< td class = "money" > {{"%f"|math:$montant|money}}< / td >
< td > {{if $l_label == null}}
{{$t_label}}
{{else}}
{{$l_label}}
{{/if}}
2024-02-16 11:54:50 +01:00
< / td >
2024-02-29 19:07:52 +01:00
< td > {{$a_code}}< / td >
< td > {{$a_label}}< / td >
< td >
{{if $linked != "true"}}
2024-03-14 18:34:45 +01:00
{{:linkbutton label="Attacher" href="attach_amort.html?amort_id=%d& immo_id=%d"|args:$l_id:$ligne_immo.immo_id shape="plus"}}
2024-02-17 19:00:24 +01:00
{{else}}
2024-02-29 19:07:52 +01:00
{{:linkbutton label="Attacher" href="" shape="lock" class="disabled"}}
2024-02-16 11:54:50 +01:00
{{/if}}
< / td >
< / tr >
{{/if}}
2024-02-29 19:07:52 +01:00
{{/select}}
2024-02-15 14:23:03 +01:00
< / tbody >
< / table >
< / section >
2024-02-29 19:07:52 +01:00
2024-02-16 11:54:50 +01:00
{{:form_errors}}
2024-02-15 14:23:03 +01:00
{{:admin_footer}}