diff --git a/htdocs/comm/propal/class/propal.class.php b/htdocs/comm/propal/class/propal.class.php index 6adbc8f94d1..4731f0343da 100644 --- a/htdocs/comm/propal/class/propal.class.php +++ b/htdocs/comm/propal/class/propal.class.php @@ -495,24 +495,31 @@ class Propal extends CommonObject $staticline=new PropaleLigne($this->db); $staticline->fetch($rowid); $this->line->oldline = $staticline; - - $this->line->rowid=$rowid; - $this->line->desc=$desc; - $this->line->qty=$qty; - $this->line->tva_tx=$txtva; - $this->line->localtax1_tx=$txlocaltax1; - $this->line->localtax2_tx=$txlocaltax2; - $this->line->remise_percent=$remise_percent; - $this->line->subprice=$pu; - $this->line->info_bits=$info_bits; - $this->line->total_ht=$total_ht; - $this->line->total_tva=$total_tva; - $this->line->total_localtax1=$total_localtax1; - $this->line->total_localtax2=$total_localtax2; - $this->line->total_ttc=$total_ttc; - $this->line->special_code=$special_code; - $this->line->fk_parent_line=$fk_parent_line; - $this->line->skip_update_total=$skip_update_total; + + // Reorder if fk_parent_line change + if (! empty($fk_parent_line) && ! empty($staticline->fk_parent_line) && $fk_parent_line != $staticline->fk_parent_line) + { + $rangmax = $this->line_max($fk_parent_line); + $this->line->rang = $rangmax + 1; + } + + $this->line->rowid = $rowid; + $this->line->desc = $desc; + $this->line->qty = $qty; + $this->line->tva_tx = $txtva; + $this->line->localtax1_tx = $txlocaltax1; + $this->line->localtax2_tx = $txlocaltax2; + $this->line->remise_percent = $remise_percent; + $this->line->subprice = $pu; + $this->line->info_bits = $info_bits; + $this->line->total_ht = $total_ht; + $this->line->total_tva = $total_tva; + $this->line->total_localtax1 = $total_localtax1; + $this->line->total_localtax2 = $total_localtax2; + $this->line->total_ttc = $total_ttc; + $this->line->special_code = $special_code; + $this->line->fk_parent_line = $fk_parent_line; + $this->line->skip_update_total = $skip_update_total; // TODO deprecated $this->line->price=$price; @@ -521,6 +528,9 @@ class Propal extends CommonObject $result=$this->line->update(); if ($result > 0) { + // Reorder if child line + if (! empty($fk_parent_line)) $this->line_order(true,'DESC'); + $this->update_price(1); $this->fk_propal = $this->id; @@ -2646,8 +2656,9 @@ class PropaleLigne } /** - * \brief Mise a jour de l'objet ligne de propale en base - * \return int <0 si ko, >0 si ok + * Mise a jour de l'objet ligne de propale en base + * + * @return int <0 si ko, >0 si ok */ function update($notrigger=0) { @@ -2692,9 +2703,10 @@ class PropaleLigne $sql.= " , info_bits=".$this->info_bits; if (strlen($this->special_code)) $sql.= " , special_code=".$this->special_code; $sql.= " , fk_parent_line=".($this->fk_parent_line>0?$this->fk_parent_line:"null"); + if (! empty($this->rang)) $sql.= ", rang=".$this->rang; $sql.= " WHERE rowid = ".$this->rowid; - dol_syslog("PropaleLigne::update sql=$sql"); + dol_syslog(get_class($this)."::update sql=".$sql, LOG_DEBUG); $resql=$this->db->query($sql); if ($resql) { @@ -2714,7 +2726,7 @@ class PropaleLigne else { $this->error=$this->db->error(); - dol_syslog("PropaleLigne::update Error ".$this->error, LOG_ERR); + dol_syslog(get_class($this)."::update Error ".$this->error, LOG_ERR); $this->db->rollback(); return -2; } diff --git a/htdocs/commande/class/commande.class.php b/htdocs/commande/class/commande.class.php index 409df18639f..6f33f315b6d 100644 --- a/htdocs/commande/class/commande.class.php +++ b/htdocs/commande/class/commande.class.php @@ -2222,6 +2222,13 @@ class Commande extends CommonObject $staticline=new OrderLine($this->db); $staticline->fetch($rowid); $this->line->oldline = $staticline; + + // Reorder if fk_parent_line change + if (! empty($fk_parent_line) && ! empty($staticline->fk_parent_line) && $fk_parent_line != $staticline->fk_parent_line) + { + $rangmax = $this->line_max($fk_parent_line); + $this->line->rang = $rangmax + 1; + } $this->line->rowid=$rowid; $this->line->desc=$desc; @@ -2250,6 +2257,9 @@ class Commande extends CommonObject $result=$this->line->update(); if ($result > 0) { + // Reorder if child line + if (! empty($fk_parent_line)) $this->line_order(true,'DESC'); + // Mise a jour info denormalisees $this->update_price(1); @@ -3095,11 +3105,10 @@ class OrderLine if ($this->date_end) { $sql.= " , date_end='".$this->db->idate($this->date_end)."'"; } $sql.= " , product_type=".$this->product_type; $sql.= " , fk_parent_line=".($this->fk_parent_line>0?$this->fk_parent_line:"null"); - + if (! empty($this->rang)) $sql.= ", rang=".$this->rang; $sql.= " WHERE rowid = ".$this->rowid; - dol_syslog("OrderLine::update sql=$sql"); - + dol_syslog(get_class($this)."::update sql=".$sql, LOG_DEBUG); $resql=$this->db->query($sql); if ($resql) { @@ -3119,7 +3128,7 @@ class OrderLine else { $this->error=$this->db->error(); - dol_syslog("OrderLine::update Error ".$this->error, LOG_ERR); + dol_syslog(get_class($this)."::update Error ".$this->error, LOG_ERR); $this->db->rollback(); return -2; } diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php index c65623d2cfe..9bcd64fd4e3 100644 --- a/htdocs/compta/facture/class/facture.class.php +++ b/htdocs/compta/facture/class/facture.class.php @@ -2016,6 +2016,13 @@ class Facture extends CommonObject $staticline=new FactureLigne($this->db); $staticline->fetch($rowid); $this->line->oldline = $staticline; + + // Reorder if fk_parent_line change + if (! empty($fk_parent_line) && ! empty($staticline->fk_parent_line) && $fk_parent_line != $staticline->fk_parent_line) + { + $rangmax = $this->line_max($fk_parent_line); + $this->line->rang = $rangmax + 1; + } $this->line->rowid = $rowid; $this->line->desc = $desc; @@ -2044,6 +2051,9 @@ class Facture extends CommonObject $result=$this->line->update(); if ($result > 0) { + // Reorder if child line + if (! empty($fk_parent_line)) $this->line_order(true,'DESC'); + // Mise a jour info denormalisees au niveau facture $this->update_price(1); $this->db->commit(); @@ -3567,8 +3577,9 @@ class FactureLigne } /** - * Update line into database - * @return int <0 if KO, >0 if OK + * Update line into database + * + * @return int <0 if KO, >0 if OK */ function update() { @@ -3621,10 +3632,10 @@ class FactureLigne $sql.= ",total_localtax1=".price2num($this->total_localtax1).""; $sql.= ",total_localtax2=".price2num($this->total_localtax2).""; $sql.= ",fk_parent_line=".($this->fk_parent_line>0?$this->fk_parent_line:"null"); + if (! empty($this->rang)) $sql.= ", rang=".$this->rang; $sql.= " WHERE rowid = ".$this->rowid; - dol_syslog("FactureLigne::update sql=".$sql); - + dol_syslog(get_class($this)."::update sql=".$sql, LOG_DEBUG); $resql=$this->db->query($sql); if ($resql) { @@ -3643,7 +3654,7 @@ class FactureLigne else { $this->error=$this->db->error(); - dol_syslog("FactureLigne::update Error ".$this->error, LOG_ERR); + dol_syslog(get_class($this)."::update Error ".$this->error, LOG_ERR); $this->db->rollback(); return -2; } diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index d7399da1a40..62051b58c37 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -967,6 +967,8 @@ abstract class CommonObject { $sql = 'SELECT rang FROM '.MAIN_DB_PREFIX.$this->table_element_line; $sql.= ' WHERE rowid ='.$rowid; + + dol_syslog(get_class($this)."::getRangOfLine sql=".$sql, LOG_DEBUG); $resql = $this->db->query($sql); if ($resql) { @@ -1008,13 +1010,18 @@ abstract class CommonObject $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; + + dol_syslog(get_class($this)."::line_max sql=".$sql, LOG_DEBUG); $resql = $this->db->query($sql); if ($resql) { $row = $this->db->fetch_row($resql); - if (! empty($row[0])) { + if (! empty($row[0])) + { return $row[0]; - } else { + } + else + { return $this->getRangOfLine($fk_parent_line); } } @@ -1024,6 +1031,8 @@ abstract class CommonObject { $sql = 'SELECT max(rang) FROM '.MAIN_DB_PREFIX.$this->table_element_line; $sql.= ' WHERE '.$this->fk_element.' = '.$this->id; + + dol_syslog(get_class($this)."::line_max sql=".$sql, LOG_DEBUG); $resql = $this->db->query($sql); if ($resql) {