commit c03cd6e7ae2a94136304e7612ef207fa084b6bb1 Author: Jean-Christophe Engel Date: Thu Feb 15 14:23:03 2024 +0100 Version initiale diff --git a/_calcul_dates.html b/_calcul_dates.html new file mode 100644 index 0000000..b02b00d --- /dev/null +++ b/_calcul_dates.html @@ -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}} diff --git a/_nav.html b/_nav.html new file mode 100644 index 0000000..cc34387 --- /dev/null +++ b/_nav.html @@ -0,0 +1,6 @@ + diff --git a/amortization.html b/amortization.html new file mode 100644 index 0000000..765de72 --- /dev/null +++ b/amortization.html @@ -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 +}} +

Amortissement de « {{$label}} » d'un montant de {{"%f"|math:$montant|money_currency}} en date du {{$date_achat|date_short}}

+{{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}} + + + + + + + + + + + + + {{#foreach count="%d+1"|math:$info_immo.duration|intval key="num"}} + {{:assign solde="%d-%d"|math:$solde:$annuite_courante}} + + + + + + + {{: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}} + +
DateAnnuitéSolde
{{"%d+1"|math:$num}}{{$date_immo}}{{"%f*100"|math:$annuite_courante|money}}{{"%f*100"|math:$solde|money}}
+ +
+

Liste des amortissements

+ + + + + + + + + + + + + + + + {{#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}} + + + + + + + + + + + {{/select}} + +
DateMontantLibelléligne amortCompteNom compte
#{{$trans_id}}{{$date_achat|date_short}}{{"%f"|math:$montant|money}}{{$libelle}}{{$l_amort}}{{$compte}}{{$nom_compte}}
+
+{{* :debug lines=$lines *}} +{{* :form_errors *}} +{{:admin_footer}} diff --git a/asset.html b/asset.html new file mode 100644 index 0000000..c2bf56a --- /dev/null +++ b/asset.html @@ -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 +*}} + +
+
+ Ajouter une immobilisation +
+ {{: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 + }} +
+
+ +

+ {{:button type="submit" name="add" label="Ajouter" shape="right" class="main"}} +

+ +
+ + +{{:admin_footer}} diff --git a/index.html b/index.html new file mode 100644 index 0000000..4d42cc9 --- /dev/null +++ b/index.html @@ -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}} +

Modification effectuée

+{{elseif $_GET.err}} +

Modification refusée

+{{/if}} + + +{{* lister les immobilisations *}} +
+

Liste des immobilisations

+ + + + + + + + + + + + + + + + {{* + 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}} + + + + + + + + + + + {{/select}} + +
IdLibelléDateid_lineN° compteCompteMontant
#{{$trans_id}}{{$trans_label}}{{$trans_date|date_short}}{{$line_id}}{{$account_code}}{{$account_label}}{{"%f"|math:$debit|money}} + {{:linkbutton + label="Amortissements" + href="amortization.html?line=%s"|args:$line_id + shape="table" + }} +
+
+ +
+
+ Ajouter une immobilisation +

+ {{:linkbutton + label="Ajouter une immobilisation" + shape="plus" + href="asset.html" + }} +

+
+
+ + +{{* sélectionner un compte *}} +

TEST

+ +{{: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" +}} + +
+
+ Écriture de note de frais + {{: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 + }} +
+
+ +{{:admin_footer}} diff --git a/module.ini b/module.ini new file mode 100644 index 0000000..8204f2c --- /dev/null +++ b/module.ini @@ -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" diff --git a/schema.json b/schema.json new file mode 100644 index 0000000..c2e3b34 --- /dev/null +++ b/schema.json @@ -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"] +}