diff --git a/_archives.html b/_archives.html
index 8a8f8ad..ce92aff 100644
--- a/_archives.html
+++ b/_archives.html
@@ -153,7 +153,7 @@
{{$account_code}} |
{{$account_label}} |
- {{:linkbutton label="Modifier" href="exit_step3.html?immo_doc_id=%s"|args:$info_immo.id shape="edit"}}
+ {{:linkbutton label="Modifier" href="exit_step4.html?immo_doc_id=%s"|args:$info_immo.id shape="edit"}}
|
{{/select}}
@@ -172,7 +172,6 @@
{{$value|money_html:false|raw}} |
|
|
- |
|
{{/foreach}}
@@ -184,7 +183,6 @@
{{$total_immo|money_html:false|raw}} |
|
|
- |
|
{{/if}}
@@ -201,7 +199,6 @@
{{$value|money_html:false|raw}} |
|
|
- |
|
{{/foreach}}
@@ -213,7 +210,6 @@
{{$total_cessions|money_html:false|raw}} |
|
|
- |
|
{{/if}}
diff --git a/attach_cession.html b/attach_cession.html
new file mode 100644
index 0000000..008a4b0
--- /dev/null
+++ b/attach_cession.html
@@ -0,0 +1,61 @@
+{{* -*- 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 rebut_id=$id_transaction}}
+{{else}}
+ {{:error message="Impossible de trouver l'écriture de cession de l'immobilisation"}}
+{{/select}}
+
+{{* chercher les liaisons de l'écriture d'immobilisation *}}
+{{#select
+ CASE links.id_related = :immo_trans_id
+ WHEN true THEN links.id_transaction
+ WHEN false THEN links.id_related
+ END as linked_id
+ 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=$rebut_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
+}}
+
+{{* 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}}
diff --git a/attach_exit.html b/attach_exit.html
index 11bc17c..d639722 100644
--- a/attach_exit.html
+++ b/attach_exit.html
@@ -58,4 +58,4 @@
exit_line_id=$_GET.exit_line_id|intval
}}
-{{:redirect to="exit_step3.html?immo_doc_id=%s&ok=1&msg=attach_exit"|args:$_GET.immo_doc_id}}
+{{:redirect to="exit_step4.html?immo_doc_id=%s&ok=1&msg=attach_exit"|args:$_GET.immo_doc_id}}
diff --git a/detach_cession.html b/detach_cession.html
new file mode 100644
index 0000000..eab7863
--- /dev/null
+++ b/detach_cession.html
@@ -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}}
diff --git a/detach_exit.html b/detach_exit.html
index 486fc7c..1a71701 100644
--- a/detach_exit.html
+++ b/detach_exit.html
@@ -18,4 +18,4 @@
{{:delete id=$id}}
{{/load}}
-{{:redirect to="exit_step3.html?immo_doc_id=%s&ok=1&msg=detach_exit"|args:$_GET.immo_doc_id}}
+{{:redirect to="exit_step4.html?immo_doc_id=%s&ok=1&msg=detach_exit"|args:$_GET.immo_doc_id}}
diff --git a/exit_step1.html b/exit_step1.html
index d3cc904..0fc2fb1 100644
--- a/exit_step1.html
+++ b/exit_step1.html
@@ -1,7 +1,7 @@
{{* -*- brindille -*- *}}
{{*
- Associer les différentes écritures à une immo créée et sortie du
+ 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
*}}
@@ -197,7 +197,7 @@
{{/if}}
{{if $credit_lines}}
- Écritures au crédit du compte d'immobilisation
+ Autres écritures au crédit du compte d'immobilisation
diff --git a/exit_step2.html b/exit_step2.html
index 699b947..8199426 100644
--- a/exit_step2.html
+++ b/exit_step2.html
@@ -1,7 +1,7 @@
{{* -*- brindille -*- *}}
{{*
- Associer les différentes écritures à une immo créée et sortie du
+ 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
*}}
diff --git a/exit_step3.html b/exit_step3.html
index 671b415..5d8ff0d 100644
--- a/exit_step3.html
+++ b/exit_step3.html
@@ -1,7 +1,8 @@
{{* -*- brindille -*- *}}
+{{:admin_header title="Immobilisation sortie du bilan" custom_css="./style.css" current="module_amortization"}}
{{*
- Associer les différentes écritures à une immo créée et sortie du
+ 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
*}}
@@ -16,17 +17,8 @@
{{:redirect to="exit_step2.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 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}}
@@ -44,84 +36,13 @@
{{* 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
-*}}
+{{* chercher des écritures de cession *}}
+{{:assign total_cession=0}}
{{#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.id as line_id,
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.id as trans_id,
trans.date as date,
trans.label as trans_label,
trans.id_year as year,
@@ -131,45 +52,39 @@
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
+ WHERE account.code LIKE :code_cession_new OR account.code LIKE :code_cession_old
;
- :code_amort = $code_amort
- :immo_date=$date_immo
- assign="amort_line"
+ :code_cession_new = "757%"
+ :code_cession_old = "775%"
+ assign="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"
+ {{* 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 $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 $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}}
- {{* 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}}
+ {{:assign var="free_cessions." value=$line}}
+ {{/select}}
{{/select}}
-
-{{:admin_header title="Immobilisation sortie du bilan" custom_css="./style.css" current="module_amortization"}}
+{{*:debug linked_cessions=$linked_cessions free_cessions=$free_cessions total_cession=$total_cession*}}
{{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 $_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}}
{{$msg}}
{{/if}}
@@ -194,11 +109,15 @@
Valeur nette résiduelle
{{"%d-%d"|math:$solde:$total_amort|money_currency_html:false|raw}}
{{/if}}
+ {{if $total_cession > 0}}
+ Montant de la cession
+ {{$total_cession|money_currency_html:false|raw}}
+ {{/if}}
-{{if $exit_line != null}}
- Écriture de sortie du bilan attachée à l'immobilisation
+{{if $linked_cessions != null}}
+ Écriture de cession attachée à l'immobilisation
@@ -212,77 +131,91 @@
-
- | #{{$exit_line.trans_id}} |
- {{$exit_line.date|date_short}} |
-
- {{if $exit_line.line_label != null}}
- {{$exit_line.line_label}}
- {{else}}
- {{$exit_line.trans_label}}
- {{/if}}
- |
- {{"%f"|math:$exit_line.amount|money_html:false|raw}} |
- {{$exit_line.account_code}} |
- {{$exit_line.account_label}} |
-
- {{: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"}}
- |
-
+ {{#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}}
+
+ | #{{$line.trans_id}} |
+ {{$line.date|date_short}} |
+
+ {{if $line.line_label != null}}
+ {{$line.line_label}}
+ {{if $line.trans_label != $line.line_label}}
+ — {{$line.trans_label}}
+ {{/if}}
+ {{else}}
+ {{$line.trans_label}}
+ {{/if}}
+ |
+ {{"%f"|math:$line.amount|money_html:false|raw}} |
+ {{$line.account_code}} |
+ {{$line.account_label}} |
+
+ {{: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"}}
+ |
+
+ {{/foreach}}
-{{elseif $exit_lines}}
+{{elseif $free_cessions}}
- Vous pouvez attacher une écriture de sortie du bilan à l'immobilisation
+ Vous pouvez attacher une écriture de cession à l'immobilisation
+
+{{else}}
+
+ Aucune écriture de cession... que faire ?
{{/if}}
-{{if $exit_lines}}
- Écritures non rattachées
+
+{{if $free_cessions}}
+ Autres écritures de cession
-
- | N° |
- Date |
- Libellé |
- Montant |
- N° compte |
- Compte |
- |
-
-
-
+
+ | N° |
+ Date |
+ Libellé |
+ Montant |
+ N° compte |
+ Compte |
+ |
+
+
+
- {{#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}}
-
- | #{{$line.trans_id}} |
- {{$line.date|date_short}} |
- {{$line.trans_label}}
- {{if $line.line_label != null && $line.line_label != $line.trans_label}} — {{$line.line_label}}{{/if}}
- |
- {{"%f"|math:$line.amount|money_html:false|raw}} |
- {{$line.account_code}} |
- {{$line.account_label}} |
-
- {{: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"}}
- |
-
- {{/foreach}}
-
+ {{#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}}
+
+ | #{{$line.trans_id}} |
+ {{$line.date|date_short}} |
+
+ {{if $line.line_label != null}}
+ {{$line.line_label}}
+ {{if $line.trans_label != $line.line_label}}
+ — {{$line.trans_label}}
+ {{/if}}
+ {{else}}
+ {{$line.trans_label}}
+ {{/if}}
+ |
+ {{"%f"|math:$line.amount|money_html:false|raw}} |
+ {{$line.account_code}} |
+ {{$line.account_label}} |
+
+ {{: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"}}
+ |
+
+ {{/foreach}}
+
-{{elseif $exit_line == null}}
- Aucune écriture de sortie du bilan. Vérifiez l'attachement d'écriture d'avoir.
{{/if}}
diff --git a/exit_step4.html b/exit_step4.html
new file mode 100644
index 0000000..ccb6d7f
--- /dev/null
+++ b/exit_step4.html
@@ -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}}
+ {{$msg}}
+{{/if}}
+
+
+
+{{if $exit_line != null}}
+ Écriture de sortie du bilan attachée à l'immobilisation
+
+
+
+ | N° |
+ Date |
+ Libellé |
+ Montant |
+ N° compte |
+ Compte |
+ |
+
+
+
+
+ | #{{$exit_line.trans_id}} |
+ {{$exit_line.date|date_short}} |
+
+ {{if $exit_line.line_label != null}}
+ {{$exit_line.line_label}}
+ {{else}}
+ {{$exit_line.trans_label}}
+ {{/if}}
+ |
+ {{"%f"|math:$exit_line.amount|money_html:false|raw}} |
+ {{$exit_line.account_code}} |
+ {{$exit_line.account_label}} |
+
+ {{: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"}}
+ |
+
+
+
+{{elseif $exit_lines}}
+
+ Vous pouvez attacher une écriture de sortie du bilan à l'immobilisation
+
+{{/if}}
+
+{{if $exit_lines}}
+ Écritures non rattachées
+
+
+
+ | N° |
+ Date |
+ Libellé |
+ Montant |
+ N° compte |
+ Compte |
+ |
+
+
+
+
+ {{#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}}
+
+ | #{{$line.trans_id}} |
+ {{$line.date|date_short}} |
+ {{$line.trans_label}}
+ {{if $line.line_label != null && $line.line_label != $line.trans_label}} — {{$line.line_label}}{{/if}}
+ |
+ {{"%f"|math:$line.amount|money_html:false|raw}} |
+ {{$line.account_code}} |
+ {{$line.account_label}} |
+
+ {{: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"}}
+ |
+
+ {{/foreach}}
+
+
+{{elseif $exit_line == null}}
+ Aucune écriture de sortie du bilan. Vérifiez l'attachement d'écriture d'avoir.
+{{/if}}
+
+
diff --git a/link.schema.json b/link.schema.json
index 88968ed..111d1bc 100644
--- a/link.schema.json
+++ b/link.schema.json
@@ -5,7 +5,7 @@
"properties": {
"type": {
"type": "string",
- "enum": ["amort_link", "credit_link", "exit_link"]
+ "enum": ["amort_link", "credit_link", "cession_link", "exit_link"]
},
"immo_doc_id" : {
"description": "identifiant du document d'immobilisation associé",
@@ -27,6 +27,11 @@
"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"]
@@ -39,6 +44,9 @@
"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"]},
}