From 2c11d3e4f3012e6a24ef7d158a7375d9dd20330a Mon Sep 17 00:00:00 2001 From: Jean-Christophe Engel Date: Tue, 4 Feb 2025 14:52:50 +0100 Subject: [PATCH 01/21] ajout arrondi calcul date --- _calcul_dates.html | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/_calcul_dates.html b/_calcul_dates.html index 6ccc98b..6239b76 100644 --- a/_calcul_dates.html +++ b/_calcul_dates.html @@ -16,6 +16,4 @@ {{:assign nbjours="-1*%d"|math:$nbjours}} {{/if}} {{* pour simplifier : 360 jours par an *}} -{{if $nbjours > 360}} - {{:assign nbjours=360}} -{{/if}} +{{:assign nbjours="round(%f/365*360)"|math:$nbjours}} From fb0d34a4f47e687c97f497d5b25530a8a65c4901 Mon Sep 17 00:00:00 2001 From: Jean-Christophe Engel Date: Tue, 4 Feb 2025 16:25:32 +0100 Subject: [PATCH 02/21] =?UTF-8?q?d=C3=A9but=20r=C3=A9organisation=20classe?= =?UTF-8?q?ment=20immobilisations?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- _nav.html | 5 +- add_asset.html | 4 +- add_infos.html | 4 +- amortization.html | 47 ++++++------- immobilisations.html | 56 ++++++++------- immobilisations_autres.html | 133 ++++++++++++++++++++++++++++++++++++ index.html | 8 +-- modif_infos.html | 4 +- 8 files changed, 202 insertions(+), 59 deletions(-) create mode 100644 immobilisations_autres.html diff --git a/_nav.html b/_nav.html index 362f31a..d98dee8 100644 --- a/_nav.html +++ b/_nav.html @@ -14,9 +14,10 @@ {{if $current == 'index'}} {{if $subsubcurrent == 'amortization'}} diff --git a/add_asset.html b/add_asset.html index 8cd1403..e990d31 100644 --- a/add_asset.html +++ b/add_asset.html @@ -106,9 +106,9 @@ noamort=$noamort }} {{if $_POST.no_amort}} - {{:assign amort=0}} + {{:assign amort="autres"}} {{else}} - {{:assign amort=1}} + {{:assign amort="encours"}} {{/if}} {{:redirect force="index.html?ok=1&msg=immobilisation&amort=%s"|args:$amort}} {{/form}} diff --git a/add_infos.html b/add_infos.html index f34794c..1ce0399 100644 --- a/add_infos.html +++ b/add_infos.html @@ -55,9 +55,9 @@ }} {{if $_POST.no_amort}} - {{:assign amort=0}} + {{:assign amort="autres"}} {{else}} - {{:assign amort=1}} + {{:assign amort="encours"}} {{/if}} {{:redirect force="index.html?ok=1&msg=infos&amort=%s"|args:$amort}} {{else}} diff --git a/amortization.html b/amortization.html index 2d18a00..14b241e 100644 --- a/amortization.html +++ b/amortization.html @@ -3,12 +3,14 @@ {{:admin_header title="Liste des amortissements" custom_css="./style.css" current="module_amortissement"}} {{* barre de navigation *}} -{{if $_GET.amort == null || $_GET.amort == "amort"}} - {{:assign subcurrent="amort"}} +{{if $_GET.amort == null || $_GET.amort == "encours"}} + {{:assign subcurrent="encours"}} {{elseif $_GET.amort == "fini"}} {{:assign subcurrent="fini"}} +{{elseif $_GET.amort == "archive"}} + {{:assign subcurrent="archive"}} {{else}} - {{:assign subcurrent="no_amort"}} + {{:assign subcurrent="autres"}} {{/if}} {{:include file="_nav.html" current="index" subcurrent="%s"|args:$subcurrent subsubcurrent="amortization"}} @@ -16,7 +18,7 @@ {{if $_GET.msg|match:"attach"}} {{:assign msg="Attachement effectué (écriture %s)"|args:$_GET.trans_id}} {{elseif $_GET.msg|match:"detach"}} - {{:assign msg="Attachement supprimé (écriture %s)"|args:$_GET.trans_id}} + {{:assign msg="Attachement détaché (écriture %s)"|args:$_GET.trans_id}} {{elseif $_GET.msg|match:"amortissement"}} {{:assign msg="Amortissement enregistré"}} {{/if}} @@ -72,9 +74,8 @@ trans.id_year as amort_year, account.id as account_id, account.code as account_code, - account.label as account_name - FROM - acc_transactions_lines as l_immo + 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 ( @@ -165,7 +166,7 @@ {{/if}} {{$line.account_code}} - {{$line.account_name}} + {{$line.account_label}} {{:linkbutton label="Détacher" href="detach_amort.html?amort_id=%d&immo_id=%d"|args:$line.amort_line:$ligne_immo.immo_id shape="plus"}} @@ -242,19 +243,19 @@ {{* Autres amortissements non rattachés *}} {{#select - li.id as l_id, - li.id_transaction as t_id, - li.credit as montant, - li.reference, - li.label as l_label, + 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, - account.code as a_code, - account.label as a_label, - y.label as y_label - FROM acc_transactions_lines AS li - INNER JOIN acc_accounts AS account ON account.id = li.id_account - INNER JOIN acc_transactions AS trans ON trans.id = li.id_transaction + 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; @@ -288,21 +289,21 @@ - {{#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}} #{{$line.t_id}} {{$line.t_date|date_short}} - {{"%f"|math:$line.montant|money}} + {{"%f"|math:$line.amort_amount|money}} {{if $line.l_label == null}} {{$line.t_label}} {{else}} {{$line.l_label}} {{/if}} - {{$line.a_code}} - {{$line.a_label}} + {{$line.account_code}} + {{$line.account_label}} {{:linkbutton label="Attacher" href="attach_amort.html?amort_id=%d&immo_id=%d"|args:$line.l_id:$ligne_immo.immo_id shape="plus"}} diff --git a/immobilisations.html b/immobilisations.html index 77436e1..c31eeb1 100644 --- a/immobilisations.html +++ b/immobilisations.html @@ -3,9 +3,9 @@ {{* Liste des immobilisations amortissable ou à définir *}}
- {{if $amort == "amort"}} + {{if $amort == "encours"}}

Immobilisations en cours

- {{else}} + {{elseif $amort == "fini"}}

Immobilisations amorties

{{/if}} @@ -19,7 +19,6 @@ Durée N° compte Compte - Projet @@ -46,13 +45,11 @@ 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 @@ -98,7 +95,7 @@ AND account.code LIKE '28%'; :line_id = $immo_id|intval - }} + }} {{if $amort_amount == null}} {{:assign exist_amort=false}} {{:assign amort_amount=0}} @@ -108,8 +105,9 @@ {{/if}} {{/select}} {{* immo amortie ? *}} - {{if $amort == "amort" && $amort_amount >= $debit || - $amort == "fini" && $amort_amount < $debit + {{if $amort == "encours" && $amort_amount >= $debit || + $amort == "fini" && $amort_amount < $debit || + $amortissable == "nsp" && ! $exist_amort }} {{:continue}} {{/if}} @@ -121,30 +119,40 @@ {{if $duration != null}}{{$duration}}{{/if}} {{$account_code}} {{$account_label}} - {{$project_label}} - {{if ! $exist_amort && $duration == null}} + {{if ! $exist_amort}} {{:linkbutton - label="Ajouter infos" - href="add_infos.html?immo_id=%s&amort=1"|args:$immo_id - shape="help" - target="_dialog" - }} - {{else}} - {{if ! $exist_amort}} - {{:linkbutton label="Modifier infos" href="modif_infos.html?immo_id=%s&amort=1"|args:$immo_id - shape="help" + shape="settings" target="_dialog" - }} - {{/if}} + }} + {{elseif $amortissable == "nsp"}} {{:linkbutton - label="Amortissements" - href="amortization.html?immo_id=%s&amort=%s"|args:$immo_id:$amort - shape="table" + label="Ajouter infos" + href="add_infos.html?immo_id=%s&amort=1"|args:$immo_id + shape="settings" + target="_dialog" }} {{/if}} + {{if $amort == "encours"}} + {{:linkbutton + label="Cession" + href="" + shape="money" + }} + {{elseif $amort == "fini"}} + {{:linkbutton + label="Rebut" + href="" + shape="export" + }} + {{/if}} + {{:linkbutton + label="Amortissements" + href="amortization.html?immo_id=%s&amort=%s"|args:$immo_id:$amort + shape="table" + }} {{/select}} diff --git a/immobilisations_autres.html b/immobilisations_autres.html new file mode 100644 index 0000000..08af93e --- /dev/null +++ b/immobilisations_autres.html @@ -0,0 +1,133 @@ +{{* -*- brindille -*- *}} + +{{* Liste des immobilisations non amortissables ou non (encore) gérées *}} + +
+

Autres immobilisations

