Ajout projet et proprification

This commit is contained in:
Jean-Christophe Engel 2024-02-17 19:00:24 +01:00
parent f35ca35538
commit 5e081c4f23
3 changed files with 45 additions and 91 deletions

View File

@ -7,7 +7,6 @@
{{* Traiter l'envoi du formulaire *}} {{* Traiter l'envoi du formulaire *}}
{{#form on="add"}} {{#form on="add"}}
{{* :debug POST=$_POST *}}
{{* enregistrer l'écriture *}} {{* enregistrer l'écriture *}}
{{:assign var="credit_accounts" value=$_POST.credit_account|keys}} {{:assign var="credit_accounts" value=$_POST.credit_account|keys}}
@ -15,9 +14,6 @@
{{:assign var="debit_accounts" value=$_POST.debit_account|keys}} {{:assign var="debit_accounts" value=$_POST.debit_account|keys}}
{{:assign var="debit_account" value=$debit_accounts.0}} {{:assign var="debit_account" value=$debit_accounts.0}}
{{* :debug credit_account=$credit_account *}}
{{* :debug debit_account=$debit_account *}}
{{:api {{:api
method="POST" method="POST"
path="accounting/transaction" path="accounting/transaction"
@ -29,17 +25,11 @@
amount=$_POST.montant amount=$_POST.montant
debit=$debit_account debit=$debit_account
credit=$credit_account credit=$credit_account
id_project=$_POST.id_project
}} }}
{{* :debug result=$result *}}
{{* enregistrer les infos de l'immobilisation *}} {{* enregistrer les infos de l'immobilisation *}}
{{* :debug lines=$result.lines *}}
{{* :debug line1=$result.lines.1 *}}
{{:assign var="line_id" value=$result.lines.1.id}} {{:assign var="line_id" value=$result.lines.1.id}}
{{* :debug line_id=$line_id *}}
{{:assign key=""|uuid}} {{:assign key=""|uuid}}
{{:save {{:save
key=$key key=$key
@ -57,7 +47,7 @@
{{:assign var="bank_account.512A" value="512A — Compte courant"}} {{:assign var="bank_account.512A" value="512A — Compte courant"}}
{{#years closed=false}} {{#years closed=false}}
{{:assign var="open_years.%d"|args:$id value=$label}} {{:assign var="open_years.%d"|args:$id value=$label}}
{{if $start_date <= $now && $end_date >= $now}} {{if $start_date|strtotime <= $now && $end_date|strtotime >= $now}}
{{:assign best_year=$id}} {{:assign best_year=$id}}
{{/if}} {{/if}}
{{/years}} {{/years}}
@ -66,9 +56,13 @@
{{* {{*
TODO TODO
- ajouter projet et autres rubriques selon besoin - ajouter autres rubriques selon besoin
*}} *}}
{{#select id,label FROM acc_projects WHERE archived = 0;}}
{{:assign var="projects.%d"|args:$id value=$label}}
{{/select}}
<form method="post" action=""> <form method="post" action="">
<fieldset class="ajout_immo"> <fieldset class="ajout_immo">
<legend>Ajouter une immobilisation</legend> <legend>Ajouter une immobilisation</legend>
@ -93,6 +87,9 @@
required=true required=true
target="!acc/charts/accounts/selector.php?key=code&year=%d"|args:$best_year target="!acc/charts/accounts/selector.php?key=code&year=%d"|args:$best_year
}} }}
{{if $projects != null}}
{{:input type="select" name="id_project" label="Projet (analytique)" options=$projects default_empty="— Aucun —"}}
{{/if}}
</dl> </dl>
</fieldset> </fieldset>

View File

@ -13,27 +13,28 @@
{{#select {{#select
line.id as line_id, line.id as line_id,
line.id_account as account_id, line.id_account as account_id,
line.id_project as project_id,
trans.id as trans_id, trans.id as trans_id,
line.debit as montant, line.debit as montant,
trans.label as label, trans.label as label,
trans.date as date_achat, trans.date as date_achat,
y.id as year_id, y.id as year_id,
y.end_date as date_fin y.end_date as date_fin,
project.label as project_label
from acc_transactions_lines as line from acc_transactions_lines as line
inner join acc_transactions as trans on line.id_transaction = trans.id inner join acc_transactions as trans on line.id_transaction = trans.id
inner join acc_years as y on trans.id_year = y.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; where line.id = :line_id;
:line_id = $_GET.line|intval :line_id = $_GET.line|intval
assign=ligne_immo assign=ligne_immo
}} }}
<h3>Amortissement de « {{$label}} » d'un montant de {{"%f"|math:$montant|money_currency}} en date du {{$date_achat|date_short}}</h3> <h2>Amortissement de « {{$label}} » d'un montant de {{"%f"|math:$montant|money_currency}} en date du {{$date_achat|date_short}} sur {{$info_immo.duration}} ans</h2>
{{else}} {{else}}
{{:assign message="Immobilisation %s non trouvée"|args:$_GET.line}} {{:assign message="Immobilisation %s non trouvée"|args:$_GET.line}}
{{:error message=$message}} {{:error message=$message}}
{{/select}} {{/select}}
{{*:debug ligne_immo=$ligne_immo*}}
{{* lister les écritures d'amortissement *}} {{* lister les écritures d'amortissement *}}
{{#select {{#select
line.id as l_immo, line.id as l_immo,
@ -45,6 +46,8 @@
line2.id_transaction as trans_id, line2.id_transaction as trans_id,
line2.id_project as projet, line2.id_project as projet,
line2.id_account as account_id, line2.id_account as account_id,
line2.id_project as project_id,
project.label as project_label,
trans.date as date_immo, trans.date as date_immo,
acc.code as account_code, acc.code as account_code,
acc.label as nom_compte, acc.label as nom_compte,
@ -54,6 +57,7 @@
inner JOIN acc_transactions_lines as line2 on links.id_transaction = line2.id_transaction inner JOIN acc_transactions_lines as line2 on links.id_transaction = line2.id_transaction
inner join acc_accounts as acc on line2.id_account = acc.id inner join acc_accounts as acc on line2.id_account = acc.id
inner join acc_transactions as trans on line2.id_transaction = trans.id inner join acc_transactions as trans on line2.id_transaction = trans.id
left join acc_projects AS project ON line.id_project = project.id
where line.id = :line_id and line2.debit <> 0 where line.id = :line_id and line2.debit <> 0
order by trans.date; order by trans.date;
:line_id = $info_immo.line|intval :line_id = $info_immo.line|intval
@ -61,16 +65,11 @@
}} }}
{{:assign trans_url="%s/acc/transactions/details.php?id=%s"|args:$admin_url:$trans_id}} {{:assign trans_url="%s/acc/transactions/details.php?id=%s"|args:$admin_url:$trans_id}}
{{/select}} {{/select}}
{{*:debug lines=$lines*}}
{{*:debug line=$lines.0*}}
{{*:debug line=$lines.1*}}
{{* calculer les amortissements *}} {{* calculer les amortissements *}}
{{* montant de l'annuité normale *}} {{* montant de l'annuité normale *}}
{{:assign montant="%f"|math:$ligne_immo.montant}} {{:assign montant="%f"|math:$ligne_immo.montant}}
{{:assign annuite="%f/%f"|math:$montant:$info_immo.duration|intval}} {{:assign annuite="%f/%f"|math:$montant:$info_immo.duration|intval}}
{{*:debug montant=$montant *}}
{{*:debug annuite=$annuite *}}
{{* liste des exercices *}} {{* liste des exercices *}}
{{#years}} {{#years}}
@ -79,24 +78,18 @@
{{:assign var="all_years.%d.closed"|args:$id value=$closed}} {{:assign var="all_years.%d.closed"|args:$id value=$closed}}
{{/years}} {{/years}}
{{*
{{:debug all_years=$all_years}}
{{:assign current_year=8}}
{{:assign var="date_immo" from="all_years.%s.end_date"|args:$current_year}}
{{:debug date_immo=$date_immo}}
*}}
{{* première annuité *}} {{* première annuité *}}
{{:assign date_achat=$ligne_immo.date_achat|date_short}} {{:assign date_achat=$ligne_immo.date_achat|date_short}}
{{:assign date_fin=$ligne_immo.date_fin|date_short}} {{:assign date_fin=$ligne_immo.date_fin|date_short}}
{{:include file="_calcul_dates.html" date_debut=$date_achat date_fin=$date_fin keep="nbjours"}} {{:include file="_calcul_dates.html" date_debut=$date_achat date_fin=$date_fin keep="nbjours"}}
{{:assign annuite_1="%f/360*%d"|math:$annuite:$nbjours|intval}} {{:assign annuite_1="%f/360*%d"|math:$annuite:$nbjours|intval}}
{{*:debug annuite1=$annuite_1 *}}
{{:assign date_immo=$date_fin}} {{:assign date_immo=$date_fin}}
{{:assign annuite_courante=$annuite_1}} {{:assign annuite_courante=$annuite_1}}
{{:assign solde=$montant}} {{:assign solde=$montant}}
{{:assign current_year=$ligne_immo.year_id}} {{:assign current_year=$ligne_immo.year_id}}
{{:assign project_id=$ligne_immo.project_id}}
{{:assign project_label=$ligne_immo.project_label}}
<section class="amortissement"> <section class="amortissement">
<h2 class="ruler">Liste des amortissements</h2> <h2 class="ruler">Liste des amortissements</h2>
@ -108,16 +101,15 @@
<th>Montant</th> <th>Montant</th>
<th>Solde</th> <th>Solde</th>
<th>Libellé</th> <th>Libellé</th>
<th>ligne amort</th> <th>N° compte</th>
<th>Compte</th> <th>Compte</th>
<th>Nom compte</th> <th>Projet</th>
<th class="actions"></th> <th class="actions"></th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
{{#foreach count="%d+1"|math:$info_immo.duration|intval key="num"}} {{#foreach count="%d+1"|math:$info_immo.duration|intval key="num"}}
{{:assign var="line" from="lines.%s"|args:$num}} {{:assign var="line" from="lines.%s"|args:$num}}
{{*:debug line=$line*}}
{{if $line != null}} {{if $line != null}}
{{* données de l'écriture *}} {{* données de l'écriture *}}
@ -129,13 +121,15 @@
<td class="money">{{"%f"|math:$line.montant|money}}</td> <td class="money">{{"%f"|math:$line.montant|money}}</td>
<td class="money">{{"%f"|math:$solde|money}}</td> <td class="money">{{"%f"|math:$solde|money}}</td>
<td>{{$line.libelle}}</td> <td>{{$line.libelle}}</td>
<td>{{$line.l_amort}}</td>
<td>{{$line.account_code}}</td> <td>{{$line.account_code}}</td>
<td>{{$line.nom_compte}}</td> <td>{{$line.nom_compte}}</td>
<td>{{$line.project_label}}</td>
<td class="actions"></td> <td class="actions"></td>
</tr> </tr>
{{:assign libelle=$line.libelle}} {{:assign libelle=$line.libelle}}
{{:assign ammort_account=$line.ammort_account}} {{:assign ammort_account=$line.ammort_account}}
{{:assign project_id=$line.project_id}}
{{:assign project_label=$line.project_label}}
{{:assign annuite_courante="min(%f,%f)"|math:$annuite:$solde}} {{:assign annuite_courante="min(%f,%f)"|math:$annuite:$solde}}
{{:assign current_year="%d+1"|math:$current_year}} {{:assign current_year="%d+1"|math:$current_year}}
{{:assign date_immo=$line.date_immo}} {{:assign date_immo=$line.date_immo}}
@ -167,14 +161,16 @@
</td> </td>
<td></td> <td></td>
<td></td> <td></td>
<td></td> <td>{{$project_label}}</td>
<td class="actions"> <td class="actions">
{{if $all_years|keys|has:$current_year}} {{if $all_years|keys|has:$current_year}}
{{:linkbutton {{:linkbutton
label="Enregistrer" label="Enregistrer"
href="save_amort.html?amount=%d&account=%s&year=%s&label=%s"|args:$annuite_courante:$ligne_immo.account_id:$current_year:$libelle href="save_amort.html?amount=%d&account=%s&year=%s&trans_id=%d&line_id=%s&project_id=%d&label=%s"|args:$annuite_courante:$ligne_immo.account_id:$current_year:$ligne_immo.trans_id:$_GET.line:$project_id:$libelle
shape="right" shape="right"
}} }}
{{else}}
{{:linkbutton label="Enregistrer" href="" shape="alert"}}
{{/if}} {{/if}}
</td> </td>
</tr> </tr>

View File

@ -4,12 +4,11 @@
{{:include file="_nav.html" current="index"}} {{:include file="_nav.html" current="index"}}
{{if $_GET.ok}} {{if $_GET.ok}}
<p class="block confirm">Modification effectuée</p> <p class="block confirm">Immobilisation enregistrée</p>
{{elseif $_GET.err}} {{elseif $_GET.err}}
<p class="block error">Modification refusée</p> <p class="block error">Enregistrement immobilisation refusée</p>
{{/if}} {{/if}}
{{* lister les immobilisations *}} {{* lister les immobilisations *}}
<section class="immobilisation"> <section class="immobilisation">
<h2 class="ruler">Liste des immobilisations</h2> <h2 class="ruler">Liste des immobilisations</h2>
@ -17,21 +16,20 @@
<table class="list"> <table class="list">
<thead> <thead>
<tr> <tr>
<th>Id</th> <th></th>
<th>Libellé</th>
<th>Date</th> <th>Date</th>
<th>id_line</th> <th>Libellé</th>
<th>Montant</th>
<th>Durée</th>
<th>N° compte</th> <th>N° compte</th>
<th>Compte</th> <th>Compte</th>
<th>Montant</th> <th>Projet</th>
<th class="actions"></th> <th class="actions"></th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
{{* {{*
TODO améliorer cette requête : TODO améliorer cette requête : voir si assez général
- ne pas mettre l'id du PC
- voir si assez général
*}} *}}
{{#select {{#select
@ -41,27 +39,28 @@
line.id as line_id, line.id as line_id,
account.code as account_code, account.code as account_code,
account.label as account_label, account.label as account_label,
line.debit AS debit line.debit AS debit,
project.label as project_label
FROM acc_transactions AS trans FROM acc_transactions AS trans
INNER JOIN acc_transactions_lines AS line ON line.id_transaction = trans.id 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_accounts AS account ON line.id_account = account.id
INNER JOIN acc_years AS years ON trans.id_year = years.id INNER JOIN acc_years AS years ON trans.id_year = years.id
LEFT JOIN acc_projects AS proj ON line.id_project = proj.id LEFT JOIN acc_projects AS project ON line.id_project = project.id
WHERE WHERE
account.id_chart = "3"
AND
(account.code LIKE '21%' OR account.code LIKE '22%') (account.code LIKE '21%' OR account.code LIKE '22%')
ORDER BY trans.date DESC ORDER BY trans.date DESC
}} }}
{{:assign trans_url="%s/acc/transactions/details.php?id=%s"|args:$admin_url:$trans_id}} {{:assign trans_url="%s/acc/transactions/details.php?id=%s"|args:$admin_url:$trans_id}}
{{#load type="immo" assign="info_immo" where="$$.line = :line_id" :line_id=$line_id|intval}}{{/load}}
<tr> <tr>
<td class="num"><a href={{$trans_url}}>#{{$trans_id}}</a></td> <td class="num"><a href={{$trans_url}}>#{{$trans_id}}</a></td>
<td>{{$trans_label}}</td>
<td>{{$trans_date|date_short}}</td> <td>{{$trans_date|date_short}}</td>
<td>{{$line_id}}</td> <td>{{$trans_label}}</td>
<td class="money">{{"%f"|math:$debit|money}}</td>
<td class="num">{{$info_immo.duration}}</td>
<td>{{$account_code}}</td> <td>{{$account_code}}</td>
<td>{{$account_label}}</td> <td>{{$account_label}}</td>
<td class="money">{{"%f"|math:$debit|money}}</td> <td>{{$project_label}}</td>
<td class="actions"> <td class="actions">
{{:linkbutton {{:linkbutton
label="Amortissements" label="Amortissements"
@ -88,42 +87,4 @@
</fieldset> </fieldset>
</form> </form>
{{* sélectionner un compte *}}
<h1>TEST</h1>
{{:assign var="ll.0.d" value="%f/100"|math:$debit}}
{{:assign var="ll.1.c" value="%f/100"|math:$debit}}
{{* :debug ll=$ll *}}
{{:assign
var="qs"
t=0
l="Amortissement de %s"|args:$trans_label
dt=$trans_date
a00=0
ll=$ll
}}
{{:assign qs=$qs|http_build_query}}
{{:linkbutton
label="Ajouter"
href="!acc/transactions/new.php?%s"|args:$qs
shape="plus"
target="_dialog"
}}
<form method="post" action="">
<fieldset>
<legend>Écriture de note de frais</legend>
{{:assign var="default_account.625" value="625 Déplacements, missions et réceptions"}}
{{:input
type="list"
name="account"
label="Compte de paiement"
required=true
target="!acc/charts/accounts/selector.php?targets=5&key=code&year=%d"|args:7
default=$default_account
}}
</fieldset>
</form>
{{:admin_footer}} {{:admin_footer}}