{{* -*- brindille -*- *}} {{:admin_header title="Transfert d'immobilisation en cours" current="module_amortissement"}} {{:include file="_get_config.html" keep="module.config.prefixes"}} {{#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:" ("|cat:$debut|cat:" - "|cat:$fin|cat:")"}} {{if $ts_debut <= $now && $now <= $ts_fin}} {{:assign selected_year=$id}} {{/if}} {{else}} {{:error message="Aucun exercice ouvert"}} {{/years}} {{* Traiter l'envoi du formulaire *}} {{#form on="transfer"}} {{* vérifier que la date de mise en service est située dans l'exercice sélectionné *}} {{:assign ts_date = $_POST.date_mes|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 !"}} {{/if}} {{if ! $_POST.amortir}} {{* ne pas amortir *}} {{:assign duration=0}} {{:assign date_debut=$_POST.date_achat|parse_date}} {{:assign status="ignored"}} {{else}} {{* vérifier que la date d'acquisition est antérieure à la date de mise en service *}} {{:assign date_debut=$_POST.date_mes|parse_date}} {{:assign duration=$_POST.duree|intval}} {{:assign status="managed"}} {{/if}} {{* comptes de débit *}} {{#foreach from=$_POST.credit_accounts key="rang" item="elem"}} {{:include file="_get_codes.html" account=$elem keep="account_code" }} {{:assign debit_account=$account_code|keys|key:0}} {{:assign var="amount" from="_POST.credit_lines.%s"|args:$rang}} {{:assign var="label" from="_POST.line_labels.%s"|args:$rang}} {{:assign var="lines." account=$debit_account credit=$amount label=$label }} {{/foreach}} {{* compte de crédit *}} {{:include file="_get_codes.html" account=$_POST.debit_account keep="account_code" }} {{:assign credit_account=$account_code|keys|key:0}} {{:assign var="amount" from="_POST.debit_lines.%s"|args:0}} {{:assign count=$_POST.line_labels|count}} {{:assign count="%d-1"|math:$count}} {{:assign var="label" from="_POST.line_labels.%s"|args:$count}} {{:assign var="lines." account=$credit_account debit=$amount label=$label }} {{* vérifier : - que le compte d'immo débute par un préfixe correct (20, 21, ...) - est présent dans le PC de l'exercice correspondant à la date *}} {{:include file="_check_account.html" account=$account_code chart_id=$selected_chart prefix_array=$module.config.prefixes keep="account_ok" }} {{if $account_ok == null}} {{:assign compte=$credit_account|implode:""}} {{:error message="Le compte « %s » n'est pas un compte d'immobilisation ou n'est pas dans le plan comptable de l'exercice choisi"|args:$compte}} {{/if}} {{* écritures liées *}} {{:assign var="linked_transactions" value=$_GET.trans|explode:","}} {{* enregistrer l'écriture *}} {{:api method="POST" path="accounting/transaction" assign="result" id_year=$_POST.id_year type="advanced" date=$_POST.date_mes label=$_POST.designation|trim lines=$lines linked_transactions=$linked_transactions }} {{:assign lines_count=$lines|count}} {{:assign lines_count="%d-1"|math:$lines_count}} {{:assign var="immo_id" from="result.lines.%s.id"|args:$lines_count}} {{* enregistrer les infos de l'immobilisation *}} {{:save key=""|uuid validate_schema="schema.json" type="immo" line=$immo_id duration=$duration date=$date_debut status=$status }} {{if $_POST.amortir}} {{:assign type_immo="managed"}} {{else}} {{:assign type_immo="other"}} {{/if}} {{:redirect force="index.html?ok=1&msg=immobilisation&type_immo=%s"|args:$type_immo}} {{/form}} {{* barre de navigation *}} {{if ! $dialog}} {{:include file="_nav.html" current="index"}} {{/if}} {{:form_errors}} {{* formulaire d'ajout d'immobilisation *}} {{#select id,label FROM acc_projects WHERE archived = 0;}} {{:assign var="projects.%d"|args:$id value=$label}} {{/select}} {{#foreach from=$module.config.prefixes item="code"}} {{:assign var="pattern_array." value="%s*"|args:$code}} {{/foreach}} {{:assign var="patterns" value=$pattern_array|implode:"|"}}
La date choisie n'est dans aucun exercice ouvert !