diff --git a/htdocs/commande/commande.class.php b/htdocs/commande/commande.class.php
index 1485e48ad70..b1a50c550ee 100644
--- a/htdocs/commande/commande.class.php
+++ b/htdocs/commande/commande.class.php
@@ -1136,19 +1136,19 @@ class Commande extends CommonObject
// Recherche total en stock pour chaque produit
if (sizeof($array_of_product))
{
- $sql = "SELECT fk_product, sum(ps.reel)";
+ $sql = "SELECT fk_product, sum(ps.reel) as total";
$sql.= " FROM ".MAIN_DB_PREFIX."product_stock as ps";
$sql.= " WHERE ps.fk_product in (".join(',',$array_of_product).")";
$sql.= ' GROUP BY fk_product ';
$result = $this->db->query($sql);
if ($result)
{
- $num = $this->db->num_rows();
+ $num = $this->db->num_rows($result);
$i = 0;
while ($i < $num)
{
- $row = $this->db->fetch_row( $i);
- $this->stocks[$row[0]] = $row[1];
+ $obj = $this->db->fetch_object($result);
+ $this->stocks[$obj->fk_product] = $obj->total;
$i++;
}
$this->db->free();
@@ -1426,13 +1426,12 @@ class Commande extends CommonObject
}
}
- /**
- * \brief Renvoi la liste des commandes (éventuellement filtrée sur un user) dans un tableau
- * \param brouillon 0=non brouillon, 1=brouillon
- * \param user Objet user de filtre
- * \return int -1 si erreur, tableau résultat si ok
- */
-
+ /**
+ * \brief Renvoi la liste des commandes (éventuellement filtrée sur un user) dans un tableau
+ * \param brouillon 0=non brouillon, 1=brouillon
+ * \param user Objet user de filtre
+ * \return int -1 si erreur, tableau résultat si ok
+ */
function liste_array ($brouillon=0, $user='')
{
$ga = array();
diff --git a/htdocs/fourn/commande/fiche.php b/htdocs/fourn/commande/fiche.php
index 3f0b73f32f4..9ef9f3ba118 100644
--- a/htdocs/fourn/commande/fiche.php
+++ b/htdocs/fourn/commande/fiche.php
@@ -438,16 +438,8 @@ if ($_GET["id"] > 0)
{
$objp = $db->fetch_object($resql);
print "
";
- print '| '.img_object($langs->trans("ShowProduct"),'product').' '.$objp->ref.' | ';
- if ($objp->fk_product > 0)
- {
- print '';
- print ''.stripslashes(nl2br($objp->description)).' | ';
- }
- else
- {
- print "".stripslashes(nl2br($objp->description))." | \n";
- }
+ print ''.img_object($langs->trans("ShowProduct"),'product').' '.$objp->ref.' | ';
+ print "".nl2br($objp->description)." | ";
print ''.$objp->tva_tx.'% | ';
print ''.$objp->qty.' | ';
if ($objp->remise_percent > 0)
diff --git a/htdocs/fourn/product/fiche.php b/htdocs/fourn/product/fiche.php
index 892138ce82e..eb05cf75281 100644
--- a/htdocs/fourn/product/fiche.php
+++ b/htdocs/fourn/product/fiche.php
@@ -49,10 +49,11 @@ $types[1] = $langs->trans("Service");
if ($_GET["action"] == 'fastappro')
{
- $product = new Product($db);
- $product->fetch($_GET["id"]);
- $result = $product->fastappro($user);
- Header("Location: fiche.php?id=".$_GET["id"]);
+ $product = new Product($db);
+ $product->fetch($_GET["id"]);
+ $result = $product->fastappro($user);
+ Header("Location: fiche.php?id=".$_GET["id"]);
+ exit;
}
@@ -572,27 +573,28 @@ else
print "\n\n";
diff --git a/htdocs/lib/product.lib.php b/htdocs/lib/product.lib.php
index 56c56401fec..7fb269e65a8 100644
--- a/htdocs/lib/product.lib.php
+++ b/htdocs/lib/product.lib.php
@@ -1,4 +1,4 @@
-
*
* This program is free software; you can redistribute it and/or modify
@@ -26,22 +26,22 @@
\version $Revision$
Ensemble de fonctions de base de dolibarr sous forme d'include
-*/
-
-function product_prepare_head($product)
-{
- global $langs, $conf;
- $h = 0;
- $head = array();
-
+*/
+
+function product_prepare_head($product)
+{
+ global $langs, $conf;
+ $h = 0;
+ $head = array();
+
$head[$h][0] = DOL_URL_ROOT."/product/fiche.php?id=".$product->id;
$head[$h][1] = $langs->trans("Card");
- $head[$h][2] = 'card';
+ $head[$h][2] = 'card';
$h++;
$head[$h][0] = DOL_URL_ROOT."/product/price.php?id=".$product->id;
$head[$h][1] = $langs->trans("Price");
- $head[$h][2] = 'price';
+ $head[$h][2] = 'price';
$h++;
//affichage onglet catégorie
@@ -49,7 +49,7 @@ function product_prepare_head($product)
{
$head[$h][0] = DOL_URL_ROOT."/product/categorie.php?id=".$product->id;
$head[$h][1] = $langs->trans('Categories');
- $head[$h][2] = 'category';
+ $head[$h][2] = 'category';
$h++;
}
@@ -61,30 +61,19 @@ function product_prepare_head($product)
{
$head[$h][0] = DOL_URL_ROOT."/product/barcode.php?id=".$product->id;
$head[$h][1] = $langs->trans("BarCode");
- $head[$h][2] = 'barcode';
+ $head[$h][2] = 'barcode';
$h++;
}
}
}
- if($product->type == 0) // Si produit stockable
- {
- if ($conf->stock->enabled)
- {
- $head[$h][0] = DOL_URL_ROOT."/product/stock/product.php?id=".$product->id;
- $head[$h][1] = $langs->trans("Stock");
- $head[$h][2] = 'stock';
- $h++;
- }
- }
-
- // Multilangs
+ // Multilangs
// TODO Ecran a virer et à remplacer par
if($conf->global->MAIN_MULTILANGS)
{
$head[$h][0] = DOL_URL_ROOT."/product/traduction.php?id=".$product->id;
$head[$h][1] = $langs->trans("Translation");
- $head[$h][2] = 'translation';
+ $head[$h][2] = 'translation';
$h++;
}
@@ -92,13 +81,13 @@ function product_prepare_head($product)
{
$head[$h][0] = DOL_URL_ROOT."/product/fournisseurs.php?id=".$product->id;
$head[$h][1] = $langs->trans("Suppliers");
- $head[$h][2] = 'suppliers';
+ $head[$h][2] = 'suppliers';
$h++;
}
$head[$h][0] = DOL_URL_ROOT."/product/stats/fiche.php?id=".$product->id;
$head[$h][1] = $langs->trans('Statistics');
- $head[$h][2] = 'stats';
+ $head[$h][2] = 'stats';
$h++;
// sousproduits
@@ -106,27 +95,38 @@ function product_prepare_head($product)
{
$head[$h][0] = DOL_URL_ROOT."/product/sousproduits/fiche.php?id=".$product->id;
$head[$h][1] = $langs->trans('AssociatedProducts');
- $head[$h][2] = 'subproduct';
+ $head[$h][2] = 'subproduct';
$h++;
}
$head[$h][0] = DOL_URL_ROOT."/product/stats/facture.php?id=".$product->id;
$head[$h][1] = $langs->trans('Referers');
- $head[$h][2] = 'referers';
+ $head[$h][2] = 'referers';
$h++;
$head[$h][0] = DOL_URL_ROOT."/product/photos.php?id=".$product->id;
$head[$h][1] = $langs->trans("Photos");
- $head[$h][2] = 'photos';
+ $head[$h][2] = 'photos';
$h++;
$head[$h][0] = DOL_URL_ROOT.'/product/document.php?id='.$product->id;
$head[$h][1] = $langs->trans('Documents');
- $head[$h][2] = 'document';
- $h++;
-
- return $head;
-}
-
+ $head[$h][2] = 'document';
+ $h++;
+
+ if($product->type == 0) // Si produit stockable
+ {
+ if ($conf->stock->enabled)
+ {
+ $head[$h][0] = DOL_URL_ROOT."/product/stock/product.php?id=".$product->id;
+ $head[$h][1] = $langs->trans("Stock");
+ $head[$h][2] = 'stock';
+ $h++;
+ }
+ }
+
+ return $head;
+}
+
?>
\ No newline at end of file
diff --git a/htdocs/product.class.php b/htdocs/product.class.php
index 593fc9a7f78..e6876641928 100644
--- a/htdocs/product.class.php
+++ b/htdocs/product.class.php
@@ -964,14 +964,14 @@ class Product
/**
- * \brief Charge tableau des stats commande pour le produit/service
- * \param socid Id societe
- * \return array Tableau des stats
+ * \brief Charge tableau des stats commande client pour le produit/service
+ * \param socid Id societe pour filtrer sur une société
+ * \param filtrestatut Id statut pour filtrer sur un statut
+ * \return array Tableau des stats
*/
- function load_stats_commande($socid=0)
+ function load_stats_commande($socid=0,$filtrestatut='')
{
- global $conf;
- global $user;
+ global $conf,$user;
$sql = "SELECT COUNT(DISTINCT c.fk_soc) as nb_customers, COUNT(DISTINCT c.rowid) as nb,";
$sql.= " COUNT(cd.rowid) as nb_rows, SUM(cd.qty) as qty";
@@ -980,12 +980,15 @@ class Product
if (!$user->rights->commercial->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
$sql.= " WHERE c.rowid = cd.fk_commande AND cd.fk_product = ".$this->id;
if (!$user->rights->commercial->client->voir && !$socid) $sql .= " AND c.fk_soc = sc.fk_soc AND sc.fk_user = " .$user->id;
- //$sql.= " AND c.fk_statut != 0";
if ($socid > 0)
{
- $sql .= " AND c.fk_soc = $socid";
+ $sql.= " AND c.fk_soc = ".$socid;
}
-
+ if ($filtrestatut)
+ {
+ $sql.= " AND c.fk_statut = ".$filtrestatut;
+ }
+
$result = $this->db->query($sql) ;
if ( $result )
{
@@ -1003,6 +1006,49 @@ class Product
}
}
+ /**
+ * \brief Charge tableau des stats commande fournisseur pour le produit/service
+ * \param socid Id societe pour filtrer sur une société
+ * \param filtrestatut Id statut pour filtrer sur un statut
+ * \return array Tableau des stats
+ */
+ function load_stats_commande_fournisseur($socid=0,$filtrestatut='')
+ {
+ global $conf,$user;
+
+ $sql = "SELECT COUNT(DISTINCT c.fk_soc) as nb_suppliers, COUNT(DISTINCT c.rowid) as nb,";
+ $sql.= " COUNT(cd.rowid) as nb_rows, SUM(cd.qty) as qty";
+ $sql.= " FROM ".MAIN_DB_PREFIX."commande_fournisseurdet as cd,";
+ $sql.= " ".MAIN_DB_PREFIX."commande_fournisseur as c";
+ if (!$user->rights->commercial->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
+ $sql.= " WHERE c.rowid = cd.fk_commande AND cd.fk_product = ".$this->id;
+ if (!$user->rights->commercial->client->voir && !$socid) $sql .= " AND c.fk_soc = sc.fk_soc AND sc.fk_user = " .$user->id;
+ if ($socid > 0)
+ {
+ $sql.= " AND c.fk_soc = ".$socid;
+ }
+ if ($filtrestatut)
+ {
+ $sql.= " AND c.fk_statut = ".$filtrestatut;
+ }
+
+ $result = $this->db->query($sql) ;
+ if ( $result )
+ {
+ $obj=$this->db->fetch_object($result);
+ $this->stats_commande_fournisseur['suppliers']=$obj->nb_suppliers;
+ $this->stats_commande_fournisseur['nb']=$obj->nb;
+ $this->stats_commande_fournisseur['rows']=$obj->nb_rows;
+ $this->stats_commande_fournisseur['qty']=$obj->qty?$obj->qty:0;
+ return 1;
+ }
+ else
+ {
+ $this->error=$this->db->error();
+ return -1;
+ }
+ }
+
/**
* \brief Charge tableau des stats contrat pour le produit/service
* \param socid Id societe
@@ -1360,61 +1406,55 @@ class Product
}
}
-
- /**
- * \brief Renvoie le nombre de fournisseurs
- * \return int nombre de fournisseur
- */
-
- function count_fournisseur()
- {
- $sql = "SELECT fk_soc";
- $sql .= " FROM ".MAIN_DB_PREFIX."product_fournisseur as p";
- $sql .= " WHERE p.fk_product = ".$this->id;
-
- $result = $this->db->query($sql) ;
-
- if ( $result )
+
+ /**
+ * \brief Renvoie la liste des fournisseurs du produit/service
+ * \return array Tableau des id de fournisseur
+ */
+ function list_suppliers()
{
- $num = $this->db->num_rows();
+ $list = array();
+
+ $sql = "SELECT fk_soc";
+ $sql.= " FROM ".MAIN_DB_PREFIX."product_fournisseur as p";
+ $sql.= " WHERE p.fk_product = ".$this->id;
+
+ $result = $this->db->query($sql);
+ if ($result)
+ {
+ $num = $this->db->num_rows($result);
+ $i=0;
+ while ($i < $num)
+ {
+ $obj = $this->db->fetch_object($result);
+ $list[$i] = $obj->fk_soc;
+ $i++;
+ }
+ }
- if ($num == 1)
- {
- $row = $this->db->fetch_row();
- $this->fourn_appro_open = $row[0];
- return 1;
- }
- else
- {
- return 0;
- }
+ return $list;
}
- else
+
+ /**
+ * \brief Saisie une commande fournisseur
+ * \param user Objet user de celui qui demande
+ * \param int <0 si ko, >0 si ok
+ */
+ function fastappro($user)
{
- return 0;
+ include_once DOL_DOCUMENT_ROOT."/fourn/fournisseur.class.php";
+
+ $list = $this->list_suppliers();
+ if (sizeof($list) > 0)
+ {
+ dolibarr_syslog("Product::fastappro");
+ $fournisseur = new Fournisseur($this->db);
+ $fournisseur->fetch($this->fourn_appro_open);
+
+ $fournisseur->ProductCommande($user, $this->id);
+ }
+ return 1;
}
- }
-
-
- /**
- *
- *
- */
- function fastappro($user)
- {
- include_once DOL_DOCUMENT_ROOT."/fourn/fournisseur.class.php";
-
- $nbf = $this->count_fournisseur();
- if ($nbf == 1)
- {
- dolibarr_syslog("Product::fastappro");
- $fournisseur = new Fournisseur($this->db);
- $fournisseur->fetch($this->fourn_appro_open);
-
- $fournisseur->ProductCommande($user, $this->id);
- }
-
- }
/**
diff --git a/htdocs/product/fiche.php b/htdocs/product/fiche.php
index 16552176291..488826e8d5d 100644
--- a/htdocs/product/fiche.php
+++ b/htdocs/product/fiche.php
@@ -353,24 +353,6 @@ if ($_POST["action"] == 'addinfacture' && $user->rights->facture->creer)
exit;
}
-if ($_POST["action"] == 'add_fourn' && $_POST["cancel"] <> $langs->trans("Cancel"))
-{
-
- $product = new Product($db);
- if( $product->fetch($_GET["id"]) )
- {
- if ($product->add_fournisseur($user, $_POST["id_fourn"], $_POST["ref_fourn"]) > 0)
- {
- $action = '';
- $mesg = $langs->trans("SupplierAdded");
- }
- else
- {
- $action = '';
- }
- }
-}
-
if ($_POST["cancel"] == $langs->trans("Cancel"))
{
$action = '';
@@ -500,7 +482,7 @@ if ($_GET["action"] == 'create' && $user->rights->produit->creer)
}
-/*
+/**
* Fiche produit
*/
if ($_GET["id"] || $_GET["ref"])
@@ -509,8 +491,15 @@ if ($_GET["id"] || $_GET["ref"])
if ($_GET["action"] <> 're-edit')
{
$product = new Product($db);
- if ($_GET["ref"]) $result = $product->fetch('',$_GET["ref"]);
- if ($_GET["id"]) $result = $product->fetch($_GET["id"]);
+ if ($_GET["ref"])
+ {
+ $result = $product->fetch('',$_GET["ref"]);
+ $_GET["id"] = $product->id;
+ }
+ elseif ($_GET["id"])
+ {
+ $result = $product->fetch($_GET["id"]);
+ }
llxHeader("","",$langs->trans("CardProduct".$product->type));
}
@@ -600,7 +589,7 @@ if ($_GET["id"] || $_GET["ref"])
// Stock
if ($product->type == 0 && $conf->stock->enabled)
{
- print '
| '.$langs->trans("Stock").' | ';
+ print '
| '.$langs->trans("Stock").' | ';
if ($product->no_stock)
{
print "Pas de définition de stock pour ce produit";
@@ -762,12 +751,6 @@ print "\n\n";
if ($_GET["action"] == '')
{
- if ($product->type == 0 && $user->rights->produit->commander && $num_fournisseur == 1)
- {
- print ' ';
- print $langs->trans("Order").'';
- }
-
if ( $user->rights->produit->creer)
{
print ' '.$langs->trans("Edit").'';
@@ -775,9 +758,24 @@ if ($_GET["action"] == '')
print ' '.$langs->trans("CreateCopy").'';
}
- $prod_use = $product->verif_prod_use($product->id);
+/*
+ if ($product->type == 0 && $user->rights->commande->creer)
+ {
+ $langs->load('orders');
+ print ' ';
+ print $langs->trans("CreateCustomerOrder").'';
+ }
- if ($user->rights->produit->supprimer && $prod_use == 0)
+ if ($product->type == 0 && $user->rights->fournisseur->commande->creer)
+ {
+ $langs->load('orders');
+ print ' ';
+ print $langs->trans("CreateSupplierOrder").'';
+ }
+*/
+
+ $product_is_used = $product->verif_prod_use($product->id);
+ if ($user->rights->produit->supprimer && ! $product_is_used)
{
print ' '.$langs->trans("Delete").'';
}
diff --git a/htdocs/product/stock/product.php b/htdocs/product/stock/product.php
index 078b7369520..454cd4a1813 100644
--- a/htdocs/product/stock/product.php
+++ b/htdocs/product/stock/product.php
@@ -40,9 +40,9 @@ $langs->load("bills");
$user->getrights('produit');
$mesg = '';
-if (!$user->rights->produit->lire)
+if (! $user->rights->produit->lire || ! $product->type == 0 || ! $conf->stock->enabled)
{
- accessforbidden();
+ accessforbidden();
}
@@ -142,32 +142,54 @@ if ($_GET["id"] || $_GET["ref"])
print $product->getLibStatut(2);
print ' |
';
- // TVA
- $langs->load("bills");
- print '| '.$langs->trans("VATRate").' | '.$product->tva_tx.'% |
';
-
// Stock
- if ($product->type == 0 && $conf->stock->enabled)
+ print '| '.$langs->trans("TotalStock").' | ';
+ if ($product->no_stock)
{
- print '
| '.$langs->trans("TotalStock").' | ';
- if ($product->no_stock)
+ print "Pas de définition de stock pour ce produit";
+ }
+ else
+ {
+ if ($product->stock_reel <= $product->seuil_stock_alerte)
{
- print " | Pas de définition de stock pour ce produit";
+ print ' | '.$product->stock_reel.' Seuil : '.$product->seuil_stock_alerte;
}
else
{
- if ($product->stock_reel <= $product->seuil_stock_alerte)
- {
- print ' | '.$product->stock_reel.' Seuil : '.$product->seuil_stock_alerte;
- }
- else
- {
- print " | ".$product->stock_reel;
- }
+ print " | ".$product->stock_reel;
}
- print ' |
';
}
+ print '';
+
+ // Nbre de commande clients en cours
+ if ($conf->commande->enabled)
+ {
+ $result=$product->load_stats_commande(0,'1');
+ if ($result < 0) dolibarr_print_error($db,$product->error);
+ print '| '.$langs->trans("CustomersOrders").' | ';
+ print '';
+ print $product->stats_commande['qty'];
+ $result=$product->load_stats_commande(0,'0');
+ if ($result < 0) dolibarr_print_error($db,$product->error);
+ print ' ('.$langs->trans("Draft").': '.$product->stats_commande['qty'].')';
+ print ' |
';
+ }
+
+ // Nbre de commande fournisseurs en cours
+ if ($conf->fournisseur->enabled)
+ {
+ $result=$product->load_stats_commande_fournisseur(0,'1');
+ if ($result < 0) dolibarr_print_error($db,$product->error);
+ print '| '.$langs->trans("SuppliersOrders").' | ';
+ print '';
+ print $product->stats_commande_fournisseur['qty'];
+ $result=$product->load_stats_commande_fournisseur(0,'0');
+ if ($result < 0) dolibarr_print_error($db,$product->error);
+ print ' ('.$langs->trans("Draft").': '.$product->stats_commande_fournisseur['qty'].')';
+ print ' |
';
+ }
+
print "";
}