Version initiale
This commit is contained in:
commit
c03cd6e7ae
27
_calcul_dates.html
Normal file
27
_calcul_dates.html
Normal file
@ -0,0 +1,27 @@
|
||||
{{*
|
||||
Calcule le nombre de jours entre deux dates
|
||||
paramètres :
|
||||
- date_debut
|
||||
- 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}}
|
6
_nav.html
Normal file
6
_nav.html
Normal file
@ -0,0 +1,6 @@
|
||||
<nav class="tabs">
|
||||
<ul>
|
||||
<li {{if $current == 'index'}} class="current"{{/if}}><a href="{{$module.url}}index.html">Immobilisations</a></li>
|
||||
<li {{if $current == 'amortissements'}} class="current"{{/if}}><a href="{{$module.url}}/amortissements.html">Amortissements</a></li>
|
||||
</ul>
|
||||
</nav>
|
148
amortization.html
Normal file
148
amortization.html
Normal file
@ -0,0 +1,148 @@
|
||||
{{:admin_header title="Gestion des amortissements" custom_css=$custom_css current="module_amortissement"}}
|
||||
|
||||
{{* barre de navigation *}}
|
||||
{{:include file="_nav.html" current="amortissements"}}
|
||||
|
||||
{{* récupérer les infos de l'immobilisation *}}
|
||||
{{#load type="immo" assign="info_immo" where="$$.line = :line_id" :line_id=$_GET.line|intval}}
|
||||
{{else}}
|
||||
{{:assign message="Immobilisation %s non trouvée"|args:$_GET.line}}
|
||||
{{:error message=$message}}
|
||||
{{/load}}
|
||||
|
||||
{{*
|
||||
["info_immo"]=> array(5) {
|
||||
["id"]=> int(3)
|
||||
["key"]=> string(36) "e0b5a8ab-b123-48ca-9a4c-8f623315818b"
|
||||
["type"]=> string(4) "immo"
|
||||
["line"]=> int(3890)
|
||||
["duration"]=> int(5)
|
||||
}
|
||||
*}}
|
||||
|
||||
{{#select
|
||||
line.id as line_id,
|
||||
trans.id as trans_id,
|
||||
line.debit as montant,
|
||||
trans.label as label,
|
||||
trans.date as date_achat,
|
||||
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
|
||||
}}
|
||||
<h3>Amortissement de « {{$label}} » d'un montant de {{"%f"|math:$montant|money_currency}} en date du {{$date_achat|date_short}}</h3>
|
||||
{{else}}
|
||||
{{:assign message="Immobilisation %s non trouvée"|args:$_GET.line}}
|
||||
{{:error message=$message}}
|
||||
{{/select}}
|
||||
|
||||
{{* calculer les amortissements *}}
|
||||
{{* :debug montant=$ligne_immo.montant *}}
|
||||
{{* montant de l'annuité normale *}}
|
||||
{{:assign montant="%d"|math:$ligne_immo.montant|money}}
|
||||
{{:assign annuite="%d/%d"|math:$montant:$info_immo.duration|intval}}
|
||||
{{* :debug annuite=$annuite *}}
|
||||
|
||||
{{* 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="%d/360*%d"|math:$annuite:$nbjours|intval}}
|
||||
{{* :debug annuite1=$annuite_1 *}}
|
||||
|
||||
{{:assign date_immo=$date_fin}}
|
||||
{{:assign annuite_courante=$annuite_1}}
|
||||
{{:assign solde=$montant}}
|
||||
|
||||
<table class="list">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>N°</th>
|
||||
<th>Date</th>
|
||||
<th>Annuité</th>
|
||||
<th>Solde</th>
|
||||
<th class="actions"></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{{#foreach count="%d+1"|math:$info_immo.duration|intval key="num"}}
|
||||
{{:assign solde="%d-%d"|math:$solde:$annuite_courante}}
|
||||
<tr>
|
||||
<td>{{"%d+1"|math:$num}}</td>
|
||||
<td>{{$date_immo}}</td>
|
||||
<td class="money">{{"%f*100"|math:$annuite_courante|money}}</td>
|
||||
<td class="money">{{"%f*100"|math:$solde|money}}</td>
|
||||
</tr>
|
||||
{{:assign annuite_courante="min(%d,%d)"|math:$annuite:$solde}}
|
||||
{{: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}}
|
||||
{{* :debug date_immo=$date_immo *}}
|
||||
{{/foreach}}
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<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>Libellé</th>
|
||||
<th>ligne amort</th>
|
||||
<th>Compte</th>
|
||||
<th>Nom compte</th>
|
||||
<th class="actions"></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{{#select
|
||||
line.id as l_immo,
|
||||
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 compte,
|
||||
trans.date as date_achat,
|
||||
acc.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}}
|
||||
<tr>
|
||||
<td class="num"><a href={{$trans_url}}>#{{$trans_id}}</a></td>
|
||||
<td>{{$date_achat|date_short}}</td>
|
||||
<td class="money">{{"%f"|math:$montant|money}}</td>
|
||||
<td>{{$libelle}}</td>
|
||||
<td>{{$l_amort}}</td>
|
||||
<td>{{$compte}}</td>
|
||||
<td>{{$nom_compte}}</td>
|
||||
<td></td>
|
||||
</tr>
|
||||
{{/select}}
|
||||
</tbody>
|
||||
</table>
|
||||
</section>
|
||||
{{* :debug lines=$lines *}}
|
||||
{{* :form_errors *}}
|
||||
{{:admin_footer}}
|
106
asset.html
Normal file
106
asset.html
Normal file
@ -0,0 +1,106 @@
|
||||
{{:admin_header title="Ajout immobilisation" current="module_amortissement"}}
|
||||
|
||||
{{* barre de navigation *}}
|
||||
{{if ! $dialog}}
|
||||
{{:include file="_nav.html" current="index"}}
|
||||
{{/if}}
|
||||
|
||||
{{* Traiter l'envoi du formulaire *}}
|
||||
{{#form on="add"}}
|
||||
{{* :debug POST=$_POST *}}
|
||||
|
||||
{{* 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
|
||||
label=$_POST.designation
|
||||
amount=$_POST.montant
|
||||
debit=$debit_account
|
||||
credit=$credit_account
|
||||
}}
|
||||
|
||||
{{* :debug result=$result *}}
|
||||
|
||||
{{* 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
|
||||
}}
|
||||
|
||||
{{: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}}
|
||||
{{/years}}
|
||||
|
||||
{{* formulaire d'ajout d'immobilisation *}}
|
||||
|
||||
{{*
|
||||
TODO
|
||||
- ajouter projet et autres rubriques selon besoin
|
||||
*}}
|
||||
|
||||
<form method="post" action="">
|
||||
<fieldset class="ajout_immo">
|
||||
<legend>Ajouter une 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="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
|
||||
}}
|
||||
{{:input
|
||||
type="list"
|
||||
name="debit_account"
|
||||
label="Compte d'immobilisation (20xx ou 21xx)"
|
||||
required=true
|
||||
target="!acc/charts/accounts/selector.php?key=code&year=%d"|args:$best_year
|
||||
}}
|
||||
</dl>
|
||||
</fieldset>
|
||||
|
||||
<p class="submit">
|
||||
{{:button type="submit" name="add" label="Ajouter" shape="right" class="main"}}
|
||||
</p>
|
||||
|
||||
</form>
|
||||
|
||||
|
||||
{{:admin_footer}}
|
129
index.html
Normal file
129
index.html
Normal file
@ -0,0 +1,129 @@
|
||||
{{:admin_header title="Gestion des amortissements" custom_css=$custom_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}}
|
||||
|
||||
|
||||
{{* lister les immobilisations *}}
|
||||
<section class="immobilisation">
|
||||
<h2 class="ruler">Liste des immobilisations</h2>
|
||||
|
||||
<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
|
||||
*}}
|
||||
|
||||
{{#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>
|
||||
|
||||
<form method="post" action="">
|
||||
<fieldset>
|
||||
<legend>Ajouter une immobilisation</legend>
|
||||
<p class="submit">
|
||||
{{:linkbutton
|
||||
label="Ajouter une immobilisation"
|
||||
shape="plus"
|
||||
href="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>
|
||||
|
||||
{{:admin_footer}}
|
8
module.ini
Normal file
8
module.ini
Normal file
@ -0,0 +1,8 @@
|
||||
name="Gestion des amortissements"
|
||||
description="Gestion des amortissements : ..."
|
||||
author="Jean-Christophe Engel"
|
||||
author_url="https://git.roflcopter.fr/lesanges"
|
||||
home_button=false
|
||||
menu=true
|
||||
restrict_section="accounting"
|
||||
restrict_level="write"
|
19
schema.json
Normal file
19
schema.json
Normal file
@ -0,0 +1,19 @@
|
||||
{
|
||||
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"type": {
|
||||
"type": "string",
|
||||
"enum": ["immo"]
|
||||
},
|
||||
"line" : {
|
||||
"description": "id ligne écriture de l'immobilisation",
|
||||
"type": "integer"
|
||||
},
|
||||
"duration" : {
|
||||
"description": "durée de l'amortissement en années",
|
||||
"type": "integer"
|
||||
}
|
||||
},
|
||||
"required": ["type", "line", "duration"]
|
||||
}
|
Loading…
Reference in New Issue
Block a user