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 $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,21 +163,19 @@ 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');
|
|
||||||
}
|
}
|
||||||
else
|
if ($this->price_base_type != 'TTC' && $this->price > 0)
|
||||||
{
|
{
|
||||||
$price_ht = price2num($this->price,'MU');
|
$price_ht = price2num($this->price,'MU');
|
||||||
$price_ttc = price2num($this->price * (1 + ($this->tva_tx / 100)),'MU');
|
$price_ttc = price2num($this->price * (1 + ($this->tva_tx / 100)),'MU');
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// Check parameters
|
// Check parameters
|
||||||
if (empty($this->libelle))
|
if (empty($this->libelle))
|
||||||
@ -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)
|
||||||
@ -976,7 +973,7 @@ class Product extends CommonObject
|
|||||||
{
|
{
|
||||||
$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"];
|
||||||
|
|||||||
@ -85,8 +85,9 @@ if ($_POST["action"] == 'add' && $user->rights->produit->creer)
|
|||||||
|
|
||||||
$product->ref = $_POST["ref"];
|
$product->ref = $_POST["ref"];
|
||||||
$product->libelle = $_POST["libelle"];
|
$product->libelle = $_POST["libelle"];
|
||||||
$product->price = $_POST["price"];
|
|
||||||
$product->price_base_type = $_POST["price_base_type"];
|
$product->price_base_type = $_POST["price_base_type"];
|
||||||
|
if ($product->price_base_type == 'TTC') $product->price_ttc = $_POST["price"];
|
||||||
|
else $product->price = $_POST["price"];
|
||||||
$product->tva_tx = $_POST["tva_tx"];
|
$product->tva_tx = $_POST["tva_tx"];
|
||||||
$product->type = $_POST["type"];
|
$product->type = $_POST["type"];
|
||||||
$product->status = $_POST["statut"];
|
$product->status = $_POST["statut"];
|
||||||
@ -142,8 +143,8 @@ if ($_POST["action"] == 'add' && $user->rights->produit->creer)
|
|||||||
|
|
||||||
// Action mise a jour d'un produit ou service
|
// Action mise a jour d'un produit ou service
|
||||||
if ($_POST["action"] == 'update' &&
|
if ($_POST["action"] == 'update' &&
|
||||||
$_POST["cancel"] <> $langs->trans("Cancel") &&
|
$_POST["cancel"] <> $langs->trans("Cancel") &&
|
||||||
$user->rights->produit->creer)
|
$user->rights->produit->creer)
|
||||||
{
|
{
|
||||||
$product = new Product($db);
|
$product = new Product($db);
|
||||||
if ($product->fetch($_POST["id"]))
|
if ($product->fetch($_POST["id"]))
|
||||||
@ -220,18 +221,22 @@ if ($_GET["action"] == 'clone' && $user->rights->produit->creer)
|
|||||||
// $product->clone_fournisseurs($originalId, $id);
|
// $product->clone_fournisseurs($originalId, $id);
|
||||||
|
|
||||||
$db->commit();
|
$db->commit();
|
||||||
|
$db->close();
|
||||||
|
|
||||||
Header("Location: fiche.php?id=$id");
|
Header("Location: fiche.php?id=$id");
|
||||||
$db->close();
|
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
else if ($id == -3)
|
else
|
||||||
|
{
|
||||||
|
if ($product->error == 'ErrorProductAlreadyExists')
|
||||||
{
|
{
|
||||||
$db->rollback();
|
$db->rollback();
|
||||||
|
|
||||||
$_error = 1;
|
$_error = 1;
|
||||||
$_GET["action"] = "";
|
$_GET["action"] = "";
|
||||||
dolibarr_print_error($product->db);
|
|
||||||
|
$mesg='<div class="error">'.$langs->trans("ErrorProductAlreadyExists",$product->ref).'</div>';
|
||||||
|
//dolibarr_print_error($product->db);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -240,6 +245,7 @@ if ($_GET["action"] == 'clone' && $user->rights->produit->creer)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$db->rollback();
|
$db->rollback();
|
||||||
@ -248,8 +254,8 @@ if ($_GET["action"] == 'clone' && $user->rights->produit->creer)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Suppression d'un produit/service pas encore affect
|
* Suppression d'un produit/service pas encore affect
|
||||||
*/
|
*/
|
||||||
if ($_POST['action'] == 'confirm_delete' && $_POST['confirm'] == 'yes' && $user->rights->produit->supprimer)
|
if ($_POST['action'] == 'confirm_delete' && $_POST['confirm'] == 'yes' && $user->rights->produit->supprimer)
|
||||||
{
|
{
|
||||||
$product = new Product($db);
|
$product = new Product($db);
|
||||||
@ -557,7 +563,7 @@ if ($_GET["action"] == 'create' && $user->rights->produit->creer)
|
|||||||
|
|
||||||
llxHeader("","",$langs->trans("CardProduct".$product->type));
|
llxHeader("","",$langs->trans("CardProduct".$product->type));
|
||||||
|
|
||||||
if ($mesg) print "$mesg\n";
|
if ($mesg) print $mesg."\n";
|
||||||
|
|
||||||
if (! $conf->global->PRODUCT_CANVAS_ABILITY || !$_GET["canvas"])
|
if (! $conf->global->PRODUCT_CANVAS_ABILITY || !$_GET["canvas"])
|
||||||
{
|
{
|
||||||
@ -711,10 +717,10 @@ if ($_GET["action"] == 'create' && $user->rights->produit->creer)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* Fiche produit
|
* Fiche produit
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
if ($_GET["id"] || $_GET["ref"])
|
if ($_GET["id"] || $_GET["ref"])
|
||||||
{
|
{
|
||||||
$product = new Product($db);
|
$product = new Product($db);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user