diff --git a/htdocs/cashdesk/facturation_dhtml.php b/htdocs/cashdesk/facturation_dhtml.php
index bc566052f86ee99bdc8dadf46e624e018137a98b..cf5b262774cc2c2f060d52cb98fcf2a123d25f20 100644
--- a/htdocs/cashdesk/facturation_dhtml.php
+++ b/htdocs/cashdesk/facturation_dhtml.php
@@ -29,55 +29,55 @@ $langs->load("@cashdesk");
 // Verification
 if ( strlen ($_GET["code"]) >= 0 )	// If at least one key
 {
-	$request="SELECT p.rowid, p.ref, p.label, p.tva_tx
-			FROM ".MAIN_DB_PREFIX."product as p
-			LEFT JOIN ".MAIN_DB_PREFIX."product_stock as ps ON p.rowid = ps.fk_product
-			WHERE p.envente = 1
-				AND p.fk_product_type = 0";
-	if ($conf->stock->enabled) $request.="	AND ps.fk_entrepot = '".$conf_fkentrepot."'";
-	$request.="	AND (p.ref LIKE '%".$_GET['code']."%'
-				OR p.label LIKE '%".$_GET['code']."%')
-			ORDER BY label";
-	dol_syslog($request);
-	$res = $db->query ($request);
+	$sql = "SELECT p.rowid, p.ref, p.label, p.tva_tx";
+	$sql.= " FROM ".MAIN_DB_PREFIX."product as p";
+	if ($conf->stock->enabled && !empty($conf_fkentrepot)) $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product_stock as ps ON p.rowid = ps.fk_product";
+	$sql.= " WHERE p.envente = 1";
+	$sql.= " AND p.fk_product_type = 0";
+	if ($conf->stock->enabled && !empty($conf_fkentrepot)) $sql.=" AND ps.fk_entrepot = '".$conf_fkentrepot."'";
+	$sql.= " AND (p.ref LIKE '%".$_GET['code']."%' OR p.label LIKE '%".$_GET['code']."%')";
+	$sql.= " ORDER BY label";
+	
+	dol_syslog($sql);
+	$result = $db->query($sql);
 
