Bonjour,
Pourriez-vous m'aider, car ça fait 2 jour que je cherche l'erreur de mon script pour calculer la TVA:
Voici le script:
Code js : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58 <script language="javascript"><!-- var tax_rates = new Array(); tax_rates["1"] = 7.6; function doRound(x, places) { return Math.round(x * Math.pow(10, places)) / Math.pow(10, places); } function updateGrossAT(nomm,nommGross,tax) { var tax_rates = new Array(); tax_rates["1"] = 7.6; var selected_value = document.forms["new_product"].tax.selectedIndex; var parameterVal = document.forms["new_product"].tax[selected_value].value; if ( (parameterVal > 0) && (tax_rates[parameterVal] > 0) ) { var taxRate = tax_rates[parameterVal]; } else { var taxRate = 0; } var grossValue = document.forms["new_product"].nomm.value; if (taxRate > 0) { grossValue = grossValue * ((taxRate / 100) + 1); } document.forms["new_product"].nommGross.value = doRound(grossValue, 4); } function updateNetAT(nomm,nomGross,tax) { var tax_rates = new Array(); tax_rates["1"] = 7.6; var selected_value = document.forms["new_product"].tax.selectedIndex; var parameterVal = document.forms["new_product"].tax[selected_value].value; if ( (parameterVal > 0) && (tax_rates[parameterVal] > 0) ) { var taxRate = tax_rates[parameterVal]; } else { var taxRate = 0; } var netValue = document.forms["new_product"].nomGross.value; if (taxRate > 0) { netValue = netValue / ((taxRate / 100) + 1); } document.forms["new_product"].nomm.value = doRound(netValue, 4); } //--></script>
Et dans le BODY :
Code html : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11 <input size="6" type="text" name="att_price[0]" value="" onchange="updateGrossAT("att_price[0]","att_price_gross[0]","products_tax_class_id[0]")"> <select name="products_tax_class_id[0]" onchange="updateGrossAT("att_price[0]","att_price_gross[0]","products_tax_class_id[0]")"> <option value="0">--aucun--</option> <option value="1" SELECTED>TVA</option> </select> <input type="text" name="att_price_gross[0]" OnKeyUp="updateNetAT("att_price[0]","att_price_gross[0]","products_tax_class_id[0]")">
Merci d'avance pour votre aide.
Partager