فهرست منبع

FIX convert product class

Regis Houssin 3 سال پیش
والد
کامیت
116bcd1bdc

+ 23 - 23
htdocs/product/class/api_products.class.php

@@ -188,21 +188,21 @@ class Products extends DolibarrApi
 		$socid = DolibarrApiAccess::$user->socid ? DolibarrApiAccess::$user->socid : '';
 
 		$sql = "SELECT t.rowid, t.ref, t.ref_ext";
-		$sql .= " FROM ".MAIN_DB_PREFIX."product as t";
+		$sql .= " FROM ".$this->db->prefix()."product as t";
 		if ($category > 0) {
-			$sql .= ", ".MAIN_DB_PREFIX."categorie_product as c";
+			$sql .= ", ".$this->db->prefix()."categorie_product as c";
 		}
 		$sql .= ' WHERE t.entity IN ('.getEntity('product').')';
 
 		if ($variant_filter == 1) {
-			$sql .= ' AND t.rowid not in (select distinct fk_product_parent from '.MAIN_DB_PREFIX.'product_attribute_combination)';
-			$sql .= ' AND t.rowid not in (select distinct fk_product_child from '.MAIN_DB_PREFIX.'product_attribute_combination)';
+			$sql .= ' AND t.rowid not in (select distinct fk_product_parent from '.$this->db->prefix().'product_attribute_combination)';
+			$sql .= ' AND t.rowid not in (select distinct fk_product_child from '.$this->db->prefix().'product_attribute_combination)';
 		}
 		if ($variant_filter == 2) {
-			$sql .= ' AND t.rowid in (select distinct fk_product_parent from '.MAIN_DB_PREFIX.'product_attribute_combination)';
+			$sql .= ' AND t.rowid in (select distinct fk_product_parent from '.$this->db->prefix().'product_attribute_combination)';
 		}
 		if ($variant_filter == 3) {
-			$sql .= ' AND t.rowid in (select distinct fk_product_child from '.MAIN_DB_PREFIX.'product_attribute_combination)';
+			$sql .= ' AND t.rowid in (select distinct fk_product_child from '.$this->db->prefix().'product_attribute_combination)';
 		}
 
 		// Select products of given category
@@ -861,11 +861,11 @@ class Products extends DolibarrApi
 		}
 
 		$sql = "SELECT t.rowid, t.ref, t.ref_ext";
-		$sql .= " FROM ".MAIN_DB_PREFIX."product as t";
+		$sql .= " FROM ".$this->db->prefix()."product as t";
 		if ($category > 0) {
-			$sql .= ", ".MAIN_DB_PREFIX."categorie_product as c";
+			$sql .= ", ".$this->db->prefix()."categorie_product as c";
 		}
-		$sql .= ", ".MAIN_DB_PREFIX."product_fournisseur_price as s";
+		$sql .= ", ".$this->db->prefix()."product_fournisseur_price as s";
 
 		$sql .= ' WHERE t.entity IN ('.getEntity('product').')';
 
@@ -1013,7 +1013,7 @@ class Products extends DolibarrApi
 		}
 
 		$sql = "SELECT t.rowid, t.ref, t.ref_ext, t.label, t.rang, t.entity";
-		$sql .= " FROM ".MAIN_DB_PREFIX."product_attribute as t";
+		$sql .= " FROM ".$this->db->prefix()."product_attribute as t";
 		$sql .= ' WHERE t.entity IN ('.getEntity('product').')';
 
 		// Add sql filters
@@ -1094,8 +1094,8 @@ class Products extends DolibarrApi
 			}
 		}
 
-		$sql = "SELECT COUNT(*) as nb FROM ".MAIN_DB_PREFIX."product_attribute_combination2val as pac2v";
-		$sql .= " JOIN ".MAIN_DB_PREFIX."product_attribute_combination as pac ON pac2v.fk_prod_combination = pac.rowid";
+		$sql = "SELECT COUNT(*) as nb FROM ".$this->db->prefix()."product_attribute_combination2val as pac2v";
+		$sql .= " JOIN ".$this->db->prefix()."product_attribute_combination as pac ON pac2v.fk_prod_combination = pac.rowid";
 		$sql .= " WHERE pac2v.fk_prod_attr = ".((int) $prodattr->id)." AND pac.entity IN (".getEntity('product').")";
 
 		$resql = $this->db->query($sql);
@@ -1122,7 +1122,7 @@ class Products extends DolibarrApi
 			throw new RestException(401);
 		}
 
-		$sql = "SELECT rowid, ref, ref_ext, label, rang, entity FROM ".MAIN_DB_PREFIX."product_attribute WHERE ref LIKE '".trim($ref)."' AND entity IN (".getEntity('product').")";
+		$sql = "SELECT rowid, ref, ref_ext, label, rang, entity FROM ".$this->db->prefix()."product_attribute WHERE ref LIKE '".trim($ref)."' AND entity IN (".getEntity('product').")";
 
 		$query = $this->db->query($sql);
 
@@ -1140,8 +1140,8 @@ class Products extends DolibarrApi
 		$attr['rang'] = $result->rang;
 		$attr['entity'] = $result->entity;
 
-		$sql = "SELECT COUNT(*) as nb FROM ".MAIN_DB_PREFIX."product_attribute_combination2val as pac2v";
-		$sql .= " JOIN ".MAIN_DB_PREFIX."product_attribute_combination as pac ON pac2v.fk_prod_combination = pac.rowid";
+		$sql = "SELECT COUNT(*) as nb FROM ".$this->db->prefix()."product_attribute_combination2val as pac2v";
+		$sql .= " JOIN ".$this->db->prefix()."product_attribute_combination as pac ON pac2v.fk_prod_combination = pac.rowid";
 		$sql .= " WHERE pac2v.fk_prod_attr = ".((int) $result->rowid)." AND pac.entity IN (".getEntity('product').")";
 
 		$resql = $this->db->query($sql);
@@ -1169,7 +1169,7 @@ class Products extends DolibarrApi
 			throw new RestException(401);
 		}
 
-		$sql = "SELECT rowid, ref, ref_ext, label, rang, entity FROM ".MAIN_DB_PREFIX."product_attribute WHERE ref_ext LIKE '".trim($ref_ext)."' AND entity IN (".getEntity('product').")";
+		$sql = "SELECT rowid, ref, ref_ext, label, rang, entity FROM ".$this->db->prefix()."product_attribute WHERE ref_ext LIKE '".trim($ref_ext)."' AND entity IN (".getEntity('product').")";
 
 		$query = $this->db->query($sql);
 
@@ -1187,8 +1187,8 @@ class Products extends DolibarrApi
 		$attr['rang'] = $result->rang;
 		$attr['entity'] = $result->entity;
 
-		$sql = "SELECT COUNT(*) as nb FROM ".MAIN_DB_PREFIX."product_attribute_combination2val as pac2v";
-		$sql .= " JOIN ".MAIN_DB_PREFIX."product_attribute_combination as pac ON pac2v.fk_prod_combination = pac.rowid";
+		$sql = "SELECT COUNT(*) as nb FROM ".$this->db->prefix()."product_attribute_combination2val as pac2v";
+		$sql .= " JOIN ".$this->db->prefix()."product_attribute_combination as pac ON pac2v.fk_prod_combination = pac.rowid";
 		$sql .= " WHERE pac2v.fk_prod_attr = ".((int) $result->rowid)." AND pac.entity IN (".getEntity('product').")";
 
 		$resql = $this->db->query($sql);
@@ -1322,7 +1322,7 @@ class Products extends DolibarrApi
 			throw new RestException(401);
 		}
 
-		$sql = "SELECT rowid, fk_product_attribute, ref, value FROM ".MAIN_DB_PREFIX."product_attribute_value WHERE rowid = ".(int) $id." AND entity IN (".getEntity('product').")";
+		$sql = "SELECT rowid, fk_product_attribute, ref, value FROM ".$this->db->prefix()."product_attribute_value WHERE rowid = ".(int) $id." AND entity IN (".getEntity('product').")";
 
 		$query = $this->db->query($sql);
 
@@ -1365,7 +1365,7 @@ class Products extends DolibarrApi
 
 		$ref = trim($ref);
 
-		$sql = "SELECT rowid, fk_product_attribute, ref, value FROM ".MAIN_DB_PREFIX."product_attribute_value";
+		$sql = "SELECT rowid, fk_product_attribute, ref, value FROM ".$this->db->prefix()."product_attribute_value";
 		$sql .= " WHERE ref LIKE '".$this->db->escape($ref)."' AND fk_product_attribute = ".((int) $id)." AND entity IN (".getEntity('product').")";
 
 		$query = $this->db->query($sql);
@@ -1408,7 +1408,7 @@ class Products extends DolibarrApi
 
 		$ref = trim($ref);
 
-		$sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."product_attribute_value";
+		$sql = "SELECT rowid FROM ".$this->db->prefix()."product_attribute_value";
 		$sql .= " WHERE ref LIKE '".$this->db->escape($ref)."' AND fk_product_attribute = ".((int) $id)." AND entity IN (".getEntity('product').")";
 		$query = $this->db->query($sql);
 
@@ -1485,8 +1485,8 @@ class Products extends DolibarrApi
 		$return = array();
 
 		$sql = 'SELECT ';
-		$sql .= 'v.fk_product_attribute, v.rowid, v.ref, v.value FROM '.MAIN_DB_PREFIX.'product_attribute_value as v';
-		$sql .= " WHERE v.fk_product_attribute IN (SELECT rowid FROM ".MAIN_DB_PREFIX."product_attribute WHERE ref LIKE '".$this->db->escape($ref)."')";
+		$sql .= 'v.fk_product_attribute, v.rowid, v.ref, v.value FROM '.$this->db->prefix().'product_attribute_value as v';
+		$sql .= " WHERE v.fk_product_attribute IN (SELECT rowid FROM ".$this->db->prefix()."product_attribute WHERE ref LIKE '".$this->db->escape($ref)."')";
 
 		$resql = $this->db->query($sql);
 

+ 6 - 6
htdocs/product/class/html.formproduct.class.php

@@ -102,12 +102,12 @@ class FormProduct
 		} elseif ($sumStock) {
 			$sql .= ", sum(ps.reel) as stock";
 		}
-		$sql .= " FROM ".MAIN_DB_PREFIX."entrepot as e";
-		$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product_stock as ps on ps.fk_entrepot = e.rowid";
+		$sql .= " FROM ".$this->db->prefix()."entrepot as e";
+		$sql .= " LEFT JOIN ".$this->db->prefix()."product_stock as ps on ps.fk_entrepot = e.rowid";
 		if (!empty($fk_product) && $fk_product > 0) {
 			$sql .= " AND ps.fk_product = ".((int) $fk_product);
 			if (!empty($batch)) {
-				$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product_batch as pb on pb.fk_product_stock = ps.rowid AND pb.batch = '".$this->db->escape($batch)."'";
+				$sql .= " LEFT JOIN ".$this->db->prefix()."product_batch as pb on pb.fk_product_stock = ps.rowid AND pb.batch = '".$this->db->escape($batch)."'";
 			}
 		}
 		$sql .= " WHERE e.entity IN (".getEntity('stock').")";
@@ -699,9 +699,9 @@ class FormProduct
 			$this->cache_lot = array();
 			$productIdList = implode(',', $productIdArray);
 			$sql = "SELECT pb.batch, pb.rowid, ps.fk_entrepot, pb.qty, e.ref as label, ps.fk_product";
