2024-02-23 09:24:47 +01:00
|
|
|
{{* -*- brindille -*- *}}
|
2024-02-29 19:07:13 +01:00
|
|
|
|
2024-02-16 11:53:19 +01:00
|
|
|
{{:admin_header title="Ajout amortissement" current="module_amortissement"}}
|
|
|
|
|
|
|
|
{{* barre de navigation *}}
|
|
|
|
{{if ! $dialog}}
|
|
|
|
{{:include file="_nav.html" current="amortization"}}
|
|
|
|
{{/if}}
|
|
|
|
|
|
|
|
{{* Traiter l'envoi du formulaire *}}
|
2024-02-17 19:01:04 +01:00
|
|
|
{{#form on="save"}}
|
2024-03-19 18:20:53 +01:00
|
|
|
|
|
|
|
{{* vérifier que la date est située dans un exercice ouvert *}}
|
2024-03-25 19:15:04 +01:00
|
|
|
{{:include
|
|
|
|
file="_check_date.html"
|
|
|
|
date=$_POST.date
|
|
|
|
keep="open_years, selected_year, selected_chart"
|
|
|
|
}}
|
2024-03-19 18:20:53 +01:00
|
|
|
|
|
|
|
{{if $selected_year == null}}
|
|
|
|
{{:assign message="La date choisie n'est dans aucun exercice ouvert !!\nExercices ouverts : %s"|args:$open_years}}
|
|
|
|
{{:error message=$message}}
|
|
|
|
{{/if}}
|
|
|
|
|
2024-03-25 19:15:04 +01:00
|
|
|
{{* déterminer le numéro des comptes au cas où la clé serait un identifiant *}}
|
|
|
|
{{:include
|
|
|
|
file="_get_codes.html"
|
|
|
|
account=$_POST.debit_account
|
|
|
|
keep="account_code"
|
|
|
|
}}
|
|
|
|
{{:assign debit_account=$account_code}}
|
|
|
|
{{:include
|
|
|
|
file="_get_codes.html"
|
|
|
|
account=$_POST.credit_account
|
|
|
|
keep="account_code"
|
|
|
|
}}
|
|
|
|
{{:assign credit_account=$account_code}}
|
|
|
|
|
2024-03-19 18:20:53 +01:00
|
|
|
{{* vérifier :
|
|
|
|
- que le compte d'amortissement débute par 280 ou 281
|
|
|
|
- est présent dans le PC de l'exercice correspondant à la date
|
|
|
|
*}}
|
|
|
|
{{:assign var="prefix_array." value="'280%'"}}
|
|
|
|
{{:assign var="prefix_array." value="'281%'"}}
|
|
|
|
{{:include
|
|
|
|
file="_check_account.html"
|
2024-03-25 19:15:04 +01:00
|
|
|
account=$credit_account
|
2024-03-19 18:20:53 +01:00
|
|
|
chart_id=$selected_chart
|
|
|
|
prefix_array=$prefix_array
|
|
|
|
keep="account_ok"
|
|
|
|
}}
|
|
|
|
|
|
|
|
{{if $account_ok == null}}
|
2024-03-25 19:15:04 +01:00
|
|
|
{{:assign compte=$credit_account|implode:""}}
|
|
|
|
{{:error message="Le compte « %s » n'est pas un compte d'amortissement ou n'est pas dans le plan comptable de l'exercice choisi"|args:$compte}}
|
2024-03-19 18:20:53 +01:00
|
|
|
{{/if}}
|
|
|
|
|
|
|
|
{{* vérifier que le montant ne dépasse pas le solde restant *}}
|
2024-03-20 18:08:47 +01:00
|
|
|
{{if $_POST.montant|trim|money_int > $_GET.solde|intval}}
|
|
|
|
{{:assign solde=$_GET.solde|money_raw}}
|
2024-03-19 18:20:53 +01:00
|
|
|
{{:error message="Le montant indiqué « %s » dépasse le solde à amortir « %s »"|args:$_POST.montant:$solde}}
|
|
|
|
{{/if}}
|
|
|
|
|
2024-02-17 19:01:04 +01:00
|
|
|
{{* enregistrer l'écriture *}}
|
|
|
|
{{:assign var="linked_transactions." value=$_GET.trans_id}}
|
|
|
|
|
|
|
|
{{:assign
|
|
|
|
var="lines."
|
|
|
|
debit=$_POST.montant
|
2024-03-25 19:15:04 +01:00
|
|
|
account=$debit_account|keys|key:0
|
2024-02-17 19:01:04 +01:00
|
|
|
id_project=$_GET.project_id
|
|
|
|
label=$_POST.designation
|
|
|
|
}}
|
|
|
|
{{:assign
|
|
|
|
var="lines."
|
|
|
|
credit=$_POST.montant
|
2024-03-25 19:15:04 +01:00
|
|
|
account=$credit_account|keys|key:0
|
2024-02-17 19:01:04 +01:00
|
|
|
id_project=$_GET.project_id
|
|
|
|
label=$_POST.designation
|
|
|
|
}}
|
|
|
|
|
|
|
|
{{:api
|
|
|
|
method="POST"
|
|
|
|
path="accounting/transaction"
|
|
|
|
assign="result"
|
|
|
|
assign_code="result_code"
|
2024-03-19 18:20:53 +01:00
|
|
|
id_year=$selected_year
|
2024-02-17 19:01:04 +01:00
|
|
|
type="advanced"
|
|
|
|
date=$_POST.date
|
|
|
|
label=$_POST.designation
|
|
|
|
lines=$lines
|
|
|
|
linked_transactions=$_GET.trans_id|intval
|
|
|
|
}}
|
|
|
|
|
2024-03-14 18:34:45 +01:00
|
|
|
{{:redirect force="amortization.html?immo_id=%s&ok=1&msg=amortissement"|args:$_GET.immo_id}}
|
2024-02-17 19:01:04 +01:00
|
|
|
{{/form}}
|
2024-02-16 11:53:19 +01:00
|
|
|
|
2024-03-19 18:20:53 +01:00
|
|
|
{{:form_errors}}
|
|
|
|
|
2024-02-16 11:53:19 +01:00
|
|
|
{{* Préparer les infos pour le formulaire *}}
|
|
|
|
{{:assign var="debit_account.6811" value="6811 — Dot. aux amortissements des immobilisations"}}
|
|
|
|
|
|
|
|
{{*
|
|
|
|
déterminer le compte d'amortissement en fonction du compte
|
|
|
|
d'immobilisation => ajouter un 8 après le 2 de tête
|
2024-03-12 17:09:40 +01:00
|
|
|
*}}
|
2024-02-16 11:53:19 +01:00
|
|
|
{{#select code, label from acc_accounts where id = :id; :id=$_GET.account assign=amort_account}}{{/select}}
|
|
|
|
{{:assign c1=$amort_account.code|substr:0:1}}
|
|
|
|
{{:assign reste=$amort_account.code|substr:1}}
|
|
|
|
{{:assign amort_code=$c1|cat:8|cat:$reste}}
|
|
|
|
{{:assign var="credit_account.%s"|args:$amort_code value="%s — Amortissements "|args:$amort_code|cat:$amort_account.label}}
|
|
|
|
|
2024-03-14 18:34:45 +01:00
|
|
|
{{#select
|
|
|
|
id,
|
|
|
|
label,
|
2024-03-15 20:53:59 +01:00
|
|
|
end_date as date_amort
|
2024-03-14 18:34:45 +01:00
|
|
|
from acc_years where id=:id;
|
|
|
|
:id=$_GET.year assign=year
|
|
|
|
}}
|
|
|
|
{{/select}}
|
2024-02-16 11:53:19 +01:00
|
|
|
|
|
|
|
{{#years closed=false}}
|
|
|
|
{{:assign var="open_years.%d"|args:$id value=$label}}
|
|
|
|
{{/years}}
|
|
|
|
|
|
|
|
<form method="post" action="">
|
|
|
|
<fieldset class="ajout_amort">
|
|
|
|
<legend>Ajouter une écriture d'amortissement</legend>
|
|
|
|
<dl>
|
2024-03-14 18:34:45 +01:00
|
|
|
{{:input type="date" name="date" label="Date" required=true default=$year.date_amort|date_short}}
|
2024-02-16 11:53:19 +01:00
|
|
|
{{: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?&key=code&year=%d"|args:$year.id
|
|
|
|
default=$debit_account
|
|
|
|
}}
|
|
|
|
{{:input
|
|
|
|
type="list"
|
2024-02-17 19:01:04 +01:00
|
|
|
name="credit_account"
|
2024-02-16 11:53:19 +01:00
|
|
|
label="Compte d'amortissement (280xx ou 281xx)"
|
|
|
|
required=true
|
|
|
|
target="!acc/charts/accounts/selector.php?key=code&year=%d"|args:$year.id
|
|
|
|
default=$credit_account
|
|
|
|
}}
|
|
|
|
</dl>
|
|
|
|
</fieldset>
|
|
|
|
|
|
|
|
<p class="submit">
|
2024-02-17 19:01:04 +01:00
|
|
|
{{:button type="submit" name="save" label="Enregistrer" shape="right" class="main"}}
|
2024-02-16 11:53:19 +01:00
|
|
|
</p>
|
|
|
|
</form>
|
|
|
|
{{:admin_footer}}
|