109 lines
3.2 KiB
HTML
109 lines
3.2 KiB
HTML
{{* -*- brindille -*- *}}
|
|
|
|
{{:admin_header title="Renseigner informations amortissement" custom_css=$custom_css current="module_amortissement"}}
|
|
|
|
{{* barre de navigation *}}
|
|
{{if ! $dialog}}
|
|
{{:include file="_nav.html" current="index"}}
|
|
{{/if}}
|
|
|
|
{{* Traiter l'envoi du formulaire *}}
|
|
{{#form on="add"}}
|
|
|
|
{{* chercher la date d'acquisition de l'immobilisation *}}
|
|
{{:assign var="immo_id" value=$_GET.immo_id|intval}}
|
|
{{#select
|
|
trans.date as date_achat
|
|
from acc_transactions_lines as line
|
|
inner join acc_transactions as trans on line.id_transaction = trans.id
|
|
where line.id = :line_id;
|
|
:line_id = $immo_id
|
|
assign=ligne_immo
|
|
}}
|
|
{{/select}}
|
|
|
|
{{if $_POST.no_amort}}
|
|
{{* ne pas amortir *}}
|
|
{{:assign duration=0}}
|
|
{{:assign date_debut=$ligne_immo.date_achat|parse_date}}
|
|
{{:assign noamort=true}}
|
|
{{else}}
|
|
{{* vérifier que la date d'acquisition est antérieure à la date de mise en service *}}
|
|
{{:assign date_debut=$_POST.date_mes|or:$ligne_immo.date_achat|parse_date}}
|
|
{{if $date_debut|strtotime < $ligne_immo.date_achat|strtotime}}
|
|
{{:assign dd=$date_debut|date_short}}
|
|
{{:assign da=$ligne_immo.date_achat|date_short}}
|
|
{{:error message="Erreur : la date de mise en service (%s) ne peut être antérieure à la date d'acquisition (%s)"|args:$dd:$da}}
|
|
{{/if}}
|
|
{{:assign duration=$_POST.duree|intval}}
|
|
{{if $duration <= 0}}
|
|
{{:error message="Erreur : la durée d'amortissement doit être strictement positive"}}
|
|
{{/if}}
|
|
{{:assign noamort=false}}
|
|
{{/if}}
|
|
|
|
{{* enregistrer les infos de l'immobilisation *}}
|
|
{{:assign key=""|uuid}}
|
|
{{:save
|
|
key=$key
|
|
validate_schema="schema.json"
|
|
type="immo"
|
|
line=$immo_id
|
|
duration=$duration
|
|
date=$date_debut
|
|
noamort=$noamort
|
|
}}
|
|
|
|
{{if $_POST.no_amort}}
|
|
{{:assign amort=0}}
|
|
{{else}}
|
|
{{:assign amort=1}}
|
|
{{/if}}
|
|
{{:redirect force="index.html?ok=1&msg=infos&amort=%s"|args:$amort}}
|
|
{{else}}
|
|
{{:form_errors}}
|
|
{{/form}}
|
|
|
|
{{* renseigner la date de mise en service et durée d'amortissement *}}
|
|
{{if $_GET.amort == 0}}
|
|
{{:assign checked=1}}
|
|
{{:assign disabled=1}}
|
|
{{else}}
|
|
{{:assign checked=0}}
|
|
{{:assign disabled=0}}
|
|
{{/if}}
|
|
<form method="post" action="">
|
|
<fieldset id="infos_immo">
|
|
<legend></legend>
|
|
<dl>
|
|
{{:input id="no_amort" type="checkbox" value=1 name="no_amort" label="Ne pas amortir" default=$checked help="Cocher pour ne pas amortir" onclick="toggleInputs('infos_immo','f_no_amort_1')"}}
|
|
{{:input type="date" name="date_mes" label="Date de mise en service" disabled=$disabled help="à renseigner uniquement si différente de la date d'acquisition"}}
|
|
{{:input type="number" name="duree" label="Durée d'amortissement" required=true min=1 default=1 disabled=$disabled}}
|
|
</dl>
|
|
</fieldset>
|
|
|
|
<p class="submit">
|
|
{{:button type="submit" name="add" label="Ajouter" shape="right" class="main"}}
|
|
</p>
|
|
|
|
</form>
|
|
|
|
{{* activer/désactiver les champs de saisie *}}
|
|
<script type="text/javascript">
|
|
function toggleInputs(idfs, idcb) {
|
|
const noamort = document.getElementById(idcb);
|
|
const fs = document.getElementById(idfs);
|
|
for (let field of fs.querySelectorAll("input")) {
|
|
if (field == noamort) { continue }
|
|
if (noamort.checked) {
|
|
field.setAttribute("disabled","disabled");
|
|
}
|
|
else {
|
|
field.removeAttribute("disabled");
|
|
}
|
|
}
|
|
}
|
|
</script>
|
|
|
|
{{:admin_footer}}
|