diff --git a/_check_account.html b/_check_account.html index 06e1108..ce6816e 100644 --- a/_check_account.html +++ b/_check_account.html @@ -19,7 +19,7 @@ {{/foreach}} {{:assign condition=$condition|cat:"0)"}} -{{:assign account_code=$account|keys|key:0}} +{{:assign account_code=$account|keys|value:0}} {{#sql select="code" tables="acc_accounts" diff --git a/_get_codes.html b/_get_codes.html index a780b40..0373085 100644 --- a/_get_codes.html +++ b/_get_codes.html @@ -2,9 +2,13 @@ {{* déterminer le numéro du compte passé en paramètre dans un tableau + la clé est parfois l'identifiant du compte, parfois son code... + d'où l'obligation d'extraire le code de la valeur qui a toujours + la forme : code — libellé *}} -{{:assign label=$account|values|key:0}} +{{:assign values=$account|values}} +{{:assign label=$values.0}} {{:assign pos=$label|strpos:" "}} {{:assign account_code=$label|substr:0:$pos}} {{:assign var="account_code.%s"|args:$account_code value=$label}} diff --git a/_unfinished.html b/_unfinished.html index 3e41d55..60ac42b 100644 --- a/_unfinished.html +++ b/_unfinished.html @@ -16,9 +16,12 @@
@@ -181,15 +184,13 @@ -{{:admin_footer}} +function toggleInputs(event) { + toggleInputFields('div_inputs', 'f_classify_managed'); +} + +(function () { + const radios = document.querySelectorAll('input[name="classify"]'); + radios.forEach(radio => { + radio.addEventListener("change", toggleInputs); + }); +})(); + + diff --git a/balance_sheet_exit.html b/balance_sheet_exit.html index 3a56e4a..3d19e35 100644 --- a/balance_sheet_exit.html +++ b/balance_sheet_exit.html @@ -71,18 +71,13 @@ {{:assign valeur_nette="%f-%f"|math:$ligne_immo.montant:$amort_amount}} {{* -lister les exercices ouverts : - - dont la date de fin est postérieure à la date du dernier amortissment - - dont la date de début est antérieure ou égale à la date du jour + lister les exercices ouverts dont la date de fin est postérieure à la date du dernier amortissment *}} {{:assign default_exit_date=""}} {{#years closed=false order="start_date" where=":debut <= end_date" :debut=$date_debut}} {{if $start_date|strtotime <= $now && $now <= $end_date|strtotime}} {{:assign default_exit_date=$now|date_short}} {{/if}} - {{if $start_date|strtotime > $now}} - {{:break}} - {{/if}} {{:assign var="years." id=$id label=$label start_date=$start_date end_date=$end_date}} {{:assign debut=$start_date|date_short}} {{:assign fin=$end_date|date_short}} diff --git a/module.ini b/module.ini index fdd92e7..1c3c73d 100644 --- a/module.ini +++ b/module.ini @@ -1,5 +1,5 @@ name="Amortissements" -description="Immobilisations et amortissements\nversion 0.24" +description="Immobilisations et amortissements\nversion 0.25" author="Jean-Christophe Engel" author_url="https://gitea.zaclys.com/lesanges" home_button=false diff --git a/save_amort.html b/save_amort.html index 8fc110d..2872348 100644 --- a/save_amort.html +++ b/save_amort.html @@ -181,14 +181,14 @@ {{:assign var="lines." debit=$_POST.montant - account=$debit_account|keys|key:0 + account=$debit_account|keys|value:0 id_project=$_GET.project_id label=$_POST.designation }} {{:assign var="lines." credit=$_POST.montant - account=$credit_account|keys|key:0 + account=$credit_account|keys|value:0 id_project=$_GET.project_id label=$_POST.designation }} diff --git a/scripts.js b/scripts.js index 15369ff..17a738f 100644 --- a/scripts.js +++ b/scripts.js @@ -189,11 +189,29 @@ function addLine(button, codes) { }; } +// afficher le montant +function addAmountLine(amount, label, parent) { + const node = document.createElement("tr"); + const col_compte = document.createElement("td"); + col_compte.classList.add("label"); + const col_montant = document.createElement("td"); + col_montant.classList.add("money"); + const span = document.createElement("strong"); + const montant = document.createTextNode(new Intl.NumberFormat("fr-FR", { style: "currency", currency: "EUR" }).format(amount / 100., )); + span.appendChild(montant); + col_compte.appendChild(document.createTextNode(label)); + col_montant.appendChild(span); + node.appendChild(col_compte); + node.appendChild(col_montant); + parent.appendChild(node); +} + // calculer et afficher le total des lignes sélectionnées function computeTotal(id_total, id_url) { - // calculer le total par compte + // calculer le total par compte et le total général let total = new Object; + let total_general = 0; const transactions = []; let lines = document.querySelectorAll('.list tbody tr'); for (const line of lines) { @@ -206,28 +224,31 @@ function computeTotal(id_total, id_url) { } else { total[code] = getNumber(money.innerText) * 100; } + total_general += 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., )); + const body = document.getElementById(id_total).querySelector('table tbody'); + const new_body = document.createElement('tbody'); - span.appendChild(montant); - para.appendChild(libelle); - para.appendChild(span); - node.appendChild(para); - liste.appendChild(node); + for (const code in total) { + addAmountLine(total[code], "Compte " + code + " : ", new_body); + } + body.parentNode.replaceChild(new_body, body); + + // et le total général + const foot = document.getElementById(id_total).querySelector('table tfoot'); + if (Object.keys(total).length > 1) { + const new_foot = document.createElement('tfoot'); + addAmountLine(total_general, "Total : ", new_foot); + foot.parentNode.replaceChild(new_foot, foot); + } else { + // pas besoin de total général si moins de 2 comptes + for (const e of foot.children) { + foot.removeChild(e); + } } // mettre à jour les paramètres de l'url diff --git a/style.css b/style.css index 55f8cdd..cc5a348 100644 --- a/style.css +++ b/style.css @@ -55,3 +55,8 @@ fieldset.shortFormLeft div.informations { span.strong { font-weight: bold; } + +table.montant td.label { + text-align : right; + padding-right : 1em; +} diff --git a/transfer.html b/transfer.html index c7f5dfc..71f123e 100644 --- a/transfer.html +++ b/transfer.html @@ -17,8 +17,59 @@ {{:error message="Aucun exercice ouvert"}} {{/years}} +{{* 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 + }} + {{if $max_date == null || $trans_date > $max_date}} + {{:assign max_date=$trans_date}} + {{/if}} +{{/select}} + {{* Traiter l'envoi du formulaire *}} {{#form on="transfer"}} + {{* vérifier que la date de mise en service est postérieure aux dates d'acquisition *}} + {{if $_POST.date_mes|parse_date < $max_date}} + {{:assign dacq=$max_date|date_short}} + {{:error message="La date de mise en service (%s) doit être postérieure à la date d'acquisition d'immobilisation la plus récente (%s) !"|args:$_POST.date_mes:$dacq}} + {{/if}} + {{* 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}} @@ -54,7 +105,7 @@ account=$elem keep="account_code" }} - {{:assign debit_account=$account_code|keys|key:0}} + {{:assign debit_account=$account_code|keys|value:0}} {{:assign var="amount" from="_POST.credit_lines.%s"|args:$rang}} {{:assign var="label" from="_POST.line_labels.%s"|args:$rang}} {{:assign @@ -71,7 +122,7 @@ account=$_POST.debit_account keep="account_code" }} - {{:assign credit_account=$account_code|keys|key:0}} + {{:assign credit_account=$account_code|keys|value:0}} {{:assign var="amount" from="_POST.debit_lines.%s"|args:0}} {{:assign count=$_POST.line_labels|count}} {{:assign count="%d-1"|math:$count}} @@ -120,7 +171,6 @@ {{: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 @@ -137,7 +187,6 @@ {{:assign type_immo="other"}} {{/if}} {{:redirect force="index.html?ok=1&msg=immobilisation&type_immo=%s"|args:$type_immo}} - {{/form}} {{* barre de navigation *}} @@ -148,6 +197,15 @@ {{:form_errors}} {{* formulaire d'ajout d'immobilisation *}} +{{if $_GET.trans == null}} + {{:error message="Vous n'avez sélectionné aucune écriture !"}} +{{/if}} + +{{if $max_date|strtotime > $now}} + {{:assign default_date=$max_date}} +{{else}} + {{:assign default_date=$now|date_short}} +{{/if}} {{#select id,label FROM acc_projects WHERE archived = 0;}} {{:assign var="projects.%d"|args:$id value=$label}} @@ -162,53 +220,13 @@
La date choisie n'est dans aucun exercice ouvert !