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 ********************************************************************************/
41 require_once('include/Dashlets/DashletGenericChart.php');
43 class OpportunitiesByLeadSourceByOutcomeDashlet extends DashletGenericChart
45 public $lsbo_lead_sources = array();
46 public $lsbo_ids = array();
48 protected $_seedName = 'Opportunities';
50 public function displayOptions()
52 global $app_list_strings;
54 $selected_datax = array();
55 if (!empty($this->lsbo_lead_sources) && sizeof($this->lsbo_lead_sources) > 0)
56 foreach ($this->lsbo_lead_sources as $key)
57 $selected_datax[] = $key;
59 $selected_datax = array_keys($app_list_strings['lead_source_dom']);
61 $this->_searchFields['lsbo_lead_sources']['options'] = array_filter($app_list_strings['lead_source_dom']);
62 $this->_searchFields['lsbo_lead_sources']['input_name0'] = $selected_datax;
64 if (!isset($this->lsbo_ids) || count($this->lsbo_ids) == 0)
65 $this->_searchFields['lsbo_ids']['input_name0'] = array_keys(get_user_array(false));
67 return parent::displayOptions();
70 public function display()
72 global $current_user, $sugar_config;
73 require("modules/Charts/chartdefs.php");
74 $chartDef = $chartDefs['lead_source_by_outcome'];
76 require_once('include/SugarCharts/SugarChart.php');
77 $sugarChart = new SugarChart();
78 $sugarChart->is_currency = true;
79 $currency_symbol = $sugar_config['default_currency_symbol'];
80 if ($current_user->getPreference('currency')){
82 $currency = new Currency();
83 $currency->retrieve($current_user->getPreference('currency'));
84 $currency_symbol = $currency->symbol;
86 $subtitle = translate('LBL_OPP_SIZE', 'Charts') . " " . $currency_symbol . "1" . translate('LBL_OPP_THOUSANDS', 'Charts');
87 $sugarChart->setProperties('', $subtitle, $chartDef['chartType']);
88 $sugarChart->base_url = $chartDef['base_url'];
89 $sugarChart->group_by = $chartDef['groupBy'];
90 $sugarChart->url_params = array();
91 if ( count($this->lsbo_ids) > 0 )
92 $sugarChart->url_params['assigned_user_id'] = array_values($this->lsbo_ids);
93 $sugarChart->getData($this->constuctQuery());
94 $sugarChart->data_set = $sugarChart->sortData($sugarChart->data_set, 'lead_source', true, 'sales_stage', true, true);
95 $xmlFile = $sugarChart->getXMLFileName($this->id);
96 $sugarChart->saveXMLFile($xmlFile, $sugarChart->generateXML());
98 return $this->getTitle('<div align="center"></div>') .
99 '<div align="center">' . $sugarChart->display($this->id, $xmlFile, '100%', '480', false) . '</div><br />';
102 protected function constuctQuery()
104 $query = "SELECT lead_source,sales_stage,sum(amount_usdollar/1000) as total, ".
105 "count(*) as opp_count FROM opportunities ";
106 $query .= " WHERE opportunities.deleted=0 ";
107 if ( count($this->lsbo_ids) > 0 )
108 $query .= "AND opportunities.assigned_user_id IN ('".implode("','",$this->lsbo_ids)."') ";
109 if ( count($this->lsbo_lead_sources) > 0 )
110 $query .= "AND opportunities.lead_source IN ('".implode("','",$this->lsbo_lead_sources)."') ";
112 $query .= "AND opportunities.lead_source IN ('".implode("','",array_keys($GLOBALS['app_list_strings']['lead_source_dom']))."') ";
113 $query .= " GROUP BY sales_stage,lead_source ORDER BY lead_source,sales_stage";