Fix: Bad price when cloning a product with a price with tax

This commit is contained in:
Laurent Destailleur 2008-08-04 00:30:52 +00:00
parent b5660d62dc
commit 759b0395be
2 changed files with 769 additions and 766 deletions

View File

@ -48,8 +48,8 @@ class Product extends CommonObject
var $libelle; var $libelle;
var $description; var $description;
//! Prix de vente //! Prix de vente
var $price; var $price; // Price without tax
var $price_ttc; var $price_ttc; // Price with tax
//! Base de prix (ttc ou ht) //! Base de prix (ttc ou ht)
var $price_base_type; var $price_base_type;
//! Tableau des prix multiples //! Tableau des prix multiples
@ -122,14 +122,14 @@ class Product extends CommonObject
$this->canvas = ''; $this->canvas = '';
if ($id>0) $this->fetch($id); if ($id>0) $this->fetch($id);
} }
/** /**
* \brief V<EFBFBD>rifie que la r<EFBFBD>f<EFBFBD>rence et libell<EFBFBD> du produit est non null * \brief Check that ref and label are ok
* \return int 1 si ok, 0 sinon * \return int >1 if OK, <=0 if KO
*/ */
function check() function check()
{ {
$this->ref = ereg_replace("'","",stripslashes($this->ref)); $this->ref = sanitize_string(stripslashes($this->ref));
$this->ref = ereg_replace("\"","",stripslashes($this->ref));
$err = 0; $err = 0;
if (strlen(trim($this->ref)) == 0) if (strlen(trim($this->ref)) == 0)
@ -149,9 +149,9 @@ class Product extends CommonObject
} }
/** /**
\brief Insert product in database * \brief Insert product in database
\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)
{ {
@ -163,20 +163,18 @@ class Product extends CommonObject
if ($this->tva_tx=='') $this->tva_tx = 0; if ($this->tva_tx=='') $this->tva_tx = 0;
if ($this->price=='') $this->price = 0; if ($this->price=='') $this->price = 0;
if ($this->status=='') $this->status = 0; if ($this->status=='') $this->status = 0;
$price_ht=0; $price_ht=0;
$price_ttc=0; $price_ttc=0;
if ($this->price > 0) if ($this->price_base_type == 'TTC' && $this->price_ttc > 0)
{ {
if ($this->price_base_type == 'TTC') $price_ttc = price2num($this->price_ttc,'MU');
{ $price_ht = price2num($this->price_ttc / (1 + ($this->tva_tx / 100)),'MU');
$price_ttc = price2num($this->price,'MU'); }
$price_ht = price2num($this->price / (1 + ($this->tva_tx / 100)),'MU'); if ($this->price_base_type != 'TTC' && $this->price > 0)
} {
else $price_ht = price2num($this->price,'MU');
{ $price_ttc = price2num($this->price * (1 + ($this->tva_tx / 100)),'MU');
$price_ht = price2num($this->price,'MU');
$price_ttc = price2num($this->price * (1 + ($this->tva_tx / 100)),'MU');
}
} }
// Check parameters // Check parameters
@ -186,7 +184,7 @@ class Product extends CommonObject
return -1; return -1;
} }
dolibarr_syslog("Product::Create ref=".$this->ref." price=".$this->price." tva_tx=".$this->tva_tx." Categorie : ".$this->catid); dolibarr_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." Categorie : ".$this->catid);
if ($this->ref) if ($this->ref)
{ {
@ -266,7 +264,7 @@ class Product extends CommonObject
else else
{ {
// Le produit existe deja // Le produit existe deja
$this->_setErrNo("Create",257); $this->error='ErrorProductAlreadyExists';
} }
} }
else else
@ -286,7 +284,6 @@ class Product extends CommonObject
else else
{ {
$this->db->rollback(); $this->db->rollback();
$this->_setErrNo("Create",265);
return -1; return -1;
} }
} }
@ -325,7 +322,7 @@ class Product extends CommonObject
/** /**
\brief Mise <EFBFBD> jour du produit en base \brief Mise a jour du produit en base
\param id id du produit \param id id du produit
\param user utilisateur qui effectue l'insertion \param user utilisateur qui effectue l'insertion
\return int 1 si ok, -1 si ref deja existante, -2 autre erreur \return int 1 si ok, -1 si ref deja existante, -2 autre erreur
@ -393,7 +390,7 @@ class Product extends CommonObject
} }
/** /**
* \brief V<EFBFBD>rification de l'utilisation du produit en base * \brief Verification de l'utilisation du produit en base
* \param id id du produit * \param id id du produit
*/ */
function verif_prod_use($id) function verif_prod_use($id)
@ -949,13 +946,13 @@ class Product extends CommonObject
$result = $this->db->query($sql) ; $result = $this->db->query($sql) ;
if ($result) if ($result)
{ {
$result = $this->db->fetch_array(); $result = $this->db->fetch_array();
$prodid = $result["rowid"]; $prodid = $result["rowid"];
} }
else else
{ {
dolibarr_print_error($this->db); dolibarr_print_error($this->db);
return -1; return -1;
} }
} }
@ -974,33 +971,33 @@ class Product extends CommonObject
$result = $this->db->query($sql) ; $result = $this->db->query($sql) ;
if ( $result ) if ( $result )
{ {
$result = $this->db->fetch_array(); $result = $this->db->fetch_array();
if($result["price"] != "" && $result["price"] != "0.00") if ($result["price"] != "" && $result["price"] != "0.00")
{ {
$this->multiprices[$i]=$result["price"]; $this->multiprices[$i]=$result["price"];
$this->multiprices_ttc[$i]=$result["price_ttc"]; $this->multiprices_ttc[$i]=$result["price_ttc"];
$this->multiprices_base_type[$i] = $result["price_base_type"]; $this->multiprices_base_type[$i] = $result["price_base_type"];
} }
else else
{ {
$this->multiprices[$i]=$this->price; $this->multiprices[$i]=$this->price;
$this->multiprices_ttc[$i]=$this->price_ttc; $this->multiprices_ttc[$i]=$this->price_ttc;
$this->multiprices_base_type[$i] = $this->price_base_type; $this->multiprices_base_type[$i] = $this->price_base_type;
} }
} }
else else
{ {
dolibarr_print_error($this->db); dolibarr_print_error($this->db);
return -1; return -1;
} }
} }
} }
$res=$this->load_stock(); $res=$this->load_stock();
return $res; return $res;
} }
else else
{ {

File diff suppressed because it is too large Load Diff