293 lines
9.9 KiB
HTML
293 lines
9.9 KiB
HTML
{{* -*- brindille -*- *}}
|
|
{{:admin_header title="Modifier l'immobilisation" custom_css="./style.css" current="module_amortization"}}
|
|
|
|
{{*
|
|
@param immo_doc_id
|
|
¿ @param type_immo : managed, amortized, archived, other ?
|
|
|
|
TODO :
|
|
- séparer les cas des immo simples et complexes (BOI)
|
|
par exemple pour la durée d'amort par défaut {{:input ...}}
|
|
- prise en charge immo => param = immo_line_id
|
|
- modif param immo => param = immo_doc_id
|
|
- DONE possibilité supprimer liaison écriture avoir
|
|
*}}
|
|
|
|
{{* données de l'immobilisation *}}
|
|
{{#load id=$_GET.immo_doc_id|intval assign="info_immo"}}
|
|
{{else}}
|
|
{{:error message="Immobilisation non trouvée"}}
|
|
{{/load}}
|
|
{{#select
|
|
trans.id as immo_trans_id,
|
|
trans.label as trans_label,
|
|
trans.date as date_achat,
|
|
line.debit as montant,
|
|
line.label as line_label,
|
|
acc.code,
|
|
acc.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 acc ON line.id_account = acc.id
|
|
WHERE line.id = :line_id;
|
|
:line_id = $info_immo.line
|
|
assign="ligne_immo"
|
|
}}
|
|
{{else}}
|
|
{{:error message="Immobilisation non trouvée"}}
|
|
{{/select}}
|
|
{{:assign montant_immo=$info_immo.amount|or:$ligne_immo.montant}}
|
|
|
|
{{:assign immo_label=$info_immo.label|or:$ligne_immo.trans_label}}
|
|
{{if $ligne_immo.line_label != null && $ligne_immo.line_label != $immo_label}}
|
|
{{:assign immo_label=$immo_label|cat:" — "|cat:$ligne_immo.line_label}}
|
|
{{/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 linked_immos=null}}
|
|
{{:assign total_credits=0}}
|
|
{{#load type="credit_link" where="$$.immo_doc_id=:immo_doc_id" :immo_doc_id=$_GET.immo_doc_id|intval}}
|
|
{{#select
|
|
line.credit,
|
|
trans.id
|
|
FROM acc_transactions_lines AS line
|
|
INNER JOIN acc_transactions AS trans ON line.id_transaction = trans.id
|
|
WHERE line.id = :credit_line_id;
|
|
:credit_line_id=$credit_line_id
|
|
}}
|
|
{{:assign credit=$credit}}
|
|
{{:assign credit_trans_id=$id}}
|
|
{{/select}}
|
|
{{:assign var="linked_immos." doc=$id trans=$credit_trans_id}}
|
|
{{if $amount == null}}
|
|
{{:assign total_credits="%d+%d"|math:$total_credits:$credit}}
|
|
{{else}}
|
|
{{:assign total_credits="%d+%d"|math:$total_credits:$amount}}
|
|
{{/if}}
|
|
{{/load}}
|
|
{{:assign solde="%d-%d"|math:$montant_immo:$total_credits}}
|
|
|
|
{{:assign autres_amount=0}}
|
|
{{#load
|
|
type="immo"
|
|
where="$$.line = :line_id AND id != :doc_id"
|
|
:line_id = $info_immo.line
|
|
:doc_id = $info_immo.id
|
|
}}
|
|
{{:assign autres_amount="%d+%d"|math:$autres_amount:$amount}}
|
|
{{/load}}
|
|
{{:assign max_disponible="%d-%d"|math:$ligne_immo.montant:$autres_amount}}
|
|
|
|
{{* traiter la saisie *}}
|
|
{{#form on="save"}}
|
|
{{if ! $_POST.amortir}}
|
|
{{* ne pas amortir *}}
|
|
{{:assign duration=0}}
|
|
{{:assign libelle=null}}
|
|
{{:assign montant=null}}
|
|
{{:assign date_achat=null}}
|
|
{{:assign date_mes=null}}
|
|
{{:assign status="ignored"}}
|
|
{{else}}
|
|
{{if $_POST.date_achat == null || $_POST.date_achat|parse_date == $ligne_immo.date_achat}}
|
|
{{:assign date_achat=null}}
|
|
{{elseif $_POST.date_achat|parse_date == $info_immo.date_achat}}
|
|
{{:assign date_achat=$info_immo.date_achat}}
|
|
{{else}}
|
|
{{:assign date_achat=$_POST.date_achat|parse_date}}
|
|
{{/if}}
|
|
{{if $_POST.date_achat|parse_date > $ligne_immo.date_achat}}
|
|
{{:assign da=$ligne_immo.date_achat|date_short}}
|
|
{{:error message="Erreur : la date d'achat (%s) ne peut être postérieure à la date de l'écriture d'immobilisation (%s)"|args:$_POST.date_achat:$da}}
|
|
{{/if}}
|
|
|
|
{{if $_POST.date_mes == null || $_POST.date_mes|parse_date == $ligne_immo.date_achat}}
|
|
{{:assign date_mes=null}}
|
|
{{elseif $_POST.date_mes|parse_date == $info_immo.date_achat}}
|
|
{{:assign date_mes=null}}
|
|
{{else}}
|
|
{{:assign date_mes=$_POST.date_mes|parse_date}}
|
|
{{:assign date_achat_comp=$ligne_immo.date_achat}}
|
|
{{if $date_achat != null}}
|
|
{{:assign date_achat_comp=$date_achat}}
|
|
{{/if}}
|
|
{{if $date_mes < $date_achat_comp}}
|
|
{{:assign da=$date_achat_comp|date_short}}
|
|
{{:error message="Erreur : la date de mise en service (%s) ne peut être antérieure à la date d'acquisition (%s)"|args:$_POST.date_mes:$da}}
|
|
{{/if}}
|
|
{{/if}}
|
|
|
|
{{:assign duration=$_POST.duree|intval}}
|
|
{{if $duration <= 0}}
|
|
{{:error message="Erreur : la durée d'amortissement doit être strictement positive"}}
|
|
{{/if}}
|
|
|
|
{{if $_POST.libelle != $ligne_immo.line_label && $_POST.libelle != $ligne_immo.trans_label}}
|
|
{{:assign libelle=$_POST.libelle}}
|
|
{{else}}
|
|
{{:assign libelle=null}}
|
|
{{/if}}
|
|
|
|
{{:assign montant=null}}
|
|
{{if $_POST.montant == null || $_POST.montant|money_int == 0 || $_POST.montant|money_int == $info_immo.amount}}
|
|
{{:assign montant=$info_immo.amount}}
|
|
{{else}}
|
|
{{:assign montant=$_POST.montant|money_int}}
|
|
{{if $montant < 0 || $montant > $max_disponible}}
|
|
{{:assign montant_aff="%f"|math:$montant|money_currency:false}}
|
|
{{:assign max_aff="%f"|math:$max_disponible|money_currency:false}}
|
|
{{:error message="Le montant (%s) doit être positif et ne peut être supérieur à %s"|args:$montant_aff:$max_aff}}
|
|
{{/if}}
|
|
{{/if}}
|
|
|
|
{{:assign status="managed"}}
|
|
{{/if}}
|
|
|
|
{{* écritures de crédit *}}
|
|
{{#foreach from=$linked_immos item="elem"}}
|
|
{{if ! $_POST.credit_id|has:$elem.trans}}
|
|
{{:assign var="docs_to_remove." value=$elem.doc}}
|
|
{{:assign var="links_to_remove." value=$elem.trans}}
|
|
{{/if}}
|
|
{{/foreach}}
|
|
|
|
{{if $docs_to_remove != null}}
|
|
{{:assign remove_set=$docs_to_remove|implode:","}}
|
|
{{:assign remove_set="("|cat:$remove_set|cat:")"}}
|
|
{{:delete where="id IN %s"|args:$remove_set}}
|
|
|
|
{{* idem avec acc_transactions_links *}}
|
|
{{#select
|
|
CASE links.id_related = :immo_trans_id
|
|
WHEN true THEN links.id_transaction
|
|
WHEN false THEN links.id_related
|
|
END as linked_id
|
|
FROM acc_transactions_links as links
|
|
WHERE id_transaction = :immo_trans_id or id_related = :immo_trans_id;
|
|
:immo_trans_id = $ligne_immo.immo_trans_id
|
|
}}
|
|
{{if ! $linked_id|in:$links_to_remove}}
|
|
{{:assign var="linked_transactions." value=$linked_id}}
|
|
{{/if}}
|
|
{{/select}}
|
|
|
|
{{* Enregistrer les liaisons *}}
|
|
{{:api
|
|
method="POST"
|
|
path="accounting/transaction/%s/transactions"|args:$ligne_immo.immo_trans_id
|
|
assign="result"
|
|
assign_code="result_code"
|
|
transactions=$linked_transactions
|
|
}}
|
|
{{/if}}
|
|
|
|
{{* enregistrer les infos de l'immobilisation *}}
|
|
{{:save
|
|
key=$info_immo.key
|
|
validate_schema="schema.json"
|
|
type="immo"
|
|
line=$info_immo.line
|
|
duration=$duration
|
|
label=$libelle
|
|
amount=$montant
|
|
date_achat=$date_achat
|
|
date_mes=$date_mes
|
|
status=$status
|
|
assign_new_id="new_id"
|
|
}}
|
|
|
|
{{if $_POST.amortir}}
|
|
{{:assign type_immo="managed"}}
|
|
{{else}}
|
|
{{:assign type_immo="other"}}
|
|
{{/if}}
|
|
{{:redirect force="index.html?ok=1&msg=infos&type_immo=%s"|args:$type_immo}}
|
|
|
|
{{/form}}
|
|
{{:form_errors}}
|
|
|
|
{{* barre de navigation *}}
|
|
{{if ! $dialog}}
|
|
{{:include file="_nav.html" current="index" subcurrent="%s"|args:$_GET.type_immo subsubcurrent="parameter"}}
|
|
{{/if}}
|
|
|
|
{{:assign choix_defaut=$_GET.type_immo}}
|
|
|
|
{{*
|
|
modifier la date de mise en service, les écritures associées ou la durée d'amortissement
|
|
*}}
|
|
|
|
{{:assign trans_url="%s/acc/transactions/details.php?id=%s"|args:$admin_url:$ligne_immo.immo_trans_id}}
|
|
<h3 class="ruler">Paramètres de l'immobilisation</h3>
|
|
<div class="informations">
|
|
<dl class="describe">
|
|
<dt>Immobilisation</dt>
|
|
<dd><span class="num"><a href="{{$trans_url}}">#{{$ligne_immo.immo_trans_id}}</a></span> {{$immo_label}}</dd>
|
|
<dt>Compte d'immobilisation</dt>
|
|
<dd>{{$ligne_immo.code}} — {{$ligne_immo.account_label}}
|
|
<dt>Montant</dt>
|
|
<dd class="money strong">{{"%f"|math:$montant_immo|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>Date de l'écriture d'immobilisation</dt>
|
|
<dd>{{$ligne_immo.date_achat|date_short}}</dd>
|
|
</dl>
|
|
</div>
|
|
|
|
<form method="post" action="">
|
|
<fieldset>
|
|
<legend>Paramètres de l'amortissement</legend>
|
|
<dl>
|
|
{{:input id="amortir" type="checkbox" value=1 name="amortir" label="Amortir cette immobilisation sur une ou plusieurs années" checked="checked" help="Dé-cocher pour ne pas amortir"}}
|
|
<div class="masquable">
|
|
{{:input type="number" name="duree" label="Durée d'amortissement" min=1 default=$info_immo.duration}}
|
|
{{:input type="text" name="libelle" label="Libellé" default=$info_immo.label}}
|
|
{{if $info_immo.amount != null}}
|
|
{{:assign max_aff="%f"|math:$max_disponible|money_currency:false}}
|
|
{{:input type="money" name="montant" label="Montant de l'immobilisation" default=$montant_immo help="Montant maximum = %s"|args:$max_aff}}
|
|
{{/if}}
|
|
{{:input type="date" name="date_achat" label="Date d'acquisition" default=$info_immo.date_achat}}
|
|
{{:input type="date" name="date_mes" label="Date de mise en service" default=$info_immo.date_mes}}
|
|
{{if $linked_immos != null}}
|
|
<dt><label>Écritures d'avoir liées à l'immobilisation</label></dt>
|
|
<dd>
|
|
<span class="input-list avoirs">
|
|
<label for="credit_id">Écritures :</label>
|
|
{{#foreach from=$linked_immos item="elem"}}
|
|
<span class="label">
|
|
<input type="hidden" name="credit_id[]" value="{{$elem.trans}}">{{$elem.trans}}
|
|
<button data-icon="✘" type="button" class=" icn-btn" title="Cliquer pour supprimer la liaison"></button>
|
|
</span>
|
|
{{/foreach}}
|
|
</span>
|
|
</dd>
|
|
{{/if}}
|
|
</div>
|
|
</dl>
|
|
</fieldset>
|
|
<p class="submit">
|
|
{{:button type="submit" name="save" label="Enregistrer" shape="right" class="main"}}
|
|
</p>
|
|
</form>
|
|
|
|
{{:admin_footer}}
|
|
|
|
<script type="text/javascript" src="scripts.js"></script>
|
|
<script type="text/javascript">
|
|
|
|
function changeVisibility(evt, idcheck = 'f_amortir_1', hiddenclass = 'masquable')
|
|
{
|
|
toggleVisibility(idcheck, document.querySelectorAll('.' + hiddenclass));
|
|
}
|
|
|
|
(function () {
|
|
document.getElementById('f_amortir_1').onclick = changeVisibility;
|
|
})();
|
|
|
|
</script>
|