canot delete product with supplier refs

This commit is contained in:
tiaris 2011-07-29 06:59:36 +00:00
parent 2f9f32e204
commit a76ffc8777

View File

@ -17,14 +17,15 @@
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/ */
/** /**
* \file htdocs/product/class/product.class.php * \file htdocs/product/class/product.class.php
* \ingroup produit * \ingroup produit
* \brief Fichier de la classe des produits predefinis * \brief Fichier de la classe des produits predefinis
* \version $Id: product.class.php,v 1.48 2011/07/31 23:24:03 eldy Exp $ * \version $Id: product.class.php,v 1.46 2011/07/29 06:59:36 tiaris Exp $
*/ */
require_once(DOL_DOCUMENT_ROOT ."/core/class/commonobject.class.php"); require_once(DOL_DOCUMENT_ROOT ."/core/class/commonobject.class.php");
@ -191,14 +192,13 @@ class Product extends CommonObject
/** /**
* Insert product into database * Insert product into database
* @param user User making insert * @param user User making insert
* @param notrigger Disable triggers * @return int id of product/service if OK or number of error < 0
* @return int Id of product/service if OK or number of error < 0
*/ */
function create($user,$notrigger=0) function create($user)
{ {
global $conf, $langs; global $conf ;
$error=0; $this->errno = 0;
// Clean parameters // Clean parameters
$this->ref = dol_string_nospecial(trim($this->ref)); $this->ref = dol_string_nospecial(trim($this->ref));
@ -250,27 +250,23 @@ class Product extends CommonObject
$this->error='ErrorWrongParameters'; $this->error='ErrorWrongParameters';
return -1; return -1;
} }
if (empty($this->ref))
{
$this->error='ErrorWrongParameters';
return -2;
}
dol_syslog("Product::Create ref=".$this->ref." price=".$this->price." price_ttc=".$this->price_ttc." tva_tx=".$this->tva_tx." price_base_type=".$this->price_base_type." Category : ".$this->catid, LOG_DEBUG); dol_syslog("Product::Create ref=".$this->ref." price=".$this->price." price_ttc=".$this->price_ttc." tva_tx=".$this->tva_tx." price_base_type=".$this->price_base_type." Category : ".$this->catid, LOG_DEBUG);
if ($this->ref)
{
$this->db->begin(); $this->db->begin();
$sql = "SELECT count(*) as nb"; $sql = "SELECT count(*)";
$sql.= " FROM ".MAIN_DB_PREFIX."product"; $sql.= " FROM ".MAIN_DB_PREFIX."product";
$sql.= " WHERE ref = '" .$this->ref."'"; $sql.= " WHERE ref = '" .$this->ref."'";
$sql.= " AND entity = ".$conf->entity; $sql.= " AND entity = ".$conf->entity;
$result = $this->db->query($sql); $result = $this->db->query($sql) ;
if ($result) if ($result)
{ {
$obj = $this->db->fetch_object($result); $row = $this->db->fetch_array($result);
if ($obj->nb == 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 (";
@ -285,8 +281,6 @@ class Product extends CommonObject
$sql.= ", price"; $sql.= ", price";
$sql.= ", price_ttc"; $sql.= ", price_ttc";
$sql.= ", price_base_type"; $sql.= ", price_base_type";
$sql.= ", tobuy";
$sql.= ", tosell";
$sql.= ", canvas"; $sql.= ", canvas";
$sql.= ", finished"; $sql.= ", finished";
$sql.= ", hidden"; $sql.= ", hidden";
@ -302,8 +296,6 @@ class Product extends CommonObject
$sql.= ", ".price2num($price_ht); $sql.= ", ".price2num($price_ht);
$sql.= ", ".price2num($price_ttc); $sql.= ", ".price2num($price_ttc);
$sql.= ", '".$this->price_base_type."'"; $sql.= ", '".$this->price_base_type."'";
$sql.= ", ".$this->status;
$sql.= ", ".$this->status_buy;
$sql.= ", '".$this->canvas."'"; $sql.= ", '".$this->canvas."'";
$sql.= ", ".$this->finished; $sql.= ", ".$this->finished;
$sql.= ", ".$this->hidden; $sql.= ", ".$this->hidden;
@ -337,41 +329,42 @@ class Product extends CommonObject
} }
else else
{ {
$error++; $this->_setErrNo("Create",260,$this->error);
$this->error='ErrorFailedToUpdateRecord';
} }
} }
else else
{ {
$error++; $this->error=$this->db->error();
$this->error=$this->db->lasterror(); $this->_setErrNo("Create",264,$this->error);
} }
} }
else else
{ {
$error++; $this->_setErrNo("Create",259);
$this->error='ErrorFailedToGetInsertedId';
} }
} }
else else
{ {
$error++; $this->error=$this->db->error();
$this->error=$this->db->lasterror(); $this->_setErrNo("Create",258,$this->error);
} }
} }
else else
{ {
// Product already exists with this ref // Le produit existe deja
$langs->trans("Error")." : ".$langs->trans("ErrorProductAlreadyExists",$this->ref); $this->error='ErrorProductAlreadyExists';
} }
} }
else else
{ {
$error++; $this->_setErrNo("Create",263);
$this->error=$this->db->lasterror();
} }
if (! $error && ! $notrigger) /*
* END COMMIT
*/
if ($this->errno === 0)
{ {
// Appel des triggers // Appel des triggers
include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php"); include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php");
@ -379,19 +372,49 @@ class Product extends CommonObject
$result=$interface->run_triggers('PRODUCT_CREATE',$this,$user,$langs,$conf); $result=$interface->run_triggers('PRODUCT_CREATE',$this,$user,$langs,$conf);
if ($result < 0) { $error++; $this->errors=$interface->errors; } if ($result < 0) { $error++; $this->errors=$interface->errors; }
// Fin appel triggers // Fin appel triggers
}
if (! $error)
{
$this->db->commit(); $this->db->commit();
return $this->id; return $id;
} }
else else
{ {
$this->db->rollback(); $this->db->rollback();
return -$error; return -1;
} }
} }
else
{
$this->_setErrNo("Create",262);
return -2;
}
return -1;
}
/**
* Positionne le numero d'erreur
* @param func Nom de la fonction
* @param num Numero de l'erreur
* @param error string
*/
function _setErrNo($func, $num, $error='')
{
$this->errno = $num;
dol_syslog(get_class($this)."::".$func." - ERRNO(".$this->errno.")".($error?' - '.$error:''), LOG_ERR);
}
/**
* Retourne le texte de l'erreur
*/
function error()
{
$errs[257] = "ErrorProductAlreadyExists";
$errs[262] = "ErrorProductBadRefOrLabel";
return $errs[$this->errno];
}
/** /**
* Update a record into database * Update a record into database