222 lines
7.7 KiB
HTML
222 lines
7.7 KiB
HTML
{{* -*- brindille -*- *}}
|
|
|
|
{{*
|
|
Associer les différentes écritures à une immo créée et sortie du
|
|
bilan avant la mise en service du module
|
|
@param immo_doc_id : id du doc associé à l'immobilisation
|
|
*}}
|
|
|
|
{{* données de l'immobilisation *}}
|
|
{{:include file="_get_immo_data.html" immo_doc_id=$_GET.immo_doc_id keep="info_immo, ligne_immo, message"}}
|
|
{{if $message != null}}
|
|
{{:error message=$message}}
|
|
{{/if}}
|
|
|
|
{{:assign label_immo=$info_immo.label|or:$ligne_immo.trans_label}}
|
|
{{if $ligne_immo.line_label != null && $ligne_immo.line_label != $label_immo}}
|
|
{{:assign label_immo=$label_immo|cat:" — "|cat:$ligne_immo.line_label}}
|
|
{{/if}}
|
|
{{:assign trans_url="%s/acc/transactions/details.php?id=%s"|args:$admin_url:$ligne_immo.trans_id}}
|
|
{{:assign date_immo=$info_immo.date_mes|or:$info_immo.date_achat|or:$ligne_immo.date_achat}}
|
|
{{:assign montant_immo=$info_immo.amount|or:$ligne_immo.amount}}
|
|
|
|
{{* déduire le montant des écritures liées à l'immo courante au crédit du même compte *}}
|
|
{{:include file="_get_credit_lines.html" immo_doc_id=$_GET.immo_doc_id keep="linked_immos, total_credits"}}
|
|
{{:assign solde="%d-%d"|math:$montant_immo:$total_credits}}
|
|
|
|
{{* lister les amortissements liés à l'immobilisation *}}
|
|
{{:include file="./_get_amort_lines.html" immo_doc_id=$_GET.immo_doc_id keep="linked_amort, total_amort"}}
|
|
|
|
{{* chercher des écritures au crédit du compte de l'immo sans doc associé *}}
|
|
{{*
|
|
- line.credit < ligne_immo.amount => peut-être un avoir
|
|
- line.credit = ligne_immo.amount - avoirs => écriture de sortie du bilan
|
|
*}}
|
|
{{#select
|
|
trans.id as trans_id,
|
|
trans.label as trans_label,
|
|
trans.date as date,
|
|
trans.id_year as year,
|
|
line.id as credit_line_id,
|
|
line.label as line_label,
|
|
line.credit as amount,
|
|
acc.id as account_id,
|
|
acc.code as account_code,
|
|
acc.label as account_label
|
|
FROM acc_transactions AS trans
|
|
INNER JOIN acc_transactions_lines AS line ON line.id_transaction = trans.id
|
|
INNER JOIN acc_accounts AS acc ON line.id_account = acc.id
|
|
LEFT JOIN module_data_amortization AS mda ON json_extract(mda.document, '$.amort_line_id') = line.id
|
|
WHERE
|
|
acc.code = :acc_code
|
|
AND line.credit > 0
|
|
AND credit_line_id NOT IN (
|
|
SELECT json_extract(link.document, '$.credit_line_id') AS line_id FROM !table as link
|
|
WHERE json_extract(link.document, '$.type') == "credit_link")
|
|
;
|
|
:acc_code=$ligne_immo.account_code
|
|
!table =$module.table
|
|
assign="credit_line"
|
|
}}
|
|
{{if $credit_line.amount < $solde}}
|
|
{{:assign var="credit_lines." value=$credit_line}}
|
|
{{elseif $credit_line.amount == $solde}}
|
|
{{:assign var="exit_lines." value=$credit_line}}
|
|
{{/if}}
|
|
{{/select}}
|
|
|
|
{{* déterminer le compte d'amortissement en fonction du compte d'immobilisation *}}
|
|
{{:include
|
|
file="./_get_amort_code.html"
|
|
code_immo=$ligne_immo.account_code
|
|
keep="code_amort"
|
|
}}
|
|
|
|
{{* chercher des écritures d'amortissement correspondant au compte d'une immo sans doc associé *}}
|
|
{{* TODO écritures d'amort pas entièrement affectées *}}
|
|
{{#select
|
|
line.id as amort_line_id,
|
|
line.credit as amort_amount,
|
|
line.label as line_label,
|
|
trans.id as amort_trans_id,
|
|
trans.date as date,
|
|
trans.label as trans_label,
|
|
trans.id_year as year,
|
|
account.id as account_id,
|
|
account.code as account_code,
|
|
account.label as account_label
|
|
FROM acc_transactions_lines AS line
|
|
INNER JOIN acc_accounts AS account ON line.id_account = account.id
|
|
INNER JOIN acc_transactions AS trans ON line.id_transaction = trans.id
|
|
WHERE
|
|
account.code = :code_amort
|
|
AND line.credit > 0
|
|
AND (NOT trans.status & 16)
|
|
AND trans.date >= :immo_date
|
|
;
|
|
:code_amort = $code_amort
|
|
:immo_date=$date_immo
|
|
assign="amort_line"
|
|
}}
|
|
{{* voir s'il existe des lignes d'immo liées à cette ligne d'amortissement *}}
|
|
{{:assign amort_amount=0}}
|
|
{{:assign keep_amort=true}}
|
|
{{#load type="amort_link"
|
|
where="$$.amort_line_id = :amort_line_id"
|
|
:amort_line_id=$amort_line.amort_line_id|intval
|
|
assign="amort_link"
|
|
}}
|
|
{{if $amort_link.amount == null || $amort_link.amount == 0}}
|
|
{{:assign amort_amount=$amort_line.amort_amount}}
|
|
{{:assign keep_amort=false}}
|
|
{{else}}
|
|
{{:assign amort_amount="%d+%d"|math:$amort_amount:$amort_link.amount}}
|
|
{{/if}}
|
|
{{else}}
|
|
{{* pas de ligne d'immo liée à cette ligne d'amort => garder cette ligne d'amortissement *}}
|
|
{{/load}}
|
|
{{if $keep_amort && $amort_amount < $amort_line.amort_amount}}
|
|
{{:assign var="free_amort_lines." value=$amort_line}}
|
|
{{/if}}
|
|
{{/select}}
|
|
|
|
{{:admin_header title="Immobilisation sortie du bilan" custom_css="./style.css" current="module_amortization"}}
|
|
|
|
<div class="informations">
|
|
<dl class="describe">
|
|
<dt>Immobilisation</dt>
|
|
<dd><span class="num"><a href="{{$trans_url}}">#{{$ligne_immo.trans_id}}</a></span> {{$label_immo}}</dd>
|
|
<dt>Compte d'immobilisation</dt>
|
|
<dd>{{$ligne_immo.account_code}} — {{$ligne_immo.account_label}}</dd>
|
|
<dt>Montant de l'immobilisation</dt>
|
|
<dd><span class="money">{{$ligne_immo.amount|money_html|raw}}</dd>
|
|
{{if $total_credits > 0}}
|
|
<dt>Montant des avoirs</dt>
|
|
<dd class="money">{{"%f"|math:$total_credits|money_currency_html:false|raw}}</dd>
|
|
<dt>Montant à amortir</dt>
|
|
<dd class="money">{{"%f"|math:$solde|money_currency_html:false|raw}}</dd>
|
|
{{/if}}
|
|
{{if $total_amort > 0}}
|
|
<dt>Montant des amortissements</dt>
|
|
<dd>{{$total_amort|money_currency_html:false|raw}}</dd>
|
|
<dt>Valeur nette résiduelle</dt>
|
|
<dd>{{"%d-%d"|math:$solde:$total_amort|money_currency_html:false|raw}}</dd>
|
|
{{/if}}
|
|
</dl>
|
|
</div>
|
|
|
|
{{if $linked_immos != null}}
|
|
<h3 class="ruler">Écritures d'avoir attachées à l'immobilisation</h3>
|
|
{{/if}}
|
|
|
|
{{if $linked_immos != null}}
|
|
<table class="list">
|
|
<thead>
|
|
<td class="num">N°</td>
|
|
<td>Date</td>
|
|
<td>Libellé</td>
|
|
<td class="nombre">Montant</td>
|
|
<td class="actions"></td>
|
|
</thead>
|
|
<tbody>
|
|
{{#foreach from=$linked_immos item="line"}}
|
|
{{:assign url="%s/acc/transactions/details.php?id=%s"|args:$admin_url:$line.trans_id}}
|
|
<tr>
|
|
<td class="num"><a href="{{$url}}">#{{$line.trans_id}}</a></td>
|
|
<td>{{$line.date|date_short}}</td>
|
|
<td>{{$line.label}}</td>
|
|
<td class="money">{{"%f"|math:$line.amount|money_currency_html:false|raw}}</td>
|
|
<td>
|
|
{{:linkbutton label="Détacher" href="detach_credit.html?immo_doc_id=%s&credit_line_id=%s&from=exit"|args:$_GET.immo_doc_id:$line.credit_line_id shape="minus"}}
|
|
</td>
|
|
</tr>
|
|
{{/foreach}}
|
|
</tbody>
|
|
</table>
|
|
{{else}}
|
|
<p class="block alert">
|
|
Vous pouvez attacher une ou plusieurs écritures d'avoir à votre immobilisation
|
|
</p>
|
|
{{/if}}
|
|
|
|
{{if $credit_lines}}
|
|
<h3 class="ruler">Écritures au crédit du compte d'immobilisation</h3>
|
|
<table class="list">
|
|
<thead>
|
|
<tr>
|
|
<td class="num">N°</td>
|
|
<td>Date</td>
|
|
<td>Libellé</td>
|
|
<td>Montant</td>
|
|
<td>N° compte</td>
|
|
<td>Compte</td>
|
|
<td class="actions"></td>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
{{#foreach from=$credit_lines}}
|
|
{{:assign credit_url="%s/acc/transactions/details.php?id=%s"|args:$admin_url:$trans_id}}
|
|
{{:assign compte_url="%s/acc/accounts/journal.php?id=%s&year=%s"|args:$admin_url:$account_id:$year}}
|
|
<tr>
|
|
<td class="num"><a href="{{$credit_url}}">#{{$trans_id}}</a></td>
|
|
<td>{{$date|date_short}}</td>
|
|
<td>{{$trans_label}}
|
|
{{if $line_label != null && $line_label != $trans_label}} — {{$line_label}}{{/if}}
|
|
</td>
|
|
<td class="money">{{$amount|money_html|raw}}</td>
|
|
<td><a href="{{$compte_url}}">{{$account_code}}</a></td>
|
|
<td>{{$account_label}}</td>
|
|
<td>
|
|
{{:linkbutton label="Attacher" href="attach_credit.html?immo_doc_id=%s&credit_line_id=%s&from=exit"|args:$_GET.immo_doc_id:$credit_line_id shape="plus" target="_dialog"}}
|
|
</td>
|
|
</tr>
|
|
{{/foreach}}
|
|
</tbody>
|
|
</table>
|
|
{{/if}}
|
|
|
|
<form method="post" action="exit_step2.html?immo_doc_id={{$_GET.immo_doc_id}}">
|
|
<p class="submit">
|
|
{{:button type="submit" name="proceed" label="Poursuivre" shape="right" class="main"}}
|
|
</p>
|
|
</form>
|