public function getCreateViewUrl() { $createViewUrl = parent::getCreateViewUrl(); $currentUserModel = Users_Record_Model::getCurrentUserModel(); $parentRecordModel = $this->getParentRecordModel(); $currencyValue = $parentRecordModel->get('hdnGrandTotal'); $parentRecordModelCurrencyId = $parentRecordModel->get('currency_id'); if ($parentRecordModelCurrencyId == $currentUserModel->get('currency_id')) { $amount = CurrencyField::convertToUserFormat($currencyValue, null, true); } else { $baseCurrencyId = CurrencyField::getDBCurrencyId(); $allCurrencies = getAllCurrencies(); foreach ($allCurrencies as $currencyInfo) { if ($parentRecordModelCurrencyId == $currencyInfo['currency_id']) { $currencyValue = CurrencyField::convertToDollar($currencyValue, $currencyInfo['conversionrate']); } } foreach ($allCurrencies as $currencyInfo) { if ($baseCurrencyId == $currencyInfo['currency_id']) { $currencyValue = CurrencyField::convertFromMasterCurrency($currencyValue, $currencyInfo['conversionrate']); } } $amount = CurrencyField::convertToUserFormat($currencyValue); } return $createViewUrl . '&relatedcontact=' . $parentRecordModel->get('contact_id') . '&relatedorganization=' . $parentRecordModel->get('account_id') . '&amount=' . $amount; }
/** Function used to get all the price details for different currencies which are associated to the given product * @param int $productid - product id to which we want to get all the associated prices * @param decimal $unit_price - Unit price of the product * @param string $available - available or available_associated where as default is available, if available then the prices in the currencies which are available now will be returned, otherwise if the value is available_associated then prices of all the associated currencies will be retruned * @return array $price_details - price details as a array with productid, curid, curname */ function getPriceDetailsForProduct($productid, $unit_price, $available = 'available', $itemtype = 'Products') { $adb = PearDatabase::getInstance(); $log = vglobal('log'); $log->debug("Entering into function getPriceDetailsForProduct({$productid})"); if ($productid != '') { $product_currency_id = getProductBaseCurrency($productid, $itemtype); $product_base_conv_rate = getBaseConversionRateForProduct($productid, 'edit', $itemtype); // Detail View if ($available == 'available_associated') { $query = "select vtiger_currency_info.*, vtiger_productcurrencyrel.converted_price, vtiger_productcurrencyrel.actual_price\n\t\t\t\t\tfrom vtiger_currency_info\n\t\t\t\t\tinner join vtiger_productcurrencyrel on vtiger_currency_info.id = vtiger_productcurrencyrel.currencyid\n\t\t\t\t\twhere vtiger_currency_info.currency_status = 'Active' and vtiger_currency_info.deleted=0\n\t\t\t\t\tand vtiger_productcurrencyrel.productid = ? and vtiger_currency_info.id != ?"; $params = array($productid, $product_currency_id); } else { // Edit View $query = "select vtiger_currency_info.*, vtiger_productcurrencyrel.converted_price, vtiger_productcurrencyrel.actual_price\n\t\t\t\t\tfrom vtiger_currency_info\n\t\t\t\t\tleft join vtiger_productcurrencyrel\n\t\t\t\t\ton vtiger_currency_info.id = vtiger_productcurrencyrel.currencyid and vtiger_productcurrencyrel.productid = ?\n\t\t\t\t\twhere vtiger_currency_info.currency_status = 'Active' and vtiger_currency_info.deleted=0"; $params = array($productid); } //Postgres 8 fixes if ($adb->isPostgres()) { $query = fixPostgresQuery($query, $log, 0); } $res = $adb->pquery($query, $params); for ($i = 0; $i < $adb->num_rows($res); $i++) { $price_details[$i]['productid'] = $productid; $price_details[$i]['currencylabel'] = $adb->query_result($res, $i, 'currency_name'); $price_details[$i]['currencycode'] = $adb->query_result($res, $i, 'currency_code'); $price_details[$i]['currencysymbol'] = $adb->query_result($res, $i, 'currency_symbol'); $currency_id = $adb->query_result($res, $i, 'id'); $price_details[$i]['curid'] = $currency_id; $price_details[$i]['curname'] = 'curname' . $adb->query_result($res, $i, 'id'); $cur_value = $adb->query_result($res, $i, 'actual_price'); // Get the conversion rate for the given currency, get the conversion rate of the product currency to base currency. // Both together will be the actual conversion rate for the given currency. $conversion_rate = $adb->query_result($res, $i, 'conversion_rate'); $actual_conversion_rate = $product_base_conv_rate * $conversion_rate; $is_basecurrency = false; if ($currency_id == $product_currency_id) { $is_basecurrency = true; } if ($cur_value == null || $cur_value == '') { $price_details[$i]['check_value'] = false; if ($unit_price != null) { $cur_value = CurrencyField::convertFromMasterCurrency($unit_price, $actual_conversion_rate); } else { $cur_value = '0'; } } else { if ($is_basecurrency) { $price_details[$i]['check_value'] = true; } } $price_details[$i]['curvalue'] = CurrencyField::convertToUserFormat($cur_value, null, true); $price_details[$i]['conversionrate'] = $actual_conversion_rate; $price_details[$i]['is_basecurrency'] = $is_basecurrency; } } else { if ($available == 'available') { // Create View $current_user = vglobal('current_user'); $user_currency_id = fetchCurrency($current_user->id); $query = "select vtiger_currency_info.* from vtiger_currency_info\n\t\t\t\t\twhere vtiger_currency_info.currency_status = 'Active' and vtiger_currency_info.deleted=0"; $params = array(); $res = $adb->pquery($query, $params); for ($i = 0; $i < $adb->num_rows($res); $i++) { $price_details[$i]['currencylabel'] = $adb->query_result($res, $i, 'currency_name'); $price_details[$i]['currencycode'] = $adb->query_result($res, $i, 'currency_code'); $price_details[$i]['currencysymbol'] = $adb->query_result($res, $i, 'currency_symbol'); $currency_id = $adb->query_result($res, $i, 'id'); $price_details[$i]['curid'] = $currency_id; $price_details[$i]['curname'] = 'curname' . $adb->query_result($res, $i, 'id'); // Get the conversion rate for the given currency, get the conversion rate of the product currency(logged in user's currency) to base currency. // Both together will be the actual conversion rate for the given currency. $conversion_rate = $adb->query_result($res, $i, 'conversion_rate'); $user_cursym_convrate = getCurrencySymbolandCRate($user_currency_id); $product_base_conv_rate = 1 / $user_cursym_convrate['rate']; $actual_conversion_rate = $product_base_conv_rate * $conversion_rate; $price_details[$i]['check_value'] = false; $price_details[$i]['curvalue'] = '0'; $price_details[$i]['conversionrate'] = $actual_conversion_rate; $is_basecurrency = false; if ($currency_id == $user_currency_id) { $is_basecurrency = true; } $price_details[$i]['is_basecurrency'] = $is_basecurrency; } } else { $log->debug("Product id is empty. we cannot retrieve the associated prices."); } } $log->debug("Exit from function getPriceDetailsForProduct({$productid})"); return $price_details; }
/** * Creates pie chart image of opportunities by lead_source. * param $datax- the sales stage data to display in the x-axis * param $datay- the sum of opportunity amounts for each opportunity in each sales stage * to display in the y-axis * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.. * All Rights Reserved.. * Contributor(s): ______________________________________.. */ function pipeline_by_lead_source($legends = array('foo', 'bar'), $user_id = array('1'), $cache_file_name = 'a_file', $refresh = true, $width = 900, $height = 500) { global $log, $current_user; $log->debug("Entering pipeline_by_lead_source(" . $legends . ") method ..."); global $app_strings, $lang_crm, $current_module_strings, $log, $charset, $tmp_dir; global $theme; include_once 'Image/Graph.php'; include_once 'Image/Canvas.php'; $font = calculate_font_name($lang_crm); if (!file_exists($cache_file_name) || !file_exists($cache_file_name . '.map') || $refresh == true) { $log =& LoggerManager::getLogger('opportunity charts'); $log->debug("starting pipeline chart"); $log->debug("legends is:"); $log->debug($legends); $log->debug("user_id is: "); $log->debug($user_id); $log->debug("cache_file_name is: {$cache_file_name}"); //Now do the db queries //query for opportunity data that matches $legends and $user $where = ""; //build the where clause for the query that matches $datax $count = count($legends); if ($count > 0) { $where .= " leadsource in ( "; $ls_i = 0; foreach ($legends as $key => $value) { if ($ls_i != 0) { $where .= ", "; } $where .= "'" . addslashes($key) . "'"; $ls_i++; } $where .= ")"; } $opp = new Potentials(); $opp_list = $opp->get_full_list("vtiger_potential.amount DESC, vtiger_potential.closingdate DESC", $where); //build pipeline by lead source data $total = 0; $count = array(); $sum = array(); if (isset($opp_list)) { foreach ($opp_list as $record) { if (!isset($sum[$record->column_fields['leadsource']])) { $sum[$record->column_fields['leadsource']] = 0; } if (isset($record->column_fields['amount']) && isset($record->column_fields['leadsource'])) { // Strip all non numbers from this string. $amount = CurrencyField::convertFromMasterCurrency(preg_replace('/[^0-9]/', '', floor($record->column_fields['amount'])), $current_user->conv_rate); $sum[$record->column_fields['leadsource']] = $sum[$record->column_fields['leadsource']] + $amount / 1000; if (isset($count[$record->column_fields['leadsource']])) { $count[$record->column_fields['leadsource']]++; } else { $count[$record->column_fields['leadsource']] = 1; } $total = $total + $amount / 1000; } } } $visible_legends = array(); $data = array(); $aTargets = array(); $aAlts = array(); foreach ($legends as $lead_source_key => $lead_source_translation) { if (isset($sum[$lead_source_key])) { array_push($data, $sum[$lead_source_key]); if ($lead_source_key != '') { array_push($visible_legends, $lead_source_translation); } else { // put none in if the vtiger_field is blank. array_push($visible_legends, $current_module_strings['NTC_NO_LEGENDS']); } $cvid = getCvIdOfAll("Potentials"); array_push($aTargets, "index.php?module=Potentials&action=ListView&leadsource=" . urlencode($lead_source_key) . "&query=true&type=dbrd&viewname=" . $cvid); array_push($aAlts, $count[$lead_source_key] . " " . $current_module_strings['LBL_OPPS_IN_LEAD_SOURCE'] . " {$lead_source_translation}\t"); } } $log->debug("sum is:"); $log->debug($sum); $log->debug("count is:"); $log->debug($count); $log->debug("total is: {$total}"); if ($total == 0) { $log->debug("Exiting pipeline_by_lead_source method ..."); return $current_module_strings['ERR_NO_OPPS']; } if ($theme == "blue") { $font_color = "#212473"; } else { $font_color = "#000000"; } $canvas =& Image_Canvas::factory('png', array('width' => $width, 'height' => $height, 'usemap' => true)); $imagemap = $canvas->getImageMap(); $graph =& Image_Graph::factory('graph', $canvas); $font =& $graph->addNew('font', calculate_font_name($lang_crm)); // set the font size to 11 pixels $font->setSize(8); $font->setColor($font_color); $graph->setFont($font); // create the plotarea layout $title =& Image_Graph::factory('title', array('Test', 10)); $plotarea =& Image_Graph::factory('plotarea', array('category', 'axis')); $footer =& Image_Graph::factory('title', array('Footer', 8)); $graph->add(Image_Graph::vertical($title, Image_Graph::vertical($plotarea, $footer, 90), 5)); // Generate colours $colors = color_generator(count($visible_legends), '#33CCFF', '#3322FF'); $index = 0; $dataset =& Image_Graph::factory('dataset'); $fills =& Image_Graph::factory('Image_Graph_Fill_Array'); foreach ($visible_legends as $legend) { $dataset->addPoint($legend, $data[$index], array('url' => $aTargets[$index], 'alt' => $aAlts[$index])); $fills->addColor($colors[$index]); $log->debug('point =' . $legend . ',' . $data[$index]); $index++; } // create the pie chart and associate the filling colours $gbplot =& $plotarea->addNew('pie', $dataset); $plotarea->hideAxis(); $gbplot->setFillStyle($fills); // Setup title $titlestr = $current_module_strings['LBL_TOTAL_PIPELINE'] . $current_user->currency_symbol . $total . $app_strings['LBL_THOUSANDS_SYMBOL']; //$titlestr = $current_module_strings['LBL_TOTAL_PIPELINE'].$current_user->currency_symbol.$total; $title->setText($titlestr); // format the data values $valueproc =& Image_Graph::factory('Image_Graph_DataPreprocessor_Formatted', $current_user->currency_symbol . "%d"); // set markers $marker =& $graph->addNew('value_marker', IMAGE_GRAPH_VALUE_Y); $marker->setDataPreprocessor($valueproc); $marker->setFillColor('#FFFFFF'); $marker->setBorderColor($font_color); $marker->setFontColor($font_color); $marker->setFontSize(8); $pointingMarker =& $graph->addNew('Image_Graph_Marker_Pointing_Angular', array(20, &$marker)); $gbplot->setMarker($pointingMarker); // set legend $legend_box =& $plotarea->addNew('legend'); $legend_box->setPadding(array('top' => 20, 'bottom' => 0, 'left' => 0, 'right' => 0)); $legend_box->setFillColor('#F5F5F5'); $legend_box->showShadow(); $subtitle = $current_module_strings['LBL_OPP_SIZE'] . $current_user->currency_symbol . $current_module_strings['LBL_OPP_SIZE_VALUE']; $footer->setText($subtitle); $footer->setAlignment(IMAGE_GRAPH_ALIGN_TOP_LEFT); $imgMap = $graph->done(array('tohtml' => true, 'border' => 0, 'filename' => $cache_file_name, 'filepath' => './', 'urlpath' => '')); //$imgMap = htmlspecialchars($output); save_image_map($cache_file_name . '.map', $imgMap); } else { $imgMap_fp = fopen($cache_file_name . '.map', "rb"); $imgMap = fread($imgMap_fp, filesize($cache_file_name . '.map')); fclose($imgMap_fp); } $fileModTime = filemtime($cache_file_name . '.map'); $return = "\n{$imgMap}"; $log->debug("Exiting pipeline_by_lead_source method ..."); return $return; }