Gestion des la precision decimals sur les prix unitaires des produits.

This commit is contained in:
Laurent Destailleur 2007-06-16 13:06:05 +00:00
parent b0beed7fb6
commit 357ce5bdf1
14 changed files with 294 additions and 321 deletions

View File

@ -472,11 +472,11 @@ class Conf
$this->format_date_short_java="dd/MM/yyyy"; $this->format_date_short_java="dd/MM/yyyy";
// Format montant affichés // Limites decimales
if (! isset($this->global->MAIN_MAX_DECIMALS_SHOWN)) if (! isset($this->global->MAIN_MAX_DECIMALS_UNIT)) $this->global->MAIN_MAX_DECIMALS_UNIT=5;
{ if (! isset($this->global->MAIN_MAX_DECIMALS_TTC)) $this->global->MAIN_MAX_DECIMALS_TTC=2;
$this->global->MAIN_MAX_DECIMALS_SHOWN=5; if (! isset($this->global->MAIN_MAX_DECIMALS_SHOWN)) $this->global->MAIN_MAX_DECIMALS_SHOWN=8;
}
/* \todo Ajouter une option Gestion de la TVA dans le module compta qui permet de désactiver la fonction TVA /* \todo Ajouter une option Gestion de la TVA dans le module compta qui permet de désactiver la fonction TVA
* (pour particuliers ou libéraux en franchise) * (pour particuliers ou libéraux en franchise)

View File

@ -78,6 +78,7 @@ EnterPaymentDueToCustomer=Make payment due to customer
VAT=VAT VAT=VAT
VATRate=VAT Rate VATRate=VAT Rate
Amount=Amount Amount=Amount
PriceBase=Price base
TotalTTCToYourCredit=Total TTC to your credit TotalTTCToYourCredit=Total TTC to your credit
BillStatus=Invoice status BillStatus=Invoice status
BillStatusDraft=Draft (needs to be validated) BillStatusDraft=Draft (needs to be validated)

View File

@ -52,6 +52,7 @@ InformationToHelpDiagnose=This is information that can help to diagnose
MoreInformation=More information MoreInformation=More information
NotePublic=Note (public) NotePublic=Note (public)
NotePrivate=Note (private) NotePrivate=Note (private)
PrecisionUnitIsLimitedToXDecimals=Dolibarr was setup to limit precision of unit prices to <b>%s</b> decimals.
yes=yes yes=yes
Yes=Yes Yes=Yes
no=no no=no

View File

@ -78,6 +78,7 @@ EnterPaymentDueToCustomer=R
VAT=TVA VAT=TVA
VATRate=Taux TVA VATRate=Taux TVA
Amount=Montant Amount=Montant
PriceBase=Base du prix
TotalTTCToYourCredit=Total TTC à votre crédit TotalTTCToYourCredit=Total TTC à votre crédit
BillStatus=État de la facture BillStatus=État de la facture
BillStatusDraft=Brouillon (à valider) BillStatusDraft=Brouillon (à valider)

View File

@ -52,6 +52,7 @@ InformationToHelpDiagnose=Voici les informations qui pourront aider au diagnosti
MoreInformation=Plus d'information MoreInformation=Plus d'information
NotePublic=Note (publique) NotePublic=Note (publique)
NotePrivate=Note (privée) NotePrivate=Note (privée)
PrecisionUnitIsLimitedToXDecimals=Dolibarr a été configuré pour limiter la précision des prix unitaires à <b>%s</b> décimals.
yes=oui yes=oui
Yes=Oui Yes=Oui
no=non no=non

View File

@ -1896,12 +1896,12 @@ function print_fleche_navigation($page,$file,$options='',$nextpage)
/** /**
* \brief Fonction qui retourne un montant monétaire formaté * \brief Fonction qui retourne un montant monétaire formaté pour visualisation
* \remarks Fonction utilisée dans les pdf et les pages html * \remarks Fonction utilisée dans les pdf et les pages html
* \param amount Montant a formater * \param amount Montant a formater
* \param html Formatage html ou pas (0 par defaut) * \param html Formatage html ou pas (0 par defaut)
* \param outlangs Objet langs pour formatage * \param outlangs Objet langs pour formatage
* \param trunc 1=Tronque affichage si trop de décimales * \param trunc 1=Tronque affichage si trop de décimales,0=Force le non troncage
* \return string Chaine avec montant formaté * \return string Chaine avec montant formaté
* \seealso price2num Fonction inverse de price * \seealso price2num Fonction inverse de price
*/ */
@ -1919,12 +1919,13 @@ function price($amount, $html=0, $outlangs='', $trunc=1)
if ($outlangs->trans("SeparatorThousand")!= "SeparatorThousand") $thousand=$outlangs->trans("SeparatorThousand"); if ($outlangs->trans("SeparatorThousand")!= "SeparatorThousand") $thousand=$outlangs->trans("SeparatorThousand");
//print "dec=".$dec." thousand=".$thousand; //print "dec=".$dec." thousand=".$thousand;
//print "xx".$amount."-"; //print "amount=".$amount."-";
$amount = ereg_replace(',','.',$amount); $amount = ereg_replace(',','.',$amount);
//print $amount."-"; //print $amount."-";
$datas = split("\.",$amount); $datas = split("\.",$amount);
$decpart = $datas[1]; $decpart = $datas[1];
//print $datas[1]."<br>"; $decpart = eregi_replace('0+$','',$decpart); // Supprime les 0 de fin de partie décimale
//print "decpart=".$decpart."<br>";
// On pose par defaut 2 decimales // On pose par defaut 2 decimales
$nbdecimal = 2; $nbdecimal = 2;
@ -1953,16 +1954,35 @@ function price($amount, $html=0, $outlangs='', $trunc=1)
} }
/** /**
\brief Fonction qui retourne un numérique depuis un montant formaté \brief Fonction qui retourne un numérique conforme PHP et SQL, depuis un montant au
\remarks Fonction à appeler sur montants saisi avant un insert format utilisateur.
\param amount montant a formater \remarks Fonction à appeler sur montants saisis avant un insert en base
\seealso price Fonction inverse de price2num \param amount Montant a formater
\param rounding 'MU'=Round to Max unit price (MAIN_MAX_DECIMALS_UNIT)
'MT'=Round to Max with Tax (MAIN_MAX_DECIMALS_TTC)
'MS'=Round to Max Shown (MAIN_MAX_DECIMALS_SHOWN)
''=No rounding
\return string Montant au format numérique PHP et SQL (Exemple: '99.99999')
\seealso price Fonction inverse de price2num
*/ */
function price2num($amount) function price2num($amount,$rounding='')
{ {
$amount=ereg_replace(',','.',$amount); global $conf;
$amount=ereg_replace(' ','',$amount);
return $amount; // Round PHP function does not allow number like '1,234.5'.
// Numbers must be '1234.5'
$amount=ereg_replace(',','.',$amount);
$amount=ereg_replace(' ','',$amount);
if ($rounding)
{
if ($rounding == 'MU') $amount = round($amount,$conf->global->MAIN_MAX_DECIMALS_UNIT);
elseif ($rounding == 'MT') $amount = round($amount,$conf->global->MAIN_MAX_DECIMALS_TTC);
elseif ($rounding == 'MS') $amount = round($amount,$conf->global->MAIN_MAX_DECIMALS_SHOWN);
else $amount='ErrorBadParameterProvidedToFunction';
$amount=ereg_replace(',','.',$amount);
$amount=ereg_replace(' ','',$amount);
}
return $amount;
} }

