Fix: correct reorder line with fk_parent_line
Fix: problem with create order from proposals with fk_parent_line
This commit is contained in:
parent
d6291a65a3
commit
ecd673399f
@ -350,7 +350,7 @@ class Propal extends CommonObject
|
|||||||
$rangtouse = $rang;
|
$rangtouse = $rang;
|
||||||
if ($rangtouse == -1)
|
if ($rangtouse == -1)
|
||||||
{
|
{
|
||||||
$rangmax = $this->line_max();
|
$rangmax = $this->line_max($fk_parent_line);
|
||||||
$rangtouse = $rangmax + 1;
|
$rangtouse = $rangmax + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -399,6 +399,9 @@ class Propal extends CommonObject
|
|||||||
$result=$this->line->insert();
|
$result=$this->line->insert();
|
||||||
if ($result > 0)
|
if ($result > 0)
|
||||||
{
|
{
|
||||||
|
// Reorder if child line
|
||||||
|
if (! empty($fk_parent_line)) $this->line_order(true,'DESC');
|
||||||
|
|
||||||
// Mise a jour informations denormalisees au niveau de la propale meme
|
// Mise a jour informations denormalisees au niveau de la propale meme
|
||||||
$result=$this->update_price(1);
|
$result=$this->update_price(1);
|
||||||
if ($result > 0)
|
if ($result > 0)
|
||||||
|
|||||||
@ -592,11 +592,19 @@ class Commande extends CommonObject
|
|||||||
|
|
||||||
if ($this->id)
|
if ($this->id)
|
||||||
{
|
{
|
||||||
|
$fk_parent_line=0;
|
||||||
|
$num=sizeof($this->lines);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Insertion du detail des produits dans la base
|
* Insertion du detail des produits dans la base
|
||||||
*/
|
*/
|
||||||
for ($i = 0 ; $i < sizeof($this->lines) ; $i++)
|
for ($i=0;$i<$num;$i++)
|
||||||
{
|
{
|
||||||
|
// Reset fk_parent_line for no child products and special product
|
||||||
|
if (($this->lines[$i]->product_type != 9 && empty($this->lines[$i]->fk_parent_line)) || $this->lines[$i]->product_type == 9) {
|
||||||
|
$fk_parent_line = 0;
|
||||||
|
}
|
||||||
|
|
||||||
$result = $this->addline(
|
$result = $this->addline(
|
||||||
$this->id,
|
$this->id,
|
||||||
$this->lines[$i]->desc,
|
$this->lines[$i]->desc,
|
||||||
@ -615,7 +623,8 @@ class Commande extends CommonObject
|
|||||||
$this->lines[$i]->date_end,
|
$this->lines[$i]->date_end,
|
||||||
$this->lines[$i]->product_type,
|
$this->lines[$i]->product_type,
|
||||||
$this->lines[$i]->rang,
|
$this->lines[$i]->rang,
|
||||||
$this->lines[$i]->special_code
|
$this->lines[$i]->special_code,
|
||||||
|
$fk_parent_line
|
||||||
);
|
);
|
||||||
if ($result < 0)
|
if ($result < 0)
|
||||||
{
|
{
|
||||||
@ -624,6 +633,10 @@ class Commande extends CommonObject
|
|||||||
$this->db->rollback();
|
$this->db->rollback();
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
// Defined the new fk_parent_line
|
||||||
|
if ($result > 0 && $this->lines[$i]->product_type == 9) {
|
||||||
|
$fk_parent_line = $result;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Mise a jour ref
|
// Mise a jour ref
|
||||||
@ -985,8 +998,8 @@ class Commande extends CommonObject
|
|||||||
$this->line->price=$price;
|
$this->line->price=$price;
|
||||||
$this->line->remise=$remise;
|
$this->line->remise=$remise;
|
||||||
|
|
||||||
$result=$this->line->insert();
|
$resInsert=$this->line->insert();
|
||||||
if ($result > 0)
|
if ($resInsert > 0)
|
||||||
{
|
{
|
||||||
// Mise a jour informations denormalisees au niveau de la commande meme
|
// Mise a jour informations denormalisees au niveau de la commande meme
|
||||||
$this->id=$commandeid; // TODO A virer
|
$this->id=$commandeid; // TODO A virer
|
||||||
@ -994,7 +1007,7 @@ class Commande extends CommonObject
|
|||||||
if ($result > 0)
|
if ($result > 0)
|
||||||
{
|
{
|
||||||
$this->db->commit();
|
$this->db->commit();
|
||||||
return 1;
|
return $resInsert;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
@ -700,7 +700,7 @@ class CommonObject
|
|||||||
* Stocke un numero de rang pour toutes les lignes de detail d'un element qui n'en ont pas.
|
* Stocke un numero de rang pour toutes les lignes de detail d'un element qui n'en ont pas.
|
||||||
* @param renum true to renum all already ordered lines, false to renum only not already ordered lines.
|
* @param renum true to renum all already ordered lines, false to renum only not already ordered lines.
|
||||||
*/
|
*/
|
||||||
function line_order($renum=false)
|
function line_order($renum=false, $rowidorder='ASC')
|
||||||
{
|
{
|
||||||
if (! $this->table_element_line)
|
if (! $this->table_element_line)
|
||||||
{
|
{
|
||||||
@ -727,7 +727,7 @@ class CommonObject
|
|||||||
{
|
{
|
||||||
$sql = 'SELECT rowid FROM '.MAIN_DB_PREFIX.$this->table_element_line;
|
$sql = 'SELECT rowid FROM '.MAIN_DB_PREFIX.$this->table_element_line;
|
||||||
$sql.= ' WHERE '.$this->fk_element.' = '.$this->id;
|
$sql.= ' WHERE '.$this->fk_element.' = '.$this->id;
|
||||||
$sql.= ' ORDER BY rang ASC, rowid ASC';
|
$sql.= ' ORDER BY rang ASC, rowid '.$rowidorder;
|
||||||
$resql = $this->db->query($sql);
|
$resql = $this->db->query($sql);
|
||||||
if ($resql)
|
if ($resql)
|
||||||
{
|
{
|
||||||
@ -736,14 +736,10 @@ class CommonObject
|
|||||||
while ($i < $num)
|
while ($i < $num)
|
||||||
{
|
{
|
||||||
$row = $this->db->fetch_row($resql);
|
$row = $this->db->fetch_row($resql);
|
||||||
$li[$i] = $row[0];
|
$this->updateRangOfLine($row[0], ($i+1));
|
||||||
$i++;
|
$i++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for ($i = 0 ; $i < sizeof($li) ; $i++)
|
|
||||||
{
|
|
||||||
$this->updateRangOfLine($li[$i], ($i+1));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -896,7 +892,27 @@ class CommonObject
|
|||||||
* Get max value used for position of line (rang)
|
* Get max value used for position of line (rang)
|
||||||
* @result int Max value of rang in table of lines
|
* @result int Max value of rang in table of lines
|
||||||
*/
|
*/
|
||||||
function line_max()
|
function line_max($fk_parent_line=0)
|
||||||
|
{
|
||||||
|
// Search the last rang with fk_parent_line
|
||||||
|
if ($fk_parent_line)
|
||||||
|
{
|
||||||
|
$sql = 'SELECT max(rang) FROM '.MAIN_DB_PREFIX.$this->table_element_line;
|
||||||
|
$sql.= ' WHERE '.$this->fk_element.' = '.$this->id;
|
||||||
|
$sql.= ' AND fk_parent_line = '.$fk_parent_line;
|
||||||
|
$resql = $this->db->query($sql);
|
||||||
|
if ($resql)
|
||||||
|
{
|
||||||
|
$row = $this->db->fetch_row($resql);
|
||||||
|
if (! empty($row[0])) {
|
||||||
|
return $row[0];
|
||||||
|
} else {
|
||||||
|
return $this->getRangOfLine($fk_parent_line);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// If not, search the last rang of element
|
||||||
|
else
|
||||||
{
|
{
|
||||||
$sql = 'SELECT max(rang) FROM '.MAIN_DB_PREFIX.$this->table_element_line;
|
$sql = 'SELECT max(rang) FROM '.MAIN_DB_PREFIX.$this->table_element_line;
|
||||||
$sql.= ' WHERE '.$this->fk_element.' = '.$this->id;
|
$sql.= ' WHERE '.$this->fk_element.' = '.$this->id;
|
||||||
@ -907,6 +923,7 @@ class CommonObject
|
|||||||
return $row[0];
|
return $row[0];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Update private note of element
|
* \brief Update private note of element
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user