Compare commits
2 commits
bf5e561b98
...
f5526c1147
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f5526c1147 | ||
|
|
61d67e5622 |
5 changed files with 92 additions and 43 deletions
|
|
@ -174,12 +174,14 @@
|
||||||
<td class="money">{{"%d-%d"|math:$montant_immo:$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><a href={{$compte_url}}>{{$account_code}}</a></td>
|
||||||
<td class="actions">
|
<td class="actions">
|
||||||
{{:linkbutton
|
{{if ! $exist_amort || $status == "unknown"}}
|
||||||
label="Paramètres"
|
{{:linkbutton
|
||||||
href="add_infos.html?immo_id=%s&type_immo=%s"|args:$immo_line_id:$type_immo
|
label="Paramètres"
|
||||||
shape="settings"
|
href="add_infos.html?immo_id=%s&type_immo=%s"|args:$immo_line_id:$type_immo
|
||||||
target="_dialog"
|
shape="settings"
|
||||||
}}
|
target="_dialog"
|
||||||
|
}}
|
||||||
|
{{/if}}
|
||||||
{{:linkbutton
|
{{:linkbutton
|
||||||
label="Amortissements"
|
label="Amortissements"
|
||||||
href="amortization.html?immo_id=%s&type_immo=%s"|args:$immo_line_id:$type_immo
|
href="amortization.html?immo_id=%s&type_immo=%s"|args:$immo_line_id:$type_immo
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
<nav class="tabs">
|
<nav class="tabs">
|
||||||
{{if $current == "index" && $subsubcurrent == null}}
|
{{if $current == "index" && $subsubcurrent == null}}
|
||||||
<aside>
|
<aside>
|
||||||
{{:linkbutton label="Ajouter une immobilisation" shape="plus" href="add_asset.html" target="_dialog"}}
|
{{:linkbutton label="Ajouter une immobilisation" shape="plus" href="add_asset.html"}}
|
||||||
</aside>
|
</aside>
|
||||||
{{elseif $subsubcurrent == "amortization" && $type_immo == null || $type_immo == "managed" || $type_immo == "other"}}
|
{{elseif $subsubcurrent == "amortization" && $type_immo == null || $type_immo == "managed" || $type_immo == "other"}}
|
||||||
<aside>
|
<aside>
|
||||||
|
|
@ -11,7 +11,7 @@
|
||||||
{{:linkbutton label="Rattacher une écriture" href="other_amortizations.html?immo_id=%s"|args:$_GET.immo_id shape="link" target="_dialog"}}
|
{{:linkbutton label="Rattacher une écriture" href="other_amortizations.html?immo_id=%s"|args:$_GET.immo_id shape="link" target="_dialog"}}
|
||||||
{{/if}}
|
{{/if}}
|
||||||
{{:linkbutton label="Enregistrer un amortissement" shape="plus"
|
{{:linkbutton label="Enregistrer un amortissement" shape="plus"
|
||||||
href="save_amort.html?immo_id=%s"|args:$_GET.immo_id target="_dialog"}}
|
href="save_amort.html?immo_id=%s"|args:$_GET.immo_id}}
|
||||||
</aside>
|
</aside>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -160,7 +160,7 @@
|
||||||
{{:admin_header title="Ajout immobilisation" current="module_amortization"}}
|
{{:admin_header title="Ajout immobilisation" current="module_amortization"}}
|
||||||
{{* barre de navigation *}}
|
{{* barre de navigation *}}
|
||||||
{{if ! $dialog}}
|
{{if ! $dialog}}
|
||||||
{{:include file="_nav.html" current="index"}}
|
{{:include file="_nav.html" current="index" subcurrent="managed"}}
|
||||||
{{/if}}
|
{{/if}}
|
||||||
|
|
||||||
{{:form_errors}}
|
{{:form_errors}}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
name="Amortissements"
|
name="Amortissements"
|
||||||
description="Immobilisations et amortissements\nversion 0.30"
|
description="Immobilisations et amortissements\nversion 0.31"
|
||||||
author="Jean-Christophe Engel"
|
author="Jean-Christophe Engel"
|
||||||
author_url="https://gitea.zaclys.com/lesanges"
|
author_url="https://gitea.zaclys.com/lesanges"
|
||||||
home_button=false
|
home_button=false
|
||||||
|
|
|
||||||
113
save_amort.html
113
save_amort.html
|
|
@ -7,20 +7,16 @@
|
||||||
|
|
||||||
{{* Infos de l'immobilisation *}}
|
{{* Infos de l'immobilisation *}}
|
||||||
{{#select
|
{{#select
|
||||||
line.id as immo_id,
|
|
||||||
line.id_account as account_id,
|
line.id_account as account_id,
|
||||||
line.debit as montant,
|
line.debit as montant,
|
||||||
line.id_project as project_id,
|
line.id_project as project_id,
|
||||||
trans.id as trans_id,
|
trans.id as trans_id,
|
||||||
trans.label,
|
trans.label,
|
||||||
trans.date,
|
trans.date,
|
||||||
y.id as year_id,
|
account.code as account_code
|
||||||
y.start_date,
|
|
||||||
y.end_date,
|
|
||||||
project.label as project_label
|
|
||||||
FROM acc_transactions_lines AS line
|
FROM acc_transactions_lines AS line
|
||||||
INNER JOIN acc_transactions AS trans ON line.id_transaction = trans.id
|
INNER JOIN acc_transactions AS trans ON line.id_transaction = trans.id
|
||||||
INNER JOIN acc_years AS y ON trans.id_year = y.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
|
LEFT JOIN acc_projects AS project ON line.id_project = project.id
|
||||||
WHERE line.id = :line_id;
|
WHERE line.id = :line_id;
|
||||||
:line_id = $_GET.immo_id|intval
|
:line_id = $_GET.immo_id|intval
|
||||||
|
|
@ -30,28 +26,54 @@
|
||||||
{{:error message="Immobilisation %s non trouvée"|args:$_GET.immo_id}}
|
{{:error message="Immobilisation %s non trouvée"|args:$_GET.immo_id}}
|
||||||
{{/select}}
|
{{/select}}
|
||||||
{{:assign date_debut=$ligne_immo.date}}
|
{{:assign date_debut=$ligne_immo.date}}
|
||||||
|
{{:assign var="amort_label" value="Amortissement %s"|args:$ligne_immo.label}}
|
||||||
|
|
||||||
{{#load type="immo" where="$$.line = :line_id" :line_id=$_GET.immo_id|intval}}
|
{{#load type="immo" where="$$.line = :line_id" :line_id=$_GET.immo_id|intval}}
|
||||||
{{:assign duree=$duration}}
|
{{:assign duree=$duration}}
|
||||||
{{:assign date_debut=$date}}
|
{{:assign date_debut=$date}}
|
||||||
{{if $amount != null}}
|
{{:assign status=$status}}
|
||||||
{{:assign var="ligne_immo.montant" value=$amount}}
|
|
||||||
{{/if}}
|
|
||||||
{{else}}
|
{{else}}
|
||||||
{{:error message="Vous devez renseigner la date de mise en service et la durée d'immobilisation"}}
|
{{:error message="Vous devez renseigner la date de mise en service et la durée d'immobilisation"}}
|
||||||
{{/load}}
|
{{/load}}
|
||||||
|
|
||||||
|
{{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_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_id AND line.credit > 0 AND acc.code = :account;
|
||||||
|
:immo_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 *}}
|
{{* chercher des écritures d'amortissement liées à l'immobilisation *}}
|
||||||
{{#select
|
{{#select
|
||||||
SUM(l_amort.credit) as amort_amount,
|
l_amort.credit as amort_amount,
|
||||||
l_amort.label as amort_label,
|
l_amort.label as amort_label,
|
||||||
l_amort.id as amort_line_id,
|
l_amort.id as amort_line_id,
|
||||||
CASE WHEN links.id_related = t_immo.id
|
CASE WHEN links.id_related = t_immo.id
|
||||||
THEN links.id_transaction
|
THEN links.id_transaction
|
||||||
ELSE links.id_related
|
ELSE links.id_related
|
||||||
END as amort_trans_id,
|
END as amort_trans_id,
|
||||||
MAX(trans.date) as amort_date,
|
trans.date as amort_date,
|
||||||
COUNT(trans.id) as amort_number,
|
|
||||||
trans.label as trans_label,
|
trans.label as trans_label,
|
||||||
trans.id_year as amort_year,
|
trans.id_year as amort_year,
|
||||||
account.id as account_id,
|
account.id as account_id,
|
||||||
|
|
@ -60,20 +82,48 @@
|
||||||
FROM acc_transactions_lines as l_immo
|
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 as t_immo on t_immo.id = l_immo.id_transaction
|
||||||
INNER JOIN acc_transactions_links as links
|
INNER JOIN acc_transactions_links as links
|
||||||
ON (t_immo.id = links.id_transaction
|
ON (t_immo.id = links.id_transaction OR t_immo.id = links.id_related)
|
||||||
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_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_transactions as trans on l_amort.id_transaction = trans.id
|
||||||
INNER join acc_accounts as account on l_amort.id_account = account.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%'
|
WHERE
|
||||||
ORDER BY trans.date DESC LIMIT 1;
|
l_immo.id = :line_id
|
||||||
|
AND account.code LIKE '28%'
|
||||||
|
ORDER BY trans.date;
|
||||||
:line_id = $_GET.immo_id|intval
|
:line_id = $_GET.immo_id|intval
|
||||||
assign=amort_line
|
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_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}}
|
{{/select}}
|
||||||
|
|
||||||
{{if $amort_line.amort_number == 0}}
|
|
||||||
|
{{:assign total_amort=0}}
|
||||||
|
{{:assign valeur_residuelle=$ligne_immo.montant}}
|
||||||
|
{{#foreach from=$linked_amort}}
|
||||||
|
{{:assign valeur_residuelle="%d-%d"|math:$valeur_residuelle:$amort_amount}}
|
||||||
|
{{:assign total_amort="%d+%d"|math:$total_amort:$amort_amount}}
|
||||||
|
{{:assign date_debut=$amort_date}}
|
||||||
|
{{:assign code_amort=$account_code}}
|
||||||
|
{{:assign amort_account_label=$account_label}}
|
||||||
|
{{:assign amort_label=$amort_label}}
|
||||||
|
{{/foreach}}
|
||||||
|
|
||||||
|
{{if $valeur_residuelle == 0}}
|
||||||
|
{{:error message="Cette immobilisation est complètement amortie ; il est impossible d'ajouter une écriture d'amortissement"}}
|
||||||
|
{{/if}}
|
||||||
|
|
||||||
|
{{if $total_amort == 0}}
|
||||||
{{* 1er amortissement *}}
|
{{* 1er amortissement *}}
|
||||||
{{* déterminer le compte d'amortissement en fonction du compte d'immobilisation *}}
|
{{* déterminer le compte d'amortissement en fonction du compte d'immobilisation *}}
|
||||||
{{#select code, label from acc_accounts where id = :id; :id=$ligne_immo.account_id assign=amort_account}}
|
{{#select code, label from acc_accounts where id = :id; :id=$ligne_immo.account_id assign=amort_account}}
|
||||||
|
|
@ -83,15 +133,12 @@
|
||||||
code_immo=$amort_account.code
|
code_immo=$amort_account.code
|
||||||
keep="code_amort"
|
keep="code_amort"
|
||||||
}}
|
}}
|
||||||
{{:assign var=amort_label value="Amortissement %s"|args:$amort_account.label}}
|
{{: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.label}}
|
||||||
{{else}}
|
{{else}}
|
||||||
{{* amortissements suivants *}}
|
{{* amortissements suivants *}}
|
||||||
{{:assign date_debut=$amort_line.amort_date|strtotime}}
|
{{:assign date_debut=$date_debut|strtotime}}
|
||||||
{{:assign date_debut="%d+(60*60*24)"|math:$date_debut|date:"Y-m-d"}}
|
{{:assign date_debut="%d+(60*60*24)"|math:$date_debut|date:"Y-m-d"}}
|
||||||
{{:assign var=code_amort value=$amort_line.account_code}}
|
|
||||||
{{:assign var=amort_label value=$amort_line.account_label}}
|
|
||||||
{{:assign var=libelle value=$amort_line.amort_label}}
|
|
||||||
{{/if}}
|
{{/if}}
|
||||||
|
|
||||||
{{*
|
{{*
|
||||||
|
|
@ -101,7 +148,7 @@
|
||||||
{{:assign msg_years=""}}
|
{{:assign msg_years=""}}
|
||||||
{{#years closed=false order="start_date" where="start_date <= :debut AND :debut <= end_date"
|
{{#years closed=false order="start_date" where="start_date <= :debut AND :debut <= end_date"
|
||||||
:debut=$date_debut assign=years.}}
|
:debut=$date_debut assign=years.}}
|
||||||
{{if $amort_line.amort_number == 0}}
|
{{if $total_amort == 0}}
|
||||||
{{:assign ts_debut=$date_debut|strtotime}}
|
{{:assign ts_debut=$date_debut|strtotime}}
|
||||||
{{else}}
|
{{else}}
|
||||||
{{:assign ts_debut=$start_date|strtotime}}
|
{{:assign ts_debut=$start_date|strtotime}}
|
||||||
|
|
@ -174,7 +221,7 @@
|
||||||
{{/if}}
|
{{/if}}
|
||||||
|
|
||||||
{{* vérifier que le montant ne dépasse pas le solde restant *}}
|
{{* vérifier que le montant ne dépasse pas le solde restant *}}
|
||||||
{{:assign solde="%d-%d"|math:$ligne_immo.montant:$amort_line.amort_amount}}
|
{{:assign solde="%d-%d"|math:$ligne_immo.montant:$total_amort}}
|
||||||
{{if $_POST.montant|trim|money_int > $solde|intval}}
|
{{if $_POST.montant|trim|money_int > $solde|intval}}
|
||||||
{{:assign solde=$solde|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:$_POST.montant:$solde}}
|
||||||
|
|
@ -185,14 +232,14 @@
|
||||||
var="lines."
|
var="lines."
|
||||||
debit=$_POST.montant
|
debit=$_POST.montant
|
||||||
account=$debit_account|keys|value:0
|
account=$debit_account|keys|value:0
|
||||||
id_project=$_GET.project_id
|
id_project=$ligne_immo.project_id
|
||||||
label=$_POST.designation
|
label=$_POST.designation
|
||||||
}}
|
}}
|
||||||
{{:assign
|
{{:assign
|
||||||
var="lines."
|
var="lines."
|
||||||
credit=$_POST.montant
|
credit=$_POST.montant
|
||||||
account=$credit_account|keys|value:0
|
account=$credit_account|keys|value:0
|
||||||
id_project=$_GET.project_id
|
id_project=$ligne_immo.project_id
|
||||||
label=$_POST.designation
|
label=$_POST.designation
|
||||||
}}
|
}}
|
||||||
{{:api
|
{{:api
|
||||||
|
|
@ -211,7 +258,7 @@
|
||||||
{{:redirect force="amortization.html?immo_id=%s&ok=1&msg=amortissement"|args:$_GET.immo_id}}
|
{{:redirect force="amortization.html?immo_id=%s&ok=1&msg=amortissement"|args:$_GET.immo_id}}
|
||||||
{{/form}}
|
{{/form}}
|
||||||
|
|
||||||
{{:admin_header title="Ajout amortissement" current="module_amortization"}}
|
{{:admin_header title="Ajout amortissement" custom_css="./style.css" current="module_amortization"}}
|
||||||
|
|
||||||
{{* barre de navigation *}}
|
{{* barre de navigation *}}
|
||||||
{{if ! $dialog}}
|
{{if ! $dialog}}
|
||||||
|
|
@ -226,9 +273,9 @@
|
||||||
|
|
||||||
{{* montant de l'amortissement *}}
|
{{* montant de l'amortissement *}}
|
||||||
{{:assign montant_amort="%f/%f/365*%d"|math:$ligne_immo.montant:$duree:$nbjours|intval}}
|
{{: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:$amort_line.amort_amount}}
|
{{:assign montant_amort="min(%f, %d-%d)"|math:$montant_amort:$ligne_immo.montant:$total_amort}}
|
||||||
{{:assign var="debit_account.6811" value="6811 — Dot. aux amortissements des immobilisations"}}
|
{{: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_label}}
|
{{:assign var="credit_account.%s"|args:$code_amort value="%s — "|args:$code_amort|cat:$amort_account_label}}
|
||||||
|
|
||||||
{{* -------------------------------------------------------------------------------- *}}
|
{{* -------------------------------------------------------------------------------- *}}
|
||||||
|
|
||||||
|
|
@ -242,7 +289,7 @@
|
||||||
<dl>
|
<dl>
|
||||||
{{:input type="select" default=$selected_year name="id_year" label="Exercice" required=true default_empty="— Faire un choix —" options=$open_years}}
|
{{:input type="select" default=$selected_year name="id_year" label="Exercice" required=true default_empty="— Faire un choix —" options=$open_years}}
|
||||||
{{:input type="date" name="date_amort" label="Date" required=true default=$date_amort|date_short}}
|
{{:input type="date" name="date_amort" label="Date" required=true default=$date_amort|date_short}}
|
||||||
{{:input type="text" name="designation" label="Libellé" required=true default=$libelle}}
|
{{:input type="text" name="designation" label="Libellé" required=true default=$amort_label}}
|
||||||
{{:input type="money" name="montant" label="Montant" required=true default=$montant_amort}}
|
{{:input type="money" name="montant" label="Montant" required=true default=$montant_amort}}
|
||||||
{{:input
|
{{:input
|
||||||
type="list"
|
type="list"
|
||||||
|
|
@ -263,7 +310,7 @@
|
||||||
<div id="donnees" class="hidden">
|
<div id="donnees" class="hidden">
|
||||||
{{:input type="text" name="montant_immo" default=$ligne_immo.montant}}
|
{{:input type="text" name="montant_immo" default=$ligne_immo.montant}}
|
||||||
{{:input type="text" name="duree_amort" default=$duree}}
|
{{:input type="text" name="duree_amort" default=$duree}}
|
||||||
{{:input type="text" name="somme_amort" default=$amort_line.amort_amount}}
|
{{:input type="text" name="somme_amort" default=$total_amort}}
|
||||||
{{:input type="select" name="years_data" options=$years_data}}
|
{{:input type="select" name="years_data" options=$years_data}}
|
||||||
</div>
|
</div>
|
||||||
</dl>
|
</dl>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue