Merge branch 'classification_initiale'
This commit is contained in:
commit
a99bcc1753
42 changed files with 3215 additions and 1513 deletions
|
|
@ -5,7 +5,6 @@
|
|||
Cette page liste les immobilisations sorties du bilan
|
||||
</p>
|
||||
|
||||
{{* Immobilisation avec une écriture de sortie de bilan *}}
|
||||
{{:include file="_get_config.html" keep="module.config"}}
|
||||
|
||||
{{* lister les immobilisations *}}
|
||||
|
|
@ -35,7 +34,6 @@
|
|||
<th class="nombre">Montant</th>
|
||||
<th>N° compte</th>
|
||||
<th>Compte</th>
|
||||
<th>Projet</th>
|
||||
<th class="actions"></th>
|
||||
</tr>
|
||||
</thead>
|
||||
|
|
@ -55,58 +53,61 @@
|
|||
line.debit AS debit,
|
||||
account.id as account_id,
|
||||
account.code as account_code,
|
||||
account.label as account_label,
|
||||
project.label as project_label
|
||||
account.label as account_label
|
||||
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 acc_projects AS project ON line.id_project = project.id
|
||||
WHERE !condition
|
||||
ORDER BY trans.date DESC;
|
||||
!condition=$condition
|
||||
}}
|
||||
{{:assign montant_immo=$debit}}
|
||||
|
||||
{{* voir si l'immo est prise en charge *}}
|
||||
{{#load type="immo" where="$$.line = :line_id" :line_id=$immo_line_id|intval}}
|
||||
{{#load type="immo" where="$$.line = :line_id" :line_id=$immo_line_id assign="info_immo"}}
|
||||
{{:assign status=$status}}
|
||||
{{else}}
|
||||
{{:assign amortissable="nsp"}}
|
||||
{{:assign status="unknown"}}
|
||||
{{:assign status=null}}
|
||||
{{/load}}
|
||||
{{if $status == "ignored"}}
|
||||
{{if $status != "archived"}}
|
||||
{{:continue}}
|
||||
{{/if}}
|
||||
{{:assign date_mes=$info_immo.date_mes|or:$trans_date}}
|
||||
{{:assign montant_immo=$debit}}
|
||||
|
||||
{{* 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 solde_immo=$montant_immo}}
|
||||
{{* chercher le doc de sortie du bilan *}}
|
||||
{{:assign exit_date=null}}
|
||||
{{#load type="exit_link" where="$$.immo_doc_id = :immo_doc_id" :immo_doc_id=$info_immo.id}}
|
||||
{{:assign exit_line_id=$exit_line_id}}
|
||||
{{#select
|
||||
trans.date
|
||||
FROM acc_transactions_lines AS line
|
||||
INNER JOIN acc_transactions AS trans ON line.id_transaction = trans.id
|
||||
WHERE line.id = :exit_line_id;
|
||||
:exit_line_id=$exit_line_id
|
||||
}}
|
||||
{{:assign exit_date=$date}}
|
||||
{{/select}}
|
||||
{{/load}}
|
||||
|
||||
{{* déduire le montant des écritures liées à l'immo courante au crédit du même compte *}}
|
||||
{{:assign credit_immo=null}}
|
||||
{{#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,
|
||||
MAX(trans2.date) as exit_date
|
||||
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
|
||||
INNER JOIN acc_transactions AS trans2 ON trans2.id = other_id
|
||||
WHERE trans.id = :immo_trans_id AND line.credit > 0 AND acc.code = :account
|
||||
ORDER BY trans2.date, trans2.id
|
||||
;
|
||||
:immo_trans_id=$trans_id
|
||||
:account=$account_code
|
||||
assign="credit_immo."
|
||||
{{:assign total_credits=0}}
|
||||
{{#load
|
||||
type="credit_link"
|
||||
where="$$.immo_doc_id = :immo_doc_id" :immo_doc_id = $info_immo.id
|
||||
}}
|
||||
{{:assign solde_immo="%d-%d"|math:$solde_immo:$credit}}
|
||||
{{:assign exit_date=$exit_date}}
|
||||
{{/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 solde_immo="%d-%d"|math:$montant_immo:$total_credits}}
|
||||
|
||||
{{if $solde_immo == 0}}
|
||||
{{:assign status="archived"}}
|
||||
|
|
@ -116,11 +117,6 @@
|
|||
{{:continue}}
|
||||
{{/if}}
|
||||
|
||||
{{:assign nb=$credit_immo|count}}
|
||||
{{:assign nb="%d-1"|math:$nb}}
|
||||
{{:assign var="last_credit" from="credit_immo.%d"|args:$nb}}
|
||||
{{:assign montant_immo=$last_credit.credit}}
|
||||
|
||||
{{:assign trans_url="%s/acc/transactions/details.php?id=%s"|args:$admin_url:$trans_id}}
|
||||
{{:assign compte_url="%s/acc/accounts/journal.php?id=%s&year=%s"|args:$admin_url:$account_id:$trans_id_year}}
|
||||
{{:assign nb_immo="%d+1"|math:$nb_immo}}
|
||||
|
|
@ -150,14 +146,14 @@
|
|||
|
||||
<tr>
|
||||
<td class="num"><a href="{{$trans_url}}">#{{$trans_id}}</a></td>
|
||||
<td>{{$trans_date|date_short}}</td>
|
||||
<td>{{$date_mes|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>{{$account_label}}</td>
|
||||
<td>{{$project_label}}</td>
|
||||
<td class="actions">
|
||||
{{:linkbutton label="Modifier" href="exit_step4.html?immo_doc_id=%s"|args:$info_immo.id shape="edit"}}
|
||||
</td>
|
||||
</tr>
|
||||
{{/select}}
|
||||
|
|
@ -176,7 +172,6 @@
|
|||
<td class="money">{{$value|money_html:false|raw}}</td>
|
||||
<td></td>
|
||||
<td></td>
|
||||
<td></td>
|
||||
<td class="actions"></td>
|
||||
</tr>
|
||||
{{/foreach}}
|
||||
|
|
@ -188,7 +183,6 @@
|
|||
<td class="money strong">{{$total_immo|money_html:false|raw}}</td>
|
||||
<td></td>
|
||||
<td></td>
|
||||
<td></td>
|
||||
<td class="actions"></td>
|
||||
</tr>
|
||||
{{/if}}
|
||||
|
|
@ -205,7 +199,6 @@
|
|||
<td class="money">{{$value|money_html:false|raw}}</td>
|
||||
<td></td>
|
||||
<td></td>
|
||||
<td></td>
|
||||
<td class="actions"></td>
|
||||
</tr>
|
||||
{{/foreach}}
|
||||
|
|
@ -217,7 +210,6 @@
|
|||
<td class="money strong">{{$total_cessions|money_html:false|raw}}</td>
|
||||
<td></td>
|
||||
<td></td>
|
||||
<td></td>
|
||||
<td class="actions"></td>
|
||||
</tr>
|
||||
{{/if}}
|
||||
|
|
|
|||
37
_common_attach.html
Normal file
37
_common_attach.html
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
{{* -*- brindille -*- *}}
|
||||
|
||||
{{*
|
||||
Enregistrer l'association entre une ligne d'immo et une autre ligne (amort, credit, cession, sortie)
|
||||
@param immo_doc_id : id du doc associé à la ligne d'immobilisation
|
||||
@param trans_id : id de l'écriture à attacher
|
||||
*}}
|
||||
{{* données de l'immobilisation *}}
|
||||
{{:include file="_get_immo_data.html" immo_doc_id=$immo_doc_id|intval keep="ligne_immo, message"}}
|
||||
{{if $message != null}}
|
||||
{{:error message=$message}}
|
||||
{{/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.trans_id
|
||||
}}
|
||||
{{:assign var="linked_transactions." value=$linked_id}}
|
||||
{{/select}}
|
||||
|
||||
{{* ajouter la nouvelle liaison *}}
|
||||
{{:assign var="linked_transactions." value=$trans_id}}
|
||||
{{* Enregistrer les liaisons *}}
|
||||
{{:api
|
||||
method="POST"
|
||||
path="accounting/transaction/%s/transactions"|args:$ligne_immo.trans_id
|
||||
assign="result"
|
||||
assign_code="result_code"
|
||||
transactions=$linked_transactions
|
||||
}}
|
||||
|
||||
51
_common_detach.html
Normal file
51
_common_detach.html
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
{{* -*- brindille -*- *}}
|
||||
|
||||
{{*
|
||||
Supprimer l'association entre deux lignes
|
||||
@param immo_doc_id : id du doc associé à la ligne d'immobilisation
|
||||
@param line_id : id de la ligne à détacher
|
||||
*}}
|
||||
{{* données de l'immobilisation *}}
|
||||
{{:include file="_get_immo_data.html" immo_doc_id=$immo_doc_id|intval keep="ligne_immo, message"}}
|
||||
{{if $message != null}}
|
||||
{{:error message=$message}}
|
||||
{{/if}}
|
||||
|
||||
{{* chercher la deuxième écriture *}}
|
||||
{{#select
|
||||
id_transaction
|
||||
FROM acc_transactions_lines
|
||||
WHERE id = :line_id;
|
||||
:line_id = $line_id|intval
|
||||
}}
|
||||
{{:assign trans_id=$id_transaction}}
|
||||
{{else}}
|
||||
{{:error message="Écriture non trouvée"}}
|
||||
{{/select}}
|
||||
|
||||
{{*
|
||||
chercher les liaisons de l'écriture d'immobilisation
|
||||
et supprimer la liaison avec la deuxième écriture
|
||||
*}}
|
||||
{{#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.trans_id
|
||||
}}
|
||||
{{if $linked_id != $trans_id}}
|
||||
{{:assign var="linked_transactions." value=$linked_id}}
|
||||
{{/if}}
|
||||
{{/select}}
|
||||
|
||||
{{* Enregistrer les liaisons *}}
|
||||
{{:api
|
||||
method="POST"
|
||||
path="accounting/transaction/%s/transactions"|args:$ligne_immo.trans_id
|
||||
assign="result"
|
||||
assign_code="result_code"
|
||||
transactions=$linked_transactions
|
||||
}}
|
||||
44
_get_amort_lines.html
Normal file
44
_get_amort_lines.html
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
{{* -*- brindille -*- *}}
|
||||
|
||||
{{*
|
||||
lister les lignes d'amortissement liées à la ligne d'immobilisation
|
||||
@param immo_doc_id : id du doc associé à l'immobilisation
|
||||
@result linked_amort : lignes d'amortissement liées à la ligne d'immobilisation
|
||||
@result total_amort : montant total des amortissements de l'immobilisation
|
||||
@result created_amort : vrai s'il y a au moins un amortissement créé par le module dans la liste
|
||||
*}}
|
||||
|
||||
{{:assign total_amort=0}}
|
||||
{{#load type="amort_link"
|
||||
where="$$.immo_doc_id = :immo_doc_id"
|
||||
:immo_doc_id = $immo_doc_id|intval
|
||||
assign="amort_info"
|
||||
}}
|
||||
{{#select
|
||||
line.id as line_id,
|
||||
line.credit as amount,
|
||||
line.label as line_label,
|
||||
trans.id as trans_id,
|
||||
trans.label as trans_label,
|
||||
trans.date as date,
|
||||
trans.id_year as 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.amount" value=$amort_info.amount|or:$amort_line.amount}}
|
||||
{{if $amort_info.created}}
|
||||
{{:assign var="amort_line.created" value=true}}
|
||||
{{:assign var="created_amort" value=true}}
|
||||
{{/if}}
|
||||
{{:assign var="linked_amort.%s_%d"|args:$amort_line.date:$amort_info.id value=$amort_line}}
|
||||
{{:assign total_amort="%d+%d"|math:$total_amort:$amort_line.amount}}
|
||||
{{/select}}
|
||||
{{/load}}
|
||||
36
_get_credit_lines.html
Normal file
36
_get_credit_lines.html
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
{{* -*- brindille -*- *}}
|
||||
|
||||
{{*
|
||||
chercher des écritures liées à l'immo paramètre au crédit du même compte
|
||||
@param immo_doc_id : id du doc associé à l'immobilisation
|
||||
@result linked_immos : liste des écritures liées
|
||||
@result total_credits : montant total des écritures
|
||||
*}}
|
||||
{{:assign linked_immos=null}}
|
||||
{{:assign total_credits=0}}
|
||||
{{#load type="credit_link" where="$$.immo_doc_id=:immo_doc_id" :immo_doc_id=$immo_doc_id|intval}}
|
||||
{{#select
|
||||
line.credit,
|
||||
line.id as line_id,
|
||||
trans.id as trans_id,
|
||||
trans.label,
|
||||
trans.date,
|
||||
trans.id_year as 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 = :credit_line_id;
|
||||
:credit_line_id=$credit_line_id
|
||||
}}
|
||||
{{:assign credit=$credit}}
|
||||
{{:assign var="linked_immos." doc=$id trans_id=$trans_id credit_line_id=$line_id label=$label amount=$credit date=$date account_id=$account_id account_code=$account_code account_label=$account_label year=$year}}
|
||||
{{/select}}
|
||||
{{if $amount == null}}
|
||||
{{:assign total_credits="%d+%d"|math:$total_credits:$credit}}
|
||||
{{else}}
|
||||
{{:assign total_credits="%d+%d"|math:$total_credits:$amount}}
|
||||
{{/if}}
|
||||
{{/load}}
|
||||
47
_get_free_amort.html
Normal file
47
_get_free_amort.html
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
{{* -*- brindille -*- *}}
|
||||
|
||||
{{*
|
||||
lister les amortissement non rattachés à une immo
|
||||
@param filter_condition
|
||||
*}}
|
||||
{{#select
|
||||
line.id as line_id,
|
||||
line.id_transaction as trans_id,
|
||||
line.credit as amount,
|
||||
line.label as line_label,
|
||||
trans.date as trans_date,
|
||||
trans.label as trans_label,
|
||||
trans.id_year as 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_accounts AS account ON account.id = line.id_account
|
||||
INNER JOIN acc_transactions AS trans ON trans.id = line.id_transaction
|
||||
WHERE credit > 0 AND (NOT trans.status & 16) AND !filter_condition
|
||||
ORDER BY trans.date, trans.label;
|
||||
!filter_condition=$filter_condition
|
||||
assign="amort_line"
|
||||
}}
|
||||
{{* 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_line.line_id|intval
|
||||
assign="amort_link"
|
||||
}}
|
||||
{{if $amort_link.amount == null || $amort_link.amount == 0}}
|
||||
{{:assign amort_amount=$amort_line.amount}}
|
||||
{{:assign keep_amort=false}}
|
||||
{{else}}
|
||||
{{:assign amort_amount="%d+%d"|math:$amort_amount:$amort_link.amount}}
|
||||
{{/if}}
|
||||
{{else}}
|
||||
{{* pas de ligne d'immo liée à cette ligne d'amort => garder cette ligne d'amortissement *}}
|
||||
{{/load}}
|
||||
{{if $keep_amort && $amort_amount < $amort_line.amount}}
|
||||
{{:assign var="amort_line.amount" value="%d-%d"|math:$amort_line.amount:$amort_amount}}
|
||||
{{:assign var="free_amort_lines." value=$amort_line}}
|
||||
{{/if}}
|
||||
{{/select}}
|
||||
39
_get_immo_data.html
Normal file
39
_get_immo_data.html
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
{{* -*- brindille -*- *}}
|
||||
|
||||
{{*
|
||||
Récupérer les infos d'une immobilisation
|
||||
@param immo_doc_id : id du document associé à l'immobilisation
|
||||
@result info_immo : infos du document associé
|
||||
@result ligne_immo : données de la base
|
||||
@result message non null si une erreur s'est produite
|
||||
*}}
|
||||
|
||||
{{#load id=$immo_doc_id|intval assign="info_immo"}}
|
||||
{{else}}
|
||||
{{:assign error=true}}
|
||||
{{:assign message="Immobilisation non trouvée"}}
|
||||
{{/load}}
|
||||
|
||||
{{if ! $error}}
|
||||
{{#select
|
||||
line.id as line_id,
|
||||
line.debit as amount,
|
||||
line.label as line_label,
|
||||
line.id_project as id_project,
|
||||
trans.id as trans_id,
|
||||
trans.label as trans_label,
|
||||
trans.date as date_achat,
|
||||
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 = :line_id;
|
||||
:line_id = $info_immo.line
|
||||
assign="ligne_immo"
|
||||
}}
|
||||
{{else}}
|
||||
{{:assign message="Immobilisation non trouvée"}}
|
||||
{{/select}}
|
||||
{{/if}}
|
||||
|
|
@ -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,19 +29,6 @@
|
|||
</thead>
|
||||
<tbody>
|
||||
|
||||
{{* vérifier l'existence de la table du module *}}
|
||||
{{if $module.table != null}}
|
||||
{{: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' AND $$.status <> 'archived')"}}
|
||||
{{:assign doc_condition2="$$.status IS NULL"}}
|
||||
{{else}}
|
||||
{{:assign columns=""}}
|
||||
{{:assign table_join=""}}
|
||||
{{:assign doc_condition1="0"}}
|
||||
{{:assign doc_condition2="1"}}
|
||||
{{/if}}
|
||||
|
||||
{{* lister les immobilisations *}}
|
||||
{{:assign account_condition="("}}
|
||||
{{#foreach from=$module.config.prefixes item="code"}}
|
||||
|
|
@ -49,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="("|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 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}}
|
||||
|
|
@ -72,127 +50,64 @@
|
|||
line.label AS line_label,
|
||||
account.id as account_id,
|
||||
account.code as account_code,
|
||||
!columns
|
||||
trans.id_year as trans_id_year
|
||||
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
|
||||
!table_join
|
||||
INNER JOIN !table AS info ON $$.line = line.id
|
||||
WHERE !condition
|
||||
ORDER BY trans.date DESC;
|
||||
!columns=$columns
|
||||
!table_join=$table_join
|
||||
ORDER BY COALESCE(doc_date_achat, trans_date) DESC;
|
||||
!table=$module.table
|
||||
!condition=$condition
|
||||
}}
|
||||
{{if $status != "managed" && $status != "amortized"}}
|
||||
{{:continue}}
|
||||
{{/if}}
|
||||
{{: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
|
||||
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}}
|
||||
{{* déduire le montant des écritures liées à l'immo courante au crédit du même compte *}}
|
||||
{{#load
|
||||
type="credit_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 *}}
|
||||
{{if $montant_immo == 0}}
|
||||
{{* Immobilisation soldée *}}
|
||||
{{:continue}}
|
||||
{{/if}}
|
||||
|
||||
{{* lister les lignes des écritures d'amortissement liées à l'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}}
|
||||
|
||||
{{#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}}
|
||||
{{* montant des amortissements liés à l'immobilisation *}}
|
||||
{{:include file="./_get_amort_lines.html" immo_doc_id=$immo_doc_id keep="total_amort"}}
|
||||
{{:assign amort_amount=$total_amort}}
|
||||
|
||||
{{* 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}}
|
||||
|
|
@ -200,26 +115,17 @@
|
|||
{{: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"}}
|
||||
{{:linkbutton
|
||||
label="Paramètres"
|
||||
href="add_infos.html?immo_line_id=%s&type_immo=%s"|args:$immo_line_id:$type_immo
|
||||
shape="settings"
|
||||
}}
|
||||
{{* target="_dialog"*}}
|
||||
{{/if}}
|
||||
{{:linkbutton
|
||||
label="Amortissements"
|
||||
href="amortization.html?immo_line_id=%s&type_immo=%s"|args:$immo_line_id:$type_immo
|
||||
shape="table"
|
||||
label="Détails"
|
||||
href="amortization.html?immo_doc_id=%s&type_immo=%s"|args:$immo_doc_id:$type_immo shape="eye"
|
||||
}}
|
||||
</td>
|
||||
</tr>
|
||||
|
|
@ -256,9 +162,8 @@
|
|||
</tr>
|
||||
{{/if}}
|
||||
</tfoot>
|
||||
{{*/if*}}
|
||||
</table>
|
||||
{{if $nb_immo == 0}}
|
||||
<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,186 @@
|
|||
{{* -*- 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}}
|
||||
|
||||
<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 $trans_label|strpos:$filter !== 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"|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') {
|
||||
|
|
|
|||
28
_nav.html
28
_nav.html
|
|
@ -1,17 +1,35 @@
|
|||
{{* -*- brindille -*- *}}
|
||||
|
||||
<nav class="tabs">
|
||||
{{if $current == "index" && $subsubcurrent == null}}
|
||||
{{if $current == "index" && $subcurrent != "unfinished" && $subsubcurrent == null}}
|
||||
<aside>
|
||||
{{:linkbutton label="Ajouter une immobilisation" shape="plus" href="add_asset.html"}}
|
||||
</aside>
|
||||
{{elseif $current == "index" && $subcurrent == "details"}}
|
||||
<aside>
|
||||
{{if $subsubcurrent|match:"credit"}}
|
||||
{{:linkbutton label="Rattacher une écriture d'immobilisation" href="link_immo.html?immo_doc_id=%s"|args:$_GET.immo_doc_id shape="link" target="_dialog"}}
|
||||
{{/if}}
|
||||
{{if $subsubcurrent|match:"modif"}}
|
||||
{{:linkbutton label="Modifier" href="modify_infos.html?immo_doc_id=%s"|args:$_GET.immo_doc_id shape="edit" target="_dialog"}}
|
||||
{{/if}}
|
||||
</aside>
|
||||
{{elseif $subsubcurrent == "amortization" && $type_immo == null || $type_immo == "managed" || $type_immo == "other"}}
|
||||
<aside>
|
||||
{{if $autres_amort}}
|
||||
{{:linkbutton label="Rattacher une écriture" href="other_amortizations.html?immo_line_id=%s"|args:$_GET.immo_line_id shape="link" target="_dialog"}}
|
||||
{{:linkbutton
|
||||
label="Rattacher un amortissement"
|
||||
title="Rattacher un amortissement existant"
|
||||
href="other_amortizations.html?immo_doc_id=%s"|args:$_GET.immo_doc_id
|
||||
shape="link"
|
||||
target="_dialog"}}
|
||||
{{/if}}
|
||||
{{:linkbutton label="Enregistrer un amortissement" shape="plus"
|
||||
href="save_amort.html?immo_line_id=%s"|args:$_GET.immo_line_id}}
|
||||
{{:linkbutton
|
||||
label="Enregistrer un amortissement"
|
||||
title="Enregistrer un nouvel amortissement"
|
||||
href="save_amort.html?immo_doc_id=%s"|args:$_GET.immo_doc_id target="_dialog"
|
||||
shape="plus"
|
||||
}}
|
||||
</aside>
|
||||
{{/if}}
|
||||
|
||||
|
|
@ -20,7 +38,7 @@
|
|||
<li {{if $subcurrent == "amortized"}}class="current"{{/if}}><a href="index.html?type_immo=amortized">Amorties</a></li>
|
||||
<li {{if $subcurrent == "archived"}}class="current"{{/if}}><a href="index.html?type_immo=archived">Sorties du bilan</a></li>
|
||||
<li {{if $subcurrent == "unfinished"}}class="current"{{/if}}><a href="index.html?type_immo=unfinished">En cours</a></li>
|
||||
<li {{if $subcurrent == "other"}}class="current"{{/if}}><a href="index.html?type_immo=other">Autres</a></li>
|
||||
<li {{if $subcurrent == "other"}}class="current"{{/if}}><a href="index.html?type_immo=other">À classer</a></li>
|
||||
<li {{if $current == "config"}} class="current"{{/if}}><a href="config.html">Configuration</a></li>
|
||||
</ul>
|
||||
|
||||
|
|
|
|||
45
_remove_orphan_docs.tpl
Normal file
45
_remove_orphan_docs.tpl
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
{{* -*- brindille -*- *}}
|
||||
|
||||
{{if $module.table}}
|
||||
{{* supprimer les documents sans écriture associée *}}
|
||||
{{:assign var="docs." type="amort_link" field="amort_line_id"}}
|
||||
{{:assign var="docs." type="credit_link" field="credit_line_id"}}
|
||||
{{:assign var="docs." type="cession_link" field="cession_line_id"}}
|
||||
{{:assign var="docs." type="exit_link" field="exit_line_id"}}
|
||||
{{:assign var="docs." type="immo" field="line"}}
|
||||
|
||||
{{#foreach from=$docs}}
|
||||
|
||||
{{:assign join_field="$$."|cat:$field}}
|
||||
{{:assign type_name=$type|quote_sql}}
|
||||
{{:assign type_cond="$$.type"|cat:" = "|cat:$type_name}}
|
||||
|
||||
{{* vérifier existence écriture associée au doc *}}
|
||||
{{#select
|
||||
info.id as info_id,
|
||||
$$.immo_doc_id as immo_doc_id,
|
||||
line.id as line_id
|
||||
FROM !table AS info
|
||||
LEFT JOIN acc_transactions_lines as line ON !join_field = line.id
|
||||
WHERE !type_cond
|
||||
;
|
||||
!table=$module.table
|
||||
!type_cond = $type_cond
|
||||
!join_field = $join_field
|
||||
assign="line"
|
||||
}}
|
||||
{{if $line.line_id == null}}
|
||||
{{:delete id=$line.info_id}}
|
||||
{{/if}}
|
||||
|
||||
{{* vérifier existence doc immo *}}
|
||||
{{if $type != "immo"}}
|
||||
{{#load id=$immo_doc_id assign="immo_doc"}}
|
||||
{{else}}
|
||||
{{:delete id=$line.info_id}}
|
||||
{{/load}}
|
||||
{{/if}}
|
||||
{{/select}}
|
||||
|
||||
{{/foreach}}
|
||||
{{/if}}
|
||||
|
|
@ -126,7 +126,13 @@
|
|||
{{:continue}}
|
||||
{{/if}}
|
||||
|
||||
{{* voir s'il existe une écriture qui solde l'immobilisation *}}
|
||||
{{*
|
||||
TODO cas où :
|
||||
- il y a (au moins) une écriture d'avoir
|
||||
- il y a une écriture qui solde l'immo (montant = montant immo - avoir
|
||||
*}}
|
||||
|
||||
{{* voir s'il existe une écriture qui solde l'immobilisation (voir ci-dessus) *}}
|
||||
{{#select
|
||||
count(*) AS count
|
||||
FROM acc_transactions AS trans
|
||||
|
|
|
|||
|
|
@ -75,7 +75,7 @@
|
|||
|
||||
{{if $account_ok == null}}
|
||||
{{:assign compte=$debit_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}}
|
||||
|
||||
{{:assign debit_account=$debit_account|keys|value:0}}
|
||||
|
|
@ -93,12 +93,7 @@
|
|||
{{/if}}
|
||||
{{/foreach}}
|
||||
|
||||
{{if $status != "unfinished" && ! $_POST.amortir}}
|
||||
{{* ne pas amortir *}}
|
||||
{{:assign duration=0}}
|
||||
{{:assign date_debut=$_POST.date_achat|parse_date}}
|
||||
{{:assign status="ignored"}}
|
||||
{{elseif $status != "unfinished"}}
|
||||
{{if $status != "unfinished"}}
|
||||
{{* vérifier que la date d'acquisition est antérieure à la date de mise en service *}}
|
||||
{{:assign date_debut=$_POST.date_mes|or:$_POST.date_achat|parse_date}}
|
||||
{{if $date_debut|strtotime < $_POST.date_achat|parse_date|strtotime}}
|
||||
|
|
@ -108,6 +103,11 @@
|
|||
{{/if}}
|
||||
{{:assign duration=$_POST.duree|intval}}
|
||||
{{:assign status="managed"}}
|
||||
{{if $_POST.date_mes == null || $_POST.date_mes == $_POST.date_achat}}
|
||||
{{:assign date_mes=null}}
|
||||
{{else}}
|
||||
{{:assign date_mes=$_POST.date_mes|parse_date}}
|
||||
{{/if}}
|
||||
{{/if}}
|
||||
|
||||
{{* enregistrer l'écriture *}}
|
||||
|
|
@ -137,18 +137,19 @@
|
|||
{{* enregistrer les infos de l'immobilisation *}}
|
||||
{{:save
|
||||
key=$key
|
||||
validate_schema="schema.json"
|
||||
validate_schema="asset.schema.json"
|
||||
type="immo"
|
||||
line=$immo_line_id
|
||||
duration=$duration
|
||||
date=$date_debut
|
||||
date_mes=$date_mes
|
||||
status=$status
|
||||
created=true
|
||||
}}
|
||||
{{/if}}
|
||||
|
||||
{{if $status == "unfinished"}}
|
||||
{{:assign type_immo="unfinished"}}
|
||||
{{elseif $_POST.amortir}}
|
||||
{{elseif $status == "managed"}}
|
||||
{{:assign type_immo="managed"}}
|
||||
{{else}}
|
||||
{{:assign type_immo="other"}}
|
||||
|
|
@ -201,7 +202,7 @@
|
|||
name="credit_account"
|
||||
label="Compte de décaissement"
|
||||
required=true
|
||||
target="!acc/charts/accounts/selector.php?types=%s&id_year=%d"|args:"1|2|3":$selected_year
|
||||
target="!acc/charts/accounts/selector.php?codes=%s&id_year=%d"|args:"512*|530*|404*":$selected_year
|
||||
}}
|
||||
{{:input
|
||||
type="list"
|
||||
|
|
@ -221,7 +222,6 @@
|
|||
<fieldset>
|
||||
<legend>Amortissement</legend>
|
||||
<dl>
|
||||
{{: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 id="div_amort">
|
||||
{{:input type="number" name="duree" label="Durée d'amortissement" required=true min=0 default=1 suffix="année(s)"}}
|
||||
{{:input type="date" name="date_mes" label="Date de mise en service" help="C'est la date de première utilisation ; à renseigner uniquement si différente de la date d'acquisition"}}
|
||||
|
|
@ -243,12 +243,7 @@ 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 () {
|
||||
document.getElementById('f_id_year').onchange = changeYear;
|
||||
document.getElementById('f_amortir_1').onclick = changeVisibility;
|
||||
})();
|
||||
</script>
|
||||
|
|
|
|||
333
add_infos.html
333
add_infos.html
|
|
@ -1,159 +1,15 @@
|
|||
{{* -*- brindille -*- *}}
|
||||
|
||||
{{*
|
||||
Classer une immobilisation non prise en charge
|
||||
@param immo_line_id
|
||||
@param type_immo : managed, amortized, archived, other
|
||||
*}}
|
||||
|
||||
{{* données de l'immobilisaion *}}
|
||||
{{#load type="immo" assign="info_immo" where="$$.line = :line_id" :line_id=$_GET.immo_line_id|intval}}
|
||||
{{* 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.date as date_achat,
|
||||
line.debit as montant,
|
||||
line.label as line_label,
|
||||
acc.code
|
||||
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
|
||||
}}
|
||||
{{else}}
|
||||
{{:error message="Aucune immobilisation trouvée"}}
|
||||
{{/select}}
|
||||
|
||||
{{* chercher les liaisons de l'écriture d'immobilisation *}}
|
||||
{{: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 linked_id,
|
||||
line.credit,
|
||||
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 total_credits="%d+%d"|math:$total_credits:$credit}}
|
||||
{{:assign var="linked_transactions.%d."|args:$code value=$linked_id}}
|
||||
{{/select}}
|
||||
{{:assign var="immo_transactions" from="linked_transactions.%d"|args:$ligne_immo.code}}
|
||||
|
||||
{{* Traiter l'envoi du formulaire *}}
|
||||
{{#form on="save"}}
|
||||
{{if $_POST.classify == null}}
|
||||
{{:error message="Vous devez choisir une action"}}
|
||||
{{/if}}
|
||||
|
||||
{{if $_POST.classify == "ignored"}}
|
||||
{{* ne pas amortir *}}
|
||||
{{:assign duration=0}}
|
||||
{{:assign date_debut=$ligne_immo.date_achat|parse_date}}
|
||||
{{: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}}
|
||||
{{/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"}}
|
||||
{{/if}}
|
||||
{{/if}}
|
||||
|
||||
{{* enregistrer les infos de l'immobilisation *}}
|
||||
{{if $info_immo == null}}
|
||||
{{: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
|
||||
status=$status
|
||||
}}
|
||||
|
||||
{{* 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"}}
|
||||
{{else}}
|
||||
{{:assign type_immo=$_GET.type_immo}}
|
||||
{{/if}}
|
||||
{{:redirect force="index.html?ok=1&msg=infos&type_immo=%s"|args:$type_immo}}
|
||||
{{/form}}
|
||||
{{:form_errors}}
|
||||
|
||||
{{:admin_header title="Classer l'immobilisation" custom_css="./style.css" current="module_amortization"}}
|
||||
|
||||
{{* barre de navigation *}}
|
||||
{{if ! $dialog}}
|
||||
{{:include file="_nav.html" current="index" subcurrent="%s"|args:$_GET.type_immo subsubcurrent="parameter"}}
|
||||
{{/if}}
|
||||
|
||||
{{:assign choix_defaut=$_GET.type_immo}}
|
||||
|
||||
{{if $info_immo != null}}
|
||||
{{:assign date_defaut=$info_immo.date}}
|
||||
{{:assign duree_defaut=$info_immo.duration}}
|
||||
|
|
@ -162,30 +18,166 @@
|
|||
{{:assign duree_defaut=null}}
|
||||
{{/if}}
|
||||
|
||||
{{#select
|
||||
trans.id as immo_trans_id,
|
||||
trans.label as trans_label,
|
||||
trans.date as date_achat,
|
||||
line.debit as montant,
|
||||
line.label as line_label,
|
||||
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|intval
|
||||
assign="ligne_immo"
|
||||
}}
|
||||
{{else}}
|
||||
{{:error message="Immobilisation non trouvée"}}
|
||||
{{/select}}
|
||||
{{:assign reste="%d-%d"|math:$ligne_immo.montant:$montant_affecte}}
|
||||
|
||||
|
||||
{{#form on="save"}}
|
||||
{{if $_POST.classify == null}}
|
||||
{{:error message="Vous devez faire un choix de classement"}}
|
||||
{{/if}}
|
||||
|
||||
{{if $_POST.classify == "ignored"}}
|
||||
{{* ne pas amortir *}}
|
||||
{{:assign duration=0}}
|
||||
{{:assign libelle=null}}
|
||||
{{:assign montant=null}}
|
||||
{{:assign date_achat=null}}
|
||||
{{:assign date_mes=null}}
|
||||
{{:assign status="ignored"}}
|
||||
{{elseif $_POST.classify == "archived"}}
|
||||
{{* immobilisation sortie du bilan *}}
|
||||
{{:save
|
||||
key=""|uuid
|
||||
validate_schema="asset.schema.json"
|
||||
type="immo"
|
||||
line=$_GET.immo_line_id|intval
|
||||
duration=0
|
||||
status="managed"
|
||||
assign_new_id="immo_doc_id"
|
||||
}}
|
||||
{{:redirect force="exit_step1.html?immo_doc_id=%s"|args:$immo_doc_id}}
|
||||
{{else}}
|
||||
{{* immobilisation amortissable *}}
|
||||
{{if $_POST.date_achat|parse_date > $ligne_immo.date_achat}}
|
||||
{{:assign da=$ligne_immo.date_achat|date_short}}
|
||||
{{:error message="Erreur : la date d'achat (%s) ne peut être postérieure à la date de l'écriture d'immobilisation (%s)"|args:$_POST.date_achat:$da}}
|
||||
{{/if}}
|
||||
|
||||
{{* 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.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}}
|
||||
{{:assign date_mes=null}}
|
||||
{{else}}
|
||||
{{:assign date_mes=$_POST.date_mes|parse_date}}
|
||||
{{/if}}
|
||||
|
||||
{{: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}}
|
||||
|
||||
{{:assign status="managed"}}
|
||||
{{/if}}
|
||||
|
||||
{{* enregistrer les infos de l'immobilisation *}}
|
||||
{{if $info_immo == null || $montant_affecte > 0}}
|
||||
{{:assign key=""|uuid}}
|
||||
{{else}}
|
||||
{{:assign key=$info_immo.key}}
|
||||
{{/if}}
|
||||
{{:save
|
||||
key=$key
|
||||
validate_schema="asset.schema.json"
|
||||
type="immo"
|
||||
line=$_GET.immo_line_id|intval
|
||||
duration=$duration
|
||||
label=$libelle
|
||||
amount=$montant
|
||||
date_achat=$date_achat
|
||||
date_mes=$date_mes
|
||||
status=$status
|
||||
}}
|
||||
|
||||
{{if $_POST.classify == "managed"}}
|
||||
{{:assign type_immo="managed"}}
|
||||
{{else}}
|
||||
{{:assign type_immo="other"}}
|
||||
{{/if}}
|
||||
{{:redirect force="index.html?ok=1&msg=infos&type_immo=%s"|args:$type_immo}}
|
||||
{{/form}}
|
||||
|
||||
{{:admin_header title="Classer l'immobilisation" custom_css="./style.css" current="module_amortization"}}
|
||||
{{* barre de navigation *}}
|
||||
{{if ! $dialog}}
|
||||
{{:include file="_nav.html" current="index" subcurrent="other" subsubcurrent="parameter"}}
|
||||
{{/if}}
|
||||
{{:form_errors}}
|
||||
|
||||
{{*
|
||||
- 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>
|
||||
<dt>Montant de l'immobilisation</dt>
|
||||
<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>
|
||||
{{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">{{"%d-%d"|math:$ligne_immo.montant:$total_credits|money_currency_html:false|raw}}</dd>
|
||||
{{if $montant_affecte > 0}}
|
||||
<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>
|
||||
{{/if}}
|
||||
<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>
|
||||
|
||||
|
|
@ -195,18 +187,19 @@
|
|||
<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">
|
||||
<fieldset class="masquable">
|
||||
<legend>Informations</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 type="number" name="duree" label="Durée d'amortissement" required=true min=1 suffix="année(s)"}}
|
||||
{{:input type="money" name="montant" label="Montant de l'immobilisation" required=true default=$reste help="à modifier si différent du montant de l'écriture d'immobilisation"}}
|
||||
{{: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"}}
|
||||
</dl>
|
||||
</fieldset>
|
||||
|
||||
|
|
@ -218,20 +211,18 @@
|
|||
|
||||
{{: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);
|
||||
g.toggle('.masquable', true);
|
||||
document.getElementById('f_duree').focus();
|
||||
} else {
|
||||
g.toggle('#infos_immo', false);
|
||||
g.toggle('.masquable', false);
|
||||
}
|
||||
}
|
||||
toggleInputs();
|
||||
|
|
|
|||
|
|
@ -2,180 +2,46 @@
|
|||
|
||||
{{*
|
||||
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 *}}
|
||||
{{#select
|
||||
line.id as immo_line_id,
|
||||
line.debit as montant,
|
||||
line.label as line_label,
|
||||
trans.id as immo_trans_id,
|
||||
trans.label as label,
|
||||
trans.date,
|
||||
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 = $_GET.immo_line_id|intval
|
||||
assign=ligne_immo
|
||||
}}
|
||||
{{else}}
|
||||
{{:error message="Immobilisation %s non trouvée"|args:$_GET.immo_line_id}}
|
||||
{{/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}}
|
||||
{{* données de l'immobilisation *}}
|
||||
{{:include file="_get_immo_data.html" immo_doc_id=$_GET.immo_doc_id keep="info_immo, ligne_immo, message"}}
|
||||
{{if $message != null}}
|
||||
{{:error message=$message}}
|
||||
{{/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}}
|
||||
{{/load}}
|
||||
{{:assign trans_url="%s/acc/transactions/details.php?id=%s"|args:$admin_url:$ligne_immo.trans_id}}
|
||||
{{:assign date_debut=$info_immo.date_mes|or:$info_immo.date_achat|or:$ligne_immo.date_achat}}
|
||||
{{:assign label_immo=$info_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}}
|
||||
{{if $info_immo.amount != null}}
|
||||
{{:assign var="ligne_immo.amount" 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
|
||||
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}}
|
||||
{{:assign montant_amortissable="%d-%d"|math:$ligne_immo.montant:$total_credits}}
|
||||
{{:assign solde=$montant_amortissable}}
|
||||
{{* déduire le montant des écritures liées à l'immo courante au crédit du même compte *}}
|
||||
{{:include file="_get_credit_lines.html" immo_doc_id=$_GET.immo_doc_id keep="linked_immos, total_credits"}}
|
||||
{{:assign solde="%d-%d"|math:$ligne_immo.amount:$total_credits}}
|
||||
{{:assign valeur_residuelle=$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}}
|
||||
{{* lister les amortissements liés à l'immobilisation *}}
|
||||
{{:include file="./_get_amort_lines.html" immo_doc_id=$_GET.immo_doc_id keep="linked_amort, total_amort, created_amort"}}
|
||||
{{:assign valeur_residuelle="%d-%d"|math:$valeur_residuelle:$total_amort}}
|
||||
|
||||
{{if $status == "amortized"}}
|
||||
{{:assign amort_amount=$montant_amortissable}}
|
||||
{{:assign valeur_residuelle=0}}
|
||||
{{else}}
|
||||
{{:assign valeur_residuelle=$montant_amortissable}}
|
||||
{{#foreach from=$linked_amort}}
|
||||
{{:assign valeur_residuelle="%d-%d"|math:$valeur_residuelle:$amort_amount}}
|
||||
{{/foreach}}
|
||||
{{if $valeur_residuelle > 0}}
|
||||
{{* lister les amortissements non attachés à une immo *}}
|
||||
{{:assign account_filter="28%"|quote_sql}}
|
||||
{{:assign filter_condition="account.code LIKE "|cat:$account_filter}}
|
||||
{{:include file="./_get_free_amort.html" filter_condition=$filter_condition keep="free_amort_lines"}}
|
||||
{{/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)"}}
|
||||
|
||||
{{: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 *}}
|
||||
{{#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 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}}
|
||||
{{else}}
|
||||
{{:assign keep=false}}
|
||||
{{/load}}
|
||||
{{if $keep}}
|
||||
{{:assign autres_amortissements=true}}
|
||||
{{/if}}
|
||||
{{else}}
|
||||
{{:assign autres_amortissements=true}}
|
||||
{{/select}}
|
||||
{{/select}}
|
||||
|
||||
{{:admin_header title="Liste des amortissements" custom_css="./style.css" current="module_amortization"}}
|
||||
|
||||
{{* barre de navigation *}}
|
||||
|
|
@ -195,21 +61,27 @@
|
|||
subcurrent="%s"|args:$subcurrent
|
||||
subsubcurrent="amortization"
|
||||
type_immo=$_GET.type_immo
|
||||
autres_amort=$autres_amortissements
|
||||
autres_amort=$free_amort_lines
|
||||
}}
|
||||
|
||||
{{if $_GET.ok}}
|
||||
{{if $_GET.msg|match:"attach"}}
|
||||
{{:assign msg="Attachement écriture %s effectué"|args:$_GET.trans_id}}
|
||||
{{elseif $_GET.msg|match:"detach"}}
|
||||
{{:assign msg="Détachement écriture %s affectué"|args:$_GET.trans_id}}
|
||||
{{if $_GET.msg|match:"attach_amort"}}
|
||||
{{:assign msg="Attachement amortissement effectué"}}
|
||||
{{elseif $_GET.msg|match:"detach_amort"}}
|
||||
{{:assign msg="Détachement amortissement affectué"}}
|
||||
{{elseif $_GET.msg|match:"attach_avoir"}}
|
||||
{{:assign msg="Attachement avoir affectué"}}
|
||||
{{elseif $_GET.msg|match:"detach_avoir"}}
|
||||
{{:assign msg="Détachement avoir affectué"}}
|
||||
{{elseif $_GET.msg|match:"amortissement"}}
|
||||
{{:assign msg="Amortissement enregistré"}}
|
||||
{{elseif $_GET.msg|match:"modif"}}
|
||||
{{:assign msg="Modifications enregistrées"}}
|
||||
{{/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,28 +94,47 @@
|
|||
<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_doc_id=%s&type_immo=%s"|args:$_GET.immo_doc_id:$_GET.type_immo
|
||||
shape="export"
|
||||
class="main"
|
||||
}}
|
||||
</p>
|
||||
<p class="help">
|
||||
Il sera possible de choisir la date de sortie, d'indiquer
|
||||
le montant de la cession le cas échéant et de modifier les
|
||||
comptes associés.
|
||||
Il sera possible de choisir la date de sortie et d'indiquer
|
||||
le montant de la cession le cas échéant.
|
||||
</p>
|
||||
</fieldset>
|
||||
</form>
|
||||
|
||||
<h3 class="ruler">Immobilisation</h3>
|
||||
<nav class="actions">
|
||||
{{if $total_amort == 0}}
|
||||
{{:linkbutton label="Modifier les paramètres" href="modify_infos.html?immo_doc_id=%s"|args:$_GET.immo_doc_id shape="edit" target="_dialog"}}
|
||||
{{if ! $info_immo.created}}
|
||||
{{:linkbutton label="Supprimer les paramètres" href="delete_infos.html?immo_doc_id=%s"|args:$_GET.immo_doc_id shape="delete" target="_dialog"}}
|
||||
{{/if}}
|
||||
{{/if}}
|
||||
</nav>
|
||||
|
||||
<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.trans_id}}</a></span> {{$label_immo}}</dd>
|
||||
<dt>Compte d'immobilisation</dt>
|
||||
<dd>{{$ligne_immo.account_code}} — {{$ligne_immo.account_label}}</dd>
|
||||
<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}}
|
||||
<dt>Montant de l'immobilisation</dt>
|
||||
<dd class="money strong">{{"%f"|math:$ligne_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>Montant à amortir</dt>
|
||||
<dd class="money strong">{{"%f"|math:$solde|money_currency_html:false|raw}}</dd>
|
||||
{{/if}}
|
||||
<dt>Montant de l'immobilisation</dt>
|
||||
<dd class="money">{{"%f"|math:$ligne_immo.montant|money_currency_html:false|raw}}</dd>
|
||||
|
|
@ -255,18 +146,70 @@
|
|||
{{/if}}
|
||||
{{if $valeur_residuelle > 0}}
|
||||
<dt>Montant des amortissements</dt>
|
||||
<dd>{{"%d-%d"|math:$montant_amortissable:$valeur_residuelle|money_currency_html:false|raw}}</dd>
|
||||
<dt>Valeur nette comptable</dt>
|
||||
<dd>{{$total_amort|money_currency_html:false|raw}}</dd>
|
||||
<dt>Valeur nette résiduelle</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:$montant_amortissable:$duree|money_currency_html:false|raw}}</dd>
|
||||
<dd>{{"min(%d, %f/%d)"|math:$valeur_residuelle:$solde:$info_immo.duration|money_currency_html:false|raw}}</dd>
|
||||
{{/if}}
|
||||
</dl>
|
||||
</div>
|
||||
|
||||
<h3 class="ruler">Amortissements enregistrés</h3>
|
||||
<h3 class="ruler">Avoirs</h3>
|
||||
<nav class="actions">
|
||||
{{if $total_amort == 0}}
|
||||
{{:linkbutton label="Attacher une écriture d'avoir" href="link_immo.html?immo_doc_id=%s"|args:$_GET.immo_doc_id shape="link" target="_dialog"}}
|
||||
{{/if}}
|
||||
</nav>
|
||||
|
||||
{{if $linked_immos != null}}
|
||||
<table class="list">
|
||||
<thead>
|
||||
<th class="num">N°</th>
|
||||
<th>Date</th>
|
||||
<th>Libellé</th>
|
||||
<th class="nombre">Montant</th>
|
||||
<th class="actions"></th>
|
||||
</thead>
|
||||
<tbody>
|
||||
{{#foreach from=$linked_immos item="line"}}
|
||||
{{:assign url="%s/acc/transactions/details.php?id=%s"|args:$admin_url:$line.trans_id}}
|
||||
<tr>
|
||||
<td class="num"><a href="{{$url}}">#{{$line.trans_id}}</a></td>
|
||||
<td>{{$line.date|date_short}}</td>
|
||||
<td>{{$line.label}}</td>
|
||||
<td class="money">{{"%f"|math:$line.amount|money_currency_html:false|raw}}</td>
|
||||
<td>
|
||||
{{if $total_amort == 0}}
|
||||
{{:linkbutton label="Détacher" href="detach_credit.html?immo_doc_id=%s&credit_line_id=%s"|args:$_GET.immo_doc_id:$line.credit_line_id shape="minus"}}
|
||||
{{/if}}
|
||||
</td>
|
||||
</tr>
|
||||
{{/foreach}}
|
||||
</tbody>
|
||||
</table>
|
||||
{{/if}}
|
||||
|
||||
<h3 class="ruler">Amortissements</h3>
|
||||
<nav class="actions">
|
||||
{{if $free_amort_lines && ! $created_amort}}
|
||||
{{:linkbutton
|
||||
label="Attacher un amortissement"
|
||||
title="Attacher un amortissement existant"
|
||||
href="other_amortizations.html?immo_doc_id=%s&filter=true"|args:$_GET.immo_doc_id
|
||||
shape="link"
|
||||
target="_dialog"}}
|
||||
{{/if}}
|
||||
{{:linkbutton
|
||||
label="Enregistrer un amortissement"
|
||||
title="Enregistrer un nouvel amortissement"
|
||||
href="save_amort.html?immo_doc_id=%s"|args:$_GET.immo_doc_id target="_dialog"
|
||||
shape="plus"
|
||||
}}
|
||||
</nav>
|
||||
|
||||
{{if $linked_amort != null}}
|
||||
<section class="amortissement">
|
||||
<table class="list">
|
||||
|
|
@ -274,55 +217,55 @@
|
|||
<tr>
|
||||
<th class="num">N°</th>
|
||||
<th>Date</th>
|
||||
<th>Libellé</th>
|
||||
<th class="nombre">Montant</th>
|
||||
<th class="nombre">Valeur nette</th>
|
||||
<th>Libellé</th>
|
||||
<th>N° compte</th>
|
||||
<th>Compte</th>
|
||||
<th class="actions"></th>
|
||||
</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}}
|
||||
{{:assign solde="%f-%d"|math:$solde:$line.amort_amount}}
|
||||
{{:assign trans_url="%s/acc/transactions/details.php?id=%s"|args:$admin_url:$line.trans_id}}
|
||||
{{:assign compte_url="%s/acc/accounts/journal.php?id=%s&year=%s"|args:$admin_url:$line.account_id:$line.year}}
|
||||
{{:assign solde="%f-%d"|math:$solde:$line.amount}}
|
||||
<tr>
|
||||
<td class="num"><a href="{{$trans_url}}">#{{$line.amort_trans_id}}</a></td>
|
||||
<td>{{$line.amort_date|date_short}}</td>
|
||||
<td class="money">{{"%f"|math:$line.amort_amount|money_html:false|raw}}</td>
|
||||
<td class="money">{{"%f"|math:$solde|money_html:false|raw}}</td>
|
||||
<td class="num"><a href="{{$trans_url}}">#{{$line.trans_id}}</a></td>
|
||||
<td>{{$line.date|date_short}}</td>
|
||||
<td>
|
||||
{{$line.amort_trans_label}}
|
||||
{{if $line.amort_line_label != null && $line.amort_line_label != $line.amort_trans_label}}
|
||||
— {{$line.amort_line_label}}
|
||||
{{$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.amount|money_html:false|raw}}</td>
|
||||
<td class="money">{{"%f"|math:$solde|money_html:false|raw}}</td>
|
||||
<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"}}
|
||||
{{if ! $created_amort}}
|
||||
{{:linkbutton label="Détacher" href="detach_amort.html?immo_doc_id=%s&amort_line_id=%s"|args:$_GET.immo_doc_id:$line.line_id shape="minus"}}
|
||||
{{/if}}
|
||||
</td>
|
||||
</tr>
|
||||
{{/foreach}}
|
||||
</tbody>
|
||||
</table>
|
||||
</section>
|
||||
{{else}}
|
||||
<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 $free_amort_lines && ! $created_amort}}
|
||||
<p class="block alert">
|
||||
Il y a des écritures d'amortissement qui ne sont pas attachées à une immobilisation ! <br />
|
||||
Utilisez le bouton « Attacher un amortissement » pour les afficher ; vous pourrez choisir d'en attacher certaines à cette immobilisation.
|
||||
</p>
|
||||
{{/if}}
|
||||
|
||||
{{if $linked_amort == null}}
|
||||
<p class="block alert">Aucun amortissement enregistré pour cette immobilisation ; utilisez le bouton « Enregistrer un amortissement » pour enregistrer un nouvel amortissement</p>
|
||||
{{/if}}
|
||||
|
||||
{{:form_errors}}
|
||||
{{:admin_footer}}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
{
|
||||
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
||||
"description": "Donnée d'une immobilisation",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"type": {
|
||||
|
|
@ -14,11 +15,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"
|
||||
|
|
@ -26,7 +36,11 @@
|
|||
"status" : {
|
||||
"type" : ["string", "null"],
|
||||
"enum" : ["managed", "amortized", "archived", "ignored"]
|
||||
},
|
||||
"created" : {
|
||||
"description" : "vrai si immobilisation créée dans le module",
|
||||
"type" : ["boolean", "null"]
|
||||
}
|
||||
},
|
||||
"required": ["type", "line", "duration", "date"]
|
||||
"required": ["type", "line", "duration", "status"]
|
||||
}
|
||||
|
|
@ -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_doc_id : numéro du doc d'immo
|
||||
@param amort_line_id : numéro de ligne de l'écriture d'amortissement
|
||||
*}}
|
||||
|
||||
{{* chercher l'écriture d'immobilisation *}}
|
||||
{{#select
|
||||
id_transaction
|
||||
FROM acc_transactions_lines
|
||||
WHERE id = :line_id;
|
||||
:line_id = $_GET.immo_line_id|intval
|
||||
}}
|
||||
{{: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}}
|
||||
{{/select}}
|
||||
{{* données de l'immobilisation *}}
|
||||
{{:include file="_get_immo_data.html" immo_doc_id=$_GET.immo_doc_id|intval keep="info_immo, ligne_immo, message"}}
|
||||
{{if $message != null}}
|
||||
{{:error message=$message}}
|
||||
{{/if}}
|
||||
|
||||
{{:assign label_immo=$info_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}}
|
||||
{{:assign montant_immo=$info_immo.amount|or:$ligne_immo.amount}}
|
||||
|
||||
{{* 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 amort_label=$amort_line.trans_label}}
|
||||
{{if $amort_line.line_label != null && $amort_line.line_label != $amort_label}}
|
||||
{{:assign amort_label=$amort_label|cat:"— "|cat:$amort_line.line_label}}
|
||||
{{/if}}
|
||||
{{: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"
|
||||
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 || $_POST.montant == 0}}
|
||||
{{:assign montant_amort=$reste}}
|
||||
{{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}}
|
||||
|
||||
{{* déduire le montant des écritures liées à l'immo courante au crédit du même compte *}}
|
||||
{{:include file="_get_credit_lines.html" immo_doc_id=$_GET.immo_doc_id keep="total_credits"}}
|
||||
{{:assign montant_immo="%d-%d"|math:$montant_immo:$total_credits}}
|
||||
|
||||
{{* montant des amortissements *}}
|
||||
{{:include file="./_get_amort_lines.html" immo_doc_id=$_GET.immo_doc_id keep="total_amort"}}
|
||||
|
||||
{{* vérifier que le montant total des amortissements ne dépasse pas la valeur de l'immo *}}
|
||||
{{:assign vnc="%d-%d"|math:$montant_immo:$total_amort}}
|
||||
{{:assign total_amort="%d+%d"|math:$total_amort:$montant_amort}}
|
||||
{{if $total_amort > $montant_immo}}
|
||||
{{:assign ma="%f"|math:$montant_amort|money_currency:false}}
|
||||
{{:assign vnc="%f"|math:$vnc|money_currency:false}}
|
||||
{{:error message="Le montant de l'amortissement (%s) dépasse la valeur résiduelle de l'immobilisation (%s)"|args:$ma:$vnc}}
|
||||
{{/if}}
|
||||
|
||||
{{* Lier l'écriture d'amortissement à l'écriture d'immobilisation *}}
|
||||
{{:include file="_common_attach.html" immo_doc_id=$_GET.immo_doc_id trans_id=$amort_line.trans_id}}
|
||||
|
||||
{{* 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}}
|
||||
|
||||
{{* À VÉRIFIER immo soldée ? *}}
|
||||
{{if $total_amort == $montant_immo}}
|
||||
{{:assign status="amortized"}}
|
||||
{{:save
|
||||
key=$info_immo.key
|
||||
status=$status
|
||||
}}
|
||||
{{/if}}
|
||||
|
||||
{{if $_GET.from == "exit"}}
|
||||
{{:redirect force="exit_step2.html?immo_doc_id=%s&ok=1&msg=attach_amort"|args:$_GET.immo_doc_id}}
|
||||
{{else}}
|
||||
{{:redirect force="amortization.html?immo_doc_id=%s&type_immo=%s&ok=1&msg=attach_amort"|args:$_GET.immo_doc_id:$status}}
|
||||
{{/if}}
|
||||
{{/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> {{$amort_label}}</dd>
|
||||
<dt>Montant de l'écriture d'amortissement</dt>
|
||||
<dd>{{$amort_line.amount|money_currency_html:false|raw}}</dd>
|
||||
{{if $montant_affecte > 0}}
|
||||
<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>
|
||||
{{/if}}
|
||||
</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>
|
||||
|
||||
|
|
|
|||
39
attach_cession.html
Normal file
39
attach_cession.html
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
{{* -*- brindille -*- *}}
|
||||
|
||||
{{*
|
||||
Enregistrer la liaison entre une écriture d'immobilisation et
|
||||
une écriture de cession
|
||||
@param immo_doc_id : id du document associé à l'immobilisation
|
||||
@param cession_line_id : ligne de l'écriture de cession
|
||||
*}}
|
||||
|
||||
{{* données de l'immobilisation *}}
|
||||
{{:include file="_get_immo_data.html" immo_doc_id=$_GET.immo_doc_id keep="info_immo, ligne_immo, message"}}
|
||||
{{if $message != null}}
|
||||
{{:error message=$message}}
|
||||
{{/if}}
|
||||
|
||||
{{* chercher l'écriture de cession de l'immobilisation *}}
|
||||
{{#select
|
||||
id_transaction
|
||||
FROM acc_transactions_lines
|
||||
WHERE id = :line_id;
|
||||
:line_id = $_GET.cession_line_id|intval
|
||||
}}
|
||||
{{:assign cession_id=$id_transaction}}
|
||||
{{else}}
|
||||
{{:error message="Impossible de trouver l'écriture de cession de l'immobilisation"}}
|
||||
{{/select}}
|
||||
|
||||
{{* Lier l'écriture de cession à l'écriture d'immobilisation *}}
|
||||
{{:include file="_common_attach.html" immo_doc_id=$_GET.immo_doc_id trans_id=$cession_id}}
|
||||
|
||||
{{* enregistrer la liaison de l'écriture de cession *}}
|
||||
{{:save
|
||||
key=""|uuid
|
||||
type="cession_link"
|
||||
immo_doc_id=$info_immo.id
|
||||
cession_line_id=$_GET.cession_line_id|intval
|
||||
}}
|
||||
|
||||
{{:redirect force="exit_step3.html?immo_doc_id=%s&ok=1&msg=attach_cession"|args:$_GET.immo_doc_id}}
|
||||
151
attach_credit.html
Normal file
151
attach_credit.html
Normal file
|
|
@ -0,0 +1,151 @@
|
|||
{{* -*- brindille -*- *}}
|
||||
|
||||
{{*
|
||||
Enregistrer la liaison entre une ligne d'immobilisation et
|
||||
une ligne d'écriture au crédit du compte de l'immobilisation
|
||||
@param immo_doc_id : numéro du doc d'immo
|
||||
@param credit_line_id : ligne d'écriture au crédit du compte de l'immobilisation
|
||||
*}}
|
||||
|
||||
{{* données de l'immobilisation *}}
|
||||
{{:include file="_get_immo_data.html" immo_doc_id=$_GET.immo_doc_id|intval keep="info_immo, ligne_immo, message"}}
|
||||
{{if $message != null}}
|
||||
{{:error message=$message}}
|
||||
{{/if}}
|
||||
|
||||
{{:assign label_immo=$info_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}}
|
||||
|
||||
{{* déduire le montant des écritures liées à l'immo courante au crédit du même compte *}}
|
||||
{{:include file="_get_credit_lines.html" immo_doc_id=$_GET.immo_doc_id keep="total_credits"}}
|
||||
{{:assign solde_immo="%d-%d"|math:$ligne_immo.amount:$total_credits}}
|
||||
|
||||
{{* chercher l'écriture au crédit du compte d'immobilisation *}}
|
||||
{{#select
|
||||
line.id_transaction as 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="Écriture au crédit non trouvée"}}
|
||||
{{/select}}
|
||||
{{:assign credit_trans_url="%s/acc/transactions/details.php?id=%s"|args:$admin_url:$credit_line.trans_id}}
|
||||
|
||||
{{* montant de l'écriture de crédit déjà affecté *}}
|
||||
{{:assign montant_affecte=0}}
|
||||
{{#load type="credit_link"
|
||||
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"}}
|
||||
|
||||
{{if $_POST.montant == null}}
|
||||
{{if $montant_affecte == 0}}
|
||||
{{:assign saved_credit=null}}
|
||||
{{:assign montant_credit=$credit_line.amount}}
|
||||
{{else}}
|
||||
{{:assign saved_credit=$reste}}
|
||||
{{:assign montant_credit=$reste}}
|
||||
{{/if}}
|
||||
{{else}}
|
||||
{{:assign montant_credit=$_POST.montant|money_int}}
|
||||
{{* vérifier que le montant saisi est inférieur au solde de l'écriture d'immobilisation *}}
|
||||
{{if $montant_credit > $solde_immo}}
|
||||
{{:assign solde_nb="%f"|math:$solde_immo|money_currency:false}}
|
||||
{{:error message="Le montant de l'avoir ne peut être supérieur au montant de l'immobilisation (%s)"|args:$solde_nb}}
|
||||
{{/if}}
|
||||
{{* vérifier que le montant saisi est inférieur au reste de l'écriture de crédit *}}
|
||||
{{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}}
|
||||
|
||||
{{* Lier l'écriture de crédit à l'écriture d'immobilisation *}}
|
||||
{{:include file="_common_attach.html" immo_doc_id=$_GET.immo_doc_id trans_id=$credit_line.trans_id}}
|
||||
|
||||
{{*
|
||||
TODO ? vérifier le succès avant d'enregistrer le doc ?
|
||||
*}}
|
||||
|
||||
{{* enregistrer la liaison des lignes d'immo *}}
|
||||
{{:save
|
||||
key=""|uuid
|
||||
type="credit_link"
|
||||
immo_doc_id=$_GET.immo_doc_id|intval
|
||||
credit_line_id=$_GET.credit_line_id|intval
|
||||
amount=$saved_credit
|
||||
}}
|
||||
|
||||
{{*
|
||||
{{if $montant_credit == $solde_immo}}
|
||||
{{:save
|
||||
id=$_GET.immo_doc_id
|
||||
status="archived"
|
||||
}}
|
||||
{{/if}}
|
||||
*}}
|
||||
|
||||
{{if $_GET.from == "exit"}}
|
||||
{{:redirect force="exit_step1.html?immo_doc_id=%s&ok=1&msg=attach_avoir"|args:$_GET.immo_doc_id}}
|
||||
{{else}}
|
||||
{{:redirect force="amortization.html?immo_doc_id=%s&ok=1&msg=attach_avoir"|args:$_GET.immo_doc_id}}
|
||||
{{/if}}
|
||||
{{/form}}
|
||||
|
||||
{{:admin_header title="Écritures au crédit du compte d'immobilisation" custom_css="./style.css" current="module_amortization"}}
|
||||
{{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.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>
|
||||
|
||||
39
attach_exit.html
Normal file
39
attach_exit.html
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
{{* -*- brindille -*- *}}
|
||||
|
||||
{{*
|
||||
Enregistrer la liaison entre une écriture d'immobilisation et
|
||||
une écriture de sortie d'immobilisation
|
||||
@param immo_doc_id : id du document associé à l'immobilisation
|
||||
@param exit_line_id : ligne de l'écriture de sortie d'immobilisation
|
||||
*}}
|
||||
|
||||
{{* données de l'immobilisation *}}
|
||||
{{:include file="_get_immo_data.html" immo_doc_id=$_GET.immo_doc_id keep="info_immo, ligne_immo, message"}}
|
||||
{{if $message != null}}
|
||||
{{:error message=$message}}
|
||||
{{/if}}
|
||||
|
||||
{{* chercher l'écriture de sortie d'immobilisation *}}
|
||||
{{#select
|
||||
id_transaction
|
||||
FROM acc_transactions_lines
|
||||
WHERE id = :line_id;
|
||||
:line_id = $_GET.exit_line_id|intval
|
||||
}}
|
||||
{{:assign rebut_id=$id_transaction}}
|
||||
{{else}}
|
||||
{{:error message="Impossible de trouver l'écriture de sortie d'immobilisation"}}
|
||||
{{/select}}
|
||||
|
||||
{{* Lier l'écriture de sortie à l'écriture d'immobilisation *}}
|
||||
{{:include file="_common_attach.html" immo_doc_id=$_GET.immo_doc_id trans_id=$rebut_id}}
|
||||
|
||||
{{* enregistrer la liaison de l'écriture de sortie *}}
|
||||
{{:save
|
||||
key=""|uuid
|
||||
type="exit_link"
|
||||
immo_doc_id=$info_immo.id
|
||||
exit_line_id=$_GET.exit_line_id|intval
|
||||
}}
|
||||
|
||||
{{:redirect to="exit_step4.html?immo_doc_id=%s&ok=1&msg=attach_exit"|args:$_GET.immo_doc_id}}
|
||||
|
|
@ -2,131 +2,60 @@
|
|||
|
||||
{{*
|
||||
Sortir une immobilisation du bilan
|
||||
@param immo_line_id : id de la ligne d'immobilisation
|
||||
@param immo_doc_id : id du doc associé à l'immo
|
||||
*}}
|
||||
|
||||
{{* Infos de l'immobilisation *}}
|
||||
{{#select
|
||||
line.debit as montant,
|
||||
trans.id AS trans_id,
|
||||
trans.date as date_achat,
|
||||
trans.label,
|
||||
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 = $_GET.immo_line_id|intval
|
||||
assign="ligne_immo"
|
||||
}}
|
||||
{{else}}
|
||||
{{:error message="Immobilisation %s non trouvée"|args:$_GET.immo_line_id}}
|
||||
{{/select}}
|
||||
{{* données de l'immobilisation *}}
|
||||
{{:include file="_get_immo_data.html" immo_doc_id=$_GET.immo_doc_id|intval keep="info_immo, ligne_immo, message"}}
|
||||
{{if $message != null}}
|
||||
{{:error message=$message}}
|
||||
{{/if}}
|
||||
|
||||
{{:assign date_debut=$ligne_immo.date_achat}}
|
||||
{{:assign ts_mes=$ligne_immo.date_achat|strtotime}}
|
||||
{{:assign label_immo=$info_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}}
|
||||
|
||||
{{#load type="immo" assign="info_immo" where="$$.line = :line_id" :line_id=$_GET.immo_line_id|intval}}
|
||||
{{:assign ts_mes=$date|strtotime}}
|
||||
{{:assign date_debut=$date}}
|
||||
{{:assign duree_amort=$duration}}
|
||||
{{/load}}
|
||||
{{:assign date_achat=$info_immo.date_achat|or:$ligne_immo.date_achat}}
|
||||
{{if $info_immo.date_mes != null && $info_immo.date_mes != $date_achat}}
|
||||
{{:assign date_mes=$info_immo.date_mes}}
|
||||
{{/if}}
|
||||
{{:assign date_debut=$info_immo.date_mes|or:$info_immo.date_achat|or:$ligne_immo.date_achat}}
|
||||
|
||||
{{* 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
|
||||
}}
|
||||
{{:assign total_credits="%d+%d"|math:$total_credits:$credit}}
|
||||
{{/select}}
|
||||
{{:assign var="ligne_immo.montant" value="%d-%d"|math:$ligne_immo.montant:$total_credits}}
|
||||
{{if $info_immo.amount != null}}
|
||||
{{:assign var="ligne_immo.amount" value=$info_immo.amount}}
|
||||
{{/if}}
|
||||
|
||||
{{* chercher des écritures d'amortissement liées à l'immobilisation *}}
|
||||
{{:assign total_amort=0}}
|
||||
{{:assign amort_number=0}}
|
||||
{{#select
|
||||
l_amort.credit as amort_amount,
|
||||
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
|
||||
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%'
|
||||
;
|
||||
:line_id = $_GET.immo_line_id|intval
|
||||
assign="amort_lines."
|
||||
}}
|
||||
{{/select}}
|
||||
{{* déduire le montant des écritures liées à l'immo courante au crédit du même compte *}}
|
||||
{{:include file="_get_credit_lines.html" immo_doc_id=$_GET.immo_doc_id keep="total_credits"}}
|
||||
{{:assign var="ligne_immo.amount" value="%d-%d"|math:$ligne_immo.amount:$total_credits}}
|
||||
|
||||
{{#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"
|
||||
:immo_line_id=$_GET.immo_line_id|intval :amort_trans_id=$amort_line.amort_trans_id
|
||||
}}
|
||||
{{if $line.amort_line_id == $amort_line.amort_line_id}}
|
||||
{{:assign amort_number="%d+1"|math:$amort_number}}
|
||||
{{:assign total_amort="%d+%d"|math:$total_amort:$amort_line.amort_amount}}
|
||||
{{if $first_amort_date == null}}
|
||||
{{:assign first_amort_date=$amort_line.date}}
|
||||
{{elseif $amort_line.date < $first_amort_date}}
|
||||
{{:assign first_amort_date=$amort_line.date}}
|
||||
{{/if}}
|
||||
{{if $last_amort_date == null}}
|
||||
{{:assign last_amort_date=$amort_line.date}}
|
||||
{{elseif $amort_line.date > $last_amort_date}}
|
||||
{{:assign last_amort_date=$amort_line.date}}
|
||||
{{/if}}
|
||||
{{/if}}
|
||||
{{else}}
|
||||
{{:assign amort_number="%d+1"|math:$amort_number}}
|
||||
{{:assign total_amort="%d+%d"|math:$total_amort:$amort_line.amort_amount}}
|
||||
{{if $first_amort_date == null}}
|
||||
{{:assign first_amort_date=$amort_line.date}}
|
||||
{{elseif $amort_line.date < $first_amort_date}}
|
||||
{{:assign first_amort_date=$amort_line.date}}
|
||||
{{/if}}
|
||||
{{if $last_amort_date == null}}
|
||||
{{:assign last_amort_date=$amort_line.date}}
|
||||
{{elseif $amort_line.date > $last_amort_date}}
|
||||
{{:assign last_amort_date=$amort_line.date}}
|
||||
{{/if}}
|
||||
{{/load}}
|
||||
{{* lister les amortissements liés à l'immobilisation *}}
|
||||
{{:include file="./_get_amort_lines.html" immo_doc_id=$_GET.immo_doc_id keep="linked_amort, total_amort"}}
|
||||
{{:assign amort_number=$linked_amort|count}}
|
||||
|
||||
{{#foreach from=$linked_amort|ksort item="line"}}
|
||||
{{if $first_amort_date == null}}
|
||||
{{:assign first_amort_date=$line.date}}
|
||||
{{/if}}
|
||||
{{if $last_amort_date == null}}
|
||||
{{:assign last_amort_date=$line.date}}
|
||||
{{elseif $line.date > $last_amort_date}}
|
||||
{{:assign last_amort_date=$line.date}}
|
||||
{{/if}}
|
||||
{{/foreach}}
|
||||
|
||||
{{if $total_amort == 0}}
|
||||
{{if $info_immo.status == "amortized"}}
|
||||
{{:assign total_amort=$ligne_immo.montant}}
|
||||
{{:assign total_amort=$ligne_immo.amount}}
|
||||
{{/if}}
|
||||
{{else}}
|
||||
{{:assign date_debut=$last_amort_date|strtotime}}
|
||||
{{:assign date_debut="%d+(60*60*24)"|math:$date_debut|date:"Y-m-d"}}
|
||||
{{:assign date_debut=$last_amort_date}}
|
||||
{{/if}}
|
||||
{{:assign ts_debut=$date_debut|strtotime}}
|
||||
{{:assign valeur_nette="%f-%f"|math:$ligne_immo.montant:$total_amort}}
|
||||
{{:assign ts_debut="%d+(60*60*24)"|math:$ts_debut}}
|
||||
{{:assign date_debut=$ts_debut|date:"Y-m-d"}}
|
||||
{{:assign valeur_nette="%f-%f"|math:$ligne_immo.amount:$total_amort}}
|
||||
|
||||
{{*
|
||||
lister les exercices ouverts dont la date de fin est postérieure à la date du dernier amortissment
|
||||
|
|
@ -141,7 +70,8 @@
|
|||
{{:assign fin=$end_date|date_short}}
|
||||
{{:assign var="open_years.%d"|args:$id value=$label|cat:" (du "|cat:$debut|cat:" au "|cat:$fin|cat:")"}}
|
||||
{{else}}
|
||||
{{:error message="Aucun exercice ouvert pour enregistrer un amortissement"}}
|
||||
{{:assign debut=$date_debut|date_short}}
|
||||
{{:error message="Aucun exercice ouvert pour enregistrer un amortissement à partir du %s"|args:$debut}}
|
||||
{{/years}}
|
||||
{{if $years|count == 1}}
|
||||
{{:assign default_year=$years.0.id}}
|
||||
|
|
@ -156,39 +86,12 @@
|
|||
{{:error message="Vous devez renseigner la date de sortie"}}
|
||||
{{/if}}
|
||||
|
||||
{{* vérifier la validité de la date de mise en service *}}
|
||||
{{if $_POST.date_mes != null}}
|
||||
{{:assign ts_mes=$_POST.date_mes|parse_date|strtotime}}
|
||||
{{if $ts_mes < $ligne_immo.date_achat|strtotime || $ts_mes > $first_amort_date|strtotime}}
|
||||
{{:assign immo_date=$ligne_immo.date_achat|date_short}}
|
||||
{{:assign amort_date=$first_amort_date|date_short}}
|
||||
{{:error message="La date de mise en service doit être postérieure à la date d'acquisition de l'immobilisation (%s) et antérieure à la date du premier amortissement (%s)"|args:$immo_date:$amort_date}}
|
||||
{{/if}}
|
||||
{{/if}}
|
||||
|
||||
{{* vérifier la validité de la durée d'immobilisation *}}
|
||||
{{if $valeur_nette > 0}}
|
||||
{{if $info_immo.duration == null}}
|
||||
{{if $_POST.duree == null}}
|
||||
{{:error message="Vous devez renseigner la durée de l'immobilisation"}}
|
||||
{{elseif $_POST.duree < $amort_number}}
|
||||
{{:error message="La durée de l'amortissement ne peut être inférieure au nombre d'écritures d'amortissement (%d)"|args:$amort_number}}
|
||||
{{else}}
|
||||
{{:assign duree_amort=$_POST.duree}}
|
||||
{{/if}}
|
||||
{{/if}}
|
||||
{{/if}}
|
||||
|
||||
{{* vérifier la validité de la date de sortie *}}
|
||||
{{if $info_immo.date != null}}
|
||||
{{if $_POST.date_sortie|parse_date < $info_immo.date}}
|
||||
{{:assign immo_date=$info_immo.date|date_short}}
|
||||
{{if $info_immo.date_mes != null}}
|
||||
{{if $_POST.date_sortie|parse_date < $info_immo.date_mes}}
|
||||
{{:assign immo_date=$info_immo.date_mes|date_short}}
|
||||
{{:error message="La date de sortie doit être postérieure à la date de mise en service de l'immobilisation (%s)"|args:$immo_date}}
|
||||
{{/if}}
|
||||
{{elseif $_POST.date_mes != null}}
|
||||
{{if $_POST.date_sortie|parse_date < $_POST.date_mes|parse_date}}
|
||||
{{:error message="La date de sortie doit être postérieure à la date de mise en service de l'immobilisation (%s)"|args:$_POST.date_mes}}
|
||||
{{/if}}
|
||||
{{elseif $_POST.date_sortie|parse_date < $ligne_immo.date_achat}}
|
||||
{{:assign immo_date=$ligne_immo.date_achat|date_short}}
|
||||
{{:error message="La date de sortie doit être postérieure à la date d'acquisition de l'immobilisation (%s)"|args:$immo_date}}
|
||||
|
|
@ -198,57 +101,58 @@
|
|||
{{:error message="La date de sortie doit être postérieure à la date du dernier amortissement (%s)"|args:$last_amort_date}}
|
||||
{{/if}}
|
||||
|
||||
{{* vérifier que la date de sortie est située dans un exercice ouvert *}}
|
||||
{{:assign ts_exit = $_POST.date_sortie|parse_date|strtotime}}
|
||||
{{:assign ok=false}}
|
||||
{{:assign msg_amort=""}}
|
||||
{{#foreach from=$years}}
|
||||
{{if $id == $_POST.id_year}}
|
||||
{{:assign selected_year=$id}}
|
||||
{{:assign exercice_ok=false}}
|
||||
{{* vérifier que la date de sortie est dans l'exercice choisi *}}
|
||||
{{#foreach from=$years item="current_year"}}
|
||||
{{if $current_year.id == $_POST.id_year}}
|
||||
{{:assign selected_year=$current_year.id}}
|
||||
{{if $start_date|strtotime <= $ts_exit && $ts_exit <= $end_date|strtotime}}
|
||||
{{:assign ok=true}}
|
||||
{{:assign current_year=$current_year}}
|
||||
{{:assign exercice_ok=true}}
|
||||
{{:break}}
|
||||
{{/if}}
|
||||
{{/if}}
|
||||
|
||||
{{* voir si des amortissements ont été oubliés *}}
|
||||
{{if $valeur_nette > 0 && $info_immo.status != "amortized" && $start_date|strtotime > $last_amort_date|strtotime && $end_date|strtotime < $now}}
|
||||
{{:assign debut=$start_date|date_short}}
|
||||
{{:assign fin=$end_date|date_short}}
|
||||
{{:assign msg_amort=$msg_amort|cat:"\n"|cat:" - "|cat:$label|cat:" : du "|cat:$debut|cat:" au "|cat:$fin}}
|
||||
{{/if}}
|
||||
{{/foreach}}
|
||||
{{if ! $ok}}
|
||||
{{if ! $exercice_ok}}
|
||||
{{:error message="La date choisie n'est pas dans l'exercice sélectionné !"}}
|
||||
{{/if}}
|
||||
{{if $msg_amort != ""}}
|
||||
{{:error message="Vous devez d'abord enregistrer les amortissements des exercices suivants : %s"|args:$msg_amort}}
|
||||
|
||||
{{* voir si des amortissements ont été oubliés *}}
|
||||
{{if $valeur_nette > 0 && $info_immo.status != "amortized"}}
|
||||
{{if $current_year.start_date <= $date_debut && $date_debut <= $current_year.end_date}}
|
||||
{{:assign amort_ok=true}}
|
||||
{{else}}
|
||||
{{:assign amort_ok=false}}
|
||||
{{/if}}
|
||||
{{if ! $amort_ok}}
|
||||
{{:error message="Vous devez d'abord enregistrer les amortissements des exercices précédents"}}
|
||||
{{/if}}
|
||||
{{/if}}
|
||||
|
||||
{{:redirect to="compute_exit_data.html?immo_line_id=%s&amort_amount=%s&year=%s&date_mes=%s&date_debut=%s&exit_date=%s&duree_amort=%s"|args:$_GET.immo_line_id:$total_amort:$selected_year:$ts_mes:$ts_debut:$ts_exit:$duree_amort}}
|
||||
{{:redirect to="compute_exit_data.html?immo_doc_id=%s&amort_amount=%s&year=%s&date_debut=%s&exit_date=%s"|args:$_GET.immo_doc_id:$total_amort:$selected_year:$ts_debut:$ts_exit}}
|
||||
{{/form}}
|
||||
|
||||
{{:admin_header title="Sortie de bilan" custom_css="./style.css" current="module_amortization"}}
|
||||
{{* barre de navigation *}}
|
||||
{{if ! $dialog}}
|
||||
{{:include file="_nav.html" current="index" subcurrent="%s"|args:$_GET.type_immo subsubcurrent="balance_exit"}}
|
||||
{{/if}}
|
||||
{{:form_errors}}
|
||||
|
||||
{{* formulaire de sortie du bilan *}}
|
||||
<h3>Sortir l'immobilisation « {{$ligne_immo.label}} » du bilan</h3>
|
||||
<h3>Sortir l'immobilisation « {{$label_immo}} » du bilan</h3>
|
||||
<form method="post" action="">
|
||||
|
||||
<div class="informations">
|
||||
<legend>Données de l'imobilisation</legend>
|
||||
<dl class="describe">
|
||||
<dt>Montant</dt>
|
||||
<dd id="montant_immo" class="money">{{$ligne_immo.montant|money_currency_html:false|raw}}</dd>
|
||||
<dd id="montant_immo" class="money">{{$ligne_immo.amount|money_currency_html:false|raw}}</dd>
|
||||
<dt>Date d'acquisition</dt>
|
||||
<dd >{{$ligne_immo.date_achat|date_short}}</dd>
|
||||
{{if $info_immo.date != null && $info_immo.date != $ligne_immo.date_achat}}
|
||||
<dd>{{$date_achat|date_short}}
|
||||
{{if $date_mes != null}}
|
||||
<dt>Date de mise en service</dt>
|
||||
<dd>{{$info_immo.date|date_short}}</dd>
|
||||
<dd>{{$date_mes|date_short}}</dd>
|
||||
{{/if}}
|
||||
{{if $info_immo.duration != null}}
|
||||
<dt>Durée de l'amortissement</dt>
|
||||
|
|
@ -258,23 +162,13 @@
|
|||
<dd id="montant_amort" class="money">{{$total_amort|money_currency_html:false|raw}} <span class="help">(à la date de début de l'exercice)</span></dd>
|
||||
<dt>Valeur nette résiduelle</dt>
|
||||
<dd class="money">{{$valeur_nette|money_currency_html:false|raw}} <span class="help">(à la date de début de l'exercice)</span></dd>
|
||||
{{if $last_amort_date != null}}
|
||||
<dt>Date du dernier amortissement</dt>
|
||||
<dd>{{$last_amort_date|date_short}}</dd>
|
||||
{{/if}}
|
||||
</dl>
|
||||
</div>
|
||||
{{if $valeur_nette > 0}}
|
||||
{{if $info_immo.date == null || $info_immo.duration == null}}
|
||||
<fieldset>
|
||||
<legend>Informations sur l'immobilisation</legend>
|
||||
<dl>
|
||||
{{if $info_immo.date == null}}
|
||||
{{:input type="date" name="date_mes" label="Date de mise en service" help="C'est la date de première utilisation ; à renseigner uniquement si différente de la date d'acquisition"}}
|
||||
{{/if}}
|
||||
{{if $info_immo.duration == null}}
|
||||
{{:input type="number" name="duree" label="Durée d'amortissement" required=true min=1 help="La durée est nécessaire pour calculer l'amortissement complémentaire"}}
|
||||
{{/if}}
|
||||
</dl>
|
||||
</fieldset>
|
||||
{{/if}}
|
||||
{{/if}}
|
||||
|
||||
<fieldset>
|
||||
<legend>Informations de sortie</legend>
|
||||
<dl>
|
||||
|
|
|
|||
|
|
@ -3,60 +3,42 @@
|
|||
{{*
|
||||
Calculer les valeurs de la sortie et saisir le montant de la cession (optionnel)
|
||||
paramètres :
|
||||
- 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 : datede mise en service de l'immobilisation
|
||||
- date_debut : date de début de la période d'amortissement complémentaire
|
||||
- exit_date : date de sortie de l'immobilisation
|
||||
- duree_amort : durée de l'amortiseement (optionnel)
|
||||
@param immo_doc_id : id du doc associé à l'immo
|
||||
@param amort_amount : montant des amortissements
|
||||
@param year : exercice de la date de sortie de l'immobilisation
|
||||
@param date_debut : date de début de la période d'amortissement complémentaire
|
||||
@param exit_date : date de sortie de l'immobilisation
|
||||
*}}
|
||||
{{* TODO *}}
|
||||
{{* données de l'immobilisation *}}
|
||||
{{:include file="_get_immo_data.html" immo_doc_id=$_GET.immo_doc_id|intval keep="info_immo, ligne_immo, message"}}
|
||||
{{if $message != null}}
|
||||
{{:error message=$message}}
|
||||
{{/if}}
|
||||
|
||||
{{#select
|
||||
line.debit as montant,
|
||||
trans.id AS trans_id,
|
||||
trans.date as date_achat,
|
||||
trans.label,
|
||||
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 = $_GET.immo_line_id|intval
|
||||
assign="ligne_immo"
|
||||
}}
|
||||
{{else}}
|
||||
{{:error message="Immobilisation %s non trouvée"|args:$_GET.immo_line_id}}
|
||||
{{/select}}
|
||||
{{:assign label_immo=$info_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 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
|
||||
}}
|
||||
{{:assign total_credits="%d+%d"|math:$total_credits:$credit}}
|
||||
{{/select}}
|
||||
{{:assign var="ligne_immo.montant" value="%d-%d"|math:$ligne_immo.montant:$total_credits}}
|
||||
{{:assign date_achat=$info_immo.date_achat|or:$ligne_immo.date_achat}}
|
||||
{{if $info_immo.date_mes != null && $info_immo.date_mes != $date_achat}}
|
||||
{{:assign date_mes=$info_immo.date_mes}}
|
||||
{{/if}}
|
||||
|
||||
{{if $info_immo.amount != null}}
|
||||
{{:assign var="ligne_immo.amount" value=$info_immo.amount}}
|
||||
{{/if}}
|
||||
|
||||
{{* déduire le montant des écritures liées à l'immo courante au crédit du même compte *}}
|
||||
{{:include file="_get_credit_lines.html" immo_doc_id=$_GET.immo_doc_id keep="total_credits"}}
|
||||
{{:assign var="ligne_immo.amount" value="%d-%d"|math:$ligne_immo.amount:$total_credits}}
|
||||
{{:assign valeur_nette="%f-%f"|math:$ligne_immo.amount:$_GET.amort_amount}}
|
||||
|
||||
{{:assign valeur_nette="%f-%f"|math:$ligne_immo.montant:$_GET.amort_amount}}
|
||||
{{:assign amort_comp=0}} {{* amortissement complémentaire jqà date sortie *}}
|
||||
{{if $valeur_nette > 0}}
|
||||
{{:assign nbjours="1+(%d-%d)/(60*60*24)"|math:$_GET.exit_date:$_GET.date_debut}}
|
||||
{{:assign annuite="%f/%f"|math:$ligne_immo.montant:$_GET.duree_amort}}
|
||||
{{:assign annuite="%f/%f"|math:$ligne_immo.amount:$info_immo.duration}}
|
||||
{{:assign amort_comp="round(%f/365*%f, 0)"|math:$annuite:$nbjours}}
|
||||
{{:assign amort_comp="min(%f, %f)"|math:$valeur_nette:$amort_comp}}
|
||||
{{/if}}
|
||||
|
|
@ -69,7 +51,7 @@
|
|||
{{/if}}
|
||||
{{/if}}
|
||||
|
||||
{{:redirect to="write_exit.html?immo_line_id=%s&amort_amount=%s&year=%s&date_mes=%s&date_debut=%s&exit_date=%s&duree_amort=%s&cession=%s"|args:$_GET.immo_line_id:$_GET.amort_amount:$_GET.year:$_GET.date_mes:$_GET.date_debut:$_GET.exit_date:$_GET.duree_amort:$_POST.montant_cession}}
|
||||
{{:redirect to="write_exit.html?immo_doc_id=%s&amort_amount=%s&year=%s&date_debut=%s&exit_date=%s&cession=%s"|args:$_GET.immo_doc_id:$_GET.amort_amount:$_GET.year:$_GET.date_debut:$_GET.exit_date:$_POST.montant_cession}}
|
||||
|
||||
{{/form}}
|
||||
{{:admin_header title="Sortie du bilan" custom_css="./style.css" current="module_amortization"}}
|
||||
|
|
@ -81,24 +63,22 @@
|
|||
|
||||
{{:form_errors}}
|
||||
|
||||
<h3>Sortir l'immobilisation « {{$ligne_immo.label}} » du bilan</h3>
|
||||
<h3>Sortir l'immobilisation « {{$label_immo}} » du bilan</h3>
|
||||
<form method="post" action="">
|
||||
|
||||
<div class="informations">
|
||||
<legend>Données de l'imobilisation</legend>
|
||||
<dl class="describe">
|
||||
<dt>Montant</dt>
|
||||
<dd id="montant_immo" class="money">{{$ligne_immo.montant|money_currency_html:false|raw}}</dd>
|
||||
<dd id="montant_immo" class="money">{{$ligne_immo.amount|money_currency_html:false|raw}}</dd>
|
||||
<dt>Date d'acquisition</dt>
|
||||
<dd >{{$ligne_immo.date_achat|date_short}}</dd>
|
||||
{{if $_GET.date_mes != $ligne_immo.date_achat|strtotime}}
|
||||
<dd >{{$date_achat|date_short}}</dd>
|
||||
{{if $date_mes != null}}
|
||||
<dt>Date de mise en service</dt>
|
||||
<dd>{{$_GET.date_mes|date:"d/m/Y"}}</dd>
|
||||
{{/if}}
|
||||
{{if $_GET.duree_amort != null && $_GET.duree_amort != 0}}
|
||||
<dt>Durée de l'amortissement</dt>
|
||||
<dd id="duree_amort" class="num">{{$_GET.duree_amort}} ans</dd>
|
||||
<dd>{{$date_mes|date_short}}</dd>
|
||||
{{/if}}
|
||||
<dt>Durée de l'amortissement</dt>
|
||||
<dd id="duree_amort" class="num">{{$info_immo.duration}} ans</dd>
|
||||
<dt>Montant des amortissements</dt>
|
||||
<dd id="montant_amort" class="money">{{$_GET.amort_amount|money_currency_html:false|raw}} <span class="help">(à la date de début de l'exercice)</span></dd>
|
||||
<dt>Valeur nette résiduelle</dt>
|
||||
|
|
|
|||
79
delete_infos.html
Normal file
79
delete_infos.html
Normal file
|
|
@ -0,0 +1,79 @@
|
|||
{{* -*- brindille -*- *}}
|
||||
|
||||
{{*
|
||||
Supprimer les infos d'une immo et les liaisons d'immo associées
|
||||
@param immo_doc_id
|
||||
*}}
|
||||
|
||||
{{:include file="_get_immo_data.html" immo_doc_id=$_GET.immo_doc_id|intval keep="info_immo, ligne_immo, message"}}
|
||||
{{if $message != null}}
|
||||
{{:error message=$message}}
|
||||
{{/if}}
|
||||
|
||||
{{:assign trans_url="%s/acc/transactions/details.php?id=%s"|args:$admin_url:$ligne_immo.trans_id}}
|
||||
{{:assign immo_label=$info_immo.label|or:$ligne_immo.trans_label}}
|
||||
{{if $ligne_immo.line_label != null && $ligne_immo.line_label != $immo_label}}
|
||||
{{:assign immo_label=$immo_label|cat::" — "|cat:$ligne_immo.line_label}}
|
||||
{{/if}}
|
||||
|
||||
{{#form on="delete"}}
|
||||
{{#select
|
||||
trans.id
|
||||
FROM acc_transactions_lines AS line
|
||||
INNER JOIN !table AS credit_link ON $$.credit_line_id = line.id
|
||||
INNER JOIN acc_transactions AS trans ON line.id_transaction = trans.id
|
||||
WHERE $$.type = "credit_link" AND $$.immo_doc_id = :immo_doc_id
|
||||
;
|
||||
!table = $module.table
|
||||
:immo_doc_id = $_GET.immo_doc_id|intval
|
||||
}}
|
||||
{{:assign var="linked_trans." value=$id}}
|
||||
{{/select}}
|
||||
|
||||
{{if $linked_trans != null}}
|
||||
{{* chercher et supprimer les écritures liées *}}
|
||||
{{#select
|
||||
CASE links.id_related = trans.id
|
||||
WHEN true THEN links.id_transaction
|
||||
WHEN false THEN links.id_related
|
||||
END as linked_id
|
||||
FROM acc_transactions AS trans
|
||||
INNER JOIN acc_transactions_links as links
|
||||
ON (links.id_transaction = trans.id OR links.id_related = trans.id)
|
||||
WHERE trans.id = :immo_trans_id
|
||||
;
|
||||
:immo_trans_id=$ligne_immo.trans_id
|
||||
}}
|
||||
{{if ! $linked_trans|has:$linked_id}}
|
||||
{{:assign var="linked_transactions." value=$linked_id}}
|
||||
{{/if}}
|
||||
{{/select}}
|
||||
|
||||
{{* enregistrer les liaisons restantes *}}
|
||||
{{:api
|
||||
method="POST"
|
||||
path="accounting/transaction/%s/transactions"|args:$ligne_immo.trans_id
|
||||
assign="result"
|
||||
assign_code="result_code"
|
||||
transactions=$linked_transactions
|
||||
}}
|
||||
|
||||
{{* supprimer les docs de liaison *}}
|
||||
{{:delete type="credit_link" where="$$.immo_doc_id = :immo_doc_id" :immo_doc_id = $_GET.immo_doc_id|intval}}
|
||||
{{/if}}
|
||||
|
||||
{{* supprimer les infos de l'immobilisation *}}
|
||||
{{:delete id=$_GET.immo_doc_id|intval}}
|
||||
{{:redirect force="index.html?ok=1&msg=suppr_infos&type_immo=other"}}
|
||||
{{/form}}
|
||||
|
||||
|
||||
{{:admin_header title="Supprimer" current="module_amortization"}}
|
||||
{{:form_errors}}
|
||||
{{:delete_form
|
||||
legend="Immobilisation « #%s %s »"|args:$ligne_immo.trans_id:$immo_label
|
||||
warning="Supprimer les paramètres de l'immobilisation « #%s %s » ?"|args:$ligne_immo.trans_id:$immo_label
|
||||
info="L'écriture d'immobilisation ne sera pas supprimée ; les nouveaux paramètres pourront être saisis depuis l'onglet « À classer »"
|
||||
}}
|
||||
|
||||
{{:admin_footer}}
|
||||
|
|
@ -3,69 +3,30 @@
|
|||
{{*
|
||||
Supprimer l'association entre une écriture d'amortissement et
|
||||
une écriture d'immobilisation
|
||||
@param immo_doc_id : id du doc associé à l'immo
|
||||
@param amort_line_id : id de la ligne d'amortissement
|
||||
*}}
|
||||
|
||||
{{* chercher l'écriture d'immobilisation *}}
|
||||
{{#select
|
||||
id_transaction
|
||||
FROM acc_transactions_lines
|
||||
WHERE id = :line_id;
|
||||
:line_id = $_GET.immo_line_id|intval
|
||||
}}
|
||||
{{: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}}
|
||||
{{/select}}
|
||||
|
||||
{{* chercher l'écriture d'amortissement *}}
|
||||
{{#select
|
||||
id_transaction
|
||||
FROM acc_transactions_lines
|
||||
WHERE id = :line_id;
|
||||
:line_id = $_GET.amort_line_id|intval
|
||||
}}
|
||||
{{:assign amort_id=$id_transaction}}
|
||||
{{else}}
|
||||
{{:error message="Impossible de trouver l'écriture d'amortissement de la ligne « %s »"|args:$_GET.amort_line_id}}
|
||||
{{/select}}
|
||||
|
||||
{{*
|
||||
chercher les liaisons de l'écriture d'immobilisation
|
||||
et supprimer la liaison avec l'écriture d'amortissement
|
||||
*}}
|
||||
{{#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
|
||||
}}
|
||||
{{if $linked_id != $amort_id}}
|
||||
{{:assign var="linked_transactions." value=$linked_id}}
|
||||
{{/if}}
|
||||
{{/select}}
|
||||
|
||||
{{* Enregistrer les liaisons *}}
|
||||
{{:api
|
||||
method="POST"
|
||||
path="accounting/transaction/%s/transactions"|args:$immo_trans_id
|
||||
assign="result"
|
||||
assign_code="result_code"
|
||||
transactions=$linked_transactions
|
||||
}}
|
||||
{{:include file="_common_detach.html" immo_doc_id=$_GET.immo_doc_id line_id=$_GET.amort_line_id}}
|
||||
|
||||
{{* 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}}
|
||||
{{* marquer immo non soldée *}}
|
||||
{{* TODO : À VÉRIFIER *}}
|
||||
{{:save
|
||||
key=$info_immo.key
|
||||
status="managed"
|
||||
}}
|
||||
|
||||
{{if $_GET.from == "exit"}}
|
||||
{{:redirect force="exit_step2.html?immo_doc_id=%s&ok=1&msg=detach_amort"|args:$_GET.immo_doc_id}}
|
||||
{{else}}
|
||||
{{:redirect force="amortization.html?immo_doc_id=%s&ok=1&msg=detach_amort"|args:$_GET.immo_doc_id:}}
|
||||
{{/if}}
|
||||
|
|
|
|||
21
detach_cession.html
Normal file
21
detach_cession.html
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
{{* -*- brindille -*- *}}
|
||||
|
||||
{{*
|
||||
Supprimer l'association entre une écriture d'immobilisation et
|
||||
une écriture de cession
|
||||
@param immo_doc_id : id du doc associé à l'immo
|
||||
@param cession_line_id : id de la ligne de cession
|
||||
*}}
|
||||
|
||||
{{:include file="_common_detach.html" immo_doc_id=$_GET.immo_doc_id line_id=$_GET.cession_line_id}}
|
||||
|
||||
{{* supprimer le doc de liaison entre les lignes *}}
|
||||
{{#load type="cession_link"
|
||||
where="$$.immo_doc_id = :immo_doc_id AND $$.cession_line_id = :cession_line_id"
|
||||
:immo_doc_id=$_GET.immo_doc_id|intval
|
||||
:cession_line_id = $_GET.cession_line_id|intval
|
||||
}}
|
||||
{{:delete id=$id}}
|
||||
{{/load}}
|
||||
|
||||
{{:redirect to="exit_step3.html?immo_doc_id=%s&ok=1&msg=detach_cession"|args:$_GET.immo_doc_id}}
|
||||
25
detach_credit.html
Normal file
25
detach_credit.html
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
{{* -*- brindille -*- *}}
|
||||
|
||||
{{*
|
||||
Supprimer l'association entre une écriture d'immobilisation et
|
||||
une écriture au crédit du compte d'immobilisation
|
||||
@param immo_doc_id : id du doc associé à l'immo
|
||||
@param credit_line_id : id de la ligne de crédit
|
||||
*}}
|
||||
|
||||
{{:include file="_common_detach.html" immo_doc_id=$_GET.immo_doc_id line_id=$_GET.credit_line_id}}
|
||||
|
||||
{{* supprimer le doc de liaison entre les lignes *}}
|
||||
{{#load type="credit_link"
|
||||
where="$$.immo_doc_id = :immo_doc_id AND $$.credit_line_id = :credit_line_id"
|
||||
:immo_doc_id=$_GET.immo_doc_id|intval
|
||||
:credit_line_id = $_GET.credit_line_id|intval
|
||||
}}
|
||||
{{:delete id=$id}}
|
||||
{{/load}}
|
||||
|
||||
{{if $_GET.from == "exit"}}
|
||||
{{:redirect force="exit_step1.html?immo_doc_id=%s&ok=1&msg=detach_avoir"|args:$_GET.immo_doc_id}}
|
||||
{{else}}
|
||||
{{:redirect force="amortization.html?immo_doc_id=%s&ok=1&msg=detach_avoir"|args:$_GET.immo_doc_id}}
|
||||
{{/if}}
|
||||
21
detach_exit.html
Normal file
21
detach_exit.html
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
{{* -*- brindille -*- *}}
|
||||
|
||||
{{*
|
||||
Supprimer l'association entre une écriture d'immobilisation et
|
||||
une écriture de sortie de bilan
|
||||
@param immo_doc_id : id du doc associé à l'immo
|
||||
@param exit_line_id : id de la ligne de sortie de bilan
|
||||
*}}
|
||||
|
||||
{{:include file="_common_detach.html" immo_doc_id=$_GET.immo_doc_id line_id=$_GET.exit_line_id}}
|
||||
|
||||
{{* supprimer le doc de liaison entre les lignes *}}
|
||||
{{#load type="exit_link"
|
||||
where="$$.immo_doc_id = :immo_doc_id AND $$.exit_line_id = :exit_line_id"
|
||||
:immo_doc_id=$_GET.immo_doc_id|intval
|
||||
:exit_line_id = $_GET.exit_line_id|intval
|
||||
}}
|
||||
{{:delete id=$id}}
|
||||
{{/load}}
|
||||
|
||||
{{:redirect to="exit_step4.html?immo_doc_id=%s&ok=1&msg=detach_exit"|args:$_GET.immo_doc_id}}
|
||||
239
exit_step1.html
Normal file
239
exit_step1.html
Normal file
|
|
@ -0,0 +1,239 @@
|
|||
{{* -*- brindille -*- *}}
|
||||
|
||||
{{*
|
||||
Associer des écritures de crédit à une immo créée et sortie du
|
||||
bilan avant la mise en service du module
|
||||
@param immo_doc_id : id du doc associé à l'immobilisation
|
||||
*}}
|
||||
|
||||
{{* données de l'immobilisation *}}
|
||||
{{:include file="_get_immo_data.html" immo_doc_id=$_GET.immo_doc_id keep="info_immo, ligne_immo, message"}}
|
||||
{{if $message != null}}
|
||||
{{:error message=$message}}
|
||||
{{/if}}
|
||||
|
||||
{{:assign label_immo=$info_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}}
|
||||
{{:assign trans_url="%s/acc/transactions/details.php?id=%s"|args:$admin_url:$ligne_immo.trans_id}}
|
||||
{{:assign date_immo=$info_immo.date_mes|or:$info_immo.date_achat|or:$ligne_immo.date_achat}}
|
||||
{{:assign montant_immo=$info_immo.amount|or:$ligne_immo.amount}}
|
||||
|
||||
{{* déduire le montant des écritures liées à l'immo courante au crédit du même compte *}}
|
||||
{{:include file="_get_credit_lines.html" immo_doc_id=$_GET.immo_doc_id keep="linked_immos, total_credits"}}
|
||||
{{:assign solde="%d-%d"|math:$montant_immo:$total_credits}}
|
||||
|
||||
{{* lister les amortissements liés à l'immobilisation *}}
|
||||
{{:include file="./_get_amort_lines.html" immo_doc_id=$_GET.immo_doc_id keep="linked_amort, total_amort"}}
|
||||
|
||||
{{*
|
||||
chercher des écritures au crédit du compte de l'immo sans doc associé
|
||||
- line.credit < ligne_immo.amount => peut-être un avoir
|
||||
- line.credit = ligne_immo.amount - avoirs => écriture de sortie du bilan
|
||||
*}}
|
||||
{{#select
|
||||
trans.id as trans_id,
|
||||
trans.label as trans_label,
|
||||
trans.date as date,
|
||||
trans.id_year as year,
|
||||
line.id as credit_line_id,
|
||||
line.label as line_label,
|
||||
line.credit as amount,
|
||||
acc.id as account_id,
|
||||
acc.code as account_code,
|
||||
acc.label as account_label
|
||||
FROM acc_transactions AS trans
|
||||
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
|
||||
LEFT JOIN module_data_amortization AS mda ON json_extract(mda.document, '$.amort_line_id') = line.id
|
||||
WHERE
|
||||
acc.code = :acc_code
|
||||
AND line.credit > 0
|
||||
AND credit_line_id NOT IN (
|
||||
SELECT json_extract(credit_link.document, '$.credit_line_id') AS line_id FROM !table as credit_link
|
||||
WHERE json_extract(credit_link.document, '$.type') == "credit_link"
|
||||
UNION
|
||||
SELECT json_extract(exit_link.document, '$.exit_line_id') AS line_id FROM !table as exit_link
|
||||
WHERE json_extract(exit_link.document, '$.type') == "exit_link"
|
||||
)
|
||||
;
|
||||
:acc_code=$ligne_immo.account_code
|
||||
!table =$module.table
|
||||
assign="credit_line"
|
||||
}}
|
||||
{{if $credit_line.amount < $solde}}
|
||||
{{:assign var="credit_lines." value=$credit_line}}
|
||||
{{/if}}
|
||||
{{/select}}
|
||||
|
||||
{{* déterminer le compte d'amortissement en fonction du compte d'immobilisation *}}
|
||||
{{:include
|
||||
file="./_get_amort_code.html"
|
||||
code_immo=$ligne_immo.account_code
|
||||
keep="code_amort"
|
||||
}}
|
||||
|
||||
{{* chercher des écritures d'amortissement correspondant au compte d'une immo sans doc associé *}}
|
||||
{{* TODO écritures d'amort pas entièrement affectées *}}
|
||||
{{#select
|
||||
line.id as amort_line_id,
|
||||
line.credit as amort_amount,
|
||||
line.label as line_label,
|
||||
trans.id as amort_trans_id,
|
||||
trans.date as date,
|
||||
trans.label as trans_label,
|
||||
trans.id_year as 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_accounts AS account ON line.id_account = account.id
|
||||
INNER JOIN acc_transactions AS trans ON line.id_transaction = trans.id
|
||||
WHERE
|
||||
account.code = :code_amort
|
||||
AND line.credit > 0
|
||||
AND (NOT trans.status & 16)
|
||||
AND trans.date >= :immo_date
|
||||
;
|
||||
:code_amort = $code_amort
|
||||
:immo_date=$date_immo
|
||||
assign="amort_line"
|
||||
}}
|
||||
{{* 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_line.amort_line_id|intval
|
||||
assign="amort_link"
|
||||
}}
|
||||
{{if $amort_link.amount == null || $amort_link.amount == 0}}
|
||||
{{:assign amort_amount=$amort_line.amort_amount}}
|
||||
{{:assign keep_amort=false}}
|
||||
{{else}}
|
||||
{{:assign amort_amount="%d+%d"|math:$amort_amount:$amort_link.amount}}
|
||||
{{/if}}
|
||||
{{else}}
|
||||
{{* pas de ligne d'immo liée à cette ligne d'amort => garder cette ligne d'amortissement *}}
|
||||
{{/load}}
|
||||
{{if $keep_amort && $amort_amount < $amort_line.amort_amount}}
|
||||
{{:assign var="free_amort_lines." value=$amort_line}}
|
||||
{{/if}}
|
||||
{{/select}}
|
||||
|
||||
{{:admin_header title="Immobilisation sortie du bilan" custom_css="./style.css" current="module_amortization"}}
|
||||
|
||||
{{if $_GET.ok}}
|
||||
{{if $_GET.msg|match:"attach_avoir"}}
|
||||
{{:assign msg="Écriture d'avoir attachée"}}
|
||||
{{elseif $_GET.msg|match:"detach_avoir"}}
|
||||
{{:assign msg="Écriture d'avoir détachée"}}
|
||||
{{/if}}
|
||||
<p class="block confirm">{{$msg}}</p>
|
||||
{{/if}}
|
||||
|
||||
<div class="informations">
|
||||
<dl class="describe">
|
||||
<dt>Immobilisation</dt>
|
||||
<dd><span class="num"><a href="{{$trans_url}}">#{{$ligne_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><span class="money">{{$ligne_immo.amount|money_html|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">{{"%f"|math:$solde|money_currency_html:false|raw}}</dd>
|
||||
{{/if}}
|
||||
{{if $total_amort > 0}}
|
||||
<dt>Montant des amortissements</dt>
|
||||
<dd>{{$total_amort|money_currency_html:false|raw}}</dd>
|
||||
<dt>Valeur nette résiduelle</dt>
|
||||
<dd>{{"%d-%d"|math:$solde:$total_amort|money_currency_html:false|raw}}</dd>
|
||||
{{/if}}
|
||||
</dl>
|
||||
</div>
|
||||
|
||||
{{if $linked_immos != null}}
|
||||
<h3 class="ruler">Écritures d'avoir attachées à l'immobilisation</h3>
|
||||
<table class="list">
|
||||
<thead>
|
||||
<td class="num">N°</td>
|
||||
<td>Date</td>
|
||||
<td>Libellé</td>
|
||||
<td class="nombre">Montant</td>
|
||||
<td>N° compte</td>
|
||||
<td>Compte</td>
|
||||
<td class="actions"></td>
|
||||
</thead>
|
||||
<tbody>
|
||||
{{#foreach from=$linked_immos item="line"}}
|
||||
{{:assign url="%s/acc/transactions/details.php?id=%s"|args:$admin_url:$line.trans_id}}
|
||||
{{:assign compte_url="%s/acc/accounts/journal.php?id=%s&year=%s"|args:$admin_url:$line.account_id:$line.year}}
|
||||
<tr>
|
||||
<td class="num"><a href="{{$url}}">#{{$line.trans_id}}</a></td>
|
||||
<td>{{$line.date|date_short}}</td>
|
||||
<td>{{$line.label}}</td>
|
||||
<td class="money">{{"%f"|math:$line.amount|money_currency_html:false|raw}}</td>
|
||||
<td><a href="{{$compte_url}}">{{$line.account_code}}</a></td>
|
||||
<td>{{$line.account_label}}</td>
|
||||
<td>
|
||||
{{:linkbutton label="Détacher" href="detach_credit.html?immo_doc_id=%s&credit_line_id=%s&from=exit"|args:$_GET.immo_doc_id:$line.credit_line_id shape="minus"}}
|
||||
</td>
|
||||
</tr>
|
||||
{{/foreach}}
|
||||
</tbody>
|
||||
</table>
|
||||
{{elseif $credit_lines}}
|
||||
<p class="block alert">
|
||||
Vous pouvez attacher une ou plusieurs écritures d'avoir à votre immobilisation
|
||||
</p>
|
||||
{{else}}
|
||||
<p class="block alert">
|
||||
Aucune écriture au crédit du compte d'immobilisation ; vous pouvez passer à la suite
|
||||
</p>
|
||||
{{/if}}
|
||||
|
||||
{{if $credit_lines}}
|
||||
<h3 class="ruler">Autres écritures au crédit du compte d'immobilisation</h3>
|
||||
<table class="list">
|
||||
<thead>
|
||||
<tr>
|
||||
<td class="num">N°</td>
|
||||
<td>Date</td>
|
||||
<td>Libellé</td>
|
||||
<td>Montant</td>
|
||||
<td>N° compte</td>
|
||||
<td>Compte</td>
|
||||
<td class="actions"></td>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{{#foreach from=$credit_lines}}
|
||||
{{:assign credit_url="%s/acc/transactions/details.php?id=%s"|args:$admin_url:$trans_id}}
|
||||
{{:assign compte_url="%s/acc/accounts/journal.php?id=%s&year=%s"|args:$admin_url:$account_id:$year}}
|
||||
<tr>
|
||||
<td class="num"><a href="{{$credit_url}}">#{{$trans_id}}</a></td>
|
||||
<td>{{$date|date_short}}</td>
|
||||
<td>{{$trans_label}}
|
||||
{{if $line_label != null && $line_label != $trans_label}} — {{$line_label}}{{/if}}
|
||||
</td>
|
||||
<td class="money">{{$amount|money_html|raw}}</td>
|
||||
<td><a href="{{$compte_url}}">{{$account_code}}</a></td>
|
||||
<td>{{$account_label}}</td>
|
||||
<td>
|
||||
{{:linkbutton label="Attacher" href="attach_credit.html?immo_doc_id=%s&credit_line_id=%s&from=exit"|args:$_GET.immo_doc_id:$credit_line_id shape="plus" target="_dialog"}}
|
||||
</td>
|
||||
</tr>
|
||||
{{/foreach}}
|
||||
</tbody>
|
||||
</table>
|
||||
{{/if}}
|
||||
|
||||
<form method="post" action="exit_step2.html?immo_doc_id={{$_GET.immo_doc_id}}">
|
||||
<p class="submit">
|
||||
{{:button type="submit" name="proceed" label="Poursuivre" shape="right" class="main"}}
|
||||
</p>
|
||||
</form>
|
||||
233
exit_step2.html
Normal file
233
exit_step2.html
Normal file
|
|
@ -0,0 +1,233 @@
|
|||
{{* -*- brindille -*- *}}
|
||||
|
||||
{{*
|
||||
Associer des écritures d'amortissement à une immo créée et sortie du
|
||||
bilan avant la mise en service du module
|
||||
@param immo_doc_id : id du doc associé à l'immobilisation
|
||||
*}}
|
||||
|
||||
{{* données de l'immobilisation *}}
|
||||
{{:include file="_get_immo_data.html" immo_doc_id=$_GET.immo_doc_id keep="info_immo, ligne_immo, message"}}
|
||||
{{if $message != null}}
|
||||
{{:error message=$message}}
|
||||
{{/if}}
|
||||
|
||||
{{#form on="backward"}}
|
||||
{{:redirect to="exit_step1.html?immo_doc_id=%s"|args:$_GET.immo_doc_id}}
|
||||
{{/form}}
|
||||
|
||||
{{#form on="forward"}}
|
||||
{{:redirect to="exit_step3.html?immo_doc_id=%s"|args:$_GET.immo_doc_id}}
|
||||
{{/form}}
|
||||
|
||||
{{:assign label_immo=$info_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}}
|
||||
{{:assign trans_url="%s/acc/transactions/details.php?id=%s"|args:$admin_url:$ligne_immo.trans_id}}
|
||||
{{:assign date_immo=$info_immo.date_mes|or:$info_immo.date_achat|or:$ligne_immo.date_achat}}
|
||||
{{:assign montant_immo=$info_immo.amount|or:$ligne_immo.amount}}
|
||||
|
||||
{{* déduire le montant des écritures liées à l'immo courante au crédit du même compte *}}
|
||||
{{:include file="_get_credit_lines.html" immo_doc_id=$_GET.immo_doc_id keep="linked_immos, total_credits"}}
|
||||
{{:assign solde="%d-%d"|math:$montant_immo:$total_credits}}
|
||||
|
||||
{{* lister les amortissements liés à l'immobilisation *}}
|
||||
{{:include file="./_get_amort_lines.html" immo_doc_id=$_GET.immo_doc_id keep="linked_amort, total_amort"}}
|
||||
|
||||
{{* déterminer le compte d'amortissement en fonction du compte d'immobilisation *}}
|
||||
{{:include
|
||||
file="./_get_amort_code.html"
|
||||
code_immo=$ligne_immo.account_code
|
||||
keep="code_amort"
|
||||
}}
|
||||
|
||||
{{* chercher des écritures d'amortissement correspondant au compte d'une immo sans doc associé *}}
|
||||
{{* TODO écritures d'amort pas entièrement affectées *}}
|
||||
{{#select
|
||||
line.id as amort_line_id,
|
||||
line.credit as amort_amount,
|
||||
line.label as line_label,
|
||||
trans.id as amort_trans_id,
|
||||
trans.date as date,
|
||||
trans.label as trans_label,
|
||||
trans.id_year as 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_accounts AS account ON line.id_account = account.id
|
||||
INNER JOIN acc_transactions AS trans ON line.id_transaction = trans.id
|
||||
WHERE
|
||||
account.code = :code_amort
|
||||
AND line.credit > 0
|
||||
AND (NOT trans.status & 16)
|
||||
AND trans.date >= :immo_date
|
||||
;
|
||||
:code_amort = $code_amort
|
||||
:immo_date=$date_immo
|
||||
assign="amort_line"
|
||||
}}
|
||||
{{* 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_line.amort_line_id|intval
|
||||
assign="amort_link"
|
||||
}}
|
||||
{{if $amort_link.amount == null || $amort_link.amount == 0}}
|
||||
{{:assign amort_amount=$amort_line.amort_amount}}
|
||||
{{:assign keep_amort=false}}
|
||||
{{else}}
|
||||
{{:assign amort_amount="%d+%d"|math:$amort_amount:$amort_link.amount}}
|
||||
{{/if}}
|
||||
{{else}}
|
||||
{{* pas de ligne d'immo liée à cette ligne d'amort => garder cette ligne d'amortissement *}}
|
||||
{{/load}}
|
||||
{{if $keep_amort && $amort_amount < $amort_line.amort_amount}}
|
||||
{{:assign var="free_amort_lines." value=$amort_line}}
|
||||
{{/if}}
|
||||
{{/select}}
|
||||
|
||||
{{:admin_header title="Immobilisation sortie du bilan" custom_css="./style.css" current="module_amortization"}}
|
||||
|
||||
{{if $_GET.ok}}
|
||||
{{if $_GET.msg|match:"attach_amort"}}
|
||||
{{:assign msg="Écriture d'amortissement attachée"}}
|
||||
{{elseif $_GET.msg|match:"detach_amort"}}
|
||||
{{:assign msg="Écriture d'amortissement détachée"}}
|
||||
{{/if}}
|
||||
<p class="block confirm">{{$msg}}</p>
|
||||
{{/if}}
|
||||
|
||||
<div class="informations">
|
||||
<dl class="describe">
|
||||
<dt>Immobilisation</dt>
|
||||
<dd><span class="num"><a href="{{$trans_url}}">#{{$ligne_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><span class="money">{{$ligne_immo.amount|money_html|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">{{"%f"|math:$solde|money_currency_html:false|raw}}</dd>
|
||||
{{/if}}
|
||||
{{if $total_amort > 0}}
|
||||
<dt>Montant des amortissements</dt>
|
||||
<dd>{{$total_amort|money_currency_html:false|raw}}</dd>
|
||||
<dt>Valeur nette résiduelle</dt>
|
||||
<dd>{{"%d-%d"|math:$solde:$total_amort|money_currency_html:false|raw}}</dd>
|
||||
{{/if}}
|
||||
</dl>
|
||||
</div>
|
||||
|
||||
{{if $linked_amort != null}}
|
||||
<h3 class="ruler">Écritures d'amortissement attachées à l'immobilisation</h3>
|
||||
<table class="list">
|
||||
<thead>
|
||||
<tr>
|
||||
<td class="num">N°</td>
|
||||
<td>Date</td>
|
||||
<td>Libellé</td>
|
||||
<td class="nombre">Montant</td>
|
||||
<td>N° compte</td>
|
||||
<td>Compte</td>
|
||||
<td class="actions"></td>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{{#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.trans_id}}
|
||||
{{:assign compte_url="%s/acc/accounts/journal.php?id=%s&year=%s"|args:$admin_url:$line.account_id:$line.year}}
|
||||
<tr>
|
||||
<td class="num"><a href="{{$trans_url}}">#{{$line.trans_id}}</a></td>
|
||||
<td>{{$line.date|date_short}}</td>
|
||||
<td>
|
||||
{{if $line.line_label != null}}
|
||||
{{$line.line_label}}
|
||||
{{if $line.trans_label != $line.line_label}}
|
||||
— {{$line.trans_label}}
|
||||
{{/if}}
|
||||
{{else}}
|
||||
{{$line.trans_label}}
|
||||
{{/if}}
|
||||
</td>
|
||||
<td class="money">{{"%f"|math:$line.amount|money_html:false|raw}}</td>
|
||||
<td><a href="{{$compte_url}}">{{$line.account_code}}</a></td>
|
||||
<td>{{$line.account_label}}</td>
|
||||
<td>
|
||||
{{:linkbutton label="Détacher" href="detach_amort.html?immo_doc_id=%s&amort_line_id=%s&from=exit"|args:$_GET.immo_doc_id:$line.line_id shape="minus"}}
|
||||
</td>
|
||||
</tr>
|
||||
{{/foreach}}
|
||||
</tbody>
|
||||
</table>
|
||||
{{elseif $free_amort_lines}}
|
||||
<p class="block alert">
|
||||
Vous pouvez attacher une ou plusieurs écritures d'amortissement à l'immobilisation
|
||||
</p>
|
||||
{{else}}
|
||||
<p class="block alert">
|
||||
Aucune écriture d'amortissement à rattacher ; vous pouvez passer à la suite
|
||||
</p>
|
||||
{{/if}}
|
||||
|
||||
|
||||
{{if $free_amort_lines}}
|
||||
<h3 class="ruler">Autres écritures d'amortissements</h3>
|
||||
<table class="list">
|
||||
<thead>
|
||||
<tr>
|
||||
<td class="num">N°</td>
|
||||
<td>Date</td>
|
||||
<td>Libellé</td>
|
||||
<td class="nombre">Montant</td>
|
||||
<td>N° compte</td>
|
||||
<td>Compte</td>
|
||||
<td class="actions"></td>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
|
||||
{{#foreach from=$free_amort_lines item="line"}}
|
||||
{{:assign amort_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.year}}
|
||||
<tr>
|
||||
<td class="num"><a href="{{$amort_url}}">#{{$line.amort_trans_id}}</a></td>
|
||||
<td>{{$line.date|date_short}}</td>
|
||||
<td>
|
||||
{{if $line.line_label != null}}
|
||||
{{$line.line_label}}
|
||||
{{if $line.trans_label != $line.line_label}}
|
||||
— {{$line.trans_label}}
|
||||
{{/if}}
|
||||
{{else}}
|
||||
{{$line.trans_label}}
|
||||
{{/if}}
|
||||
{{*
|
||||
{{$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.amort_amount|money_html:false|raw}}</td>
|
||||
<td><a href="{{$compte_url}}">{{$line.account_code}}</a></td>
|
||||
<td>{{$line.account_label}}</td>
|
||||
<td>
|
||||
{{:linkbutton label="Attacher" href="attach_amort.html?immo_doc_id=%s&amort_line_id=%s&from=exit"|args:$_GET.immo_doc_id:$line.amort_line_id shape="plus" target="_dialog"}}
|
||||
</td>
|
||||
</tr>
|
||||
{{/foreach}}
|
||||
</tbody>
|
||||
</table>
|
||||
{{/if}}
|
||||
|
||||
<form method="post" action="">
|
||||
<p class="submit">
|
||||
{{:button type="submit" name="backward" label="Revenir à l'étape précédente" shape="left" class="main"}}
|
||||
{{:button type="submit" name="forward" label="Poursuivre" shape="right" class="main"}}
|
||||
</p>
|
||||
</form>
|
||||
221
exit_step3.html
Normal file
221
exit_step3.html
Normal file
|
|
@ -0,0 +1,221 @@
|
|||
{{* -*- brindille -*- *}}
|
||||
|
||||
{{:admin_header title="Immobilisation sortie du bilan" custom_css="./style.css" current="module_amortization"}}
|
||||
{{*
|
||||
Associer une écriture de cession à une immo créée et sortie du
|
||||
bilan avant la mise en service du module
|
||||
@param immo_doc_id : id du doc associé à l'immobilisation
|
||||
*}}
|
||||
|
||||
{{* données de l'immobilisation *}}
|
||||
{{:include file="_get_immo_data.html" immo_doc_id=$_GET.immo_doc_id keep="info_immo, ligne_immo, message"}}
|
||||
{{if $message != null}}
|
||||
{{:error message=$message}}
|
||||
{{/if}}
|
||||
|
||||
{{#form on="backward"}}
|
||||
{{:redirect to="exit_step2.html?immo_doc_id=%s"|args:$_GET.immo_doc_id}}
|
||||
{{/form}}
|
||||
|
||||
{{#form on="forward"}}
|
||||
{{:redirect to="exit_step4.html?immo_doc_id=%s"|args:$_GET.immo_doc_id}}
|
||||
{{/form}}
|
||||
|
||||
{{:assign label_immo=$info_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}}
|
||||
{{:assign trans_url="%s/acc/transactions/details.php?id=%s"|args:$admin_url:$ligne_immo.trans_id}}
|
||||
{{:assign date_immo=$info_immo.date_mes|or:$info_immo.date_achat|or:$ligne_immo.date_achat}}
|
||||
{{:assign montant_immo=$info_immo.amount|or:$ligne_immo.amount}}
|
||||
|
||||
{{* déduire le montant des écritures liées à l'immo courante au crédit du même compte *}}
|
||||
{{:include file="_get_credit_lines.html" immo_doc_id=$_GET.immo_doc_id keep="linked_immos, total_credits"}}
|
||||
{{:assign solde="%d-%d"|math:$montant_immo:$total_credits}}
|
||||
|
||||
{{* lister les amortissements liés à l'immobilisation *}}
|
||||
{{:include file="./_get_amort_lines.html" immo_doc_id=$_GET.immo_doc_id keep="linked_amort, total_amort"}}
|
||||
|
||||
{{* chercher des écritures de cession *}}
|
||||
{{:assign total_cession=0}}
|
||||
{{#select
|
||||
line.id as line_id,
|
||||
line.credit as amount,
|
||||
line.label as line_label,
|
||||
trans.id as trans_id,
|
||||
trans.date as date,
|
||||
trans.label as trans_label,
|
||||
trans.id_year as 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_accounts AS account ON line.id_account = account.id
|
||||
INNER JOIN acc_transactions AS trans ON line.id_transaction = trans.id
|
||||
WHERE account.code LIKE :code_cession_new OR account.code LIKE :code_cession_old
|
||||
;
|
||||
:code_cession_new = "757%"
|
||||
:code_cession_old = "775%"
|
||||
assign="line"
|
||||
}}
|
||||
{{* voir si l'écriture de cession est déjà liée à une immo *}}
|
||||
{{#select
|
||||
CASE WHEN links.id_related = :trans_id
|
||||
THEN links.id_transaction
|
||||
ELSE links.id_related
|
||||
END as linked_id
|
||||
FROM acc_transactions_links as links
|
||||
WHERE links.id_transaction = :trans_id OR links.id_related = :trans_id
|
||||
;
|
||||
:trans_id = $line.trans_id
|
||||
}}
|
||||
{{if $linked_id == $ligne_immo.trans_id}}
|
||||
{{:assign total_cession="%d+%d"|math:$total_cession:$line.amount}}
|
||||
{{:assign var="line.linked_id" value=$linked_id}}
|
||||
{{:assign var="linked_cessions." value=$line}}
|
||||
{{/if}}
|
||||
{{else}}
|
||||
{{:assign var="free_cessions." value=$line}}
|
||||
{{/select}}
|
||||
{{/select}}
|
||||
{{*:debug linked_cessions=$linked_cessions free_cessions=$free_cessions total_cession=$total_cession*}}
|
||||
|
||||
{{if $_GET.ok}}
|
||||
{{if $_GET.msg|match:"attach_cession"}}
|
||||
{{:assign msg="Écriture de cession attachée"}}
|
||||
{{elseif $_GET.msg|match:"detach_cession"}}
|
||||
{{:assign msg="Écriture de cession détachée"}}
|
||||
{{/if}}
|
||||
<p class="block confirm">{{$msg}}</p>
|
||||
{{/if}}
|
||||
|
||||
<div class="informations">
|
||||
<dl class="describe">
|
||||
<dt>Immobilisation</dt>
|
||||
<dd><span class="num"><a href="{{$trans_url}}">#{{$ligne_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><span class="money">{{$ligne_immo.amount|money_html|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">{{"%f"|math:$solde|money_currency_html:false|raw}}</dd>
|
||||
{{/if}}
|
||||
{{if $total_amort > 0}}
|
||||
<dt>Montant des amortissements</dt>
|
||||
<dd>{{$total_amort|money_currency_html:false|raw}}</dd>
|
||||
<dt>Valeur nette résiduelle</dt>
|
||||
<dd>{{"%d-%d"|math:$solde:$total_amort|money_currency_html:false|raw}}</dd>
|
||||
{{/if}}
|
||||
{{if $total_cession > 0}}
|
||||
<dt>Montant de la cession</dt>
|
||||
<dd>{{$total_cession|money_currency_html:false|raw}}</dd>
|
||||
{{/if}}
|
||||
</dl>
|
||||
</div>
|
||||
|
||||
{{if $linked_cessions != null}}
|
||||
<h3 class="ruler">Écriture de cession attachée à l'immobilisation</h3>
|
||||
<table class="list">
|
||||
<thead>
|
||||
<tr>
|
||||
<td class="num">N°</td>
|
||||
<td>Date</td>
|
||||
<td>Libellé</td>
|
||||
<td class="nombre">Montant</td>
|
||||
<td>N° compte</td>
|
||||
<td>Compte</td>
|
||||
<td class="actions"></td>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{{#foreach from=$linked_cessions item="line"}}
|
||||
{{* données de l'écriture *}}
|
||||
{{:assign trans_url="%s/acc/transactions/details.php?id=%s"|args:$admin_url:$line.trans_id}}
|
||||
{{:assign compte_url="%s/acc/accounts/journal.php?id=%s&year=%s"|args:$admin_url:$line.account_id:$line.year}}
|
||||
<tr>
|
||||
<td class="num"><a href="{{$trans_url}}">#{{$line.trans_id}}</a></td>
|
||||
<td>{{$line.date|date_short}}</td>
|
||||
<td>
|
||||
{{if $line.line_label != null}}
|
||||
{{$line.line_label}}
|
||||
{{if $line.trans_label != $line.line_label}}
|
||||
— {{$line.trans_label}}
|
||||
{{/if}}
|
||||
{{else}}
|
||||
{{$line.trans_label}}
|
||||
{{/if}}
|
||||
</td>
|
||||
<td class="money">{{"%f"|math:$line.amount|money_html:false|raw}}</td>
|
||||
<td><a href="{{$compte_url}}">{{$line.account_code}}</a></td>
|
||||
<td>{{$line.account_label}}</td>
|
||||
<td>
|
||||
{{:linkbutton label="Détacher" href="detach_cession.html?immo_doc_id=%s&cession_line_id=%s&from=exit"|args:$_GET.immo_doc_id:$line.line_id shape="minus"}}
|
||||
</td>
|
||||
</tr>
|
||||
{{/foreach}}
|
||||
</tbody>
|
||||
</table>
|
||||
{{elseif $free_cessions}}
|
||||
<p class="block alert">
|
||||
Vous pouvez attacher une écriture de cession à l'immobilisation
|
||||
</p>
|
||||
{{else}}
|
||||
<p class="block alert">
|
||||
Aucune écriture de cession... que faire ?
|
||||
</p>
|
||||
{{/if}}
|
||||
|
||||
|
||||
{{if $free_cessions}}
|
||||
<h3 class="ruler">Autres écritures de cession</h3>
|
||||
<table class="list">
|
||||
<thead>
|
||||
<tr>
|
||||
<td class="num">N°</td>
|
||||
<td>Date</td>
|
||||
<td>Libellé</td>
|
||||
<td class="nombre">Montant</td>
|
||||
<td>N° compte</td>
|
||||
<td>Compte</td>
|
||||
<td class="actions"></td>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
|
||||
{{#foreach from=$free_cessions item="line"}}
|
||||
{{:assign cession_url="%s/acc/transactions/details.php?id=%s"|args:$admin_url:$line.trans_id}}
|
||||
{{:assign compte_url="%s/acc/accounts/journal.php?id=%s&year=%s"|args:$admin_url:$line.account_id:$line.year}}
|
||||
<tr>
|
||||
<td class="num"><a href="{{$cession_url}}">#{{$line.trans_id}}</a></td>
|
||||
<td>{{$line.date|date_short}}</td>
|
||||
<td>
|
||||
{{if $line.line_label != null}}
|
||||
{{$line.line_label}}
|
||||
{{if $line.trans_label != $line.line_label}}
|
||||
— {{$line.trans_label}}
|
||||
{{/if}}
|
||||
{{else}}
|
||||
{{$line.trans_label}}
|
||||
{{/if}}
|
||||
</td>
|
||||
<td class="money">{{"%f"|math:$line.amount|money_html:false|raw}}</td>
|
||||
<td><a href="{{$compte_url}}">{{$line.account_code}}</a></td>
|
||||
<td>{{$line.account_label}}</td>
|
||||
<td>
|
||||
{{:linkbutton label="Attacher" href="attach_cession.html?immo_doc_id=%s&cession_line_id=%s&from=exit"|args:$_GET.immo_doc_id:$line.line_id shape="plus"}}
|
||||
</td>
|
||||
</tr>
|
||||
{{/foreach}}
|
||||
</tbody>
|
||||
</table>
|
||||
{{/if}}
|
||||
|
||||
<form method="post" action="">
|
||||
<p class="submit">
|
||||
{{:button type="submit" name="backward" label="Revenir à l'étape précédente" shape="left" class="main"}}
|
||||
{{:button type="submit" name="forward" label="Poursuivre" shape="right" class="main"}}
|
||||
</p>
|
||||
</form>
|
||||
288
exit_step4.html
Normal file
288
exit_step4.html
Normal file
|
|
@ -0,0 +1,288 @@
|
|||
{{* -*- brindille -*- *}}
|
||||
|
||||
{{*
|
||||
Associer les différentes écritures à une immo créée et sortie du
|
||||
bilan avant la mise en service du module
|
||||
@param immo_doc_id : id du doc associé à l'immobilisation
|
||||
*}}
|
||||
|
||||
{{* données de l'immobilisation *}}
|
||||
{{:include file="_get_immo_data.html" immo_doc_id=$_GET.immo_doc_id keep="info_immo, ligne_immo, message"}}
|
||||
{{if $message != null}}
|
||||
{{:error message=$message}}
|
||||
{{/if}}
|
||||
|
||||
{{#form on="backward"}}
|
||||
{{:redirect to="exit_step3.html?immo_doc_id=%s"|args:$_GET.immo_doc_id}}
|
||||
{{/form}}
|
||||
|
||||
{{#form on="validate"}}
|
||||
{{* mettre à jour l'état de l'immobilisation *}}
|
||||
{{:save
|
||||
key=$info_immo.key
|
||||
status="archived"
|
||||
}}
|
||||
{{:redirect to="index.html?type_immo=archived"}}
|
||||
{{/form}}
|
||||
|
||||
{{#form on="finish"}}
|
||||
{{:redirect to="index.html?type_immo=managed"}}
|
||||
{{/form}}
|
||||
|
||||
{{:assign label_immo=$info_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}}
|
||||
{{:assign trans_url="%s/acc/transactions/details.php?id=%s"|args:$admin_url:$ligne_immo.trans_id}}
|
||||
{{:assign date_immo=$info_immo.date_mes|or:$info_immo.date_achat|or:$ligne_immo.date_achat}}
|
||||
{{:assign montant_immo=$info_immo.amount|or:$ligne_immo.amount}}
|
||||
|
||||
{{* déduire le montant des écritures liées à l'immo courante au crédit du même compte *}}
|
||||
{{:include file="_get_credit_lines.html" immo_doc_id=$_GET.immo_doc_id keep="linked_immos, total_credits"}}
|
||||
{{:assign solde="%d-%d"|math:$montant_immo:$total_credits}}
|
||||
|
||||
{{* lister les amortissements liés à l'immobilisation *}}
|
||||
{{:include file="./_get_amort_lines.html" immo_doc_id=$_GET.immo_doc_id keep="linked_amort, total_amort"}}
|
||||
|
||||
{{* chercher une écriture de sortie de bilan associée *}}
|
||||
{{#load type="exit_link" where="$$.immo_doc_id = :immo_doc_id" :immo_doc_id=$info_immo.id assign="exit_info"}}
|
||||
{{/load}}
|
||||
{{if $exit_info != null}}
|
||||
{{#select
|
||||
trans.id as trans_id,
|
||||
trans.label as trans_label,
|
||||
trans.date as date,
|
||||
line.id as line_id,
|
||||
line.label as line_label,
|
||||
line.credit as amount,
|
||||
acc.id as account_id,
|
||||
acc.code as account_code,
|
||||
acc.label as account_label
|
||||
FROM acc_transactions AS trans
|
||||
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 line.id = :exit_line_id;
|
||||
:exit_line_id = $exit_info.exit_line_id
|
||||
assign="exit_line"
|
||||
}}
|
||||
{{/select}}
|
||||
{{/if}}
|
||||
|
||||
{{*
|
||||
chercher des écritures au crédit du compte de l'immo sans doc associé
|
||||
- line.credit < ligne_immo.amount => peut-être un avoir
|
||||
- line.credit = ligne_immo.amount - avoirs => écriture de sortie du bilan
|
||||
*}}
|
||||
{{#select
|
||||
trans.id as trans_id,
|
||||
trans.label as trans_label,
|
||||
trans.date as date,
|
||||
trans.id_year as year,
|
||||
line.id as credit_line_id,
|
||||
line.label as line_label,
|
||||
line.credit as amount,
|
||||
acc.id as account_id,
|
||||
acc.code as account_code,
|
||||
acc.label as account_label
|
||||
FROM acc_transactions AS trans
|
||||
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
|
||||
LEFT JOIN module_data_amortization AS mda ON json_extract(mda.document, '$.amort_line_id') = line.id
|
||||
WHERE
|
||||
acc.code = :acc_code
|
||||
AND line.credit > 0
|
||||
AND credit_line_id NOT IN (
|
||||
SELECT json_extract(credit_link.document, '$.credit_line_id') AS line_id FROM !table as credit_link
|
||||
WHERE json_extract(credit_link.document, '$.type') == "credit_link"
|
||||
UNION
|
||||
SELECT json_extract(exit_link.document, '$.exit_line_id') AS line_id FROM !table as exit_link
|
||||
WHERE json_extract(exit_link.document, '$.type') == "exit_link"
|
||||
)
|
||||
;
|
||||
:acc_code=$ligne_immo.account_code
|
||||
!table =$module.table
|
||||
assign="credit_line"
|
||||
}}
|
||||
{{if $credit_line.amount == $solde}}
|
||||
{{:assign var="exit_lines." value=$credit_line}}
|
||||
{{/if}}
|
||||
{{/select}}
|
||||
|
||||
{{* déterminer le compte d'amortissement en fonction du compte d'immobilisation *}}
|
||||
{{:include
|
||||
file="./_get_amort_code.html"
|
||||
code_immo=$ligne_immo.account_code
|
||||
keep="code_amort"
|
||||
}}
|
||||
|
||||
{{* chercher des écritures d'amortissement correspondant au compte d'une immo sans doc associé *}}
|
||||
{{* TODO écritures d'amort pas entièrement affectées *}}
|
||||
{{#select
|
||||
line.id as amort_line_id,
|
||||
line.credit as amort_amount,
|
||||
line.label as line_label,
|
||||
trans.id as amort_trans_id,
|
||||
trans.date as date,
|
||||
trans.label as trans_label,
|
||||
trans.id_year as 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_accounts AS account ON line.id_account = account.id
|
||||
INNER JOIN acc_transactions AS trans ON line.id_transaction = trans.id
|
||||
WHERE
|
||||
account.code = :code_amort
|
||||
AND line.credit > 0
|
||||
AND (NOT trans.status & 16)
|
||||
AND trans.date >= :immo_date
|
||||
;
|
||||
:code_amort = $code_amort
|
||||
:immo_date=$date_immo
|
||||
assign="amort_line"
|
||||
}}
|
||||
{{* 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_line.amort_line_id|intval
|
||||
assign="amort_link"
|
||||
}}
|
||||
{{if $amort_link.amount == null || $amort_link.amount == 0}}
|
||||
{{:assign amort_amount=$amort_line.amort_amount}}
|
||||
{{:assign keep_amort=false}}
|
||||
{{else}}
|
||||
{{:assign amort_amount="%d+%d"|math:$amort_amount:$amort_link.amount}}
|
||||
{{/if}}
|
||||
{{else}}
|
||||
{{* pas de ligne d'immo liée à cette ligne d'amort => garder cette ligne d'amortissement *}}
|
||||
{{/load}}
|
||||
{{if $keep_amort && $amort_amount < $amort_line.amort_amount}}
|
||||
{{:assign var="free_amort_lines." value=$amort_line}}
|
||||
{{/if}}
|
||||
{{/select}}
|
||||
|
||||
{{:admin_header title="Immobilisation sortie du bilan" custom_css="./style.css" current="module_amortization"}}
|
||||
|
||||
{{if $_GET.ok}}
|
||||
{{if $_GET.msg|match:"attach_exit"}}
|
||||
{{:assign msg="Écriture de sortie de bilan attachée"}}
|
||||
{{elseif $_GET.msg|match:"detach_exit"}}
|
||||
{{:assign msg="Écriture de sortie de bilan détachée"}}
|
||||
{{/if}}
|
||||
<p class="block confirm">{{$msg}}</p>
|
||||
{{/if}}
|
||||
|
||||
<div class="informations">
|
||||
<dl class="describe">
|
||||
<dt>Immobilisation</dt>
|
||||
<dd><span class="num"><a href="{{$trans_url}}">#{{$ligne_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><span class="money">{{$ligne_immo.amount|money_html|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">{{"%f"|math:$solde|money_currency_html:false|raw}}</dd>
|
||||
{{/if}}
|
||||
{{if $total_amort > 0}}
|
||||
<dt>Montant des amortissements</dt>
|
||||
<dd>{{$total_amort|money_currency_html:false|raw}}</dd>
|
||||
<dt>Valeur nette résiduelle</dt>
|
||||
<dd>{{"%d-%d"|math:$solde:$total_amort|money_currency_html:false|raw}}</dd>
|
||||
{{/if}}
|
||||
</dl>
|
||||
</div>
|
||||
|
||||
{{if $exit_line != null}}
|
||||
<h3 class="ruler">Écriture de sortie du bilan attachée à l'immobilisation</h3>
|
||||
<table class="list">
|
||||
<thead>
|
||||
<tr>
|
||||
<td class="num">N°</td>
|
||||
<td>Date</td>
|
||||
<td>Libellé</td>
|
||||
<td class="nombre">Montant</td>
|
||||
<td>N° compte</td>
|
||||
<td>Compte</td>
|
||||
<td class="actions"></td>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td class="num"><a href="{{$trans_url}}">#{{$exit_line.trans_id}}</a></td>
|
||||
<td>{{$exit_line.date|date_short}}</td>
|
||||
<td>
|
||||
{{if $exit_line.line_label != null}}
|
||||
{{$exit_line.line_label}}
|
||||
{{else}}
|
||||
{{$exit_line.trans_label}}
|
||||
{{/if}}
|
||||
</td>
|
||||
<td class="money">{{"%f"|math:$exit_line.amount|money_html:false|raw}}</td>
|
||||
<td><a href="{{$compte_url}}">{{$exit_line.account_code}}</a></td>
|
||||
<td>{{$exit_line.account_label}}</td>
|
||||
<td>
|
||||
{{:linkbutton label="Détacher" href="detach_exit.html?immo_doc_id=%s&exit_line_id=%s&from=exit"|args:$_GET.immo_doc_id:$exit_line.line_id shape="minus"}}
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
{{elseif $exit_lines}}
|
||||
<p class="block alert">
|
||||
Vous pouvez attacher une écriture de sortie du bilan à l'immobilisation
|
||||
</p>
|
||||
{{/if}}
|
||||
|
||||
{{if $exit_lines}}
|
||||
<h3 class="ruler">Écritures non rattachées</h3>
|
||||
<table class="list">
|
||||
<thead>
|
||||
<tr>
|
||||
<td class="num">N°</td>
|
||||
<td>Date</td>
|
||||
<td>Libellé</td>
|
||||
<td class="nombre">Montant</td>
|
||||
<td>N° compte</td>
|
||||
<td>Compte</td>
|
||||
<td class="actions"></td>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
|
||||
{{#foreach from=$exit_lines item="line"}}
|
||||
{{:assign exit_url="%s/acc/transactions/details.php?id=%s"|args:$admin_url:$line.trans_id}}
|
||||
{{:assign compte_url="%s/acc/accounts/journal.php?id=%s&year=%s"|args:$admin_url:$line.account_id:$line.year}}
|
||||
<tr>
|
||||
<td class="num"><a href="{{$exit_url}}">#{{$line.trans_id}}</a></td>
|
||||
<td>{{$line.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.amount|money_html:false|raw}}</td>
|
||||
<td><a href="{{$compte_url}}">{{$line.account_code}}</a></td>
|
||||
<td>{{$line.account_label}}</td>
|
||||
<td>
|
||||
{{:linkbutton label="Attacher" href="attach_exit.html?immo_doc_id=%s&exit_line_id=%s&from=exit"|args:$_GET.immo_doc_id:$line.credit_line_id shape="plus"}}
|
||||
</td>
|
||||
</tr>
|
||||
{{/foreach}}
|
||||
</tbody>
|
||||
</table>
|
||||
{{elseif $exit_line == null}}
|
||||
<p class="block alert">Aucune écriture de sortie du bilan. Vérifiez l'attachement d'écriture d'avoir.</p>
|
||||
{{/if}}
|
||||
|
||||
<form method="post" action="">
|
||||
<p class="submit">
|
||||
{{:button type="submit" name="backward" label="Revenir à l'étape précédente" shape="left" class="main"}}
|
||||
{{if $exit_line}}
|
||||
{{:button type="submit" name="validate" label="Terminer" shape="check" class="main"}}
|
||||
{{else}}
|
||||
{{:button type="submit" name="finish" label="Terminer" shape="export" class="main"}}
|
||||
{{/if}}
|
||||
</p>
|
||||
</form>
|
||||
|
|
@ -30,7 +30,7 @@
|
|||
{{:assign status="ignored"}}
|
||||
{{:save
|
||||
key=""|uuid
|
||||
validate_schema="schema.json"
|
||||
validate_schema="asset.schema.json"
|
||||
type="immo"
|
||||
line=$_GET.immo_line_id|intval
|
||||
duration=$duration
|
||||
|
|
|
|||
22
index.html
22
index.html
|
|
@ -14,16 +14,18 @@
|
|||
{{elseif $type_immo == "archived"}}
|
||||
{{:admin_header title="Immobilisations archivées" custom_css="./style.css" current="module_amortization"}}
|
||||
{{elseif $type_immo == "other"}}
|
||||
{{:admin_header title="Autres immobilisations" custom_css="./style.css" current="module_amortization"}}
|
||||
{{:admin_header title="Immobilisations à classer" custom_css="./style.css" current="module_amortization"}}
|
||||
{{elseif $type_immo == "unfinished"}}
|
||||
{{:admin_header title="Immobilisations en cours de constitution" custom_css="./style.css" current="module_amortization"}}
|
||||
{{:admin_header title="Immobilisations en cours de constitution" custom_css="./style.css" current="module_amortization" subcurrent="unfinished"}}
|
||||
{{/if}}
|
||||
|
||||
{{:include file="_nav.html" current="index" subcurrent="%s"|args:$type_immo}}
|
||||
{{:include file="_nav.html" current="index" subcurrent=$type_immo}}
|
||||
|
||||
{{if $_GET.ok}}
|
||||
{{if $_GET.msg|match:"immobilisation"}}
|
||||
{{:assign msg="Immobilisation enregistrée"}}
|
||||
{{elseif $_GET.msg|match:"suppr_infos"}}
|
||||
{{:assign msg="Informations supprimées"}}
|
||||
{{elseif $_GET.msg|match:"infos"}}
|
||||
{{:assign msg="Informations enregistrées"}}
|
||||
{{/if}}
|
||||
|
|
@ -32,18 +34,8 @@
|
|||
<p class="block error">Échec enregistrement immobilisation</p>
|
||||
{{/if}}
|
||||
|
||||
{{#load type="immo"}}
|
||||
{{* supprimer les documents sans écriture associée *}}
|
||||
{{#select
|
||||
line.id as line_id
|
||||
FROM acc_transactions_lines as line
|
||||
WHERE line.id = :line_id;
|
||||
:line_id = $line
|
||||
}}
|
||||
{{else}}
|
||||
{{:delete key=$key}}
|
||||
{{/select}}
|
||||
{{/load}}
|
||||
{{* supprimer les documents sans écriture associée *}}
|
||||
{{:include file="_remove_orphan_docs.tpl"}}
|
||||
|
||||
{{if $type_immo == "other"}}
|
||||
{{:include file="_immobilisations_autres.html"}}
|
||||
|
|
|
|||
56
link.schema.json
Normal file
56
link.schema.json
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
{
|
||||
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
||||
"description": "Schéma des liens entre écritures",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"type": {
|
||||
"type": "string",
|
||||
"enum": ["amort_link", "credit_link", "cession_link", "exit_link"]
|
||||
},
|
||||
"immo_doc_id" : {
|
||||
"description": "identifiant du document d'immobilisation associé",
|
||||
"type" : "integer",
|
||||
"exclusiveMinimum": 0
|
||||
},
|
||||
"amort_line_id" : {
|
||||
"description": "ligne d'amortissement associée à l'immobilisation",
|
||||
"type": "integer",
|
||||
"exclusiveMinimum": 0
|
||||
},
|
||||
"credit_line_id": {
|
||||
"description": "ligne au crédit du compte de l'immobilisation",
|
||||
"type": "integer",
|
||||
"exclusiveMinimum": 0
|
||||
},
|
||||
"exit_line_id": {
|
||||
"description": "ligne de sortie du bilan de l'immobilisation",
|
||||
"type": "integer",
|
||||
"exclusiveMinimum": 0
|
||||
},
|
||||
"cession_line_id": {
|
||||
"description": "ligne de cession de l'immobilisation",
|
||||
"type": "integer",
|
||||
"exclusiveMinimum": 0
|
||||
},
|
||||
"amount": {
|
||||
"description": "montant de la ligne d'amortissement ou de crédit",
|
||||
"type": ["number", "null"]
|
||||
},
|
||||
"created" : {
|
||||
"description" : "vrai si amortissement créé dans le module",
|
||||
"type" : ["boolean", "null"]
|
||||
}
|
||||
},
|
||||
"required": ["type", "immo_doc_id"],
|
||||
"if": {"properties": {"type": {"const": "amort_link"}}, "required": ["type"]},
|
||||
"then": {"required": ["amort_line_id"]},
|
||||
"else":
|
||||
"if": {"properties": {"type": {"const": "credit_link"}}, "required": ["type"]},
|
||||
"then": {"required": ["credit_line_id"]},
|
||||
"else":
|
||||
"if": {"properties": {"type": {"const": "cession_link"}}, "required": ["type"]},
|
||||
"then": {"required": ["cession_line_id"]},
|
||||
"else":
|
||||
"if": {"properties": {"type": {"const": "exit_link"}}, "required": ["type"]},
|
||||
"then": {"required": ["exit_line_id"]},
|
||||
}
|
||||
118
link_immo.html
Normal file
118
link_immo.html
Normal file
|
|
@ -0,0 +1,118 @@
|
|||
{{* -*- 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
|
||||
*}}
|
||||
|
||||
{{:include file="_get_immo_data.html" immo_doc_id=$_GET.immo_doc_id|intval keep="info_immo, ligne_immo, message"}}
|
||||
{{if $message != null}}
|
||||
{{:error message=$message}}
|
||||
{{/if}}
|
||||
{{:assign label_immo=$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}}
|
||||
|
||||
{{*
|
||||
lister les écritures au crédit du compte de l'immobilisation
|
||||
*}}
|
||||
{{#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_line_id NOT IN (
|
||||
SELECT json_extract(link.document, '$.credit_line_id') AS credit_line_id FROM !table as link
|
||||
WHERE json_extract(link.document, '$.type') == "credit_link")
|
||||
ORDER BY trans.date, trans.label;
|
||||
:account_code = $ligne_immo.account_code
|
||||
!table =$module.table
|
||||
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.trans_id}}</a></span> {{$label_immo}}</dd>
|
||||
<dt>Montant</dt>
|
||||
<dd class="money strong">{{"%f"|math:$ligne_immo.amount|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_credit.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}}
|
||||
206
modify_infos.html
Normal file
206
modify_infos.html
Normal file
|
|
@ -0,0 +1,206 @@
|
|||
{{* -*- brindille -*- *}}
|
||||
|
||||
{{*
|
||||
@param immo_doc_id
|
||||
*}}
|
||||
|
||||
{{:include file="_get_immo_data.html" immo_doc_id=$_GET.immo_doc_id|intval keep="info_immo, ligne_immo, message"}}
|
||||
{{if $message != null}}
|
||||
{{:error message=$message}}
|
||||
{{/if}}
|
||||
|
||||
{{:assign montant_immo=$info_immo.amount|or:$ligne_immo.amount}}
|
||||
{{:assign immo_label=$info_immo.label|or:$ligne_immo.trans_label}}
|
||||
{{if $ligne_immo.line_label != null && $ligne_immo.line_label != $immo_label}}
|
||||
{{:assign immo_label=$immo_label|cat:" — "|cat:$ligne_immo.line_label}}
|
||||
{{/if}}
|
||||
|
||||
{{* déduire le montant des écritures liées à l'immo courante au crédit du même compte *}}
|
||||
{{:include file="_get_credit_lines.html" immo_doc_id=$_GET.immo_doc_id keep="linked_immos, total_credits"}}
|
||||
{{:assign solde="%d-%d"|math:$montant_immo:$total_credits}}
|
||||
|
||||
{{:assign autres_amount=0}}
|
||||
{{#load
|
||||
type="immo"
|
||||
where="$$.line = :line_id AND id != :doc_id"
|
||||
:line_id = $info_immo.line
|
||||
:doc_id = $info_immo.id
|
||||
}}
|
||||
{{:assign autres_amount="%d+%d"|math:$autres_amount:$amount}}
|
||||
{{/load}}
|
||||
{{:assign max_disponible="%d-%d"|math:$ligne_immo.amount:$autres_amount}}
|
||||
|
||||
{{* traiter la saisie *}}
|
||||
{{#form on="save"}}
|
||||
{{if $_POST.date_achat|parse_date > $ligne_immo.date_achat}}
|
||||
{{:assign da=$ligne_immo.date_achat|date_short}}
|
||||
{{:error message="Erreur : la date d'achat (%s) ne peut être postérieure à la date de l'écriture d'immobilisation (%s)"|args:$_POST.date_achat:$da}}
|
||||
{{/if}}
|
||||
|
||||
{{if $_POST.date_achat == null || $_POST.date_achat|parse_date == $info_immo.date_achat}}
|
||||
{{:assign date_achat=$info_immo.date_achat}}
|
||||
{{elseif $_POST.date_achat|parse_date == $ligne_immo.date_achat}}
|
||||
{{:assign date_achat=null}}
|
||||
{{else}}
|
||||
{{:assign date_achat=$_POST.date_achat|parse_date}}
|
||||
{{/if}}
|
||||
|
||||
{{* TODO : simplifier ? *}}
|
||||
{{if $_POST.date_mes == null || $_POST.date_mes|parse_date == $info_immo.date_mes}}
|
||||
{{:assign date_mes=$info_immo.date_mes}}
|
||||
{{elseif $_POST.date_mes|parse_date == $info_immo.date_achat}}
|
||||
{{:assign date_mes=null}}
|
||||
{{elseif $_POST.date_mes|parse_date == $ligne_immo.date_achat}}
|
||||
{{if $info_immo.date_achat == null}}
|
||||
{{:assign date_mes=null}}
|
||||
{{else}}
|
||||
{{:assign date_mes=$ligne_immo.date_achat}}
|
||||
{{/if}}
|
||||
{{else}}
|
||||
{{:assign date_mes=$_POST.date_mes|parse_date}}
|
||||
{{:assign date_achat_comp=$ligne_immo.date_achat}}
|
||||
{{if $date_achat != null}}
|
||||
{{:assign date_achat_comp=$date_achat}}
|
||||
{{/if}}
|
||||
{{if $date_mes < $date_achat_comp}}
|
||||
{{:assign da=$date_achat_comp|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}}
|
||||
|
||||
{{: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}}
|
||||
{{else}}
|
||||
{{:assign libelle=null}}
|
||||
{{/if}}
|
||||
|
||||
{{:assign montant=null}}
|
||||
{{if $_POST.montant == null || $_POST.montant|money_int == 0 || $_POST.montant|money_int == $info_immo.amount}}
|
||||
{{:assign montant=$info_immo.amount}}
|
||||
{{else}}
|
||||
{{:assign montant=$_POST.montant|money_int}}
|
||||
{{if $montant < 0 || $montant > $max_disponible}}
|
||||
{{:assign montant_aff="%f"|math:$montant|money_currency:false}}
|
||||
{{:assign max_aff="%f"|math:$max_disponible|money_currency:false}}
|
||||
{{:error message="Le montant (%s) doit être positif et ne peut être supérieur à %s"|args:$montant_aff:$max_aff}}
|
||||
{{/if}}
|
||||
{{/if}}
|
||||
|
||||
{{:assign status="managed"}}
|
||||
|
||||
{{* écritures de crédit *}}
|
||||
{{#foreach from=$linked_immos item="line"}}
|
||||
{{if ! $_POST.credit_id|has:$line.trans_id}}
|
||||
{{:assign var="docs_to_remove." value=$line.doc}}
|
||||
{{:assign var="links_to_remove." value=$line.trans_id}}
|
||||
{{/if}}
|
||||
{{/foreach}}
|
||||
|
||||
{{if $docs_to_remove != null}}
|
||||
{{:assign remove_set=$docs_to_remove|implode:","}}
|
||||
{{:assign remove_set="("|cat:$remove_set|cat:")"}}
|
||||
{{:delete where="id IN %s"|args:$remove_set}}
|
||||
|
||||
{{* idem avec acc_transactions_links *}}
|
||||
{{#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.trans_id
|
||||
}}
|
||||
{{if ! $linked_id|in:$links_to_remove}}
|
||||
{{:assign var="linked_transactions." value=$linked_id}}
|
||||
{{/if}}
|
||||
{{/select}}
|
||||
|
||||
{{* Enregistrer les liaisons *}}
|
||||
{{:api
|
||||
method="POST"
|
||||
path="accounting/transaction/%s/transactions"|args:$ligne_immo.trans_id
|
||||
assign="result"
|
||||
assign_code="result_code"
|
||||
transactions=$linked_transactions
|
||||
}}
|
||||
{{/if}}
|
||||
|
||||
{{* enregistrer les infos de l'immobilisation *}}
|
||||
{{:save
|
||||
key=$info_immo.key
|
||||
validate_schema="asset.schema.json"
|
||||
type="immo"
|
||||
line=$info_immo.line
|
||||
duration=$duration
|
||||
label=$libelle
|
||||
amount=$montant
|
||||
date_achat=$date_achat
|
||||
date_mes=$date_mes
|
||||
status=$status
|
||||
assign_new_id="new_id"
|
||||
}}
|
||||
|
||||
{{:assign type_immo="managed"}}
|
||||
{{:redirect force="amortization.html?immo_doc_id=%s&type_immo=%s&ok=1&msg=modif"|args:$_GET.immo_doc_id:$type_immo}}
|
||||
|
||||
{{/form}}
|
||||
|
||||
{{:admin_header title="Modifier l'immobilisation" custom_css="./style.css" current="module_amortization"}}
|
||||
{{if ! $dialog}}
|
||||
{{:include file="_nav.html" current="index" subcurrent="%s"|args:$_GET.type_immo subsubcurrent="parameter"}}
|
||||
{{/if}}
|
||||
{{:form_errors}}
|
||||
|
||||
{{:assign choix_defaut=$_GET.type_immo}}
|
||||
|
||||
{{*
|
||||
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.trans_id}}
|
||||
<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.trans_id}}</a></span> {{$immo_label}}</dd>
|
||||
<dt>Compte d'immobilisation</dt>
|
||||
<dd>{{$ligne_immo.account_code}} — {{$ligne_immo.account_label}}
|
||||
<dt>Montant</dt>
|
||||
<dd class="money strong">{{"%f"|math:$montant_immo|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>Date de l'écriture d'immobilisation</dt>
|
||||
<dd>{{$ligne_immo.date_achat|date_short}}</dd>
|
||||
</dl>
|
||||
</div>
|
||||
|
||||
<form method="post" action="">
|
||||
<fieldset>
|
||||
<legend>Paramètres de l'amortissement</legend>
|
||||
<dl>
|
||||
{{:input type="number" name="duree" label="Durée d'amortissement" min=1 default=$info_immo.duration suffix="année(s)"}}
|
||||
{{if $info_immo.amount != null}}
|
||||
{{:assign max_aff="%f"|math:$max_disponible|money_currency:false}}
|
||||
{{:input type="money" name="montant" label="Montant de l'immobilisation" default=$montant_immo help="Montant maximum : %s"|args:$max_aff}}
|
||||
{{/if}}
|
||||
{{:input type="date" name="date_achat" label="Date d'acquisition" default=$info_immo.date_achat help="si différente de la date de l'écriture d'immobilisation"}}
|
||||
{{:input type="date" name="date_mes" label="Date de mise en service" default=$info_immo.date_mes help="si différente de la date d'acquisition"}}
|
||||
{{:input type="text" name="libelle" label="Libellé" default=$info_immo.label help="si différent du libellé de l'écriture d'immobilisation"}}
|
||||
</dl>
|
||||
</fieldset>
|
||||
<p class="submit">
|
||||
{{:button type="submit" name="save" label="Enregistrer" shape="right" class="main"}}
|
||||
</p>
|
||||
</form>
|
||||
|
||||
{{:admin_footer}}
|
||||
|
|
@ -3,98 +3,34 @@
|
|||
{{*
|
||||
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
|
||||
*}}
|
||||
|
||||
{{* récupérer les infos de l'immobilisation *}}
|
||||
{{#select
|
||||
trans.label as 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
|
||||
}}
|
||||
{{else}}
|
||||
{{:error message="Immobilisation %s non trouvée"|args:$_GET.immo_line_id}}
|
||||
{{/select}}
|
||||
|
||||
{{:include file="_get_config.html" keep="module.config"}}
|
||||
|
||||
{{if $_POST.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"}}
|
||||
@param immo_doc_id id du doc d'immo associé
|
||||
*}}
|
||||
{{* données de l'immobilisation *}}
|
||||
{{:include file="_get_immo_data.html" immo_doc_id=$_GET.immo_doc_id|intval keep="info_immo, ligne_immo, message"}}
|
||||
{{if $message != null}}
|
||||
{{:error message=$message}}
|
||||
{{/if}}
|
||||
|
||||
{{* lister les écritures d'amortissement *}}
|
||||
{{#select
|
||||
line.id as amort_line_id,
|
||||
line.id_transaction as amort_trans_id,
|
||||
line.credit as amort_amount,
|
||||
line.label as line_label,
|
||||
trans.date as trans_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 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"
|
||||
}}
|
||||
{{:assign label_immo=$info_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}}
|
||||
|
||||
{{* 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
|
||||
{{if $_GET.filter}}
|
||||
{{* déterminer le compte d'amortissement en fonction du compte d'immobilisation *}}
|
||||
{{:include
|
||||
file="./_get_amort_code.html"
|
||||
code_immo=$ligne_immo.account_code
|
||||
keep="code_amort"
|
||||
}}
|
||||
{{* 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}}
|
||||
{{else}}
|
||||
{{:assign keep=false}}
|
||||
{{/load}}
|
||||
{{if $keep}}
|
||||
{{:assign var="autres_amortissements." value=$amort}}
|
||||
{{/if}}
|
||||
{{else}}
|
||||
{{:assign var="autres_amortissements." value=$amort}}
|
||||
{{/select}}
|
||||
{{/select}}
|
||||
{{:assign filter_condition="account.code = "|cat:$code_amort}}
|
||||
{{else}}
|
||||
{{:assign account_filter="28%"|quote_sql}}
|
||||
{{:assign filter_condition="account.code LIKE "|cat:$account_filter}}
|
||||
{{/if}}
|
||||
|
||||
{{* lister les amortissements non rattachés à une immo *}}
|
||||
{{:include file="./_get_free_amort.html" filter_condition=$filter_condition keep="free_amort_lines"}}
|
||||
|
||||
{{:admin_header title="Amortissements non rattachés" custom_css="./style.css" current="module_amortization"}}
|
||||
|
||||
|
|
@ -103,60 +39,81 @@
|
|||
{{:include
|
||||
file="_nav.html"
|
||||
current="index"
|
||||
subcurrent="other"
|
||||
subcurrent="managed"
|
||||
subsubcurrent="amortization"
|
||||
type_immo="other"
|
||||
autres_amort=$autres_amortissements
|
||||
type_immo="managed"
|
||||
autres_amort=$free_amort_lines
|
||||
}}
|
||||
{{/if}}
|
||||
|
||||
{{if $_POST.unhide != null}}
|
||||
{{:assign checked="checked"}}
|
||||
{{/if}}
|
||||
<nav class="tabs">
|
||||
<ul>
|
||||
<li {{if $_GET.filter}}class="current"{{/if}}>
|
||||
<a href="other_amortizations.html?immo_doc_id={{$_GET.immo_doc_id}}{{if $dialog}}&_dialog{{/if}}&filter=true">
|
||||
Amortissements du compte {{$code_amort}}
|
||||
</a>
|
||||
</li>
|
||||
<li {{if ! $_GET.filter}}class="current"{{/if}}>
|
||||
<a href="other_amortizations.html?immo_doc_id={{$_GET.immo_doc_id}}{{if $dialog}}&_dialog{{/if}}">
|
||||
Tous les amortissements
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
</nav>
|
||||
|
||||
<form method="post" action="">
|
||||
<fieldset>
|
||||
{{:input type="checkbox" value=1 name="unhide" checked="%s"|args:$checked label="Afficher toutes les écritures" }}
|
||||
</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>
|
||||
<th>N°</th>
|
||||
<th>Date</th>
|
||||
<th class="nombre">Montant</th>
|
||||
<th>Libellé</th>
|
||||
<th class="nombre">Montant</th>
|
||||
<th>N° compte</th>
|
||||
<th>Compte</th>
|
||||
<th class="actions"></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{{#foreach from=$autres_amortissements 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}}
|
||||
{{#foreach from=$free_amort_lines item="line"}}
|
||||
{{*
|
||||
{{if $_GET.filter && $line.account_code != $code_amort}}
|
||||
{{:continue}}
|
||||
{{/if}}
|
||||
*}}
|
||||
{{:assign trans_url="%s/acc/transactions/details.php?id=%s"|args:$admin_url:$line.trans_id}}
|
||||
{{:assign compte_url="%s/acc/accounts/journal.php?id=%s&year=%s"|args:$admin_url:$line.account_id:$line.year}}
|
||||
<tr>
|
||||
<td class="num"><a href="{{$trans_url}}">#{{$line.amort_trans_id}}</a></td>
|
||||
<td class="num"><a href="{{$trans_url}}">#{{$line.trans_id}}</a></td>
|
||||
<td>{{$line.trans_date|date_short}}</td>
|
||||
<td class="money">{{"%f"|math:$line.amort_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>
|
||||
{{if $line.line_label != null}}
|
||||
{{$line.line_label}}
|
||||
{{if $line.trans_label != $line.line_label}}
|
||||
— {{$line.trans_label}}
|
||||
{{/if}}
|
||||
{{else}}
|
||||
{{$line.trans_label}}
|
||||
{{/if}}
|
||||
</td>
|
||||
<td class="money">{{"%f"|math:$line.amount|money_html:false|raw}}</td>
|
||||
<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"}}
|
||||
{{:linkbutton label="Attacher" href="attach_amort.html?immo_doc_id=%s&amort_line_id=%s"|args:$_GET.immo_doc_id:$line.line_id shape="plus"}}
|
||||
</td>
|
||||
</tr>
|
||||
{{/foreach}}
|
||||
</tbody>
|
||||
</table>
|
||||
</section>
|
||||
{{else}}
|
||||
<p class="block alert">Aucun amortissement pour le compte {{$code_amort}}</p>
|
||||
{{/if}}
|
||||
|
||||
|
||||
{{:form_errors}}
|
||||
{{:admin_footer}}
|
||||
|
||||
|
|
|
|||
211
save_amort.html
211
save_amort.html
|
|
@ -2,130 +2,45 @@
|
|||
|
||||
{{*
|
||||
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 *}}
|
||||
{{#select
|
||||
line.id_account as account_id,
|
||||
line.debit as montant,
|
||||
line.id_project as project_id,
|
||||
line.label as line_label,
|
||||
trans.id as trans_id,
|
||||
trans.label,
|
||||
trans.date,
|
||||
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
|
||||
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
|
||||
}}
|
||||
{{else}}
|
||||
{{:error message="Immobilisation %s non trouvée"|args:$_GET.immo_line_id}}
|
||||
{{/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}}
|
||||
{{* données de l'immobilisation *}}
|
||||
{{:include file="_get_immo_data.html" immo_doc_id=$_GET.immo_doc_id|intval keep="info_immo, ligne_immo, message"}}
|
||||
{{if $message != null}}
|
||||
{{:error message=$message}}
|
||||
{{/if}}
|
||||
|
||||
{{if $info_immo.amount != null}}
|
||||
{{:assign var="ligne_immo.amount" value=$info_immo.amount}}
|
||||
{{/if}}
|
||||
{{:assign date_debut=$info_immo.date_mes|or:$info_immo.date_achat|or:$ligne_immo.date_achat}}
|
||||
{{:assign amort_label=$info_immo.label|or:$ligne_immo.trans_label}}
|
||||
|
||||
{{if $ligne_immo.line_label != null && $ligne_immo.line_label != $amort_label}}
|
||||
{{:assign amort_label=$amort_label|cat:" — "|cat:$ligne_immo.line_label}}
|
||||
{{/if}}
|
||||
{{:assign var="amort_label" value="Amortissement %s"|args:$amort_label}}
|
||||
|
||||
{{#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}}
|
||||
{{* déduire le montant des écritures liées à l'immo courante au crédit du même compte *}}
|
||||
{{:include file="_get_credit_lines.html" immo_doc_id=$_GET.immo_doc_id keep="total_credits"}}
|
||||
{{:assign var="ligne_immo.amount" value="%d-%d"|math:$ligne_immo.amount:$total_credits}}
|
||||
|
||||
{{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
|
||||
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
|
||||
}}
|
||||
{{:assign total_credits="%d+%d"|math:$total_credits:$credit}}
|
||||
{{/select}}
|
||||
{{: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
|
||||
}}
|
||||
{{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}}
|
||||
|
||||
{{: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=$trans_label}}
|
||||
{{/foreach}}
|
||||
{{* lister les amortissements liés à l'immobilisation *}}
|
||||
{{:include file="./_get_amort_lines.html" immo_doc_id=$_GET.immo_doc_id keep="linked_amort, total_amort"}}
|
||||
|
||||
{{:assign valeur_residuelle="%d-%d"|math:$ligne_immo.amount:$total_amort}}
|
||||
{{if $valeur_residuelle == 0}}
|
||||
{{:error message="Cette immobilisation est complètement amortie ; il est impossible d'ajouter une écriture d'amortissement"}}
|
||||
{{/if}}
|
||||
|
||||
{{#foreach from=$linked_amort|ksort item="line"}}
|
||||
{{:assign date_debut=$line.date}}
|
||||
{{:assign code_amort=$line.account_code}}
|
||||
{{:assign amort_account_label=$line.account_label}}
|
||||
{{:assign amort_label=$line_label|or:$trans_label}}
|
||||
{{/foreach}}
|
||||
|
||||
{{if $total_amort == 0}}
|
||||
{{* 1er amortissement *}}
|
||||
{{* déterminer le compte d'amortissement en fonction du compte d'immobilisation *}}
|
||||
|
|
@ -137,7 +52,7 @@
|
|||
keep="code_amort"
|
||||
}}
|
||||
{{:assign var="amort_account_label" value="Amortissement %s"|args:$amort_account.label}}
|
||||
{{:assign var=libelle value="Amortissement %s"|args:$ligne_immo.label}}
|
||||
{{:assign var=libelle value="Amortissement %s"|args:$ligne_immo.trans_label}}
|
||||
{{else}}
|
||||
{{* amortissements suivants *}}
|
||||
{{:assign date_debut=$date_debut|strtotime}}
|
||||
|
|
@ -163,7 +78,9 @@
|
|||
{{:assign var="years_data.%d"|args:$id value=$ts_debut|cat:" "|cat:$ts_fin}}
|
||||
{{:assign msg_years=$msg_years|cat:"\n"|cat:" - "|cat:$label|cat:" : "|cat:$debut|cat:" à "|cat:$fin}}
|
||||
{{else}}
|
||||
{{:error message="Aucun exercice ouvert pour enregistrer un amortissement"}}
|
||||
{{:assign date_debut=$date_debut|date_short}}
|
||||
{{:assign msg="Pas d'exercice ouvert pour enregistrer un amortissement à partir du %s"|args:$date_debut}}
|
||||
{{:error message=$msg}}
|
||||
{{/years}}
|
||||
|
||||
{{* Traiter l'envoi du formulaire *}}
|
||||
|
|
@ -220,14 +137,15 @@
|
|||
}}
|
||||
{{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 *}}
|
||||
{{:assign solde="%d-%d"|math:$ligne_immo.montant:$total_amort}}
|
||||
{{:assign solde="%d-%d"|math:$ligne_immo.amount:$total_amort}}
|
||||
{{if $_POST.montant|trim|money_int > $solde|intval}}
|
||||
{{:assign montant=$_POST.montant|trim|money_int|money_raw}}
|
||||
{{:assign solde=$solde|money_raw}}
|
||||
{{:error message="Le montant indiqué « %s » dépasse le solde à amortir « %s »"|args:$_POST.montant:$solde}}
|
||||
{{:error message="Le montant indiqué « %s » dépasse le solde à amortir « %s »"|args:$montant:$solde}}
|
||||
{{/if}}
|
||||
|
||||
{{* enregistrer l'écriture *}}
|
||||
|
|
@ -235,16 +153,15 @@
|
|||
var="lines."
|
||||
debit=$_POST.montant
|
||||
account=$debit_account|keys|value:0
|
||||
id_project=$ligne_immo.project_id
|
||||
label=$_POST.designation
|
||||
id_project=$ligne_immo.id_project
|
||||
}}
|
||||
{{:assign
|
||||
var="lines."
|
||||
credit=$_POST.montant
|
||||
account=$credit_account|keys|value:0
|
||||
id_project=$ligne_immo.project_id
|
||||
label=$_POST.designation
|
||||
id_project=$ligne_immo.id_project
|
||||
}}
|
||||
|
||||
{{:api
|
||||
method="POST"
|
||||
path="accounting/transaction"
|
||||
|
|
@ -259,29 +176,29 @@
|
|||
}}
|
||||
|
||||
{{* enregistrer la liaison des lignes *}}
|
||||
{{#select
|
||||
trans.id AS trans_id,
|
||||
line.id AS line_id
|
||||
FROM acc_transactions AS trans
|
||||
INNER JOIN acc_transactions_lines AS line ON line.id_transaction = trans.id
|
||||
WHERE trans.id = :trans_id
|
||||
;
|
||||
:trans_id = $result.id
|
||||
}}
|
||||
{{:assign amort_trans_id=$trans_id}}
|
||||
{{:assign amort_line_id=$line_id}}
|
||||
{{/select}}
|
||||
{{if $amort_trans_id != null}}
|
||||
{{#foreach from=$result.lines item="line"}}
|
||||
{{if $line.account_code == $credit_account|keys|value:0}}
|
||||
{{:save
|
||||
key=""|uuid
|
||||
type="amort_link"
|
||||
immo_doc_id=$_GET.immo_doc_id|intval
|
||||
amort_line_id=$line.id
|
||||
created=true
|
||||
}}
|
||||
{{:break}}
|
||||
{{/if}}
|
||||
{{/foreach}}
|
||||
|
||||
{{* immo soldée ? *}}
|
||||
{{if $_POST.montant|trim|money_int == $solde}}
|
||||
{{:assign var="info_immo.status" value="amortized"}}
|
||||
{{:save
|
||||
key=""|uuid
|
||||
type="link"
|
||||
immo_line_id=$_GET.immo_line_id|intval
|
||||
amort_line_id=$amort_line_id|intval
|
||||
amort_trans_id=$result.id
|
||||
key=$info_immo.key
|
||||
status=$info_immo.status
|
||||
}}
|
||||
{{/if}}
|
||||
|
||||
{{:redirect force="amortization.html?immo_line_id=%s&ok=1&msg=amortissement"|args:$_GET.immo_line_id}}
|
||||
{{:redirect force="amortization.html?immo_doc_id=%s&type_immo=%s&ok=1&msg=amortissement"|args:$_GET.immo_doc_id:$info_immo.status}}
|
||||
{{/form}}
|
||||
|
||||
{{:admin_header title="Ajout amortissement" custom_css="./style.css" current="module_amortization"}}
|
||||
|
|
@ -298,8 +215,8 @@
|
|||
{{:include file="_calcul_dates.html" date_debut=$date_debut date_fin=$date_amort keep="nbjours"}}
|
||||
|
||||
{{* montant de l'amortissement *}}
|
||||
{{:assign montant_amort="%f/%f/365*%d"|math:$ligne_immo.montant:$duree:$nbjours|intval}}
|
||||
{{:assign montant_amort="min(%f, %d-%d)"|math:$montant_amort:$ligne_immo.montant:$total_amort}}
|
||||
{{:assign montant_amort="%f/%f/365*%d"|math:$ligne_immo.amount:$info_immo.duration:$nbjours|intval}}
|
||||
{{:assign montant_amort="min(%f, %d-%d)"|math:$montant_amort:$ligne_immo.amount:$total_amort}}
|
||||
{{:assign var="debit_account.6811" value="6811 — Dot. aux amortissements des immobilisations"}}
|
||||
{{:assign var="credit_account.%s"|args:$code_amort value="%s — "|args:$code_amort|cat:$amort_account_label}}
|
||||
|
||||
|
|
@ -322,6 +239,7 @@
|
|||
name="debit_account"
|
||||
label="Compte de débit"
|
||||
required=true
|
||||
readonly=true
|
||||
target="!acc/charts/accounts/selector.php?codes=%s&id_year=%d"|args:"68*":$selected_year
|
||||
default=$debit_account
|
||||
}}
|
||||
|
|
@ -330,12 +248,13 @@
|
|||
name="credit_account"
|
||||
label="Compte d'amortissement (28xx)"
|
||||
required=true
|
||||
readonly=true
|
||||
target="!acc/charts/accounts/selector.php?codes=%s&id_year=%d"|args:"28*":$selected_year
|
||||
default=$credit_account
|
||||
}}
|
||||
<div id="donnees" class="hidden">
|
||||
{{:input type="text" name="montant_immo" default=$ligne_immo.montant}}
|
||||
{{:input type="text" name="duree_amort" default=$duree}}
|
||||
{{:input type="text" name="montant_immo" default=$ligne_immo.amount}}
|
||||
{{:input type="text" name="duree_amort" default=$info_immo.duration}}
|
||||
{{:input type="text" name="somme_amort" default=$total_amort}}
|
||||
{{:input type="select" name="years_data" options=$years_data}}
|
||||
</div>
|
||||
|
|
@ -368,8 +287,8 @@ function redisplayData(evt,
|
|||
)
|
||||
{
|
||||
setDateEnd(f_years_select, f_date, f_years_data);
|
||||
setSelectorYear(['credit_account', 'debit_account'], f_years_select);
|
||||
displayAmort(f_immo, f_duree, f_amort, f_years_data, f_years_select, f_montant, f_erreur);
|
||||
setSelectorYear(['credit_account', 'debit_account'], f_years_select);
|
||||
}
|
||||
|
||||
function redisplayAmort(evt,
|
||||
|
|
|
|||
23
scripts.js
23
scripts.js
|
|
@ -14,23 +14,24 @@ 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
|
||||
function setAccountYear(button_names, id_year) {
|
||||
for (const name of button_names) {
|
||||
const button = document.querySelector("button[data-name=" + name + "]");
|
||||
const b_value = button.value;
|
||||
const new_value = b_value.replace(/id_year=\d+/, 'id_year=' + id_year);
|
||||
button.setAttribute('value', new_value);
|
||||
if (button != null) {
|
||||
const b_value = button.value;
|
||||
const new_value = b_value.replace(/id_year=\d+/, 'id_year=' + id_year);
|
||||
button.setAttribute('value', new_value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -80,7 +81,7 @@ function setDateEnd(id_exercices, id_date, id_years) {
|
|||
|
||||
// renvoyer la valeur numérique d'un montant formaté en €
|
||||
function getNumber(text) {
|
||||
return Number(text.replace(/[^0-9,]/g, '').replace(/,/, '.'));
|
||||
return Number(text.replace(/[^0-9,]/g, '').replace(/,/, '.'));
|
||||
}
|
||||
|
||||
// calculer le montant d'un amortissement
|
||||
|
|
@ -132,7 +133,9 @@ function displayAmort(id_immo, id_duree, id_amort, id_years, id_exercices, id_mo
|
|||
case_montant.innerText = montant_amort;
|
||||
}
|
||||
|
||||
function setSelectorYear(button_names, f_years_selector) {
|
||||
function setSelectorYear(button_names, f_years_selector)
|
||||
{
|
||||
const selector = document.getElementById(f_years_selector);
|
||||
const selected_year = document.getElementById(f_years_selector).value;
|
||||
setAccountYear(button_names, selected_year);
|
||||
}
|
||||
|
|
|
|||
28
style.css
28
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,31 @@ 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);
|
||||
}
|
||||
|
||||
span.input-list.avoirs label {
|
||||
padding : 0.4rem 0.6rem;
|
||||
}
|
||||
|
||||
aside.right {
|
||||
float: right;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -75,12 +75,12 @@
|
|||
{{/if}}
|
||||
|
||||
{{* vérifier que la date de mise en service est située dans l'exercice sélectionné *}}
|
||||
{{:assign ts_date = $_POST.date_mes|parse_date|strtotime}}
|
||||
{{:assign ts_date = $_POST.date_mes|parse_date}}
|
||||
{{:assign ok=false}}
|
||||
{{#foreach from=$years}}
|
||||
{{if $id == $_POST.id_year}}
|
||||
{{:assign selected_chart=$id_chart}}
|
||||
{{if $start_date|strtotime <= $ts_date && $ts_date <= $end_date|strtotime}}
|
||||
{{if $start_date <= $ts_date && $ts_date <= $end_date}}
|
||||
{{:assign ok=true}}
|
||||
{{:break}}
|
||||
{{/if}}
|
||||
|
|
@ -93,11 +93,8 @@
|
|||
{{if ! $_POST.amortir}}
|
||||
{{* ne pas amortir *}}
|
||||
{{:assign duration=0}}
|
||||
{{:assign date_debut=$_POST.date_achat|parse_date}}
|
||||
{{: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|parse_date}}
|
||||
{{:assign duration=$_POST.duree|intval}}
|
||||
{{:assign status="managed"}}
|
||||
{{/if}}
|
||||
|
|
@ -178,11 +175,11 @@
|
|||
{{* enregistrer les infos de l'immobilisation *}}
|
||||
{{:save
|
||||
key=""|uuid
|
||||
validate_schema="schema.json"
|
||||
validate_schema="asset.schema.json"
|
||||
type="immo"
|
||||
line=$immo_line_id
|
||||
duration=$duration
|
||||
date=$date_debut
|
||||
date_mes=null
|
||||
status=$status
|
||||
}}
|
||||
{{if $_POST.amortir}}
|
||||
|
|
@ -260,6 +257,7 @@
|
|||
type="list"
|
||||
name="credit_accounts[]"
|
||||
required=true
|
||||
readonly=true
|
||||
target="!acc/charts/accounts/selector.php?codes=%s&id_year=%d"|args:$code:$selected_year
|
||||
default=$current_account
|
||||
}}
|
||||
|
|
@ -274,6 +272,7 @@
|
|||
</td>
|
||||
</tr>
|
||||
{{/foreach}}
|
||||
<tr><td colspan="5"></td></tr>
|
||||
</tbody>
|
||||
<tfoot>
|
||||
<tr>
|
||||
|
|
|
|||
175
write_exit.html
175
write_exit.html
|
|
@ -3,70 +3,35 @@
|
|||
{{*
|
||||
Enregistrer les écritures de sortie du bilan
|
||||
paramètres :
|
||||
- immo_line_id : numéro de ligne de l'écriture d'immobilisation
|
||||
- immo_doc_id : id du doc associé à l'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
|
||||
- date_debut : date de début de la période d'amortissement complémentaire
|
||||
- exit_date : date de sortie de l'immobilisation
|
||||
- duree_amort : durée de l'amortiseement (optionnel)
|
||||
- cession : montant de la cession (optionnel)
|
||||
*}}
|
||||
|
||||
{{#select
|
||||
line.debit as montant,
|
||||
line.id_transaction,
|
||||
trans.id AS trans_id,
|
||||
trans.date as date_achat,
|
||||
trans.label,
|
||||
acc.code as account_code,
|
||||
id_project
|
||||
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 = :immo_line_id;
|
||||
:immo_line_id = $_GET.immo_line_id|intval
|
||||
assign="ligne_immo"
|
||||
}}
|
||||
{{/select}}
|
||||
{{* données de l'immobilisation *}}
|
||||
{{:include file="_get_immo_data.html" immo_doc_id=$_GET.immo_doc_id|intval keep="info_immo, ligne_immo, message"}}
|
||||
{{if $message != null}}
|
||||
{{:error message=$message}}
|
||||
{{/if}}
|
||||
|
||||
{{#load type="immo" assign="info_immo" where="$$.line = :line_id" :line_id=$_GET.immo_line_id|intval}}
|
||||
{{/load}}
|
||||
{{* déduire le montant des écritures liées à l'immo courante au crédit du même compte *}}
|
||||
{{:include file="_get_credit_lines.html" immo_doc_id=$_GET.immo_doc_id keep="total_credits"}}
|
||||
{{:assign var="ligne_immo.amount" value="%d-%d"|math:$ligne_immo.amount:$total_credits}}
|
||||
{{:assign valeur_nette="%f-%f"|math:$ligne_immo.amount:$_GET.amort_amount}}
|
||||
|
||||
{{* 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
|
||||
}}
|
||||
{{:assign total_credits="%d+%d"|math:$total_credits:$credit}}
|
||||
{{/select}}
|
||||
{{:assign var="ligne_immo.montant" value="%d-%d"|math:$ligne_immo.montant:$total_credits}}
|
||||
|
||||
{{:assign valeur_nette="%f-%f"|math:$ligne_immo.montant:$_GET.amort_amount}}
|
||||
{{:assign amort_comp=0}} {{* amortissement complémentaire jqà date sortie *}}
|
||||
{{:assign amort_except=0}} {{* amortissement exceptionnel jqà date fin amortissement *}}
|
||||
{{if $valeur_nette > 0}}
|
||||
{{:assign nbjours="1+(%d-%d)/(60*60*24)"|math:$_GET.exit_date:$_GET.date_debut}}
|
||||
{{:assign annuite="%f/%f"|math:$ligne_immo.montant:$_GET.duree_amort}}
|
||||
{{:assign annuite="%f/%f"|math:$ligne_immo.amount:$info_immo.duration}}
|
||||
{{:assign amort_comp="round(%f/365*%f, 0)"|math:$annuite:$nbjours}}
|
||||
{{:assign amort_comp="min(%f, %f)"|math:$valeur_nette:$amort_comp}}
|
||||
|
||||
{{if $_GET.cession == null}}
|
||||
{{:assign amort_except="%f-%f-%f"|math:$ligne_immo.montant:$_GET.amort_amount:$amort_comp}}
|
||||
{{:assign amort_except="%f-%f-%f"|math:$ligne_immo.amount:$_GET.amort_amount:$amort_comp}}
|
||||
{{/if}}
|
||||
{{/if}}
|
||||
|
||||
|
|
@ -76,6 +41,10 @@
|
|||
{{:assign montant_cession="%f*100"|math:$_GET.cession}}
|
||||
{{/if}}
|
||||
|
||||
{{* numéros de comptes ; voir info.org *}}
|
||||
{{:assign vnc_code="652"}}
|
||||
{{:assign cession_code="757"}}
|
||||
|
||||
{{* TODO : faut-il forcer les 3 sélecteurs de compte d'amortissement à avoir toujours la même valeur ? *}}
|
||||
|
||||
{{* Traiter l'envoi du formulaire *}}
|
||||
|
|
@ -109,7 +78,7 @@
|
|||
}}
|
||||
{{:assign comp_account_code=$account_code|keys|value:0}}
|
||||
|
||||
{{:assign libelle="Amortissement complémentaire "|cat:$ligne_immo.label}}
|
||||
{{:assign libelle="Amortissement complémentaire "|cat:$ligne_immo.trans_label}}
|
||||
{{:assign
|
||||
var="lines."
|
||||
debit="%f/100"|math:$amort_comp
|
||||
|
|
@ -134,7 +103,7 @@
|
|||
keep="account_code"
|
||||
}}
|
||||
{{:assign except_account_code=$account_code|keys|value:0}}
|
||||
{{:assign libelle="Amortissement exceptionnel "|cat:$ligne_immo.label}}
|
||||
{{:assign libelle="Amortissement exceptionnel "|cat:$ligne_immo.trans_label}}
|
||||
{{:assign
|
||||
var="lines."
|
||||
debit="%f/100"|math:$amort_except
|
||||
|
|
@ -160,10 +129,22 @@
|
|||
id_year=$_GET.year
|
||||
type="advanced"
|
||||
date=$_GET.exit_date
|
||||
label="Amortissement final "|cat:$ligne_immo.label
|
||||
label="Amortissement final "|cat:$ligne_immo.trans_label
|
||||
lines=$lines
|
||||
linked_transactions=$ligne_immo.id_transaction
|
||||
linked_transactions=$ligne_immo.trans_id
|
||||
}}
|
||||
|
||||
{{* liaisons lignes d'amortissement *}}
|
||||
{{#foreach from=$result.lines item="line"}}
|
||||
{{if $line.account_code == $amort_account_code}}
|
||||
{{:save
|
||||
key=""|uuid
|
||||
type="amort_link"
|
||||
immo_doc_id=$info_immo.id
|
||||
amort_line_id=$line.id
|
||||
}}
|
||||
{{/if}}
|
||||
{{/foreach}}
|
||||
{{/if}}
|
||||
|
||||
{{* écriture de sortie du bilan *}}
|
||||
|
|
@ -174,18 +155,18 @@
|
|||
keep="account_code"
|
||||
}}
|
||||
{{:assign immo_account_code=$account_code|keys|value:0}}
|
||||
{{:assign libelle="Sortie du bilan de "|cat:$ligne_immo.label}}
|
||||
{{:assign libelle="Sortie du bilan de "|cat:$ligne_immo.trans_label}}
|
||||
{{:assign
|
||||
var="lines."
|
||||
account=$immo_account_code
|
||||
credit="%f/100"|math:$ligne_immo.montant
|
||||
credit="%f/100"|math:$ligne_immo.amount
|
||||
id_project=$ligne_immo.id_project
|
||||
label=$libelle
|
||||
}}
|
||||
{{:assign
|
||||
var="lines."
|
||||
account=$amort_account_code
|
||||
debit="(%f-%f)/100"|math:$ligne_immo.montant:$valeur_nette
|
||||
debit="(%f-%f)/100"|math:$ligne_immo.amount:$valeur_nette
|
||||
id_project=$ligne_immo.id_project
|
||||
label=$libelle
|
||||
}}
|
||||
|
|
@ -215,12 +196,25 @@
|
|||
date=$_GET.exit_date
|
||||
label=$libelle
|
||||
lines=$lines
|
||||
linked_transactions=$ligne_immo.id_transaction
|
||||
linked_transactions=$ligne_immo.trans_id
|
||||
}}
|
||||
|
||||
{{* liaison écriture de sortie *}}
|
||||
{{#foreach from=$result.lines item="line"}}
|
||||
{{if $line.account_code == $immo_account_code}}
|
||||
{{:save
|
||||
key=""|uuid
|
||||
type="exit_link"
|
||||
immo_doc_id=$info_immo.id
|
||||
exit_line_id=$line.id
|
||||
}}
|
||||
{{:break}}
|
||||
{{/if}}
|
||||
{{/foreach}}
|
||||
|
||||
{{if $montant_cession > 0}}
|
||||
{{* Cession de l'immobilisation *}}
|
||||
{{:assign libelle="Produit cession "|cat:$ligne_immo.label}}
|
||||
{{:assign libelle="Produit cession "|cat:$ligne_immo.trans_label}}
|
||||
{{:include
|
||||
file="_get_codes.html"
|
||||
account=$_POST.creance_account
|
||||
|
|
@ -246,34 +240,32 @@
|
|||
debit=$creance_account
|
||||
credit=$cession_account
|
||||
id_project=$ligne_immo.id_project
|
||||
linked_transactions=$ligne_immo.id_transaction
|
||||
linked_transactions=$ligne_immo.trans_id
|
||||
}}
|
||||
{{/if}}
|
||||
|
||||
{{if $info_immo != null}}
|
||||
{{* mettre à jour l'état de l'immobilisation *}}
|
||||
{{:save
|
||||
key=$info_immo.key
|
||||
status="archived"
|
||||
}}
|
||||
{{else}}
|
||||
{{:save
|
||||
key=""|uuid
|
||||
validate_schema="schema.json"
|
||||
type="immo"
|
||||
line=$_GET.immo_line_id|intval
|
||||
duration=$_GET.duree_amort|intval
|
||||
date=$_GET.date_mes|date:"Y-m-d"
|
||||
status="archived"
|
||||
}}
|
||||
{{/if}}
|
||||
{{* liaison écriture de cession *}}
|
||||
{{#foreach from=$result.lines item="line"}}
|
||||
{{if $line.account_code == $cession_code}}
|
||||
{{:save
|
||||
key=""|uuid
|
||||
type="cession_link"
|
||||
immo_doc_id=$info_immo.id
|
||||
cession_line_id=$line.id
|
||||
}}
|
||||
{{:break}}
|
||||
{{/if}}
|
||||
{{/foreach}}
|
||||
|
||||
{{* mettre à jour l'état de l'immobilisation *}}
|
||||
{{:save
|
||||
key=$info_immo.key
|
||||
status="archived"
|
||||
}}
|
||||
{{:redirect to="index.html?type_immo=archived"}}
|
||||
{{/form}}
|
||||
|
||||
{{:admin_header title="Sortie du bilan" custom_css="./style.css" current="module_amortization"}}
|
||||
|
||||
{{* barre de navigation *}}
|
||||
{{if ! $dialog}}
|
||||
{{:include file="_nav.html" current="index" subcurrent="balance_exit"}}
|
||||
{{/if}}
|
||||
|
|
@ -289,10 +281,6 @@
|
|||
keep="code_amort"
|
||||
}}
|
||||
|
||||
{{* numéros de comptes ; voir info.org *}}
|
||||
{{:assign vnc_code="652"}}
|
||||
{{:assign cession_code="757"}}
|
||||
|
||||
{{:assign var="liste_codes.6811" name="comp_account"}}
|
||||
{{:assign var="liste_codes.687" name="except_account"}}
|
||||
{{:assign var="liste_codes.462" name="creance_account"}}
|
||||
|
|
@ -337,24 +325,22 @@
|
|||
{{/foreach}}
|
||||
{{:assign patterns=$pattern_array|implode:"|"}}
|
||||
|
||||
<h3>Sortir l'immobilisation « {{$ligne_immo.label}} » du bilan</h3>
|
||||
<h3>Sortir l'immobilisation « {{$ligne_immo.trans_label}} » du bilan</h3>
|
||||
<form method="post" action="">
|
||||
|
||||
<div class="informations">
|
||||
<legend>Données de l'imobilisation</legend>
|
||||
<dl class="describe">
|
||||
<dt>Montant</dt>
|
||||
<dd class="money">{{$ligne_immo.montant|money_currency_html:false|raw}}</dd>
|
||||
<dd class="money">{{$ligne_immo.amount|money_currency_html:false|raw}}</dd>
|
||||
<dt>Date d'acquisition</dt>
|
||||
<dd >{{$ligne_immo.date_achat|date_short}}</dd>
|
||||
{{if $_GET.date_mes != $ligne_immo.date_achat|strtotime}}
|
||||
{{if $info_immo.date_mes != null && $info_immo.date_mes != $ligne_immo.date_achat}}
|
||||
<dt>Date de mise en service</dt>
|
||||
<dd>{{$_GET.date_mes|date:"d/m/Y"}}</dd>
|
||||
{{/if}}
|
||||
{{if $_GET.duree_amort != null}}
|
||||
<dt>Durée de l'amortissement</dt>
|
||||
<dd class="num">{{$_GET.duree_amort}} ans</dd>
|
||||
<dd>{{$info_immo.date_mes|date_short}}</dd>
|
||||
{{/if}}
|
||||
<dt>Durée de l'amortissement</dt>
|
||||
<dd class="num">{{$info_immo.duration}} ans</dd>
|
||||
<dt>Montant des amortissements</dt>
|
||||
<dd class="money">{{$_GET.amort_amount|money_currency_html:false|raw}} <span class="help">(à la date de début de l'exercice)</span></dd>
|
||||
<dt>Valeur nette résiduelle</dt>
|
||||
|
|
@ -406,6 +392,7 @@
|
|||
type="list"
|
||||
name="comp_account"
|
||||
target="!acc/charts/accounts/selector.php?codes=%s&id_chart=%s"|args:"68*":$chart_id
|
||||
readonly=true
|
||||
default=$comp_account
|
||||
}}
|
||||
</td>
|
||||
|
|
@ -418,6 +405,7 @@
|
|||
type="list"
|
||||
name="amort_comp_account"
|
||||
target="!acc/charts/accounts/selector.php?codes=%s&id_chart=%s"|args:"28*":$chart_id
|
||||
readonly=true
|
||||
default=$amort_account
|
||||
}}
|
||||
</td>
|
||||
|
|
@ -450,6 +438,7 @@
|
|||
type="list"
|
||||
name="except_account"
|
||||
target="!acc/charts/accounts/selector.php?codes=%s&id_chart=%s"|args:"687*":$chart_id
|
||||
readonly=true
|
||||
default=$except_account
|
||||
}}
|
||||
</td>
|
||||
|
|
@ -462,6 +451,7 @@
|
|||
type="list"
|
||||
name="amort_except_account"
|
||||
target="!acc/charts/accounts/selector.php?codes=%s&id_chart=%s"|args:"28*":$chart_id
|
||||
readonly=true
|
||||
default=$amort_account
|
||||
}}
|
||||
</td>
|
||||
|
|
@ -488,11 +478,12 @@
|
|||
type="list"
|
||||
name="amort_sortie_account"
|
||||
target="!acc/charts/accounts/selector.php?codes=%s&id_chart=%s"|args:"28*":$chart_id
|
||||
readonly=true
|
||||
default=$amort_account
|
||||
}}
|
||||
</td>
|
||||
{{if $montant_cession == 0}}
|
||||
{{:assign montant=$ligne_immo.montant}}
|
||||
{{:assign montant=$ligne_immo.amount}}
|
||||
{{else}}
|
||||
{{:assign montant="%f+%f"|math:$_GET.amort_amount:$amort_comp}}
|
||||
{{/if}}
|
||||
|
|
@ -506,6 +497,7 @@
|
|||
type="list"
|
||||
name="vnc_account"
|
||||
target="!acc/charts/accounts/selector.php?codes=%s*&id_chart=%s"|args:$vnc_code:$chart_id
|
||||
readonly=true
|
||||
default=$vnc_account
|
||||
}}
|
||||
</td>
|
||||
|
|
@ -519,11 +511,12 @@
|
|||
type="list"
|
||||
name="immo_account"
|
||||
target="!acc/charts/accounts/selector.php?codes=%s&id_chart=%s"|args:$patterns:$chart_id
|
||||
readonly=true
|
||||
default=$immo_account
|
||||
}}
|
||||
</td>
|
||||
<td></td>
|
||||
<td>{{$ligne_immo.montant|money_currency_html:false|raw}}</td>
|
||||
<td>{{$ligne_immo.amount|money_currency_html:false|raw}}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
|
@ -545,6 +538,7 @@
|
|||
type="list"
|
||||
name="creance_account"
|
||||
target="!acc/charts/accounts/selector.php?codes=%s&id_chart=%s"|args:"462*":$chart_id
|
||||
readonly=true
|
||||
default=$creance_account
|
||||
}}
|
||||
</td>
|
||||
|
|
@ -557,6 +551,7 @@
|
|||
type="list"
|
||||
name="cession_account"
|
||||
target="!acc/charts/accounts/selector.php?codes=%s*&id_chart=%s"|args:$cession_code:$chart_id
|
||||
readonly=true
|
||||
default=$cession_account
|
||||
}}
|
||||
</td>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue