function getListViewSmarty($parentFieldArray, $vardef, $displayParams, $col)
 {
     global $current_user;
     $tabindex = 1;
     $this->setup($parentFieldArray, $vardef, $displayParams, $tabindex, false);
     $baseCurrency = SugarCurrency::getBaseCurrency();
     $amount = $parentFieldArray[strtoupper($vardef['name'])];
     $currencyId = !empty($parentFieldArray['CURRENCY_ID']) ? $parentFieldArray['CURRENCY_ID'] : $baseCurrency->id;
     $currencySymbol = !empty($parentFieldArray['CURRENCY_SYMBOL']) ? $parentFieldArray['CURRENCY_SYMBOL'] : SugarCurrency::getCurrencyByID($currencyId)->symbol;
     if (empty($currencyId) || !empty($vardef['is_base_currency'])) {
         // this is a base USDOLLAR field
         if ($current_user->getPreference('currency_show_preferred')) {
             // display base amount in user preferred currency
             $userCurrency = SugarCurrency::getUserLocaleCurrency();
             $currencyId = $userCurrency->id;
             $currencySymbol = $userCurrency->symbol;
             if (!empty($parentFieldArray['BASE_RATE']) && $parentFieldArray['BASE_RATE'] != 1) {
                 $amount = SugarCurrency::convertWithRate($amount, 1.0, $parentFieldArray['BASE_RATE']);
             } else {
                 $amount = SugarCurrency::convertWithRate($amount, 1.0, $userCurrency->conversion_rate);
             }
         } else {
             // display in base currency
             $currencyId = $baseCurrency->id;
             $currencySymbol = $baseCurrency->symbol;
         }
     }
     $this->ss->assign('currency_id', $currencyId);
     $this->ss->assign('currency_symbol', $currencySymbol);
     $this->ss->assign('amount', $amount);
     return $this->fetch($this->findTemplate('ListView'));
 }
 /**
  * Returns the the conversion rate for the passed in currency
  */
 public function evaluate()
 {
     $id = $this->getParameters()->evaluate();
     $currency = SugarCurrency::getCurrencyByID($id);
     return $currency->conversion_rate;
 }
示例#3
0
 function getCurrencySymbol($user = null)
 {
     $currencyId = $this->getPrecedentPreference('currency', $user);
     $currencyId = $currencyId ? $currencyId : '-99';
     $currency = SugarCurrency::getCurrencyByID($currencyId);
     return $currency->symbol;
 }
示例#4
0
/**
 * Retrieve a list of beans.  This is the primary method for getting list of SugarBeans from Sugar using the SOAP API.
 *
 * @param String $session -- Session ID returned by a previous call to login.
 * @param String $module_name -- The name of the module to return records from.  This name should be the name the module was developed under (changing a tab name is studio does not affect the name that should be passed into this method)..
 * @param String $query -- SQL where clause without the word 'where'
 * @param String $order_by -- SQL order by clause without the phrase 'order by'
 * @param String $offset -- The record offset to start from.
 * @param Array  $select_fields -- A list of the fields to be included in the results. This optional parameter allows for only needed fields to be retrieved.
 * @param String $max_results -- The maximum number of records to return.  The default is the sugar configuration value for 'list_max_entries_per_page'
 * @param Number $deleted -- false if deleted records should not be include, true if deleted records should be included.
 * @return Array 'result_count' -- The number of records returned
 *               'next_offset' -- The start of the next page (This will always be the previous offset plus the number of rows returned.  It does not indicate if there is additional data unless you calculate that the next_offset happens to be closer than it should be.
 *               'field_list' -- The vardef information on the selected fields.
 *                      Array -- 'field'=>  'name' -- the name of the field
 *                                          'type' -- the data type of the field
 *                                          'label' -- the translation key for the label of the field
 *                                          'required' -- Is the field required?
 *                                          'options' -- Possible values for a drop down field
 *               'entry_list' -- The records that were retrieved
 *               'error' -- The SOAP error, if any
 */
