diff --git a/htdocs/commande/class/commande.class.php b/htdocs/commande/class/commande.class.php index c1dd64cb80c..d6a3109426e 100644 --- a/htdocs/commande/class/commande.class.php +++ b/htdocs/commande/class/commande.class.php @@ -1,9 +1,9 @@ - * Copyright (C) 2004-2010 Laurent Destailleur - * Copyright (C) 2005-2010 Regis Houssin + * Copyright (C) 2004-2011 Laurent Destailleur + * Copyright (C) 2005-2011 Regis Houssin * Copyright (C) 2006 Andre Cianfarani - * Copyright (C) 2010 Juanjo Menent + * Copyright (C) 2010-2011 Juanjo Menent * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -953,7 +953,7 @@ class Commande extends CommonObject $rangtouse = $rang; if ($rangtouse == -1) { - $rangmax = $this->line_max(); + $rangmax = $this->line_max($fk_parent_line); $rangtouse = $rangmax + 1; } @@ -998,16 +998,19 @@ class Commande extends CommonObject $this->line->price=$price; $this->line->remise=$remise; - $resInsert=$this->line->insert(); - if ($resInsert > 0) + $result=$this->line->insert(); + 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 commande meme $this->id=$commandeid; // TODO A virer $result=$this->update_price(1); if ($result > 0) { $this->db->commit(); - return $resInsert; + return $this->line->rowid; } else { @@ -2777,7 +2780,7 @@ class OrderLine } $this->db->commit(); - return $this->rowid; + return 1; } else { diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php index c0a8c7b6cb9..5a7c4cc27ed 100644 --- a/htdocs/compta/facture/class/facture.class.php +++ b/htdocs/compta/facture/class/facture.class.php @@ -1728,7 +1728,7 @@ class Facture extends CommonObject $rangtouse = $rang; if ($rangtouse == -1) { - $rangmax = $this->line_max(); + $rangmax = $this->line_max($fk_parent_line); $rangtouse = $rangmax + 1; } @@ -1785,6 +1785,9 @@ class Facture extends CommonObject $result=$this->line->insert(); 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 facture meme $this->id=$facid; // TODO To move this we must remove parameter facid into this function declaration $result=$this->update_price(1); @@ -3055,6 +3058,8 @@ class FactureLigne var $rowid; //! Id facture var $fk_facture; + //! Id parent line + var $fk_parent_line; //! Description ligne var $desc; var $fk_product; // Id of predefined product