diff --git a/_archives.html b/_archives.html index e774b6d..0bf6672 100644 --- a/_archives.html +++ b/_archives.html @@ -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}} diff --git a/_get_config.html b/_get_config.html new file mode 100644 index 0000000..25cd4e7 --- /dev/null +++ b/_get_config.html @@ -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}} diff --git a/_immobilisations.html b/_immobilisations.html index e9d6eab..6144a45 100644 --- a/_immobilisations.html +++ b/_immobilisations.html @@ -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}} diff --git a/_immobilisations_autres.html b/_immobilisations_autres.html index f283686..f5cf801 100644 --- a/_immobilisations_autres.html +++ b/_immobilisations_autres.html @@ -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}} diff --git a/_nav.html b/_nav.html index fc5c3c3..323d316 100644 --- a/_nav.html +++ b/_nav.html @@ -15,14 +15,13 @@ {{/if}} - {{if $current == "index"}} {{* && $subsubcurrent != "balance_exit" *}} -
Configuration enregistrée.
+{{/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*}} + +{{* +