From 4c160e054a4c37984f92a3686f3cb8e196512841 Mon Sep 17 00:00:00 2001
From: Jean-Christophe Engel
Date: Mon, 17 Nov 2025 11:56:47 +0100
Subject: [PATCH] =?UTF-8?q?Transf=C3=A9rer=20immobilisations=20en=20cours?=
=?UTF-8?q?=20vers=20immobilisation=20amortissable?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
_unfinished.html | 85 +++++++++----
scripts.js | 49 +++++++-
style.css | 6 +
transfer.html | 317 +++++++++++++++++++++++++++++++++++++++++++++++
4 files changed, 430 insertions(+), 27 deletions(-)
create mode 100644 transfer.html
diff --git a/_unfinished.html b/_unfinished.html
index 0c2d86b..5db1083 100644
--- a/_unfinished.html
+++ b/_unfinished.html
@@ -8,13 +8,39 @@
Cette page liste les immobilisations en cours de constitution, donc non amortissables
+
+
- | N° |
+ {{*:input type="checkbox" name="all" value="all"*}} |
+ N° |
Date |
Libellé |
- Montant |
+ Montant |
N° compte |
Compte |
|
@@ -25,13 +51,13 @@
{{* lister les immobilisations en cours de constitution *}}
{{:include file="_get_config.html" keep="module.config.unfinished"}}
- {{:assign condition="("}}
+ {{:assign accounts_condition="("}}
{{#foreach from=$module.config.unfinished item="elem"}}
{{:assign code=$elem.code|cat:"%"|quote_sql}}
- {{:assign condition=$condition|cat:" account.code LIKE "|cat:$code|cat:" OR "}}
+ {{:assign accounts_condition=$accounts_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)"}}
+ {{:assign accounts_condition=$accounts_condition|cat:"0)"}}
+ {{:assign condition=$accounts_condition|cat:" AND debit > 0 AND NOT (trans.status & 16)"}}
{{:assign nb_immo=0}}
{{#select
@@ -54,27 +80,20 @@
!condition=$condition
}}
{{* 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
+ count(*) AS count
+ 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
+ WHERE line.credit = :amount AND code = :account_code
+ ;
+ :amount = $debit
+ :account_code = $account_code
}}
- {{:assign ignore=true}}
+ {{:assign count=$count}}
{{/select}}
- {{if $ignore}}
+ {{* S'il y a plus d'une écriture de même montant on ne peut pas décider *}}
+ {{if $count == 1}}
{{:continue}}
{{/if}}
@@ -83,11 +102,12 @@
{{:assign nb_immo="%d+1"|math:$nb_immo}}
+ | {{:input type="checkbox" name="selected[]" value=$trans_id}} |
#{{$trans_id}} |
{{$trans_date|date_short}} |
{{$trans_label}} |
{{"%f"|math:$debit|money:false}} |
- {{$account_code}} |
+ {{$account_code}} |
{{$account_label}} |
|
@@ -98,3 +118,18 @@
Aucune immobilisation
{{/if}}
+
+
+
diff --git a/scripts.js b/scripts.js
index 9764bcc..818d3ed 100644
--- a/scripts.js
+++ b/scripts.js
@@ -119,7 +119,6 @@ function displayAmort(id_immo, id_duree, id_amort, id_years, id_exercices, id_mo
}
if (id_date != null) {
const date_choisie = str2sec(document.getElementById(id_date).value);
- console.log("date_choisie = " + date_choisie + ", date_debut=" + date_debut + ", date_fin = " + date_fin);
if (date_debut <= date_choisie && date_choisie <= date_fin) {
date_fin = date_choisie;
} else {
@@ -161,7 +160,6 @@ function initLine(row) {
// Associer au bouton « Ajouter » de chaque table l'action d'ajouter une ligne
function addLine(button, codes) {
- console.log("codes=" + JSON.stringify(codes));
button.onclick = () => {
let lines = button.closest("table").querySelectorAll('tbody tr');
let line = lines[lines.length - 1];
@@ -190,3 +188,50 @@ function addLine(button, codes) {
initLine(newNode);
};
}
+
+// calculer et afficher le total des lignes sélectionnées
+function computeTotal(id_total, id_url) {
+
+ // calculer le total par compte
+ let total = new Object;
+ const transactions = [];
+ let lines = document.querySelectorAll('.list tbody tr');
+ for (const line of lines) {
+ let button = line.querySelector('input[type=checkbox]');
+ if (button.checked) {
+ let money = line.querySelector('.money');
+ let code = line.querySelector('.account_code a').innerText;
+ if (code in total) {
+ total[code] += getNumber(money.innerText) * 100;
+ } else {
+ total[code] = getNumber(money.innerText) * 100;
+ }
+ const number = line.querySelector('.num a').innerText.slice(1);
+ transactions.push(number);
+ }
+ }
+ // afficher les totaux
+ const liste = document.getElementById(id_total).querySelector('ul');
+ while (liste.firstChild) {
+ liste.removeChild(liste.firstChild);
+ }
+ for (const code in total) {
+ const node = document.createElement("li");
+ const para = document.createElement("p");
+ const libelle = document.createTextNode("Compte " + code + " : ");
+ const span = document.createElement("strong");
+ span.classList.add("money");
+ const montant = document.createTextNode(new Intl.NumberFormat("fr-FR", { style: "currency", currency: "EUR" }).format(total[code] / 100., ));
+
+ span.appendChild(montant);
+ para.appendChild(libelle);
+ para.appendChild(span);
+ node.appendChild(para);
+ liste.appendChild(node);
+ }
+
+ // mettre à jour les paramètres de l'url
+ let url = document.getElementById(id_url);
+ let new_href = url.href.replace(/trans=.*/, 'trans=' + Object.values(transactions));
+ url.href = new_href;
+}
diff --git a/style.css b/style.css
index c9c23f9..40922ee 100644
--- a/style.css
+++ b/style.css
@@ -41,3 +41,9 @@ h2[class="aide"], h3[class="aide"] {
nav.amort aside {
margin-top : 0;
}
+
+fieldset.shortFormLeft div.informations {
+ border: 1px solid var(--gLightBorderColor);
+ background: rgba(var(--gSecondColor), 0.2);
+ border-radius: .5em;
+}
diff --git a/transfer.html b/transfer.html
new file mode 100644
index 0000000..c7f5dfc
--- /dev/null
+++ b/transfer.html
@@ -0,0 +1,317 @@
+{{* -*- brindille -*- *}}
+
+{{:admin_header title="Transfert d'immobilisation en cours" current="module_amortissement"}}
+{{:include file="_get_config.html" keep="module.config.prefixes"}}
+
+{{#years closed=false order="start_date" assign=years.}}
+ {{:assign ts_debut=$start_date|strtotime}}
+ {{:assign ts_fin=$end_date|strtotime}}
+ {{:assign debut=$start_date|date_short}}
+ {{:assign fin=$end_date|date_short}}
+ {{:assign var="years_data.%d"|args:$id value=$ts_debut|cat:" "|cat:$ts_fin}}
+ {{:assign var="open_years.%d"|args:$id value=$label|cat:" ("|cat:$debut|cat:" - "|cat:$fin|cat:")"}}
+ {{if $ts_debut <= $now && $now <= $ts_fin}}
+ {{:assign selected_year=$id}}
+ {{/if}}
+{{else}}
+ {{:error message="Aucun exercice ouvert"}}
+{{/years}}
+
+{{* Traiter l'envoi du formulaire *}}
+{{#form on="transfer"}}
+ {{* vérifier que la date de mise en service est située dans l'exercice sélectionné *}}
+ {{:assign ts_date = $_POST.date_mes|parse_date|strtotime}}
+ {{:assign ok=false}}
+ {{#foreach from=$years}}
+ {{if $id == $_POST.id_year}}
+ {{:assign selected_chart=$id_chart}}
+ {{if $start_date|strtotime <= $ts_date && $ts_date <= $end_date|strtotime}}
+ {{:assign ok=true}}
+ {{:break}}
+ {{/if}}
+ {{/if}}
+ {{/foreach}}
+ {{if ! $ok}}
+ {{:error message="La date saisie n'est pas dans l'exercice choisi !"}}
+ {{/if}}
+
+ {{if ! $_POST.amortir}}
+ {{* ne pas amortir *}}
+ {{:assign duration=0}}
+ {{:assign date_debut=$_POST.date_achat|parse_date}}
+ {{:assign status="ignored"}}
+ {{else}}
+ {{* vérifier que la date d'acquisition est antérieure à la date de mise en service *}}
+ {{:assign date_debut=$_POST.date_mes|parse_date}}
+ {{:assign duration=$_POST.duree|intval}}
+ {{:assign status="managed"}}
+ {{/if}}
+
+ {{* comptes de débit *}}
+ {{#foreach from=$_POST.credit_accounts key="rang" item="elem"}}
+ {{:include
+ file="_get_codes.html"
+ account=$elem
+ keep="account_code"
+ }}
+ {{:assign debit_account=$account_code|keys|key:0}}
+ {{:assign var="amount" from="_POST.credit_lines.%s"|args:$rang}}
+ {{:assign var="label" from="_POST.line_labels.%s"|args:$rang}}
+ {{:assign
+ var="lines."
+ account=$debit_account
+ credit=$amount
+ label=$label
+ }}
+ {{/foreach}}
+
+ {{* compte de crédit *}}
+ {{:include
+ file="_get_codes.html"
+ account=$_POST.debit_account
+ keep="account_code"
+ }}
+ {{:assign credit_account=$account_code|keys|key:0}}
+ {{:assign var="amount" from="_POST.debit_lines.%s"|args:0}}
+ {{:assign count=$_POST.line_labels|count}}
+ {{:assign count="%d-1"|math:$count}}
+ {{:assign var="label" from="_POST.line_labels.%s"|args:$count}}
+ {{:assign
+ var="lines."
+ account=$credit_account
+ debit=$amount
+ label=$label
+ }}
+
+ {{* vérifier :
+ - que le compte d'immo débute par un préfixe correct (20, 21, ...)
+ - est présent dans le PC de l'exercice correspondant à la date
+ *}}
+
+ {{:include
+ file="_check_account.html"
+ account=$account_code
+ chart_id=$selected_chart
+ prefix_array=$module.config.prefixes
+ keep="account_ok"
+ }}
+
+ {{if $account_ok == null}}
+ {{:assign compte=$credit_account|implode:""}}
+ {{:error message="Le compte « %s » n'est pas un compte d'immobilisation ou n'est pas dans le plan comptable de l'exercice choisi"|args:$compte}}
+ {{/if}}
+
+ {{* écritures liées *}}
+ {{:assign var="linked_transactions" value=$_GET.trans|explode:","}}
+
+ {{* enregistrer l'écriture *}}
+ {{:api
+ method="POST"
+ path="accounting/transaction"
+ assign="result"
+ id_year=$_POST.id_year
+ type="advanced"
+ date=$_POST.date_mes
+ label=$_POST.designation|trim
+ lines=$lines
+ linked_transactions=$linked_transactions
+ }}
+
+ {{:assign lines_count=$lines|count}}
+ {{:assign lines_count="%d-1"|math:$lines_count}}
+ {{:assign var="immo_id" from="result.lines.%s.id"|args:$lines_count}}
+
+ {{* enregistrer les infos de l'immobilisation *}}
+ {{:save
+ key=""|uuid
+ validate_schema="schema.json"
+ type="immo"
+ line=$immo_id
+ duration=$duration
+ date=$date_debut
+ status=$status
+ }}
+ {{if $_POST.amortir}}
+ {{:assign type_immo="managed"}}
+ {{else}}
+ {{:assign type_immo="other"}}
+ {{/if}}
+ {{:redirect force="index.html?ok=1&msg=immobilisation&type_immo=%s"|args:$type_immo}}
+
+{{/form}}
+
+{{* barre de navigation *}}
+{{if ! $dialog}}
+ {{:include file="_nav.html" current="index"}}
+{{/if}}
+
+{{:form_errors}}
+
+{{* formulaire d'ajout d'immobilisation *}}
+
+{{#select id,label FROM acc_projects WHERE archived = 0;}}
+ {{:assign var="projects.%d"|args:$id value=$label}}
+{{/select}}
+
+{{#foreach from=$module.config.prefixes item="code"}}
+ {{:assign var="pattern_array." value="%s*"|args:$code}}
+{{/foreach}}
+{{:assign var="patterns" value=$pattern_array|implode:"|"}}
+
+
+
La date choisie n'est dans aucun exercice ouvert !
+
+
+{{if $_GET.trans == null}}
+ {{:error message="Vous n'avez sélectionné aucune écriture !"}}
+{{/if}}
+
+{{* déterminer les comptes d'immo en cours *}}
+{{:include file="_get_config.html" keep="module.config.unfinished"}}
+{{:assign condition="("}}
+{{#foreach from=$module.config.unfinished item="elem"}}
+ {{:assign code=$elem.code|cat:"%"|quote_sql}}
+ {{:assign condition=$condition|cat:" account.code LIKE "|cat:$code|cat:" OR "}}
+{{/foreach}}
+{{:assign condition=$condition|cat:"0)"}}
+
+{{* détails des écritures paramètres *}}
+{{:assign trans=$_GET.trans|explode:","}}
+{{:assign var="trans_list" value=$trans|map:quote_sql}}
+{{:assign trans_list=$trans_list|implode:","}}
+{{:assign trans_list="("|cat:$trans_list|cat:")"}}
+{{:assign condition=$condition|cat:" AND trans.id IN "|cat:$trans_list}}
+{{:assign condition=$condition|cat:" AND NOT (trans.status & 16)"}}
+
+{{#select
+ trans.id as trans_id,
+ trans.label AS trans_label,
+ trans.date AS trans_date,
+ SUM(line.debit) AS line_debit,
+ account.code AS account_code,
+ account.label AS account_label,
+ line.id_project as project_id
+ 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
+ WHERE !condition
+ GROUP BY trans.id
+ ;
+ !condition=$condition
+}}
+ {{:assign var="transactions.%s"|args:$trans_id amount=$line_debit date=$trans_date code=$account_code label=$account_label project=$project_id}}
+{{/select}}
+
+
+{{:admin_footer}}
+
+
+