diff --git a/htdocs/product/class/product.class.php b/htdocs/product/class/product.class.php
index 9422eed8250..8cac5ebe573 100644
--- a/htdocs/product/class/product.class.php
+++ b/htdocs/product/class/product.class.php
@@ -1803,7 +1803,7 @@ class Product extends CommonObject
$result=$this->del_sousproduit($id_pere, $id_fils);
if ($result < 0) return $result;
-
+
// 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 .= ' WHERE fk_product_pere = '.$id_fils.' AND fk_product_fils = '.$id_pere;
@@ -1852,11 +1852,11 @@ class Product extends CommonObject
{
if (! is_numeric($fk_parent)) $fk_parent=0;
if (! is_numeric($fk_child)) $fk_child=0;
-
+
$sql = "DELETE FROM ".MAIN_DB_PREFIX."product_association";
$sql.= " WHERE fk_product_pere = ".$fk_parent;
$sql.= " AND fk_product_fils = ".$fk_child;
-
+
dol_syslog(get_class($this).'::del_sousproduit sql='.$sql);
if (! $this->db->query($sql))
{
@@ -2122,7 +2122,7 @@ class Product extends CommonObject
* Define value of this->res
*
* @param array $prod Products array
- * @param string $compl_path Directory path
+ * @param string $compl_path Directory path of parents to add before
* @param int $multiply Because each sublevel must be multiplicated by parent nb
* @param int $level Init level
* @return void
@@ -2132,7 +2132,8 @@ class Product extends CommonObject
global $conf,$langs;
$product = new Product($this->db);
- foreach($prod as $nom_pere => $desc_pere)
+ //var_dump($prod);
+ foreach($prod as $id_product => $desc_pere) // nom_pere is 0 or id of sub_product
{
if (is_array($desc_pere)) // If this parent desc is an array, this is an array of childs
{
@@ -2140,58 +2141,27 @@ class Product extends CommonObject
$nb=(! empty($desc_pere[1]) ? $desc_pere[1] :'');
$type=(! empty($desc_pere[2]) ? $desc_pere[2] :'');
$label=(! empty($desc_pere[3]) ? $desc_pere[3] :'');
+ if ($multiply < 1) $multiply=1;
- if ($multiply)
- {
- //print "XXX ".$desc_pere[1]." multiply=".$multiply;
- $img="";
- $this->fetch($id);
- $this->load_stock();
- if ($this->stock_warehouse[1]->real < $this->seuil_stock_alerte)
- {
- $img=img_warning($langs->trans("StockTooLow"));
- }
- $this->res[]= array(
-/* "
| ->
- ".$compl_path.stripslashes($nom_pere)."
- (".$desc_pere[1].") | ".($desc_pere[1]*$multiply)." |   |   |
- ".$this->stock_entrepot[1]." ".$img." |
",
- $desc_pere[0], // Id product
-*/ 'id'=>$id, // Id product
- 'nb'=>$nb, // Nb of units that compose parent product
- 'nb_total'=>$nb*$multiply, // Nb of units for all nb of product
- 'stock'=>$this->stock_warehouse[1]->real, // Stock
- 'stock_alert'=>$this->seuil_stock_alerte, // Stock alert
- 'fullpath' => $compl_path.$label, // Label
- 'type'=>$type // Nb of units that compose parent product
- );
- }
- else
- {
- $this->fetch($desc_pere[0]);
- $this->load_stock();
- $this->res[]= array(
-/* $compl_path.$nom_pere." (".$desc_pere[1].")",
- $desc_pere[0], // Id product
-*/ 'id'=>$id, // Id product
+ //print "XXX We add id=".$id." - label=".$label." - nb=".$nb." - multiply=".$multiply." fullpath=".$compl_path.$label."\n";
+ $this->fetch($id);
+ $this->load_stock();
+ $this->res[]= array(
+ 'id'=>$id, // Id product
'nb'=>$nb, // Nb of units that compose parent product
- 'nb_total'=>$nb, // Nb of units for all nb of product
- 'stock'=>$this->stock_warehouse[1]->real, // Stock
+ 'nb_total'=>$nb*$multiply, // Nb of units for all nb of product
+ 'stock'=>$this->stock_warehouse[1]->real, // Stock
'stock_alert'=>$this->seuil_stock_alerte, // Stock alert
- 'fullpath' => $compl_path.$nom_pere, // Label
- 'type'=>$type // Nb of units that compose parent product
- );
- }
- }
- else if($nom_pere != "0" && $nom_pere != "1")
- {
- $this->res[]= array($compl_path.$nom_pere,$desc_pere);
+ 'fullpath' => $compl_path.$label, // Label
+ 'type'=>$type // Nb of units that compose parent product
+ );
}
// Recursive call if child is an array
- if (is_array($desc_pere[0]))
+ if (is_array($desc_pere['childs']))
{
- $this ->fetch_prod_arbo($desc_pere[0], $nom_pere." -> ", $desc_pere[1]*$multiply, $level+1);
+ //print 'YYY We go down for '.$desc_pere[3]." -> \n";
+ $this ->fetch_prod_arbo($desc_pere['childs'], $compl_path.$desc_pere[3]." -> ", $desc_pere[1]*$multiply, $level+1);
}
}
}
@@ -2228,11 +2198,12 @@ class Product extends CommonObject
$this->res = array();
if (isset($this->sousprods) && is_array($this->sousprods))
{
- foreach($this->sousprods as $nom_pere => $desc_pere)
+ foreach($this->sousprods as $prod_name => $desc_product)
{
- if (is_array($desc_pere)) $this->fetch_prod_arbo($desc_pere,"",$multiply);
+ if (is_array($desc_product)) $this->fetch_prod_arbo($desc_product,"",$multiply);
}
}
+ //var_dump($this->res);
return $this->res;
}
@@ -2293,7 +2264,7 @@ class Product extends CommonObject
/**
- * Return all parent products fo current product
+ * Return all direct parent products fo current product
*
* @return array prod
*/
@@ -2324,19 +2295,19 @@ class Product extends CommonObject
}
/**
- * Return childs of product with if fk_parent
+ * Return childs of product $id
*
- * @param int $fk_parent Id of product to search childs of
+ * @param int $id Id of product to search childs of
* @return array Prod
*/
- function getChildsArbo($fk_parent)
+ function getChildsArbo($id)
{
$sql = "SELECT p.rowid, p.label as label, pa.qty as qty, pa.fk_product_fils as id, p.fk_product_type";
$sql.= " FROM ".MAIN_DB_PREFIX."product as p";
$sql.= ", ".MAIN_DB_PREFIX."product_association as pa";
$sql.= " WHERE p.rowid = pa.fk_product_fils";
- $sql.= " AND pa.fk_product_pere = ".$fk_parent;
- $sql.= " AND pa.fk_product_fils != ".$fk_parent; // This should not happens, it is to avoid invinite loop if it happens
+ $sql.= " AND pa.fk_product_pere = ".$id;
+ $sql.= " AND pa.fk_product_fils != ".$id; // This should not happens, it is to avoid infinite loop if it happens
dol_syslog(get_class($this).'::getChildsArbo sql='.$sql);
$res = $this->db->query($sql);
@@ -2351,7 +2322,7 @@ class Product extends CommonObject
$listofchilds=$this->getChildsArbo($rec['id']);
foreach($listofchilds as $keyChild => $valueChild)
{
- $prods[$rec['rowid']][$keyChild] = $valueChild;
+ $prods[$rec['rowid']]['childs'][$keyChild] = $valueChild;
}
}
@@ -2373,14 +2344,14 @@ class Product extends CommonObject
function get_sousproduits_arbo()
{
$parent = $this->getParent();
- foreach($parent as $key => $value)
+ foreach($parent as $key => $value) // key=label, value[0]=id
{
foreach($this->getChildsArbo($value[0]) as $keyChild => $valueChild)
{
$parent[$key][$keyChild] = $valueChild;
}
}
- foreach($parent as $key => $value)
+ foreach($parent as $key => $value) // key=label, value is array of childs
{
$this->sousprods[$key] = $value;
}
@@ -2418,7 +2389,7 @@ class Product extends CommonObject
else if ($option == 'category')
{
$lien = '';
- }
+ }
else
{
$lien = '';
diff --git a/htdocs/product/composition/fiche.php b/htdocs/product/composition/fiche.php
index d02253b4d24..71ce35c76e1 100644
--- a/htdocs/product/composition/fiche.php
+++ b/htdocs/product/composition/fiche.php
@@ -227,7 +227,7 @@ if ($id || $ref)
//print $value[0]; // This contains a tr line.
print '';
//print '| '.$productstatic->getNomUrl(1,'composition').' ('.$value['nb'].($value['nb_total'] > $value['nb']?'->'.$value['nb_total']:'').')     | ';
- print ''.$productstatic->getNomUrl(1,'composition').' ('.$value['nb_total'].')     | ';
+ print ''.$productstatic->getNomUrl(1,'composition').' ('.$value['nb'].')     | ';
if (! empty($conf->stock->enabled)) print ''.$langs->trans("Stock").' : '.$productstatic->stock_reel.' | ';
print '
';
}
@@ -292,12 +292,14 @@ if ($id || $ref)
// Number of subproducts
$prodsfather = $product->getFather(); //Parent Products
$product->get_sousproduits_arbo();
- print '| '.$langs->trans("AssociatedProductsNumber").' | '.count($product->get_arbo_each_prod()).' | ';
+ $prods_arbo=$product->get_arbo_each_prod();
+ $nbofsubproducts=count($prods_arbo);
+ print '
| '.$langs->trans("AssociatedProductsNumber").' | ';
+ print $form->textwithpicto($nbofsubproducts, $langs->trans('IfZeroItIsNotAVirtualProduct'));
+ print ' | ';
print '
';
// List of subproducts
- $prods_arbo = $product->get_arbo_each_prod();
- //var_dump($prods_arbo);
if(count($prods_arbo) > 0)
{
print '| ';
@@ -322,8 +324,10 @@ if ($id || $ref)
print ' |
';
}
- // Number of parent products
- print '| '.$langs->trans("ParentProductsNumber").' | '.count($prodsfather).' | ';
+ // Number of parent virtual products
+ print '
| '.$langs->trans("ParentProductsNumber").' | ';
+ print $form->textwithpicto(count($prodsfather), $langs->trans('IfZeroItIsNotUsedByVirtualProduct'));
+ print ' | ';
if (count($prodsfather) > 0)
{