|
|
|
|
@ -3,7 +3,6 @@
|
|
|
|
|
{{*
|
|
|
|
|
Sortir une immobilisation du bilan
|
|
|
|
|
@param immo_line_id : id de la ligne d'immobilisation
|
|
|
|
|
@param immo_doc_id : id du doc associé à l'immo
|
|
|
|
|
*}}
|
|
|
|
|
|
|
|
|
|
{{* Infos de l'immobilisation *}}
|
|
|
|
|
@ -21,49 +20,23 @@
|
|
|
|
|
assign="ligne_immo"
|
|
|
|
|
}}
|
|
|
|
|
{{else}}
|
|
|
|
|
{{:error message="Immobilisation non trouvée"}}
|
|
|
|
|
{{:error message="Immobilisation %s non trouvée"|args:$_GET.immo_line_id}}
|
|
|
|
|
{{/select}}
|
|
|
|
|
|
|
|
|
|
{{:assign date_debut=$ligne_immo.date_achat}}
|
|
|
|
|
{{:assign ts_mes=$ligne_immo.date_achat|strtotime}}
|
|
|
|
|
|
|
|
|
|
{{* TODO : traiter le cas des immos sans doc *}}
|
|
|
|
|
{{#load id=$_GET.immo_doc_id|intval assign="info_immo"}}
|
|
|
|
|
{{:assign ts_mes=$date_mes|strtotime}}
|
|
|
|
|
{{if $date_mes != null}}
|
|
|
|
|
{{:assign date_debut=$date_mes}}
|
|
|
|
|
{{/if}}
|
|
|
|
|
{{#load type="immo" assign="info_immo" where="$$.line = :line_id" :line_id=$_GET.immo_line_id|intval}}
|
|
|
|
|
{{:assign ts_mes=$date|strtotime}}
|
|
|
|
|
{{:assign date_debut=$date}}
|
|
|
|
|
{{:assign duree_amort=$duration}}
|
|
|
|
|
{{if $amount != null}}
|
|
|
|
|
{{:assign var="ligne_immo.montant" value=$amount}}
|
|
|
|
|
{{/if}}
|
|
|
|
|
{{else}}
|
|
|
|
|
{{* TODO *}}
|
|
|
|
|
{{:error message="Immobilisation non trouvée"}}
|
|
|
|
|
{{/load}}
|
|
|
|
|
|
|
|
|
|
{{* 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 = $info_immo.id
|
|
|
|
|
assign="credit_link"
|
|
|
|
|
}}
|
|
|
|
|
{{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}}
|
|
|
|
|
{{else}}
|
|
|
|
|
{{* pas de doc => voir liaison écritures *}}
|
|
|
|
|
{{#select
|
|
|
|
|
{{#select
|
|
|
|
|
CASE links.id_related = :immo_trans_id
|
|
|
|
|
WHEN true THEN links.id_transaction
|
|
|
|
|
WHEN false THEN links.id_related
|
|
|
|
|
@ -77,64 +50,80 @@
|
|
|
|
|
WHERE trans.id = :immo_trans_id AND line.credit > 0 AND acc.code = :account;
|
|
|
|
|
:immo_trans_id=$ligne_immo.trans_id
|
|
|
|
|
:account=$ligne_immo.account_code
|
|
|
|
|
}}
|
|
|
|
|
}}
|
|
|
|
|
{{:assign total_credits="%d+%d"|math:$total_credits:$credit}}
|
|
|
|
|
{{/select}}
|
|
|
|
|
{{/load}}
|
|
|
|
|
{{/select}}
|
|
|
|
|
{{:assign var="ligne_immo.montant" value="%d-%d"|math:$ligne_immo.montant:$total_credits}}
|
|
|
|
|
|
|
|
|
|
{{* chercher des écritures d'amortissement liées à l'immobilisation *}}
|
|
|
|
|
{{:assign total_amort=0}}
|
|
|
|
|
{{#load type="amort_link"
|
|
|
|
|
where="$$.immo_doc_id = :immo_doc_id"
|
|
|
|
|
:immo_doc_id = $_GET.immo_doc_id|intval
|
|
|
|
|
}}
|
|
|
|
|
{{#select
|
|
|
|
|
line.id as amort_line_id,
|
|
|
|
|
line.credit,
|
|
|
|
|
line.label as amort_line_label,
|
|
|
|
|
trans.id as amort_trans_id,
|
|
|
|
|
trans.label as amort_trans_label,
|
|
|
|
|
trans.date as amort_date,
|
|
|
|
|
trans.id_year as amort_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_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
|
|
|
|
|
{{:assign amort_number=0}}
|
|
|
|
|
{{#select
|
|
|
|
|
l_amort.credit as amort_amount,
|
|
|
|
|
l_amort.id as amort_line_id,
|
|
|
|
|
CASE
|
|
|
|
|
WHEN links.id_related = t_immo.id
|
|
|
|
|
THEN links.id_transaction
|
|
|
|
|
ELSE links.id_related
|
|
|
|
|
END as amort_trans_id,
|
|
|
|
|
trans.date
|
|
|
|
|
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_links as links
|
|
|
|
|
ON (t_immo.id = links.id_transaction 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 as trans on l_amort.id_transaction = trans.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%'
|
|
|
|
|
;
|
|
|
|
|
:amort_line_id = $amort_line_id
|
|
|
|
|
:line_id = $_GET.immo_line_id|intval
|
|
|
|
|
assign="amort_line"
|
|
|
|
|
}}
|
|
|
|
|
{{:assign var="amort_line.amort_amount" value=$amount|or:$credit}}
|
|
|
|
|
{{:assign total_amort="%d+%d"|math:$total_amort:$amort_line.amort_amount}}
|
|
|
|
|
{{:assign var="linked_amort.%s_%d"|args:$amort_date:$id value=$amort_line}}
|
|
|
|
|
{{/select}}
|
|
|
|
|
{{/load}}
|
|
|
|
|
{{:assign amort_number=$linked_amort|count}}
|
|
|
|
|
}}
|
|
|
|
|
|
|
|
|
|
{{#foreach from=$linked_amort|ksort item="line"}}
|
|
|
|
|
{{#load type="link"
|
|
|
|
|
where="$$.immo_line_id = :immo_line_id AND $$.amort_trans_id = :amort_trans_id"
|
|
|
|
|
assign="line"
|
|
|
|
|
:immo_line_id=$_GET.immo_line_id|intval :amort_trans_id=$amort_line.amort_trans_id
|
|
|
|
|
}}
|
|
|
|
|
{{if $line.amort_line_id == $amort_line.amort_line_id}}
|
|
|
|
|
{{:assign amort_number="%d+1"|math:$amort_number}}
|
|
|
|
|
{{:assign total_amort="%d+%d"|math:$total_amort:$amort_line.amort_amount}}
|
|
|
|
|
{{if $first_amort_date == null}}
|
|
|
|
|
{{:assign first_amort_date=$line.amort_date}}
|
|
|
|
|
{{:assign first_amort_date=$amort_line.date}}
|
|
|
|
|
{{elseif $amort_line.date < $first_amort_date}}
|
|
|
|
|
{{:assign first_amort_date=$amort_line.date}}
|
|
|
|
|
{{/if}}
|
|
|
|
|
{{if $last_amort_date == null}}
|
|
|
|
|
{{:assign last_amort_date=$line.amort_date}}
|
|
|
|
|
{{elseif $line.amort_date > $last_amort_date}}
|
|
|
|
|
{{:assign last_amort_date=$line.amort_date}}
|
|
|
|
|
{{:assign last_amort_date=$amort_line.date}}
|
|
|
|
|
{{elseif $amort_line.date > $last_amort_date}}
|
|
|
|
|
{{:assign last_amort_date=$amort_line.date}}
|
|
|
|
|
{{/if}}
|
|
|
|
|
{{/foreach}}
|
|
|
|
|
{{/if}}
|
|
|
|
|
{{else}}
|
|
|
|
|
{{:assign amort_number="%d+1"|math:$amort_number}}
|
|
|
|
|
{{:assign total_amort="%d+%d"|math:$total_amort:$amort_line.amort_amount}}
|
|
|
|
|
{{if $first_amort_date == null}}
|
|
|
|
|
{{:assign first_amort_date=$amort_line.date}}
|
|
|
|
|
{{elseif $amort_line.date < $first_amort_date}}
|
|
|
|
|
{{:assign first_amort_date=$amort_line.date}}
|
|
|
|
|
{{/if}}
|
|
|
|
|
{{if $last_amort_date == null}}
|
|
|
|
|
{{:assign last_amort_date=$amort_line.date}}
|
|
|
|
|
{{elseif $amort_line.date > $last_amort_date}}
|
|
|
|
|
{{:assign last_amort_date=$amort_line.date}}
|
|
|
|
|
{{/if}}
|
|
|
|
|
{{/load}}
|
|
|
|
|
{{/select}}
|
|
|
|
|
|
|
|
|
|
{{if $total_amort == 0}}
|
|
|
|
|
{{if $info_immo.status == "amortized"}}
|
|
|
|
|
{{:assign total_amort=$ligne_immo.montant}}
|
|
|
|
|
{{/if}}
|
|
|
|
|
{{else}}
|
|
|
|
|
{{:assign date_debut=$last_amort_date}}
|
|
|
|
|
{{:assign date_debut=$last_amort_date|strtotime}}
|
|
|
|
|
{{:assign date_debut="%d+(60*60*24)"|math:$date_debut|date:"Y-m-d"}}
|
|
|
|
|
{{/if}}
|
|
|
|
|
{{:assign ts_debut=$date_debut|strtotime}}
|
|
|
|
|
{{:assign ts_debut="%d+(60*60*24)"|math:$ts_debut}}
|
|
|
|
|
{{:assign date_debut=$ts_debut|date:"Y-m-d"}}
|
|
|
|
|
{{:assign valeur_nette="%f-%f"|math:$ligne_immo.montant:$total_amort}}
|
|
|
|
|
|
|
|
|
|
{{*
|
|
|
|
|
@ -150,8 +139,7 @@
|
|
|
|
|
{{:assign fin=$end_date|date_short}}
|
|
|
|
|
{{:assign var="open_years.%d"|args:$id value=$label|cat:" (du "|cat:$debut|cat:" au "|cat:$fin|cat:")"}}
|
|
|
|
|
{{else}}
|
|
|
|
|
{{:assign debut=$date_debut|date_short}}
|
|
|
|
|
{{:error message="Aucun exercice ouvert pour enregistrer un amortissement à partir du %s"|args:$debut}}
|
|
|
|
|
{{:error message="Aucun exercice ouvert pour enregistrer un amortissement"}}
|
|
|
|
|
{{/years}}
|
|
|
|
|
{{if $years|count == 1}}
|
|
|
|
|
{{:assign default_year=$years.0.id}}
|
|
|
|
|
@ -190,9 +178,9 @@
|
|
|
|
|
{{/if}}
|
|
|
|
|
|
|
|
|
|
{{* vérifier la validité de la date de sortie *}}
|
|
|
|
|
{{if $info_immo.date_mes != null}}
|
|
|
|
|
{{if $_POST.date_sortie|parse_date < $info_immo.date_mes}}
|
|
|
|
|
{{:assign immo_date=$info_immo.date_mes|date_short}}
|
|
|
|
|
{{if $info_immo.date != null}}
|
|
|
|
|
{{if $_POST.date_sortie|parse_date < $info_immo.date}}
|
|
|
|
|
{{:assign immo_date=$info_immo.date|date_short}}
|
|
|
|
|
{{:error message="La date de sortie doit être postérieure à la date de mise en service de l'immobilisation (%s)"|args:$immo_date}}
|
|
|
|
|
{{/if}}
|
|
|
|
|
{{elseif $_POST.date_mes != null}}
|
|
|
|
|
@ -208,34 +196,31 @@
|
|
|
|
|
{{:error message="La date de sortie doit être postérieure à la date du dernier amortissement (%s)"|args:$last_amort_date}}
|
|
|
|
|
{{/if}}
|
|
|
|
|
|
|
|
|
|
{{* vérifier que la date de sortie est située dans un exercice ouvert *}}
|
|
|
|
|
{{:assign ts_exit = $_POST.date_sortie|parse_date|strtotime}}
|
|
|
|
|
{{:assign exercice_ok=false}}
|
|
|
|
|
{{* vérifier que la date de sortie est dans l'exercice choisi *}}
|
|
|
|
|
{{#foreach from=$years item="current_year"}}
|
|
|
|
|
{{if $current_year.id == $_POST.id_year}}
|
|
|
|
|
{{:assign selected_year=$current_year.id}}
|
|
|
|
|
{{:assign ok=false}}
|
|
|
|
|
{{:assign msg_amort=""}}
|
|
|
|
|
{{#foreach from=$years}}
|
|
|
|
|
{{if $id == $_POST.id_year}}
|
|
|
|
|
{{:assign selected_year=$id}}
|
|
|
|
|
{{if $start_date|strtotime <= $ts_exit && $ts_exit <= $end_date|strtotime}}
|
|
|
|
|
{{:assign current_year=$current_year}}
|
|
|
|
|
{{:assign exercice_ok=true}}
|
|
|
|
|
{{:assign ok=true}}
|
|
|
|
|
{{:break}}
|
|
|
|
|
{{/if}}
|
|
|
|
|
{{/if}}
|
|
|
|
|
{{/foreach}}
|
|
|
|
|
{{if ! $exercice_ok}}
|
|
|
|
|
{{:error message="La date choisie n'est pas dans l'exercice sélectionné !"}}
|
|
|
|
|
{{/if}}
|
|
|
|
|
|
|
|
|
|
{{* voir si des amortissements ont été oubliés *}}
|
|
|
|
|
{{if $valeur_nette > 0 && $info_immo.status != "amortized"}}
|
|
|
|
|
{{if $current_year.start_date <= $date_debut && $date_debut <= $current_year.end_date}}
|
|
|
|
|
{{:assign amort_ok=true}}
|
|
|
|
|
{{else}}
|
|
|
|
|
{{:assign amort_ok=false}}
|
|
|
|
|
{{if $valeur_nette > 0 && $info_immo.status != "amortized" && $start_date|strtotime > $last_amort_date|strtotime && $end_date|strtotime < $now}}
|
|
|
|
|
{{:assign debut=$start_date|date_short}}
|
|
|
|
|
{{:assign fin=$end_date|date_short}}
|
|
|
|
|
{{:assign msg_amort=$msg_amort|cat:"\n"|cat:" - "|cat:$label|cat:" : du "|cat:$debut|cat:" au "|cat:$fin}}
|
|
|
|
|
{{/if}}
|
|
|
|
|
|
|
|
|
|
{{if ! $amort_ok}}
|
|
|
|
|
{{:error message="Vous devez d'abord enregistrer les amortissements des exercices précédents"}}
|
|
|
|
|
{{/foreach}}
|
|
|
|
|
{{if ! $ok}}
|
|
|
|
|
{{:error message="La date choisie n'est pas dans l'exercice sélectionné !"}}
|
|
|
|
|
{{/if}}
|
|
|
|
|
{{if $msg_amort != ""}}
|
|
|
|
|
{{:error message="Vous devez d'abord enregistrer les amortissements des exercices suivants : %s"|args:$msg_amort}}
|
|
|
|
|
{{/if}}
|
|
|
|
|
|
|
|
|
|
{{:redirect to="compute_exit_data.html?immo_line_id=%s&amort_amount=%s&year=%s&date_mes=%s&date_debut=%s&exit_date=%s&duree_amort=%s"|args:$_GET.immo_line_id:$total_amort:$selected_year:$ts_mes:$ts_debut:$ts_exit:$duree_amort}}
|
|
|
|
|
@ -258,10 +243,10 @@
|
|
|
|
|
<dt>Montant</dt>
|
|
|
|
|
<dd id="montant_immo" class="money">{{$ligne_immo.montant|money_currency_html:false|raw}}</dd>
|
|
|
|
|
<dt>Date d'acquisition</dt>
|
|
|
|
|
<dd>{{$info_immo.date_achat|or:$ligne_immo.date_achat|date_short}}</dd>
|
|
|
|
|
{{if $info_immo.date_mes != null && $info_immo.date_mes != $ligne_immo.date_achat}}
|
|
|
|
|
<dd >{{$ligne_immo.date_achat|date_short}}</dd>
|
|
|
|
|
{{if $info_immo.date != null && $info_immo.date != $ligne_immo.date_achat}}
|
|
|
|
|
<dt>Date de mise en service</dt>
|
|
|
|
|
<dd>{{$info_immo.date_mes|date_short}}</dd>
|
|
|
|
|
<dd>{{$info_immo.date|date_short}}</dd>
|
|
|
|
|
{{/if}}
|
|
|
|
|
{{if $info_immo.duration != null}}
|
|
|
|
|
<dt>Durée de l'amortissement</dt>
|
|
|
|
|
@ -271,23 +256,23 @@
|
|
|
|
|
<dd id="montant_amort" class="money">{{$total_amort|money_currency_html:false|raw}} <span class="help">(à la date de début de l'exercice)</span></dd>
|
|
|
|
|
<dt>Valeur nette résiduelle</dt>
|
|
|
|
|
<dd class="money">{{$valeur_nette|money_currency_html:false|raw}} <span class="help">(à la date de début de l'exercice)</span></dd>
|
|
|
|
|
{{if $last_amort_date != null}}
|
|
|
|
|
<dt>Date du dernier amortissement</dt>
|
|
|
|
|
<dd>{{$last_amort_date|date_short}}</dd>
|
|
|
|
|
{{/if}}
|
|
|
|
|
</dl>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
{{if $info_immo == null && $total_amort == 0 }}
|
|
|
|
|
{{if $valeur_nette > 0}}
|
|
|
|
|
{{if $info_immo.date == null || $info_immo.duration == null}}
|
|
|
|
|
<fieldset>
|
|
|
|
|
<legend>Autres informations</legend>
|
|
|
|
|
<legend>Informations sur l'immobilisation</legend>
|
|
|
|
|
<dl>
|
|
|
|
|
{{if $info_immo.date == null}}
|
|
|
|
|
{{:input type="date" name="date_mes" label="Date de mise en service" help="C'est la date de première utilisation ; à renseigner uniquement si différente de la date d'acquisition"}}
|
|
|
|
|
{{/if}}
|
|
|
|
|
{{if $info_immo.duration == null}}
|
|
|
|
|
{{:input type="number" name="duree" label="Durée d'amortissement" required=true min=1 help="La durée est nécessaire pour calculer l'amortissement complémentaire"}}
|
|
|
|
|
{{/if}}
|
|
|
|
|
</dl>
|
|
|
|
|
</fieldset>
|
|
|
|
|
{{/if}}
|
|
|
|
|
|
|
|
|
|
{{/if}}
|
|
|
|
|
<fieldset>
|
|
|
|
|
<legend>Informations de sortie</legend>
|
|
|
|
|
<dl>
|
|
|
|
|
|