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 OutcomeByMonthDashlet extends DashletGenericChart
46 public $obm_ids = array();
47 public $obm_date_start;
51 * @see DashletGenericChart::$_seedName
53 protected $_seedName = 'Opportunities';
56 * @see DashletGenericChart::__construct()
58 public function __construct(
65 if(empty($options['obm_date_start']))
66 $options['obm_date_start'] = $timedate->nowDbDate();
68 if(empty($options['obm_date_end']))
69 $options['obm_date_end'] = $timedate->asDbDate($timedate->getNow()->modify("+6 months"));
71 parent::__construct($id,$options);
75 * @see DashletGenericChart::displayOptions()
77 public function displayOptions()
79 if (!isset($this->obm_ids) || count($this->obm_ids) == 0)
80 $this->_searchFields['obm_ids']['input_name0'] = array_keys(get_user_array(false));
82 return parent::displayOptions();
86 * @see DashletGenericChart::display()
88 public function display()
90 $currency_symbol = $GLOBALS['sugar_config']['default_currency_symbol'];
91 if ($GLOBALS['current_user']->getPreference('currency')){
93 $currency = new Currency();
94 $currency->retrieve($GLOBALS['current_user']->getPreference('currency'));
95 $currency_symbol = $currency->symbol;
98 require("modules/Charts/chartdefs.php");
99 $chartDef = $chartDefs['outcome_by_month'];
101 require_once('include/SugarCharts/SugarChartFactory.php');
102 $sugarChart = SugarChartFactory::getInstance();
103 $sugarChart->setProperties('',
104 translate('LBL_OPP_SIZE', 'Charts') . ' ' . $currency_symbol . '1' .translate('LBL_OPP_THOUSANDS', 'Charts'),
105 $chartDef['chartType']);
106 $sugarChart->base_url = $chartDef['base_url'];
107 $sugarChart->group_by = $chartDef['groupBy'];
108 $sugarChart->url_params = array();
109 $sugarChart->getData($this->constructQuery());
110 $sugarChart->is_currency = true;
111 $sugarChart->data_set = $sugarChart->sortData($sugarChart->data_set, 'm', false, 'sales_stage', true, true);
112 $xmlFile = $sugarChart->getXMLFileName($this->id);
113 $sugarChart->saveXMLFile($xmlFile, $sugarChart->generateXML());
115 return $this->getTitle('<div align="center"></div>') .
116 '<div align="center">' . $sugarChart->display($this->id, $xmlFile, '100%', '480', false) . '</div>'. $this->processAutoRefresh();
120 * @see DashletGenericChart::constructQuery()
122 protected function constructQuery()
124 $query = "SELECT sales_stage,".
125 db_convert('opportunities.date_closed','date_format',array("'%Y-%m'"),array("'YYYY-MM'"))." as m, ".
126 "sum(amount_usdollar/1000) as total, count(*) as opp_count FROM opportunities ";
127 $query .= " WHERE opportunities.date_closed >= ".db_convert("'".$this->obm_date_start."'",'date') .
128 " AND opportunities.date_closed <= ".db_convert("'".$this->obm_date_end."'",'date') .
129 " AND opportunities.deleted=0";
130 if (count($this->obm_ids) > 0)
131 $query .= " AND opportunities.assigned_user_id IN ('" . implode("','",$this->obm_ids) . "')";
132 $query .= " GROUP BY sales_stage,".
133 db_convert('opportunities.date_closed','date_format',array("'%Y-%m'"),array("'YYYY-MM'")) .