Séparation immobilisations amortissables ou pas

This commit is contained in:
Jean-Christophe Engel 2024-12-23 12:03:00 +01:00
parent 66859c550e
commit d599d49e1a
7 changed files with 264 additions and 126 deletions

View File

@ -6,9 +6,13 @@
{{if $current == 'index'}}
<ul class="sub">
{{if $subcurrent == 'amortization'}}
<li {{if $subcurrent == 'amort'}}class="current"{{/if}}><a href="index.html?amort=1">Amortissables</a></li>
<li {{if $subcurrent == 'no_amort'}}class="current"{{/if}}><a href="index.html?amort=0">Non amortissables</a></li>
</ul>
{{if $subsubcurrent == 'amortization'}}
<ul class="sub">
<li class="current"><a>Amortissements</a></li>
{{/if}}
</ul>
{{/if}}
{{/if}}
</nav>

View File

@ -9,7 +9,8 @@
{{* Traiter l'envoi du formulaire *}}
{{#form on="add"}}
{{* chercher la date d'achat de l'immobilisation *}}
{{* chercher la date d'acquisition de l'immobilisation *}}
{{:assign var="immo_id" value=$_GET.immo_id|intval}}
{{#select
trans.date as date_achat
@ -21,6 +22,12 @@
}}
{{/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}}
@ -28,28 +35,42 @@
{{: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 key=""|uuid}}
{{:assign duration=$_POST.duree|intval}}
{{: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=$_POST.duree|intval
duration=$duration
date=$date_debut
noamort=$noamort
}}
{{:redirect force="index.html?ok=1&msg=durée"}}
{{:redirect force="index.html?ok=1&msg=infos"}}
{{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 class="ajout_duree">
<legend>Renseigner informations amortissement</legend>
<fieldset id="infos_immo">
<legend></legend>
<dl>
{{: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="number" name="duree" label="Durée d'amortissement" required=true default=1}}
{{: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 default=1 disabled=$disabled}}
</dl>
</fieldset>
@ -59,5 +80,22 @@
</form>
{{:form_errors}}
{{* activer/désactiver les champs de saisie *}}
<script type="text/javascript">
function toggleInputs(idfs, idcb) {
console.log("cb=" + 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}}

View File

@ -3,7 +3,7 @@
{{:admin_header title="Liste des amortissements" custom_css="./style.css" current="module_amortissement"}}
{{* barre de navigation *}}
{{:include file="_nav.html" current="index" subcurrent="amortization"}}
{{:include file="_nav.html" current="index" subcurrent="immobilisation" subsubcurrent="amortization"}}
{{if $_GET.ok}}
{{if $_GET.msg|match:"attach"}}

114
immobilisations.html Normal file
View File

@ -0,0 +1,114 @@
{{* -*- brindille -*- *}}
{{* Liste des immobilisations amortissable ou à définir *}}
<section class="immobilisation">
<h2 class="ruler">Liste des immobilisations</h2>
<table class="list">
<thead>
<tr>
<th></th>
<th>Date</th>
<th>Libellé</th>
<th>Montant</th>
<th>Durée</th>
<th>N° compte</th>
<th>Compte</th>
<th>Projet</th>
<th class="actions"></th>
</tr>
</thead>
<tbody>
{{* lister les immobilisations *}}
{{:read file="./defaut.json" assign="config_json"}}
{{:assign config_defaut=$config_json|json_decode}}
{{:assign var="prefix_array" value=$config_defaut.prefixes|keys}}
{{:assign quote="'"}}
{{:assign condition="("}}
{{#foreach from=$prefix_array item="code"}}
{{:assign condition=$condition|cat:" account.code LIKE "|cat:$quote|cat:$code|cat:"%"|cat:$quote|cat:" OR "}}
{{/foreach}}
{{:assign condition=$condition|cat:"0)"}}
{{#select
trans.id as trans_id,
trans.label as trans_label,
trans.date as trans_date,
line.id as immo_id,
account.id as account_id,
account.code as account_code,
account.label as account_label,
line.debit AS debit,
project.label as project_label,
trans.id_year as trans_id_year
FROM acc_transactions AS trans
INNER JOIN acc_transactions_lines AS line ON line.id_transaction = trans.id
INNER JOIN acc_accounts AS account ON line.id_account = account.id
INNER JOIN acc_years AS years ON trans.id_year = years.id
LEFT JOIN acc_projects AS project ON line.id_project = project.id
WHERE !condition
ORDER BY trans.date DESC;
!condition=$condition
}}
{{:assign trans_url="%s/acc/transactions/details.php?id=%s"|args:$admin_url:$trans_id}}
{{:assign compte_url="%s/acc/accounts/journal.php?id=%s&year=%s"|args:$admin_url:$account_id:$trans_id_year}}
{{:assign duration=null}}
{{#load type="immo" where="$$.line = :line_id" :line_id=$immo_id|intval}}
{{:assign duration=$duration}}
{{if $noamort}}
{{:assign amortissable="non"}}
{{else}}
{{:assign amortissable="oui"}}
{{/if}}
{{else}}
{{:assign amortissable="nsp"}}
{{/load}}
{{if $amortissable == "non"}}
{{:continue}}
{{/if}}
<tr>
<td class="num"><a href={{$trans_url}}>#{{$trans_id}}</a></td>
<td>{{$trans_date|date_short}}</td>
<td>{{$trans_label}}</td>
<td class="money">{{"%f"|math:$debit|money}}</td>
<td class="num">{{if $duration != null}}{{$duration}}{{/if}}</td>
<td><a href={{$compte_url}}>{{$account_code}}</a></td>
<td>{{$account_label}}</td>
<td>{{$project_label}}</td>
<td class="actions">
{{if $duration == null}}
{{:linkbutton
label="Ajouter infos"
href="add_duration.html?immo_id=%s&amort=1"|args:$immo_id
shape="help"
target="_dialog"
}}
{{else}}
{{:linkbutton
label="Amortissements"
href="amortization.html?immo_id=%s"|args:$immo_id
shape="table"
}}
{{/if}}
</td>
</tr>
{{/select}}
</tbody>
</table>
</section>
<form method="post" action="">
<fieldset>
<legend>Ajouter une immobilisation</legend>
<p class="submit">
{{:linkbutton
label="Ajouter une immobilisation"
shape="plus"
href="add_asset.html"
target="_dialog"
}}
</p>
</fieldset>
</form>

71
immobilisations_non.html Normal file
View File

@ -0,0 +1,71 @@
{{* -*- brindille -*- *}}
{{* Liste des immobilisations non amortissable *}}
<section class="immobilisation">
<h2 class="ruler">Immobilisations non amortissables</h2>
<table class="list">
<thead>
<tr>
<th></th>
<th>Date</th>
<th>Libellé</th>
<th>Montant</th>
<th>N° compte</th>
<th>Compte</th>
<th>Projet</th>
<th class="actions"></th>
</tr>
</thead>
<tbody>
{{#load type="immo" where="$$.noamort = true"}}
{{:assign var="lines." value="'%s'"|args:$line}}
{{/load}}
{{:assign lines=$lines|implode:","}}
{{:assign lines="("|cat:$lines|cat:")"}}
{{:assign condition="line.id IN %s"|args:$lines}}
{{#select
trans.id as trans_id,
trans.label as trans_label,
trans.date as trans_date,
line.id as immo_id,
account.id as account_id,
account.code as account_code,
account.label as account_label,
line.debit AS debit,
project.label as project_label,
trans.id_year as trans_id_year
FROM acc_transactions AS trans
INNER JOIN acc_transactions_lines AS line ON line.id_transaction = trans.id
INNER JOIN acc_accounts AS account ON line.id_account = account.id
INNER JOIN acc_years AS years ON trans.id_year = years.id
LEFT JOIN acc_projects AS project ON line.id_project = project.id
WHERE !condition
ORDER BY trans.date DESC;
!condition=$condition
}}
{{:assign trans_url="%s/acc/transactions/details.php?id=%s"|args:$admin_url:$trans_id}}
{{:assign compte_url="%s/acc/accounts/journal.php?id=%s&year=%s"|args:$admin_url:$account_id:$trans_id_year}}
<tr>
<td class="num"><a href={{$trans_url}}>#{{$trans_id}}</a></td>
<td>{{$trans_date|date_short}}</td>
<td>{{$trans_label}}</td>
<td class="money">{{"%f"|math:$debit|money}}</td>
<td><a href={{$compte_url}}>{{$account_code}}</a></td>
<td>{{$account_label}}</td>
<td>{{$project_label}}</td>
<td class="actions">
{{:linkbutton
label="Ajouter infos"
href="add_duration.html?immo_id=%s&amort=0"|args:$immo_id
shape="help"
target="_dialog"
}}
</td>
</tr>
{{/select}}
</tbody>
</table>
</section>

View File

@ -2,13 +2,19 @@
{{:admin_header title="Gestion des amortissements" custom_css=$custom_css current="module_amortissement"}}
{{* barre de navigation *}}
{{:include file="_nav.html" current="index"}}
{{if $_GET.amort == null || $_GET.amort}}
{{:assign amort="amort"}}
{{else}}
{{:assign amort="no_amort"}}
{{/if}}
{{:include file="_nav.html" current="index" subcurrent="%s"|args:$amort}}
{{if $_GET.ok}}
{{if $_GET.msg|match:"immobilisation"}}
{{:assign msg="Immobilisation enregistrée"}}
{{elseif $_GET.msg|match:"durée"}}
{{:assign msg="Durée enregistrée"}}
{{elseif $_GET.msg|match:"infos"}}
{{:assign msg="Informations enregistrées"}}
{{/if}}
<p class="block confirm">{{$msg}}</p>
{{elseif $_GET.err}}
@ -29,107 +35,9 @@
{{/select}}
{{/load}}
<section class="immobilisation">
<h2 class="ruler">Liste des immobilisations</h2>
<table class="list">
<thead>
<tr>
<th></th>
<th>Date</th>
<th>Libellé</th>
<th>Montant</th>
<th>Durée</th>
<th>N° compte</th>
<th>Compte</th>
<th>Projet</th>
<th class="actions"></th>
</tr>
</thead>
<tbody>
{{* lister les immobilisations *}}
{{:read file="./defaut.json" assign="config_json"}}
{{:assign config_defaut=$config_json|json_decode}}
{{:assign var="prefix_array" value=$config_defaut.prefixes|keys}}
{{:assign quote="'"}}
{{:assign condition="("}}
{{#foreach from=$prefix_array item="code"}}
{{:assign condition=$condition|cat:" account.code LIKE "|cat:$quote|cat:$code|cat:"%"|cat:$quote|cat:" OR "}}
{{/foreach}}
{{:assign condition=$condition|cat:"0)"}}
{{#select
trans.id as trans_id,
trans.label as trans_label,
trans.date as trans_date,
line.id as immo_id,
account.id as account_id,
account.code as account_code,
account.label as account_label,
line.debit AS debit,
project.label as project_label,
trans.id_year as trans_id_year
FROM acc_transactions AS trans
INNER JOIN acc_transactions_lines AS line ON line.id_transaction = trans.id
INNER JOIN acc_accounts AS account ON line.id_account = account.id
INNER JOIN acc_years AS years ON trans.id_year = years.id
LEFT JOIN acc_projects AS project ON line.id_project = project.id
WHERE !condition
ORDER BY trans.date DESC;
!condition=$condition
}}
{{:assign trans_url="%s/acc/transactions/details.php?id=%s"|args:$admin_url:$trans_id}}
{{:assign compte_url="%s/acc/accounts/journal.php?id=%s&year=%s"|args:$admin_url:$account_id:$trans_id_year}}
{{#load type="immo" where="$$.line = :line_id" :line_id=$immo_id|intval}}
{{:assign duration=$duration}}
{{if $amort == "amort"}}
{{:include file="./immobilisations.html"}}
{{else}}
{{:assign duration=null}}
{{/load}}
<tr>
<td class="num"><a href={{$trans_url}}>#{{$trans_id}}</a></td>
<td>{{$trans_date|date_short}}</td>
<td>{{$trans_label}}</td>
<td class="money">{{"%f"|math:$debit|money}}</td>
<td class="num">{{if $duration != null}}{{$duration}}{{/if}}</td>
<td><a href={{$compte_url}}>{{$account_code}}</a></td>
<td>{{$account_label}}</td>
<td>{{$project_label}}</td>
<td class="actions">
{{if $duration == null}}
{{:linkbutton
label="Ajouter infos"
href="add_duration.html?immo_id=%s"|args:$immo_id
shape="help"
target="_dialog"
}}
{{else}}
{{:linkbutton
label="Amortissements"
href="amortization.html?immo_id=%s"|args:$immo_id
shape="table"
}}
{{:include file="./immobilisations_non.html"}}
{{/if}}
</td>
</tr>
{{/select}}
</tbody>
</table>
</section>
<form method="post" action="">
<fieldset>
<legend>Ajouter une immobilisation</legend>
<p class="submit">
{{:linkbutton
label="Ajouter une immobilisation"
shape="plus"
href="add_asset.html"
target="_dialog"
}}
</p>
</fieldset>
</form>
{{:admin_footer}}

View File

@ -18,6 +18,9 @@
"description" : "date de mise en service de l'immobilisation",
"type" : ["string", "null"],
"format" : "date"
},
"noamort" : {
"type" : ["null", "boolean"]
}
},
"required": ["type", "line", "duration", "date"]