2004-12-08 16:02:07 +01:00
|
|
|
<?php
|
2009-04-27 22:37:50 +02:00
|
|
|
/* Copyright (C) 2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
|
2012-12-30 15:13:49 +01:00
|
|
|
* Copyright (C) 2005-2012 Regis Houssin <regis.houssin@capnetworks.com>
|
2009-07-30 00:59:18 +02:00
|
|
|
*
|
2004-12-08 16:02:07 +01:00
|
|
|
* 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
|
2013-01-16 15:36:08 +01:00
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
2004-12-08 16:02:07 +01:00
|
|
|
* (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
|
2011-08-01 01:19:04 +02:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2004-12-08 16:02:07 +01:00
|
|
|
*/
|
|
|
|
|
|
2005-08-12 23:45:18 +02:00
|
|
|
/**
|
2010-07-21 13:21:37 +02:00
|
|
|
* \file htdocs/societe/class/client.class.php
|
2009-07-30 00:59:18 +02:00
|
|
|
* \ingroup societe
|
|
|
|
|
* \brief File for class of customers
|
|
|
|
|
*/
|
2012-08-23 02:04:35 +02:00
|
|
|
include_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
|
2004-12-08 16:02:07 +01:00
|
|
|
|
|
|
|
|
|
2009-07-30 00:59:18 +02:00
|
|
|
/**
|
2013-06-16 21:31:21 +02:00
|
|
|
* Class to manage customers
|
2009-07-30 00:59:18 +02:00
|
|
|
*/
|
2005-08-12 23:45:18 +02:00
|
|
|
class Client extends Societe
|
|
|
|
|
{
|
2011-09-20 23:29:13 +02:00
|
|
|
var $nb;
|
2009-07-30 00:59:18 +02:00
|
|
|
|
2005-08-12 23:45:18 +02:00
|
|
|
/**
|
2011-09-20 23:29:13 +02:00
|
|
|
* Constructor
|
|
|
|
|
*
|
2012-01-10 17:16:17 +01:00
|
|
|
* @param DoliDB $db Database handler
|
2005-08-12 23:45:18 +02:00
|
|
|
*/
|
2012-01-10 17:16:17 +01:00
|
|
|
function __construct($db)
|
2005-08-12 23:45:18 +02:00
|
|
|
{
|
2012-01-10 17:16:17 +01:00
|
|
|
$this->db = $db;
|
2005-08-12 23:45:18 +02:00
|
|
|
}
|
2004-12-08 16:02:07 +01:00
|
|
|
|
2005-08-12 23:45:18 +02:00
|
|
|
/**
|
2011-09-20 23:29:13 +02:00
|
|
|
* Load indicators into this->nb for board
|
|
|
|
|
*
|
|
|
|
|
* @return int <0 if KO, >0 if OK
|
2005-08-12 23:45:18 +02:00
|
|
|
*/
|
|
|
|
|
function load_state_board()
|
|
|
|
|
{
|
2006-03-31 18:04:12 +02:00
|
|
|
global $conf, $user;
|
2009-07-30 00:59:18 +02:00
|
|
|
|
2007-01-03 02:50:29 +01:00
|
|
|
$this->nb=array("customers" => 0,"prospects" => 0);
|
2007-10-24 21:40:09 +02:00
|
|
|
$clause = "WHERE";
|
2004-12-08 16:02:07 +01:00
|
|
|
|
2007-06-12 00:51:47 +02:00
|
|
|
$sql = "SELECT count(s.rowid) as nb, s.client";
|
2005-08-12 23:45:18 +02:00
|
|
|
$sql.= " FROM ".MAIN_DB_PREFIX."societe as s";
|
2008-03-01 02:26:41 +01:00
|
|
|
if (!$user->rights->societe->client->voir && !$user->societe_id)
|
2007-10-24 21:40:09 +02:00
|
|
|
{
|
|
|
|
|
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON s.rowid = sc.fk_soc";
|
|
|
|
|
$sql.= " WHERE sc.fk_user = " .$user->id;
|
|
|
|
|
$clause = "AND";
|
|
|
|
|
}
|
2012-01-10 17:16:17 +01:00
|
|
|
$sql.= " ".$clause." s.client IN (1,2,3)";
|
2012-01-11 14:14:14 +01:00
|
|
|
$sql.= ' AND s.entity IN ('.getEntity($this->element, 1).')';
|
2005-08-12 23:45:18 +02:00
|
|
|
$sql.= " GROUP BY s.client";
|
2009-07-30 00:59:18 +02:00
|
|
|
|
2005-08-12 23:45:18 +02:00
|
|
|
$resql=$this->db->query($sql);
|
|
|
|
|
if ($resql)
|
|
|
|
|
{
|
|
|
|
|
while ($obj=$this->db->fetch_object($resql))
|
|
|
|
|
{
|
2010-01-05 21:03:37 +01:00
|
|
|
if ($obj->client == 1 || $obj->client == 3) $this->nb["customers"]+=$obj->nb;
|
|
|
|
|
if ($obj->client == 2 || $obj->client == 3) $this->nb["prospects"]+=$obj->nb;
|
2005-08-12 23:45:18 +02:00
|
|
|
}
|
2013-06-16 21:31:21 +02:00
|
|
|
$this->db->free($resql);
|
2005-08-12 23:45:18 +02:00
|
|
|
return 1;
|
|
|
|
|
}
|
2009-07-30 00:59:18 +02:00
|
|
|
else
|
2005-08-12 23:45:18 +02:00
|
|
|
{
|
2009-02-20 23:53:15 +01:00
|
|
|
dol_print_error($this->db);
|
2005-08-12 23:45:18 +02:00
|
|
|
$this->error=$this->db->error();
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
2004-12-08 16:02:07 +01:00
|
|
|
|
2005-08-12 23:45:18 +02:00
|
|
|
}
|
2009-07-30 00:59:18 +02:00
|
|
|
|
2004-12-08 16:02:07 +01:00
|
|
|
}
|
|
|
|
|
?>
|