function get_entry_list($session, $module_name, $query, $order_by, $offset, $select_fields, $max_results, $deleted)
{
    $error = new SoapError();
    if (!validate_authenticated($session)) {
        $error->set_error('invalid_login');
        return array('result_count' => -1, 'entry_list' => array(), 'error' => $error->get_soap_array());
    }
    $using_cp = false;
    if ($module_name == 'CampaignProspects') {
        $module_name = 'Prospects';
        $using_cp = true;
    }
    global $current_user;
    if (!check_modules_access($current_user, $module_name, 'read')) {
        $error->set_error('no_access');
        return array('result_count' => -1, 'entry_list' => array(), 'error' => $error->get_soap_array());
    }
    // If the maximum number of entries per page was specified, override the configuration value.
    if ($max_results > 0) {
        global $sugar_config;
        $sugar_config['list_max_entries_per_page'] = $max_results;
    }
    $seed = BeanFactory::getBean($module_name);
    if (empty($seed)) {
        $error->set_error('no_module');
        return array('result_count' => -1, 'entry_list' => array(), 'error' => $error->get_soap_array());
    }
    if (!($seed->ACLAccess('Export') && $seed->ACLAccess('list'))) {
        $error->set_error('no_access');
        return array('result_count' => -1, 'entry_list' => array(), 'error' => $error->get_soap_array());
    }
    require_once 'include/SugarSQLValidate.php';
    $valid = new SugarSQLValidate();
    if (!$valid->validateQueryClauses($query, $order_by)) {
        $GLOBALS['log']->error("Bad query: {$query} {$order_by}");
        $error->set_error('no_access');
        return array('result_count' => -1, 'error' => $error->get_soap_array());
    }
    if ($query == '') {
        $where = '';
    }
    if ($offset == '' || $offset == -1) {
        $offset = 0;
    }
    if ($using_cp) {
        $response = $seed->retrieveTargetList($query, $select_fields, $offset, -1, -1, $deleted);
    } else {
        $response = $seed->get_list($order_by, $query, $offset, -1, -1, $deleted, true, $select_fields);
    }
    $list = $response['list'];
    $output_list = array();
    $isEmailModule = false;
    if ($module_name == 'Emails') {
        $isEmailModule = true;
    }
    // retrieve the vardef information on the bean's fields.
    $field_list = array();
    require_once 'modules/Currencies/Currency.php';
    $currencies = array();
    foreach ($list as $value) {
        if (isset($value->emailAddress)) {
            $value->emailAddress->handleLegacyRetrieve($value);
        }
        if ($isEmailModule) {
            $value->retrieveEmailText();
        }
        $value->fill_in_additional_detail_fields();
        // bug 55129 - populate currency from user settings
        if (property_exists($value, 'currency_id')) {
            if (!isset($currencies[$value->currency_id])) {
                $currencies[$value->currency_id] = SugarCurrency::getCurrencyByID($value->currency_id);
            }
            $row_currency = $currencies[$value->currency_id];
            // walk through all currency-related fields
            foreach ($value->field_defs as $temp_field) {
                if (isset($temp_field['type']) && 'relate' == $temp_field['type'] && isset($temp_field['module']) && 'Currencies' == $temp_field['module'] && isset($temp_field['id_name']) && 'currency_id' == $temp_field['id_name']) {
                    // populate related properties manually
                    $temp_property = $temp_field['name'];
                    $currency_property = $temp_field['rname'];
                    $value->{$temp_property} = $row_currency->{$currency_property};
                }
            }
        }
        // end of bug 55129
        $output_list[] = get_return_value($value, $module_name);
        if (empty($field_list)) {
            $field_list = get_field_list($value);
        }
    }
    // Filter the search results to only include the requested fields.
    $output_list = filter_return_list($output_list, $select_fields, $module_name);
    // Filter the list of fields to only include information on the requested fields.
    $field_list = filter_return_list($field_list, $select_fields, $module_name);
    // Calculate the offset for the start of the next page
    $next_offset = $offset + sizeof($output_list);
    return array('result_count' => sizeof($output_list), 'next_offset' => $next_offset, 'field_list' => $field_list, 'entry_list' => $output_list, 'error' => $error->get_soap_array());
}
示例#5
0
 public function save($check_notify = false)
 {
     if (empty($this->currency_id)) {
         // use user preferences for currency
         $currency = SugarCurrency::getUserLocaleCurrency();
         $this->currency_id = $currency->id;
     } else {
         $currency = SugarCurrency::getCurrencyByID($this->currency_id);
     }
     $this->base_rate = $currency->conversion_rate;
     return parent::save($check_notify);
 }
 /**
  * @param string $data The job data set for this particular Scheduled Job instance
  * @return boolean true if the run succeeded; false otherwise
  */
 public function run($data)
 {
     $settings = Opportunity::getSettings();
     if (isset($settings['opps_view_by']) && $settings['opps_view_by'] !== 'Opportunities') {
         $GLOBALS['log']->fatal("Opportunity are being used with Revenue Line Items. " . __CLASS__ . " should not be running");
         return false;
     }
     $args = json_decode(html_entity_decode($data), true);
     $this->job->runnable_ran = true;
     $labels = $args['labels'];
     $data = $args['chunk'];
     $currencies = array();
     Activity::disable();
     // disable the fts index as well
     /* @var $ftsSearch SugarSearchEngineElastic */
     $ftsSearch = SugarSearchEngineFactory::getInstance();
     $ftsSearch->setForceAsyncIndex(true);
     foreach ($data as $opp_id => $rli_data) {
         /* @var $opp Opportunity */
         $opp = BeanFactory::getBean('Opportunities', $opp_id);
         /* @var $note Note */
         $note = BeanFactory::getBean('Notes');
         $note->parent_id = $opp_id;
         $note->parent_type = 'Opportunities';
         $note->assigned_user_id = $opp->assigned_user_id;
         $note->created_by = $opp->created_by;
         $note->name = 'Previous Associated Revenue Line Items';
         $desc = '';
         foreach ($rli_data as $rli) {
             $desc .= $rli['name'] . "\n";
             foreach ($rli as $field => $value) {
                 if (isset($labels[$field])) {
                     if ($field === 'currency_id') {
                         if (!isset($currencies[$value])) {
                             $currencies[$value] = SugarCurrency::getCurrencyByID($value);
                         }
                         $desc .= " - " . $labels[$field] . ": " . $currencies[$value]->name . "\n";
                     } elseif ($field !== 'name' && $field !== 'opportunity_id') {
                         $desc .= " - " . $labels[$field] . ": " . $value . "\n";
                     }
                 }
             }
             $desc .= "\n\n";
         }
         $note->description = trim($desc);
         $note->save();
     }
     // set it back to the default value from the config.
     $ftsSearch->setForceAsyncIndex(SugarConfig::getInstance()->get('search_engine.force_async_index', false));
     Activity::enable();
     $this->job->succeedJob();
     $this->notifyAssignedUser();
     return true;
 }
