From 58229907d4eb9ba2ea0611b39858db9468179cda Mon Sep 17 00:00:00 2001
From: Laurent Destailleur <eldy@destailleur.fr>
Date: Tue, 28 Feb 2017 12:35:55 +0100
Subject: [PATCH] Removed not used class "Service". Reduce nb of request on
 dashboard.

---
 htdocs/index.php                       |  7 +-
 htdocs/product/class/product.class.php | 12 ++--
 htdocs/product/class/service.class.php | 88 --------------------------
 3 files changed, 10 insertions(+), 97 deletions(-)
 delete mode 100644 htdocs/product/class/service.class.php

diff --git a/htdocs/index.php b/htdocs/index.php
index 810d2fff4b7..b59535d0169 100644
--- a/htdocs/index.php
+++ b/htdocs/index.php
@@ -210,7 +210,7 @@ if (empty($user->societe_id))
 	                   'Contact',
 	                   'Adherent',
 	                   'Product',
-	                   'Service',
+	                   'Product',
 	                   'Propal',
 	                   'Commande',
 	                   'Facture',
@@ -338,7 +338,10 @@ if (empty($user->societe_id))
 	                $board->load_state_board($user);
 	                $boardloaded[$classe]=$board;
 	            }
-	            else $board=$boardloaded[$classe];
+	            else 
+	            {
+	                $board=$boardloaded[$classe];
+	            }
 
 	            $var=!$var;
 	            if (!empty($langfile[$key])) $langs->load($langfile[$key]);
diff --git a/htdocs/product/class/product.class.php b/htdocs/product/class/product.class.php
index 9726f822636..ad4aa3b0b5d 100644
--- a/htdocs/product/class/product.class.php
+++ b/htdocs/product/class/product.class.php
@@ -4223,29 +4223,27 @@ class Product extends CommonObject
 	}
 
 	/**
-	 *  Charge indicateurs this->nb de tableau de bord
+	 *  Load indicators this->nb for the dashboard
 	 *
-	 *  @param     int     $type       0=Product, 1=Service
 	 *  @return    int                 <0 if KO, >0 if OK
 	 */
-	function load_state_board($type=0)
+	function load_state_board()
 	{
 		global $conf, $user;
 
 		$this->nb=array();
 
-		$sql = "SELECT count(p.rowid) as nb";
+		$sql = "SELECT count(p.rowid) as nb, fk_product_type";
 		$sql.= " FROM ".MAIN_DB_PREFIX."product as p";
 		$sql.= ' WHERE p.entity IN ('.getEntity($this->element, 1).')';
-		if ($type == 1) $sql.= " AND p.fk_product_type = 1";
-		else $sql.= " AND p.fk_product_type <> 1";
+		$sql.= ' GROUP BY fk_product_type';
 
 		$resql=$this->db->query($sql);
 		if ($resql)
 		{
 			while ($obj=$this->db->fetch_object($resql))
 			{
-				if ($type == 1) $this->nb["services"]=$obj->nb;
+				if ($obj->fk_product_type == 1) $this->nb["services"]=$obj->nb;
 				else $this->nb["products"]=$obj->nb;
 			}
             $this->db->free($resql);
diff --git a/htdocs/product/class/service.class.php b/htdocs/product/class/service.class.php
deleted file mode 100644
index 40e8d39488b..00000000000
--- a/htdocs/product/class/service.class.php
+++ /dev/null
@@ -1,88 +0,0 @@
-<?php
-/* Copyright (C) 2002      Rodolphe Quiedeville <rodolphe@quiedeville.org>
- * Copyright (C) 2004-2013 Laurent Destailleur  <eldy@users.sourceforge.net>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-/**
- *       \file       htdocs/product/class/service.class.php
- *       \ingroup    service
- *       \brief      Fichier de la classe des services predefinis
- */
-require_once DOL_DOCUMENT_ROOT .'/core/class/commonobject.class.php';
-
-
-/**
- *	Class to manage predefined services
- *
- *  @deprecated     Use class Product compatible for both product and services
- */
-class Service extends CommonObject
-{
-	public $libelle;
-	public $price;
-	public $tms;
-	public $debut;
-	public $fin;
-
-	public $debut_epoch;
-	public $fin_epoch;
-
-	/**
-	*  Constructor
-	*
-	*  @param      DoliDB		$db      Database handler
-	*/
-	function __construct($db)
-	{
-		$this->db = $db;
-	}
-
-
-	/**
-	 *	Charge indicateurs this->nb de tableau de bord
-	 *
-	 *	@return     int         <0 if KO, >0 if OK
-	 */
-	function load_state_board()
-	{
-		global $conf, $user;
-
-		$this->nb=array();
-
-		$sql = "SELECT count(p.rowid) as nb";
-		$sql.= " FROM ".MAIN_DB_PREFIX."product as p";
-		$sql.= ' WHERE p.entity IN ('.getEntity('product', 1).')';
-		$sql.= " AND p.fk_product_type = 1";
-
-		$resql=$this->db->query($sql);
-		if ($resql)
-		{
-			while ($obj=$this->db->fetch_object($resql))
-			{
-				$this->nb["services"]=$obj->nb;
-			}
-            $this->db->free($resql);
-			return 1;
-		}
-		else
-		{
-			dol_print_error($this->db);
-			$this->error=$this->db->error();
-			return -1;
-		}
-	}
-
-}
-- 
GitLab