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>
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue