]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - modules/Charts/Dashlets/OpportunitiesByLeadSourceByOutcomeDashlet/OpportunitiesByLeadSourceByOutcomeDashlet.php
Release 6.5.0
[Github/sugarcrm.git] / modules / Charts / Dashlets / OpportunitiesByLeadSourceByOutcomeDashlet / OpportunitiesByLeadSourceByOutcomeDashlet.php
1 <?php
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.
6  * 
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.
13  * 
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
17  * details.
18  * 
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
22  * 02110-1301 USA.
23  * 
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.
26  * 
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.
30  * 
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  ********************************************************************************/
37
38
39
40
41 require_once('include/Dashlets/DashletGenericChart.php');
42
43 class OpportunitiesByLeadSourceByOutcomeDashlet extends DashletGenericChart 
44 {
45     public $lsbo_lead_sources = array();
46     public $lsbo_ids          = array();
47     
48     /**
49      * @see DashletGenericChart::$_seedName
50      */
51     protected $_seedName = 'Opportunities';
52     
53     /**
54      * @see DashletGenericChart::displayOptions()
55      */
56     public function displayOptions()
57     {
58         global $app_list_strings;
59         
60         $selected_datax = array();
61         if (!empty($this->lsbo_lead_sources) && sizeof($this->lsbo_lead_sources) > 0)
62             foreach ($this->lsbo_lead_sources as $key)
63                 $selected_datax[] = $key;
64         else
65             $selected_datax = array_keys($app_list_strings['lead_source_dom']);
66         
67         $this->_searchFields['lsbo_lead_sources']['options'] = array_filter($app_list_strings['lead_source_dom']);
68         $this->_searchFields['lsbo_lead_sources']['input_name0'] = $selected_datax;
69         
70         if (!isset($this->lsbo_ids) || count($this->lsbo_ids) == 0)
71                         $this->_searchFields['lsbo_ids']['input_name0'] = array_keys(get_user_array(false));
72         
73         return parent::displayOptions();
74     }
75
76     /**
77      * @see DashletGenericChart::display()
78      */
79     public function display() 
80     {
81         global $current_user, $sugar_config;
82         require("modules/Charts/chartdefs.php");
83         $chartDef = $chartDefs['lead_source_by_outcome'];
84                 
85         require_once('include/SugarCharts/SugarChartFactory.php');
86         $sugarChart = SugarChartFactory::getInstance();
87         $sugarChart->is_currency = true;   
88         $currency_symbol = $sugar_config['default_currency_symbol'];
89         if ($current_user->getPreference('currency')){
90             
91             $currency = new Currency();
92             $currency->retrieve($current_user->getPreference('currency'));
93             $currency_symbol = $currency->symbol;
94         }
95         $subtitle = translate('LBL_OPP_SIZE', 'Charts') . " " . $currency_symbol . "1" . translate('LBL_OPP_THOUSANDS', 'Charts');
96         $sugarChart->setProperties('', $subtitle, $chartDef['chartType']);
97         $sugarChart->base_url = $chartDef['base_url'];
98         $sugarChart->group_by = $chartDef['groupBy'];
99         $sugarChart->url_params = array();
100         if ( count($this->lsbo_ids) > 0 )
101             $sugarChart->url_params['assigned_user_id'] = array_values($this->lsbo_ids);                
102         $sugarChart->getData($this->constuctQuery());
103         $sugarChart->data_set = $sugarChart->sortData($sugarChart->data_set, 'lead_source', true, 'sales_stage', true, true);
104         $xmlFile = $sugarChart->getXMLFileName($this->id);
105         $sugarChart->saveXMLFile($xmlFile, $sugarChart->generateXML());
106         
107         return $this->getTitle('<div align="center"></div>') . 
108             '<div align="center">' . $sugarChart->display($this->id, $xmlFile, '100%', '480', false) . '</div>'. $this->processAutoRefresh();
109         }
110     
111     /**
112      * @see DashletGenericChart::constructQuery()
113      */
114     protected function constuctQuery()
115     {
116         $query = "SELECT lead_source,sales_stage,sum(amount_usdollar/1000) as total, ".
117                     "count(*) as opp_count FROM opportunities ";
118                 $query .= " WHERE opportunities.deleted=0 ";
119                 if ( count($this->lsbo_ids) > 0 )
120             $query .= "AND opportunities.assigned_user_id IN ('".implode("','",$this->lsbo_ids)."') ";
121         if ( count($this->lsbo_lead_sources) > 0 )
122             $query .= "AND opportunities.lead_source IN ('".implode("','",$this->lsbo_lead_sources)."') ";
123                 else
124             $query .= "AND opportunities.lead_source IN ('".implode("','",array_keys($GLOBALS['app_list_strings']['lead_source_dom']))."') ";
125         $query .= " GROUP BY sales_stage,lead_source ORDER BY lead_source,sales_stage";
126                 
127         return $query;
128         }
129 }