2 if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
3 /*********************************************************************************
4 * SugarCRM Community Edition is a customer relationship management program developed by
5 * SugarCRM, Inc. Copyright (C) 2004-2012 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();
50 * @see DashletGenericChart::$_seedName
52 protected $_seedName = 'Opportunities';
55 * @see DashletGenericChart::displayOptions()
57 public function displayOptions()
59 global $app_list_strings;
61 $selected_datax = array();
62 if (!empty($this->pbls_lead_sources) && sizeof($this->pbls_lead_sources) > 0)
63 foreach ($this->pbls_lead_sources as $key)
64 $selected_datax[] = $key;
66 $selected_datax = array_keys($app_list_strings['lead_source_dom']);
68 $this->_searchFields['pbls_lead_sources']['options'] = array_filter($app_list_strings['lead_source_dom']);
69 $this->_searchFields['pbls_lead_sources']['input_name0'] = $selected_datax;
71 if (!isset($this->pbls_ids) || count($this->pbls_ids) == 0)
72 $this->_searchFields['pbls_ids']['input_name0'] = array_keys(get_user_array(false));
74 return parent::displayOptions();
78 * @see DashletGenericChart::display()
80 public function display()
82 global $current_user, $sugar_config;
83 require("modules/Charts/chartdefs.php");
84 $chartDef = $chartDefs['pipeline_by_lead_source'];
86 require_once('include/SugarCharts/SugarChartFactory.php');
87 $sugarChart = SugarChartFactory::getInstance();
88 $sugarChart->is_currency = true;
89 $currency_symbol = $sugar_config['default_currency_symbol'];
90 if ($current_user->getPreference('currency')){
92 $currency = new Currency();
93 $currency->retrieve($current_user->getPreference('currency'));
94 $currency_symbol = $currency->symbol;
96 $subtitle = translate('LBL_OPP_SIZE', 'Charts') . " " . $currency_symbol . "1" . translate('LBL_OPP_THOUSANDS', 'Charts');
97 $sugarChart->setProperties('', $subtitle, $chartDef['chartType']);
98 $sugarChart->base_url = $chartDef['base_url'];
99 $sugarChart->group_by = $chartDef['groupBy'];
100 $sugarChart->url_params = array();
101 if ( count($this->pbls_ids) > 0 )
102 $sugarChart->url_params['assigned_user_id'] = array_values($this->pbls_ids);
103 $sugarChart->getData($this->constructQuery());
104 $sugarChart->data_set = $sugarChart->sortData($sugarChart->data_set, 'lead_source', true);
105 $xmlFile = $sugarChart->getXMLFileName($this->id);
106 $sugarChart->saveXMLFile($xmlFile, $sugarChart->generateXML());
108 return $this->getTitle('<div align="center"></div>') .
109 '<div align="center">' . $sugarChart->display($this->id, $xmlFile, '100%', '480', false) . '</div>'. $this->processAutoRefresh();
113 * @see DashletGenericChart::constructQuery()
115 protected function constructQuery()
117 $query = "SELECT lead_source,sum(amount_usdollar/1000) as total,count(*) as opp_count ".
118 "FROM opportunities ";
119 $query .= "WHERE opportunities.deleted=0 ";
120 if ( count($this->pbls_ids) > 0 )
121 $query .= "AND opportunities.assigned_user_id IN ('".implode("','",$this->pbls_ids)."') ";
122 if ( count($this->pbls_lead_sources) > 0 )
123 $query .= "AND opportunities.lead_source IN ('".implode("','",$this->pbls_lead_sources)."') ";
125 $query .= "AND opportunities.lead_source IN ('".implode("','",array_keys($GLOBALS['app_list_strings']['lead_source_dom']))."') ";
126 $query .= "GROUP BY lead_source ORDER BY total DESC";