2 if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
3 /*********************************************************************************
4 * SugarCRM is a customer relationship management program developed by
5 * SugarCRM, Inc. Copyright (C) 2004-2011 SugarCRM Inc.
7 * This program is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU Affero General Public License version 3 as published by the
9 * Free Software Foundation with the addition of the following permission added
10 * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
11 * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
12 * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
14 * This program is distributed in the hope that it will be useful, but WITHOUT
15 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16 * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
19 * You should have received a copy of the GNU Affero General Public License along with
20 * this program; if not, see http://www.gnu.org/licenses or write to the Free
21 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
24 * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
25 * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
27 * The interactive user interfaces in modified source and object code versions
28 * of this program must display Appropriate Legal Notices, as required under
29 * Section 5 of the GNU Affero General Public License version 3.
31 * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
32 * these Appropriate Legal Notices must retain the display of the "Powered by
33 * SugarCRM" logo. If the display of the logo is not reasonably feasible for
34 * technical reasons, the Appropriate Legal Notices must display the words
35 * "Powered by SugarCRM".
36 ********************************************************************************/
40 require_once('include/generic/SugarWidgets/SugarWidget.php');
45 $global_currency_obj = null;
47 function get_currency()
49 global $current_user,$global_currency_obj;
50 if (empty($global_currency_obj))
52 $global_currency_obj = new Currency();
53 // $global_currency_symbol = '$';
55 if($current_user->getPreference('currency') )
57 $global_currency_obj->retrieve($current_user->getPreference('currency'));
61 $global_currency_obj->retrieve('-99');
64 return $global_currency_obj;
68 class SugarWidgetFieldCurrency extends SugarWidgetFieldInt
70 function & displayList($layout_def)
74 // If it's not grouped, or if it's grouped around a system currency column, look up the currency symbol so we can display it next to the amount
75 if ( empty($layout_def['group_function']) || $this->isSystemCurrency($layout_def) ) {
76 if ( isset($layout_def['varname']) ) {
77 $key = $layout_def['varname'];
79 $key = $this->_get_column_alias($layout_def);
81 $key = strtoupper($key);
83 if ( $this->isSystemCurrency($layout_def) ) {
86 $currency_id = $layout_def['fields'][$key.'_CURRENCY'];
88 if ( empty($currency_id) ) {
92 if ( !isset($currencies[$currency_id]) ) {
93 $currencies[$currency_id] = new Currency();
94 $currencies[$currency_id]->retrieve($currency_id);
96 if(!empty($currencies[$currency_id]->symbol)){
97 $symbol = $currencies[$currency_id]->symbol.' ';
104 // $global_currency_obj = get_currency();
105 // $display = format_number($this->displayListPlain($layout_def), 2, 2, array('convert' => true, 'currency_symbol' => true));
106 // $display = $global_currency_obj->symbol. round($global_currency_obj->convertFromDollar($this->displayListPlain($layout_def)),2);
107 $display = $symbol.$this->displayListPlain($layout_def);
111 function displayListPlain($layout_def) {
112 // $value = $this->_get_list_value($layout_def);
113 $value = format_number(parent::displayListPlain($layout_def), 2, 2, array('convert' => false, 'currency_symbol' => false));
116 function queryFilterEquals(&$layout_def)
118 return $this->_get_column_select($layout_def)."=".$GLOBALS['db']->quote(unformat_number($layout_def['input_name0']))."\n";
121 function queryFilterNot_Equals(&$layout_def)
123 return $this->_get_column_select($layout_def)."!=".$GLOBALS['db']->quote(unformat_number($layout_def['input_name0']))."\n";
126 function queryFilterGreater(&$layout_def)
128 return $this->_get_column_select($layout_def)." > ".$GLOBALS['db']->quote(unformat_number($layout_def['input_name0']))."\n";
131 function queryFilterLess(&$layout_def)
133 return $this->_get_column_select($layout_def)." < ".$GLOBALS['db']->quote(unformat_number($layout_def['input_name0']))."\n";
136 function queryFilterBetween(&$layout_def){
137 return $this->_get_column_select($layout_def)." > ".$GLOBALS['db']->quote(unformat_number($layout_def['input_name0'])). " AND ". $this->_get_column_select($layout_def)." < ".$GLOBALS['db']->quote(unformat_number($layout_def['input_name1']))."\n";
140 function isSystemCurrency(&$layout_def)
142 if (strpos($layout_def['name'],'_usdoll') === false) {
149 function querySelect(&$layout_def)
151 // We need to fetch the currency id as well
152 if ( !$this->isSystemCurrency($layout_def) && empty($layout_def['group_function'])) {
153 if ( !empty($layout_def['table_alias']) ) {
154 $table = $layout_def['table_alias'];
159 $add_currency_id = false;
161 $cols = $GLOBALS['db']->getHelper()->get_columns($table);
162 $add_currency_id = isset($cols['currency_id']) ? true : false;
164 if(!$add_currency_id && preg_match('/.*?_cstm$/i', $table)) {
165 $table = str_replace('_cstm', '', $table);
166 $cols = $GLOBALS['db']->getHelper()->get_columns($table);
167 $add_currency_id = isset($cols['currency_id']) ? true : false;
171 if($add_currency_id) {
172 return $this->_get_column_select($layout_def)." ".$this->_get_column_alias($layout_def)." , ".$table.".currency_id ". $this->getTruncatedColumnAlias($this->_get_column_alias($layout_def)."_currency") . "\n";
174 return $this->_get_column_select($layout_def)." ".$this->_get_column_alias($layout_def)."\n";
177 return $this->_get_column_select($layout_def)." ".$this->_get_column_alias($layout_def)."\n";