-			$sql .= " FROM ".MAIN_DB_PREFIX."product_batch as pb";
-			$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product_stock as ps on ps.rowid = pb.fk_product_stock";
-			$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."entrepot as e on e.rowid = ps.fk_entrepot AND e.entity IN (".getEntity('stock').")";
+			$sql .= " FROM ".$this->db->prefix()."product_batch as pb";
+			$sql .= " LEFT JOIN ".$this->db->prefix()."product_stock as ps on ps.rowid = pb.fk_product_stock";
+			$sql .= " LEFT JOIN ".$this->db->prefix()."entrepot as e on e.rowid = ps.fk_entrepot AND e.entity IN (".getEntity('stock').")";
 			if (!empty($productIdList)) {
 				$sql .= " WHERE ps.fk_product IN (".$this->db->sanitize($productIdList).")";
 			}

+ 152 - 152
htdocs/product/class/product.class.php

@@ -689,7 +689,7 @@ class Product extends CommonObject
 
 		if ($result >= 0) {
 			$sql = "SELECT count(*) as nb";
-			$sql .= " FROM ".MAIN_DB_PREFIX."product";
+			$sql .= " FROM ".$this->db->prefix()."product";
 			$sql .= " WHERE entity IN (".getEntity('product').")";
 			$sql .= " AND ref = '".$this->db->escape($this->ref)."'";
 
@@ -698,7 +698,7 @@ class Product extends CommonObject
 				$obj = $this->db->fetch_object($result);
 				if ($obj->nb == 0) {
 					// Produit non deja existant
-					$sql = "INSERT INTO ".MAIN_DB_PREFIX."product (";
+					$sql = "INSERT INTO ".$this->db->prefix()."product (";
 					$sql .= "datec";
 					$sql .= ", entity";
 					$sql .= ", ref";
@@ -761,7 +761,7 @@ class Product extends CommonObject
 					dol_syslog(get_class($this)."::Create", LOG_DEBUG);
 					$result = $this->db->query($sql);
 					if ($result) {
-						$id = $this->db->last_insert_id(MAIN_DB_PREFIX."product");
+						$id = $this->db->last_insert_id($this->db->prefix()."product");
 
 						if ($id > 0) {
 							$this->id = $id;
@@ -782,9 +782,9 @@ class Product extends CommonObject
 
 							// update accountancy for this entity
 							if (!$error && !empty($conf->global->MAIN_PRODUCT_PERENTITY_SHARED)) {
-								$this->db->query("DELETE FROM " . MAIN_DB_PREFIX . "product_perentity WHERE fk_product = " .((int) $this->id) . " AND entity = " . ((int) $conf->entity));
+								$this->db->query("DELETE FROM " . $this->db->prefix() . "product_perentity WHERE fk_product = " .((int) $this->id) . " AND entity = " . ((int) $conf->entity));
 
-								$sql = "INSERT INTO " . MAIN_DB_PREFIX . "product_perentity (";
+								$sql = "INSERT INTO " . $this->db->prefix() . "product_perentity (";
 								$sql .= " fk_product";
 								$sql .= ", entity";
 								$sql .= ", accountancy_code_buy";
@@ -1062,7 +1062,7 @@ class Product extends CommonObject
 					foreach ($ObjW->detail_batch as $detail) {    // Each lines of detail in product_batch of the current $ObjW = product_stock
 						if ($detail->batch == $valueforundefinedlot || $detail->batch == 'Undefined') {
 							// We discard this line, we will create it later
-							$sqlclean = "DELETE FROM ".MAIN_DB_PREFIX."product_batch WHERE batch in('Undefined', '".$this->db->escape($valueforundefinedlot)."') AND fk_product_stock = ".((int) $ObjW->id);
+							$sqlclean = "DELETE FROM ".$this->db->prefix()."product_batch WHERE batch in('Undefined', '".$this->db->escape($valueforundefinedlot)."') AND fk_product_stock = ".((int) $ObjW->id);
 							$result = $this->db->query($sqlclean);
 							if (!$result) {
 								dol_print_error($this->db);
@@ -1094,7 +1094,7 @@ class Product extends CommonObject
 				$this->barcode = $this->get_barcode($this, $this->barcode_type_code);
 			}
 
-			$sql = "UPDATE ".MAIN_DB_PREFIX."product";
+			$sql = "UPDATE ".$this->db->prefix()."product";
 			$sql .= " SET label = '".$this->db->escape($this->label)."'";
 
 			if ($updatetype && ($this->isProduct() || $this->isService())) {
@@ -1182,9 +1182,9 @@ class Product extends CommonObject
 
 				// update accountancy for this entity
 				if (!$error && !empty($conf->global->MAIN_PRODUCT_PERENTITY_SHARED)) {
-					$this->db->query("DELETE FROM " . MAIN_DB_PREFIX . "product_perentity WHERE fk_product = " . ((int) $this->id) . " AND entity = " . ((int) $conf->entity));
+					$this->db->query("DELETE FROM " . $this->db->prefix() . "product_perentity WHERE fk_product = " . ((int) $this->id) . " AND entity = " . ((int) $conf->entity));
 
-					$sql = "INSERT INTO " . MAIN_DB_PREFIX . "product_perentity (";
+					$sql = "INSERT INTO " . $this->db->prefix() . "product_perentity (";
 					$sql .= " fk_product";
 					$sql .= ", entity";
 					$sql .= ", accountancy_code_buy";
@@ -1327,9 +1327,9 @@ class Product extends CommonObject
 
 			// Delete from product_batch on product delete
 			if (!$error) {
-				$sql = "DELETE FROM ".MAIN_DB_PREFIX.'product_batch';
+				$sql = "DELETE FROM ".$this->db->prefix().'product_batch';
 				$sql .= " WHERE fk_product_stock IN (";
-				$sql .= "SELECT rowid FROM ".MAIN_DB_PREFIX.'product_stock';
+				$sql .= "SELECT rowid FROM ".$this->db->prefix().'product_stock';
 				$sql .= " WHERE fk_product = ".((int) $this->id).")";
 
 				$result = $this->db->query($sql);
@@ -1344,7 +1344,7 @@ class Product extends CommonObject
 				$elements = array('product_fournisseur_price', 'product_price', 'product_lang', 'categorie_product', 'product_stock', 'product_customer_price', 'product_lot'); // product_batch is done before
 				foreach ($elements as $table) {
 					if (!$error) {
-						$sql = "DELETE FROM ".MAIN_DB_PREFIX.$table;
+						$sql = "DELETE FROM ".$this->db->prefix().$table;
 						$sql .= " WHERE fk_product = ".(int) $this->id;
 
 						$result = $this->db->query($sql);
@@ -1377,7 +1377,7 @@ class Product extends CommonObject
 
 			// Delete from product_association
 			if (!$error) {
-				$sql = "DELETE FROM ".MAIN_DB_PREFIX."product_association";
+				$sql = "DELETE FROM ".$this->db->prefix()."product_association";
 				$sql .= " WHERE fk_product_pere = ".(int) $this->id." OR fk_product_fils = ".(int) $this->id;
 
 				$result = $this->db->query($sql);
@@ -1398,7 +1398,7 @@ class Product extends CommonObject
 
 			// Delete product
 			if (!$error) {
-				$sqlz = "DELETE FROM ".MAIN_DB_PREFIX."product";
+				$sqlz = "DELETE FROM ".$this->db->prefix()."product";
 				$sqlz .= " WHERE rowid = ".(int) $this->id;
 
 				$resultz = $this->db->query($sqlz);
@@ -1456,14 +1456,14 @@ class Product extends CommonObject
 		foreach ($langs_available as $key => $value) {
 			if ($key == $current_lang) {
 				$sql = "SELECT rowid";
-				$sql .= " FROM ".MAIN_DB_PREFIX."product_lang";
+				$sql .= " FROM ".$this->db->prefix()."product_lang";
 				$sql .= " WHERE fk_product = ".((int) $this->id);
 				$sql .= " AND lang = '".$this->db->escape($key)."'";
 
 				$result = $this->db->query($sql);
 
 				if ($this->db->num_rows($result)) { // if there is already a description line for this language
-					$sql2 = "UPDATE ".MAIN_DB_PREFIX."product_lang";
+					$sql2 = "UPDATE ".$this->db->prefix()."product_lang";
 					$sql2 .= " SET ";
 					$sql2 .= " label='".$this->db->escape($this->label)."',";
 					$sql2 .= " description='".$this->db->escape($this->description)."'";
@@ -1472,7 +1472,7 @@ class Product extends CommonObject
 					}
 					$sql2 .= " WHERE fk_product = ".((int) $this->id)." AND lang = '".$this->db->escape($key)."'";
 				} else {
-					$sql2 = "INSERT INTO ".MAIN_DB_PREFIX."product_lang (fk_product, lang, label, description";
+					$sql2 = "INSERT INTO ".$this->db->prefix()."product_lang (fk_product, lang, label, description";
 					if (!empty($conf->global->PRODUCT_USE_OTHER_FIELD_IN_TRANSLATION)) {
 						$sql2 .= ", note";
 					}
@@ -1496,14 +1496,14 @@ class Product extends CommonObject
 				}
 
 				$sql = "SELECT rowid";
-				$sql .= " FROM ".MAIN_DB_PREFIX."product_lang";
+				$sql .= " FROM ".$this->db->prefix()."product_lang";
 				$sql .= " WHERE fk_product = ".((int) $this->id);
 				$sql .= " AND lang = '".$this->db->escape($key)."'";
 
 				$result = $this->db->query($sql);
 
 				if ($this->db->num_rows($result)) { // if there is already a description line for this language
-					$sql2 = "UPDATE ".MAIN_DB_PREFIX."product_lang";
+					$sql2 = "UPDATE ".$this->db->prefix()."product_lang";
 					$sql2 .= " SET ";
 					$sql2 .= " label = '".$this->db->escape($this->multilangs["$key"]["label"])."',";
 					$sql2 .= " description = '".$this->db->escape($this->multilangs["$key"]["description"])."'";
@@ -1512,7 +1512,7 @@ class Product extends CommonObject
 					}
 					$sql2 .= " WHERE fk_product = ".((int) $this->id)." AND lang = '".$this->db->escape($key)."'";
 				} else {
-					$sql2 = "INSERT INTO ".MAIN_DB_PREFIX."product_lang (fk_product, lang, label, description";
+					$sql2 = "INSERT INTO ".$this->db->prefix()."product_lang (fk_product, lang, label, description";
 					if (!empty($conf->global->PRODUCT_USE_OTHER_FIELD_IN_TRANSLATION)) {
 						$sql2 .= ", note";
 					}
@@ -1558,7 +1558,7 @@ class Product extends CommonObject
 	 */
 	public function delMultiLangs($langtodelete, $user)
 	{
-		$sql = "DELETE FROM ".MAIN_DB_PREFIX."product_lang";
+		$sql = "DELETE FROM ".$this->db->prefix()."product_lang";
 		$sql .= " WHERE fk_product = ".((int) $this->id)." AND lang = '".$this->db->escape($langtodelete)."'";
 
 		dol_syslog(get_class($this).'::delMultiLangs', LOG_DEBUG);
@@ -1612,7 +1612,7 @@ class Product extends CommonObject
 			return -1;
 		}
 
-		$sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element." SET ";
+		$sql = "UPDATE ".$this->db->prefix().$this->table_element." SET ";
 		$sql .= "$field = '".$this->db->escape($value)."'";
 		$sql .= " WHERE rowid = ".((int) $this->id);
 
@@ -1655,7 +1655,7 @@ class Product extends CommonObject
 		$current_lang = $langs->getDefaultLang();
 
 		$sql = "SELECT lang, label, description, note as other";
-		$sql .= " FROM ".MAIN_DB_PREFIX."product_lang";
+		$sql .= " FROM ".$this->db->prefix()."product_lang";
 		$sql .= " WHERE fk_product = ".((int) $this->id);
 
 		$result = $this->db->query($sql);
@@ -1731,7 +1731,7 @@ class Product extends CommonObject
 		}
 
 		// Add new price
-		$sql = "INSERT INTO ".MAIN_DB_PREFIX."product_price(price_level,date_price, fk_product, fk_user_author, price, price_ttc, price_base_type,tosell, tva_tx, default_vat_code, recuperableonly,";
+		$sql = "INSERT INTO ".$this->db->prefix()."product_price(price_level,date_price, fk_product, fk_user_author, price, price_ttc, price_base_type,tosell, tva_tx, default_vat_code, recuperableonly,";
 		$sql .= " localtax1_tx, localtax2_tx, localtax1_type, localtax2_type, price_min,price_min_ttc,price_by_qty,entity,fk_price_expression) ";
 		$sql .= " VALUES(".($level ? ((int) $level) : 1).", '".$this->db->idate($now)."', ".((int) $this->id).", ".((int) $user->id).", ".((float) price2num($this->price)).", ".((float) price2num($this->price_ttc)).",'".$this->db->escape($this->price_base_type)."',".((int) $this->status).", ".((float) price2num($this->tva_tx)).", ".($this->default_vat_code ? ("'".$this->db->escape($this->default_vat_code)."'") : "null").", ".((int) $this->tva_npr).",";
 		$sql .= " ".price2num($this->localtax1_tx).", ".price2num($this->localtax2_tx).", '".$this->db->escape($this->localtax1_type)."', '".$this->db->escape($this->localtax2_type)."', ".price2num($this->price_min).", ".price2num($this->price_min_ttc).", ".price2num($this->price_by_qty).", ".((int) $conf->entity).",".($this->fk_price_expression > 0 ? ((int) $this->fk_price_expression) : 'null');
@@ -1760,11 +1760,11 @@ class Product extends CommonObject
 	public function log_price_delete($user, $rowid)
 	{
 		// phpcs:enable
-		$sql = "DELETE FROM ".MAIN_DB_PREFIX."product_price_by_qty";
+		$sql = "DELETE FROM ".$this->db->prefix()."product_price_by_qty";
 		$sql .= " WHERE fk_product_price = ".((int) $rowid);
 		$resql = $this->db->query($sql);
 
-		$sql = "DELETE FROM ".MAIN_DB_PREFIX."product_price";
+		$sql = "DELETE FROM ".$this->db->prefix()."product_price";
 		$sql .= " WHERE rowid=".((int) $rowid);
 		$resql = $this->db->query($sql);
 		if ($resql) {
@@ -1912,7 +1912,7 @@ class Product extends CommonObject
 		if (!empty($conf->global->PRODUCT_USE_SUPPLIER_PACKAGING)) {
 			$sql .= ", pfp.packaging";
 		}
-		$sql .= " FROM ".MAIN_DB_PREFIX."product_fournisseur_price as pfp";
+		$sql .= " FROM ".$this->db->prefix()."product_fournisseur_price as pfp";
 		$sql .= " WHERE pfp.rowid = ".((int) $prodfournprice);
 		if ($qty > 0) {
 			$sql .= " AND pfp.quantity <= ".((float) $qty);
@@ -1966,7 +1966,7 @@ class Product extends CommonObject
 				$sql .= " pfp.default_vat_code,";
 				$sql .= " pfp.multicurrency_price, pfp.multicurrency_unitprice, pfp.multicurrency_tx, pfp.fk_multicurrency, pfp.multicurrency_code,";
 				$sql .= " pfp.packaging";
-				$sql .= " FROM ".MAIN_DB_PREFIX."product_fournisseur_price as pfp";
+				$sql .= " FROM ".$this->db->prefix()."product_fournisseur_price as pfp";
 				$sql .= " WHERE pfp.fk_product = ".((int) $product_id);
 				if ($fourn_ref != 'none') {
 					$sql .= " AND pfp.ref_fourn = '".$this->db->escape($fourn_ref)."'";
@@ -2146,7 +2146,7 @@ class Product extends CommonObject
 
 			// Ne pas mettre de quote sur les numeriques decimaux.
 			// Ceci provoque des stockages avec arrondis en base au lieu des valeurs exactes.
-			$sql = "UPDATE ".MAIN_DB_PREFIX."product SET";
+			$sql = "UPDATE ".$this->db->prefix()."product SET";
 			$sql .= " price_base_type='".$this->db->escape($newpricebase)."',";
 			$sql .= " price=".$price.",";
 			$sql .= " price_ttc=".$price_ttc.",";
@@ -2276,7 +2276,7 @@ class Product extends CommonObject
 		$separatedStock = false;		// Set to true will count stock from subtable llx_product_stock. It is slower than using denormalized field 'stock', but it is required when using multientity and shared warehouses.
 		if (!empty($conf->global->MULTICOMPANY_PRODUCT_SHARING_ENABLED)) {
 			if (!empty($conf->global->MULTICOMPANY_PMP_PER_ENTITY_ENABLED)) {
-				$checkPMPPerEntity = $this->db->query("SELECT pmp FROM " . MAIN_DB_PREFIX . "product_perentity WHERE fk_product = ".((int) $id)." AND entity = ".(int) $conf->entity);
+				$checkPMPPerEntity = $this->db->query("SELECT pmp FROM " . $this->db->prefix() . "product_perentity WHERE fk_product = ".((int) $id)." AND entity = ".(int) $conf->entity);
 				if ($this->db->num_rows($checkPMPPerEntity)>0) {
 					$separatedEntityPMP = true;
 				}
@@ -2300,12 +2300,12 @@ class Product extends CommonObject
 		} else {
 			$sql .= " p.stock";
 		}
-		$sql .= " FROM ".MAIN_DB_PREFIX."product as p";
+		$sql .= " FROM ".$this->db->prefix()."product as p";
 		if (!empty($conf->global->MAIN_PRODUCT_PERENTITY_SHARED) || $separatedEntityPMP) {
-			$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "product_perentity as ppe ON ppe.fk_product = p.rowid AND ppe.entity = " . ((int) $conf->entity);
+			$sql .= " LEFT JOIN " . $this->db->prefix() . "product_perentity as ppe ON ppe.fk_product = p.rowid AND ppe.entity = " . ((int) $conf->entity);
 		}
 		if ($separatedStock) {
-			$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "product_stock as sp ON sp.fk_product = p.rowid AND sp.fk_entrepot IN (SELECT rowid FROM ".MAIN_DB_PREFIX."entrepot WHERE entity IN (".$this->db->sanitize($visibleWarehousesEntities)."))";
+			$sql .= " LEFT JOIN " . $this->db->prefix() . "product_stock as sp ON sp.fk_product = p.rowid AND sp.fk_entrepot IN (SELECT rowid FROM ".$this->db->prefix()."entrepot WHERE entity IN (".$this->db->sanitize($visibleWarehousesEntities)."))";
 		}
 
 		if ($id) {
@@ -2455,7 +2455,7 @@ class Product extends CommonObject
 					for ($i = 1; $i <= $conf->global->PRODUIT_MULTIPRICES_LIMIT; $i++) {
 						$sql = "SELECT price, price_ttc, price_min, price_min_ttc,";
 						$sql .= " price_base_type, tva_tx, default_vat_code, tosell, price_by_qty, rowid, recuperableonly";
-						$sql .= " FROM ".MAIN_DB_PREFIX."product_price";
+						$sql .= " FROM ".$this->db->prefix()."product_price";
 						$sql .= " WHERE entity IN (".getEntity('productprice').")";
 						$sql .= " AND price_level=".((int) $i);
 						$sql .= " AND fk_product = ".((int) $this->id);
@@ -2482,7 +2482,7 @@ class Product extends CommonObject
 							 if ($this->prices_by_qty[$i] == 1)
 							 {
 							 $sql = "SELECT rowid, price, unitprice, quantity, remise_percent, remise, price_base_type";
-							 $sql.= " FROM ".MAIN_DB_PREFIX."product_price_by_qty";
+							 $sql.= " FROM ".$this->db->prefix()."product_price_by_qty";
 							 $sql.= " WHERE fk_product_price = ".((int) $this->prices_by_qty_id[$i]);
 							 $sql.= " ORDER BY quantity ASC";
 							 $resultat=array();
@@ -2519,7 +2519,7 @@ class Product extends CommonObject
 				} elseif (!empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY) && empty($ignore_price_load)) {    // prices per quantity
 					$sql = "SELECT price, price_ttc, price_min, price_min_ttc,";
 					$sql .= " price_base_type, tva_tx, default_vat_code, tosell, price_by_qty, rowid";
-					$sql .= " FROM ".MAIN_DB_PREFIX."product_price";
+					$sql .= " FROM ".$this->db->prefix()."product_price";
 					$sql .= " WHERE fk_product = ".((int) $this->id);
 					$sql .= " ORDER BY date_price DESC, rowid DESC";
 					$sql .= " LIMIT 1";
@@ -2533,7 +2533,7 @@ class Product extends CommonObject
 						// Récuperation de la liste des prix selon qty si flag positionné
 						if ($this->prices_by_qty[0] == 1) {
 							$sql = "SELECT rowid,price, unitprice, quantity, remise_percent, remise, remise, price_base_type";
-							$sql .= " FROM ".MAIN_DB_PREFIX."product_price_by_qty";
+							$sql .= " FROM ".$this->db->prefix()."product_price_by_qty";
 							$sql .= " WHERE fk_product_price = ".((int) $this->prices_by_qty_id[0]);
 							$sql .= " ORDER BY quantity ASC";
 							$resultat = array();
@@ -2565,7 +2565,7 @@ class Product extends CommonObject
 					for ($i = 1; $i <= $conf->global->PRODUIT_MULTIPRICES_LIMIT; $i++) {
 						$sql = "SELECT price, price_ttc, price_min, price_min_ttc,";
 						$sql .= " price_base_type, tva_tx, default_vat_code, tosell, price_by_qty, rowid, recuperableonly";
-						$sql .= " FROM ".MAIN_DB_PREFIX."product_price";
+						$sql .= " FROM ".$this->db->prefix()."product_price";
 						$sql .= " WHERE entity IN (".getEntity('productprice').")";
 						$sql .= " AND price_level=".((int) $i);
 						$sql .= " AND fk_product = ".((int) $this->id);
@@ -2590,7 +2590,7 @@ class Product extends CommonObject
 							// Récuperation de la liste des prix selon qty si flag positionné
 							if ($this->prices_by_qty[$i] == 1) {
 								$sql = "SELECT rowid, price, unitprice, quantity, remise_percent, remise, price_base_type";
-								$sql .= " FROM ".MAIN_DB_PREFIX."product_price_by_qty";
+								$sql .= " FROM ".$this->db->prefix()."product_price_by_qty";
 								$sql .= " WHERE fk_product_price = ".((int) $this->prices_by_qty_id[$i]);
 								$sql .= " ORDER BY quantity ASC";
 								$resultat = array();
@@ -2668,10 +2668,10 @@ class Product extends CommonObject
 
 			$sql = "SELECT COUNT(DISTINCT c.fk_soc) as nb_customers, COUNT(DISTINCT c.rowid) as nb,";
 			$sql .= " SUM(mp.qty) as qty";
-			$sql .= " FROM ".MAIN_DB_PREFIX."mrp_mo as c";
-			$sql .= " INNER JOIN ".MAIN_DB_PREFIX."mrp_production as mp ON mp.fk_mo=c.rowid";
+			$sql .= " FROM ".$this->db->prefix()."mrp_mo as c";
+			$sql .= " INNER JOIN ".$this->db->prefix()."mrp_production as mp ON mp.fk_mo=c.rowid";
 			if (empty($user->rights->societe->client->voir) && !$socid) {
-				$sql .= "INNER JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON sc.fk_soc=c.fk_soc AND sc.fk_user = ".((int) $user->id);
+				$sql .= "INNER JOIN ".$this->db->prefix()."societe_commerciaux as sc ON sc.fk_soc=c.fk_soc AND sc.fk_user = ".((int) $user->id);
 			}
 			$sql .= " WHERE ";
 			$sql .= " c.entity IN (".getEntity('mo').")";
@@ -2728,8 +2728,8 @@ class Product extends CommonObject
 
 		$sql = "SELECT COUNT(DISTINCT b.rowid) as nb_toproduce,";
 		$sql .= " SUM(b.qty) as qty_toproduce";
-		$sql .= " FROM ".MAIN_DB_PREFIX."bom_bom as b";
-		$sql .= " INNER JOIN ".MAIN_DB_PREFIX."bom_bomline as bl ON bl.fk_bom=b.rowid";
+		$sql .= " FROM ".$this->db->prefix()."bom_bom as b";
+		$sql .= " INNER JOIN ".$this->db->prefix()."bom_bomline as bl ON bl.fk_bom=b.rowid";
 		$sql .= " WHERE ";
 		$sql .= " b.entity IN (".getEntity('bom').")";
 		$sql .= " AND b.fk_product =".((int) $this->id);
@@ -2747,8 +2747,8 @@ class Product extends CommonObject
 
 		$sql = "SELECT COUNT(DISTINCT bl.rowid) as nb_toconsume,";
 		$sql .= " SUM(bl.qty) as qty_toconsume";
-		$sql .= " FROM ".MAIN_DB_PREFIX."bom_bom as b";
-		$sql .= " INNER JOIN ".MAIN_DB_PREFIX."bom_bomline as bl ON bl.fk_bom=b.rowid";
+		$sql .= " FROM ".$this->db->prefix()."bom_bom as b";
+		$sql .= " INNER JOIN ".$this->db->prefix()."bom_bomline as bl ON bl.fk_bom=b.rowid";
 		$sql .= " WHERE ";
 		$sql .= " b.entity IN (".getEntity('bom').")";
 		$sql .= " AND bl.fk_product =".((int) $this->id);
@@ -2790,11 +2790,11 @@ class Product extends CommonObject
 
 		$sql = "SELECT COUNT(DISTINCT p.fk_soc) as nb_customers, COUNT(DISTINCT p.rowid) as nb,";
 		$sql .= " COUNT(pd.rowid) as nb_rows, SUM(pd.qty) as qty";
-		$sql .= " FROM ".MAIN_DB_PREFIX."propaldet as pd";
-		$sql .= ", ".MAIN_DB_PREFIX."propal as p";
-		$sql .= ", ".MAIN_DB_PREFIX."societe as s";
+		$sql .= " FROM ".$this->db->prefix()."propaldet as pd";
+		$sql .= ", ".$this->db->prefix()."propal as p";
+		$sql .= ", ".$this->db->prefix()."societe as s";
 		if (empty($user->rights->societe->client->voir) && !$socid) {
-			$sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
+			$sql .= ", ".$this->db->prefix()."societe_commerciaux as sc";
 		}
 		$sql .= " WHERE p.rowid = pd.fk_propal";
 		$sql .= " AND p.fk_soc = s.rowid";
@@ -2865,11 +2865,11 @@ class Product extends CommonObject
 
 		$sql = "SELECT COUNT(DISTINCT p.fk_soc) as nb_suppliers, COUNT(DISTINCT p.rowid) as nb,";
 		$sql .= " COUNT(pd.rowid) as nb_rows, SUM(pd.qty) as qty";
-		$sql .= " FROM ".MAIN_DB_PREFIX."supplier_proposaldet as pd";
-		$sql .= ", ".MAIN_DB_PREFIX."supplier_proposal as p";
-		$sql .= ", ".MAIN_DB_PREFIX."societe as s";
+		$sql .= " FROM ".$this->db->prefix()."supplier_proposaldet as pd";
+		$sql .= ", ".$this->db->prefix()."supplier_proposal as p";
+		$sql .= ", ".$this->db->prefix()."societe as s";
 		if (empty($user->rights->societe->client->voir) && !$socid) {
-			$sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
+			$sql .= ", ".$this->db->prefix()."societe_commerciaux as sc";
 		}
 		$sql .= " WHERE p.rowid = pd.fk_supplier_proposal";
 		$sql .= " AND p.fk_soc = s.rowid";
@@ -2921,11 +2921,11 @@ class Product extends CommonObject
 
 		$sql = "SELECT COUNT(DISTINCT c.fk_soc) as nb_customers, COUNT(DISTINCT c.rowid) as nb,";
 		$sql .= " COUNT(cd.rowid) as nb_rows, SUM(cd.qty) as qty";
-		$sql .= " FROM ".MAIN_DB_PREFIX."commandedet as cd";
-		$sql .= ", ".MAIN_DB_PREFIX."commande as c";
-		$sql .= ", ".MAIN_DB_PREFIX."societe as s";
+		$sql .= " FROM ".$this->db->prefix()."commandedet as cd";
+		$sql .= ", ".$this->db->prefix()."commande as c";
+		$sql .= ", ".$this->db->prefix()."societe as s";
 		if (empty($user->rights->societe->client->voir) && !$socid && !$forVirtualStock) {
-			$sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
+			$sql .= ", ".$this->db->prefix()."societe_commerciaux as sc";
 		}
 		$sql .= " WHERE c.rowid = cd.fk_commande";
 		$sql .= " AND c.fk_soc = s.rowid";
@@ -2976,10 +2976,10 @@ class Product extends CommonObject
 			if (!empty($conf->global->STOCK_CALCULATE_ON_BILL)) {
 				if (!empty($conf->global->DECREASE_ONLY_UNINVOICEDPRODUCTS)) {
 					$adeduire = 0;
-					$sql = "SELECT sum(fd.qty) as count FROM ".MAIN_DB_PREFIX."facturedet fd ";
-					$sql .= " JOIN ".MAIN_DB_PREFIX."facture f ON fd.fk_facture = f.rowid ";
-					$sql .= " JOIN ".MAIN_DB_PREFIX."element_element el ON el.fk_target = f.rowid and el.targettype = 'facture' and sourcetype = 'commande'";
-					$sql .= " JOIN ".MAIN_DB_PREFIX."commande c ON el.fk_source = c.rowid ";
+					$sql = "SELECT sum(fd.qty) as count FROM ".$this->db->prefix()."facturedet fd ";
+					$sql .= " JOIN ".$this->db->prefix()."facture f ON fd.fk_facture = f.rowid ";
+					$sql .= " JOIN ".$this->db->prefix()."element_element el ON el.fk_target = f.rowid and el.targettype = 'facture' and sourcetype = 'commande'";
+					$sql .= " JOIN ".$this->db->prefix()."commande c ON el.fk_source = c.rowid ";
 					$sql .= " WHERE c.fk_statut IN (".$this->db->sanitize($filtrestatut).") AND c.facture = 0 AND fd.fk_product = ".((int) $this->id);
 					dol_syslog(__METHOD__.":: sql $sql", LOG_NOTICE);
 
@@ -3023,11 +3023,11 @@ class Product extends CommonObject
 
 		$sql = "SELECT COUNT(DISTINCT c.fk_soc) as nb_suppliers, COUNT(DISTINCT c.rowid) as nb,";
 		$sql .= " COUNT(cd.rowid) as nb_rows, SUM(cd.qty) as qty";
-		$sql .= " FROM ".MAIN_DB_PREFIX."commande_fournisseurdet as cd";
-		$sql .= ", ".MAIN_DB_PREFIX."commande_fournisseur as c";
-		$sql .= ", ".MAIN_DB_PREFIX."societe as s";
+		$sql .= " FROM ".$this->db->prefix()."commande_fournisseurdet as cd";
+		$sql .= ", ".$this->db->prefix()."commande_fournisseur as c";
+		$sql .= ", ".$this->db->prefix()."societe as s";
 		if (empty($user->rights->societe->client->voir) && !$socid && !$forVirtualStock) {
-			$sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
+			$sql .= ", ".$this->db->prefix()."societe_commerciaux as sc";
 		}
 		$sql .= " WHERE c.rowid = cd.fk_commande";
 		$sql .= " AND c.fk_soc = s.rowid";
@@ -3081,13 +3081,13 @@ class Product extends CommonObject
 
 		$sql = "SELECT COUNT(DISTINCT e.fk_soc) as nb_customers, COUNT(DISTINCT e.rowid) as nb,";
 		$sql .= " COUNT(ed.rowid) as nb_rows, SUM(ed.qty) as qty";
-		$sql .= " FROM ".MAIN_DB_PREFIX."expeditiondet as ed";
-		$sql .= ", ".MAIN_DB_PREFIX."commandedet as cd";
-		$sql .= ", ".MAIN_DB_PREFIX."commande as c";
-		$sql .= ", ".MAIN_DB_PREFIX."expedition as e";
-		$sql .= ", ".MAIN_DB_PREFIX."societe as s";
+		$sql .= " FROM ".$this->db->prefix()."expeditiondet as ed";
+		$sql .= ", ".$this->db->prefix()."commandedet as cd";
+		$sql .= ", ".$this->db->prefix()."commande as c";
+		$sql .= ", ".$this->db->prefix()."expedition as e";
+		$sql .= ", ".$this->db->prefix()."societe as s";
 		if (empty($user->rights->societe->client->voir) && !$socid && !$forVirtualStock) {
-			$sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
+			$sql .= ", ".$this->db->prefix()."societe_commerciaux as sc";
 		}
 		$sql .= " WHERE e.rowid = ed.fk_expedition";
 		$sql .= " AND c.rowid = cd.fk_commande";
@@ -3166,11 +3166,11 @@ class Product extends CommonObject
 
 		$sql = "SELECT COUNT(DISTINCT cf.fk_soc) as nb_suppliers, COUNT(DISTINCT cf.rowid) as nb,";
 		$sql .= " COUNT(fd.rowid) as nb_rows, SUM(fd.qty) as qty";
-		$sql .= " FROM ".MAIN_DB_PREFIX."commande_fournisseur_dispatch as fd";
-		$sql .= ", ".MAIN_DB_PREFIX."commande_fournisseur as cf";
-		$sql .= ", ".MAIN_DB_PREFIX."societe as s";
+		$sql .= " FROM ".$this->db->prefix()."commande_fournisseur_dispatch as fd";
+		$sql .= ", ".$this->db->prefix()."commande_fournisseur as cf";
+		$sql .= ", ".$this->db->prefix()."societe as s";
 		if (empty($user->rights->societe->client->voir) && !$socid && !$forVirtualStock) {
-			$sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
+			$sql .= ", ".$this->db->prefix()."societe_commerciaux as sc";
 		}
 		$sql .= " WHERE cf.rowid = fd.fk_commande";
 		$sql .= " AND cf.fk_soc = s.rowid";
@@ -3223,11 +3223,11 @@ class Product extends CommonObject
 
 		$sql = "SELECT COUNT(DISTINCT m.fk_soc) as nb_customers, COUNT(DISTINCT m.rowid) as nb,";
 		$sql .= " COUNT(mp.rowid) as nb_rows, SUM(mp.qty) as qty, role";
-		$sql .= " FROM ".MAIN_DB_PREFIX."mrp_production as mp";
-		$sql .= ", ".MAIN_DB_PREFIX."mrp_mo as m";
-		$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid = m.fk_soc";
+		$sql .= " FROM ".$this->db->prefix()."mrp_production as mp";
+		$sql .= ", ".$this->db->prefix()."mrp_mo as m";
+		$sql .= " LEFT JOIN ".$this->db->prefix()."societe as s ON s.rowid = m.fk_soc";
 		if (empty($user->rights->societe->client->voir) && !$socid && !$forVirtualStock) {
-			$sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
+			$sql .= ", ".$this->db->prefix()."societe_commerciaux as sc";
 		}
 		$sql .= " WHERE m.rowid = mp.fk_mo";
 		$sql .= " AND m.entity IN (".getEntity($forVirtualStock && !empty($conf->global->STOCK_CALCULATE_VIRTUAL_STOCK_TRANSVERSE_MODE) ? 'stock' : 'mrp').")";
@@ -3316,11 +3316,11 @@ class Product extends CommonObject
 
 		$sql = "SELECT COUNT(DISTINCT c.fk_soc) as nb_customers, COUNT(DISTINCT c.rowid) as nb,";
 		$sql .= " COUNT(cd.rowid) as nb_rows, SUM(cd.qty) as qty";
-		$sql .= " FROM ".MAIN_DB_PREFIX."contratdet as cd";
-		$sql .= ", ".MAIN_DB_PREFIX."contrat as c";
-		$sql .= ", ".MAIN_DB_PREFIX."societe as s";
+		$sql .= " FROM ".$this->db->prefix()."contratdet as cd";
+		$sql .= ", ".$this->db->prefix()."contrat as c";
+		$sql .= ", ".$this->db->prefix()."societe as s";
 		if (empty($user->rights->societe->client->voir) && !$socid) {
-			$sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
+			$sql .= ", ".$this->db->prefix()."societe_commerciaux as sc";
 		}
 		$sql .= " WHERE c.rowid = cd.fk_contrat";
 		$sql .= " AND c.fk_soc = s.rowid";
@@ -3390,11 +3390,11 @@ class Product extends CommonObject
 
 		$sql = "SELECT COUNT(DISTINCT f.fk_soc) as nb_customers, COUNT(DISTINCT f.rowid) as nb,";
 		$sql .= " COUNT(fd.rowid) as nb_rows, SUM(".$this->db->ifsql('f.type != 2', 'fd.qty', 'fd.qty * -1').") as qty";
-		$sql .= " FROM ".MAIN_DB_PREFIX."facturedet as fd";
-		$sql .= ", ".MAIN_DB_PREFIX."facture as f";
-		$sql .= ", ".MAIN_DB_PREFIX."societe as s";
+		$sql .= " FROM ".$this->db->prefix()."facturedet as fd";
+		$sql .= ", ".$this->db->prefix()."facture as f";
+		$sql .= ", ".$this->db->prefix()."societe as s";
 		if (empty($user->rights->societe->client->voir) && !$socid) {
-			$sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
+			$sql .= ", ".$this->db->prefix()."societe_commerciaux as sc";
 		}
 		$sql .= " WHERE f.rowid = fd.fk_facture";
 		$sql .= " AND f.fk_soc = s.rowid";
@@ -3464,11 +3464,11 @@ class Product extends CommonObject
 
 		$sql = "SELECT COUNT(DISTINCT f.fk_soc) as nb_suppliers, COUNT(DISTINCT f.rowid) as nb,";
 		$sql .= " COUNT(fd.rowid) as nb_rows, SUM(fd.qty) as qty";
-		$sql .= " FROM ".MAIN_DB_PREFIX."facture_fourn_det as fd";
-		$sql .= ", ".MAIN_DB_PREFIX."facture_fourn as f";
-		$sql .= ", ".MAIN_DB_PREFIX."societe as s";
+		$sql .= " FROM ".$this->db->prefix()."facture_fourn_det as fd";
+		$sql .= ", ".$this->db->prefix()."facture_fourn as f";
+		$sql .= ", ".$this->db->prefix()."societe as s";
 		if (empty($user->rights->societe->client->voir) && !$socid) {
-			$sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
+			$sql .= ", ".$this->db->prefix()."societe_commerciaux as sc";
 		}
 		$sql .= " WHERE f.rowid = fd.fk_facture_fourn";
 		$sql .= " AND f.fk_soc = s.rowid";
@@ -3595,12 +3595,12 @@ class Product extends CommonObject
 		if ($mode == 'bynumber') {
 			$sql .= ", count(DISTINCT f.rowid)";
 		}
-		$sql .= " FROM ".MAIN_DB_PREFIX."facturedet as d, ".MAIN_DB_PREFIX."facture as f, ".MAIN_DB_PREFIX."societe as s";
+		$sql .= " FROM ".$this->db->prefix()."facturedet as d, ".$this->db->prefix()."facture as f, ".$this->db->prefix()."societe as s";
 		if ($filteronproducttype >= 0) {
-			$sql .= ", ".MAIN_DB_PREFIX."product as p";
+			$sql .= ", ".$this->db->prefix()."product as p";
 		}
 		if (empty($user->rights->societe->client->voir) && !$socid) {
-			$sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
+			$sql .= ", ".$this->db->prefix()."societe_commerciaux as sc";
 		}
 		$sql .= " WHERE f.rowid = d.fk_facture";
 		if ($this->id > 0) {
@@ -3648,12 +3648,12 @@ class Product extends CommonObject
 		if ($mode == 'bynumber') {
 			$sql .= ", count(DISTINCT f.rowid)";
 		}
-		$sql .= " FROM ".MAIN_DB_PREFIX."facture_fourn_det as d, ".MAIN_DB_PREFIX."facture_fourn as f, ".MAIN_DB_PREFIX."societe as s";
+		$sql .= " FROM ".$this->db->prefix()."facture_fourn_det as d, ".$this->db->prefix()."facture_fourn as f, ".$this->db->prefix()."societe as s";
 		if ($filteronproducttype >= 0) {
-			$sql .= ", ".MAIN_DB_PREFIX."product as p";
+			$sql .= ", ".$this->db->prefix()."product as p";
 		}
 		if (empty($user->rights->societe->client->voir) && !$socid) {
-			$sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
+			$sql .= ", ".$this->db->prefix()."societe_commerciaux as sc";
 		}
 		$sql .= " WHERE f.rowid = d.fk_facture_fourn";
 		if ($this->id > 0) {
@@ -3699,12 +3699,12 @@ class Product extends CommonObject
 		if ($mode == 'bynumber') {
 			$sql .= ", count(DISTINCT p.rowid)";
 		}
-		$sql .= " FROM ".MAIN_DB_PREFIX."propaldet as d, ".MAIN_DB_PREFIX."propal as p, ".MAIN_DB_PREFIX."societe as s";
+		$sql .= " FROM ".$this->db->prefix()."propaldet as d, ".$this->db->prefix()."propal as p, ".$this->db->prefix()."societe as s";
 		if ($filteronproducttype >= 0) {
-			$sql .= ", ".MAIN_DB_PREFIX."product as prod";
+			$sql .= ", ".$this->db->prefix()."product as prod";
 		}
 		if (empty($user->rights->societe->client->voir) && !$socid) {
-			$sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
+			$sql .= ", ".$this->db->prefix()."societe_commerciaux as sc";
 		}
 		$sql .= " WHERE p.rowid = d.fk_propal";
 		if ($this->id > 0) {
@@ -3751,12 +3751,12 @@ class Product extends CommonObject
 		if ($mode == 'bynumber') {
 			$sql .= ", count(DISTINCT p.rowid)";
 		}
-		$sql .= " FROM ".MAIN_DB_PREFIX."supplier_proposaldet as d, ".MAIN_DB_PREFIX."supplier_proposal as p, ".MAIN_DB_PREFIX."societe as s";
+		$sql .= " FROM ".$this->db->prefix()."supplier_proposaldet as d, ".$this->db->prefix()."supplier_proposal as p, ".$this->db->prefix()."societe as s";
 		if ($filteronproducttype >= 0) {
-			$sql .= ", ".MAIN_DB_PREFIX."product as prod";
+			$sql .= ", ".$this->db->prefix()."product as prod";
 		}
 		if (empty($user->rights->societe->client->voir) && !$socid) {
-			$sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
+			$sql .= ", ".$this->db->prefix()."societe_commerciaux as sc";
 		}
 		$sql .= " WHERE p.rowid = d.fk_supplier_proposal";
 		if ($this->id > 0) {
@@ -3802,12 +3802,12 @@ class Product extends CommonObject
 		if ($mode == 'bynumber') {
 			$sql .= ", count(DISTINCT c.rowid)";
 		}
-		$sql .= " FROM ".MAIN_DB_PREFIX."commandedet as d, ".MAIN_DB_PREFIX."commande as c, ".MAIN_DB_PREFIX."societe as s";
+		$sql .= " FROM ".$this->db->prefix()."commandedet as d, ".$this->db->prefix()."commande as c, ".$this->db->prefix()."societe as s";
 		if ($filteronproducttype >= 0) {
-			$sql .= ", ".MAIN_DB_PREFIX."product as p";
+			$sql .= ", ".$this->db->prefix()."product as p";
 		}
 		if (empty($user->rights->societe->client->voir) && !$socid) {
-			$sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
+			$sql .= ", ".$this->db->prefix()."societe_commerciaux as sc";
 		}
 		$sql .= " WHERE c.rowid = d.fk_commande";
 		if ($this->id > 0) {
@@ -3853,12 +3853,12 @@ class Product extends CommonObject
 		if ($mode == 'bynumber') {
 			$sql .= ", count(DISTINCT c.rowid)";
 		}
-		$sql .= " FROM ".MAIN_DB_PREFIX."commande_fournisseurdet as d, ".MAIN_DB_PREFIX."commande_fournisseur as c, ".MAIN_DB_PREFIX."societe as s";
+		$sql .= " FROM ".$this->db->prefix()."commande_fournisseurdet as d, ".$this->db->prefix()."commande_fournisseur as c, ".$this->db->prefix()."societe as s";
 		if ($filteronproducttype >= 0) {
-			$sql .= ", ".MAIN_DB_PREFIX."product as p";
+			$sql .= ", ".$this->db->prefix()."product as p";
 		}
 		if (empty($user->rights->societe->client->voir) && !$socid) {
-			$sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
+			$sql .= ", ".$this->db->prefix()."societe_commerciaux as sc";
 		}
 		$sql .= " WHERE c.rowid = d.fk_commande";
 		if ($this->id > 0) {
@@ -3904,12 +3904,12 @@ class Product extends CommonObject
 		if ($mode == 'bynumber') {
 			$sql .= ", count(DISTINCT c.rowid)";
 		}
-		$sql .= " FROM ".MAIN_DB_PREFIX."contratdet as d, ".MAIN_DB_PREFIX."contrat as c, ".MAIN_DB_PREFIX."societe as s";
+		$sql .= " FROM ".$this->db->prefix()."contratdet as d, ".$this->db->prefix()."contrat as c, ".$this->db->prefix()."societe as s";
 		if ($filteronproducttype >= 0) {
-			$sql .= ", ".MAIN_DB_PREFIX."product as p";
+			$sql .= ", ".$this->db->prefix()."product as p";
 		}
 		if (empty($user->rights->societe->client->voir) && !$socid) {
-			$sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
+			$sql .= ", ".$this->db->prefix()."societe_commerciaux as sc";
 		}
 
 		$sql .= " WHERE c.entity IN (".getEntity('contract').")";
@@ -3958,12 +3958,12 @@ class Product extends CommonObject
 		if ($mode == 'bynumber') {
 			$sql .= ", count(DISTINCT d.rowid)";
 		}
-		$sql .= " FROM ".MAIN_DB_PREFIX."mrp_mo as d LEFT JOIN  ".MAIN_DB_PREFIX."societe as s ON d.fk_soc = s.rowid";
+		$sql .= " FROM ".$this->db->prefix()."mrp_mo as d LEFT JOIN  ".$this->db->prefix()."societe as s ON d.fk_soc = s.rowid";
 		if ($filteronproducttype >= 0) {
-			$sql .= ", ".MAIN_DB_PREFIX."product as p";
+			$sql .= ", ".$this->db->prefix()."product as p";
 		}
 		if (empty($user->rights->societe->client->voir) && !$socid) {
-			$sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
+			$sql .= ", ".$this->db->prefix()."societe_commerciaux as sc";
 		}
 
 		$sql .= " WHERE d.entity IN (".getEntity('mo').")";
@@ -4021,21 +4021,21 @@ class Product extends CommonObject
 		}
 
 		// Check not already father of id_pere (to avoid father -> child -> father links)
-		$sql = "SELECT fk_product_pere from ".MAIN_DB_PREFIX."product_association";
+		$sql = "SELECT fk_product_pere from ".$this->db->prefix()."product_association";
 		$sql .= " WHERE fk_product_pere = ".((int) $id_fils)." AND fk_product_fils = ".((int) $id_pere);
 		if (!$this->db->query($sql)) {
 			dol_print_error($this->db);
 			return -1;
 		} else {
 			//Selection of the highest row
-			$sql = "SELECT MAX(rang) as max_rank FROM ".MAIN_DB_PREFIX."product_association";
+			$sql = "SELECT MAX(rang) as max_rank FROM ".$this->db->prefix()."product_association";
 			$sql .= " WHERE fk_product_pere  = ".((int) $id_pere);
 			$resql = $this->db->query($sql);
 			if ($resql > 0) {
 				$obj = $this->db->fetch_object($resql);
 				$rank = $obj->max_rank + 1;
 				//Addition of a product with the highest rank +1
-				$sql = "INSERT INTO ".MAIN_DB_PREFIX."product_association(fk_product_pere,fk_product_fils,qty,incdec,rang)";
+				$sql = "INSERT INTO ".$this->db->prefix()."product_association(fk_product_pere,fk_product_fils,qty,incdec,rang)";
 				$sql .= " VALUES (".((int) $id_pere).", ".((int) $id_fils).", ".price2num($qty, 'MS').", ".price2num($incdec, 'MS').", ".((int) $rank).")";
 				if (! $this->db->query($sql)) {
 					dol_print_error($this->db);
@@ -4077,7 +4077,7 @@ class Product extends CommonObject
 			$qty = 1;
 		}
 
-		$sql = 'UPDATE '.MAIN_DB_PREFIX.'product_association SET ';
+		$sql = 'UPDATE '.$this->db->prefix().'product_association SET ';
 		$sql .= 'qty = '.price2num($qty, 'MS');
 		$sql .= ',incdec = '.price2num($incdec, 'MS');
 		$sql .= ' WHERE fk_product_pere = '.((int) $id_pere).' AND fk_product_fils = '.((int) $id_fils);
@@ -4108,7 +4108,7 @@ class Product extends CommonObject
 			$fk_child = 0;
 		}
 
-		$sql = "DELETE FROM ".MAIN_DB_PREFIX."product_association";
+		$sql = "DELETE FROM ".$this->db->prefix()."product_association";
 		$sql .= " WHERE fk_product_pere  = ".((int) $fk_parent);
 		$sql .= " AND fk_product_fils = ".((int) $fk_child);
 
@@ -4119,7 +4119,7 @@ class Product extends CommonObject
 		}
 
 		// Updated ranks so that none are missing
-		$sqlrank = "SELECT rowid, rang FROM ".MAIN_DB_PREFIX."product_association";
+		$sqlrank = "SELECT rowid, rang FROM ".$this->db->prefix()."product_association";
 		$sqlrank.= " WHERE fk_product_pere = ".((int) $fk_parent);
 		$sqlrank.= " ORDER BY rang";
 		$resqlrank = $this->db->query($sqlrank);
@@ -4127,7 +4127,7 @@ class Product extends CommonObject
 			$cpt = 0;
 			while ($objrank = $this->db->fetch_object($resqlrank)) {
 				$cpt++;
-				$sql = "UPDATE ".MAIN_DB_PREFIX."product_association";
+				$sql = "UPDATE ".$this->db->prefix()."product_association";
 				$sql.= " SET rang = ".((int) $cpt);
 				$sql.= " WHERE rowid = ".((int) $objrank->rowid);
 				if (! $this->db->query($sql)) {
@@ -4151,7 +4151,7 @@ class Product extends CommonObject
 	{
 		// phpcs:enable
 		$sql = "SELECT fk_product_pere, qty, incdec";
-		$sql .= " FROM ".MAIN_DB_PREFIX."product_association";
+		$sql .= " FROM ".$this->db->prefix()."product_association";
 		$sql .= " WHERE fk_product_pere  = ".((int) $fk_parent);
 		$sql .= " AND fk_product_fils = ".((int) $fk_child);
 
@@ -4201,7 +4201,7 @@ class Product extends CommonObject
 
 		if ($ref_fourn) {
 			$sql = "SELECT rowid, fk_product";
-			$sql .= " FROM ".MAIN_DB_PREFIX."product_fournisseur_price";
+			$sql .= " FROM ".$this->db->prefix()."product_fournisseur_price";
 			$sql .= " WHERE fk_soc = ".((int) $id_fourn);
 			$sql .= " AND ref_fourn = '".$this->db->escape($ref_fourn)."'";
 			$sql .= " AND fk_product <> ".((int) $this->id);
@@ -4220,7 +4220,7 @@ class Product extends CommonObject
 		}
 
 		$sql = "SELECT rowid";
-		$sql .= " FROM ".MAIN_DB_PREFIX."product_fournisseur_price";
+		$sql .= " FROM ".$this->db->prefix()."product_fournisseur_price";
 		$sql .= " WHERE fk_soc = ".((int) $id_fourn);
 		if ($ref_fourn) {
 			$sql .= " AND ref_fourn = '".$this->db->escape($ref_fourn)."'";
@@ -4237,7 +4237,7 @@ class Product extends CommonObject
 
 			// The reference supplier does not exist, we create it for this product.
 			if (empty($obj)) {
-				$sql = "INSERT INTO ".MAIN_DB_PREFIX."product_fournisseur_price(";
+				$sql = "INSERT INTO ".$this->db->prefix()."product_fournisseur_price(";
 				$sql .= "datec";
 				$sql .= ", entity";
 				$sql .= ", fk_product";
@@ -4258,7 +4258,7 @@ class Product extends CommonObject
 				$sql .= ")";
 
 				if ($this->db->query($sql)) {
-					$this->product_fourn_price_id = $this->db->last_insert_id(MAIN_DB_PREFIX."product_fournisseur_price");
+					$this->product_fourn_price_id = $this->db->last_insert_id($this->db->prefix()."product_fournisseur_price");
 					return 1;
 				} else {
 					$this->error = $this->db->lasterror();
@@ -4290,7 +4290,7 @@ class Product extends CommonObject
 		$list = array();
 
 		$sql = "SELECT DISTINCT p.fk_soc";
-		$sql .= " FROM ".MAIN_DB_PREFIX."product_fournisseur_price as p";
+		$sql .= " FROM ".$this->db->prefix()."product_fournisseur_price as p";
 		$sql .= " WHERE p.fk_product = ".((int) $this->id);
 		$sql .= " AND p.entity = ".((int) $conf->entity);
 
@@ -4325,7 +4325,7 @@ class Product extends CommonObject
 		$this->db->begin();
 
 		// prices
-		$sql  = "INSERT INTO ".MAIN_DB_PREFIX."product_price (";
+		$sql  = "INSERT INTO ".$this->db->prefix()."product_price (";
 		$sql .= " entity";
 		$sql .= ", fk_product";
 		$sql .= ", date_price";
@@ -4378,7 +4378,7 @@ class Product extends CommonObject
 		$sql .= ", multicurrency_tx";
 		$sql .= ", multicurrency_price";
 		$sql .= ", multicurrency_price_ttc";
-		$sql .= " FROM ".MAIN_DB_PREFIX."product_price";
+		$sql .= " FROM ".$this->db->prefix()."product_price";
 		$sql .= " WHERE fk_product = ".((int) $fromId);
 		$sql .= " ORDER BY date_price DESC";
 		if ($conf->global->PRODUIT_MULTIPRICES_LIMIT > 0) {
@@ -4409,8 +4409,8 @@ class Product extends CommonObject
 		// phpcs:enable
 		$this->db->begin();
 
-		$sql = 'INSERT INTO '.MAIN_DB_PREFIX.'product_association (fk_product_pere, fk_product_fils, qty)';
-		$sql .= " SELECT ".$toId.", fk_product_fils, qty FROM ".MAIN_DB_PREFIX."product_association";
+		$sql = 'INSERT INTO '.$this->db->prefix().'product_association (fk_product_pere, fk_product_fils, qty)';
+		$sql .= " SELECT ".$toId.", fk_product_fils, qty FROM ".$this->db->prefix()."product_association";
 		$sql .= " WHERE fk_product_pere = ".((int) $fromId);
 
 		dol_syslog(get_class($this).'::clone_association', LOG_DEBUG);
@@ -4439,10 +4439,10 @@ class Product extends CommonObject
 		$now = dol_now();
 
 		// les fournisseurs
-		/*$sql = "INSERT ".MAIN_DB_PREFIX."product_fournisseur ("
+		/*$sql = "INSERT ".$this->db->prefix()."product_fournisseur ("
 		 . " datec, fk_product, fk_soc, ref_fourn, fk_user_author )"
 		 . " SELECT '".$this->db->idate($now)."', ".$toId.", fk_soc, ref_fourn, fk_user_author"
-		 . " FROM ".MAIN_DB_PREFIX."product_fournisseur"
+		 . " FROM ".$this->db->prefix()."product_fournisseur"
 		 . " WHERE fk_product = ".((int) $fromId);
 
 		 if ( ! $this->db->query($sql ) )
@@ -4452,10 +4452,10 @@ class Product extends CommonObject
 		 }*/
 
 		// les prix de fournisseurs.
-		$sql = "INSERT ".MAIN_DB_PREFIX."product_fournisseur_price (";
+		$sql = "INSERT ".$this->db->prefix()."product_fournisseur_price (";
 		$sql .= " datec, fk_product, fk_soc, price, quantity, fk_user)";
 		$sql .= " SELECT '".$this->db->idate($now)."', ".((int) $toId).", fk_soc, price, quantity, fk_user";
-		$sql .= " FROM ".MAIN_DB_PREFIX."product_fournisseur_price";
+		$sql .= " FROM ".$this->db->prefix()."product_fournisseur_price";
 		$sql .= " WHERE fk_product = ".((int) $fromId);
 
 		dol_syslog(get_class($this).'::clone_fournisseurs', LOG_DEBUG);
@@ -4573,7 +4573,7 @@ class Product extends CommonObject
 		$nb = 0;
 
 		$sql = "SELECT COUNT(pa.rowid) as nb";
-		$sql .= " FROM ".MAIN_DB_PREFIX."product_association as pa";
+		$sql .= " FROM ".$this->db->prefix()."product_association as pa";
 		if ($mode == 0) {
 			$sql .= " WHERE pa.fk_product_fils = ".((int) $this->id)." OR pa.fk_product_pere = ".((int) $this->id);
 		} elseif ($mode == -1) {
@@ -4603,7 +4603,7 @@ class Product extends CommonObject
 	public function hasVariants()
 	{
 		$nb = 0;
-		$sql = "SELECT count(rowid) as nb FROM ".MAIN_DB_PREFIX."product_attribute_combination WHERE fk_product_parent = ".((int) $this->id);
+		$sql = "SELECT count(rowid) as nb FROM ".$this->db->prefix()."product_attribute_combination WHERE fk_product_parent = ".((int) $this->id);
 		$sql .= " AND entity IN (".getEntity('product').")";
 
 		$resql = $this->db->query($sql);
@@ -4627,7 +4627,7 @@ class Product extends CommonObject
 	{
 		global $conf;
 		if (!empty($conf->variants->enabled)) {
-			$sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."product_attribute_combination WHERE fk_product_child = ".((int) $this->id)." AND entity IN (".getEntity('product').")";
+			$sql = "SELECT rowid FROM ".$this->db->prefix()."product_attribute_combination WHERE fk_product_child = ".((int) $this->id)." AND entity IN (".getEntity('product').")";
 
 			$query = $this->db->query($sql);
 
@@ -4655,8 +4655,8 @@ class Product extends CommonObject
 	{
 		$sql = "SELECT p.rowid, p.label as label, p.ref as ref, pa.fk_product_pere as id, p.fk_product_type, pa.qty, pa.incdec, p.entity";
 		$sql .= ", p.tosell as status, p.tobuy as status_buy";
-		$sql .= " FROM ".MAIN_DB_PREFIX."product_association as pa,";
-		$sql .= " ".MAIN_DB_PREFIX."product as p";
+		$sql .= " FROM ".$this->db->prefix()."product_association as pa,";
+		$sql .= " ".$this->db->prefix()."product as p";
 		$sql .= " WHERE p.rowid = pa.fk_product_pere";
 		$sql .= " AND pa.fk_product_fils = ".((int) $this->id);
 
@@ -4702,8 +4702,8 @@ class Product extends CommonObject
 		$sql = "SELECT p.rowid, p.ref, p.label as label, p.fk_product_type,";
 		$sql .= " pa.qty as qty, pa.fk_product_fils as id, pa.incdec,";
 		$sql .= " pa.rowid as fk_association, pa.rang";
-		$sql .= " FROM ".MAIN_DB_PREFIX."product as p,";
-		$sql .= " ".MAIN_DB_PREFIX."product_association as pa";
+		$sql .= " FROM ".$this->db->prefix()."product as p,";
+		$sql .= " ".$this->db->prefix()."product_association as pa";
 		$sql .= " WHERE p.rowid = pa.fk_product_fils";
 		$sql .= " AND pa.fk_product_pere = ".((int) $id);
 		$sql .= " AND pa.fk_product_fils <> ".((int) $id); // This should not happens, it is to avoid infinite loop if it happens
@@ -5088,7 +5088,7 @@ class Product extends CommonObject
 		$langs->load('products');
 
 		if (isset($this->finished) && $this->finished >= 0) {
-			$sql = "SELECT label, code FROM ".MAIN_DB_PREFIX."c_product_nature where code = ".((int) $this->finished)." AND active=1";
+			$sql = "SELECT label, code FROM ".$this->db->prefix()."c_product_nature where code = ".((int) $this->finished)." AND active=1";
 			$resql = $this->db->query($sql);
 			if ($resql && $this->db->num_rows($resql) > 0) {
 				$res = $this->db->fetch_array($resql);
@@ -5249,8 +5249,8 @@ class Product extends CommonObject
 		}
 
 		$sql = "SELECT ps.rowid, ps.reel, ps.fk_entrepot";
-		$sql .= " FROM ".MAIN_DB_PREFIX."product_stock as ps";
-		$sql .= ", ".MAIN_DB_PREFIX."entrepot as w";
+		$sql .= " FROM ".$this->db->prefix()."product_stock as ps";
+		$sql .= ", ".$this->db->prefix()."entrepot as w";
 		$sql .= " WHERE w.entity IN (".getEntity('stock').")";
 		$sql .= " AND w.rowid = ps.fk_entrepot";
 		$sql .= " AND ps.fk_product = ".((int) $this->id);
@@ -5413,7 +5413,7 @@ class Product extends CommonObject
 	{
 		$result = array();
 
-		$sql = "SELECT pb.batch, pb.eatby, pb.sellby, SUM(pb.qty) AS qty FROM ".MAIN_DB_PREFIX."product_batch as pb, ".MAIN_DB_PREFIX."product_stock as ps";
+		$sql = "SELECT pb.batch, pb.eatby, pb.sellby, SUM(pb.qty) AS qty FROM ".$this->db->prefix()."product_batch as pb, ".$this->db->prefix()."product_stock as ps";
 		$sql .= " WHERE pb.fk_product_stock = ps.rowid AND ps.fk_product = ".((int) $this->id)." AND pb.batch = '".$this->db->escape($batch)."'";
 		$sql .= " GROUP BY pb.batch, pb.eatby, pb.sellby";
 		dol_syslog(get_class($this)."::loadBatchInfo load first entry found for lot/serial = ".$batch, LOG_DEBUG);
@@ -5647,7 +5647,7 @@ class Product extends CommonObject
 		$this->nb = array();
 
 		$sql = "SELECT count(p.rowid) as nb, fk_product_type";
-		$sql .= " FROM ".MAIN_DB_PREFIX."product as p";
+		$sql .= " FROM ".$this->db->prefix()."product as p";
 		$sql .= ' WHERE p.entity IN ('.getEntity($this->element, 1).')';
 		// Add where from hooks
 		if (is_object($hookmanager)) {
@@ -5805,7 +5805,7 @@ class Product extends CommonObject
 			$label_type = 'short_label';
 		}
 
-		$sql = "SELECT ".$label_type.", code from ".MAIN_DB_PREFIX."c_units where rowid = ".((int) $this->fk_unit);
+		$sql = "SELECT ".$label_type.", code from ".$this->db->prefix()."c_units where rowid = ".((int) $this->fk_unit);
 
 		$resql = $this->db->query($sql);
 		if ($resql && $this->db->num_rows($resql) > 0) {
@@ -5913,7 +5913,7 @@ class Product extends CommonObject
 	{
 		global $conf, $db;
 
-		$sql = "SELECT rowid, level, fk_level, var_percent, var_min_percent FROM ".MAIN_DB_PREFIX."product_pricerules";
+		$sql = "SELECT rowid, level, fk_level, var_percent, var_min_percent FROM ".$this->db->prefix()."product_pricerules";
 		$query = $this->db->query($sql);
 
 		$rules = array();
@@ -5986,7 +5986,7 @@ class Product extends CommonObject
 	{
 		$sql = "SELECT p.rowid, p.ref, p.datec as date_creation, p.tms as date_modification,";
 		$sql .= " p.fk_user_author, p.fk_user_modif";
-		$sql .= " FROM ".MAIN_DB_PREFIX.$this->table_element." as p";
+		$sql .= " FROM ".$this->db->prefix().$this->table_element." as p";
 		$sql .= " WHERE p.rowid = ".((int) $id);
 
 		$result = $this->db->query($sql);

+ 13 - 13
htdocs/product/class/productbatch.class.php

@@ -87,7 +87,7 @@ class Productbatch extends CommonObject
 		// Put here code to add control on parameters values
 
 		// Insert request
-		$sql = "INSERT INTO ".MAIN_DB_PREFIX."product_batch (";
+		$sql = "INSERT INTO ".$this->db->prefix()."product_batch (";
 		$sql .= "fk_product_stock,";
 		$sql .= "sellby,";				// no more used
 		$sql .= "eatby,";				// no more used
@@ -111,7 +111,7 @@ class Productbatch extends CommonObject
 			$error++; $this->errors[] = "Error ".$this->db->lasterror();
 		}
 		if (!$error) {
-			$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX.self::$_table_element);
+			$this->id = $this->db->last_insert_id($this->db->prefix().self::$_table_element);
 		}
 
 		// Commit or rollback
@@ -149,8 +149,8 @@ class Productbatch extends CommonObject
 		$sql .= " pl.eatby,";
 		$sql .= " pl.sellby";
 
-		$sql .= " FROM ".MAIN_DB_PREFIX."product_batch as t INNER JOIN ".MAIN_DB_PREFIX."product_stock w on t.fk_product_stock = w.rowid";
-		$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product_lot as pl on pl.fk_product = w.fk_product and pl.batch = t.batch";
+		$sql .= " FROM ".$this->db->prefix()."product_batch as t INNER JOIN ".$this->db->prefix()."product_stock w on t.fk_product_stock = w.rowid";
+		$sql .= " LEFT JOIN ".$this->db->prefix()."product_lot as pl on pl.fk_product = w.fk_product and pl.batch = t.batch";
 		$sql .= " WHERE t.rowid = ".((int) $id);
 
 		dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
@@ -199,7 +199,7 @@ class Productbatch extends CommonObject
 		}
 
 		// Update request
-		$sql = "UPDATE ".MAIN_DB_PREFIX.self::$_table_element." SET";
+		$sql = "UPDATE ".$this->db->prefix().self::$_table_element." SET";
 		$sql .= " fk_product_stock=".(isset($this->fk_product_stock) ? $this->fk_product_stock : "null").",";
 		$sql .= " sellby=".(dol_strlen($this->sellby) != 0 ? "'".$this->db->idate($this->sellby)."'" : 'null').",";
 		$sql .= " eatby=".(dol_strlen($this->eatby) != 0 ? "'".$this->db->idate($this->eatby)."'" : 'null').",";
@@ -245,7 +245,7 @@ class Productbatch extends CommonObject
 		$this->db->begin();
 
 		if (!$error) {
-			$sql = "DELETE FROM ".MAIN_DB_PREFIX.self::$_table_element."";
+			$sql = "DELETE FROM ".$this->db->prefix().self::$_table_element."";
 			$sql .= " WHERE rowid=".((int) $this->id);
 
 			dol_syslog(get_class($this)."::delete", LOG_DEBUG);
@@ -383,7 +383,7 @@ class Productbatch extends CommonObject
 		$sql .= " t.batch,";
 		$sql .= " t.qty,";
 		$sql .= " t.import_key";
-		$sql .= " FROM ".MAIN_DB_PREFIX.self::$_table_element." as t";
+		$sql .= " FROM ".$this->db->prefix().self::$_table_element." as t";
 		$sql .= " WHERE fk_product_stock=".((int) $fk_product_stock);
 
 		if (!empty($eatby)) {
@@ -453,9 +453,9 @@ class Productbatch extends CommonObject
 			$sql .= ", pl.rowid as lotid, pl.eatby as eatby, pl.sellby as sellby";
 			// TODO May add extrafields to ?
 		}
-		$sql .= " FROM ".MAIN_DB_PREFIX."product_batch as t";
+		$sql .= " FROM ".$this->db->prefix()."product_batch as t";
 		if ($fk_product > 0) {
-			$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product_lot as pl ON pl.fk_product = ".((int) $fk_product)." AND pl.batch = t.batch";
+			$sql .= " LEFT JOIN ".$this->db->prefix()."product_lot as pl ON pl.fk_product = ".((int) $fk_product)." AND pl.batch = t.batch";
 			// TODO May add extrafields to ?
 		}
 		$sql .= " WHERE fk_product_stock=".((int) $fk_product_stock);
@@ -526,10 +526,10 @@ class Productbatch extends CommonObject
 		$sql .= ", pl.sellby";
 		$sql .= ", pl.eatby";
 		$sql .= ", pb.qty";
-		$sql .= " FROM ".MAIN_DB_PREFIX."product_lot as pl";
-		$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product as p ON p.rowid = pl.fk_product";
-		$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product_batch AS pb ON pl.batch = pb.batch";
-		$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product_stock AS ps ON ps.rowid = pb.fk_product_stock";
+		$sql .= " FROM ".$this->db->prefix()."product_lot as pl";
+		$sql .= " LEFT JOIN ".$this->db->prefix()."product as p ON p.rowid = pl.fk_product";
+		$sql .= " LEFT JOIN ".$this->db->prefix()."product_batch AS pb ON pl.batch = pb.batch";
+		$sql .= " LEFT JOIN ".$this->db->prefix()."product_stock AS ps ON ps.rowid = pb.fk_product_stock";
 		$sql .= " WHERE p.entity IN (".getEntity('product').")";
 		$sql .= " AND pl.fk_product = ".((int) $fk_product);
 		if ($fk_warehouse > 0) {

+ 14 - 14
htdocs/product/class/productcustomerprice.class.php

@@ -188,7 +188,7 @@ class Productcustomerprice extends CommonObject
 		}
 
 		// Insert request
-		$sql = "INSERT INTO ".MAIN_DB_PREFIX."product_customer_price(";
+		$sql = "INSERT INTO ".$this->db->prefix()."product_customer_price(";
 		$sql .= "entity,";
 		$sql .= "datec,";
 		$sql .= "fk_product,";
@@ -240,7 +240,7 @@ class Productcustomerprice extends CommonObject
 		}
 
 		if (!$error) {
-			$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."product_customer_price");
+			$this->id = $this->db->last_insert_id($this->db->prefix()."product_customer_price");
 
 			if (!$notrigger) {
 				$result = $this->call_trigger('PRODUCT_CUSTOMER_PRICE_CREATE', $user);
@@ -301,7 +301,7 @@ class Productcustomerprice extends CommonObject
 		$sql .= " t.localtax2_tx,";
 		$sql .= " t.fk_user,";
 		$sql .= " t.import_key";
-		$sql .= " FROM ".MAIN_DB_PREFIX."product_customer_price as t";
+		$sql .= " FROM ".$this->db->prefix()."product_customer_price as t";
 		$sql .= " WHERE t.rowid = ".((int) $id);
 
 		dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
@@ -392,9 +392,9 @@ class Productcustomerprice extends CommonObject
 		$sql .= " t.import_key,";
 		$sql .= " soc.nom as socname,";
 		$sql .= " prod.ref as prodref";
-		$sql .= " FROM ".MAIN_DB_PREFIX."product_customer_price as t,";
-		$sql .= " ".MAIN_DB_PREFIX."product as prod,";
-		$sql .= " ".MAIN_DB_PREFIX."societe as soc";
+		$sql .= " FROM ".$this->db->prefix()."product_customer_price as t,";
+		$sql .= " ".$this->db->prefix()."product as prod,";
+		$sql .= " ".$this->db->prefix()."societe as soc";
 		$sql .= " WHERE soc.rowid=t.fk_soc ";
 		$sql .= " AND prod.rowid=t.fk_product ";
 		$sql .= " AND prod.entity IN (".getEntity('product').")";
@@ -510,9 +510,9 @@ class Productcustomerprice extends CommonObject
 		$sql .= " t.import_key,";
 		$sql .= " soc.nom as socname,";
 		$sql .= " prod.ref as prodref";
-		$sql .= " FROM ".MAIN_DB_PREFIX."product_customer_price_log as t";
-		$sql .= " ,".MAIN_DB_PREFIX."product as prod";
-		$sql .= " ,".MAIN_DB_PREFIX."societe as soc";
+		$sql .= " FROM ".$this->db->prefix()."product_customer_price_log as t";
+		$sql .= " ,".$this->db->prefix()."product as prod";
+		$sql .= " ,".$this->db->prefix()."societe as soc";
 		$sql .= " WHERE soc.rowid=t.fk_soc";
 		$sql .= " AND prod.rowid=t.fk_product ";
 		$sql .= " AND prod.entity IN (".getEntity('product').")";
@@ -675,7 +675,7 @@ class Productcustomerprice extends CommonObject
 
 		// Do a copy of current record into log table
 		// Insert request
-		$sql = "INSERT INTO ".MAIN_DB_PREFIX."product_customer_price_log(";
+		$sql = "INSERT INTO ".$this->db->prefix()."product_customer_price_log(";
 
 		$sql .= "entity,";
 		$sql .= "datec,";
@@ -720,7 +720,7 @@ class Productcustomerprice extends CommonObject
 		$sql .= " t.fk_user,";
 		$sql .= " t.import_key";
 
-		$sql .= " FROM ".MAIN_DB_PREFIX."product_customer_price as t";
+		$sql .= " FROM ".$this->db->prefix()."product_customer_price as t";
 		$sql .= " WHERE t.rowid = ".((int) $this->id);
 
 		$this->db->begin();
@@ -732,7 +732,7 @@ class Productcustomerprice extends CommonObject
 		}
 
 		// Update request
-		$sql = "UPDATE ".MAIN_DB_PREFIX."product_customer_price SET";
+		$sql = "UPDATE ".$this->db->prefix()."product_customer_price SET";
 
 		$sql .= " entity=".$conf->entity.",";
 		$sql .= " datec='".$this->db->idate(dol_now())."',";
@@ -813,7 +813,7 @@ class Productcustomerprice extends CommonObject
 
 		// Find all susidiaries
 		$sql = "SELECT s.rowid";
-		$sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
+		$sql .= " FROM ".$this->db->prefix()."societe as s";
 		$sql .= " WHERE s.parent = ".((int) $this->fk_soc);
 		$sql .= " AND s.entity IN (".getEntity('societe').")";
 
@@ -911,7 +911,7 @@ class Productcustomerprice extends CommonObject
 		}
 
 		if (!$error) {
-			$sql = "DELETE FROM ".MAIN_DB_PREFIX."product_customer_price";
+			$sql = "DELETE FROM ".$this->db->prefix()."product_customer_price";
 			$sql .= " WHERE rowid=".((int) $this->id);
 
 			dol_syslog(get_class($this)."::delete", LOG_DEBUG);

+ 4 - 4
htdocs/product/class/productfournisseurprice.class.php

@@ -318,7 +318,7 @@ class ProductFournisseurPrice extends CommonObject
 
 		$sql = 'SELECT ';
 		$sql .= $this->getFieldList();
-		$sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
+		$sql .= ' FROM '.$this->db->prefix().$this->table_element.' as t';
 		if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) $sql .= ' WHERE t.entity IN ('.getEntity($this->element).')';
 		else $sql .= ' WHERE 1 = 1';
 		// Manage filter
@@ -433,7 +433,7 @@ class ProductFournisseurPrice extends CommonObject
 
 		if (!empty($num)) {
 			// Validate
-			$sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element;
+			$sql = "UPDATE ".$this->db->prefix().$this->table_element;
 			$sql .= " SET ref = '".$this->db->escape($num)."',";
 			$sql .= " status = ".self::STATUS_VALIDATED;
 			if (!empty($this->fields['date_validation'])) $sql .= ", date_validation = '".$this->db->idate($now)."'";
@@ -462,7 +462,7 @@ class ProductFournisseurPrice extends CommonObject
 			// Rename directory if dir was a temporary ref
 			if (preg_match('/^[\(]?PROV/i', $this->ref)) {
 				// Now we rename also files into index
-				$sql = 'UPDATE '.MAIN_DB_PREFIX."ecm_files set filename = CONCAT('".$this->db->escape($this->newref)."', SUBSTR(filename, ".(strlen($this->ref) + 1).")), filepath = 'productfournisseurprice/".$this->db->escape($this->newref)."'";
+				$sql = 'UPDATE '.$this->db->prefix()."ecm_files set filename = CONCAT('".$this->db->escape($this->newref)."', SUBSTR(filename, ".(strlen($this->ref) + 1).")), filepath = 'productfournisseurprice/".$this->db->escape($this->newref)."'";
 				$sql .= " WHERE filename LIKE '".$this->db->escape($this->ref)."%' AND filepath = 'productfournisseurprice/".$this->db->escape($this->ref)."' and entity = ".$conf->entity;
 				$resql = $this->db->query($sql);
 				if (!$resql) { $error++; $this->error = $this->db->lasterror(); }
@@ -700,7 +700,7 @@ class ProductFournisseurPrice extends CommonObject
 	{
 		$sql = 'SELECT rowid, date_creation as datec, tms as datem,';
 		$sql .= ' fk_user_creat, fk_user_modif';
-		$sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
+		$sql .= ' FROM '.$this->db->prefix().$this->table_element.' as t';
 		$sql .= ' WHERE t.rowid = '.((int) $id);
 		$result = $this->db->query($sql);
 		if ($result) {

+ 8 - 8
htdocs/product/class/propalmergepdfproduct.class.php

@@ -104,7 +104,7 @@ class Propalmergepdfproduct extends CommonObject
 		// Put here code to add control on parameters values
 
 		// Insert request
-		$sql = "INSERT INTO ".MAIN_DB_PREFIX."propal_merge_pdf_product(";
+		$sql = "INSERT INTO ".$this->db->prefix()."propal_merge_pdf_product(";
 		$sql .= "fk_product,";
 		$sql .= "file_name,";
 		if ($conf->global->MAIN_MULTILANGS) {
@@ -132,7 +132,7 @@ class Propalmergepdfproduct extends CommonObject
 		}
 
 		if (!$error) {
-			$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."propal_merge_pdf_product");
+			$this->id = $this->db->last_insert_id($this->db->prefix()."propal_merge_pdf_product");
 		}
 
 		// Commit or rollback
@@ -173,7 +173,7 @@ class Propalmergepdfproduct extends CommonObject
 		$sql .= " t.import_key";
 
 
-		$sql .= " FROM ".MAIN_DB_PREFIX."propal_merge_pdf_product as t";
+		$sql .= " FROM ".$this->db->prefix()."propal_merge_pdf_product as t";
 		$sql .= " WHERE t.rowid = ".((int) $id);
 
 		dol_syslog(__METHOD__, LOG_DEBUG);
@@ -231,7 +231,7 @@ class Propalmergepdfproduct extends CommonObject
 		$sql .= " t.import_key";
 
 
-		$sql .= " FROM ".MAIN_DB_PREFIX."propal_merge_pdf_product as t";
+		$sql .= " FROM ".$this->db->prefix()."propal_merge_pdf_product as t";
 		$sql .= " WHERE t.fk_product = ".((int) $product_id);
 		if (!empty($conf->global->MAIN_MULTILANGS) && !empty($lang)) {
 			$sql .= " AND t.lang = '".$this->db->escape($lang)."'";
@@ -307,7 +307,7 @@ class Propalmergepdfproduct extends CommonObject
 		// Put here code to add a control on parameters values
 
 		// Update request
-		$sql = "UPDATE ".MAIN_DB_PREFIX."propal_merge_pdf_product SET";
+		$sql = "UPDATE ".$this->db->prefix()."propal_merge_pdf_product SET";
 
 		$sql .= " fk_product=".(isset($this->fk_product) ? $this->fk_product : "null").",";
 		$sql .= " file_name=".(isset($this->file_name) ? "'".$this->db->escape($this->file_name)."'" : "null").",";
@@ -357,7 +357,7 @@ class Propalmergepdfproduct extends CommonObject
 		$this->db->begin();
 
 		if (!$error) {
-			$sql = "DELETE FROM ".MAIN_DB_PREFIX."propal_merge_pdf_product";
+			$sql = "DELETE FROM ".$this->db->prefix()."propal_merge_pdf_product";
 			$sql .= " WHERE rowid=".((int) $this->id);
 
 			dol_syslog(__METHOD__, LOG_DEBUG);
@@ -400,7 +400,7 @@ class Propalmergepdfproduct extends CommonObject
 		$this->db->begin();
 
 		if (!$error) {
-			$sql = "DELETE FROM ".MAIN_DB_PREFIX."propal_merge_pdf_product";
+			$sql = "DELETE FROM ".$this->db->prefix()."propal_merge_pdf_product";
 			$sql .= " WHERE fk_product = ".((int) $product_id);
 
 			if ($conf->global->MAIN_MULTILANGS && !empty($lang_id)) {
@@ -444,7 +444,7 @@ class Propalmergepdfproduct extends CommonObject
 		$this->db->begin();
 
 		if (!$error) {
-			$sql = "DELETE FROM ".MAIN_DB_PREFIX."propal_merge_pdf_product";
+			$sql = "DELETE FROM ".$this->db->prefix()."propal_merge_pdf_product";
 			$sql .= " WHERE fk_product = ".((int) $this->fk_product)." AND file_name = '".$this->db->escape($this->file_name)."'";
 
 			dol_syslog(__METHOD__, LOG_DEBUG);