diff --git a/htdocs/product.class.php b/htdocs/product.class.php
index 1c80e1433b0..2ce6007f3a0 100644
--- a/htdocs/product.class.php
+++ b/htdocs/product.class.php
@@ -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�rifie que la r�f�rence et libell� 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,15 +184,15 @@ 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)
{
$this->db->begin();
-
+
$sql = "SELECT count(*)";
$sql .= " FROM ".MAIN_DB_PREFIX."product WHERE ref = '" .$this->ref."'";
-
+
$result = $this->db->query($sql) ;
if ($result)
{
@@ -216,7 +214,7 @@ class Product extends CommonObject
$sql.= price2num($price_ttc).",";
$sql.= "'".$this->price_base_type."',";
$sql.= "'".$this->canvas."')";
-
+
dolibarr_syslog("Product::Create sql=".$sql);
$result = $this->db->query($sql);
if ( $result )
@@ -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 � 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�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)
@@ -802,7 +799,7 @@ class Product extends CommonObject
$price_ttc = price2num($newprice) * (1 + ($newvat / 100));
$price_ttc = price2num($price_ttc,'MU');
}
-
+
// Ne pas mettre de quote sur le num�riques decimaux.
// Ceci provoque des sotckage avec arrondis en base au lieu des valeurs exactes.
$sql = "UPDATE ".MAIN_DB_PREFIX."product SET";
@@ -949,16 +946,16 @@ 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;
}
}
-
+
$this->multiprices[1] = $this->price;
$this->multiprices_ttc[1] = $this->price_ttc;
$this->multiprices_base_type[1] = $this->price_base_type;
@@ -974,33 +971,33 @@ class Product extends CommonObject
$result = $this->db->query($sql) ;
if ( $result )
{
- $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;
- }
+ $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;
+ }
}
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
{
@@ -1594,7 +1591,7 @@ class Product extends CommonObject
$sql = "INSERT INTO ".MAIN_DB_PREFIX."product_fournisseur ";
$sql .= " (datec, fk_product, fk_soc, ref_fourn, fk_user_author)";
$sql .= " VALUES (now(), ".$this->id.", ".$id_fourn.", '".$ref_fourn."', ".$user->id.")";
-
+
if ($this->db->query($sql))
{
$this->product_fourn_id = $this->db->last_insert_id(MAIN_DB_PREFIX."product_fournisseur");
@@ -2021,7 +2018,7 @@ class Product extends CommonObject
{
$sql = "INSERT INTO ".MAIN_DB_PREFIX."stock_mouvement (datem, fk_product, fk_entrepot, value, type_mouvement, fk_user_author)";
$sql .= " VALUES (now(), ".$this->id.", ".$id_entrepot.", ".$nbpiece.", 0, ".$user->id.")";
-
+
dolibarr_syslog("Product::create_stock sql=".$sql);
$resql=$this->db->query($sql);
if ($resql)
@@ -2106,7 +2103,7 @@ class Product extends CommonObject
{
$sql = "INSERT INTO ".MAIN_DB_PREFIX."stock_mouvement (datem, fk_product, fk_entrepot, value, type_mouvement, fk_user_author)";
$sql .= " VALUES (now(), ".$this->id.", ".$id_entrepot.", ".$op[$mouvement].", 0, ".$user->id.")";
-
+
dolibarr_syslog("Product::ajust_stock sql=".$sql);
$resql=$this->db->query($sql);
if ($resql)
@@ -2202,7 +2199,7 @@ class Product extends CommonObject
$this->stock_reel = $this->stock_reel + $row[0];
$i++;
}
-
+
$this->no_stock = 0;
}
else
@@ -2241,7 +2238,7 @@ class Product extends CommonObject
if (file_exists($dir))
{
$originImage = $dir . $file['name'];
-
+
// Cree fichier en taille origine
$result=dol_move_uploaded_file($file['tmp_name'], $originImage, 1);
@@ -2294,7 +2291,7 @@ class Product extends CommonObject
// Cree fichier en taille origine
$content = file_get_contents($files);
-
+
$nom = basename($files);
$im = fopen($dir.$nom,'wb');
fwrite($im, $content);
@@ -2317,7 +2314,7 @@ class Product extends CommonObject
if (file_exists($dir))
{
$handle=opendir($dir);
-
+
while (($file = readdir($handle)) != false)
{
if (is_file($dir.$file)) return true;
@@ -2355,7 +2352,7 @@ class Product extends CommonObject
{
$nbphoto++;
$photo = $file;
-
+
if ($size == 1) { // Format vignette
// On determine nom du fichier vignette
$photo_vignette='';
@@ -2427,14 +2424,14 @@ class Product extends CommonObject
if (file_exists($dir))
{
$handle=opendir($dir);
-
+
while (($file = readdir($handle)) != false)
{
if (is_file($dir.$file))
{
$nbphoto++;
$photo = $file;
-
+
// On determine nom du fichier vignette
$photo_vignette='';
if (eregi('(\.jpg|\.bmp|\.gif|\.png|\.tiff)$',$photo,$regs))
@@ -2454,7 +2451,7 @@ class Product extends CommonObject
if ($nbmax && $nbphoto >= $nbmax) break;
}
}
-
+
closedir($handle);
}
@@ -2470,10 +2467,10 @@ class Product extends CommonObject
$dir = dirname($file).'/'; // Chemin du dossier contenant l'image d'origine
$dirthumb = $dir.'/thumbs/'; // Chemin du dossier contenant la vignette
$filename = eregi_replace($dir,'',$file); // Nom du fichier
-
+
// On efface l'image d'origine
unlink($file);
-
+
// Si elle existe, on efface la vignette
if (eregi('(\.jpg|\.bmp|\.gif|\.png|\.tiff)$',$filename,$regs))
{
diff --git a/htdocs/product/fiche.php b/htdocs/product/fiche.php
index 9d1f05d7a71..3e64ac6e98c 100644
--- a/htdocs/product/fiche.php
+++ b/htdocs/product/fiche.php
@@ -48,11 +48,11 @@ if (!$user->rights->produit->lire) accessforbidden();
*/
if ($_GET["action"] == 'fastappro')
{
- $product = new Product($db);
- $product->fetch($_GET["id"]);
- $result = $product->fastappro($user);
- Header("Location: fiche.php?id=".$_GET["id"]);
- exit;
+ $product = new Product($db);
+ $product->fetch($_GET["id"]);
+ $result = $product->fastappro($user);
+ Header("Location: fiche.php?id=".$_GET["id"]);
+ exit;
}
@@ -60,7 +60,7 @@ if ($_GET["action"] == 'fastappro')
if ($_POST["action"] == 'add' && $user->rights->produit->creer)
{
$error=0;
-
+
if (empty($_POST["libelle"]))
{
$mesg='
'.$langs->trans('ErrorFieldRequired',$langs->transnoentities('Label')).'
';
@@ -69,7 +69,7 @@ if ($_POST["action"] == 'add' && $user->rights->produit->creer)
$_GET["type"] = $_POST["type"];
$error++;
}
-
+
if (! $error)
{
if ($_POST["canvas"] <> '' && file_exists('canvas/product.'.$_POST["canvas"].'.class.php') )
@@ -82,11 +82,12 @@ if ($_POST["action"] == 'add' && $user->rights->produit->creer)
{
$product = new Product($db);
}
-
+
$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"];
@@ -117,14 +118,14 @@ if ($_POST["action"] == 'add' && $user->rights->produit->creer)
}
}
}
-
+
if ( $value != $current_lang ) $e_product = $product;
-
+
// Produit spécifique
// $_POST n'est pas utilise dans la classe Product
// mais dans des classes qui hérite de Product
$id = $product->create($user, $_POST);
-
+
if ($id > 0)
{
Header("Location: fiche.php?id=".$id);
@@ -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"]))
@@ -162,7 +163,7 @@ if ($_POST["action"] == 'update' &&
$product->weight_units = $_POST["weight_units"];
$product->volume = $_POST["volume"];
$product->volume_units = $_POST["volume_units"];
-
+
if ($product->check())
{
if ($product->update($product->id, $user) > 0)
@@ -183,13 +184,13 @@ if ($_POST["action"] == 'update' &&
$_GET["id"] = $_POST["id"];
$mesg = $langs->trans("ErrorProductBadRefOrLabel");
}
-
+
// Produit spécifique
if ($product->canvas <> '' && file_exists('canvas/product.'.$product->canvas.'.class.php') )
{
$class = 'Product'.ucfirst($product->canvas);
include_once('canvas/product.'.$product->canvas.'.class.php');
-
+
$product = new $class($db);
if ($product->FetchCanvas($_POST["id"]))
{
@@ -202,70 +203,75 @@ if ($_POST["action"] == 'update' &&
// clone d'un produit
if ($_GET["action"] == 'clone' && $user->rights->produit->creer)
{
- $db->begin();
-
- $product = new Product($db);
- $originalId = $_GET["id"];
- if ($product->fetch($_GET["id"]) > 0)
- {
- $product->ref = "Clone ".$product->ref;
- $product->status = 0;
- $product->id = null;
-
- if ($product->check())
+ $db->begin();
+
+ $product = new Product($db);
+ $originalId = $_GET["id"];
+ if ($product->fetch($_GET["id"]) > 0)
{
- $id = $product->create($user);
- if ($id > 0)
- {
- // $product->clone_fournisseurs($originalId, $id);
-
- $db->commit();
-
- Header("Location: fiche.php?id=$id");
- $db->close();
- exit;
- }
- else if ($id == -3)
- {
- $db->rollback();
-
- $_error = 1;
- $_GET["action"] = "";
- dolibarr_print_error($product->db);
- }
- else
- {
- $db->rollback();
- dolibarr_print_error($product->db);
- }
+ $product->ref = "Clone ".$product->ref;
+ $product->status = 0;
+ $product->id = null;
+
+ if ($product->check())
+ {
+ $id = $product->create($user);
+ if ($id > 0)
+ {
+ // $product->clone_fournisseurs($originalId, $id);
+
+ $db->commit();
+ $db->close();
+
+ Header("Location: fiche.php?id=$id");
+ exit;
+ }
+ else
+ {
+ if ($product->error == 'ErrorProductAlreadyExists')
+ {
+ $db->rollback();
+
+ $_error = 1;
+ $_GET["action"] = "";
+
+ $mesg=''.$langs->trans("ErrorProductAlreadyExists",$product->ref).'
';
+ //dolibarr_print_error($product->db);
+ }
+ else
+ {
+ $db->rollback();
+ dolibarr_print_error($product->db);
+ }
+ }
+ }
+ }
+ else
+ {
+ $db->rollback();
+ dolibarr_print_error($product->db);
}
- }
- else
- {
- $db->rollback();
- dolibarr_print_error($product->db);
- }
}
/*
-* 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);
- $product->fetch($_GET['id']);
- $result = $product->delete($_GET['id']);
-
- if ($result == 0)
- {
- Header('Location: '.DOL_URL_ROOT.'/product/liste.php?delprod='.$product->ref);
- exit;
- }
- else
- {
- $reload = 0;
- $_GET['action']='';
- }
+ $product = new Product($db);
+ $product->fetch($_GET['id']);
+ $result = $product->delete($_GET['id']);
+
+ if ($result == 0)
+ {
+ Header('Location: '.DOL_URL_ROOT.'/product/liste.php?delprod='.$product->ref);
+ exit;
+ }
+ else
+ {
+ $reload = 0;
+ $_GET['action']='';
+ }
}
@@ -274,208 +280,49 @@ if ($_POST['action'] == 'confirm_delete' && $_POST['confirm'] == 'yes' && $user-
*/
if ($_POST["action"] == 'addinpropal')
{
- $propal = New Propal($db);
- $result=$propal->fetch($_POST["propalid"]);
- if ($result <= 0)
- {
- dolibarr_print_error($db,$propal->error);
- exit;
- }
-
- $soc = new Societe($db);
- $result=$soc->fetch($propal->socid,$user);
- if ($result <= 0)
- {
- dolibarr_print_error($db,$soc->error);
- exit;
- }
-
- $prod = new Product($db);
- $result=$prod->fetch($_GET['id']);
- if ($result <= 0)
- {
- dolibarr_print_error($db,$prod->error);
- exit;
- }
-
- $desc = $prod->description;
- $tva_tx = get_default_tva($mysoc,$soc,$prod->tva_tx);
-
- $price_base_type = 'HT';
-
- // multiprix
- if ($conf->global->PRODUIT_MULTIPRICES == 1)
- {
- $pu_ht = $prod->multiprices[$soc->price_level];
- $pu_ttc = $prod->multiprices_ttc[$soc->price_level];
- $price_base_type = $prod->multiprices_base_type[$soc->price_level];
- }
- else
- {
- $pu_ht = $prod->price;
- $pu_ttc = $prod->price_ttc;
- $price_base_type = $prod->price_base_type;
- }
-
- // On reevalue prix selon taux tva car taux tva transaction peut etre different
- // de ceux du produit par defaut (par exemple si pays different entre vendeur et acheteur).
- if ($tva_tx != $prod->tva_tx)
+ $propal = New Propal($db);
+ $result=$propal->fetch($_POST["propalid"]);
+ if ($result <= 0)
{
- if ($price_base_type != 'HT')
- {
- $pu_ht = price2num($pu_ttc / (1 + ($tva_tx/100)), 'MU');
- }
- else
- {
- $pu_ttc = price2num($pu_ht * (1 + ($tva_tx/100)), 'MU');
- }
+ dolibarr_print_error($db,$propal->error);
+ exit;
}
-
- $result = $propal->addline($propal->id,
- $desc,
- $pu_ht,
- $_POST["qty"],
- $tva_tx,
- $prod->id,
- $_POST["remise_percent"],
- $price_base_type,
- $pu_ttc
- );
- if ($result > 0)
- {
- Header("Location: ".DOL_URL_ROOT."/comm/propal.php?propalid=".$propal->id);
- return;
- }
-
- $mesg = $langs->trans("ErrorUnknown").": $result";
-}
-/*
- * Ajout du produit dans une commande
- */
-if ($_POST["action"] == 'addincommande')
-{
- $commande = new Commande($db);
- $result=$commande->fetch($_POST["commandeid"]);
- if ($result <= 0)
- {
- dolibarr_print_error($db,$commande->error);
- exit;
- }
-
- $soc = new Societe($db);
- $result=$soc->fetch($commande->socid,$user);
- if ($result <= 0)
- {
- dolibarr_print_error($db,$soc->error);
- exit;
- }
-
- $prod = new Product($db);
- $result=$prod->fetch($_GET['id']);
- if ($result <= 0)
- {
- dolibarr_print_error($db,$prod->error);
- exit;
- }
-
- $desc = $prod->description;
- $tva_tx = get_default_tva($mysoc,$soc,$prod->tva_tx);
-
- // multiprix
- if ($conf->global->PRODUIT_MULTIPRICES == 1)
- {
- $pu_ht = $prod->multiprices[$soc->price_level];
- $pu_ttc = $prod->multiprices_ttc[$soc->price_level];
- $price_base_type = $prod->multiprices_base_type[$soc->price_level];
- }
- else
- {
- $pu_ht = $prod->price;
- $pu_ttc = $prod->price_ttc;
- $price_base_type = $prod->price_base_type;
- }
-
- // On reevalue prix selon taux tva car taux tva transaction peut etre different
- // de ceux du produit par defaut (par exemple si pays different entre vendeur et acheteur).
- if ($tva_tx != $prod->tva_tx)
+ $soc = new Societe($db);
+ $result=$soc->fetch($propal->socid,$user);
+ if ($result <= 0)
{
- if ($price_base_type != 'HT')
- {
- $pu_ht = price2num($pu_ttc / (1 + ($tva_tx/100)), 'MU');
- }
- else
- {
- $pu_ttc = price2num($pu_ht * (1 + ($tva_tx/100)), 'MU');
- }
+ dolibarr_print_error($db,$soc->error);
+ exit;
}
-
- $result = $commande->addline($commande->id,
- $desc,
- $pu_ht,
- $_POST["qty"],
- $tva_tx,
- $prod->id,
- $_POST["remise_percent"],
- '',
- '', //Todo: voir si fk_remise_except est encore valable car n'apparait plus dans les propales
- $price_base_type,
- $pu_ttc
- );
- if ($result > 0)
- {
- Header("Location: ".DOL_URL_ROOT."/commande/fiche.php?id=".$commande->id);
- exit;
- }
-}
+ $prod = new Product($db);
+ $result=$prod->fetch($_GET['id']);
+ if ($result <= 0)
+ {
+ dolibarr_print_error($db,$prod->error);
+ exit;
+ }
-/*
- * Ajout du produit dans une facture
- */
-if ($_POST["action"] == 'addinfacture' && $user->rights->facture->creer)
-{
- $facture = New Facture($db);
- $result=$facture->fetch($_POST["factureid"]);
- if ($result <= 0)
- {
- dolibarr_print_error($db,$facture->error);
- exit;
- }
-
- $soc = new Societe($db);
- $soc->fetch($facture->socid,$user);
- if ($result <= 0)
- {
- dolibarr_print_error($db,$soc->error);
- exit;
- }
-
- $prod = new Product($db);
- $result = $prod->fetch($_GET["id"]);
- if ($result <= 0)
- {
- dolibarr_print_error($db,$prod->error);
- exit;
- }
-
- $desc = $prod->description;
- $tva_tx = get_default_tva($mysoc,$soc,$prod->tva_tx);
+ $desc = $prod->description;
+ $tva_tx = get_default_tva($mysoc,$soc,$prod->tva_tx);
- // multiprix
- if ($conf->global->PRODUIT_MULTIPRICES == 1)
- {
- $pu_ht = $prod->multiprices[$soc->price_level];
- $pu_ttc = $prod->multiprices_ttc[$soc->price_level];
- $price_base_type = $prod->multiprices_base_type[$soc->price_level];
- }
- else
- {
- $pu_ht = $prod->price;
- $pu_ttc = $prod->price_ttc;
+ $price_base_type = 'HT';
+
+ // multiprix
+ if ($conf->global->PRODUIT_MULTIPRICES == 1)
+ {
+ $pu_ht = $prod->multiprices[$soc->price_level];
+ $pu_ttc = $prod->multiprices_ttc[$soc->price_level];
+ $price_base_type = $prod->multiprices_base_type[$soc->price_level];
+ }
+ else
+ {
+ $pu_ht = $prod->price;
+ $pu_ttc = $prod->price_ttc;
$price_base_type = $prod->price_base_type;
}
-
+
// On reevalue prix selon taux tva car taux tva transaction peut etre different
// de ceux du produit par defaut (par exemple si pays different entre vendeur et acheteur).
if ($tva_tx != $prod->tva_tx)
@@ -483,41 +330,200 @@ if ($_POST["action"] == 'addinfacture' && $user->rights->facture->creer)
if ($price_base_type != 'HT')
{
$pu_ht = price2num($pu_ttc / (1 + ($tva_tx/100)), 'MU');
- }
+ }
else
{
$pu_ttc = price2num($pu_ht * (1 + ($tva_tx/100)), 'MU');
}
}
-
- $result = $facture->addline($facture->id,
- $desc,
- $pu_ht,
- $_POST["qty"],
- $tva_tx,
- $prod->id,
- $_POST["remise_percent"],
+
+ $result = $propal->addline($propal->id,
+ $desc,
+ $pu_ht,
+ $_POST["qty"],
+ $tva_tx,
+ $prod->id,
+ $_POST["remise_percent"],
+ $price_base_type,
+ $pu_ttc
+ );
+ if ($result > 0)
+ {
+ Header("Location: ".DOL_URL_ROOT."/comm/propal.php?propalid=".$propal->id);
+ return;
+ }
+
+ $mesg = $langs->trans("ErrorUnknown").": $result";
+}
+
+/*
+ * Ajout du produit dans une commande
+ */
+if ($_POST["action"] == 'addincommande')
+{
+ $commande = new Commande($db);
+ $result=$commande->fetch($_POST["commandeid"]);
+ if ($result <= 0)
+ {
+ dolibarr_print_error($db,$commande->error);
+ exit;
+ }
+
+ $soc = new Societe($db);
+ $result=$soc->fetch($commande->socid,$user);
+ if ($result <= 0)
+ {
+ dolibarr_print_error($db,$soc->error);
+ exit;
+ }
+
+ $prod = new Product($db);
+ $result=$prod->fetch($_GET['id']);
+ if ($result <= 0)
+ {
+ dolibarr_print_error($db,$prod->error);
+ exit;
+ }
+
+ $desc = $prod->description;
+ $tva_tx = get_default_tva($mysoc,$soc,$prod->tva_tx);
+
+ // multiprix
+ if ($conf->global->PRODUIT_MULTIPRICES == 1)
+ {
+ $pu_ht = $prod->multiprices[$soc->price_level];
+ $pu_ttc = $prod->multiprices_ttc[$soc->price_level];
+ $price_base_type = $prod->multiprices_base_type[$soc->price_level];
+ }
+ else
+ {
+ $pu_ht = $prod->price;
+ $pu_ttc = $prod->price_ttc;
+ $price_base_type = $prod->price_base_type;
+ }
+
+ // On reevalue prix selon taux tva car taux tva transaction peut etre different
+ // de ceux du produit par defaut (par exemple si pays different entre vendeur et acheteur).
+ if ($tva_tx != $prod->tva_tx)
+ {
+ if ($price_base_type != 'HT')
+ {
+ $pu_ht = price2num($pu_ttc / (1 + ($tva_tx/100)), 'MU');
+ }
+ else
+ {
+ $pu_ttc = price2num($pu_ht * (1 + ($tva_tx/100)), 'MU');
+ }
+ }
+
+ $result = $commande->addline($commande->id,
+ $desc,
+ $pu_ht,
+ $_POST["qty"],
+ $tva_tx,
+ $prod->id,
+ $_POST["remise_percent"],
+ '',
+ '', //Todo: voir si fk_remise_except est encore valable car n'apparait plus dans les propales
+ $price_base_type,
+ $pu_ttc
+ );
+
+ if ($result > 0)
+ {
+ Header("Location: ".DOL_URL_ROOT."/commande/fiche.php?id=".$commande->id);
+ exit;
+ }
+}
+
+/*
+ * Ajout du produit dans une facture
+ */
+if ($_POST["action"] == 'addinfacture' && $user->rights->facture->creer)
+{
+ $facture = New Facture($db);
+ $result=$facture->fetch($_POST["factureid"]);
+ if ($result <= 0)
+ {
+ dolibarr_print_error($db,$facture->error);
+ exit;
+ }
+
+ $soc = new Societe($db);
+ $soc->fetch($facture->socid,$user);
+ if ($result <= 0)
+ {
+ dolibarr_print_error($db,$soc->error);
+ exit;
+ }
+
+ $prod = new Product($db);
+ $result = $prod->fetch($_GET["id"]);
+ if ($result <= 0)
+ {
+ dolibarr_print_error($db,$prod->error);
+ exit;
+ }
+
+ $desc = $prod->description;
+ $tva_tx = get_default_tva($mysoc,$soc,$prod->tva_tx);
+
+ // multiprix
+ if ($conf->global->PRODUIT_MULTIPRICES == 1)
+ {
+ $pu_ht = $prod->multiprices[$soc->price_level];
+ $pu_ttc = $prod->multiprices_ttc[$soc->price_level];
+ $price_base_type = $prod->multiprices_base_type[$soc->price_level];
+ }
+ else
+ {
+ $pu_ht = $prod->price;
+ $pu_ttc = $prod->price_ttc;
+ $price_base_type = $prod->price_base_type;
+ }
+
+ // On reevalue prix selon taux tva car taux tva transaction peut etre different
+ // de ceux du produit par defaut (par exemple si pays different entre vendeur et acheteur).
+ if ($tva_tx != $prod->tva_tx)
+ {
+ if ($price_base_type != 'HT')
+ {
+ $pu_ht = price2num($pu_ttc / (1 + ($tva_tx/100)), 'MU');
+ }
+ else
+ {
+ $pu_ttc = price2num($pu_ht * (1 + ($tva_tx/100)), 'MU');
+ }
+ }
+
+ $result = $facture->addline($facture->id,
+ $desc,
+ $pu_ht,
+ $_POST["qty"],
+ $tva_tx,
+ $prod->id,
+ $_POST["remise_percent"],
'',
'',
'',
'',
'',
- $price_base_type,
- $pu_ttc
- );
-
- if ($result > 0)
- {
- Header("Location: ".DOL_URL_ROOT."/compta/facture.php?facid=".$facture->id);
- exit;
- }
+ $price_base_type,
+ $pu_ttc
+ );
+
+ if ($result > 0)
+ {
+ Header("Location: ".DOL_URL_ROOT."/compta/facture.php?facid=".$facture->id);
+ exit;
+ }
}
if ($_POST["cancel"] == $langs->trans("Cancel"))
{
- $action = '';
- Header("Location: fiche.php?id=".$_POST["id"]);
- exit;
+ $action = '';
+ Header("Location: fiche.php?id=".$_POST["id"]);
+ exit;
}
@@ -538,13 +544,13 @@ if ($_GET["action"] == 'create' && $user->rights->produit->creer)
{
$class = 'Product'.ucfirst($_GET["canvas"]);
include_once($filecanvas);
-
+
$product = new $class($db,0,$user);
}
else
{
$product = new Product($db);
- }
+ }
}
$product->assign_smarty_values($smarty, 'create');
@@ -554,21 +560,21 @@ if ($_GET["action"] == 'create' && $user->rights->produit->creer)
$product = $e_product;
}
}
-
+
llxHeader("","",$langs->trans("CardProduct".$product->type));
- if ($mesg) print "$mesg\n";
+ if ($mesg) print $mesg."\n";
if (! $conf->global->PRODUCT_CANVAS_ABILITY || !$_GET["canvas"])
{
print '';
}
else
{
//RODO
- // On assigne les valeurs meme en creation car elles sont definies si
+ // On assigne les valeurs meme en creation car elles sont definies si
// on revient en erreur
//
$smarty->template_dir = DOL_DOCUMENT_ROOT.'/product/canvas/'.$_GET["canvas"].'/';
@@ -711,47 +717,47 @@ if ($_GET["action"] == 'create' && $user->rights->produit->creer)
}
/**
-*
-* Fiche produit
-*
-*/
+ *
+ * Fiche produit
+ *
+ */
if ($_GET["id"] || $_GET["ref"])
{
$product = new Product($db);
-
+
if ($_GET["ref"])
- {
+ {
$result = $product->fetch('',$_GET["ref"]);
$_GET["id"] = $product->id;
- }
+ }
elseif ($_GET["id"])
- {
+ {
$result = $product->fetch($_GET["id"]);
- }
-
+ }
+
// Gestion des produits specifiques
$product->canvas = '';
if ($conf->global->PRODUCT_CANVAS_ABILITY)
{
if ($product->canvas <> '' && file_exists('canvas/product.'.$product->canvas.'.class.php') )
- {
- $class = 'Product'.ucfirst($product->canvas);
- include_once('canvas/product.'.$product->canvas.'.class.php');
- $product = new $class($db);
-
- $result = $product->FetchCanvas($_GET["id"],'',$_GET["action"]);
-
- $smarty->template_dir = DOL_DOCUMENT_ROOT.'/product/canvas/'.$product->canvas.'/';
-
- $product->assign_smarty_values($smarty,$_GET["action"]);
- }
+ {
+ $class = 'Product'.ucfirst($product->canvas);
+ include_once('canvas/product.'.$product->canvas.'.class.php');
+ $product = new $class($db);
+
+ $result = $product->FetchCanvas($_GET["id"],'',$_GET["action"]);
+
+ $smarty->template_dir = DOL_DOCUMENT_ROOT.'/product/canvas/'.$product->canvas.'/';
+
+ $product->assign_smarty_values($smarty,$_GET["action"]);
+ }
}
// END TODO RODO FINISH THIS PART
-
+
llxHeader("","",$langs->trans("CardProduct".$product->type));
-
+
if ( $result )
- {
+ {
if ($_GET["action"] <> 'edit')
{
$head=product_prepare_head($product, $user);
@@ -761,9 +767,9 @@ if ($_GET["id"] || $_GET["ref"])
// Confirmation de la suppression de la facture
if ($_GET["action"] == 'delete')
{
- $html = new Form($db);
- $html->form_confirm("fiche.php?id=".$product->id,$langs->trans("DeleteProduct"),$langs->trans("ConfirmDeleteProduct"),"confirm_delete");
- print "
\n";
+ $html = new Form($db);
+ $html->form_confirm("fiche.php?id=".$product->id,$langs->trans("DeleteProduct"),$langs->trans("ConfirmDeleteProduct"),"confirm_delete");
+ print "
\n";
}
print($mesg);
@@ -771,8 +777,8 @@ if ($_GET["id"] || $_GET["ref"])
if ($_GET["action"] <> 'edit' && $product->canvas <> '')
{
/*
- * Smarty en mode visu
- */
+ * Smarty en mode visu
+ */
$smarty->assign('fiche_cursor_prev',$previous_ref);
$smarty->assign('fiche_cursor_next',$next_ref);
@@ -783,17 +789,17 @@ if ($_GET["id"] || $_GET["ref"])
print "\n\n";
}
-
+
if ($_GET["action"] <> 'edit' && $product->canvas == '')
{
// En mode visu
print '';
-
+
// Reference
print '| '.$langs->trans("Ref").' | ';
print $html->showrefnav($product,'ref','',1,'ref');
print ' | ';
-
+
$nblignes=6;
if ($product->isproduct() && $conf->stock->enabled) $nblignes++;
if ($product->isservice()) $nblignes++;
@@ -805,15 +811,15 @@ if ($_GET["id"] || $_GET["ref"])
print '';
}
print '
';
-
+
// Libelle
print '| '.$langs->trans("Label").' | '.$product->libelle.' |
';
-
+
// MultiPrix
if($conf->global->PRODUIT_MULTIPRICES == 1)
{
print '| '.$langs->trans("SellingPrice").' 1 | ';
-
+
if ($product->price_base_type == 'TTC')
{
print ''.price($product->price_ttc);
@@ -822,13 +828,13 @@ if ($_GET["id"] || $_GET["ref"])
{
print ' | '.price($product->price);
}
-
+
print ' '.$langs->trans($product->price_base_type);
print ' |
';
for($i=2;$i<=$conf->global->PRODUIT_MULTIPRICES_LIMIT;$i++)
{
print '| '.$langs->trans("SellingPrice").' '.$i.' | ';
-
+
if ($product->multiprices_base_type["$i"] == 'TTC')
{
print ''.price($product->multiprices_ttc["$i"]);
@@ -837,7 +843,7 @@ if ($_GET["id"] || $_GET["ref"])
{
print ' | '.price($product->multiprices["$i"]);
}
-
+
if ($product->multiprices_base_type["$i"])
{
print ' '.$langs->trans($product->multiprices_base_type["$i"]);
@@ -846,7 +852,7 @@ if ($_GET["id"] || $_GET["ref"])
{
print ' '.$langs->trans($product->price_base_type);
}
-
+
print ' |
';
}
}
@@ -867,15 +873,15 @@ if ($_GET["id"] || $_GET["ref"])
// TVA
print '| '.$langs->trans("VATRate").' | '.vatrate($product->tva_tx,true).' |
';
-
+
// Statut
print '| '.$langs->trans("Status").' | ';
print $product->getLibStatut(2);
print ' |
';
-
+
// Description
print '| '.$langs->trans("Description").' | '.nl2br($product->description).' |
';
-
+
if ($product->isservice())
{
// Duration
@@ -889,7 +895,7 @@ if ($_GET["id"] || $_GET["ref"])
$dur=array("h"=>$langs->trans("Hour"),"d"=>$langs->trans("Day"),"w"=>$langs->trans("Week"),"m"=>$langs->trans("Month"),"y"=>$langs->trans("Year"));
}
print $langs->trans($dur[$product->duration_unit])." ";
-
+
print '';
}
else
@@ -921,25 +927,25 @@ if ($_GET["id"] || $_GET["ref"])
print "
\n";
print "\n\n";
}
- }
-
- /*
- * Fiche en mode edition
- */
- if ($_GET["action"] == 'edit' && $user->rights->produit->creer)
- {
- if ($product->isservice()) {
- print_fiche_titre($langs->trans('Modify').' '.$langs->trans('Service').' : '.$product->ref, "");
- } else {
- print_fiche_titre($langs->trans('Modify').' '.$langs->trans('Product').' : '.$product->ref, "");
- }
-
- if ($mesg) {
- print '
'.$mesg.'
';
- }
-
- if ( $product->canvas == '')
+ }
+
+ /*
+ * Fiche en mode edition
+ */
+ if ($_GET["action"] == 'edit' && $user->rights->produit->creer)
{
+ if ($product->isservice()) {
+ print_fiche_titre($langs->trans('Modify').' '.$langs->trans('Service').' : '.$product->ref, "");
+ } else {
+ print_fiche_titre($langs->trans('Modify').' '.$langs->trans('Product').' : '.$product->ref, "");
+ }
+
+ if ($mesg) {
+ print '
'.$mesg.'
';
+ }
+
+ if ( $product->canvas == '')
+ {
print "\n";
print "