epicier/prix_vente.html
Jean-Christophe Engel 6581b4afb7 Enregistrement initial
2025-10-27 21:20:12 +01:00

100 lines
3.4 KiB
HTML

{{* -*- brindille -*- *}}
{{:admin_header title="Calcul prix de vente" custom_css="./style.css" current="module_epicier"}}
{{:include file="./_nav.html" current="prix_vente"}}
{{:assign var="taux_tva." value="0.021"}}
{{:assign var="taux_tva." value="0.055"}}
{{:assign var="taux_tva." value="0.1"}}
{{:assign var="taux_tva." value="0.2"}}
{{:assign ind=0}}
{{#foreach from=$taux_tva item="taux"}}
{{:assign taux="%f*100"|math:$taux}}
{{:assign var="options.%s"|args:$ind value=$taux|cat:"%"}}
{{:assign ind="%d+1"|math:$ind}}
{{/foreach}}
<form method="post" action="" data-focus="1">
<fieldset class="saisie">
<legend>Saisie</legend>
<dl>
{{:input type="text" pattern="[0-9]+\.[0-9]+" name="prix_ht" label="Prix HT" required=true title="Saisir un nombre décimal ; ex : 1.78" size="10"}}
{{:input type="select" name="taux_tva" label="Taux TVA" required=true default_empty="— Choisir —" options=$options}}
{{:input type="text" pattern="[0-9]+\.[0-9]+" name="prix_ttc" label="Prix TTC" required=false size="10" readonly=true}}
{{:input type="text" pattern="[0-9]+\.[0-9]+" name="paff" label="Taux PAFF" required=true title="Saisir un nombre décimal ; ex : 3.5" size="10"}}
{{:input type="text" name="prix_vente" label="Prix de vente" required=false size="10" readonly=true}}
</dl>
</fieldset>
</form>
<script type="text/javascript">
function raz(field_list)
{
for (const elem of field_list) {
document.getElementById(elem).value = '';
}
}
function displayPrixTTC(evt,
id_taux_tva = 'f_taux_tva',
id_prix_ht = 'f_prix_ht',
id_prix_ttc = 'f_prix_ttc',
id_paff = 'f_paff',
id_prix_vente = 'f_prix_vente'
)
{
const select_tva = document.getElementById(id_taux_tva);
const ind_tva = select_tva.selectedIndex;
if (ind_tva > 0) {
// taux TVA choisi
const val_tva = parseFloat(select_tva.options[ind_tva].label.replace(/ *%.*/, ""));
const prix_ttc = parseFloat(document.getElementById(id_prix_ht).value) * ( 1 + val_tva / 100.);
document.getElementById(id_prix_ttc).value = prix_ttc.toFixed(2);
const val_paff = document.getElementById(id_paff).value.replace(/ *%.*/, "");
if (val_paff != '') {
computePrixVente(evt, id_taux_tva, id_prix_ht, id_prix_ttc, id_paff, id_prix_vente);
} else {
document.getElementById(id_paff).focus();
}
} else {
// pas de taux de tva choisi
raz([id_prix_ttc, id_prix_vente]);
select_tva.focus();
}
}
function computePrixVente(evt,
id_taux_tva = 'f_taux_tva',
id_prix_ht = 'f_prix_ht',
id_prix_ttc = 'f_prix_ttc',
id_paff = 'f_paff',
id_prix_vente = 'f_prix_vente'
)
{
const val_pht = document.getElementById(id_prix_ht).value;
if (val_pht === "") {
document.getElementById(id_prix_ht).focus();
return;
}
const val_pttc = document.getElementById(id_prix_ttc).value;
if (val_pttc === "") {
document.getElementById(id_taux_tva).focus();
return;
}
const val_paff = document.getElementById(id_paff).value.replace(/ *%.*/, "");
if (val_paff != "") {
const prix_vente = parseFloat(val_pttc) * (1 + parseFloat(val_paff)/100.);
document.getElementById(id_prix_vente).value = prix_vente.toFixed(2);
document.getElementById(id_prix_ht).focus();
}
}
(function () {
document.getElementById('f_prix_ht').onchange = displayPrixTTC;
document.getElementById('f_taux_tva').onchange = displayPrixTTC;
document.getElementById('f_paff').onchange = computePrixVente;
})();
</script>