Fix: If multiprice is enabled and level is not defined for customer, we always use the level 1. We can't use the denormalized price stored in product table as this price is the last price saved (it might be any level) and should never bee seen by user when multiprice is activated.

So we force the level to 1 if not defined.
This commit is contained in:
Laurent Destailleur 2009-06-19 07:32:39 +00:00
parent 127ab8911d
commit 2be9a2fdb4
11 changed files with 73 additions and 59 deletions

View File

@ -281,7 +281,7 @@ if ($_GET["action"] == 'create')
{
print '<tr><td>';
// multiprix
if($conf->global->PRODUIT_MULTIPRICES)
if($conf->global->PRODUIT_MULTIPRICES && $soc->price_level)
$html->select_produits('',"idprod".$i,'',$conf->produit->limit_size,$soc->price_level);
else
$html->select_produits('',"idprod".$i,'',$conf->produit->limit_size);

View File

@ -642,7 +642,7 @@ if ($_POST['action'] == "addline" && $user->rights->propale->creer)
$tva_npr = get_default_npr($mysoc,$propal->client,$prod->tva_tx);
// On defini prix unitaire
if ($conf->global->PRODUIT_MULTIPRICES && isset($prod->multiprices_base_type[$propal->client->price_level]))
if ($conf->global->PRODUIT_MULTIPRICES && $propal->client->price_level)
{
$pu_ht = $prod->multiprices[$propal->client->price_level];
$pu_ttc = $prod->multiprices_ttc[$propal->client->price_level];

View File

@ -853,48 +853,48 @@ class Commande extends CommonObject
$tva_tx = get_default_tva($mysoc,$this->client,$prod->tva_tx);
// multiprix
if($conf->global->PRODUIT_MULTIPRICES)
$price = $prod->multiprices[$this->client->price_level];
else
$price = $prod->price;
if($conf->global->PRODUIT_MULTIPRICES && $this->client->price_level)
$price = $prod->multiprices[$this->client->price_level];
else
$price = $prod->price;
$line=new CommandeLigne($this->db);
$line->fk_product=$idproduct;
$line->desc=$prod->description;
$line->qty=$qty;
$line->subprice=$price;
$line->remise_percent=$remise_percent;
$line->tva_tx=$tva_tx;
$line->ref=$prod->ref;
$line->libelle=$prod->libelle;
$line->product_desc=$prod->description;
$line=new CommandeLigne($this->db);
$line->fk_product=$idproduct;
$line->desc=$prod->description;
$line->qty=$qty;
$line->subprice=$price;
$line->remise_percent=$remise_percent;
$line->tva_tx=$tva_tx;
$line->ref=$prod->ref;
$line->libelle=$prod->libelle;
$line->product_desc=$prod->description;
// Added by Matelli (See http://matelli.fr/showcases/patchs-dolibarr/add-dates-in-order-lines.html)
// Save the start and end date of the line in the object
if ($date_start) { $line->date_start = $date_start; }
if ($date_end) { $line->date_end = $date_end; }
// Added by Matelli (See http://matelli.fr/showcases/patchs-dolibarr/add-dates-in-order-lines.html)
// Save the start and end date of the line in the object
if ($date_start) { $line->date_start = $date_start; }
if ($date_end) { $line->date_end = $date_end; }
$this->lines[] = $line;
$this->lines[] = $line;
/** POUR AJOUTER AUTOMATIQUEMENT LES SOUSPRODUITS a LA COMMANDE
if (! empty($conf->global->PRODUIT_SOUSPRODUITS))
{
$prod = new Product($this->db, $idproduct);
$prod -> get_sousproduits_arbo ();
$prods_arbo = $prod->get_each_prod();
if(sizeof($prods_arbo) > 0)
{
foreach($prods_arbo as $key => $value)
{
// print "id : ".$value[1].' :qty: '.$value[0].'<br>';
if(! in_array($value[1],$this->products))
$this->add_product($value[1], $value[0]);
/** POUR AJOUTER AUTOMATIQUEMENT LES SOUSPRODUITS a LA COMMANDE
if (! empty($conf->global->PRODUIT_SOUSPRODUITS))
{
$prod = new Product($this->db, $idproduct);
$prod -> get_sousproduits_arbo ();
$prods_arbo = $prod->get_each_prod();
if(sizeof($prods_arbo) > 0)
{
foreach($prods_arbo as $key => $value)
{
// print "id : ".$value[1].' :qty: '.$value[0].'<br>';
if(! in_array($value[1],$this->products))
$this->add_product($value[1], $value[0]);
}
}
}
}
}
**/
}
**/
}
}

