diff --git a/htdocs/core/lib/product.lib.php b/htdocs/core/lib/product.lib.php
index dfc57313add..2bd0dc1ced2 100644
--- a/htdocs/core/lib/product.lib.php
+++ b/htdocs/core/lib/product.lib.php
@@ -360,13 +360,13 @@ function show_stats_for_company($product, $socid)
if (!empty($conf->mrp->enabled) && $user->rights->mrp->read)
{
$nblines++;
- //$ret = $product->load_stats_mo($socid);
+ $ret = $product->load_stats_mo($socid);
if ($ret < 0) dol_print_error($db);
$langs->load("orders");
print '
| ';
print ''.img_object('', 'mrp').' '.$langs->trans("MO").'';
print ' | ';
- print $product->stats_mo['suppliers'];
+ print $product->stats_mo['customers'];
print ' | ';
print $product->stats_mo['nb'];
print ' | ';
diff --git a/htdocs/product/class/product.class.php b/htdocs/product/class/product.class.php
index 18565347072..f4cc018ff31 100644
--- a/htdocs/product/class/product.class.php
+++ b/htdocs/product/class/product.class.php
@@ -2357,6 +2357,48 @@ class Product extends CommonObject
}
}
+ // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
+ /**
+ * Charge tableau des stats OF pour le produit/service
+ *
+ * @param int $socid Id societe
+ * @return integer Tableau des stats dans $this->stats_mo, <0 if ko >0 if ok
+ */
+ public function load_stats_mo($socid = 0) {
+ // phpcs:enable
+ global $conf, $user, $hookmanager;
+
+ $sql = "SELECT COUNT(DISTINCT c.fk_soc) as nb_customers, COUNT(DISTINCT c.rowid) as nb,";
+ $sql .= " SUM(c.qty) as qty";
+ $sql .= " FROM ".MAIN_DB_PREFIX."mrp_mo as c";
+ if (!$user->rights->societe->client->voir && !$socid) {
+ $sql .= "INNER JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON sc.fk_soc=c.fk_soc AND sc.fk_user = ".$user->id;
+ }
+ $sql .= " WHERE ";
+ $sql .= " c.entity IN (".getEntity('mo').")";
+
+ $sql .= " AND c.fk_product =".$this->id;
+ if ($socid > 0) {
+ $sql .= " AND c.fk_soc = ".$socid;
+ }
+
+ $result = $this->db->query($sql);
+ if ($result) {
+ $obj = $this->db->fetch_object($result);
+ $this->stats_mo['customers'] = $obj->nb_customers ? $obj->nb_customers : 0;
+ $this->stats_mo['nb'] = $obj->nb;
+ $this->stats_mo['qty'] = $obj->qty ? $obj->qty : 0;
+
+ $parameters = array('socid' => $socid);
+ $reshook = $hookmanager->executeHooks('loadStatsCustomerProposal', $parameters, $this, $action);
+ if ($reshook > 0) $this->stats_mo = $hookmanager->resArray['stats_mo'];
+
+ return 1;
+ } else {
+ $this->error = $this->db->error();
+ return -1;
+ }
+ }
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
/**
|