From 9df9702d1184fe0dcdb834c8d1a878cb25a42db6 Mon Sep 17 00:00:00 2001 From: Rodolphe Quiedeville Date: Mon, 4 Dec 2006 21:03:17 +0000 Subject: [PATCH] Ajuste les stocks de commande des sous-produits --- htdocs/product.class.php | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/htdocs/product.class.php b/htdocs/product.class.php index 0c4a1e7cbd0..75efe59d6b9 100644 --- a/htdocs/product.class.php +++ b/htdocs/product.class.php @@ -1412,6 +1412,35 @@ class Product } } + /** + * \brief Remplit le tableau des sous-produits + * \return int < 0 si erreur, > 0 si ok + */ + function load_subproduct() + { + $this->subproducts_id = array(); + $i = 0; + + $sql = "SELECT fk_product_subproduct FROM ".MAIN_DB_PREFIX."product_subproduct"; + $sql .= " WHERE fk_product=$this->id;"; + + if ($result = $this->db->query($sql)) + { + while ($row = $this->db->fetch_row($result) ) + { + $this->subproducts_id[$i] = $row[0]; + $i++; + } + $this->db->free($result); + return 0; + } + else + { + return -1; + } + } + + /** * \brief Lie un sous produit au produit/service * \param id_sub Id du produit à lier @@ -1990,6 +2019,16 @@ class Product if ($this->db->query($sql) ) { + + $this->load_subproduct(); + + for ($i = 0 ; $i < sizeof($this->subproducts_id) ; $i++) + { + $product = new Product($this->db); + $product->id = $this->subproducts_id[$i]; + $product->ajust_stock_commande($nbpiece, $mouvement); + } + $this->db->commit(); return 1; }