Dbut ajout gestion du HT et TTC avec l'option multiprix

This commit is contained in:
Regis Houssin 2006-12-19 16:55:16 +00:00
parent 0e6fe8d2d2
commit c9016fdc18
3 changed files with 206 additions and 98 deletions

View File

@ -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
{

View File

@ -656,27 +656,48 @@ if ($_GET["id"] || $_GET["ref"])
// MultiPrix
if($conf->global->PRODUIT_MULTIPRICES == 1)
{
print '<tr><td>'.$langs->trans("SellingPrice").' 1</td><td>'.price($product->price).'</td>';
print '</tr>';
{
print '<tr><td>'.$langs->trans("SellingPrice").' 1</td>';
print '<td>'.price($product->price);
print ' '.$langs->trans($product->price_base_type);
print '</td></tr>';
for($i=2;$i<=$conf->global->PRODUIT_MULTIPRICES_LIMIT;$i++)
{
print '<tr><td>'.$langs->trans("SellingPrice").' '.$i.'</td><td>'.price($product->multiprices["$i"]).'</td>';
print '</tr>';
}
}
{
print '<tr><td>'.$langs->trans("SellingPrice").' '.$i.'</td>';
if ($product->multiprices_base_type["$i"] == 'TTC')
{
print '<td>'.price($product->multiprices_ttc["$i"]);
}
else
{
print '<td>'.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 '</td></tr>';
}
}
// Prix
else
{
{
print '<tr><td>'.$langs->trans("SellingPrice").'</td><td>';
if ($product->price_base_type == 'TTC')
{
print price($product->price_ttc).' '.$langs->trans($product->price_base_type).'</td></tr>';
}
{
print price($product->price_ttc).' '.$langs->trans($product->price_base_type).'</td></tr>';
}
else
{
print price($product->price).' '.$langs->trans($product->price_base_type).'</td></tr>';
}
{
print price($product->price).' '.$langs->trans($product->price_base_type).'</td></tr>';
}
}
// Statut
print '<tr><td>'.$langs->trans("Status").'</td><td>';

View File

@ -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 '</tr>';
// MultiPrix
if($conf->global->PRODUIT_MULTIPRICES == 1)
{
print '<tr><td>'.$langs->trans("SellingPrice").' 1</td><td colspan="2">'.price($product->price).'</td></tr>';
print '<tr><td>'.$langs->trans("SellingPrice").' 1</td>';
if ($product->price_base_type == 'TTC')
{
print '<td colspan="2">'.price($product->price_ttc);
}
else
{
print '<td colspan="2">'.price($product->price);
}
print ' '.$langs->trans($product->price_base_type);
print '</td></tr>';
for($i=2;$i<=$conf->global->PRODUIT_MULTIPRICES_LIMIT;$i++)
{
print '<tr><td>'.$langs->trans("SellingPrice").' '.$i.'</td><td>'.price($product->multiprices["$i"]).'</td>';
print '</tr>';
{
print '<tr><td>'.$langs->trans("SellingPrice").' '.$i.'</td>';
if ($product->multiprices_base_type["$i"] == 'TTC')
{
print '<td>'.price($product->multiprices_ttc["$i"]);
}
else
{
print '<td>'.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 '</td></tr>';
}
}
// Prix
@ -191,33 +225,25 @@ if ($_GET["action"] == 'edit_price' && $user->rights->produit->creer)
print '<input type="hidden" name="id" value="'.$product->id.'">';
print '<table class="border" width="100%">';
if($conf->global->PRODUIT_MULTIPRICES == 1)
{
print '<tr><td width="15%">'.$langs->trans('SellingPrice').' 1</td>';
if ($product->price_base_type == 'TTC')
{
print '<td><input name="price" size="10" value="'.price($product->price_ttc).'">';
}
else
{
print '<td><input name="price" size="10" value="'.price($product->price).'">';
}
print $html->select_PriceBaseType($product->price_base_type, "price_base_type");
print '</td></tr>';
}
{
print '<tr><td width="15%">'.$langs->trans('SellingPrice').' 1</td>';
}
else
{
print '<tr><td width="15%">'.$langs->trans('SellingPrice').'</td>';
if ($product->price_base_type == 'TTC')
{
print '<td><input name="price" size="10" value="'.price($product->price_ttc).'">';
}
else
{
print '<td><input name="price" size="10" value="'.price($product->price).'">';
}
print $html->select_PriceBaseType($product->price_base_type, "price_base_type");
print '</td></tr>';
}
{
print '<tr><td width="15%">'.$langs->trans('SellingPrice').'</td>';
}
if ($product->price_base_type == 'TTC')
{
print '<td><input name="price" size="10" value="'.price($product->price_ttc).'">';
}
else
{
print '<td><input name="price" size="10" value="'.price($product->price).'">';
}
print $html->select_PriceBaseType($product->price_base_type, "price_base_type");
print '</td></tr>';
print '<tr><td colspan="2" align="center"><input type="submit" class="button" value="'.$langs->trans("Save").'">&nbsp;';
print '<input type="submit" class="button" name="cancel" value="'.$langs->trans("Cancel").'"></td></tr>';
print '</table>';
@ -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 '<form action="price.php?id='.$product->id.'" method="post">';
print '<input type="hidden" name="action" value="update_price">';
print '<input type="hidden" name="id" value="'.$product->id.'">';
print '<table class="border" width="100%">';
print '<tr><td width="15%">'.$langs->trans("SellingPrice").' '.$i.'</td>';
if ($product->price_base_type == 'TTC')
{
print '<td><input name="price_'.$i.'" size="10" value="'.price($product->multiprices_ttc["$i"]).'">';
}
else
{
print '<td><input name="price_'.$i.'" size="10" value="'.price($product->multiprices["$i"]).'">';
}
print $html->select_PriceBaseType($product->price_base_type, "price_base_type_".$i);
print '</td></tr>';
print '<tr><td colspan="2" align="center"><input type="submit" class="button" value="'.$langs->trans("Save").'">&nbsp;';
print '<input type="submit" class="button" name="cancel" value="'.$langs->trans("Cancel").'"></td></tr>';
print '</table>';
print '</form>';
}
{
print '<form action="price.php?id='.$product->id.'" method="post">';
print '<input type="hidden" name="action" value="update_price">';
print '<input type="hidden" name="id" value="'.$product->id.'">';
print '<table class="border" width="100%">';
print '<tr><td width="15%">'.$langs->trans("SellingPrice").' '.$i.'</td>';
if ($product->multiprices_base_type["$i"] == 'TTC')
{
print '<td><input name="price_'.$i.'" size="10" value="'.price($product->multiprices_ttc["$i"]).'">';
}
else
{
print '<td><input name="price_'.$i.'" size="10" value="'.price($product->multiprices["$i"]).'">';
}
print $html->select_PriceBaseType($product->multiprices_base_type["$i"], "multiprices_base_type_".$i);
print '</td></tr>';
print '<tr><td colspan="2" align="center"><input type="submit" class="button" value="'.$langs->trans("Save").'">&nbsp;';
print '<input type="submit" class="button" name="cancel" value="'.$langs->trans("Cancel").'"></td></tr>';
print '</table>';
print '</form>';
}
}
}
// 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 '<tr class="liste_titre">';
print '<td>'.$langs->trans("AppliedPricesFrom").'</td>';
if($conf->global->PRODUIT_MULTIPRICES == 1)
print '<td>'.$langs->trans("MultiPriceLevelsName").'</td>';
if($conf->global->PRODUIT_MULTIPRICES == 1)
{
print '<td>'.$langs->trans("MultiPriceLevelsName").'</td>';
}
print '<td>'.$langs->trans("Price").'</td>';
print '<td>'.$langs->trans("ChangedBy").'</td>';
print '</tr>';
@ -317,12 +349,21 @@ if ($result)
// Date
print "<td>".dolibarr_print_date($objp->dp,"%d %b %Y %H:%M:%S")."</td>";
// catégorie de Prix
if($conf->global->PRODUIT_MULTIPRICES == 1)
print "<td>".$objp->price_level."</td>";
// Prix
print "<td>".price($objp->price)."</td>";
// catégorie de Prix
if($conf->global->PRODUIT_MULTIPRICES == 1)
{
print "<td>".$objp->price_level."</td>";
if ($objp->price_base_type == 'TTC')
{
print "<td>".price($objp->price_ttc);
}
else
{
print "<td>".price($objp->price);
}
print " ".$langs->trans($objp->price_base_type)."</td>";
}
// User
print '<td><a href="'.DOL_URL_ROOT.'/user/fiche.php?id='.$objp->user_id.'">'.img_object($langs->trans("ShowUser"),'user').' '.$objp->login.'</a></td>';