diff --git a/_calcul_dates.html b/_calcul_dates.html index e4dd864..00ca468 100644 --- a/_calcul_dates.html +++ b/_calcul_dates.html @@ -9,4 +9,12 @@ {{:assign ts_debut=$date_debut|strtotime}} {{:assign ts_fin=$date_fin|strtotime}} -{{:assign nbjours="1+abs(%d-%d)/(60*60*24)"|math:$ts_fin:$ts_debut}} + +{{if $ts_debut <= $ts_fin}} + {{:assign nbjours="(%d-%d)/(60*60*24)"|math:$ts_fin:$ts_debut}} +{{else}} + {{:assign nbjours="(%d-%d)/(60*60*24)"|math:$ts_debut:$ts_fin}} +{{/if}} + +{{* pour simplifier : 360 jours par an *}} +{{:assign nbjours="round(%f/365*360)"|math:$nbjours}} diff --git a/_check_account.html b/_check_account.html index 06e1108..d1234a3 100644 --- a/_check_account.html +++ b/_check_account.html @@ -24,10 +24,11 @@ select="code" tables="acc_accounts" where="id_chart = :id_chart %s"|args:$condition - :id_chart = $chart_id|intval + :id_chart = $selected_chart|intval }} {{if $account_code == $code}} {{:assign account_ok=1}} {{:break}} {{/if}} {{/sql}} + diff --git a/_check_date.html b/_check_date.html index f68ec49..3dc1362 100644 --- a/_check_date.html +++ b/_check_date.html @@ -8,11 +8,15 @@ *}} {{:assign open_years=""}} -{{#years closed=false order="start_date" assign="open_years."}} +{{#years status=false order="start_date"}} + {{:assign open_years=$open_years|cat:"\n"|cat:" - "|cat:$label|cat:" : "}} + {{:assign debut=$start_date|date_short}} + {{:assign fin=$end_date|date_short}} + {{:assign open_years=$open_years|cat:$debut|cat:" à "|cat:$fin}} {{if $start_date|strtotime <= $date|parse_date|strtotime && $end_date|strtotime >= $date|parse_date|strtotime - }} + }} {{:assign selected_year=$id}} {{:assign selected_chart=$id_chart}} {{/if}} diff --git a/_nav.html b/_nav.html index bb819d1..362f31a 100644 --- a/_nav.html +++ b/_nav.html @@ -12,22 +12,17 @@
  • Aide
  • - {{if $current == 'index' && $subsubcurrent != 'balance_exit'}} - + {{/if}} {{/if}} diff --git a/add_asset.html b/add_asset.html index 051d7ba..8cd1403 100644 --- a/add_asset.html +++ b/add_asset.html @@ -1,44 +1,33 @@ {{* -*- brindille -*- *}} +{{:admin_header title="Ajout immobilisation" current="module_amortissement"}} + +{{* barre de navigation *}} +{{if ! $dialog}} + {{:include file="_nav.html" current="index"}} +{{/if}} {{:read file="./defaut.json" assign="config_json"}} {{:assign config_defaut=$config_json|json_decode}} {{:assign var="prefix_array" value=$config_defaut.prefixes|keys}} -{{#years closed=false order="start_date" assign=years.}} - {{:assign ts_debut=$start_date|strtotime}} - {{:assign ts_fin=$end_date|strtotime}} - {{:assign debut=$start_date|date_short}} - {{:assign fin=$end_date|date_short}} - {{:assign var="years_data.%d"|args:$id value=$ts_debut|cat:" "|cat:$ts_fin}} - {{:assign var="open_years.%d"|args:$id value=$label|cat:" (du "|cat:$debut|cat:" au "|cat:$fin|cat:")"}} - {{if $ts_debut <= $now && $now <= $ts_fin}} - {{:assign selected_year=$id}} - {{/if}} -{{/years}} - {{* Traiter l'envoi du formulaire *}} {{#form on="add"}} - {{* vérifier que la date d'achat est située dans un l'exercice sélectionné *}} - {{:assign ts_date = $_POST.date_achat|parse_date|strtotime}} - {{:assign ok=false}} - {{#foreach from=$years}} - {{if $id == $_POST.id_year}} - {{:assign selected_chart=$id_chart}} - {{if $start_date|strtotime <= $ts_date && $ts_date <= $end_date|strtotime}} - {{:assign ok=true}} - {{:break}} - {{/if}} - {{/if}} - {{/foreach}} - {{if ! $ok}} - {{:error message="La date saisie n'est pas dans l'exercice choisi !"}} + + {{* vérifier que la date est située dans un exercice ouvert *}} + {{:include + file="_check_date.html" + date=$_POST.date_achat + keep="open_years, selected_year, selected_chart" + }} + {{if $selected_year == null}} + {{:error message="La date choisie n'est dans aucun exercice ouvert !!\nExercices ouverts : %s"|args:$open_years}} {{/if}} - {{if ! $_POST.amortir}} + {{if $_POST.no_amort}} {{* ne pas amortir *}} {{:assign duration=0}} - {{:assign date_debut=$_POST.date_achat|parse_date}} - {{:assign status="ignored"}} + {{:assign date_debut=$ligne_immo.date_achat|parse_date}} + {{:assign noamort=true}} {{else}} {{* vérifier que la date d'acquisition est antérieure à la date de mise en service *}} {{:assign date_debut=$_POST.date_mes|or:$_POST.date_achat|parse_date}} @@ -48,7 +37,7 @@ {{:error message="Erreur : la date de mise en service (%s) ne peut être antérieure à la date d'acquisition (%s)"|args:$dd:$da}} {{/if}} {{:assign duration=$_POST.duree|intval}} - {{:assign status="managed"}} + {{:assign noamort=false}} {{/if}} {{* déterminer le numéro des comptes au cas où la clé serait un identifiant *}} @@ -88,7 +77,7 @@ method="POST" path="accounting/transaction" assign="result" - id_year=$_POST.id_year + id_year=$selected_year type="revenue" date=$_POST.date_achat label=$_POST.designation @@ -114,26 +103,20 @@ line=$immo_id duration=$duration date=$date_debut - status=$status + noamort=$noamort }} - {{if $_POST.amortir}} - {{:assign amort="encours"}} + {{if $_POST.no_amort}} + {{:assign amort=0}} {{else}} - {{:assign amort="autres"}} + {{:assign amort=1}} {{/if}} {{:redirect force="index.html?ok=1&msg=immobilisation&amort=%s"|args:$amort}} {{/form}} -{{:admin_header title="Ajout immobilisation" current="module_amortissement"}} -{{* barre de navigation *}} -{{if ! $dialog}} - {{:include file="_nav.html" current="index"}} -{{/if}} - {{:form_errors}} {{* formulaire d'ajout d'immobilisation *}} - +{{:assign var="bank_account.512" value="512 — Banques"}} {{:assign var="immo_account.2" value="2 — Classe 2 — Comptes d'immobilisations"}} {{#select id,label FROM acc_projects WHERE archived = 0;}} @@ -144,50 +127,37 @@ {{:assign var="pattern_array." value="%s*"|args:$code}} {{/foreach}} {{:assign patterns=$pattern_array|implode:"|"}} - - +{{:assign date=$now|date:'Y-m-d'}}
    - Données de l'immobilisation + Ajouter une immobilisation
    - {{:input type="select" name="id_year" label="Exercice" required=true default_empty="— Faire un choix —" options=$open_years}} - {{:input type="date" name="date_achat" label="Date d'acquisition" required=true default=$now|date_short}} + {{:input id="no_amort" type="checkbox" value=1 name="no_amort" label="Ne pas amortir" help="Cocher pour ne pas amortir" onclick="toggleInputs('f_no_amort_1', ['f_date_mes','f_duree'])"}} + {{:input type="date" name="date_achat" label="Date d'acquisition" required=true default=$now|date_short onchange="setDate('date_achat', ['credit_account', 'debit_account'])"}} + {{:input type="date" name="date_mes" label="Date de mise en service" help="à renseigner uniquement si différente de la date d'acquisition"}} {{:input type="text" name="designation" label="Désignation" required=true}} {{:input type="money" name="montant" label="Montant" required=true}} + {{:input type="number" name="duree" label="Durée d'amortissement" required=true min=0 default=1 suffix="année(s)"}} {{:input type="list" name="credit_account" label="Compte de décaissement" required=true - target="!acc/charts/accounts/selector.php?types=%s&id_year=%d"|args:"1|2|3":$selected_year + target="!acc/charts/accounts/selector.php?types=%s&date=%s"|args:"1|2|3":$date + default=$bank_account }} {{:input type="list" name="debit_account" label="Compte d'immobilisation (20xx, 21xx, ...)" required=true - target="!acc/charts/accounts/selector.php?codes=%s&id_year=%d"|args:$patterns:$selected_year + target="!acc/charts/accounts/selector.php?date=%s&codes=%s"|args:$date:$patterns default=$immo_account }} {{if $projects != null}} {{:input type="select" name="id_project" label="Projet (analytique)" options=$projects default_empty="— Aucun —"}} {{/if}} - -
    -
    -
    - Amortissement -
    - {{:input id="amortir" type="checkbox" value=1 name="amortir" label="Amortir cette immobilisation sur plusieurs années" checked="cheched" help="Dé-cocher pour ne pas amortir"}} -
    - {{: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"}} - {{:input type="number" name="duree" label="Durée d'amortissement" required=true min=0 default=1 suffix="année(s)"}} -
    @@ -196,21 +166,36 @@

    -{{:admin_footer}} - + +{{:admin_footer}} diff --git a/add_infos.html b/add_infos.html index 01511a5..f34794c 100644 --- a/add_infos.html +++ b/add_infos.html @@ -26,7 +26,7 @@ {{* ne pas amortir *}} {{:assign duration=0}} {{:assign date_debut=$ligne_immo.date_achat|parse_date}} - {{:assign status="ignored"}} + {{:assign noamort=true}} {{else}} {{* vérifier que la date d'acquisition est antérieure à la date de mise en service *}} {{:assign date_debut=$_POST.date_mes|or:$ligne_immo.date_achat|parse_date}} @@ -39,7 +39,7 @@ {{if $duration <= 0}} {{:error message="Erreur : la durée d'amortissement doit être strictement positive"}} {{/if}} - {{:assign status="managed"}} + {{:assign noamort=false}} {{/if}} {{* enregistrer les infos de l'immobilisation *}} @@ -51,13 +51,13 @@ line=$immo_id duration=$duration date=$date_debut - status=$status + noamort=$noamort }} {{if $_POST.no_amort}} - {{:assign amort="autres"}} + {{:assign amort=0}} {{else}} - {{:assign amort="encours"}} + {{:assign amort=1}} {{/if}} {{:redirect force="index.html?ok=1&msg=infos&amort=%s"|args:$amort}} {{else}} diff --git a/amortization.html b/amortization.html index 7186a7e..b5caa4e 100644 --- a/amortization.html +++ b/amortization.html @@ -1,81 +1,14 @@ {{* -*- brindille -*- *}} -{{* récupérer les infos de l'immobilisation *}} -{{#select - line.id as immo_id, - line.debit as montant, - trans.id as trans_id, - trans.label as label, - trans.date - FROM acc_transactions_lines AS line - INNER JOIN acc_transactions AS trans ON line.id_transaction = trans.id - WHERE line.id = :line_id; - :line_id = $_GET.immo_id|intval - assign=ligne_immo - }} -{{else}} - {{:error message="Immobilisation %s non trouvée"|args:$_GET.immo_id}} -{{/select}} -{{:assign date_debut=$ligne_immo.date}} -{{:assign solde=$ligne_immo.montant}} - -{{#load type="immo" where="$$.line = :line_id" :line_id=$_GET.immo_id|intval}} - {{:assign duree=$duration}} - {{:assign date_debut=$date}} -{{/load}} - -{{* chercher des écritures d'amortissement liées à l'immobilisation *}} -{{#select - l_amort.credit as amort_amount, - l_amort.label as amort_label, - l_amort.id as amort_line, - CASE WHEN links.id_related = t_immo.id - THEN links.id_transaction - ELSE links.id_related - END as amort_trans_id, - trans.date as amort_date, - trans.label as trans_label, - 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 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%' - ORDER BY trans.date; - :line_id = $_GET.immo_id|intval - assign=linked_lines. -}} - {{if $date_debut == null}} - {{:assign date_debut=$amort_date}} - {{/if}} -{{/select}} - -{{:assign valeur_residuelle=$ligne_immo.montant}} -{{#foreach from=$linked_lines}} - {{:assign valeur_residuelle="%d-%d"|math:$valeur_residuelle:$amort_amount}} -{{/foreach}} - {{:admin_header title="Liste des amortissements" custom_css="./style.css" current="module_amortissement"}} {{* barre de navigation *}} -{{if $_GET.amort == "fini" || $valeur_residuelle== 0 }} +{{if $_GET.amort == null || $_GET.amort == "amort"}} + {{:assign subcurrent="amort"}} +{{elseif $_GET.amort == "fini"}} {{:assign subcurrent="fini"}} -{{elseif $_GET.amort == "archive"}} - {{:assign subcurrent="archive"}} -{{elseif $_GET.amort == null || $_GET.amort == "encours"}} - {{:assign subcurrent="encours"}} {{else}} - {{:assign subcurrent="autres"}} + {{:assign subcurrent="no_amort"}} {{/if}} {{:include file="_nav.html" current="index" subcurrent="%s"|args:$subcurrent subsubcurrent="amortization"}} @@ -97,13 +30,77 @@

    {{$msg}}

    {{/if}} -{{if $valeur_residuelle > 0}} - -{{/if}} +{{* récupérer les infos de l'immobilisation *}} +{{#select + line.id as immo_id, + line.id_account as account_id, + line.id_project as project_id, + line.debit as montant, + trans.id as trans_id, + trans.label as label, + trans.date, + y.id as year_id, + y.end_date as date_amort, + project.label as project_label + FROM acc_transactions_lines AS line + INNER JOIN acc_transactions AS trans ON line.id_transaction = trans.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 + WHERE line.id = :line_id; + :line_id = $_GET.immo_id|intval + assign=ligne_immo + }} +{{else}} + {{:error message="Immobilisation %s non trouvée"|args:$_GET.immo_id}} +{{/select}} +{{:assign date_debut=$ligne_immo.date}} + +{{#load type="immo" assign="info_immo" where="$$.line = :line_id" :line_id=$_GET.immo_id|intval}} + {{:assign var="duree" from="info_immo.duration"|args:$_GET.immo_id}} + {{:assign date_debut=$info_immo.date}} +{{/load}} + +{{* chercher des écritures d'amortissement liées à l'immobilisation *}} +{{#select + l_amort.credit as amort_amount, + l_amort.label as amort_label, + l_amort.id as amort_line, + CASE links.id_related = t_immo.id + WHEN true THEN links.id_transaction + WHEN false THEN links.id_related + END as amort_trans_id, + trans.date as amort_date, + trans.label as trans_label, + 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 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 + l_amort.credit <> 0 + AND + account.code LIKE '28%' + ORDER BY trans.date; + :line_id = $_GET.immo_id|intval + assign=linked_lines. +}} + {{:assign var="amort_years." value=$amort_year}} + {{if $date_debut == null}} + {{:assign date_debut=$amort_date}} + {{/if}} +{{/select}}

    Amortissement de « +{{if $duree != null}} + {{* montant de l'annuité théorique *}} + {{:assign montant="%f"|math:$ligne_immo.montant}} + {{:assign annuite="%f/%f"|math:$montant:$duree}} + {{* première annuité *}} + {{:assign date_amort=$ligne_immo.date_amort}} + {{if $date_amort|strtotime < $date_debut|strtotime}} + {{* changer d'exercice *}} + {{:include file="_next_year.html" date=$date_amort keep="date_amort"}} + {{:assign date_amort=$date_amort|parse_date}} + {{/if}} + {{:include file="_calcul_dates.html" date_debut=$date_debut date_fin=$date_amort keep="nbjours"}} + {{:assign annuite_1="%f/360*%d"|math:$annuite:$nbjours|intval}} + {{:assign annuite_courante=$annuite_1}} + {{:assign current_year=$ligne_immo.year_id}} + {{:assign nbamort=0}} +{{/if}} + +{{:assign solde=$ligne_immo.montant}} {{if $linked_lines != null}}

    Amortissements rattachés

    @@ -135,6 +151,8 @@ {{:assign trans_url="%s/acc/transactions/details.php?id=%s"|args:$admin_url:$line.amort_trans_id}} {{:assign compte_url="%s/acc/accounts/journal.php?id=%s&year=%s"|args:$admin_url:$line.account_id:$line.amort_year}} {{:assign solde="%f-%d"|math:$solde:$line.amort_amount}} + {{:assign date_amort=$line.amort_date}} + {{:assign current_year=$line.amort_year}}
    #{{$line.amort_trans_id}} {{$line.amort_date|date_short}} @@ -150,9 +168,71 @@ {{$line.account_code}} {{$line.account_label}} - {{:linkbutton label="Détacher" href="detach_amort.html?amort_id=%d&immo_id=%d"|args:$line.amort_line:$ligne_immo.immo_id shape="minus"}} + {{:linkbutton label="Détacher" href="detach_amort.html?amort_id=%d&immo_id=%d"|args:$line.amort_line:$ligne_immo.immo_id shape="plus"}} + {{:assign annuite_courante=$annuite}} + {{:include file="_next_year.html" date=$date_amort keep="date_amort"}} + {{:assign nbamort="%d+1"|math:$nbamort}} + {{/foreach}} + + +
    +{{/if}} + +{{if $duree != null && $solde > 0}} + {{:assign project_id=$ligne_immo.project_id}} + {{:assign project_label=$ligne_immo.project_label}} + {{:assign nbamort="%d-%d"|math:$duree:$nbamort}} + {{:assign annuite_courante="min(%f,%f)"|math:$annuite_courante:$solde}} +
    +

    Amortissements à enregistrer

    + + + + + + + + + + + + + {{#foreach count="%d+1"|math:$nbamort key="num"}} + {{:assign solde_prec=$solde}} + {{:assign solde="%f-%d"|math:$solde:$annuite_courante}} + {{#select id FROM acc_years WHERE :amort_date >= start_date AND :amort_date <= end_date AND status == 0; :amort_date=$date_amort|parse_date}} + {{:assign enregistrer=1}} + {{:assign current_year=$id}} + {{else}} + {{:assign enregistrer=0}} + {{/select}} + + + + + + + + + {{:include file="_next_year.html" date=$date_amort keep="date_amort"}} + {{:assign annuite_courante="min(%f,%f)"|math:$annuite:$solde}} + {{if $solde == 0}}{{:break}}{{/if}} {{/foreach}}
    DateMontantSoldeLibellé
    {{"%d+1"|math:$num}}{{$date_amort|date_short}}{{"%f"|math:$annuite_courante|money}}{{$solde|money:false}} + {{if $libelle == null}} + {{:assign libelle="Amortissement "|cat:$ligne_immo.label}} + {{/if}} + {{$libelle}} + + {{if $enregistrer == 1}} + {{:linkbutton + label="Créer l'écriture" + href="save_amort.html?amount=%d&account=%s&year=%s&trans_id=%d&immo_id=%s&project_id=%d&label=%s&solde=%d"|args:$annuite_courante:$ligne_immo.account_id:$current_year:$ligne_immo.trans_id:$_GET.immo_id:$project_id:$libelle:$solde_prec + shape="right" + target="_dialog" + }} + {{/if}} +
    diff --git a/archives.html b/archives.html deleted file mode 100644 index 9160b73..0000000 --- a/archives.html +++ /dev/null @@ -1,71 +0,0 @@ -{{* -*- brindille -*- *}} - -{{* Liste des immobilisations archivées *}} - -
    -

    Immobilisations archivées

    - - {{:assign nb_immo=0}} - - - - - - - - - - - - - - - - {{#load type="immo" where="$$.status = 'archived'"}} - {{:assign var="lines." value="'%s'"|args:$line}} - {{/load}} - {{:assign lines=$lines|implode:","}} - {{:assign lines="("|cat:$lines|cat:")"}} - {{:assign condition="line.id IN %s"|args:$lines}} - - {{#select - trans.id as trans_id, - trans.label as trans_label, - trans.date as trans_date, - line.id as immo_id, - account.id as account_id, - account.code as account_code, - account.label as account_label, - line.debit AS debit, - project.label as project_label, - trans.id_year as trans_id_year - FROM acc_transactions AS trans - INNER JOIN acc_transactions_lines AS line ON line.id_transaction = trans.id - INNER JOIN acc_accounts AS account ON line.id_account = account.id - INNER JOIN acc_years AS years ON trans.id_year = years.id - LEFT JOIN acc_projects AS project ON line.id_project = project.id - WHERE !condition - ORDER BY trans.date DESC; - !condition=$condition - }} - {{:assign trans_url="%s/acc/transactions/details.php?id=%s"|args:$admin_url:$trans_id}} - {{:assign compte_url="%s/acc/accounts/journal.php?id=%s&year=%s"|args:$admin_url:$account_id:$trans_id_year}} - {{:assign nb_immo="%d+1"|math:$nb_immo}} - - - - - - - - - - - {{/select}} - -
    DateLibelléMontantN° compteCompteProjet
    #{{$trans_id}}{{$trans_date|date_short}}{{$trans_label}}{{"%f"|math:$debit|money:false}}{{$account_code}}{{$account_label}}{{$project_label}} -
    - {{if $nb_immo == 0}} -

    Aucune immobilisation

    - {{/if}} -
    diff --git a/balance_sheet_exit.html b/balance_sheet_exit.html deleted file mode 100644 index 9f9de48..0000000 --- a/balance_sheet_exit.html +++ /dev/null @@ -1,220 +0,0 @@ -{{* -*- brindille -*- *}} - -{{* - Sortir une immobilisation du bilan - @param immo_id : id de la ligne d'immobilisation -*}} - -{{* Infos de l'immobilisation *}} -{{#select - line.debit as montant, - trans.date as date_achat, - trans.label - FROM acc_transactions_lines AS line - INNER JOIN acc_transactions AS trans ON line.id_transaction = trans.id - WHERE line.id = :line_id; - :line_id = $_GET.immo_id|intval - assign="ligne_immo" -}} -{{else}} - {{:error message="Immobilisation %s non trouvée"|args:$_GET.immo_id}} -{{/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_id|intval}} - {{:assign ts_mes=$date|strtotime}} - {{:assign date_debut=$date}} - {{:assign duree_amort=$duration}} -{{/load}} - -{{* chercher des écritures d'amortissement liées à l'immobilisation *}} -{{#select - SUM(l_amort.credit) as amort_amount, - CASE - WHEN links.id_related = t_immo.id - THEN links.id_transaction - ELSE links.id_related - END as amort_trans_id, - MAX(trans.date) as last_amort_date, - MIN(trans.date) as first_amort_date, - COUNT(trans.id) as amort_number - 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%' - LIMIT 1; - :line_id = $_GET.immo_id|intval - assign=amort_line -}} -{{/select}} - -{{if $amort_line.amort_number == 0}} - {{:assign amort_amount=0}} -{{else}} - {{:assign amort_amount=$amort_line.amort_amount}} - {{:assign date_debut=$amort_line.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 valeur_nette="%f-%f"|math:$ligne_immo.montant:$amort_amount}} - -{{* - lister les exercices qui englobent la date de début du prochain amortissement -*}} -{{:assign default_exit_date=""}} -{{#years closed=false order="start_date" where="start_date <= :debut AND :debut <= end_date" - :debut=$date_debut assign=years.}} - {{if $start_date|strtotime <= $now && $now <= $end_date|strtotime}} - {{:assign default_exit_date=$now|date_short}} - {{/if}} - {{:assign ts_fin=$end_date|strtotime}} - {{:assign debut=$start_date|date_short}} - {{:assign fin=$end_date|date_short}} - {{:assign var="open_years.%d"|args:$id value=$label|cat:" (du "|cat:$debut|cat:" au "|cat:$fin|cat:")"}} - {{:assign var="years_data.%d"|args:$id value=$ts_debut|cat:" "|cat:$ts_fin}} -{{else}} - {{:error message="Aucun exercice ouvert pour enregistrer un amortissement"}} -{{/years}} -{{if $years|count == 1}} - {{:assign default_year=$years.0.id}} -{{else}} - {{:assign default_year=""}} -{{/if}} - -{{* Traiter l'envoi du formulaire *}} -{{#form on="proceed"}} - - {{if $_POST.date_sortie == null}} - {{:error message="Vous devez renseigner la date de sortie"}} - {{/if}} - - {{* vérifier la validité de la date de mise en service *}} - {{if $_POST.date_mes != null}} - {{:assign ts_mes=$_POST.date_mes|parse_date|strtotime}} - {{if $ts_mes < $ligne_immo.date_achat|strtotime || $ts_mes > $amort_line.first_amort_date|strtotime}} - {{:assign immo_date=$ligne_immo.date_achat|date_short}} - {{:assign amort_date=$amort_line.first_amort_date|date_short}} - {{:error message="La date de mise en service doit être postérieure à la date d'acquisition de l'immobilisation (%s) et antérieure à la date du premier amortissement (%s)"|args:$immo_date:$amort_date}} - {{/if}} - {{/if}} - - {{* vérifier la validité de la durée d'immobilisation *}} - {{if $valeur_nette > 0}} - {{if $info_immo.duration == null}} - {{if $_POST.duree == null}} - {{:error message="Vous devez renseigner la durée de l'immobilisation"}} - {{elseif $_POST.duree < $amort_line.amort_number}} - {{:error message="La durée de l'amortissement ne peut être inférieure au nombre d'écritures d'amortissement (%d)"|args:$amort_line.amort_number}} - {{else}} - {{:assign duree_amort=$_POST.duree}} - {{/if}} - {{/if}} - {{/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}} - {{: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}} - {{if $_POST.date_sortie|parse_date < $_POST.date_mes|parse_date}} - {{:error message="La date de sortie doit être postérieure à la date de mise en service de l'immobilisation (%s)"|args:$_POST.date_mes}} - {{/if}} - {{elseif $_POST.date_sortie|parse_date < $ligne_immo.date_achat}} - {{:assign immo_date=$ligne_immo.date_achat|date_short}} - {{:error message="La date de sortie doit être postérieure à la date d'acquisition de l'immobilisation (%s)"|args:$immo_date}} - {{/if}} - {{if $amort_line.amort_number != 0 && $_POST.date_sortie|parse_date <= $amort_line.last_amort_date}} - {{:assign last_amort_date=$amort_line.last_amort_date|date_short}} - {{:error message="La date de sortie doit être postérieure à la date de la dernière immobilisation (%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}} - {{#foreach from=$years}} - {{if $id == $_POST.id_year}} - {{:assign selected_year=$id}} - {{if $start_date|strtotime <= $ts_exit && $ts_exit <= $end_date|strtotime}} - {{:assign ok=true}} - {{:break}} - {{/if}} - {{/if}} - {{/foreach}} - {{if ! $ok}} - {{:error message="La date choisie n'est pas dans l'exercice sélectionné !"}} - {{/if}} - - {{:redirect to="compute_exit_data.html?immo_id=%s&amort_amount=%s&year=%s&date_mes=%s&date_debut=%s&exit_date=%s&duree_amort=%s"|args:$_GET.immo_id:$amort_amount:$selected_year:$ts_mes:$ts_debut:$ts_exit:$duree_amort}} -{{/form}} - -{{:admin_header title="Sortie de bilan" custom_css="./style.css" current="module_amortissement"}} -{{* barre de navigation *}} -{{if ! $dialog}} - {{:include file="_nav.html" current="index" subsubcurrent="balance_exit"}} -{{/if}} -{{:form_errors}} - -{{* formulaire de sortie du bilan *}} -

    Sortir l'immobilisation « {{$ligne_immo.label}} » du bilan

    -
    - -
    - Données de l'imobilisation -
    -
    Montant
    -
    {{$ligne_immo.montant|money_currency:false}}
    -
    Date d'acquisition
    -
    {{$ligne_immo.date_achat|date_short}}
    - {{if $info_immo.date != null && $info_immo.date != $ligne_immo.date_achat}} -
    Date de mise en service
    -
    {{$info_immo.date|date_short}}
    - {{/if}} - {{if $info_immo.duration != null}} -
    Durée de l'amortissement
    -
    {{$info_immo.duration}} ans
    - {{/if}} -
    Montant des amortissements
    -
    {{$amort_amount|money_currency:false}} (à la date de début de l'exercice)
    -
    Valeur nette résiduelle
    -
    {{$valeur_nette|money_currency:false}} (à la date de début de l'exercice)
    -
    -
    - {{if $valeur_nette > 0}} - {{if $info_immo.date == null || $info_immo.duration == null}} -
    - Informations sur l'immobilisation -
    - {{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}} -
    -
    - {{/if}} - {{/if}} -
    - Informations de sortie -
    - {{:input type="select" default=$default_year name="id_year" label="Exercice" required=true default_empty="— Faire un choix —" options=$open_years}} - {{:input type="date" name="date_sortie" label="Date de sortie du bilan" required=true default=$default_exit_date}} -
    -
    - -

    - {{:button type="submit" name="proceed" label="Poursuivre" shape="right" class="main"}} -

    -
    - -{{:admin_footer}} diff --git a/compute_exit_data.html b/compute_exit_data.html deleted file mode 100644 index 2909ddc..0000000 --- a/compute_exit_data.html +++ /dev/null @@ -1,133 +0,0 @@ -{{* -*- brindille -*- *}} - -{{* - Calculer les valeurs de la sortie et saisir le montant de la cession (optionnel) - 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 : datede 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) -*}} - -{{#select - line.debit as montant, - trans.date as date_achat, - trans.label - FROM acc_transactions_lines AS line - INNER JOIN acc_transactions AS trans ON line.id_transaction = trans.id - WHERE line.id = :line_id; - :line_id = $_GET.immo_id|intval - assign="ligne_immo" -}} -{{else}} - {{:error message="Immobilisation %s non trouvée"|args:$_GET.immo_id}} -{{/select}} - -{{:assign valeur_nette="%f-%f"|math:$ligne_immo.montant:$_GET.amort_amount}} -{{:assign amort_comp=0}} {{* amortissement complémentaire jqà date sortie *}} -{{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}} - -{{* Traiter l'envoi du formulaire *}} -{{#form on="proceed"}} - {{:debug post=$_POST}} - {{if $_POST.cession != null}} - {{if $_POST.montant_cession == null}} - {{:error message="Vous devez saisir le montant de la cession"}} - {{/if}} - {{/if}} - - {{:redirect to="write_exit.html?immo_id=%s&amort_amount=%s&year=%s&date_mes=%s&date_debut=%s&exit_date=%s&duree_amort=%s&cession=%s"|args:$_GET.immo_id:$_GET.amort_amount:$_GET.year:$_GET.date_mes:$_GET.date_debut:$_GET.exit_date:$_GET.duree_amort:$_POST.montant_cession}} - -{{/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" subsubcurrent="balance_exit"}} -{{/if}} - -{{:form_errors}} - -

    Sortir l'immobilisation « {{$ligne_immo.label}} » du bilan

    -
    - -
    - Données de l'imobilisation -
    -
    Montant
    -
    {{$ligne_immo.montant|money_currency:false}}
    -
    Date d'acquisition
    -
    {{$ligne_immo.date_achat|date_short}}
    - {{if $_GET.date_mes != $ligne_immo.date_achat|strtotime}} -
    Date de mise en service
    -
    {{$_GET.date_mes|date:"d/m/Y"}}
    - {{/if}} - {{if $_GET.duree_amort != null}} -
    Durée de l'amortissement
    -
    {{$_GET.duree_amort}} ans
    - {{/if}} -
    Montant des amortissements
    -
    {{$_GET.amort_amount|money_currency:false}} (à la date de début de l'exercice)
    -
    Valeur nette résiduelle
    -
    {{$valeur_nette|money_currency:false}} (à la date de début de l'exercice)
    -
    Date de sortie
    -
    {{$_GET.exit_date|date:"d/m/Y"}}
    - {{if $amort_comp > 0}} -
    Amortissement complémentaire
    -
    {{$amort_comp|money_currency:false}} (jusqu'à la date de sortie)
    -
    Total des amortissements
    -
    {{"%f+%f"|math:$_GET.amort_amount:$amort_comp|money_currency:false}} (à la date de sortie)
    -
    Valeur nette résiduelle
    -
    {{"%f-%f"|math:$valeur_nette:$amort_comp|money_currency:false}} (à la date de sortie)
    - {{/if}} -
    -
    -
    - Informations de sortie -
    - {{:input type="checkbox" value=1 name="cession" label="Cession" help="Cocher si la sortie est due à une cession" onclick="toggleHiddenAndFocus('f_cession_1', ['infos_cession'], 'f_montant_cession')"}} - -
    -
    - -

    - {{:button type="submit" name="proceed" label="Poursuivre" shape="right" class="main"}} -

    - -
    - - - -{{:admin_footer}} diff --git a/immobilisations.html b/immobilisations.html index 6f1c86c..cf746c5 100644 --- a/immobilisations.html +++ b/immobilisations.html @@ -3,12 +3,11 @@ {{* Liste des immobilisations amortissable ou à définir *}}
    - {{if $amort == "encours"}} + {{if $amort == "amort"}}

    Immobilisations en cours

    - {{elseif $amort == "fini"}} + {{else}}

    Immobilisations amorties

    {{/if}} - {{:assign nb_immo=0}} @@ -20,6 +19,7 @@ + @@ -46,11 +46,13 @@ account.code as account_code, account.label as account_label, line.debit AS debit, + project.label as project_label, trans.id_year as trans_id_year FROM acc_transactions AS trans INNER JOIN acc_transactions_lines AS line ON line.id_transaction = trans.id INNER JOIN acc_accounts AS account ON line.id_account = account.id INNER JOIN acc_years AS years ON trans.id_year = years.id + LEFT JOIN acc_projects AS project ON line.id_project = project.id WHERE !condition ORDER BY trans.date DESC; !condition=$condition @@ -61,7 +63,7 @@ {{* voir si l'immo est prise en charge *}} {{#load type="immo" where="$$.line = :line_id" :line_id=$immo_id|intval}} {{:assign duration=$duration}} - {{if $status == "ignored"}} + {{if $noamort}} {{:assign amortissable="non"}} {{else}} {{:assign amortissable="oui"}} @@ -72,32 +74,6 @@ {{if $amortissable == "non"}} {{:continue}} {{/if}} - - {{* voir s'il existe une écriture qui solde l'immobilisation *}} - {{:assign ignore=false}} - {{#select - line.id AS line, - line.id_transaction AS trans, - line.debit, - line.label, - line2.id AS line2, - line2.id_transaction AS trans2, - line2.credit, - line2.label - FROM acc_transactions_lines AS line - INNER JOIN acc_accounts AS acc ON acc.id = line.id_account - INNER JOIN acc_transactions_lines AS line2 ON line2.id_account = acc.id - WHERE - line.id = :line_id - AND line2.credit = line.debit; - :line_id = $immo_id|intval - }} - {{:assign ignore=true}} - {{/select}} - {{if $ignore}} - {{:continue}} - {{/if}} - {{* voir s'il existe des écritures d'amortissement associées *}} {{#select sum(l_amort.credit) as amort_amount, @@ -122,7 +98,7 @@ AND account.code LIKE '28%'; :line_id = $immo_id|intval - }} + }} {{if $amort_amount == null}} {{:assign exist_amort=false}} {{:assign amort_amount=0}} @@ -131,15 +107,12 @@ {{:assign exist_amort=true}} {{/if}} {{/select}} - - {{* classement par onglet *}} - {{if $amort == "encours" && $amort_amount >= $debit || - $amort == "fini" && $amort_amount < $debit || - $amortissable == "nsp" && ! $exist_amort + {{* immo amortie ? *}} + {{if $amort == "amort" && $amort_amount >= $debit || + $amort == "fini" && $amort_amount < $debit }} {{:continue}} {{/if}} - {{:assign nb_immo="%d+1"|math:$nb_immo}} @@ -148,40 +121,33 @@ + {{/select}}
    Durée N° compte CompteProjet
    #{{$trans_id}} {{$trans_date|date_short}}{{if $duration != null}}{{$duration}}{{/if}} {{$account_code}} {{$account_label}}{{$project_label}} - {{if ! $exist_amort}} + {{if ! $exist_amort && $duration == null}} {{:linkbutton + label="Ajouter infos" + href="add_infos.html?immo_id=%s&amort=1"|args:$immo_id + shape="help" + target="_dialog" + }} + {{else}} + {{if ! $exist_amort}} + {{:linkbutton label="Modifier infos" href="modif_infos.html?immo_id=%s&amort=1"|args:$immo_id - shape="settings" + shape="help" target="_dialog" - }} - {{elseif $amortissable == "nsp"}} + }} + {{/if}} {{:linkbutton - label="Ajouter infos" - href="add_infos.html?immo_id=%s&amort=1"|args:$immo_id - shape="settings" - target="_dialog" + label="Amortissements" + href="amortization.html?immo_id=%s&amort=%s"|args:$immo_id:$amort + shape="table" }} {{/if}} - {{if $amort == "encours" || $amort == "fini"}} - {{:linkbutton - label="Sortir du bilan" - href="balance_sheet_exit.html?immo_id=%s"|args:$immo_id - shape="export" - }} - {{/if}} - {{:linkbutton - label="Amortissements" - href="amortization.html?immo_id=%s&amort=%s"|args:$immo_id:$amort - shape="table" - }}
    - {{if $nb_immo == 0}} -

    Aucune immobilisation

    - {{/if}}
    diff --git a/immobilisations_autres.html b/immobilisations_autres.html deleted file mode 100644 index ecbfd33..0000000 --- a/immobilisations_autres.html +++ /dev/null @@ -1,129 +0,0 @@ -{{* -*- brindille -*- *}} - -{{* Liste des immobilisations non amortissables ou non (encore) gérées *}} - -
    -

    Autres immobilisations

    - - - - - - - - - - - - - - - - {{* lister les immobilisations *}} - {{:read file="./defaut.json" assign="config_json"}} - {{:assign config_defaut=$config_json|json_decode}} - {{:assign var="prefix_array" value=$config_defaut.prefixes|keys}} - {{:assign condition="("}} - {{#foreach from=$prefix_array item="code"}} - {{:assign code=$code|cat:"%"|quote_sql}} - {{:assign condition=$condition|cat:" account.code LIKE "|cat:$code|cat:" OR "}} - {{/foreach}} - {{:assign condition=$condition|cat:"0)"}} - {{:assign condition=$condition|cat:" AND debit > 0 AND NOT (trans.status & 16)"}} - - {{#select - trans.id as trans_id, - trans.label as trans_label, - trans.date as trans_date, - line.id as immo_id, - account.id as account_id, - account.code as account_code, - account.label as account_label, - line.debit AS debit, - trans.id_year as trans_id_year - FROM acc_transactions AS trans - INNER JOIN acc_transactions_lines AS line ON line.id_transaction = trans.id - INNER JOIN acc_accounts AS account ON line.id_account = account.id - INNER JOIN acc_years AS years ON trans.id_year = years.id - WHERE !condition - ORDER BY trans.date DESC; - !condition=$condition - }} - {{:assign trans_url="%s/acc/transactions/details.php?id=%s"|args:$admin_url:$trans_id}} - {{:assign compte_url="%s/acc/accounts/journal.php?id=%s&year=%s"|args:$admin_url:$account_id:$trans_id_year}} - {{* voir si l'immo est prise en charge *}} - {{#load type="immo" where="$$.line = :line_id" :line_id=$immo_id|intval}} - {{:assign status=$status}} - {{else}} - {{:assign status="nsp"}} - {{/load}} - {{if $status != "ignored" && $status != "nsp"}} - {{:continue}} - {{/if}} - {{*:debug immo_id=$immo_id status=$status*}} - - {{* voir s'il existe des écritures d'amortissement associées *}} - {{#select - sum(l_amort.credit) as amort_amount, - CASE links.id_related = t_immo.id - WHEN true THEN links.id_transaction - WHEN false THEN links.id_related - END as amort_trans_id - 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_accounts AS account ON l_amort.id_account = account.id - WHERE - l_immo.id = :line_id - AND - l_amort.credit <> 0 - AND - account.code LIKE '28%'; - :line_id = $immo_id|intval - }} - {{if $amort_amount != null}} - {{:assign ignore=true}} - {{else}} - {{:assign ignore=false}} - {{/if}} - {{/select}} - - {{if $ignore}} - {{:continue}} - {{/if}} - - - - - - - - - - - {{/select}} - -
    DateLibelléMontantN° compteCompte
    #{{$trans_id}}{{$trans_date|date_short}}{{$trans_label}}{{"%f"|math:$debit|money:false}}{{$account_code}}{{$account_label}} - {{if $status == "nsp"}} - {{:linkbutton - label="Ajouter infos" - href="add_infos.html?immo_id=%s&amort=1"|args:$immo_id - shape="settings" - target="_dialog" - }} - {{else}} - {{:linkbutton - label="Modifier infos" - href="modif_infos.html?immo_id=%s&amort=0"|args:$immo_id - shape="help" - target="_dialog" - }} - {{/if}} -
    -
    diff --git a/immobilisations_non.html b/immobilisations_non.html index 39fbd96..2b31c84 100644 --- a/immobilisations_non.html +++ b/immobilisations_non.html @@ -20,13 +20,12 @@ - {{#load type="immo" where="$$.status = 'ignored'"}} + {{#load type="immo" where="$$.noamort = true"}} {{:assign var="lines." value="'%s'"|args:$line}} {{/load}} {{:assign lines=$lines|implode:","}} {{:assign lines="("|cat:$lines|cat:")"}} {{:assign condition="line.id IN %s"|args:$lines}} -{{:debug condition=$condition}} {{#select trans.id as trans_id, trans.label as trans_label, diff --git a/index.html b/index.html index 25f4c29..5057665 100644 --- a/index.html +++ b/index.html @@ -3,7 +3,7 @@ {{* barre de navigation *}} {{if $_GET.amort == null}} - {{:assign amort="encours"}} + {{:assign amort="amort"}} {{else}} {{:assign amort=$_GET.amort}} {{/if}} @@ -34,7 +34,7 @@ {{:delete key=$key}} {{/select}} - {{* supprimer les documents correspondant à une écriture de la balance d'ouverture + {{* supprimer les documents correspondant à une écriture de la balance d'ouverture *}} {{#select line.id as line_id, trans.status @@ -45,14 +45,11 @@ }} {{:delete key=$key}} {{/select}} - *}} {{/load}} -{{if $amort == "autres"}} - {{:include file="./immobilisations_autres.html"}} -{{elseif $amort == "archive"}} - {{:include file="archives.html"}} -{{elseif $amort == "encours" || $amort == "fini"}} +{{if $amort == "no_amort"}} + {{:include file="./immobilisations_non.html"}} +{{else}} {{:include file="./immobilisations.html"}} {{/if}} diff --git a/modif_infos.html b/modif_infos.html index 7181226..c5f3599 100644 --- a/modif_infos.html +++ b/modif_infos.html @@ -30,7 +30,7 @@ {{* ne pas amortir *}} {{:assign duration=0}} {{:assign date_debut=$ligne_immo.date_achat|parse_date}} - {{:assign status="ignored"}} + {{:assign noamort=true}} {{else}} {{* vérifier que la date d'acquisition est antérieure à la date de mise en service *}} {{:assign date_debut=$_POST.date_mes|or:$ligne_immo.date_achat|parse_date}} @@ -43,7 +43,7 @@ {{if $duration <= 0}} {{:error message="Erreur : la durée d'amortissement doit être strictement positive"}} {{/if}} - {{:assign status="managed"}} + {{:assign noamort=false}} {{/if}} {{* enregistrer les infos modifiées de l'immobilisation *}} @@ -54,13 +54,13 @@ line=$immo_id duration=$duration date=$date_debut - status=$status + noamort=$noamort }} {{if $_POST.no_amort}} - {{:assign amort="autres"}} + {{:assign amort=0}} {{else}} - {{:assign amort="encours"}} + {{:assign amort=1}} {{/if}} {{:redirect force="index.html?ok=1&msg=infos&amort=%s"|args:$amort}} {{else}} @@ -81,12 +81,7 @@
    - {{if $checked}} - {{:assign helptext = "Dé-cocher pour amortir"}} - {{else}} - {{:assign helptext = "Cocher pour ne pas amortir"}} - {{/if}} - {{:input id="no_amort" type="checkbox" value=1 name="no_amort" label="Ne pas amortir" default=$checked help=$helptext onclick="toggleInputs('infos_immo','f_no_amort_1')"}} + {{:input id="no_amort" type="checkbox" value=1 name="no_amort" label="Ne pas amortir" default=$checked help="Cocher pour ne pas amortir" onclick="toggleInputs('infos_immo','f_no_amort_1')"}} {{:input type="date" name="date_mes" label="Date de mise en service" default=$info_immo.date disabled=$disabled help="à renseigner uniquement si différente de la date d'acquisition"}} {{:input type="number" name="duree" label="Durée d'amortissement" default=$info_immo.duration required=true min=1 disabled=$disabled}}
    diff --git a/save_amort.html b/save_amort.html index 1c9df59..54bc596 100644 --- a/save_amort.html +++ b/save_amort.html @@ -1,135 +1,26 @@ {{* -*- brindille -*- *}} -{{* - Créer une écriture d'amortissement - @param immo_id : id de la ligne d'immobilisation -*}} +{{:admin_header title="Ajout amortissement" current="module_amortissement"}} -{{* Infos de l'immobilisation *}} -{{#select - line.id as immo_id, - line.id_account as account_id, - line.debit as montant, - line.id_project as project_id, - trans.id as trans_id, - trans.label, - trans.date, - y.id as year_id, - y.start_date, - y.end_date, - project.label as project_label - FROM acc_transactions_lines AS line - INNER JOIN acc_transactions AS trans ON line.id_transaction = trans.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 - WHERE line.id = :line_id; - :line_id = $_GET.immo_id|intval - assign=ligne_immo - }} -{{else}} - {{:error message="Immobilisation %s non trouvée"|args:$_GET.immo_id}} -{{/select}} -{{:assign date_debut=$ligne_immo.date}} - -{{#load type="immo" where="$$.line = :line_id" :line_id=$_GET.immo_id|intval}} - {{:assign duree=$duration}} - {{:assign date_debut=$date}} -{{else}} - {{:error message="Vous devez renseigner la date de mise en service et la durée d'immobilisation"}} -{{/load}} - -{{* chercher des écritures d'amortissement liées à l'immobilisation *}} -{{#select - SUM(l_amort.credit) as amort_amount, - l_amort.label as amort_label, - 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, - MAX(trans.date) as amort_date, - COUNT(trans.id) as amort_number, - trans.label as trans_label, - 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 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%' - ORDER BY trans.date DESC LIMIT 1; - :line_id = $_GET.immo_id|intval - assign=amort_line -}} -{{/select}} - -{{if $amort_line.amort_number == 0}} - {{* 1er amortissement *}} - {{* 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}} - {{:include - file="./_get_amort_code.html" - code_immo=$amort_account.code - keep="code_amort" - }} - {{:assign var=amort_label value="Amortissement %s"|args:$amort_account.label}} - {{:assign var=libelle value="Amortissement %s"|args:$ligne_immo.label}} -{{else}} - {{* amortissements suivants *}} - {{:assign date_debut=$amort_line.amort_date|strtotime}} - {{: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}} +{{* barre de navigation *}} +{{if ! $dialog}} + {{:include file="_nav.html" current="amortization"}} {{/if}} -{{* - lister les exercices qui englobent la date de mise en service de l'immo - ou la date du dernier amortissement -*}} -{{:assign msg_years=""}} -{{#years closed=false order="start_date" where="start_date <= :debut AND :debut <= end_date" - :debut=$date_debut assign=years.}} - {{if $amort_line.amort_number == 0}} - {{:assign ts_debut=$date_debut|strtotime}} - {{else}} - {{:assign ts_debut=$start_date|strtotime}} - {{/if}} - {{:assign ts_fin=$end_date|strtotime}} - {{:assign debut=$start_date|date_short}} - {{:assign fin=$end_date|date_short}} - {{:assign var="open_years.%d"|args:$id value=$label|cat:" (du "|cat:$debut|cat:" au "|cat:$fin|cat:")"}} - {{:assign var="years_data.%d"|args:$id value=$ts_debut|cat:" "|cat:$ts_fin}} - {{:assign msg_years=$msg_years|cat:"\n"|cat:" - "|cat:$label|cat:" : "|cat:$debut|cat:" à "|cat:$fin}} -{{else}} - {{:error message="Aucun exercice ouvert pour enregistrer un amortissement"}} -{{/years}} - {{* Traiter l'envoi du formulaire *}} {{#form on="save"}} - {{* vérifier que la date est située dans un exercice compatible *}} - {{:assign ts_date = $_POST.date_amort|parse_date|strtotime}} - {{:assign ok=false}} - {{#foreach from=$years}} - {{if $id == $_POST.id_year}} - {{:assign selected_chart=$id_chart}} - {{if $start_date|strtotime <= $ts_date && $ts_date <= $end_date|strtotime}} - {{:assign ok=true}} - {{:break}} - {{/if}} - {{/if}} - {{/foreach}} - {{if ! $ok}} - {{:error message="La date choisie n'est dans aucun exercice compatible !\nExercices compatibles : %s"|args:$msg_years}} + + {{* vérifier que la date est située dans un exercice ouvert *}} + {{:include + file="_check_date.html" + date=$_POST.date + keep="open_years, selected_year, selected_chart" + }} + + {{if $selected_year == null}} + {{:error message="La date choisie n'est dans aucun exercice ouvert !!\nExercices ouverts : %s"|args:$open_years}} {{/if}} + {{* déterminer le numéro des comptes au cas où la clé serait un identifiant *}} {{:include file="_get_codes.html" @@ -143,6 +34,7 @@ keep="account_code" }} {{:assign credit_account=$account_code}} + {{* vérifier : - que le compte d'amortissement débute par un préfixe correct (280, 281, ...) - est présent dans le PC de l'exercice correspondant à la date @@ -167,19 +59,21 @@ prefix_array=$amort_array keep="account_ok" }} + {{if $account_ok == null}} {{:assign compte=$credit_account|implode:""}} {{:redirect url="add_account.html?account=%s&chart=%s&immo_id=%s"|args:$compte:$selected_chart:$_GET.immo_id}} {{/if}} {{* vérifier que le montant ne dépasse pas le solde restant *}} - {{:assign solde="%d-%d"|math:$ligne_immo.montant:$amort_line.amort_amount}} - {{if $_POST.montant|trim|money_int > $solde|intval}} - {{:assign solde=$solde|money_raw}} + {{if $_POST.montant|trim|money_int > $_GET.solde|intval}} + {{:assign solde=$_GET.solde|money_raw}} {{:error message="Le montant indiqué « %s » dépasse le solde à amortir « %s »"|args:$_POST.montant:$solde}} {{/if}} {{* enregistrer l'écriture *}} + {{:assign var="linked_transactions." value=$_GET.trans_id}} + {{:assign var="lines." debit=$_POST.montant @@ -194,61 +88,66 @@ id_project=$_GET.project_id label=$_POST.designation }} + {{:api method="POST" path="accounting/transaction" assign="result" assign_code="result_code" - id_year=$_POST.id_year + id_year=$selected_year type="advanced" - date=$_POST.date_amort + date=$_POST.date label=$_POST.designation lines=$lines - linked_transactions=$ligne_immo.trans_id|intval + linked_transactions=$_GET.trans_id|intval }} {{:redirect force="amortization.html?immo_id=%s&ok=1&msg=amortissement"|args:$_GET.immo_id}} {{/form}} -{{:admin_header title="Ajout amortissement" current="module_amortissement"}} - -{{* barre de navigation *}} -{{if ! $dialog}} - {{:include file="_nav.html" current="index" subcurrent="encours" subsubcurrent="amortization"}} -{{/if}} - {{:form_errors}} -{{:assign var=selected_year value=$years.0.id}} -{{:assign var=date_amort value=$years.0.end_date}} -{{:include file="_calcul_dates.html" date_debut=$date_debut date_fin=$date_amort keep="nbjours"}} - -{{* montant de l'amortissement *}} -{{: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}} +{{* Préparer les infos pour le formulaire *}} {{: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}} -{{* -------------------------------------------------------------------------------- *}} +{{* + déterminer le compte d'amortissement en fonction du compte + d'immobilisation => ajouter un 8 après le 2 de tête +*}} +{{#select code, label from acc_accounts where id = :id; :id=$_GET.account assign=amort_account}}{{/select}} +{{:include + file="./_get_amort_code.html" + code_immo=$amort_account.code + keep="code_amort" +}} +{{:assign var="credit_account.%s"|args:$code_amort value="%s — Amortissements "|args:$code_amort|cat:$amort_account.label}} - +{{#select + id, + label, + end_date as date_amort + from acc_years where id=:id; + :id=$_GET.year assign=year + }} +{{/select}} + +{{#years status=false}} + {{:assign var="open_years.%d"|args:$id value=$label}} +{{/years}}
    Ajouter une écriture d'amortissement
    - {{: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="text" name="designation" label="Désignation" required=true default=$libelle}} - {{:input type="money" name="montant" label="Montant" required=true default=$montant_amort}} + {{:input type="date" name="date" label="Date" required=true default=$year.date_amort|date_short}} + {{: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="list" name="debit_account" label="Compte de débit" required=true - target="!acc/charts/accounts/selector.php?codes=%s&id_year=%d"|args:"68*":$selected_year + target="!acc/charts/accounts/selector.php?codes=%s&year=%d"|args:"68*":$year.id default=$debit_account }} {{:input @@ -256,15 +155,9 @@ name="credit_account" label="Compte d'amortissement (280xx ou 281xx)" required=true - target="!acc/charts/accounts/selector.php?codes=%s&id_year=%d"|args:"28*":$selected_year + target="!acc/charts/accounts/selector.php?codes=%s&year=%d"|args:"28*":$year.id default=$credit_account }} -
    @@ -273,48 +166,3 @@

    {{:admin_footer}} - - - diff --git a/schema.json b/schema.json index ea8e31c..b2d16e2 100644 --- a/schema.json +++ b/schema.json @@ -19,9 +19,8 @@ "type" : ["string", "null"], "format" : "date" }, - "status" : { - "type" : ["string", "null"], - "enum" : ["managed", "archived", "ignored"] + "noamort" : { + "type" : ["null", "boolean"] } }, "required": ["type", "line", "duration", "date"] diff --git a/scripts.js b/scripts.js deleted file mode 100644 index 232df76..0000000 --- a/scripts.js +++ /dev/null @@ -1,141 +0,0 @@ -// activer/désactiver les champs passés en paramètres -function toggleInputs(idcb, idfields) { - const elem = document.getElementById(idcb); - for (let id of idfields) { - const field = document.getElementById(id); - if (elem.checked) { - field.removeAttribute("disabled"); - } - else { - field.setAttribute("disabled","disabled"); - } - } -} - -function toggleVisibility(idcheck, fields) { - const elem = document.getElementById(idcheck); - for (let id of fields) { - const field = document.getElementById(id); - if (elem.checked) { - field.setAttribute('class', ''); - } else { - field.setAttribute('class', 'hidden'); - } - } -} - -// fixer l'exercice des sélecteurs de compte -function setAccountYear(button_names, id_year) { - for (const name of button_names) { - const button = document.querySelector("button[data-name=" + name + "]"); - const b_value = button.value; - const new_value = b_value.replace(/id_year=\d+/, 'id_year=' + id_year); - button.setAttribute('value', new_value); - } -} - -/** - * renvoyer la valeur en secondes d'une date au format j/m/a - * @param {string} date - */ -function str2sec(date) { - const jma = date.split('/'); - const dd = new Date(jma[2], jma[1]-1, jma[0]); - return dd.getTime()/1000; -} - -// renvoyer la valeur en secondes d'un champ date -function getDate(idelem) { - return str2sec(document.getElementById(idelem).value); -} - -// (unused) désactiver les options du sélecteur qui ne sont pas dans un tableau de valeurs -function disableOptions(idSelect, init, values) { - for (let i = init; i < idSelect.options.length; ++i) { - const choix = idSelect.options[i]; - if (! values.includes(choix.value)) { - choix.setAttribute('disabled', 'true'); - choix.removeAttribute('selected'); - } - } -} - -// afficher la date de fin de l'exercice choisi -function setDateEnd(id_exercices, id_date, id_years) { - const selected_year = document.getElementById(id_exercices).value; - if (selected_year == '') { - document.getElementById(id_date).value = ''; - return; - } - const years_data = document.getElementById(id_years); - for (const choix of years_data.options) { - if (choix.value == selected_year) { - const epox = choix.text.split(' '); - const date_fin = new Date(epox[1] * 1000); - document.getElementById(id_date).value = date_fin.toLocaleDateString(); - break; - } - } -} - -// renvoyer la valeur numérique d'un montant formaté en € -function getNumber(text) { - return Number(text.replace(/ /g, '').replace(/,/, '.').replace(/€/, '')); -} - -// calculer le montant d'un amortissement -// @param montant immo -// @param durée immo (années) -// @param somme amortissements -// @param date début -// @param date de fin -// @result montant de l'amortissement -function computeAmort(montant_immo, duree_immo, somme_amort, date_debut, date_fin) { - const nbjours = 1 + (date_fin - date_debut) / (60*60*24); - return Math.round(Math.min(montant_immo / duree_immo / 365 * nbjours, montant_immo - somme_amort)); -} - -// calculer et afficher le montant de l'amortissement -function displayAmort(id_immo, id_duree, id_amort, id_years, id_exercices, id_montant, id_erreur, id_date=null) -{ - const div_erreur = document.getElementById(id_erreur); - div_erreur.setAttribute('class', 'hidden'); -// document.getElementById(id_erreur).setAttribute('class', 'hidden'); - let case_montant = document.getElementById(id_montant); - const selected_year = document.getElementById(id_exercices).value; - if (selected_year == '') { - case_montant.value = ''; - return; - } - const years_data = document.getElementById(id_years); - let date_debut, date_fin; - for (const choix of years_data.options) { - if (choix.value == selected_year) { - const epox = choix.text.split(' '); - date_debut = epox[0]; - date_fin = epox[1]; - break; - } - } - if (id_date != null) { - const date_choisie = str2sec(document.getElementById(id_date).value); - console.log("date_choisie = " + date_choisie + ", date_debut=" + date_debut + ", date_fin = " + date_fin); - if (date_debut <= date_choisie && date_choisie <= date_fin) { - date_fin = date_choisie; - } else { - div_erreur.setAttribute('class', ''); -// document.getElementById(id_erreur).setAttribute('class', ''); - } - } - const montant_immo = Number(document.getElementById(id_immo).value); - const duree_immo = Number(document.getElementById(id_duree).value); - const somme_amort = Number(document.getElementById(id_amort).value); - const montant_amort = computeAmort(montant_immo, duree_immo, somme_amort, date_debut, date_fin); - case_montant.value = montant_amort/100; - case_montant.innerText = montant_amort; -} - -function setSelectorYear(button_names, f_years_selector) { - const selected_year = document.getElementById(f_years_selector).value; - setAccountYear(button_names, selected_year); -} diff --git a/style.css b/style.css index c9c23f9..a742142 100644 --- a/style.css +++ b/style.css @@ -17,27 +17,3 @@ h2[class="aide"], h3[class="aide"] { margin-top: 0.5em; margin-bottom: 0.5em; } - -.informations { - margin-top : 0.5em; - margin-bottom : 0.5em; - padding : 0.5em; -} - -.informations legend { - font-weight: bold; - border-bottom : solid 1px var(--gLightBorderColor); - margin-bottom : 0.5em; -} - -.informations dt::after { - content: ' :'; -} - -.informations dl.describe > dt { - margin-right: 0; -} - -nav.amort aside { - margin-top : 0; -} diff --git a/write_exit.html b/write_exit.html deleted file mode 100644 index 95f4045..0000000 --- a/write_exit.html +++ /dev/null @@ -1,536 +0,0 @@ -{{* -*- 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, - id_project - FROM acc_transactions_lines AS line - INNER JOIN acc_transactions AS trans ON line.id_transaction = trans.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}} - {{*:assign date_debut=$start_date*}} -{{/select}} - -{{*if $date_debut < "2025-01-01"*}} - {{:assign vnc_code=675}} - {{:assign cession_code=775}} -{{* -{{else}} - {{:assign vnc_code=657}} - {{:assign cession_code=757}} -{{/if}} -*}} - -{{: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=$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=$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 - id_project=$ligne_immo.id_project - label=$libelle - }} - {{:assign - var="lines." - credit="%f/100"|math:$amort_comp - account=$amort_account - 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=$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 - id_project=$ligne_immo.id_project - label=$libelle - }} - {{:assign - var="lines." - credit="%f/100"|math:$amort_except - account=$amort_account - 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 libelle="Sortie du bilan de "|cat:$ligne_immo.label}} - {{:assign lines=null}} - {{:assign - var="lines." - id_account=$ligne_immo.id_account - credit="%f/100"|math:$ligne_immo.montant - id_project=$ligne_immo.id_project - label=$libelle - }} - {{:assign - var="lines." - account=$amort_account - debit="(%f-%f)/100"|math:$ligne_immo.montant:$valeur_nette - id_project=$ligne_immo.id_project - label=$libelle - }} - {{if $valeur_nette > 0}} - {{:assign - var="lines." - account=$vnc_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" subsubcurrent="balance_exit"}} -{{/if}} -{{:form_errors}} - -{{* Préparer les infos pour le formulaire *}} - -{{* déterminer les comptes pour les différentes écritures *}} -{{:assign var="comp_account.6811" value="6811 — Dot. aux amortissements des immobilisations"}} -{{:assign var="except_account.687" value="687 — Dot. aux amortissements & provisions - Charges exceptionnelles"}} - -{{#select code, label from acc_accounts where id = :id; - :id=$ligne_immo.id_account - assign=immo_account_info -}} -{{/select}} - -{{:include - file="./_get_amort_code.html" - code_immo=$immo_account_info.code - keep="code_amort" -}} -{{:assign - var="amort_account.%s"|args:$code_amort - value="%s — Amortissements "|args:$code_amort|cat:$immo_account_info.label}} -{{:assign - var="immo_account.%s"|args:$immo_account_info.code - value="%s — Immobilisation "|args::$immo_account_info.code|cat:$immo_account_info.label}} -{{:assign - var="vnc_account.%s"|args:$vnc_code - value="%s — Valeurs comptables des éléments d'actifs cédés"|args:$vnc_code}} -{{:assign - var="cession_account.%s"|args:$cession_code - value="%s — Produits des cessions d'actif"|args:$cession_code}} -{{:assign var="creance_account.462" value="462 — Créances sur cessions d'immobilisations"}} - -{{: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:"|"}} - -

    Sortir l'immobilisation « {{$ligne_immo.label}} » du bilan

    -
    - -
    - Données de l'imobilisation -
    -
    Montant
    -
    {{$ligne_immo.montant|money_currency:false}}
    -
    Date d'acquisition
    -
    {{$ligne_immo.date_achat|date_short}}
    - {{if $_GET.date_mes != $ligne_immo.date_achat|strtotime}} -
    Date de mise en service
    -
    {{$_GET.date_mes|date:"d/m/Y"}}
    - {{/if}} - {{if $_GET.duree_amort != null}} -
    Durée de l'amortissement
    -
    {{$_GET.duree_amort}} ans
    - {{/if}} -
    Montant des amortissements
    -
    {{$_GET.amort_amount|money_currency:false}} (à la date de début de l'exercice)
    -
    Valeur nette résiduelle
    -
    {{$valeur_nette|money_currency:false}} (à la date de début de l'exercice)
    -
    Date de sortie
    -
    {{$_GET.exit_date|date:"d/m/Y"}}
    - {{if $amort_comp > 0}} - {{:assign valeur_nette="%f-%f"|math:$valeur_nette:$amort_comp}} -
    Amortissement complémentaire
    -
    {{$amort_comp|money_currency:false}} (jusqu'à la date de sortie)
    -
    Total des amortissements
    -
    {{"%f+%f"|math:$_GET.amort_amount:$amort_comp|money_currency:false}} (à la date de sortie)
    -
    Valeur nette résiduelle
    -
    {{$valeur_nette|money_currency:false}} (à la date de sortie)
    - {{/if}} - {{if $montant_cession == 0}} - {{if $amort_except > 0}} -
    Amortissement exceptionnel
    -
    {{$amort_except|money_currency:false}}
    - {{/if}} - {{else}} -
    Montant de la cession
    -
    {{$montant_cession|money_currency:false}}
    - {{/if}} -
    -
    - -
    - Écritures de sortie du bilan - {{* Amortissement complémentaire *}} - {{if $amort_comp > 0}} - - - - - - - - - - - - - - - - - - - - - - - -
    Amortissement complémentaireDébitCrédit
    - Entre la date de début de l'exercice et la date de sortie du bilan -
    - {{:input - type="list" - name="comp_account" - target="!acc/charts/accounts/selector.php?codes=%s&year=%d"|args:"68*":$_GET.year - default=$comp_account - }} - {{$amort_comp|money_currency:false}}
    - {{:input - type="list" - name="amort_comp_account" - target="!acc/charts/accounts/selector.php?codes=%s&year=%d"|args:"28*":$_GET.year - default=$amort_account - }} - {{$amort_comp|money_currency:false}}
    - {{/if}} - - {{* Amortissement exceptionnel *}} - {{if $montant_cession == 0 && $amort_except > 0}} - - - - - - - - - - - - - - - - - - - - - - - -
    Amortissement exceptionnelDébitCrédit
    - Montant de l'immobilisation non encore amortie (valeur nette résiduelle à la date de sortie) -
    - {{:input - type="list" - name="except_account" - target="!acc/charts/accounts/selector.php?codes=%s&year=%d"|args:"687*":$_GET.year - default=$except_account - }} - {{$amort_except|money_currency:false}}
    - {{:input - type="list" - name="amort_except_account" - target="!acc/charts/accounts/selector.php?codes=%s&year=%d"|args:"28*":$_GET.year - default=$amort_account - }} - {{$amort_except|money_currency:false}}
    - {{/if}} - - {{* Sortie du bilan *}} - - - - - - - - - - - - {{if $montant_cession == 0}} - {{:assign montant=$ligne_immo.montant}} - {{else}} - {{:assign montant="%f+%f"|math:$_GET.amort_amount:$amort_comp}} - {{/if}} - - - - {{if $montant_cession > 0 && $valeur_nette > 0}} - - - - - - {{/if}} - - - - - - -
    Sortie du bilanDébitCrédit
    - {{:input - type="list" - name="amort_sortie_account" - target="!acc/charts/accounts/selector.php?codes=%s&year=%d"|args:"28*":$_GET.year - default=$amort_account - }} - {{$montant|money_currency:false}}
    - {{:input - type="list" - name="vnc_account" - target="!acc/charts/accounts/selector.php?codes=%s*&year=%d"|args:$vnc_code:$_GET.year - default=$vnc_account - }} - {{$valeur_nette|money_currency:false}}
    {{* style="pointer-events: none; opacity: 0.6;">*}} - {{:input - type="list" - name="immo_account" - target="!acc/charts/accounts/selector.php?codes=%s&year=%d"|args:$patterns:$_GET.year - default=$immo_account - }} - {{$ligne_immo.montant|money_currency:false}}
    - - {{* comptabilisation du produit de la cession *}} - {{if $montant_cession > 0}} - - - - - - - - - - - - - - - - - - - - -
    Comptabilisation de la cessionDébitCrédit
    - {{:input - type="list" - name="creance_account" - target="!acc/charts/accounts/selector.php?codes=%s&year=%d"|args:"462*":$_GET.year - default=$creance_account - }} - {{$montant_cession|money_currency:false}}
    - {{:input - type="list" - name="cession_account" - target="!acc/charts/accounts/selector.php?codes=%s*&year=%d"|args:$cession_code:$_GET.year - default=$cession_account - }} - {{$montant_cession|money_currency:false}}
    - {{/if}} -
    - -

    - {{:button type="submit" name="save" label="Enregistrer" shape="right" class="main"}} -

    -
    -{{:admin_footer}}