{{* -*- brindille -*- *}} {{* Enregistrer les écritures de sortie du bilan paramètres : - immo_id : numéro de ligne de l'écriture d'immobilisation - amort_amount : montant des amortissements - year : exercice de la date de sortie de l'immobilisation - date_mes : date de mise en service de l'immobilisation - date_debut : date de début de la période d'amortissement complémentaire - exit_date : date de sortie de l'immobilisation - duree_amort : durée de l'amortiseement (optionnel) - cession : montant de la cession (optionnel) *}} {{#select line.debit as montant, line.id_transaction, line.id_account, trans.date as date_achat, trans.label, acc.code, id_project FROM acc_transactions_lines AS line INNER JOIN acc_transactions AS trans ON line.id_transaction = trans.id INNER JOIN acc_accounts AS acc ON line.id_account = acc.id WHERE line.id = :immo_id; :immo_id = $_GET.immo_id|intval assign="ligne_immo" }} {{/select}} {{#load type="immo" assign="info_immo" where="$$.line = :line_id" :line_id=$_GET.immo_id|intval}} {{/load}} {{* date de début de l'exercice *}} {{#select start_date FROM acc_years WHERE id = :year_id; :year_id = $_GET.year}} {{* {{if $start_date < "2025-01-01" *}} {{:assign vnc_code="675"}} {{:assign cession_code="775"}} {{* {{else}} {{:assign vnc_code="657"}} {{:assign cession_code="757"}} {{/if}} *}} {{/select}} {{:assign valeur_nette="%f-%f"|math:$ligne_immo.montant:$_GET.amort_amount}} {{:assign amort_comp=0}} {{* amortissement complémentaire jqà date sortie *}} {{:assign amort_except=0}} {{* amortissement exceptionnel jqà date fin amortissement *}} {{if $valeur_nette > 0}} {{:assign nbjours="1+(%d-%d)/(60*60*24)"|math:$_GET.exit_date:$_GET.date_debut}} {{:assign annuite="%f/%f"|math:$ligne_immo.montant:$_GET.duree_amort}} {{:assign amort_comp="round(%f/365*%f, 0)"|math:$annuite:$nbjours}} {{:assign amort_comp="min(%f, %f)"|math:$valeur_nette:$amort_comp}} {{if $_GET.cession == null}} {{:assign amort_except="%f-%f-%f"|math:$ligne_immo.montant:$_GET.amort_amount:$amort_comp}} {{/if}} {{/if}} {{if $_GET.cession == null}} {{:assign montant_cession=0}} {{else}} {{:assign montant_cession="%f*100"|math:$_GET.cession}} {{/if}} {{* TODO : faut-il forcer les 3 sélecteurs de compte d'amortissement à avoir toujours la même valeur ? *}} {{* Traiter l'envoi du formulaire *}} {{#form on="save"}} {{* {{if $_POST.amort_comp_account != null} {{:assign account=$_POST.amort_comp_account}} {{elseif $_POST.amort_except_account != null} {{:assign account=$_POST.amort_except_account}} {{elseif $_POST.amort_sortie_account != null} {{:assign account=$_POST.amort_sortie_account}} {{/if}} *}} {{:assign account=$_POST.amort_sortie_account}} {{:include file="_get_codes.html" account=$account keep="account_code" }} {{:assign amort_account_code=$account_code|keys|key:0}} {{if $valeur_nette > 0}} {{* immo non totalement amortie *}} {{* lignes d'écriture de l'amortissement complémentaire *}} {{:include file="_get_codes.html" account=$_POST.comp_account keep="account_code" }} {{:assign comp_account_code=$account_code|keys|key:0}} {{:assign libelle="Amortissement complémentaire "|cat:$ligne_immo.label}} {{:assign var="lines." debit="%f/100"|math:$amort_comp account=$comp_account_code id_project=$ligne_immo.id_project label=$libelle }} {{:assign var="lines." credit="%f/100"|math:$amort_comp account=$amort_account_code id_project=$ligne_immo.id_project label=$libelle }} {{:assign valeur_nette="%f-%f"|math:$valeur_nette:$amort_comp}} {{if $_GET.cession == null && $amort_except > 0}} {{* lignes d'écriture de l'amortissement exceptionnel *}} {{:include file="_get_codes.html" account=$_POST.except_account keep="account_code" }} {{:assign except_account_code=$account_code|keys|key:0}} {{:assign libelle="Amortissement exceptionnel "|cat:$ligne_immo.label}} {{:assign var="lines." debit="%f/100"|math:$amort_except account=$except_account_code id_project=$ligne_immo.id_project label=$libelle }} {{:assign var="lines." credit="%f/100"|math:$amort_except account=$amort_account_code id_project=$ligne_immo.id_project label=$libelle }} {{:assign valeur_nette="%f-%f"|math:$valeur_nette:$amort_except}} {{/if}} {{:api method="POST" path="accounting/transaction" assign="result" assign_code="result_code" id_year=$_GET.year type="advanced" date=$_GET.exit_date label="Amortissement final "|cat:$ligne_immo.label lines=$lines linked_transactions=$ligne_immo.id_transaction }} {{/if}} {{* écriture de sortie du bilan *}} {{:assign lines=null}} {{:include file="_get_codes.html" account=$_POST.immo_account keep="account_code" }} {{:assign immo_account_code=$account_code|keys|key:0}} {{:assign libelle="Sortie du bilan de "|cat:$ligne_immo.label}} {{:assign var="lines." account=$immo_account_code credit="%f/100"|math:$ligne_immo.montant id_project=$ligne_immo.id_project label=$libelle }} {{:assign var="lines." account=$amort_account_code debit="(%f-%f)/100"|math:$ligne_immo.montant:$valeur_nette id_project=$ligne_immo.id_project label=$libelle }} {{if $valeur_nette > 0}} {{:include file="_get_codes.html" account=$_POST.vnc_account keep="account_code" }} {{:assign vnc_account_code=$account_code|keys|key:0}} {{:assign var="lines." account=$vnc_account_code debit="%f/100"|math:$valeur_nette id_project=$ligne_immo.id_project label=$libelle }} {{/if}} {{:api method="POST" path="accounting/transaction" assign="result" assign_code="result_code" id_year=$_GET.year type="advanced" date=$_GET.exit_date label=$libelle lines=$lines linked_transactions=$ligne_immo.id_transaction }} {{if $montant_cession > 0}} {{* Cession de l'immobilisation *}} {{:assign libelle="Produit cession "|cat:$ligne_immo.label}} {{:include file="_get_codes.html" account=$_POST.creance_account keep="account_code" }} {{:assign creance_account=$account_code|keys|key:0}} {{:include file="_get_codes.html" account=$_POST.cession_account keep="account_code" }} {{:assign cession_account=$account_code|keys|key:0}} {{:api method="POST" path="accounting/transaction" assign="result" assign_code="result_code" id_year=$_GET.year type="credit" date=$_GET.exit_date label=$libelle amount="%f/100"|math:$montant_cession debit=$creance_account credit=$cession_account id_project=$ligne_immo.id_project linked_transactions=$ligne_immo.id_transaction }} {{/if}} {{if $info_immo != null}} {{* mettre à jour l'état de l'immobilisation *}} {{:save key=$info_immo.key status="archived" }} {{else}} {{:save key=""|uuid validate_schema="schema.json" type="immo" line=$_GET.immo_id|intval duration=$_GET.duree_amort|intval date=$_GET.date_mes|date:"Y-m-d" status="archived" }} {{/if}} {{:redirect to="index.html?amort=archive"}} {{/form}} {{:admin_header title="Sortie du bilan" custom_css="./style.css" current="module_amortissement"}} {{* barre de navigation *}} {{if ! $dialog}} {{:include file="_nav.html" current="index" subcurrent="balance_exit"}} {{/if}} {{:form_errors}} {{* Préparer les infos pour le formulaire *}} {{* déterminer les comptes pour les différentes écritures *}} {{:include file="./_get_amort_code.html" code_immo=$ligne_immo.code keep="code_amort" }} {{:assign var="liste_codes.6811" name="comp_account"}} {{:assign var="liste_codes.687" name="except_account"}} {{:assign var="liste_codes.462" name="creance_account"}} {{:assign var="liste_codes.%s"|args:$code_amort name="amort_account"}} {{:assign var="liste_codes.%s"|args:$ligne_immo.code name="immo_account"}} {{:assign var="liste_codes.%s"|args:$vnc_code name="vnc_account"}} {{:assign var="liste_codes.%s"|args:$cession_code name="cession_account"}} {{:assign condition=$liste_codes|keys|implode:","}} {{:assign condition="acc.code IN ("|cat:$condition|cat:")"}} {{#select acc.id, acc.code as acc_code, acc.label as acc_label, year.label as year_label FROM acc_accounts as acc INNER JOIN acc_charts as chart ON chart.id = acc.id_chart INNER JOIN acc_years as year ON chart.id = year.id_chart WHERE year.id = 1 AND !condition; !condition=$condition }} {{:assign var="liste_codes.%s.id"|args:$acc_code value=$id}} {{:assign var="liste_codes.%s.acc_label"|args:$acc_code value=$acc_label}} {{:assign var="liste_codes.%s.year_label"|args:$acc_code value=$year_label}} {{/select}} {{#foreach from=$liste_codes key=code}} {{:assign var="%s.%s"|args:$name:$code value="%s — %s"|args:$code:$acc_label}} {{/foreach}} {{:read file="./defaut.json" assign="config_json"}} {{:assign config_defaut=$config_json|json_decode}} {{:assign var="prefix_array" value=$config_defaut.prefixes|keys}} {{#foreach from=$prefix_array item="code"}} {{:assign var="pattern_array." value="%s*"|args:$code}} {{/foreach}} {{:assign patterns=$pattern_array|implode:"|"}}