Choisir exercice avant date amortissement
This commit is contained in:
parent
5b8c869ba4
commit
839739b992
4 changed files with 203 additions and 158 deletions
|
@ -35,19 +35,12 @@
|
||||||
{{* récupérer les infos de l'immobilisation *}}
|
{{* récupérer les infos de l'immobilisation *}}
|
||||||
{{#select
|
{{#select
|
||||||
line.id as immo_id,
|
line.id as immo_id,
|
||||||
line.id_account as account_id,
|
|
||||||
line.id_project as project_id,
|
|
||||||
line.debit as montant,
|
line.debit as montant,
|
||||||
trans.id as trans_id,
|
trans.id as trans_id,
|
||||||
trans.label as label,
|
trans.label as label,
|
||||||
trans.date,
|
trans.date
|
||||||
y.id as year_id,
|
|
||||||
y.end_date as date_amort,
|
|
||||||
project.label as project_label
|
|
||||||
FROM acc_transactions_lines AS line
|
FROM acc_transactions_lines AS line
|
||||||
INNER JOIN acc_transactions AS trans ON line.id_transaction = trans.id
|
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;
|
WHERE line.id = :line_id;
|
||||||
:line_id = $_GET.immo_id|intval
|
:line_id = $_GET.immo_id|intval
|
||||||
assign=ligne_immo
|
assign=ligne_immo
|
||||||
|
@ -56,6 +49,7 @@
|
||||||
{{:error message="Immobilisation %s non trouvée"|args:$_GET.immo_id}}
|
{{:error message="Immobilisation %s non trouvée"|args:$_GET.immo_id}}
|
||||||
{{/select}}
|
{{/select}}
|
||||||
{{:assign date_debut=$ligne_immo.date}}
|
{{:assign date_debut=$ligne_immo.date}}
|
||||||
|
{{:assign solde=$ligne_immo.montant}}
|
||||||
|
|
||||||
{{#load type="immo" where="$$.line = :line_id" :line_id=$_GET.immo_id|intval}}
|
{{#load type="immo" where="$$.line = :line_id" :line_id=$_GET.immo_id|intval}}
|
||||||
{{:assign duree=$duration}}
|
{{:assign duree=$duration}}
|
||||||
|
@ -98,6 +92,19 @@
|
||||||
{{/if}}
|
{{/if}}
|
||||||
{{/select}}
|
{{/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 «
|
<h3>Amortissement de «
|
||||||
<a class="num"
|
<a class="num"
|
||||||
href={{"%s/acc/transactions/details.php?id=%s"|args:$admin_url:$ligne_immo.trans_id}}>#{{$ligne_immo.trans_id}}</a>
|
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}}
|
en date du {{$date_debut|date_short}}{{if $duree != null}} sur {{$duree}} ans{{/if}}
|
||||||
</h3>
|
</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}}
|
{{if $linked_lines != null}}
|
||||||
<section class="amortissement">
|
<section class="amortissement">
|
||||||
<h3 class="center-block ruler">Amortissements rattachés</h3>
|
<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 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 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 solde="%f-%d"|math:$solde:$line.amort_amount}}
|
||||||
{{:assign date_amort=$line.amort_date}}
|
|
||||||
{{:assign current_year=$line.amort_year}}
|
|
||||||
<tr>
|
<tr>
|
||||||
<td class="num"><a href={{$trans_url}}>#{{$line.amort_trans_id}}</a></td>
|
<td class="num"><a href={{$trans_url}}>#{{$line.amort_trans_id}}</a></td>
|
||||||
<td>{{$line.amort_date|date_short}}</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"}}
|
{{: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>
|
</td>
|
||||||
</tr>
|
</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>N°</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}}
|
{{/foreach}}
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
|
220
save_amort.html
220
save_amort.html
|
@ -1,24 +1,128 @@
|
||||||
{{* -*- brindille -*- *}}
|
{{* -*- brindille -*- *}}
|
||||||
|
|
||||||
{{:admin_header title="Ajout amortissement" current="module_amortissement"}}
|
{{*
|
||||||
|
créer une écriture d'amortissement
|
||||||
|
paramètres
|
||||||
|
- immo_id : id de la ligne d'immobilisation
|
||||||
|
*}}
|
||||||
|
|
||||||
{{* barre de navigation *}}
|
{{* Infos de l'immobilisation *}}
|
||||||
{{if ! $dialog}}
|
{{#select
|
||||||
{{:include file="_nav.html" current="amortization"}}
|
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
|
||||||
|
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
|
||||||
|
}}
|
||||||
|
{{else}}
|
||||||
|
{{:error message="Immobilisation %s non trouvée"|args:$_GET.immo_id}}
|
||||||
|
{{/select}}
|
||||||
|
{{:assign date_debut=$ligne_immo.date}}
|
||||||
|
|
||||||
|
{{#load type="immo" where="$$.line = :line_id" :line_id=$_GET.immo_id|intval}}
|
||||||
|
{{:assign duree=$duration}}
|
||||||
|
{{:assign date_debut=$date}}
|
||||||
|
{{else}}
|
||||||
|
{{:error message="Vous devez renseigner la date de mise en service et la durée d'immobilisation"}}
|
||||||
|
{{/load}}
|
||||||
|
|
||||||
|
{{* chercher des écritures d'amortissement liées à l'immobilisation *}}
|
||||||
|
{{#select
|
||||||
|
SUM(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,
|
||||||
|
trans.label as trans_label,
|
||||||
|
trans.id_year as amort_year,
|
||||||
|
account.id as account_id,
|
||||||
|
account.code as account_code,
|
||||||
|
account.label as account_label
|
||||||
|
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 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;
|
||||||
|
:line_id = $_GET.immo_id|intval
|
||||||
|
assign=amort_line
|
||||||
|
}}
|
||||||
|
{{/select}}
|
||||||
|
|
||||||
|
{{if $amort_line.amort_amount == null}}
|
||||||
|
{{* 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}}
|
||||||
|
{{/select}}
|
||||||
|
{{:include
|
||||||
|
file="./_get_amort_code.html"
|
||||||
|
code_immo=$amort_account.code
|
||||||
|
keep="code_amort"
|
||||||
|
}}
|
||||||
|
{{:assign var=amort_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="%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}}
|
{{/if}}
|
||||||
|
|
||||||
|
{{*
|
||||||
|
lister les exercices dont la date de fin est postérieure à la date
|
||||||
|
de mise en service de l'immo ou à la date du dernier amortissement
|
||||||
|
*}}
|
||||||
|
{{:assign msg_years=""}}
|
||||||
|
{{#years closed=false order="start_date" where="end_date > :debut" :debut=$date_debut assign=years.}}
|
||||||
|
{{:assign ts_debut=$start_date|strtotime}}
|
||||||
|
{{:assign ts_fin=$end_date|strtotime}}
|
||||||
|
{{:assign var="years_data.%d"|args:$id value=$ts_debut|cat:" "|cat:$ts_fin}}
|
||||||
|
{{:assign debut=$start_date|date_short}}
|
||||||
|
{{:assign fin=$end_date|date_short}}
|
||||||
|
{{:assign var="open_years.%d"|args:$id value=$label|cat:" (du "|cat:$debut|cat:" au "|cat:$fin|cat:")"}}
|
||||||
|
{{:assign msg_years=$msg_years|cat:"\n"|cat:" - "|cat:$label|cat:" : "|cat:$debut|cat:" à "|cat:$fin}}
|
||||||
|
{{else}}
|
||||||
|
{{:error message="Aucun exercice ouvert pour enregistrer un amortissement"}}
|
||||||
|
{{/years}}
|
||||||
|
|
||||||
|
|
||||||
{{* Traiter l'envoi du formulaire *}}
|
{{* Traiter l'envoi du formulaire *}}
|
||||||
{{#form on="save"}}
|
{{#form on="save"}}
|
||||||
|
{{* UTILE ? vérifier que la date est située dans un exercice compatible *}}
|
||||||
|
|
||||||
{{* vérifier que la date est située dans un exercice ouvert *}}
|
{{:assign ts_date = $_POST.date_amort|parse_date|strtotime}}
|
||||||
{{:include
|
{{:assign ok=false}}
|
||||||
file="_check_date.html"
|
{{#foreach from=$years}}
|
||||||
date=$_POST.date
|
{{if $start_date|strtotime <= $ts_date && $ts_date <= $end_date|strtotime}}
|
||||||
keep="open_years, selected_year, selected_chart"
|
{{:assign ok=true}}
|
||||||
}}
|
{{:break}}
|
||||||
|
{{/if}}
|
||||||
{{if $selected_year == null}}
|
{{/foreach}}
|
||||||
{{:error message="La date choisie n'est dans aucun exercice ouvert !!\nExercices ouverts : %s"|args:$open_years}}
|
{{if ! $ok}}
|
||||||
|
{{:error message="La date choisie n'est dans aucun exercice compatible !!\nExercices compatibles : %s"|args:$msg_years}}
|
||||||
{{/if}}
|
{{/if}}
|
||||||
|
|
||||||
{{* déterminer le numéro des comptes au cas où la clé serait un identifiant *}}
|
{{* déterminer le numéro des comptes au cas où la clé serait un identifiant *}}
|
||||||
|
@ -34,7 +138,6 @@
|
||||||
keep="account_code"
|
keep="account_code"
|
||||||
}}
|
}}
|
||||||
{{:assign credit_account=$account_code}}
|
{{:assign credit_account=$account_code}}
|
||||||
|
|
||||||
{{* vérifier :
|
{{* vérifier :
|
||||||
- que le compte d'amortissement débute par un préfixe correct (280, 281, ...)
|
- que le compte d'amortissement débute par un préfixe correct (280, 281, ...)
|
||||||
- est présent dans le PC de l'exercice correspondant à la date
|
- est présent dans le PC de l'exercice correspondant à la date
|
||||||
|
@ -51,6 +154,9 @@
|
||||||
}}
|
}}
|
||||||
{{:assign var="amort_array." value=$code_amort|intval}}
|
{{:assign var="amort_array." value=$code_amort|intval}}
|
||||||
{{/foreach}}
|
{{/foreach}}
|
||||||
|
{{#years closed=false where="id = :year_id" :year_id=$_POST.id_year}}
|
||||||
|
{{:assign selected_chart=$id_chart}}
|
||||||
|
{{/years}}
|
||||||
|
|
||||||
{{:include
|
{{:include
|
||||||
file="_check_account.html"
|
file="_check_account.html"
|
||||||
|
@ -59,21 +165,19 @@
|
||||||
prefix_array=$amort_array
|
prefix_array=$amort_array
|
||||||
keep="account_ok"
|
keep="account_ok"
|
||||||
}}
|
}}
|
||||||
|
|
||||||
{{if $account_ok == null}}
|
{{if $account_ok == null}}
|
||||||
{{:assign compte=$credit_account|implode:""}}
|
{{:assign compte=$credit_account|implode:""}}
|
||||||
{{:redirect url="add_account.html?account=%s&chart=%s&immo_id=%s"|args:$compte:$selected_chart:$_GET.immo_id}}
|
{{:redirect url="add_account.html?account=%s&chart=%s&immo_id=%s"|args:$compte:$selected_chart:$_GET.immo_id}}
|
||||||
{{/if}}
|
{{/if}}
|
||||||
|
|
||||||
{{* vérifier que le montant ne dépasse pas le solde restant *}}
|
{{* vérifier que le montant ne dépasse pas le solde restant *}}
|
||||||
{{if $_POST.montant|trim|money_int > $_GET.solde|intval}}
|
{{:assign solde="%d-%d"|math:$ligne_immo.montant:$amort_line.amort_amount}}
|
||||||
{{:assign solde=$_GET.solde|money_raw}}
|
{{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}}
|
{{:error message="Le montant indiqué « %s » dépasse le solde à amortir « %s »"|args:$_POST.montant:$solde}}
|
||||||
{{/if}}
|
{{/if}}
|
||||||
|
|
||||||
{{* enregistrer l'écriture *}}
|
{{* enregistrer l'écriture *}}
|
||||||
{{:assign var="linked_transactions." value=$_GET.trans_id}}
|
|
||||||
|
|
||||||
{{:assign
|
{{:assign
|
||||||
var="lines."
|
var="lines."
|
||||||
debit=$_POST.montant
|
debit=$_POST.montant
|
||||||
|
@ -88,66 +192,61 @@
|
||||||
id_project=$_GET.project_id
|
id_project=$_GET.project_id
|
||||||
label=$_POST.designation
|
label=$_POST.designation
|
||||||
}}
|
}}
|
||||||
|
|
||||||
{{:api
|
{{:api
|
||||||
method="POST"
|
method="POST"
|
||||||
path="accounting/transaction"
|
path="accounting/transaction"
|
||||||
assign="result"
|
assign="result"
|
||||||
assign_code="result_code"
|
assign_code="result_code"
|
||||||
id_year=$selected_year
|
id_year=$_POST.id_year
|
||||||
type="advanced"
|
type="advanced"
|
||||||
date=$_POST.date
|
date=$_POST.date_amort
|
||||||
label=$_POST.designation
|
label=$_POST.designation
|
||||||
lines=$lines
|
lines=$lines
|
||||||
linked_transactions=$_GET.trans_id|intval
|
linked_transactions=$ligne_immo.trans_id|intval
|
||||||
}}
|
}}
|
||||||
|
|
||||||
{{:redirect force="amortization.html?immo_id=%s&ok=1&msg=amortissement"|args:$_GET.immo_id}}
|
{{:redirect force="amortization.html?immo_id=%s&ok=1&msg=amortissement"|args:$_GET.immo_id}}
|
||||||
{{/form}}
|
{{/form}}
|
||||||
|
|
||||||
|
{{:admin_header title="Ajout amortissement" current="module_amortissement"}}
|
||||||
|
|
||||||
|
{{* barre de navigation *}}
|
||||||
|
{{if ! $dialog}}
|
||||||
|
{{:include file="_nav.html" current="index" subcurrent="encours" subsubcurrent="amortization"}}
|
||||||
|
{{/if}}
|
||||||
|
|
||||||
{{:form_errors}}
|
{{:form_errors}}
|
||||||
|
|
||||||
{{* Préparer les infos pour le formulaire *}}
|
{{:assign var=selected_year value=$years.0.id}}
|
||||||
|
{{:assign var=date_amort value=$years.0.end_date}}
|
||||||
|
{{:include file="_calcul_dates.html" date_debut=$date_debut date_fin=$date_amort keep="nbjours"}}
|
||||||
|
|
||||||
|
{{* 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 var="debit_account.6811" value="6811 — Dot. aux amortissements des immobilisations"}}
|
{{: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}}
|
||||||
|
|
||||||
{{*
|
{{* -------------------------------------------------------------------------------- *}}
|
||||||
déterminer le compte d'amortissement en fonction du compte
|
|
||||||
d'immobilisation => ajouter un 8 après le 2 de tête
|
|
||||||
*}}
|
|
||||||
{{#select code, label from acc_accounts where id = :id; :id=$_GET.account assign=amort_account}}{{/select}}
|
|
||||||
{{:include
|
|
||||||
file="./_get_amort_code.html"
|
|
||||||
code_immo=$amort_account.code
|
|
||||||
keep="code_amort"
|
|
||||||
}}
|
|
||||||
{{:assign var="credit_account.%s"|args:$code_amort value="%s — Amortissements "|args:$code_amort|cat:$amort_account.label}}
|
|
||||||
|
|
||||||
{{#select
|
<div id="erreur" class="hidden">
|
||||||
id,
|
<p class="block error">La date choisie n'est dans aucun exercice ouvert</p>
|
||||||
label,
|
</div>
|
||||||
end_date as date_amort
|
|
||||||
from acc_years where id=:id;
|
|
||||||
:id=$_GET.year assign=year
|
|
||||||
}}
|
|
||||||
{{/select}}
|
|
||||||
|
|
||||||
{{#years status=false}}
|
|
||||||
{{:assign var="open_years.%d"|args:$id value=$label}}
|
|
||||||
{{/years}}
|
|
||||||
|
|
||||||
<form method="post" action="">
|
<form method="post" action="">
|
||||||
<fieldset class="ajout_amort">
|
<fieldset class="ajout_amort">
|
||||||
<legend>Ajouter une écriture d'amortissement</legend>
|
<legend>Ajouter une écriture d'amortissement</legend>
|
||||||
<dl>
|
<dl>
|
||||||
{{:input type="date" name="date" label="Date" required=true default=$year.date_amort|date_short}}
|
{{:input type="select" default=$selected_year name="id_year" label="Exercice" required=true default_empty="— Faire un choix —" options=$open_years}}
|
||||||
{{:input type="text" name="designation" label="Désignation" required=true default=$_GET.label}}
|
{{:input type="date" name="date_amort" label="Date" required=true default=$date_amort|date_short}}
|
||||||
{{:input type="money" name="montant" label="Montant" required=true default=$_GET.amount}}
|
{{:input type="text" name="designation" label="Désignation" required=true default=$libelle}}
|
||||||
|
{{:input type="money" name="montant" label="Montant" required=true default=$montant_amort}}
|
||||||
{{:input
|
{{:input
|
||||||
type="list"
|
type="list"
|
||||||
name="debit_account"
|
name="debit_account"
|
||||||
label="Compte de débit"
|
label="Compte de débit"
|
||||||
required=true
|
required=true
|
||||||
target="!acc/charts/accounts/selector.php?codes=%s&year=%d"|args:"68*":$year.id
|
target="!acc/charts/accounts/selector.php?codes=%s&id_year=%d"|args:"68*":$year.id
|
||||||
default=$debit_account
|
default=$debit_account
|
||||||
}}
|
}}
|
||||||
{{:input
|
{{:input
|
||||||
|
@ -155,9 +254,12 @@
|
||||||
name="credit_account"
|
name="credit_account"
|
||||||
label="Compte d'amortissement (280xx ou 281xx)"
|
label="Compte d'amortissement (280xx ou 281xx)"
|
||||||
required=true
|
required=true
|
||||||
target="!acc/charts/accounts/selector.php?codes=%s&year=%d"|args:"28*":$year.id
|
target="!acc/charts/accounts/selector.php?codes=%s&id_year=%d"|args:"28*":$year.id
|
||||||
default=$credit_account
|
default=$credit_account
|
||||||
}}
|
}}
|
||||||
|
<div id="donnees" class="hidden">
|
||||||
|
{{:input type="select" name="years_data" options=$years_data}}
|
||||||
|
</div>
|
||||||
</dl>
|
</dl>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
|
|
||||||
|
@ -166,3 +268,17 @@
|
||||||
</p>
|
</p>
|
||||||
</form>
|
</form>
|
||||||
{{:admin_footer}}
|
{{:admin_footer}}
|
||||||
|
|
||||||
|
<script type="text/javascript" src="scripts.js"></script>
|
||||||
|
<script type="text/javascript">
|
||||||
|
|
||||||
|
// afficher la date de fin de l'exercice choisi
|
||||||
|
function setDate(evt, id_exercices = 'f_id_year', id_date = 'f_date_amort', id_years = 'f_years_data') {
|
||||||
|
setDateEnd(id_exercices, id_date, id_years);
|
||||||
|
}
|
||||||
|
|
||||||
|
(function () {
|
||||||
|
setDateEnd('f_id_year', 'f_date_amort', 'f_years_data');
|
||||||
|
document.getElementById('f_id_year').onchange = setDate;
|
||||||
|
})();
|
||||||
|
</script>
|
||||||
|
|
16
scripts.js
16
scripts.js
|
@ -81,3 +81,19 @@ function chooseYears(id_date, id_exercices, id_years)
|
||||||
setAccountYear(['credit_account', 'debit_account'], 0);
|
setAccountYear(['credit_account', 'debit_account'], 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// afficher la date de fin de l'exercice choisi
|
||||||
|
function setDateEnd(id_exercices, id_date, id_years) {
|
||||||
|
const selected_year = document.getElementById(id_exercices).value;
|
||||||
|
const years_data = document.getElementById(id_years);
|
||||||
|
for (const choix of years_data.options) {
|
||||||
|
if (choix.value == '') {
|
||||||
|
document.getElementById(id_date).value = '';
|
||||||
|
} else if (choix.value == selected_year) {
|
||||||
|
const epox = choix.text.split(' ');
|
||||||
|
const date_fin = new Date(epox[1] * 1000);
|
||||||
|
document.getElementById(id_date).value = date_fin.toLocaleDateString();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -37,3 +37,7 @@ h2[class="aide"], h3[class="aide"] {
|
||||||
.informations dl.describe > dt {
|
.informations dl.describe > dt {
|
||||||
margin-right: 0;
|
margin-right: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
nav.amort aside {
|
||||||
|
margin-top : 0;
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue