Prise en compte écritures BOI avec montant immo subdivisé
This commit is contained in:
parent
f8f4da59b6
commit
d5c62b6ef3
4 changed files with 329 additions and 319 deletions
253
add_infos.html
253
add_infos.html
|
|
@ -3,140 +3,137 @@
|
|||
{{*
|
||||
@param immo_line_id
|
||||
@param type_immo : managed, amortized, archived, other
|
||||
|
||||
TODO :
|
||||
- séparer les cas des immo simples et complexes (BOI)
|
||||
par exemple pour la durée d'amort par défaut {{:input ...}}
|
||||
- prise en charge immo => param = immo_line_id
|
||||
- modif param immo => param = immo_doc_id
|
||||
*}}
|
||||
|
||||
{{* données de l'immobilisaion *}}
|
||||
{{#load type="immo" assign="info_immo" where="$$.line = :line_id" :line_id=$_GET.immo_line_id|intval}}
|
||||
{{* cas de la prise en charge *}}
|
||||
{{* données de l'immobilisation *}}
|
||||
{{:assign montant_affecte=0}}
|
||||
{{#load type="immo" where="$$.line = :line_id" :line_id=$_GET.immo_line_id|intval assign="info_immo"}}
|
||||
{{:assign montant_affecte="%d+%d"|math:$montant_affecte:$amount}}
|
||||
{{/load}}
|
||||
|
||||
{{#select
|
||||
trans.id as immo_trans_id,
|
||||
trans.label,
|
||||
trans.label as trans_label,
|
||||
trans.date as date_achat,
|
||||
line.debit as montant,
|
||||
line.label as line_label,
|
||||
acc.code
|
||||
acc.code,
|
||||
acc.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 acc ON line.id_account = acc.id
|
||||
WHERE line.id = :line_id;
|
||||
:line_id = $_GET.immo_line_id
|
||||
assign=ligne_immo
|
||||
:line_id = $_GET.immo_line_id|intval
|
||||
assign="ligne_immo"
|
||||
}}
|
||||
{{else}}
|
||||
{{:error message="Aucune immobilisation trouvée"}}
|
||||
{{:error message="Immobilisation non trouvée"}}
|
||||
{{/select}}
|
||||
|
||||
{{* 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,
|
||||
acc.code
|
||||
FROM acc_transactions_links as links
|
||||
INNER JOIN acc_transactions_lines AS line on line.id_transaction = linked_id
|
||||
INNER JOIN acc_accounts AS acc ON line.id_account = acc.id
|
||||
WHERE (links.id_transaction = :immo_trans_id or links.id_related = :immo_trans_id)
|
||||
AND line.credit > 0
|
||||
;
|
||||
:immo_trans_id = $ligne_immo.immo_trans_id
|
||||
}}
|
||||
{{:assign var="linked_transactions.%d."|args:$code value=$linked_id}}
|
||||
{{/select}}
|
||||
{{:assign var="immo_transactions" from="linked_transactions.%d"|args:$ligne_immo.code}}
|
||||
{{:assign reste="%d-%d"|math:$ligne_immo.montant:$montant_affecte}}
|
||||
{{*
|
||||
{{if $info_immo != null}}
|
||||
{{:assign date_defaut=$info_immo.date}}
|
||||
{{:assign duree_defaut=$info_immo.duration}}
|
||||
{{:assign choix_defaut=$info_immo.status}}
|
||||
{{else}}
|
||||
{{:assign duree_defaut=null}}
|
||||
{{/if}}
|
||||
*}}
|
||||
|
||||
{{* Traiter l'envoi du formulaire *}}
|
||||
{{#form on="save"}}
|
||||
{{if $_POST.classify == null}}
|
||||
{{:error message="Vous devez choisir une action"}}
|
||||
{{/if}}
|
||||
|
||||
{{if $_POST.classify == "ignored"}}
|
||||
{{if ! $_POST.amortir}}
|
||||
{{* ne pas amortir *}}
|
||||
{{:assign duration=0}}
|
||||
{{:assign date_debut=$ligne_immo.date_achat|parse_date}}
|
||||
{{:assign libelle=null}}
|
||||
{{:assign montant=null}}
|
||||
{{:assign date_achat=null}}
|
||||
{{:assign date_mes=null}}
|
||||
{{:assign status="ignored"}}
|
||||
{{else}}
|
||||
{{* vérifier que la date d'acquisition est antérieure à la date de mise en service *}}
|
||||
{{:assign date_debut=$_POST.date_mes|or:$ligne_immo.date_achat|parse_date}}
|
||||
{{if $date_debut|strtotime < $ligne_immo.date_achat|strtotime}}
|
||||
{{:assign dd=$date_debut|date_short}}
|
||||
{{:assign da=$ligne_immo.date_achat|date_short}}
|
||||
{{:error message="Erreur : la date de mise en service (%s) ne peut être antérieure à la date d'acquisition (%s)"|args:$dd:$da}}
|
||||
|
||||
{{* vérifier que la date de mise en service est postérieure à la date d'acquisition *}}
|
||||
{{:assign d1=$_POST.date_achat|or:$ligne_immo.date_achat|parse_date}}
|
||||
{{:assign d2=$_POST.date_mes|or:$d1|parse_date}}
|
||||
{{if $d2 < $d1}}
|
||||
{{:assign da=$d1|date_short}}
|
||||
{{:error message="Erreur : la date de mise en service (%s) ne peut être antérieure à la date d'acquisition (%s)"|args:$_POST.date_mes:$da}}
|
||||
{{/if}}
|
||||
|
||||
{{if $_POST.classify == "amortized"}}
|
||||
{{if $info_immo.duration == null}}
|
||||
{{:assign duration=0}}
|
||||
{{else}}
|
||||
{{:assign duration=$info_immo.duration}}
|
||||
{{/if}}
|
||||
{{:assign status="amortized"}}
|
||||
{{elseif $_POST.classify == "archived"}}
|
||||
{{if $info_immo.duration == null}}
|
||||
{{:assign duration=0}}
|
||||
{{else}}
|
||||
{{:assign duration=$info_immo.duration}}
|
||||
{{/if}}
|
||||
{{:assign status="archived"}}
|
||||
{{else}}
|
||||
{{:assign duration=$_POST.duree|intval}}
|
||||
{{if $duration <= 0}}
|
||||
{{:error message="Erreur : la durée d'amortissement doit être strictement positive"}}
|
||||
{{/if}}
|
||||
{{:assign status="managed"}}
|
||||
{{:assign duration=$_POST.duree|intval}}
|
||||
{{if $duration <= 0}}
|
||||
{{:error message="Erreur : la durée d'amortissement doit être strictement positive"}}
|
||||
{{/if}}
|
||||
|
||||
{{if $_POST.libelle != $ligne_immo.line_label && $_POST.libelle != $ligne_immo.trans_label}}
|
||||
{{:assign libelle=$_POST.libelle}}
|
||||
{{/if}}
|
||||
|
||||
{{if $_POST.montant == null || $_POST.montant|intval == 0 }}
|
||||
{{if $montant_affecte > 0}}
|
||||
{{:assign montant=$reste}}
|
||||
{{else}}
|
||||
{{:assign montant=null}}
|
||||
{{/if}}
|
||||
{{else}}
|
||||
{{:assign montant=$_POST.montant|intval}}
|
||||
{{:assign montant="%d*100"|math:$montant}}
|
||||
{{if $montant == $reste}}
|
||||
{{:assign montant=null}}
|
||||
{{/if}}
|
||||
{{/if}}
|
||||
{{if $montant > $reste}}
|
||||
{{:assign reste_nb="%f"|math:$reste|money_currency:false}}
|
||||
{{:assign montant_nb="%f"|math:$montant|money_currency:false}}
|
||||
{{:error message="Le montant (%s) ne peut être supérieur au reste (%s)"|args:$montant_nb:$reste_nb}}
|
||||
{{/if}}
|
||||
|
||||
{{if $_POST.date_achat == null || $_POST.date_achat|parse_date == $ligne_immo.date_achat}}
|
||||
{{:assign date_achat=null}}
|
||||
{{else}}
|
||||
{{:assign date_achat=$_POST.date_achat|parse_date}}
|
||||
{{/if}}
|
||||
|
||||
{{if $_POST.date_mes == null || $_POST.date_mes == $_POST.date_achat || $_POST.date_mes|parse_date == $ligne_immo.date_achat}}
|
||||
{{:assign date_mes=null}}
|
||||
{{else}}
|
||||
{{:assign date_mes=$_POST.date_mes|parse_date}}
|
||||
{{/if}}
|
||||
{{:assign status="managed"}}
|
||||
{{/if}}
|
||||
|
||||
{{* enregistrer les infos de l'immobilisation *}}
|
||||
{{if $info_immo == null}}
|
||||
{{if $info_immo == null || $montant_affecte > 0}}
|
||||
{{:assign key=""|uuid}}
|
||||
{{else}}
|
||||
{{:assign key=$info_immo.key}}
|
||||
{{/if}}
|
||||
|
||||
{{:save
|
||||
key=$key
|
||||
validate_schema="schema.json"
|
||||
type="immo"
|
||||
line=$_GET.immo_line_id|intval
|
||||
duration=$duration
|
||||
date=$date_debut
|
||||
label=$libelle
|
||||
amount=$montant
|
||||
date_achat=$date_achat
|
||||
date_mes=$date_mes
|
||||
status=$status
|
||||
assign_new_id="new_id"
|
||||
}}
|
||||
|
||||
{{* copier les autres liaisons *}}
|
||||
{{#foreach from=$linked_transactions key="code" item="liaisons"}}
|
||||
{{if $code != $ligne_immo.code}}
|
||||
{{:debug code=$code liaisons=$liaisons}}
|
||||
{{#foreach from=$liaisons item="elem"}}
|
||||
{{:assign var="new_transactions." value=$elem}}
|
||||
{{/foreach}}
|
||||
{{/if}}
|
||||
{{/foreach}}
|
||||
|
||||
{{* nouvelles liaisons *}}
|
||||
{{#foreach from=$_POST.transactions key="key" item="elem"}}
|
||||
{{:assign var="new_transactions." value=$elem|intval}}
|
||||
{{/foreach}}
|
||||
|
||||
{{* Enregistrer les liaisons *}}
|
||||
{{if $new_transactions != null}}
|
||||
{{:api
|
||||
method="POST"
|
||||
path="accounting/transaction/%s/transactions"|args:$ligne_immo.immo_trans_id
|
||||
assign="result"
|
||||
assign_code="result_code"
|
||||
transactions=$new_transactions
|
||||
}}
|
||||
{{/if}}
|
||||
|
||||
{{if $_POST.classify == "managed" || $_POST.classify == "amortized"}}
|
||||
{{:assign type_immo=$_POST.classify}}
|
||||
{{elseif $_POST.classify == "ignored"}}
|
||||
{{:assign type_immo="other"}}
|
||||
{{if $_POST.amortir}}
|
||||
{{:assign type_immo="managed"}}
|
||||
{{else}}
|
||||
{{:assign type_immo=$_GET.type_immo}}
|
||||
{{:assign type_immo="other"}}
|
||||
{{/if}}
|
||||
{{:redirect force="index.html?ok=1&msg=infos&type_immo=%s"|args:$type_immo}}
|
||||
{{/form}}
|
||||
|
|
@ -151,53 +148,46 @@
|
|||
|
||||
{{:assign choix_defaut=$_GET.type_immo}}
|
||||
|
||||
{{if $info_immo != null}}
|
||||
{{:assign date_defaut=$info_immo.date}}
|
||||
{{:assign duree_defaut=$info_immo.duration}}
|
||||
{{:assign choix_defaut=$info_immo.status}}
|
||||
{{else}}
|
||||
{{:assign duree_defaut=null}}
|
||||
{{/if}}
|
||||
|
||||
{{*
|
||||
- classer l'immobilisation
|
||||
- renseigner ou modifier la date de mise en service, les écritures associées ou la durée d'amortissement
|
||||
*}}
|
||||
|
||||
{{:assign trans_url="%s/acc/transactions/details.php?id=%s"|args:$admin_url:$ligne_immo.immo_trans_id}}
|
||||
<h3 class="ruler">
|
||||
Paramètres de l'immobilisation
|
||||
<span class="num"><a href="{{$trans_url}}">#{{$ligne_immo.immo_trans_id}}</a></span>
|
||||
</h3>
|
||||
<h3 class="ruler">Paramètres de l'immobilisation</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> {{$ligne_immo.label}}{{if $ligne_immo.line_label != null && $ligne_immo.line_label != $ligne_immo.label}} — {{$ligne_immo.line_label}}{{/if}}</dd>
|
||||
<dd><span class="num"><a href="{{$trans_url}}">#{{$ligne_immo.immo_trans_id}}</a></span> {{$ligne_immo.trans_label}}{{if $ligne_immo.line_label != null && $ligne_immo.line_label != $ligne_immo.trans_label}} — {{$ligne_immo.line_label}}{{/if}}</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>
|
||||
<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> <dt>Date de l'écriture d'immobilisation</dt>
|
||||
<dd>{{$ligne_immo.date_achat|date_short}}</dd>
|
||||
<dt>Compte d'immobilisation</dt>
|
||||
<dd>{{$ligne_immo.code}} — {{$ligne_immo.account_label}}
|
||||
</dl>
|
||||
</div>
|
||||
|
||||
<form method="post" action="">
|
||||
<fieldset>
|
||||
<legend>Classement</legend>
|
||||
<dl id="classement_immo">
|
||||
<dt><label>Faites un choix</label> <b>(obligatoire)</b></dt>
|
||||
{{:input type="radio-btn" name="classify" value="managed" label="Immobilisation à amortir" help="Cette immobilisation sera classée parmi les immobilisations amortissables" default=$choix_defaut}}
|
||||
{{:input type="radio-btn" name="classify" value="amortized" label="Amortissement terminé" help="Cette immobilisation sera classée parmi les immobilisations amorties" default=$choix_defaut}}
|
||||
{{:input type="radio-btn" name="classify" value="archived" label="Immobilisation sortie du bilan" help="Cette immobilisation sera classée parmi les immobilisations sorties du bilan" default=$choix_defaut}}
|
||||
{{:input type="radio-btn" name="classify" value="ignored" label="Immobilisation à ignorer" help="Cette écriture n'apparaitra plus dans la liste des immobilisations" default=$choix_defaut}}
|
||||
</dl>
|
||||
</fieldset>
|
||||
|
||||
<fieldset id="infos_immo">
|
||||
<legend>Informations</legend>
|
||||
<legend>Amortissement</legend>
|
||||
<dl>
|
||||
{{:input type="number" name="duree" label="Durée d'amortissement" default=$duree_defaut required=true min=1}}
|
||||
{{:input type="list" name="transactions" default=$immo_transactions label="Écritures liées au crédit du compte d'immobilisation" target="!acc/transactions/selector.php" multiple=true help="par exemple écriture d'avoir ou autre réduction du montant de l'acquisition"}}
|
||||
{{:input type="date" name="date_mes" label="Date de mise en service" default=$date_defaut help="à renseigner uniquement si différente de la date d'acquisition"}}
|
||||
{{:input id="amortir" type="checkbox" value=1 name="amortir" label="Amortir cette immobilisation sur une ou plusieurs années" checked="checked" help="Dé-cocher pour ne pas amortir"}}
|
||||
<div class="masquable">
|
||||
{{:input type="number" name="duree" label="Durée d'amortissement" required=true min=1}}
|
||||
</div>
|
||||
</dl>
|
||||
</fieldset>
|
||||
<fieldset class="masquable">
|
||||
<legend>Informations facultatives</legend>
|
||||
<dl>
|
||||
{{:input type="date" name="date_achat" label="Date d'acquisition" help="à renseigner uniquement si différente de la date de l'écriture d'immobilisation"}}
|
||||
{{:input type="date" name="date_mes" label="Date de mise en service" help="à renseigner uniquement si différente de la date d'acquisition"}}
|
||||
{{:input type="text" name="libelle" label="Libellé" help="à renseigner uniquement si différent du libellé de l'écriture d'immobilisation"}}
|
||||
{{:input type="money" name="montant" label="Montant de l'immobilisation" default=$reste}}
|
||||
</dl>
|
||||
</fieldset>
|
||||
|
||||
|
|
@ -209,29 +199,16 @@
|
|||
|
||||
{{:admin_footer}}
|
||||
|
||||
<script type="text/javascript" src="scripts.js"></script>
|
||||
<script type="text/javascript">
|
||||
var info_immo = {{$info_immo|json_encode|raw}};
|
||||
|
||||
// afficher/masquer les champs de saisie
|
||||
function toggleInputs(event) {
|
||||
const classement_immo = document.getElementById('classement_immo');
|
||||
const managed = classement_immo.querySelector('input[type=radio][value=managed]');
|
||||
const amortized = classement_immo.querySelector('input[type=radio][value=amortized]');
|
||||
if (managed.checked) {
|
||||
g.toggle('#infos_immo', true);
|
||||
} else if (amortized.checked && info_immo != null && info_immo.duration != 0) {
|
||||
g.toggle('#infos_immo', true);
|
||||
} else {
|
||||
g.toggle('#infos_immo', false);
|
||||
}
|
||||
function changeVisibility(evt, idcheck = 'f_amortir_1', hiddenclass = 'masquable')
|
||||
{
|
||||
toggleVisibility(idcheck, document.querySelectorAll('.' + hiddenclass));
|
||||
}
|
||||
toggleInputs();
|
||||
|
||||
(function () {
|
||||
const radios = document.querySelectorAll('input[name="classify"]');
|
||||
radios.forEach(radio => {
|
||||
radio.addEventListener("change", toggleInputs);
|
||||
});
|
||||
document.getElementById('f_amortir_1').onclick = changeVisibility;
|
||||
})();
|
||||
|
||||
</script>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue