amortization/config.html
Jean-Christophe Engel 7a41c43ea3 Nettoyage code
2025-09-15 15:09:43 +02:00

191 lines
5.2 KiB
HTML

{{* -*- 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"}}
{{#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}}
{{/if}}
{{/foreach}}
{{if ! $present}}
{{:assign var="account_codes." value=$fields.0}}
{{/if}}
{{/foreach}}
{{: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}}
{{* 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}}
{{#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}}
{{/select}}
<h3>Comptes d'immobilisation</h3>
<form method="post" action="">
<p class="help">
Les immobilisations sont cherchées dans les comptes sélectionnées et leurs sous-comptes.
</p>
<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="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>