Qual: Mise en transaction creation ligne commande

This commit is contained in:
Laurent Destailleur 2005-08-14 02:46:33 +00:00
parent a691947a84
commit 1db9003b84

View File

@ -361,34 +361,38 @@ class Commande
} }
} }
} }
/** /**
* Ajoute une ligne de commande * Ajoute une ligne de commande
* *
*/ */
function addline($desc, $pu, $qty, $txtva, $fk_product=0, $remise_percent=0) function addline($desc, $pu, $qty, $txtva, $fk_product=0, $remise_percent=0)
{ {
// Nettoyage parametres
$qty = ereg_replace(",",".",$qty); $qty = ereg_replace(",",".",$qty);
$pu = ereg_replace(",",".",$pu); $pu = ereg_replace(",",".",$pu);
$desc=trim($desc);
if ($this->brouillon && strlen(trim($desc)))
{
if (strlen(trim($qty))==0) if (strlen(trim($qty))==0)
{ {
$qty=1; $qty=1;
} }
// Verifs
if (! $this->brouillon) return -1;
$this->db->begin();
if ($fk_product > 0) if ($fk_product > 0)
{ {
$prod = new Product($this->db, $fk_product); $prod = new Product($this->db, $fk_product);
if ($prod->fetch($fk_product) > 0) if ($prod->fetch($fk_product) > 0)
{ {
$desc = $prod->libelle; $desc = $desc?$desc:$prod->libelle;
$pu = $prod->price; $pu = $prod->price;
$txtva = $prod->tva_tx; $txtva = $prod->tva_tx;
} }
} }
$remise = 0; $remise = 0;
$price = round(ereg_replace(",",".",$pu), 2); $price = round(ereg_replace(",",".",$pu), 2);
$subprice = $price; $subprice = $price;
@ -404,15 +408,17 @@ class Commande
if ( $this->db->query( $sql) ) if ( $this->db->query( $sql) )
{ {
$this->update_price(); $this->update_price();
$this->db->commit();
return 1; return 1;
} }
else else
{ {
dolibarr_print_error($this->db); $this->error=$this->db->error();
$this->db->rollback();
return -1; return -1;
} }
} }
}
/** /**
* Ajoute un produit dans la commande * Ajoute un produit dans la commande
* *
@ -638,7 +644,7 @@ class Commande
} }
else else
{ {
dolibarr_print_error($this->db); dolibarr_syslog("Commande::set_remise Erreur SQL");
} }
} }
} }
@ -867,7 +873,6 @@ class Commande
} }
else else
{ {
dolibarr_print_error($this->db);
$this->error=$this->db->error(); $this->error=$this->db->error();
return -1; return -1;
} }
@ -938,7 +943,9 @@ class Commande
class CommandeLigne class CommandeLigne
{ {
var $pu; function CommandeLigne()
{
}
} }
?> ?>