From 885f7372335ae5518f30dd20ea90703d349c31cb Mon Sep 17 00:00:00 2001 From: Jean-Christophe Engel Date: Thu, 14 Mar 2024 18:34:45 +0100 Subject: [PATCH] =?UTF-8?q?Prise=20en=20compte=20exercices=20sur=202=20ann?= =?UTF-8?q?=C3=A9es=20civiles?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 1 + amortization.html | 88 +++++++++++++++++++++++------------------------ module.ini | 2 +- save_amort.html | 13 +++++-- 4 files changed, 56 insertions(+), 48 deletions(-) diff --git a/README.md b/README.md index f382aea..3316ecb 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,7 @@ # Module de gestion d'amortissements pour Paheko 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 : diff --git a/amortization.html b/amortization.html index 0f352d2..9ea65da 100644 --- a/amortization.html +++ b/amortization.html @@ -24,27 +24,18 @@ {{/if}} {{* récupérer les infos de l'immobilisation *}} -{{#load type="immo" assign="info_immo" where="$$.line = :line_id" :line_id=$_GET.line_id|intval}} -{{else}} - {{:assign message="Pas d'info concernant l'immobilisation %s"|args:$_GET.line_id}} - {{:error message=$message}} -{{/load}} - -{{* liste de toutes les immobilisations gérées *}} -{{#load type="immo"}} - {{:assign - var="info_immos.%s"|args:$line - duration=$duration - amort=$amort - }} +{{#load type="immo" assign="info_immo" where="$$.line = :line_id" :line_id=$_GET.immo_id|intval}} {{#foreach from=$amort item="elem"}} {{:assign var="amort_associes." value=$elem"}} {{/foreach}} +{{else}} + {{:assign message="Pas d'info concernant l'immobilisation %s"|args:$_GET.immo_id}} + {{:error message=$message}} {{/load}} -{{:assign var="duree" from="info_immos.%s.duration"|args:$_GET.line_id}} +{{:assign var="duree" from="info_immo.duration"|args:$_GET.immo_id}} {{#select - line.id as line_id, + line.id as immo_id, line.id_account as account_id, line.id_project as project_id, line.debit as montant, @@ -52,59 +43,67 @@ trans.label as label, trans.date as date_achat, y.id as year_id, - y.end_date as date_fin, + date(y.start_date, "start of year", "+1 year", "-1 day") as date_amort, 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.line_id|intval + :line_id = $_GET.immo_id|intval assign=ligne_immo }}

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

