213 lines
7.1 KiB
HTML
213 lines
7.1 KiB
HTML
{{* -*- brindille -*- *}}
|
|
|
|
{{*
|
|
@param immo_line_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
|
|
*}}
|
|
|
|
{{* cas de la prise en charge *}}
|
|
{{* données de l'immobilisation *}}
|
|
{{:assign montant_affecte=0}}
|
|
{{#load type="immo" where="$$.line = :line_id" :line_id=$_GET.immo_line_id|intval assign="info_immo"}}
|
|
{{:assign montant_affecte="%d+%d"|math:$montant_affecte:$amount}}
|
|
{{/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 = $_GET.immo_line_id|intval
|
|
assign="ligne_immo"
|
|
}}
|
|
{{else}}
|
|
{{:error message="Immobilisation non trouvée"}}
|
|
{{/select}}
|
|
|
|
{{:assign reste="%d-%d"|math:$ligne_immo.montant:$montant_affecte}}
|
|
{{*
|
|
{{if $info_immo != null}}
|
|
{{:assign date_defaut=$info_immo.date}}
|
|
{{:assign duree_defaut=$info_immo.duration}}
|
|
{{:assign choix_defaut=$info_immo.status}}
|
|
{{else}}
|
|
{{:assign duree_defaut=null}}
|
|
{{/if}}
|
|
*}}
|
|
|
|
{{#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}}
|
|
|
|
{{* vérifier que la date de mise en service est postérieure à la date d'acquisition *}}
|
|
{{:assign d1=$_POST.date_achat|or:$ligne_immo.date_achat|parse_date}}
|
|
{{:assign d2=$_POST.date_mes|or:$d1|parse_date}}
|
|
{{if $d2 < $d1}}
|
|
{{:assign da=$d1|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}}
|
|
|
|
{{: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}}
|
|
{{/if}}
|
|
|
|
{{if $_POST.montant == null || $_POST.montant|money_int == 0 }}
|
|
{{if $montant_affecte > 0}}
|
|
{{:assign montant=$reste}}
|
|
{{else}}
|
|
{{:assign montant=null}}
|
|
{{/if}}
|
|
{{else}}
|
|
{{:assign montant=$_POST.montant|money_int}}
|
|
{{if $montant == $ligne_immo.montant}}
|
|
{{:assign montant=null}}
|
|
{{/if}}
|
|
{{/if}}
|
|
{{if $montant > $reste}}
|
|
{{:assign reste_nb="%f"|math:$reste|money_currency:false}}
|
|
{{:assign montant_nb="%f"|math:$montant|money_currency:false}}
|
|
{{:error message="Le montant (%s) ne peut être supérieur au reste (%s)"|args:$montant_nb:$reste_nb}}
|
|
{{/if}}
|
|
|
|
{{if $_POST.date_achat == null || $_POST.date_achat|parse_date == $ligne_immo.date_achat}}
|
|
{{:assign date_achat=null}}
|
|
{{else}}
|
|
{{:assign date_achat=$_POST.date_achat|parse_date}}
|
|
{{/if}}
|
|
|
|
{{if $_POST.date_mes == null || $_POST.date_mes == $_POST.date_achat || $_POST.date_mes|parse_date == $ligne_immo.date_achat}}
|
|
{{:assign date_mes=null}}
|
|
{{else}}
|
|
{{:assign date_mes=$_POST.date_mes|parse_date}}
|
|
{{/if}}
|
|
{{:assign status="managed"}}
|
|
{{/if}}
|
|
|
|
{{* enregistrer les infos de l'immobilisation *}}
|
|
{{if $info_immo == null || $montant_affecte > 0}}
|
|
{{:assign key=""|uuid}}
|
|
{{else}}
|
|
{{:assign key=$info_immo.key}}
|
|
{{/if}}
|
|
{{:save
|
|
key=$key
|
|
validate_schema="schema.json"
|
|
type="immo"
|
|
line=$_GET.immo_line_id|intval
|
|
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}}
|
|
|
|
{{:admin_header title="Classer l'immobilisation" custom_css="./style.css" current="module_amortization"}}
|
|
|
|
{{* 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}}
|
|
|
|
{{*
|
|
- classer l'immobilisation
|
|
- renseigner ou 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> {{$ligne_immo.trans_label}}{{if $ligne_immo.line_label != null && $ligne_immo.line_label != $ligne_immo.trans_label}} — {{$ligne_immo.line_label}}{{/if}}</dd>
|
|
<dt>Montant</dt>
|
|
<dd class="money strong">{{"%f"|math:$ligne_immo.montant|money_currency_html:false|raw}}</dd>
|
|
<dt>Montant déjà affecté</dt>
|
|
<dd class="money strong">{{"%f"|math:$montant_affecte|money_currency_html:false|raw}}</dd>
|
|
<dt>Montant restant à affecter</dt>
|
|
<dd class="money strong">{{"%f"|math:$reste|money_currency_html:false|raw}}</dd> <dt>Date de l'écriture d'immobilisation</dt>
|
|
<dd>{{$ligne_immo.date_achat|date_short}}</dd>
|
|
<dt>Compte d'immobilisation</dt>
|
|
<dd>{{$ligne_immo.code}} — {{$ligne_immo.account_label}}
|
|
</dl>
|
|
</div>
|
|
|
|
<form method="post" action="">
|
|
<fieldset>
|
|
<legend>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" required=true min=1}}
|
|
</div>
|
|
</dl>
|
|
</fieldset>
|
|
<fieldset class="masquable">
|
|
<legend>Informations facultatives</legend>
|
|
<dl>
|
|
{{:input type="date" name="date_achat" label="Date d'acquisition" help="à renseigner uniquement si différente de la date de l'écriture d'immobilisation"}}
|
|
{{:input type="date" name="date_mes" label="Date de mise en service" help="à renseigner uniquement si différente de la date d'acquisition"}}
|
|
{{:input type="text" name="libelle" label="Libellé" help="à renseigner uniquement si différent du libellé de l'écriture d'immobilisation"}}
|
|
{{:input type="money" name="montant" label="Montant de l'immobilisation" required=true default=$reste}}
|
|
</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>
|