Compare commits
102 Commits
Author | SHA1 | Date | |
---|---|---|---|
95bfdf27b4 | |||
609563f0ba | |||
830b0e7885 | |||
2e51d768d3 | |||
0c4f39b21a | |||
3fc96927a5 | |||
dec6c8d676 | |||
1aa1e65b61 | |||
9f8660a51f | |||
673003ea77 | |||
b587121d3f | |||
f533118360 | |||
99aa29a4a1 | |||
515eb443fa | |||
90af8a0790 | |||
839739b992 | |||
5b8c869ba4 | |||
ea8d805dba | |||
d669b5c95b | |||
1637f6eafd | |||
0f1f3ed56d | |||
91b75e77d4 | |||
f509cd42c9 | |||
8b87ce74cf | |||
b6ced673dc | |||
31a0371ae2 | |||
9ac427415a | |||
fb0d34a4f4 | |||
2c11d3e4f3 | |||
17d132ffa2 | |||
f17ccd1bc8 | |||
4b63ad4560 | |||
2aa64cc525 | |||
022e324bea | |||
5ab7d628a8 | |||
ad4b76695d | |||
f1bea6bda2 | |||
1e2ba133f5 | |||
993ded84d3 | |||
a604a86a3f | |||
9e79eb7f42 | |||
03488b0ab9 | |||
5fcf510b25 | |||
3ef33e15e3 | |||
c943c9d3e6 | |||
0160fef1c2 | |||
6e06d4f24f | |||
3738ea0721 | |||
a1bf1c485c | |||
b1a78a3047 | |||
f76c243b8c | |||
11be1386c2 | |||
4f1be445ff | |||
9d2c30f0eb | |||
516021031d | |||
d599d49e1a | |||
66859c550e | |||
eb533ba381 | |||
ddbea77660 | |||
33ad15dbfc | |||
92622fb9a0 | |||
0e2625e9a2 | |||
b17a14526e | |||
10f2128b1b | |||
59e6abe581 | |||
d2f924a81e | |||
ec1922e5dd | |||
0e3a9669ec | |||
00071437ef | |||
318bbce353 | |||
46f203a89c | |||
e00b9b0a7e | |||
2fc7e5e902 | |||
01ea1ad3dd | |||
105080c111 | |||
d189f6d4c4 | |||
061a27d40d | |||
b91c1087ae | |||
48504bcb1d | |||
7d829bbf9c | |||
77aac6fd4a | |||
db26c7b2d6 | |||
cc7ea1b54c | |||
885f737233 | |||
b45e53f5ea | |||
f3c2d2c884 | |||
5d1666b1f1 | |||
6cbc624146 | |||
486fc54569 | |||
e8f5ad7e0f | |||
a30613e0ee | |||
8a4b605e99 | |||
628887fd97 | |||
6f620e2d24 | |||
3515c32e0c | |||
7e6eb4ea12 | |||
406408d47e | |||
f682d37b1c | |||
ce71b27188 | |||
5e8026e09b | |||
5e081c4f23 | |||
f35ca35538 |
20
README.md
Normal file
20
README.md
Normal file
@ -0,0 +1,20 @@
|
||||
# Module de gestion d'amortissements pour Paheko
|
||||
|
||||
## Ce dépôt n'est plus mis à jour ; nouvel emplacement https://gitea.zaclys.com/lesanges/amortization
|
||||
|
||||
Ce module permet de gérer les écritures d'amortissements pour les immobilisations :
|
||||
|
||||
- lister les immobilisations
|
||||
- ajouter une nouvelle immobilisation
|
||||
- lister les amortissements d'une immobilisation :
|
||||
- amortissements déjà enregistrés
|
||||
- amortissements à venir
|
||||
- associer une écriture d'amortissement à une immobilisation
|
||||
- enregistrer un nouvel amortissement
|
||||
|
||||
## Installation
|
||||
- télécharger [l'archive zip](https://link.infini.fr/amortissement)
|
||||
- cliquer « Configuration » puis « Extensions »
|
||||
- en bas de la page, cliquer « Importer un module »
|
||||
- sélectionner l'archive téléchargée ci-dessus
|
||||
- activer le module qui est maintenant présent dans la liste des extensions inactives
|
@ -1,3 +1,4 @@
|
||||
{{* -*- brindille -*- *}}
|
||||
{{*
|
||||
Calcule le nombre de jours entre deux dates
|
||||
paramètres :
|
||||
@ -5,23 +6,7 @@
|
||||
- date_fin
|
||||
résultat : nbjours
|
||||
*}}
|
||||
{{* pour simplifier : 30 jours par mois et 360 jours par an *}}
|
||||
|
||||
{{:assign jour_debut=$date_debut|date:"d"}}
|
||||
{{:assign jour_debut="min(%d, 30)"|math:$jour_debut}}
|
||||
{{:assign mois_debut=$date_debut|date:"m"}}
|
||||
{{:assign annee_debut=$date_debut|date:"Y"}}
|
||||
|
||||
{{:assign jour_fin=$date_fin|date:"d"}}
|
||||
{{:assign jour_fin="min(%d, 30)"|math:$jour_fin}}
|
||||
{{:assign mois_fin=$date_fin|date:"m"}}
|
||||
{{:assign annee_fin=$date_fin|date:"Y"}}
|
||||
|
||||
{{:assign nbjours="%d-%d"|math:$jour_fin:$jour_debut}}
|
||||
{{:assign nbjours="%d+(%d-%d)*30"|math:$nbjours:$mois_fin:$mois_debut}}
|
||||
{{:assign nbjours="%d+(%d-%d)*360"|math:$nbjours:$annee_fin:$annee_debut}}
|
||||
|
||||
{{* au cas où les deux dates seraient inversées ... *}}
|
||||
{{if $nbjours < 0}}
|
||||
{{:assign nbjours="-1*%d"|math:$nbjours}}
|
||||
{{/if}}
|
||||
{{:assign ts_debut=$date_debut|strtotime}}
|
||||
{{:assign ts_fin=$date_fin|strtotime}}
|
||||
{{:assign nbjours="1+abs(%d-%d)/(60*60*24)"|math:$ts_fin:$ts_debut}}
|
||||
|
33
_check_account.html
Normal file
33
_check_account.html
Normal file
@ -0,0 +1,33 @@
|
||||
{{* -*- brindille -*- *}}
|
||||
|
||||
{{*
|
||||
vérifier :
|
||||
- que le compte débute par le préfixe correct
|
||||
- est présent dans le PC indiqué
|
||||
paramètres :
|
||||
- account : tableau avec un identifiant de compte
|
||||
- chart_id : identifiant de plan comptable
|
||||
- prefix_array : tableau des préfixes
|
||||
résultat :
|
||||
- account_ok
|
||||
*}}
|
||||
|
||||
{{:assign condition=" AND ("}}
|
||||
{{#foreach from=$prefix_array item="code"}}
|
||||
{{:assign code=$code|cat:"%"|quote_sql}}
|
||||
{{:assign condition=$condition|cat:" code LIKE "|cat:$code|cat:" OR "}}
|
||||
{{/foreach}}
|
||||
{{:assign condition=$condition|cat:"0)"}}
|
||||
|
||||
{{:assign account_code=$account|keys|key:0}}
|
||||
{{#sql
|
||||
select="code"
|
||||
tables="acc_accounts"
|
||||
where="id_chart = :id_chart %s"|args:$condition
|
||||
:id_chart = $chart_id|intval
|
||||
}}
|
||||
{{if $account_code == $code}}
|
||||
{{:assign account_ok=1}}
|
||||
{{:break}}
|
||||
{{/if}}
|
||||
{{/sql}}
|
19
_check_date.html
Normal file
19
_check_date.html
Normal file
@ -0,0 +1,19 @@
|
||||
{{* -*- brindille -*- *}}
|
||||
|
||||
{{*
|
||||
vérifier que la date est située dans un exercice ouvert
|
||||
paramètres :
|
||||
- date
|
||||
résultat : open_years, selected_year, selected_chart
|
||||
*}}
|
||||
|
||||
{{:assign open_years=""}}
|
||||
{{#years closed=false order="start_date" assign="open_years."}}
|
||||
{{if
|
||||
$start_date|strtotime <= $date|parse_date|strtotime &&
|
||||
$end_date|strtotime >= $date|parse_date|strtotime
|
||||
}}
|
||||
{{:assign selected_year=$id}}
|
||||
{{:assign selected_chart=$id_chart}}
|
||||
{{/if}}
|
||||
{{/years}}
|
14
_get_amort_code.html
Normal file
14
_get_amort_code.html
Normal file
@ -0,0 +1,14 @@
|
||||
{{* -*- brindille -*- *}}
|
||||
|
||||
{{*
|
||||
déterminer le numéro du compte d'amortissement associé à un compte d'immobilisation
|
||||
- param :
|
||||
- code_immo : numéro du compte d'immobilisation
|
||||
- résultat :
|
||||
- code_amort : numéro du compte d'amortissement
|
||||
*}}
|
||||
|
||||
{{:assign code_s=$code_immo|strval}}
|
||||
{{:assign ch1=$code_s|substr:0:1}}
|
||||
{{:assign reste=$code_s|substr:1}}
|
||||
{{:assign code_amort=$ch1|cat:"8"|cat:$reste}}
|
10
_get_codes.html
Normal file
10
_get_codes.html
Normal file
@ -0,0 +1,10 @@
|
||||
{{* -*- brindille -*- *}}
|
||||
|
||||
{{*
|
||||
déterminer le numéro du compte passé en paramètre dans un tableau
|
||||
*}}
|
||||
|
||||
{{:assign label=$account|values|key:0}}
|
||||
{{:assign pos=$label|strpos:" "}}
|
||||
{{:assign account_code=$label|substr:0:$pos}}
|
||||
{{:assign var="account_code.%s"|args:$account_code value=$label}}
|
29
_nav.html
29
_nav.html
@ -1,6 +1,33 @@
|
||||
{{* -*- brindille -*- *}}
|
||||
|
||||
<nav class="tabs">
|
||||
{{if $current == 'index'}}
|
||||
<aside>
|
||||
{{:linkbutton label="Ajouter une immobilisation" shape="plus" href="add_asset.html" target="_dialog"}}
|
||||
</aside>
|
||||
{{/if}}
|
||||
|
||||
<ul>
|
||||
<li {{if $current == 'index'}} class="current"{{/if}}><a href="{{$module.url}}index.html">Immobilisations</a></li>
|
||||
<li {{if $current == 'amortization'}} class="current"{{/if}}><a href="{{$module.url}}/amortization.html">Amortissements</a></li>
|
||||
<li {{if $current == 'aide'}} class="current"{{/if}}><a href="{{$module.url}}aide.html">Aide</a></li>
|
||||
</ul>
|
||||
|
||||
{{if $current == 'index' && $subsubcurrent != 'balance_exit'}}
|
||||
<ul class="sub">
|
||||
<li {{if $subcurrent == 'encours'}}class="current"{{/if}}><a href="index.html?amort=encours">En cours</a></li>
|
||||
<li {{if $subcurrent == 'fini'}}class="current"{{/if}}><a href="index.html?amort=fini">Terminées</a></li>
|
||||
<li {{if $subcurrent == 'archive'}}class="current"{{/if}}><a href="index.html?amort=archive">Archivées</a></li>
|
||||
<li {{if $subcurrent == 'autres'}}class="current"{{/if}}><a href="index.html?amort=autres">Autres</a></li>
|
||||
</ul>
|
||||
{{/if}}
|
||||
|
||||
{{if $subsubcurrent == 'amortization'}}
|
||||
<ul class="sub">
|
||||
<li class="title"><strong>Amortissements</strong></li>
|
||||
</ul>
|
||||
{{elseif $subsubcurrent == 'balance_exit'}}
|
||||
<ul class="sub">
|
||||
<li class="title"><strong>Sortie du bilan</strong></li>
|
||||
</ul>
|
||||
{{/if}}
|
||||
</nav>
|
||||
|
13
_next_year.html
Normal file
13
_next_year.html
Normal file
@ -0,0 +1,13 @@
|
||||
{{* -*- brindille -*- *}}
|
||||
{{*
|
||||
Rend une date située un an après la date paramètre
|
||||
paramètres :
|
||||
- date
|
||||
résultat : date_amort
|
||||
*}}
|
||||
|
||||
{{:assign jour=$date|date:"d"}}
|
||||
{{:assign mois=$date|date:"m"}}
|
||||
{{:assign annee=$date|date:"Y"}}
|
||||
{{:assign annee="%d+1"|math:$annee}}
|
||||
{{:assign date_amort="%s/%s/%s"|args:$jour:$mois:$annee}}
|
21
add_account.html
Normal file
21
add_account.html
Normal file
@ -0,0 +1,21 @@
|
||||
{{* -*- brindille -*- *}}
|
||||
{{:admin_header title="Ajout immobilisation" current="module_amortissement"}}
|
||||
|
||||
{{* barre de navigation *}}
|
||||
{{if ! $dialog}}
|
||||
{{:include file="_nav.html" current="index"}}
|
||||
{{/if}}
|
||||
|
||||
<div class="block error">
|
||||
Le compte « {{$_GET.account}} » n'est pas un compte
|
||||
d'amortissement ou n'est pas dans le plan comptable de l'exercice
|
||||
choisi
|
||||
</div>
|
||||
|
||||
<div>
|
||||
{{:linkbutton
|
||||
label="Créer le compte"
|
||||
shape="plus"
|
||||
href="!acc/charts/accounts/new.php?id=%s"|args:$_GET.chart
|
||||
}}
|
||||
</div>
|
217
add_asset.html
217
add_asset.html
@ -1,98 +1,193 @@
|
||||
{{:admin_header title="Ajout immobilisation" current="module_amortissement"}}
|
||||
{{* -*- brindille -*- *}}
|
||||
|
||||
{{* barre de navigation *}}
|
||||
{{if ! $dialog}}
|
||||
{{:include file="_nav.html" current="index"}}
|
||||
{{/if}}
|
||||
{{:read file="./defaut.json" assign="config_json"}}
|
||||
{{:assign config_defaut=$config_json|json_decode}}
|
||||
{{:assign var="prefix_array" value=$config_defaut.prefixes|keys}}
|
||||
|
||||
{{#years closed=false order="start_date" assign=years.}}
|
||||
{{:assign ts_debut=$start_date|strtotime}}
|
||||
{{:assign ts_fin=$end_date|strtotime}}
|
||||
{{:assign debut=$start_date|date_short}}
|
||||
{{:assign fin=$end_date|date_short}}
|
||||
{{:assign var="years_data.%d"|args:$id value=$ts_debut|cat:" "|cat:$ts_fin}}
|
||||
{{:assign var="open_years.%d"|args:$id value=$label|cat:" (du "|cat:$debut|cat:" au "|cat:$fin|cat:")"}}
|
||||
{{if $ts_debut <= $now && $now <= $ts_fin}}
|
||||
{{:assign selected_year=$id}}
|
||||
{{/if}}
|
||||
{{/years}}
|
||||
|
||||
{{* Traiter l'envoi du formulaire *}}
|
||||
{{#form on="add"}}
|
||||
{{* :debug POST=$_POST *}}
|
||||
{{* vérifier que la date d'achat est située dans un l'exercice sélectionné *}}
|
||||
{{:assign ts_date = $_POST.date_achat|parse_date|strtotime}}
|
||||
{{:assign ok=false}}
|
||||
{{#foreach from=$years}}
|
||||
{{if $id == $_POST.id_year}}
|
||||
{{:assign selected_chart=$id_chart}}
|
||||
{{if $start_date|strtotime <= $ts_date && $ts_date <= $end_date|strtotime}}
|
||||
{{:assign ok=true}}
|
||||
{{:break}}
|
||||
{{/if}}
|
||||
{{/if}}
|
||||
{{/foreach}}
|
||||
{{if ! $ok}}
|
||||
{{:error message="La date saisie n'est pas dans l'exercice choisi !"}}
|
||||
{{/if}}
|
||||
|
||||
{{if ! $_POST.amortir}}
|
||||
{{* ne pas amortir *}}
|
||||
{{:assign duration=0}}
|
||||
{{:assign date_debut=$_POST.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:$_POST.date_achat|parse_date}}
|
||||
{{if $date_debut|strtotime < $_POST.date_achat|parse_date|strtotime}}
|
||||
{{:assign dd=$date_debut|date_short}}
|
||||
{{:assign da=$_POST.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}}
|
||||
{{:assign status="managed"}}
|
||||
{{/if}}
|
||||
|
||||
{{* déterminer le numéro des comptes au cas où la clé serait un identifiant *}}
|
||||
{{:include
|
||||
file="_get_codes.html"
|
||||
account=$_POST.debit_account
|
||||
keep="account_code"
|
||||
}}
|
||||
{{:assign debit_account=$account_code}}
|
||||
{{:include
|
||||
file="_get_codes.html"
|
||||
account=$_POST.credit_account
|
||||
keep="account_code"
|
||||
}}
|
||||
{{:assign credit_account=$account_code}}
|
||||
|
||||
{{* vérifier :
|
||||
- que le compte d'immo débute par un préfixe correct (20, 21, ...)
|
||||
- est présent dans le PC de l'exercice correspondant à la date
|
||||
*}}
|
||||
|
||||
{{:include
|
||||
file="_check_account.html"
|
||||
account=$debit_account
|
||||
chart_id=$selected_chart
|
||||
prefix_array=$prefix_array
|
||||
keep="account_ok"
|
||||
}}
|
||||
|
||||
{{if $account_ok == null}}
|
||||
{{:assign compte=$debit_account|implode:""}}
|
||||
{{:error message="Le compte « %s » n'est pas un compte d'immobilisation ou n'est pas dans le plan comptable de l'exercice choisi"|args:$compte}}
|
||||
{{/if}}
|
||||
|
||||
{{* enregistrer l'écriture *}}
|
||||
{{:assign var="credit_accounts" value=$_POST.credit_account|keys}}
|
||||
{{:assign var="credit_account" value=$credit_accounts.0}}
|
||||
{{:assign var="debit_accounts" value=$_POST.debit_account|keys}}
|
||||
{{:assign var="debit_account" value=$debit_accounts.0}}
|
||||
|
||||
{{* :debug credit_account=$credit_account *}}
|
||||
{{* :debug debit_account=$debit_account *}}
|
||||
|
||||
{{:api
|
||||
method="POST"
|
||||
path="accounting/transaction"
|
||||
assign="result"
|
||||
id_year=$_POST.id_year
|
||||
type="revenue"
|
||||
date=$_POST.date
|
||||
date=$_POST.date_achat
|
||||
label=$_POST.designation
|
||||
amount=$_POST.montant
|
||||
debit=$debit_account
|
||||
credit=$credit_account
|
||||
debit=$debit_account|keys|key:0
|
||||
credit=$credit_account|keys|key:0
|
||||
id_project=$_POST.id_project
|
||||
}}
|
||||
|
||||
{{* :debug result=$result *}}
|
||||
{{* vérifier s'il y a déjà un document avec le même numéro de ligne *}}
|
||||
{{:assign var="immo_id" value=$result.lines.1.id}}
|
||||
{{#load where="$$.line = :line_id" :line_id=$immo_id}}
|
||||
{{:assign key=$key}}
|
||||
{{else}}
|
||||
{{:assign key=""|uuid}}
|
||||
{{/load}}
|
||||
|
||||
{{* enregistrer les infos de l'immobilisation *}}
|
||||
{{* :debug lines=$result.lines *}}
|
||||
{{* :debug line1=$result.lines.1 *}}
|
||||
|
||||
{{:assign var="line_id" value=$result.lines.1.id}}
|
||||
{{* :debug line_id=$line_id *}}
|
||||
|
||||
{{:assign key=""|uuid}}
|
||||
{{:save
|
||||
key=$key
|
||||
validate_schema="schema.json"
|
||||
type="immo"
|
||||
line=$line_id
|
||||
duration=$_POST.duree|intval
|
||||
line=$immo_id
|
||||
duration=$duration
|
||||
date=$date_debut
|
||||
status=$status
|
||||
}}
|
||||
|
||||
{{:redirect to="index.html?ok=1"}}
|
||||
{{/form}}
|
||||
|
||||
{{* Préparer les infos pour le formulaire *}}
|
||||
|
||||
{{:assign var="bank_account.512A" value="512A — Compte courant"}}
|
||||
{{#years closed=false}}
|
||||
{{:assign var="open_years.%d"|args:$id value=$label}}
|
||||
{{if $start_date <= $now && $end_date >= $now}}
|
||||
{{:assign best_year=$id}}
|
||||
{{if $_POST.amortir}}
|
||||
{{:assign amort="encours"}}
|
||||
{{else}}
|
||||
{{:assign amort="autres"}}
|
||||
{{/if}}
|
||||
{{/years}}
|
||||
{{:redirect force="index.html?ok=1&msg=immobilisation&amort=%s"|args:$amort}}
|
||||
{{/form}}
|
||||
|
||||
{{:admin_header title="Ajout immobilisation" current="module_amortissement"}}
|
||||
{{* barre de navigation *}}
|
||||
{{if ! $dialog}}
|
||||
{{:include file="_nav.html" current="index"}}
|
||||
{{/if}}
|
||||
|
||||
{{:form_errors}}
|
||||
|
||||
{{* formulaire d'ajout d'immobilisation *}}
|
||||
|
||||
{{*
|
||||
TODO
|
||||
- ajouter projet et autres rubriques selon besoin
|
||||
*}}
|
||||
{{:assign var="immo_account.2" value="2 — Classe 2 — Comptes d'immobilisations"}}
|
||||
|
||||
{{#select id,label FROM acc_projects WHERE archived = 0;}}
|
||||
{{:assign var="projects.%d"|args:$id value=$label}}
|
||||
{{/select}}
|
||||
|
||||
{{#foreach from=$prefix_array item="code"}}
|
||||
{{:assign var="pattern_array." value="%s*"|args:$code}}
|
||||
{{/foreach}}
|
||||
{{:assign patterns=$pattern_array|implode:"|"}}
|
||||
|
||||
<div id="erreur" class="hidden">
|
||||
<p class="block error">La date choisie n'est dans aucun exercice ouvert !</p>
|
||||
</div>
|
||||
|
||||
<form method="post" action="">
|
||||
<fieldset class="ajout_immo">
|
||||
<legend>Ajouter une immobilisation</legend>
|
||||
<fieldset>
|
||||
<legend>Données de l'immobilisation</legend>
|
||||
<dl>
|
||||
{{:input type="select" default=$best_year name="id_year" label="Exercice" required=true options=$open_years}}
|
||||
{{:input type="date" name="date" label="Date" required=true default=$now|date_short}}
|
||||
{{:input type="select" name="id_year" label="Exercice" required=true default_empty="— Faire un choix —" options=$open_years}}
|
||||
{{:input type="date" name="date_achat" label="Date d'acquisition" required=true default=$now|date_short}}
|
||||
{{:input type="text" name="designation" label="Désignation" required=true}}
|
||||
{{:input type="money" name="montant" label="Montant" required=true}}
|
||||
{{:input type="number" name="duree" label="Durée d'amortissement" required=true default=1}}
|
||||
{{:input
|
||||
type="list"
|
||||
name="credit_account"
|
||||
label="Compte de décaissement"
|
||||
required=true
|
||||
target="!acc/charts/accounts/selector.php?targets=1:2:3&key=code&year=%d"|args:$best_year
|
||||
default=$bank_account
|
||||
target="!acc/charts/accounts/selector.php?types=%s&id_year=%d"|args:"1|2|3":$selected_year
|
||||
}}
|
||||
{{:input
|
||||
type="list"
|
||||
name="debit_account"
|
||||
label="Compte d'immobilisation (20xx ou 21xx)"
|
||||
label="Compte d'immobilisation (20xx, 21xx, ...)"
|
||||
required=true
|
||||
target="!acc/charts/accounts/selector.php?key=code&year=%d"|args:$best_year
|
||||
target="!acc/charts/accounts/selector.php?codes=%s&id_year=%d"|args:$patterns:$selected_year
|
||||
default=$immo_account
|
||||
}}
|
||||
{{if $projects != null}}
|
||||
{{:input type="select" name="id_project" label="Projet (analytique)" options=$projects default_empty="— Aucun —"}}
|
||||
{{/if}}
|
||||
<div id="donnees" class="hidden">
|
||||
{{:input type="select" name="years_data" options=$years_data}}
|
||||
</div>
|
||||
</dl>
|
||||
</fieldset>
|
||||
<fieldset>
|
||||
<legend>Amortissement</legend>
|
||||
<dl>
|
||||
{{:input id="amortir" type="checkbox" value=1 name="amortir" label="Amortir cette immobilisation sur plusieurs années" checked="cheched" help="Dé-cocher pour ne pas amortir"}}
|
||||
<div id="div_amort">
|
||||
{{:input type="date" name="date_mes" label="Date de mise en service" help="C'est la date de première utilisation ; à renseigner uniquement si différente de la date d'acquisition"}}
|
||||
{{:input type="number" name="duree" label="Durée d'amortissement" required=true min=0 default=1 suffix="année(s)"}}
|
||||
</div>
|
||||
</dl>
|
||||
</fieldset>
|
||||
|
||||
@ -101,5 +196,21 @@
|
||||
</p>
|
||||
|
||||
</form>
|
||||
|
||||
{{:admin_footer}}
|
||||
|
||||
<script type="text/javascript" src="scripts.js"></script>
|
||||
<script type="text/javascript">
|
||||
|
||||
function changeYear(evt, f_accounts = ['credit_account', 'debit_account'], f_years_select = 'f_id_year') {
|
||||
setSelectorYear(f_accounts, f_years_select);
|
||||
}
|
||||
|
||||
function changeVisibility(evt, idcheck = 'f_amortir_1', fields = ['div_amort']) {
|
||||
toggleVisibility(idcheck, fields);
|
||||
}
|
||||
|
||||
(function () {
|
||||
document.getElementById('f_id_year').onchange = changeYear;
|
||||
document.getElementById('f_amortir_1').onclick = changeVisibility;
|
||||
})();
|
||||
</script>
|
||||
|
108
add_infos.html
Normal file
108
add_infos.html
Normal file
@ -0,0 +1,108 @@
|
||||
{{* -*- 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 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 *}}
|
||||
{{:assign key=""|uuid}}
|
||||
{{:save
|
||||
key=$key
|
||||
validate_schema="schema.json"
|
||||
type="immo"
|
||||
line=$immo_id
|
||||
duration=$duration
|
||||
date=$date_debut
|
||||
status=$status
|
||||
}}
|
||||
|
||||
{{if $_POST.no_amort}}
|
||||
{{:assign amort="autres"}}
|
||||
{{else}}
|
||||
{{:assign amort="encours"}}
|
||||
{{/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}}
|
155
aide.html
Normal file
155
aide.html
Normal file
@ -0,0 +1,155 @@
|
||||
{{* -*- brindille -*- *}}
|
||||
|
||||
{{:admin_header title="Aide" custom_css="./style.css" current="module_amortissement"}}
|
||||
|
||||
{{* barre de navigation *}}
|
||||
{{:include file="_nav.html" current="aide"}}
|
||||
|
||||
<p class="aide">
|
||||
Ce module gère l'amortissement linéaire des immobilisations.
|
||||
</p>
|
||||
|
||||
<h2 class="aide">Immobilisations</h2>
|
||||
Elles sont classées dans 3 onglets :
|
||||
|
||||
<h3 class="aide">Amortissables</h3>
|
||||
|
||||
On y trouve les immobilisations en cours et celles pour lesquelles le
|
||||
module n'a pas d'information.
|
||||
|
||||
<p class="aide">
|
||||
Dans le deuxième cas, il faut cliquer sur le bouton « Ajouter
|
||||
infos » puis :
|
||||
<ul class="aide">
|
||||
<li>soit indiquer que l'immobilisation ne doit pas être amortie</li>
|
||||
<li>soit fournir la date de mise en service du bien (si différente de la date d'acquisition) ainsi
|
||||
que la durée en années de l'amortissement</li>
|
||||
</ul>
|
||||
</p>
|
||||
<p class="aide">
|
||||
Tant qu'une immobilisation ne possède pas d'amortissement, il est
|
||||
possible de modifier ses informations à l'aide du bouton «
|
||||
Modifier infos ».
|
||||
</p>
|
||||
|
||||
<h3 class="aide">Terminées</h3>
|
||||
|
||||
On y trouve les immobilisations dont l'amortissement est terminé
|
||||
|
||||
<h3 class="aide">Non amortissables</h3>
|
||||
|
||||
<h3 class="aide">Ajouter une immobilisation</h3>
|
||||
|
||||
<div class="aide">
|
||||
<p class="aide">
|
||||
On peut indiquer qu'il s'agit d'une immobilisation qui ne doit pas être amortie ; dans le cas contraire, il faut renseigner les différents paramètres de l'immobilisation :
|
||||
</p>
|
||||
<ul class="aide">
|
||||
<li>Date d'acquisition du bien</li>
|
||||
<li>Date de mise en service du bien : uniquement si différente de la précédente</li>
|
||||
<li>Désignation : c'est le libellé de l'immobilisation</li>
|
||||
<li>Montant</li>
|
||||
<li>Durée d'amortissement en années</li>
|
||||
<li>Compte de décaissement : à choisir dans la liste</li>
|
||||
<li>Compte d'immobilisation : doit débuter par <b>20</b>, <b>21</b> ou <b>27</b></li>
|
||||
<li>Projet analytique (optionnel)</li>
|
||||
</ul>
|
||||
<p>
|
||||
Après ajout, on se retrouve sur la page d'accueil des immobilisations.
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<h2 class="aide">Amortissements</h2>
|
||||
|
||||
<div class="infos">
|
||||
<p class="aide">
|
||||
Le calcul de l'amortissement se fait par la <em>méthode linéaire</em>.
|
||||
</p>
|
||||
<p class="aide">
|
||||
La date de début du calcul est par défaut la <em>date d'achat</em> ; si la
|
||||
date de mise en service est <em>postérieure</em> à la date d'achat, c'est
|
||||
celle-ci qui est prise en compte.
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<h3 class="aide">Liste des amortissements</h3>
|
||||
|
||||
<div class="aide">
|
||||
On trouve ici de une à trois listes, selon la situation :
|
||||
<ul class="aide">
|
||||
<li>
|
||||
<b>Écritures d'amortissement liées à l'immobilisation courante</b>
|
||||
<p>
|
||||
Ce sont des écritures d'amortissement déjà
|
||||
enregistrées et liées à l'écriture de
|
||||
l'immobilisation courante.
|
||||
</p>
|
||||
</li>
|
||||
<li>
|
||||
<b>Écritures d'amortissements à enregistrer</b>
|
||||
<p>
|
||||
Ce sont les écritures amortissement de
|
||||
l'immobilisation courante qui n'ont pas encore été
|
||||
enregistrées ; seules les amortissements d'un
|
||||
exercice ouvert peuvent être enregistrés ; les
|
||||
autres sont présents pour information et pourront
|
||||
être enregistrés quand l'exercice correspondant
|
||||
aura été ouvert.
|
||||
</p>
|
||||
</li>
|
||||
<li>
|
||||
<b>Écritures d'amortissement qui ne sont associées à aucune immobilisation</b>
|
||||
<p>
|
||||
Ce sont des écritures passées sur un compte
|
||||
d'amortissement (<b>28xx</b>) ; en cliquant le
|
||||
bouton « Attacher », on peut rattacher l'écriture
|
||||
d'amortissement sélectionnée à l'immobilisation
|
||||
courante.
|
||||
</p>
|
||||
<p>
|
||||
Si on a rattaché par erreur une écriture
|
||||
d'amortissement à une immobilisation, le bouton «
|
||||
Détacher » en face de l'écriture permettra de
|
||||
défaire l'opération.
|
||||
</p>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<h3 class="aide">Créer une écriture d'amortissement</h3>
|
||||
|
||||
<div class="aide">
|
||||
<p class=aide">
|
||||
Il faut renseigner les différents paramètres de l'amortissement :
|
||||
<ul class="aide">
|
||||
<li>Date ; par défaut, il s'agit de la date de fin d'exercice</li>
|
||||
<li>Désignation : déterminée à partir du libellé de l'immobilisation< ; elle peut être modifiée/li>
|
||||
<li>Montant : sa valeur est calculée par le module ; elle peut être modifiée</li>
|
||||
<li>
|
||||
Compte de débit : à choisir dans la liste ; par défaut c'est le compte <em>6811 : Dotation aux amortissements des immobilisations</em>
|
||||
</li>
|
||||
<li>
|
||||
Compte d'amortissement : à choisir dans la liste ; par défaut c'est le compte formé en intercalant un 8 après le 2 initial du compte d'immobilisation (exemple : 2183 => 28183)
|
||||
</li>
|
||||
</ul>
|
||||
<p class="aide">
|
||||
Après enregistrement, on se retrouve sur la page des amortissements
|
||||
</p>
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<h2 class="aide">Remarques</h2>
|
||||
|
||||
<ul class="aide">
|
||||
<li>
|
||||
Les écritures d'immobilisation et d'amortissement créées en
|
||||
dehors du module ne peuvent être associées automatiquement que
|
||||
si leurs écritures ont été liées ; dans le cas contraire, il
|
||||
faudra renseigner manuellement les infos de l'immobilisation.
|
||||
</li>
|
||||
<li>
|
||||
Les écritures d'immobilisation de la balance d'ouverture ne
|
||||
peuvent être détectées automatiquement : il faudra indiquer
|
||||
manuellement qu'elles ne doivent pas être amorties.
|
||||
</li>
|
||||
</ul>
|
@ -1,189 +1,238 @@
|
||||
{{:admin_header title="Gestion des amortissements" custom_css=$custom_css current="module_amortissement"}}
|
||||
|
||||
{{* barre de navigation *}}
|
||||
{{:include file="_nav.html" current="amortization"}}
|
||||
{{* -*- brindille -*- *}}
|
||||
|
||||
{{* récupérer les infos de l'immobilisation *}}
|
||||
{{#load type="immo" assign="info_immo" where="$$.line = :line_id" :line_id=$_GET.line|intval}}
|
||||
{{#select
|
||||
line.id as immo_id,
|
||||
line.debit as montant,
|
||||
trans.id as trans_id,
|
||||
trans.label as label,
|
||||
trans.date
|
||||
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|intval
|
||||
assign=ligne_immo
|
||||
}}
|
||||
{{else}}
|
||||
{{:assign message="Immobilisation %s non trouvée"|args:$_GET.line}}
|
||||
{{:error message=$message}}
|
||||
{{:error message="Immobilisation %s non trouvée"|args:$_GET.immo_id}}
|
||||
{{/select}}
|
||||
{{:assign date_debut=$ligne_immo.date}}
|
||||
{{:assign solde=$ligne_immo.montant}}
|
||||
|
||||
{{#load type="immo" where="$$.line = :line_id" :line_id=$_GET.immo_id|intval}}
|
||||
{{:assign duree=$duration}}
|
||||
{{:assign date_debut=$date}}
|
||||
{{/load}}
|
||||
|
||||
{{* chercher des écritures d'amortissement liées à l'immobilisation *}}
|
||||
{{#select
|
||||
line.id as line_id,
|
||||
line.id_account as account_id,
|
||||
trans.id as trans_id,
|
||||
line.debit as montant,
|
||||
trans.label as label,
|
||||
trans.date as date_achat,
|
||||
y.id as year_id,
|
||||
y.end_date as date_fin
|
||||
from acc_transactions_lines as line
|
||||
inner join acc_transactions as trans on line.id_transaction = trans.id
|
||||
inner join acc_years as y on trans.id_year = y.id
|
||||
where line.id = :line_id;
|
||||
:line_id = $_GET.line|intval
|
||||
assign=ligne_immo
|
||||
l_amort.credit as amort_amount,
|
||||
l_amort.label as amort_label,
|
||||
l_amort.id as amort_line,
|
||||
CASE WHEN links.id_related = t_immo.id
|
||||
THEN links.id_transaction
|
||||
ELSE links.id_related
|
||||
END as amort_trans_id,
|
||||
trans.date as amort_date,
|
||||
trans.label as trans_label,
|
||||
trans.id_year as amort_year,
|
||||
account.id as account_id,
|
||||
account.code as account_code,
|
||||
account.label as account_label
|
||||
FROM acc_transactions_lines as l_immo
|
||||
INNER JOIN acc_transactions as t_immo on t_immo.id = l_immo.id_transaction
|
||||
INNER JOIN acc_transactions_links as links
|
||||
ON (t_immo.id = links.id_transaction
|
||||
OR
|
||||
t_immo.id = links.id_related)
|
||||
INNER JOIN acc_transactions_lines as l_amort on amort_trans_id = l_amort.id_transaction
|
||||
INNER join acc_transactions as trans on l_amort.id_transaction = trans.id
|
||||
INNER join acc_accounts as account on l_amort.id_account = account.id
|
||||
WHERE
|
||||
l_immo.id = :line_id
|
||||
AND account.code LIKE '28%'
|
||||
ORDER BY trans.date;
|
||||
:line_id = $_GET.immo_id|intval
|
||||
assign=linked_lines.
|
||||
}}
|
||||
<h3>Amortissement de « {{$label}} » d'un montant de {{"%f"|math:$montant|money_currency}} en date du {{$date_achat|date_short}}</h3>
|
||||
{{if $date_debut == null}}
|
||||
{{:assign date_debut=$amort_date}}
|
||||
{{/if}}
|
||||
{{/select}}
|
||||
|
||||
{{:assign valeur_residuelle=$ligne_immo.montant}}
|
||||
{{#foreach from=$linked_lines}}
|
||||
{{:assign valeur_residuelle="%d-%d"|math:$valeur_residuelle:$amort_amount}}
|
||||
{{/foreach}}
|
||||
|
||||
{{:admin_header title="Liste des amortissements" custom_css="./style.css" current="module_amortissement"}}
|
||||
|
||||
{{* barre de navigation *}}
|
||||
{{if $_GET.amort == "fini" || $valeur_residuelle== 0 }}
|
||||
{{:assign subcurrent="fini"}}
|
||||
{{elseif $_GET.amort == "archive"}}
|
||||
{{:assign subcurrent="archive"}}
|
||||
{{elseif $_GET.amort == null || $_GET.amort == "encours"}}
|
||||
{{:assign subcurrent="encours"}}
|
||||
{{else}}
|
||||
{{:assign message="Immobilisation %s non trouvée"|args:$_GET.line}}
|
||||
{{:error message=$message}}
|
||||
{{/select}}
|
||||
{{:assign subcurrent="autres"}}
|
||||
{{/if}}
|
||||
{{:include file="_nav.html" current="index" subcurrent="%s"|args:$subcurrent subsubcurrent="amortization"}}
|
||||
|
||||
{{*:debug ligne_immo=$ligne_immo*}}
|
||||
{{if $_GET.ok}}
|
||||
{{if $_GET.msg|match:"attach"}}
|
||||
{{:assign msg="Attachement écriture %s effectué"|args:$_GET.trans_id}}
|
||||
{{elseif $_GET.msg|match:"detach"}}
|
||||
{{:assign msg="Détachement écriture %s affectué"|args:$_GET.trans_id}}
|
||||
{{elseif $_GET.msg|match:"amortissement"}}
|
||||
{{:assign msg="Amortissement enregistré"}}
|
||||
{{/if}}
|
||||
<p class="block confirm">{{$msg}}</p>
|
||||
{{elseif $_GET.err}}
|
||||
{{if $_GET.msg|match:"attach"}}
|
||||
{{:assign msg="Échec attachement"}}
|
||||
{{elseif $_GET.msg|match:"amortissement"}}
|
||||
{{:assign msg="Échec enregistrement amortissement"}}
|
||||
{{/if}}
|
||||
<p class="block error">{{$msg}}</p>
|
||||
{{/if}}
|
||||
|
||||
{{* lister les écritures d'amortissement *}}
|
||||
{{#select
|
||||
line.id as l_immo,
|
||||
line.id_account as ammort_account,
|
||||
line2.debit as montant,
|
||||
line2.label as libelle,
|
||||
links.id_transaction as t_amort,
|
||||
line2.id as l_amort,
|
||||
line2.id_transaction as trans_id,
|
||||
line2.id_project as projet,
|
||||
line2.id_account as account_id,
|
||||
trans.date as date_immo,
|
||||
acc.code as account_code,
|
||||
acc.label as nom_compte,
|
||||
acc.id_chart as PC
|
||||
from acc_transactions_lines as line
|
||||
inner JOIN acc_transactions_links as links on line.id_transaction = links.id_related
|
||||
inner JOIN acc_transactions_lines as line2 on links.id_transaction = line2.id_transaction
|
||||
inner join acc_accounts as acc on line2.id_account = acc.id
|
||||
inner join acc_transactions as trans on line2.id_transaction = trans.id
|
||||
where line.id = :line_id and line2.debit <> 0
|
||||
order by trans.date;
|
||||
:line_id = $info_immo.line|intval
|
||||
assign=lines.
|
||||
}}
|
||||
{{:assign trans_url="%s/acc/transactions/details.php?id=%s"|args:$admin_url:$trans_id}}
|
||||
{{/select}}
|
||||
{{*:debug lines=$lines*}}
|
||||
{{*:debug line=$lines.0*}}
|
||||
{{*:debug line=$lines.1*}}
|
||||
{{if $valeur_residuelle > 0}}
|
||||
<nav class="tabs amort">
|
||||
<aside>
|
||||
{{:linkbutton label="Enregistrer un amortissement" shape="plus" href="save_amort.html?immo_id=%s"|args:$_GET.immo_id target="_dialog"}}
|
||||
</aside>
|
||||
</nav>
|
||||
{{/if}}
|
||||
|
||||
{{* calculer les amortissements *}}
|
||||
{{* montant de l'annuité normale *}}
|
||||
{{:assign montant="%f"|math:$ligne_immo.montant}}
|
||||
{{:assign annuite="%f/%f"|math:$montant:$info_immo.duration|intval}}
|
||||
{{*:debug montant=$montant *}}
|
||||
{{*:debug annuite=$annuite *}}
|
||||
<h3>Amortissement de «
|
||||
<a class="num"
|
||||
href={{"%s/acc/transactions/details.php?id=%s"|args:$admin_url:$ligne_immo.trans_id}}>#{{$ligne_immo.trans_id}}</a>
|
||||
{{$ligne_immo.label}} » d'un montant de
|
||||
{{"%f"|math:$ligne_immo.montant|money_currency}}
|
||||
en date du {{$date_debut|date_short}}{{if $duree != null}} sur {{$duree}} ans{{/if}}
|
||||
</h3>
|
||||
|
||||
{{* liste des exercices *}}
|
||||
{{#years}}
|
||||
{{:assign var="all_years.%d.label"|args:$id value=$label}}
|
||||
{{:assign var="all_years.%d.end_date"|args:$id value=$end_date}}
|
||||
{{:assign var="all_years.%d.closed"|args:$id value=$closed}}
|
||||
{{/years}}
|
||||
|
||||
{{*
|
||||
{{:debug all_years=$all_years}}
|
||||
{{:assign current_year=8}}
|
||||
{{:assign var="date_immo" from="all_years.%s.end_date"|args:$current_year}}
|
||||
{{:debug date_immo=$date_immo}}
|
||||
*}}
|
||||
|
||||
{{* première annuité *}}
|
||||
{{:assign date_achat=$ligne_immo.date_achat|date_short}}
|
||||
{{:assign date_fin=$ligne_immo.date_fin|date_short}}
|
||||
{{:include file="_calcul_dates.html" date_debut=$date_achat date_fin=$date_fin keep="nbjours"}}
|
||||
{{:assign annuite_1="%f/360*%d"|math:$annuite:$nbjours|intval}}
|
||||
{{*:debug annuite1=$annuite_1 *}}
|
||||
|
||||
{{:assign date_immo=$date_fin}}
|
||||
{{:assign annuite_courante=$annuite_1}}
|
||||
{{:assign solde=$montant}}
|
||||
{{:assign current_year=$ligne_immo.year_id}}
|
||||
|
||||
<section class="amortissement">
|
||||
<h2 class="ruler">Liste des amortissements</h2>
|
||||
<table class="list">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>N°</th>
|
||||
<th>Date</th>
|
||||
<th>Montant</th>
|
||||
<th>Solde</th>
|
||||
<th>Libellé</th>
|
||||
<th>ligne amort</th>
|
||||
<th>Compte</th>
|
||||
<th>Nom compte</th>
|
||||
<th class="actions"></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{{#foreach count="%d+1"|math:$info_immo.duration|intval key="num"}}
|
||||
{{:assign var="line" from="lines.%s"|args:$num}}
|
||||
{{*:debug line=$line*}}
|
||||
|
||||
{{if $line != null}}
|
||||
{{if $linked_lines != null}}
|
||||
<section class="amortissement">
|
||||
<h3 class="center-block ruler">Amortissements rattachés</h3>
|
||||
<table class="list">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>N°</th>
|
||||
<th>Date</th>
|
||||
<th class="nombre">Montant</th>
|
||||
<th class="nombre">Solde</th>
|
||||
<th>Libellé</th>
|
||||
<th>N° compte</th>
|
||||
<th>Compte</th>
|
||||
<th class="actions"></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{{#foreach from=$linked_lines item="line"}}
|
||||
{{* données de l'écriture *}}
|
||||
{{:assign trans_url="%s/acc/transactions/details.php?id=%s"|args:$admin_url:$line.t_amort}}
|
||||
{{:assign solde="%f-%d"|math:$solde:$line.montant}}
|
||||
{{:assign trans_url="%s/acc/transactions/details.php?id=%s"|args:$admin_url:$line.amort_trans_id}}
|
||||
{{:assign compte_url="%s/acc/accounts/journal.php?id=%s&year=%s"|args:$admin_url:$line.account_id:$line.amort_year}}
|
||||
{{:assign solde="%f-%d"|math:$solde:$line.amort_amount}}
|
||||
<tr>
|
||||
<td class="num"><a href={{$trans_url}}>#{{$line.t_amort}}</a></td>
|
||||
<td>{{$line.date_immo|date_short}}</td>
|
||||
<td class="money">{{"%f"|math:$line.montant|money}}</td>
|
||||
<td class="money">{{"%f"|math:$solde|money}}</td>
|
||||
<td>{{$line.libelle}}</td>
|
||||
<td>{{$line.l_amort}}</td>
|
||||
<td>{{$line.account_code}}</td>
|
||||
<td>{{$line.nom_compte}}</td>
|
||||
<td class="actions"></td>
|
||||
</tr>
|
||||
{{:assign libelle=$line.libelle}}
|
||||
{{:assign ammort_account=$line.ammort_account}}
|
||||
{{:assign annuite_courante="min(%f,%f)"|math:$annuite:$solde}}
|
||||
{{:assign current_year="%d+1"|math:$current_year}}
|
||||
{{:assign date_immo=$line.date_immo}}
|
||||
|
||||
{{else}}
|
||||
{{* pas d'écriture *}}
|
||||
|
||||
{{:assign solde="%f-%d"|math:$solde:$annuite_courante}}
|
||||
{{if $all_years|keys|has:$current_year}}
|
||||
{{:assign var="date_immo" from="all_years.%s.end_date"|args:$current_year}}
|
||||
{{:assign date_immo=$date_immo|date_short}}
|
||||
{{else}}
|
||||
{{:assign jour=$date_immo|date:"d"}}
|
||||
{{:assign mois=$date_immo|date:"m"}}
|
||||
{{:assign annee=$date_immo|date:"Y"}}
|
||||
{{:assign annee="%d+1"|math:$annee}}
|
||||
{{:assign date_immo="%s/%s/%s"|args:$jour:$mois:$annee|parse_date|date_short}}
|
||||
{{/if}}
|
||||
<tr>
|
||||
<td class="num">{{"%d+1"|math:$num}}</td>
|
||||
<td>{{$date_immo}}</td>
|
||||
<td class="money">{{"%f"|math:$annuite_courante|money}}</td>
|
||||
<td class="money">{{if $solde == 0}}0,00{{else}}{{"%f"|math:$solde|money}}{{/if}}</td>
|
||||
<td class="num"><a href={{$trans_url}}>#{{$line.amort_trans_id}}</a></td>
|
||||
<td>{{$line.amort_date|date_short}}</td>
|
||||
<td class="money">{{"%f"|math:$line.amort_amount|money}}</td>
|
||||
<td class="money">{{"%f"|math:$solde|money:false}}</td>
|
||||
<td>
|
||||
{{if $libelle == null}}
|
||||
{{:assign libelle="Amortissement "|cat:$ligne_immo.label}}
|
||||
{{if $line.amort_label == null}}
|
||||
{{$line.trans_label}}
|
||||
{{else}}
|
||||
{{$line.amort_label}}
|
||||
{{/if}}
|
||||
{{$libelle}}
|
||||
</td>
|
||||
<td></td>
|
||||
<td></td>
|
||||
<td></td>
|
||||
<td class="actions">
|
||||
{{if $all_years|keys|has:$current_year}}
|
||||
{{:linkbutton
|
||||
label="Enregistrer"
|
||||
href="save_amort.html?amount=%d&account=%s&year=%s&label=%s"|args:$annuite_courante:$ligne_immo.account_id:$current_year:$libelle
|
||||
shape="right"
|
||||
}}
|
||||
{{/if}}
|
||||
<td><a href={{$compte_url}}>{{$line.account_code}}</a></td>
|
||||
<td>{{$line.account_label}}</td>
|
||||
<td>
|
||||
{{:linkbutton label="Détacher" href="detach_amort.html?amort_id=%d&immo_id=%d"|args:$line.amort_line:$ligne_immo.immo_id shape="minus"}}
|
||||
</td>
|
||||
</tr>
|
||||
{{:assign current_year="%d+1"|math:$current_year}}
|
||||
{{:assign annuite_courante="min(%f,%f)"|math:$annuite:$solde}}
|
||||
{{/if}}
|
||||
{{/foreach}}
|
||||
</tbody>
|
||||
</table>
|
||||
</section>
|
||||
{{/foreach}}
|
||||
</tbody>
|
||||
</table>
|
||||
</section>
|
||||
{{/if}}
|
||||
|
||||
{{if $_GET.amort == null || $_GET.amort != "fini"}}
|
||||
|
||||
{{* Autres amortissements non rattachés *}}
|
||||
{{#select
|
||||
line.id as l_id,
|
||||
line.id_transaction as t_id,
|
||||
line.credit as amort_amount,
|
||||
line.label as l_label,
|
||||
trans.date as t_date,
|
||||
trans.label as t_label,
|
||||
trans.id_year as amort_year,
|
||||
account.id as account_id,
|
||||
account.code as account_code,
|
||||
account.label as account_label
|
||||
FROM acc_transactions_lines AS line
|
||||
INNER JOIN acc_accounts AS account ON account.id = line.id_account
|
||||
INNER JOIN acc_transactions AS trans ON trans.id = line.id_transaction
|
||||
INNER JOIN acc_years AS y ON y.id = trans.id_year
|
||||
WHERE account.code LIKE "28%" AND credit > 0 AND (NOT trans.status & 16)
|
||||
ORDER BY trans.date, trans.label;
|
||||
assign=autre_amort
|
||||
}}
|
||||
{{#select
|
||||
id_transaction,
|
||||
id_related
|
||||
FROM acc_transactions_links
|
||||
WHERE id_transaction = :id_amort OR id_related = :id_amort;
|
||||
:id_amort=$t_id
|
||||
}}
|
||||
{{else}}
|
||||
{{:assign var="autres_amortissements." value=$autre_amort}}
|
||||
{{/select}}
|
||||
{{/select}}
|
||||
|
||||
{{if $autres_amortissements != null}}
|
||||
<section class="amortissement">
|
||||
<h3 class="center-block ruler">Autres amortissements non rattachés</h3>
|
||||
<table class="list">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>N°</th>
|
||||
<th>Date</th>
|
||||
<th class="nombre">Montant</th>
|
||||
<th>Libellé</th>
|
||||
<th>N° compte</th>
|
||||
<th>Compte</th>
|
||||
<th class="actions"></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{{#foreach from=$autres_amortissements item="line"}}
|
||||
{{:assign trans_url="%s/acc/transactions/details.php?id=%s"|args:$admin_url:$line.t_id}}
|
||||
{{:assign compte_url="%s/acc/accounts/journal.php?id=%s&year=%s"|args:$admin_url:$line.account_id:$line.amort_year}}
|
||||
<tr>
|
||||
<td class="num"><a href={{$trans_url}}>#{{$line.t_id}}</a></td>
|
||||
<td>{{$line.t_date|date_short}}</td>
|
||||
<td class="money">{{"%f"|math:$line.amort_amount|money}}</td>
|
||||
<td>{{if $line.l_label == null}}
|
||||
{{$line.t_label}}
|
||||
{{else}}
|
||||
{{$line.l_label}}
|
||||
{{/if}}
|
||||
</td>
|
||||
<td><a href={{$compte_url}}>{{$line.account_code}}</a></td>
|
||||
<td>{{$line.account_label}}</td>
|
||||
<td>
|
||||
{{:linkbutton label="Attacher" href="attach_amort.html?amort_id=%d&immo_id=%d"|args:$line.l_id:$ligne_immo.immo_id shape="plus"}}
|
||||
</td>
|
||||
</tr>
|
||||
{{/foreach}}
|
||||
</tbody>
|
||||
</table>
|
||||
</section>
|
||||
{{/if}}
|
||||
{{/if}}
|
||||
{{:form_errors}}
|
||||
{{:admin_footer}}
|
||||
|
71
archives.html
Normal file
71
archives.html
Normal file
@ -0,0 +1,71 @@
|
||||
{{* -*- brindille -*- *}}
|
||||
|
||||
{{* Liste des immobilisations archivées *}}
|
||||
|
||||
<section class="immobilisation">
|
||||
<h2 class="ruler">Immobilisations archivées</h2>
|
||||
|
||||
{{:assign nb_immo=0}}
|
||||
<table class="list">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>N°</th>
|
||||
<th>Date</th>
|
||||
<th>Libellé</th>
|
||||
<th class="nombre">Montant</th>
|
||||
<th>N° compte</th>
|
||||
<th>Compte</th>
|
||||
<th>Projet</th>
|
||||
<th class="actions"></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
|
||||
{{#load type="immo" where="$$.status = 'archived'"}}
|
||||
{{: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}}
|
||||
{{:assign nb_immo="%d+1"|math:$nb_immo}}
|
||||
<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:false}}</td>
|
||||
<td><a href={{$compte_url}}>{{$account_code}}</a></td>
|
||||
<td>{{$account_label}}</td>
|
||||
<td>{{$project_label}}</td>
|
||||
<td class="actions">
|
||||
</td>
|
||||
</tr>
|
||||
{{/select}}
|
||||
</tbody>
|
||||
</table>
|
||||
{{if $nb_immo == 0}}
|
||||
<p class="block alert">Aucune immobilisation</p>
|
||||
{{/if}}
|
||||
</section>
|
56
attach_amort.html
Normal file
56
attach_amort.html
Normal file
@ -0,0 +1,56 @@
|
||||
{{* -*- brindille -*- *}}
|
||||
|
||||
{{*
|
||||
Enregistrer la liaison entre une écriture d'amortissement et
|
||||
l'écriture d'immobilisation correspondante
|
||||
*}}
|
||||
|
||||
{{* chercher l'écriture d'immobilisation *}}
|
||||
{{#select
|
||||
id_transaction
|
||||
FROM acc_transactions_lines
|
||||
WHERE id = :line_id;
|
||||
:line_id = $_GET.immo_id|intval
|
||||
}}
|
||||
{{:assign immo_trans_id=$id_transaction}}
|
||||
{{else}}
|
||||
{{:error message="Impossible de trouver l'écriture d'immobilisation de la ligne « %s »"|args:$_GET.immo_id}}
|
||||
{{/select}}
|
||||
|
||||
{{* chercher l'écriture d'amortissement *}}
|
||||
{{#select
|
||||
id_transaction
|
||||
FROM acc_transactions_lines
|
||||
WHERE id = :line_id;
|
||||
:line_id = $_GET.amort_id|intval
|
||||
}}
|
||||
{{:assign amort_id=$id_transaction}}
|
||||
{{else}}
|
||||
{{:error message="Impossible de trouver l'écriture d'amortissement de la ligne « %s »"|args:$_GET.amort_id}}
|
||||
{{/select}}
|
||||
|
||||
{{* chercher les liaisons de l'écriture d'immobilisation *}}
|
||||
{{#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 = $immo_trans_id
|
||||
}}
|
||||
{{:assign var="linked_transactions." value=$linked_id}}
|
||||
{{/select}}
|
||||
|
||||
{{* ajouter la nouvelle liaison *}}
|
||||
{{:assign var="linked_transactions." value=$amort_id}}
|
||||
|
||||
{{* Enregistrer les liaisons *}}
|
||||
{{:api
|
||||
method="POST"
|
||||
path="accounting/transaction/%s/transactions"|args:$immo_trans_id
|
||||
assign="result"
|
||||
assign_code="result_code"
|
||||
transactions=$linked_transactions
|
||||
}}
|
||||
{{:redirect to="amortization.html?immo_id=%s&ok=1&msg=attach&trans_id=%s"|args:$_GET.immo_id:$amort_id}}
|
220
balance_sheet_exit.html
Normal file
220
balance_sheet_exit.html
Normal file
@ -0,0 +1,220 @@
|
||||
{{* -*- brindille -*- *}}
|
||||
|
||||
{{*
|
||||
Sortir une immobilisation du bilan
|
||||
@param immo_id : id de la ligne d'immobilisation
|
||||
*}}
|
||||
|
||||
{{* Infos de l'immobilisation *}}
|
||||
{{#select
|
||||
line.debit as montant,
|
||||
trans.date as date_achat,
|
||||
trans.label
|
||||
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|intval
|
||||
assign="ligne_immo"
|
||||
}}
|
||||
{{else}}
|
||||
{{:error message="Immobilisation %s non trouvée"|args:$_GET.immo_id}}
|
||||
{{/select}}
|
||||
|
||||
{{:assign date_debut=$ligne_immo.date_achat}}
|
||||
{{:assign ts_mes=$ligne_immo.date_achat|strtotime}}
|
||||
|
||||
{{#load type="immo" assign="info_immo" where="$$.line = :line_id" :line_id=$_GET.immo_id|intval}}
|
||||
{{:assign ts_mes=$date|strtotime}}
|
||||
{{:assign date_debut=$date}}
|
||||
{{:assign duree_amort=$duration}}
|
||||
{{/load}}
|
||||
|
||||
{{* chercher des écritures d'amortissement liées à l'immobilisation *}}
|
||||
{{#select
|
||||
SUM(l_amort.credit) as amort_amount,
|
||||
CASE
|
||||
WHEN links.id_related = t_immo.id
|
||||
THEN links.id_transaction
|
||||
ELSE links.id_related
|
||||
END as amort_trans_id,
|
||||
MAX(trans.date) as last_amort_date,
|
||||
MIN(trans.date) as first_amort_date,
|
||||
COUNT(trans.id) as amort_number
|
||||
FROM acc_transactions_lines as l_immo
|
||||
INNER JOIN acc_transactions as t_immo on t_immo.id = l_immo.id_transaction
|
||||
INNER JOIN acc_transactions_links as links
|
||||
ON (t_immo.id = links.id_transaction
|
||||
OR
|
||||
t_immo.id = links.id_related)
|
||||
INNER JOIN acc_transactions_lines as l_amort on amort_trans_id = l_amort.id_transaction
|
||||
INNER join acc_transactions as trans on l_amort.id_transaction = trans.id
|
||||
INNER JOIN acc_accounts AS account ON l_amort.id_account = account.id
|
||||
WHERE l_immo.id = :line_id AND account.code LIKE '28%'
|
||||
LIMIT 1;
|
||||
:line_id = $_GET.immo_id|intval
|
||||
assign=amort_line
|
||||
}}
|
||||
{{/select}}
|
||||
|
||||
{{if $amort_line.amort_number == 0}}
|
||||
{{:assign amort_amount=0}}
|
||||
{{else}}
|
||||
{{:assign amort_amount=$amort_line.amort_amount}}
|
||||
{{:assign date_debut=$amort_line.last_amort_date|strtotime}}
|
||||
{{:assign date_debut="%d+(60*60*24)"|math:$date_debut|date:"Y-m-d"}}
|
||||
{{/if}}
|
||||
{{:assign ts_debut=$date_debut|strtotime}}
|
||||
{{:assign valeur_nette="%f-%f"|math:$ligne_immo.montant:$amort_amount}}
|
||||
|
||||
{{*
|
||||
lister les exercices qui englobent la date de début du prochain amortissement
|
||||
*}}
|
||||
{{:assign default_exit_date=""}}
|
||||
{{#years closed=false order="start_date" where="start_date <= :debut AND :debut <= end_date"
|
||||
:debut=$date_debut assign=years.}}
|
||||
{{if $start_date|strtotime <= $now && $now <= $end_date|strtotime}}
|
||||
{{:assign default_exit_date=$now|date_short}}
|
||||
{{/if}}
|
||||
{{:assign ts_fin=$end_date|strtotime}}
|
||||
{{:assign debut=$start_date|date_short}}
|
||||
{{:assign fin=$end_date|date_short}}
|
||||
{{:assign var="open_years.%d"|args:$id value=$label|cat:" (du "|cat:$debut|cat:" au "|cat:$fin|cat:")"}}
|
||||
{{:assign var="years_data.%d"|args:$id value=$ts_debut|cat:" "|cat:$ts_fin}}
|
||||
{{else}}
|
||||
{{:error message="Aucun exercice ouvert pour enregistrer un amortissement"}}
|
||||
{{/years}}
|
||||
{{if $years|count == 1}}
|
||||
{{:assign default_year=$years.0.id}}
|
||||
{{else}}
|
||||
{{:assign default_year=""}}
|
||||
{{/if}}
|
||||
|
||||
{{* Traiter l'envoi du formulaire *}}
|
||||
{{#form on="proceed"}}
|
||||
|
||||
{{if $_POST.date_sortie == null}}
|
||||
{{:error message="Vous devez renseigner la date de sortie"}}
|
||||
{{/if}}
|
||||
|
||||
{{* vérifier la validité de la date de mise en service *}}
|
||||
{{if $_POST.date_mes != null}}
|
||||
{{:assign ts_mes=$_POST.date_mes|parse_date|strtotime}}
|
||||
{{if $ts_mes < $ligne_immo.date_achat|strtotime || $ts_mes > $amort_line.first_amort_date|strtotime}}
|
||||
{{:assign immo_date=$ligne_immo.date_achat|date_short}}
|
||||
{{:assign amort_date=$amort_line.first_amort_date|date_short}}
|
||||
{{:error message="La date de mise en service doit être postérieure à la date d'acquisition de l'immobilisation (%s) et antérieure à la date du premier amortissement (%s)"|args:$immo_date:$amort_date}}
|
||||
{{/if}}
|
||||
{{/if}}
|
||||
|
||||
{{* vérifier la validité de la durée d'immobilisation *}}
|
||||
{{if $valeur_nette > 0}}
|
||||
{{if $info_immo.duration == null}}
|
||||
{{if $_POST.duree == null}}
|
||||
{{:error message="Vous devez renseigner la durée de l'immobilisation"}}
|
||||
{{elseif $_POST.duree < $amort_line.amort_number}}
|
||||
{{:error message="La durée de l'amortissement ne peut être inférieure au nombre d'écritures d'amortissement (%d)"|args:$amort_line.amort_number}}
|
||||
{{else}}
|
||||
{{:assign duree_amort=$_POST.duree}}
|
||||
{{/if}}
|
||||
{{/if}}
|
||||
{{/if}}
|
||||
|
||||
{{* vérifier la validité de la date de sortie *}}
|
||||
{{if $info_immo.date != null}}
|
||||
{{if $_POST.date_sortie|parse_date < $info_immo.date}}
|
||||
{{:assign immo_date=$info_immo.date|date_short}}
|
||||
{{:error message="La date de sortie doit être postérieure à la date de mise en service de l'immobilisation (%s)"|args:$immo_date}}
|
||||
{{/if}}
|
||||
{{elseif $_POST.date_mes != null}}
|
||||
{{if $_POST.date_sortie|parse_date < $_POST.date_mes|parse_date}}
|
||||
{{:error message="La date de sortie doit être postérieure à la date de mise en service de l'immobilisation (%s)"|args:$_POST.date_mes}}
|
||||
{{/if}}
|
||||
{{elseif $_POST.date_sortie|parse_date < $ligne_immo.date_achat}}
|
||||
{{:assign immo_date=$ligne_immo.date_achat|date_short}}
|
||||
{{:error message="La date de sortie doit être postérieure à la date d'acquisition de l'immobilisation (%s)"|args:$immo_date}}
|
||||
{{/if}}
|
||||
{{if $amort_line.amort_number != 0 && $_POST.date_sortie|parse_date <= $amort_line.last_amort_date}}
|
||||
{{:assign last_amort_date=$amort_line.last_amort_date|date_short}}
|
||||
{{:error message="La date de sortie doit être postérieure à la date de la dernière immobilisation (%s)"|args:$last_amort_date}}
|
||||
{{/if}}
|
||||
|
||||
{{* vérifier que la date de sortie est située dans un exercice ouvert *}}
|
||||
{{:assign ts_exit = $_POST.date_sortie|parse_date|strtotime}}
|
||||
{{:assign ok=false}}
|
||||
{{#foreach from=$years}}
|
||||
{{if $id == $_POST.id_year}}
|
||||
{{:assign selected_year=$id}}
|
||||
{{if $start_date|strtotime <= $ts_exit && $ts_exit <= $end_date|strtotime}}
|
||||
{{:assign ok=true}}
|
||||
{{:break}}
|
||||
{{/if}}
|
||||
{{/if}}
|
||||
{{/foreach}}
|
||||
{{if ! $ok}}
|
||||
{{:error message="La date choisie n'est pas dans l'exercice sélectionné !"}}
|
||||
{{/if}}
|
||||
|
||||
{{:redirect to="compute_exit_data.html?immo_id=%s&amort_amount=%s&year=%s&date_mes=%s&date_debut=%s&exit_date=%s&duree_amort=%s"|args:$_GET.immo_id:$amort_amount:$selected_year:$ts_mes:$ts_debut:$ts_exit:$duree_amort}}
|
||||
{{/form}}
|
||||
|
||||
{{:admin_header title="Sortie de bilan" custom_css="./style.css" current="module_amortissement"}}
|
||||
{{* barre de navigation *}}
|
||||
{{if ! $dialog}}
|
||||
{{:include file="_nav.html" current="index" subsubcurrent="balance_exit"}}
|
||||
{{/if}}
|
||||
{{:form_errors}}
|
||||
|
||||
{{* formulaire de sortie du bilan *}}
|
||||
<h3>Sortir l'immobilisation « {{$ligne_immo.label}} » du bilan</h3>
|
||||
<form method="post" action="">
|
||||
|
||||
<div class="informations">
|
||||
<legend>Données de l'imobilisation</legend>
|
||||
<dl class="describe">
|
||||
<dt>Montant</dt>
|
||||
<dd id="montant_immo" class="money">{{$ligne_immo.montant|money_currency:false}}</dd>
|
||||
<dt>Date d'acquisition</dt>
|
||||
<dd >{{$ligne_immo.date_achat|date_short}}</dd>
|
||||
{{if $info_immo.date != null && $info_immo.date != $ligne_immo.date_achat}}
|
||||
<dt>Date de mise en service</dt>
|
||||
<dd>{{$info_immo.date|date_short}}</dd>
|
||||
{{/if}}
|
||||
{{if $info_immo.duration != null}}
|
||||
<dt>Durée de l'amortissement</dt>
|
||||
<dd id="duree_amort" class="num">{{$info_immo.duration}} ans</dd>
|
||||
{{/if}}
|
||||
<dt>Montant des amortissements</dt>
|
||||
<dd id="montant_amort" class="money">{{$amort_amount|money_currency:false}} <span class="help">(à la date de début de l'exercice)</span></dd>
|
||||
<dt>Valeur nette résiduelle</dt>
|
||||
<dd class="money">{{$valeur_nette|money_currency:false}} <span class="help">(à la date de début de l'exercice)</span></dd>
|
||||
</dl>
|
||||
</div>
|
||||
{{if $valeur_nette > 0}}
|
||||
{{if $info_immo.date == null || $info_immo.duration == null}}
|
||||
<fieldset>
|
||||
<legend>Informations sur l'immobilisation</legend>
|
||||
<dl>
|
||||
{{if $info_immo.date == null}}
|
||||
{{:input type="date" name="date_mes" label="Date de mise en service" help="C'est la date de première utilisation ; à renseigner uniquement si différente de la date d'acquisition"}}
|
||||
{{/if}}
|
||||
{{if $info_immo.duration == null}}
|
||||
{{:input type="number" name="duree" label="Durée d'amortissement" required=true min=1 help="La durée est nécessaire pour calculer l'amortissement complémentaire"}}
|
||||
{{/if}}
|
||||
</dl>
|
||||
</fieldset>
|
||||
{{/if}}
|
||||
{{/if}}
|
||||
<fieldset>
|
||||
<legend>Informations de sortie</legend>
|
||||
<dl>
|
||||
{{:input type="select" default=$default_year name="id_year" label="Exercice" required=true default_empty="— Faire un choix —" options=$open_years}}
|
||||
{{:input type="date" name="date_sortie" label="Date de sortie du bilan" required=true default=$default_exit_date}}
|
||||
</dl>
|
||||
</fieldset>
|
||||
|
||||
<p class="submit">
|
||||
{{:button type="submit" name="proceed" label="Poursuivre" shape="right" class="main"}}
|
||||
</p>
|
||||
</form>
|
||||
|
||||
{{:admin_footer}}
|
133
compute_exit_data.html
Normal file
133
compute_exit_data.html
Normal file
@ -0,0 +1,133 @@
|
||||
{{* -*- brindille -*- *}}
|
||||
|
||||
{{*
|
||||
Calculer les valeurs de la sortie et saisir le montant de la cession (optionnel)
|
||||
paramètres :
|
||||
- immo_id : numéro de ligne de l'écriture d'immobilisation
|
||||
- amort_amount : montant des amortissements
|
||||
- year : exercice de la date de sortie de l'immobilisation
|
||||
- date_mes : datede mise en service de l'immobilisation
|
||||
- date_debut : date de début de la période d'amortissement complémentaire
|
||||
- exit_date : date de sortie de l'immobilisation
|
||||
- duree_amort : durée de l'amortiseement (optionnel)
|
||||
*}}
|
||||
|
||||
{{#select
|
||||
line.debit as montant,
|
||||
trans.date as date_achat,
|
||||
trans.label
|
||||
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|intval
|
||||
assign="ligne_immo"
|
||||
}}
|
||||
{{else}}
|
||||
{{:error message="Immobilisation %s non trouvée"|args:$_GET.immo_id}}
|
||||
{{/select}}
|
||||
|
||||
{{:assign valeur_nette="%f-%f"|math:$ligne_immo.montant:$_GET.amort_amount}}
|
||||
{{:assign amort_comp=0}} {{* amortissement complémentaire jqà date sortie *}}
|
||||
{{if $valeur_nette > 0}}
|
||||
{{:assign nbjours="1+(%d-%d)/(60*60*24)"|math:$_GET.exit_date:$_GET.date_debut}}
|
||||
{{:assign annuite="%f/%f"|math:$ligne_immo.montant:$_GET.duree_amort}}
|
||||
{{:assign amort_comp="round(%f/365*%f, 0)"|math:$annuite:$nbjours}}
|
||||
{{:assign amort_comp="min(%f, %f)"|math:$valeur_nette:$amort_comp}}
|
||||
{{/if}}
|
||||
|
||||
{{* Traiter l'envoi du formulaire *}}
|
||||
{{#form on="proceed"}}
|
||||
{{:debug post=$_POST}}
|
||||
{{if $_POST.cession != null}}
|
||||
{{if $_POST.montant_cession == null}}
|
||||
{{:error message="Vous devez saisir le montant de la cession"}}
|
||||
{{/if}}
|
||||
{{/if}}
|
||||
|
||||
{{:redirect to="write_exit.html?immo_id=%s&amort_amount=%s&year=%s&date_mes=%s&date_debut=%s&exit_date=%s&duree_amort=%s&cession=%s"|args:$_GET.immo_id:$_GET.amort_amount:$_GET.year:$_GET.date_mes:$_GET.date_debut:$_GET.exit_date:$_GET.duree_amort:$_POST.montant_cession}}
|
||||
|
||||
{{/form}}
|
||||
{{:admin_header title="Sortie du bilan" custom_css="./style.css" current="module_amortissement"}}
|
||||
|
||||
{{* barre de navigation *}}
|
||||
{{if ! $dialog}}
|
||||
{{:include file="_nav.html" current="index" subsubcurrent="balance_exit"}}
|
||||
{{/if}}
|
||||
|
||||
{{:form_errors}}
|
||||
|
||||
<h3>Sortir l'immobilisation « {{$ligne_immo.label}} » du bilan</h3>
|
||||
<form method="post" action="">
|
||||
|
||||
<div class="informations">
|
||||
<legend>Données de l'imobilisation</legend>
|
||||
<dl class="describe">
|
||||
<dt>Montant</dt>
|
||||
<dd id="montant_immo" class="money">{{$ligne_immo.montant|money_currency:false}}</dd>
|
||||
<dt>Date d'acquisition</dt>
|
||||
<dd >{{$ligne_immo.date_achat|date_short}}</dd>
|
||||
{{if $_GET.date_mes != $ligne_immo.date_achat|strtotime}}
|
||||
<dt>Date de mise en service</dt>
|
||||
<dd>{{$_GET.date_mes|date:"d/m/Y"}}</dd>
|
||||
{{/if}}
|
||||
{{if $_GET.duree_amort != null}}
|
||||
<dt>Durée de l'amortissement</dt>
|
||||
<dd id="duree_amort" class="num">{{$_GET.duree_amort}} ans</dd>
|
||||
{{/if}}
|
||||
<dt>Montant des amortissements</dt>
|
||||
<dd id="montant_amort" class="money">{{$_GET.amort_amount|money_currency:false}} <span class="help">(à la date de début de l'exercice)</span></dd>
|
||||
<dt>Valeur nette résiduelle</dt>
|
||||
<dd class="money">{{$valeur_nette|money_currency:false}} <span class="help">(à la date de début de l'exercice)</span></dd>
|
||||
<dt>Date de sortie</dt>
|
||||
<dd>{{$_GET.exit_date|date:"d/m/Y"}}</dd>
|
||||
{{if $amort_comp > 0}}
|
||||
<dt>Amortissement complémentaire</dt>
|
||||
<dd class="money">{{$amort_comp|money_currency:false}} <span class="help">(jusqu'à la date de sortie)</span></dd>
|
||||
<dt>Total des amortissements</dt>
|
||||
<dd class="money">{{"%f+%f"|math:$_GET.amort_amount:$amort_comp|money_currency:false}} <span class="help">(à la date de sortie)</span></dd>
|
||||
<dt>Valeur nette résiduelle</dt>
|
||||
<dd class="money">{{"%f-%f"|math:$valeur_nette:$amort_comp|money_currency:false}} <span class="help">(à la date de sortie)</span></dd>
|
||||
{{/if}}
|
||||
</dl>
|
||||
</div>
|
||||
<fieldset>
|
||||
<legend>Informations de sortie</legend>
|
||||
<dl>
|
||||
{{:input type="checkbox" value=1 name="cession" label="Cession" help="Cocher si la sortie est due à une cession" onclick="toggleHiddenAndFocus('f_cession_1', ['infos_cession'], 'f_montant_cession')"}}
|
||||
<div id="infos_cession" class="hidden">
|
||||
{{:input type="money" name="montant_cession" label="Montant de la cession" required=true}}
|
||||
</div>
|
||||
</dl>
|
||||
</fieldset>
|
||||
|
||||
<p class="submit">
|
||||
{{:button type="submit" name="proceed" label="Poursuivre" shape="right" class="main"}}
|
||||
</p>
|
||||
|
||||
</form>
|
||||
|
||||
<script type="text/javascript">
|
||||
/*
|
||||
- activer/désactiver les champs passés en paramètres
|
||||
- donner le focus au champ de saisie du montant
|
||||
*/
|
||||
function toggleHiddenAndFocus(idcb, idfields, idinput) {
|
||||
const cession = document.getElementById(idcb);
|
||||
for (let id of idfields) {
|
||||
const field = document.getElementById(id);
|
||||
if (cession.checked) {
|
||||
field.setAttribute("class", "");
|
||||
document.getElementById(idinput).focus();
|
||||
}
|
||||
else {
|
||||
field.setAttribute("class","hidden")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
(function () {
|
||||
toggleHiddenAndFocus('f_cession_1', ['infos_cession'], 'f_montant_cession');
|
||||
})();
|
||||
</script>
|
||||
|
||||
{{:admin_footer}}
|
8
defaut.json
Normal file
8
defaut.json
Normal file
@ -0,0 +1,8 @@
|
||||
{
|
||||
"tva": false,
|
||||
"prefixes": {
|
||||
"20": "Immobilisations incorporelles",
|
||||
"21": "Immobilisations corporelles",
|
||||
"27": "Immobilisations financières"
|
||||
}
|
||||
}
|
58
detach_amort.html
Normal file
58
detach_amort.html
Normal file
@ -0,0 +1,58 @@
|
||||
{{* -*- brindille -*- *}}
|
||||
|
||||
{{*
|
||||
Supprimer l'association entre une écriture d'amortissement et
|
||||
une écriture d'immobilisation
|
||||
*}}
|
||||
|
||||
{{* chercher l'écriture d'immobilisation *}}
|
||||
{{#select
|
||||
id_transaction
|
||||
FROM acc_transactions_lines
|
||||
WHERE id = :line_id;
|
||||
:line_id = $_GET.immo_id|intval
|
||||
}}
|
||||
{{:assign immo_trans_id=$id_transaction}}
|
||||
{{else}}
|
||||
{{:error message="Impossible de trouver l'écriture d'immobilisation de la ligne « %s »"|args:$_GET.immo_id}}
|
||||
{{/select}}
|
||||
|
||||
{{* chercher l'écriture d'amortissement *}}
|
||||
{{#select
|
||||
id_transaction
|
||||
FROM acc_transactions_lines
|
||||
WHERE id = :line_id;
|
||||
:line_id = $_GET.amort_id|intval
|
||||
}}
|
||||
{{:assign amort_id=$id_transaction}}
|
||||
{{else}}
|
||||
{{:error message="Impossible de trouver l'écriture d'amortissement de la ligne « %s »"|args:$_GET.amort_id}}
|
||||
{{/select}}
|
||||
|
||||
{{*
|
||||
chercher les liaisons de l'écriture d'immobilisation
|
||||
et supprimer la liaison avec l'écriture d'amortissement
|
||||
*}}
|
||||
{{#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 = $immo_trans_id
|
||||
}}
|
||||
{{if $linked_id != $amort_id}}
|
||||
{{:assign var="linked_transactions." value=$linked_id}}
|
||||
{{/if}}
|
||||
{{/select}}
|
||||
|
||||
{{* Enregistrer les liaisons *}}
|
||||
{{:api
|
||||
method="POST"
|
||||
path="accounting/transaction/%s/transactions"|args:$immo_trans_id
|
||||
assign="result"
|
||||
assign_code="result_code"
|
||||
transactions=$linked_transactions
|
||||
}}
|
||||
{{:redirect to="amortization.html?immo_id=%s&ok=1&msg=detach&trans_id=%s"|args:$_GET.immo_id:$amort_id}}
|
187
immobilisations.html
Normal file
187
immobilisations.html
Normal file
@ -0,0 +1,187 @@
|
||||
{{* -*- brindille -*- *}}
|
||||
|
||||
{{* Liste des immobilisations amortissable ou à définir *}}
|
||||
|
||||
<section class="immobilisation">
|
||||
{{if $amort == "encours"}}
|
||||
<h2 class="ruler">Immobilisations en cours</h2>
|
||||
{{elseif $amort == "fini"}}
|
||||
<h2 class="ruler">Immobilisations amorties</h2>
|
||||
{{/if}}
|
||||
{{:assign nb_immo=0}}
|
||||
|
||||
<table class="list">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>N°</th>
|
||||
<th>Date</th>
|
||||
<th>Libellé</th>
|
||||
<th class="nombre">Montant</th>
|
||||
<th class="nombre">Durée</th>
|
||||
<th>N° compte</th>
|
||||
<th>Compte</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 condition="("}}
|
||||
{{#foreach from=$prefix_array item="code"}}
|
||||
{{:assign code=$code|cat:"%"|quote_sql}}
|
||||
{{:assign condition=$condition|cat:" account.code LIKE "|cat:$code|cat:" OR "}}
|
||||
{{/foreach}}
|
||||
{{:assign condition=$condition|cat:"0)"}}
|
||||
{{:assign condition=$condition|cat:" AND debit > 0 AND NOT (trans.status & 16)"}}
|
||||
|
||||
{{#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,
|
||||
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
|
||||
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}}
|
||||
{{* voir si l'immo est prise en charge *}}
|
||||
{{#load type="immo" where="$$.line = :line_id" :line_id=$immo_id|intval}}
|
||||
{{:assign duration=$duration}}
|
||||
{{if $status == "ignored"}}
|
||||
{{:assign amortissable="non"}}
|
||||
{{else}}
|
||||
{{:assign amortissable="oui"}}
|
||||
{{/if}}
|
||||
{{else}}
|
||||
{{:assign amortissable="nsp"}}
|
||||
{{/load}}
|
||||
{{if $amortissable == "non"}}
|
||||
{{:continue}}
|
||||
{{/if}}
|
||||
|
||||
{{* voir s'il existe une écriture qui solde l'immobilisation *}}
|
||||
{{:assign ignore=false}}
|
||||
{{#select
|
||||
line.id AS line,
|
||||
line.id_transaction AS trans,
|
||||
line.debit,
|
||||
line.label,
|
||||
line2.id AS line2,
|
||||
line2.id_transaction AS trans2,
|
||||
line2.credit,
|
||||
line2.label
|
||||
FROM acc_transactions_lines AS line
|
||||
INNER JOIN acc_accounts AS acc ON acc.id = line.id_account
|
||||
INNER JOIN acc_transactions_lines AS line2 ON line2.id_account = acc.id
|
||||
WHERE
|
||||
line.id = :line_id
|
||||
AND line2.credit = line.debit;
|
||||
:line_id = $immo_id|intval
|
||||
}}
|
||||
{{:assign ignore=true}}
|
||||
{{/select}}
|
||||
{{if $ignore}}
|
||||
{{:continue}}
|
||||
{{/if}}
|
||||
|
||||
{{* voir s'il existe des écritures d'amortissement associées *}}
|
||||
{{#select
|
||||
sum(l_amort.credit) as amort_amount,
|
||||
CASE links.id_related = t_immo.id
|
||||
WHEN true THEN links.id_transaction
|
||||
WHEN false THEN links.id_related
|
||||
END as amort_trans_id
|
||||
FROM acc_transactions_lines as l_immo
|
||||
INNER JOIN acc_transactions as t_immo on t_immo.id = l_immo.id_transaction
|
||||
INNER JOIN acc_transactions_links as links
|
||||
ON (
|
||||
t_immo.id = links.id_transaction
|
||||
OR
|
||||
t_immo.id = links.id_related
|
||||
)
|
||||
INNER JOIN acc_transactions_lines as l_amort on amort_trans_id = l_amort.id_transaction
|
||||
INNER JOIN acc_accounts AS account ON l_amort.id_account = account.id
|
||||
WHERE
|
||||
l_immo.id = :line_id
|
||||
AND
|
||||
l_amort.credit <> 0
|
||||
AND
|
||||
account.code LIKE '28%';
|
||||
:line_id = $immo_id|intval
|
||||
}}
|
||||
{{if $amort_amount == null}}
|
||||
{{:assign exist_amort=false}}
|
||||
{{:assign amort_amount=0}}
|
||||
{{else}}
|
||||
{{:assign amort_amount=$amort_amount}}
|
||||
{{:assign exist_amort=true}}
|
||||
{{/if}}
|
||||
{{/select}}
|
||||
|
||||
{{* classement par onglet *}}
|
||||
{{if $amort == "encours" && $amort_amount >= $debit ||
|
||||
$amort == "fini" && $amort_amount < $debit ||
|
||||
$amortissable == "nsp" && ! $exist_amort
|
||||
}}
|
||||
{{:continue}}
|
||||
{{/if}}
|
||||
{{:assign nb_immo="%d+1"|math:$nb_immo}}
|
||||
<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="money">{{if $duration != null}}{{$duration}}{{/if}}</td>
|
||||
<td><a href={{$compte_url}}>{{$account_code}}</a></td>
|
||||
<td>{{$account_label}}</td>
|
||||
<td class="actions">
|
||||
{{if ! $exist_amort}}
|
||||
{{:linkbutton
|
||||
label="Modifier infos"
|
||||
href="modif_infos.html?immo_id=%s&amort=1"|args:$immo_id
|
||||
shape="settings"
|
||||
target="_dialog"
|
||||
}}
|
||||
{{elseif $amortissable == "nsp"}}
|
||||
{{:linkbutton
|
||||
label="Ajouter infos"
|
||||
href="add_infos.html?immo_id=%s&amort=1"|args:$immo_id
|
||||
shape="settings"
|
||||
target="_dialog"
|
||||
}}
|
||||
{{/if}}
|
||||
{{if $amort == "encours" || $amort == "fini"}}
|
||||
{{:linkbutton
|
||||
label="Sortir du bilan"
|
||||
href="balance_sheet_exit.html?immo_id=%s"|args:$immo_id
|
||||
shape="export"
|
||||
}}
|
||||
{{/if}}
|
||||
{{:linkbutton
|
||||
label="Amortissements"
|
||||
href="amortization.html?immo_id=%s&amort=%s"|args:$immo_id:$amort
|
||||
shape="table"
|
||||
}}
|
||||
</td>
|
||||
</tr>
|
||||
{{/select}}
|
||||
</tbody>
|
||||
</table>
|
||||
{{if $nb_immo == 0}}
|
||||
<p class="block alert">Aucune immobilisation</p>
|
||||
{{/if}}
|
||||
</section>
|
129
immobilisations_autres.html
Normal file
129
immobilisations_autres.html
Normal file
@ -0,0 +1,129 @@
|
||||
{{* -*- brindille -*- *}}
|
||||
|
||||
{{* Liste des immobilisations non amortissables ou non (encore) gérées *}}
|
||||
|
||||
<section class="immobilisation">
|
||||
<h2 class="ruler">Autres immobilisations</h2>
|
||||
|
||||
<table class="list">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>N°</th>
|
||||
<th>Date</th>
|
||||
<th>Libellé</th>
|
||||
<th class="nombre">Montant</th>
|
||||
<th>N° compte</th>
|
||||
<th>Compte</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 condition="("}}
|
||||
{{#foreach from=$prefix_array item="code"}}
|
||||
{{:assign code=$code|cat:"%"|quote_sql}}
|
||||
{{:assign condition=$condition|cat:" account.code LIKE "|cat:$code|cat:" OR "}}
|
||||
{{/foreach}}
|
||||
{{:assign condition=$condition|cat:"0)"}}
|
||||
{{:assign condition=$condition|cat:" AND debit > 0 AND NOT (trans.status & 16)"}}
|
||||
|
||||
{{#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,
|
||||
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
|
||||
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}}
|
||||
{{* voir si l'immo est prise en charge *}}
|
||||
{{#load type="immo" where="$$.line = :line_id" :line_id=$immo_id|intval}}
|
||||
{{:assign status=$status}}
|
||||
{{else}}
|
||||
{{:assign status="nsp"}}
|
||||
{{/load}}
|
||||
{{if $status != "ignored" && $status != "nsp"}}
|
||||
{{:continue}}
|
||||
{{/if}}
|
||||
{{*:debug immo_id=$immo_id status=$status*}}
|
||||
|
||||
{{* voir s'il existe des écritures d'amortissement associées *}}
|
||||
{{#select
|
||||
sum(l_amort.credit) as amort_amount,
|
||||
CASE links.id_related = t_immo.id
|
||||
WHEN true THEN links.id_transaction
|
||||
WHEN false THEN links.id_related
|
||||
END as amort_trans_id
|
||||
FROM acc_transactions_lines as l_immo
|
||||
INNER JOIN acc_transactions as t_immo on t_immo.id = l_immo.id_transaction
|
||||
INNER JOIN acc_transactions_links as links
|
||||
ON (
|
||||
t_immo.id = links.id_transaction
|
||||
OR
|
||||
t_immo.id = links.id_related
|
||||
)
|
||||
INNER JOIN acc_transactions_lines as l_amort on amort_trans_id = l_amort.id_transaction
|
||||
INNER JOIN acc_accounts AS account ON l_amort.id_account = account.id
|
||||
WHERE
|
||||
l_immo.id = :line_id
|
||||
AND
|
||||
l_amort.credit <> 0
|
||||
AND
|
||||
account.code LIKE '28%';
|
||||
:line_id = $immo_id|intval
|
||||
}}
|
||||
{{if $amort_amount != null}}
|
||||
{{:assign ignore=true}}
|
||||
{{else}}
|
||||
{{:assign ignore=false}}
|
||||
{{/if}}
|
||||
{{/select}}
|
||||
|
||||
{{if $ignore}}
|
||||
{{: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:false}}</td>
|
||||
<td><a href={{$compte_url}}>{{$account_code}}</a></td>
|
||||
<td>{{$account_label}}</td>
|
||||
<td class="actions">
|
||||
{{if $status == "nsp"}}
|
||||
{{:linkbutton
|
||||
label="Ajouter infos"
|
||||
href="add_infos.html?immo_id=%s&amort=1"|args:$immo_id
|
||||
shape="settings"
|
||||
target="_dialog"
|
||||
}}
|
||||
{{else}}
|
||||
{{:linkbutton
|
||||
label="Modifier infos"
|
||||
href="modif_infos.html?immo_id=%s&amort=0"|args:$immo_id
|
||||
shape="help"
|
||||
target="_dialog"
|
||||
}}
|
||||
{{/if}}
|
||||
</td>
|
||||
</tr>
|
||||
{{/select}}
|
||||
</tbody>
|
||||
</table>
|
||||
</section>
|
72
immobilisations_non.html
Normal file
72
immobilisations_non.html
Normal file
@ -0,0 +1,72 @@
|
||||
{{* -*- brindille -*- *}}
|
||||
|
||||
{{* Liste des immobilisations non amortissables *}}
|
||||
|
||||
<section class="immobilisation">
|
||||
<h2 class="ruler">Immobilisations non amortissables</h2>
|
||||
|
||||
<table class="list">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>N°</th>
|
||||
<th>Date</th>
|
||||
<th>Libellé</th>
|
||||
<th class="nombre">Montant</th>
|
||||
<th>N° compte</th>
|
||||
<th>Compte</th>
|
||||
<th>Projet</th>
|
||||
<th class="actions"></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
|
||||
{{#load type="immo" where="$$.status = 'ignored'"}}
|
||||
{{: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}}
|
||||
{{:debug condition=$condition}}
|
||||
{{#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:false}}</td>
|
||||
<td><a href={{$compte_url}}>{{$account_code}}</a></td>
|
||||
<td>{{$account_label}}</td>
|
||||
<td>{{$project_label}}</td>
|
||||
<td class="actions">
|
||||
{{:linkbutton
|
||||
label="Modifier infos"
|
||||
href="modif_infos.html?immo_id=%s&amort=0"|args:$immo_id
|
||||
shape="help"
|
||||
target="_dialog"
|
||||
}}
|
||||
</td>
|
||||
</tr>
|
||||
{{/select}}
|
||||
</tbody>
|
||||
</table>
|
||||
</section>
|
168
index.html
168
index.html
@ -1,129 +1,59 @@
|
||||
{{:admin_header title="Gestion des amortissements" custom_css=$custom_css current="module_amortissement"}}
|
||||
{{* -*- brindille -*- *}}
|
||||
{{:admin_header title="Gestion des amortissements" custom_css="./style.css" current="module_amortissement"}}
|
||||
|
||||
{{* barre de navigation *}}
|
||||
{{:include file="_nav.html" current="index"}}
|
||||
|
||||
{{if $_GET.ok}}
|
||||
<p class="block confirm">Modification effectuée</p>
|
||||
{{elseif $_GET.err}}
|
||||
<p class="block error">Modification refusée</p>
|
||||
{{if $_GET.amort == null}}
|
||||
{{:assign amort="encours"}}
|
||||
{{else}}
|
||||
{{:assign amort=$_GET.amort}}
|
||||
{{/if}}
|
||||
|
||||
{{:include file="_nav.html" current="index" subcurrent="%s"|args:$amort}}
|
||||
|
||||
{{* lister les immobilisations *}}
|
||||
<section class="immobilisation">
|
||||
<h2 class="ruler">Liste des immobilisations</h2>
|
||||
{{if $_GET.ok}}
|
||||
{{if $_GET.msg|match:"immobilisation"}}
|
||||
{{:assign msg="Immobilisation enregistrée"}}
|
||||
{{elseif $_GET.msg|match:"infos"}}
|
||||
{{:assign msg="Informations enregistrées"}}
|
||||
{{/if}}
|
||||
<p class="block confirm">{{$msg}}</p>
|
||||
{{elseif $_GET.err}}
|
||||
<p class="block error">Échec enregistrement immobilisation</p>
|
||||
{{/if}}
|
||||
|
||||
<table class="list">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Id</th>
|
||||
<th>Libellé</th>
|
||||
<th>Date</th>
|
||||
<th>id_line</th>
|
||||
<th>N° compte</th>
|
||||
<th>Compte</th>
|
||||
<th>Montant</th>
|
||||
<th class="actions"></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{{*
|
||||
TODO améliorer cette requête :
|
||||
- ne pas mettre l'id du PC
|
||||
- voir si assez général
|
||||
*}}
|
||||
{{#load type="immo"}}
|
||||
{{* supprimer les documents sans écriture associée *}}
|
||||
{{#select
|
||||
line.id as line_id
|
||||
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 = $line
|
||||
}}
|
||||
{{else}}
|
||||
{{:delete key=$key}}
|
||||
{{/select}}
|
||||
|
||||
{{#select
|
||||
trans.id as trans_id,
|
||||
trans.label as trans_label,
|
||||
trans.date as trans_date,
|
||||
line.id as line_id,
|
||||
account.code as account_code,
|
||||
account.label as account_label,
|
||||
line.debit AS debit
|
||||
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 proj ON line.id_project = proj.id
|
||||
WHERE
|
||||
account.id_chart = "3"
|
||||
AND
|
||||
(account.code LIKE '21%' OR account.code LIKE '22%')
|
||||
ORDER BY trans.date DESC
|
||||
}}
|
||||
{{:assign trans_url="%s/acc/transactions/details.php?id=%s"|args:$admin_url:$trans_id}}
|
||||
<tr>
|
||||
<td class="num"><a href={{$trans_url}}>#{{$trans_id}}</a></td>
|
||||
<td>{{$trans_label}}</td>
|
||||
<td>{{$trans_date|date_short}}</td>
|
||||
<td>{{$line_id}}</td>
|
||||
<td>{{$account_code}}</td>
|
||||
<td>{{$account_label}}</td>
|
||||
<td class="money">{{"%f"|math:$debit|money}}</td>
|
||||
<td class="actions">
|
||||
{{:linkbutton
|
||||
label="Amortissements"
|
||||
href="amortization.html?line=%s"|args:$line_id
|
||||
shape="table"
|
||||
}}
|
||||
</td>
|
||||
</tr>
|
||||
{{/select}}
|
||||
</tbody>
|
||||
</table>
|
||||
</section>
|
||||
{{* supprimer les documents correspondant à une écriture de la balance d'ouverture
|
||||
{{#select
|
||||
line.id as line_id,
|
||||
trans.status
|
||||
FROM acc_transactions_lines as line
|
||||
INNER JOIN acc_transactions AS trans on line.id_transaction = trans.id
|
||||
WHERE line.id = :line_id AND (trans.status & 16);
|
||||
:line_id = $line
|
||||
}}
|
||||
{{:delete key=$key}}
|
||||
{{/select}}
|
||||
*}}
|
||||
{{/load}}
|
||||
|
||||
<form method="post" action="">
|
||||
<fieldset>
|
||||
<legend>Ajouter une immobilisation</legend>
|
||||
<p class="submit">
|
||||
{{:linkbutton
|
||||
label="Ajouter une immobilisation"
|
||||
shape="plus"
|
||||
href="add_asset.html"
|
||||
}}
|
||||
</p>
|
||||
</fieldset>
|
||||
</form>
|
||||
|
||||
|
||||
{{* sélectionner un compte *}}
|
||||
<h1>TEST</h1>
|
||||
|
||||
{{:assign var="ll.0.d" value="%f/100"|math:$debit}}
|
||||
{{:assign var="ll.1.c" value="%f/100"|math:$debit}}
|
||||
{{* :debug ll=$ll *}}
|
||||
{{:assign
|
||||
var="qs"
|
||||
t=0
|
||||
l="Amortissement de %s"|args:$trans_label
|
||||
dt=$trans_date
|
||||
a00=0
|
||||
ll=$ll
|
||||
}}
|
||||
{{:assign qs=$qs|http_build_query}}
|
||||
{{:linkbutton
|
||||
label="Ajouter"
|
||||
href="!acc/transactions/new.php?%s"|args:$qs
|
||||
shape="plus"
|
||||
target="_dialog"
|
||||
}}
|
||||
|
||||
<form method="post" action="">
|
||||
<fieldset>
|
||||
<legend>Écriture de note de frais</legend>
|
||||
{{:assign var="default_account.625" value="625 Déplacements, missions et réceptions"}}
|
||||
{{:input
|
||||
type="list"
|
||||
name="account"
|
||||
label="Compte de paiement"
|
||||
required=true
|
||||
target="!acc/charts/accounts/selector.php?targets=5&key=code&year=%d"|args:7
|
||||
default=$default_account
|
||||
}}
|
||||
</fieldset>
|
||||
</form>
|
||||
{{if $amort == "autres"}}
|
||||
{{:include file="./immobilisations_autres.html"}}
|
||||
{{elseif $amort == "archive"}}
|
||||
{{:include file="archives.html"}}
|
||||
{{elseif $amort == "encours" || $amort == "fini"}}
|
||||
{{:include file="./immobilisations.html"}}
|
||||
{{/if}}
|
||||
|
||||
{{:admin_footer}}
|
||||
|
118
modif_infos.html
Normal file
118
modif_infos.html
Normal file
@ -0,0 +1,118 @@
|
||||
{{* -*- brindille -*- *}}
|
||||
|
||||
{{:admin_header title="Modifier informations amortissement" custom_css=$custom_css current="module_amortissement"}}
|
||||
|
||||
{{* barre de navigation *}}
|
||||
{{if ! $dialog}}
|
||||
{{:include file="_nav.html" current="index"}}
|
||||
{{/if}}
|
||||
|
||||
{{* infos de l'immobilisation *}}
|
||||
{{:assign var="immo_id" value=$_GET.immo_id|intval}}
|
||||
{{#load type="immo" assign="info_immo" where="$$.line = :line_id" :line_id=$immo_id|intval}}
|
||||
{{/load}}
|
||||
|
||||
{{* Traiter l'envoi du formulaire *}}
|
||||
{{#form on="change"}}
|
||||
|
||||
{{* 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 = $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 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 modifiées de l'immobilisation *}}
|
||||
{{:save
|
||||
key=$info_immo.key
|
||||
validate_schema="schema.json"
|
||||
type="immo"
|
||||
line=$immo_id
|
||||
duration=$duration
|
||||
date=$date_debut
|
||||
status=$status
|
||||
}}
|
||||
|
||||
{{if $_POST.no_amort}}
|
||||
{{:assign amort="autres"}}
|
||||
{{else}}
|
||||
{{:assign amort="encours"}}
|
||||
{{/if}}
|
||||
{{:redirect force="index.html?ok=1&msg=infos&amort=%s"|args:$amort}}
|
||||
{{else}}
|
||||
{{:form_errors}}
|
||||
{{/form}}
|
||||
|
||||
{{* modifier 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>
|
||||
{{if $checked}}
|
||||
{{:assign helptext = "Dé-cocher pour amortir"}}
|
||||
{{else}}
|
||||
{{:assign helptext = "Cocher pour ne pas amortir"}}
|
||||
{{/if}}
|
||||
{{:input id="no_amort" type="checkbox" value=1 name="no_amort" label="Ne pas amortir" default=$checked help=$helptext onclick="toggleInputs('infos_immo','f_no_amort_1')"}}
|
||||
{{:input type="date" name="date_mes" label="Date de mise en service" default=$info_immo.date disabled=$disabled help="à renseigner uniquement si différente de la date d'acquisition"}}
|
||||
{{:input type="number" name="duree" label="Durée d'amortissement" default=$info_immo.duration required=true min=1 disabled=$disabled}}
|
||||
</dl>
|
||||
</fieldset>
|
||||
|
||||
<p class="submit">
|
||||
{{:button type="submit" name="change" label="Modifier" 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}}
|
@ -1,5 +1,5 @@
|
||||
name="Gestion des amortissements"
|
||||
description="Gestion des amortissements : ..."
|
||||
name="Amortissements"
|
||||
description="Gestion des amortissements pour le logiciel de comptabilité Paheko (v0.16)"
|
||||
author="Jean-Christophe Engel"
|
||||
author_url="https://git.roflcopter.fr/lesanges"
|
||||
home_button=false
|
||||
|
311
save_amort.html
311
save_amort.html
@ -1,61 +1,320 @@
|
||||
{{* -*- brindille -*- *}}
|
||||
|
||||
{{*
|
||||
Créer une écriture d'amortissement
|
||||
@param immo_id : id de la ligne d'immobilisation
|
||||
*}}
|
||||
|
||||
{{* Infos de l'immobilisation *}}
|
||||
{{#select
|
||||
line.id as immo_id,
|
||||
line.id_account as account_id,
|
||||
line.debit as montant,
|
||||
line.id_project as project_id,
|
||||
trans.id as trans_id,
|
||||
trans.label,
|
||||
trans.date,
|
||||
y.id as year_id,
|
||||
y.start_date,
|
||||
y.end_date,
|
||||
project.label as project_label
|
||||
FROM acc_transactions_lines AS line
|
||||
INNER JOIN acc_transactions AS trans ON line.id_transaction = trans.id
|
||||
INNER JOIN acc_years AS y ON trans.id_year = y.id
|
||||
LEFT JOIN acc_projects AS project ON line.id_project = project.id
|
||||
WHERE line.id = :line_id;
|
||||
:line_id = $_GET.immo_id|intval
|
||||
assign=ligne_immo
|
||||
}}
|
||||
{{else}}
|
||||
{{:error message="Immobilisation %s non trouvée"|args:$_GET.immo_id}}
|
||||
{{/select}}
|
||||
{{:assign date_debut=$ligne_immo.date}}
|
||||
|
||||
{{#load type="immo" where="$$.line = :line_id" :line_id=$_GET.immo_id|intval}}
|
||||
{{:assign duree=$duration}}
|
||||
{{:assign date_debut=$date}}
|
||||
{{else}}
|
||||
{{:error message="Vous devez renseigner la date de mise en service et la durée d'immobilisation"}}
|
||||
{{/load}}
|
||||
|
||||
{{* chercher des écritures d'amortissement liées à l'immobilisation *}}
|
||||
{{#select
|
||||
SUM(l_amort.credit) as amort_amount,
|
||||
l_amort.label as amort_label,
|
||||
l_amort.id as amort_line_id,
|
||||
CASE WHEN links.id_related = t_immo.id
|
||||
THEN links.id_transaction
|
||||
ELSE links.id_related
|
||||
END as amort_trans_id,
|
||||
MAX(trans.date) as amort_date,
|
||||
COUNT(trans.id) as amort_number,
|
||||
trans.label as trans_label,
|
||||
trans.id_year as amort_year,
|
||||
account.id as account_id,
|
||||
account.code as account_code,
|
||||
account.label as account_label
|
||||
FROM acc_transactions_lines as l_immo
|
||||
INNER JOIN acc_transactions as t_immo on t_immo.id = l_immo.id_transaction
|
||||
INNER JOIN acc_transactions_links as links
|
||||
ON (t_immo.id = links.id_transaction
|
||||
OR
|
||||
t_immo.id = links.id_related)
|
||||
INNER JOIN acc_transactions_lines as l_amort on amort_trans_id = l_amort.id_transaction
|
||||
INNER join acc_transactions as trans on l_amort.id_transaction = trans.id
|
||||
INNER join acc_accounts as account on l_amort.id_account = account.id
|
||||
WHERE l_immo.id = :line_id AND account.code LIKE '28%'
|
||||
ORDER BY trans.date DESC LIMIT 1;
|
||||
:line_id = $_GET.immo_id|intval
|
||||
assign=amort_line
|
||||
}}
|
||||
{{/select}}
|
||||
|
||||
{{if $amort_line.amort_number == 0}}
|
||||
{{* 1er amortissement *}}
|
||||
{{* déterminer le compte d'amortissement en fonction du compte d'immobilisation *}}
|
||||
{{#select code, label from acc_accounts where id = :id; :id=$ligne_immo.account_id assign=amort_account}}
|
||||
{{/select}}
|
||||
{{:include
|
||||
file="./_get_amort_code.html"
|
||||
code_immo=$amort_account.code
|
||||
keep="code_amort"
|
||||
}}
|
||||
{{:assign var=amort_label value="Amortissement %s"|args:$amort_account.label}}
|
||||
{{:assign var=libelle value="Amortissement %s"|args:$ligne_immo.label}}
|
||||
{{else}}
|
||||
{{* amortissements suivants *}}
|
||||
{{:assign date_debut=$amort_line.amort_date|strtotime}}
|
||||
{{:assign date_debut="%d+(60*60*24)"|math:$date_debut|date:"Y-m-d"}}
|
||||
{{:assign var=code_amort value=$amort_line.account_code}}
|
||||
{{:assign var=amort_label value=$amort_line.account_label}}
|
||||
{{:assign var=libelle value=$amort_line.amort_label}}
|
||||
{{/if}}
|
||||
|
||||
{{*
|
||||
lister les exercices qui englobent la date de mise en service de l'immo
|
||||
ou la date du dernier amortissement
|
||||
*}}
|
||||
{{:assign msg_years=""}}
|
||||
{{#years closed=false order="start_date" where="start_date <= :debut AND :debut <= end_date"
|
||||
:debut=$date_debut assign=years.}}
|
||||
{{if $amort_line.amort_number == 0}}
|
||||
{{:assign ts_debut=$date_debut|strtotime}}
|
||||
{{else}}
|
||||
{{:assign ts_debut=$start_date|strtotime}}
|
||||
{{/if}}
|
||||
{{:assign ts_fin=$end_date|strtotime}}
|
||||
{{:assign debut=$start_date|date_short}}
|
||||
{{:assign fin=$end_date|date_short}}
|
||||
{{:assign var="open_years.%d"|args:$id value=$label|cat:" (du "|cat:$debut|cat:" au "|cat:$fin|cat:")"}}
|
||||
{{:assign var="years_data.%d"|args:$id value=$ts_debut|cat:" "|cat:$ts_fin}}
|
||||
{{:assign msg_years=$msg_years|cat:"\n"|cat:" - "|cat:$label|cat:" : "|cat:$debut|cat:" à "|cat:$fin}}
|
||||
{{else}}
|
||||
{{:error message="Aucun exercice ouvert pour enregistrer un amortissement"}}
|
||||
{{/years}}
|
||||
|
||||
{{* Traiter l'envoi du formulaire *}}
|
||||
{{#form on="save"}}
|
||||
{{* vérifier que la date est située dans un exercice compatible *}}
|
||||
{{:assign ts_date = $_POST.date_amort|parse_date|strtotime}}
|
||||
{{:assign ok=false}}
|
||||
{{#foreach from=$years}}
|
||||
{{if $id == $_POST.id_year}}
|
||||
{{:assign selected_chart=$id_chart}}
|
||||
{{if $start_date|strtotime <= $ts_date && $ts_date <= $end_date|strtotime}}
|
||||
{{:assign ok=true}}
|
||||
{{:break}}
|
||||
{{/if}}
|
||||
{{/if}}
|
||||
{{/foreach}}
|
||||
{{if ! $ok}}
|
||||
{{:error message="La date choisie n'est dans aucun exercice compatible !\nExercices compatibles : %s"|args:$msg_years}}
|
||||
{{/if}}
|
||||
{{* déterminer le numéro des comptes au cas où la clé serait un identifiant *}}
|
||||
{{:include
|
||||
file="_get_codes.html"
|
||||
account=$_POST.debit_account
|
||||
keep="account_code"
|
||||
}}
|
||||
{{:assign debit_account=$account_code}}
|
||||
{{:include
|
||||
file="_get_codes.html"
|
||||
account=$_POST.credit_account
|
||||
keep="account_code"
|
||||
}}
|
||||
{{:assign credit_account=$account_code}}
|
||||
{{* vérifier :
|
||||
- que le compte d'amortissement débute par un préfixe correct (280, 281, ...)
|
||||
- est présent dans le PC de l'exercice correspondant à la date
|
||||
*}}
|
||||
{{:read file="./defaut.json" assign="config_json"}}
|
||||
{{:assign config_defaut=$config_json|json_decode}}
|
||||
{{:assign var="prefix_array" value=$config_defaut.prefixes|keys}}
|
||||
{{#foreach from=$prefix_array item="code"}}
|
||||
{{* déterminer le numéro du compte d'amortissement associé au compte d'immobilisation *}}
|
||||
{{:include
|
||||
file="./_get_amort_code.html"
|
||||
code_immo=$code
|
||||
keep="code_amort"
|
||||
}}
|
||||
{{:assign var="amort_array." value=$code_amort|intval}}
|
||||
{{/foreach}}
|
||||
|
||||
{{:include
|
||||
file="_check_account.html"
|
||||
account=$credit_account
|
||||
chart_id=$selected_chart
|
||||
prefix_array=$amort_array
|
||||
keep="account_ok"
|
||||
}}
|
||||
{{if $account_ok == null}}
|
||||
{{:assign compte=$credit_account|implode:""}}
|
||||
{{:redirect url="add_account.html?account=%s&chart=%s&immo_id=%s"|args:$compte:$selected_chart:$_GET.immo_id}}
|
||||
{{/if}}
|
||||
|
||||
{{* vérifier que le montant ne dépasse pas le solde restant *}}
|
||||
{{:assign solde="%d-%d"|math:$ligne_immo.montant:$amort_line.amort_amount}}
|
||||
{{if $_POST.montant|trim|money_int > $solde|intval}}
|
||||
{{:assign solde=$solde|money_raw}}
|
||||
{{:error message="Le montant indiqué « %s » dépasse le solde à amortir « %s »"|args:$_POST.montant:$solde}}
|
||||
{{/if}}
|
||||
|
||||
{{* enregistrer l'écriture *}}
|
||||
{{:assign
|
||||
var="lines."
|
||||
debit=$_POST.montant
|
||||
account=$debit_account|keys|key:0
|
||||
id_project=$_GET.project_id
|
||||
label=$_POST.designation
|
||||
}}
|
||||
{{:assign
|
||||
var="lines."
|
||||
credit=$_POST.montant
|
||||
account=$credit_account|keys|key:0
|
||||
id_project=$_GET.project_id
|
||||
label=$_POST.designation
|
||||
}}
|
||||
{{:api
|
||||
method="POST"
|
||||
path="accounting/transaction"
|
||||
assign="result"
|
||||
assign_code="result_code"
|
||||
id_year=$_POST.id_year
|
||||
type="advanced"
|
||||
date=$_POST.date_amort
|
||||
label=$_POST.designation
|
||||
lines=$lines
|
||||
linked_transactions=$ligne_immo.trans_id|intval
|
||||
}}
|
||||
|
||||
{{:redirect force="amortization.html?immo_id=%s&ok=1&msg=amortissement"|args:$_GET.immo_id}}
|
||||
{{/form}}
|
||||
|
||||
{{:admin_header title="Ajout amortissement" current="module_amortissement"}}
|
||||
|
||||
{{* barre de navigation *}}
|
||||
{{if ! $dialog}}
|
||||
{{:include file="_nav.html" current="amortization"}}
|
||||
{{:include file="_nav.html" current="index" subcurrent="encours" subsubcurrent="amortization"}}
|
||||
{{/if}}
|
||||
|
||||
{{* Traiter l'envoi du formulaire *}}
|
||||
{{:form_errors}}
|
||||
|
||||
{{* Préparer les infos pour le formulaire *}}
|
||||
{{:assign var=selected_year value=$years.0.id}}
|
||||
{{:assign var=date_amort value=$years.0.end_date}}
|
||||
{{:include file="_calcul_dates.html" date_debut=$date_debut date_fin=$date_amort keep="nbjours"}}
|
||||
|
||||
{{* montant de l'amortissement *}}
|
||||
{{:assign montant_amort="%f/%f/365*%d"|math:$ligne_immo.montant:$duree:$nbjours|intval}}
|
||||
{{:assign montant_amort="min(%f, %d-%d)"|math:$montant_amort:$ligne_immo.montant:$amort_line.amort_amount}}
|
||||
{{:assign var="debit_account.6811" value="6811 — Dot. aux amortissements des immobilisations"}}
|
||||
{{:assign var="credit_account.%s"|args:$code_amort value="%s — "|args:$code_amort|cat:$amort_label}}
|
||||
|
||||
{{*
|
||||
déterminer le compte d'amortissement en fonction du compte
|
||||
d'immobilisation => ajouter un 8 après le 2 de tête
|
||||
*}}
|
||||
{{#select code, label from acc_accounts where id = :id; :id=$_GET.account assign=amort_account}}{{/select}}
|
||||
{{:assign c1=$amort_account.code|substr:0:1}}
|
||||
{{:assign reste=$amort_account.code|substr:1}}
|
||||
{{:assign amort_code=$c1|cat:8|cat:$reste}}
|
||||
{{:assign var="credit_account.%s"|args:$amort_code value="%s — Amortissements "|args:$amort_code|cat:$amort_account.label}}
|
||||
{{* -------------------------------------------------------------------------------- *}}
|
||||
|
||||
{{#select id, label, end_date from acc_years where id=:id; :id=$_GET.year assign=year}}{{/select}}
|
||||
{{*:debug year.id=$year.id year.end_date=$year.end_date|date_short*}}
|
||||
|
||||
{{#years closed=false}}
|
||||
{{:assign var="open_years.%d"|args:$id value=$label}}
|
||||
{{/years}}
|
||||
<div id="f_erreur" class="hidden">
|
||||
<p class="block error">La date saisie n'est pas dans l'exercice choisi !</p>
|
||||
</div>
|
||||
|
||||
<form method="post" action="">
|
||||
<fieldset class="ajout_amort">
|
||||
<legend>Ajouter une écriture d'amortissement</legend>
|
||||
<dl>
|
||||
{{:input type="select" default=$year.id name="id_year" label="Exercice" required=true options=$open_years}}
|
||||
{{:input type="date" name="date" label="Date" required=true default=$year.end_date|date_short}}
|
||||
{{:input type="text" name="designation" label="Désignation" required=true default=$_GET.label}}
|
||||
{{:input type="money" name="montant" label="Montant" required=true default=$_GET.amount}}
|
||||
{{:input type="select" default=$selected_year name="id_year" label="Exercice" required=true default_empty="— Faire un choix —" options=$open_years}}
|
||||
{{:input type="date" name="date_amort" label="Date" required=true default=$date_amort|date_short}}
|
||||
{{:input type="text" name="designation" label="Désignation" required=true default=$libelle}}
|
||||
{{:input type="money" name="montant" label="Montant" required=true default=$montant_amort}}
|
||||
{{:input
|
||||
type="list"
|
||||
name="debit_account"
|
||||
label="Compte de débit"
|
||||
required=true
|
||||
target="!acc/charts/accounts/selector.php?&key=code&year=%d"|args:$year.id
|
||||
target="!acc/charts/accounts/selector.php?codes=%s&id_year=%d"|args:"68*":$selected_year
|
||||
default=$debit_account
|
||||
}}
|
||||
{{:input
|
||||
type="list"
|
||||
name="credi_account"
|
||||
name="credit_account"
|
||||
label="Compte d'amortissement (280xx ou 281xx)"
|
||||
required=true
|
||||
target="!acc/charts/accounts/selector.php?key=code&year=%d"|args:$year.id
|
||||
target="!acc/charts/accounts/selector.php?codes=%s&id_year=%d"|args:"28*":$selected_year
|
||||
default=$credit_account
|
||||
}}
|
||||
<div id="donnees" class="hidden">
|
||||
{{:input type="text" name="montant_immo" default=$ligne_immo.montant}}
|
||||
{{:input type="text" name="duree_amort" default=$duree}}
|
||||
{{:input type="text" name="somme_amort" default=$amort_line.amort_amount}}
|
||||
{{:input type="select" name="years_data" options=$years_data}}
|
||||
</div>
|
||||
</dl>
|
||||
</fieldset>
|
||||
|
||||
<p class="submit">
|
||||
{{:button type="submit" name="add" label="Enregistrer" shape="right" class="main"}}
|
||||
{{: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">
|
||||
|
||||
/*
|
||||
afficher la date de fin de l'exercice choisi
|
||||
mettre à jour le numéro d'exercice dans les sélecteur de comptes
|
||||
recalculer le montant de l'amortissement
|
||||
*/
|
||||
function redisplayData(evt,
|
||||
f_immo = 'f_montant_immo',
|
||||
f_duree = 'f_duree_amort',
|
||||
f_amort = 'f_somme_amort',
|
||||
f_years_data = 'f_years_data',
|
||||
f_years_select = 'f_id_year',
|
||||
f_date = 'f_date_amort',
|
||||
f_montant = 'f_montant',
|
||||
f_erreur = 'f_erreur'
|
||||
)
|
||||
{
|
||||
setDateEnd(f_years_select, f_date, f_years_data);
|
||||
setSelectorYear(['credit_account', 'debit_account'], f_years_select);
|
||||
displayAmort(f_immo, f_duree, f_amort, f_years_data, f_years_select, f_montant, f_erreur);
|
||||
}
|
||||
|
||||
function redisplayAmort(evt,
|
||||
f_immo = 'f_montant_immo',
|
||||
f_duree = 'f_duree_amort',
|
||||
f_amort = 'f_somme_amort',
|
||||
f_years_data = 'f_years_data',
|
||||
f_years_select = 'f_id_year',
|
||||
f_date = 'f_date_amort',
|
||||
f_montant = 'f_montant',
|
||||
f_erreur = 'f_erreur'
|
||||
)
|
||||
{
|
||||
displayAmort(f_immo, f_duree, f_amort, f_years_data, f_years_select, f_montant, f_erreur, f_date);
|
||||
}
|
||||
|
||||
(function () {
|
||||
setDateEnd('f_id_year', 'f_date_amort', 'f_years_data');
|
||||
document.getElementById('f_id_year').onchange = redisplayData;
|
||||
document.getElementById('f_date_amort').onchange = redisplayAmort;
|
||||
})();
|
||||
</script>
|
||||
|
11
schema.json
11
schema.json
@ -13,7 +13,16 @@
|
||||
"duration" : {
|
||||
"description": "durée de l'amortissement en années",
|
||||
"type": "integer"
|
||||
},
|
||||
"date" : {
|
||||
"description" : "date de mise en service de l'immobilisation",
|
||||
"type" : ["string", "null"],
|
||||
"format" : "date"
|
||||
},
|
||||
"status" : {
|
||||
"type" : ["string", "null"],
|
||||
"enum" : ["managed", "archived", "ignored"]
|
||||
}
|
||||
},
|
||||
"required": ["type", "line", "duration"]
|
||||
"required": ["type", "line", "duration", "date"]
|
||||
}
|
||||
|
141
scripts.js
Normal file
141
scripts.js
Normal file
@ -0,0 +1,141 @@
|
||||
// activer/désactiver les champs passés en paramètres
|
||||
function toggleInputs(idcb, idfields) {
|
||||
const elem = document.getElementById(idcb);
|
||||
for (let id of idfields) {
|
||||
const field = document.getElementById(id);
|
||||
if (elem.checked) {
|
||||
field.removeAttribute("disabled");
|
||||
}
|
||||
else {
|
||||
field.setAttribute("disabled","disabled");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function toggleVisibility(idcheck, fields) {
|
||||
const elem = document.getElementById(idcheck);
|
||||
for (let id of fields) {
|
||||
const field = document.getElementById(id);
|
||||
if (elem.checked) {
|
||||
field.setAttribute('class', '');
|
||||
} else {
|
||||
field.setAttribute('class', 'hidden');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// fixer l'exercice des sélecteurs de compte
|
||||
function setAccountYear(button_names, id_year) {
|
||||
for (const name of button_names) {
|
||||
const button = document.querySelector("button[data-name=" + name + "]");
|
||||
const b_value = button.value;
|
||||
const new_value = b_value.replace(/id_year=\d+/, 'id_year=' + id_year);
|
||||
button.setAttribute('value', new_value);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* renvoyer la valeur en secondes d'une date au format j/m/a
|
||||
* @param {string} date
|
||||
*/
|
||||
function str2sec(date) {
|
||||
const jma = date.split('/');
|
||||
const dd = new Date(jma[2], jma[1]-1, jma[0]);
|
||||
return dd.getTime()/1000;
|
||||
}
|
||||
|
||||
// renvoyer la valeur en secondes d'un champ date
|
||||
function getDate(idelem) {
|
||||
return str2sec(document.getElementById(idelem).value);
|
||||
}
|
||||
|
||||
// (unused) désactiver les options du sélecteur qui ne sont pas dans un tableau de valeurs
|
||||
function disableOptions(idSelect, init, values) {
|
||||
for (let i = init; i < idSelect.options.length; ++i) {
|
||||
const choix = idSelect.options[i];
|
||||
if (! values.includes(choix.value)) {
|
||||
choix.setAttribute('disabled', 'true');
|
||||
choix.removeAttribute('selected');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// afficher la date de fin de l'exercice choisi
|
||||
function setDateEnd(id_exercices, id_date, id_years) {
|
||||
const selected_year = document.getElementById(id_exercices).value;
|
||||
if (selected_year == '') {
|
||||
document.getElementById(id_date).value = '';
|
||||
return;
|
||||
}
|
||||
const years_data = document.getElementById(id_years);
|
||||
for (const choix of years_data.options) {
|
||||
if (choix.value == selected_year) {
|
||||
const epox = choix.text.split(' ');
|
||||
const date_fin = new Date(epox[1] * 1000);
|
||||
document.getElementById(id_date).value = date_fin.toLocaleDateString();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// renvoyer la valeur numérique d'un montant formaté en €
|
||||
function getNumber(text) {
|
||||
return Number(text.replace(/ /g, '').replace(/,/, '.').replace(/€/, ''));
|
||||
}
|
||||
|
||||
// calculer le montant d'un amortissement
|
||||
// @param montant immo
|
||||
// @param durée immo (années)
|
||||
// @param somme amortissements
|
||||
// @param date début
|
||||
// @param date de fin
|
||||
// @result montant de l'amortissement
|
||||
function computeAmort(montant_immo, duree_immo, somme_amort, date_debut, date_fin) {
|
||||
const nbjours = 1 + (date_fin - date_debut) / (60*60*24);
|
||||
return Math.round(Math.min(montant_immo / duree_immo / 365 * nbjours, montant_immo - somme_amort));
|
||||
}
|
||||
|
||||
// calculer et afficher le montant de l'amortissement
|
||||
function displayAmort(id_immo, id_duree, id_amort, id_years, id_exercices, id_montant, id_erreur, id_date=null)
|
||||
{
|
||||
const div_erreur = document.getElementById(id_erreur);
|
||||
div_erreur.setAttribute('class', 'hidden');
|
||||
// document.getElementById(id_erreur).setAttribute('class', 'hidden');
|
||||
let case_montant = document.getElementById(id_montant);
|
||||
const selected_year = document.getElementById(id_exercices).value;
|
||||
if (selected_year == '') {
|
||||
case_montant.value = '';
|
||||
return;
|
||||
}
|
||||
const years_data = document.getElementById(id_years);
|
||||
let date_debut, date_fin;
|
||||
for (const choix of years_data.options) {
|
||||
if (choix.value == selected_year) {
|
||||
const epox = choix.text.split(' ');
|
||||
date_debut = epox[0];
|
||||
date_fin = epox[1];
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (id_date != null) {
|
||||
const date_choisie = str2sec(document.getElementById(id_date).value);
|
||||
console.log("date_choisie = " + date_choisie + ", date_debut=" + date_debut + ", date_fin = " + date_fin);
|
||||
if (date_debut <= date_choisie && date_choisie <= date_fin) {
|
||||
date_fin = date_choisie;
|
||||
} else {
|
||||
div_erreur.setAttribute('class', '');
|
||||
// document.getElementById(id_erreur).setAttribute('class', '');
|
||||
}
|
||||
}
|
||||
const montant_immo = Number(document.getElementById(id_immo).value);
|
||||
const duree_immo = Number(document.getElementById(id_duree).value);
|
||||
const somme_amort = Number(document.getElementById(id_amort).value);
|
||||
const montant_amort = computeAmort(montant_immo, duree_immo, somme_amort, date_debut, date_fin);
|
||||
case_montant.value = montant_amort/100;
|
||||
case_montant.innerText = montant_amort;
|
||||
}
|
||||
|
||||
function setSelectorYear(button_names, f_years_selector) {
|
||||
const selected_year = document.getElementById(f_years_selector).value;
|
||||
setAccountYear(button_names, selected_year);
|
||||
}
|
43
style.css
Normal file
43
style.css
Normal file
@ -0,0 +1,43 @@
|
||||
.disabled {
|
||||
pointer-events: none;
|
||||
font-style : oblique;
|
||||
}
|
||||
|
||||
.nombre {
|
||||
text-align: right !important;
|
||||
}
|
||||
|
||||
.aide {
|
||||
list-style: revert;
|
||||
padding: revert;
|
||||
line-height : 1.5em;
|
||||
}
|
||||
|
||||
h2[class="aide"], h3[class="aide"] {
|
||||
margin-top: 0.5em;
|
||||
margin-bottom: 0.5em;
|
||||
}
|
||||
|
||||
.informations {
|
||||
margin-top : 0.5em;
|
||||
margin-bottom : 0.5em;
|
||||
padding : 0.5em;
|
||||
}
|
||||
|
||||
.informations legend {
|
||||
font-weight: bold;
|
||||
border-bottom : solid 1px var(--gLightBorderColor);
|
||||
margin-bottom : 0.5em;
|
||||
}
|
||||
|
||||
.informations dt::after {
|
||||
content: ' :';
|
||||
}
|
||||
|
||||
.informations dl.describe > dt {
|
||||
margin-right: 0;
|
||||
}
|
||||
|
||||
nav.amort aside {
|
||||
margin-top : 0;
|
||||
}
|
536
write_exit.html
Normal file
536
write_exit.html
Normal file
@ -0,0 +1,536 @@
|
||||
{{* -*- brindille -*- *}}
|
||||
|
||||
{{*
|
||||
Enregistrer les écritures de sortie du bilan
|
||||
paramètres :
|
||||
- immo_id : numéro de ligne de l'écriture d'immobilisation
|
||||
- amort_amount : montant des amortissements
|
||||
- year : exercice de la date de sortie de l'immobilisation
|
||||
- date_mes : date de mise en service de l'immobilisation
|
||||
- date_debut : date de début de la période d'amortissement complémentaire
|
||||
- exit_date : date de sortie de l'immobilisation
|
||||
- duree_amort : durée de l'amortiseement (optionnel)
|
||||
- cession : montant de la cession (optionnel)
|
||||
*}}
|
||||
|
||||
{{#select
|
||||
line.debit as montant,
|
||||
line.id_transaction,
|
||||
line.id_account,
|
||||
trans.date as date_achat,
|
||||
trans.label,
|
||||
id_project
|
||||
FROM acc_transactions_lines AS line
|
||||
INNER JOIN acc_transactions AS trans ON line.id_transaction = trans.id
|
||||
WHERE line.id = :immo_id;
|
||||
:immo_id = $_GET.immo_id|intval
|
||||
assign="ligne_immo"
|
||||
}}
|
||||
{{/select}}
|
||||
|
||||
{{#load type="immo" assign="info_immo" where="$$.line = :line_id" :line_id=$_GET.immo_id|intval}}
|
||||
{{/load}}
|
||||
|
||||
{{* date de début de l'exercice *}}
|
||||
{{#select start_date FROM acc_years WHERE id = :year_id; :year_id = $_GET.year}}
|
||||
{{*:assign date_debut=$start_date*}}
|
||||
{{/select}}
|
||||
|
||||
{{*if $date_debut < "2025-01-01"*}}
|
||||
{{:assign vnc_code=675}}
|
||||
{{:assign cession_code=775}}
|
||||
{{*
|
||||
{{else}}
|
||||
{{:assign vnc_code=657}}
|
||||
{{:assign cession_code=757}}
|
||||
{{/if}}
|
||||
*}}
|
||||
|
||||
{{:assign valeur_nette="%f-%f"|math:$ligne_immo.montant:$_GET.amort_amount}}
|
||||
{{:assign amort_comp=0}} {{* amortissement complémentaire jqà date sortie *}}
|
||||
{{:assign amort_except=0}} {{* amortissement exceptionnel jqà date fin amortissement *}}
|
||||
{{if $valeur_nette > 0}}
|
||||
{{:assign nbjours="1+(%d-%d)/(60*60*24)"|math:$_GET.exit_date:$_GET.date_debut}}
|
||||
{{:assign annuite="%f/%f"|math:$ligne_immo.montant:$_GET.duree_amort}}
|
||||
{{:assign amort_comp="round(%f/365*%f, 0)"|math:$annuite:$nbjours}}
|
||||
{{:assign amort_comp="min(%f, %f)"|math:$valeur_nette:$amort_comp}}
|
||||
|
||||
{{if $_GET.cession == null}}
|
||||
{{:assign amort_except="%f-%f-%f"|math:$ligne_immo.montant:$_GET.amort_amount:$amort_comp}}
|
||||
{{/if}}
|
||||
{{/if}}
|
||||
|
||||
{{if $_GET.cession == null}}
|
||||
{{:assign montant_cession=0}}
|
||||
{{else}}
|
||||
{{:assign montant_cession="%f*100"|math:$_GET.cession}}
|
||||
{{/if}}
|
||||
|
||||
{{* TODO : faut-il forcer les 3 sélecteurs de compte d'amortissement à avoir toujours la même valeur ? *}}
|
||||
|
||||
|
||||
{{* Traiter l'envoi du formulaire *}}
|
||||
{{#form on="save"}}
|
||||
{{*
|
||||
{{if $_POST.amort_comp_account != null}
|
||||
{{:assign account=$_POST.amort_comp_account}}
|
||||
{{elseif $_POST.amort_except_account != null}
|
||||
{{:assign account=$_POST.amort_except_account}}
|
||||
{{elseif $_POST.amort_sortie_account != null}
|
||||
{{:assign account=$_POST.amort_sortie_account}}
|
||||
{{/if}}
|
||||
*}}
|
||||
{{:assign account=$_POST.amort_sortie_account}}
|
||||
|
||||
{{:include
|
||||
file="_get_codes.html"
|
||||
account=$account
|
||||
keep="account_code"
|
||||
}}
|
||||
{{:assign amort_account=$account_code|keys|key:0}}
|
||||
|
||||
{{if $valeur_nette > 0}}
|
||||
{{* immo non totalement amortie *}}
|
||||
|
||||
{{* lignes d'écriture de l'amortissement complémentaire *}}
|
||||
{{:include
|
||||
file="_get_codes.html"
|
||||
account=$_POST.comp_account
|
||||
keep="account_code"
|
||||
}}
|
||||
{{:assign comp_account=$account_code|keys|key:0}}
|
||||
|
||||
{{:assign libelle="Amortissement complémentaire "|cat:$ligne_immo.label}}
|
||||
{{:assign
|
||||
var="lines."
|
||||
debit="%f/100"|math:$amort_comp
|
||||
account=$comp_account
|
||||
id_project=$ligne_immo.id_project
|
||||
label=$libelle
|
||||
}}
|
||||
{{:assign
|
||||
var="lines."
|
||||
credit="%f/100"|math:$amort_comp
|
||||
account=$amort_account
|
||||
id_project=$ligne_immo.id_project
|
||||
label=$libelle
|
||||
}}
|
||||
{{:assign valeur_nette="%f-%f"|math:$valeur_nette:$amort_comp}}
|
||||
|
||||
{{if $_GET.cession == null && $amort_except > 0}}
|
||||
{{* lignes d'écriture de l'amortissement exceptionnel *}}
|
||||
{{:include
|
||||
file="_get_codes.html"
|
||||
account=$_POST.except_account
|
||||
keep="account_code"
|
||||
}}
|
||||
{{:assign except_account=$account_code|keys|key:0}}
|
||||
{{:assign libelle="Amortissement exceptionnel "|cat:$ligne_immo.label}}
|
||||
{{:assign
|
||||
var="lines."
|
||||
debit="%f/100"|math:$amort_except
|
||||
account=$except_account
|
||||
id_project=$ligne_immo.id_project
|
||||
label=$libelle
|
||||
}}
|
||||
{{:assign
|
||||
var="lines."
|
||||
credit="%f/100"|math:$amort_except
|
||||
account=$amort_account
|
||||
id_project=$ligne_immo.id_project
|
||||
label=$libelle
|
||||
}}
|
||||
{{:assign valeur_nette="%f-%f"|math:$valeur_nette:$amort_except}}
|
||||
{{/if}}
|
||||
|
||||
{{:api
|
||||
method="POST"
|
||||
path="accounting/transaction"
|
||||
assign="result"
|
||||
assign_code="result_code"
|
||||
id_year=$_GET.year
|
||||
type="advanced"
|
||||
date=$_GET.exit_date
|
||||
label="Amortissement final "|cat:$ligne_immo.label
|
||||
lines=$lines
|
||||
linked_transactions=$ligne_immo.id_transaction
|
||||
}}
|
||||
{{/if}}
|
||||
|
||||
{{* écriture de sortie du bilan *}}
|
||||
{{:assign libelle="Sortie du bilan de "|cat:$ligne_immo.label}}
|
||||
{{:assign lines=null}}
|
||||
{{:assign
|
||||
var="lines."
|
||||
id_account=$ligne_immo.id_account
|
||||
credit="%f/100"|math:$ligne_immo.montant
|
||||
id_project=$ligne_immo.id_project
|
||||
label=$libelle
|
||||
}}
|
||||
{{:assign
|
||||
var="lines."
|
||||
account=$amort_account
|
||||
debit="(%f-%f)/100"|math:$ligne_immo.montant:$valeur_nette
|
||||
id_project=$ligne_immo.id_project
|
||||
label=$libelle
|
||||
}}
|
||||
{{if $valeur_nette > 0}}
|
||||
{{:assign
|
||||
var="lines."
|
||||
account=$vnc_code
|
||||
debit="%f/100"|math:$valeur_nette
|
||||
id_project=$ligne_immo.id_project
|
||||
label=$libelle
|
||||
}}
|
||||
{{/if}}
|
||||
|
||||
{{:api
|
||||
method="POST"
|
||||
path="accounting/transaction"
|
||||
assign="result"
|
||||
assign_code="result_code"
|
||||
id_year=$_GET.year
|
||||
type="advanced"
|
||||
date=$_GET.exit_date
|
||||
label=$libelle
|
||||
lines=$lines
|
||||
linked_transactions=$ligne_immo.id_transaction
|
||||
}}
|
||||
|
||||
{{if $montant_cession > 0}}
|
||||
{{* Cession de l'immobilisation *}}
|
||||
{{:assign libelle="Produit cession "|cat:$ligne_immo.label}}
|
||||
{{:include
|
||||
file="_get_codes.html"
|
||||
account=$_POST.creance_account
|
||||
keep="account_code"
|
||||
}}
|
||||
{{:assign creance_account=$account_code|keys|key:0}}
|
||||
{{:include
|
||||
file="_get_codes.html"
|
||||
account=$_POST.cession_account
|
||||
keep="account_code"
|
||||
}}
|
||||
{{:assign cession_account=$account_code|keys|key:0}}
|
||||
{{:api
|
||||
method="POST"
|
||||
path="accounting/transaction"
|
||||
assign="result"
|
||||
assign_code="result_code"
|
||||
id_year=$_GET.year
|
||||
type="credit"
|
||||
date=$_GET.exit_date
|
||||
label=$libelle
|
||||
amount="%f/100"|math:$montant_cession
|
||||
debit=$creance_account
|
||||
credit=$cession_account
|
||||
id_project=$ligne_immo.id_project
|
||||
linked_transactions=$ligne_immo.id_transaction
|
||||
}}
|
||||
{{/if}}
|
||||
|
||||
{{if $info_immo != null}}
|
||||
{{* mettre à jour l'état de l'immobilisation *}}
|
||||
{{:save
|
||||
key=$info_immo.key
|
||||
status="archived"
|
||||
}}
|
||||
{{else}}
|
||||
{{:save
|
||||
key=""|uuid
|
||||
validate_schema="schema.json"
|
||||
type="immo"
|
||||
line=$_GET.immo_id|intval
|
||||
duration=$_GET.duree_amort|intval
|
||||
date=$_GET.date_mes|date:"Y-m-d"
|
||||
status="archived"
|
||||
}}
|
||||
{{/if}}
|
||||
|
||||
{{:redirect to="index.html?amort=archive"}}
|
||||
{{/form}}
|
||||
|
||||
{{:admin_header title="Sortie du bilan" custom_css="./style.css" current="module_amortissement"}}
|
||||
|
||||
{{* barre de navigation *}}
|
||||
{{if ! $dialog}}
|
||||
{{:include file="_nav.html" current="index" subsubcurrent="balance_exit"}}
|
||||
{{/if}}
|
||||
{{:form_errors}}
|
||||
|
||||
{{* Préparer les infos pour le formulaire *}}
|
||||
|
||||
{{* déterminer les comptes pour les différentes écritures *}}
|
||||
{{:assign var="comp_account.6811" value="6811 — Dot. aux amortissements des immobilisations"}}
|
||||
{{:assign var="except_account.687" value="687 — Dot. aux amortissements & provisions - Charges exceptionnelles"}}
|
||||
|
||||
{{#select code, label from acc_accounts where id = :id;
|
||||
:id=$ligne_immo.id_account
|
||||
assign=immo_account_info
|
||||
}}
|
||||
{{/select}}
|
||||
|
||||
{{:include
|
||||
file="./_get_amort_code.html"
|
||||
code_immo=$immo_account_info.code
|
||||
keep="code_amort"
|
||||
}}
|
||||
{{:assign
|
||||
var="amort_account.%s"|args:$code_amort
|
||||
value="%s — Amortissements "|args:$code_amort|cat:$immo_account_info.label}}
|
||||
{{:assign
|
||||
var="immo_account.%s"|args:$immo_account_info.code
|
||||
value="%s — Immobilisation "|args::$immo_account_info.code|cat:$immo_account_info.label}}
|
||||
{{:assign
|
||||
var="vnc_account.%s"|args:$vnc_code
|
||||
value="%s — Valeurs comptables des éléments d'actifs cédés"|args:$vnc_code}}
|
||||
{{:assign
|
||||
var="cession_account.%s"|args:$cession_code
|
||||
value="%s — Produits des cessions d'actif"|args:$cession_code}}
|
||||
{{:assign var="creance_account.462" value="462 — Créances sur cessions d'immobilisations"}}
|
||||
|
||||
{{:read file="./defaut.json" assign="config_json"}}
|
||||
{{:assign config_defaut=$config_json|json_decode}}
|
||||
{{:assign var="prefix_array" value=$config_defaut.prefixes|keys}}
|
||||
|
||||
{{#foreach from=$prefix_array item="code"}}
|
||||
{{:assign var="pattern_array." value="%s*"|args:$code}}
|
||||
{{/foreach}}
|
||||
{{:assign patterns=$pattern_array|implode:"|"}}
|
||||
|
||||
<h3>Sortir l'immobilisation « {{$ligne_immo.label}} » du bilan</h3>
|
||||
<form method="post" action="">
|
||||
|
||||
<div class="informations">
|
||||
<legend>Données de l'imobilisation</legend>
|
||||
<dl class="describe">
|
||||
<dt>Montant</dt>
|
||||
<dd class="money">{{$ligne_immo.montant|money_currency:false}}</dd>
|
||||
<dt>Date d'acquisition</dt>
|
||||
<dd >{{$ligne_immo.date_achat|date_short}}</dd>
|
||||
{{if $_GET.date_mes != $ligne_immo.date_achat|strtotime}}
|
||||
<dt>Date de mise en service</dt>
|
||||
<dd>{{$_GET.date_mes|date:"d/m/Y"}}</dd>
|
||||
{{/if}}
|
||||
{{if $_GET.duree_amort != null}}
|
||||
<dt>Durée de l'amortissement</dt>
|
||||
<dd class="num">{{$_GET.duree_amort}} ans</dd>
|
||||
{{/if}}
|
||||
<dt>Montant des amortissements</dt>
|
||||
<dd class="money">{{$_GET.amort_amount|money_currency:false}} <span class="help">(à la date de début de l'exercice)</span></dd>
|
||||
<dt>Valeur nette résiduelle</dt>
|
||||
<dd class="money">{{$valeur_nette|money_currency:false}} <span class="help">(à la date de début de l'exercice)</span></dd>
|
||||
<dt>Date de sortie</dt>
|
||||
<dd>{{$_GET.exit_date|date:"d/m/Y"}}</dd>
|
||||
{{if $amort_comp > 0}}
|
||||
{{:assign valeur_nette="%f-%f"|math:$valeur_nette:$amort_comp}}
|
||||
<dt>Amortissement complémentaire</dt>
|
||||
<dd class="money">{{$amort_comp|money_currency:false}} <span class="help">(jusqu'à la date de sortie)</span></dd>
|
||||
<dt>Total des amortissements</dt>
|
||||
<dd class="money">{{"%f+%f"|math:$_GET.amort_amount:$amort_comp|money_currency:false}} <span class="help">(à la date de sortie)</span></dd>
|
||||
<dt>Valeur nette résiduelle</dt>
|
||||
<dd class="money">{{$valeur_nette|money_currency:false}} <span class="help">(à la date de sortie)</span></dd>
|
||||
{{/if}}
|
||||
{{if $montant_cession == 0}}
|
||||
{{if $amort_except > 0}}
|
||||
<dt>Amortissement exceptionnel</dt>
|
||||
<dd class="money">{{$amort_except|money_currency:false}}</dd>
|
||||
{{/if}}
|
||||
{{else}}
|
||||
<dt>Montant de la cession</dt>
|
||||
<dd class="money">{{$montant_cession|money_currency:false}}</dd>
|
||||
{{/if}}
|
||||
</dl>
|
||||
</div>
|
||||
|
||||
<fieldset>
|
||||
<legend>Écritures de sortie du bilan</legend>
|
||||
{{* Amortissement complémentaire *}}
|
||||
{{if $amort_comp > 0}}
|
||||
<table class="list">
|
||||
<thead>
|
||||
<tr>
|
||||
<td>Amortissement complémentaire</td>
|
||||
<td>Débit</td>
|
||||
<td>Crédit</td>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td colspan="3" class="help">
|
||||
Entre la date de début de l'exercice et la date de sortie du bilan
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
{{:input
|
||||
type="list"
|
||||
name="comp_account"
|
||||
target="!acc/charts/accounts/selector.php?codes=%s&year=%d"|args:"68*":$_GET.year
|
||||
default=$comp_account
|
||||
}}
|
||||
</td>
|
||||
<td>{{$amort_comp|money_currency:false}}</td>
|
||||
<td></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
{{:input
|
||||
type="list"
|
||||
name="amort_comp_account"
|
||||
target="!acc/charts/accounts/selector.php?codes=%s&year=%d"|args:"28*":$_GET.year
|
||||
default=$amort_account
|
||||
}}
|
||||
</td>
|
||||
<td></td>
|
||||
<td>{{$amort_comp|money_currency:false}}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
{{/if}}
|
||||
|
||||
{{* Amortissement exceptionnel *}}
|
||||
{{if $montant_cession == 0 && $amort_except > 0}}
|
||||
<table class="list">
|
||||
<thead>
|
||||
<tr>
|
||||
<td>Amortissement exceptionnel</td>
|
||||
<td>Débit</td>
|
||||
<td>Crédit</td>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td colspan="3" class="help">
|
||||
Montant de l'immobilisation non encore amortie (valeur nette résiduelle à la date de sortie)
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
{{:input
|
||||
type="list"
|
||||
name="except_account"
|
||||
target="!acc/charts/accounts/selector.php?codes=%s&year=%d"|args:"687*":$_GET.year
|
||||
default=$except_account
|
||||
}}
|
||||
</td>
|
||||
<td>{{$amort_except|money_currency:false}}</td>
|
||||
<td></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
{{:input
|
||||
type="list"
|
||||
name="amort_except_account"
|
||||
target="!acc/charts/accounts/selector.php?codes=%s&year=%d"|args:"28*":$_GET.year
|
||||
default=$amort_account
|
||||
}}
|
||||
</td>
|
||||
<td></td>
|
||||
<td>{{$amort_except|money_currency:false}}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
{{/if}}
|
||||
|
||||
{{* Sortie du bilan *}}
|
||||
<table class="list">
|
||||
<thead>
|
||||
<tr>
|
||||
<td>Sortie du bilan</td>
|
||||
<td>Débit</td>
|
||||
<td>Crédit</td>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>
|
||||
{{:input
|
||||
type="list"
|
||||
name="amort_sortie_account"
|
||||
target="!acc/charts/accounts/selector.php?codes=%s&year=%d"|args:"28*":$_GET.year
|
||||
default=$amort_account
|
||||
}}
|
||||
</td>
|
||||
{{if $montant_cession == 0}}
|
||||
{{:assign montant=$ligne_immo.montant}}
|
||||
{{else}}
|
||||
{{:assign montant="%f+%f"|math:$_GET.amort_amount:$amort_comp}}
|
||||
{{/if}}
|
||||
<td>{{$montant|money_currency:false}}</td>
|
||||
<td></td>
|
||||
</tr>
|
||||
{{if $montant_cession > 0 && $valeur_nette > 0}}
|
||||
<tr>
|
||||
<td>
|
||||
{{:input
|
||||
type="list"
|
||||
name="vnc_account"
|
||||
target="!acc/charts/accounts/selector.php?codes=%s*&year=%d"|args:$vnc_code:$_GET.year
|
||||
default=$vnc_account
|
||||
}}
|
||||
</td>
|
||||
<td>{{$valeur_nette|money_currency:false}}</td>
|
||||
<td></td>
|
||||
</tr>
|
||||
{{/if}}
|
||||
<tr>
|
||||
<td> {{* style="pointer-events: none; opacity: 0.6;">*}}
|
||||
{{:input
|
||||
type="list"
|
||||
name="immo_account"
|
||||
target="!acc/charts/accounts/selector.php?codes=%s&year=%d"|args:$patterns:$_GET.year
|
||||
default=$immo_account
|
||||
}}
|
||||
</td>
|
||||
<td></td>
|
||||
<td>{{$ligne_immo.montant|money_currency:false}}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
{{* comptabilisation du produit de la cession *}}
|
||||
{{if $montant_cession > 0}}
|
||||
<table class="list">
|
||||
<thead>
|
||||
<tr>
|
||||
<td>Comptabilisation de la cession</td>
|
||||
<td>Débit</td>
|
||||
<td>Crédit</td>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>
|
||||
{{:input
|
||||
type="list"
|
||||
name="creance_account"
|
||||
target="!acc/charts/accounts/selector.php?codes=%s&year=%d"|args:"462*":$_GET.year
|
||||
default=$creance_account
|
||||
}}
|
||||
</td>
|
||||
<td>{{$montant_cession|money_currency:false}}</td>
|
||||
<td></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
{{:input
|
||||
type="list"
|
||||
name="cession_account"
|
||||
target="!acc/charts/accounts/selector.php?codes=%s*&year=%d"|args:$cession_code:$_GET.year
|
||||
default=$cession_account
|
||||
}}
|
||||
</td>
|
||||
<td></td>
|
||||
<td>{{$montant_cession|money_currency:false}}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
{{/if}}
|
||||
</fieldset>
|
||||
|
||||
<p class="submit">
|
||||
{{:button type="submit" name="save" label="Enregistrer" shape="right" class="main"}}
|
||||
</p>
|
||||
</form>
|
||||
{{:admin_footer}}
|
Loading…
Reference in New Issue
Block a user