SUITE - Débutante Ajax - Action 'onClick'

charlottebardet
Invité n'ayant pas de compte PHPfrance

25 avr. 2008, 12:02

Alors ! Normalement tout devrait marcher ! Juste un petit souci avec ma fonction aff_tva($h,$sens) !

Pour le moment mon appel ressemble à ça :

Code : Tout sélectionner

<td class="RowHeader10" nowrap>&nbsp;&nbsp;&nbsp;<a onclick="javascript:changerSigne(1);calcul_TVA_Total(); aff_tva('-1', '<?php echo $sens; ?>')"><img name="image" src="img/plus.GIF"></a>&nbsp;TVA</td>
Ensuite dans mon JS j'ai :

Code : Tout sélectionner

function aff_tva(h, sens) { alert("aff tva"); retourJS2 = getXhr('page/ajax.php?action=aff_tva&h='+h+'&sens='+sens); document.getElementById('divdaffichageTOTAL_TVA').innerHTML = retourJS2; }
Et enfin dans mon fichier ajax.php ma fonction :

Code : Tout sélectionner

if($_GET['action'] == 'aff_tva&h='+h+'&sens='+sens) { echo "aff_tva"; if($h==-1){ $t[0] = $achat->tva0_total; $tx[0] = 1; $t[1] = $achat->tva21_total; $tx[1] = 2; $t[2] = $achat->tva55_total; $tx[2] = 3; $t[3] = $achat->tva196_total; $tx[3] = 4; } else{ $t[0] = $achat->tva0[$h]; $tx[0] = 1; $t[1] = $achat->tva21[$h]; $tx[1] = 2; $t[2] = $achat->tva55[$h]; $tx[2] = 3; $t[3] = $achat->tva196[$h]; $tx[3] = 4; } $temp = ''; $temp2 = ''; $longueur = count($t); $desordre = true; while($desordre){ $desordre = false; for($i=0;$i<($longueur-1);$i++){ if($sens == 'ASC'){ if($t[$i]>$t[$i+1]){ $temp = $t[$i]; $temp2 = $tx[$i]; $t[$i] = $t[$i+1]; $tx[$i] = $tx[$i+1]; $t[$i+1] = $temp; $tx[$i+1] = $temp2; $desordre = true; } } else{ if($t[$i]<$t[$i+1]){ $temp = $t[$i]; $temp2 = $tx[$i]; $t[$i] = $t[$i+1]; $tx[$i] = $tx[$i+1]; $t[$i+1] = $temp; $tx[$i+1] = $temp2; $desordre = true; } } } } for($j = 0;$j<$longueur;$j++){ if($tx[$j]==1) $achat->aff_tva0($h); else if($tx[$j]==2) $achat->aff_tva21($h); else if($tx[$j]==3) $achat->aff_tva55($h); else if($tx[$j]==4) $achat->aff_tva196($h); } }
Cependant l'exécution bloque au niveau de la dernière boucle for (ci-dessus), et me renvoie l'erreur :

Code : Tout sélectionner

Fatal error: Call to undefined method stdClass::aff_tva0() in C:\Pharmavitale\Fichiers\PHP\Stats\page\ajax.php on line 111
qui correspond donc à la ligne :

Code : Tout sélectionner

if($tx[$j]==1) $achat->aff_tva0($h);
ma fonction aff_tva0($h) se situent dans une classe achat (fichier cls_achat.php).
Ce qui m'étonne c'est que $achat->tva0[$h]; par exemple, ne lui pose pas problème :?

HELP :cry:

Mammouth du PHP | 1353 Messages

25 avr. 2008, 12:05

Bonjour,

Pourrais tu nous montrer la classe achat s'il te plait ?
Tell me and I forget. Teach me and I remember. Involve me and I learn.

Invité
Invité n'ayant pas de compte PHPfrance

25 avr. 2008, 12:09

Oula elle est assez enorme :?

J'ai les déclaration de variables :
class Achat {
	var $debut;
	var $fin;
	
	var $TOTAL_TVA=false;
	var $TOTAL_Prix=false;
	var $TOTAL_Categorie=false;
	
	var $Grossiste_TVA=false;
	var $Grossiste_Prix=false;
	var $Grossiste_Categorie=false;
	
	var $Direct_TVA=false;
	var $Direct_Prix=false;
	var $Direct_Categorie=false;
	
	var $Fournisseur=false;
	
	var $montant_total;
	var $qte_total;
	var $montant_direct;
	var $qte_direct;
	var $montant_grossiste;
	var $qte_grossiste;
	
	var $tva0_total;
	var $tva21_total;
	var $tva55_total;
	var $tva196_total;
	var $qtetva0_total;
	var $qtetva21_total;
	var $qtetva55_total;
	var $qtetva196_total;

	var $tva0;
	var $tva21;
	var $tva55;
	var $tva196;
	var $qtetva0;
	var $qtetva21;
	var $qtetva55;
	var $qtetva196;

	var $prix1_total;
	var $prix2_total;
	var $prix3_total;
	var $qteprix1_total;
	var $qteprix2_total;
	var $qteprix3_total;
	
	var $prix1;
	var $prix2;
	var $prix3;	
	var $qteprix1;
	var $qteprix2;
	var $qteprix3;
	
	var $categorie;
	var $categorie_grossiste;
	var $categorie_direct;
	
