Ajout gestion configuration comptes d'immobilisation
This commit is contained in:
parent
e7763d7cac
commit
bcf89ba874
11 changed files with 309 additions and 28 deletions
|
@ -37,10 +37,9 @@
|
|||
{{* Immobilisation avec une écriture de sortie de bilan *}}
|
||||
{{:read file="./defaut.json" assign="config_json"}}
|
||||
{{:assign config_defaut=$config_json|json_decode}}
|
||||
{{:assign var="prefix_array" value=$config_defaut.prefixes|keys}}
|
||||
|
||||
{{:assign condition="("}}
|
||||
{{#foreach from=$prefix_array item="code"}}
|
||||
{{#foreach from=$config_defaut.prefixes item="code"}}
|
||||
{{:assign code=$code|cat:"%"|quote_sql}}
|
||||
{{:assign condition=$condition|cat:"account.code LIKE "|cat:$code|cat:" OR "}}
|
||||
{{/foreach}}
|
||||
|
|
23
_get_config.html
Normal file
23
_get_config.html
Normal file
|
@ -0,0 +1,23 @@
|
|||
{{* -*- brindille -*- *}}
|
||||
|
||||
{{*
|
||||
Récupérer la config
|
||||
*}}
|
||||
|
||||
{{* config par défaut *}}
|
||||
{{:read file="./defaut.json" assign="config_defaut"}}
|
||||
{{:assign config_defaut=$config_defaut|json_decode}}
|
||||
|
||||
{{*
|
||||
{{if $module.config.tva != null}}
|
||||
{{:assign var="config.tva" value=$module.config.tva}}
|
||||
{{else}}
|
||||
{{:assign var="config.tva" value=$config_defaut.tva}}
|
||||
{{/if}}
|
||||
*}}
|
||||
|
||||
{{if $module.config.prefixes != null}}
|
||||
{{:assign var="config.prefixes" value=$module.config.prefixes}}
|
||||
{{else}}
|
||||
{{:assign var="config.prefixes" value=$config_defaut.prefixes}}
|
||||
{{/if}}
|
|
@ -28,9 +28,8 @@
|
|||
{{* 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 condition="("}}
|
||||
{{#foreach from=$prefix_array item="code"}}
|
||||
{{#foreach from=$config_defaut.prefixes item="code"}}
|
||||
{{:assign code=$code|cat:"%"|quote_sql}}
|
||||
{{:assign condition=$condition|cat:" account.code LIKE "|cat:$code|cat:" OR "}}
|
||||
{{/foreach}}
|
||||
|
|
|
@ -29,9 +29,8 @@
|
|||
{{* 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 condition="("}}
|
||||
{{#foreach from=$prefix_array item="code"}}
|
||||
{{#foreach from=$config_defaut.prefixes item="code"}}
|
||||
{{:assign code=$code|cat:"%"|quote_sql}}
|
||||
{{:assign condition=$condition|cat:" account.code LIKE "|cat:$code|cat:" OR "}}
|
||||
{{/foreach}}
|
||||
|
|
15
_nav.html
15
_nav.html
|
@ -15,14 +15,13 @@
|
|||
</aside>
|
||||
{{/if}}
|
||||
|
||||
{{if $current == "index"}} {{* && $subsubcurrent != "balance_exit" *}}
|
||||
<ul>
|
||||
<li {{if $subcurrent == "managed"}}class="current"{{/if}}><a href="index.html?type_immo=managed">En cours</a></li>
|
||||
<li {{if $subcurrent == "amortized"}}class="current"{{/if}}><a href="index.html?type_immo=amortized">Amorties</a></li>
|
||||
<li {{if $subcurrent == "archived"}}class="current"{{/if}}><a href="index.html?type_immo=archived">Sorties du bilan</a></li>
|
||||
<li {{if $subcurrent == "other"}}class="current"{{/if}}><a href="index.html?type_immo=other">Autres</a></li>
|
||||
</ul>
|
||||
{{/if}}
|
||||
<ul>
|
||||
<li {{if $subcurrent == "managed"}}class="current"{{/if}}><a href="index.html?type_immo=managed">En cours</a></li>
|
||||
<li {{if $subcurrent == "amortized"}}class="current"{{/if}}><a href="index.html?type_immo=amortized">Amorties</a></li>
|
||||
<li {{if $subcurrent == "archived"}}class="current"{{/if}}><a href="index.html?type_immo=archived">Sorties du bilan</a></li>
|
||||
<li {{if $subcurrent == "other"}}class="current"{{/if}}><a href="index.html?type_immo=other">Autres</a></li>
|
||||
<li {{if $current == "config"}} class="current"{{/if}}><a href="config.html">Configuration</a></li>
|
||||
</ul>
|
||||
|
||||
{{if $subsubcurrent == "amortization"}}
|
||||
<ul class="sub">
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
|
||||
{{:read file="./defaut.json" assign="config_json"}}
|
||||
{{:assign config_defaut=$config_json|json_decode}}
|
||||
{{:assign var="prefix_array" value=$config_defaut.prefixes|keys}}
|
||||
|
||||
{{#years closed=false order="start_date" assign=years.}}
|
||||
{{:assign ts_debut=$start_date|strtotime}}
|
||||
|
@ -74,7 +73,7 @@
|
|||
file="_check_account.html"
|
||||
account=$debit_account
|
||||
chart_id=$selected_chart
|
||||
prefix_array=$prefix_array
|
||||
prefix_array=$config_defaut.prefixes
|
||||
keep="account_ok"
|
||||
}}
|
||||
|
||||
|
@ -138,7 +137,7 @@
|
|||
{{:assign var="projects.%d"|args:$id value=$label}}
|
||||
{{/select}}
|
||||
|
||||
{{#foreach from=$prefix_array item="code"}}
|
||||
{{#foreach from=$config_defaut.prefixes item="code"}}
|
||||
{{:assign var="pattern_array." value="%s*"|args:$code}}
|
||||
{{/foreach}}
|
||||
{{:assign var="patterns" value=$pattern_array|implode:"|"}}
|
||||
|
|
247
config.html
Normal file
247
config.html
Normal file
|
@ -0,0 +1,247 @@
|
|||
{{* -*- brindille -*- *}}
|
||||
{{:admin_header title="Configuration" custom_css="./style.css" current="module_amortissement"}}
|
||||
{{* barre de navigation *}}
|
||||
{{:include file="_nav.html" current="config"}}
|
||||
{{if $_GET.ok == 1}}
|
||||
<p class="block confirm">Configuration enregistrée.</p>
|
||||
{{/if}}
|
||||
|
||||
{{* lecture config (défaut ou enregistrée) *}}
|
||||
{{:include file="./_get_config.html" keep="config"}}
|
||||
|
||||
{{*:debug prefixes=$config.prefixes*}}
|
||||
|
||||
{{#form on="save"}}
|
||||
{{*:debug post=$_POST*}}
|
||||
{{:assign ok=0}}
|
||||
{{*
|
||||
TODO ? gérer le cas d'un compte qui englobe un autre...
|
||||
ex : 27 21 273 ou 20 21 27 2
|
||||
*}}
|
||||
{{#foreach from=$_POST.immo_accounts item="line"}}
|
||||
{{:assign elem=$line|values}}
|
||||
{{:assign elem=$elem.0}}
|
||||
{{*:debug elem=$elem*}}
|
||||
{{:assign var="fields" value=$elem|explode:" "}}
|
||||
{{*if ! $account_codes|has:$fields.0*}}
|
||||
{{:assign present=false}}
|
||||
{{* ne pas garder si préfixe d'un compte déjà présent => voir commentaire précédent *}}
|
||||
{{#foreach from=$account_codes item="code"}}
|
||||
{{:assign pos=$code|strpos:$fields.0}}
|
||||
{{*:debug code=$code pos=$pos*}}
|
||||
{{if $pos !== false}}
|
||||
{{:assign present=true}}
|
||||
{{:break}}
|
||||
{{/if}}
|
||||
{{/foreach}}
|
||||
{{if ! $present}}
|
||||
{{:assign var="account_codes." value=$fields.0}}
|
||||
{{/if}}
|
||||
{{/foreach}}
|
||||
{{*:debug codes=$account_codes*}}
|
||||
|
||||
{{:save
|
||||
key="config"
|
||||
prefixes=$account_codes|sort
|
||||
}}
|
||||
{{:assign ok=1}}
|
||||
|
||||
{{:redirect to="./config.html?ok=%d"|args:$ok}}
|
||||
{{/form}}
|
||||
|
||||
{{* récupérer l'exercice courant *}}
|
||||
{{:assign var="selected_year" from="logged_user.preferences.accounting_year}}
|
||||
{{if $selected_year == null}}
|
||||
{{* sélectionner l'exercice le plus probable *}}
|
||||
{{#years closed=false order="start_date"}}
|
||||
{{:assign var="open_years.%d"|args:$id value=$label}}
|
||||
{{if $start_date|strtotime <= $now && $end_date|strtotime >= $now}}
|
||||
{{:assign selected_year=$id}}
|
||||
{{:break}}
|
||||
{{/if}}
|
||||
{{/years}}
|
||||
{{/if}}
|
||||
|
||||
|
||||
{{*
|
||||
{{#select
|
||||
year.id,
|
||||
year.label as year_label,
|
||||
year.start_date,
|
||||
year.end_date,
|
||||
chart.id as chart_id,
|
||||
chart.label AS chart_label
|
||||
FROM acc_years AS year
|
||||
INNER JOIN acc_charts AS chart ON chart.id = year.id_chart
|
||||
WHERE year.id = :year_id;
|
||||
:year_id = $selected_year
|
||||
}}
|
||||
*}}
|
||||
{{*:debug year=$year_label chart=$chart_label*}}
|
||||
{{*
|
||||
{{/select}}
|
||||
*}}
|
||||
|
||||
{{* libellés des comptes d'immobilisation *}}
|
||||
{{:assign condition="("}}
|
||||
{{#foreach from=$config.prefixes item="code"}}
|
||||
{{:assign code=$code|quote_sql}}
|
||||
{{:assign condition=$condition|cat:" account.code = "|cat:$code|cat:" OR "}}
|
||||
{{/foreach}}
|
||||
{{:assign condition=$condition|cat:"0)"}}
|
||||
{{:assign condition=$condition|cat:" AND year.id = %s"|args:$selected_year}}
|
||||
{{*:debug cond=$condition*}}
|
||||
|
||||
{{#select
|
||||
account.id as account_id,
|
||||
account.code,
|
||||
account.id_chart,
|
||||
account.label,
|
||||
year.label as year_label,
|
||||
chart.label as chart_label
|
||||
FROM acc_accounts AS account
|
||||
INNER JOIN acc_charts AS chart ON chart.id = account.id_chart
|
||||
INNER JOIN acc_years AS year ON year.id_chart = chart.id
|
||||
WHERE !condition
|
||||
;
|
||||
!condition=$condition
|
||||
}}
|
||||
{{:assign var="accounts.%s"|args:$code label=$label id=$account_id}}
|
||||
{{*:debug acc_id=$account_id code=$code label=$label year_label=$year_label chart_label=$chart_label*}}
|
||||
{{/select}}
|
||||
{{*:debug accounts=$accounts*}}
|
||||
|
||||
{{*
|
||||
<form method="post" action="">
|
||||
*}}
|
||||
<h3>Comptes d'immobilisation</h3>
|
||||
<form method="post" action="">
|
||||
<table class="list transaction-lines" id="asset_prefixes">
|
||||
<thead>
|
||||
<tr>
|
||||
<td>Compte</td>
|
||||
<td></td>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{{#foreach from=$accounts key=code item=elem}}
|
||||
<tr>
|
||||
<td>
|
||||
{{:assign var="immo_account.%s.%s"|args:$code:$code value="%s — "|args:$code|cat:$elem.label}}
|
||||
{{:assign var="current_account" from="immo_account.%s"|args:$code}}
|
||||
{{*:debug immo_account=$immo_account current_account=$current_account*}}
|
||||
{{:input
|
||||
type="list"
|
||||
name="immo_accounts[]"
|
||||
target="!acc/charts/accounts/selector.php?codes=%s&id_year=%d"|args:$code::$selected_year
|
||||
default=$current_account
|
||||
}}
|
||||
</td>
|
||||
<td class="actions">
|
||||
{{:button
|
||||
label="Enlever"
|
||||
title="Enlever une ligne"
|
||||
shape="minus"
|
||||
min="1"
|
||||
name="remove_line"
|
||||
}}
|
||||
</td>
|
||||
</tr>
|
||||
{{/foreach}}
|
||||
</tbody>
|
||||
<tfoot>
|
||||
<tr>
|
||||
<td></td>
|
||||
<td class="actions">{{:button shape="plus" label="Ajouter" title="Ajouter un compte"}}</td>
|
||||
</tr>
|
||||
</tfoot>
|
||||
</table>
|
||||
{{*
|
||||
<p class="actions">
|
||||
{{:button shape="plus" label="Ajouter" title="Ajouter un compte"}}
|
||||
*}}
|
||||
{{*:button shape="plus" label="Ajouter un compte" onclick="var a = $('#asset_prefixes tbody')[0].lastElementChild; var b = a.cloneNode(true); b.querySelectorAll('input, select').forEach((e) => e.value = null); a.parentNode.append(b);"*}}
|
||||
{{*
|
||||
</p>
|
||||
*}}
|
||||
|
||||
{{*
|
||||
<fieldset>
|
||||
<dl>
|
||||
{{:input
|
||||
type="list"
|
||||
name="immo_account"
|
||||
label="Ajouter un compte d'immobilisation"
|
||||
target="!acc/charts/accounts/selector.php?codes=2*&year=%s"|args:$selected_year
|
||||
}}
|
||||
*}}
|
||||
{{*:input type="checkbox" name="tva" value=1 label="TVA" source=$config help="Cocher si l'asso est assujettie à la TVA"*}}
|
||||
{{*
|
||||
</dl>
|
||||
</fieldset>
|
||||
*}}
|
||||
|
||||
<p class="submit">
|
||||
{{:button type="submit" name="save" label="Enregistrer" shape="right" class="main"}}
|
||||
</p>
|
||||
</form>
|
||||
|
||||
<script type="text/javascript" src="scripts.js"></script>
|
||||
<script type="text/javascript">
|
||||
function remove_line(idtable, code) {
|
||||
let trouve = false, row = null;
|
||||
const table = document.getElementById(idtable);
|
||||
for (let i = 0; i < table.rows.length; ++i) {
|
||||
row = table.rows[i];
|
||||
for (let j = 0; j < row.cells.length; ++j) {
|
||||
const col = row.cells[j];
|
||||
if (col.innerText == code) {
|
||||
trouve = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (trouve) { break; }
|
||||
}
|
||||
if (row != null) {
|
||||
row.parentNode.removeChild(row);
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<script type="text/javascript" async="async">
|
||||
|
||||
// bouton - : supprimer une ligne
|
||||
var lines = $('.transaction-lines tbody tr');
|
||||
lines.forEach(initLine);
|
||||
|
||||
// bouton + : dupliquer une ligne
|
||||
$('.transaction-lines tfoot button')[0].onclick = () => {
|
||||
let lines = $('.transaction-lines tbody tr');
|
||||
var line = lines[lines.length - 1];
|
||||
var n = line.cloneNode(true);
|
||||
|
||||
// Réinitialiser le sélecteur de compte
|
||||
let b = n.querySelector('.input-list button');
|
||||
let url = b.value;
|
||||
let new_url = url.replace(/codes=[0-9]+\*?/, "codes=2*");
|
||||
b.value = new_url;
|
||||
|
||||
// gestionnaire d'événement
|
||||
b.onclick = () => {
|
||||
g.current_list_input = b.parentNode;
|
||||
let url = b.value + (b.value.indexOf('?') > 0 ? '&' : '?') + '_dialog';
|
||||
g.openFrameDialog(url);
|
||||
return false;
|
||||
};
|
||||
|
||||
// réinitialiser le label
|
||||
let l = n.querySelector('.input-list span.label');
|
||||
console.log("label=" + l.innerText);
|
||||
l.innerText = '';
|
||||
|
||||
line.parentNode.appendChild(n);
|
||||
initLine(n);
|
||||
|
||||
};
|
||||
</script>
|
||||
|
10
defaut.json
10
defaut.json
|
@ -1,8 +1,8 @@
|
|||
{
|
||||
"tva": false,
|
||||
"prefixes": {
|
||||
"20": "Immobilisations incorporelles",
|
||||
"21": "Immobilisations corporelles",
|
||||
"27": "Immobilisations financières"
|
||||
}
|
||||
"prefixes": [
|
||||
"20",
|
||||
"21",
|
||||
"27"
|
||||
]
|
||||
}
|
||||
|
|
|
@ -149,8 +149,7 @@
|
|||
*}}
|
||||
{{: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"}}
|
||||
{{#foreach from=$config_defaut.prefixes item="code"}}
|
||||
{{* déterminer le numéro du compte d'amortissement associé au compte d'immobilisation *}}
|
||||
{{:include
|
||||
file="./_get_amort_code.html"
|
||||
|
@ -254,7 +253,7 @@
|
|||
{{:input
|
||||
type="list"
|
||||
name="credit_account"
|
||||
label="Compte d'amortissement (280xx ou 281xx)"
|
||||
label="Compte d'amortissement (28xx)"
|
||||
required=true
|
||||
target="!acc/charts/accounts/selector.php?codes=%s&id_year=%d"|args:"28*":$selected_year
|
||||
default=$credit_account
|
||||
|
|
18
scripts.js
18
scripts.js
|
@ -139,3 +139,21 @@ function setSelectorYear(button_names, f_years_selector) {
|
|||
const selected_year = document.getElementById(f_years_selector).value;
|
||||
setAccountYear(button_names, selected_year);
|
||||
}
|
||||
|
||||
// config : gestion des ajouts/suppression comptes immo
|
||||
|
||||
function initLine(row) {
|
||||
var removeBtn = row.querySelector('button[name="remove_line"]');
|
||||
removeBtn.onclick = () => {
|
||||
var count = $('.transaction-lines tbody tr').length;
|
||||
var min = removeBtn.getAttribute('min');
|
||||
|
||||
if (count <= min) {
|
||||
alert("Il n'est pas possible d'avoir moins de " + min + " compte(s).");
|
||||
return false;
|
||||
}
|
||||
|
||||
row.parentNode.removeChild(row);
|
||||
return true;
|
||||
};
|
||||
}
|
||||
|
|
|
@ -260,7 +260,7 @@
|
|||
}}
|
||||
{{/if}}
|
||||
|
||||
{{:redirect to="index.html?type_immo=sortie"}}
|
||||
{{:redirect to="index.html?type_immo=archived"}}
|
||||
{{/form}}
|
||||
|
||||
{{:admin_header title="Sortie du bilan" custom_css="./style.css" current="module_amortissement"}}
|
||||
|
@ -311,9 +311,8 @@
|
|||
|
||||
{{: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"}}
|
||||
{{#foreach from=$config_defaut.prefixes item="code"}}
|
||||
{{:assign var="pattern_array." value="%s*"|args:$code}}
|
||||
{{/foreach}}
|
||||
{{:assign patterns=$pattern_array|implode:"|"}}
|
||||
|
|
Loading…
Add table
Reference in a new issue