Qual: Make code simpler.
This commit is contained in:
parent
54040bed1d
commit
c87c7703cd
@ -2122,7 +2122,7 @@ class Product extends CommonObject
|
|||||||
* Define value of this->res
|
* Define value of this->res
|
||||||
*
|
*
|
||||||
* @param array $prod Products array
|
* @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 $multiply Because each sublevel must be multiplicated by parent nb
|
||||||
* @param int $level Init level
|
* @param int $level Init level
|
||||||
* @return void
|
* @return void
|
||||||
@ -2132,7 +2132,8 @@ class Product extends CommonObject
|
|||||||
global $conf,$langs;
|
global $conf,$langs;
|
||||||
|
|
||||||
$product = new Product($this->db);
|
$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
|
if (is_array($desc_pere)) // If this parent desc is an array, this is an array of childs
|
||||||
{
|
{
|
||||||
@ -2140,24 +2141,13 @@ class Product extends CommonObject
|
|||||||
$nb=(! empty($desc_pere[1]) ? $desc_pere[1] :'');
|
$nb=(! empty($desc_pere[1]) ? $desc_pere[1] :'');
|
||||||
$type=(! empty($desc_pere[2]) ? $desc_pere[2] :'');
|
$type=(! empty($desc_pere[2]) ? $desc_pere[2] :'');
|
||||||
$label=(! empty($desc_pere[3]) ? $desc_pere[3] :'');
|
$label=(! empty($desc_pere[3]) ? $desc_pere[3] :'');
|
||||||
|
if ($multiply < 1) $multiply=1;
|
||||||
|
|
||||||
if ($multiply)
|
//print "XXX We add id=".$id." - label=".$label." - nb=".$nb." - multiply=".$multiply." fullpath=".$compl_path.$label."\n";
|
||||||
{
|
|
||||||
//print "XXX ".$desc_pere[1]." multiply=".$multiply;
|
|
||||||
$img="";
|
|
||||||
$this->fetch($id);
|
$this->fetch($id);
|
||||||
$this->load_stock();
|
$this->load_stock();
|
||||||
if ($this->stock_warehouse[1]->real < $this->seuil_stock_alerte)
|
|
||||||
{
|
|
||||||
$img=img_warning($langs->trans("StockTooLow"));
|
|
||||||
}
|
|
||||||
$this->res[]= array(
|
$this->res[]= array(
|
||||||
/* "<tr><td> ->
|
'id'=>$id, // Id product
|
||||||
<a href=\"".DOL_URL_ROOT."/product/fiche.php?id=".$desc_pere[0]."\">".$compl_path.stripslashes($nom_pere)."
|
|
||||||
</a> (".$desc_pere[1].")</td><td align=\"center\"> ".($desc_pere[1]*$multiply)."</td><td> </td><td> </td>
|
|
||||||
<td align=\"center\">".$this->stock_entrepot[1]." ".$img."</td></tr>",
|
|
||||||
$desc_pere[0], // Id product
|
|
||||||
*/ 'id'=>$id, // Id product
|
|
||||||
'nb'=>$nb, // Nb of units that compose parent product
|
'nb'=>$nb, // Nb of units that compose parent product
|
||||||
'nb_total'=>$nb*$multiply, // Nb of units for all nb of product
|
'nb_total'=>$nb*$multiply, // Nb of units for all nb of product
|
||||||
'stock'=>$this->stock_warehouse[1]->real, // Stock
|
'stock'=>$this->stock_warehouse[1]->real, // Stock
|
||||||
@ -2166,32 +2156,12 @@ class Product extends CommonObject
|
|||||||
'type'=>$type // Nb of units that compose parent product
|
'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
|
|
||||||
'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
|
|
||||||
'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);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Recursive call if child is an array
|
// 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();
|
$this->res = array();
|
||||||
if (isset($this->sousprods) && is_array($this->sousprods))
|
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;
|
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
|
* @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
|
* @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 = "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.= " FROM ".MAIN_DB_PREFIX."product as p";
|
||||||
$sql.= ", ".MAIN_DB_PREFIX."product_association as pa";
|
$sql.= ", ".MAIN_DB_PREFIX."product_association as pa";
|
||||||
$sql.= " WHERE p.rowid = pa.fk_product_fils";
|
$sql.= " WHERE p.rowid = pa.fk_product_fils";
|
||||||
$sql.= " AND pa.fk_product_pere = ".$fk_parent;
|
$sql.= " AND pa.fk_product_pere = ".$id;
|
||||||
$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_fils != ".$id; // This should not happens, it is to avoid infinite loop if it happens
|
||||||
|
|
||||||
dol_syslog(get_class($this).'::getChildsArbo sql='.$sql);
|
dol_syslog(get_class($this).'::getChildsArbo sql='.$sql);
|
||||||
$res = $this->db->query($sql);
|
$res = $this->db->query($sql);
|
||||||
@ -2351,7 +2322,7 @@ class Product extends CommonObject
|
|||||||
$listofchilds=$this->getChildsArbo($rec['id']);
|
$listofchilds=$this->getChildsArbo($rec['id']);
|
||||||
foreach($listofchilds as $keyChild => $valueChild)
|
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()
|
function get_sousproduits_arbo()
|
||||||
{
|
{
|
||||||
$parent = $this->getParent();
|
$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)
|
foreach($this->getChildsArbo($value[0]) as $keyChild => $valueChild)
|
||||||
{
|
{
|
||||||
$parent[$key][$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;
|
$this->sousprods[$key] = $value;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -227,7 +227,7 @@ if ($id || $ref)
|
|||||||
//print $value[0]; // This contains a tr line.
|
//print $value[0]; // This contains a tr line.
|
||||||
print '<tr>';
|
print '<tr>';
|
||||||
//print '<td>'.$productstatic->getNomUrl(1,'composition').' ('.$value['nb'].($value['nb_total'] > $value['nb']?'->'.$value['nb_total']:'').')    </td>';
|
//print '<td>'.$productstatic->getNomUrl(1,'composition').' ('.$value['nb'].($value['nb_total'] > $value['nb']?'->'.$value['nb_total']:'').')    </td>';
|
||||||
print '<td>'.$productstatic->getNomUrl(1,'composition').' ('.$value['nb_total'].')    </td>';
|
print '<td>'.$productstatic->getNomUrl(1,'composition').' ('.$value['nb'].')    </td>';
|
||||||
if (! empty($conf->stock->enabled)) print '<td>'.$langs->trans("Stock").' : <b>'.$productstatic->stock_reel.'</b></td>';
|
if (! empty($conf->stock->enabled)) print '<td>'.$langs->trans("Stock").' : <b>'.$productstatic->stock_reel.'</b></td>';
|
||||||
print '</tr>';
|
print '</tr>';
|
||||||
}
|
}
|
||||||
@ -292,12 +292,14 @@ if ($id || $ref)
|
|||||||
// Number of subproducts
|
// Number of subproducts
|
||||||
$prodsfather = $product->getFather(); //Parent Products
|
$prodsfather = $product->getFather(); //Parent Products
|
||||||
$product->get_sousproduits_arbo();
|
$product->get_sousproduits_arbo();
|
||||||
print '<tr><td>'.$langs->trans("AssociatedProductsNumber").'</td><td>'.count($product->get_arbo_each_prod()).'</td>';
|
$prods_arbo=$product->get_arbo_each_prod();
|
||||||
|
$nbofsubproducts=count($prods_arbo);
|
||||||
|
print '<tr><td>'.$langs->trans("AssociatedProductsNumber").'</td><td>';
|
||||||
|
print $form->textwithpicto($nbofsubproducts, $langs->trans('IfZeroItIsNotAVirtualProduct'));
|
||||||
|
print '</td>';
|
||||||
print '</tr>';
|
print '</tr>';
|
||||||
|
|
||||||
// List of subproducts
|
// List of subproducts
|
||||||
$prods_arbo = $product->get_arbo_each_prod();
|
|
||||||
//var_dump($prods_arbo);
|
|
||||||
if(count($prods_arbo) > 0)
|
if(count($prods_arbo) > 0)
|
||||||
{
|
{
|
||||||
print '<tr><td colspan="2">';
|
print '<tr><td colspan="2">';
|
||||||
@ -322,8 +324,10 @@ if ($id || $ref)
|
|||||||
print '</td></tr>';
|
print '</td></tr>';
|
||||||
}
|
}
|
||||||
|
|
||||||
// Number of parent products
|
// Number of parent virtual products
|
||||||
print '<tr><td>'.$langs->trans("ParentProductsNumber").'</td><td>'.count($prodsfather).'</td>';
|
print '<tr><td>'.$langs->trans("ParentProductsNumber").'</td><td>';
|
||||||
|
print $form->textwithpicto(count($prodsfather), $langs->trans('IfZeroItIsNotUsedByVirtualProduct'));
|
||||||
|
print '</td>';
|
||||||
|
|
||||||
if (count($prodsfather) > 0)
|
if (count($prodsfather) > 0)
|
||||||
{
|
{
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user