public function display() { global $current_user, $sugar_config; require "modules/Charts/chartdefs.php"; $chartDef = $chartDefs['lead_source_by_outcome']; require_once 'include/SugarCharts/SugarChart.php'; $sugarChart = new SugarChart(); $sugarChart->is_currency = true; $currency_symbol = $sugar_config['default_currency_symbol']; if ($current_user->getPreference('currency')) { $currency = new Currency(); $currency->retrieve($current_user->getPreference('currency')); $currency_symbol = $currency->symbol; } $subtitle = translate('LBL_OPP_SIZE', 'Charts') . " " . $currency_symbol . "1" . translate('LBL_OPP_THOUSANDS', 'Charts'); $sugarChart->setProperties('', $subtitle, $chartDef['chartType']); $sugarChart->base_url = $chartDef['base_url']; $sugarChart->group_by = $chartDef['groupBy']; $sugarChart->url_params = array(); if (count($this->lsbo_ids) > 0) { $sugarChart->url_params['assigned_user_id'] = array_values($this->lsbo_ids); } $sugarChart->getData($this->constuctQuery()); $sugarChart->data_set = $sugarChart->sortData($sugarChart->data_set, 'lead_source', true, 'sales_stage', true, true); $xmlFile = $sugarChart->getXMLFileName($this->id); $sugarChart->saveXMLFile($xmlFile, $sugarChart->generateXML()); return $this->getTitle('<div align="center"></div>') . '<div align="center">' . $sugarChart->display($this->id, $xmlFile, '100%', '480', false) . '</div><br />'; }
/** * We check, that groups with NULL value remain their order in subgroups tag * and won't fall down under not null valued groups. * This way we guarantee that links will be put correctly to each user in * whole user list (will, max, etc.). * * @group 44696 * @group 53845 */ public function testCorrectXml() { $actual = $this->sugarChartObject->xmlDataGenericChart(); $expected = $this->compareXml(); $order = array("\r\n", "\n", "\r", "\t"); $replace = ""; // remove all break lines and spaces and tabs $expected = str_replace($order, $replace, $expected); $actual = str_replace($order, $replace, $actual); $this->assertEquals($expected, $actual); }
/** * @see DashletGenericChart::display() */ public function display() { $currency_symbol = $GLOBALS['sugar_config']['default_currency_symbol']; if ($GLOBALS['current_user']->getPreference('currency')) { $currency = new Currency(); $currency->retrieve($GLOBALS['current_user']->getPreference('currency')); $currency_symbol = $currency->symbol; } require "modules/Charts/chartdefs.php"; $chartDef = $chartDefs['outcome_by_month']; require_once 'include/SugarCharts/SugarChart.php'; $sugarChart = new SugarChart(); $sugarChart->setProperties('', translate('LBL_OPP_SIZE', 'Charts') . ' ' . $currency_symbol . '1' . translate('LBL_OPP_THOUSANDS', 'Charts'), $chartDef['chartType']); $sugarChart->base_url = $chartDef['base_url']; $sugarChart->group_by = $chartDef['groupBy']; $sugarChart->url_params = array(); $sugarChart->getData($this->constructQuery()); $sugarChart->is_currency = true; $sugarChart->data_set = $sugarChart->sortData($sugarChart->data_set, 'm', false, 'sales_stage', true, true); $xmlFile = $sugarChart->getXMLFileName($this->id); $sugarChart->saveXMLFile($xmlFile, $sugarChart->generateXML()); return $this->getTitle('<div align="center"></div>') . '<div align="center">' . $sugarChart->display($this->id, $xmlFile, '100%', '480', false) . '</div><br />'; }
function __construct() { parent::__construct(); }
/** * @see DashletGenericChart::display() */ public function display() { global $sugar_config, $current_user; require_once 'include/SugarCharts/SugarChart.php'; $sugarChart = new SugarChart(); $sugarChart->base_url = array('module' => 'Opportunities', 'action' => 'index', 'query' => 'true', 'searchFormTab' => 'advanced_search'); $sugarChart->url_params = array('assigned_user_id' => $current_user->id); $sugarChart->group_by = $this->constructGroupBy(); $currency_symbol = $sugar_config['default_currency_symbol']; if ($current_user->getPreference('currency')) { $currency = new Currency(); $currency->retrieve($current_user->getPreference('currency')); $currency_symbol = $currency->symbol; } $sugarChart->is_currency = true; $sugarChart->thousands_symbol = translate('LBL_OPP_THOUSANDS', 'Charts'); $subtitle = translate('LBL_OPP_SIZE', 'Charts') . " " . $currency_symbol . "1" . translate('LBL_OPP_THOUSANDS', 'Charts'); $query = $this->constructQuery(); $dataset = $this->constructCEChartData($this->getChartData($query)); $sugarChart->setData($dataset); $total = format_number($this->getHorizBarTotal($dataset), 0, 0, array('convert' => true)); $pipeline_total_string = translate('LBL_TOTAL_PIPELINE', 'Charts') . $sugarChart->currency_symbol . $total . $sugarChart->thousands_symbol; $sugarChart->setProperties($pipeline_total_string, $subtitle, 'horizontal bar chart'); $xmlFile = $sugarChart->getXMLFileName($this->id); $sugarChart->saveXMLFile($xmlFile, $sugarChart->generateXML()); return $this->getTitle('') . '<div align="center">' . $sugarChart->display($this->id, $xmlFile, '100%', '480', false) . '</div><br />'; }
function display() { global $app_list_strings, $current_language, $sugar_config, $currentModule, $action, $current_user, $theme, $timedate, $image_path; $this->loadLanguage('MyLeadsByStatusDashlet', 'custom/modules/Charts/Dashlets/'); $returnStr = ''; $user_dateFormat = $timedate->get_date_format(); $current_module_strings = return_module_language($current_language, 'Charts'); if (isset($_REQUEST['myleadschart_refresh'])) { $refresh = $_REQUEST['myleadschart_refresh']; } else { $refresh = false; } $date_start = $this->myleadschart_date_start; $date_end = $this->myleadschart_date_end; // cn: format date_start|end to user's preferred $dateStartDisplay = strftime($timedate->get_user_date_format(), strtotime($date_start)); $dateEndDisplay = strftime($timedate->get_user_date_format(), strtotime($date_end)); $seps = array("-", "/"); $dates = array($date_start, $date_end); $dateFileNameSafe = str_replace($seps, "_", $dates); //$dateXml[0] = $timedate->swap_formats($date_start, $user_dateFormat, $timedate->dbDayFormat); //$dateXml[1] = $timedate->swap_formats($date_end, $user_dateFormat, $timedate->dbDayFormat); $dateXml[0] = $date_start; $dateXml[1] = $date_end; $datax = array(); $selected_datax = array(); //get list of lead status keys to display $user_status = $this->myleadschart_status; $tempx = $user_status; //set $datax using selected lead status keys if (count($tempx) > 0) { foreach ($tempx as $key) { $datax[$key] = $app_list_strings['lead_status_dom'][$key]; array_push($selected_datax, $key); } } else { $datax = $app_list_strings['lead_status_dom']; $selected_datax = array_keys($app_list_strings['lead_status_dom']); } $GLOBALS['log']->debug("datax is:"); $GLOBALS['log']->debug($datax); $ids = array($current_user->id); //create unique prefix based on selected users for image files $id_hash = '1'; if (isset($ids)) { sort($ids); $id_hash = crc32(implode('', $ids)); if ($id_hash < 0) { $id_hash = $id_hash * -1; } } $GLOBALS['log']->debug("ids is:"); $GLOBALS['log']->debug($ids); $id_md5 = substr(md5($current_user->id), 0, 9); $seps = array("-", "/"); $dates = array($dateStartDisplay, $dateEndDisplay); $dateFileNameSafe = str_replace($seps, "_", $dates); $cache_file_name = $current_user->getUserPrivGuid() . "_" . $theme . "_my_status_" . $dateFileNameSafe[0] . "_" . $dateFileNameSafe[1] . ".xml"; $GLOBALS['log']->debug("cache file name is: {$cache_file_name}"); if (file_exists($sugar_config['tmp_dir'] . $cache_file_name)) { $file_date = date($timedate->get_date_format() . " " . $timedate->get_time_format(), filemtime($sugar_config['tmp_dir'] . $cache_file_name)); } else { $file_date = ''; } require_once 'include/Sugar_Smarty.php'; require_once 'include/SugarCharts/SugarChart.php'; $sugar_smarty = new Sugar_Smarty(); $charts = array(); $sugarChart = new SugarChart(); $sugarChart->base_url = array('module' => 'Leads', 'action' => 'index', 'query' => 'true', 'searchFormTab' => 'advanced_search'); $sugarChart->url_params = array('assigned_user_id' => $current_user->id); $sugarChart->group_by = $this->constructGroupBy(); $query = $this->constructQuery($datax, $dateXml[0], $dateXml[1], $ids, $sugar_config['tmp_dir'] . $cache_file_name, $refresh, 'hBarS', $current_module_strings); $total = format_number($sugarChart->getTotal(), 0, 0); $sugarChart->thousands_symbol = translate('LBL_OPP_THOUSANDS', 'Charts'); $subtitle = translate('LBL_LEAD_COUNT', 'Charts'); $dataset = $this->constructCEChartData($this->getChartData($query)); $sugarChart->setData($dataset); $total = format_number($this->getHorizBarTotal($dataset), 0, 0); $pipeline_total_string = translate('LBL_TOTAL_PIPELINE', 'Charts') . $total . $sugarChart->thousands_symbol; $sugarChart->setProperties($pipeline_total_string, $subtitle, 'horizontal bar chart'); $xmlFile = $sugar_config['tmp_dir'] . $current_user->id . '_' . $this->id . '.xml'; $sugarChart->saveXMLFile($xmlFile, $sugarChart->generateXML()); $returnStr .= $sugarChart->display($this->id, $xmlFile, '100%', '480', false); return $this->getTitle('') . '<div align="center">' . $returnStr . '</div><br />'; }
function campaign_response_roi($datay = array(), $targets = array(), $campaign_id, $cache_file_name = 'a_file', $refresh = false, $marketing_id = '', $is_dashlet = false, $dashlet_id = '') { global $app_strings, $mod_strings, $current_module_strings, $charset, $lang, $app_list_strings, $current_language, $sugar_config; $not_empty = false; if ($is_dashlet) { $mod_strings = return_module_language($current_language, 'Campaigns'); } if (!file_exists($cache_file_name) || $refresh == true) { $GLOBALS['log']->debug("datay is:"); $GLOBALS['log']->debug($datay); $GLOBALS['log']->debug("user_id is: "); $GLOBALS['log']->debug("cache_file_name is: {$cache_file_name}"); $focus = new Campaign(); $focus->retrieve($campaign_id); $opp_count = 0; $opp_query = "select count(*) opp_count,sum(" . db_convert("amount_usdollar", "IFNULL", array(0)) . ") total_value"; $opp_query .= " from opportunities"; $opp_query .= " where campaign_id='{$campaign_id}'"; $opp_query .= " and sales_stage='Prospecting'"; $opp_query .= " and deleted=0"; $opp_result = $focus->db->query($opp_query); $opp_data = $focus->db->fetchByAssoc($opp_result); // if (empty($opp_data['opp_count'])) $opp_data['opp_count']=0; if (empty($opp_data['total_value'])) { $opp_data['total_value'] = 0; } //report query $opp_query1 = "select SUM(opp.amount) as revenue"; $opp_query1 .= " from opportunities opp"; $opp_query1 .= " right join campaigns camp on camp.id = opp.campaign_id"; $opp_query1 .= " where opp.sales_stage = 'Closed Won'and camp.id='{$campaign_id}' and opp.deleted=0"; $opp_query1 .= " group by camp.name"; $opp_result1 = $focus->db->query($opp_query1); $opp_data1 = $focus->db->fetchByAssoc($opp_result1); //if (empty($opp_data1[])) if (empty($opp_data1['revenue'])) { $opp_data1[$mod_strings['LBL_ROI_CHART_REVENUE']] = 0; unset($opp_data1['revenue']); } else { $opp_data1[$mod_strings['LBL_ROI_CHART_REVENUE']] = $opp_data1['revenue']; unset($opp_data1['revenue']); $not_empty = true; } $camp_query1 = "select camp.name, SUM(camp.actual_cost) as investment,SUM(camp.budget) as budget,SUM(camp.expected_revenue) as expected_revenue"; $camp_query1 .= " from campaigns camp"; $camp_query1 .= " where camp.id='{$campaign_id}'"; $camp_query1 .= " group by camp.name"; $camp_result1 = $focus->db->query($camp_query1); $camp_data1 = $focus->db->fetchByAssoc($camp_result1); //query needs to be lowercase, but array keys need to be propercased, as these are used in //chart to display legend if (empty($camp_data1['investment'])) { $camp_data1['investment'] = 0; } else { $not_empty = true; } if (empty($camp_data1['budget'])) { $camp_data1['budget'] = 0; } else { $not_empty = true; } if (empty($camp_data1['expected_revenue'])) { $camp_data1['expected_revenue'] = 0; } else { $not_empty = true; } $opp_data1[$mod_strings['LBL_ROI_CHART_INVESTMENT']] = $camp_data1['investment']; $opp_data1[$mod_strings['LBL_ROI_CHART_BUDGET']] = $camp_data1['budget']; $opp_data1[$mod_strings['LBL_ROI_CHART_EXPECTED_REVENUE']] = $camp_data1['expected_revenue']; $query = "SELECT activity_type,target_type, count(*) hits "; $query .= " FROM campaign_log "; $query .= " WHERE campaign_id = '{$campaign_id}' AND archived=0 AND deleted=0"; //if $marketing id is specified, then lets filter the chart by the value if (!empty($marketing_id)) { $query .= " AND marketing_id ='{$marketing_id}'"; } $query .= " GROUP BY activity_type, target_type"; $query .= " ORDER BY activity_type, target_type"; $result = $focus->db->query($query); $leadSourceArr = array(); $total = 0; $total_targeted = 0; } global $current_user; $user_id = $current_user->id; require_once 'include/SugarCharts/SugarChart.php'; $width = $is_dashlet ? '100%' : '720px'; $return = '<script type="text/javascript" src="' . getJSPath('include/javascript/swfobject.js') . '"></script>'; if (!$is_dashlet) { $return .= '<br />'; } $currency_id = $focus->currency_id; $currency_symbol = $sugar_config['default_currency_symbol']; if (!empty($currency_id)) { $cur = new Currency(); $cur->retrieve($currency_id); $currency_symbol = $cur->symbol; } $sugarChart = new SugarChart(); $sugarChart->is_currency = true; $sugarChart->currency_symbol = $currency_symbol; if ($not_empty) { $sugarChart->setData($opp_data1); } else { $sugarChart->setData(array()); } $sugarChart->setProperties($mod_strings['LBL_CAMPAIGN_RETURN_ON_INVESTMENT'], $mod_strings['LBL_AMOUNT_IN'] . $currency_symbol, 'bar chart'); if (!$is_dashlet) { $xmlFile = $sugarChart->getXMLFileName('roi_details_chart'); $sugarChart->saveXMLFile($xmlFile, $sugarChart->generateXML()); $return .= $sugarChart->display('roi_details_chart', $xmlFile, $width, '480'); } else { $xmlFile = $sugarChart->getXMLFileName($dashlet_id); $sugarChart->saveXMLFile($xmlFile, $sugarChart->generateXML()); $return .= $sugarChart->display($dashlet_id, $xmlFile, $width, '480'); } return $return; }