{{else}} - {{:assign message="Immobilisation %s non trouvée"|args:$_GET.line_id}} + {{:assign message="Immobilisation %s non trouvée"|args:$_GET.immo_id}} {{:error message=$message}} {{/select}} +{{*:debug ligne_immo=$ligne_immo*}} + {{* chercher des écritures d'amortissement liées à l'immobilisation *}} {{#select - l_immo.id, - l_immo.id_account, l_amort.credit as amort_amount, l_amort.label as amort_label, l_amort.id as amort_line, - l_amort.id_transaction as amort_trans_id, - l_amort.id_project as projet, - l_amort.id_account as account_id, - l_amort.id_project as project_id, - project.label as project_label, + CASE links.id_related = t_immo.id + WHEN true THEN links.id_transaction + WHEN false THEN links.id_related + END as amort_trans_id, trans.date as amort_date, trans.label as trans_label, trans.id_year as amort_year, acc.code as account_code, acc.label as account_name, - acc.id_chart as PC, "vrai" as linked - from acc_transactions_lines as l_immo - inner JOIN acc_transactions_links as links on l_immo.id_transaction = links.id_related - inner JOIN acc_transactions_lines as l_amort on links.id_transaction = l_amort.id_transaction - inner join acc_accounts as acc on l_amort.id_account = acc.id - inner join acc_transactions as trans on l_amort.id_transaction = trans.id - inner join acc_projects AS project ON l_immo.id_project = project.id - where l_immo.id = :line_id and l_amort.credit <> 0 - order by trans.date; - :line_id = $_GET.line_id|intval + 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 acc on l_amort.id_account = acc.id + WHERE + l_immo.id = :line_id + AND + l_amort.credit <> 0 + ORDER BY trans.date; + :line_id = $_GET.immo_id|intval assign=linked_lines. }} {{:assign var="amort_associes." value=$amort_line}} {{:assign var="amort_years." value=$amort_year}} {{/select}} +{{*:debug linked_lines=$linked_lines amort_associes=$amort_associes*}} + {{* chercher parmi les associations *}} -{{:assign var="liste_amort" from="info_immos.%s.amort"|args:$_GET.line_id}} -{{#foreach from=$liste_amort item="id_amort"}} +{{#foreach from=$info_immo.amort item="id_amort"}} {{#select l_amort.id_transaction as amort_trans_id, l_amort.credit as amort_amount, @@ -139,17 +138,18 @@ {{/select}} {{/foreach}} +{{*:debug linked_lines=$linked_lines*}} {{* montant de l'annuité théorique *}} {{:assign montant="%f"|math:$ligne_immo.montant}} {{:assign annuite="%f/%f"|math:$montant:$duree}} {{* 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 date_amort=$ligne_immo.date_amort|date_short}} +{{:include file="_calcul_dates.html" date_debut=$date_achat date_fin=$date_amort keep="nbjours"}} {{:assign annuite_1="%f/360*%d"|math:$annuite:$nbjours|intval}} -{{:assign date_amort=$date_fin}} +{{*:assign date_amort=$date_fin*}} {{:assign annuite_courante=$annuite_1}} {{:assign current_year=$ligne_immo.year_id}} {{:assign solde=$ligne_immo.montant}} @@ -201,7 +201,7 @@ {{$line.project_label}} {{if $line.linked == null}} - {{:linkbutton label="Détacher" href="detach_amort.html?amort_id=%d&immo_id=%d"|args:$line.amort_line:$ligne_immo.line_id shape="plus"}} + {{:linkbutton label="Détacher" href="detach_amort.html?amort_id=%d&immo_id=%d"|args:$line.amort_line:$ligne_immo.immo_id shape="plus"}} {{else}} {{:linkbutton label="Détacher" href="" shape="lock" class="disabled"}} {{/if}} @@ -243,7 +243,7 @@ {{#foreach count="%d+1"|math:$nbamort key="num"}} {{:assign solde="%f-%d"|math:$solde:$annuite_courante}} - {{#select id from acc_years where end_date = :end_date and closed = 0; :end_date=$date_amort|parse_date}} + {{#select id from acc_years where :amort_date >= start_date and :amort_date <= end_date and closed = 0; :amort_date=$date_amort|parse_date}} {{:assign enregistrer=1}} {{:assign current_year=$id}} {{else}} @@ -267,7 +267,7 @@ {{if $enregistrer == 1}} {{:linkbutton label="Enregistrer" - href="save_amort.html?amount=%d&account=%s&year=%s&trans_id=%d&line_id=%s&project_id=%d&label=%s"|args:$annuite_courante:$ligne_immo.account_id:$current_year:$ligne_immo.trans_id:$_GET.line_id:$project_id:$libelle + href="save_amort.html?amount=%d&account=%s&year=%s&trans_id=%d&immo_id=%s&project_id=%d&label=%s"|args:$annuite_courante:$ligne_immo.account_id:$current_year:$ligne_immo.trans_id:$_GET.immo_id:$project_id:$libelle shape="right" target="_dialog" }} @@ -352,7 +352,7 @@ {{$p_label}} {{if $linked != "true"}} - {{:linkbutton label="Attacher" href="attach_amort.html?amort_id=%d&immo_id=%d"|args:$l_id:$ligne_immo.line_id shape="plus"}} + {{:linkbutton label="Attacher" href="attach_amort.html?amort_id=%d&immo_id=%d"|args:$l_id:$ligne_immo.immo_id shape="plus"}} {{else}} {{:linkbutton label="Attacher" href="" shape="lock" class="disabled"}} {{/if}} diff --git a/module.ini b/module.ini index 5c6da4c..923cc23 100644 --- a/module.ini +++ b/module.ini @@ -1,4 +1,4 @@ -name="Gestion des amortissements" +name="Amortissements" description="Gestion des amortissements pour le logiciel de comptabilité Paheko" author="Jean-Christophe Engel" author_url="https://git.roflcopter.fr/lesanges" diff --git a/save_amort.html b/save_amort.html index d0794c9..30adbec 100644 --- a/save_amort.html +++ b/save_amort.html @@ -40,7 +40,7 @@ linked_transactions=$_GET.trans_id|intval }} - {{:redirect force="amortization.html?line_id=%s&ok=1&msg=amortissement"|args:$_GET.line_id}} + {{:redirect force="amortization.html?immo_id=%s&ok=1&msg=amortissement"|args:$_GET.immo_id}} {{/form}} {{* Préparer les infos pour le formulaire *}} @@ -56,7 +56,14 @@ {{: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}} +{{#select + id, + label, + date(start_date, "start of year", "+1 year", "-1 day") as date_amort + from acc_years where id=:id; + :id=$_GET.year assign=year + }} +{{/select}} {{#years closed=false}} {{:assign var="open_years.%d"|args:$id value=$label}} @@ -67,7 +74,7 @@ Ajouter une écriture d'amortissement
{{: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="date" name="date" label="Date" required=true default=$year.date_amort|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