diff --git a/htdocs/product.class.php b/htdocs/product.class.php index c8de6ba6637..9295e5a808e 100644 --- a/htdocs/product.class.php +++ b/htdocs/product.class.php @@ -46,10 +46,13 @@ class Product var $description; //! Prix de vente var $price; + var $price_ttc; //! Base de prix (ttc ou ht) var $price_base_type; //! Tableau des prix multiples var $multiprices=array(); + var $multiprices_ttc=array(); + var $multiprices_base_type=array(); //! Taux de TVA var $tva_tx; //! Type 0 pour produit, 1 pour service @@ -128,10 +131,10 @@ class Product { $price = ereg_replace(" ","", $price); $price = ereg_replace(",",".", $price); - - $this->price = $price; - - $this->price_base_type = $base_type; + + $this->price = $price; + $this->price_base_type = $base_type; + } /** * \brief Insère le produit en base @@ -519,6 +522,16 @@ class Product { if($this->multiprices["$i"] != "") { + if ($this->multiprices_base_type["$i"] == 'TTC') + { + $price_ttc = $this->multiprices["$i"]; + $this->multiprices["$i"] = $this->multiprices["$i"] / (1 + ($this->tva_tx / 100)); + } + else + { + $price_ttc = $this->multiprices["$i"] * (1 + ($this->tva_tx / 100)); + } + // On supprimme ligne existante au cas ou $sql_multiprix = "DELETE FROM ".MAIN_DB_PREFIX."product_price "; $sql_multiprix .= "WHERE date_price = now()"; @@ -529,8 +542,8 @@ class Product $this->db->query($sql_multiprix); // On ajoute nouveau tarif - $sql_multiprix = "INSERT INTO ".MAIN_DB_PREFIX."product_price(date_price,fk_product,fk_user_author,price_level,price,price_base_type) "; - $sql_multiprix .= " VALUES(now(),".$this->id.",".$user->id.",".$i.",".price2num($this->multiprices["$i"]).",'".$this->price_base_type["$i"]."'"; + $sql_multiprix = "INSERT INTO ".MAIN_DB_PREFIX."product_price(date_price,fk_product,fk_user_author,price_level,price,price_ttc,price_base_type) "; + $sql_multiprix .= " VALUES(now(),".$this->id.",".$user->id.",".$i.",".price2num($this->multiprices["$i"]).",'".$price_ttc."','".$this->multiprices_base_type["$i"]."'"; $sql_multiprix .= ")"; if (! $this->db->query($sql_multiprix) ) { @@ -540,20 +553,31 @@ class Product } 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)); + } + // On supprimme ligne existante au cas ou $sql = "DELETE FROM ".MAIN_DB_PREFIX."product_price "; $sql .= "WHERE date_price = now()"; $sql .= " and fk_product = ".$this->id; $sql .= " and fk_user_author = ".$user->id; - $sql .= " and price = ".price2num($this->price); + $sql .= " and price = ".price2num($price); $sql .= " and envente = ".$this->status; $sql .= " and tva_tx = ".$this->tva_tx; $this->db->query($sql); // On ajoute nouveau tarif - $sql = "INSERT INTO ".MAIN_DB_PREFIX."product_price(date_price,fk_product,fk_user_author,price,envente,tva_tx) "; - $sql .= " VALUES(now(),".$this->id.",".$user->id.",".price2num($this->price).",".$this->status.",".$this->tva_tx; + $sql = "INSERT INTO ".MAIN_DB_PREFIX."product_price(date_price,fk_product,fk_user_author,price,price_ttc,price_base_type,envente,tva_tx) "; + $sql .= " VALUES(now(),".$this->id.",".$user->id.",".price2num($price).",'".$price_ttc."','".$this->price_base_type."',".$this->status.",".$this->tva_tx; $sql .= ")"; if (! $this->db->query($sql) ) $queryError = true; @@ -754,15 +778,16 @@ class Product if ($this->price_base_type == 'TTC') { $price_ttc = $this->price; - $this->price = $this->price / (1 + ($this->tva_tx / 100)); + $price = $this->price / (1 + ($this->tva_tx / 100)); } else { + $price = $this->price; $price_ttc = $this->price * (1 + ($this->tva_tx / 100)); } $sql = "UPDATE ".MAIN_DB_PREFIX."product "; - $sql .= " SET price = " . price2num($this->price); + $sql .= " SET price = " . price2num($price); $sql .= " , price_base_type='".$this->price_base_type."'"; $sql .= " , price_ttc='".$price_ttc."'"; $sql .= " WHERE rowid = " . $id; @@ -883,11 +908,11 @@ class Product dolibarr_print_error($this->db); return -1; } - } - $this -> multiprices[1] = $this->price; - for($i=2;$i<=$conf->global->PRODUIT_MULTIPRICES_LIMIT;$i++) - { - $sql= "SELECT price, tva_tx, envente "; + } + $this -> multiprices[1] = $this->price; + for($i=2;$i<=$conf->global->PRODUIT_MULTIPRICES_LIMIT;$i++) + { + $sql= "SELECT price, price_ttc, price_base_type, tva_tx, envente "; $sql.= "FROM ".MAIN_DB_PREFIX."product_price "; $sql.= "where price_level=".$i." and "; if ($id) $sql.= "fk_product = '".$id."' "; @@ -897,10 +922,31 @@ class Product if ( $result ) { $result = $this->db->fetch_array(); + + $this->multiprices_base_type[$i] = $result["price_base_type"]; + if($result["price"] != "" && $result["price"] != "0.00") - $this -> multiprices[$i]=$result["price"]; + { + if ($result["price_base_type"] == 'TTC') + { + $this->multiprices_ttc[$i]=$result["price_ttc"]; + } + else + { + $this->multiprices[$i]=$result["price"]; + } + } else - $this -> multiprices[$i]=$this->price; + { + if ($result["price_base_type"] == 'TTC') + { + $this->multiprices_ttc[$i]=$this->price_ttc; + } + else + { + $this->multiprices[$i]=$this->price; + } + } } else { diff --git a/htdocs/product/fiche.php b/htdocs/product/fiche.php index 8f3fc54e18b..d87564a575f 100644 --- a/htdocs/product/fiche.php +++ b/htdocs/product/fiche.php @@ -656,27 +656,48 @@ if ($_GET["id"] || $_GET["ref"]) // MultiPrix if($conf->global->PRODUIT_MULTIPRICES == 1) - { - print ''.$langs->trans("SellingPrice").' 1'.price($product->price).''; - print ''; + { + print ''.$langs->trans("SellingPrice").' 1'; + 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.''.price($product->multiprices["$i"]).''; - print ''; - } - } + { + print ''.$langs->trans("SellingPrice").' '.$i.''; + + if ($product->multiprices_base_type["$i"] == 'TTC') + { + print ''.price($product->multiprices_ttc["$i"]); + } + else + { + print ''.price($product->multiprices["$i"]); + } + + if ($product->multiprices_base_type["$i"]) + { + print ' '.$langs->trans($product->multiprices_base_type["$i"]); + } + else + { + print ' '.$langs->trans($product->price_base_type); + } + + print ''; + } + } // Prix else - { + { print ''.$langs->trans("SellingPrice").''; if ($product->price_base_type == 'TTC') - { - print price($product->price_ttc).' '.$langs->trans($product->price_base_type).''; - } + { + print price($product->price_ttc).' '.$langs->trans($product->price_base_type).''; + } else - { - print price($product->price).' '.$langs->trans($product->price_base_type).''; - } + { + print price($product->price).' '.$langs->trans($product->price_base_type).''; + } } // Statut print ''.$langs->trans("Status").''; diff --git a/htdocs/product/price.php b/htdocs/product/price.php index 65be1149327..bd71fe29a42 100644 --- a/htdocs/product/price.php +++ b/htdocs/product/price.php @@ -67,8 +67,11 @@ if ($_POST["action"] == 'update_price' && { if($_POST["price_".$i]) { - //$product->SetSellprice($_POST["price_".$i], $_POST["price_base_type_".$i]); - $product->multiprices["$i"] = $product->SetSellprice($_POST["price_".$i], $_POST["price_base_type_".$i]); + $price = ereg_replace(" ","", $_POST["price_".$i]); + $price = ereg_replace(",",".", $price); + //$product->SetSellprice($_POST["price_".$i], $_POST["price_base_type_".$i], $i); + $product->multiprices["$i"] = $price; + $product->multiprices_base_type["$i"] = $_POST["multiprices_base_type_".$i]; } else { @@ -128,11 +131,42 @@ print ''; // MultiPrix if($conf->global->PRODUIT_MULTIPRICES == 1) { - print ''.$langs->trans("SellingPrice").' 1'.price($product->price).''; + print ''.$langs->trans("SellingPrice").' 1'; + + if ($product->price_base_type == 'TTC') + { + print ''.price($product->price_ttc); + } + else + { + 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.''.price($product->multiprices["$i"]).''; - print ''; + { + print ''.$langs->trans("SellingPrice").' '.$i.''; + + if ($product->multiprices_base_type["$i"] == 'TTC') + { + print ''.price($product->multiprices_ttc["$i"]); + } + else + { + print ''.price($product->multiprices["$i"]); + } + + if ($product->multiprices_base_type["$i"]) + { + print ' '.$langs->trans($product->multiprices_base_type["$i"]); + } + else + { + print ' '.$langs->trans($product->price_base_type); + } + print ''; } } // Prix @@ -191,33 +225,25 @@ if ($_GET["action"] == 'edit_price' && $user->rights->produit->creer) print ''; print ''; if($conf->global->PRODUIT_MULTIPRICES == 1) - { - print ''; - if ($product->price_base_type == 'TTC') - { - print ''; - } + { + print ''; + } else - { - print ''; - if ($product->price_base_type == 'TTC') - { - print ''; - } + { + print ''; + } + + if ($product->price_base_type == 'TTC') + { + print ''; + print ''; print '
'.$langs->trans('SellingPrice').' 1'; - } - else - { - print ''; - } - print $html->select_PriceBaseType($product->price_base_type, "price_base_type"); - print '
'.$langs->trans('SellingPrice').' 1
'.$langs->trans('SellingPrice').''; - } - else - { - print ''; - } - print $html->select_PriceBaseType($product->price_base_type, "price_base_type"); - print '
'.$langs->trans('SellingPrice').''; + } + else + { + print ''; + } + print $html->select_PriceBaseType($product->price_base_type, "price_base_type"); + print '
 '; print '