-	if ( $nbr = $db->num_rows($res) ) {
-
-		$resultat = '<ul class="dhtml_bloc">';
-
-		$ret=array(); $i=0;
-		while ( $tab = $db->fetch_array($res) )
+	if ($result)
+	{
+		if ( $nbr = $db->num_rows($result) )
 		{
-			foreach ( $tab as $cle => $valeur )
+			$resultat = '<ul class="dhtml_bloc">';
+			
+			$ret=array(); $i=0;
+			while ( $tab = $db->fetch_array($result) )
 			{
-				$ret[$i][$cle] = $valeur;
+				foreach ( $tab as $cle => $valeur )
+				{
+					$ret[$i][$cle] = $valeur;
+				}
+				$i++;
 			}
-			$i++;
-		}
-		$tab=$ret;
-
-		for ( $i = 0; $i < count ($tab); $i++ ) {
-
-			$resultat .= '
+			$tab=$ret;
+			
+			for ( $i = 0; $i < count ($tab); $i++ )
+			{
+				$resultat .= '
 					<li class="dhtml_defaut" title="'.$tab[$i]['ref'].'"
 						onMouseOver="javascript: this.className = \'dhtml_selection\';"
 						onMouseOut="javascript: this.className = \'dhtml_defaut\';"
 					">'.htmlentities($tab[$i]['ref'].' - '.$tab[$i]['label']).'</li>
 				';
-
+			}
+			
+			$resultat .= '</ul>';
+			
+			print $resultat;
+		}
+		else
+		{
+			print '<ul class="dhtml_bloc">';
+			print '<li class="dhtml_defaut">'.$langs->trans("NoResults").'</li>';
+			print '</ul>';
 		}
-
-		$resultat .= '</ul>';
-
-		echo $resultat;
-
-	} else {
-		echo ('
-				<ul class="dhtml_bloc">
-					<li class="dhtml_defaut">'.$langs->trans("NoResults").'</li>
-				</ul>
-			');
-
 	}
 
 }
diff --git a/htdocs/cashdesk/facturation_verif.php b/htdocs/cashdesk/facturation_verif.php
index 6de317a009115919ba9d767657b2b04846a5d25c..2c5bda9cb13d7ad6ce5ea4cccd7fc6b817a01c44 100644
--- a/htdocs/cashdesk/facturation_verif.php
+++ b/htdocs/cashdesk/facturation_verif.php
@@ -25,88 +25,86 @@ $obj_facturation = unserialize ($_SESSION['serObjFacturation']);
 unset ($_SESSION['serObjFacturation']);
 
 
-switch ( $_GET['action'] ) {
-
+switch ( $_GET['action'] )
+{
 	default:
-		if ( $_POST['hdnSource'] != 'NULL' ) {
-
-			// Recuperation des donnees en fonction de la source (liste d�roulante ou champ texte) ...
-			if ( $_POST['hdnSource'] == 'LISTE' ) {
-
-				$res = $db->query('SELECT fk_product, ref, price, reel, tva_tx
-								FROM '.MAIN_DB_PREFIX.'product
-								LEFT JOIN '.MAIN_DB_PREFIX.'product_stock ON '.MAIN_DB_PREFIX.'product.rowid = '.MAIN_DB_PREFIX.'product_stock.fk_product
-								WHERE fk_product = '.$_POST['selProduit'].'
-								;');
-
-			} else if ( $_POST['hdnSource'] == 'REF' ) {
-
-				$res = $db->query('SELECT fk_product, ref, price, reel, tva_tx
-								FROM '.MAIN_DB_PREFIX.'product
-								LEFT JOIN '.MAIN_DB_PREFIX.'product_stock ON '.MAIN_DB_PREFIX.'product.rowid = '.MAIN_DB_PREFIX.'product_stock.fk_product
-								WHERE ref = \''.$_POST['txtRef'].'\'
-								;');
-
+		if ( $_POST['hdnSource'] != 'NULL' )
+		{
+			$sql = "SELECT p.rowid, p.ref, p.price, p.tva_tx";
+			if ($conf->stock->enabled && !empty($conf_fkentrepot)) $sql.= ", ps.reel";
+			$sql.= " FROM ".MAIN_DB_PREFIX."product as p";
+			if ($conf->stock->enabled && !empty($conf_fkentrepot)) $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product_stock as ps ON p.rowid = ps.fk_product";
+			
+			// Recuperation des donnees en fonction de la source (liste deroulante ou champ texte) ...
+			if ( $_POST['hdnSource'] == 'LISTE' )
+			{
+				$sql.= " WHERE p.rowid = ".$_POST['selProduit'];
 			}
-
-
-
-			// ... et enregistrement dans l'objet
-			if ( $db->num_rows ($res) ) {
-
-				$ret=array();
-				$tab = $db->fetch_array($res);
-				foreach ( $tab as $cle => $valeur )
+			else if ( $_POST['hdnSource'] == 'REF' )
+			{
+				$sql.= " WHERE p.ref = '".$_POST['txtRef']."'";
+			}
+			if ($conf->stock->enabled && !empty($conf_fkentrepot)) $sql.= " AND ps.fk_entrepot = ".$conf_fkentrepot;
+			
+			$result = $db->query($sql);
+			
+			if ($result)
+			{
+				// ... et enregistrement dans l'objet
+				if ( $db->num_rows ($result) )
 				{
-					$ret[$cle] = $valeur;
+					$ret=array();
+					$tab = $db->fetch_array($result);
+					foreach ( $tab as $key => $value )
+					{
+						$ret[$key] = $value;
+					}
+					
+					$obj_facturation->id( $ret['rowid'] );
+					$obj_facturation->ref( $ret['ref'] );
+					$obj_facturation->stock( $ret['reel'] );
+					$obj_facturation->prix( $ret['price'] );
+					$obj_facturation->tva( $ret['tva_tx'] );
+					
+					// Definition du filtre pour n'afficher que le produit concerne
+					if ( $_POST['hdnSource'] == 'LISTE' )
+					{
+						$filtre = $ret['ref'];
+					}
+					else if ( $_POST['hdnSource'] == 'REF' )
+					{
+						$filtre = $_POST['txtRef'];
+					}
+					
+					$redirection = DOL_URL_ROOT.'/cashdesk/affIndex.php?menu=facturation&filtre='.$filtre;
 				}
-				$tab = $ret;
-
-				$obj_facturation->id( $tab['fk_product'] );
-				$obj_facturation->ref( $tab['ref'] );
-				$obj_facturation->stock( $tab['reel']);
-				$obj_facturation->prix( $tab['price'] );
-				$obj_facturation->tva( $tab['tva_tx'] );
-
-				// Definition du filtre pour n'afficher que le produit concerne
-				if ( $_POST['hdnSource'] == 'LISTE' ) {
-
-					$filtre = $tab['ref'];
-
-				} else if ( $_POST['hdnSource'] == 'REF' ) {
-
-					$filtre = $_POST['txtRef'];;
-
-				}
-
-
-				$redirection = DOL_URL_ROOT.'/cashdesk/affIndex.php?menu=facturation&filtre='.$filtre;
-
-			} else {
-
-				$obj_facturation->raz();
-
-				if ( $_POST['hdnSource'] == 'REF' ) {
-
-					$redirection = DOL_URL_ROOT.'/cashdesk/affIndex.php?menu=facturation&filtre='.$_POST['txtRef'];
-
-				} else {
-
-					$redirection = DOL_URL_ROOT.'/cashdesk/affIndex.php?menu=facturation';
-
+				else
+				{
+					$obj_facturation->raz();
+					
+					if ( $_POST['hdnSource'] == 'REF' )
+					{
+						$redirection = DOL_URL_ROOT.'/cashdesk/affIndex.php?menu=facturation&filtre='.$_POST['txtRef'];
+					}
+					else
+					{
+						$redirection = DOL_URL_ROOT.'/cashdesk/affIndex.php?menu=facturation';
+					}
 				}
-
 			}
-
-		} else {
-
+			else
+			{
+				dol_print_error($db);
+			}
+		}
+		else
+		{
 			$redirection = DOL_URL_ROOT.'/cashdesk/affIndex.php?menu=facturation';
-
 		}
 
-		break;
+	break;
 
-	case 'ajout_article';
+	case 'ajout_article':
 	$obj_facturation->qte($_POST['txtQte']);
 	$obj_facturation->tva($_POST['selTva']);
 	$obj_facturation->remise_percent($_POST['txtRemise']);
@@ -116,10 +114,10 @@ switch ( $_GET['action'] ) {
 	break;
 
 	case 'suppr_article':
-		$obj_facturation->supprArticle($_GET['suppr_id']);
+	$obj_facturation->supprArticle($_GET['suppr_id']);
 
-		$redirection = DOL_URL_ROOT.'/cashdesk/affIndex.php?menu=facturation';
-		break;
+	$redirection = DOL_URL_ROOT.'/cashdesk/affIndex.php?menu=facturation';
+	break;
 
 }