diff --git a/htdocs/product/class/product.class.php b/htdocs/product/class/product.class.php index ef1ec0a856e..89a7ac8a910 100644 --- a/htdocs/product/class/product.class.php +++ b/htdocs/product/class/product.class.php @@ -926,7 +926,7 @@ class Product extends CommonObject // Delete all child tables if (! $error) { - $elements = array('product_fournisseur_price','product_price','product_lang','categorie_product','product_stock','product_customer_price','product_lot'); + $elements = array('product_fournisseur_price','product_price','product_lang','categorie_product','product_stock','product_customer_price','product_lot','product_stock_entrepot'); foreach($elements as $table) { if (! $error) diff --git a/htdocs/product/stock/class/entrepot.class.php b/htdocs/product/stock/class/entrepot.class.php index d01d1709335..d99de70f506 100644 --- a/htdocs/product/stock/class/entrepot.class.php +++ b/htdocs/product/stock/class/entrepot.class.php @@ -221,17 +221,24 @@ class Entrepot extends CommonObject { $this->db->begin(); - $sql = "DELETE FROM ".MAIN_DB_PREFIX."stock_mouvement"; - $sql.= " WHERE fk_entrepot = " . $this->id; - dol_syslog(get_class($this)."::delete", LOG_DEBUG); - $resql1=$this->db->query($sql); + $elements = array('stock_mouvement','product_stock','product_stock_entrepot'); + foreach($elements as $table) + { + if (! $error) + { + $sql = "DELETE FROM ".MAIN_DB_PREFIX.$table; + $sql.= " WHERE fk_entrepot = " . $this->id; + dol_syslog(get_class($this)."::delete", LOG_DEBUG); + $result=$this->db->query($sql); + if (! $result) + { + $error++; + $this->errors[] = $this->db->lasterror(); + } + } + } - $sql = "DELETE FROM ".MAIN_DB_PREFIX."product_stock"; - $sql.= " WHERE fk_entrepot = " . $this->id; - dol_syslog(get_class($this)."::delete", LOG_DEBUG); - $resql2=$this->db->query($sql); - - if ($resql1 && $resql2) + if (! $error) { $sql = "DELETE FROM ".MAIN_DB_PREFIX."entrepot"; $sql.= " WHERE rowid = " . $this->id; diff --git a/htdocs/product/stock/class/productstockentrepot.class.php b/htdocs/product/stock/class/productstockentrepot.class.php index cffc14532d9..e11467940d7 100644 --- a/htdocs/product/stock/class/productstockentrepot.class.php +++ b/htdocs/product/stock/class/productstockentrepot.class.php @@ -229,7 +229,8 @@ class ProductStockEntrepot extends CommonObject /** * Load object in memory from the database * - * @param int $fk_product Product from which we want to get limit and desired stock by warehouse + * @param int $fk_product Product from which we want to get limit and desired stock by warehouse + * @param int $fk_entrepot Warehouse in which we want to get products limit and desired stock * @param string $sortorder Sort Order * @param string $sortfield Sort field * @param int $limit offset limit @@ -239,7 +240,7 @@ class ProductStockEntrepot extends CommonObject * * @return int <0 if KO, >0 if OK */ - public function fetchAll($fk_product='', $sortorder='', $sortfield='', $limit=0, $offset=0, array $filter = array(), $filtermode='AND') + public function fetchAll($fk_product='', $fk_entrepot='', $sortorder='', $sortfield='', $limit=0, $offset=0, array $filter = array(), $filtermode='AND') { dol_syslog(__METHOD__, LOG_DEBUG); @@ -268,36 +269,29 @@ class ProductStockEntrepot extends CommonObject if (count($sqlwhere) > 0) $sql .= ' AND ' . implode(' '.$filtermode.' ', $sqlwhere); if(!empty($fk_product)) $sql .= ' AND fk_product = '.$fk_product; + elseif(!empty($fk_entrepot)) $sql .= ' AND fk_entrepot = '.$fk_entrepot; + // "elseif" used instead of "if" because getting list with specified fk_product and specified fk_entrepot would be the same as doing a fetch if (!empty($sortfield)) $sql .= $this->db->order($sortfield,$sortorder); if (!empty($limit)) $sql .= ' ' . $this->db->plimit($limit + 1, $offset); - $this->lines = array(); + $lines = array(); $resql = $this->db->query($sql); if ($resql) { - $num = $this->db->num_rows($resql); - + while ($obj = $this->db->fetch_object($resql)) { - - //$line->tms = $this->db->jdate($obj->tms); - $line->seuil_stock_alerte = $obj->seuil_stock_alerte; - $line->desiredstock = $obj->desiredstock; - //$line->import_key = $obj->import_key; - - - - $this->lines[$obj->rowid] = array( - 'id'=>$obj->rowid - ,'fk_product'=>$obj->fk_product - ,'fk_entrepot'=>$obj->fk_entrepot - ,'seuil_stock_alerte'=>$obj->seuil_stock_alerte - ,'desiredstock'=>$obj->desiredstock - ); + $lines[$obj->rowid] = array( + 'id'=>$obj->rowid + ,'fk_product'=>$obj->fk_product + ,'fk_entrepot'=>$obj->fk_entrepot + ,'seuil_stock_alerte'=>$obj->seuil_stock_alerte + ,'desiredstock'=>$obj->desiredstock + ); } $this->db->free($resql); - return $num; + return $lines; } else { $this->errors[] = 'Error ' . $this->db->lasterror(); dol_syslog(__METHOD__ . ' ' . implode(',', $this->errors), LOG_ERR); diff --git a/htdocs/product/stock/product.php b/htdocs/product/stock/product.php index 8ef8e2bc486..4482e249410 100644 --- a/htdocs/product/stock/product.php +++ b/htdocs/product/stock/product.php @@ -937,12 +937,12 @@ if(!empty($conf->global->STOCK_ALLOW_ADD_LIMIT_STOCK_BY_WAREHOUSE)) { print ''; $pse = new ProductStockEntrepot($db); - $pse->fetchAll(GETPOST('id')); + $lines = $pse->fetchAll(GETPOST('id')); - if(!empty($pse->lines)) { + if(!empty($lines)) { $var=false; - foreach($pse->lines as $line) { + foreach($lines as $line) { $ent = new Entrepot($db); $ent->fetch($line['fk_entrepot']);