Fix: Bad price when cloning a product with a price with tax
This commit is contained in:
parent
b5660d62dc
commit
759b0395be
@ -48,8 +48,8 @@ class Product extends CommonObject
|
||||
var $libelle;
|
||||
var $description;
|
||||
//! Prix de vente
|
||||
var $price;
|
||||
var $price_ttc;
|
||||
var $price; // Price without tax
|
||||
var $price_ttc; // Price with tax
|
||||
//! Base de prix (ttc ou ht)
|
||||
var $price_base_type;
|
||||
//! Tableau des prix multiples
|
||||
@ -122,14 +122,14 @@ class Product extends CommonObject
|
||||
$this->canvas = '';
|
||||
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
|
||||
* \return int 1 si ok, 0 sinon
|
||||
* \brief Check that ref and label are ok
|
||||
* \return int >1 if OK, <=0 if KO
|
||||
*/
|
||||
function check()
|
||||
{
|
||||
$this->ref = ereg_replace("'","",stripslashes($this->ref));
|
||||
$this->ref = ereg_replace("\"","",stripslashes($this->ref));
|
||||
$this->ref = sanitize_string(stripslashes($this->ref));
|
||||
|
||||
$err = 0;
|
||||
if (strlen(trim($this->ref)) == 0)
|
||||
@ -149,9 +149,9 @@ class Product extends CommonObject
|
||||
}
|
||||
|
||||
/**
|
||||
\brief Insert product in database
|
||||
\param user Utilisateur qui effectue l'insertion
|
||||
\return int id du produit ou numero d'erreur < 0
|
||||
* \brief Insert product in database
|
||||
* \param user Utilisateur qui effectue l'insertion
|
||||
* \return int id du produit ou numero d'erreur < 0
|
||||
*/
|
||||
function create($user)
|
||||
{
|
||||
@ -163,20 +163,18 @@ class Product extends CommonObject
|
||||
if ($this->tva_tx=='') $this->tva_tx = 0;
|
||||
if ($this->price=='') $this->price = 0;
|
||||
if ($this->status=='') $this->status = 0;
|
||||
|
||||
$price_ht=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,'MU');
|
||||
$price_ht = price2num($this->price / (1 + ($this->tva_tx / 100)),'MU');
|
||||
}
|
||||
else
|
||||
{
|
||||
$price_ht = price2num($this->price,'MU');
|
||||
$price_ttc = price2num($this->price * (1 + ($this->tva_tx / 100)),'MU');
|
||||
}
|
||||
$price_ttc = price2num($this->price_ttc,'MU');
|
||||
$price_ht = price2num($this->price_ttc / (1 + ($this->tva_tx / 100)),'MU');
|
||||
}
|
||||
if ($this->price_base_type != 'TTC' && $this->price > 0)
|
||||
{
|
||||
$price_ht = price2num($this->price,'MU');
|
||||
$price_ttc = price2num($this->price * (1 + ($this->tva_tx / 100)),'MU');
|
||||
}
|
||||
|
||||
// Check parameters
|
||||
@ -186,7 +184,7 @@ class Product extends CommonObject
|
||||
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)
|
||||
{
|
||||
@ -266,7 +264,7 @@ class Product extends CommonObject
|
||||
else
|
||||
{
|
||||
// Le produit existe deja
|
||||
$this->_setErrNo("Create",257);
|
||||
$this->error='ErrorProductAlreadyExists';
|
||||
}
|
||||
}
|
||||
else
|
||||
@ -286,7 +284,6 @@ class Product extends CommonObject
|
||||
else
|
||||
{
|
||||
$this->db->rollback();
|
||||
$this->_setErrNo("Create",265);
|
||||
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 user utilisateur qui effectue l'insertion
|
||||
\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
|
||||
*/
|
||||
function verif_prod_use($id)
|
||||
@ -949,13 +946,13 @@ class Product extends CommonObject
|
||||
$result = $this->db->query($sql) ;
|
||||
if ($result)
|
||||
{
|
||||
$result = $this->db->fetch_array();
|
||||
$prodid = $result["rowid"];
|
||||
$result = $this->db->fetch_array();
|
||||
$prodid = $result["rowid"];
|
||||
}
|
||||
else
|
||||
{
|
||||
dolibarr_print_error($this->db);
|
||||
return -1;
|
||||
dolibarr_print_error($this->db);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
@ -974,33 +971,33 @@ class Product extends CommonObject
|
||||
$result = $this->db->query($sql) ;
|
||||
if ( $result )
|
||||
{
|
||||
$result = $this->db->fetch_array();
|
||||
$result = $this->db->fetch_array();
|
||||
|
||||
if($result["price"] != "" && $result["price"] != "0.00")
|
||||
{
|
||||
$this->multiprices[$i]=$result["price"];
|
||||
$this->multiprices_ttc[$i]=$result["price_ttc"];
|
||||
$this->multiprices_base_type[$i] = $result["price_base_type"];
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->multiprices[$i]=$this->price;
|
||||
$this->multiprices_ttc[$i]=$this->price_ttc;
|
||||
$this->multiprices_base_type[$i] = $this->price_base_type;
|
||||
}
|
||||
if ($result["price"] != "" && $result["price"] != "0.00")
|
||||
{
|
||||
$this->multiprices[$i]=$result["price"];
|
||||
$this->multiprices_ttc[$i]=$result["price_ttc"];
|
||||
$this->multiprices_base_type[$i] = $result["price_base_type"];
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->multiprices[$i]=$this->price;
|
||||
$this->multiprices_ttc[$i]=$this->price_ttc;
|
||||
$this->multiprices_base_type[$i] = $this->price_base_type;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
dolibarr_print_error($this->db);
|
||||
return -1;
|
||||
dolibarr_print_error($this->db);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
$res=$this->load_stock();
|
||||
$res=$this->load_stock();
|
||||
|
||||
return $res;
|
||||
return $res;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user