	var $color;
		
Et ensuite plein de petites fonctions du même type que aff_tva.

En fait à l'origine cette fonction était elle même dans ce fichier, mais pour éviter un rechargement de ma page lors de l'appel je me met à l'ajax (voir mon premier sujet Débutante Ajax - 'onclick').

charlottebardet
Invité n'ayant pas de compte PHPfrance

25 avr. 2008, 12:11

Je vous met quand même la suite de ma classe achat pour un aperçu :
function Achat($debut,$fin) {
		set_time_limit(600);
		$this->debut = $debut;
		$this->fin = $fin;
		$this->color = 0;
    }	
/*
	function calcul_TVA_TOTAL(){
		$result = mssql_query("SELECT ligcom.code_tva, sum(cast(ligcom.qterec_ligcom*ligcom.prixremht_ligcom as bigint)), sum(ligcom.qterec_ligcom) 
FROM (ligcom LEFT JOIN com on ligcom.id_com=com.id_com)
WHERE ligcom.qterec_ligcom <> 0
AND CASE WHEN com.dtliv_com IS NOT NULL THEN (com.dtliv_com)
ELSE CASE WHEN com.dprevliv_com IS NOT NULL THEN (com.dprevliv_com)
ELSE (com.dtenvoi_com) END END >= '".$this->debut."'
AND CASE WHEN com.dtliv_com IS NOT NULL THEN (com.dtliv_com)
ELSE CASE WHEN com.dprevliv_com IS NOT NULL THEN (com.dprevliv_com)
ELSE (com.dtenvoi_com) END END  <= '".$this->fin."'
GROUP BY ligcom.code_tva
ORDER BY ligcom.code_tva");
			
		$this->tva0_total = 0;
		$this->qtetva0_total = 0;
		$this->tva196_total = 0;
		$this->qtetva196_total = 0;
		$this->tva55_total = 0;
		$this->qtetva55_total = 0;
		$this->tva21_total = 0;
		$this->qtetva21_total = 0;

	while($rows = mssql_fetch_row($result)){
		$this->montant_total = $this->montant_total + $rows[1]/10000;
		$this->qte_total = $this->qte_total + $rows[2];
		if($rows[0]=='0'){
			$tva0++;
			$this->tva0_total = $rows[1]/10000;
			$this->qtetva0_total = $rows[2];
		}
		else if($rows[0]=='2'){
			$tva196++;
			$this->tva196_total = $rows[1]/10000;
			$this->qtetva196_total = $rows[2];
		}
		else if($rows[0]=='3'){
			$tva55++;
			$this->tva55_total = $rows[1]/10000;
			$this->qtetva55_total = $rows[2];
		}
		else if($rows[0]=='5'){
			$tva21++;
			$this->tva21_total = $rows[1]/10000;
			$this->qtetva21_total = $rows[2];
		}
						
	}
}*/
		function calcul_prix_TOTAL(){
		$result = mssql_query("SELECT CASE WHEN ligcom.prixcat_ligcom <= 2290 THEN 'prix1' ELSE CASE WHEN ligcom.prixcat_ligcom <= 15000 AND ligcom.prixcat_ligcom > 2290 THEN 'prix2' ELSE 'prix3' END END, sum(cast(ligcom.qterec_ligcom*ligcom.prixremht_ligcom as bigint)), sum(ligcom.qterec_ligcom)
FROM (ligcom LEFT JOIN com on ligcom.id_com=com.id_com)
WHERE ligcom.qterec_ligcom <> 0
AND CASE WHEN com.dtliv_com IS NOT NULL THEN (com.dtliv_com)
ELSE CASE WHEN com.dprevliv_com IS NOT NULL THEN (com.dprevliv_com)
ELSE (com.dtenvoi_com) END END >= '".$this->debut."'
AND CASE WHEN com.dtliv_com IS NOT NULL THEN (com.dtliv_com)
ELSE CASE WHEN com.dprevliv_com IS NOT NULL THEN (com.dprevliv_com)
ELSE (com.dtenvoi_com) END END  <= '".$this->fin."'
GROUP BY CASE WHEN ligcom.prixcat_ligcom <= 2290 THEN 'prix1' ELSE CASE WHEN ligcom.prixcat_ligcom <= 15000 AND ligcom.prixcat_ligcom > 2290 THEN 'prix2' ELSE 'prix3' END END
ORDER BY CASE WHEN ligcom.prixcat_ligcom <= 2290 THEN 'prix1' ELSE CASE WHEN ligcom.prixcat_ligcom <= 15000 AND ligcom.prixcat_ligcom > 2290 THEN 'prix2' ELSE 'prix3' END END");

		$this->prix1_total = 0;
		$this->qteprix1_total = 0;
		$this->prix2_total = 0;
		$this->qteprix2_total = 0;
		$this->prix3_total = 0;
		$this->qteprix3_total = 0;
			
		while($rows = mssql_fetch_row($result)){
			if($rows[0]=='prix1'){
				$this->prix1_total = $rows[1]/10000;
				$this->qteprix1_total = $rows[2];
			}
			else if($rows[0]=='prix2'){
				$prix2++;
				$this->prix2_total = $rows[1]/10000;
				$this->qteprix2_total = $rows[2];
			}
			else if($rows[0]=='prix3'){
				$prix3++;
				$this->prix3_total = $rows[1]/10000;
				$this->qteprix3_total = $rows[2];
			}
		}
	}
	
	function calcul_TVA_Grossiste(){
		$result = mssql_query("SELECT com.type_com, ligcom.code_tva, sum(cast(ligcom.qterec_ligcom*ligcom.prixremht_ligcom as bigint)), sum(ligcom.qterec_ligcom) 
FROM (ligcom LEFT JOIN com on ligcom.id_com=com.id_com)
WHERE ligcom.qterec_ligcom <> 0 AND com.type_com='G'
AND CASE WHEN com.dtliv_com IS NOT NULL THEN (com.dtliv_com)
ELSE CASE WHEN com.dprevliv_com IS NOT NULL THEN (com.dprevliv_com)
ELSE (com.dtenvoi_com) END END >= '".$this->debut."'
AND CASE WHEN com.dtliv_com IS NOT NULL THEN (com.dtliv_com)
ELSE CASE WHEN com.dprevliv_com IS NOT NULL THEN (com.dprevliv_com)
ELSE (com.dtenvoi_com) END END  <= '".$this->fin."'
GROUP BY com.type_com, ligcom.code_tva
ORDER BY com.type_com, ligcom.code_tva");
				
		$this->tva0[1] = 0;
		$this->qtetva0[1] = 0;
		$this->tva196[1] = 0;
		$this->qtetva196[1] = 0;
		$this->tva55[1] = 0;
		$this->qtetva55[1] = 0;
		$this->tva21[1] = 0;
		$this->qtetva21[1] = 0;
		
	while($rows = mssql_fetch_row($result)){
			$this->montant_grossiste = $this->montant_grossiste + $rows[2]/10000;
			$this->qte_grossiste = $this->qte_grossiste + $rows[3];
			if($rows[1]=='0'){
				$this->tva0[1] = $rows[2]/10000;
				$this->qtetva0[1] = $rows[3];
			}
			else if($rows[1]=='2'){
				$this->tva196[1] = $rows[2]/10000;
				$this->qtetva196[1] = $rows[3];
			}
			else if($rows[1]=='3'){
				$this->tva55[1] = $rows[2]/10000;
				$this->qtetva55[1] = $rows[3];
			}
			else if($rows[1]=='5'){
				$this->tva21[1] = $rows[2]/10000;
				$this->qtetva21[1] = $rows[3];
			}	
		}
	}
	
		function calcul_prix_Grossiste(){
		$result = mssql_query("SELECT com.type_com, CASE WHEN ligcom.prixcat_ligcom <= 2290 THEN 'prix1' ELSE CASE WHEN ligcom.prixcat_ligcom <= 15000 AND ligcom.prixcat_ligcom > 2290 THEN 'prix2' ELSE 'prix3' END END, sum(cast(ligcom.qterec_ligcom*ligcom.prixremht_ligcom as bigint)), sum(ligcom.qterec_ligcom)
FROM (ligcom LEFT JOIN com on ligcom.id_com=com.id_com)
WHERE ligcom.qterec_ligcom <> 0 AND com.type_com='G'
AND CASE WHEN com.dtliv_com IS NOT NULL THEN (com.dtliv_com)
ELSE CASE WHEN com.dprevliv_com IS NOT NULL THEN (com.dprevliv_com)
ELSE (com.dtenvoi_com) END END >= '".$this->debut."'
AND CASE WHEN com.dtliv_com IS NOT NULL THEN (com.dtliv_com)
ELSE CASE WHEN com.dprevliv_com IS NOT NULL THEN (com.dprevliv_com)
ELSE (com.dtenvoi_com) END END  <= '".$this->fin."'
GROUP BY com.type_com, CASE WHEN ligcom.prixcat_ligcom <= 2290 THEN 'prix1' ELSE CASE WHEN ligcom.prixcat_ligcom <= 15000 AND ligcom.prixcat_ligcom > 2290 THEN 'prix2' ELSE 'prix3' END END
ORDER BY com.type_com, CASE WHEN ligcom.prixcat_ligcom <= 2290 THEN 'prix1' ELSE CASE WHEN ligcom.prixcat_ligcom <= 15000 AND ligcom.prixcat_ligcom > 2290 THEN 'prix2' ELSE 'prix3' END END");

		$this->prix1[1] = 0;
		$this->qteprix1[1] = 0;
		$this->prix2[1] = 0;
		$this->qteprix2[1] = 0;
		$this->prix3[1] = 0;
		$this->qteprix3[1] = 0;

		while($rows = mssql_fetch_row($result)){
			if($rows[1]=='prix1'){
				$this->prix1[1] = $rows[2]/10000;
				$this->qteprix1[1] = $rows[3];
			}
			else if($rows[1]=='prix2'){
				$this->prix2[1] = $rows[2]/10000;
				$this->qteprix2[1] = $rows[3];
			}
			else if($rows[1]=='prix3'){
				$this->prix3[1] = $rows[2]/10000;
				$this->qteprix3[1] = $rows[3];
			}			
		}
	}
	
	function calcul_TVA_Direct(){
		$result = mssql_query("SELECT com.type_com, ligcom.code_tva, sum(cast(ligcom.qterec_ligcom*ligcom.prixremht_ligcom as bigint)), sum(ligcom.qterec_ligcom) 
FROM (ligcom LEFT JOIN com on ligcom.id_com=com.id_com)
WHERE ligcom.qterec_ligcom <> 0 AND com.type_com='D'
AND CASE WHEN com.dtliv_com IS NOT NULL THEN (com.dtliv_com)
ELSE CASE WHEN com.dprevliv_com IS NOT NULL THEN (com.dprevliv_com)
ELSE (com.dtenvoi_com) END END >= '".$this->debut."'
AND CASE WHEN com.dtliv_com IS NOT NULL THEN (com.dtliv_com)
ELSE CASE WHEN com.dprevliv_com IS NOT NULL THEN (com.dprevliv_com)
ELSE (com.dtenvoi_com) END END  <= '".$this->fin."'
GROUP BY com.type_com, ligcom.code_tva
ORDER BY com.type_com, ligcom.code_tva");
				
		$this->tva0[0] = 0;
		$this->qtetva0[0] = 0;
		$this->tva196[0] = 0;
		$this->qtetva196[0] = 0;
		$this->tva55[0] = 0;
		$this->qtetva55[0] = 0;
		$this->tva21[0] = 0;
		$this->qtetva21[0] = 0;
		
	while($rows = mssql_fetch_row($result)){
			$this->montant_direct = $this->montant_direct + $rows[2]/10000;
			$this->qte_direct = $this->qte_direct + $rows[3];
			if($rows[1]=='0'){
				$this->tva0[0] = $rows[2]/10000;
				$this->qtetva0[0] = $rows[3];
			}
			else if($rows[1]=='2'){
				$this->tva196[0] = $rows[2]/10000;
				$this->qtetva196[0] = $rows[3];
			}
			else if($rows[1]=='3'){
				$this->tva55[0] = $rows[2]/10000;
				$this->qtetva55[0] = $rows[3];
			}
			else if($rows[1]=='5'){
				$this->tva21[0] = $rows[2]/10000;
				$this->qtetva21[0] = $rows[3];
			}	
		}
	}
	
	function calcul_prix_Direct(){
		$result = mssql_query("SELECT com.type_com, CASE WHEN ligcom.prixcat_ligcom <= 2290 THEN 'prix1' ELSE CASE WHEN ligcom.prixcat_ligcom <= 15000 AND ligcom.prixcat_ligcom > 2290 THEN 'prix2' ELSE 'prix3' END END, sum(cast(ligcom.qterec_ligcom*ligcom.prixremht_ligcom as bigint)), sum(ligcom.qterec_ligcom)
FROM (ligcom LEFT JOIN com on ligcom.id_com=com.id_com)
WHERE ligcom.qterec_ligcom <> 0 AND com.type_com='D'
AND CASE WHEN com.dtliv_com IS NOT NULL THEN (com.dtliv_com)
ELSE CASE WHEN com.dprevliv_com IS NOT NULL THEN (com.dprevliv_com)
ELSE (com.dtenvoi_com) END END >= '".$this->debut."'
AND CASE WHEN com.dtliv_com IS NOT NULL THEN (com.dtliv_com)
ELSE CASE WHEN com.dprevliv_com IS NOT NULL THEN (com.dprevliv_com)
ELSE (com.dtenvoi_com) END END  <= '".$this->fin."'
GROUP BY com.type_com, CASE WHEN ligcom.prixcat_ligcom <= 2290 THEN 'prix1' ELSE CASE WHEN ligcom.prixcat_ligcom <= 15000 AND ligcom.prixcat_ligcom > 2290 THEN 'prix2' ELSE 'prix3' END END
ORDER BY com.type_com, CASE WHEN ligcom.prixcat_ligcom <= 2290 THEN 'prix1' ELSE CASE WHEN ligcom.prixcat_ligcom <= 15000 AND ligcom.prixcat_ligcom > 2290 THEN 'prix2' ELSE 'prix3' END END");

		$this->prix1[0] = 0;
		$this->qteprix1[0] = 0;
		$this->prix2[0] = 0;
		$this->qteprix2[0] = 0;
		$this->prix3[0] = 0;
		$this->qteprix3[0] = 0;
		
		while($rows = mssql_fetch_row($result)){
			if($rows[1]=='prix1'){
				$this->prix1[0] = $rows[2]/10000;
				$this->qteprix1[0] = $rows[3];
			}
			else if($rows[1]=='prix2'){
				$this->prix2[0] = $rows[2]/10000;
				$this->qteprix2[0] = $rows[3];
			}
			else if($rows[1]=='prix3'){
				$this->prix3[0] = $rows[2]/10000;
				$this->qteprix3[0] = $rows[3];
			}
		}
	}
	
	/*function aff_tva($h,$sens){
		if($h==-1){
			$t[0] = $this->tva0_total;
			$tx[0] = 1;
			$t[1] = $this->tva21_total;
			$tx[1] = 2;
			$t[2] = $this->tva55_total;
			$tx[2] = 3;
			$t[3] = $this->tva196_total;
			$tx[3] = 4;	
		}
		else{
			$t[0] = $this->tva0[$h];
			$tx[0] = 1;
			$t[1] = $this->tva21[$h];
			$tx[1] = 2;
			$t[2] = $this->tva55[$h];
			$tx[2] = 3;
			$t[3] = $this->tva196[$h];
			$tx[3] = 4;
		}
		
		$temp = '';
		$temp2 = '';
		$longueur = count($t);
		$desordre = true;
		while($desordre){
			$desordre = false;
			for($i=0;$i<($longueur-1);$i++){
				if($sens == 'ASC'){
					if($t[$i]>$t[$i+1]){
						$temp = $t[$i];
						$temp2 = $tx[$i];
						$t[$i] = $t[$i+1];
						$tx[$i] = $tx[$i+1];
						$t[$i+1] = $temp;
						$tx[$i+1] = $temp2;
						$desordre = true;
					}
				}
				else{
					if($t[$i]<$t[$i+1]){
						$temp = $t[$i];
						$temp2 = $tx[$i];
						$t[$i] = $t[$i+1];
						$tx[$i] = $tx[$i+1];
						$t[$i+1] = $temp;
						$tx[$i+1] = $temp2;
						$desordre = true;
					}					
				}
			}
		}		

		for($j = 0;$j<$longueur;$j++){			
			if($tx[$j]==1) $this->aff_tva0($h);
			else if($tx[$j]==2) $this->aff_tva21($h);
			else if($tx[$j]==3) $this->aff_tva55($h);
			else if($tx[$j]==4) $this->aff_tva196($h);
		}
	}
	*/
	function aff_tva0($h){
		if($h==-1){
			if($this->tva0_total!=0){
		?>
		<tr>
			<td class="<?php echo 'RowHeader2'.($this->color%2); ?>" nowrap>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;0%</td>
			<td class="<?php echo 'Value2'.($this->color%2); ?>" nowrap><?php echo number_format($this->qtetva0_total, 0, ',', ' '); ?></td>
			<td class="<?php echo 'Value2'.($this->color%2); ?>" nowrap><?php echo number_format($this->tva0_total, 2, ',', ' ').' &euro;'; ?></td>
			<td class="<?php echo 'Value2'.($this->color%2); ?>" nowrap><?php if(isset($this->montant_total)) echo number_format(($this->tva0_total/$this->montant_total*100),3).'%'; ?></td>
		</tr>		
		<?php
			$this->color++;
			}
		}
		else{
			if($this->tva0[$h]!=0){
		?>
		<tr>
			<td class="<?php echo 'RowHeader2'.($this->color%2); ?>" nowrap>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;0%</td>
			<td class="<?php echo 'Value2'.($this->color%2); ?>" nowrap><?php echo number_format($this->qtetva0[$h], 0, ',', ' '); ?></td>
			<td class="<?php echo 'Value2'.($this->color%2); ?>" nowrap><?php echo number_format($this->tva0[$h], 2, ',', ' ').' &euro;'; ?></td>
			<td class="<?php echo 'Value2'.($this->color%2); ?>" nowrap>
			<?php 
				if ($h == 1) {
					if(isset($this->montant_grossiste)) echo number_format(($this->tva0[$h]/$this->montant_grossiste*100),3).'%';
				} else {
					if(isset($this->montant_direct)) echo number_format(($this->tva0[$h]/$this->montant_direct*100),3).'%';
				}
			?>
			</td>
		</tr>	
		<?php
			$this->color++;
			}
		}		
	}
	
	function aff_tva21($h){
		if($h==-1){
		?>
		<tr>
			<td class="<?php echo 'RowHeader2'.($this->color%2); ?>" nowrap>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<?php echo $_SESSION['tva5'].'%'; ?></td>
			<td class="<?php echo 'Value2'.($this->color%2); ?>" nowrap><?php echo number_format($this->qtetva21_total, 0, ',', ' '); ?></td>
			<td class="<?php echo 'Value2'.($this->color%2); ?>" nowrap><?php echo number_format($this->tva21_total, 2, ',', ' ').' &euro;'; ?></td>
			<td class="<?php echo 'Value2'.($this->color%2); ?>" nowrap><?php if(isset($this->montant_total)) echo number_format(($this->tva21_total/$this->montant_total*100),3).'%'; ?></td>
		</tr>		
		<?php
		}
		else{
		?>
		<tr>
			<td class="<?php echo 'RowHeader2'.($this->color%2); ?>" nowrap>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<?php echo $_SESSION['tva5'].'%'; ?></td>
			<td class="<?php echo 'Value2'.($this->color%2); ?>" nowrap><?php echo number_format($this->qtetva21[$h], 0, ',', ' '); ?></td>
			<td class="<?php echo 'Value2'.($this->color%2); ?>" nowrap><?php echo number_format($this->tva21[$h], 2, ',', ' ').' &euro;'; ?></td>
			<td class="<?php echo 'Value2'.($this->color%2); ?>" nowrap>
			<?php 
				if ($h == 1) {
					if(isset($this->montant_grossiste)) echo number_format(($this->tva21[$h]/$this->montant_grossiste*100),3).'%';
				} else {
					if(isset($this->montant_direct)) echo number_format(($this->tva21[$h]/$this->montant_direct*100),3).'%';
				}
			?>
			</td>
		</tr>		
		<?php
		}
		$this->color++;
	}
	
	function aff_tva55($h){
		if($h==-1){
		?>
		<tr>
			<td class="<?php echo 'RowHeader2'.($this->color%2); ?>" nowrap>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<?php echo $_SESSION['tva3'].'%'; ?></td>
			<td class="<?php echo 'Value2'.($this->color%2); ?>" nowrap><?php echo number_format($this->qtetva55_total, 0, ',', ' '); ?></td>
			<td class="<?php echo 'Value2'.($this->color%2); ?>" nowrap><?php echo number_format($this->tva55_total, 2, ',', ' ').' &euro;'; ?></td>
			<td class="<?php echo 'Value2'.($this->color%2); ?>" nowrap><?php if(isset($this->montant_total)) echo number_format(($this->tva55_total/$this->montant_total*100),3).'%'; ?></td>
		</tr>		
		<?php
		}
		else{
		?>
		<tr>
			<td class="<?php echo 'RowHeader2'.($this->color%2); ?>" nowrap>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<?php echo $_SESSION['tva3'].'%'; ?></td>
			<td class="<?php echo 'Value2'.($this->color%2); ?>" nowrap><?php echo number_format($this->qtetva55[$h], 0, ',', ' '); ?></td>
			<td class="<?php echo 'Value2'.($this->color%2); ?>" nowrap><?php echo number_format($this->tva55[$h], 2, ',', ' ').' &euro;'; ?></td>
			<td class="<?php echo 'Value2'.($this->color%2); ?>" nowrap>
			<?php 
				if ($h == 1) {
					if(isset($this->montant_grossiste)) echo number_format(($this->tva55[$h]/$this->montant_grossiste*100),3).'%';
				} else {
					if(isset($this->montant_direct)) echo number_format(($this->tva55[$h]/$this->montant_direct*100),3).'%';
				}
			?>
			</td>
		</tr>		
		<?php
		}
		$this->color++;
	}
	
	function aff_tva196($h){
		if($h==-1){
		?>
		<tr>
			<td class="<?php echo 'RowHeader2'.($this->color%2); ?>" nowrap>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<?php echo $_SESSION['tva2'].'%'; ?></td>
			<td class="<?php echo 'Value2'.($this->color%2); ?>" nowrap><?php echo number_format($this->qtetva196_total, 0, ',', ' '); ?></td>
			<td class="<?php echo 'Value2'.($this->color%2); ?>" nowrap><?php echo number_format($this->tva196_total, 2, ',', ' ').' &euro;'; ?></td>
			<td class="<?php echo 'Value2'.($this->color%2); ?>" nowrap><?php if(isset($this->montant_total)) echo number_format(($this->tva196_total/$this->montant_total*100),3).'%'; ?></td>
		</tr>		
		<?php
		}
		else{
		?>
		<tr>
			<td class="<?php echo 'RowHeader2'.($this->color%2); ?>" nowrap>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<?php echo $_SESSION['tva2'].'%'; ?></td>
			<td class="<?php echo 'Value2'.($this->color%2); ?>" nowrap><?php echo number_format($this->qtetva196[$h], 0, ',', ' '); ?></td>
			<td class="<?php echo 'Value2'.($this->color%2); ?>" nowrap><?php echo number_format($this->tva196[$h], 2, ',', ' ').' &euro;'; ?></td>
			<td class="<?php echo 'Value2'.($this->color%2); ?>" nowrap>
			<?php 
				if ($h == 1) {
					if(isset($this->montant_grossiste)) echo number_format(($this->tva196[$h]/$this->montant_grossiste*100),3).'%';
				} else {
					if(isset($this->montant_direct)) echo number_format(($this->tva196[$h]/$this->montant_direct*100),3).'%';
				}
			?>
			</td>
			
			
		</tr>	
		<?php
		}
		$this->color++;
	}
	
	
	function aff_prix($h,$sens){
		if($h==-1){
			$t[0] = $this->prix1_total;
			$tx[0] = 1;
			$t[1] = $this->prix2_total;
			$tx[1] = 2;
			$t[2] = $this->prix3_total;
			$tx[2] = 3;	
		}
		else{
			$t[0] = $this->prix1[$h];
			$tx[0] = 1;
			$t[1] = $this->prix2[$h];
			$tx[1] = 2;
			$t[2] = $this->prix3[$h];
			$tx[2] = 3;
		}
		
		$temp = '';
		$temp2 = '';
		$longueur = count($t);
		$desordre = true;
		while($desordre){
			$desordre = false;
			for($i=0;$i<($longueur-1);$i++){
				if($sens == 'ASC'){
					if($t[$i]>$t[$i+1]){
						$temp = $t[$i];
						$temp2 = $tx[$i];
						$t[$i] = $t[$i+1];
						$tx[$i] = $tx[$i+1];
						$t[$i+1] = $temp;
						$tx[$i+1] = $temp2;
						$desordre = true;
					}
				}
				else{
					if($t[$i]<$t[$i+1]){
						$temp = $t[$i];
						$temp2 = $tx[$i];
						$t[$i] = $t[$i+1];
						$tx[$i] = $tx[$i+1];
						$t[$i+1] = $temp;
						$tx[$i+1] = $temp2;
						$desordre = true;
					}					
				}
			}
		}		

		for($j = 0;$j<$longueur;$j++){			
			if($tx[$j]==1) $this->aff_prix1($h);
			else if($tx[$j]==2) $this->aff_prix2($h);
			else if($tx[$j]==3) $this->aff_prix3($h);
		}
	}
	
	function aff_prix1($h){
		if($h==-1){
		?>
		<tr>
			<td class="<?php echo 'RowHeader2'.($this->color%2); ?>" nowrap>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Moins de 22,90&euro;</td>
			<td class="<?php echo 'Value2'.($this->color%2); ?>" nowrap><?php echo number_format($this->qteprix1_total, 0, ',', ' '); ?></td>
			<td class="<?php echo 'Value2'.($this->color%2); ?>" nowrap><?php echo number_format($this->prix1_total, 2, ',', ' ').' &euro;'; ?></td>
			<td class="<?php echo 'Value2'.($this->color%2); ?>" nowrap><?php if(isset($this->montant_total)) echo number_format(($this->prix1_total/$this->montant_total*100),3).'%'; ?></td>
		</tr>		
		<?php
		}
		else{
		?>
		<tr>
			<td class="<?php echo 'RowHeader2'.($this->color%2); ?>" nowrap>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Moins de 22,90&euro;</td>
			<td class="<?php echo 'Value2'.($this->color%2); ?>" nowrap><?php echo number_format($this->qteprix1[$h], 0, ',', ' '); ?></td>
			<td class="<?php echo 'Value2'.($this->color%2); ?>" nowrap><?php echo number_format($this->prix1[$h], 2, ',', ' ').' &euro;'; ?></td>
			<td class="<?php echo 'Value2'.($this->color%2); ?>" nowrap>
			<?php 
				if ($h == 1) {
					if(isset($this->montant_grossiste)) echo number_format(($this->prix1[$h]/$this->montant_grossiste*100),3).'%'; 
				} else {
					if(isset($this->montant_direct)) echo number_format(($this->prix1[$h]/$this->montant_direct*100),3).'%'; 
				}
			?>
			</td>
		</tr>		
		<?php
		}
		$this->color++;
	}
	
	function aff_prix2($h){
		if($h==-1){
		?>
		<tr>
			<td class="<?php echo 'RowHeader2'.($this->color%2); ?>" nowrap>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Entre 22,90&euro; et 150&euro;</td>
			<td class="<?php echo 'Value2'.($this->color%2); ?>" nowrap><?php echo number_format($this->qteprix2_total, 0, ',', ' '); ?></td>
			<td class="<?php echo 'Value2'.($this->color%2); ?>" nowrap><?php echo number_format($this->prix2_total, 2, ',', ' ').' &euro;'; ?></td>
			<td class="<?php echo 'Value2'.($this->color%2); ?>" nowrap><?php if(isset($this->montant_total)) echo number_format(($this->prix2_total/$this->montant_total*100),3).'%'; ?></td>
		</tr>		
		<?php
		}
		else{
		?>
		<tr>
			<td class="<?php echo 'RowHeader2'.($this->color%2); ?>" nowrap>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Entre 22,90&euro; et 150&euro;</td>
			<td class="<?php echo 'Value2'.($this->color%2); ?>" nowrap><?php echo number_format($this->qteprix2[$h], 0, ',', ' '); ?></td>
			<td class="<?php echo 'Value2'.($this->color%2); ?>" nowrap><?php echo number_format($this->prix2[$h], 2, ',', ' ').' &euro;'; ?></td>
			<td class="<?php echo 'Value2'.($this->color%2); ?>" nowrap>
			<?php 
				if ($h == 1) {
					if(isset($this->montant_grossiste)) echo number_format(($this->prix2[$h]/$this->montant_grossiste*100),3).'%'; 
				} else {
					if(isset($this->montant_direct)) echo number_format(($this->prix2[$h]/$this->montant_direct*100),3).'%'; 
				}
			?>
			</td>
		</tr>		
		<?php
		}
		$this->color++;	
	}
		
	function aff_prix3($h){
		if($h==-1){
		?>
		<tr>
			<td class="<?php echo 'RowHeader2'.($this->color%2); ?>" nowrap>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Plus de 150&euro;</td>
			<td class="<?php echo 'Value2'.($this->color%2); ?>" nowrap><?php echo number_format($this->qteprix3_total, 0, ',', ' '); ?></td>
			<td class="<?php echo 'Value2'.($this->color%2); ?>" nowrap><?php echo number_format($this->prix3_total, 2, ',', ' ').' &euro;'; ?></td>
			<td class="<?php echo 'Value2'.($this->color%2); ?>" nowrap><?php if(isset($this->montant_total)) echo number_format(($this->prix3_total/$this->montant_total*100),3).'%'; ?></td>
		</tr>		
		<?php
		}
		else{
		?>
		<tr>
			<td class="<?php echo 'RowHeader2'.($this->color%2); ?>" nowrap>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Plus de 150&euro;</td>
			<td class="<?php echo 'Value2'.($this->color%2); ?>" nowrap><?php echo number_format($this->qteprix3[$h], 0, ',', ' '); ?></td>
			<td class="<?php echo 'Value2'.($this->color%2); ?>" nowrap><?php echo number_format($this->prix3[$h], 2, ',', ' ').' &euro;'; ?></td>
			<td class="<?php echo 'Value2'.($this->color%2); ?>" nowrap>
			<?php 
				if ($h == 1) {
					if(isset($this->montant_grossiste)) echo number_format(($this->prix3[$h]/$this->montant_grossiste*100),3).'%'; 
				} else {
					if(isset($this->montant_direct)) echo number_format(($this->prix3[$h]/$this->montant_direct*100),3).'%'; 
				}
			?>
			</td>
		</tr>		
		<?php
		}
		$this->color++;	
	}
	
}

Invité
Invité n'ayant pas de compte PHPfrance

25 avr. 2008, 12:22

Je viens de découvrir un autre problème ... :cry:

Dans la fonction calcul_tva que j'appelle juste avant aff_tva je viens de voir que la requête du début n'est pas exécutée correctement :
if($_GET['action'] == 'calculTVATotal') { 
		echo "calculTVAtotal";
		$result = mssql_query("SELECT ligcom.code_tva, sum(cast(ligcom.qterec_ligcom*ligcom.prixremht_ligcom as bigint)), sum(ligcom.qterec_ligcom) 
FROM (ligcom LEFT JOIN com on ligcom.id_com=com.id_com)
WHERE ligcom.qterec_ligcom <> 0
AND CASE WHEN com.dtliv_com IS NOT NULL THEN (com.dtliv_com)
ELSE CASE WHEN com.dprevliv_com IS NOT NULL THEN (com.dprevliv_com)
ELSE (com.dtenvoi_com) END END >= '".$achat->debut."'
AND CASE WHEN com.dtliv_com IS NOT NULL THEN (com.dtliv_com)
ELSE CASE WHEN com.dprevliv_com IS NOT NULL THEN (com.dprevliv_com)
ELSE (com.dtenvoi_com) END END  <= '".$achat->fin."'
GROUP BY ligcom.code_tva
ORDER BY ligcom.code_tva");
			
		$achat->tva0_total = 0;
		$achat->qtetva0_total = 0;
		$achat->tva196_total = 0;
		$achat->qtetva196_total = 0;
		$achat->tva55_total = 0;
		$achat->qtetva55_total = 0;
		$achat->tva21_total = 0;
		$achat->qtetva21_total = 0;

	while($rows = mssql_fetch_row($result)){
		$achat->montant_total = $achat->montant_total + $rows[1]/10000;
		$achat->qte_total = $achat->qte_total + $rows[2];
		if($rows[0]=='0'){
			$tva0++;
			$achat->tva0_total = $rows[1]/10000;
			$achat->qtetva0_total = $rows[2];
		}
		else if($rows[0]=='2'){
			$tva196++;
			$achat->tva196_total = $rows[1]/10000;
			$achat->qtetva196_total = $rows[2];
		}
		else if($rows[0]=='3'){
			$tva55++;
			$achat->tva55_total = $rows[1]/10000;
			$achat->qtetva55_total = $rows[2];
		}
		else if($rows[0]=='5'){
			$tva21++;
			$achat->tva21_total = $rows[1]/10000;
			$achat->qtetva21_total = $rows[2];
		}
	}
	echo $achat->qtetva0_total;
	echo $achat->qtetva196_total;
	echo $achat->qtetva55_total;
	echo $achat->qtetva21_total;
}
Toutes mes valeurs que j'ai mis en echo à la fin sont à zéro.

Mammouth du PHP | 1353 Messages

25 avr. 2008, 12:31

Pour le premier problème je ne suis pas sur des attributs par défaut des fonctions, ne faudrait il pas que les fonctions soient "public" ?

Sur le deuxième problème il est possible que cela signifie simplement que votre requete ne retourne aucun résultat. Comme vous déclarer vos variables avec la valeur 0, si l'on ne rentre pas dans la boucle while elle reste à 0...

Faites un echo mysql_num_rows($result); avant le while pour vérifier. Si cela affiche 0 le problème est dans la requete....
Tell me and I forget. Teach me and I remember. Involve me and I learn.

charlottebardet
Invité n'ayant pas de compte PHPfrance

25 avr. 2008, 15:58

"Pour le premier problème je ne suis pas sur des attributs par défaut des fonctions, ne faudrait il pas que les fonctions soient "public" ? "

Comment ça 'public' ?


"Sur le deuxième problème il est possible que cela signifie simplement que votre requete ne retourne aucun résultat. Comme vous déclarer vos variables avec la valeur 0, si l'on ne rentre pas dans la boucle while elle reste à 0...

Faites un echo mysql_num_rows($result); avant le while pour vérifier. Si cela affiche 0 le problème est dans la requete...."

Le problème est donc bien dans la requête !! :wink: Mais quesqu'elle a ma réquête.... :(

Mammouth du PHP | 1353 Messages

25 avr. 2008, 16:07

Je ne suis pas sur pour php5 car je maitrise pas à fond mais dans d'autre langages lorsque l'on veut utiliser une fonction d'une classe en dehors de la classe il faut la déclarer comme public :
public function MaFonction()
{
}
Sinon pour ta requete soit elle n'est pas correcte syntaxiquement soit elle ne renvoi aucun résultat... Es tu sure d'avoir dans tes donnée des réponses possibles pour cette requete ?
Tell me and I forget. Teach me and I remember. Involve me and I learn.

Invité
Invité n'ayant pas de compte PHPfrance

25 avr. 2008, 16:11

Cette requête marchait très bien quand ma fonction était dans le fichier cls_achat.php de ma classe achat.

Sachant que je ne l'ai pas du tout modifiée mis à part les $this->debut., $this->fin. que j'ai transformé en $achat->debut, $achat->fin, quelle erreur pourrait faire qu'elle ne marche plus maintenant ?
$result = mssql_query("SELECT ligcom.code_tva, sum(cast(ligcom.qterec_ligcom*ligcom.prixremht_ligcom as bigint)), sum(ligcom.qterec_ligcom) 
FROM (ligcom LEFT JOIN com on ligcom.id_com=com.id_com)
WHERE ligcom.qterec_ligcom <> 0
AND CASE WHEN com.dtliv_com IS NOT NULL THEN (com.dtliv_com)
ELSE CASE WHEN com.dprevliv_com IS NOT NULL THEN (com.dprevliv_com)
ELSE (com.dtenvoi_com) END END >= '".$achat->debut."'
AND CASE WHEN com.dtliv_com IS NOT NULL THEN (com.dtliv_com)
ELSE CASE WHEN com.dprevliv_com IS NOT NULL THEN (com.dprevliv_com)
ELSE (com.dtenvoi_com) END END  <= '".$achat->fin."'
GROUP BY ligcom.code_tva
ORDER BY ligcom.code_tva");

Mammouth du PHP | 1353 Messages

25 avr. 2008, 16:17

Peut etre les valeurs de $achat->debut et $achat->fin... Les as tu testé ? Sont elles cohérentes ?
Tell me and I forget. Teach me and I remember. Involve me and I learn.

Invité
Invité n'ayant pas de compte PHPfrance

25 avr. 2008, 16:27

Bon alors j'ai fait d'une autre façon :
require_once('../classes/cls_achat.php');

if($_GET['action'] == 'fonctiontest') {
	echo "calcul_tva";
	$achat->calcul_TVA_TOTAL();	
}


if($_GET['action'] == 'aff_tva&h='+h+'&sens='+sens) {
	echo "aff_tva";
	$achat->aff_tva($h,$sens);
}  

Sauf qu'il trouve pas mes fonctions qui sont dans mon fichier cls_achat.php :?

Modérateur PHPfrance
Modérateur PHPfrance | 6037 Messages

25 avr. 2008, 17:33

Au début de ton script, ajoute la ligne PHP suivante :
error_reporting(E_ALL);
Tu verras s'il y a un souci.
Quel est le message ? Qu'il ne trouve pas tes méthodes?
Règle n°2 du webmaster : Toujours commencer par le HTML qu'on veut obtenir....toujours ! :priere:
J'aime apprendre de nouvelles choses.

Modérateur PHPfrance
Modérateur PHPfrance | 6037 Messages

25 avr. 2008, 17:37

Modération :
charlottebardet, afin d'améliorer la lisibilité de ton message,
pense à utiliser les balises [code] ou [php] (selon le langage utilisé).

Elles sont disponibles au-dessus de la zone de saisie de ton message
lorsque tu postes un nouveau message.

Des indications sont disponibles sur la manière de mettre en forme vos messages dans la FAQ

Tu peux réaliser cette opération toi-même en éditant tes messages si tu as posté le 1er message en tant que membre (inscrit et identifié). Je l'ai fait pour toi.

Alors... inscris-toi !!! ;)