Suite gestion des arrondis sur les montants

This commit is contained in:
Laurent Destailleur 2007-06-30 13:06:03 +00:00
parent 1de5331346
commit b90bcdcd33
2 changed files with 197 additions and 175 deletions

View File

@ -146,23 +146,23 @@ class Product
if ($this->price=='') $this->price = 0; if ($this->price=='') $this->price = 0;
if ($this->status=='') $this->status = 0; if ($this->status=='') $this->status = 0;
if (strlen(trim($this->price)) > 0 ) if ($this->price > 0)
{ {
if ($this->price_base_type == 'TTC') if ($this->price_base_type == 'TTC')
{ {
$price_ttc = $this->price; $price_ttc = price2num($this->price,'MU');
$price = $this->price / (1 + ($this->tva_tx / 100)); $price_ht = price2num($this->price / (1 + ($this->tva_tx / 100)),'MU');
} }
else else
{ {
$price = $this->price; $price_ht = price2num($this->price,'MU');
$price_ttc = $this->price * (1 + ($this->tva_tx / 100)); $price_ttc = price2num($this->price * (1 + ($this->tva_tx / 100)),'MU');
} }
} }
dolibarr_syslog("Product::Create ref=".$this->ref." Categorie : ".$this->catid); dolibarr_syslog("Product::Create ref=".$this->ref." Categorie : ".$this->catid);
if (strlen($this->ref) > 0) if ($this->ref)
{ {
$this->db->begin(); $this->db->begin();
@ -182,7 +182,14 @@ class Product
$sql.= "fk_user_author, fk_product_type, price, price_ttc, price_base_type, canvas)"; $sql.= "fk_user_author, fk_product_type, price, price_ttc, price_base_type, canvas)";
$sql.= " VALUES (now(), "; $sql.= " VALUES (now(), ";
if ($this->ref) $sql.= "'".$this->ref."', "; if ($this->ref) $sql.= "'".$this->ref."', ";
$sql.= $user->id.", ".$this->type.", '" . price2num($price) . "', '".$price_ttc."', '" . $this->price_base_type . "','".$this->canvas."')"; $sql.= $user->id.",";
$sql.= " ".$this->type.",";
$sql.= ($price_ht?price2num($price_ht):"null").",";
$sql.= ($price_ttc?price2num($price_ttc):"null").",";
$sql.= "'".$this->price_base_type."',";
$sql.= "'".$this->canvas."')";
dolibarr_syslog("Product::Create sql=".$sql);
$result = $this->db->query($sql); $result = $this->db->query($sql);
if ( $result ) if ( $result )
{ {
@ -191,7 +198,12 @@ class Product
if ($id > 0) if ($id > 0)
{ {
$this->id = $id; $this->id = $id;
$this->_log_price($user); $this->price = $price_ht;
$this->price_ttc = $price_ttc;
$result = $this->_log_price($user);
if ($result > 0)
{
if ( $this->update($id, $user) > 0) if ( $this->update($id, $user) > 0)
{ {
if ($this->catid > 0) if ($this->catid > 0)
@ -206,6 +218,11 @@ class Product
} }
} }
else else
{
$this->_setErrNo("Create",264);
}
}
else
{ {
$this->_setErrNo("Create",259); $this->_setErrNo("Create",259);
} }
@ -287,8 +304,10 @@ class Product
$langs->load("main"); $langs->load("main");
$langs->load("products"); $langs->load("products");
// Verification parametres
if (! $this->libelle) $this->libelle = 'LIBELLE MANQUANT'; if (! $this->libelle) $this->libelle = 'LIBELLE MANQUANT';
// Nettoyage parametres
$this->ref = trim(sanitize_string($this->ref)); $this->ref = trim(sanitize_string($this->ref));
$this->libelle = trim($this->libelle); $this->libelle = trim($this->libelle);
$this->description = trim($this->description); $this->description = trim($this->description);
@ -302,7 +321,7 @@ class Product
$sql = "UPDATE ".MAIN_DB_PREFIX."product "; $sql = "UPDATE ".MAIN_DB_PREFIX."product ";
$sql .= " SET label = '" . addslashes($this->libelle) ."'"; $sql .= " SET label = '" . addslashes($this->libelle) ."'";
if ($this->ref) $sql .= ",ref = '" . $this->ref ."'"; if ($this->ref) $sql .= ",ref = '" . $this->ref ."'";
$sql .= ",tva_tx = '" . $this->tva_tx."'"; $sql .= ",tva_tx = " . $this->tva_tx;
$sql .= ",envente = " . $this->status; $sql .= ",envente = " . $this->status;
$sql .= ",weight = " . ($this->new_weight!='' ? "'".$this->new_weight."'" : 'null'); $sql .= ",weight = " . ($this->new_weight!='' ? "'".$this->new_weight."'" : 'null');
$sql .= ",weight_units = '" . $this->new_weight_units."'"; $sql .= ",weight_units = '" . $this->new_weight_units."'";
@ -315,6 +334,7 @@ class Product
$sql .= ",duration = '" . $this->duration_value . $this->duration_unit ."'"; $sql .= ",duration = '" . $this->duration_value . $this->duration_unit ."'";
$sql .= " WHERE rowid = " . $id; $sql .= " WHERE rowid = " . $id;
dolibarr_syslog("Product::update sql=".$sql);
if ( $this->db->query($sql) ) if ( $this->db->query($sql) )
{ {
// Multilangs // Multilangs

View File

@ -113,7 +113,7 @@ if ($_POST["action"] == 'add' && $user->rights->produit->creer)
// Produit spécifique // Produit spécifique
// $_POST n'est pas utilise dans la classe Product // $_POST n'est pas utilise dans la classe Product
// mais dans des classes qui hérite de Product // mais dans des classes qui hérite de Product
$id = $product->Create($user, $_POST); $id = $product->create($user, $_POST);
if ($id > 0) if ($id > 0)
{ {
@ -399,10 +399,12 @@ if ($_POST["cancel"] == $langs->trans("Cancel"))
exit; exit;
} }
$html = new Form($db); $html = new Form($db);
/* /*
* Action création du produit * Fiche création du produit
*/ */
if ($_GET["action"] == 'create' && $user->rights->produit->creer) if ($_GET["action"] == 'create' && $user->rights->produit->creer)
{ {
@ -737,7 +739,7 @@ if ($_GET["id"] || $_GET["ref"])
print '</td></tr>'; print '</td></tr>';
// TVA // TVA
print '<tr><td>'.$langs->trans("VATRate").'</td><td>'.$product->tva_tx.'%</td></tr>'; print '<tr><td>'.$langs->trans("VATRate").'</td><td>'.price2num($product->tva_tx,'MU').'%</td></tr>';
// Stock // Stock
if ($product->isproduct() && $conf->stock->enabled) if ($product->isproduct() && $conf->stock->enabled)