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,21 +163,19 @@ 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');
|
||||
$price_ttc = price2num($this->price_ttc,'MU');
|
||||
$price_ht = price2num($this->price_ttc / (1 + ($this->tva_tx / 100)),'MU');
|
||||
}
|
||||
else
|
||||
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
|
||||
if (empty($this->libelle))
|
||||
@ -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)
|
||||
@ -976,7 +973,7 @@ class Product extends CommonObject
|
||||
{
|
||||
$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_ttc[$i]=$result["price_ttc"];
|
||||
|
||||
@ -85,8 +85,9 @@ if ($_POST["action"] == 'add' && $user->rights->produit->creer)
|
||||
|
||||
$product->ref = $_POST["ref"];
|
||||
$product->libelle = $_POST["libelle"];
|
||||
$product->price = $_POST["price"];
|
||||
$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->type = $_POST["type"];
|
||||
$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
|
||||
if ($_POST["action"] == 'update' &&
|
||||
$_POST["cancel"] <> $langs->trans("Cancel") &&
|
||||
$user->rights->produit->creer)
|
||||
$_POST["cancel"] <> $langs->trans("Cancel") &&
|
||||
$user->rights->produit->creer)
|
||||
{
|
||||
$product = new Product($db);
|
||||
if ($product->fetch($_POST["id"]))
|
||||
@ -220,18 +221,22 @@ if ($_GET["action"] == 'clone' && $user->rights->produit->creer)
|
||||
// $product->clone_fournisseurs($originalId, $id);
|
||||
|
||||
$db->commit();
|
||||
$db->close();
|
||||
|
||||
Header("Location: fiche.php?id=$id");
|
||||
$db->close();
|
||||
exit;
|
||||
}
|
||||
else if ($id == -3)
|
||||
else
|
||||
{
|
||||
if ($product->error == 'ErrorProductAlreadyExists')
|
||||
{
|
||||
$db->rollback();
|
||||
|
||||
$_error = 1;
|
||||
$_GET["action"] = "";
|
||||
dolibarr_print_error($product->db);
|
||||
|
||||
$mesg='<div class="error">'.$langs->trans("ErrorProductAlreadyExists",$product->ref).'</div>';
|
||||
//dolibarr_print_error($product->db);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -240,6 +245,7 @@ if ($_GET["action"] == 'clone' && $user->rights->produit->creer)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$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)
|
||||
{
|
||||
$product = new Product($db);
|
||||
@ -557,7 +563,7 @@ if ($_GET["action"] == 'create' && $user->rights->produit->creer)
|
||||
|
||||
llxHeader("","",$langs->trans("CardProduct".$product->type));
|
||||
|
||||
if ($mesg) print "$mesg\n";
|
||||
if ($mesg) print $mesg."\n";
|
||||
|
||||
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"])
|
||||
{
|
||||
$product = new Product($db);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user