From 6c286ab6f803d9e97832dfe758adbb6cf4c25351 Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Tue, 19 Dec 2006 18:15:40 +0000 Subject: [PATCH] Finalisation de l'ajout de la gestion du HT et TTC avec l'option multiprix --- htdocs/product.class.php | 142 ++++++++++++++++++++------------------- htdocs/product/price.php | 6 +- 2 files changed, 75 insertions(+), 73 deletions(-) diff --git a/htdocs/product.class.php b/htdocs/product.class.php index 9295e5a808e..9b932f7f370 100644 --- a/htdocs/product.class.php +++ b/htdocs/product.class.php @@ -152,6 +152,20 @@ class Product if ($this->status=='') $this->status = 0; $this->price = price2num($this->price); + if (strlen(trim($this->price)) > 0 ) + { + if ($this->price_base_type == 'TTC') + { + $price_ttc = $this->price; + $price = $this->price / (1 + ($this->tva_tx / 100)); + } + else + { + $price = $this->price; + $price_ttc = $this->price * (1 + ($this->tva_tx / 100)); + } + } + dolibarr_syslog("Product::Create ref=".$this->ref." Categorie : ".$this->catid); if (strlen($this->ref) > 0) @@ -163,64 +177,65 @@ class Product $result = $this->db->query($sql) ; if ($result) - { - $row = $this->db->fetch_array($result); - if ($row[0] == 0) { - // Produit non deja existant - $sql = "INSERT INTO ".MAIN_DB_PREFIX."product "; - $sql.= " (datec, "; - if ($this->ref) $sql.= "ref, "; - $sql.= "fk_user_author, fk_product_type, price, canvas)"; - $sql.= " VALUES (now(), "; - if ($this->ref) $sql.= "'".$this->ref."', "; - $sql.= $user->id.", ".$this->type.", '" . $this->price . "','".$this->canvas."')"; - $result = $this->db->query($sql); - if ( $result ) - { - $id = $this->db->last_insert_id(MAIN_DB_PREFIX."product"); + $row = $this->db->fetch_array($result); + if ($row[0] == 0) + { + // Produit non deja existant + $sql = "INSERT INTO ".MAIN_DB_PREFIX."product "; + $sql.= " (datec, "; + if ($this->ref) $sql.= "ref, "; + $sql.= "fk_user_author, fk_product_type, price, price_ttc, price_base_type, canvas)"; + $sql.= " VALUES (now(), "; + if ($this->ref) $sql.= "'".$this->ref."', "; + $sql.= $user->id.", ".$this->type.", '" . $price . "', '".$price_ttc."', '" . $this->price_base_type . "','".$this->canvas."')"; + $result = $this->db->query($sql); + if ( $result ) + { + $id = $this->db->last_insert_id(MAIN_DB_PREFIX."product"); - if ($id > 0) - { - $this->id = $id; - $this->_log_price($user); - if ( $this->update($id, $user) > 0) - { - if ($this->catid > 0) - { - $cat = new Categorie ($this->db, $this->catid); - $cat->add_product($this); - } - $this->db->commit(); - return $id; - } - else { - $this->db->rollback(); - return -5; + if ($id > 0) + { + $this->id = $id; + $this->_log_price($user); + if ( $this->update($id, $user) > 0) + { + if ($this->catid > 0) + { + $cat = new Categorie ($this->db, $this->catid); + $cat->add_product($this); + } + $this->db->commit(); + return $id; + } + else + { + $this->db->rollback(); + return -5; + } + } + else + { + $this->db->rollback(); + return -4; + } } - } - else - { - $this->db->rollback(); - return -4; - } - } - else - { - $this->error=$this->db->error()." - sql=".$sql; - $this->db->rollback(); - return -3; - } - } - else - { + else + { + $this->error=$this->db->error()." - sql=".$sql; + $this->db->rollback(); + return -3; + } + } + else + { // Produit existe deja $this->error=$langs->trans("ErrorProductAlreadyExists", $this->ref); $this->errno = 257; $this->db->rollback(); return -2; - } - } + } + } $this->error=$this->db->error(); $this->db->rollback(); @@ -888,8 +903,7 @@ class Product $this->db->free(); // multilangs if( $conf->global->MAIN_MULTILANGS) $this->getMultiLangs(); - - + // multiprix if($conf->global->PRODUIT_MULTIPRICES == 1) { @@ -923,29 +937,17 @@ class Product { $result = $this->db->fetch_array(); - $this->multiprices_base_type[$i] = $result["price_base_type"]; - if($result["price"] != "" && $result["price"] != "0.00") { - if ($result["price_base_type"] == 'TTC') - { - $this->multiprices_ttc[$i]=$result["price_ttc"]; - } - else - { - $this->multiprices[$i]=$result["price"]; - } + $this->multiprices[$i]=$result["price"]; + $this->multiprices_ttc[$i]=$result["price_ttc"]; + $this->multiprices_base_type[$i] = $result["price_base_type"]; } else { - if ($result["price_base_type"] == 'TTC') - { - $this->multiprices_ttc[$i]=$this->price_ttc; - } - else - { - $this->multiprices[$i]=$this->price; - } + $this->multiprices[$i]=$this->price; + $this->multiprices_ttc[$i]=$this->price_ttc; + $this->multiprices_base_type[$i] = $this->price_base_type; } } else diff --git a/htdocs/product/price.php b/htdocs/product/price.php index 15545c09a41..715ce71d109 100644 --- a/htdocs/product/price.php +++ b/htdocs/product/price.php @@ -280,10 +280,10 @@ if ($_GET["action"] == 'edit_price' && $user->rights->produit->creer) // Liste des evolutions du prix -$sql = "SELECT p.rowid, p.price, p.price_ttc, p.price_base_type"; +$sql = "SELECT p.rowid, p.price, p.price_ttc, p.price_base_type, "; if($conf->global->PRODUIT_MULTIPRICES == 1) { - $sql .= ", p.price_level, "; + $sql .= "p.price_level, "; $sql .= $db->pdate("p.date_price")." as dp, u.rowid as user_id, u.login"; $sql .= " FROM ".MAIN_DB_PREFIX."product_price as p, ".MAIN_DB_PREFIX."user as u"; $sql .= " WHERE fk_product = ".$product->id; @@ -352,6 +352,7 @@ if ($result) if($conf->global->PRODUIT_MULTIPRICES == 1) { print "".$objp->price_level.""; + } if ($objp->price_base_type == 'TTC') { @@ -362,7 +363,6 @@ if ($result) print "".price($objp->price); } print " ".$langs->trans($objp->price_base_type).""; - } // User print ''.img_object($langs->trans("ShowUser"),'user').' '.$objp->login.'';