Modif gestion des erreurs
This commit is contained in:
parent
870675f62f
commit
94a37e7c88
@ -75,6 +75,7 @@ class Product
|
|||||||
//! Intitule de l'erreur
|
//! Intitule de l'erreur
|
||||||
var $error;
|
var $error;
|
||||||
//! Numero de l'erreur
|
//! Numero de l'erreur
|
||||||
|
//! Numero d'erreur Plage 0256-0511
|
||||||
var $errno = 0;
|
var $errno = 0;
|
||||||
//! Canevas a utiliser si le produit n'est pas un produit generique
|
//! Canevas a utiliser si le produit n'est pas un produit generique
|
||||||
var $canvas;
|
var $canvas;
|
||||||
@ -132,19 +133,18 @@ class Product
|
|||||||
$price = ereg_replace(" ","", $price);
|
$price = ereg_replace(" ","", $price);
|
||||||
$price = ereg_replace(",",".", $price);
|
$price = ereg_replace(",",".", $price);
|
||||||
|
|
||||||
$this->price = $price;
|
$this->price = $price;
|
||||||
$this->price_base_type = $base_type;
|
$this->price_base_type = $base_type;
|
||||||
|
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* \brief Insère le produit en base
|
\brief Insère le produit en base
|
||||||
* \param user Utilisateur qui effectue l'insertion
|
\param user Utilisateur qui effectue l'insertion
|
||||||
* \return int id du produit ou numero d'erreur < 0
|
\return int id du produit ou numero d'erreur < 0
|
||||||
*/
|
*/
|
||||||
function create($user)
|
function create($user)
|
||||||
{
|
{
|
||||||
global $langs;
|
$this->errno = 0;
|
||||||
|
|
||||||
$this->ref = trim(sanitize_string($this->ref));
|
$this->ref = trim(sanitize_string($this->ref));
|
||||||
|
|
||||||
if ($this->tva_tx=='') $this->tva_tx = 0;
|
if ($this->tva_tx=='') $this->tva_tx = 0;
|
||||||
@ -153,103 +153,120 @@ class Product
|
|||||||
$this->price = price2num($this->price);
|
$this->price = price2num($this->price);
|
||||||
|
|
||||||
if (strlen(trim($this->price)) > 0 )
|
if (strlen(trim($this->price)) > 0 )
|
||||||
|
{
|
||||||
|
if ($this->price_base_type == 'TTC')
|
||||||
{
|
{
|
||||||
if ($this->price_base_type == 'TTC')
|
$price_ttc = $this->price;
|
||||||
{
|
$price = $this->price / (1 + ($this->tva_tx / 100));
|
||||||
$price_ttc = $this->price;
|
}
|
||||||
$price = $this->price / (1 + ($this->tva_tx / 100));
|
else
|
||||||
}
|
{
|
||||||
else
|
$price = $this->price;
|
||||||
{
|
$price_ttc = $this->price * (1 + ($this->tva_tx / 100));
|
||||||
$price = $this->price;
|
}
|
||||||
$price_ttc = $this->price * (1 + ($this->tva_tx / 100));
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
dolibarr_syslog("Product::Create ref=".$this->ref." Categorie : ".$this->catid);
|
dolibarr_syslog("Product::Create ref=".$this->ref." Categorie : ".$this->catid);
|
||||||
|
|
||||||
if (strlen($this->ref) > 0)
|
if (strlen($this->ref) > 0)
|
||||||
{
|
{
|
||||||
$this->db->begin();
|
$this->db->begin();
|
||||||
|
|
||||||
$sql = "SELECT count(*)";
|
$sql = "SELECT count(*)";
|
||||||
$sql .= " FROM ".MAIN_DB_PREFIX."product WHERE ref = '" .$this->ref."'";
|
$sql .= " FROM ".MAIN_DB_PREFIX."product WHERE ref = '" .$this->ref."'";
|
||||||
|
|
||||||
$result = $this->db->query($sql) ;
|
$result = $this->db->query($sql) ;
|
||||||
if ($result)
|
if ($result)
|
||||||
{
|
{
|
||||||
$row = $this->db->fetch_array($result);
|
$row = $this->db->fetch_array($result);
|
||||||
if ($row[0] == 0)
|
if ($row[0] == 0)
|
||||||
{
|
{
|
||||||
// Produit non deja existant
|
// Produit non deja existant
|
||||||
$sql = "INSERT INTO ".MAIN_DB_PREFIX."product ";
|
$sql = "INSERT INTO ".MAIN_DB_PREFIX."product ";
|
||||||
$sql.= " (datec, ";
|
$sql.= " (datec, ";
|
||||||
if ($this->ref) $sql.= "ref, ";
|
if ($this->ref) $sql.= "ref, ";
|
||||||
$sql.= "fk_user_author, fk_product_type, price, price_ttc, price_base_type, canvas)";
|
$sql.= "fk_user_author, fk_product_type, price, price_ttc, price_base_type, canvas)";
|
||||||
$sql.= " VALUES (now(), ";
|
$sql.= " VALUES (now(), ";
|
||||||
if ($this->ref) $sql.= "'".$this->ref."', ";
|
if ($this->ref) $sql.= "'".$this->ref."', ";
|
||||||
$sql.= $user->id.", ".$this->type.", '" . $price . "', '".$price_ttc."', '" . $this->price_base_type . "','".$this->canvas."')";
|
$sql.= $user->id.", ".$this->type.", '" . $price . "', '".$price_ttc."', '" . $this->price_base_type . "','".$this->canvas."')";
|
||||||
$result = $this->db->query($sql);
|
$result = $this->db->query($sql);
|
||||||
if ( $result )
|
if ( $result )
|
||||||
|
{
|
||||||
|
$id = $this->db->last_insert_id(MAIN_DB_PREFIX."product");
|
||||||
|
|
||||||
|
if ($id > 0)
|
||||||
{
|
{
|
||||||
$id = $this->db->last_insert_id(MAIN_DB_PREFIX."product");
|
$this->id = $id;
|
||||||
|
$this->_log_price($user);
|
||||||
if ($id > 0)
|
if ( $this->update($id, $user) > 0)
|
||||||
{
|
{
|
||||||
$this->id = $id;
|
if ($this->catid > 0)
|
||||||
$this->_log_price($user);
|
{
|
||||||
if ( $this->update($id, $user) > 0)
|
$cat = new Categorie ($this->db, $this->catid);
|
||||||
{
|
$cat->add_product($this);
|
||||||
if ($this->catid > 0)
|
}
|
||||||
{
|
}
|
||||||
$cat = new Categorie ($this->db, $this->catid);
|
else
|
||||||
$cat->add_product($this);
|
{
|
||||||
}
|
$this->errno = 260;
|
||||||
$this->db->commit();
|
}
|
||||||
return $id;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$this->db->rollback();
|
|
||||||
return -5;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$this->db->rollback();
|
|
||||||
return -4;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$this->error=$this->db->error()." - sql=".$sql;
|
$this->errno = 259;
|
||||||
$this->db->rollback();
|
|
||||||
return -3;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Produit existe deja
|
$this->errno = 258;
|
||||||
$this->error=$langs->trans("ErrorProductAlreadyExists", $this->ref);
|
}
|
||||||
$this->errno = 257;
|
}
|
||||||
$this->db->rollback();
|
else
|
||||||
return -2;
|
{
|
||||||
}
|
// Produit existe deja
|
||||||
}
|
$this->errno = 257;
|
||||||
|
}
|
||||||
$this->error=$this->db->error();
|
}
|
||||||
$this->db->rollback();
|
else
|
||||||
}
|
{
|
||||||
|
$this->errno = 263;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* END COMMIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
if ($this->errno === 0)
|
||||||
|
{
|
||||||
|
$this->db->commit();
|
||||||
|
return $id;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$this->db->rollback();
|
||||||
|
dolibarr_syslog("Product::Create ROLLBACK ERRNO (".$this->errno.")");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Produit existe deja
|
$this->errno = 262;
|
||||||
$this->error=$langs->trans("ErrorProductBadRefOrLabel");
|
|
||||||
$this->errno = 257;
|
|
||||||
return -2;
|
return -2;
|
||||||
}
|
}
|
||||||
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function error($errno)
|
||||||
|
{
|
||||||
|
|
||||||
|
$errs[257] = "ErrorProductAlreadyExists";
|
||||||
|
$errs[262] = "ErrorProductBadRefOrLabel";
|
||||||
|
|
||||||
|
return $errs[$errno];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Mise à jour du produit en base
|
* \brief Mise à jour du produit en base
|
||||||
* \param id id du produit
|
* \param id id du produit
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user