balance_sheet_exit : amortissement multi-lignes
This commit is contained in:
parent
a4b2115249
commit
b215c05763
1 changed files with 57 additions and 25 deletions
|
|
@ -56,43 +56,75 @@
|
||||||
{{:assign var="ligne_immo.montant" value="%d-%d"|math:$ligne_immo.montant:$total_credits}}
|
{{:assign var="ligne_immo.montant" value="%d-%d"|math:$ligne_immo.montant:$total_credits}}
|
||||||
|
|
||||||
{{* chercher des écritures d'amortissement liées à l'immobilisation *}}
|
{{* chercher des écritures d'amortissement liées à l'immobilisation *}}
|
||||||
|
{{:assign total_amort=0}}
|
||||||
|
{{:assign amort_number=0}}
|
||||||
{{#select
|
{{#select
|
||||||
SUM(l_amort.credit) as amort_amount,
|
l_amort.credit as amort_amount,
|
||||||
|
l_amort.id as amort_line_id,
|
||||||
CASE
|
CASE
|
||||||
WHEN links.id_related = t_immo.id
|
WHEN links.id_related = t_immo.id
|
||||||
THEN links.id_transaction
|
THEN links.id_transaction
|
||||||
ELSE links.id_related
|
ELSE links.id_related
|
||||||
END as amort_trans_id,
|
END as amort_trans_id,
|
||||||
MAX(trans.date) as last_amort_date,
|
trans.date
|
||||||
MIN(trans.date) as first_amort_date,
|
|
||||||
COUNT(trans.id) as amort_number
|
|
||||||
FROM acc_transactions_lines as l_immo
|
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 as t_immo on t_immo.id = l_immo.id_transaction
|
||||||
INNER JOIN acc_transactions_links as links
|
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_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_transactions as trans on l_amort.id_transaction = trans.id
|
||||||
INNER JOIN acc_accounts AS account ON l_amort.id_account = account.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%'
|
WHERE l_immo.id = :line_id AND account.code LIKE '28%'
|
||||||
LIMIT 1;
|
;
|
||||||
:line_id = $_GET.immo_id|intval
|
: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}}
|
{{/select}}
|
||||||
|
|
||||||
{{if $amort_line.amort_number == 0}}
|
{{if $total_amort == 0}}
|
||||||
{{if $info_immo.status == "amortized"}}
|
{{if $info_immo.status == "amortized"}}
|
||||||
{{:assign amort_amount=$ligne_immo.montant}}
|
{{:assign total_amort=$ligne_immo.montant}}
|
||||||
{{else}}
|
{{/if}}
|
||||||
{{:assign amort_amount=0}}
|
|
||||||
{{/if}}
|
|
||||||
{{else}}
|
{{else}}
|
||||||
{{:assign amort_amount=$amort_line.amort_amount}}
|
{{:assign date_debut=$last_amort_date|strtotime}}
|
||||||
{{:assign date_debut=$amort_line.last_amort_date|strtotime}}
|
|
||||||
{{:assign date_debut="%d+(60*60*24)"|math:$date_debut|date:"Y-m-d"}}
|
{{:assign date_debut="%d+(60*60*24)"|math:$date_debut|date:"Y-m-d"}}
|
||||||
{{/if}}
|
{{/if}}
|
||||||
{{:assign ts_debut=$date_debut|strtotime}}
|
{{: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
|
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 *}}
|
{{* vérifier la validité de la date de mise en service *}}
|
||||||
{{if $_POST.date_mes != null}}
|
{{if $_POST.date_mes != null}}
|
||||||
{{:assign ts_mes=$_POST.date_mes|parse_date|strtotime}}
|
{{: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 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}}
|
{{: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}}
|
||||||
{{/if}}
|
{{/if}}
|
||||||
|
|
@ -137,8 +169,8 @@
|
||||||
{{if $info_immo.duration == null}}
|
{{if $info_immo.duration == null}}
|
||||||
{{if $_POST.duree == null}}
|
{{if $_POST.duree == null}}
|
||||||
{{:error message="Vous devez renseigner la durée de l'immobilisation"}}
|
{{:error message="Vous devez renseigner la durée de l'immobilisation"}}
|
||||||
{{elseif $_POST.duree < $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_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_number}}
|
||||||
{{else}}
|
{{else}}
|
||||||
{{:assign duree_amort=$_POST.duree}}
|
{{:assign duree_amort=$_POST.duree}}
|
||||||
{{/if}}
|
{{/if}}
|
||||||
|
|
@ -159,9 +191,9 @@
|
||||||
{{:assign immo_date=$ligne_immo.date_achat|date_short}}
|
{{: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}}
|
{{:error message="La date de sortie doit être postérieure à la date d'acquisition de l'immobilisation (%s)"|args:$immo_date}}
|
||||||
{{/if}}
|
{{/if}}
|
||||||
{{if $amort_line.amort_number != 0 && $_POST.date_sortie|parse_date <= $amort_line.last_amort_date}}
|
{{if $amort_number != 0 && $_POST.date_sortie|parse_date <= $last_amort_date}}
|
||||||
{{:assign last_amort_date=$amort_line.last_amort_date|date_short}}
|
{{:assign last_amort_date=$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}}
|
{{:error message="La date de sortie doit être postérieure à la date du dernier amortissement (%s)"|args:$last_amort_date}}
|
||||||
{{/if}}
|
{{/if}}
|
||||||
|
|
||||||
{{* vérifier que la date de sortie est située dans un exercice ouvert *}}
|
{{* vérifier que la date de sortie est située dans un exercice ouvert *}}
|
||||||
|
|
@ -178,7 +210,7 @@
|
||||||
{{/if}}
|
{{/if}}
|
||||||
|
|
||||||
{{* voir si des amortissements ont été oubliés *}}
|
{{* 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 debut=$start_date|date_short}}
|
||||||
{{:assign fin=$end_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}}
|
{{: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}}
|
{{:error message="Vous devez d'abord enregistrer les amortissements des exercices suivants : %s"|args:$msg_amort}}
|
||||||
{{/if}}
|
{{/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}}
|
{{/form}}
|
||||||
|
|
||||||
{{:admin_header title="Sortie de bilan" custom_css="./style.css" current="module_amortization"}}
|
{{:admin_header title="Sortie de bilan" custom_css="./style.css" current="module_amortization"}}
|
||||||
|
|
@ -221,7 +253,7 @@
|
||||||
<dd id="duree_amort" class="num">{{$info_immo.duration}} ans</dd>
|
<dd id="duree_amort" class="num">{{$info_immo.duration}} ans</dd>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
<dt>Montant des amortissements</dt>
|
<dt>Montant des amortissements</dt>
|
||||||
<dd id="montant_amort" class="money">{{$amort_amount|money_currency_html:false|raw}} <span class="help">(à la date de début de l'exercice)</span></dd>
|
<dd id="montant_amort" class="money">{{$total_amort|money_currency_html:false|raw}} <span class="help">(à la date de début de l'exercice)</span></dd>
|
||||||
<dt>Valeur nette résiduelle</dt>
|
<dt>Valeur nette résiduelle</dt>
|
||||||
<dd class="money">{{$valeur_nette|money_currency_html:false|raw}} <span class="help">(à la date de début de l'exercice)</span></dd>
|
<dd class="money">{{$valeur_nette|money_currency_html:false|raw}} <span class="help">(à la date de début de l'exercice)</span></dd>
|
||||||
</dl>
|
</dl>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue