protected function generateChartJson() { global $app_list_strings, $app_strings; $arrData = array(); $arrProbabilities = array(); $forecast_strings = $this->getModuleLanguage('Forecasts'); $config = $this->getForecastConfig(); $acl = new SugarACLForecastWorksheets(); $bestAccess = $acl->checkAccess('ForecastWorksheets', 'field', array('field' => 'best_case', 'action' => 'view')); $worstAccess = $acl->checkAccess('ForecastWorksheets', 'field', array('field' => 'worst_case', 'action' => 'view')); if (!empty($this->dataArray)) { foreach ($this->dataArray as $data) { // If users have made likely/best/worst not required, // set the value to 0 for upcoming currency math if (empty($data['likely_case'])) { $data['likely_case'] = 0; } $v = array('id' => $data['id'], 'record_id' => $data['parent_id'], 'forecast' => $data['commit_stage'], 'probability' => $data['probability'], 'sales_stage' => $data['sales_stage'], 'likely' => SugarCurrency::convertWithRate($data['likely_case'], $data['base_rate']), 'date_closed_timestamp' => intval($data['date_closed_timestamp'])); if ($config['show_worksheet_best'] && $bestAccess) { if (empty($data['best_case'])) { $data['best_case'] = 0; } $v['best'] = SugarCurrency::convertWithRate($data['best_case'], $data['base_rate']); } if ($config['show_worksheet_worst'] && $worstAccess) { if (empty($data['worst_case'])) { $data['worst_case'] = 0; } $v['worst'] = SugarCurrency::convertWithRate($data['worst_case'], $data['base_rate']); } $arrData[] = $v; $arrProbabilities[$data['probability']] = $data['probability']; } asort($arrProbabilities); } $tp = $this->getTimeperiod(); $chart_info = array('title' => string_format($forecast_strings['LBL_CHART_FORECAST_FOR'], array($tp->name)), 'quota' => $this->getUserQuota(), 'x-axis' => $tp->getChartLabels(array()), 'labels' => array('forecast' => $app_list_strings[$config['buckets_dom']], 'sales_stage' => $app_list_strings['sales_stage_dom'], 'probability' => $arrProbabilities, 'dataset' => array('likely' => $app_strings['LBL_LIKELY'], 'best' => $app_strings['LBL_BEST'], 'worst' => $app_strings['LBL_WORST'])), 'data' => $arrData); return $chart_info; }
/** * Get the Numbers for the Individual (Sales Rep) View, this number comes from the quota right now * * @return array */ protected function getIndividualProgress() { //get the quota data for user /* @var $quota Quota */ $quota = BeanFactory::getBean('Quotas'); $quotaData = $quota->getRollupQuota($this->getArg('timeperiod_id'), $this->getArg('user_id')); $progressData = array("quota_amount" => isset($quotaData["amount"]) ? $quotaData["amount"] : 0); // get what we are forecasting on /* @var $admin Administration */ $admin = BeanFactory::getBean('Administration'); $settings = $admin->getConfigForModule('Forecasts'); $forecast_by = $settings['forecast_by']; $user_id = $this->getArg('user_id'); $timeperiod_id = $this->getArg('timeperiod_id'); /* @var $worksheet ForecastWorksheet */ $worksheet = BeanFactory::getBean('ForecastWorksheets'); $totals = $worksheet->worksheetTotals($timeperiod_id, $user_id, $forecast_by); $acl = new SugarACLForecastWorksheets(); $bestAccess = $acl->checkAccess('ForecastWorksheets', 'field', array('field' => 'best_case', 'action' => 'read')); $worstAccess = $acl->checkAccess('ForecastWorksheets', 'field', array('field' => 'worst_case', 'action' => 'read')); // if the user doesn't have access to best field, remove the value from totals if (!$bestAccess) { unset($totals['best_case']); } // if the user doesn't have access to worst field, remove the value from totals if (!$worstAccess) { unset($totals['worst_case']); } $totals['user_id'] = $user_id; $totals['timeperiod_id'] = $timeperiod_id; // unset some vars that come from the worksheet to avoid confusion with correct data // coming from this endpoint for progress unset($totals['pipeline_opp_count'], $totals['pipeline_amount']); // combine totals in with other progress data $progressData = array_merge($progressData, $totals); return $progressData; }