Adaptation sortie bilan aux nouveaux documents
This commit is contained in:
parent
c427e8900f
commit
bb8d27b616
3 changed files with 138 additions and 160 deletions
115
write_exit.html
115
write_exit.html
|
|
@ -3,16 +3,19 @@
|
|||
{{*
|
||||
Enregistrer les écritures de sortie du bilan
|
||||
paramètres :
|
||||
- immo_line_id : numéro de ligne de l'écriture d'immobilisation
|
||||
- immo_doc_id : id du doc associé à l'immobilisation
|
||||
- amort_amount : montant des amortissements
|
||||
- year : exercice de la date de sortie de l'immobilisation
|
||||
- date_mes : date de mise en service de l'immobilisation
|
||||
- date_debut : date de début de la période d'amortissement complémentaire
|
||||
- exit_date : date de sortie de l'immobilisation
|
||||
- duree_amort : durée de l'amortiseement (optionnel)
|
||||
- cession : montant de la cession (optionnel)
|
||||
*}}
|
||||
|
||||
{{#load id=$_GET.immo_doc_id|intval assign="info_immo"}}
|
||||
{{else}}
|
||||
{{:error message="Immobilisation non trouvée"}}
|
||||
{{/load}}
|
||||
|
||||
{{#select
|
||||
line.debit as montant,
|
||||
line.id_transaction,
|
||||
|
|
@ -25,43 +28,63 @@
|
|||
INNER JOIN acc_transactions AS trans ON line.id_transaction = trans.id
|
||||
INNER JOIN acc_accounts AS acc ON line.id_account = acc.id
|
||||
WHERE line.id = :immo_line_id;
|
||||
:immo_line_id = $_GET.immo_line_id|intval
|
||||
:immo_line_id = $info_immo.line
|
||||
assign="ligne_immo"
|
||||
}}
|
||||
{{else}}
|
||||
{{:error message="Immobilisation non trouvée"}}
|
||||
{{/select}}
|
||||
|
||||
{{#load type="immo" assign="info_immo" where="$$.line = :line_id" :line_id=$_GET.immo_line_id|intval}}
|
||||
{{/load}}
|
||||
|
||||
{{* 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_trans_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_trans_id AND line.credit > 0 AND acc.code = :account;
|
||||
:immo_trans_id=$ligne_immo.trans_id
|
||||
:account=$ligne_immo.account_code
|
||||
}}
|
||||
{{:assign total_credits="%d+%d"|math:$total_credits:$credit}}
|
||||
{{/select}}
|
||||
{{#load
|
||||
type="credit_link"
|
||||
where="$$.immo_doc_id = :immo_doc_id"
|
||||
:immo_doc_id = $info_immo.id
|
||||
assign="credit_link"
|
||||
}}
|
||||
{{if $amount == null}}
|
||||
{{#select credit FROM acc_transactions_lines WHERE id = :credit_line_id;
|
||||
:credit_line_id=$credit_line_id
|
||||
}}
|
||||
{{:assign total_credits="%d+%d"|math:$total_credits:$credit}}
|
||||
{{/select}}
|
||||
{{else}}
|
||||
{{:assign total_credits="%d+%d"|math:$total_credits:$amount}}
|
||||
{{/if}}
|
||||
{{else}}
|
||||
{{*
|
||||
TODO : à garder ?
|
||||
pas de doc => voir liaison écritures
|
||||
*}}
|
||||
{{#select
|
||||
CASE links.id_related = :immo_trans_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_trans_id AND line.credit > 0 AND acc.code = :account;
|
||||
:immo_trans_id=$ligne_immo.trans_id
|
||||
:account=$ligne_immo.account_code
|
||||
}}
|
||||
{{:assign total_credits="%d+%d"|math:$total_credits:$credit}}
|
||||
{{/select}}
|
||||
{{/load}}
|
||||
{{:assign var="ligne_immo.montant" value="%d-%d"|math:$ligne_immo.montant:$total_credits}}
|
||||
|
||||
{{:assign valeur_nette="%f-%f"|math:$ligne_immo.montant:$_GET.amort_amount}}
|
||||
|
||||
{{:assign amort_comp=0}} {{* amortissement complémentaire jqà date sortie *}}
|
||||
{{:assign amort_except=0}} {{* amortissement exceptionnel jqà date fin amortissement *}}
|
||||
{{if $valeur_nette > 0}}
|
||||
{{:assign nbjours="1+(%d-%d)/(60*60*24)"|math:$_GET.exit_date:$_GET.date_debut}}
|
||||
{{:assign annuite="%f/%f"|math:$ligne_immo.montant:$_GET.duree_amort}}
|
||||
{{:assign annuite="%f/%f"|math:$ligne_immo.montant:$info_immo.duration}}
|
||||
{{:assign amort_comp="round(%f/365*%f, 0)"|math:$annuite:$nbjours}}
|
||||
{{:assign amort_comp="min(%f, %f)"|math:$valeur_nette:$amort_comp}}
|
||||
|
||||
|
|
@ -164,8 +187,9 @@
|
|||
lines=$lines
|
||||
linked_transactions=$ligne_immo.id_transaction
|
||||
}}
|
||||
|
||||
{{* liaisons lignes d'amortissement *}}
|
||||
{{#foreach from=$result.lines item="line"}}
|
||||
{{* TODO : cas où pas de doc ? (info_immo = null) *}}
|
||||
{{if $line.account_code == $amort_account_code}}
|
||||
{{:save
|
||||
key=""|uuid
|
||||
|
|
@ -173,7 +197,6 @@
|
|||
immo_doc_id=$info_immo.id
|
||||
amort_line_id=$line.id
|
||||
}}
|
||||
{{:break}}
|
||||
{{/if}}
|
||||
{{/foreach}}
|
||||
{{/if}}
|
||||
|
|
@ -229,6 +252,8 @@
|
|||
lines=$lines
|
||||
linked_transactions=$ligne_immo.id_transaction
|
||||
}}
|
||||
|
||||
{{* liaison écriture de sortie *}}
|
||||
{{#foreach from=$result.lines item="line"}}
|
||||
{{if $line.account_code == $immo_account_code}}
|
||||
{{:save
|
||||
|
|
@ -273,30 +298,16 @@
|
|||
}}
|
||||
{{/if}}
|
||||
|
||||
{{if $info_immo != null}}
|
||||
{{* mettre à jour l'état de l'immobilisation *}}
|
||||
{{:save
|
||||
key=$info_immo.key
|
||||
status="archived"
|
||||
}}
|
||||
{{else}}
|
||||
{{:save
|
||||
key=""|uuid
|
||||
validate_schema="schema.json"
|
||||
type="immo"
|
||||
line=$_GET.immo_line_id|intval
|
||||
duration=$_GET.duree_amort|intval
|
||||
date=$_GET.date_mes|date:"Y-m-d"
|
||||
status="archived"
|
||||
}}
|
||||
{{/if}}
|
||||
{{* mettre à jour l'état de l'immobilisation *}}
|
||||
{{:save
|
||||
key=$info_immo.key
|
||||
status="archived"
|
||||
}}
|
||||
|
||||
{{:redirect to="index.html?type_immo=archived"}}
|
||||
{{/form}}
|
||||
|
||||
{{:admin_header title="Sortie du bilan" custom_css="./style.css" current="module_amortization"}}
|
||||
|
||||
{{* barre de navigation *}}
|
||||
{{if ! $dialog}}
|
||||
{{:include file="_nav.html" current="index" subcurrent="balance_exit"}}
|
||||
{{/if}}
|
||||
|
|
@ -370,14 +381,12 @@
|
|||
<dd class="money">{{$ligne_immo.montant|money_currency_html:false|raw}}</dd>
|
||||
<dt>Date d'acquisition</dt>
|
||||
<dd >{{$ligne_immo.date_achat|date_short}}</dd>
|
||||
{{if $_GET.date_mes != $ligne_immo.date_achat|strtotime}}
|
||||
{{if $info_immo.date_mes != null && $info_immo.date_mes != $ligne_immo.date_achat}}
|
||||
<dt>Date de mise en service</dt>
|
||||
<dd>{{$_GET.date_mes|date:"d/m/Y"}}</dd>
|
||||
{{/if}}
|
||||
{{if $_GET.duree_amort != null}}
|
||||
<dt>Durée de l'amortissement</dt>
|
||||
<dd class="num">{{$_GET.duree_amort}} ans</dd>
|
||||
<dd>{{$info_immo.date_mes|date_short}}</dd>
|
||||
{{/if}}
|
||||
<dt>Durée de l'amortissement</dt>
|
||||
<dd class="num">{{$info_immo.duration}} ans</dd>
|
||||
<dt>Montant des amortissements</dt>
|
||||
<dd class="money">{{$_GET.amort_amount|money_currency_html:false|raw}} <span class="help">(à la date de début de l'exercice)</span></dd>
|
||||
<dt>Valeur nette résiduelle</dt>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue