Compare commits

..

No commits in common. "885f7372335ae5518f30dd20ea90703d349c31cb" and "f3c2d2c884f759ac268fbca5450c333f605ff70c" have entirely different histories.

9 changed files with 58 additions and 66 deletions

View File

@ -1,7 +1,6 @@
# Module de gestion d'amortissements pour Paheko # Module de gestion d'amortissements pour Paheko
Ce module permet de gérer les écritures d'amortissements pour les immobilisations : Ce module permet de gérer les écritures d'amortissements pour les immobilisations :
- lister les immobilisations - lister les immobilisations
- ajouter une nouvelle immobilisation - ajouter une nouvelle immobilisation
- lister les amortissements d'une immobilisation : - lister les amortissements d'une immobilisation :

View File

@ -30,13 +30,13 @@
}} }}
{{* enregistrer les infos de l'immobilisation *}} {{* enregistrer les infos de l'immobilisation *}}
{{:assign var="immo_id" value=$result.lines.1.id}} {{:assign var="line_id" value=$result.lines.1.id}}
{{:assign key=""|uuid}} {{:assign key=""|uuid}}
{{:save {{:save
key=$key key=$key
validate_schema="schema.json" validate_schema="schema.json"
type="immo" type="immo"
line=$immo_id line=$line_id
duration=$_POST.duree|intval duration=$_POST.duree|intval
}} }}

View File

@ -14,13 +14,13 @@
{{* Traiter l'envoi du formulaire *}} {{* Traiter l'envoi du formulaire *}}
{{#form on="add"}} {{#form on="add"}}
{{* enregistrer les infos de l'immobilisation *}} {{* enregistrer les infos de l'immobilisation *}}
{{:assign var="immo_id" value=$_GET.immo_id|intval}} {{:assign var="line_id" value=$_GET.line_id|intval}}
{{:assign key=""|uuid}} {{:assign key=""|uuid}}
{{:save {{:save
key=$key key=$key
validate_schema="schema.json" validate_schema="schema.json"
type="immo" type="immo"
line=$immo_id line=$line_id
duration=$_POST.duree|intval duration=$_POST.duree|intval
}} }}

View File

@ -24,18 +24,27 @@
{{/if}} {{/if}}
{{* récupérer les infos de l'immobilisation *}} {{* récupérer les infos de l'immobilisation *}}
{{#load type="immo" assign="info_immo" where="$$.line = :line_id" :line_id=$_GET.immo_id|intval}} {{#load type="immo" assign="info_immo" where="$$.line = :line_id" :line_id=$_GET.line_id|intval}}
{{else}}
{{:assign message="Pas d'info concernant l'immobilisation %s"|args:$_GET.line_id}}
{{:error message=$message}}
{{/load}}
{{* liste de toutes les immobilisations gérées *}}
{{#load type="immo"}}
{{:assign
var="info_immos.%s"|args:$line
duration=$duration
amort=$amort
}}
{{#foreach from=$amort item="elem"}} {{#foreach from=$amort item="elem"}}
{{:assign var="amort_associes." value=$elem"}} {{:assign var="amort_associes." value=$elem"}}
{{/foreach}} {{/foreach}}
{{else}}
{{:assign message="Pas d'info concernant l'immobilisation %s"|args:$_GET.immo_id}}
{{:error message=$message}}
{{/load}} {{/load}}
{{:assign var="duree" from="info_immo.duration"|args:$_GET.immo_id}} {{:assign var="duree" from="info_immos.%s.duration"|args:$_GET.line_id}}
{{#select {{#select
line.id as immo_id, line.id as line_id,
line.id_account as account_id, line.id_account as account_id,
line.id_project as project_id, line.id_project as project_id,
line.debit as montant, line.debit as montant,
@ -43,67 +52,59 @@
trans.label as label, trans.label as label,
trans.date as date_achat, trans.date as date_achat,
y.id as year_id, y.id as year_id,
date(y.start_date, "start of year", "+1 year", "-1 day") as date_amort, y.end_date as date_fin,
project.label as project_label 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_years as y on trans.id_year = y.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.line_id|intval
assign=ligne_immo assign=ligne_immo
}} }}
<h2>Amortissement de « {{$label}} » d'un montant de {{"%f"|math:$montant|money_currency}} en date du {{$date_achat|date_short}} sur {{$duree}} ans</h2> <h2>Amortissement de « {{$label}} » d'un montant de {{"%f"|math:$montant|money_currency}} en date du {{$date_achat|date_short}} sur {{$duree}} ans</h2>
{{else}} {{else}}
{{:assign message="Immobilisation %s non trouvée"|args:$_GET.immo_id}} {{:assign message="Immobilisation %s non trouvée"|args:$_GET.line_id}}
{{:error message=$message}} {{:error message=$message}}
{{/select}} {{/select}}
{{*:debug ligne_immo=$ligne_immo*}}
{{* chercher des écritures d'amortissement liées à l'immobilisation *}} {{* chercher des écritures d'amortissement liées à l'immobilisation *}}
{{#select {{#select
l_immo.id,
l_immo.id_account,
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, l_amort.id as amort_line,
CASE links.id_related = t_immo.id l_amort.id_transaction as amort_trans_id,
WHEN true THEN links.id_transaction l_amort.id_project as projet,
WHEN false THEN links.id_related l_amort.id_account as account_id,
END as amort_trans_id, l_amort.id_project as project_id,
project.label as project_label,
trans.date as amort_date, trans.date as amort_date,
trans.label as trans_label, trans.label as trans_label,
trans.id_year as amort_year, trans.id_year as amort_year,
acc.code as account_code, acc.code as account_code,
acc.label as account_name, acc.label as account_name,
acc.id_chart as PC,
"vrai" as linked "vrai" as linked
FROM from acc_transactions_lines as l_immo
acc_transactions_lines as l_immo inner JOIN acc_transactions_links as links on l_immo.id_transaction = links.id_related
INNER JOIN acc_transactions as t_immo on t_immo.id = l_immo.id_transaction inner JOIN acc_transactions_lines as l_amort on links.id_transaction = l_amort.id_transaction
INNER JOIN acc_transactions_links as links inner join acc_accounts as acc on l_amort.id_account = acc.id
ON ( inner join acc_transactions as trans on l_amort.id_transaction = trans.id
t_immo.id = links.id_transaction inner join acc_projects AS project ON l_immo.id_project = project.id
OR where l_immo.id = :line_id and l_amort.credit <> 0
t_immo.id = links.id_related order by trans.date;
) :line_id = $_GET.line_id|intval
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 acc on l_amort.id_account = acc.id
WHERE
l_immo.id = :line_id
AND
l_amort.credit <> 0
ORDER BY trans.date;
:line_id = $_GET.immo_id|intval
assign=linked_lines. assign=linked_lines.
}} }}
{{:assign var="amort_associes." value=$amort_line}} {{:assign var="amort_associes." value=$amort_line}}
{{:assign var="amort_years." value=$amort_year}} {{:assign var="amort_years." value=$amort_year}}
{{/select}} {{/select}}
{{*:debug linked_lines=$linked_lines amort_associes=$amort_associes*}}
{{* chercher parmi les associations *}} {{* chercher parmi les associations *}}
{{#foreach from=$info_immo.amort item="id_amort"}} {{:assign var="liste_amort" from="info_immos.%s.amort"|args:$_GET.line_id}}
{{#foreach from=$liste_amort item="id_amort"}}
{{#select {{#select
l_amort.id_transaction as amort_trans_id, l_amort.id_transaction as amort_trans_id,
l_amort.credit as amort_amount, l_amort.credit as amort_amount,
@ -138,18 +139,17 @@
{{/select}} {{/select}}
{{/foreach}} {{/foreach}}
{{*:debug linked_lines=$linked_lines*}}
{{* montant de l'annuité théorique *}} {{* montant de l'annuité théorique *}}
{{:assign montant="%f"|math:$ligne_immo.montant}} {{:assign montant="%f"|math:$ligne_immo.montant}}
{{:assign annuite="%f/%f"|math:$montant:$duree}} {{:assign annuite="%f/%f"|math:$montant:$duree}}
{{* première annuité *}} {{* première annuité *}}
{{:assign date_achat=$ligne_immo.date_achat|date_short}} {{:assign date_achat=$ligne_immo.date_achat|date_short}}
{{:assign date_amort=$ligne_immo.date_amort|date_short}} {{:assign date_fin=$ligne_immo.date_fin|date_short}}
{{:include file="_calcul_dates.html" date_debut=$date_achat date_fin=$date_amort keep="nbjours"}} {{:include file="_calcul_dates.html" date_debut=$date_achat date_fin=$date_fin keep="nbjours"}}
{{:assign annuite_1="%f/360*%d"|math:$annuite:$nbjours|intval}} {{:assign annuite_1="%f/360*%d"|math:$annuite:$nbjours|intval}}
{{*:assign date_amort=$date_fin*}} {{:assign date_amort=$date_fin}}
{{:assign annuite_courante=$annuite_1}} {{:assign annuite_courante=$annuite_1}}
{{:assign current_year=$ligne_immo.year_id}} {{:assign current_year=$ligne_immo.year_id}}
{{:assign solde=$ligne_immo.montant}} {{:assign solde=$ligne_immo.montant}}
@ -201,7 +201,7 @@
<td>{{$line.project_label}}</td> <td>{{$line.project_label}}</td>
<td> <td>
{{if $line.linked == null}} {{if $line.linked == null}}
{{:linkbutton label="Détacher" href="detach_amort.html?amort_id=%d&immo_id=%d"|args:$line.amort_line:$ligne_immo.immo_id shape="plus"}} {{:linkbutton label="Détacher" href="detach_amort.html?amort_id=%d&immo_id=%d"|args:$line.amort_line:$ligne_immo.line_id shape="plus"}}
{{else}} {{else}}
{{:linkbutton label="Détacher" href="" shape="lock" class="disabled"}} {{:linkbutton label="Détacher" href="" shape="lock" class="disabled"}}
{{/if}} {{/if}}
@ -243,7 +243,7 @@
<tbody> <tbody>
{{#foreach count="%d+1"|math:$nbamort key="num"}} {{#foreach count="%d+1"|math:$nbamort key="num"}}
{{:assign solde="%f-%d"|math:$solde:$annuite_courante}} {{:assign solde="%f-%d"|math:$solde:$annuite_courante}}
{{#select id from acc_years where :amort_date >= start_date and :amort_date <= end_date and closed = 0; :amort_date=$date_amort|parse_date}} {{#select id from acc_years where end_date = :end_date and closed = 0; :end_date=$date_amort|parse_date}}
{{:assign enregistrer=1}} {{:assign enregistrer=1}}
{{:assign current_year=$id}} {{:assign current_year=$id}}
{{else}} {{else}}
@ -267,7 +267,7 @@
{{if $enregistrer == 1}} {{if $enregistrer == 1}}
{{:linkbutton {{:linkbutton
label="Enregistrer" label="Enregistrer"
href="save_amort.html?amount=%d&account=%s&year=%s&trans_id=%d&immo_id=%s&project_id=%d&label=%s"|args:$annuite_courante:$ligne_immo.account_id:$current_year:$ligne_immo.trans_id:$_GET.immo_id:$project_id:$libelle href="save_amort.html?amount=%d&account=%s&year=%s&trans_id=%d&line_id=%s&project_id=%d&label=%s"|args:$annuite_courante:$ligne_immo.account_id:$current_year:$ligne_immo.trans_id:$_GET.line_id:$project_id:$libelle
shape="right" shape="right"
target="_dialog" target="_dialog"
}} }}
@ -352,7 +352,7 @@
<td>{{$p_label}}</td> <td>{{$p_label}}</td>
<td> <td>
{{if $linked != "true"}} {{if $linked != "true"}}
{{:linkbutton label="Attacher" href="attach_amort.html?amort_id=%d&immo_id=%d"|args:$l_id:$ligne_immo.immo_id shape="plus"}} {{:linkbutton label="Attacher" href="attach_amort.html?amort_id=%d&immo_id=%d"|args:$l_id:$ligne_immo.line_id shape="plus"}}
{{else}} {{else}}
{{:linkbutton label="Attacher" href="" shape="lock" class="disabled"}} {{:linkbutton label="Attacher" href="" shape="lock" class="disabled"}}
{{/if}} {{/if}}

View File

@ -30,4 +30,4 @@
duration=$info_immo.duration duration=$info_immo.duration
amort=$assoc amort=$assoc
}} }}
{{:redirect to="amortization.html?immo_id=%s&ok=1&msg=attach"|args:$_GET.immo_id}} {{:redirect to="amortization.html?line_id=%s&ok=1&msg=attach"|args:$_GET.immo_id}}

View File

@ -28,4 +28,4 @@
duration=$info_immo.duration duration=$info_immo.duration
amort=$t_amort amort=$t_amort
}} }}
{{:redirect to="amortization.html?immo_id=%s&ok=1&msg=detach"|args:$_GET.immo_id}} {{:redirect to="amortization.html?line_id=%s&ok=1&msg=detach"|args:$_GET.immo_id}}

View File

@ -42,7 +42,7 @@
trans.id as trans_id, trans.id as trans_id,
trans.label as trans_label, trans.label as trans_label,
trans.date as trans_date, trans.date as trans_date,
line.id as immo_id, line.id as line_id,
account.code as account_code, account.code as account_code,
account.label as account_label, account.label as account_label,
line.debit AS debit, line.debit AS debit,
@ -57,7 +57,7 @@
ORDER BY trans.date DESC ORDER BY trans.date DESC
}} }}
{{:assign trans_url="%s/acc/transactions/details.php?id=%s"|args:$admin_url:$trans_id}} {{:assign trans_url="%s/acc/transactions/details.php?id=%s"|args:$admin_url:$trans_id}}
{{#load type="immo" where="$$.line = :line_id" :line_id=$immo_id|intval}} {{#load type="immo" where="$$.line = :line_id" :line_id=$line_id|intval}}
{{*:debug info_immo=$info_immo*}} {{*:debug info_immo=$info_immo*}}
{{:assign duration=$duration}} {{:assign duration=$duration}}
{{else}} {{else}}
@ -77,14 +77,14 @@
{{if $duration == null}} {{if $duration == null}}
{{:linkbutton {{:linkbutton
label="Ajouter durée" label="Ajouter durée"
href="add_duration.html?immo_id=%s"|args:$immo_id href="add_duration.html?line_id=%s"|args:$line_id
shape="help" shape="help"
target="_dialog" target="_dialog"
}} }}
{{else}} {{else}}
{{:linkbutton {{:linkbutton
label="Amortissements" label="Amortissements"
href="amortization.html?immo_id=%s"|args:$immo_id href="amortization.html?line_id=%s"|args:$line_id
shape="table" shape="table"
}} }}
{{/if}} {{/if}}

View File

@ -1,4 +1,4 @@
name="Amortissements" name="Gestion des amortissements"
description="Gestion des amortissements pour le logiciel de comptabilité Paheko" description="Gestion des amortissements pour le logiciel de comptabilité Paheko"
author="Jean-Christophe Engel" author="Jean-Christophe Engel"
author_url="https://git.roflcopter.fr/lesanges" author_url="https://git.roflcopter.fr/lesanges"

View File

@ -40,7 +40,7 @@
linked_transactions=$_GET.trans_id|intval linked_transactions=$_GET.trans_id|intval
}} }}
{{:redirect force="amortization.html?immo_id=%s&ok=1&msg=amortissement"|args:$_GET.immo_id}} {{:redirect force="amortization.html?line_id=%s&ok=1&msg=amortissement"|args:$_GET.line_id}}
{{/form}} {{/form}}
{{* Préparer les infos pour le formulaire *}} {{* Préparer les infos pour le formulaire *}}
@ -56,14 +56,7 @@
{{:assign amort_code=$c1|cat:8|cat:$reste}} {{:assign amort_code=$c1|cat:8|cat:$reste}}
{{:assign var="credit_account.%s"|args:$amort_code value="%s — Amortissements "|args:$amort_code|cat:$amort_account.label}} {{:assign var="credit_account.%s"|args:$amort_code value="%s — Amortissements "|args:$amort_code|cat:$amort_account.label}}
{{#select {{#select id, label, end_date from acc_years where id=:id; :id=$_GET.year assign=year}}{{/select}}
id,
label,
date(start_date, "start of year", "+1 year", "-1 day") as date_amort
from acc_years where id=:id;
:id=$_GET.year assign=year
}}
{{/select}}
{{#years closed=false}} {{#years closed=false}}
{{:assign var="open_years.%d"|args:$id value=$label}} {{:assign var="open_years.%d"|args:$id value=$label}}
@ -74,7 +67,7 @@
<legend>Ajouter une écriture d'amortissement</legend> <legend>Ajouter une écriture d'amortissement</legend>
<dl> <dl>
{{:input type="select" default=$year.id name="id_year" label="Exercice" required=true options=$open_years}} {{:input type="select" default=$year.id name="id_year" label="Exercice" required=true options=$open_years}}
{{:input type="date" name="date" label="Date" required=true default=$year.date_amort|date_short}} {{:input type="date" name="date" label="Date" required=true default=$year.end_date|date_short}}
{{:input type="text" name="designation" label="Désignation" required=true default=$_GET.label}} {{:input type="text" name="designation" label="Désignation" required=true default=$_GET.label}}
{{:input type="money" name="montant" label="Montant" required=true default=$_GET.amount}} {{:input type="money" name="montant" label="Montant" required=true default=$_GET.amount}}
{{:input {{:input