277 lines
9.6 KiB
HTML
277 lines
9.6 KiB
HTML
{{* -*- brindille -*- *}}
|
|
|
|
{{*
|
|
Lister les écritures d'amortissement associées à une immobilisation
|
|
@param immo_line_id : id de la ligne d'immo
|
|
@param immo_doc_id : id du doc associé à l'immo
|
|
@param type_immo : managed, amortized, archived, others
|
|
*}}
|
|
|
|
{{* données de l'immobilisation *}}
|
|
{{#load type="immo" id=$_GET.immo_doc_id|intval assign="info_immo"}}
|
|
{{else}}
|
|
{{:error message="Immobilisation non trouvée"}}
|
|
{{/load}}
|
|
|
|
{{#select
|
|
line.id as immo_line_id,
|
|
line.debit as montant,
|
|
line.label as line_label,
|
|
trans.id as immo_trans_id,
|
|
trans.label as label,
|
|
trans.date,
|
|
account.code as account_code,
|
|
account.label as account_label
|
|
FROM acc_transactions_lines AS line
|
|
INNER JOIN acc_transactions AS trans ON line.id_transaction = trans.id
|
|
INNER JOIN acc_accounts AS account ON line.id_account = account.id
|
|
WHERE line.id = :line_id;
|
|
:line_id = $info_immo.line
|
|
assign="ligne_immo"
|
|
}}
|
|
{{else}}
|
|
{{:error message="Immobilisation non trouvée"}}
|
|
{{/select}}
|
|
{{:assign trans_url="%s/acc/transactions/details.php?id=%s"|args:$admin_url:$ligne_immo.immo_trans_id}}
|
|
|
|
{{:assign date_debut=$info_immo.date_mes|or:$info_immo.date_achat|or:$ligne_immo.date}}
|
|
{{:assign label_immo=$info_immo.label|or:$ligne_immo.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}}
|
|
{{if $info_immo.amount != null}}
|
|
{{:assign var="ligne_immo.montant" value=$info_immo.amount}}
|
|
{{/if}}
|
|
|
|
{{if $info_immo.status == 'ignored'}}
|
|
{{:error message="Cette immobilisation ne doit pas être amortie"}}
|
|
{{/if}}
|
|
|
|
{{*
|
|
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}}
|
|
{{#load type="immo_link" where="$$.immo_doc_id=:immo_doc_id" :immo_doc_id=$_GET.immo_doc_id|intval}}
|
|
{{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}}
|
|
{{/load}}
|
|
{{:assign var="ligne_immo.montant" value="%d-%d"|math:$ligne_immo.montant:$total_credits}}
|
|
{{:assign solde=$ligne_immo.montant}}
|
|
{{*:debug info_immo=$info_immo ligne_immo=$ligne_immo total_credits=$total_credits solde=$solde*}}
|
|
|
|
{{if $info_immo.status == "amortized"}}
|
|
{{:assign amort_amount=$ligne_immo.montant}}
|
|
{{:assign valeur_residuelle=0}}
|
|
{{else}}
|
|
{{:assign valeur_residuelle=$ligne_immo.montant}}
|
|
{{/if}}
|
|
|
|
{{* lister les lignes des écritures d'amortissement liées à l'immobilisation *}}
|
|
{{#load type="amort_link"
|
|
where="$$.immo_doc_id = :immo_doc_id"
|
|
:immo_doc_id = $_GET.immo_doc_id|intval
|
|
}}
|
|
{{#select
|
|
line.id as amort_line_id,
|
|
line.credit,
|
|
line.label as amort_line_label,
|
|
trans.id as amort_trans_id,
|
|
trans.label as amort_trans_label,
|
|
trans.date as amort_date,
|
|
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 line
|
|
INNER JOIN acc_transactions AS trans ON line.id_transaction = trans.id
|
|
INNER join acc_accounts AS account on line.id_account = account.id
|
|
WHERE line.id = :amort_line_id
|
|
;
|
|
:amort_line_id = $amort_line_id
|
|
assign="amort_line"
|
|
}}
|
|
{{:assign var="amort_line.amort_amount" value=$amount|or:$credit}}
|
|
{{:assign var="linked_amort.%s_%d"|args:$amort_date:$id value=$amort_line}}
|
|
{{:assign valeur_residuelle="%d-%d"|math:$valeur_residuelle:$amort_line.amort_amount}}
|
|
{{/select}}
|
|
{{/load}}
|
|
|
|
{{:assign autres_amortissements=false}}
|
|
{{if $valeur_residuelle > 0}}
|
|
{{* Chercher des amortissements non rattachés à une immo *}}
|
|
{{#select
|
|
line.id as amort_line_id,
|
|
line.id_transaction AS amort_trans_id
|
|
FROM acc_transactions_lines AS line
|
|
INNER JOIN acc_accounts AS account ON account.id = line.id_account
|
|
INNER JOIN acc_transactions AS trans ON trans.id = line.id_transaction
|
|
INNER JOIN acc_years AS y ON y.id = trans.id_year
|
|
WHERE account.code LIKE "28%" AND credit > 0 AND (NOT trans.status & 16)
|
|
ORDER BY trans.date, trans.label;
|
|
}}
|
|
{{* cette ligne d'amortissement a-t-elle un doc associé ? *}}
|
|
{{#load type="amort_link"
|
|
where="$$.amort_line_id = :amort_line_id"
|
|
:amort_line_id = $amort_line_id
|
|
}}
|
|
{{else}}
|
|
{{:assign autres_amortissements=true}}
|
|
{{/load}}
|
|
{{/select}}
|
|
{{/if}}
|
|
|
|
{{:admin_header title="Liste des amortissements" custom_css="./style.css" current="module_amortization"}}
|
|
|
|
{{* barre de navigation *}}
|
|
{{if $_GET.type_immo == "amortized" || $valeur_residuelle== 0 }}
|
|
{{:assign subcurrent="amortized"}}
|
|
{{elseif $_GET.type_immo == "archived"}}
|
|
{{:assign subcurrent="archived"}}
|
|
{{elseif $_GET.type_immo == null || $_GET.type_immo == "managed"}}
|
|
{{:assign subcurrent="managed"}}
|
|
{{else}}
|
|
{{:assign subcurrent="other"}}
|
|
{{/if}}
|
|
|
|
{{:include
|
|
file="_nav.html"
|
|
current="index"
|
|
subcurrent="%s"|args:$subcurrent
|
|
subsubcurrent="amortization"
|
|
type_immo=$_GET.type_immo
|
|
autres_amort=$autres_amortissements
|
|
}}
|
|
|
|
{{if $_GET.ok}}
|
|
{{if $_GET.msg|match:"attach"}}
|
|
{{:assign msg="Attachement amortissement %s effectué"|args:$_GET.trans_id}}
|
|
{{elseif $_GET.msg|match:"detach"}}
|
|
{{:assign msg="Détachement amortissement %s affectué"|args:$_GET.trans_id}}
|
|
{{elseif $_GET.msg|match:"amortissement"}}
|
|
{{:assign msg="Amortissement enregistré"}}
|
|
{{/if}}
|
|
<p class="block confirm">{{$msg}}</p>
|
|
{{elseif $_GET.err}}
|
|
{{if $_GET.msg|match:"attach"}}
|
|
{{:assign msg="Échec attachement amortissement"}}
|
|
{{elseif $_GET.msg|match:"amortissement"}}
|
|
{{:assign msg="Échec enregistrement amortissement"}}
|
|
{{/if}}
|
|
<p class="block error">{{$msg}}</p>
|
|
{{/if}}
|
|
|
|
<form method="post" action="">
|
|
<fieldset>
|
|
<legend>Sortir l'immobilisation du bilan ?</legend>
|
|
<p class="submit">
|
|
{{:linkbutton
|
|
label="Sortir du bilan"
|
|
href="balance_sheet_exit.html?immo_line_id=%s&immo_doc_id=%s&type_immo=%s"|args:$_GET.immo_line_id:$_GET.immo_doc_id:$_GET.type_immo
|
|
shape="export"
|
|
class="main"
|
|
}}
|
|
</p>
|
|
<p class="help">
|
|
Il sera possible de choisir la date de sortie, d'indiquer
|
|
le montant de la cession le cas échéant et de modifier les
|
|
comptes associés.
|
|
</p>
|
|
</fieldset>
|
|
</form>
|
|
|
|
<div class="informations">
|
|
<dl class="describe">
|
|
<dt>Immobilisation</dt>
|
|
<dd><span class="num"><a href="{{$trans_url}}">#{{$ligne_immo.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 class="money strong">{{"%f"|math:$ligne_immo.montant|money_currency_html:false|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 strong">{{"%f"|math:$solde|money_currency_html:false|raw}}</dd>
|
|
{{/if}}
|
|
<dt>Début d'amortissement</dt>
|
|
<dd>{{$date_debut|date_short}}</dd>
|
|
{{if $info_immo.duration != null}}
|
|
<dt>Durée</dt>
|
|
<dd>{{$info_immo.duration}} ans</dd>
|
|
{{/if}}
|
|
{{if $valeur_residuelle > 0}}
|
|
<dt>Montant des amortissements</dt>
|
|
<dd>{{"%d-%d"|math:$ligne_immo.montant:$valeur_residuelle|money_currency_html:false|raw}}</dd>
|
|
<dt>Valeur nette comptable</dt>
|
|
<dd>{{$valeur_residuelle|money_currency_html:false|raw}}</dd>
|
|
{{/if}}
|
|
{{if $info_immo.duration != null && $valeur_residuelle > 0}}
|
|
<dt>Annuité estimée</dt>
|
|
<dd>{{"min(%d, %f/%d)"|math:$valeur_residuelle:$ligne_immo.montant:$info_immo.duration|money_currency_html:false|raw}}</dd>
|
|
{{/if}}
|
|
</dl>
|
|
</div>
|
|
|
|
<h3 class="ruler">Amortissements enregistrés</h3>
|
|
{{if $linked_amort != null}}
|
|
<section class="amortissement">
|
|
<table class="list">
|
|
<thead>
|
|
<tr>
|
|
<th class="num">N°</th>
|
|
<th>Date</th>
|
|
<th class="nombre">Montant</th>
|
|
<th class="nombre">Valeur nette</th>
|
|
<th>Libellé</th>
|
|
<th>N° compte</th>
|
|
<th>Compte</th>
|
|
<th class="actions"></th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
{{#foreach from=$linked_amort|ksort item="line"}}
|
|
{{* données de l'écriture *}}
|
|
{{: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 solde="%f-%d"|math:$solde:$line.amort_amount}}
|
|
<tr>
|
|
<td class="num"><a href="{{$trans_url}}">#{{$line.amort_trans_id}}</a></td>
|
|
<td>{{$line.amort_date|date_short}}</td>
|
|
<td class="money">{{"%f"|math:$line.amort_amount|money_html:false|raw}}</td>
|
|
<td class="money">{{"%f"|math:$solde|money_html:false|raw}}</td>
|
|
<td>
|
|
{{$line.amort_trans_label}}
|
|
{{if $line.amort_line_label != null && $line.amort_line_label != $line.amort_trans_label}}
|
|
— {{$line.amort_line_label}}
|
|
{{/if}}
|
|
</td>
|
|
<td><a href="{{$compte_url}}">{{$line.account_code}}</a></td>
|
|
<td>{{$line.account_label}}</td>
|
|
<td>
|
|
{{:linkbutton label="Détacher" href="detach_amort.html?amort_line_id=%d&immo_line_id=%d&immo_doc_id=%s"|args:$line.amort_line_id:$ligne_immo.immo_line_id:$_GET.immo_doc_id shape="minus"}}
|
|
</td>
|
|
</tr>
|
|
{{/foreach}}
|
|
</tbody>
|
|
</table>
|
|
</section>
|
|
{{else}}
|
|
<p class="block alert">Aucun amortissement enregistré pour cette immobilisation</p>
|
|
{{/if}}
|
|
|
|
{{if $autres_amortissements}}
|
|
<p class="block alert">
|
|
Il y a des écritures d'amortissement qui ne sont pas rattachées à une immobilisation ! <br />
|
|
Utilisez le bouton « Rattacher un amortissement » pour les afficher ; vous pourrez choisir d'en attacher certaines à cette immobilisation.
|
|
</p>
|
|
{{/if}}
|
|
{{:form_errors}}
|
|
{{:admin_footer}}
|