Choisir exercice avant date amortissement

This commit is contained in:
Jean-Christophe Engel 2025-05-06 17:07:46 +02:00
parent 5b8c869ba4
commit 839739b992
4 changed files with 203 additions and 158 deletions

View file

@ -35,19 +35,12 @@
{{* récupérer les infos de l'immobilisation *}}
{{#select
line.id as immo_id,
line.id_account as account_id,
line.id_project as project_id,
line.debit as montant,
trans.id as trans_id,
trans.label as label,
trans.date,
y.id as year_id,
y.end_date as date_amort,
project.label as project_label
trans.date
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
LEFT JOIN acc_projects AS project ON line.id_project = project.id
WHERE line.id = :line_id;
:line_id = $_GET.immo_id|intval
assign=ligne_immo
@ -56,6 +49,7 @@
{{:error message="Immobilisation %s non trouvée"|args:$_GET.immo_id}}
{{/select}}
{{:assign date_debut=$ligne_immo.date}}
{{:assign solde=$ligne_immo.montant}}
{{#load type="immo" where="$$.line = :line_id" :line_id=$_GET.immo_id|intval}}
{{:assign duree=$duration}}
@ -98,6 +92,19 @@
{{/if}}
{{/select}}
{{:assign valeur_residuelle=$ligne_immo.montant}}
{{#foreach from=$linked_lines}}
{{:assign valeur_residuelle="%d-%d"|math:$valeur_residuelle:$amort_amount}}
{{/foreach}}
{{if $valeur_residuelle > 0}}
<nav class="tabs amort">
<aside>
{{:linkbutton label="Enregistrer un amortissement" shape="plus" href="save_amort.html?immo_id=%s"|args:$_GET.immo_id target="_dialog"}}
</aside>
</nav>
{{/if}}
<h3>Amortissement de «
<a class="num"
href={{"%s/acc/transactions/details.php?id=%s"|args:$admin_url:$ligne_immo.trans_id}}>#{{$ligne_immo.trans_id}}</a>
@ -106,25 +113,6 @@
en date du {{$date_debut|date_short}}{{if $duree != null}} sur {{$duree}} ans{{/if}}
</h3>
{{if $duree != null}}
{{* montant de l'annuité théorique *}}
{{:assign montant="%f"|math:$ligne_immo.montant}}
{{:assign annuite="%f/%f"|math:$montant:$duree}}
{{* première annuité *}}
{{:assign date_amort=$ligne_immo.date_amort}}
{{if $date_amort|strtotime < $date_debut|strtotime}}
{{* changer d'exercice *}}
{{:include file="_next_year.html" date=$date_amort keep="date_amort"}}
{{:assign date_amort=$date_amort|parse_date}}
{{/if}}
{{:include file="_calcul_dates.html" date_debut=$date_debut date_fin=$date_amort keep="nbjours"}}
{{:assign annuite_1="%f/360*%d"|math:$annuite:$nbjours|intval}}
{{:assign annuite_courante=$annuite_1}}
{{:assign current_year=$ligne_immo.year_id}}
{{:assign nbamort=0}}
{{/if}}
{{:assign solde=$ligne_immo.montant}}
{{if $linked_lines != null}}
<section class="amortissement">
<h3 class="center-block ruler">Amortissements rattachés</h3>
@ -147,8 +135,6 @@
{{:assign trans_url="%s/acc/transactions/details.php?id=%s"|args:$admin_url:$line.amort_trans_id}}
{{:assign compte_url="%s/acc/accounts/journal.php?id=%s&year=%s"|args:$admin_url:$line.account_id:$line.amort_year}}
{{: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>
@ -167,83 +153,6 @@
{{:linkbutton label="Détacher" href="detach_amort.html?amort_id=%d&immo_id=%d"|args:$line.amort_line:$ligne_immo.immo_id shape="minus"}}
</td>
</tr>
{{:assign annuite_courante=$annuite}}
{{:include file="_next_year.html" date=$date_amort keep="date_amort"}}
{{:assign nbamort="%d+1"|math:$nbamort}}
{{/foreach}}
</tbody>
</table>
</section>
{{/if}}
{{if $duree != null && $solde > 0}}
{{:assign project_id=$ligne_immo.project_id}}
{{:assign project_label=$ligne_immo.project_label}}
{{:assign nbamort="%d-%d"|math:$duree:$nbamort}}
{{:assign annuite_courante="min(%f,%f)"|math:$annuite_courante:$solde}}
{{:assign libelle="Amortissement "|cat:$ligne_immo.label}}
{{* infos des comptes d'immo et d'amortissement *}}
{{#sql select="code, id_chart" tables="acc_accounts" where="id = :id" :id=$ligne_immo.account_id assign="immo_account"}}
{{/sql}}
{{:include
file="./_get_amort_code.html"
code_immo=$immo_account.code
keep="code_amort"
}}
{{#sql select="id,label" tables="acc_accounts" where="code = :code AND id_chart = :id_chart"
:code=$code_amort :id_chart=$immo_account.id_chart assign="amort_account"}}
{{/sql}}
<section class="amortissement">
<h3 class="center-block ruler">Amortissements à enregistrer</h3>
<table class="list">
<thead>
<tr>
<th></th>
<th>Date</th>
<th class="nombre">Montant</th>
<th class="nombre">Solde</th>
<th>Libellé</th>
<th>N° compte</th>
<th>Compte</th>
<th class="actions"></th>
</tr>
</thead>
<tbody>
{{#foreach count="%d+1"|math:$nbamort key="num"}}
{{:assign solde_prec=$solde}}
{{:assign solde="%f-%d"|math:$solde:$annuite_courante}}
{{#select id FROM acc_years
WHERE :amort_date >= start_date AND :amort_date <= end_date AND status == 0 LIMIT 1;
:amort_date=$date_amort|parse_date}}
{{:assign enregistrer=1}}
{{:assign current_year=$id}}
{{else}}
{{:assign enregistrer=0}}
{{/select}}
<tr>
<td class="num">{{"%d+1"|math:$num}}</td>
<td>{{$date_amort|date_short}}</td>
<td class="money">{{"%f"|math:$annuite_courante|money}}</td>
<td class="money">{{$solde|money:false}}</td>
<td>{{$libelle}}</td>
<td>{{$code_amort}}</td>
<td>{{$amort_account.label}}</td>
<td class="actions">
{{if $enregistrer == 1}}
{{:linkbutton
label="Créer l'écriture"
href="save_amort.html?amount=%d&account=%s&year=%s&trans_id=%d&immo_id=%s&project_id=%d&label=%s&solde=%d"|args:$annuite_courante:$ligne_immo.account_id:$current_year:$ligne_immo.trans_id:$_GET.immo_id:$project_id:$libelle:$solde_prec
shape="right"
target="_dialog"
}}
{{/if}}
</td>
</tr>
{{:include file="_next_year.html" date=$date_amort keep="date_amort"}}
{{:assign annuite_courante="min(%f,%f)"|math:$annuite:$solde}}
{{if $solde == 0}}{{:break}}{{/if}}
{{/foreach}}
</tbody>
</table>