FIX : must not get full path with recursive query

This commit is contained in:
gauthier 2016-10-20 14:29:51 +02:00
parent 9a3d4031c5
commit 59941f9980
3 changed files with 35 additions and 7 deletions

View File

@ -67,7 +67,7 @@ class FormProduct
if (is_array($exclude)) $excludeGroups = implode("','",$exclude);
$sql = "SELECT e.rowid, e.label, e.description";
$sql = "SELECT e.rowid, e.label, e.description, e.fk_parent";
if (!empty($fk_product))
{
if (!empty($batch))
@ -118,14 +118,19 @@ class FormProduct
{
$obj = $this->db->fetch_object($resql);
if ($sumStock) $obj->stock = price2num($obj->stock,5);
$o = new Entrepot($this->db);
$o->fetch($obj->rowid);
$this->cache_warehouses[$obj->rowid]['id'] =$obj->rowid;
$this->cache_warehouses[$obj->rowid]['label']=$o->get_full_arbo();
$this->cache_warehouses[$obj->rowid]['label']=$obj->label;
$this->cache_warehouses[$obj->rowid]['parent_id']=$obj->fk_parent;
$this->cache_warehouses[$obj->rowid]['description'] = $obj->description;
$this->cache_warehouses[$obj->rowid]['stock'] = $obj->stock;
$i++;
}
// Full label init
foreach($this->cache_warehouses as $obj_rowid=>$tab) {
$this->cache_warehouses[$obj_rowid]['full_label'] = $this->get_parent_path($tab);
}
return $num;
}
else
@ -134,6 +139,29 @@ class FormProduct
return -1;
}
}
/**
* Return full path to current warehouse in $tab (recursive function)
*
* @param array $tab warehouse data in $this->cache_warehouses line
* @param String $final_label full label with all parents, separated by ' >> ' (completed on each call)
* @return String full label with all parents, separated by ' >> '
*/
private function get_parent_path($tab, $final_label='') {
if(empty($final_label)) $final_label = $tab['label'];
if(empty($tab['parent_id'])) return $final_label;
else {
if(!empty($this->cache_warehouses[$tab['parent_id']])) {
$final_label = $this->cache_warehouses[$tab['parent_id']]['label'].' >> '.$final_label;
return $this->get_parent_path($this->cache_warehouses[$tab['parent_id']], $final_label);
}
}
return $final_label;
}
/**
* Return list of warehouses
@ -178,7 +206,7 @@ class FormProduct
$out.='<option value="'.$id.'"';
if ($selected == $id || ($selected == 'ifone' && $nbofwarehouses == 1)) $out.=' selected';
$out.='>';
$out.=$arraytypes['label'];
$out.=$arraytypes['full_label'];
if (($fk_product || ($showstock > 0)) && ($arraytypes['stock'] != 0 || ($showstock > 0))) $out.=' ('.$langs->trans("Stock").':'.$arraytypes['stock'].')';
$out.='</option>';
}

View File

@ -646,7 +646,7 @@ else
// Parent entrepot
print '<tr><td>'.$langs->trans("AddIn").'</td><td>';
print $formproduct->selectWarehouses($object->fk_parent, 'fk_parent', '', 1, 0, 0, '', 0, 0, array(), 'minwidth200', array($object->id));
print $formproduct->selectWarehouses($object->fk_parent, 'fk_parent', '', 1);
print '</td></tr>';
// Description

View File

@ -174,7 +174,7 @@ class Entrepot extends CommonObject
{
// Check if new parent is already a child of current warehouse
if(!empty($this->fk_parent)) {
$TChildWarehouses = array();
$TChildWarehouses = array($id);
$TChildWarehouses = $this->get_children_warehouses($this->id, $TChildWarehouses);
if(in_array($this->fk_parent, $TChildWarehouses)) {
$this->error = 'ErrorCannotAddThisParentWarehouse';