Bonjour,

Je dois calculer le pourcentage.
Le prix change selon la condition, si on est en code > 0 comme dans la première condition, on a un prixcat et on obtient le prixclient quand code == 2 comme dans la deuxième condition (de là découle le prix2). Je dois calculer le pourcentage dessus.

Mes variables sont renseignées avec javascript, ajax. Il faut que je fasse ma fonction calcul pourcentage dans le javascript mais ça ne fonctionne pas.

Merci pour votre aide

Code javascript : 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
 
<script type="text/javascript">
function ajax2(articles,code){
var paramcat=articles;
var paramcat2=code;
$.ajax({ type: "GET",url: "fichier.php",data:"articles="+paramcat+"&code="+code,
 
success: 
function(msg){
var xml = msg,
    xmlDoc = $.parseXML( xml ),
    $xml = $( xmlDoc ),
    $prixcat = $xml.find( "PRIXCAT" );
    $prixclient = $xml.find( "PRIXCLIENT" );
    $remise = $xml.find( "REMISE" );
 
 
var de1=$prixcat.text();
if(de1==""){
de1="<a href='code.php?code="+paramcat+"'>Demande</a>";
}
else{ 
de1=$prixcat.text();
}
var de2=$prixclient.text();
if(de2==""){
de2=de1;
}
else{ 
de2=$prixclient.text();
}
 
 
$( "#prixcat"+paramcat ).empty();
$( "#prixclient"+paramcat ).empty();
$( "#remise"+paramcat ).empty();
 
$( "#prixcat"+paramcat ).append(de1);
$( "#prixclient"+paramcat ).append(de2);
//alert(msg);
}})
;}
 
 
//REMISE calcul du taux de remise effectuée
function cacul_pourcentage(){
 
var montantremise = $prixcatalogue - $prixclient
var resultat = (montantremise*100) / $prixcatalogue
 
return round(resultat)
}
 
 
</script>




Code php : 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
 
 
<?php
//REMISE calcul du taux de remise effectuée
/*function cacul_pourcentage($nombre,$total,$pourcentage)
{ 
	$resultat = ($nombre/$total) * $pourcentage;
	return round($resultat); // Arrondi la valeur
} 
 */
 
 
if ($_SESSION['code']>0)
{
echo "<strong>Prix cat. : <span id=\"prixcat".$rang['article']."\"></span></strong><br />";
$rang['article'] = $prix1;
    if ($_SESSION['code']=="2")
    {
    echo "<strong>Prix net : <span id=\"prixclient".$rang['article']."\"></span></strong> <br />";
    $rang['article'] = $prix2;
 
 
        //--------------------  Taux REMISE  -------------------------//
        if ($_SESSION['acces'] == '00005852')
        { 														    
                  //$valeur_pourcentage = 100;
                  echo "<strong>Remise : </strong>";
                  //echo cacul_pourcentage($prix1,$prix2,$valeur_pourcentage)." %"; 
                      echo "<br/>";
		echo "<strong>Remise : <span id=\"remise\"></span></strong> <br />";
 
        }
        //--------------------  Taux REMISE -------------------------//
 
    } else { echo "<br />";}
 
?>