'; @@ -226,39 +252,41 @@ if ($_GET["action"] == 'edit_price' && $user->rights->produit->creer) if($conf->global->PRODUIT_MULTIPRICES == 1) { for($i=2;$i<=$conf->global->PRODUIT_MULTIPRICES_LIMIT;$i++) - { - print '
'; - print ''; - print ''; - print ''; - print ''; - if ($product->price_base_type == 'TTC') - { - print ''; - print ''; - print '
'.$langs->trans("SellingPrice").' '.$i.''; - } - else - { - print ''; - } - print $html->select_PriceBaseType($product->price_base_type, "price_base_type_".$i); - print '
 '; - print '
'; - print '
'; - } + { + print '
'; + print ''; + print ''; + print ''; + print ''; + + if ($product->multiprices_base_type["$i"] == 'TTC') + { + print ''; + print ''; + print '
'.$langs->trans("SellingPrice").' '.$i.''; + } + else + { + print ''; + } + + print $html->select_PriceBaseType($product->multiprices_base_type["$i"], "multiprices_base_type_".$i); + print '
 '; + print '
'; + print '
'; + } } } // Liste des evolutions du prix -$sql = "SELECT p.rowid, p.price, "; +$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, llx_user as u"; + $sql .= " FROM ".MAIN_DB_PREFIX."product_price as p, ".MAIN_DB_PREFIX."user as u"; $sql .= " WHERE fk_product = ".$product->id; $sql .= " AND p.fk_user_author = u.rowid "; $sql .= " ORDER BY p.price_level ASC "; @@ -267,7 +295,7 @@ if($conf->global->PRODUIT_MULTIPRICES == 1) else { $sql .= $db->pdate("p.date_price")." as dp, u.rowid as user_id, u.login"; - $sql .= " FROM ".MAIN_DB_PREFIX."product_price as p, llx_user as u"; + $sql .= " FROM ".MAIN_DB_PREFIX."product_price as p, ".MAIN_DB_PREFIX."user as u"; $sql .= " WHERE fk_product = ".$product->id; $sql .= " AND p.fk_user_author = u.rowid "; $sql .= " ORDER BY p.date_price DESC "; @@ -300,8 +328,12 @@ if ($result) print ''; print ''.$langs->trans("AppliedPricesFrom").''; - if($conf->global->PRODUIT_MULTIPRICES == 1) - print ''.$langs->trans("MultiPriceLevelsName").''; + + if($conf->global->PRODUIT_MULTIPRICES == 1) + { + print ''.$langs->trans("MultiPriceLevelsName").''; + } + print ''.$langs->trans("Price").''; print ''.$langs->trans("ChangedBy").''; print ''; @@ -317,12 +349,21 @@ if ($result) // Date print "".dolibarr_print_date($objp->dp,"%d %b %Y %H:%M:%S").""; - // catégorie de Prix - if($conf->global->PRODUIT_MULTIPRICES == 1) - print "".$objp->price_level.""; - - // Prix - print "".price($objp->price).""; + // catégorie de Prix + if($conf->global->PRODUIT_MULTIPRICES == 1) + { + print "".$objp->price_level.""; + + if ($objp->price_base_type == 'TTC') + { + print "".price($objp->price_ttc); + } + else + { + print "".price($objp->price); + } + print " ".$langs->trans($objp->price_base_type).""; + } // User print ''.img_object($langs->trans("ShowUser"),'user').' '.$objp->login.'';