View File

@ -354,7 +354,7 @@ if ($_POST['action'] == 'addline' && $user->rights->commande->creer)
$tva_tx = get_default_tva($mysoc,$commande->client,$prod->tva_tx);
// multiprix
if ($conf->global->PRODUIT_MULTIPRICES)
if ($conf->global->PRODUIT_MULTIPRICES && $commande->client->price_level)
{
$pu_ht = $prod->multiprices[$commande->client->price_level];
$pu_ttc = $prod->multiprices_ttc[$commande->client->price_level];

View File

@ -18,21 +18,20 @@
*/
/**
\file htdocs/commonobject.class.php
\ingroup core
\brief Fichier de la classe mere des classes metiers (facture, contrat, propal, commande, etc...)
\version $Id$
* \file htdocs/commonobject.class.php
* \ingroup core
* \brief Fichier de la classe mere des classes metiers (facture, contrat, propal, commande, etc...)
* \version $Id$
*/
/**
\class CommonObject
\brief Classe mere pour heritage des classes metiers
* \class CommonObject
* \brief Classe mere pour heritage des classes metiers
*/
class CommonObject
{
/**
* \brief Ajoute un contact associe au l'entite definie dans $this->element
* \param fk_socpeople Id du contact a ajouter
@ -352,9 +351,15 @@ class CommonObject
*/
function fetch_client()
{
global $conf;
$client = new Societe($this->db);
$result=$client->fetch($this->socid);
$this->client = $client;
// Use first price level if level not defined for third party
if ($conf->global->PRODUIT_MULTIPRICES && empty($this->client->price_level)) $this->client->price_level=1;
return $result;
}

View File

@ -885,7 +885,7 @@ if (($_POST['action'] == 'addline' || $_POST['action'] == 'addline_predef') && $
$tva_npr = get_default_npr($mysoc,$fac->client,$prod->tva_tx);
// We define price for product
if ($conf->global->PRODUIT_MULTIPRICES)
if ($conf->global->PRODUIT_MULTIPRICES && $fac->client->price_level)
{
$pu_ht = $prod->multiprices[$fac->client->price_level];
$pu_ttc = $prod->multiprices_ttc[$fac->client->price_level];

View File

@ -226,7 +226,7 @@ if ($_POST["action"] == 'addligne' && $user->rights->contrat->creer)
$tva_npr = get_default_npr($mysoc,$contrat->client,$prod->tva_npr);
// On defini prix unitaire
if ($conf->global->PRODUIT_MULTIPRICES)
if ($conf->global->PRODUIT_MULTIPRICES && $contrat->client->price_level)
{
$pu_ht = $prod->multiprices[$contrat->client->price_level];
$pu_ttc = $prod->multiprices_ttc[$contrat->client->price_level];

View File

@ -870,8 +870,12 @@ class Form
$opt.= '>'.$objp->ref.' - ';
$opt.= dol_trunc($objp->label,32).' - ';
$found=0;
$currencytext=$langs->trans("Currency".$conf->monnaie);
if (strlen($currencytext) > 10) $currencytext=$conf->monnaie; // If text is too long, we use the short code
// Multiprice
if ($price_level > 1)
if ($price_level >= 1) // If we need a particular price level (from 1 to 6)
{
$sql= "SELECT price, price_ttc, price_base_type ";
$sql.= "FROM ".MAIN_DB_PREFIX."product_price ";
@ -887,10 +891,11 @@ class Form
$objp2 = $this->db->fetch_object($result2);
if ($objp2)
{
$found=1;
if ($objp2->price_base_type == 'HT')
$opt.= price($objp2->price,1).' '.$langs->trans("Currency".$conf->monnaie).' '.$langs->trans("HT");
$opt.= price($objp2->price,1).' '.$currencytext.' '.$langs->trans("HT");
else
$opt.= price($objp2->price_ttc,1).' '.$langs->trans("Currency".$conf->monnaie).' '.$langs->trans("TTC");
$opt.= price($objp2->price_ttc,1).' '.$currencytext.' '.$langs->trans("TTC");
}
}
else
@ -898,13 +903,14 @@ class Form
dol_print_error($this->db);
}
}
//si il n'y a pas de prix multiple on prend le prix de base du produit/service
else
// If level no defined or multiprice not found, we used the default price
if (! $found)
{
if ($objp->price_base_type == 'HT')
$opt.= price($objp->price,1).' '.$langs->trans("Currency".$conf->monnaie).' '.$langs->trans("HT");
$opt.= price($objp->price,1).' '.$currencytext.' '.$langs->trans("HT");
else
$opt.= price($objp->price_ttc,1).' '.$langs->trans("Currency".$conf->monnaie).' '.$langs->trans("TTC");
$opt.= price($objp->price_ttc,1).' '.$currencytext.' '.$langs->trans("TTC");
}
if ($conf->stock->enabled && isset($objp->stock) && $objp->fk_product_type == 0)

View File

@ -338,7 +338,7 @@ if ($_POST["action"] == 'addinpropal')
$price_base_type = 'HT';
// multiprix
if ($conf->global->PRODUIT_MULTIPRICES)
if ($conf->global->PRODUIT_MULTIPRICES && $soc->price_level)
{
$pu_ht = $prod->multiprices[$soc->price_level];
$pu_ttc = $prod->multiprices_ttc[$soc->price_level];
@ -417,7 +417,7 @@ if ($_POST["action"] == 'addincommande')
$tva_tx = get_default_tva($mysoc,$soc,$prod->tva_tx);
// multiprix
if ($conf->global->PRODUIT_MULTIPRICES)
if ($conf->global->PRODUIT_MULTIPRICES && $soc->price_level)
{
$pu_ht = $prod->multiprices[$soc->price_level];
$pu_ttc = $prod->multiprices_ttc[$soc->price_level];
@ -497,7 +497,7 @@ if ($_POST["action"] == 'addinfacture' && $user->rights->facture->creer)
$tva_tx = get_default_tva($mysoc,$soc,$prod->tva_tx);
// multiprix
if ($conf->global->PRODUIT_MULTIPRICES)
if ($conf->global->PRODUIT_MULTIPRICES && $soc->price_level)
{
$pu_ht = $prod->multiprices[$soc->price_level];
$pu_ttc = $prod->multiprices_ttc[$soc->price_level];

View File

@ -155,7 +155,7 @@ class Propal extends CommonObject
$tva_tx = get_default_tva($mysoc,$this->client,$prod->tva_tx);
// multiprix
if($conf->global->PRODUIT_MULTIPRICES)
if($conf->global->PRODUIT_MULTIPRICES && $this->client->price_level)
{
$price = $prod->multiprices[$this->client->price_level];
}

View File

@ -633,6 +633,9 @@ class Societe extends CommonObject
$result = -3;
}
// Use first price level if level not defined for third party
if ($conf->global->PRODUIT_MULTIPRICES && empty($this->price_level)) $this->price_level=1;
return $result;
}