2 if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
3 /*********************************************************************************
4 * SugarCRM is a customer relationship management program developed by
5 * SugarCRM, Inc. Copyright (C) 2004-2011 SugarCRM Inc.
7 * This program is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU Affero General Public License version 3 as published by the
9 * Free Software Foundation with the addition of the following permission added
10 * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
11 * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
12 * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
14 * This program is distributed in the hope that it will be useful, but WITHOUT
15 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16 * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
19 * You should have received a copy of the GNU Affero General Public License along with
20 * this program; if not, see http://www.gnu.org/licenses or write to the Free
21 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
24 * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
25 * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
27 * The interactive user interfaces in modified source and object code versions
28 * of this program must display Appropriate Legal Notices, as required under
29 * Section 5 of the GNU Affero General Public License version 3.
31 * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
32 * these Appropriate Legal Notices must retain the display of the "Powered by
33 * SugarCRM" logo. If the display of the logo is not reasonably feasible for
34 * technical reasons, the Appropriate Legal Notices must display the words
35 * "Powered by SugarCRM".
36 ********************************************************************************/
42 require_once('include/Dashlets/DashletGenericChart.php');
44 class OpportunitiesByLeadSourceDashlet extends DashletGenericChart
46 public $pbls_lead_sources = array();
47 public $pbls_ids = array();
49 protected $_seedName = 'Opportunities';
51 public function displayOptions()
53 global $app_list_strings;
55 $selected_datax = array();
56 if (!empty($this->pbls_lead_sources) && sizeof($this->pbls_lead_sources) > 0)
57 foreach ($this->pbls_lead_sources as $key)
58 $selected_datax[] = $key;
60 $selected_datax = array_keys($app_list_strings['lead_source_dom']);
62 $this->_searchFields['pbls_lead_sources']['options'] = array_filter($app_list_strings['lead_source_dom']);
63 $this->_searchFields['pbls_lead_sources']['input_name0'] = $selected_datax;
65 if (!isset($this->pbls_ids) || count($this->pbls_ids) == 0)
66 $this->_searchFields['pbls_ids']['input_name0'] = array_keys(get_user_array(false));
68 return parent::displayOptions();
71 public function display()
73 global $current_user, $sugar_config;
74 require("modules/Charts/chartdefs.php");
75 $chartDef = $chartDefs['pipeline_by_lead_source'];
77 require_once('include/SugarCharts/SugarChart.php');
78 $sugarChart = new SugarChart();
79 $sugarChart->is_currency = true;
80 $currency_symbol = $sugar_config['default_currency_symbol'];
81 if ($current_user->getPreference('currency')){
83 $currency = new Currency();
84 $currency->retrieve($current_user->getPreference('currency'));
85 $currency_symbol = $currency->symbol;
87 $subtitle = translate('LBL_OPP_SIZE', 'Charts') . " " . $currency_symbol . "1" . translate('LBL_OPP_THOUSANDS', 'Charts');
88 $sugarChart->setProperties('', $subtitle, $chartDef['chartType']);
89 $sugarChart->base_url = $chartDef['base_url'];
90 $sugarChart->group_by = $chartDef['groupBy'];
91 $sugarChart->url_params = array();
92 if ( count($this->pbls_ids) > 0 )
93 $sugarChart->url_params['assigned_user_id'] = array_values($this->pbls_ids);
94 $sugarChart->getData($this->constructQuery());
95 $sugarChart->data_set = $sugarChart->sortData($sugarChart->data_set, 'lead_source', true);
96 $xmlFile = $sugarChart->getXMLFileName($this->id);
97 $sugarChart->saveXMLFile($xmlFile, $sugarChart->generateXML());
99 return $this->getTitle('<div align="center"></div>') .
100 '<div align="center">' . $sugarChart->display($this->id, $xmlFile, '100%', '480', false) . '</div><br />';
103 protected function constructQuery()
105 $query = "SELECT lead_source,sum(amount_usdollar/1000) as total,count(*) as opp_count ".
106 "FROM opportunities ";
107 $query .= "WHERE opportunities.deleted=0 ";
108 if ( count($this->pbls_ids) > 0 )
109 $query .= "AND opportunities.assigned_user_id IN ('".implode("','",$this->pbls_ids)."') ";
110 if ( count($this->pbls_lead_sources) > 0 )
111 $query .= "AND opportunities.lead_source IN ('".implode("','",$this->pbls_lead_sources)."') ";
113 $query .= "AND opportunities.lead_source IN ('".implode("','",array_keys($GLOBALS['app_list_strings']['lead_source_dom']))."') ";
114 $query .= "GROUP BY lead_source ORDER BY total DESC";