ajout immo : Choisir exercice avant date d'achat
This commit is contained in:
parent
673003ea77
commit
9f8660a51f
2 changed files with 33 additions and 76 deletions
|
@ -4,23 +4,34 @@
|
|||
{{:assign config_defaut=$config_json|json_decode}}
|
||||
{{:assign var="prefix_array" value=$config_defaut.prefixes|keys}}
|
||||
|
||||
{{#years closed=false order="start_date" assign=years.}}
|
||||
{{:assign ts_debut=$start_date|strtotime}}
|
||||
{{:assign ts_fin=$end_date|strtotime}}
|
||||
{{:assign debut=$start_date|date_short}}
|
||||
{{:assign fin=$end_date|date_short}}
|
||||
{{:assign var="years_data.%d"|args:$id value=$ts_debut|cat:" "|cat:$ts_fin}}
|
||||
{{:assign var="open_years.%d"|args:$id value=$label|cat:" (du "|cat:$debut|cat:" au "|cat:$fin|cat:")"}}
|
||||
{{if $ts_debut <= $now && $now <= $ts_fin}}
|
||||
{{:assign selected_year=$id}}
|
||||
{{/if}}
|
||||
{{/years}}
|
||||
|
||||
{{* Traiter l'envoi du formulaire *}}
|
||||
{{#form on="add"}}
|
||||
|
||||
{{* vérifier que la date est située dans un exercice ouvert *}}
|
||||
{{:include
|
||||
file="_check_date.html"
|
||||
date=$_POST.date_achat
|
||||
keep="open_years, selected_year, selected_chart"
|
||||
}}
|
||||
{{if $selected_year == null}}
|
||||
{{:assign msg_years=""}}
|
||||
{{#foreach from=$open_years}}
|
||||
{{:assign debut=$start_date|date_short}}
|
||||
{{:assign fin=$end_date|date_short}}
|
||||
{{:assign msg_years=$msg_years|cat:"\n"|cat:" - "|cat:$label|cat:" : "|cat:$debut|cat:" à "|cat:$fin}}
|
||||
{{/foreach}}
|
||||
{{:error message="La date choisie n'est dans aucun exercice ouvert !!\nExercices ouverts : %s"|args:$msg_years}}
|
||||
{{* vérifier que la date d'achat est située dans un exercice ouvert *}}
|
||||
{{:assign ts_date = $_POST.date_achat|parse_date|strtotime}}
|
||||
{{:assign ok=false}}
|
||||
{{#foreach from=$years}}
|
||||
{{if $id == $_POST.id_year}}
|
||||
{{:assign selected_chart=$id_chart}}
|
||||
{{if $start_date|strtotime <= $ts_date && $ts_date <= $end_date|strtotime}}
|
||||
{{:assign ok=true}}
|
||||
{{:break}}
|
||||
{{/if}}
|
||||
{{/if}}
|
||||
{{/foreach}}
|
||||
{{if ! $ok}}
|
||||
{{:error message="La date saisie n'est pas dans l'exercice choisi !"}}
|
||||
{{/if}}
|
||||
|
||||
{{if $_POST.no_amort}}
|
||||
|
@ -77,7 +88,7 @@
|
|||
method="POST"
|
||||
path="accounting/transaction"
|
||||
assign="result"
|
||||
id_year=$selected_year
|
||||
id_year=$_POST.id_year
|
||||
type="revenue"
|
||||
date=$_POST.date_achat
|
||||
label=$_POST.designation
|
||||
|
@ -122,17 +133,6 @@
|
|||
{{:form_errors}}
|
||||
|
||||
{{* formulaire d'ajout d'immobilisation *}}
|
||||
{{#years closed=false order="start_date"}}
|
||||
{{:assign ts_debut=$start_date|strtotime}}
|
||||
{{:assign ts_fin=$end_date|strtotime}}
|
||||
{{:assign debut=$start_date|date_short}}
|
||||
{{:assign fin=$end_date|date_short}}
|
||||
{{:assign var="years_data.%d"|args:$id value=$ts_debut|cat:" "|cat:$ts_fin}}
|
||||
{{:assign var="open_years.%d"|args:$id value=$label|cat:" (du "|cat:$debut|cat:" au "|cat:$fin|cat:")"}}
|
||||
{{if $ts_debut <= $now && $now <= $ts_fin}}
|
||||
{{:assign selected_year=$id}}
|
||||
{{/if}}
|
||||
{{/years}}
|
||||
|
||||
{{:assign var="immo_account.2" value="2 — Classe 2 — Comptes d'immobilisations"}}
|
||||
|
||||
|
@ -146,7 +146,7 @@
|
|||
{{:assign patterns=$pattern_array|implode:"|"}}
|
||||
|
||||
<div id="erreur" class="hidden">
|
||||
<p class="block error">La date choisie n'est dans aucun exercice ouvert</p>
|
||||
<p class="block error">La date choisie n'est dans aucun exercice ouvert !</p>
|
||||
</div>
|
||||
|
||||
<form method="post" action="">
|
||||
|
@ -154,8 +154,8 @@
|
|||
<legend>Ajouter une immobilisation</legend>
|
||||
<dl>
|
||||
{{:input id="no_amort" type="checkbox" value=1 name="no_amort" label="Ne pas amortir" help="Cocher pour ne pas amortir" onclick="toggleInputs('f_no_amort_1', ['f_date_mes','f_duree'])"}}
|
||||
{{:input type="select" name="id_year" label="Exercice" required=true default_empty="— Faire un choix —" options=$open_years}}
|
||||
{{:input type="date" name="date_achat" label="Date d'acquisition" required=true default=$now|date_short}}
|
||||
{{:input type="select" default=$selected_year name="id_year" label="Exercice" required=true default_empty="— Faire un choix —" options=$open_years}}
|
||||
{{: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="designation" label="Désignation" required=true}}
|
||||
{{:input type="money" name="montant" label="Montant" required=true}}
|
||||
|
@ -194,13 +194,11 @@
|
|||
<script type="text/javascript" src="scripts.js"></script>
|
||||
<script type="text/javascript">
|
||||
|
||||
function setYears(evt, id_date = 'f_date_achat', id_exercices = 'f_id_year', id_years = 'f_years_data') {
|
||||
chooseYears(id_date, id_exercices, id_years);
|
||||
function changeYear(evt, f_accounts = ['credit_account', 'debit_account'], f_years_select = 'f_id_year') {
|
||||
setSelectorYear(f_accounts, f_years_select);
|
||||
}
|
||||
|
||||
(function () {
|
||||
chooseYears('f_date_achat', 'f_id_year', 'f_years_data');
|
||||
let date_field = document.getElementById('f_date_achat');
|
||||
date_field.onchange = setYears;
|
||||
document.getElementById('f_id_year').onchange = changeYear;
|
||||
})();
|
||||
</script>
|
||||
|
|
43
scripts.js
43
scripts.js
|
@ -48,47 +48,6 @@ function disableOptions(idSelect, init, values) {
|
|||
}
|
||||
}
|
||||
|
||||
// choisir les exercices affichés selon la date paramètre
|
||||
function chooseYears(id_date, id_exercices, id_years)
|
||||
{
|
||||
// masquer le message d'erreur
|
||||
document.getElementById('erreur').setAttribute('class', 'hidden');
|
||||
// activer toutes les options
|
||||
const select_field = document.getElementById(id_exercices);
|
||||
for (const choix of select_field.options) {
|
||||
choix.removeAttribute('disabled');
|
||||
choix.removeAttribute('selected');
|
||||
}
|
||||
|
||||
// voir dans quels exercices ouverts se situe la date d'acquisition
|
||||
const date_achat = getDate(id_date);
|
||||
const years_data = document.getElementById(id_years);
|
||||
let array_years = [];
|
||||
for (const choix of years_data.options) {
|
||||
if (choix.value != '') {
|
||||
const epox = choix.text.split(' ');
|
||||
if (epox[0] <= date_achat && date_achat <= epox[1]) {
|
||||
array_years.push(choix.value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (array_years.length == 0) {
|
||||
document.getElementById('erreur').setAttribute('class', '');
|
||||
disableOptions(select_field, 1, array_years);
|
||||
select_field.value = '';
|
||||
setAccountYear(['credit_account', 'debit_account'], 0);
|
||||
} else if (array_years.length == 1) {
|
||||
disableOptions(select_field, 0, array_years);
|
||||
select_field.value = array_years[0];
|
||||
setAccountYear(['credit_account', 'debit_account'], array_years[0]);
|
||||
} else {
|
||||
disableOptions(select_field, 1, array_years);
|
||||
select_field.value = '';
|
||||
setAccountYear(['credit_account', 'debit_account'], 0);
|
||||
}
|
||||
}
|
||||
|
||||
// afficher la date de fin de l'exercice choisi
|
||||
function setDateEnd(id_exercices, id_date, id_years) {
|
||||
const selected_year = document.getElementById(id_exercices).value;
|
||||
|
@ -107,7 +66,7 @@ function setDateEnd(id_exercices, id_date, id_years) {
|
|||
}
|
||||
}
|
||||
|
||||
// renvoyer la valeur numérique d'un montant formatté en €
|
||||
// renvoyer la valeur numérique d'un montant formaté en €
|
||||
function getNumber(text) {
|
||||
return Number(text.replace(/ /g, '').replace(/,/, '.').replace(/€/, ''));
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue