diff --git a/htdocs/product.class.php3 b/htdocs/product.class.php3
index c19a3da017e..df4ebed2546 100644
--- a/htdocs/product.class.php3
+++ b/htdocs/product.class.php3
@@ -47,16 +47,25 @@ class Product
*/
Function create($user)
{
+ if (strlen($this->price)==0)
+ {
+ $this->price = 0;
+ }
+ $sql = "INSERT INTO llx_product (datec, fk_user_author, fk_product_type, price)";
+ $sql .= " VALUES (now(),".$user->id.",$this->type, " . ereg_replace(",",".",$this->price) . ")";
- $sql = "INSERT INTO llx_product (datec, fk_user_author, fk_product_type) VALUES (now(),".$user->id.",$this->type)";
-
if ($this->db->query($sql) )
{
$id = $this->db->last_insert_id();
- if ( $this->update($id, $user) )
+ if ($id > 0)
{
- return $id;
+ $this->id = $id;
+ $this->_log_price($user);
+ if ( $this->update($id, $user) )
+ {
+ return $id;
+ }
}
}
else
@@ -64,6 +73,58 @@ class Product
print $this->db->error() . ' in ' . $sql;
}
}
+ /*
+ *
+ */
+ Function _log_price($user)
+ {
+
+ $sql = "REPLACE INTO llx_product_price ";
+ $sql .= " SET date_price= now()";
+ $sql .= " ,fk_product = ".$this->id;
+ $sql .= " ,fk_user_author = ".$user->id;
+ $sql .= " ,price = ".$this->price;
+ $sql .= " ,envente = ".$this->envente;
+ $sql .= " ,tva_tx = ".$this->tva_tx;
+
+ if ($this->db->query($sql) )
+ {
+ return 1;
+ }
+ else
+ {
+ print $this->db->error() . ' in ' . $sql;
+ }
+ }
+ /*
+ *
+ *
+ */
+ Function update_price($id, $user)
+ {
+ if (strlen(trim($this->price)) > 0 )
+ {
+ $sql = "UPDATE llx_product ";
+ $sql .= " SET price = " . ereg_replace(",",".",$this->price);
+ $sql .= " WHERE rowid = " . $id;
+
+ if ( $this->db->query($sql) )
+ {
+ $this->_log_price($user);
+ return 1;
+ }
+ else
+ {
+ print $this->db->error() . ' in ' . $sql;
+ return -1;
+ }
+ }
+ else
+ {
+ $this->mesg_error = "Prix saisi invalide.";
+ return -2;
+ }
+ }
/*
*
@@ -77,7 +138,6 @@ class Product
$sql = "UPDATE llx_product ";
$sql .= " SET label = '" . trim($this->libelle) ."'";
$sql .= ",ref = '" . trim($this->ref) ."'";
- $sql .= ",price = " . ereg_replace(",",".",$this->price);
$sql .= ",tva_tx = " . $this->tva_tx ;
$sql .= ",envente = " . $this->envente ;
$sql .= ",description = '" . trim($this->description) ."'";
diff --git a/htdocs/product/fiche.php3 b/htdocs/product/fiche.php3
index db844146648..47d2571328b 100644
--- a/htdocs/product/fiche.php3
+++ b/htdocs/product/fiche.php3
@@ -112,6 +112,32 @@ if ($HTTP_POST_VARS["action"] == 'update' &&
$mesg = 'Fiche non mise à jour !' . "
" . $product->mesg_error;
}
}
+
+if ($HTTP_POST_VARS["action"] == 'update_price' &&
+ $cancel <> 'Annuler' &&
+ ( $user->rights->produit->modifier || $user->rights->produit->creer))
+{
+ $product = new Product($db);
+ $result = $product->fetch($id);
+ $product->price = $HTTP_POST_VARS["price"];
+
+ if ( $product->update_price($id, $user) > 0 )
+ {
+ $action = '';
+ $mesg = 'Fiche mise à jour';
+ }
+ else
+ {
+ $action = 'edit_price';
+ $mesg = 'Fiche non mise à jour !' . "
" . $product->mesg_error;
+ }
+}
+
+
+if ($cancel == 'Annuler')
+{
+ $action = '';
+}
/*
*
*
@@ -131,7 +157,7 @@ if ($action == 'create')
print '
| Taux TVA | ';
$html = new Form($db);
print $html->select_tva("tva_tx");
- print ' % |
';
+ print '';
print "| Description | ";
print ' |
";
@@ -221,8 +247,27 @@ else
print "";
}
+
+ if ($action == 'edit_price' && $user->rights->produit->creer)
+ {
+ print '
Edition de la fiche '.$types[$product->type].' : '.$product->ref.'
';
+
+ print "';
+ }
+
+
- if ($action == 'edit')
+ if ($action == 'edit' && $user->rights->produit->creer)
{
print '
Edition de la fiche '.$types[$product->type].' : '.$product->ref.'
';
@@ -230,14 +275,15 @@ else
print '';
print '';
print '';
@@ -313,15 +359,25 @@ else
/* ************************************************************************** */
print '
';
-print '| - | ';
-print '- | ';
-print '- | ';
-
-if ($action == 'create' || $action == 'edit')
+if ($action == '')
+{
+ if ($user->rights->produit->modifier || $user->rights->produit->creer)
+ {
+ print '[Changer le prix] | ';
+ }
+ else
+ {
+ print '- | ';
+ }
+}
+else
{
print '- | ';
}
-else
+print '- | ';
+print '- | ';
+
+if ($action == '')
{
if ($user->rights->produit->modifier || $user->rights->produit->creer)
{
@@ -332,6 +388,10 @@ else
print '- | ';
}
}
+else
+{
+ print '- | ';
+}
print '- | ';
print '
';