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

📄 chart_outcome_by_month.php

📁 SugarCRM5.1 开源PHP客户关系管理系统
💻 PHP
📖 第 1 页 / 共 2 页
字号:
			$GLOBALS['log']->debug("cache_file_name is: $cache_file_name");			$where = "";			//build the where clause for the query that matches $user			$count = count($user_id);			$id = array();			if ($count>0) {				foreach ($user_id as $the_id) {					$id[] = "'".$the_id."'";				}				$ids = join(",",$id);				$where .= "opportunities.assigned_user_id IN ($ids) ";			}			// cn: adding user-pref date handling			$dateStartDisplay = date($timedate->get_date_format(), strtotime($date_start));			$dateEndDisplay = date($timedate->get_date_format(), strtotime($date_end));			$opp = new Opportunity();			//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')." AND opportunities.deleted=0";			$query = "SELECT sales_stage,".db_convert('opportunities.date_closed','date_format',array("'%Y-%m'"),array("'YYYY-MM'"))." as m, sum(amount_usdollar/1000) as total, count(*) as opp_count FROM opportunities ";			$query .= "WHERE ".$where;			$query .= " GROUP BY sales_stage,".db_convert('opportunities.date_closed','date_format',array("'%Y-%m'"),array("'YYYY-MM'"))."ORDER BY m";			//Now do the db queries			//query for opportunity data that matches $datay and $user			//_pp($query);								$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'];			$other = $current_module_strings['LBL_LEAD_SOURCE_OTHER'];			$rowTotalArr = array();			$rowTotalArr[] = 0;			global $current_user;			$salesStages = array("Closed Lost"=>$app_list_strings['sales_stage_dom']["Closed Lost"],"Closed Won"=>$app_list_strings['sales_stage_dom']["Closed Won"],"Other"=>$other);			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;			}			$months = array();			$monthArr = array();			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($row['sales_stage'] == 'Closed Won' || $row['sales_stage'] == 'Closed Lost'){					$salesStage = $row['sales_stage'];					$salesStageT = $app_list_strings['sales_stage_dom'][$row['sales_stage']];				} else {					$salesStage = "Other";					$salesStageT = $other;				}				$months[$row['m']] = $row['m'];				if(!isset($monthArr[$row['m']]['row_total'])) {$monthArr[$row['m']]['row_total']=0;}				$monthArr[$row['m']][$salesStage]['opp_count'][] = $row['opp_count'];				$monthArr[$row['m']][$salesStage]['total'][] = $sum;				$monthArr[$row['m']]['outcome'][$salesStage]=$salesStageT;				$monthArr[$row['m']]['row_total'] += $sum;				$total += $sum;			}			$fileContents = '     <xData length="20">'."\n";			if (!empty($months)) {				foreach ($months as $month){					$rowTotalArr[]=$monthArr[$month]['row_total'];					if($monthArr[$month]['row_total']>100)					{						$monthArr[$month]['row_total']=round($monthArr[$month]['row_total']);					}					$fileContents .= '          <dataRow title="'.$month.'" endLabel="'.currency_format_number($monthArr[$month]['row_total'], array('currency_symbol' => true)).'">'."\n";					arsort($salesStages);					foreach ($salesStages as $outcome=>$outcome_translation){						if(isset($monthArr[$month][$outcome])) {						$fileContents .= '               <bar id="'.$outcome.'" totalSize="'.array_sum($monthArr[$month][$outcome]['total']).'" altText="'.$month.': '.format_number(array_sum($monthArr[$month][$outcome]['opp_count']), 0, 0).' '.$current_module_strings['LBL_OPPS_WORTH'].' '.currency_format_number(array_sum($monthArr[$month][$outcome]['total']),array('currency_symbol' => true)).$current_module_strings['LBL_OPP_THOUSANDS'].' '.$current_module_strings['LBL_OPPS_OUTCOME'].' '.$outcome_translation.'" url="index.php?module=Opportunities&action=index&date_closed='.$month.'&sales_stage='.urlencode($outcome).'&query=true&searchFormTab=advanced_search"/>'."\n";						}					}					$fileContents .= '          </dataRow>'."\n";				}			} else {				$fileContents .= '          <dataRow title="" endLabel="">'."\n";				$fileContents .= '               <bar id="" totalSize="0" altText="" url=""/>'."\n";				$fileContents .= '          </dataRow>'."\n";				$rowTotalArr[] = 1000;			}			$fileContents .= '     </xData>'."\n";			$max = get_max($rowTotalArr);			$fileContents .= '     <yData min="0" max="'.$max.'" length="10" prefix="'.$symbol.'" suffix="" kDelim="'.$kDelim.'" defaultAltText="'.$current_module_strings['LBL_ROLLOVER_DETAILS'].'"/>'."\n";			$fileContents .= '     <colorLegend status="on">'."\n";			$i=0;			asort($salesStages);			foreach ($salesStages as $outcome=>$outcome_translation) {				$color = generate_graphcolor($outcome,$i);				$fileContents .= '          <mapping id="'.$outcome.'" name="'.$outcome_translation.'" 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 = round($total, 2);			$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;			//echo $fileContents;			save_xml_file($cache_file_name, $fileContents);		}		$return = create_chart('vBarF',$cache_file_name);		return $return;	}		function constructQuery(){		global $current_user;		global $timedate;		$user_date_start = $current_user->getPreference('obm_date_start');		if (!empty($user_date_start)  && !isset($_REQUEST['obm_date_start'])) {			$date_start =$user_date_start;			$GLOBALS['log']->debug("USER PREFERENCES['obm_date_start'] is:");			$GLOBALS['log']->debug($user_date_start);		}		elseif (isset($_REQUEST['obm_year']) && $_REQUEST['obm_year'] != '') {			$date_start = $_REQUEST['obm_year'].'-01-01';			$current_user->setPreference('obm_date_start', $date_start);			$GLOBALS['log']->debug("_REQUEST['obm_date_start'] is:");			$GLOBALS['log']->debug($_REQUEST['obm_date_start']);			$GLOBALS['log']->debug("_SESSION['obm_date_start'] is:");			$GLOBALS['log']->debug($current_user->getPreference('obm_date_start'));		}		else {			$date_start = date('Y').'-01-01';		}		$user_date_end = $current_user->getPreference('obm_date_end');		if (!empty($user_date_end) && !isset($_REQUEST['obm_date_end'])) {			$date_end =$user_date_end;			$GLOBALS['log']->debug("USER PREFERENCES['obm_date_end'] is:");			$GLOBALS['log']->debug($date_end);		}		elseif (isset($_REQUEST['obm_year']) && $_REQUEST['obm_year'] != '') {			$date_end = $_REQUEST['obm_year'].'-12-31';			$current_user->setPreference('obm_date_end', $date_end );			$GLOBALS['log']->debug("_REQUEST['obm_date_end'] is:");			$GLOBALS['log']->debug($_REQUEST['obm_date_end']);			$GLOBALS['log']->debug("USER PREFERENCES['obm_date_end'] is:");			$GLOBALS['log']->debug($current_user->getPreference('obm_date_end'));		}		else {			$date_end = date('Y').'-12-31';		}						$ids = array();		//get list of user ids for which to display data		$user_ids = $current_user->getPreference('obm_ids');		if (!empty($user_ids) && count($user_ids) != 0 && !isset($_REQUEST['obm_ids'])) {			$ids = $user_ids;			$GLOBALS['log']->debug("USER PREFERENCES['obm_ids'] is:");			$GLOBALS['log']->debug($user_ids);		}		elseif (isset($_REQUEST['obm_ids']) && count($_REQUEST['obm_ids']) > 0) {			$ids = $_REQUEST['obm_ids'];			$current_user->setPreference('obm_ids', $_REQUEST['obm_ids']);			$GLOBALS['log']->debug("_REQUEST['obm_ids'] is:");			$GLOBALS['log']->debug($_REQUEST['obm_ids']);			$GLOBALS['log']->debug("USER PREFRENCES['obm_ids'] is:");			$GLOBALS['log']->debug($current_user->getPreference('obm_ids'));		}		else {			$ids = get_user_array(false);			$ids = array_keys($ids);		}				$user_id = $ids;				$where = "";		//build the where clause for the query that matches $user		$count = count($user_id);		$id = array();		if ($count>0) {			foreach ($user_id as $the_id) {				$id[] = "'".$the_id."'";			}			$ids = join(",",$id);			$where .= "opportunities.assigned_user_id IN ($ids) ";		}		// cn: adding user-pref date handling		$dateStartDisplay = date($timedate->get_date_format(), strtotime($date_start));		$dateEndDisplay = date($timedate->get_date_format(), strtotime($date_end));		$opp = new Opportunity();		//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')." AND opportunities.deleted=0";		$query = "SELECT sales_stage,".db_convert('opportunities.date_closed','date_format',array("'%Y-%m'"),array("'YYYY-MM'"))." as m, sum(amount_usdollar/1000) as total, count(*) as opp_count FROM opportunities ";		$query .= "WHERE ".$where;		$query .= " GROUP BY sales_stage,".db_convert('opportunities.date_closed','date_format',array("'%Y-%m'"),array("'YYYY-MM'"))."ORDER BY m";				return $query;	}		function constructGroupBy(){		return array( 'm', 'sales_stage', );	}	}?>

⌨️ 快捷键说明

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