Compare commits
12 commits
main
...
classifica
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
62692ef550 | ||
|
|
401aac686b | ||
|
|
b74ef8ae9c | ||
|
|
d6fd5b4047 | ||
|
|
e31286f440 | ||
|
|
faccd71ef8 | ||
|
|
87a1f31bb3 | ||
|
|
d5c62b6ef3 | ||
|
|
f8f4da59b6 | ||
|
|
463d5d109e | ||
|
|
269ff406e4 | ||
|
|
aae9580ee0 |
19 changed files with 1258 additions and 815 deletions
|
|
@ -149,12 +149,12 @@
|
|||
{{/select}}
|
||||
|
||||
<tr>
|
||||
<td class="num"><a href="{{$trans_url}}">#{{$trans_id}}</a></td>
|
||||
<td class="num"><a href={{$trans_url}}>#{{$trans_id}}</a></td>
|
||||
<td>{{$trans_date|date_short}}</td>
|
||||
<td>{{$exit_date|date_short}}</td>
|
||||
<td>{{$trans_label}}{{if $line_label != null && $line_label != $trans_label}} — {{$line_label}}{{/if}}</td>
|
||||
<td class="money">{{"%f"|math:$montant_immo|money_html:false|raw}}</td>
|
||||
<td><a href="{{$compte_url}}">{{$account_code}}</a></td>
|
||||
<td><a href={{$compte_url}}>{{$account_code}}</a></td>
|
||||
<td>{{$account_label}}</td>
|
||||
<td>{{$project_label}}</td>
|
||||
<td class="actions">
|
||||
|
|
|
|||
|
|
@ -3,16 +3,16 @@
|
|||
{{* Liste des immobilisations en cours d'amortissement ou amorties *}}
|
||||
|
||||
{{:include file="_get_config.html" keep="module.config"}}
|
||||
<section class="immobilisation">
|
||||
|
||||
<p class="help">
|
||||
{{if $type_immo == "managed"}}
|
||||
Cette page liste les immobilisations en cours d'amortissement
|
||||
{{elseif $type_immo == "amortized"}}
|
||||
Cette page liste les immobilisations dont l'amortissement est terminé
|
||||
{{/if}}
|
||||
</p>
|
||||
<p class="help">
|
||||
{{if $type_immo == "managed"}}
|
||||
Cette page liste les immobilisations en cours d'amortissement
|
||||
{{elseif $type_immo == "amortized"}}
|
||||
Cette page liste les immobilisations dont l'amortissement est terminé
|
||||
{{/if}}
|
||||
</p>
|
||||
|
||||
{{if $module.table != null}}
|
||||
<table class="list">
|
||||
<thead>
|
||||
<tr>
|
||||
|
|
@ -29,14 +29,6 @@
|
|||
</thead>
|
||||
<tbody>
|
||||
|
||||
{{* vérifier l'existence de la table du module *}}
|
||||
{{#load limit="1"}}
|
||||
{{:assign table_presente=true}}
|
||||
{{else}}
|
||||
{{:assign table_presente=false}}
|
||||
{{/load}}
|
||||
|
||||
{{if $table_presente}}
|
||||
{{* lister les immobilisations *}}
|
||||
{{:assign account_condition="("}}
|
||||
{{#foreach from=$module.config.prefixes item="code"}}
|
||||
|
|
@ -44,17 +36,8 @@
|
|||
{{:assign account_condition=$account_condition|cat:" account.code LIKE "|cat:$code|cat:" OR "}}
|
||||
{{/foreach}}
|
||||
{{:assign account_condition=$account_condition|cat:"0)"}}
|
||||
{{:assign doc_condition="($$.status <> 'ignored' AND $$.status <> 'archived')"}}
|
||||
|
||||
{{:assign filter_condition="NOT ("}}
|
||||
{{#foreach from=$module.config.filters item="filter"}}
|
||||
{{:assign filter="%"|cat:$filter|cat:"%"|quote_sql}}
|
||||
{{:assign filter_condition=$filter_condition|cat:" trans_label LIKE "|cat:$filter|cat:" OR "}}
|
||||
{{/foreach}}
|
||||
{{:assign filter_condition=$filter_condition|cat:"0)"}}
|
||||
{{:assign filter_condition="($$.status IS NULL AND NOT (trans.status & 16) AND "|cat:$filter_condition|cat:")"}}
|
||||
|
||||
{{:assign condition=$account_condition|cat:" AND debit > 0 AND ("|cat:$filter_condition|cat:" OR "|cat:$doc_condition|cat:")"}}
|
||||
{{:assign status_condition="($$.status = 'managed' OR $$.status = 'amortized')"}}
|
||||
{{:assign condition=$account_condition|cat:" AND line.debit > 0 AND "|cat:$status_condition}}
|
||||
|
||||
{{:assign nb_immo=0}}
|
||||
{{:assign total_immo = 0}}
|
||||
|
|
@ -68,125 +51,79 @@
|
|||
account.id as account_id,
|
||||
account.code as account_code,
|
||||
trans.id_year as trans_id_year,
|
||||
info.id as immo_doc_id,
|
||||
$$.duration as duration,
|
||||
$$.label as doc_label,
|
||||
$$.amount as doc_amount,
|
||||
$$.date_achat as doc_date_achat,
|
||||
$$.date as doc_date_mes,
|
||||
$$.status as status
|
||||
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
|
||||
INNER JOIN acc_years AS years ON trans.id_year = years.id
|
||||
LEFT JOIN !table AS info ON $$.line = line.id
|
||||
INNER JOIN !table AS info ON $$.line = line.id
|
||||
WHERE !condition
|
||||
ORDER BY trans.date DESC;
|
||||
ORDER BY COALESCE(doc_date_achat, trans_date) DESC;
|
||||
!table=$module.table
|
||||
!condition=$condition
|
||||
}}
|
||||
{{:assign trans_url="%s/acc/transactions/details.php?id=%s"|args:$admin_url:$immo_trans_id}}
|
||||
{{:assign compte_url="%s/acc/accounts/journal.php?id=%s&year=%s"|args:$admin_url:$account_id:$trans_id_year}}
|
||||
{{:assign duration=$duration}}
|
||||
{{:assign montant_immo=$debit}}
|
||||
{{if $status == null}}
|
||||
{{:assign status="unknown"}}
|
||||
{{:assign montant_immo=$doc_amount|or:$debit}}
|
||||
{{:assign immo_date = $doc_date_achat|or:$trans_date}}
|
||||
{{:assign label_immo=$doc_label|or:$trans_label}}
|
||||
{{if $line_label != null && $line_label != $label_immo}}
|
||||
{{:assign label_immo=$label_immo|cat:" — "|cat:$line_label}}
|
||||
{{/if}}
|
||||
|
||||
{{* chercher des écritures liées à l'immo courante au crédit du même compte
|
||||
{{*
|
||||
chercher des écritures liées à l'immo courante au crédit du même compte
|
||||
et déduire leur montant de celui de l'immo
|
||||
*}}
|
||||
{{#select
|
||||
CASE links.id_related = :immo_trans_id
|
||||
WHEN true THEN links.id_transaction
|
||||
WHEN false THEN links.id_related
|
||||
END as other_id,
|
||||
line.credit
|
||||
FROM acc_transactions AS trans
|
||||
INNER JOIN acc_transactions_links as links
|
||||
ON (trans.id = links.id_transaction OR trans.id = links.id_related)
|
||||
INNER JOIN acc_transactions_lines AS line on line.id_transaction = other_id
|
||||
INNER JOIN acc_accounts AS acc ON line.id_account = acc.id
|
||||
WHERE trans.id = :immo_trans_id AND line.credit > 0 AND acc.code = :account;
|
||||
:immo_trans_id=$immo_trans_id
|
||||
:account=$account_code
|
||||
}}
|
||||
{{:assign montant_immo="%d-%d"|math:$montant_immo:$credit}}
|
||||
{{/select}}
|
||||
{{#load
|
||||
type="immo_link"
|
||||
where="$$.immo_doc_id = :immo_doc_id" :immo_doc_id = $immo_doc_id
|
||||
}}
|
||||
{{if $amount == null}}
|
||||
{{#select credit FROM acc_transactions_lines WHERE id = :credit_line_id;
|
||||
:credit_line_id=$credit_line_id
|
||||
}}
|
||||
{{:assign montant_immo="%d-%d"|math:$montant_immo:$credit}}
|
||||
{{/select}}
|
||||
{{else}}
|
||||
{{:assign montant_immo="%d-%d"|math:$montant_immo:$amount}}
|
||||
{{/if}}
|
||||
{{/load}}
|
||||
|
||||
{{* Immobilisation soldée ? *}}
|
||||
{{* TODO marquer archivée *}}
|
||||
{{* TODO ¿ marquer archivée ? *}}
|
||||
{{if $montant_immo == 0}}
|
||||
{{:continue}}
|
||||
{{/if}}
|
||||
|
||||
{{* lister les lignes des écritures d'amortissement liées à l'immobilisation *}}
|
||||
{{* chercher des lignes des écritures d'amortissement liées à la ligne d'immobilisation *}}
|
||||
{{:assign amort_lines=null}}
|
||||
{{#select
|
||||
l_amort.credit as amount,
|
||||
CASE links.id_related = t_immo.id
|
||||
WHEN true THEN links.id_transaction
|
||||
WHEN false THEN links.id_related
|
||||
END as amort_trans_id,
|
||||
l_amort.id AS amort_line_id
|
||||
FROM acc_transactions_lines as l_immo
|
||||
INNER JOIN acc_transactions as t_immo on t_immo.id = l_immo.id_transaction
|
||||
INNER JOIN acc_transactions_links as links
|
||||
ON (t_immo.id = links.id_transaction OR t_immo.id = links.id_related)
|
||||
INNER JOIN acc_transactions_lines as l_amort on amort_trans_id = l_amort.id_transaction
|
||||
INNER JOIN acc_accounts AS account ON l_amort.id_account = account.id
|
||||
WHERE l_immo.id = :line_id AND l_amort.credit <> 0 AND account.code LIKE '28%';
|
||||
:line_id = $immo_line_id|intval
|
||||
assign="line"
|
||||
}}
|
||||
{{:assign var="amort_lines.%d."|args:$amort_trans_id value=$line}}
|
||||
{{/select}}
|
||||
|
||||
{{:assign amort_amount=0}}
|
||||
{{#foreach from=$amort_lines key="amort_trans_id" item="lines"}}
|
||||
{{:assign nb=$lines|count}}
|
||||
{{* lister les docs de liaison de l'écriture d'amortissement *}}
|
||||
{{:assign links=null}}
|
||||
{{#load type="link"
|
||||
where="$$.immo_line_id = :immo_line_id AND $$.amort_trans_id = :amort_trans_id"
|
||||
:immo_line_id = $immo_line_id
|
||||
:amort_trans_id = $amort_trans_id
|
||||
assign="links."
|
||||
{{#load type="amort_link"
|
||||
where="$$.immo_doc_id = :immo_doc_id"
|
||||
:immo_doc_id = $immo_doc_id
|
||||
assign="amort_link"
|
||||
}}
|
||||
{{/load}}
|
||||
|
||||
{{#foreach from=$lines item="line"}}
|
||||
{{* voir s'il existe une ligne associée à l'écriture d'amortissement *}}
|
||||
{{:assign line_link_exist=false}}
|
||||
{{#foreach from=$links item="link"}}
|
||||
{{if $link.amort_line_id == $line.amort_line_id}}
|
||||
{{:assign amort_amount="%d+%d"|math:$amort_amount:$line.amount}}
|
||||
{{:assign line_link_exist=true}}
|
||||
{{/if}}
|
||||
{{/foreach}}
|
||||
{{if ! $line_link_exist}}
|
||||
{{if $nb == 1}}
|
||||
{{* créer la liaison ligne immo <-> ligne amort *}}
|
||||
{{*:debug lier_immo_line_id=$immo_line_id lier_amort_trans_id=$amort_trans_id avec_amort_line_id=$amort_line_id*}}
|
||||
{{:save
|
||||
key=""|uuid
|
||||
type="link"
|
||||
immo_line_id=$immo_line_id
|
||||
amort_line_id=$amort_line_id
|
||||
amort_trans_id=$amort_trans_id
|
||||
}}
|
||||
{{:assign amort_amount="%d+%d"|math:$amort_amount:$line.amount}}
|
||||
{{/if}}
|
||||
{{/if}}
|
||||
{{/foreach}}
|
||||
{{/foreach}}
|
||||
|
||||
{{if $amort_amount == 0}}
|
||||
{{:assign exist_amort=false}}
|
||||
{{else}}
|
||||
{{:assign exist_amort=true}}
|
||||
{{:assign amort_amount=$amort_amount}}
|
||||
{{/if}}
|
||||
{{if $amount == null}}
|
||||
{{#select credit FROM acc_transactions_lines WHERE id = :amort_line_id;
|
||||
:amort_line_id = $amort_line_id
|
||||
}}
|
||||
{{:assign amort_amount="%d+%d"|math:$amort_amount:$credit}}
|
||||
{{/select}}
|
||||
{{else}}
|
||||
{{:assign amort_amount="%d+%d"|math:$amort_amount:$amount}}
|
||||
{{/if}}
|
||||
{{/load}}
|
||||
|
||||
{{* classement par onglet *}}
|
||||
{{if $type_immo == "managed" && $amort_amount >= $montant_immo}}{{:continue}}{{/if}}
|
||||
{{if $status == "unknown" && ! $exist_amort}}{{:continue}}{{/if}}
|
||||
{{if $type_immo == "amortized" && $amort_amount < $montant_immo}}{{:continue}}{{/if}} {{* ?? *}}
|
||||
{{if $type_immo == "amortized" && $amort_amount < $montant_immo}}{{:continue}}{{/if}}
|
||||
|
||||
{{:assign nb_immo="%d+1"|math:$nb_immo}}
|
||||
{{:assign total_immo="%d+%d"|math:$total_immo:$montant_immo}}
|
||||
|
|
@ -194,26 +131,25 @@
|
|||
{{:assign var="sommes_immo.%s"|args:$account_code value="%d+%d"|math:$montant:$montant_immo}}
|
||||
<tr>
|
||||
<td class="num"><a href="{{$trans_url}}">#{{$immo_trans_id}}</a></td>
|
||||
<td>{{$trans_date|date_short}}</td>
|
||||
<td>{{$trans_label}}{{if $line_label != null && $line_label != $trans_label}} — {{$line_label}}{{/if}}</td>
|
||||
<td>{{$immo_date|date_short}}</td>
|
||||
<td>{{$label_immo}}</td>
|
||||
<td class="money">{{$montant_immo|money_html:false|raw}}</td>
|
||||
<td class="money">{{if $duration != null}}{{$duration}}{{/if}}</td>
|
||||
<td class="money">{{$amort_amount|money_html:false|raw}}</td>
|
||||
<td class="money">{{"%d-%d"|math:$montant_immo:$amort_amount|money_html:false|raw}}</td>
|
||||
<td><a href="{{$compte_url}}">{{$account_code}}</a></td>
|
||||
<td class="actions">
|
||||
{{if ! $exist_amort || $status == "unknown"}}
|
||||
{{*if $amort_amount == 0*}}
|
||||
{{:linkbutton
|
||||
label="Paramètres"
|
||||
href="add_infos.html?immo_line_id=%s&type_immo=%s"|args:$immo_line_id:$type_immo
|
||||
shape="settings"
|
||||
label="Détails"
|
||||
href="details_immo.html?immo_doc_id=%s"|args:$immo_doc_id
|
||||
shape="search"
|
||||
}}
|
||||
{{* target="_dialog"*}}
|
||||
{{/if}}
|
||||
{{* target="_dialog"*}}
|
||||
{{*/if*}}
|
||||
{{:linkbutton
|
||||
label="Amortissements"
|
||||
href="amortization.html?immo_line_id=%s&type_immo=%s"|args:$immo_line_id:$type_immo
|
||||
shape="table"
|
||||
href="amortization.html?immo_line_id=%s&type_immo=%s&immo_doc_id=%s"|args:$immo_line_id:$type_immo:$immo_doc_id shape="table"
|
||||
}}
|
||||
</td>
|
||||
</tr>
|
||||
|
|
@ -250,9 +186,8 @@
|
|||
</tr>
|
||||
{{/if}}
|
||||
</tfoot>
|
||||
{{/if}}
|
||||
</table>
|
||||
{{if $nb_immo == 0 || ! $table_presente}}
|
||||
<p class="block alert">Aucune immobilisation</p>
|
||||
{{/if}}
|
||||
</section>
|
||||
{{/if}}
|
||||
{{if $nb_immo == 0 || $module.table == null}}
|
||||
<p class="block alert">Aucune immobilisation</p>
|
||||
{{/if}}
|
||||
|
|
|
|||
|
|
@ -1,199 +1,187 @@
|
|||
{{* -*- brindille -*- *}}
|
||||
|
||||
{{* Liste des immobilisations non amortissables ou non (encore) gérées *}}
|
||||
{{* Liste des immobilisations non gérées ou non entièrement affectées *}}
|
||||
|
||||
{{:include file="_get_config.html" keep="module.config"}}
|
||||
<section class="immobilisation">
|
||||
<p class="help">
|
||||
Cette page liste les immobilisations pas encore prises en charge
|
||||
par le module ou les écritures de la balance d'ouverture initiale
|
||||
dont le montant n'est pas encore totalement affecté
|
||||
</p>
|
||||
|
||||
<p class="help">
|
||||
Cette page liste les écritures pas (encore) prises en charge par le module et sans écriture d'amortissement associée.
|
||||
</p>
|
||||
{{:assign saved_hides=$module.config.hides}}
|
||||
{{:assign var="user_hides" from="saved_hides.%s"|args:$logged_user.id}}
|
||||
|
||||
{{:assign saved_hides=$module.config.hides}}
|
||||
{{:assign var="user_hides" from="saved_hides.%s"|args:$logged_user.id}}
|
||||
|
||||
{{if $_POST|count == 0}}
|
||||
{{:assign unhide=$user_hides.unhide_other}}
|
||||
{{if $_POST|count == 0}}
|
||||
{{:assign unhide=$user_hides.unhide_other}}
|
||||
{{else}}
|
||||
{{if $_POST.unhide == null}}
|
||||
{{:assign unhide=0}}
|
||||
{{else}}
|
||||
{{if $_POST.unhide == null}}
|
||||
{{:assign unhide=0}}
|
||||
{{else}}
|
||||
{{:assign unhide=1}}
|
||||
{{:assign unhide=1}}
|
||||
{{/if}}
|
||||
{{:assign var="user_hides.unhide_other" value=$unhide"}}
|
||||
{{:assign var="saved_hides.%s"|args:$logged_user.id value=$user_hides}}
|
||||
{{:save key="config" hides=$saved_hides}}
|
||||
{{/if}}
|
||||
{{if $unhide}}
|
||||
{{:assign checked="checked"}}
|
||||
{{/if}}
|
||||
|
||||
{{* vérifier l'existence de la table du module *}}
|
||||
{{if $module.table != null}}
|
||||
{{:assign columns="$$.status as status, SUM($$.amount) as amount,"}}
|
||||
{{:assign table_join="LEFT JOIN !table AS info ON $$.line = line.id"}}
|
||||
{{:assign doc_condition="($$.status IS NULL OR $$.status == 'managed' OR $$.status == 'ignored')"}}
|
||||
{{else}}
|
||||
{{:assign columns=""}}
|
||||
{{:assign table_join=""}}
|
||||
{{:assign doc_condition="1"}}
|
||||
{{/if}}
|
||||
|
||||
{{*
|
||||
lister les immobilisations non prises en charge par le module
|
||||
ou dont le montant n'a pas été totalement affecté
|
||||
*}}
|
||||
{{:assign account_condition="("}}
|
||||
{{#foreach from=$module.config.prefixes item="code"}}
|
||||
{{:assign code=$code|cat:"%"|quote_sql}}
|
||||
{{:assign account_condition=$account_condition|cat:" account.code LIKE "|cat:$code|cat:" OR "}}
|
||||
{{/foreach}}
|
||||
{{:assign account_condition=$account_condition|cat:"0)"}}
|
||||
|
||||
{{if $unhide == null}}
|
||||
{{:assign filter_condition="NOT ("}}
|
||||
{{#foreach from=$module.config.filters item="filter"}}
|
||||
{{:assign filter="%"|cat:$filter|cat:"%"|quote_sql}}
|
||||
{{:assign filter_condition=$filter_condition|cat:" trans_label LIKE "|cat:$filter|cat:" OR "}}
|
||||
{{/foreach}}
|
||||
{{:assign filter_condition=$filter_condition|cat:"0)"}}
|
||||
{{else}}
|
||||
{{:assign filter_condition="1"}}
|
||||
{{/if}}
|
||||
|
||||
{{:assign condition=$account_condition|cat:" AND debit > 0 AND NOT (trans.status & 16) AND "|cat:$filter_condition|cat:" AND "|cat:$doc_condition}}
|
||||
|
||||
{{:assign nb_managed=0}}
|
||||
{{:assign nb_ignored=0}}
|
||||
{{:assign nb_null=0}}
|
||||
{{:assign nb_other=0}}
|
||||
{{#select
|
||||
trans.id as immo_trans_id,
|
||||
trans.label as trans_label,
|
||||
trans.date as trans_date,
|
||||
line.id as immo_line_id,
|
||||
line.debit AS debit,
|
||||
line.label AS line_label,
|
||||
account.id as account_id,
|
||||
account.code as account_code,
|
||||
account.label as account_label,
|
||||
!columns
|
||||
trans.id_year as trans_id_year
|
||||
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
|
||||
INNER JOIN acc_years AS years ON trans.id_year = years.id
|
||||
!table_join
|
||||
WHERE !condition
|
||||
GROUP BY immo_line_id
|
||||
ORDER BY trans.date DESC;
|
||||
!columns=$columns
|
||||
!table_join=$table_join
|
||||
!table=$module.table
|
||||
!condition=$condition
|
||||
assign="immo_line"
|
||||
}}
|
||||
{{*
|
||||
parmi les immos gérées, ne conserver que celles dont le montant dans le doc est non nul
|
||||
et inférieur au montant de l'écriture d'immo
|
||||
*}}
|
||||
{{if $immo_line.status == 'managed'}}
|
||||
{{if $immo_line.amount == null || $immo_line.amount == 0 || $immo_line.amount == $immo_line.debit}}
|
||||
{{:continue}}
|
||||
{{/if}}
|
||||
{{:assign var="user_hides.unhide_other" value=$unhide"}}
|
||||
{{:assign var="saved_hides.%s"|args:$logged_user.id value=$user_hides}}
|
||||
{{:save key="config" hides=$saved_hides}}
|
||||
{{/if}}
|
||||
{{if $unhide}}
|
||||
{{:assign checked="checked"}}
|
||||
{{if $status == null}}
|
||||
{{:assign nb_null="%d+1"|math:$nb_null}}
|
||||
{{elseif $status == 'managed'}}
|
||||
{{:assign nb_managed="%d+1"|math:$nb_managed}}
|
||||
{{elseif $status == 'ignored'}}
|
||||
{{:assign nb_ignored="%d+1"|math:$nb_ignored}}
|
||||
{{else}}
|
||||
{{:assign nb_other="%d+1"|math:$nb_other}}
|
||||
{{/if}}
|
||||
|
||||
<form method="post" action="">
|
||||
<fieldset>
|
||||
{{:input type="checkbox" value=1 name="unhide" checked="%s"|args:$checked label="Afficher toutes les écritures" }}
|
||||
</fieldset>
|
||||
</form>
|
||||
{{:assign var="immo_lines." value=$immo_line}}
|
||||
{{/select}}
|
||||
{{*:debug lines=$immo_lines nb_lines=$immo_lines|count nb_null=$nb_null nb_managed=$nb_managed nb_ignored=$nb_ignored nb_other=$nb_other unhide=$unhide*}}
|
||||
|
||||
<table class="list">
|
||||
<thead>
|
||||
<tr>
|
||||
<th class="num">N°</th>
|
||||
<th>Date</th>
|
||||
<th>Libellé</th>
|
||||
<th class="nombre">Montant</th>
|
||||
<th>N° compte</th>
|
||||
<th>Compte</th>
|
||||
<th class="actions"></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<form method="post" action="">
|
||||
<fieldset>
|
||||
{{:input type="checkbox" value=1 name="unhide" checked="%s"|args:$checked label="Afficher les écritures ignorées" }}
|
||||
</fieldset>
|
||||
</form>
|
||||
|
||||
{{* vérifier l'existence de la table du module *}}
|
||||
{{#load limit="1"}}
|
||||
{{:assign columns="$$.duration as duration, $$.status as status,"}}
|
||||
{{:assign table_join="LEFT JOIN !table AS info ON $$.line = line.id"}}
|
||||
{{:assign doc_condition1="($$.status == 'ignored')"}}
|
||||
{{:assign doc_condition2="$$.status IS NULL"}}
|
||||
{{else}}
|
||||
{{:assign columns=""}}
|
||||
{{:assign table_join=""}}
|
||||
{{:assign doc_condition1="0"}}
|
||||
{{:assign doc_condition2="1"}}
|
||||
{{/load}}
|
||||
{{if $immo_lines|count > 0}}
|
||||
<table class="list">
|
||||
<thead>
|
||||
<tr>
|
||||
<th class="num">N°</th>
|
||||
<th class="nombre">Ligne</th>
|
||||
<th>Date</th>
|
||||
<th>Libellé</th>
|
||||
<th class="nombre">Montant</th>
|
||||
<th class="nombre">Affecté</th>
|
||||
<th class="nombre">Reste</th>
|
||||
<th>N° compte</th>
|
||||
<th>Compte</th>
|
||||
<th class="actions"></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{{#foreach from=$immo_lines item="line"}}
|
||||
|
||||
{{* lister les immobilisations *}}
|
||||
{{:assign account_condition="("}}
|
||||
{{#foreach from=$module.config.prefixes item="code"}}
|
||||
{{:assign code=$code|cat:"%"|quote_sql}}
|
||||
{{:assign account_condition=$account_condition|cat:" account.code LIKE "|cat:$code|cat:" OR "}}
|
||||
{{/foreach}}
|
||||
{{:assign account_condition=$account_condition|cat:"0)"}}
|
||||
|
||||
{{if $unhide == null}}
|
||||
{{:assign filter_condition="NOT ("}}
|
||||
{{#foreach from=$module.config.filters item="filter"}}
|
||||
{{:assign filter="%"|cat:$filter|cat:"%"|quote_sql}}
|
||||
{{:assign filter_condition=$filter_condition|cat:" trans_label LIKE "|cat:$filter|cat:" OR "}}
|
||||
{{/foreach}}
|
||||
{{:assign filter_condition=$filter_condition|cat:"0)"}}
|
||||
{{else}}
|
||||
{{:assign filter_condition="1"}}
|
||||
{{/if}}
|
||||
{{:assign filter_condition="("|cat:$doc_condition2|cat:" AND NOT (trans.status & 16) AND "|cat:$filter_condition|cat:")"}}
|
||||
|
||||
{{:assign condition=$account_condition|cat:" AND debit > 0 AND ("|cat:$filter_condition|cat:" OR "|cat:$doc_condition1|cat:")"}}
|
||||
|
||||
{{:assign nb_immo=0}}
|
||||
{{#select
|
||||
trans.id as immo_trans_id,
|
||||
trans.label as trans_label,
|
||||
trans.date as trans_date,
|
||||
line.id as immo_line_id,
|
||||
line.debit AS debit,
|
||||
line.label AS line_label,
|
||||
account.id as account_id,
|
||||
account.code as account_code,
|
||||
account.label as account_label,
|
||||
!columns
|
||||
trans.id_year as trans_id_year
|
||||
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
|
||||
INNER JOIN acc_years AS years ON trans.id_year = years.id
|
||||
!table_join
|
||||
WHERE !condition
|
||||
ORDER BY trans.date DESC;
|
||||
!columns=$columns
|
||||
!table_join=$table_join
|
||||
!table=$module.table
|
||||
!condition=$condition
|
||||
}}
|
||||
{{:assign trans_url="%s/acc/transactions/details.php?id=%s"|args:$admin_url:$immo_trans_id}}
|
||||
{{:assign compte_url="%s/acc/accounts/journal.php?id=%s&year=%s"|args:$admin_url:$account_id:$trans_id_year}}
|
||||
|
||||
{{if $status == null}}
|
||||
{{:assign status="unknown"}}
|
||||
{{/if}}
|
||||
|
||||
{{if $unhide == null}}
|
||||
{{if $status != "unknown"}}
|
||||
{{:continue}}
|
||||
{{/if}}
|
||||
{{else}}
|
||||
{{if $status != "ignored" && $status != "unknown"}}
|
||||
{{:continue}}
|
||||
{{/if}}
|
||||
{{* vérifier si le libellé aurait pu être filtré *}}
|
||||
{{#foreach from=$module.config.filters item="filter"}}
|
||||
{{if $filter|strpos:$trans_label !== false}}
|
||||
{{:assign status="ignored"}}
|
||||
{{/if}}
|
||||
{{/foreach}}
|
||||
{{/if}}
|
||||
|
||||
{{* lister les lignes des écritures d'amortissement liées à l'immobilisation *}}
|
||||
{{:assign amort_lines=null}}
|
||||
{{#select
|
||||
l_amort.credit as amort_amount,
|
||||
CASE links.id_related = t_immo.id
|
||||
WHEN true THEN links.id_transaction
|
||||
WHEN false THEN links.id_related
|
||||
END as amort_trans_id,
|
||||
l_amort.id AS amort_line_id
|
||||
FROM acc_transactions_lines as l_immo
|
||||
INNER JOIN acc_transactions as t_immo on t_immo.id = l_immo.id_transaction
|
||||
INNER JOIN acc_transactions_links as links
|
||||
ON (t_immo.id = links.id_transaction OR t_immo.id = links.id_related)
|
||||
INNER JOIN acc_transactions_lines as l_amort on amort_trans_id = l_amort.id_transaction
|
||||
INNER JOIN acc_accounts AS account ON l_amort.id_account = account.id
|
||||
WHERE l_immo.id = :line_id AND l_amort.credit <> 0 AND account.code LIKE '28%';
|
||||
:line_id = $immo_line_id|intval
|
||||
assign="amort_lines."
|
||||
}}
|
||||
{{/select}}
|
||||
{{:assign amort_amount=0}}
|
||||
{{#foreach from=$amort_lines item="line"}}
|
||||
{{* voir s'il existe un doc associé à l'écriture d'amortissement *}}
|
||||
{{#load type="link"
|
||||
where="$$.immo_line_id = :immo_line_id AND $$.amort_trans_id = :amort_trans_id AND $$.amort_line_id = :amort_line_id"
|
||||
:immo_line_id = $immo_line_id
|
||||
:amort_trans_id = $line.amort_trans_id
|
||||
:amort_line_id = $line.amort_line_id
|
||||
}}
|
||||
{{:assign amort_amount="%d+%d"|math:$amort_amount:$line.amount}}
|
||||
{{else}}
|
||||
{{* TODO À VÉRIFIER (cas multi-lignes) *}}
|
||||
{{:assign amort_amount="%d+%d"|math:$amort_amount:$line.amount}}
|
||||
{{/load}}
|
||||
{{/foreach}}
|
||||
{{if $amort_amount != 0}}
|
||||
{{if $unhide == null}}
|
||||
{{if $status == "ignored"}}
|
||||
{{:continue}}
|
||||
{{/if}}
|
||||
{{else}}
|
||||
{{* vérifier si le libellé aurait pu être filtré *}}
|
||||
{{#foreach from=$module.config.filters item="filter"}}
|
||||
{{if $filter|strpos:$trans_label !== false}}
|
||||
{{:assign status="ignored"}}
|
||||
{{/if}}
|
||||
{{/foreach}}
|
||||
{{/if}}
|
||||
|
||||
{{:assign nb_immo="%d+1"|math:$nb_immo}}
|
||||
<tr {{if $status == "ignored"}}class="ignored"{{/if}}>
|
||||
<td class="num"><a href="{{$trans_url}}">#{{$immo_trans_id}}</a></td>
|
||||
<td>{{$trans_date|date_short}}</td>
|
||||
<td>{{$trans_label}}{{if $line_label != null && $line_label != $trans_label}} — {{$line_label}}{{/if}}</td>
|
||||
<td class="money">{{"%f"|math:$debit|money_html:false|raw}}</td>
|
||||
<td><a href="{{$compte_url}}">{{$account_code}}</a></td>
|
||||
<td>{{$account_label}}</td>
|
||||
<td class="actions">
|
||||
{{:linkbutton
|
||||
label="Paramètres"
|
||||
href="add_infos.html?immo_line_id=%s&type_immo=other"|args:$immo_line_id
|
||||
shape="settings"
|
||||
target="_dialog"
|
||||
}}
|
||||
</td>
|
||||
</tr>
|
||||
{{/select}}
|
||||
</tbody>
|
||||
</table>
|
||||
{{if $nb_immo == 0}}
|
||||
<p class="block alert">Aucune immobilisation</p>
|
||||
{{/if}}
|
||||
</section>
|
||||
{{:assign trans_url="%s/acc/transactions/details.php?id=%s"|args:$admin_url:$line.immo_trans_id}}
|
||||
{{:assign compte_url="%s/acc/accounts/journal.php?id=%s&year=%s"|args:$admin_url:$line.account_id:$line.trans_id_year}}
|
||||
{{:assign reste="%d-%d"|math:$line.debit:$line.amount}}
|
||||
<tr {{if $status == "ignored"}}class="ignored"{{/if}}>
|
||||
<td class="num"><a href="{{$trans_url}}">#{{$line.immo_trans_id}}</a></td>
|
||||
<td class="nombre">{{$line.immo_line_id}}</td>
|
||||
<td>{{$trans_date|date_short}}</td>
|
||||
<td>{{$line.trans_label}}{{if $line.line_label != null && $line.line_label != $line.trans_label}} — {{$line.line_label}}{{/if}}</td>
|
||||
<td class="money">{{"%f"|math:$line.debit|money_html:false|raw}}</td>
|
||||
<td class="money">{{"%f"|math:$line.amount|money_html:false|raw}}</td>
|
||||
<td class="money">{{"%f"|math:$reste|money_html:false|raw}}</td>
|
||||
<td><a href="{{$compte_url}}">{{$line.account_code}}</a></td>
|
||||
<td>{{$line.account_label}}</td>
|
||||
<td class="actions">
|
||||
{{:linkbutton
|
||||
label="Paramètres"
|
||||
href="add_infos.html?immo_line_id=%s&type_immo=other"|args:$immo_line_id
|
||||
shape="settings"
|
||||
}}
|
||||
{{* target="_dialog"*}}
|
||||
</td>
|
||||
</tr>
|
||||
{{/foreach}}
|
||||
</tbody>
|
||||
</table>
|
||||
{{else}}
|
||||
<p class="block alert">Aucune immobilisation</p>
|
||||
{{/if}}
|
||||
|
||||
<script type="text/javascript">
|
||||
function changeVisibility(evt, idcheck = 'f_unhide_1') {
|
||||
|
|
|
|||
|
|
@ -141,7 +141,7 @@
|
|||
type="immo"
|
||||
line=$immo_line_id
|
||||
duration=$duration
|
||||
date=$date_debut
|
||||
date_mes=$date_debut
|
||||
status=$status
|
||||
}}
|
||||
{{/if}}
|
||||
|
|
@ -243,8 +243,9 @@ function changeYear(evt, f_accounts = ['credit_account', 'debit_account'], f_yea
|
|||
setSelectorYear(f_accounts, f_years_select);
|
||||
}
|
||||
|
||||
function changeVisibility(evt, idcheck = 'f_amortir_1', fields = ['div_amort']) {
|
||||
toggleVisibility(idcheck, fields);
|
||||
function changeVisibility(evt, idcheck = 'f_amortir_1', iddiv = 'div_amort')
|
||||
{
|
||||
toggleVisibility(idcheck, document.querySelectorAll('#' + iddiv));
|
||||
}
|
||||
|
||||
(function () {
|
||||
|
|
|
|||
252
add_infos.html
252
add_infos.html
|
|
@ -3,140 +3,136 @@
|
|||
{{*
|
||||
@param immo_line_id
|
||||
@param type_immo : managed, amortized, archived, other
|
||||
|
||||
TODO :
|
||||
- séparer les cas des immo simples et complexes (BOI)
|
||||
par exemple pour la durée d'amort par défaut {{:input ...}}
|
||||
- prise en charge immo => param = immo_line_id
|
||||
- modif param immo => param = immo_doc_id
|
||||
*}}
|
||||
|
||||
{{* données de l'immobilisaion *}}
|
||||
{{#load type="immo" assign="info_immo" where="$$.line = :line_id" :line_id=$_GET.immo_line_id|intval}}
|
||||
{{* cas de la prise en charge *}}
|
||||
{{* données de l'immobilisation *}}
|
||||
{{:assign montant_affecte=0}}
|
||||
{{#load type="immo" where="$$.line = :line_id" :line_id=$_GET.immo_line_id|intval assign="info_immo"}}
|
||||
{{:assign montant_affecte="%d+%d"|math:$montant_affecte:$amount}}
|
||||
{{/load}}
|
||||
|
||||
{{#select
|
||||
trans.id as immo_trans_id,
|
||||
trans.label,
|
||||
trans.label as trans_label,
|
||||
trans.date as date_achat,
|
||||
line.debit as montant,
|
||||
line.label as line_label,
|
||||
acc.code
|
||||
acc.code,
|
||||
acc.label as account_label
|
||||
FROM acc_transactions_lines AS line
|
||||
INNER join acc_transactions AS trans ON line.id_transaction = trans.id
|
||||
INNER JOIN acc_accounts AS acc ON line.id_account = acc.id
|
||||
WHERE line.id = :line_id;
|
||||
:line_id = $_GET.immo_line_id
|
||||
assign=ligne_immo
|
||||
:line_id = $_GET.immo_line_id|intval
|
||||
assign="ligne_immo"
|
||||
}}
|
||||
{{else}}
|
||||
{{:error message="Aucune immobilisation trouvée"}}
|
||||
{{:error message="Immobilisation non trouvée"}}
|
||||
{{/select}}
|
||||
|
||||
{{* chercher les liaisons de l'écriture d'immobilisation *}}
|
||||
{{#select
|
||||
CASE links.id_related = :immo_trans_id
|
||||
WHEN true THEN links.id_transaction
|
||||
WHEN false THEN links.id_related
|
||||
END as linked_id,
|
||||
acc.code
|
||||
FROM acc_transactions_links as links
|
||||
INNER JOIN acc_transactions_lines AS line on line.id_transaction = linked_id
|
||||
INNER JOIN acc_accounts AS acc ON line.id_account = acc.id
|
||||
WHERE (links.id_transaction = :immo_trans_id or links.id_related = :immo_trans_id)
|
||||
AND line.credit > 0
|
||||
;
|
||||
:immo_trans_id = $ligne_immo.immo_trans_id
|
||||
}}
|
||||
{{:assign var="linked_transactions.%d."|args:$code value=$linked_id}}
|
||||
{{/select}}
|
||||
{{:assign var="immo_transactions" from="linked_transactions.%d"|args:$ligne_immo.code}}
|
||||
{{:assign reste="%d-%d"|math:$ligne_immo.montant:$montant_affecte}}
|
||||
{{*
|
||||
{{if $info_immo != null}}
|
||||
{{:assign date_defaut=$info_immo.date}}
|
||||
{{:assign duree_defaut=$info_immo.duration}}
|
||||
{{:assign choix_defaut=$info_immo.status}}
|
||||
{{else}}
|
||||
{{:assign duree_defaut=null}}
|
||||
{{/if}}
|
||||
*}}
|
||||
|
||||
{{* Traiter l'envoi du formulaire *}}
|
||||
{{#form on="save"}}
|
||||
{{if $_POST.classify == null}}
|
||||
{{:error message="Vous devez choisir une action"}}
|
||||
{{/if}}
|
||||
|
||||
{{if $_POST.classify == "ignored"}}
|
||||
{{if ! $_POST.amortir}}
|
||||
{{* ne pas amortir *}}
|
||||
{{:assign duration=0}}
|
||||
{{:assign date_debut=$ligne_immo.date_achat|parse_date}}
|
||||
{{:assign libelle=null}}
|
||||
{{:assign montant=null}}
|
||||
{{:assign date_achat=null}}
|
||||
{{:assign date_mes=null}}
|
||||
{{:assign status="ignored"}}
|
||||
{{else}}
|
||||
{{* vérifier que la date d'acquisition est antérieure à la date de mise en service *}}
|
||||
{{:assign date_debut=$_POST.date_mes|or:$ligne_immo.date_achat|parse_date}}
|
||||
{{if $date_debut|strtotime < $ligne_immo.date_achat|strtotime}}
|
||||
{{:assign dd=$date_debut|date_short}}
|
||||
{{:assign da=$ligne_immo.date_achat|date_short}}
|
||||
{{:error message="Erreur : la date de mise en service (%s) ne peut être antérieure à la date d'acquisition (%s)"|args:$dd:$da}}
|
||||
|
||||
{{* vérifier que la date de mise en service est postérieure à la date d'acquisition *}}
|
||||
{{:assign d1=$_POST.date_achat|or:$ligne_immo.date_achat|parse_date}}
|
||||
{{:assign d2=$_POST.date_mes|or:$d1|parse_date}}
|
||||
{{if $d2 < $d1}}
|
||||
{{:assign da=$d1|date_short}}
|
||||
{{:error message="Erreur : la date de mise en service (%s) ne peut être antérieure à la date d'acquisition (%s)"|args:$_POST.date_mes:$da}}
|
||||
{{/if}}
|
||||
|
||||
{{if $_POST.classify == "amortized"}}
|
||||
{{if $info_immo.duration == null}}
|
||||
{{:assign duration=0}}
|
||||
{{else}}
|
||||
{{:assign duration=$info_immo.duration}}
|
||||
{{/if}}
|
||||
{{:assign status="amortized"}}
|
||||
{{elseif $_POST.classify == "archived"}}
|
||||
{{if $info_immo.duration == null}}
|
||||
{{:assign duration=0}}
|
||||
{{else}}
|
||||
{{:assign duration=$info_immo.duration}}
|
||||
{{/if}}
|
||||
{{:assign status="archived"}}
|
||||
{{else}}
|
||||
{{:assign duration=$_POST.duree|intval}}
|
||||
{{if $duration <= 0}}
|
||||
{{:error message="Erreur : la durée d'amortissement doit être strictement positive"}}
|
||||
{{/if}}
|
||||
{{:assign status="managed"}}
|
||||
{{:assign duration=$_POST.duree|intval}}
|
||||
{{if $duration <= 0}}
|
||||
{{:error message="Erreur : la durée d'amortissement doit être strictement positive"}}
|
||||
{{/if}}
|
||||
|
||||
{{if $_POST.libelle != $ligne_immo.line_label && $_POST.libelle != $ligne_immo.trans_label}}
|
||||
{{:assign libelle=$_POST.libelle}}
|
||||
{{/if}}
|
||||
|
||||
{{if $_POST.montant == null || $_POST.montant|money_int == 0 }}
|
||||
{{if $montant_affecte > 0}}
|
||||
{{:assign montant=$reste}}
|
||||
{{else}}
|
||||
{{:assign montant=null}}
|
||||
{{/if}}
|
||||
{{else}}
|
||||
{{:assign montant=$_POST.montant|money_int}}
|
||||
{{if $montant == $ligne_immo.montant}}
|
||||
{{:assign montant=null}}
|
||||
{{/if}}
|
||||
{{/if}}
|
||||
{{if $montant > $reste}}
|
||||
{{:assign reste_nb="%f"|math:$reste|money_currency:false}}
|
||||
{{:assign montant_nb="%f"|math:$montant|money_currency:false}}
|
||||
{{:error message="Le montant (%s) ne peut être supérieur au reste (%s)"|args:$montant_nb:$reste_nb}}
|
||||
{{/if}}
|
||||
|
||||
{{if $_POST.date_achat == null || $_POST.date_achat|parse_date == $ligne_immo.date_achat}}
|
||||
{{:assign date_achat=null}}
|
||||
{{else}}
|
||||
{{:assign date_achat=$_POST.date_achat|parse_date}}
|
||||
{{/if}}
|
||||
|
||||
{{if $_POST.date_mes == null || $_POST.date_mes == $_POST.date_achat || $_POST.date_mes|parse_date == $ligne_immo.date_achat}}
|
||||
{{:assign date_mes=null}}
|
||||
{{else}}
|
||||
{{:assign date_mes=$_POST.date_mes|parse_date}}
|
||||
{{/if}}
|
||||
{{:assign status="managed"}}
|
||||
{{/if}}
|
||||
|
||||
{{* enregistrer les infos de l'immobilisation *}}
|
||||
{{if $info_immo == null}}
|
||||
{{if $info_immo == null || $montant_affecte > 0}}
|
||||
{{:assign key=""|uuid}}
|
||||
{{else}}
|
||||
{{:assign key=$info_immo.key}}
|
||||
{{/if}}
|
||||
|
||||
{{:save
|
||||
key=$key
|
||||
validate_schema="schema.json"
|
||||
type="immo"
|
||||
line=$_GET.immo_line_id|intval
|
||||
duration=$duration
|
||||
date=$date_debut
|
||||
label=$libelle
|
||||
amount=$montant
|
||||
date_achat=$date_achat
|
||||
date_mes=$date_mes
|
||||
status=$status
|
||||
assign_new_id="new_id"
|
||||
}}
|
||||
|
||||
{{* copier les autres liaisons *}}
|
||||
{{#foreach from=$linked_transactions key="code" item="liaisons"}}
|
||||
{{if $code != $ligne_immo.code}}
|
||||
{{:debug code=$code liaisons=$liaisons}}
|
||||
{{#foreach from=$liaisons item="elem"}}
|
||||
{{:assign var="new_transactions." value=$elem}}
|
||||
{{/foreach}}
|
||||
{{/if}}
|
||||
{{/foreach}}
|
||||
|
||||
{{* nouvelles liaisons *}}
|
||||
{{#foreach from=$_POST.transactions key="key" item="elem"}}
|
||||
{{:assign var="new_transactions." value=$elem|intval}}
|
||||
{{/foreach}}
|
||||
|
||||
{{* Enregistrer les liaisons *}}
|
||||
{{if $new_transactions != null}}
|
||||
{{:api
|
||||
method="POST"
|
||||
path="accounting/transaction/%s/transactions"|args:$ligne_immo.immo_trans_id
|
||||
assign="result"
|
||||
assign_code="result_code"
|
||||
transactions=$new_transactions
|
||||
}}
|
||||
{{/if}}
|
||||
|
||||
{{if $_POST.classify == "managed" || $_POST.classify == "amortized"}}
|
||||
{{:assign type_immo=$_POST.classify}}
|
||||
{{elseif $_POST.classify == "ignored"}}
|
||||
{{:assign type_immo="other"}}
|
||||
{{if $_POST.amortir}}
|
||||
{{:assign type_immo="managed"}}
|
||||
{{else}}
|
||||
{{:assign type_immo=$_GET.type_immo}}
|
||||
{{:assign type_immo="other"}}
|
||||
{{/if}}
|
||||
{{:redirect force="index.html?ok=1&msg=infos&type_immo=%s"|args:$type_immo}}
|
||||
{{/form}}
|
||||
|
|
@ -151,53 +147,46 @@
|
|||
|
||||
{{:assign choix_defaut=$_GET.type_immo}}
|
||||
|
||||
{{if $info_immo != null}}
|
||||
{{:assign date_defaut=$info_immo.date}}
|
||||
{{:assign duree_defaut=$info_immo.duration}}
|
||||
{{:assign choix_defaut=$info_immo.status}}
|
||||
{{else}}
|
||||
{{:assign duree_defaut=null}}
|
||||
{{/if}}
|
||||
|
||||
{{*
|
||||
- classer l'immobilisation
|
||||
- renseigner ou modifier la date de mise en service, les écritures associées ou la durée d'amortissement
|
||||
*}}
|
||||
|
||||
{{:assign trans_url="%s/acc/transactions/details.php?id=%s"|args:$admin_url:$ligne_immo.immo_trans_id}}
|
||||
<h3 class="ruler">
|
||||
Paramètres de l'immobilisation
|
||||
<span class="num"><a href="{{$trans_url}}">#{{$ligne_immo.immo_trans_id}}</a></span>
|
||||
</h3>
|
||||
<h3 class="ruler">Paramètres de l'immobilisation</h3>
|
||||
<div class="informations">
|
||||
<dl class="describe">
|
||||
<dt>Immobilisation</dt>
|
||||
<dd><span class="num"><a href="{{$trans_url}}">#{{$ligne_immo.immo_trans_id}}</a></span> {{$ligne_immo.label}}{{if $ligne_immo.line_label != null && $ligne_immo.line_label != $ligne_immo.label}} — {{$ligne_immo.line_label}}{{/if}}</dd>
|
||||
<dd><span class="num"><a href="{{$trans_url}}">#{{$ligne_immo.immo_trans_id}}</a></span> {{$ligne_immo.trans_label}}{{if $ligne_immo.line_label != null && $ligne_immo.line_label != $ligne_immo.trans_label}} — {{$ligne_immo.line_label}}{{/if}}</dd>
|
||||
<dt>Montant</dt>
|
||||
<dd class="money strong">{{"%f"|math:$ligne_immo.montant|money_currency_html:false|raw}}</dd>
|
||||
<dt>Date de l'écriture d'immobilisation</dt>
|
||||
<dt>Montant déjà affecté</dt>
|
||||
<dd class="money strong">{{"%f"|math:$montant_affecte|money_currency_html:false|raw}}</dd>
|
||||
<dt>Montant restant à affecter</dt>
|
||||
<dd class="money strong">{{"%f"|math:$reste|money_currency_html:false|raw}}</dd> <dt>Date de l'écriture d'immobilisation</dt>
|
||||
<dd>{{$ligne_immo.date_achat|date_short}}</dd>
|
||||
<dt>Compte d'immobilisation</dt>
|
||||
<dd>{{$ligne_immo.code}} — {{$ligne_immo.account_label}}
|
||||
</dl>
|
||||
</div>
|
||||
|
||||
<form method="post" action="">
|
||||
<fieldset>
|
||||
<legend>Classement</legend>
|
||||
<dl id="classement_immo">
|
||||
<dt><label>Faites un choix</label> <b>(obligatoire)</b></dt>
|
||||
{{:input type="radio-btn" name="classify" value="managed" label="Immobilisation à amortir" help="Cette immobilisation sera classée parmi les immobilisations amortissables" default=$choix_defaut}}
|
||||
{{:input type="radio-btn" name="classify" value="amortized" label="Amortissement terminé" help="Cette immobilisation sera classée parmi les immobilisations amorties" default=$choix_defaut}}
|
||||
{{:input type="radio-btn" name="classify" value="archived" label="Immobilisation sortie du bilan" help="Cette immobilisation sera classée parmi les immobilisations sorties du bilan" default=$choix_defaut}}
|
||||
{{:input type="radio-btn" name="classify" value="ignored" label="Immobilisation à ignorer" help="Cette écriture n'apparaitra plus dans la liste des immobilisations" default=$choix_defaut}}
|
||||
</dl>
|
||||
</fieldset>
|
||||
|
||||
<fieldset id="infos_immo">
|
||||
<legend>Informations</legend>
|
||||
<legend>Amortissement</legend>
|
||||
<dl>
|
||||
{{:input type="number" name="duree" label="Durée d'amortissement" default=$duree_defaut required=true min=1}}
|
||||
{{:input type="list" name="transactions" default=$immo_transactions label="Écritures liées au crédit du compte d'immobilisation" target="!acc/transactions/selector.php" multiple=true help="par exemple écriture d'avoir ou autre réduction du montant de l'acquisition"}}
|
||||
{{:input type="date" name="date_mes" label="Date de mise en service" default=$date_defaut help="à renseigner uniquement si différente de la date d'acquisition"}}
|
||||
{{:input id="amortir" type="checkbox" value=1 name="amortir" label="Amortir cette immobilisation sur une ou plusieurs années" checked="checked" help="Dé-cocher pour ne pas amortir"}}
|
||||
<div class="masquable">
|
||||
{{:input type="number" name="duree" label="Durée d'amortissement" required=true min=1}}
|
||||
</div>
|
||||
</dl>
|
||||
</fieldset>
|
||||
<fieldset class="masquable">
|
||||
<legend>Informations facultatives</legend>
|
||||
<dl>
|
||||
{{:input type="date" name="date_achat" label="Date d'acquisition" help="à renseigner uniquement si différente de la date de l'écriture d'immobilisation"}}
|
||||
{{:input type="date" name="date_mes" label="Date de mise en service" help="à renseigner uniquement si différente de la date d'acquisition"}}
|
||||
{{:input type="text" name="libelle" label="Libellé" help="à renseigner uniquement si différent du libellé de l'écriture d'immobilisation"}}
|
||||
{{:input type="money" name="montant" label="Montant de l'immobilisation" required=true default=$reste}}
|
||||
</dl>
|
||||
</fieldset>
|
||||
|
||||
|
|
@ -209,29 +198,16 @@
|
|||
|
||||
{{:admin_footer}}
|
||||
|
||||
<script type="text/javascript" src="scripts.js"></script>
|
||||
<script type="text/javascript">
|
||||
var info_immo = {{$info_immo|json_encode|raw}};
|
||||
|
||||
// afficher/masquer les champs de saisie
|
||||
function toggleInputs(event) {
|
||||
const classement_immo = document.getElementById('classement_immo');
|
||||
const managed = classement_immo.querySelector('input[type=radio][value=managed]');
|
||||
const amortized = classement_immo.querySelector('input[type=radio][value=amortized]');
|
||||
if (managed.checked) {
|
||||
g.toggle('#infos_immo', true);
|
||||
} else if (amortized.checked && info_immo != null && info_immo.duration != 0) {
|
||||
g.toggle('#infos_immo', true);
|
||||
} else {
|
||||
g.toggle('#infos_immo', false);
|
||||
}
|
||||
function changeVisibility(evt, idcheck = 'f_amortir_1', hiddenclass = 'masquable')
|
||||
{
|
||||
toggleVisibility(idcheck, document.querySelectorAll('.' + hiddenclass));
|
||||
}
|
||||
toggleInputs();
|
||||
|
||||
(function () {
|
||||
const radios = document.querySelectorAll('input[name="classify"]');
|
||||
radios.forEach(radio => {
|
||||
radio.addEventListener("change", toggleInputs);
|
||||
});
|
||||
document.getElementById('f_amortir_1').onclick = changeVisibility;
|
||||
})();
|
||||
|
||||
</script>
|
||||
|
|
|
|||
|
|
@ -3,10 +3,16 @@
|
|||
{{*
|
||||
Lister les écritures d'amortissement associées à une immobilisation
|
||||
@param immo_line_id : id de la ligne d'immo
|
||||
@param immo_doc_id : id du doc associé à l'immo
|
||||
@param type_immo : managed, amortized, archived, others
|
||||
*}}
|
||||
|
||||
{{* récupérer les infos de l'immobilisation *}}
|
||||
{{* données de l'immobilisation *}}
|
||||
{{#load type="immo" id=$_GET.immo_doc_id|intval assign="info_immo"}}
|
||||
{{else}}
|
||||
{{:error message="Immobilisation non trouvée"}}
|
||||
{{/load}}
|
||||
|
||||
{{#select
|
||||
line.id as immo_line_id,
|
||||
line.debit as montant,
|
||||
|
|
@ -14,167 +20,113 @@
|
|||
trans.id as immo_trans_id,
|
||||
trans.label as label,
|
||||
trans.date,
|
||||
account.code as account_code
|
||||
account.code as account_code,
|
||||
account.label as account_label
|
||||
FROM acc_transactions_lines AS line
|
||||
INNER JOIN acc_transactions AS trans ON line.id_transaction = trans.id
|
||||
INNER JOIN acc_accounts AS account ON line.id_account = account.id
|
||||
WHERE line.id = :line_id;
|
||||
:line_id = $_GET.immo_line_id|intval
|
||||
assign=ligne_immo
|
||||
:line_id = $info_immo.line
|
||||
assign="ligne_immo"
|
||||
}}
|
||||
{{else}}
|
||||
{{:error message="Immobilisation %s non trouvée"|args:$_GET.immo_line_id}}
|
||||
{{:error message="Immobilisation non trouvée"}}
|
||||
{{/select}}
|
||||
{{:assign date_debut=$ligne_immo.date}}
|
||||
{{:assign trans_url="%s/acc/transactions/details.php?id=%s"|args:$admin_url:$ligne_immo.immo_trans_id}}
|
||||
|
||||
{{#load type="immo" where="$$.line = :line_id" :line_id=$_GET.immo_line_id|intval}}
|
||||
{{:assign duree=$duration}}
|
||||
{{:assign date_debut=$date}}
|
||||
{{:assign status=$status}}
|
||||
{{/load}}
|
||||
{{:assign date_debut=$info_immo.date_mes|or:$info_immo.date_achat|or:$ligne_immo.date}}
|
||||
{{:assign label_immo=$info_immo.label|or:$ligne_immo.label}}
|
||||
{{if $ligne_immo.line_label != null && $ligne_immo.line_label != $label_immo}}
|
||||
{{:assign label_immo=$label_immo|cat:" — "|cat:$ligne_immo.line_label}}
|
||||
{{/if}}
|
||||
{{if $info_immo.amount != null}}
|
||||
{{:assign var="ligne_immo.montant" value=$info_immo.amount}}
|
||||
{{/if}}
|
||||
|
||||
{{if $status == 'ignored'}}
|
||||
{{if $info_immo.status == 'ignored'}}
|
||||
{{:error message="Cette immobilisation ne doit pas être amortie"}}
|
||||
{{/if}}
|
||||
|
||||
{{* chercher des écritures liées à l'immo courante au crédit du même compte
|
||||
{{*
|
||||
chercher des écritures liées à l'immo courante au crédit du même compte
|
||||
et déduire leur montant de celui de l'immo
|
||||
*}}
|
||||
{{:assign total_credits=0}}
|
||||
{{#select
|
||||
CASE links.id_related = :immo_trans_id
|
||||
WHEN true THEN links.id_transaction
|
||||
WHEN false THEN links.id_related
|
||||
END as other_id,
|
||||
line.credit
|
||||
FROM acc_transactions AS trans
|
||||
INNER JOIN acc_transactions_links as links
|
||||
ON (trans.id = links.id_transaction OR trans.id = links.id_related)
|
||||
INNER JOIN acc_transactions_lines AS line on line.id_transaction = other_id
|
||||
INNER JOIN acc_accounts AS acc ON line.id_account = acc.id
|
||||
WHERE trans.id = :immo_trans_id AND line.credit > 0 AND acc.code = :account;
|
||||
:immo_trans_id=$ligne_immo.immo_trans_id
|
||||
:account=$ligne_immo.account_code
|
||||
}}
|
||||
{{:assign total_credits="%d+%d"|math:$total_credits:$credit}}
|
||||
{{/select}}
|
||||
{{#load type="immo_link" where="$$.immo_doc_id=:immo_doc_id" :immo_doc_id=$_GET.immo_doc_id|intval}}
|
||||
{{if $amount == null}}
|
||||
{{#select credit FROM acc_transactions_lines WHERE id = :credit_line_id;
|
||||
:credit_line_id=$credit_line_id
|
||||
}}
|
||||
{{:assign total_credits="%d+%d"|math:$total_credits:$credit}}
|
||||
{{/select}}
|
||||
{{else}}
|
||||
{{:assign total_credits="%d+%d"|math:$total_credits:$amount}}
|
||||
{{/if}}
|
||||
{{/load}}
|
||||
{{:assign var="ligne_immo.montant" value="%d-%d"|math:$ligne_immo.montant:$total_credits}}
|
||||
{{:assign solde=$ligne_immo.montant}}
|
||||
{{*:debug info_immo=$info_immo ligne_immo=$ligne_immo total_credits=$total_credits solde=$solde*}}
|
||||
|
||||
{{* lister les lignes des écritures d'amortissement liées à l'immobilisation *}}
|
||||
{{#select
|
||||
l_amort.credit as amort_amount,
|
||||
l_amort.label as amort_line_label,
|
||||
l_amort.id as amort_line_id,
|
||||
CASE WHEN links.id_related = t_immo.id
|
||||
THEN links.id_transaction
|
||||
ELSE links.id_related
|
||||
END as amort_trans_id,
|
||||
trans.date as amort_date,
|
||||
trans.label as amort_trans_label,
|
||||
trans.id_year as amort_year,
|
||||
account.id as account_id,
|
||||
account.code as account_code,
|
||||
account.label as account_label
|
||||
FROM acc_transactions_lines as l_immo
|
||||
INNER JOIN acc_transactions as t_immo on t_immo.id = l_immo.id_transaction
|
||||
INNER JOIN acc_transactions_links as links
|
||||
ON (t_immo.id = links.id_transaction OR t_immo.id = links.id_related)
|
||||
INNER JOIN acc_transactions_lines as l_amort on amort_trans_id = l_amort.id_transaction
|
||||
INNER join acc_transactions as trans on l_amort.id_transaction = trans.id
|
||||
INNER join acc_accounts as account on l_amort.id_account = account.id
|
||||
WHERE l_immo.id = :line_id AND account.code LIKE '28%'
|
||||
ORDER BY trans.date;
|
||||
:line_id = $_GET.immo_line_id|intval
|
||||
assign="amort_line"
|
||||
}}
|
||||
{{* lister les lignes d'amortissement liées à la ligne d'immobilisation *}}
|
||||
{{#load type="link"
|
||||
where="$$.immo_line_id = :immo_line_id AND $$.amort_trans_id = :amort_trans_id AND $$.amort_line_id = :amort_line_id"
|
||||
assign="line"
|
||||
:immo_line_id=$_GET.immo_line_id|intval
|
||||
:amort_trans_id=$amort_line.amort_trans_id
|
||||
:amort_line_id = $amort_line.amort_line_id
|
||||
}}
|
||||
{{:assign var="linked_amort." value=$amort_line}}
|
||||
{{/load}}
|
||||
{{if $date_debut == null}}
|
||||
{{:assign date_debut=$amort_date}}
|
||||
{{/if}}
|
||||
{{/select}}
|
||||
|
||||
{{if $status == "amortized"}}
|
||||
{{if $info_immo.status == "amortized"}}
|
||||
{{:assign amort_amount=$ligne_immo.montant}}
|
||||
{{:assign valeur_residuelle=0}}
|
||||
{{else}}
|
||||
{{:assign valeur_residuelle=$ligne_immo.montant}}
|
||||
{{#foreach from=$linked_amort}}
|
||||
{{:assign valeur_residuelle="%d-%d"|math:$valeur_residuelle:$amort_amount}}
|
||||
{{/foreach}}
|
||||
{{/if}}
|
||||
|
||||
{{* Autres amortissements non rattachés *}}
|
||||
{{:include file="_get_config.html" keep="module.config"}}
|
||||
{{:assign filter_condition=" NOT ("}}
|
||||
{{#foreach from=$module.config.filters item="filter"}}
|
||||
{{:assign filter="%"|cat:$filter|cat:"%"|quote_sql}}
|
||||
{{:assign filter_condition=$filter_condition|cat:" trans.label LIKE "|cat:$filter|cat:" OR "}}
|
||||
{{/foreach}}
|
||||
{{:assign filter_condition=$filter_condition|cat:"0)"}}
|
||||
{{* lister les lignes des écritures d'amortissement liées à l'immobilisation *}}
|
||||
{{#load type="amort_link"
|
||||
where="$$.immo_doc_id = :immo_doc_id"
|
||||
:immo_doc_id = $_GET.immo_doc_id|intval
|
||||
}}
|
||||
{{#select
|
||||
line.id as amort_line_id,
|
||||
line.credit,
|
||||
line.label as amort_line_label,
|
||||
trans.id as amort_trans_id,
|
||||
trans.label as amort_trans_label,
|
||||
trans.date as amort_date,
|
||||
trans.id_year as amort_year,
|
||||
account.id as account_id,
|
||||
account.code as account_code,
|
||||
account.label as account_label
|
||||
FROM acc_transactions_lines AS line
|
||||
INNER JOIN acc_transactions AS trans ON line.id_transaction = trans.id
|
||||
INNER join acc_accounts AS account on line.id_account = account.id
|
||||
WHERE line.id = :amort_line_id
|
||||
;
|
||||
:amort_line_id = $amort_line_id
|
||||
assign="amort_line"
|
||||
}}
|
||||
{{:assign var="amort_line.amort_amount" value=$amount|or:$credit}}
|
||||
{{:assign var="linked_amort.%s_%d"|args:$amort_date:$id value=$amort_line}}
|
||||
{{:assign valeur_residuelle="%d-%d"|math:$valeur_residuelle:$amort_line.amort_amount}}
|
||||
{{/select}}
|
||||
{{/load}}
|
||||
|
||||
{{:assign autres_amortissements=false}}
|
||||
{{#select
|
||||
line.id_transaction AS amort_trans_id
|
||||
FROM acc_transactions_lines AS line
|
||||
INNER JOIN acc_accounts AS account ON account.id = line.id_account
|
||||
INNER JOIN acc_transactions AS trans ON trans.id = line.id_transaction
|
||||
INNER JOIN acc_years AS y ON y.id = trans.id_year
|
||||
WHERE account.code LIKE "28%" AND credit > 0 AND (NOT trans.status & 16) AND !filter_condition
|
||||
ORDER BY trans.date, trans.label;
|
||||
!filter_condition=$filter_condition
|
||||
assign="amort"
|
||||
}}
|
||||
{{* voir s'il existe des écritures liées avec un numéro de compte d'immobilisation *}}
|
||||
{{if $valeur_residuelle > 0}}
|
||||
{{* Chercher des amortissements non rattachés à une immo *}}
|
||||
{{#select
|
||||
links.id_transaction,
|
||||
links.id_related,
|
||||
trans.id AS trans_id
|
||||
FROM acc_transactions_links AS links
|
||||
INNER JOIN acc_transactions AS trans ON (
|
||||
CASE
|
||||
WHEN links.id_transaction = :id_amort THEN links.id_related
|
||||
WHEN links.id_related = :id_amort THEN links.id_transaction
|
||||
END) = trans.id
|
||||
INNER JOIN acc_transactions_lines AS line ON line.id_transaction = trans.id
|
||||
INNER JOIN acc_accounts AS acc ON line.id_account = acc.id
|
||||
WHERE
|
||||
links.id_transaction = :id_amort OR links.id_related = :id_amort
|
||||
AND acc.code LIKE '21%'
|
||||
LIMIT 1
|
||||
;
|
||||
:id_amort=$amort.amort_trans_id
|
||||
line.id as amort_line_id,
|
||||
line.id_transaction AS amort_trans_id
|
||||
FROM acc_transactions_lines AS line
|
||||
INNER JOIN acc_accounts AS account ON account.id = line.id_account
|
||||
INNER JOIN acc_transactions AS trans ON trans.id = line.id_transaction
|
||||
INNER JOIN acc_years AS y ON y.id = trans.id_year
|
||||
WHERE account.code LIKE "28%" AND credit > 0 AND (NOT trans.status & 16)
|
||||
ORDER BY trans.date, trans.label;
|
||||
}}
|
||||
{{* voir s'il existe un doc associé à une ligne de l'amortissement *}}
|
||||
{{:assign keep=true}}
|
||||
{{#load type="link"
|
||||
where="$$.amort_trans_id = :amort_trans_id"
|
||||
:amort_trans_id = $amort.amort_trans_id
|
||||
}}
|
||||
{{if $amort_line_id == $amort.amort_line_id}}
|
||||
{{:assign keep=false}}
|
||||
{{:break}}
|
||||
{{/if}}
|
||||
{{* cette ligne d'amortissement a-t-elle un doc associé ? *}}
|
||||
{{#load type="amort_link"
|
||||
where="$$.amort_line_id = :amort_line_id"
|
||||
:amort_line_id = $amort_line_id
|
||||
}}
|
||||
{{else}}
|
||||
{{:assign keep=false}}
|
||||
{{/load}}
|
||||
{{if $keep}}
|
||||
{{:assign autres_amortissements=true}}
|
||||
{{/if}}
|
||||
{{else}}
|
||||
{{:assign autres_amortissements=true}}
|
||||
{{/load}}
|
||||
{{/select}}
|
||||
{{/select}}
|
||||
{{/if}}
|
||||
|
||||
{{:admin_header title="Liste des amortissements" custom_css="./style.css" current="module_amortization"}}
|
||||
|
||||
|
|
@ -200,16 +152,16 @@
|
|||
|
||||
{{if $_GET.ok}}
|
||||
{{if $_GET.msg|match:"attach"}}
|
||||
{{:assign msg="Attachement écriture %s effectué"|args:$_GET.trans_id}}
|
||||
{{:assign msg="Attachement amortissement %s effectué"|args:$_GET.trans_id}}
|
||||
{{elseif $_GET.msg|match:"detach"}}
|
||||
{{:assign msg="Détachement écriture %s affectué"|args:$_GET.trans_id}}
|
||||
{{:assign msg="Détachement amortissement %s affectué"|args:$_GET.trans_id}}
|
||||
{{elseif $_GET.msg|match:"amortissement"}}
|
||||
{{:assign msg="Amortissement enregistré"}}
|
||||
{{/if}}
|
||||
<p class="block confirm">{{$msg}}</p>
|
||||
{{elseif $_GET.err}}
|
||||
{{if $_GET.msg|match:"attach"}}
|
||||
{{:assign msg="Échec attachement"}}
|
||||
{{:assign msg="Échec attachement amortissement"}}
|
||||
{{elseif $_GET.msg|match:"amortissement"}}
|
||||
{{:assign msg="Échec enregistrement amortissement"}}
|
||||
{{/if}}
|
||||
|
|
@ -222,7 +174,7 @@
|
|||
<p class="submit">
|
||||
{{:linkbutton
|
||||
label="Sortir du bilan"
|
||||
href="balance_sheet_exit.html?immo_line_id=%s&type_immo=%s"|args:$_GET.immo_line_id:$_GET.type_immo
|
||||
href="balance_sheet_exit.html?immo_line_id=%s&immo_doc_id=%s&type_immo=%s"|args:$_GET.immo_line_id:$_GET.immo_doc_id:$_GET.type_immo
|
||||
shape="export"
|
||||
class="main"
|
||||
}}
|
||||
|
|
@ -238,14 +190,22 @@
|
|||
<div class="informations">
|
||||
<dl class="describe">
|
||||
<dt>Immobilisation</dt>
|
||||
<dd><span class="num"><a href="{{$trans_url}}">#{{$ligne_immo.immo_trans_id}}</a></span> {{$ligne_immo.label}}{{if $ligne_immo.line_label != null && $ligne_immo.line_label != $ligne_immo.label}} — {{$ligne_immo.line_label}}{{/if}}</dd>
|
||||
<dt>Montant</dt>
|
||||
<dd><span class="num"><a href="{{$trans_url}}">#{{$ligne_immo.immo_trans_id}}</a></span> {{$label_immo}}</dd>
|
||||
<dt>Compte d'immobilisation</dt>
|
||||
<dd>{{$ligne_immo.account_code}} — {{$ligne_immo.account_label}}</dd>
|
||||
<dt>Montant de l'immobilisation</dt>
|
||||
<dd class="money strong">{{"%f"|math:$ligne_immo.montant|money_currency_html:false|raw}}</dd>
|
||||
{{if $total_credits > 0}}
|
||||
<dt>Montant des avoirs</dt>
|
||||
<dd class="money">{{"%f"|math:$total_credits|money_currency_html:false|raw}}</dd>
|
||||
<dt>Montant à amortir</dt>
|
||||
<dd class="money strong">{{"%f"|math:$solde|money_currency_html:false|raw}}</dd>
|
||||
{{/if}}
|
||||
<dt>Début d'amortissement</dt>
|
||||
<dd>{{$date_debut|date_short}}</dd>
|
||||
{{if $duree != null}}
|
||||
{{if $info_immo.duration != null}}
|
||||
<dt>Durée</dt>
|
||||
<dd>{{$duree}} ans</dd>
|
||||
<dd>{{$info_immo.duration}} ans</dd>
|
||||
{{/if}}
|
||||
{{if $valeur_residuelle > 0}}
|
||||
<dt>Montant des amortissements</dt>
|
||||
|
|
@ -253,9 +213,9 @@
|
|||
<dt>Valeur nette comptable</dt>
|
||||
<dd>{{$valeur_residuelle|money_currency_html:false|raw}}</dd>
|
||||
{{/if}}
|
||||
{{if $duree != null && $valeur_residuelle > 0}}
|
||||
{{if $info_immo.duration != null && $valeur_residuelle > 0}}
|
||||
<dt>Annuité estimée</dt>
|
||||
<dd>{{"min(%d, %f/%d)"|math:$valeur_residuelle:$ligne_immo.montant:$duree|money_currency_html:false|raw}}</dd>
|
||||
<dd>{{"min(%d, %f/%d)"|math:$valeur_residuelle:$ligne_immo.montant:$info_immo.duration|money_currency_html:false|raw}}</dd>
|
||||
{{/if}}
|
||||
</dl>
|
||||
</div>
|
||||
|
|
@ -277,7 +237,7 @@
|
|||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{{#foreach from=$linked_amort item="line"}}
|
||||
{{#foreach from=$linked_amort|ksort item="line"}}
|
||||
{{* données de l'écriture *}}
|
||||
{{:assign trans_url="%s/acc/transactions/details.php?id=%s"|args:$admin_url:$line.amort_trans_id}}
|
||||
{{:assign compte_url="%s/acc/accounts/journal.php?id=%s&year=%s"|args:$admin_url:$line.account_id:$line.amort_year}}
|
||||
|
|
@ -296,7 +256,7 @@
|
|||
<td><a href="{{$compte_url}}">{{$line.account_code}}</a></td>
|
||||
<td>{{$line.account_label}}</td>
|
||||
<td>
|
||||
{{:linkbutton label="Détacher" href="detach_amort.html?amort_line_id=%d&immo_line_id=%d"|args:$line.amort_line_id:$ligne_immo.immo_line_id shape="minus"}}
|
||||
{{:linkbutton label="Détacher" href="detach_amort.html?amort_line_id=%d&immo_line_id=%d&immo_doc_id=%s"|args:$line.amort_line_id:$ligne_immo.immo_line_id:$_GET.immo_doc_id shape="minus"}}
|
||||
</td>
|
||||
</tr>
|
||||
{{/foreach}}
|
||||
|
|
@ -307,16 +267,11 @@
|
|||
<p class="block alert">Aucun amortissement enregistré pour cette immobilisation</p>
|
||||
{{/if}}
|
||||
|
||||
{{if $_GET.type_immo == null || $_GET.type_immo != "amortized"}}
|
||||
|
||||
{{* Autres amortissements non rattachés *}}
|
||||
|
||||
{{if $autres_amortissements}}
|
||||
<p class="block alert">
|
||||
Il existe des écritures d'amortissement qui ne sont pas rattachées à une immobilisation ! <br />
|
||||
Utilisez le bouton « Rattacher une écriture » pour les afficher ; vous pourrez choisir d'en attacher certaines à cette immobilisation.
|
||||
</p>
|
||||
{{/if}}
|
||||
{{if $autres_amortissements}}
|
||||
<p class="block alert">
|
||||
Il y a des écritures d'amortissement qui ne sont pas rattachées à une immobilisation ! <br />
|
||||
Utilisez le bouton « Rattacher un amortissement » pour les afficher ; vous pourrez choisir d'en attacher certaines à cette immobilisation.
|
||||
</p>
|
||||
{{/if}}
|
||||
{{:form_errors}}
|
||||
{{:admin_footer}}
|
||||
|
|
|
|||
|
|
@ -1,74 +1,168 @@
|
|||
{{* -*- brindille -*- *}}
|
||||
|
||||
{{*
|
||||
Enregistrer la liaison entre une écriture d'amortissement et
|
||||
l'écriture d'immobilisation correspondante
|
||||
Enregistrer la liaison entre une ligne d'écriture d'amortissement
|
||||
et une ligne d'écriture d'immobilisation
|
||||
@param immo_line_id : numéro de ligne de l'écriture d'immobilisation
|
||||
@param amort_line_id : numéro de ligne de l'écriture d'amortissement
|
||||
@param immo_doc_id : numéro du doc d'immo
|
||||
*}}
|
||||
|
||||
{{* chercher l'écriture d'immobilisation *}}
|
||||
{{#select
|
||||
id_transaction
|
||||
FROM acc_transactions_lines
|
||||
WHERE id = :line_id;
|
||||
line.id_transaction as immo_trans_id,
|
||||
trans.label as trans_label,
|
||||
line.label as line_label
|
||||
FROM acc_transactions_lines as line
|
||||
INNER JOIN acc_transactions AS trans ON line.id_transaction = trans.id
|
||||
WHERE line.id = :line_id;
|
||||
:line_id = $_GET.immo_line_id|intval
|
||||
assign="ligne_immo"
|
||||
}}
|
||||
{{:assign immo_trans_id=$id_transaction}}
|
||||
{{else}}
|
||||
{{:error message="Impossible de trouver l'écriture d'immobilisation de la ligne « %s »"|args:$_GET.immo_line_id}}
|
||||
{{:error message="Immobilisation non trouvée"}}
|
||||
{{/select}}
|
||||
|
||||
{{* chercher le doc associé à l'immo *}}
|
||||
{{#load id=$_GET.immo_doc_id|intval}}
|
||||
{{:assign label_immo=$label|or:$ligne_immo.trans_label}}
|
||||
{{else}}
|
||||
{{:error message="Immobilisation non trouvée"}}
|
||||
{{/load}}
|
||||
|
||||
{{if $ligne_immo.line_label != null && $ligne_immo.line_label != $label_immo}}
|
||||
{{:assign label_immo=$label_immo|cat:" — "|cat:$ligne_immo.line_label}}
|
||||
{{/if}}
|
||||
|
||||
{{* chercher l'écriture d'amortissement *}}
|
||||
{{#select
|
||||
id_transaction
|
||||
FROM acc_transactions_lines
|
||||
WHERE id = :line_id;
|
||||
line.credit as amount,
|
||||
line.label as line_label,
|
||||
trans.date as amort_date,
|
||||
trans.label as trans_label,
|
||||
trans.id as trans_id,
|
||||
acc.code as account_code,
|
||||
acc.label as account_label
|
||||
FROM acc_transactions_lines as line
|
||||
INNER JOIN acc_transactions as trans on line.id_transaction = trans.id
|
||||
INNER JOIN acc_accounts as acc on line.id_account = acc.id
|
||||
WHERE line.id = :line_id;
|
||||
:line_id = $_GET.amort_line_id|intval
|
||||
assign="amort_line"
|
||||
}}
|
||||
{{:assign amort_trans_id=$id_transaction}}
|
||||
{{else}}
|
||||
{{:error message="Impossible de trouver l'écriture d'amortissement de la ligne « %s »"|args:$_GET.amort_line_id}}
|
||||
{{:error message="Amortissement non trouvé"}}
|
||||
{{/select}}
|
||||
{{:assign trans_url="%s/acc/transactions/details.php?id=%s"|args:$admin_url:$amort_line.trans_id}}
|
||||
|
||||
{{* chercher les liaisons de l'écriture d'immobilisation *}}
|
||||
{{#select
|
||||
CASE links.id_related = :immo_trans_id
|
||||
WHEN true THEN links.id_transaction
|
||||
WHEN false THEN links.id_related
|
||||
END as linked_id
|
||||
FROM acc_transactions_links as links
|
||||
WHERE id_transaction = :immo_trans_id or id_related = :immo_trans_id;
|
||||
:immo_trans_id = $immo_trans_id
|
||||
}}
|
||||
{{:assign var="linked_transactions." value=$linked_id}}
|
||||
{{/select}}
|
||||
|
||||
{{* ajouter la nouvelle liaison *}}
|
||||
{{:assign var="linked_transactions." value=$amort_trans_id}}
|
||||
{{:api
|
||||
method="POST"
|
||||
path="accounting/transaction/%s/transactions"|args:$immo_trans_id
|
||||
assign="result"
|
||||
assign_code="result_code"
|
||||
transactions=$linked_transactions
|
||||
}}
|
||||
|
||||
{{* vérifier si cette liaison est déjà présente dans les documents pour éviter les doublons *}}
|
||||
{{#load type="link"
|
||||
where="$$.immo_line_id = :immo_line_id AND
|
||||
$$.amort_trans_id = :amort_trans_id AND
|
||||
$$.amort_line_id = :amort_line_id"
|
||||
:immo_line_id=$_GET.immo_line_id|intval
|
||||
:amort_trans_id = $amort_trans_id
|
||||
{{* montant de l'écriture d'amortissement déjà affecté *}}
|
||||
{{:assign montant_affecte=0}}
|
||||
{{#load type="amort_link" assign="linked_amort."
|
||||
where="$$.amort_line_id = :amort_line_id"
|
||||
:amort_line_id = $_GET.amort_line_id|intval
|
||||
limit=1
|
||||
}}
|
||||
{{else}}
|
||||
{{:save
|
||||
key=""|uuid
|
||||
type="link"
|
||||
immo_line_id=$_GET.immo_line_id|intval
|
||||
amort_line_id=$_GET.amort_line_id|intval
|
||||
amort_trans_id=$amort_trans_id
|
||||
}}
|
||||
{{:assign montant_affecte="%d+%d"|math:$montant_affecte:$amount}}
|
||||
{{/load}}
|
||||
{{:redirect force="amortization.html?immo_line_id=%s&ok=1&msg=attach&trans_id=%s"|args:$_GET.immo_line_id:$amort_trans_id}}
|
||||
{{:assign reste="%d-%d"|math:$amort_line.amount:$montant_affecte}}
|
||||
|
||||
{{* Traiter l'envoi du formulaire *}}
|
||||
{{#form on="save"}}
|
||||
|
||||
{{* vérifier que le montant saisi est inférieur au reste *}}
|
||||
{{if $_POST.montant == null}}
|
||||
{{if $montant_affecte == 0}}
|
||||
{{:assign saved_amount=null}}
|
||||
{{else}}
|
||||
{{:assign saved_amount=$reste}}
|
||||
{{/if}}
|
||||
{{else}}
|
||||
{{:assign montant_amort=$_POST.montant|money_int}}
|
||||
{{if $montant_amort > $reste}}
|
||||
{{:assign reste_nb="%f"|math:$reste|money_currency:false}}
|
||||
{{:error message="Le montant de l'amortissement ne peut être supérieur au reste (%s)"|args:$reste_nb}}
|
||||
{{/if}}
|
||||
{{if $montant_amort == $amort_line.amount}}
|
||||
{{:assign saved_amount=null}}
|
||||
{{else}}
|
||||
{{:assign saved_amount=$montant_amort}}
|
||||
{{/if}}
|
||||
{{/if}}
|
||||
|
||||
{{* chercher les liaisons de l'écriture d'immobilisation *}}
|
||||
{{#select
|
||||
CASE links.id_related = :immo_trans_id
|
||||
WHEN true THEN links.id_transaction
|
||||
WHEN false THEN links.id_related
|
||||
END as linked_id
|
||||
FROM acc_transactions_links as links
|
||||
WHERE id_transaction = :immo_trans_id or id_related = :immo_trans_id;
|
||||
:immo_trans_id = $ligne_immo.immo_trans_id
|
||||
}}
|
||||
{{:assign var="linked_transactions." value=$linked_id}}
|
||||
{{/select}}
|
||||
|
||||
{{* ajouter la nouvelle liaison *}}
|
||||
{{:assign var="linked_transactions." value=$amort_line.trans_id}}
|
||||
{{:api
|
||||
method="POST"
|
||||
path="accounting/transaction/%s/transactions"|args:$ligne_immo.immo_trans_id
|
||||
assign="result"
|
||||
assign_code="result_code"
|
||||
transactions=$linked_transactions
|
||||
}}
|
||||
|
||||
{{* vérifier si cette liaison est déjà présente dans les documents pour éviter les doublons *}}
|
||||
{{* TODO voir si nécessaire ? *}}
|
||||
{{#load type="amort_link"
|
||||
where="$$.immo_doc_id = :immo_doc_id AND $$.amort_line_id = :amort_line_id"
|
||||
:immo_doc_id=$_GET.immo_doc_id|intval
|
||||
:amort_line_id = $_GET.amort_line_id|intval
|
||||
limit=1
|
||||
}}
|
||||
{{else}}
|
||||
{{:save
|
||||
key=""|uuid
|
||||
type="amort_link"
|
||||
immo_doc_id=$_GET.immo_doc_id|intval
|
||||
amort_line_id=$_GET.amort_line_id|intval
|
||||
amount=$saved_amount
|
||||
}}
|
||||
{{/load}}
|
||||
|
||||
{{:redirect force="amortization.html?immo_line_id=%s&immo_doc_id=%s&ok=1&msg=attach_amort"|args:$_GET.immo_line_id:$_GET.immo_doc_id}}
|
||||
{{/form}}
|
||||
|
||||
{{:admin_header title="Amortir l'immobilisation" custom_css="./style.css" current="module_amortization"}}
|
||||
|
||||
{{* barre de navigation *}}
|
||||
{{if ! $dialog}}
|
||||
{{:include file="_nav.html" current="config" subcurrent="init" subsubcurrent="parameter"}}
|
||||
{{/if}}
|
||||
{{:form_errors}}
|
||||
|
||||
<div class="informations">
|
||||
<dl class="describe">
|
||||
<dt>Immobilisation</dt>
|
||||
<dd>{{$label_immo}}</dd>
|
||||
<dt>Amortissement</dt>
|
||||
<dd><span class="num"><a href="{{$trans_url}}">#{{$amort_line.trans_id}}</a></span> {{$label_immo}}</dd>
|
||||
<dt>Montant de l'écriture d'amortissement</dt>
|
||||
<dd>{{$amort_line.amount|money_currency_html:false|raw}}</dd>
|
||||
<dt>Montant déjà affecté</dt>
|
||||
<dd class="money strong">{{"%f"|math:$montant_affecte|money_currency_html:false|raw}}</dd>
|
||||
<dt>Montant restant à affecter</dt>
|
||||
<dd class="money strong">{{"%f"|math:$reste|money_currency_html:false|raw}}</dd>
|
||||
</dl>
|
||||
</div>
|
||||
|
||||
<form method="post" action="" data-focus="1">
|
||||
<fieldset>
|
||||
<dl>
|
||||
{{:input type="money" name="montant" label="Montant" default=$reste required=true help="Montant de l'amortissement"}}
|
||||
</dl>
|
||||
</fieldset>
|
||||
<p class="submit">
|
||||
{{:button type="submit" name="save" label="Enregistrer" shape="right" class="main"}}
|
||||
</p>
|
||||
</form>
|
||||
|
||||
|
|
|
|||
162
attach_immo.html
Normal file
162
attach_immo.html
Normal file
|
|
@ -0,0 +1,162 @@
|
|||
{{* -*- brindille -*- *}}
|
||||
{{:admin_header title="Écritures au crédit du compte d'immobilisation" custom_css="./style.css" current="module_amortization"}}
|
||||
|
||||
{{*
|
||||
Enregistrer la liaison entre une ligne d'immobilisation et
|
||||
une ligne d'écriture au crédit du compte de l'immobilisation
|
||||
@param credit_line_id : ligne d'écriture au crédit du compte de l'immobilisation
|
||||
@param immo_doc_id : numéro du doc d'immo
|
||||
*}}
|
||||
|
||||
{{* chercher l'écriture d'immobilisation *}}
|
||||
{{#load id=$_GET.immo_doc_id|intval assign="doc_immo"}}
|
||||
{{else}}
|
||||
{{:error message="Immobilisation non gérée ; vous devez d'abord renseigner ses informations"}}
|
||||
{{/load}}
|
||||
{{#select
|
||||
line.id as immo_line_id,
|
||||
line.id_transaction as immo_trans_id,
|
||||
line.label as line_label,
|
||||
trans.label as trans_label
|
||||
FROM acc_transactions_lines as line
|
||||
INNER JOIN acc_transactions AS trans ON line.id_transaction = trans.id
|
||||
WHERE line.id = :line_id;
|
||||
:line_id = $doc_immo.line
|
||||
assign="ligne_immo"
|
||||
}}
|
||||
{{else}}
|
||||
{{:error message="Immobilisation non trouvée"}}
|
||||
{{/select}}
|
||||
|
||||
{{:assign label_immo=$doc_immo.label|or:$ligne_immo.trans_label}}
|
||||
{{if $ligne_immo.line_label != null && $ligne_immo.line_label != $label_immo}}
|
||||
{{:assign label_immo=$label_immo|cat:" — "|cat:$ligne_immo.line_label}}
|
||||
{{/if}}
|
||||
|
||||
{{* chercher l'écriture au crédit du compte d'immobilisation *}}
|
||||
{{#select
|
||||
line.id_transaction as credit_trans_id,
|
||||
line.credit as amount,
|
||||
trans.label as trans_label,
|
||||
line.label as line_label
|
||||
FROM acc_transactions_lines as line
|
||||
INNER JOIN acc_transactions AS trans ON line.id_transaction = trans.id
|
||||
WHERE line.id = :line_id;
|
||||
:line_id = $_GET.credit_line_id|intval
|
||||
assign="credit_line"
|
||||
}}
|
||||
{{else}}
|
||||
{{:error message="Impossible de trouver l'écriture au crédit du compte de l'immobilisation de la ligne « %s »"|args:$ligne_immo.trans_label}}
|
||||
{{/select}}
|
||||
{{:assign credit_trans_url="%s/acc/transactions/details.php?id=%s"|args:$admin_url:$credit_line.credit_trans_id}}
|
||||
|
||||
{{* montant de l'écriture de crédit déjà affecté *}}
|
||||
{{:assign montant_affecte=0}}
|
||||
{{#load type="immo_link" assign="linked_immo."
|
||||
where="$$.credit_line_id = :credit_line_id"
|
||||
:credit_line_id = $_GET.credit_line_id|intval
|
||||
}}
|
||||
{{:assign montant_affecte="%d+%d"|math:$montant_affecte:$amount}}
|
||||
{{/load}}
|
||||
{{:assign reste="%d-%d"|math:$credit_line.amount:$montant_affecte}}
|
||||
|
||||
{{* Traiter l'envoi du formulaire *}}
|
||||
{{#form on="save"}}
|
||||
{{* vérifier que le montant saisi est inférieur au reste *}}
|
||||
{{if $_POST.montant == null}}
|
||||
{{if $montant_affecte == 0}}
|
||||
{{:assign saved_credit=null}}
|
||||
{{else}}
|
||||
{{:assign saved_credit=$reste}}
|
||||
{{/if}}
|
||||
{{else}}
|
||||
{{:assign montant_credit=$_POST.montant|money_int}}
|
||||
{{if $montant_credit > $reste}}
|
||||
{{:assign reste_nb="%f"|math:$reste|money_currency:false}}
|
||||
{{:error message="Le montant de l'avoir ne peut être supérieur au reste (%s)"|args:$reste_nb}}
|
||||
{{/if}}
|
||||
{{if $montant_credit == $credit_line.amount}}
|
||||
{{:assign saved_credit=null}}
|
||||
{{else}}
|
||||
{{:assign saved_credit=$montant_credit}}
|
||||
{{/if}}
|
||||
{{/if}}
|
||||
|
||||
{{* chercher les liaisons de l'écriture d'immobilisation *}}
|
||||
{{#select
|
||||
CASE links.id_related = :immo_trans_id
|
||||
WHEN true THEN links.id_transaction
|
||||
WHEN false THEN links.id_related
|
||||
END as linked_id
|
||||
FROM acc_transactions_links as links
|
||||
WHERE id_transaction = :immo_trans_id or id_related = :immo_trans_id;
|
||||
:immo_trans_id = $ligne_immo.immo_trans_id
|
||||
}}
|
||||
{{:assign var="linked_transactions." value=$linked_id}}
|
||||
{{/select}}
|
||||
|
||||
{{* ajouter la nouvelle liaison *}}
|
||||
{{:assign var="linked_transactions." value=$credit_line.credit_trans_id}}
|
||||
|
||||
{{* Enregistrer les liaisons *}}
|
||||
{{:api
|
||||
method="POST"
|
||||
path="accounting/transaction/%s/transactions"|args:$ligne_immo.immo_trans_id
|
||||
assign="result"
|
||||
assign_code="result_code"
|
||||
transactions=$linked_transactions
|
||||
}}
|
||||
|
||||
{{*
|
||||
TODO ? vérifier le succès avant d'enregistrer le doc ?
|
||||
*}}
|
||||
|
||||
{{* enregistrer la liaison des lignes d'immo *}}
|
||||
{{:save
|
||||
key=""|uuid
|
||||
type="immo_link"
|
||||
immo_doc_id=$_GET.immo_doc_id|intval
|
||||
credit_line_id=$_GET.credit_line_id|intval
|
||||
amount=$saved_credit
|
||||
}}
|
||||
|
||||
{{:redirect force="details_immo.html?immo_doc_id=%s&ok=1&msg=attach_immo"|args:$_GET.immo_doc_id}}
|
||||
{{/form}}
|
||||
|
||||
{{if ! $dialog}}
|
||||
{{:include
|
||||
file="_nav.html"
|
||||
current="config"
|
||||
subcurrent="other"
|
||||
subsubcurrent="immo"
|
||||
type_immo="other"
|
||||
}}
|
||||
{{/if}}
|
||||
{{:form_errors}}
|
||||
|
||||
<div class="informations">
|
||||
<dl class="describe">
|
||||
<dt>Immobilisation</dt>
|
||||
<dd>{{$label_immo}}</dd>
|
||||
<dt>Écriture au crédit du compte d'immobilisation</dt>
|
||||
<dd><span class="num"><a href="{{$credit_trans_url}}">#{{$credit_line.credit_trans_id}}</a></span> {{$credit_line.trans_label}}{{if $credit_line.line_label != null && $credit_line.line_label != $credit_line.trans_label}} — {{$credit_line.line_label}}{{/if}}</dd>
|
||||
<dt>Montant de l'écriture</dt>
|
||||
<dd>{{$credit_line.amount|money_currency_html:false|raw}}</dd>
|
||||
<dt>Montant déjà affecté</dt>
|
||||
<dd class="money strong">{{"%f"|math:$montant_affecte|money_currency_html:false|raw}}</dd>
|
||||
<dt>Montant restant à affecter</dt>
|
||||
<dd class="money strong">{{"%f"|math:$reste|money_currency_html:false|raw}}</dd>
|
||||
</dl>
|
||||
</div>
|
||||
|
||||
<form method="post" action="" data-focus="1">
|
||||
<fieldset>
|
||||
<dl>
|
||||
{{:input type="money" name="montant" label="Montant" default=$reste help="Montant de l'avoir"}}
|
||||
</dl>
|
||||
</fieldset>
|
||||
<p class="submit">
|
||||
{{:button type="submit" name="save" label="Enregistrer" shape="right" class="main"}}
|
||||
</p>
|
||||
</form>
|
||||
|
||||
|
|
@ -77,11 +77,9 @@
|
|||
WHERE l_immo.id = :line_id AND account.code LIKE '28%'
|
||||
;
|
||||
:line_id = $_GET.immo_line_id|intval
|
||||
assign="amort_lines."
|
||||
assign="amort_line"
|
||||
}}
|
||||
{{/select}}
|
||||
|
||||
{{#foreach from=$amort_lines item="amort_line"}}
|
||||
{{#load type="link"
|
||||
where="$$.immo_line_id = :immo_line_id AND $$.amort_trans_id = :amort_trans_id"
|
||||
assign="line"
|
||||
|
|
@ -115,7 +113,7 @@
|
|||
{{:assign last_amort_date=$amort_line.date}}
|
||||
{{/if}}
|
||||
{{/load}}
|
||||
{{/foreach}}
|
||||
{{/select}}
|
||||
|
||||
{{if $total_amort == 0}}
|
||||
{{if $info_immo.status == "amortized"}}
|
||||
|
|
|
|||
|
|
@ -3,6 +3,9 @@
|
|||
{{*
|
||||
Supprimer l'association entre une écriture d'amortissement et
|
||||
une écriture d'immobilisation
|
||||
@param immo_line_id : id de la ligne d'immo
|
||||
@param amort_line_id : id de la ligne d'amortissement
|
||||
@param immo_doc_id : id du doc associé à l'immo
|
||||
*}}
|
||||
|
||||
{{* chercher l'écriture d'immobilisation *}}
|
||||
|
|
@ -14,7 +17,7 @@
|
|||
}}
|
||||
{{:assign immo_trans_id=$id_transaction}}
|
||||
{{else}}
|
||||
{{:error message="Impossible de trouver l'écriture d'immobilisation de la ligne « %s »"|args:$_GET.immo_line_id}}
|
||||
{{:error message="Immobilisation non trouvée"}}
|
||||
{{/select}}
|
||||
|
||||
{{* chercher l'écriture d'amortissement *}}
|
||||
|
|
@ -26,7 +29,7 @@
|
|||
}}
|
||||
{{:assign amort_id=$id_transaction}}
|
||||
{{else}}
|
||||
{{:error message="Impossible de trouver l'écriture d'amortissement de la ligne « %s »"|args:$_GET.amort_line_id}}
|
||||
{{:error message="Amortissement non trouvé"}}
|
||||
{{/select}}
|
||||
|
||||
{{*
|
||||
|
|
@ -57,15 +60,13 @@
|
|||
}}
|
||||
|
||||
{{* supprimer le doc de liaison entre les lignes *}}
|
||||
{{#load type="link"
|
||||
where="$$.immo_line_id = :immo_line_id AND
|
||||
$$.amort_trans_id = :amort_trans_id AND
|
||||
$$.amort_line_id = :amort_line_id"
|
||||
:immo_line_id=$_GET.immo_line_id|intval
|
||||
:amort_trans_id = $amort_id|intval
|
||||
{{#load type="amort_link"
|
||||
where="$$.immo_doc_id = :immo_doc_id AND $$.amort_line_id = :amort_line_id"
|
||||
:immo_doc_id=$_GET.immo_doc_id|intval
|
||||
:amort_line_id = $_GET.amort_line_id|intval
|
||||
}}
|
||||
{{:delete id=$id}}
|
||||
{{/load}}
|
||||
|
||||
{{:redirect to="amortization.html?immo_line_id=%s&ok=1&msg=detach&trans_id=%s"|args:$_GET.immo_line_id:$amort_id}}
|
||||
{{:redirect
|
||||
to="amortization.html?immo_line_id=%s&ok=1&msg=detach&immo_doc_id=%s"|args:$_GET.immo_line_id:$_GET.immo_doc_id}}
|
||||
|
|
|
|||
159
details_immo.html
Normal file
159
details_immo.html
Normal file
|
|
@ -0,0 +1,159 @@
|
|||
{{* -*- brindille -*- *}}
|
||||
|
||||
{{:admin_header title="Détails de l'immobilisation" custom_css="./style.css" current="module_amortization"}}
|
||||
|
||||
{{*
|
||||
Afficher les détails d'une immmo
|
||||
- permettre l'association d'une immo au crédit du compte de l'immo
|
||||
- permettre de modifier les paramètres de l'immo
|
||||
@param (OBSOLÈTE ?) immo_line_id : numéro de ligne de l'écriture d'immobilisation
|
||||
@param immo_doc_id : numéro du doc d'immo
|
||||
*}}
|
||||
|
||||
{{*
|
||||
TODO : permettre la modification des param (en cas d'erreur de saisie)
|
||||
TODO : permettre de corriger le montant de l'amort et/ou de supprimer l'attachement
|
||||
FAIT : déduire montant au crédit de la ligne d'immo
|
||||
*}}
|
||||
|
||||
{{* données de l'immobilisation *}}
|
||||
{{#load type="immo" id=$_GET.immo_doc_id|intval assign="info_immo"}}
|
||||
{{else}}
|
||||
{{:error message="Immobilisation non trouvée"}}
|
||||
{{/load}}
|
||||
|
||||
{{#select
|
||||
trans.id as immo_trans_id,
|
||||
trans.label as label,
|
||||
trans.date as date_achat,
|
||||
line.id as immo_line_id,
|
||||
line.debit as montant,
|
||||
line.label as line_label,
|
||||
account.code as account_code,
|
||||
account.label as account_label
|
||||
FROM acc_transactions_lines AS line
|
||||
INNER join acc_transactions AS trans ON line.id_transaction = trans.id
|
||||
INNER JOIN acc_accounts AS account ON line.id_account = account.id
|
||||
WHERE line.id = :line_id;
|
||||
:line_id = $info_immo.line
|
||||
assign="ligne_immo"
|
||||
}}
|
||||
{{else}}
|
||||
{{:error message="Immobilisation non trouvée"}}
|
||||
{{/select}}
|
||||
|
||||
{{:assign var="info_immo.amount" value=$info_immo.amount|or:$ligne_immo.montant}}
|
||||
{{:assign var="info_immo.date_achat" value=$info_immo.date_achat|or:$ligne_immo.date_achat}}
|
||||
{{:assign var="info_immo.date_mes" value=$info_immo.date_mes|or:$ligne_immo.date_achat}}
|
||||
{{:assign var="info_immo.label" value=$info_immo.label|or:$ligne_immo.label}}
|
||||
{{if $ligne_immo.line_label != null && $ligne_immo.line_label != $info_immo.label}}
|
||||
{{:assign var="info_immo.label" value=$info_immo.label|cat:" — "|cat:$ligne_immo.line_label}}
|
||||
{{/if}}
|
||||
|
||||
{{*
|
||||
chercher des écritures liées à l'immo courante au crédit du même compte
|
||||
et déduire leur montant de celui de l'immo
|
||||
*}}
|
||||
{{:assign linked_immos=null}}
|
||||
{{:assign total_credits=0}}
|
||||
{{#load type="immo_link" where="$$.immo_doc_id=:immo_doc_id" :immo_doc_id=$_GET.immo_doc_id|intval}}
|
||||
{{#select
|
||||
line.credit,
|
||||
trans.id
|
||||
FROM acc_transactions_lines AS line
|
||||
INNER JOIN acc_transactions AS trans ON line.id_transaction = trans.id
|
||||
WHERE line.id = :credit_line_id;
|
||||
:credit_line_id=$credit_line_id
|
||||
}}
|
||||
{{:assign credit=$credit}}
|
||||
{{:assign credit_trans_id=$id}}
|
||||
{{/select}}
|
||||
{{:assign var="linked_immos." value=$credit_trans_id}}
|
||||
{{if $amount == null}}
|
||||
{{:assign total_credits="%d+%d"|math:$total_credits:$credit}}
|
||||
{{else}}
|
||||
{{:assign total_credits="%d+%d"|math:$total_credits:$amount}}
|
||||
{{/if}}
|
||||
{{/load}}
|
||||
{{:assign solde="%d-%d"|math:$info_immo.amount:$total_credits}}
|
||||
|
||||
{{:assign total_amort=0}}
|
||||
{{* lister les docs d'amortissement liées à la ligne d'immobilisation *}}
|
||||
{{#load type="amort_link"
|
||||
where="$$.immo_doc_id = :immo_doc_id"
|
||||
:immo_doc_id=$_GET.immo_doc_id|intval
|
||||
}}
|
||||
{{if $amount != null}}
|
||||
{{:assign total_amort="%d+%d"|math:$total_amort:$amount}}
|
||||
{{else}}
|
||||
{{#select credit FROM acc_transactions_lines WHERE id = :amort_line_id;
|
||||
:amort_line_id=$amort_line_id
|
||||
}}
|
||||
{{:assign total_amort="%d+%d"|math:$total_amort:$credit}}
|
||||
{{/select}}
|
||||
{{/if}}
|
||||
{{/load}}
|
||||
|
||||
{{* barre de navigation *}}
|
||||
{{if ! $dialog}}
|
||||
{{if $total_credits == 0 && $total_amort == 0}}
|
||||
{{:assign subsubcurrent="credit"}}
|
||||
{{else}}
|
||||
{{:assign subsubcurrent=null}}
|
||||
{{/if}}
|
||||
{{:include file="_nav.html" current="index" subcurrent="details" subsubcurrent=$subsubcurrent}}
|
||||
{{/if}}
|
||||
{{:assign trans_url="%s/acc/transactions/details.php?id=%s"|args:$admin_url:$ligne_immo.immo_trans_id}}
|
||||
|
||||
{{if $_GET.ok}}
|
||||
{{if $_GET.msg|match:"attach_amort"}}
|
||||
{{:assign msg="Attachement amortissement effectué"}}
|
||||
{{elseif $_GET.msg|match:"attach_immo"}}
|
||||
{{:assign msg="Attachement avoir effectué"}}
|
||||
{{elseif $_GET.msg|match:"info"}}
|
||||
{{:assign msg="Données de l'immobilisation enregistrées"}}
|
||||
{{/if}}
|
||||
<p class="block confirm">{{$msg}}</p>
|
||||
{{elseif $_GET.err}}
|
||||
{{:assign msg="L'opération a échoué"}}
|
||||
<p class="block error">{{$msg}}</p>
|
||||
{{/if}}
|
||||
|
||||
<h3 class="ruler">
|
||||
Paramètres de l'immobilisation
|
||||
<span class="num"><a href="{{$trans_url}}">#{{$ligne_immo.immo_trans_id}}</a></span>
|
||||
</h3>
|
||||
<div class="informations">
|
||||
<dl class="describe">
|
||||
<dt>Immobilisation</dt>
|
||||
<dd><span class="num"><a href="{{$trans_url}}">#{{$ligne_immo.immo_trans_id}}</a></span> {{$info_immo.label}}</dd>
|
||||
<dt>Compte d'immobilisation</dt>
|
||||
<dd>{{$ligne_immo.account_code}} — {{$ligne_immo.account_label}}</dd>
|
||||
<dt>Montant de l'immobilisation</dt>
|
||||
<dd class="money strong">{{"%f"|math:$info_immo.amount|money_currency_html:false|raw}}</dd>
|
||||
{{if $total_credits > 0}}
|
||||
<dt>Montant des avoirs</dt>
|
||||
<dd class="money">{{"%f"|math:$total_credits|money_currency_html:false|raw}}</dd>
|
||||
<dt>Écritures d'avoir</dt>
|
||||
<dd>
|
||||
{{#foreach from=$linked_immos item="id"}}
|
||||
{{:assign url="%s/acc/transactions/details.php?id=%s"|args:$admin_url:$id}}
|
||||
<span class="num"><a href="{{$url}}">#{{$id}}</a></span>
|
||||
{{/foreach}}
|
||||
{{*:debug linked_immos=$linked_immos*}}
|
||||
</dd>
|
||||
<dt>Montant à amortir</dt>
|
||||
<dd class="money strong">{{"%f"|math:$solde|money_currency_html:false|raw}}</dd>
|
||||
{{/if}}
|
||||
<dt>Date d'acquisition</dt>
|
||||
<dd>{{$info_immo.date_achat|date_short}}</dd>
|
||||
{{if $info_immo.date_mes != null && $info_immo.date_mes != $info_immo.date_achat}}
|
||||
<dt>Date de mise en service</dt>
|
||||
<dd>{{$info_immo.date_mes|date_short}}</dd>
|
||||
{{/if}}
|
||||
<dt>Durée d'amortissement</dt>
|
||||
<dd>{{$info_immo.duration}} ans</dd>
|
||||
<dt>Montant des amortissements</dt>
|
||||
<dd>{{$total_amort|money_currency_html:false|raw}}</dd>
|
||||
</dl>
|
||||
</div>
|
||||
36
link.schema.json
Normal file
36
link.schema.json
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
{
|
||||
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
||||
"description": "Schéma des liens entre documents",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"type": {
|
||||
"type": "string",
|
||||
"enum": ["amort_link", "immo_link"]
|
||||
},
|
||||
"immo_doc_id" : {
|
||||
"description": "identifiant du document d'immobilisation associé",
|
||||
"type" : "integer",
|
||||
"exclusiveMinimum": 0
|
||||
},
|
||||
"amort_line_id" : {
|
||||
"description": "numéro de ligne d'amortissement associée à l'immobilisation",
|
||||
"type": "integer",
|
||||
"exclusiveMinimum": 0
|
||||
},
|
||||
"credit_line_id": {
|
||||
"description": "numéro de ligne au crédit du compte de l'immobilisation",
|
||||
"type": "integer",
|
||||
"exclusiveMinimum": 0
|
||||
},
|
||||
"amount": {
|
||||
"description": "montant de la ligne d'amortissement ou de crédit",
|
||||
"type": ["number", "null"]
|
||||
}
|
||||
},
|
||||
"required": ["type", "immo_doc_id"],
|
||||
"if": {"properties": {"type": {"const": "amort_link"}}, "required": ["type"]},
|
||||
"then": {"required": ["amort_line_id"]},
|
||||
"else":
|
||||
"if": {"properties": {"type": {"const": "immo_link"}}, "required": ["type"]},
|
||||
"then": {"required": ["credit_line_id"]},
|
||||
}
|
||||
142
link_immo.html
Normal file
142
link_immo.html
Normal file
|
|
@ -0,0 +1,142 @@
|
|||
{{* -*- brindille -*- *}}
|
||||
|
||||
{{*
|
||||
Lister les écritures au crédit du compte de l'immobilisation
|
||||
paramètre et proposer de les attacher à l'immo paramètre
|
||||
@param immo_doc_id : document associé à l'immo
|
||||
*}}
|
||||
|
||||
{{#load id=$_GET.immo_doc_id|intval assign="info_immo"}}
|
||||
{{else}}
|
||||
{{:error message="Informations de l'immobilisation non trouvées"}}
|
||||
{{/load}}
|
||||
|
||||
{{* récupérer les infos de l'immobilisation *}}
|
||||
{{#select
|
||||
trans.id as immo_trans_id,
|
||||
trans.label as label,
|
||||
trans.date as date_achat,
|
||||
line.id as immo_line_id,
|
||||
line.label as line_label,
|
||||
line.debit as montant,
|
||||
account.code as account_code
|
||||
FROM acc_transactions_lines AS line
|
||||
INNER JOIN acc_transactions AS trans ON line.id_transaction = trans.id
|
||||
INNER JOIN acc_accounts AS account ON line.id_account = account.id
|
||||
WHERE line.id = :line_id;
|
||||
:line_id = $info_immo.line
|
||||
assign="ligne_immo"
|
||||
}}
|
||||
{{else}}
|
||||
{{:error message="Immobilisation « %s » non trouvée"|args:$info_immo.line}}
|
||||
{{/select}}
|
||||
{{:assign trans_url="%s/acc/transactions/details.php?id=%s"|args:$admin_url:$ligne_immo.immo_trans_id}}
|
||||
{{:assign label_immo=$ligne_immo.label}}
|
||||
{{if $ligne_immo.line_label != null && $ligne_immo.line_label != $label_immo}}
|
||||
{{:assign label_immo=$label_immo|cat:" — "|cat:$ligne_immo.line_label}}
|
||||
{{/if}}
|
||||
|
||||
{{*
|
||||
lister les écritures au crédit du compte de l'immobilisation
|
||||
variante : utiliser une jointure ; pas forcément plus efficace
|
||||
*}}
|
||||
{{#select
|
||||
line.id as credit_line_id,
|
||||
line.id_transaction as credit_trans_id,
|
||||
line.credit as credit_amount,
|
||||
line.label as line_label,
|
||||
trans.id as immo_trans_id,
|
||||
trans.date as trans_date,
|
||||
trans.label as trans_label,
|
||||
trans.id_year as credit_year,
|
||||
account.id as account_id,
|
||||
account.code as account_code,
|
||||
account.label as account_label
|
||||
FROM acc_transactions_lines AS line
|
||||
INNER JOIN acc_transactions AS trans ON trans.id = line.id_transaction
|
||||
INNER JOIN acc_accounts AS account ON account.id = line.id_account
|
||||
INNER JOIN acc_years AS y ON y.id = trans.id_year
|
||||
WHERE account.code = :account_code AND credit > 0
|
||||
AND credit_trans_id NOT IN (
|
||||
SELECT
|
||||
CASE WHEN id_transaction = credit_trans_id THEN id_transaction
|
||||
ELSE id_related
|
||||
END AS other_id
|
||||
FROM acc_transactions_links WHERE other_id = credit_trans_id)
|
||||
ORDER BY trans.date, trans.label;
|
||||
:account_code = $ligne_immo.account_code
|
||||
assign="other_immos."
|
||||
}}
|
||||
{{/select}}
|
||||
|
||||
{{:admin_header title="Écritures au crédit du compte d'immobilisation" custom_css="./style.css" current="module_amortization"}}
|
||||
|
||||
{{* barre de navigation *}}
|
||||
{{if ! $dialog}}
|
||||
{{:include
|
||||
file="_nav.html"
|
||||
current="config"
|
||||
subcurrent="other"
|
||||
subsubcurrent="immo"
|
||||
type_immo="other"
|
||||
}}
|
||||
{{/if}}
|
||||
|
||||
<section class="immobilisation">
|
||||
<fieldset>
|
||||
<legend>
|
||||
Écritures au crédit du compte d'immobilisation « {{$ligne_immo.account_code}} »
|
||||
</legend>
|
||||
|
||||
<div class="informations">
|
||||
<dl class="describe">
|
||||
<dt>Immobilisation</dt>
|
||||
<dd><span class="num"><a href="{{$trans_url}}">#{{$ligne_immo.immo_trans_id}}</a></span> {{$label_immo}}</dd>
|
||||
<dt>Montant</dt>
|
||||
<dd class="money strong">{{"%f"|math:$ligne_immo.montant|money_currency_html:false|raw}}</dd>
|
||||
<dt>Date de l'écriture d'immobilisation</dt>
|
||||
<dd>{{$ligne_immo.date_achat|date_short}}</dd>
|
||||
</dl>
|
||||
</div>
|
||||
</fieldset>
|
||||
|
||||
{{if $other_immos != null}}
|
||||
<table class="list">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>N°</th>
|
||||
<th>Date</th>
|
||||
<th class="nombre">Montant</th>
|
||||
<th>Libellé</th>
|
||||
<th>N° compte</th>
|
||||
<th>Compte</th>
|
||||
<th class="actions"></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{{#foreach from=$other_immos item="line"}}
|
||||
{{:assign trans_url="%s/acc/transactions/details.php?id=%s"|args:$admin_url:$line.credit_trans_id}}
|
||||
{{:assign compte_url="%s/acc/accounts/journal.php?id=%s&year=%s"|args:$admin_url:$line.account_id:$line.credit_year}}
|
||||
<tr>
|
||||
<td class="num"><a href="{{$trans_url}}">#{{$line.credit_trans_id}}</a></td>
|
||||
<td>{{$line.trans_date|date_short}}</td>
|
||||
<td class="money">{{"%f"|math:$line.credit_amount|money_html:false|raw}}</td>
|
||||
<td>{{$line.trans_label}}
|
||||
{{if $line.line_label != null && $line.line_label != $line.trans_label}} - {{$line.line_label}}{{/if}}
|
||||
</td>
|
||||
<td><a href="{{$compte_url}}">{{$line.account_code}}</a></td>
|
||||
<td>{{$line.account_label}}</td>
|
||||
<td>
|
||||
{{:linkbutton label="Attacher" href="attach_immo.html?credit_line_id=%d&immo_doc_id=%s"|args:$line.credit_line_id:$_GET.immo_doc_id shape="plus"}}
|
||||
</td>
|
||||
</tr>
|
||||
{{/foreach}}
|
||||
</tbody>
|
||||
</table>
|
||||
<p class="help">Sélectionner une écriture d'avoir ou autre réduction du montant de l'acquisition pour l'associer à l'immobilisation</p>
|
||||
{{else}}
|
||||
<p class="block alert">Aucune écriture au crédit du compte « {{$ligne_immo.account_code}} »</p>
|
||||
{{/if}}
|
||||
</section>
|
||||
{{:form_errors}}
|
||||
{{:admin_footer}}
|
||||
|
|
@ -4,6 +4,7 @@
|
|||
Lister les écritures d'amortissement indépendantes
|
||||
et proposer des les attacher à l'immo sélectionnée
|
||||
@param immo_line_id = id de la ligne d'immo
|
||||
@param immo_doc_id id du doc d'immo associé
|
||||
*}}
|
||||
|
||||
{{* récupérer les infos de l'immobilisation *}}
|
||||
|
|
@ -17,11 +18,19 @@
|
|||
assign=ligne_immo
|
||||
}}
|
||||
{{else}}
|
||||
{{:error message="Immobilisation %s non trouvée"|args:$_GET.immo_line_id}}
|
||||
{{:error message="Immobilisation non trouvée"}}
|
||||
{{/select}}
|
||||
|
||||
{{:include file="_get_config.html" keep="module.config"}}
|
||||
{{#load id=$_GET.immo_doc_id|intval}}
|
||||
{{:assign label_immo=$label|or:$ligne_immo.label}}
|
||||
{{else}}
|
||||
{{:error message="Informations de l'immobilisation %s (%s) non trouvées"|args:$_GET.immo_line_id:$ligne_immo.label}}
|
||||
{{/load}}
|
||||
{{if $ligne_immo.line_label != null && $ligne_immo.line_label != $label_immo}}
|
||||
{{:assign label_immo=$label_immo|cat:" — "|cat:$ligne_immo.line_label}}
|
||||
{{/if}}
|
||||
|
||||
{{:include file="_get_config.html" keep="module.config"}}
|
||||
{{if $_POST.unhide == null}}
|
||||
{{:assign filter_condition=" NOT ("}}
|
||||
{{#foreach from=$module.config.filters item="filter"}}
|
||||
|
|
@ -54,46 +63,26 @@
|
|||
!filter_condition=$filter_condition
|
||||
assign="amort"
|
||||
}}
|
||||
|
||||
{{* voir s'il existe des écritures liées avec un numéro de compte d'immobilisation *}}
|
||||
{{#select
|
||||
links.id_transaction,
|
||||
links.id_related,
|
||||
trans.id AS trans_id
|
||||
FROM acc_transactions_links AS links
|
||||
INNER JOIN acc_transactions AS trans ON (
|
||||
CASE
|
||||
WHEN links.id_transaction = :id_amort THEN links.id_related
|
||||
WHEN links.id_related = :id_amort THEN links.id_transaction
|
||||
END) = trans.id
|
||||
INNER JOIN acc_transactions_lines AS line ON line.id_transaction = trans.id
|
||||
INNER JOIN acc_accounts AS acc ON line.id_account = acc.id
|
||||
WHERE
|
||||
links.id_transaction = :id_amort OR links.id_related = :id_amort
|
||||
AND acc.code LIKE '21%'
|
||||
LIMIT 1
|
||||
;
|
||||
:id_amort=$amort.amort_trans_id
|
||||
{{* voir s'il existe des lignes d'immo liées à cette ligne d'amortissement *}}
|
||||
{{:assign amort_amount=0}}
|
||||
{{:assign keep_amort=true}}
|
||||
{{#load type="amort_link"
|
||||
where="$$.amort_line_id = :amort_line_id"
|
||||
:amort_line_id=$amort.amort_line_id|intval
|
||||
assign="amort_link"
|
||||
}}
|
||||
{{* voir s'il existe un doc associé à une ligne de l'amortissement *}}
|
||||
{{:assign keep=true}}
|
||||
{{#load type="link"
|
||||
where="$$.amort_trans_id = :amort_trans_id"
|
||||
:amort_trans_id = $amort.amort_trans_id
|
||||
}}
|
||||
{{if $amort_line_id == $amort.amort_line_id}}
|
||||
{{:assign keep=false}}
|
||||
{{:break}}
|
||||
{{/if}}
|
||||
{{if $amort_link.amount == null || $amort_link.amount == 0}}
|
||||
{{:assign amort_amount=$amort.amort_amount}}
|
||||
{{:assign keep_amort=false}}
|
||||
{{else}}
|
||||
{{:assign keep=false}}
|
||||
{{/load}}
|
||||
{{if $keep}}
|
||||
{{:assign var="autres_amortissements." value=$amort}}
|
||||
{{:assign amort_amount="%d+%d"|math:$amort_amount:$amort_link.amount}}
|
||||
{{/if}}
|
||||
{{else}}
|
||||
{{:assign var="autres_amortissements." value=$amort}}
|
||||
{{/select}}
|
||||
{{* pas de ligne d'immo liée à cette ligne d'amort => garder cette ligne d'amortissement *}}
|
||||
{{/load}}
|
||||
{{if $keep_amort && $amort_amount < $amort.amort_amount}}
|
||||
{{:assign var="free_amort_lines." value=$amort}}
|
||||
{{/if}}
|
||||
{{/select}}
|
||||
|
||||
{{:admin_header title="Amortissements non rattachés" custom_css="./style.css" current="module_amortization"}}
|
||||
|
|
@ -106,7 +95,7 @@
|
|||
subcurrent="other"
|
||||
subsubcurrent="amortization"
|
||||
type_immo="other"
|
||||
autres_amort=$autres_amortissements
|
||||
autres_amort=$free_amort_lines
|
||||
}}
|
||||
{{/if}}
|
||||
|
||||
|
|
@ -116,13 +105,13 @@
|
|||
|
||||
<form method="post" action="">
|
||||
<fieldset>
|
||||
{{:input type="checkbox" value=1 name="unhide" checked="%s"|args:$checked label="Afficher toutes les écritures" }}
|
||||
{{:input type="checkbox" value=1 name="unhide" checked="%s"|args:$checked label="Afficher les écritures ignorées"}}
|
||||
</fieldset>
|
||||
</form>
|
||||
|
||||
{{if $autres_amortissements != null}}
|
||||
{{if $free_amort_lines != null}}
|
||||
<section class="amortissement">
|
||||
<h3 class="ruler">Immobilisation « {{$ligne_immo.label}}{{if $ligne_immo.line_label != null && $ligne_immo.line_label != $ligne_immo.label}} — {{$ligne_immo.line_label}}{{/if}} »</h3>
|
||||
<h3 class="ruler">Immobilisation « {{$label_immo}} »</h3>
|
||||
<table class="list">
|
||||
<thead>
|
||||
<tr>
|
||||
|
|
@ -136,7 +125,7 @@
|
|||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{{#foreach from=$autres_amortissements item="line"}}
|
||||
{{#foreach from=$free_amort_lines item="line"}}
|
||||
{{:assign trans_url="%s/acc/transactions/details.php?id=%s"|args:$admin_url:$line.amort_trans_id}}
|
||||
{{:assign compte_url="%s/acc/accounts/journal.php?id=%s&year=%s"|args:$admin_url:$line.account_id:$line.amort_year}}
|
||||
<tr>
|
||||
|
|
@ -149,7 +138,11 @@
|
|||
<td><a href="{{$compte_url}}">{{$line.account_code}}</a></td>
|
||||
<td>{{$line.account_label}}</td>
|
||||
<td>
|
||||
{{:linkbutton label="Attacher" href="attach_amort.html?amort_line_id=%d&immo_line_id=%d"|args:$line.amort_line_id:$_GET.immo_line_id shape="plus"}}
|
||||
{{if $_GET.init == null}}
|
||||
{{:linkbutton label="Attacher" href="attach_amort.html?amort_line_id=%d&immo_line_id=%d&immo_doc_id=%s"|args:$line.amort_line_id:$_GET.immo_line_id:$_GET.immo_doc_id shape="plus"}}
|
||||
{{elseif $_GET.init}}
|
||||
{{:linkbutton label="Attacher" href="attach_amort_init.html?amort_line_id=%d&immo_line_id=%d&immo_doc_id=%s"|args:$line.amort_line_id:$_GET.immo_line_id:$_GET.immo_doc_id shape="plus"}}
|
||||
{{/if}}
|
||||
</td>
|
||||
</tr>
|
||||
{{/foreach}}
|
||||
|
|
|
|||
154
save_amort.html
154
save_amort.html
|
|
@ -3,6 +3,7 @@
|
|||
{{*
|
||||
Créer une écriture d'amortissement
|
||||
@param immo_line_id : id de la ligne d'immobilisation
|
||||
@param immo_doc_id : id du doc associé à l'immo
|
||||
*}}
|
||||
|
||||
{{* Infos de l'immobilisation *}}
|
||||
|
|
@ -11,7 +12,7 @@
|
|||
line.debit as montant,
|
||||
line.id_project as project_id,
|
||||
line.label as line_label,
|
||||
trans.id as trans_id,
|
||||
trans.id as immo_trans_id,
|
||||
trans.label,
|
||||
trans.date,
|
||||
account.code as account_code
|
||||
|
|
@ -21,106 +22,90 @@
|
|||
LEFT JOIN acc_projects AS project ON line.id_project = project.id
|
||||
WHERE line.id = :line_id;
|
||||
:line_id = $_GET.immo_line_id|intval
|
||||
assign=ligne_immo
|
||||
assign="ligne_immo"
|
||||
}}
|
||||
{{else}}
|
||||
{{:error message="Immobilisation %s non trouvée"|args:$_GET.immo_line_id}}
|
||||
{{:error message="Immobilisation non trouvée"}}
|
||||
{{/select}}
|
||||
{{:assign date_debut=$ligne_immo.date}}
|
||||
{{:assign var="amort_label" value="Amortissement %s"|args:$ligne_immo.label}}
|
||||
{{if $ligne_immo.line_label != null && $ligne_immo.line_label != $ligne_immo.label}}
|
||||
|
||||
{{#load id=$_GET.immo_doc_id|intval}}
|
||||
{{:assign duree=$duration}}
|
||||
{{if $date_mes != null}}
|
||||
{{:assign date_debut=$date_mes}}
|
||||
{{/if}}
|
||||
{{:assign status=$status}}
|
||||
{{:assign amort_label=$label|or:$ligne_immo.label}}
|
||||
{{if $amount != null}}
|
||||
{{:assign var="ligne_immo.montant" value=$amount}}
|
||||
{{/if}}
|
||||
{{else}}
|
||||
{{:error message="Informations de l'immobilisation « %s » non trouvées ; vous devez d'abord les renseigner"|args:$ligne_immo.label}}
|
||||
{{/load}}
|
||||
{{if $ligne_immo.line_label != null && $ligne_immo.line_label != $amort_label}}
|
||||
{{:assign amort_label=$amort_label|cat:" — "|cat:$ligne_immo.line_label}}
|
||||
{{/if}}
|
||||
|
||||
{{#load type="immo" where="$$.line = :line_id" :line_id=$_GET.immo_line_id|intval}}
|
||||
{{:assign duree=$duration}}
|
||||
{{:assign date_debut=$date}}
|
||||
{{:assign status=$status}}
|
||||
{{else}}
|
||||
{{:error message="Vous devez renseigner la date de mise en service et la durée d'immobilisation"}}
|
||||
{{/load}}
|
||||
{{:assign var="amort_label" value="Amortissement %s"|args:$amort_label}}
|
||||
|
||||
{{if $status == "amortized" || $status == "archived"}}
|
||||
{{:error message="Cette immobilisation est complètement amortie ; il est impossible d'ajouter une écriture d'amortissement"}}
|
||||
{{/if}}
|
||||
|
||||
{{* chercher des écritures liées à l'immo courante au crédit du même compte
|
||||
{{*
|
||||
chercher des écritures liées à l'immo courante au crédit du même compte
|
||||
et déduire leur montant de celui de l'immo
|
||||
*}}
|
||||
{{:assign total_credits=0}}
|
||||
{{#select
|
||||
CASE links.id_related = :immo_trans_id
|
||||
WHEN true THEN links.id_transaction
|
||||
WHEN false THEN links.id_related
|
||||
END as other_id,
|
||||
line.credit
|
||||
FROM acc_transactions AS trans
|
||||
INNER JOIN acc_transactions_links as links
|
||||
ON (trans.id = links.id_transaction OR trans.id = links.id_related)
|
||||
INNER JOIN acc_transactions_lines AS line on line.id_transaction = other_id
|
||||
INNER JOIN acc_accounts AS acc ON line.id_account = acc.id
|
||||
WHERE trans.id = :immo_trans_id AND line.credit > 0 AND acc.code = :account;
|
||||
:immo_trans_id=$ligne_immo.trans_id
|
||||
:account=$ligne_immo.account_code
|
||||
{{#load
|
||||
type="immo_link"
|
||||
where="$$.immo_doc_id = :immo_doc_id" :immo_doc_id = $_GET.immo_doc_id|intval
|
||||
}}
|
||||
{{:assign total_credits="%d+%d"|math:$total_credits:$credit}}
|
||||
{{/select}}
|
||||
{{if $amount == null}}
|
||||
{{#select credit FROM acc_transactions_lines WHERE id = :credit_line_id;
|
||||
:credit_line_id=$credit_line_id
|
||||
}}
|
||||
{{:assign total_credits="%d+%d"|math:$total_credits:$credit}}
|
||||
{{/select}}
|
||||
{{else}}
|
||||
{{:assign total_credits="%d+%d"|math:$total_credits:$amount}}
|
||||
{{/if}}
|
||||
{{/load}}
|
||||
{{:assign var="ligne_immo.montant" value="%d-%d"|math:$ligne_immo.montant:$total_credits}}
|
||||
{{:assign solde=$ligne_immo.montant}}
|
||||
|
||||
{{* chercher des écritures d'amortissement liées à l'immobilisation *}}
|
||||
{{#select
|
||||
l_amort.credit as amort_amount,
|
||||
l_amort.label as amort_label,
|
||||
l_amort.id as amort_line_id,
|
||||
CASE WHEN links.id_related = t_immo.id
|
||||
THEN links.id_transaction
|
||||
ELSE links.id_related
|
||||
END as amort_trans_id,
|
||||
trans.date as amort_date,
|
||||
trans.label as trans_label,
|
||||
trans.id_year as amort_year,
|
||||
account.id as account_id,
|
||||
account.code as account_code,
|
||||
account.label as account_label
|
||||
FROM acc_transactions_lines as l_immo
|
||||
INNER JOIN acc_transactions as t_immo on t_immo.id = l_immo.id_transaction
|
||||
INNER JOIN acc_transactions_links as links
|
||||
ON (t_immo.id = links.id_transaction OR t_immo.id = links.id_related)
|
||||
INNER JOIN acc_transactions_lines as l_amort on amort_trans_id = l_amort.id_transaction
|
||||
INNER join acc_transactions as trans on l_amort.id_transaction = trans.id
|
||||
INNER join acc_accounts as account on l_amort.id_account = account.id
|
||||
WHERE
|
||||
l_immo.id = :line_id
|
||||
AND account.code LIKE '28%'
|
||||
ORDER BY trans.date;
|
||||
:line_id = $_GET.immo_line_id|intval
|
||||
assign="amort_line"
|
||||
}}
|
||||
{{#load type="link"
|
||||
where="$$.immo_line_id = :immo_line_id AND $$.amort_trans_id = :amort_trans_id"
|
||||
order="$$.date"
|
||||
assign="line"
|
||||
:immo_line_id=$_GET.immo_line_id|intval :amort_trans_id=$amort_line.amort_trans_id
|
||||
{{* chercher des écritures d'amortissement liées à la ligne d'immobilisation *}}
|
||||
{{#load
|
||||
type="amort_link"
|
||||
where="$$.immo_doc_id = :immo_doc_id"
|
||||
order="$$.date"
|
||||
:immo_doc_id=$_GET.immo_doc_id|intval
|
||||
}}
|
||||
{{if $line.amort_line_id == $amort_line.amort_line_id}}
|
||||
{{:assign var="linked_amort." value=$amort_line}}
|
||||
{{/if}}
|
||||
{{else}}
|
||||
{{:assign var="linked_amort." value=$amort_line}}
|
||||
{{/load}}
|
||||
{{/select}}
|
||||
|
||||
{{#select
|
||||
line.credit,
|
||||
trans.date as amort_date,
|
||||
account.code as account_code,
|
||||
account.label as account_label
|
||||
FROM acc_transactions_lines AS line
|
||||
INNER JOIN acc_transactions AS trans ON line.id_transaction = trans.id
|
||||
INNER join acc_accounts AS account on line.id_account = account.id
|
||||
WHERE line.id = :amort_line_id
|
||||
;
|
||||
:amort_line_id = $amort_line_id
|
||||
assign="amort_line"
|
||||
}}
|
||||
{{:assign var="amort_line.amort_amount" value=$amount|or:$credit}}
|
||||
{{:assign var="linked_amort.%s_%d"|args:$amort_date:$id value=$amort_line}}
|
||||
{{/select}}
|
||||
{{/load}}
|
||||
|
||||
{{:assign total_amort=0}}
|
||||
{{:assign valeur_residuelle=$ligne_immo.montant}}
|
||||
{{#foreach from=$linked_amort}}
|
||||
{{:assign valeur_residuelle="%d-%d"|math:$valeur_residuelle:$amort_amount}}
|
||||
{{:assign total_amort="%d+%d"|math:$total_amort:$amort_amount}}
|
||||
{{:assign date_debut=$amort_date}}
|
||||
{{:assign code_amort=$account_code}}
|
||||
{{:assign amort_account_label=$account_label}}
|
||||
{{:assign amort_label=$amort_label}}
|
||||
{{#foreach from=$linked_amort|ksort item="line"}}
|
||||
{{:assign valeur_residuelle="%d-%d"|math:$valeur_residuelle:$line.amort_amount}}
|
||||
{{:assign total_amort="%d+%d"|math:$total_amort:$line.amort_amount}}
|
||||
{{:assign date_debut=$line.amort_date}}
|
||||
{{:assign code_amort=$line.account_code}}
|
||||
{{:assign amort_account_label=$line.account_label}}
|
||||
{{/foreach}}
|
||||
|
||||
{{if $valeur_residuelle == 0}}
|
||||
|
|
@ -221,7 +206,7 @@
|
|||
}}
|
||||
{{if $account_ok == null}}
|
||||
{{:assign compte=$credit_account|implode:""}}
|
||||
{{:redirect url="add_account.html?account=%s&chart=%s&immo_line_id=%s"|args:$compte:$selected_chart:$_GET.immo_line_id}}
|
||||
{{:redirect url="add_account.html?account=%s&chart=%s"|args:$compte:$selected_chart}}
|
||||
{{/if}}
|
||||
|
||||
{{* vérifier que le montant ne dépasse pas le solde restant *}}
|
||||
|
|
@ -256,7 +241,7 @@
|
|||
date=$_POST.date_amort
|
||||
label=$_POST.designation
|
||||
lines=$lines
|
||||
linked_transactions=$ligne_immo.trans_id|intval
|
||||
linked_transactions=$ligne_immo.immo_trans_id|intval
|
||||
}}
|
||||
|
||||
{{* enregistrer la liaison des lignes *}}
|
||||
|
|
@ -275,14 +260,13 @@
|
|||
{{if $amort_trans_id != null}}
|
||||
{{:save
|
||||
key=""|uuid
|
||||
type="link"
|
||||
immo_line_id=$_GET.immo_line_id|intval
|
||||
type="amort_link"
|
||||
immo_doc_id=$_GET.immo_doc_id|intval
|
||||
amort_line_id=$amort_line_id|intval
|
||||
amort_trans_id=$result.id
|
||||
}}
|
||||
{{/if}}
|
||||
|
||||
{{:redirect force="amortization.html?immo_line_id=%s&ok=1&msg=amortissement"|args:$_GET.immo_line_id}}
|
||||
{{:redirect force="amortization.html?immo_line_id=%s&immo_doc_id=%s&ok=1&msg=amortissement"|args:$_GET.immo_line_id:$_GET.immo_doc_id}}
|
||||
{{/form}}
|
||||
|
||||
{{:admin_header title="Ajout amortissement" custom_css="./style.css" current="module_amortization"}}
|
||||
|
|
|
|||
13
schema.json
13
schema.json
|
|
@ -14,11 +14,20 @@
|
|||
"description": "durée de l'amortissement en années",
|
||||
"type": "integer"
|
||||
},
|
||||
"label" : {
|
||||
"description" : "libellé de l'immobilisation si besoin",
|
||||
"type" : ["string", "null"]
|
||||
},
|
||||
"amount" : {
|
||||
"description": "montant de l'immobilisation si besoin",
|
||||
"type": ["integer", "null"]
|
||||
},
|
||||
"date" : {
|
||||
"date_achat" : {
|
||||
"description" : "date d'achat de l'immobilisation si besoin",
|
||||
"type" : ["string", "null"],
|
||||
"format" : "date"
|
||||
},
|
||||
"date_mes" : {
|
||||
"description" : "date de mise en service de l'immobilisation",
|
||||
"type" : ["string", "null"],
|
||||
"format" : "date"
|
||||
|
|
@ -28,5 +37,5 @@
|
|||
"enum" : ["managed", "amortized", "archived", "ignored"]
|
||||
}
|
||||
},
|
||||
"required": ["type", "line", "duration", "date"]
|
||||
"required": ["type", "line", "duration", "status"]
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,14 +14,13 @@ function toggleInputs(idcb, idfields) {
|
|||
|
||||
function toggleVisibility(idcheck, fields) {
|
||||
const elem = document.getElementById(idcheck);
|
||||
for (let id of fields) {
|
||||
const field = document.getElementById(id);
|
||||
fields.forEach(function (field) {
|
||||
if (elem.checked) {
|
||||
field.setAttribute('class', '');
|
||||
field.classList.remove('hidden');
|
||||
} else {
|
||||
field.setAttribute('class', 'hidden');
|
||||
field.classList.add('hidden');
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// fixer l'exercice des sélecteurs de compte
|
||||
|
|
|
|||
20
style.css
20
style.css
|
|
@ -35,17 +35,15 @@ h2[class="aide"], h3[class="aide"] {
|
|||
}
|
||||
|
||||
.informations dl.describe {
|
||||
grid-template-columns : 20rem 1fr;
|
||||
grid-template-columns : 25rem 1fr;
|
||||
}
|
||||
|
||||
.informations dl.describe > dt {
|
||||
flex: 0 0 15rem;
|
||||
margin-right: 0;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.informations dl.describe > dd {
|
||||
flex: 0 0 calc(100% - 20rem);
|
||||
margin-right: 0;
|
||||
}
|
||||
|
||||
|
|
@ -76,7 +74,23 @@ table.list tbody tr.ignored:nth-child(even) {
|
|||
font-style: italic;
|
||||
background: rgba(255, 255, 200, 0.5);
|
||||
}
|
||||
html.dark table.list tbody tr.ignored:nth-child(odd) {
|
||||
font-style: italic;
|
||||
background: rgba(100, 100, 0, 0.4);
|
||||
}
|
||||
html.dark table.list tbody tr.ignored:nth-child(even) {
|
||||
font-style: italic;
|
||||
background: rgba(100, 100, 0, 0.4);
|
||||
}
|
||||
|
||||
html.dialog.dark {
|
||||
filter: none !important;
|
||||
}
|
||||
|
||||
html.dialog.dark main {
|
||||
background-color : #ddd;
|
||||
}
|
||||
|
||||
html.dark .block.alert {
|
||||
background-color : rgba(87, 206, 235, 0.5);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
{{*
|
||||
Enregistrer les écritures de sortie du bilan
|
||||
paramètres :
|
||||
- immo_line_id : numéro de ligne de l'écriture d'immobilisation
|
||||
- immo_line_id : numéro de ligne de l'écriture d'immobilisation
|
||||
- amort_amount : montant des amortissements
|
||||
- year : exercice de la date de sortie de l'immobilisation
|
||||
- date_mes : date de mise en service de l'immobilisation
|
||||
|
|
@ -30,9 +30,6 @@
|
|||
}}
|
||||
{{/select}}
|
||||
|
||||
{{#load type="immo" assign="info_immo" where="$$.line = :line_id" :line_id=$_GET.immo_line_id|intval}}
|
||||
{{/load}}
|
||||
|
||||
{{* chercher des écritures liées à l'immo courante au crédit du même compte
|
||||
et déduire leur montant de celui de l'immo
|
||||
*}}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue