Adaptation nouvelles liaisons + améliorations vérif dates
This commit is contained in:
parent
2c0181b298
commit
85bc1316b5
1 changed files with 130 additions and 115 deletions
|
|
@ -3,6 +3,7 @@
|
|||
{{*
|
||||
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 *}}
|
||||
|
|
@ -20,22 +21,48 @@
|
|||
assign="ligne_immo"
|
||||
}}
|
||||
{{else}}
|
||||
{{:error message="Immobilisation %s non trouvée"|args:$_GET.immo_line_id}}
|
||||
{{:error message="Immobilisation non trouvée"}}
|
||||
{{/select}}
|
||||
|
||||
{{:assign date_debut=$ligne_immo.date_achat}}
|
||||
{{:assign ts_mes=$ligne_immo.date_achat|strtotime}}
|
||||
|
||||
{{#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}}
|
||||
{{* 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}}
|
||||
{{: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
|
||||
CASE links.id_related = :immo_trans_id
|
||||
WHEN true THEN links.id_transaction
|
||||
|
|
@ -53,77 +80,61 @@
|
|||
}}
|
||||
{{:assign total_credits="%d+%d"|math:$total_credits:$credit}}
|
||||
{{/select}}
|
||||
{{/load}}
|
||||
{{: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}}
|
||||
{{:assign amort_number=0}}
|
||||
{{#load type="amort_link"
|
||||
where="$$.immo_doc_id = :immo_doc_id"
|
||||
:immo_doc_id = $_GET.immo_doc_id|intval
|
||||
}}
|
||||
{{#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%'
|
||||
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
|
||||
;
|
||||
:line_id = $_GET.immo_line_id|intval
|
||||
:amort_line_id = $amort_line_id
|
||||
assign="amort_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 var="amort_line.amort_amount" value=$amount|or:$credit}}
|
||||
{{: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}}
|
||||
{{/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}}
|
||||
{{: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"}}
|
||||
{{if $first_amort_date == null}}
|
||||
{{:assign first_amort_date=$line.amort_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}}
|
||||
{{/if}}
|
||||
{{/foreach}}
|
||||
|
||||
{{if $total_amort == 0}}
|
||||
{{if $info_immo.status == "amortized"}}
|
||||
{{:assign total_amort=$ligne_immo.montant}}
|
||||
{{/if}}
|
||||
{{else}}
|
||||
{{:assign date_debut=$last_amort_date|strtotime}}
|
||||
{{:assign date_debut="%d+(60*60*24)"|math:$date_debut|date:"Y-m-d"}}
|
||||
{{:assign date_debut=$last_amort_date}}
|
||||
{{/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}}
|
||||
|
||||
{{*
|
||||
|
|
@ -139,7 +150,8 @@
|
|||
{{: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}}
|
||||
{{:error message="Aucun exercice ouvert pour enregistrer un amortissement"}}
|
||||
{{:assign debut=$date_debut|date_short}}
|
||||
{{:error message="Aucun exercice ouvert pour enregistrer un amortissement à partir du %s"|args:$debut}}
|
||||
{{/years}}
|
||||
{{if $years|count == 1}}
|
||||
{{:assign default_year=$years.0.id}}
|
||||
|
|
@ -178,9 +190,9 @@
|
|||
{{/if}}
|
||||
|
||||
{{* vérifier la validité de la date de sortie *}}
|
||||
{{if $info_immo.date != null}}
|
||||
{{if $_POST.date_sortie|parse_date < $info_immo.date}}
|
||||
{{:assign immo_date=$info_immo.date|date_short}}
|
||||
{{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}}
|
||||
{{: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}}
|
||||
|
|
@ -196,31 +208,34 @@
|
|||
{{: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 ok=false}}
|
||||
{{:assign msg_amort=""}}
|
||||
{{#foreach from=$years}}
|
||||
{{if $id == $_POST.id_year}}
|
||||
{{:assign selected_year=$id}}
|
||||
{{: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}}
|
||||
{{if $start_date|strtotime <= $ts_exit && $ts_exit <= $end_date|strtotime}}
|
||||
{{:assign ok=true}}
|
||||
{{:assign current_year=$current_year}}
|
||||
{{:assign exercice_ok=true}}
|
||||
{{:break}}
|
||||
{{/if}}
|
||||
{{/if}}
|
||||
|
||||
{{* voir si des amortissements ont été oubliés *}}
|
||||
{{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}}
|
||||
{{/foreach}}
|
||||
{{if ! $ok}}
|
||||
{{if ! $exercice_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}}
|
||||
|
||||
{{* 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}}
|
||||
|
||||
{{if ! $amort_ok}}
|
||||
{{:error message="Vous devez d'abord enregistrer les amortissements des exercices précédents"}}
|
||||
{{/if}}
|
||||
{{/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}}
|
||||
|
|
@ -243,10 +258,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 >{{$ligne_immo.date_achat|date_short}}</dd>
|
||||
{{if $info_immo.date != null && $info_immo.date != $ligne_immo.date_achat}}
|
||||
<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}}
|
||||
<dt>Date de mise en service</dt>
|
||||
<dd>{{$info_immo.date|date_short}}</dd>
|
||||
<dd>{{$info_immo.date_mes|date_short}}</dd>
|
||||
{{/if}}
|
||||
{{if $info_immo.duration != null}}
|
||||
<dt>Durée de l'amortissement</dt>
|
||||
|
|
@ -256,23 +271,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 $valeur_nette > 0}}
|
||||
{{if $info_immo.date == null || $info_immo.duration == null}}
|
||||
|
||||
{{if $info_immo == null && $total_amort == 0 }}
|
||||
<fieldset>
|
||||
<legend>Informations sur l'immobilisation</legend>
|
||||
<legend>Autres informations</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>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue