amortization/add_asset.html

136 lines
3.9 KiB
HTML
Raw Normal View History

2024-02-23 09:24:47 +01:00
{{* -*- brindille -*- *}}
2024-02-15 14:23:03 +01:00
{{:admin_header title="Ajout immobilisation" current="module_amortissement"}}
{{* barre de navigation *}}
{{if ! $dialog}}
{{:include file="_nav.html" current="index"}}
{{/if}}
{{* Traiter l'envoi du formulaire *}}
{{#form on="add"}}
{{* vérifier que la date est située dans un exercice ouvert *}}
{{:assign open_years=""}}
{{#years closed=false}}
{{: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 <= $_POST.date|parse_date|strtotime && $end_date|strtotime >= $_POST.date|parse_date|strtotime}}
{{:assign selected_year=$id}}
{{:assign selected_chart=$id_chart}}
{{/if}}
{{/years}}
{{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}}
{{* vérifier :
- que le compte d'immo débute par 20 ou 21
- est présent dans le PC de l'exercice correspondant à la date
*}}
{{#select
code
FROM acc_accounts
WHERE id_chart =:id_chart
AND
(code LIKE "20%" OR code LIKE "21%");
:id_chart = $selected_chart|intval
}}
{{if $_POST.debit_account|has_key:$code}}
{{:assign account_ok=1}}
{{:break}}
{{/if}}
{{/select}}
{{if $account_ok == null}}
{{:assign compte=$_POST.debit_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}}
2024-02-15 14:23:03 +01:00
{{* enregistrer l'écriture *}}
{{:assign var="credit_accounts" value=$_POST.credit_account|keys}}
{{:assign var="credit_account" value=$credit_accounts.0}}
{{:assign var="debit_accounts" value=$_POST.debit_account|keys}}
{{:assign var="debit_account" value=$debit_accounts.0}}
{{:api
method="POST"
path="accounting/transaction"
assign="result"
id_year=$selected_year
2024-02-15 14:23:03 +01:00
type="revenue"
date=$_POST.date
label=$_POST.designation
amount=$_POST.montant
debit=$debit_account
credit=$credit_account
2024-02-17 19:00:24 +01:00
id_project=$_POST.id_project
2024-02-15 14:23:03 +01:00
}}
{{* enregistrer les infos de l'immobilisation *}}
2024-03-14 11:03:54 +01:00
{{:assign var="immo_id" value=$result.lines.1.id}}
2024-02-15 14:23:03 +01:00
{{:assign key=""|uuid}}
{{:save
key=$key
validate_schema="schema.json"
type="immo"
2024-03-14 11:03:54 +01:00
line=$immo_id
2024-02-15 14:23:03 +01:00
duration=$_POST.duree|intval
}}
2024-03-12 17:09:40 +01:00
{{:redirect force="index.html?ok=1&msg=immobilisation"}}
2024-02-23 09:24:47 +01:00
{{/form}}
2024-02-15 14:23:03 +01:00
{{:form_errors}}
2024-02-15 14:23:03 +01:00
{{* formulaire d'ajout d'immobilisation *}}
{{:assign var="bank_account.512A" value="512A — Compte courant"}}
2024-02-15 14:23:03 +01:00
{{*
TODO
2024-02-17 19:00:24 +01:00
- ajouter autres rubriques selon besoin
2024-02-15 14:23:03 +01:00
*}}
2024-02-17 19:00:24 +01:00
{{#select id,label FROM acc_projects WHERE archived = 0;}}
{{:assign var="projects.%d"|args:$id value=$label}}
{{/select}}
2024-02-15 14:23:03 +01:00
<form method="post" action="">
<fieldset class="ajout_immo">
<legend>Ajouter une immobilisation</legend>
<dl>
{{:input type="date" name="date" label="Date" required=true default=$now|date_short}}
{{: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 default=1}}
{{:input
type="list"
name="credit_account"
label="Compte de décaissement"
required=true
target="!acc/charts/accounts/selector.php?targets=1:2:3&key=code"
2024-02-15 14:23:03 +01:00
default=$bank_account
}}
{{:input
type="list"
name="debit_account"
label="Compte d'immobilisation (20xx ou 21xx)"
required=true
target="!acc/charts/accounts/selector.php?key=code"
2024-02-15 14:23:03 +01:00
}}
2024-02-17 19:00:24 +01:00
{{if $projects != null}}
{{:input type="select" name="id_project" label="Projet (analytique)" options=$projects default_empty="— Aucun —"}}
{{/if}}
2024-02-15 14:23:03 +01:00
</dl>
</fieldset>
<p class="submit">
{{:button type="submit" name="add" label="Ajouter" shape="right" class="main"}}
</p>
</form>
{{:admin_footer}}