示例#7
0
 public function save($check_notify = false)
 {
     // set the currency for the forecast to always be the base currency
     // since the committed end point only sends the data as the base currency format
     if (empty($this->currency_id)) {
         // use user preferences for currency
         $currency = SugarCurrency::getBaseCurrency();
         $this->currency_id = $currency->id;
     } else {
         $currency = SugarCurrency::getCurrencyByID($this->currency_id);
     }
     $this->base_rate = $currency->conversion_rate;
     parent::save($check_notify);
 }
示例#8
0
function get_display_text($temp_module, $field, $field_value, $adv_type = null, $ext1 = null, $context = null)
{
    global $app_list_strings, $current_user;
    if ($temp_module->field_defs[$field]['type'] == "relate") {
        //echo $field;
        //bug 23502, assigned user should be displayed as username here. But I don't know if created user, modified user or even other module should display names instead of ids.
        if ($temp_module->field_defs[$field]['name'] == 'assigned_user_id' && !empty($field_value) && !empty($context['for_action_display'])) {
            if ($adv_type != 'exist_user') {
                return get_username_by_id($field_value);
            } else {
                $target_type = "assigned_user_name";
            }
        } else {
            if (!empty($temp_module->field_defs[$field]['dbType'])) {
                $target_type = $temp_module->field_defs[$field]['dbType'];
            } else {
                return $field_value;
            }
        }
    } else {
        if (!empty($temp_module->field_defs[$field]['calculated']) && !empty($context['for_action_display'])) {
            //Cannot set the value of calculated fields.
            return false;
        } else {
            $target_type = $temp_module->field_defs[$field]['type'];
        }
    }
    //Land of the "one offs"
    //This is for meetings and calls, the reminder time
    if ($temp_module->field_defs[$field]['name'] == "reminder_time") {
        $target_type = "enum";
        $temp_module->field_defs[$field]['options'] = "reminder_time_options";
    }
    // handle currency_id field to display the actual currency name vs the id when in edit view.
    if ($target_type == 'currency_id' && !empty($field_value)) {
        $currency = SugarCurrency::getCurrencyByID($field_value);
        return $currency->name;
    }
    // display team name for team_id field
    if ($field == 'team_id' && !empty($field_value)) {
        $team = BeanFactory::getBean('Teams', $field_value, array('strict_retrieve' => true));
        if ($team) {
            return Team::getDisplayName($team->name, $team->name_2);
        }
    }
    if ($target_type == "assigned_user_name") {
        if ($adv_type == null) {
            $user_array = get_user_array(TRUE, "Active", $field_value, true);
            if (!isset($user_array[$field_value])) {
                return false;
            }
            return $user_array[$field_value];
        }
        if ($adv_type == "exist_user") {
            if ($ext1 == "Manager") {
                return "Manager of the " . $app_list_strings['wflow_adv_user_type_dom'][$field_value];
            } else {
                return $app_list_strings['wflow_adv_user_type_dom'][$field_value];
            }
        }
    }
    if ($adv_type == "datetime") {
        if (empty($field_value)) {
            $field_value = 0;
        }
        return $app_list_strings['tselect_type_dom'][$field_value] . " from " . $app_list_strings['wflow_action_datetime_type_dom'][$ext1];
    }
    if ($adv_type == "exist_team") {
        return $app_list_strings['wflow_adv_team_type_dom'][$field_value];
    }
    if ($adv_type == "value_calc") {
        return "existing value" . $app_list_strings['query_calc_oper_dom'][$ext1] . " by " . $field_value;
    }
    if ($adv_type == "enum_step") {
        return $app_list_strings['wflow_adv_enum_type_dom'][$ext1] . " " . $field_value . " step(s)";
    }
    //Used primarily for alert templates
    require_once 'include/SugarFields/SugarFieldHandler.php';
    $sugarField = SugarFieldHandler::getSugarField($target_type);
    $field_value = $sugarField->getEmailTemplateValue($field_value, $temp_module->field_defs[$field], $context);
    return $field_value;
    //end get_display_text
}