135 lines
3.9 KiB
HTML
135 lines
3.9 KiB
HTML
{{* -*- brindille -*- *}}
|
|
|
|
{{*
|
|
@param immo_id
|
|
@param amort = 1 si immo amortissable, 0 si non
|
|
@param op = new ou modif
|
|
@param type_immo : encours, archive, fini, autre
|
|
*}}
|
|
|
|
{{if $_GET.op == "modif"}}
|
|
{{#load type="immo" assign="info_immo" where="$$.line = :line_id" :line_id=$_GET.immo_id|intval}}
|
|
{{/load}}
|
|
{{/if}}
|
|
|
|
{{* Traiter l'envoi du formulaire *}}
|
|
{{#form on="save"}}
|
|
|
|
{{* chercher la date d'acquisition de l'immobilisation *}}
|
|
{{#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 = $_GET.immo_id
|
|
assign=ligne_immo
|
|
}}
|
|
{{/select}}
|
|
|
|
{{if ! $_POST.amortir}}
|
|
{{* ne pas amortir *}}
|
|
{{:assign duration=0}}
|
|
{{:assign date_debut=$ligne_immo.date_achat|parse_date}}
|
|
{{:assign status="ignored"}}
|
|
{{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 status="managed"}}
|
|
{{/if}}
|
|
|
|
{{* enregistrer les infos de l'immobilisation *}}
|
|
{{if $_GET.op == "new"}}
|
|
{{:assign key=""|uuid}}
|
|
{{else}}
|
|
{{:assign key=$info_immo.key}}
|
|
{{/if}}
|
|
{{:save
|
|
key=$key
|
|
validate_schema="schema.json"
|
|
type="immo"
|
|
line=$_GET.immo_id|intval
|
|
duration=$duration
|
|
date=$date_debut
|
|
status=$status
|
|
}}
|
|
|
|
{{if ! $_POST.amortir}}
|
|
{{:assign type_immo="autres"}}
|
|
{{else}}
|
|
{{:assign type_immo=$_GET.type_immo}}
|
|
{{/if}}
|
|
{{:redirect force="index.html?ok=1&msg=infos&type_immo=%s"|args:$type_immo}}
|
|
{{else}}
|
|
{{:form_errors}}
|
|
{{/form}}
|
|
|
|
{{: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}}
|
|
|
|
{{* renseigner ou modifier la date de mise en service et la durée d'amortissement *}}
|
|
{{if $_GET.amort == 0}}
|
|
{{:assign checked=0}}
|
|
{{:assign disabled=1}}
|
|
{{else}}
|
|
{{:assign checked=1}}
|
|
{{:assign disabled=0}}
|
|
{{/if}}
|
|
|
|
<form method="post" action="">
|
|
<fieldset id="infos_immo">
|
|
<legend></legend>
|
|
<dl>
|
|
{{if $checked}}
|
|
{{:assign helptext = "Dé-cocher pour ne pas amortir"}}
|
|
{{else}}
|
|
{{:assign helptext = "Cocher pour amortir"}}
|
|
{{/if}}
|
|
{{:input id="amortir" type="checkbox" value=1 name="amortir" label="Amortir" default=$checked help=$helptext onclick="toggleInputs('infos_immo','f_amortir_1')"}}
|
|
{{if $info_immo != null}}
|
|
{{:assign date_defaut=$info_immo.date}}
|
|
{{:assign duree_defaut=$info_immo.duration}}
|
|
{{else}}
|
|
{{:assign duree_defaut=1}}
|
|
{{/if}}
|
|
{{:input type="number" name="duree" label="Durée d'amortissement" default=$duree_defaut required=true min=1 disabled=$disabled}}
|
|
{{:input type="date" name="date_mes" label="Date de mise en service" default=$date_defaut disabled=$disabled help="à renseigner uniquement si différente de la date d'acquisition"}}
|
|
</dl>
|
|
</fieldset>
|
|
|
|
<p class="submit">
|
|
{{:button type="submit" name="save" label="Enregistrer" shape="right" class="main"}}
|
|
</p>
|
|
|
|
</form>
|
|
|
|
{{* activer/désactiver les champs de saisie *}}
|
|
<script type="text/javascript">
|
|
function toggleInputs(idfs, idcb) {
|
|
const amortir = document.getElementById(idcb);
|
|
const fs = document.getElementById(idfs);
|
|
for (let field of fs.querySelectorAll("input")) {
|
|
if (field == amortir) { continue }
|
|
if (! amortir.checked) {
|
|
field.setAttribute("disabled","disabled");
|
|
}
|
|
else {
|
|
field.removeAttribute("disabled");
|
|
}
|
|
}
|
|
}
|
|
</script>
|
|
|
|
{{:admin_footer}}
|