288 lines
9.7 KiB
HTML
288 lines
9.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}}
|
|
|
|
{{#form on="backward"}}
|
|
{{:redirect to="exit_step3.html?immo_doc_id=%s"|args:$_GET.immo_doc_id}}
|
|
{{/form}}
|
|
|
|
{{#form on="validate"}}
|
|
{{* mettre à jour l'état de l'immobilisation *}}
|
|
{{:save
|
|
key=$info_immo.key
|
|
status="archived"
|
|
}}
|
|
{{:redirect to="index.html?type_immo=archived"}}
|
|
{{/form}}
|
|
|
|
{{#form on="finish"}}
|
|
{{:redirect to="index.html?type_immo=managed"}}
|
|
{{/form}}
|
|
|
|
{{: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 une écriture de sortie de bilan associée *}}
|
|
{{#load type="exit_link" where="$$.immo_doc_id = :immo_doc_id" :immo_doc_id=$info_immo.id assign="exit_info"}}
|
|
{{/load}}
|
|
{{if $exit_info != null}}
|
|
{{#select
|
|
trans.id as trans_id,
|
|
trans.label as trans_label,
|
|
trans.date as date,
|
|
line.id as 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
|
|
WHERE line.id = :exit_line_id;
|
|
:exit_line_id = $exit_info.exit_line_id
|
|
assign="exit_line"
|
|
}}
|
|
{{/select}}
|
|
{{/if}}
|
|
|
|
{{*
|
|
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(credit_link.document, '$.credit_line_id') AS line_id FROM !table as credit_link
|
|
WHERE json_extract(credit_link.document, '$.type') == "credit_link"
|
|
UNION
|
|
SELECT json_extract(exit_link.document, '$.exit_line_id') AS line_id FROM !table as exit_link
|
|
WHERE json_extract(exit_link.document, '$.type') == "exit_link"
|
|
)
|
|
;
|
|
:acc_code=$ligne_immo.account_code
|
|
!table =$module.table
|
|
assign="credit_line"
|
|
}}
|
|
{{if $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"}}
|
|
|
|
{{if $_GET.ok}}
|
|
{{if $_GET.msg|match:"attach_exit"}}
|
|
{{:assign msg="Écriture de sortie de bilan attachée"}}
|
|
{{elseif $_GET.msg|match:"detach_exit"}}
|
|
{{:assign msg="Écriture de sortie de bilan détachée"}}
|
|
{{/if}}
|
|
<p class="block confirm">{{$msg}}</p>
|
|
{{/if}}
|
|
|
|
<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 $exit_line != null}}
|
|
<h3 class="ruler">Écriture de sortie du bilan attachée à l'immobilisation</h3>
|
|
<table class="list">
|
|
<thead>
|
|
<tr>
|
|
<td class="num">N°</td>
|
|
<td>Date</td>
|
|
<td>Libellé</td>
|
|
<td class="nombre">Montant</td>
|
|
<td>N° compte</td>
|
|
<td>Compte</td>
|
|
<td class="actions"></td>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<tr>
|
|
<td class="num"><a href="{{$trans_url}}">#{{$exit_line.trans_id}}</a></td>
|
|
<td>{{$exit_line.date|date_short}}</td>
|
|
<td>
|
|
{{if $exit_line.line_label != null}}
|
|
{{$exit_line.line_label}}
|
|
{{else}}
|
|
{{$exit_line.trans_label}}
|
|
{{/if}}
|
|
</td>
|
|
<td class="money">{{"%f"|math:$exit_line.amount|money_html:false|raw}}</td>
|
|
<td><a href="{{$compte_url}}">{{$exit_line.account_code}}</a></td>
|
|
<td>{{$exit_line.account_label}}</td>
|
|
<td>
|
|
{{:linkbutton label="Détacher" href="detach_exit.html?immo_doc_id=%s&exit_line_id=%s&from=exit"|args:$_GET.immo_doc_id:$exit_line.line_id shape="minus"}}
|
|
</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
{{elseif $exit_lines}}
|
|
<p class="block alert">
|
|
Vous pouvez attacher une écriture de sortie du bilan à l'immobilisation
|
|
</p>
|
|
{{/if}}
|
|
|
|
{{if $exit_lines}}
|
|
<h3 class="ruler">Écritures non rattachées</h3>
|
|
<table class="list">
|
|
<thead>
|
|
<tr>
|
|
<td class="num">N°</td>
|
|
<td>Date</td>
|
|
<td>Libellé</td>
|
|
<td class="nombre">Montant</td>
|
|
<td>N° compte</td>
|
|
<td>Compte</td>
|
|
<td class="actions"></td>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
|
|
{{#foreach from=$exit_lines item="line"}}
|
|
{{:assign exit_url="%s/acc/transactions/details.php?id=%s"|args:$admin_url:$line.trans_id}}
|
|
{{:assign compte_url="%s/acc/accounts/journal.php?id=%s&year=%s"|args:$admin_url:$line.account_id:$line.year}}
|
|
<tr>
|
|
<td class="num"><a href="{{$exit_url}}">#{{$line.trans_id}}</a></td>
|
|
<td>{{$line.date|date_short}}</td>
|
|
<td>{{$line.trans_label}}
|
|
{{if $line.line_label != null && $line.line_label != $line.trans_label}} — {{$line.line_label}}{{/if}}
|
|
</td>
|
|
<td class="money">{{"%f"|math:$line.amount|money_html:false|raw}}</td>
|
|
<td><a href="{{$compte_url}}">{{$line.account_code}}</a></td>
|
|
<td>{{$line.account_label}}</td>
|
|
<td>
|
|
{{:linkbutton label="Attacher" href="attach_exit.html?immo_doc_id=%s&exit_line_id=%s&from=exit"|args:$_GET.immo_doc_id:$line.credit_line_id shape="plus"}}
|
|
</td>
|
|
</tr>
|
|
{{/foreach}}
|
|
</tbody>
|
|
</table>
|
|
{{elseif $exit_line == null}}
|
|
<p class="block alert">Aucune écriture de sortie du bilan. Vérifiez l'attachement d'écriture d'avoir.</p>
|
|
{{/if}}
|
|
|
|
<form method="post" action="">
|
|
<p class="submit">
|
|
{{:button type="submit" name="backward" label="Revenir à l'étape précédente" shape="left" class="main"}}
|
|
{{if $exit_line}}
|
|
{{:button type="submit" name="validate" label="Terminer" shape="check" class="main"}}
|
|
{{else}}
|
|
{{:button type="submit" name="finish" label="Terminer" shape="export" class="main"}}
|
|
{{/if}}
|
|
</p>
|
|
</form>
|