Mutualisation infos immo, écritures crédit, amortissements liés et libres
This commit is contained in:
parent
91795c69a8
commit
780eb206ce
21 changed files with 410 additions and 879 deletions
129
save_amort.html
129
save_amort.html
|
|
@ -5,37 +5,17 @@
|
|||
@param immo_doc_id : id du doc associé à l'immo
|
||||
*}}
|
||||
|
||||
{{* Infos de l'immobilisation *}}
|
||||
{{#load id=$_GET.immo_doc_id|intval assign="info_immo"}}
|
||||
{{else}}
|
||||
{{:error message="Immobilisation non trouvée"}}
|
||||
{{/load}}
|
||||
|
||||
{{#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 immo_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 = $info_immo.line
|
||||
assign="ligne_immo"
|
||||
}}
|
||||
{{else}}
|
||||
{{:error message="Immobilisation non trouvée"}}
|
||||
{{/select}}
|
||||
{{if $info_immo.amount != null}}
|
||||
{{:assign var="ligne_immo.montant" value=$info_immo.amount}}
|
||||
{{* 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=$info_immo.date_mes|or:$info_immo.date_achat|or:$ligne_immo.date}}
|
||||
{{:assign amort_label=$info_immo.label|or:$ligne_immo.label}}
|
||||
|
||||
{{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}}
|
||||
|
|
@ -46,69 +26,25 @@
|
|||
{{: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}}
|
||||
{{#load
|
||||
type="credit_link"
|
||||
where="$$.immo_doc_id = :immo_doc_id" :immo_doc_id = $_GET.immo_doc_id|intval
|
||||
}}
|
||||
{{if $amount == null}}
|
||||
{{#select credit FROM acc_transactions_lines WHERE id = :credit_line_id;
|
||||
:credit_line_id=$credit_line_id
|
||||
}}
|
||||
{{:assign total_credits="%d+%d"|math:$total_credits:$credit}}
|
||||
{{/select}}
|
||||
{{else}}
|
||||
{{:assign total_credits="%d+%d"|math:$total_credits:$amount}}
|
||||
{{/if}}
|
||||
{{/load}}
|
||||
{{:assign var="ligne_immo.montant" value="%d-%d"|math:$ligne_immo.montant:$total_credits}}
|
||||
{{:assign solde=$ligne_immo.montant}}
|
||||
{{* 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}}
|
||||
|
||||
{{* chercher des écritures d'amortissement liées à la ligne d'immobilisation *}}
|
||||
{{#load
|
||||
type="amort_link"
|
||||
where="$$.immo_doc_id = :immo_doc_id"
|
||||
order="$$.date"
|
||||
:immo_doc_id=$_GET.immo_doc_id|intval
|
||||
}}
|
||||
{{#select
|
||||
line.credit,
|
||||
trans.date as amort_date,
|
||||
COALESCE(trans.label, line.label) as amort_label,
|
||||
account.code as account_code,
|
||||
account.label as account_label
|
||||
FROM acc_transactions_lines AS line
|
||||
INNER JOIN acc_transactions AS trans ON line.id_transaction = trans.id
|
||||
INNER join acc_accounts AS account on line.id_account = account.id
|
||||
WHERE line.id = :amort_line_id
|
||||
;
|
||||
:amort_line_id = $amort_line_id
|
||||
assign="amort_line"
|
||||
}}
|
||||
{{:assign var="amort_line.amort_amount" value=$amount|or:$credit}}
|
||||
{{:assign var="linked_amort.%s_%d"|args:$amort_date:$id value=$amort_line}}
|
||||
{{/select}}
|
||||
{{/load}}
|
||||
|
||||
{{:assign total_amort=0}}
|
||||
{{:assign valeur_residuelle=$ligne_immo.montant}}
|
||||
{{#foreach from=$linked_amort|ksort item="line"}}
|
||||
{{:assign valeur_residuelle="%d-%d"|math:$valeur_residuelle:$line.amort_amount}}
|
||||
{{:assign total_amort="%d+%d"|math:$total_amort:$line.amort_amount}}
|
||||
{{:assign date_debut=$line.amort_date}}
|
||||
{{:assign code_amort=$line.account_code}}
|
||||
{{:assign amort_account_label=$line.account_label}}
|
||||
{{:assign amort_label=$amort_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 *}}
|
||||
|
|
@ -120,7 +56,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}}
|
||||
|
|
@ -207,10 +143,11 @@
|
|||
{{/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 *}}
|
||||
|
|
@ -218,13 +155,13 @@
|
|||
var="lines."
|
||||
debit=$_POST.montant
|
||||
account=$debit_account|keys|value:0
|
||||
id_project=$ligne_immo.project_id
|
||||
id_project=$ligne_immo.id_project
|
||||
}}
|
||||
{{:assign
|
||||
var="lines."
|
||||
credit=$_POST.montant
|
||||
account=$credit_account|keys|value:0
|
||||
id_project=$ligne_immo.project_id
|
||||
id_project=$ligne_immo.id_project
|
||||
}}
|
||||
|
||||
{{:api
|
||||
|
|
@ -237,7 +174,7 @@
|
|||
date=$_POST.date_amort
|
||||
label=$_POST.designation
|
||||
lines=$lines
|
||||
linked_transactions=$ligne_immo.immo_trans_id|intval
|
||||
linked_transactions=$ligne_immo.trans_id|intval
|
||||
}}
|
||||
|
||||
{{* enregistrer la liaison des lignes *}}
|
||||
|
|
@ -279,8 +216,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:$info_immo.duration:$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}}
|
||||
|
||||
|
|
@ -315,7 +252,7 @@
|
|||
default=$credit_account
|
||||
}}
|
||||
<div id="donnees" class="hidden">
|
||||
{{:input type="text" name="montant_immo" default=$ligne_immo.montant}}
|
||||
{{: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}}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue