Compare commits

...

2 Commits

4 changed files with 48 additions and 22 deletions

View File

@ -9,6 +9,46 @@
{{* 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}}
{{* enregistrer l'écriture *}}
{{:assign var="credit_accounts" value=$_POST.credit_account|keys}}
{{:assign var="credit_account" value=$credit_accounts.0}}
@ -19,7 +59,7 @@
method="POST"
path="accounting/transaction"
assign="result"
id_year=$_POST.id_year
id_year=$selected_year
type="revenue"
date=$_POST.date
label=$_POST.designation
@ -43,17 +83,10 @@
{{:redirect force="index.html?ok=1&msg=immobilisation"}}
{{/form}}
{{* Préparer les infos pour le formulaire *}}
{{:assign var="bank_account.512A" value="512A — Compte courant"}}
{{#years closed=false}}
{{:assign var="open_years.%d"|args:$id value=$label}}
{{if $start_date|strtotime <= $now && $end_date|strtotime >= $now}}
{{:assign best_year=$id}}
{{/if}}
{{/years}}
{{:form_errors}}
{{* formulaire d'ajout d'immobilisation *}}
{{:assign var="bank_account.512A" value="512A — Compte courant"}}
{{*
TODO
@ -68,7 +101,6 @@
<fieldset class="ajout_immo">
<legend>Ajouter une immobilisation</legend>
<dl>
{{:input type="select" default=$best_year name="id_year" label="Exercice" required=true options=$open_years}}
{{: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}}
@ -78,7 +110,7 @@
name="credit_account"
label="Compte de décaissement"
required=true
target="!acc/charts/accounts/selector.php?targets=1:2:3&key=code&year=%d"|args:$best_year
target="!acc/charts/accounts/selector.php?targets=1:2:3&key=code"
default=$bank_account
}}
{{:input
@ -86,7 +118,7 @@
name="debit_account"
label="Compte d'immobilisation (20xx ou 21xx)"
required=true
target="!acc/charts/accounts/selector.php?key=code&year=%d"|args:$best_year
target="!acc/charts/accounts/selector.php?key=code"
}}
{{if $projects != null}}
{{:input type="select" name="id_project" label="Projet (analytique)" options=$projects default_empty="— Aucun —"}}

View File

@ -33,7 +33,7 @@
<li>Montant</li>
<li>Durée d'amortissement en années</li>
<li>Compte de décaissement : à choisir dans la liste</li>
<li>Compte d'immobilisation : idem</li>
<li>Compte d'immobilisation : doit débuter par <b>20</b> ou <b>21</b></li>
<li>Projet analytique (optionnel)</li>
</ul>

View File

@ -43,7 +43,7 @@
trans.label as label,
trans.date as date_achat,
y.id as year_id,
date(y.start_date, "start of year", "+1 year", "-1 day") as date_amort,
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
@ -59,8 +59,6 @@
{{:error message=$message}}
{{/select}}
{{*:debug ligne_immo=$ligne_immo*}}
{{* chercher des écritures d'amortissement liées à l'immobilisation *}}
{{#select
l_amort.credit as amort_amount,
@ -100,8 +98,6 @@
{{:assign var="amort_years." value=$amort_year}}
{{/select}}
{{*:debug linked_lines=$linked_lines amort_associes=$amort_associes*}}
{{* chercher parmi les associations *}}
{{#foreach from=$info_immo.amort item="id_amort"}}
{{#select
@ -138,7 +134,6 @@
{{/select}}
{{/foreach}}
{{*:debug linked_lines=$linked_lines*}}
{{* montant de l'annuité théorique *}}
{{:assign montant="%f"|math:$ligne_immo.montant}}
{{:assign annuite="%f/%f"|math:$montant:$duree}}
@ -149,7 +144,6 @@
{{:include file="_calcul_dates.html" date_debut=$date_achat date_fin=$date_amort keep="nbjours"}}
{{:assign annuite_1="%f/360*%d"|math:$annuite:$nbjours|intval}}
{{*:assign date_amort=$date_fin*}}
{{:assign annuite_courante=$annuite_1}}
{{:assign current_year=$ligne_immo.year_id}}
{{:assign solde=$ligne_immo.montant}}

View File

@ -59,7 +59,7 @@
{{#select
id,
label,
date(start_date, "start of year", "+1 year", "-1 day") as date_amort
end_date as date_amort
from acc_years where id=:id;
:id=$_GET.year assign=year
}}