amortization/_amort_exclus.html

70 lines
2.3 KiB
HTML
Raw Normal View History

{{* -*- brindille -*- *}}
{{*
Trouver les lignes d'amortissement et d'immobilisation qui sont dans la même écriture
- param : aucun
- résultat : amort_exclus = tableau des amortissements à exclure
*}}
{{* lignes des immo non amorties *}}
{{#load type="immo" where="$$.noamort = true"}}
{{:assign var="lines." value="'%s'"|args:$line}}
{{/load}}
{{:assign lines=$lines|implode:","}}
{{:assign lines="("|cat:$lines|cat:")"}}
{{:assign condition="line.id IN %s"|args:$lines}}
{{*:debug condition=$condition*}}
{{* écritures et comptes associés *}}
{{#select
line.id as line_id,
line.id_transaction as trans_id,
account.id as account_id,
account.code as account_code,
account.id_chart as id_chart
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 line.id_account = account.id
INNER JOIN acc_years AS years ON trans.id_year = years.id
WHERE !condition;
!condition=$condition
assign="ecriture"
}}
{{:assign var="ecritures." value="'%s'"|args:$trans_id}}
{{* déterminer le numéro du compte d'amortissement associé au compte d'immobilisation *}}
{{:include
file="./_get_amort_code.html"
code_immo=$account_code
keep="code_amort"
}}
{{:assign var="accounts." value="'%s'"|args:$code_amort}}
{{/select}}
{{*:debug ecritures=$ecritures accounts=$accounts*}}
{{* écritures d'amortissement avec :
- numéro d'écritures obtenus ci-dessus
- numéros de comptes d'amortissement déduits des comptes d'immo ci-dessus
*}}
{{:assign ecritures=$ecritures|implode:","}}
{{:assign ecritures="("|cat:$ecritures|cat:")"}}
{{:assign accounts=$accounts|implode:","}}
{{:assign accounts="("|cat:$accounts|cat:")"}}
{{:assign condition="line.id_transaction IN %s AND account.code IN %s"|args:$ecritures:$accounts}}
{{#select
line.id as line_id,
line.id_transaction as trans_id,
account.id as account_id,
account.code as account_code
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 line.id_account = account.id
INNER JOIN acc_years AS years ON trans.id_year = years.id
WHERE !condition;
!condition=$condition
assign="amort"
}}
{{:assign var="amort_exclus." value=$trans_id}}
{{/select}}