Affichage détails immo ; ajout montant au crédit du compte d'une l'immo
This commit is contained in:
parent
269ff406e4
commit
463d5d109e
3 changed files with 454 additions and 0 deletions
153
attach_immo.html
Normal file
153
attach_immo.html
Normal file
|
|
@ -0,0 +1,153 @@
|
|||
{{* -*- brindille -*- *}}
|
||||
{{:admin_header title="Écritures au crédit du compte d'immobilisation" custom_css="./style.css" current="module_amortization"}}
|
||||
|
||||
{{*
|
||||
Enregistrer la liaison entre une ligne d'immobilisation et
|
||||
une ligne d'écriture au crédit du compte de l'immobilisation
|
||||
@param credit_line_id : ligne d'écriture au crédit du compte de l'immobilisation
|
||||
@param immo_doc_id : numéro du doc d'immo
|
||||
*}}
|
||||
|
||||
{{* chercher l'écriture d'immobilisation *}}
|
||||
{{#load id=$_GET.immo_doc_id|intval assign="doc_immo"}}
|
||||
{{else}}
|
||||
{{:error message="Immobilisation non gérée ; vous devez d'abord renseigner ses informations"}}
|
||||
{{/load}}
|
||||
{{#select
|
||||
line.id as immo_line_id,
|
||||
line.id_transaction as immo_trans_id,
|
||||
line.label as line_label,
|
||||
trans.label as trans_label
|
||||
FROM acc_transactions_lines as line
|
||||
INNER JOIN acc_transactions AS trans ON line.id_transaction = trans.id
|
||||
WHERE line.id = :line_id;
|
||||
:line_id = $doc_immo.line
|
||||
assign="ligne_immo"
|
||||
}}
|
||||
{{else}}
|
||||
{{:error message="Immobilisation non trouvée"}}
|
||||
{{/select}}
|
||||
|
||||
{{:assign label_immo=$doc_immo.label|or:$ligne_immo.trans_label}}
|
||||
{{if $ligne_immo.line_label != null && $ligne_immo.line_label != $label_immo}}
|
||||
{{:assign label_immo=$label_immo|cat:" — "|cat:$ligne_immo.line_label}}
|
||||
{{/if}}
|
||||
|
||||
{{* chercher l'écriture au crédit du compte d'immobilisation *}}
|
||||
{{#select
|
||||
line.id_transaction as credit_trans_id,
|
||||
line.credit as amount,
|
||||
trans.label as trans_label,
|
||||
line.label as line_label
|
||||
FROM acc_transactions_lines as line
|
||||
INNER JOIN acc_transactions AS trans ON line.id_transaction = trans.id
|
||||
WHERE line.id = :line_id;
|
||||
:line_id = $_GET.credit_line_id|intval
|
||||
assign="credit_line"
|
||||
}}
|
||||
{{else}}
|
||||
{{:error message="Impossible de trouver l'écriture au crédit du compte de l'immobilisation de la ligne « %s »"|args:$ligne_immo.trans_label}}
|
||||
{{/select}}
|
||||
{{:assign credit_trans_url="%s/acc/transactions/details.php?id=%s"|args:$admin_url:$credit_line.credit_trans_id}}
|
||||
|
||||
{{:assign montant_affecte=0}}
|
||||
{{#load type="immo_link" assign="linked_immo."
|
||||
where="$$.credit_line_id = :credit_line_id"
|
||||
:credit_line_id = $_GET.credit_line_id|intval
|
||||
}}
|
||||
{{:assign montant_affecte="%d+%d"|math:$montant_affecte:$amount}}
|
||||
{{/load}}
|
||||
{{:assign reste="%d-%d"|math:$credit_line.amount:$montant_affecte}}
|
||||
|
||||
{{* Traiter l'envoi du formulaire *}}
|
||||
{{#form on="save"}}
|
||||
{{* vérifier que le montant est inférieur au reste *}}
|
||||
{{if $_POST.montant == null}}
|
||||
{{:assign montant_credit=null}}
|
||||
{{else}}
|
||||
{{:assign montant_credit=$_POST.montant|floatval}}
|
||||
{{:assign montant_credit="%f*100"|math:$montant_credit}}
|
||||
{{if $montant_credit > $reste}}
|
||||
{{:assign reste_nb="%f"|math:$reste|money_currency:false}}
|
||||
{{:error message="Le montant de l'avoir ne peut être supérieur au reste (%s)"|args:$reste_nb}}
|
||||
{{/if}}
|
||||
{{/if}}
|
||||
|
||||
{{* chercher les liaisons de l'écriture d'immobilisation *}}
|
||||
{{#select
|
||||
CASE links.id_related = :immo_trans_id
|
||||
WHEN true THEN links.id_transaction
|
||||
WHEN false THEN links.id_related
|
||||
END as linked_id
|
||||
FROM acc_transactions_links as links
|
||||
WHERE id_transaction = :immo_trans_id or id_related = :immo_trans_id;
|
||||
:immo_trans_id = $ligne_immo.immo_trans_id
|
||||
}}
|
||||
{{:assign var="linked_transactions." value=$linked_id}}
|
||||
{{/select}}
|
||||
|
||||
{{* ajouter la nouvelle liaison *}}
|
||||
{{:assign var="linked_transactions." value=$credit_line.credit_trans_id}}
|
||||
|
||||
{{* Enregistrer les liaisons *}}
|
||||
{{:api
|
||||
method="POST"
|
||||
path="accounting/transaction/%s/transactions"|args:$ligne_immo.immo_trans_id
|
||||
assign="result"
|
||||
assign_code="result_code"
|
||||
transactions=$linked_transactions
|
||||
}}
|
||||
|
||||
{{*
|
||||
TODO ? vérifier le succès avant d'enregistrer le doc ?
|
||||
*}}
|
||||
|
||||
{{* enregistrer la liaison des lignes d'immo *}}
|
||||
{{:save
|
||||
key=""|uuid
|
||||
type="immo_link"
|
||||
immo_doc_id=$_GET.immo_doc_id|intval
|
||||
credit_line_id=$_GET.credit_line_id|intval
|
||||
amount=$montant_credit|intval
|
||||
}}
|
||||
|
||||
{{:redirect force="details_immo.html?immo_doc_id=%s&ok=1&msg=attach_immo"|args:$_GET.immo_doc_id}}
|
||||
{{/form}}
|
||||
|
||||
{{if ! $dialog}}
|
||||
{{:include
|
||||
file="_nav.html"
|
||||
current="config"
|
||||
subcurrent="other"
|
||||
subsubcurrent="immo"
|
||||
type_immo="other"
|
||||
}}
|
||||
{{/if}}
|
||||
{{:form_errors}}
|
||||
|
||||
<div class="informations">
|
||||
<dl class="describe">
|
||||
<dt>Immobilisation</dt>
|
||||
<dd>{{$label_immo}}</dd>
|
||||
<dt>Écriture au crédit du compte d'immobilisation</dt>
|
||||
<dd><span class="num"><a href="{{$credit_trans_url}}">#{{$credit_line.credit_trans_id}}</a></span> {{$credit_line.trans_label}}{{if $credit_line.line_label != null && $credit_line.line_label != $credit_line.trans_label}} — {{$credit_line.line_label}}{{/if}}</dd>
|
||||
<dt>Montant de l'écriture</dt>
|
||||
<dd>{{$credit_line.amount|money_currency_html:false|raw}}</dd>
|
||||
<dt>Montant déjà affecté</dt>
|
||||
<dd class="money strong">{{"%f"|math:$montant_affecte|money_currency_html:false|raw}}</dd>
|
||||
<dt>Montant restant à affecter</dt>
|
||||
<dd class="money strong">{{"%f"|math:$reste|money_currency_html:false|raw}}</dd>
|
||||
</dl>
|
||||
</div>
|
||||
|
||||
<form method="post" action="" data-focus="1">
|
||||
<fieldset>
|
||||
<dl>
|
||||
{{:input type="money" name="montant" label="Montant" help="Montant de l'avoir ; à renseigner uniquement si différent du montant de l'écriture"}}
|
||||
</dl>
|
||||
</fieldset>
|
||||
<p class="submit">
|
||||
{{:button type="submit" name="save" label="Enregistrer" shape="right" class="main"}}
|
||||
</p>
|
||||
</form>
|
||||
|
||||
159
details_immo.html
Normal file
159
details_immo.html
Normal file
|
|
@ -0,0 +1,159 @@
|
|||
{{* -*- brindille -*- *}}
|
||||
|
||||
{{:admin_header title="Détails de l'immobilisation" custom_css="./style.css" current="module_amortization"}}
|
||||
|
||||
{{*
|
||||
Afficher les détails d'une immmo
|
||||
- permettre l'association d'une immo au crédit du compte de l'immo
|
||||
- permettre de modifier les paramètres de l'immo
|
||||
@param (OBSOLÈTE ?) immo_line_id : numéro de ligne de l'écriture d'immobilisation
|
||||
@param immo_doc_id : numéro du doc d'immo
|
||||
*}}
|
||||
|
||||
{{*
|
||||
TODO : permettre la modification des param (en cas d'erreur de saisie)
|
||||
TODO : permettre de corriger le montant de l'amort et/ou de supprimer l'attachement
|
||||
FAIT : déduire montant au crédit de la ligne d'immo
|
||||
*}}
|
||||
|
||||
{{* données de l'immobilisation *}}
|
||||
{{#load type="immo" id=$_GET.immo_doc_id|intval assign="info_immo"}}
|
||||
{{else}}
|
||||
{{:error message="Immobilisation non trouvée"}}
|
||||
{{/load}}
|
||||
|
||||
{{#select
|
||||
trans.id as immo_trans_id,
|
||||
trans.label as label,
|
||||
trans.date as date_achat,
|
||||
line.id as immo_line_id,
|
||||
line.debit as montant,
|
||||
line.label as line_label,
|
||||
account.code as account_code,
|
||||
account.label as account_label
|
||||
FROM acc_transactions_lines AS line
|
||||
INNER join acc_transactions AS trans ON line.id_transaction = trans.id
|
||||
INNER JOIN acc_accounts AS account ON line.id_account = account.id
|
||||
WHERE line.id = :line_id;
|
||||
:line_id = $info_immo.line
|
||||
assign="ligne_immo"
|
||||
}}
|
||||
{{else}}
|
||||
{{:error message="Immobilisation non trouvée"}}
|
||||
{{/select}}
|
||||
|
||||
{{:assign var="info_immo.amount" value=$info_immo.amount|or:$ligne_immo.montant}}
|
||||
{{:assign var="info_immo.date_achat" value=$info_immo.date_achat|or:$ligne_immo.date_achat}}
|
||||
{{:assign var="info_immo.date_mes" value=$info_immo.date_mes|or:$ligne_immo.date_achat}}
|
||||
{{:assign var="info_immo.label" value=$info_immo.label|or:$ligne_immo.label}}
|
||||
{{if $ligne_immo.line_label != null && $ligne_immo.line_label != $info_immo.label}}
|
||||
{{:assign var="info_immo.label" value=$info_immo.label|cat:" — "|cat:$ligne_immo.line_label}}
|
||||
{{/if}}
|
||||
|
||||
{{*
|
||||
chercher des écritures liées à l'immo courante au crédit du même compte
|
||||
et déduire leur montant de celui de l'immo
|
||||
*}}
|
||||
{{:assign linked_immos=null}}
|
||||
{{:assign total_credits=0}}
|
||||
{{#load type="immo_link" where="$$.immo_doc_id=:immo_doc_id" :immo_doc_id=$_GET.immo_doc_id|intval}}
|
||||
{{#select
|
||||
line.credit,
|
||||
trans.id
|
||||
FROM acc_transactions_lines AS line
|
||||
INNER JOIN acc_transactions AS trans ON line.id_transaction = trans.id
|
||||
WHERE line.id = :credit_line_id;
|
||||
:credit_line_id=$credit_line_id
|
||||
}}
|
||||
{{:assign credit=$credit}}
|
||||
{{:assign credit_trans_id=$id}}
|
||||
{{/select}}
|
||||
{{:assign var="linked_immos." value=$credit_trans_id}}
|
||||
{{if $amount == null}}
|
||||
{{:assign total_credits="%d+%d"|math:$total_credits:$credit}}
|
||||
{{else}}
|
||||
{{:assign total_credits="%d+%d"|math:$total_credits:$amount}}
|
||||
{{/if}}
|
||||
{{/load}}
|
||||
{{:assign solde="%d-%d"|math:$info_immo.amount:$total_credits}}
|
||||
|
||||
{{:assign total_amort=0}}
|
||||
{{* lister les docs d'amortissement liées à la ligne d'immobilisation *}}
|
||||
{{#load type="amort_link"
|
||||
where="$$.immo_doc_id = :immo_doc_id"
|
||||
:immo_doc_id=$_GET.immo_doc_id|intval
|
||||
}}
|
||||
{{if $amount != null}}
|
||||
{{:assign total_amort="%d+%d"|math:$total_amort:$amount}}
|
||||
{{else}}
|
||||
{{#select credit FROM acc_transactions_lines WHERE id = :amort_line_id;
|
||||
:amort_line_id=$amort_line_id
|
||||
}}
|
||||
{{:assign total_amort="%d+%d"|math:$total_amort:$credit}}
|
||||
{{/select}}
|
||||
{{/if}}
|
||||
{{/load}}
|
||||
|
||||
{{* barre de navigation *}}
|
||||
{{if ! $dialog}}
|
||||
{{if $total_credits == 0 && $total_amort == 0}}
|
||||
{{:assign subsubcurrent="credit"}}
|
||||
{{else}}
|
||||
{{:assign subsubcurrent=null}}
|
||||
{{/if}}
|
||||
{{:include file="_nav.html" current="index" subcurrent="details" subsubcurrent=$subsubcurrent}}
|
||||
{{/if}}
|
||||
{{:assign trans_url="%s/acc/transactions/details.php?id=%s"|args:$admin_url:$ligne_immo.immo_trans_id}}
|
||||
|
||||
{{if $_GET.ok}}
|
||||
{{if $_GET.msg|match:"attach_amort"}}
|
||||
{{:assign msg="Attachement amortissement effectué"}}
|
||||
{{elseif $_GET.msg|match:"attach_immo"}}
|
||||
{{:assign msg="Attachement avoir effectué"}}
|
||||
{{elseif $_GET.msg|match:"info"}}
|
||||
{{:assign msg="Données de l'immobilisation enregistrées"}}
|
||||
{{/if}}
|
||||
<p class="block confirm">{{$msg}}</p>
|
||||
{{elseif $_GET.err}}
|
||||
{{:assign msg="L'opération a échoué"}}
|
||||
<p class="block error">{{$msg}}</p>
|
||||
{{/if}}
|
||||
|
||||
<h3 class="ruler">
|
||||
Paramètres de l'immobilisation
|
||||
<span class="num"><a href="{{$trans_url}}">#{{$ligne_immo.immo_trans_id}}</a></span>
|
||||
</h3>
|
||||
<div class="informations">
|
||||
<dl class="describe">
|
||||
<dt>Immobilisation</dt>
|
||||
<dd><span class="num"><a href="{{$trans_url}}">#{{$ligne_immo.immo_trans_id}}</a></span> {{$info_immo.label}}</dd>
|
||||
<dt>Compte d'immobilisation</dt>
|
||||
<dd>{{$ligne_immo.account_code}} — {{$ligne_immo.account_label}}</dd>
|
||||
<dt>Montant de l'immobilisation</dt>
|
||||
<dd class="money strong">{{"%f"|math:$info_immo.amount|money_currency_html:false|raw}}</dd>
|
||||
{{if $total_credits > 0}}
|
||||
<dt>Montant des avoirs</dt>
|
||||
<dd class="money">{{"%f"|math:$total_credits|money_currency_html:false|raw}}</dd>
|
||||
<dt>Écritures d'avoir</dt>
|
||||
<dd>
|
||||
{{#foreach from=$linked_immos item="id"}}
|
||||
{{:assign url="%s/acc/transactions/details.php?id=%s"|args:$admin_url:$id}}
|
||||
<span class="num"><a href="{{$url}}">#{{$id}}</a></span>
|
||||
{{/foreach}}
|
||||
{{*:debug linked_immos=$linked_immos*}}
|
||||
</dd>
|
||||
<dt>Montant à amortir</dt>
|
||||
<dd class="money strong">{{"%f"|math:$solde|money_currency_html:false|raw}}</dd>
|
||||
{{/if}}
|
||||
<dt>Date d'acquisition</dt>
|
||||
<dd>{{$info_immo.date_achat|date_short}}</dd>
|
||||
{{if $info_immo.date_mes != null && $info_immo.date_mes != $info_immo.date_achat}}
|
||||
<dt>Date de mise en service</dt>
|
||||
<dd>{{$info_immo.date_mes|date_short}}</dd>
|
||||
{{/if}}
|
||||
<dt>Durée d'amortissement</dt>
|
||||
<dd>{{$info_immo.duration}} ans</dd>
|
||||
<dt>Montant des amortissements</dt>
|
||||
<dd>{{$total_amort|money_currency_html:false|raw}}</dd>
|
||||
</dl>
|
||||
</div>
|
||||
142
link_immo.html
Normal file
142
link_immo.html
Normal file
|
|
@ -0,0 +1,142 @@
|
|||
{{* -*- brindille -*- *}}
|
||||
|
||||
{{*
|
||||
Lister les écritures au crédit du compte de l'immobilisation
|
||||
paramètre et proposer de les attacher à l'immo paramètre
|
||||
@param immo_doc_id : document associé à l'immo
|
||||
*}}
|
||||
|
||||
{{#load id=$_GET.immo_doc_id|intval assign="info_immo"}}
|
||||
{{else}}
|
||||
{{:error message="Informations de l'immobilisation non trouvées"}}
|
||||
{{/load}}
|
||||
|
||||
{{* récupérer les infos de l'immobilisation *}}
|
||||
{{#select
|
||||
trans.id as immo_trans_id,
|
||||
trans.label as label,
|
||||
trans.date as date_achat,
|
||||
line.id as immo_line_id,
|
||||
line.label as line_label,
|
||||
line.debit as montant,
|
||||
account.code as account_code
|
||||
FROM acc_transactions_lines AS line
|
||||
INNER JOIN acc_transactions AS trans ON line.id_transaction = trans.id
|
||||
INNER JOIN acc_accounts AS account ON line.id_account = account.id
|
||||
WHERE line.id = :line_id;
|
||||
:line_id = $info_immo.line
|
||||
assign="ligne_immo"
|
||||
}}
|
||||
{{else}}
|
||||
{{:error message="Immobilisation « %s » non trouvée"|args:$info_immo.line}}
|
||||
{{/select}}
|
||||
{{:assign trans_url="%s/acc/transactions/details.php?id=%s"|args:$admin_url:$ligne_immo.immo_trans_id}}
|
||||
{{:assign label_immo=$ligne_immo.label}}
|
||||
{{if $ligne_immo.line_label != null && $ligne_immo.line_label != $label_immo}}
|
||||
{{:assign label_immo=$label_immo|cat:" — "|cat:$ligne_immo.line_label}}
|
||||
{{/if}}
|
||||
|
||||
{{*
|
||||
lister les écritures au crédit du compte de l'immobilisation
|
||||
variante : utiliser une jointure ; pas forcément plus efficace
|
||||
*}}
|
||||
{{#select
|
||||
line.id as credit_line_id,
|
||||
line.id_transaction as credit_trans_id,
|
||||
line.credit as credit_amount,
|
||||
line.label as line_label,
|
||||
trans.id as immo_trans_id,
|
||||
trans.date as trans_date,
|
||||
trans.label as trans_label,
|
||||
trans.id_year as credit_year,
|
||||
account.id as account_id,
|
||||
account.code as account_code,
|
||||
account.label as account_label
|
||||
FROM acc_transactions_lines AS line
|
||||
INNER JOIN acc_transactions AS trans ON trans.id = line.id_transaction
|
||||
INNER JOIN acc_accounts AS account ON account.id = line.id_account
|
||||
INNER JOIN acc_years AS y ON y.id = trans.id_year
|
||||
WHERE account.code = :account_code AND credit > 0
|
||||
AND credit_trans_id NOT IN (
|
||||
SELECT
|
||||
CASE WHEN id_transaction = credit_trans_id THEN id_transaction
|
||||
ELSE id_related
|
||||
END AS other_id
|
||||
FROM acc_transactions_links WHERE other_id = credit_trans_id)
|
||||
ORDER BY trans.date, trans.label;
|
||||
:account_code = $ligne_immo.account_code
|
||||
assign="other_immos."
|
||||
}}
|
||||
{{/select}}
|
||||
|
||||
{{:admin_header title="Écritures au crédit du compte d'immobilisation" custom_css="./style.css" current="module_amortization"}}
|
||||
|
||||
{{* barre de navigation *}}
|
||||
{{if ! $dialog}}
|
||||
{{:include
|
||||
file="_nav.html"
|
||||
current="config"
|
||||
subcurrent="other"
|
||||
subsubcurrent="immo"
|
||||
type_immo="other"
|
||||
}}
|
||||
{{/if}}
|
||||
|
||||
<section class="immobilisation">
|
||||
<fieldset>
|
||||
<legend>
|
||||
Écritures au crédit du compte d'immobilisation « {{$ligne_immo.account_code}} »
|
||||
</legend>
|
||||
|
||||
<div class="informations">
|
||||
<dl class="describe">
|
||||
<dt>Immobilisation</dt>
|
||||
<dd><span class="num"><a href="{{$trans_url}}">#{{$ligne_immo.immo_trans_id}}</a></span> {{$label_immo}}</dd>
|
||||
<dt>Montant</dt>
|
||||
<dd class="money strong">{{"%f"|math:$ligne_immo.montant|money_currency_html:false|raw}}</dd>
|
||||
<dt>Date de l'écriture d'immobilisation</dt>
|
||||
<dd>{{$ligne_immo.date_achat|date_short}}</dd>
|
||||
</dl>
|
||||
</div>
|
||||
</fieldset>
|
||||
|
||||
{{if $other_immos != null}}
|
||||
<table class="list">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>N°</th>
|
||||
<th>Date</th>
|
||||
<th class="nombre">Montant</th>
|
||||
<th>Libellé</th>
|
||||
<th>N° compte</th>
|
||||
<th>Compte</th>
|
||||
<th class="actions"></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{{#foreach from=$other_immos item="line"}}
|
||||
{{:assign trans_url="%s/acc/transactions/details.php?id=%s"|args:$admin_url:$line.credit_trans_id}}
|
||||
{{:assign compte_url="%s/acc/accounts/journal.php?id=%s&year=%s"|args:$admin_url:$line.account_id:$line.credit_year}}
|
||||
<tr>
|
||||
<td class="num"><a href="{{$trans_url}}">#{{$line.credit_trans_id}}</a></td>
|
||||
<td>{{$line.trans_date|date_short}}</td>
|
||||
<td class="money">{{"%f"|math:$line.credit_amount|money_html:false|raw}}</td>
|
||||
<td>{{$line.trans_label}}
|
||||
{{if $line.line_label != null && $line.line_label != $line.trans_label}} - {{$line.line_label}}{{/if}}
|
||||
</td>
|
||||
<td><a href="{{$compte_url}}">{{$line.account_code}}</a></td>
|
||||
<td>{{$line.account_label}}</td>
|
||||
<td>
|
||||
{{:linkbutton label="Attacher" href="attach_immo.html?credit_line_id=%d&immo_doc_id=%s"|args:$line.credit_line_id:$_GET.immo_doc_id shape="plus"}}
|
||||
</td>
|
||||
</tr>
|
||||
{{/foreach}}
|
||||
</tbody>
|
||||
</table>
|
||||
<p class="help">Sélectionner une écriture d'avoir ou autre réduction du montant de l'acquisition pour l'associer à l'immobilisation</p>
|
||||
{{else}}
|
||||
<p class="block alert">Aucune écriture au crédit du compte « {{$ligne_immo.account_code}} »</p>
|
||||
{{/if}}
|
||||
</section>
|
||||
{{:form_errors}}
|
||||
{{:admin_footer}}
|
||||
Loading…
Add table
Add a link
Reference in a new issue