View File

@ -23,12 +23,13 @@
/** /**
\file htdocs/lib/price.lib.php \file htdocs/lib/price.lib.php
\brief Librairie contenant les fonctions pour calculer un prix. \brief Librairie contenant les fonctions pour calculer un prix.
\author Rodolphe Quiedeville. \author Rodolphe Quiedeville.
\version $Revision$ \version $Revision$
Ensemble des fonctions permettant de calculer un prix. Ensemble des fonctions permettant de calculer un prix.
*/ */
/** /**
\brief Permet de calculer les parts total HT, TVA et TTC d'une ligne de \brief Permet de calculer les parts total HT, TVA et TTC d'une ligne de
facture, propale, commande ou autre depuis: facture, propale, commande ou autre depuis:

View File

@ -130,18 +130,7 @@ class Product
return 1; return 1;
} }
} }
/**
* \brief Definit le prix de vente
* \return void
*/
function SetSellPrice($price, $base_type='HT')
{
$price = ereg_replace(" ","", $price);
$price = ereg_replace(",",".", $price);
$this->price = $price;
$this->price_base_type = $base_type;
}
/** /**
\brief Insère le produit en base \brief Insère le produit en base
\param user Utilisateur qui effectue l'insertion \param user Utilisateur qui effectue l'insertion
@ -574,130 +563,70 @@ class Product
/** /**
* \brief Ajoute un changement de prix en base dans l'historique des prix * \brief Ajoute un changement de prix en base dans l'historique des prix
* \param user utilisateur qui modifie le prix * \param user Objet utilisateur qui modifie le prix
*/ * \return int <0 si KO, >0 si OK
function _log_price($user) */
{ function _log_price($user)
// MultiPrix : si activé, on gère tout ici, même le prix standard {
global $conf; // MultiPrix : si activé, on gère tout ici, même le prix standard
if($conf->global->PRODUIT_MULTIPRICES == 1) global $conf;
{
$queryError = false;
for($i=2;$i<=$conf->global->PRODUIT_MULTIPRICES_LIMIT;$i++)
{
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 if ($conf->global->PRODUIT_MULTIPRICES)
$sql_multiprix = "DELETE FROM ".MAIN_DB_PREFIX."product_price "; {
$sql_multiprix .= "WHERE date_price = now()"; $queryError = false;
$sql_multiprix .= " and fk_product = ".$this->id; for($i=2;$i<=$conf->global->PRODUIT_MULTIPRICES_LIMIT;$i++)
$sql_multiprix .= " and fk_user_author = ".$user->id; {
$sql_multiprix .= " and price = ".price2num($this->multiprices["$i"]); if($this->multiprices["$i"] != "")
{
// On ajoute nouveau tarif
$sql_multiprix = "INSERT INTO ".MAIN_DB_PREFIX."product_price(date_price,fk_product,fk_user_author,price_level,price,price_ttc,price_base_type,tva_tx) ";
$sql_multiprix .= " VALUES(now(),".$this->id.",".$user->id.",".$i.",".price2num($this->multiprices["$i"]).",'".price2num($this->multiprices_ttc["$i"])."','".$this->multiprices_base_type["$i"]."',".$this->tva_tx;
$sql_multiprix .= ")";
if (! $this->db->query($sql_multiprix) )
{
$queryError = true;
}
}
}
if (strlen(trim($this->price)) > 0 )
{
// On ajoute nouveau tarif
$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.",".$this->price.",".$this->price_ttc.",'".$this->price_base_type."',".$this->status.",".$this->tva_tx;
$sql .= ")";
if (! $this->db->query($sql) )
$queryError = true;
}
if($queryError)
{
dolibarr_print_error($this->db);
return 0;
}
else
return 1;
}
else
{
// On ajoute nouveau tarif
$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.",".$this->price.",".$this->price_ttc.",'".$this->price_base_type."',".$this->status.",".$this->tva_tx;
$sql .= ")";
$this->db->query($sql_multiprix); dolibarr_syslog("Product::_log_price sql=".$sql);
$resql=$this->db->query($sql);
// On ajoute nouveau tarif if ($resql)
$sql_multiprix = "INSERT INTO ".MAIN_DB_PREFIX."product_price(date_price,fk_product,fk_user_author,price_level,price,price_ttc,price_base_type,tva_tx) "; {
$sql_multiprix .= " VALUES(now(),".$this->id.",".$user->id.",".$i.",".price2num($this->multiprices["$i"]).",'".$price_ttc."','".$this->multiprices_base_type["$i"]."',".$this->tva_tx; return 1;
$sql_multiprix .= ")"; }
if (! $this->db->query($sql_multiprix) ) else
{ {
$queryError = true; dolibarr_print_error($this->db);
} return -1;
} }
} }
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($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,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;
}
if($queryError)
{
dolibarr_print_error($this->db);
return 0;
}
else
return 1;
}
else
{
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 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,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) )
{
return 1;
}
else
{
dolibarr_print_error($this->db);
return 0;
}
}
}
/** /**
@ -869,57 +798,70 @@ class Product
} }
/** /**
\brief Modifie le prix d'un produit/service \brief Modifie le prix d'un produit/service
\param id id du produit/service à modifier \param id Id du produit/service à modifier
\param user utilisateur qui modifie le prix \param newprice Nouveau prix
*/ \param newpricebase HT ou TTC
function update_price($id, $user) \param user Objet utilisateur qui modifie le prix
{ */
//multiprix function update_price($id, $newprice, $newpricebase, $user)
global $conf; {
//multiprix
global $conf,$langs;
dolibarr_syslog("Product::update_price id=".$id." newprice=".$newprice." newpricebase=".$newpricebase);
if (strlen(trim($this->price)) > 0 ) if ($newprice)
{ {
if ($this->price_base_type == 'TTC') if ($newpricebase == 'TTC')
{ {
$price_ttc = $this->price; $price_ttc = price2num($newprice,'MU');
$price = $this->price / (1 + ($this->tva_tx / 100)); $price = price2num($newprice) / (1 + ($this->tva_tx / 100));
} $price = price2num($price,'MU');
else }
{ else
$price = $this->price; {
$price_ttc = $this->price * (1 + ($this->tva_tx / 100)); $price = price2num($newprice,'MU');
} $price_ttc = price2num($newprice) * (1 + ($this->tva_tx / 100));
$price_ttc = price2num($price_ttc,'MU');
}
$sql = "UPDATE ".MAIN_DB_PREFIX."product "; // Ne pas mettre de quote sur le numériques decimaux.
$sql .= " SET price = " . price2num($price); // Ceci provoque des sotckage avec arrondis en base au lieu des valeurs exactes.
$sql .= " , price_base_type='".$this->price_base_type."'"; $sql = "UPDATE ".MAIN_DB_PREFIX."product ";
$sql .= " , price_ttc='".$price_ttc."'"; $sql .= " SET price=".$price."";
$sql .= " WHERE rowid = " . $id; $sql .= " , price_base_type='".$newpricebase."'";
$sql .= " , price_ttc=".$price_ttc."";
$sql .= " WHERE rowid = " . $id;
if ( $this->db->query($sql) ) dolibarr_syslog("Product::update_price sql=".$sql);
{ $resql=$this->db->query($sql);
$this->_log_price($user); if ($resql)
return 1; {
} $this->price = $price;
else $this->price_ttc = $price_ttc;
{ $this->price_base_type = $newpricebase;
dolibarr_print_error($this->db);
return -1; $this->_log_price($user);
} return 1;
} }
else if(($conf->global->PRODUIT_MULTIPRICES == 1) && (count($this->multiprices) > 0)) else
{ {
$this->_log_price($user); dolibarr_print_error($this->db);
return 1; return -1;
} }
else }
{ else if(($conf->global->PRODUIT_MULTIPRICES) && (count($this->multiprices) > 0))
$this->error = "Prix saisi invalide."; {
return -2; $this->_log_price($user);
} return 1;
} }
else
{
$this->error = $langs->trans("ErrorBadParameter");
return -2;
}
}
/** /**
@ -957,9 +899,9 @@ class Product
$this->id = $result["rowid"]; $this->id = $result["rowid"];
$this->ref = $result["ref"]; $this->ref = $result["ref"];
$this->libelle = stripslashes($result["label"]); $this->libelle = $result["label"];
$this->description = stripslashes($result["description"]); $this->description = $result["description"];
$this->note = stripslashes($result["note"]); $this->note = $result["note"];
$this->price = $result["price"]; $this->price = $result["price"];
$this->price_ttc = $result["price_ttc"]; $this->price_ttc = $result["price_ttc"];
$this->price_base_type = $result["price_base_type"]; $this->price_base_type = $result["price_base_type"];
@ -987,7 +929,7 @@ class Product
if( $conf->global->MAIN_MULTILANGS) $this->getMultiLangs(); if( $conf->global->MAIN_MULTILANGS) $this->getMultiLangs();
// multiprix // multiprix
if($conf->global->PRODUIT_MULTIPRICES == 1) if ($conf->global->PRODUIT_MULTIPRICES)
{ {
if ($ref) if ($ref)
{ {

View File

@ -42,7 +42,7 @@ $user->getrights('produit');
if (!$user->rights->produit->lire) if (!$user->rights->produit->lire)
accessforbidden(); accessforbidden();
$html = new Form($db);
/* /*
* Actions * Actions
@ -51,48 +51,49 @@ $html = new Form($db);
if ($_POST["action"] == 'update_price' && if ($_POST["action"] == 'update_price' &&
$_POST["cancel"] <> $langs->trans("Cancel") && $user->rights->produit->creer) $_POST["cancel"] <> $langs->trans("Cancel") && $user->rights->produit->creer)
{ {
$product = new Product($db); $product = new Product($db);
$result = $product->fetch($_GET["id"]); $result = $product->fetch($_GET["id"]);
$product->SetSellprice($_POST["price"], $_POST["price_base_type"]); $newprice=price2num($_POST["price"],'MU');
$newpricebase=$_POST["price_base_type"];
// MultiPrix // MultiPrix
if($conf->global->PRODUIT_MULTIPRICES == 1) if($conf->global->PRODUIT_MULTIPRICES)
{ {
for($i=2;$i<=$conf->global->PRODUIT_MULTIPRICES_LIMIT;$i++) for($i=2;$i<=$conf->global->PRODUIT_MULTIPRICES_LIMIT;$i++)
{ {
if($_POST["price_".$i]) if($_POST["price_".$i])
{ {
$price = ereg_replace(" ","", $_POST["price_".$i]); $price = ereg_replace(" ","", $_POST["price_".$i]);
$price = ereg_replace(",",".", $price); $price = ereg_replace(",",".", $price);
$product->multiprices["$i"] = $price; $product->multiprices["$i"] = $price;
$product->multiprices_base_type["$i"] = $_POST["multiprices_base_type_".$i]; $product->multiprices_base_type["$i"] = $_POST["multiprices_base_type_".$i];
} }
else else
{ {
$product->multiprices["$i"] = ""; $product->multiprices["$i"] = "";
} }
} }
} }
if ( $product->update_price($product->id, $user) > 0 ) if ($product->update_price($product->id, $newprice, $newpricebase, $user) > 0)
{ {
$_GET["action"] = ''; $_GET["action"] = '';
$mesg = 'Fiche mise à jour'; $mesg = $langs->trans("RecordSaved");
} }
else else
{ {
$_GET["action"] = 'edit_price'; $_GET["action"] = 'edit_price';
$mesg = 'Fiche non mise à jour !' . "<br>" . $product->mesg_error; $mesg = '<div class="error">'.$product->error.'</div>';
} }
} }
/* /*
* Affiche historique prix * Affiche historique prix
*/ */
$html = new Form($db);
$product = new Product($db); $product = new Product($db);
if ($_GET["ref"]) $result = $product->fetch('',$_GET["ref"]); if ($_GET["ref"]) $result = $product->fetch('',$_GET["ref"]);
@ -125,7 +126,7 @@ print '</tr>';
// MultiPrix // MultiPrix
if($conf->global->PRODUIT_MULTIPRICES == 1) if($conf->global->PRODUIT_MULTIPRICES)
{ {
print '<tr><td>'.$langs->trans("SellingPrice").' 1</td>'; print '<tr><td>'.$langs->trans("SellingPrice").' 1</td>';
@ -168,15 +169,15 @@ if($conf->global->PRODUIT_MULTIPRICES == 1)
// Prix // Prix
else else
{ {
print '<tr><td>'.$langs->trans("SellingPrice").'</td><td colspan="2">'; print '<tr><td>'.$langs->trans("SellingPrice").'</td><td colspan="2">';
if ($product->price_base_type == 'TTC') 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 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 // Statut
@ -196,17 +197,18 @@ print "</div>\n";
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
print "\n<div class=\"tabsAction\">\n"; if (! $_GET["action"])
if ($_GET["action"] == '')
{ {
print "\n<div class=\"tabsAction\">\n";
if ($user->rights->produit->modifier || $user->rights->produit->creer) if ($user->rights->produit->modifier || $user->rights->produit->creer)
{ {
print '<a class="butAction" href="'.DOL_URL_ROOT.'/product/price.php?action=edit_price&amp;id='.$product->id.'">'.$langs->trans("UpdatePrice").'</a>'; print '<a class="butAction" href="'.DOL_URL_ROOT.'/product/price.php?action=edit_price&amp;id='.$product->id.'">'.$langs->trans("UpdatePrice").'</a>';
} }
print "\n</div>\n";
} }
print "\n</div>\n";
/* /*
@ -214,20 +216,16 @@ print "\n</div>\n";
*/ */
if ($_GET["action"] == 'edit_price' && $user->rights->produit->creer) if ($_GET["action"] == 'edit_price' && $user->rights->produit->creer)
{ {
print_fiche_titre($langs->trans("NewPrice")); print_fiche_titre($langs->trans("NewPrice"));
print '<form action="price.php?id='.$product->id.'" method="post">';
print '<form action="price.php?id='.$product->id.'" method="post">'; print '<input type="hidden" name="action" value="update_price">';
print '<input type="hidden" name="action" value="update_price">'; print '<input type="hidden" name="id" value="'.$product->id.'">';
print '<input type="hidden" name="id" value="'.$product->id.'">'; print '<table class="border" width="100%">';
print '<table class="border" width="100%">'; print '<tr><td width="15%">';
if($conf->global->PRODUIT_MULTIPRICES == 1) $text=$langs->trans('SellingPrice');
{ if ($conf->global->PRODUIT_MULTIPRICES) $text.=' 1';
print '<tr><td width="15%">'.$langs->trans('SellingPrice').' 1</td>'; print $html->textwithhelp($text,$langs->trans("PrecisionUnitIsLimitedToXDecimals",$conf->global->MAIN_MAX_DECIMALS_UNIT),$direction=1,$usehelpcursor=1);
} print '</td>';
else
{
print '<tr><td width="15%">'.$langs->trans('SellingPrice').'</td>';
}
if ($product->price_base_type == 'TTC') if ($product->price_base_type == 'TTC')
{ {
@ -278,7 +276,7 @@ if ($_GET["action"] == 'edit_price' && $user->rights->produit->creer)
// Liste des evolutions du prix // 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) if($conf->global->PRODUIT_MULTIPRICES)
{ {
$sql .= "p.price_level, "; $sql .= "p.price_level, ";
$sql .= $db->pdate("p.date_price")." as dp, u.rowid as user_id, u.login"; $sql .= $db->pdate("p.date_price")." as dp, u.rowid as user_id, u.login";
@ -293,13 +291,12 @@ else
$sql .= $db->pdate("p.date_price")." as dp, u.rowid as user_id, u.login"; $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 .= " FROM ".MAIN_DB_PREFIX."product_price as p, ".MAIN_DB_PREFIX."user as u";
$sql .= " WHERE fk_product = ".$product->id; $sql .= " WHERE fk_product = ".$product->id;
$sql .= " AND p.fk_user_author = u.rowid "; $sql .= " AND p.fk_user_author = u.rowid";
$sql .= " ORDER BY p.date_price DESC "; $sql .= " ORDER BY p.date_price DESC ";
} }
//$sql .= $db->plimit();
$sql .= $db->plimit();
$result = $db->query($sql) ; $result = $db->query($sql) ;
if ($result) if ($result)
{ {
$num = $db->num_rows($result); $num = $db->num_rows($result);
@ -325,47 +322,42 @@ if ($result)
print '<tr class="liste_titre">'; print '<tr class="liste_titre">';
print '<td>'.$langs->trans("AppliedPricesFrom").'</td>'; print '<td>'.$langs->trans("AppliedPricesFrom").'</td>';
if($conf->global->PRODUIT_MULTIPRICES == 1) if($conf->global->PRODUIT_MULTIPRICES)
{ {
print '<td>'.$langs->trans("MultiPriceLevelsName").'</td>'; print '<td>'.$langs->trans("MultiPriceLevelsName").'</td>';
} }
print '<td>'.$langs->trans("Price").'</td>'; print '<td align="right">'.$langs->trans("HT").'</td>';
print '<td align="right">'.$langs->trans("TTC").'</td>';
print '<td align="center">'.$langs->trans("PriceBase").'</td>';
print '<td>'.$langs->trans("ChangedBy").'</td>'; print '<td>'.$langs->trans("ChangedBy").'</td>';
print '</tr>'; print '</tr>';
$var=True; $var=True;
$i = 0; $i = 0;
while ($i < $num) while ($i < $num)
{ {
$objp = $db->fetch_object($result); $objp = $db->fetch_object($result);
$var=!$var; $var=!$var;
print "<tr $bc[$var]>"; print "<tr $bc[$var]>";
// Date
print "<td>".dolibarr_print_date($objp->dp,"%d %b %Y %H:%M:%S")."</td>";
// Date // catégorie de Prix
print "<td>".dolibarr_print_date($objp->dp,"%d %b %Y %H:%M:%S")."</td>"; if($conf->global->PRODUIT_MULTIPRICES)
{
print "<td>".$objp->price_level."</td>";
}
// catégorie de Prix print '<td align="right">'.price($objp->price)."</td>";
if($conf->global->PRODUIT_MULTIPRICES == 1) print '<td align="right">'.price($objp->price_ttc)."</td>";
{ print '<td align="center">'.$langs->trans($objp->price_base_type)."</td>";
print "<td>".$objp->price_level."</td>";
}
if ($objp->price_base_type == 'TTC') // 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>';
print "<td>".price($objp->price_ttc); print "</tr>\n";
} $i++;
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>';
print "</tr>\n";
$i++;
}
$db->free($result); $db->free($result);
print "</table>"; print "</table>";
print "<br>"; print "<br>";

View File

@ -561,11 +561,25 @@ drop table if exists llx_ventes;
drop table if exists llx_pointmort; drop table if exists llx_pointmort;
drop table if exists llx_birthday_alert; drop table if exists llx_birthday_alert;
-- Pas de limite sur nb decimal dans base car definie en option -- Pas de limite sur nb decimal des prix dans base car definie en option
ALTER TABLE llx_product_price ADD COLUMN price_ttc float DEFAULT 0 AFTER price; -- Tous les prix doivent etre au format float(16,8)
ALTER TABLE llx_product ADD COLUMN price_ttc float DEFAULT 0 AFTER price_base_type; -- Tous les tx tva doivent etre au format float(6,3)
ALTER TABLE llx_product_price MODIFY price_ttc float DEFAULT 0; ALTER TABLE llx_product_price ADD COLUMN price_ttc double(16,8) DEFAULT 0 AFTER price;
ALTER TABLE llx_product ADD COLUMN price_ttc float DEFAULT 0; ALTER TABLE llx_product ADD COLUMN price_ttc double(16,8) DEFAULT 0 AFTER price_base_type;
ALTER TABLE llx_product MODIFY price double(16,8) DEFAULT 0;
ALTER TABLE llx_product MODIFY price_ttc double(16,8) DEFAULT 0;
ALTER TABLE llx_product MODIFY tva_tx double(6,3);
ALTER TABLE llx_product_price MODIFY price double(16,8) DEFAULT 0;
ALTER TABLE llx_product_price MODIFY price_ttc double(16,8) DEFAULT 0;
ALTER TABLE llx_product_price MODIFY tva_tx double(6,3);
ALTER TABLE llx_product_fournisseur_price_log MODIFY price double(16,8);
ALTER TABLE llx_product_fournisseur_price_log MODIFY quantity double;
ALTER TABLE llx_product_fournisseur_price MODIFY price double(16,8);
ALTER TABLE llx_product_fournisseur_price MODIFY quantity double;
-- Changement de idp en rowid -- Changement de idp en rowid
-- V4 ALTER TABLE llx_propal DROP FOREIGN KEY llx_propal_ibfk1; -- V4 ALTER TABLE llx_propal DROP FOREIGN KEY llx_propal_ibfk1;

View File

@ -29,10 +29,10 @@ create table llx_product
label varchar(255) NOT NULL, label varchar(255) NOT NULL,
description text, description text,
note text, note text,
price double, price double(16,8),
price_ttc float(12,4) DEFAULT 0, price_ttc double(16,8) DEFAULT 0,
price_base_type varchar(3) DEFAULT 'HT', price_base_type varchar(3) DEFAULT 'HT',
tva_tx double, tva_tx double(6,3),
fk_user_author integer, fk_user_author integer,
envente tinyint DEFAULT 1, envente tinyint DEFAULT 1,
nbvente integer DEFAULT 0, nbvente integer DEFAULT 0,

View File

@ -27,8 +27,8 @@ create table llx_product_fournisseur_price
tms timestamp, tms timestamp,
fk_product integer, fk_product integer,
fk_soc integer, -- lien sur llx_societe fk_soc integer, -- lien sur llx_societe
price real, price double(16,8),
quantity real, quantity double,
fk_user integer fk_user integer
)type=innodb; )type=innodb;

View File

@ -26,8 +26,8 @@ create table llx_product_fournisseur_price_log
datec datetime, datec datetime,
fk_product integer, fk_product integer,
fk_soc integer, -- lien sur llx_societe fk_soc integer, -- lien sur llx_societe
price real, price double(16,8),
quantity real, quantity double,
fk_user integer fk_user integer
)type=innodb; )type=innodb;

View File

@ -26,11 +26,11 @@ create table llx_product_price
tms timestamp, tms timestamp,
fk_product integer NOT NULL, fk_product integer NOT NULL,
date_price datetime NOT NULL, date_price datetime NOT NULL,
price_level tinyint(4) NULL DEFAULT 1, price_level tinyint(4) NULL DEFAULT 1,
price double, price double(16,8),
price_ttc float(12,4) DEFAULT 0, price_ttc double(16,8) DEFAULT 0,
price_base_type varchar(3) DEFAULT 'HT', price_base_type varchar(3) DEFAULT 'HT',
tva_tx double NOT NULL, tva_tx double(6,3) NOT NULL,
fk_user_author integer, fk_user_author integer,
envente tinyint DEFAULT 1 envente tinyint DEFAULT 1
)type=innodb; )type=innodb;