+ + + + + + + + + + + + + + + + {{* lister les immobilisations *}} + {{:read file="./defaut.json" assign="config_json"}} + {{:assign config_defaut=$config_json|json_decode}} + {{:assign var="prefix_array" value=$config_defaut.prefixes|keys}} + {{:assign quote="'"}} + {{:assign condition="("}} + {{#foreach from=$prefix_array item="code"}} + {{:assign condition=$condition|cat:" account.code LIKE "|cat:$quote|cat:$code|cat:"%"|cat:$quote|cat:" OR "}} + {{/foreach}} + {{:assign condition=$condition|cat:"0)"}} + {{: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}} + {{if $noamort}} + {{:assign amortissable="non"}} + {{else}} + {{:assign amortissable="oui"}} + {{/if}} + {{else}} + {{:assign amortissable="nsp"}} + {{/load}} + + {{if $amortissable == "oui"}} + {{: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 ignore=true}} + {{else}} + {{:assign ignore=false}} + {{/if}} + {{/select}} + + {{if $ignore}} + {{:continue}} + {{/if}} + + + + + + + + + + + {{/select}} + +
DateLibelléMontantN° compteCompte
#{{$trans_id}}{{$trans_date|date_short}}{{$trans_label}}{{"%f"|math:$debit|money:false}}{{$account_code}}{{$account_label}} + {{if $amortissable == "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}} +
+
diff --git a/index.html b/index.html index 5057665..40e74c9 100644 --- a/index.html +++ b/index.html @@ -3,7 +3,7 @@ {{* barre de navigation *}} {{if $_GET.amort == null}} - {{:assign amort="amort"}} + {{:assign amort="encours"}} {{else}} {{:assign amort=$_GET.amort}} {{/if}} @@ -47,9 +47,9 @@ {{/select}} {{/load}} -{{if $amort == "no_amort"}} - {{:include file="./immobilisations_non.html"}} -{{else}} +{{if $amort == "autres"}} + {{:include file="./immobilisations_autres.html"}} +{{elseif $amort == "encours" || $amort == "fini"}} {{:include file="./immobilisations.html"}} {{/if}} diff --git a/modif_infos.html b/modif_infos.html index c5f3599..096fc2c 100644 --- a/modif_infos.html +++ b/modif_infos.html @@ -58,9 +58,9 @@ }} {{if $_POST.no_amort}} - {{:assign amort=0}} + {{:assign amort="autres"}} {{else}} - {{:assign amort=1}} + {{:assign amort="encours"}} {{/if}} {{:redirect force="index.html?ok=1&msg=infos&amort=%s"|args:$amort}} {{else}} From 31a0371ae2946db6a12addcf315a790b644fbc2e Mon Sep 17 00:00:00 2001 From: Jean-Christophe Engel Date: Wed, 23 Apr 2025 11:11:28 +0200 Subject: [PATCH 03/21] =?UTF-8?q?Introduction=20status=20dans=20sch=C3=A9m?= =?UTF-8?q?a=20immobilisation?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- add_asset.html | 25 ++++++++++++++----------- add_infos.html | 6 +++--- immobilisations_autres.html | 18 +++++++----------- modif_infos.html | 13 +++++++++---- schema.json | 5 +++-- 5 files changed, 36 insertions(+), 31 deletions(-) diff --git a/add_asset.html b/add_asset.html index e990d31..ba960df 100644 --- a/add_asset.html +++ b/add_asset.html @@ -1,10 +1,4 @@ {{* -*- brindille -*- *}} -{{:admin_header title="Ajout immobilisation" current="module_amortissement"}} - -{{* 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}} @@ -27,7 +21,7 @@ {{* ne pas amortir *}} {{:assign duration=0}} {{:assign date_debut=$ligne_immo.date_achat|parse_date}} - {{:assign noamort=true}} + {{: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}} @@ -37,7 +31,7 @@ {{: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 noamort=false}} + {{:assign status="managed"}} {{/if}} {{* déterminer le numéro des comptes au cas où la clé serait un identifiant *}} @@ -103,7 +97,7 @@ line=$immo_id duration=$duration date=$date_debut - noamort=$noamort + status=$status }} {{if $_POST.no_amort}} {{:assign amort="autres"}} @@ -113,12 +107,23 @@ {{: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 *}} {{:assign var="bank_account.512" value="512 — Banques"}} {{:assign var="immo_account.2" value="2 — Classe 2 — Comptes d'immobilisations"}} +{{* À TESTER : remplacer code compte par identifiant ? +{{:assign var="bank_account.553" value="512A — Compte courant"}} +{{:assign var="immo_account.2" value="Comptes d'immobilisations"}} +*}} + {{#select id,label FROM acc_projects WHERE archived = 0;}} {{:assign var="projects.%d"|args:$id value=$label}} {{/select}} @@ -190,9 +195,7 @@ function setDate(b_date, button_names) { const button = document.querySelector("button[data-name=" + name + "]"); const b_value = button.value; const new_value = b_value.replace(/date=[0-9]+-[0-9]+-[0-9]+/, 'date=' + new_date); - console.log(" date = " + new_date + " old_val = " + b_value + " new_val = " + new_value); button.setAttribute('value', new_value); - console.log("button_value = " + button.value); } } diff --git a/add_infos.html b/add_infos.html index 1ce0399..01511a5 100644 --- a/add_infos.html +++ b/add_infos.html @@ -26,7 +26,7 @@ {{* ne pas amortir *}} {{:assign duration=0}} {{:assign date_debut=$ligne_immo.date_achat|parse_date}} - {{:assign noamort=true}} + {{: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}} @@ -39,7 +39,7 @@ {{if $duration <= 0}} {{:error message="Erreur : la durée d'amortissement doit être strictement positive"}} {{/if}} - {{:assign noamort=false}} + {{:assign status="managed"}} {{/if}} {{* enregistrer les infos de l'immobilisation *}} @@ -51,7 +51,7 @@ line=$immo_id duration=$duration date=$date_debut - noamort=$noamort + status=$status }} {{if $_POST.no_amort}} diff --git a/immobilisations_autres.html b/immobilisations_autres.html index 08af93e..ecbfd33 100644 --- a/immobilisations_autres.html +++ b/immobilisations_autres.html @@ -23,10 +23,10 @@ {{:read file="./defaut.json" assign="config_json"}} {{:assign config_defaut=$config_json|json_decode}} {{:assign var="prefix_array" value=$config_defaut.prefixes|keys}} - {{:assign quote="'"}} {{:assign condition="("}} {{#foreach from=$prefix_array item="code"}} - {{:assign condition=$condition|cat:" account.code LIKE "|cat:$quote|cat:$code|cat:"%"|cat:$quote|cat:" OR "}} + {{: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)"}} @@ -53,18 +53,14 @@ {{: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}} - {{if $noamort}} - {{:assign amortissable="non"}} - {{else}} - {{:assign amortissable="oui"}} - {{/if}} + {{:assign status=$status}} {{else}} - {{:assign amortissable="nsp"}} + {{:assign status="nsp"}} {{/load}} - - {{if $amortissable == "oui"}} + {{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 @@ -110,7 +106,7 @@ {{$account_code}} {{$account_label}} - {{if $amortissable == "nsp"}} + {{if $status == "nsp"}} {{:linkbutton label="Ajouter infos" href="add_infos.html?immo_id=%s&amort=1"|args:$immo_id diff --git a/modif_infos.html b/modif_infos.html index 096fc2c..7181226 100644 --- a/modif_infos.html +++ b/modif_infos.html @@ -30,7 +30,7 @@ {{* ne pas amortir *}} {{:assign duration=0}} {{:assign date_debut=$ligne_immo.date_achat|parse_date}} - {{:assign noamort=true}} + {{: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}} @@ -43,7 +43,7 @@ {{if $duration <= 0}} {{:error message="Erreur : la durée d'amortissement doit être strictement positive"}} {{/if}} - {{:assign noamort=false}} + {{:assign status="managed"}} {{/if}} {{* enregistrer les infos modifiées de l'immobilisation *}} @@ -54,7 +54,7 @@ line=$immo_id duration=$duration date=$date_debut - noamort=$noamort + status=$status }} {{if $_POST.no_amort}} @@ -81,7 +81,12 @@
- {{: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')"}} + {{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}}
diff --git a/schema.json b/schema.json index b2d16e2..ea8e31c 100644 --- a/schema.json +++ b/schema.json @@ -19,8 +19,9 @@ "type" : ["string", "null"], "format" : "date" }, - "noamort" : { - "type" : ["null", "boolean"] + "status" : { + "type" : ["string", "null"], + "enum" : ["managed", "archived", "ignored"] } }, "required": ["type", "line", "duration", "date"] From 91b75e77d4595d8d59ef408bcc5504250ecfbd9e Mon Sep 17 00:00:00 2001 From: Jean-Christophe Engel Date: Thu, 24 Apr 2025 11:57:15 +0200 Subject: [PATCH 04/21] =?UTF-8?q?Diverses=20am=C3=A9liorations?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- _calcul_dates.html | 10 ++++++---- _check_account.html | 4 ++-- amortization.html | 6 ++++-- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/_calcul_dates.html b/_calcul_dates.html index 6239b76..28c6da8 100644 --- a/_calcul_dates.html +++ b/_calcul_dates.html @@ -9,11 +9,13 @@ {{:assign ts_debut=$date_debut|strtotime}} {{:assign ts_fin=$date_fin|strtotime}} -{{:assign nbjours="1+(%d-%d)/(60*60*24)"|math:$ts_fin:$ts_debut}} -{{* au cas où les deux dates seraient inversées ... *}} -{{if $nbjours < 0}} - {{:assign nbjours="-1*%d"|math:$nbjours}} +{{if $ts_debut <= $ts_fin}} + {{:assign nbjours="(%d-%d)/(60*60*24)"|math:$ts_fin:$ts_debut}} +{{else}} + {{:assign nbjours="(%d-%d)/(60*60*24)"|math:$ts_debut:$ts_fin}} {{/if}} + {{* pour simplifier : 360 jours par an *}} {{:assign nbjours="round(%f/365*360)"|math:$nbjours}} +{{:debug nbjours=$nbjours}} diff --git a/_check_account.html b/_check_account.html index f0fc6ac..d1234a3 100644 --- a/_check_account.html +++ b/_check_account.html @@ -12,10 +12,10 @@ - account_ok *}} -{{:assign quote="'"}} {{:assign condition=" AND ("}} {{#foreach from=$prefix_array item="code"}} - {{:assign condition=$condition|cat:" code LIKE "|cat:$quote|cat:$code|cat:"%"|cat:$quote|cat:" OR "}} + {{:assign code=$code|cat:"%"|quote_sql}} + {{:assign condition=$condition|cat:" code LIKE "|cat:$code|cat:" OR "}} {{/foreach}} {{:assign condition=$condition|cat:"0)"}} diff --git a/amortization.html b/amortization.html index 14b241e..1e3edd7 100644 --- a/amortization.html +++ b/amortization.html @@ -16,9 +16,9 @@ {{if $_GET.ok}} {{if $_GET.msg|match:"attach"}} - {{:assign msg="Attachement effectué (écriture %s)"|args:$_GET.trans_id}} + {{:assign msg="Attachement écriture %s effectué"|args:$_GET.trans_id}} {{elseif $_GET.msg|match:"detach"}} - {{:assign msg="Attachement détaché (écriture %s)"|args:$_GET.trans_id}} + {{:assign msg="Détachement écriture %s affectué"|args:$_GET.trans_id}} {{elseif $_GET.msg|match:"amortissement"}} {{:assign msg="Amortissement enregistré"}} {{/if}} @@ -40,6 +40,7 @@ line.debit as montant, trans.id as trans_id, trans.label as label, + trans.date, y.id as year_id, y.end_date as date_amort, project.label as project_label @@ -54,6 +55,7 @@ {{else}} {{:error message="Immobilisation %s non trouvée"|args:$_GET.immo_id}} {{/select}} +{{:assign date_debut=$ligne_immo.date}} {{#load type="immo" assign="info_immo" where="$$.line = :line_id" :line_id=$_GET.immo_id|intval}} {{:assign var="duree" from="info_immo.duration"|args:$_GET.immo_id}} From 0f1f3ed56d5ea9304fec709f21ab73f03471ad4a Mon Sep 17 00:00:00 2001 From: Jean-Christophe Engel Date: Fri, 25 Apr 2025 12:34:44 +0200 Subject: [PATCH 05/21] Ajout immo : forcer choix exercice --- _check_date.html | 8 ++--- add_asset.html | 72 ++++++++++++++++++++--------------------- scripts.js | 83 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 119 insertions(+), 44 deletions(-) create mode 100644 scripts.js diff --git a/_check_date.html b/_check_date.html index 3dc1362..f68ec49 100644 --- a/_check_date.html +++ b/_check_date.html @@ -8,15 +8,11 @@ *}} {{:assign open_years=""}} -{{#years status=false order="start_date"}} - {{:assign open_years=$open_years|cat:"\n"|cat:" - "|cat:$label|cat:" : "}} - {{:assign debut=$start_date|date_short}} - {{:assign fin=$end_date|date_short}} - {{:assign open_years=$open_years|cat:$debut|cat:" à "|cat:$fin}} +{{#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}} diff --git a/add_asset.html b/add_asset.html index ba960df..bf97a82 100644 --- a/add_asset.html +++ b/add_asset.html @@ -14,7 +14,13 @@ keep="open_years, selected_year, selected_chart" }} {{if $selected_year == null}} - {{:error message="La date choisie n'est dans aucun exercice ouvert !!\nExercices ouverts : %s"|args:$open_years}} + {{:assign msg_years=""}} + {{#foreach from=$open_years}} + {{:assign debut=$start_date|date_short}} + {{:assign fin=$end_date|date_short}} + {{:assign msg_years=$msg_years|cat:"\n"|cat:" - "|cat:$label|cat:" : "|cat:$debut|cat:" à "|cat:$fin}} + {{/foreach}} + {{:error message="La date choisie n'est dans aucun exercice ouvert !!\nExercices ouverts : %s"|args:$msg_years}} {{/if}} {{if $_POST.no_amort}} @@ -116,13 +122,17 @@ {{:form_errors}} {{* formulaire d'ajout d'immobilisation *}} -{{:assign var="bank_account.512" value="512 — Banques"}} -{{:assign var="immo_account.2" value="2 — Classe 2 — Comptes d'immobilisations"}} +{{#years closed=false order="start_date"}} + {{:assign debut=$start_date|strtotime}} + {{:assign fin=$end_date|strtotime}} + {{:assign var="years_data.%d"|args:$id value=$debut|cat:" "|cat:$fin}} + {{:assign var="open_years.%d"|args:$id value=$label}} + {{if $start_date|strtotime <= $now && $end_date|strtotime >= $now}} + {{:assign selected_year=$id}} + {{/if}} +{{/years}} -{{* À TESTER : remplacer code compte par identifiant ? -{{:assign var="bank_account.553" value="512A — Compte courant"}} -{{:assign var="immo_account.2" value="Comptes d'immobilisations"}} -*}} +{{: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}} @@ -132,14 +142,18 @@ {{:assign var="pattern_array." value="%s*"|args:$code}} {{/foreach}} {{:assign patterns=$pattern_array|implode:"|"}} -{{:assign date=$now|date:'Y-m-d'}} + +
Ajouter une immobilisation
{{:input id="no_amort" type="checkbox" value=1 name="no_amort" label="Ne pas amortir" help="Cocher pour ne pas amortir" onclick="toggleInputs('f_no_amort_1', ['f_date_mes','f_duree'])"}} - {{:input type="date" name="date_achat" label="Date d'acquisition" required=true default=$now|date_short onchange="setDate('date_achat', ['credit_account', 'debit_account'])"}} + {{:input type="date" name="date_achat" label="Date d'acquisition" required=true default=$now|date_short}} + {{: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_mes" label="Date de mise en service" help="à renseigner uniquement si différente de la date d'acquisition"}} {{:input type="text" name="designation" label="Désignation" required=true}} {{:input type="money" name="montant" label="Montant" required=true}} @@ -149,20 +163,22 @@ name="credit_account" label="Compte de décaissement" required=true - target="!acc/charts/accounts/selector.php?types=%s&date=%s"|args:"1|2|3":$date - 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, 21xx, ...)" required=true - target="!acc/charts/accounts/selector.php?date=%s&codes=%s"|args:$date:$patterns + 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}} +
@@ -172,33 +188,13 @@
+ {{:admin_footer}} diff --git a/scripts.js b/scripts.js new file mode 100644 index 0000000..8dcde5f --- /dev/null +++ b/scripts.js @@ -0,0 +1,83 @@ +// activer/désactiver les champs passés en paramètres +function toggleInputs(idcb, idfields) { + const noamort = document.getElementById(idcb); + for (let id of idfields) { + const field = document.getElementById(id); + if (noamort.checked) { + field.setAttribute("disabled","disabled"); + } + else { + field.removeAttribute("disabled"); + } + } +} + +// 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 millisecondes d'un champ date +function getDate(idelem) { + const elem = document.getElementById(idelem).value; + const jma = elem.split('/'); + const dd = new Date(jma[2], jma[1]-1, jma[0]); + return dd.getTime(); +} + +// 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'); + } + } +} + +// choisir les exercices affichés selon la date d'acquisition +function setYears(evt, id_date = 'f_date_achat', id_exercices = 'f_id_year', id_years = 'f_years_data') +{ + // masquer le message d'erreur + document.getElementById('erreur').setAttribute('class', 'hidden'); + // activer toutes les options + const select_field = document.getElementById(id_exercices); + for (const choix of select_field.options) { + choix.removeAttribute('disabled'); + choix.removeAttribute('selected'); + } + + // voir dans quels exercices ouverts se situe la date d'acquisition + const date_achat = getDate(id_date)/1000; + const years_data = document.getElementById(id_years); + let array_years = []; + for (const choix of years_data.options) { + if (choix.value != '') { + const epox = choix.text.split(' '); + if (epox[0] <= date_achat && date_achat <= epox[1]) { + array_years.push(choix.value); + } + } + } + + if (array_years.length == 0) { + document.getElementById('erreur').setAttribute('class', ''); + disableOptions(select_field, 1, array_years); + select_field.value = ''; + setAccountYear(['credit_account', 'debit_account'], 0); + } else if (array_years.length == 1) { + disableOptions(select_field, 0, array_years); + select_field.value = array_years[0]; + setAccountYear(['credit_account', 'debit_account'], array_years[0]); + } else { + disableOptions(select_field, 1, array_years); + select_field.value = ''; + setAccountYear(['credit_account', 'debit_account'], 0); + } +} From 1637f6eafd35d6647798636d294b794d748cf50a Mon Sep 17 00:00:00 2001 From: Jean-Christophe Engel Date: Wed, 30 Apr 2025 10:55:42 +0200 Subject: [PATCH 06/21] =?UTF-8?q?amortization=20:=20simplifications=20et?= =?UTF-8?q?=20am=C3=A9lioration=20pr=C3=A9sentation?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- amortization.html | 55 +++++++++++++++++++++++++++-------------------- 1 file changed, 32 insertions(+), 23 deletions(-) diff --git a/amortization.html b/amortization.html index 1e3edd7..eb150a6 100644 --- a/amortization.html +++ b/amortization.html @@ -57,9 +57,9 @@ {{/select}} {{:assign date_debut=$ligne_immo.date}} -{{#load type="immo" assign="info_immo" where="$$.line = :line_id" :line_id=$_GET.immo_id|intval}} - {{:assign var="duree" from="info_immo.duration"|args:$_GET.immo_id}} - {{:assign date_debut=$info_immo.date}} +{{#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 *}} @@ -67,9 +67,9 @@ l_amort.credit as amort_amount, l_amort.label as amort_label, l_amort.id as amort_line, - CASE links.id_related = t_immo.id - WHEN true THEN links.id_transaction - WHEN false THEN links.id_related + 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, @@ -80,25 +80,19 @@ 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 + ON (t_immo.id = links.id_transaction OR - t_immo.id = links.id_related - ) + 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 - l_amort.credit <> 0 - AND - account.code LIKE '28%' + AND account.code LIKE '28%' ORDER BY trans.date; :line_id = $_GET.immo_id|intval assign=linked_lines. }} - {{:assign var="amort_years." value=$amort_year}} {{if $date_debut == null}} {{:assign date_debut=$amort_date}} {{/if}} @@ -170,7 +164,7 @@ {{$line.account_code}} {{$line.account_label}} - {{:linkbutton label="Détacher" href="detach_amort.html?amort_id=%d&immo_id=%d"|args:$line.amort_line:$ligne_immo.immo_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="minus"}} {{:assign annuite_courante=$annuite}} @@ -187,6 +181,20 @@ {{:assign project_label=$ligne_immo.project_label}} {{:assign nbamort="%d-%d"|math:$duree:$nbamort}} {{:assign annuite_courante="min(%f,%f)"|math:$annuite_courante:$solde}} + {{:assign libelle="Amortissement "|cat:$ligne_immo.label}} + + {{* infos des comptes d'immo et d'amortissement *}} + {{#sql select="code, id_chart" tables="acc_accounts" where="id = :id" :id=$ligne_immo.account_id assign="immo_account"}} + {{/sql}} + {{:include + file="./_get_amort_code.html" + code_immo=$immo_account.code + keep="code_amort" + }} + {{#sql select="id,label" tables="acc_accounts" where="code = :code AND id_chart = :id_chart" + :code=$code_amort :id_chart=$immo_account.id_chart assign="amort_account"}} + {{/sql}} +

Amortissements à enregistrer

@@ -197,6 +205,8 @@ + + @@ -204,7 +214,9 @@ {{#foreach count="%d+1"|math:$nbamort key="num"}} {{:assign solde_prec=$solde}} {{:assign solde="%f-%d"|math:$solde:$annuite_courante}} - {{#select id FROM acc_years WHERE :amort_date >= start_date AND :amort_date <= end_date AND status == 0; :amort_date=$date_amort|parse_date}} + {{#select id FROM acc_years + WHERE :amort_date >= start_date AND :amort_date <= end_date AND status == 0 LIMIT 1; + :amort_date=$date_amort|parse_date}} {{:assign enregistrer=1}} {{:assign current_year=$id}} {{else}} @@ -215,12 +227,9 @@ - + + + @@ -167,83 +153,6 @@ {{:linkbutton label="Détacher" href="detach_amort.html?amort_id=%d&immo_id=%d"|args:$line.amort_line:$ligne_immo.immo_id shape="minus"}} - {{:assign annuite_courante=$annuite}} - {{:include file="_next_year.html" date=$date_amort keep="date_amort"}} - {{:assign nbamort="%d+1"|math:$nbamort}} - {{/foreach}} - -
Montant Solde LibelléN° compteCompte
{{$date_amort|date_short}} {{"%f"|math:$annuite_courante|money}} {{$solde|money:false}} - {{if $libelle == null}} - {{:assign libelle="Amortissement "|cat:$ligne_immo.label}} - {{/if}} - {{$libelle}} - {{$libelle}}{{$code_amort}}{{$amort_account.label}} {{if $enregistrer == 1}} {{:linkbutton From d669b5c95bd8fcd4db6afeecd506dae172129aac Mon Sep 17 00:00:00 2001 From: Jean-Christophe Engel Date: Wed, 30 Apr 2025 11:32:23 +0200 Subject: [PATCH 07/21] =?UTF-8?q?petite=20am=C3=A9lioration=20script?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- add_asset.html | 12 ++++++++---- scripts.js | 4 ++-- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/add_asset.html b/add_asset.html index bf97a82..31237d4 100644 --- a/add_asset.html +++ b/add_asset.html @@ -127,7 +127,7 @@ {{:assign fin=$end_date|strtotime}} {{:assign var="years_data.%d"|args:$id value=$debut|cat:" "|cat:$fin}} {{:assign var="open_years.%d"|args:$id value=$label}} - {{if $start_date|strtotime <= $now && $end_date|strtotime >= $now}} + {{if $debut <= $now && $now <= $fin}} {{:assign selected_year=$id}} {{/if}} {{/years}} @@ -187,14 +187,18 @@

+{{:admin_footer}} - -{{:admin_footer}} diff --git a/scripts.js b/scripts.js index 8dcde5f..e530523 100644 --- a/scripts.js +++ b/scripts.js @@ -41,8 +41,8 @@ function disableOptions(idSelect, init, values) { } } -// choisir les exercices affichés selon la date d'acquisition -function setYears(evt, id_date = 'f_date_achat', id_exercices = 'f_id_year', id_years = 'f_years_data') +// choisir les exercices affichés selon la date paramètre +function chooseYears(id_date, id_exercices, id_years) { // masquer le message d'erreur document.getElementById('erreur').setAttribute('class', 'hidden'); From ea8d805dbaa9184a5adbc551518936335103933a Mon Sep 17 00:00:00 2001 From: Jean-Christophe Engel Date: Wed, 30 Apr 2025 11:34:56 +0200 Subject: [PATCH 08/21] Sortie immobilisation du bilan --- _calcul_dates.html | 1 - _nav.html | 10 +- archives.html | 66 +++++ balance_sheet_exit.html | 247 ++++++++++++++++++ immobilisations.html | 49 +++- index.html | 5 +- style.css | 20 ++ write_exit.html | 562 ++++++++++++++++++++++++++++++++++++++++ 8 files changed, 939 insertions(+), 21 deletions(-) create mode 100644 archives.html create mode 100644 balance_sheet_exit.html create mode 100644 write_exit.html diff --git a/_calcul_dates.html b/_calcul_dates.html index 28c6da8..00ca468 100644 --- a/_calcul_dates.html +++ b/_calcul_dates.html @@ -18,4 +18,3 @@ {{* pour simplifier : 360 jours par an *}} {{:assign nbjours="round(%f/365*360)"|math:$nbjours}} -{{:debug nbjours=$nbjours}} diff --git a/_nav.html b/_nav.html index d98dee8..58c4008 100644 --- a/_nav.html +++ b/_nav.html @@ -13,11 +13,11 @@ {{if $current == 'index'}} -
    -
  • En cours
  • -
  • Terminées
  • -
  • Archivées
  • -
  • Autres
  • + {{if $subsubcurrent == 'amortization'}} diff --git a/archives.html b/archives.html new file mode 100644 index 0000000..a56d15a --- /dev/null +++ b/archives.html @@ -0,0 +1,66 @@ +{{* -*- brindille -*- *}} + +{{* Liste des immobilisations archivées *}} + +
    +

    Immobilisations archivées

    + + + + + + + + + + + + + + + + + {{#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}} +{{*: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}} + + + + + + + + + + + {{/select}} + +
    DateLibelléMontantN° compteCompteProjet
    #{{$trans_id}}{{$trans_date|date_short}}{{$trans_label}}{{"%f"|math:$debit|money:false}}{{$account_code}}{{$account_label}}{{$project_label}} +
    +
    diff --git a/balance_sheet_exit.html b/balance_sheet_exit.html new file mode 100644 index 0000000..d2cdb03 --- /dev/null +++ b/balance_sheet_exit.html @@ -0,0 +1,247 @@ +{{* -*- brindille -*- *}} + +{{* + Sortir une immobilisation du bilan + @param : + - immo_id : numéro de ligne de l'immo +*}} + +{{* récupérer les infos de l'immobilisation *}} +{{#select + line.id as line_id, + line.debit as montant, + line.id_project as project_id, + trans.id as trans_id, + trans.date as trans_date, + trans.label as trans_label, + acc.id as account_id, + y.id as year_id + FROM acc_transactions_lines AS line + INNER JOIN acc_transactions AS trans ON line.id_transaction = trans.id + INNER JOIN acc_accounts as acc ON line.id_account = acc.id + INNER JOIN acc_years AS y ON trans.id_year = y.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}} + +{{#load type="immo" assign="info_immo" where="$$.line = :line_id" :line_id=$_GET.immo_id|intval}} +{{/load}} + +{{* voir s'il existe des écritures d'amortissement associées *}} +{{#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 + 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 = $_GET.immo_id|intval +}} + {{if $amort_amount == null}} + {{:assign amort_amount=0}} + {{else}} + {{:assign amort_amount=$amort_amount}} + {{/if}} +{{/select}} +{{:assign valeur_nette="%f-%f"|math:$ligne_immo.montant:$amort_amount}} + +{{* Traiter l'envoi du formulaire *}} +{{#form on="proceed"}} + + {{* + vérifier que la date de sortie est située après la date de mise en + service ou à défaut de la date d'acquisition de l'immobilisation + *}} + {{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 choisie doit être postérieure à la date de mise en service de l'immobilisation (%s)"|args:$immo_date}} + {{/if}} + {{else}} + {{if $_POST.date_sortie|parse_date < $ligne_immo.trans_date}} + {{:assign immo_date=$ligne_immo.trans_date|date_short}} + {{:error message="La date choisie doit être postérieure à la date d'acquisition de l'immobilisation (%s)"|args:$immo_date}} + {{/if}} + {{/if}} + + {{* vérifier que la date est située dans un exercice ouvert *}} + {{:include + file="_check_date.html" + date=$_POST.date_sortie + keep="open_years, selected_year, selected_chart" + }} + {{if $selected_year == null}} + {{:assign msg_years=""}} + {{#foreach from=$open_years}} + {{:assign debut=$start_date|date_short}} + {{:assign fin=$end_date|date_short}} + {{:assign msg_years=$msg_years|cat:"\n"|cat:" - "|cat:$label|cat:" : "|cat:$debut|cat:" à "|cat:$fin}} + {{/foreach}} + {{:error message="La date choisie n'est dans aucun exercice ouvert !!\nExercices ouverts : %s"|args:$msg_years}} + {{/if}} + + {{if $valeur_nette > 0}} + {{if $info_immo.duration == null}} + {{if $_POST.duree == null}} + {{:error message="Vous devez renseigner la durée de l'amortissement"}} + {{else}} + {{:assign var=info_immo.duration value=$_POST.duree}} + {{/if}} + {{/if}} + {{/if}} + + {{* Cession de l'immobilisation + {{if $_POST.cession}} + {{if $_POST.montant_cession == ""}} + {{:error message="Le montant de la cession doit être renseigné"}} + {{/if}} + {{if $_POST.montant_cession <= 0}} + {{:error message="Le montant de la cession doit être strictement positif"}} + {{/if}} + {{/if}} +*}} + {{:redirect to="compute_exit_data.html?immo_id=%s&amort_amount=%s&year=%s&exit_date=%s&duree_amort=%s"|args:$_GET.immo_id:$amort_amount:$selected_year:$_POST.date_sortie:$_POST.duree}} +{{* + {{:redirect to="write_exit.html?immo_id=%s&amort_amount=%s&year=%s&exit_date=%s&cession=%s&duree_amort=%s"|args:$_GET.immo_id:$amort_amount:$selected_year:$_POST.date_sortie:$_POST.montant_cession:$_POST.duree}} +*}} +{{/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"}} +{{/if}} +{{:form_errors}} + +{{*:debug ligne_immo=$ligne_immo amort_amount=$amort_amount*}} + +{{* formulaire de sortie du bilan *}} +

    Sortir l'immobilisation « {{$ligne_immo.trans_label}} » du bilan

    +
    + +
    + Données de l'imobilisation +
    +
    +
    {{$ligne_immo.montant|money_currency:false}}
    +
    +
    {{$ligne_immo.trans_date|date_short}}
    + {{if $info_immo.date != null && $info_immo.date != $ligne_immo.trans_date}} +
    +
    {{$info_immo.date|date_short}}
    + {{/if}} + {{if $info_immo.duration != null}} +
    Durée de l'amortissement
    +
    {{$info_immo.duration}} ans
    + {{/if}} +
    +
    {{$amort_amount|money_currency:false}} (à la date de début de l'exercice)
    +
    +
    {{$valeur_nette|money_currency:false}} (à la date de début de l'exercice)
    +
    +
    + +
    + Informations de sortie +
    + {{:input type="date" name="date_sortie" label="Date de sortie du bilan" required=true default=$now|date_short}} + {{if $info_immo.date == null && $valeur_nette > 0}} + {{:input type="date" name="date_mes" label="Date de mise en service" help="à renseigner uniquement si différente de la date d'acquisition"}} + {{/if}} + {{if $info_immo.duration == null && $valeur_nette > 0}} + {{:input type="number" name="duree" label="Durée d'amortissement" required=true min=1 onchange="computeAmort()" help="La durée est nécessaire pour calculer l'amortissement résiduel"}} + {{/if}} +{{* + {{: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')"}} + +*}} +
    +
    + +

    + {{:button type="submit" name="proceed" label="Poursuivre" shape="right" class="main"}} +

    + +
    + + + +{{:admin_footer}} diff --git a/immobilisations.html b/immobilisations.html index c31eeb1..aa69248 100644 --- a/immobilisations.html +++ b/immobilisations.html @@ -28,10 +28,10 @@ {{:read file="./defaut.json" assign="config_json"}} {{:assign config_defaut=$config_json|json_decode}} {{:assign var="prefix_array" value=$config_defaut.prefixes|keys}} - {{:assign quote="'"}} {{:assign condition="("}} {{#foreach from=$prefix_array item="code"}} - {{:assign condition=$condition|cat:" account.code LIKE "|cat:$quote|cat:$code|cat:"%"|cat:$quote|cat:" OR "}} + {{: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)"}} @@ -60,7 +60,7 @@ {{* voir si l'immo est prise en charge *}} {{#load type="immo" where="$$.line = :line_id" :line_id=$immo_id|intval}} {{:assign duration=$duration}} - {{if $noamort}} + {{if $status == "ignored"}} {{:assign amortissable="non"}} {{else}} {{:assign amortissable="oui"}} @@ -71,6 +71,32 @@ {{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, @@ -104,7 +130,8 @@ {{:assign exist_amort=true}} {{/if}} {{/select}} - {{* immo amortie ? *}} + + {{* classement par onglet *}} {{if $amort == "encours" && $amort_amount >= $debit || $amort == "fini" && $amort_amount < $debit || $amortissable == "nsp" && ! $exist_amort @@ -135,19 +162,13 @@ target="_dialog" }} {{/if}} - {{if $amort == "encours"}} + {{if $amort == "encours" || $amort == "fini"}} {{:linkbutton - label="Cession" - href="" - shape="money" - }} - {{elseif $amort == "fini"}} - {{:linkbutton - label="Rebut" - href="" + label="Sortir du bilan" + href="balance_sheet_exit.html?immo_id=%s"|args:$immo_id shape="export" }} - {{/if}} + {{/if}} {{:linkbutton label="Amortissements" href="amortization.html?immo_id=%s&amort=%s"|args:$immo_id:$amort diff --git a/index.html b/index.html index 40e74c9..25f4c29 100644 --- a/index.html +++ b/index.html @@ -34,7 +34,7 @@ {{:delete key=$key}} {{/select}} - {{* supprimer les documents correspondant à une écriture de la balance d'ouverture *}} + {{* supprimer les documents correspondant à une écriture de la balance d'ouverture {{#select line.id as line_id, trans.status @@ -45,10 +45,13 @@ }} {{:delete key=$key}} {{/select}} + *}} {{/load}} {{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}} diff --git a/style.css b/style.css index a742142..d8e1dfe 100644 --- a/style.css +++ b/style.css @@ -17,3 +17,23 @@ 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; +} diff --git a/write_exit.html b/write_exit.html new file mode 100644 index 0000000..0ef62eb --- /dev/null +++ b/write_exit.html @@ -0,0 +1,562 @@ +{{* -*- 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 + - exit_date : date de sortie de l'immobilisation + - cession : montant de la cession (optionnel) + - duree_amort : durée de l'amortiseement (optionnel) +*}} + +{{* TEMPORAIRE *}} +{{:admin_header title="Sortie du bilan" custom_css="./style.css" current="module_amortissement"}} + +{{* barre de navigation *}} +{{if ! $dialog}} + {{:include file="_nav.html" current="amortization"}} +{{/if}} +{{* /TEMPORAIRE *}} + +{{#select + id_transaction, + id_account, + debit, + label, + id_project + FROM acc_transactions_lines + WHERE id = :immo_id; + :immo_id = $_GET.immo_id|intval + assign="ligne_immo" +}} +{{/select}} + +{{#select + label,date + FROM acc_transactions + WHERE id = :trans_id; + :trans_id = $ligne_immo.id_transaction + assign="trans_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}} +*}} + +{{if $info_immo.duration == null}} + {{:assign duree_amort=$_GET.duree_amort}} +{{else}} + {{:assign duree_amort=$info_immo.duration}} +{{/if}} + +{{:assign valeur_nette="%f-%f"|math:$ligne_immo.debit:$_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}} + {{:include + file="_calcul_dates.html" + date_debut=$date_debut|parse_date + date_fin=$_GET.exit_date|parse_date + keep="nbjours" + }} +{{:debug nbjours=$nbjours}} + {{:assign annuite="%f/%f"|math:$ligne_immo.debit:$duree_amort}} + {{:assign amort_comp="round(%f/360*%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.debit:$_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}} + +{{*:debug + get=$_GET + montant=$ligne_immo.debit + amort_comp=$amort_comp + amort_except=$amort_except + montant_cession=$montant_cession +*}} + +{{* Traiter l'envoi du formulaire *}} +{{#form on="save"}} +{{*:debug post=$_POST*}} + + {{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}} + {{:include + file="_get_codes.html" + account=$_POST.amort_comp_account + keep="account_code" + }} + {{:assign amort_account=$account_code|keys|key:0}} + + {{* ? Faut-il vérifier la validité des comptes ? *}} + + {{:assign libelle="Amortissement complémentaire "|cat:$trans_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}} + {{* 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:$trans_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}} +{{*:debug lines=$lines*}} + + {{: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:$trans_immo.label + lines=$lines + linked_transactions=$ligne_immo.id_transaction + }} + {{/if}} + + {{* écriture de sortie du bilan *}} +{{*:debug valeur_nette=$valeur_nette*}} + {{:assign libelle="Sortie du bilan de "|cat:$trans_immo.label}} + {{:assign lines=null}} + {{:assign + var="lines." + id_account=$ligne_immo.id_account + credit="%f/100"|math:$ligne_immo.debit + id_project=$ligne_immo.id_project + label=$libelle + }} + {{:assign + var="lines." + account=$amort_account + debit="(%f-%f)/100"|math:$ligne_immo.debit:$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}} +{{*:debug lines=$lines*}} + {{: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:$trans_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}} + + {{* mettre à jour l'état de l'immobilisation *}} + {{:save + key=$info_immo.key + status="archived" + }} + + {{:redirect to="index.html?amort=archive"}} + +{{/form}} + +{{:form_errors}} +{{*:debug get=$_GET*}} + +{{* 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}} +{{*:debug immo_account_info=$immo_account_info*}} + +{{: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"}} + +{{*:debug +comp_account=$comp_account +except_account=$except_account +amort_account=$amort_account +immo_account=$immo_account +vnc_account=$vnc_account +*}} + +{{#select * from acc_years where start_date <= :date AND :date <= end_date; + :date=$_GET.exit_date|parse_date + assign=year +}} +{{/select}} + +{{: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:"|"}} + +{{*:debug comp_account=$comp_account amort_account=$amort_account except_account=$except_account year=$year*}} + +

    Sortir l'immobilisation « {{$trans_immo.label}} » du bilan

    +
    + +
    + Données de l'imobilisation +
    +
    +
    {{$ligne_immo.debit|money_currency:false}}
    +
    +
    {{$trans_immo.date|date_short}}
    + {{if $info_immo.date != null && $info_immo.date != $trans_immo.date}} +
    +
    {{$info_immo.date|date_short}}
    + {{/if}} + {{if $duree_amort != null}} +
    Durée de l'amortissement
    +
    {{$duree_amort}} ans
    + {{/if}} +
    +
    {{$_GET.amort_amount|money_currency:false}} (à la date de début de l'exercice)
    +
    +
    {{$valeur_nette|money_currency:false}} (à la date de début de l'exercice)
    +
    +
    {{$_GET.exit_date}}
    + {{if $amort_comp > 0}} +
    +
    {{$amort_comp|money_currency:false}}
    +
    +
    {{"%f+%f"|math:$_GET.amort_amount:$amort_comp|money_currency:false}} (à la date de sortie)
    +
    +
    {{"%f-%f"|math:$valeur_nette:$amort_comp|money_currency:false}} (à la date de sortie)
    + {{/if}} + {{if $montant_cession == 0}} + {{if $amort_except > 0}} +
    +
    {{$amort_except|money_currency:false}}
    + {{/if}} + {{else}} +
    +
    {{$montant_cession|money_currency:false}}
    + {{/if}} +
    +
    + +
    + Écritures de sortie du bilan + {{* Amortissement complémentaire *}} + {{if $valeur_nette > 0}} + + + + + + + + + + + + + + + + + + + + + + + +
    Amortissement complémentaireDébitCrédit
    + Entre la date de début de l'exercice et la date de sortie du bilan +
    + {{:input + type="list" + name="comp_account" + target="!acc/charts/accounts/selector.php?codes=%s&year=%d"|args:"68*":$year.id + default=$comp_account + }} + {{$amort_comp|money_currency:false}}
    + {{:input + type="list" + name="amort_comp_account" + target="!acc/charts/accounts/selector.php?codes=%s&year=%d"|args:"28*":$year.id + default=$amort_account + }} + {{$amort_comp|money_currency:false}}
    + + {{* Amortissement exceptionnel *}} + {{if $montant_cession == 0}} + + + + + + + + + + + + + + + + + + + + + + + +
    Amortissement exceptionnelDébitCrédit
    + Montant de l'immobilisation non encore amortie (valeur nette résiduelle à la date de sortie) +
    + {{:input + type="list" + name="except_account" + target="!acc/charts/accounts/selector.php?codes=%s&year=%d"|args:"687*":$year.id + default=$except_account + }} + {{$amort_except|money_currency:false}}
    + {{:input + type="list" + name="amort_except_account" + target="!acc/charts/accounts/selector.php?codes=%s&year=%d"|args:"28*":$year.id + default=$amort_account + }} + {{$amort_except|money_currency:false}}
    + {{/if}} + {{/if}} + + {{* Sortie du bilan *}} + + + + + + + + + + + + {{if $montant_cession == 0}} + {{:assign montant=$ligne_immo.debit}} + {{else}} + {{:assign montant="%f+%f"|math:$_GET.amort_amount:$amort_comp}} + {{/if}} + + + + {{if $montant_cession > 0}} + + + {{:assign montant="%f-%f"|math:$valeur_nette:$amort_comp}} + + + + {{/if}} + + + + + + +
    Sortie du bilanDébitCrédit
    + {{:input + type="list" + name="amort_sortie_account" + target="!acc/charts/accounts/selector.php?codes=%s&year=%d"|args:"28*":$year.id + default=$amort_account + }} + {{$montant|money_currency:false}}
    + {{:input + type="list" + name="vnc_account" + target="!acc/charts/accounts/selector.php?codes=%s*&year=%d"|args:$vnc_code:$year.id + default=$vnc_account + }} + {{$montant|money_currency:false}}
    {{* 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:$year.id + default=$immo_account + }} + {{$ligne_immo.debit|money_currency:false}}
    + + {{* comptabilisation du produit de la cession *}} + {{if $montant_cession > 0}} + + + + + + + + + + + + + + + + + + + + +
    Comptabilisation de la cessionDébitCrédit
    + {{:input + type="list" + name="creance_account" + target="!acc/charts/accounts/selector.php?codes=%s&year=%d"|args:"462*":$year.id + default=$creance_account + }} + {{$montant_cession|money_currency:false}}
    + {{:input + type="list" + name="cession_account" + target="!acc/charts/accounts/selector.php?codes=%s*&year=%d"|args:$cession_code:$year.id + default=$cession_account + }} + {{$montant_cession|money_currency:false}}
    + {{/if}} +
    + +

    + {{:button type="submit" name="save" label="Enregistrer" shape="right" class="main"}} +

    +
    +{{:admin_footer}} From 5b8c869ba419871c85820c02df472be7672540d0 Mon Sep 17 00:00:00 2001 From: Jean-Christophe Engel Date: Tue, 6 May 2025 17:07:07 +0200 Subject: [PATCH 09/21] =?UTF-8?q?Prise=20en=20compte=20exercice=20de=20dur?= =?UTF-8?q?=C3=A9e=20sup=C3=A9rieure=20=C3=A0=20un=20an?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- _calcul_dates.html | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/_calcul_dates.html b/_calcul_dates.html index 00ca468..035e70e 100644 --- a/_calcul_dates.html +++ b/_calcul_dates.html @@ -11,10 +11,7 @@ {{:assign ts_fin=$date_fin|strtotime}} {{if $ts_debut <= $ts_fin}} - {{:assign nbjours="(%d-%d)/(60*60*24)"|math:$ts_fin:$ts_debut}} + {{:assign nbjours="1+(%d-%d)/(60*60*24)"|math:$ts_fin:$ts_debut}} {{else}} - {{:assign nbjours="(%d-%d)/(60*60*24)"|math:$ts_debut:$ts_fin}} + {{:assign nbjours="1+(%d-%d)/(60*60*24)"|math:$ts_debut:$ts_fin}} {{/if}} - -{{* pour simplifier : 360 jours par an *}} -{{:assign nbjours="round(%f/365*360)"|math:$nbjours}} From 839739b99211431073147b0b61e249393ef2a16e Mon Sep 17 00:00:00 2001 From: Jean-Christophe Engel Date: Tue, 6 May 2025 17:07:46 +0200 Subject: [PATCH 10/21] Choisir exercice avant date amortissement --- amortization.html | 121 ++++--------------------- save_amort.html | 220 +++++++++++++++++++++++++++++++++++----------- scripts.js | 16 ++++ style.css | 4 + 4 files changed, 203 insertions(+), 158 deletions(-) diff --git a/amortization.html b/amortization.html index eb150a6..f4d51fe 100644 --- a/amortization.html +++ b/amortization.html @@ -35,19 +35,12 @@ {{* récupérer les infos de l'immobilisation *}} {{#select line.id as immo_id, - line.id_account as account_id, - line.id_project as project_id, line.debit as montant, trans.id as trans_id, trans.label as label, - trans.date, - y.id as year_id, - y.end_date as date_amort, - project.label as project_label + trans.date 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 @@ -56,6 +49,7 @@ {{: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}} @@ -98,6 +92,19 @@ {{/if}} {{/select}} +{{:assign valeur_residuelle=$ligne_immo.montant}} +{{#foreach from=$linked_lines}} + {{:assign valeur_residuelle="%d-%d"|math:$valeur_residuelle:$amort_amount}} +{{/foreach}} + +{{if $valeur_residuelle > 0}} + +{{/if}} +

    Amortissement de « #{{$ligne_immo.trans_id}} @@ -106,25 +113,6 @@ en date du {{$date_debut|date_short}}{{if $duree != null}} sur {{$duree}} ans{{/if}}

    -{{if $duree != null}} - {{* 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_amort=$ligne_immo.date_amort}} - {{if $date_amort|strtotime < $date_debut|strtotime}} - {{* changer d'exercice *}} - {{:include file="_next_year.html" date=$date_amort keep="date_amort"}} - {{:assign date_amort=$date_amort|parse_date}} - {{/if}} - {{:include file="_calcul_dates.html" date_debut=$date_debut date_fin=$date_amort keep="nbjours"}} - {{:assign annuite_1="%f/360*%d"|math:$annuite:$nbjours|intval}} - {{:assign annuite_courante=$annuite_1}} - {{:assign current_year=$ligne_immo.year_id}} - {{:assign nbamort=0}} -{{/if}} - -{{:assign solde=$ligne_immo.montant}} {{if $linked_lines != null}}

    Amortissements rattachés

    @@ -147,8 +135,6 @@ {{: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}} - {{:assign date_amort=$line.amort_date}} - {{:assign current_year=$line.amort_year}}
#{{$line.amort_trans_id}} {{$line.amort_date|date_short}}
-
-{{/if}} - -{{if $duree != null && $solde > 0}} - {{:assign project_id=$ligne_immo.project_id}} - {{:assign project_label=$ligne_immo.project_label}} - {{:assign nbamort="%d-%d"|math:$duree:$nbamort}} - {{:assign annuite_courante="min(%f,%f)"|math:$annuite_courante:$solde}} - {{:assign libelle="Amortissement "|cat:$ligne_immo.label}} - - {{* infos des comptes d'immo et d'amortissement *}} - {{#sql select="code, id_chart" tables="acc_accounts" where="id = :id" :id=$ligne_immo.account_id assign="immo_account"}} - {{/sql}} - {{:include - file="./_get_amort_code.html" - code_immo=$immo_account.code - keep="code_amort" - }} - {{#sql select="id,label" tables="acc_accounts" where="code = :code AND id_chart = :id_chart" - :code=$code_amort :id_chart=$immo_account.id_chart assign="amort_account"}} - {{/sql}} - -
-

Amortissements à enregistrer

- - - - - - - - - - - - - - - {{#foreach count="%d+1"|math:$nbamort key="num"}} - {{:assign solde_prec=$solde}} - {{:assign solde="%f-%d"|math:$solde:$annuite_courante}} - {{#select id FROM acc_years - WHERE :amort_date >= start_date AND :amort_date <= end_date AND status == 0 LIMIT 1; - :amort_date=$date_amort|parse_date}} - {{:assign enregistrer=1}} - {{:assign current_year=$id}} - {{else}} - {{:assign enregistrer=0}} - {{/select}} - - - - - - - - - - - {{:include file="_next_year.html" date=$date_amort keep="date_amort"}} - {{:assign annuite_courante="min(%f,%f)"|math:$annuite:$solde}} - {{if $solde == 0}}{{:break}}{{/if}} {{/foreach}}
DateMontantSoldeLibelléN° compteCompte
{{"%d+1"|math:$num}}{{$date_amort|date_short}}{{"%f"|math:$annuite_courante|money}}{{$solde|money:false}}{{$libelle}}{{$code_amort}}{{$amort_account.label}} - {{if $enregistrer == 1}} - {{:linkbutton - label="Créer l'écriture" - href="save_amort.html?amount=%d&account=%s&year=%s&trans_id=%d&immo_id=%s&project_id=%d&label=%s&solde=%d"|args:$annuite_courante:$ligne_immo.account_id:$current_year:$ligne_immo.trans_id:$_GET.immo_id:$project_id:$libelle:$solde_prec - shape="right" - target="_dialog" - }} - {{/if}} -
diff --git a/save_amort.html b/save_amort.html index 54bc596..55921c4 100644 --- a/save_amort.html +++ b/save_amort.html @@ -1,24 +1,128 @@ {{* -*- brindille -*- *}} -{{:admin_header title="Ajout amortissement" current="module_amortissement"}} +{{* + créer une écriture d'amortissement + paramètres + - immo_id : id de la ligne d'immobilisation +*}} -{{* barre de navigation *}} -{{if ! $dialog}} - {{:include file="_nav.html" current="amortization"}} +{{* 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, + 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_amount == null}} + {{* 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 dont la date de fin est postérieure à 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="end_date > :debut" :debut=$date_debut assign=years.}} + {{:assign ts_debut=$start_date|strtotime}} + {{:assign ts_fin=$end_date|strtotime}} + {{:assign var="years_data.%d"|args:$id value=$ts_debut|cat:" "|cat:$ts_fin}} + {{: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 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"}} + {{* UTILE ? vérifier que la date est située dans un exercice compatible *}} - {{* vérifier que la date est située dans un exercice ouvert *}} - {{:include - file="_check_date.html" - date=$_POST.date - keep="open_years, selected_year, selected_chart" - }} - - {{if $selected_year == null}} - {{:error message="La date choisie n'est dans aucun exercice ouvert !!\nExercices ouverts : %s"|args:$open_years}} + {{:assign ts_date = $_POST.date_amort|parse_date|strtotime}} + {{:assign ok=false}} + {{#foreach from=$years}} + {{if $start_date|strtotime <= $ts_date && $ts_date <= $end_date|strtotime}} + {{:assign ok=true}} + {{:break}} + {{/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 *}} @@ -34,7 +138,6 @@ 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 @@ -51,6 +154,9 @@ }} {{:assign var="amort_array." value=$code_amort|intval}} {{/foreach}} + {{#years closed=false where="id = :year_id" :year_id=$_POST.id_year}} + {{:assign selected_chart=$id_chart}} + {{/years}} {{:include file="_check_account.html" @@ -59,21 +165,19 @@ 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 *}} - {{if $_POST.montant|trim|money_int > $_GET.solde|intval}} - {{:assign solde=$_GET.solde|money_raw}} + {{: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="linked_transactions." value=$_GET.trans_id}} - {{:assign var="lines." debit=$_POST.montant @@ -88,66 +192,61 @@ id_project=$_GET.project_id label=$_POST.designation }} - {{:api method="POST" path="accounting/transaction" assign="result" assign_code="result_code" - id_year=$selected_year + id_year=$_POST.id_year type="advanced" - date=$_POST.date + date=$_POST.date_amort label=$_POST.designation lines=$lines - linked_transactions=$_GET.trans_id|intval + 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="index" subcurrent="encours" subsubcurrent="amortization"}} +{{/if}} + {{: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}} -{{:include - file="./_get_amort_code.html" - code_immo=$amort_account.code - keep="code_amort" -}} -{{:assign var="credit_account.%s"|args:$code_amort value="%s — Amortissements "|args:$code_amort|cat:$amort_account.label}} +{{* -------------------------------------------------------------------------------- *}} -{{#select - id, - label, - end_date as date_amort - from acc_years where id=:id; - :id=$_GET.year assign=year - }} -{{/select}} - -{{#years status=false}} - {{:assign var="open_years.%d"|args:$id value=$label}} -{{/years}} +
Ajouter une écriture d'amortissement
- {{: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 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?codes=%s&year=%d"|args:"68*":$year.id + target="!acc/charts/accounts/selector.php?codes=%s&id_year=%d"|args:"68*":$year.id default=$debit_account }} {{:input @@ -155,9 +254,12 @@ name="credit_account" label="Compte d'amortissement (280xx ou 281xx)" required=true - target="!acc/charts/accounts/selector.php?codes=%s&year=%d"|args:"28*":$year.id + target="!acc/charts/accounts/selector.php?codes=%s&id_year=%d"|args:"28*":$year.id default=$credit_account }} +
@@ -166,3 +268,17 @@

{{:admin_footer}} + + + diff --git a/scripts.js b/scripts.js index e530523..693e518 100644 --- a/scripts.js +++ b/scripts.js @@ -81,3 +81,19 @@ function chooseYears(id_date, id_exercices, id_years) setAccountYear(['credit_account', 'debit_account'], 0); } } + +// 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; + const years_data = document.getElementById(id_years); + for (const choix of years_data.options) { + if (choix.value == '') { + document.getElementById(id_date).value = ''; + } else 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; + } + } +} diff --git a/style.css b/style.css index d8e1dfe..c9c23f9 100644 --- a/style.css +++ b/style.css @@ -37,3 +37,7 @@ h2[class="aide"], h3[class="aide"] { .informations dl.describe > dt { margin-right: 0; } + +nav.amort aside { + margin-top : 0; +} From 90af8a07909805f20931b2d58227ec7a7b6a05f9 Mon Sep 17 00:00:00 2001 From: Jean-Christophe Engel Date: Tue, 6 May 2025 17:08:47 +0200 Subject: [PATCH 11/21] Petite correction --- _check_account.html | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/_check_account.html b/_check_account.html index d1234a3..06e1108 100644 --- a/_check_account.html +++ b/_check_account.html @@ -24,11 +24,10 @@ select="code" tables="acc_accounts" where="id_chart = :id_chart %s"|args:$condition - :id_chart = $selected_chart|intval + :id_chart = $chart_id|intval }} {{if $account_code == $code}} {{:assign account_ok=1}} {{:break}} {{/if}} {{/sql}} - From 515eb443fade87b2c28191b0f0d16f2b20f58251 Mon Sep 17 00:00:00 2001 From: Jean-Christophe Engel Date: Tue, 6 May 2025 19:14:20 +0200 Subject: [PATCH 12/21] =?UTF-8?q?Petite=20am=C3=A9lioration=20cosm=C3=A9ti?= =?UTF-8?q?que?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- amortization.html | 64 +++++++++++++++++++++++------------------------ 1 file changed, 32 insertions(+), 32 deletions(-) diff --git a/amortization.html b/amortization.html index f4d51fe..7186a7e 100644 --- a/amortization.html +++ b/amortization.html @@ -1,37 +1,5 @@ {{* -*- brindille -*- *}} -{{:admin_header title="Liste des amortissements" custom_css="./style.css" current="module_amortissement"}} - -{{* barre de navigation *}} -{{if $_GET.amort == null || $_GET.amort == "encours"}} - {{:assign subcurrent="encours"}} -{{elseif $_GET.amort == "fini"}} - {{:assign subcurrent="fini"}} -{{elseif $_GET.amort == "archive"}} - {{:assign subcurrent="archive"}} -{{else}} - {{:assign subcurrent="autres"}} -{{/if}} -{{:include file="_nav.html" current="index" subcurrent="%s"|args:$subcurrent subsubcurrent="amortization"}} - -{{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}} -

{{$msg}}

-{{elseif $_GET.err}} - {{if $_GET.msg|match:"attach"}} - {{:assign msg="Échec attachement"}} - {{elseif $_GET.msg|match:"amortissement"}} - {{:assign msg="Échec enregistrement amortissement"}} - {{/if}} -

{{$msg}}

-{{/if}} - {{* récupérer les infos de l'immobilisation *}} {{#select line.id as immo_id, @@ -97,6 +65,38 @@ {{: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 subcurrent="autres"}} +{{/if}} +{{:include file="_nav.html" current="index" subcurrent="%s"|args:$subcurrent subsubcurrent="amortization"}} + +{{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}} +

{{$msg}}

+{{elseif $_GET.err}} + {{if $_GET.msg|match:"attach"}} + {{:assign msg="Échec attachement"}} + {{elseif $_GET.msg|match:"amortissement"}} + {{:assign msg="Échec enregistrement amortissement"}} + {{/if}} +

{{$msg}}

+{{/if}} + {{if $valeur_residuelle > 0}}
+
+ Amortissement +
+ {{: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"}} +
+ {{: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)"}} +
+
+

{{:button type="submit" name="add" label="Ajouter" shape="right" class="main"}} @@ -198,7 +205,12 @@ function changeYear(evt, f_accounts = ['credit_account', 'debit_account'], f_yea 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; })(); diff --git a/scripts.js b/scripts.js index 5dccdcd..9d56f87 100644 --- a/scripts.js +++ b/scripts.js @@ -4,10 +4,22 @@ function toggleInputs(idcb, idfields) { for (let id of idfields) { const field = document.getElementById(id); if (noamort.checked) { - field.setAttribute("disabled","disabled"); + field.removeAttribute("disabled"); } else { - field.removeAttribute("disabled"); + field.setAttribute("disabled","disabled"); + } + } +} + +function toggleVisibility(idcheck, fields) { + const amortcb = document.getElementById(idcheck); + for (let id of fields) { + const field = document.getElementById(id); + if (amortcb.checked) { + field.setAttribute('class', ''); + } else { + field.setAttribute('class', 'hidden'); } } } @@ -37,7 +49,7 @@ function getDate(idelem) { return str2sec(document.getElementById(idelem).value); } -// désactiver les options du sélecteur qui ne sont pas dans un tableau de valeurs +// (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]; @@ -86,7 +98,9 @@ function computeAmort(montant_immo, duree_immo, somme_amort, date_debut, date_fi // 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) { - document.getElementById(id_erreur).setAttribute('class', 'hidden'); + 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 == '') { @@ -109,7 +123,8 @@ function displayAmort(id_immo, id_duree, id_amort, id_years, id_exercices, id_mo if (date_debut <= date_choisie && date_choisie <= date_fin) { date_fin = date_choisie; } else { - document.getElementById(id_erreur).setAttribute('class', ''); + div_erreur.setAttribute('class', ''); +// document.getElementById(id_erreur).setAttribute('class', ''); } } const montant_immo = Number(document.getElementById(id_immo).value); From dec6c8d676b817c4568d86ba75d42aba2bc04a9d Mon Sep 17 00:00:00 2001 From: Jean-Christophe Engel Date: Tue, 13 May 2025 10:24:47 +0200 Subject: [PATCH 19/21] Simplification calcul nombre jours --- _calcul_dates.html | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/_calcul_dates.html b/_calcul_dates.html index 035e70e..e4dd864 100644 --- a/_calcul_dates.html +++ b/_calcul_dates.html @@ -9,9 +9,4 @@ {{:assign ts_debut=$date_debut|strtotime}} {{:assign ts_fin=$date_fin|strtotime}} - -{{if $ts_debut <= $ts_fin}} - {{:assign nbjours="1+(%d-%d)/(60*60*24)"|math:$ts_fin:$ts_debut}} -{{else}} - {{:assign nbjours="1+(%d-%d)/(60*60*24)"|math:$ts_debut:$ts_fin}} -{{/if}} +{{:assign nbjours="1+abs(%d-%d)/(60*60*24)"|math:$ts_fin:$ts_debut}} From 3fc96927a5b9b1c7defa998e8ede4952ebdda733 Mon Sep 17 00:00:00 2001 From: Jean-Christophe Engel Date: Fri, 16 May 2025 15:19:48 +0200 Subject: [PATCH 20/21] Finalisation sortie du bilan --- _nav.html | 14 +- balance_sheet_exit.html | 291 +++++++++++++++++-------------------- compute_exit_data.html | 133 +++++++++++++++++ write_exit.html | 310 ++++++++++++++++++---------------------- 4 files changed, 416 insertions(+), 332 deletions(-) create mode 100644 compute_exit_data.html diff --git a/_nav.html b/_nav.html index 58c4008..bb819d1 100644 --- a/_nav.html +++ b/_nav.html @@ -12,18 +12,22 @@

  • Aide
  • - {{if $current == 'index'}} + {{if $current == 'index' && $subsubcurrent != 'balance_exit'}} + {{/if}} - {{if $subsubcurrent == 'amortization'}} + {{if $subsubcurrent == 'amortization'}} +
      +
    • Amortissements
    • +
    + {{elseif $subsubcurrent == 'balance_exit'}}
      -
    • Amortissements
    • -
    - {{/if}} +
  • Sortie du bilan
  • + {{/if}} diff --git a/balance_sheet_exit.html b/balance_sheet_exit.html index 7a72861..9f9de48 100644 --- a/balance_sheet_exit.html +++ b/balance_sheet_exit.html @@ -2,246 +2,219 @@ {{* Sortir une immobilisation du bilan - @param : - - immo_id : numéro de ligne de l'immo + @param immo_id : id de la ligne d'immobilisation *}} -{{* récupérer les infos de l'immobilisation *}} +{{* Infos de l'immobilisation *}} {{#select - line.id as line_id, line.debit as montant, - line.id_project as project_id, - trans.id as trans_id, - trans.date as trans_date, - trans.label as trans_label, - acc.id as account_id, - y.id as year_id + 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 - INNER JOIN acc_accounts as acc ON line.id_account = acc.id - INNER JOIN acc_years AS y ON trans.id_year = y.id WHERE line.id = :line_id; :line_id = $_GET.immo_id|intval - assign=ligne_immo + 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}} -{{* voir s'il existe des écritures d'amortissement associées *}} +{{* chercher des écritures d'amortissement liées à l'immobilisation *}} {{#select - sum(l_amort.credit) as amort_amount, + SUM(l_amort.credit) as amort_amount, CASE - WHEN links.id_related = t_immo.id THEN links.id_transaction + WHEN links.id_related = t_immo.id + THEN links.id_transaction ELSE links.id_related - END as amort_trans_id + 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 + ON (t_immo.id = links.id_transaction OR - t_immo.id = links.id_related - ) + 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 - l_amort.credit <> 0 - AND - account.code LIKE '28%'; + WHERE l_immo.id = :line_id AND account.code LIKE '28%' + LIMIT 1; :line_id = $_GET.immo_id|intval + assign=amort_line }} - {{if $amort_amount == null}} - {{:assign amort_amount=0}} - {{else}} - {{:assign amort_amount=$amort_amount}} - {{/if}} {{/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"}} - {{* - vérifier que la date de sortie est située après la date de mise en - service ou à défaut de la date d'acquisition de l'immobilisation - *}} - {{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 choisie doit être postérieure à la date de mise en service de l'immobilisation (%s)"|args:$immo_date}} - {{/if}} - {{else}} - {{if $_POST.date_sortie|parse_date < $ligne_immo.trans_date}} - {{:assign immo_date=$ligne_immo.trans_date|date_short}} - {{:error message="La date choisie doit être postérieure à la date d'acquisition de l'immobilisation (%s)"|args:$immo_date}} + {{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 que la date est située dans un exercice ouvert *}} - {{:include - file="_check_date.html" - date=$_POST.date_sortie - keep="open_years, selected_year, selected_chart" - }} - {{if $selected_year == null}} - {{:assign msg_years=""}} - {{#foreach from=$open_years}} - {{:assign debut=$start_date|date_short}} - {{:assign fin=$end_date|date_short}} - {{:assign msg_years=$msg_years|cat:"\n"|cat:" - "|cat:$label|cat:" : "|cat:$debut|cat:" à "|cat:$fin}} - {{/foreach}} - {{:error message="La date choisie n'est dans aucun exercice ouvert !!\nExercices ouverts : %s"|args:$msg_years}} - {{/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'amortissement"}} + {{: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 var=info_immo.duration value=$_POST.duree}} + {{:assign duree_amort=$_POST.duree}} {{/if}} {{/if}} {{/if}} - {{* Cession de l'immobilisation - {{if $_POST.cession}} - {{if $_POST.montant_cession == ""}} - {{:error message="Le montant de la cession doit être renseigné"}} + {{* 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}} - {{if $_POST.montant_cession <= 0}} - {{:error message="Le montant de la cession doit être strictement positif"}} + {{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}} -*}} - {{:redirect to="compute_exit_data.html?immo_id=%s&amort_amount=%s&year=%s&exit_date=%s&duree_amort=%s"|args:$_GET.immo_id:$amort_amount:$selected_year:$_POST.date_sortie:$_POST.duree}} -{{* - {{:redirect to="write_exit.html?immo_id=%s&amort_amount=%s&year=%s&exit_date=%s&cession=%s&duree_amort=%s"|args:$_GET.immo_id:$amort_amount:$selected_year:$_POST.date_sortie:$_POST.montant_cession:$_POST.duree}} -*}} + {{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"}} + {{:include file="_nav.html" current="index" subsubcurrent="balance_exit"}} {{/if}} {{:form_errors}} -{{*:debug ligne_immo=$ligne_immo amort_amount=$amort_amount*}} - {{* formulaire de sortie du bilan *}} -

    Sortir l'immobilisation « {{$ligne_immo.trans_label}} » du bilan

    +

    Sortir l'immobilisation « {{$ligne_immo.label}} » du bilan

    Données de l'imobilisation
    -
    +
    Montant
    {{$ligne_immo.montant|money_currency:false}}
    -
    -
    {{$ligne_immo.trans_date|date_short}}
    - {{if $info_immo.date != null && $info_immo.date != $ligne_immo.trans_date}} -
    +
    Date d'acquisition
    +
    {{$ligne_immo.date_achat|date_short}}
    + {{if $info_immo.date != null && $info_immo.date != $ligne_immo.date_achat}} +
    Date de mise en service
    {{$info_immo.date|date_short}}
    {{/if}} {{if $info_immo.duration != null}}
    Durée de l'amortissement
    {{$info_immo.duration}} ans
    {{/if}} -
    +
    Montant des amortissements
    {{$amort_amount|money_currency:false}} (à la date de début de l'exercice)
    -
    +
    Valeur nette résiduelle
    {{$valeur_nette|money_currency:false}} (à la date de début de l'exercice)
    - + {{if $valeur_nette > 0}} + {{if $info_immo.date == null || $info_immo.duration == null}} +
    + Informations sur l'immobilisation +
    + {{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}} +
    +
    + {{/if}} + {{/if}}
    Informations de sortie
    - {{:input type="date" name="date_sortie" label="Date de sortie du bilan" required=true default=$now|date_short}} - {{if $info_immo.date == null && $valeur_nette > 0}} - {{:input type="date" name="date_mes" label="Date de mise en service" help="à renseigner uniquement si différente de la date d'acquisition"}} - {{/if}} - {{if $info_immo.duration == null && $valeur_nette > 0}} - {{:input type="number" name="duree" label="Durée d'amortissement" required=true min=1 onchange="computeAmort()" help="La durée est nécessaire pour calculer l'amortissement résiduel"}} - {{/if}} -{{* - {{: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')"}} - -*}} + {{: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}}

    {{:button type="submit" name="proceed" label="Poursuivre" shape="right" class="main"}}

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

    Sortir l'immobilisation « {{$ligne_immo.label}} » du bilan

    +
    + +
    + Données de l'imobilisation +
    +
    Montant
    +
    {{$ligne_immo.montant|money_currency:false}}
    +
    Date d'acquisition
    +
    {{$ligne_immo.date_achat|date_short}}
    + {{if $_GET.date_mes != $ligne_immo.date_achat|strtotime}} +
    Date de mise en service
    +
    {{$_GET.date_mes|date:"d/m/Y"}}
    + {{/if}} + {{if $_GET.duree_amort != null}} +
    Durée de l'amortissement
    +
    {{$_GET.duree_amort}} ans
    + {{/if}} +
    Montant des amortissements
    +
    {{$_GET.amort_amount|money_currency:false}} (à la date de début de l'exercice)
    +
    Valeur nette résiduelle
    +
    {{$valeur_nette|money_currency:false}} (à la date de début de l'exercice)
    +
    Date de sortie
    +
    {{$_GET.exit_date|date:"d/m/Y"}}
    + {{if $amort_comp > 0}} +
    Amortissement complémentaire
    +
    {{$amort_comp|money_currency:false}} (jusqu'à la date de sortie)
    +
    Total des amortissements
    +
    {{"%f+%f"|math:$_GET.amort_amount:$amort_comp|money_currency:false}} (à la date de sortie)
    +
    Valeur nette résiduelle
    +
    {{"%f-%f"|math:$valeur_nette:$amort_comp|money_currency:false}} (à la date de sortie)
    + {{/if}} +
    +
    +
    + Informations de sortie +
    + {{: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')"}} + +
    +
    + +

    + {{:button type="submit" name="proceed" label="Poursuivre" shape="right" class="main"}} +

    + +
    + + + +{{:admin_footer}} diff --git a/write_exit.html b/write_exit.html index 21549ee..95f4045 100644 --- a/write_exit.html +++ b/write_exit.html @@ -6,48 +6,34 @@ - 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 - - cession : montant de la cession (optionnel) - duree_amort : durée de l'amortiseement (optionnel) + - cession : montant de la cession (optionnel) *}} -{{* TEMPORAIRE *}} -{{:admin_header title="Sortie du bilan" custom_css="./style.css" current="module_amortissement"}} - -{{* barre de navigation *}} -{{if ! $dialog}} - {{:include file="_nav.html" current="amortization"}} -{{/if}} -{{* /TEMPORAIRE *}} - {{#select - id_transaction, - id_account, - debit, - label, + line.debit as montant, + line.id_transaction, + line.id_account, + trans.date as date_achat, + trans.label, id_project - FROM acc_transactions_lines - WHERE id = :immo_id; + 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}} -{{#select - label,date - FROM acc_transactions - WHERE id = :trans_id; - :trans_id = $ligne_immo.id_transaction - assign="trans_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}} + {{*:assign date_debut=$start_date*}} {{/select}} {{*if $date_debut < "2025-01-01"*}} @@ -60,29 +46,17 @@ {{/if}} *}} -{{if $info_immo.duration == null}} - {{:assign duree_amort=$_GET.duree_amort}} -{{else}} - {{:assign duree_amort=$info_immo.duration}} -{{/if}} - -{{:assign valeur_nette="%f-%f"|math:$ligne_immo.debit:$_GET.amort_amount}} +{{: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}} - {{:include - file="_calcul_dates.html" - date_debut=$date_debut|parse_date - date_fin=$_GET.exit_date|parse_date - keep="nbjours" - }} -{{:debug nbjours=$nbjours}} - {{:assign annuite="%f/%f"|math:$ligne_immo.debit:$duree_amort}} + {{: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.debit:$_GET.amort_amount:$amort_comp}} + {{:assign amort_except="%f-%f-%f"|math:$ligne_immo.montant:$_GET.amort_amount:$amort_comp}} {{/if}} {{/if}} @@ -92,17 +66,28 @@ {{:assign montant_cession="%f*100"|math:$_GET.cession}} {{/if}} -{{*:debug - get=$_GET - montant=$ligne_immo.debit - amort_comp=$amort_comp - amort_except=$amort_except - montant_cession=$montant_cession -*}} +{{* 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"}} -{{*:debug post=$_POST*}} +{{* + {{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 *}} @@ -114,16 +99,8 @@ keep="account_code" }} {{:assign comp_account=$account_code|keys|key:0}} - {{:include - file="_get_codes.html" - account=$_POST.amort_comp_account - keep="account_code" - }} - {{:assign amort_account=$account_code|keys|key:0}} - {{* ? Faut-il vérifier la validité des comptes ? *}} - - {{:assign libelle="Amortissement complémentaire "|cat:$trans_immo.label}} + {{:assign libelle="Amortissement complémentaire "|cat:$ligne_immo.label}} {{:assign var="lines." debit="%f/100"|math:$amort_comp @@ -140,7 +117,7 @@ }} {{:assign valeur_nette="%f-%f"|math:$valeur_nette:$amort_comp}} - {{if $_GET.cession == null}} + {{if $_GET.cession == null && $amort_except > 0}} {{* lignes d'écriture de l'amortissement exceptionnel *}} {{:include file="_get_codes.html" @@ -148,7 +125,7 @@ keep="account_code" }} {{:assign except_account=$account_code|keys|key:0}} - {{:assign libelle="Amortissement exceptionnel "|cat:$trans_immo.label}} + {{:assign libelle="Amortissement exceptionnel "|cat:$ligne_immo.label}} {{:assign var="lines." debit="%f/100"|math:$amort_except @@ -165,7 +142,6 @@ }} {{:assign valeur_nette="%f-%f"|math:$valeur_nette:$amort_except}} {{/if}} -{{*:debug lines=$lines*}} {{:api method="POST" @@ -175,27 +151,26 @@ id_year=$_GET.year type="advanced" date=$_GET.exit_date - label="Amortissement final "|cat:$trans_immo.label + label="Amortissement final "|cat:$ligne_immo.label lines=$lines linked_transactions=$ligne_immo.id_transaction }} {{/if}} {{* écriture de sortie du bilan *}} -{{*:debug valeur_nette=$valeur_nette*}} - {{:assign libelle="Sortie du bilan de "|cat:$trans_immo.label}} + {{: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.debit + 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.debit:$valeur_nette + debit="(%f-%f)/100"|math:$ligne_immo.montant:$valeur_nette id_project=$ligne_immo.id_project label=$libelle }} @@ -208,7 +183,7 @@ label=$libelle }} {{/if}} -{{*:debug lines=$lines*}} + {{:api method="POST" path="accounting/transaction" @@ -224,7 +199,7 @@ {{if $montant_cession > 0}} {{* Cession de l'immobilisation *}} - {{:assign libelle="Produit cession "|cat:$trans_immo.label}} + {{:assign libelle="Produit cession "|cat:$ligne_immo.label}} {{:include file="_get_codes.html" account=$_POST.creance_account @@ -254,18 +229,34 @@ }} {{/if}} - {{* mettre à jour l'état de l'immobilisation *}} - {{:save - key=$info_immo.key - status="archived" - }} + {{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}} -{{*:debug get=$_GET*}} {{* Préparer les infos pour le formulaire *}} @@ -278,7 +269,6 @@ assign=immo_account_info }} {{/select}} -{{*:debug immo_account_info=$immo_account_info*}} {{:include file="./_get_amort_code.html" @@ -299,20 +289,6 @@ value="%s — Produits des cessions d'actif"|args:$cession_code}} {{:assign var="creance_account.462" value="462 — Créances sur cessions d'immobilisations"}} -{{*:debug -comp_account=$comp_account -except_account=$except_account -amort_account=$amort_account -immo_account=$immo_account -vnc_account=$vnc_account -*}} - -{{#select * from acc_years where start_date <= :date AND :date <= end_date; - :date=$_GET.exit_date|parse_date - assign=year -}} -{{/select}} - {{:read file="./defaut.json" assign="config_json"}} {{:assign config_defaut=$config_json|json_decode}} {{:assign var="prefix_array" value=$config_defaut.prefixes|keys}} @@ -322,47 +298,46 @@ vnc_account=$vnc_account {{/foreach}} {{:assign patterns=$pattern_array|implode:"|"}} -{{*:debug comp_account=$comp_account amort_account=$amort_account except_account=$except_account year=$year*}} - -

    Sortir l'immobilisation « {{$trans_immo.label}} » du bilan

    +

    Sortir l'immobilisation « {{$ligne_immo.label}} » du bilan

    Données de l'imobilisation
    -
    -
    {{$ligne_immo.debit|money_currency:false}}
    -
    -
    {{$trans_immo.date|date_short}}
    - {{if $info_immo.date != null && $info_immo.date != $trans_immo.date}} -
    -
    {{$info_immo.date|date_short}}
    +
    Montant
    +
    {{$ligne_immo.montant|money_currency:false}}
    +
    Date d'acquisition
    +
    {{$ligne_immo.date_achat|date_short}}
    + {{if $_GET.date_mes != $ligne_immo.date_achat|strtotime}} +
    Date de mise en service
    +
    {{$_GET.date_mes|date:"d/m/Y"}}
    {{/if}} - {{if $duree_amort != null}} + {{if $_GET.duree_amort != null}}
    Durée de l'amortissement
    -
    {{$duree_amort}} ans
    +
    {{$_GET.duree_amort}} ans
    {{/if}} -
    +
    Montant des amortissements
    {{$_GET.amort_amount|money_currency:false}} (à la date de début de l'exercice)
    -
    +
    Valeur nette résiduelle
    {{$valeur_nette|money_currency:false}} (à la date de début de l'exercice)
    -
    -
    {{$_GET.exit_date}}
    +
    Date de sortie
    +
    {{$_GET.exit_date|date:"d/m/Y"}}
    {{if $amort_comp > 0}} -
    -
    {{$amort_comp|money_currency:false}}
    -
    + {{:assign valeur_nette="%f-%f"|math:$valeur_nette:$amort_comp}} +
    Amortissement complémentaire
    +
    {{$amort_comp|money_currency:false}} (jusqu'à la date de sortie)
    +
    Total des amortissements
    {{"%f+%f"|math:$_GET.amort_amount:$amort_comp|money_currency:false}} (à la date de sortie)
    -
    -
    {{"%f-%f"|math:$valeur_nette:$amort_comp|money_currency:false}} (à la date de sortie)
    +
    Valeur nette résiduelle
    +
    {{$valeur_nette|money_currency:false}} (à la date de sortie)
    {{/if}} {{if $montant_cession == 0}} {{if $amort_except > 0}} -
    +
    Amortissement exceptionnel
    {{$amort_except|money_currency:false}}
    {{/if}} {{else}} -
    +
    Montant de la cession
    {{$montant_cession|money_currency:false}}
    {{/if}}
    @@ -371,7 +346,7 @@ vnc_account=$vnc_account
    Écritures de sortie du bilan {{* Amortissement complémentaire *}} - {{if $valeur_nette > 0}} + {{if $amort_comp > 0}} @@ -391,7 +366,7 @@ vnc_account=$vnc_account {{:input type="list" name="comp_account" - target="!acc/charts/accounts/selector.php?codes=%s&year=%d"|args:"68*":$year.id + target="!acc/charts/accounts/selector.php?codes=%s&year=%d"|args:"68*":$_GET.year default=$comp_account }} @@ -403,7 +378,7 @@ vnc_account=$vnc_account {{:input type="list" name="amort_comp_account" - target="!acc/charts/accounts/selector.php?codes=%s&year=%d"|args:"28*":$year.id + target="!acc/charts/accounts/selector.php?codes=%s&year=%d"|args:"28*":$_GET.year default=$amort_account }} @@ -412,50 +387,50 @@ vnc_account=$vnc_account
    + {{/if}} - {{* Amortissement exceptionnel *}} - {{if $montant_cession == 0}} - - - - - - - - - + {{* Amortissement exceptionnel *}} + {{if $montant_cession == 0 && $amort_except > 0}} +
    Amortissement exceptionnelDébitCrédit
    + - + + + - - - - - - - - - - - -
    - Montant de l'immobilisation non encore amortie (valeur nette résiduelle à la date de sortie) - Amortissement exceptionnelDébitCrédit
    - {{:input - type="list" - name="except_account" - target="!acc/charts/accounts/selector.php?codes=%s&year=%d"|args:"687*":$year.id - default=$except_account - }} - {{$amort_except|money_currency:false}}
    - {{:input - type="list" - name="amort_except_account" - target="!acc/charts/accounts/selector.php?codes=%s&year=%d"|args:"28*":$year.id - default=$amort_account - }} - {{$amort_except|money_currency:false}}
    - {{/if}} + + + + + Montant de l'immobilisation non encore amortie (valeur nette résiduelle à la date de sortie) + + + + + {{:input + type="list" + name="except_account" + target="!acc/charts/accounts/selector.php?codes=%s&year=%d"|args:"687*":$_GET.year + default=$except_account + }} + + {{$amort_except|money_currency:false}} + + + + + {{:input + type="list" + name="amort_except_account" + target="!acc/charts/accounts/selector.php?codes=%s&year=%d"|args:"28*":$_GET.year + default=$amort_account + }} + + + {{$amort_except|money_currency:false}} + + + {{/if}} {{* Sortie du bilan *}} @@ -473,30 +448,29 @@ vnc_account=$vnc_account {{:input type="list" name="amort_sortie_account" - target="!acc/charts/accounts/selector.php?codes=%s&year=%d"|args:"28*":$year.id + target="!acc/charts/accounts/selector.php?codes=%s&year=%d"|args:"28*":$_GET.year default=$amort_account }} {{if $montant_cession == 0}} - {{:assign montant=$ligne_immo.debit}} + {{:assign montant=$ligne_immo.montant}} {{else}} {{:assign montant="%f+%f"|math:$_GET.amort_amount:$amort_comp}} {{/if}} {{$montant|money_currency:false}} - {{if $montant_cession > 0}} + {{if $montant_cession > 0 && $valeur_nette > 0}} {{:input type="list" name="vnc_account" - target="!acc/charts/accounts/selector.php?codes=%s*&year=%d"|args:$vnc_code:$year.id + target="!acc/charts/accounts/selector.php?codes=%s*&year=%d"|args:$vnc_code:$_GET.year default=$vnc_account }} - {{:assign montant="%f-%f"|math:$valeur_nette:$amort_comp}} - {{$montant|money_currency:false}} + {{$valeur_nette|money_currency:false}} {{/if}} @@ -505,12 +479,12 @@ vnc_account=$vnc_account {{:input type="list" name="immo_account" - target="!acc/charts/accounts/selector.php?codes=%s&year=%d"|args:$patterns:$year.id + target="!acc/charts/accounts/selector.php?codes=%s&year=%d"|args:$patterns:$_GET.year default=$immo_account }} - {{$ligne_immo.debit|money_currency:false}} + {{$ligne_immo.montant|money_currency:false}} @@ -531,7 +505,7 @@ vnc_account=$vnc_account {{:input type="list" name="creance_account" - target="!acc/charts/accounts/selector.php?codes=%s&year=%d"|args:"462*":$year.id + target="!acc/charts/accounts/selector.php?codes=%s&year=%d"|args:"462*":$_GET.year default=$creance_account }} @@ -543,7 +517,7 @@ vnc_account=$vnc_account {{:input type="list" name="cession_account" - target="!acc/charts/accounts/selector.php?codes=%s*&year=%d"|args:$cession_code:$year.id + target="!acc/charts/accounts/selector.php?codes=%s*&year=%d"|args:$cession_code:$_GET.year default=$cession_account }} From 0c4f39b21a40ca936b67fbe075f5a006b87af9a0 Mon Sep 17 00:00:00 2001 From: Jean-Christophe Engel Date: Fri, 16 May 2025 15:20:22 +0200 Subject: [PATCH 21/21] =?UTF-8?q?Am=C3=A9liorations=20cosm=C3=A9tiques?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- archives.html | 7 ++++++- immobilisations.html | 5 +++++ immobilisations_non.html | 3 ++- save_amort.html | 19 +++++++++---------- scripts.js | 8 ++++---- 5 files changed, 26 insertions(+), 16 deletions(-) diff --git a/archives.html b/archives.html index a56d15a..9160b73 100644 --- a/archives.html +++ b/archives.html @@ -5,6 +5,7 @@

    Immobilisations archivées

    + {{:assign nb_immo=0}} @@ -26,7 +27,7 @@ {{: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, @@ -49,6 +50,7 @@ }} {{: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}} @@ -63,4 +65,7 @@ {{/select}}
    #{{$trans_id}} {{$trans_date|date_short}}
    + {{if $nb_immo == 0}} +

    Aucune immobilisation

    + {{/if}}
    diff --git a/immobilisations.html b/immobilisations.html index aa69248..6f1c86c 100644 --- a/immobilisations.html +++ b/immobilisations.html @@ -8,6 +8,7 @@ {{elseif $amort == "fini"}}

    Immobilisations amorties

    {{/if}} + {{:assign nb_immo=0}} @@ -138,6 +139,7 @@ }} {{:continue}} {{/if}} + {{:assign nb_immo="%d+1"|math:$nb_immo}} @@ -179,4 +181,7 @@ {{/select}}
    #{{$trans_id}} {{$trans_date|date_short}}
    + {{if $nb_immo == 0}} +

    Aucune immobilisation

    + {{/if}}
    diff --git a/immobilisations_non.html b/immobilisations_non.html index 2b31c84..39fbd96 100644 --- a/immobilisations_non.html +++ b/immobilisations_non.html @@ -20,12 +20,13 @@ - {{#load type="immo" where="$$.noamort = true"}} + {{#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, diff --git a/save_amort.html b/save_amort.html index 241834f..1c9df59 100644 --- a/save_amort.html +++ b/save_amort.html @@ -1,9 +1,8 @@ {{* -*- brindille -*- *}} {{* - créer une écriture d'amortissement - paramètres - - immo_id : id de la ligne d'immobilisation + Créer une écriture d'amortissement + @param immo_id : id de la ligne d'immobilisation *}} {{* Infos de l'immobilisation *}} @@ -49,6 +48,7 @@ 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, @@ -70,9 +70,8 @@ }} {{/select}} -{{if $amort_line.amort_amount == null}} +{{if $amort_line.amort_number == 0}} {{* 1er amortissement *}} - {{:assign premier_amort=true}} {{* 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}} @@ -85,7 +84,6 @@ {{:assign var=libelle value="Amortissement %s"|args:$ligne_immo.label}} {{else}} {{* amortissements suivants *}} - {{:assign premier_amort=false}} {{: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}} @@ -98,8 +96,9 @@ 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 $premier_amort}} +{{#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}} @@ -129,7 +128,7 @@ {{/if}} {{/foreach}} {{if ! $ok}} - {{:error message="La date choisie n'est dans aucun exercice compatible !!\nExercices compatibles : %s"|args:$msg_years}} + {{: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 @@ -233,7 +232,7 @@ {{* -------------------------------------------------------------------------------- *}} diff --git a/scripts.js b/scripts.js index 9d56f87..232df76 100644 --- a/scripts.js +++ b/scripts.js @@ -1,9 +1,9 @@ // activer/désactiver les champs passés en paramètres function toggleInputs(idcb, idfields) { - const noamort = document.getElementById(idcb); + const elem = document.getElementById(idcb); for (let id of idfields) { const field = document.getElementById(id); - if (noamort.checked) { + if (elem.checked) { field.removeAttribute("disabled"); } else { @@ -13,10 +13,10 @@ function toggleInputs(idcb, idfields) { } function toggleVisibility(idcheck, fields) { - const amortcb = document.getElementById(idcheck); + const elem = document.getElementById(idcheck); for (let id of fields) { const field = document.getElementById(id); - if (amortcb.checked) { + if (elem.checked) { field.setAttribute('class', ''); } else { field.setAttribute('class', 'hidden');