Configuration comptes immobilisations en cours
This commit is contained in:
parent
ff2d16d8cb
commit
403887a15f
11 changed files with 234 additions and 151 deletions
|
|
@ -6,14 +6,12 @@
|
|||
</p>
|
||||
|
||||
{{* Immobilisation avec une écriture de sortie de bilan *}}
|
||||
{{:include file="_get_config.html" keep="config.prefixes"}}
|
||||
{{:include file="_get_config.html" keep="module.config"}}
|
||||
|
||||
{{:assign condition="("}}
|
||||
{{#foreach from=$config.prefixes item="code"}}
|
||||
{{if $code|substr:0:2 != "23"}}
|
||||
{{#foreach from=$module.config.prefixes item="code"}}
|
||||
{{:assign code=$code|cat:"%"|quote_sql}}
|
||||
{{:assign condition=$condition|cat:"account.code LIKE "|cat:$code|cat:" OR "}}
|
||||
{{/if}}
|
||||
{{/foreach}}
|
||||
{{:assign condition=$condition|cat:"0)"}}
|
||||
{{:assign condition=$condition|cat:" AND acc2.code = account.code AND line.debit > 0 AND line.debit = line2.credit AND NOT (trans.status & 16)"}}
|
||||
|
|
|
|||
|
|
@ -4,19 +4,20 @@
|
|||
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.prefixes == null}}
|
||||
{{:assign var="module.config.prefixes" value=$config_defaut.prefixes}}
|
||||
{{/if}}
|
||||
|
||||
{{if $module.config.unfinished == null}}
|
||||
{{:assign var="module.config.unfinished" value=$config_defaut.unfinished}}
|
||||
{{/if}}
|
||||
|
||||
{{*
|
||||
{{if $module.config.tva != null}}
|
||||
{{:assign var="config.tva" value=$module.config.tva}}
|
||||
{{else}}
|
||||
{{:assign var="config.tva" value=$config_defaut.tva}}
|
||||
{{if $module.config.tva == null}}
|
||||
{{:assign var="module.config.tva" value=$config_defaut.tva}}
|
||||
{{/if}}
|
||||
*}}
|
||||
|
||||
{{if $module.config.prefixes != null}}
|
||||
{{:assign var="config.prefixes" value=$module.config.prefixes}}
|
||||
{{else}}
|
||||
{{* config par défaut *}}
|
||||
{{:read file="./defaut.json" assign="config_defaut"}}
|
||||
{{:assign config_defaut=$config_defaut|json_decode}}
|
||||
{{:assign var="config.prefixes" value=$config_defaut.prefixes}}
|
||||
{{/if}}
|
||||
|
|
|
|||
|
|
@ -28,14 +28,12 @@
|
|||
<tbody>
|
||||
|
||||
{{* lister les immobilisations *}}
|
||||
{{:include file="_get_config.html" keep="config.prefixes"}}
|
||||
{{:include file="_get_config.html" keep="module.config"}}
|
||||
|
||||
{{:assign condition="("}}
|
||||
{{#foreach from=$config.prefixes item="code"}}
|
||||
{{if $code|substr:0:2 != "23"}}
|
||||
{{#foreach from=$module.config.prefixes item="code"}}
|
||||
{{:assign code=$code|cat:"%"|quote_sql}}
|
||||
{{:assign condition=$condition|cat:" account.code LIKE "|cat:$code|cat:" OR "}}
|
||||
{{/if}}
|
||||
{{/foreach}}
|
||||
{{:assign condition=$condition|cat:"0)"}}
|
||||
{{:assign condition=$condition|cat:" AND debit > 0 AND NOT (trans.status & 16)"}}
|
||||
|
|
|
|||
|
|
@ -29,13 +29,12 @@
|
|||
<tbody>
|
||||
|
||||
{{* lister les immobilisations *}}
|
||||
{{:include file="_get_config.html" keep="config.prefixes"}}
|
||||
{{:include file="_get_config.html" keep="module.config.prefixes"}}
|
||||
|
||||
{{:assign condition="("}}
|
||||
{{#foreach from=$config.prefixes item="code"}}
|
||||
{{if $code|substr:0:2 != "23"}}
|
||||
{{#foreach from=$module.config.prefixes item="code"}}
|
||||
{{:assign code=$code|cat:"%"|quote_sql}}
|
||||
{{:assign condition=$condition|cat:" account.code LIKE "|cat:$code|cat:" OR "}}
|
||||
{{/if}}
|
||||
{{/foreach}}
|
||||
{{:assign condition=$condition|cat:"0)"}}
|
||||
{{:assign condition=$condition|cat:" AND debit > 0 AND NOT (trans.status & 16)"}}
|
||||
|
|
|
|||
|
|
@ -23,7 +23,15 @@
|
|||
<tbody>
|
||||
|
||||
{{* lister les immobilisations en cours de constitution *}}
|
||||
{{:assign condition=$condition|cat:"account.code LIKE '23%' AND debit > 0 AND NOT (trans.status & 16)"}}
|
||||
{{: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)"}}
|
||||
{{:assign condition=$condition|cat:" AND debit > 0 AND NOT (trans.status & 16)"}}
|
||||
{{:assign nb_immo=0}}
|
||||
|
||||
{{#select
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
{{* -*- brindille -*- *}}
|
||||
|
||||
{{:include file="_get_config.html" keep="config.prefixes"}}
|
||||
{{:include file="_get_config.html" keep="module.config.prefixes"}}
|
||||
|
||||
{{#years closed=false order="start_date" assign=years.}}
|
||||
{{:assign ts_debut=$start_date|strtotime}}
|
||||
|
|
@ -74,7 +74,7 @@
|
|||
file="_check_account.html"
|
||||
account=$debit_account
|
||||
chart_id=$selected_chart
|
||||
prefix_array=$config.prefixes
|
||||
prefix_array=$module.config.prefixes
|
||||
keep="account_ok"
|
||||
}}
|
||||
|
||||
|
|
@ -138,7 +138,7 @@
|
|||
{{:assign var="projects.%d"|args:$id value=$label}}
|
||||
{{/select}}
|
||||
|
||||
{{#foreach from=$config.prefixes item="code"}}
|
||||
{{#foreach from=$module.config.prefixes item="code"}}
|
||||
{{:assign var="pattern_array." value="%s*"|args:$code}}
|
||||
{{/foreach}}
|
||||
{{:assign var="patterns" value=$pattern_array|implode:"|"}}
|
||||
|
|
|
|||
194
config.html
194
config.html
|
|
@ -1,7 +1,6 @@
|
|||
{{* -*- 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}}
|
||||
|
|
@ -9,35 +8,48 @@
|
|||
{{/if}}
|
||||
|
||||
{{* lecture config (défaut ou enregistrée) *}}
|
||||
{{:include file="./_get_config.html" keep="config"}}
|
||||
{{:include file="./_get_config.html" keep="module.config, config_defaut"}}
|
||||
|
||||
{{#form on="save"}}
|
||||
{{:assign ok=0}}
|
||||
{{#foreach from=$_POST.immo_accounts item="line"}}
|
||||
{{:assign elem=$line|values}}
|
||||
{{:assign elem=$elem.0}}
|
||||
{{:assign var="fields" value=$elem|explode:" "}}
|
||||
{{:assign present=false}}
|
||||
{{* ne pas garder si préfixe d'un compte déjà présent *}}
|
||||
{{#foreach from=$account_codes item="code"}}
|
||||
{{:assign pos=$code|strpos:$fields.0}}
|
||||
{{if $pos !== false}}
|
||||
{{:assign present=true}}
|
||||
{{:break}}
|
||||
{{:assign var="fields" value=$elem|explode:" — "}}
|
||||
{{if $fields.0|strpos:$config_defaut.unfinished.0.code === 0}}
|
||||
{{:error message="Le compte « %s » n'est pas un compte d'immobilisation amortissable"|args:$fields.0}}
|
||||
{{/if}}
|
||||
{{:assign var="account_codes." value=$fields.0}}
|
||||
{{/foreach}}
|
||||
|
||||
{{#foreach from=$_POST.unfinished_accounts item="line"}}
|
||||
{{:assign elem=$line|values}}
|
||||
{{:assign elem=$elem.0}}
|
||||
{{:assign var="fields" value=$elem|explode:" — "}}
|
||||
{{:assign var="unfinished_codes." value=$fields.0}}
|
||||
{{/foreach}}
|
||||
|
||||
{{* vérifier qu'il n'y a pas d'intersection entre les deux listes de codes *}}
|
||||
{{#foreach from=$account_codes item="i_code"}}
|
||||
{{#foreach from=$unfinished_codes item="u_code"}}
|
||||
{{if $i_code|strpos:$u_code === 0}}
|
||||
{{:error message="Le compte d'immobilisation amortissable « %s » est incompatible avec le compte d'immobilisation en cours « %s »"|args:$i_code:$u_code}}
|
||||
{{/if}}
|
||||
{{if $u_code|strpos:$i_code === 0}}
|
||||
{{:error message="Le compte d'immobilisation amortissable « %s » est incompatible avec le compte d'immobilisation en cours « %s »"|args:$i_code:$u_code}}
|
||||
{{/if}}
|
||||
{{/foreach}}
|
||||
{{if ! $present}}
|
||||
{{:assign var="account_codes." value=$fields.0}}
|
||||
{{/if}}
|
||||
{{/foreach}}
|
||||
|
||||
{{:save
|
||||
key="config"
|
||||
prefixes=$account_codes|sort
|
||||
unfinished=$unfinished_codes|sort
|
||||
}}
|
||||
{{:assign ok=1}}
|
||||
|
||||
{{:redirect to="./config.html?ok=%d"|args:$ok}}
|
||||
{{else}}
|
||||
{{:form_errors}}
|
||||
{{/form}}
|
||||
|
||||
{{* récupérer l'exercice courant ou sinon le plus récent *}}
|
||||
|
|
@ -60,12 +72,11 @@
|
|||
{{:assign selected_year=$last_year}}
|
||||
{{/if}}
|
||||
{{/if}}
|
||||
|
||||
{{if $selected_year != null}}
|
||||
|
||||
{{* libellés des comptes d'immobilisation *}}
|
||||
{{* libellés des comptes d'immobilisation amortissables *}}
|
||||
{{:assign condition="("}}
|
||||
{{#foreach from=$config.prefixes item="code"}}
|
||||
{{#foreach from=$module.config.prefixes item="code"}}
|
||||
{{:assign code=$code|quote_sql}}
|
||||
{{:assign condition=$condition|cat:" account.code = "|cat:$code|cat:" OR "}}
|
||||
{{/foreach}}
|
||||
|
|
@ -75,10 +86,7 @@
|
|||
{{#select
|
||||
account.id as account_id,
|
||||
account.code,
|
||||
account.id_chart,
|
||||
account.label,
|
||||
year.label as year_label,
|
||||
chart.label as chart_label
|
||||
account.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
|
||||
|
|
@ -86,25 +94,50 @@
|
|||
;
|
||||
!condition=$condition
|
||||
}}
|
||||
{{:assign var="accounts.%s"|args:$code label=$label id=$account_id}}
|
||||
{{:assign var="immo_accounts.%s"|args:$code label=$label}}
|
||||
{{/select}}
|
||||
|
||||
<h3>Comptes d'immobilisation</h3>
|
||||
<form method="post" action="">
|
||||
{{* libellés des comptes d'immobilisation en cours de constitution *}}
|
||||
{{:assign condition="("}}
|
||||
{{#foreach from=$module.config.unfinished item="elem"}}
|
||||
{{:assign code=$elem.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}}
|
||||
|
||||
{{#select
|
||||
account.id as account_id,
|
||||
account.code,
|
||||
account.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="unfinished_accounts.%s"|args:$code label=$label}}
|
||||
{{/select}}
|
||||
{{if $unfinished_accounts|count == 0}}
|
||||
{{:assign var="unfinished_accounts.%s"|args:$config_defaut.unfinished.0.code label=$config_defaut.unfinished.0.label}}
|
||||
{{/if}}
|
||||
|
||||
<form method="post" action="">
|
||||
<h3>Comptes d'immobilisation amortissables</h3>
|
||||
<p class="help">
|
||||
Les immobilisations sont cherchées dans les comptes sélectionnées et leurs sous-comptes.
|
||||
Les immobilisations amortissables sont cherchées dans les comptes sélectionnés et leurs sous-comptes.
|
||||
</p>
|
||||
|
||||
<table class="list transaction-lines" id="asset_prefixes">
|
||||
<thead>
|
||||
<tr>
|
||||
<td>Compte</td>
|
||||
<td></td>
|
||||
<th>Compte</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{{#foreach from=$accounts key=code item=elem}}
|
||||
{{#foreach from=$immo_accounts key=code item=elem}}
|
||||
<tr>
|
||||
<td>
|
||||
{{:assign var="immo_account.%s.%s"|args:$code:$code value="%s — "|args:$code|cat:$elem.label}}
|
||||
|
|
@ -112,7 +145,54 @@
|
|||
{{:input
|
||||
type="list"
|
||||
name="immo_accounts[]"
|
||||
target="!acc/charts/accounts/selector.php?codes=%s&id_year=%d"|args:$code::$selected_year
|
||||
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>
|
||||
|
||||
<h3>Comptes d'immobilisation en cours de constitution</h3>
|
||||
<p class="help">
|
||||
Ces immobilisations ne sont pas amortissables ; elles sont cherchées dans les comptes sélectionnés et leurs sous-comptes.
|
||||
</p>
|
||||
|
||||
<table class="list transaction-lines" id="unfinished_accounts">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Compte</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
|
||||
{{#foreach from=$unfinished_accounts key=code item=elem}}
|
||||
<tr>
|
||||
<td>
|
||||
{{:assign var="unfinished_account.%s.%s"|args:$code:$code value="%s — "|args:$code|cat:$elem.label}}
|
||||
{{:assign var="current_account" from="unfinished_account.%s"|args:$code}}
|
||||
|
||||
{{:input
|
||||
type="list"
|
||||
name="unfinished_accounts[]"
|
||||
target="!acc/charts/accounts/selector.php?codes=%s*&id_year=%d"|args:$code::$selected_year
|
||||
default=$current_account
|
||||
}}
|
||||
</td>
|
||||
|
|
@ -143,60 +223,20 @@
|
|||
{{/if}}
|
||||
|
||||
<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);
|
||||
// bouton + : dupliquer une ligne de la 1ère table
|
||||
for (const b of $('#asset_prefixes tfoot button')) {
|
||||
addLine(b, "2*");
|
||||
}
|
||||
|
||||
// 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;
|
||||
// bouton + : dupliquer une ligne de la 2ème table
|
||||
for (const b of $('#unfinished_accounts tfoot button')) {
|
||||
addLine(b, "23*");
|
||||
}
|
||||
|
||||
// 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>
|
||||
|
|
|
|||
|
|
@ -4,5 +4,11 @@
|
|||
"20",
|
||||
"21",
|
||||
"27"
|
||||
],
|
||||
"unfinished": [
|
||||
{
|
||||
"code" : "23",
|
||||
"label" : "Immobilisations en cours"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
|
|||
|
|
@ -147,8 +147,8 @@
|
|||
- 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
|
||||
*}}
|
||||
{{:include file="_get_config.html" keep="config.prefixes"}}
|
||||
{{#foreach from=$config.prefixes item="code"}}
|
||||
{{:include file="_get_config.html" keep="module.config.prefixes"}}
|
||||
{{#foreach from=$module.config.prefixes item="code"}}
|
||||
{{* déterminer le numéro du compte d'amortissement associé au compte d'immobilisation *}}
|
||||
{{:include
|
||||
file="./_get_amort_code.html"
|
||||
|
|
|
|||
35
scripts.js
35
scripts.js
|
|
@ -142,10 +142,11 @@ function setSelectorYear(button_names, f_years_selector) {
|
|||
|
||||
// config : gestion des ajouts/suppression comptes immo
|
||||
|
||||
// Associer au bouton « Enlever » de chaque ligne l'action de suppression de la ligne
|
||||
function initLine(row) {
|
||||
var removeBtn = row.querySelector('button[name="remove_line"]');
|
||||
removeBtn.onclick = () => {
|
||||
var count = $('.transaction-lines tbody tr').length;
|
||||
let count = removeBtn.closest("table").querySelectorAll('tbody tr').length;
|
||||
var min = removeBtn.getAttribute('min');
|
||||
|
||||
if (count <= min) {
|
||||
|
|
@ -157,3 +158,35 @@ function initLine(row) {
|
|||
return true;
|
||||
};
|
||||
}
|
||||
|
||||
// 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];
|
||||
let newNode = line.cloneNode(true);
|
||||
|
||||
// Réinitialiser le sélecteur de compte
|
||||
let selectButton = newNode.querySelector('.input-list button');
|
||||
let url = selectButton.value;
|
||||
let new_url = url.replace(/codes=[0-9]+\*?/, "codes=" + codes);
|
||||
selectButton.value = new_url;
|
||||
|
||||
// gestionnaire d'événement du sélecteur
|
||||
selectButton.onclick = () => {
|
||||
g.current_list_input = selectButton.parentNode;
|
||||
let url = selectButton.value + (selectButton.value.indexOf('?') > 0 ? '&' : '?') + '_dialog';
|
||||
g.openFrameDialog(url);
|
||||
return false;
|
||||
};
|
||||
|
||||
// réinitialiser le libellé associé au sélecteur
|
||||
let lib = newNode.querySelector('.input-list span.label');
|
||||
lib.innerText = '';
|
||||
|
||||
// ajouter la nouvelle ligne
|
||||
line.parentNode.appendChild(newNode);
|
||||
initLine(newNode);
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -311,8 +311,8 @@
|
|||
{{:assign var="%s.%s"|args:$name:$code value="%s — %s"|args:$code:$acc_label}}
|
||||
{{/foreach}}
|
||||
|
||||
{{:include file="_get_config.html" keep="config.prefixes"}}
|
||||
{{#foreach from=$config.prefixes item="code"}}
|
||||
{{:include file="_get_config.html" keep="module.config.prefixes"}}
|
||||
{{#foreach from=$module.config.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