⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 chart_my_pipeline_by_sales_stage.php

📁 SugarCRM5.1 开源PHP客户关系管理系统
💻 PHP
📖 第 1 页 / 共 2 页
字号:
			$GLOBALS['log']->debug("cache_file_name is: $cache_file_name");			$opp = new Opportunity;			$where="";			//build the where clause for the query that matches $user			$count = count($user_id);			$id = array();			$user_list = get_user_array(false);			foreach ($user_id as $key) {				$new_ids[$key] = $user_list[$key];			}			if ($count>0) {				foreach ($new_ids as $the_id=>$the_name) {					$id[] = "'".$the_id."'";				}				$ids = join(",",$id);				$where .= "opportunities.assigned_user_id IN ($ids) ";			}			//build the where clause for the query that matches $datax			$count = count($datax);			$dataxArr = array();			if ($count>0) {				foreach ($datax as $key=>$value) {					$dataxArr[] = "'".$key."'";				}				$dataxArr = join(",",$dataxArr);				$where .= "AND opportunities.sales_stage IN	($dataxArr) ";			}			//build the where clause for the query that matches $date_start and $date_end			$where .= "	AND opportunities.date_closed >= ". db_convert("'".$date_start."'",'date'). " 						AND opportunities.date_closed <= ".db_convert("'".$date_end."'",'date') ;			$where .= "	AND opportunities.assigned_user_id = users.id  AND opportunities.deleted=0 ";			//Now do the db queries			//query for opportunity data that matches $datax and $user			$query = "	SELECT opportunities.sales_stage,							users.user_name,							opportunities.assigned_user_id,							count( * ) AS opp_count,							sum(amount_usdollar/1000) AS total						FROM users,opportunities  ";			$query .= "WHERE " .$where;			$query .= " GROUP BY opportunities.sales_stage,users.user_name,opportunities.assigned_user_id";						$result = $opp->db->query($query)			or sugar_die("Error selecting sugarbean: ".mysql_error());			//build pipeline by sales stage data			$total = 0;			$div = 1;			global $sugar_config;			$symbol = $sugar_config['default_currency_symbol'];			global $current_user;			if($current_user->getPreference('currency') ){				require_once('modules/Currencies/Currency.php');				$currency = new Currency();				$currency->retrieve($current_user->getPreference('currency'));				$div = $currency->conversion_rate;				$symbol = $currency->symbol;			}			// cn: adding user-pref date handling			$dateStartDisplay = date($timedate->get_date_format(), strtotime($date_start));			$dateEndDisplay = date($timedate->get_date_format(), strtotime($date_end));						$fileContents = '     <yData defaultAltText="'.$current_module_strings['LBL_ROLLOVER_DETAILS'].'">'."\n";			$stageArr = array();			$usernameArr = array();			$rowTotalArr = array();			$rowTotalArr[] = 0;			while($row = $opp->db->fetchByAssoc($result, -1, false))			{				if($row['total']*$div<=100){					$sum = round($row['total']*$div, 2);				} else {					$sum = round($row['total']*$div);				}				if(!isset($stageArr[$row['sales_stage']]['row_total'])) {$stageArr[$row['sales_stage']]['row_total']=0;}				$stageArr[$row['sales_stage']][$row['assigned_user_id']]['opp_count'] = $row['opp_count'];				$stageArr[$row['sales_stage']][$row['assigned_user_id']]['total'] = $sum;				$stageArr[$row['sales_stage']]['people'][$row['assigned_user_id']] = $row['user_name'];				$stageArr[$row['sales_stage']]['row_total'] += $sum;				$usernameArr[$row['assigned_user_id']] = $row['user_name'];				$total += $sum;			}			foreach ($datax as $key=>$translation) {				if(isset($stageArr[$key]['row_total'])){$rowTotalArr[]=$stageArr[$key]['row_total'];}				if(isset($stageArr[$key]['row_total']) && $stageArr[$key]['row_total']>100) {					$stageArr[$key]['row_total'] = round($stageArr[$key]['row_total']);				}				$fileContents .= '     <dataRow title="'.$translation.'" endLabel="';				if(isset($stageArr[$key]['row_total'])){$fileContents .= $stageArr[$key]['row_total'];}				$fileContents .= '">'."\n";				if(isset($stageArr[$key]['people'])){					asort($stageArr[$key]['people']);					reset($stageArr[$key]['people']);					foreach ($stageArr[$key]['people'] as $nameKey=>$nameValue) {						$fileContents .= '          <bar id="'.$nameKey.'" totalSize="'.$stageArr[$key][$nameKey]['total'].'" altText="'.$nameValue.': '.$stageArr[$key][$nameKey]['opp_count'].' '.$current_module_strings['LBL_OPPS_WORTH'].' '.currency_format_number($stageArr[$key][$nameKey]['total'], array('currency_symbol'=>true)).$current_module_strings['LBL_OPP_THOUSANDS'].' '.$current_module_strings['LBL_OPPS_IN_STAGE'].' '.$translation.'" url="index.php?module=Opportunities&action=index&assigned_user_id[]='.$nameKey.'&sales_stage='.urlencode($key).'&date_start='.$date_start.'&date_closed='.$date_end.'&query=true&searchFormTab=advanced_search"/>'."\n";					}				}				$fileContents .= '     </dataRow>'."\n";			}			$fileContents .= '     </yData>'."\n";			$max = get_max($rowTotalArr);			if($chart_size=='hBarF'){				$length = "10";			}else{				$length = "4";			}			$fileContents .= '     <xData min="0" max="'.$max.'" length="'.$length.'" kDelim="'.$kDelim.'" prefix="'.$symbol.'" suffix=""/>'."\n";			$fileContents .= '     <colorLegend status="on">'."\n";			$i=0;			asort($new_ids);			foreach ($new_ids as $key=>$value) {			$color = generate_graphcolor($key,$i);			$fileContents .= '          <mapping id="'.$key.'" name="'.$value.'" color="'.$color.'"/>'."\n";			$i++;			}			$fileContents .= '     </colorLegend>'."\n";			$fileContents .= '     <graphInfo>'."\n";			$fileContents .= '          <![CDATA['.$current_module_strings['LBL_DATE_RANGE'].' '.$dateStartDisplay.' '.$current_module_strings['LBL_DATE_RANGE_TO'].' '.$dateEndDisplay.'<BR/>'.$current_module_strings['LBL_OPP_SIZE'].' '.$symbol.'1'.$current_module_strings['LBL_OPP_THOUSANDS'].']]>'."\n";			$fileContents .= '     </graphInfo>'."\n";			$fileContents .= '     <chartColors ';			foreach ($barChartColors as $key => $value) {				$fileContents .= ' '.$key.'='.'"'.$value.'" ';			}			$fileContents .= ' />'."\n";			$fileContents .= '</graphData>'."\n";			$total = $total;			$title = '<graphData title="'.$current_module_strings['LBL_TOTAL_PIPELINE'].currency_format_number($total, array('currency_symbol' => true)).$app_strings['LBL_THOUSANDS_SYMBOL'].'">'."\n";			$fileContents = $title.$fileContents;			save_xml_file($cache_file_name, $fileContents);		}		if($chart_size=='hBarF'){			$width = "800";			$height = "400";		} else {			$width = "350";			$height = "400";		}		$return = create_chart($chart_size,$cache_file_name,$width,$height);		return $return;	}		function constructQuery(){		global $current_user;		global $time_date;				//get the dates to display		$user_date_start = $current_user->getPreference('mypbss_date_start');				if (!empty($user_date_start) && !isset($_REQUEST['mypbss_date_start'])) {			$date_start = $user_date_start;			$GLOBALS['log']->debug("USER PREFERENCES['mypbss_date_start'] is:");			$GLOBALS['log']->debug($user_date_start);		}		elseif (isset($_REQUEST['mypbss_date_start']) && $_REQUEST['mypbss_date_start'] != '') {			$date_start = $_REQUEST['mypbss_date_start'];			$current_user->setPreference('mypbss_date_start', $_REQUEST['mypbss_date_start']);			$GLOBALS['log']->debug("_REQUEST['mypbss_date_start'] is:");			$GLOBALS['log']->debug($_REQUEST['mypbss_date_start']);			$GLOBALS['log']->debug("USER PREFERENCES['mypbss_date_start'] is:");			$GLOBALS['log']->debug($current_user->getPreference('mypbss_date_start'));		}		else {			$date_start = date($timedate->get_date_format(), time());		}		$user_date_end = $current_user->getPreference('mypbss_date_end');				if (!empty($user_date_end) && !isset($_REQUEST['mypbss_date_end'])) {			$date_end = $user_date_end;			$GLOBALS['log']->debug("USER PREFERENCES['mypbss_date_end'] is:");			$GLOBALS['log']->debug($user_date_end);		}		elseif (isset($_REQUEST['mypbss_date_end']) && $_REQUEST['mypbss_date_end'] != '') {			$date_end = $_REQUEST['mypbss_date_end'];			$current_user->setPreference('mypbss_date_end', $_REQUEST['mypbss_date_end']);			$GLOBALS['log']->debug("_REQUEST['mypbss_date_end'] is:");			$GLOBALS['log']->debug($_REQUEST['mypbss_date_end']);			$GLOBALS['log']->debug("USER PREFERENCES['mypbss_date_end'] is:");			$GLOBALS['log']->debug( $current_user->getPreference('mypbss_date_end'));		}		else {			$date_end = date($timedate->get_date_format(), strtotime('2010-01-01'));			$GLOBALS['log']->debug("USER PREFERENCES['mypbss_date_end'] not found. Using: ".$date_end);		}				$user_id = array($current_user->id);						$opp = new Opportunity;		$where="";		//build the where clause for the query that matches $user		$count = count($user_id);		$id = array();		$user_list = get_user_array(false);		foreach ($user_id as $key) {			$new_ids[$key] = $user_list[$key];		}		if ($count>0) {			foreach ($new_ids as $the_id=>$the_name) {				$id[] = "'".$the_id."'";			}			$ids = join(",",$id);			$where .= "opportunities.assigned_user_id IN ($ids) ";		}		//build the where clause for the query that matches $datax		$count = count($datax);		$dataxArr = array();		if ($count>0) {			foreach ($datax as $key=>$value) {				$dataxArr[] = "'".$key."'";			}			$dataxArr = join(",",$dataxArr);			$where .= "AND opportunities.sales_stage IN	($dataxArr) ";		}		//build the where clause for the query that matches $date_start and $date_end		$where .= "	AND opportunities.date_closed >= ". db_convert("'".$date_start."'",'date'). " 					AND opportunities.date_closed <= ".db_convert("'".$date_end."'",'date') ;		$where .= "	AND opportunities.assigned_user_id = users.id  AND opportunities.deleted=0 ";		//Now do the db queries		//query for opportunity data that matches $datax and $user		$query = "	SELECT opportunities.sales_stage,						users.user_name,						opportunities.assigned_user_id,						count( * ) AS opp_count,						sum(amount_usdollar/1000) AS total					FROM users,opportunities  ";		$query .= "WHERE " .$where;		$query .= " GROUP BY opportunities.sales_stage,users.user_name,opportunities.assigned_user_id";		return $query;		}		function constructGroupBy(){		return array('sales_stage');	}?>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -