/**
  * Handles export field sanitizing for field type
  *
  * @param $value string value to be sanitized
  * @param $vardef array representing the vardef definition
  * @param $focus SugarBean object
  * @param $row Array of a row of data to be exported
  *
  * @return string sanitized value
  */
 public function exportSanitize($value, $vardef, $focus, $row = array())
 {
     // If $value is null, default to zero to prevent conversion errors.
     $value = is_null($value) ? 0 : $value;
     require_once 'include/SugarCurrency/SugarCurrency.php';
     if (isset($vardef['convertToBase']) && $vardef['convertToBase']) {
         // convert amount to base
         $baseRate = isset($row['base_rate']) ? $row['base_rate'] : $focus->base_rate;
         $value = SugarCurrency::convertWithRate($value, $baseRate);
         $currency_id = '-99';
     } elseif (isset($vardef['is_base_currency']) && $vardef['is_base_currency']) {
         $currency_id = '-99';
     } else {
         //If the row has a currency_id set, use that instead of the $focus->currency_id value
         $currency_id = isset($row['currency_id']) ? $row['currency_id'] : $focus->currency_id;
     }
     return SugarCurrency::formatAmountUserLocale($value, $currency_id);
 }
Beispiel #2
0
function create_campaign_summary($focus)
{
    global $mod_strings, $app_strings;
    $fields = array();
    $fields[] = 'name';
    $fields[] = 'assigned_user_name';
    $fields[] = 'status';
    $fields[] = 'team_name';
    $fields[] = 'start_date';
    $fields[] = 'end_date';
    if ($focus->campaign_type == 'NewsLetter') {
        $fields[] = 'frequency';
    }
    $fields[] = 'content';
    $fields[] = 'budget';
    $fields[] = 'actual_cost';
    $fields[] = 'expected_revenue';
    $fields[] = 'expected_cost';
    $fields[] = 'impressions';
    $fields[] = 'objective';
    if (!empty($focus->budget)) {
        $focus->budget = SugarCurrency::formatAmountUserLocale($focus->budget, $focus->currency_id);
    }
    if (!empty($focus->actual_cost)) {
        $focus->actual_cost = SugarCurrency::formatAmountUserLocale($focus->actual_cost, $focus->currency_id);
    }
    if (!empty($focus->expected_cost)) {
        $focus->expected_cost = SugarCurrency::formatAmountUserLocale($focus->expected_cost, $focus->currency_id);
    }
    if (!empty($focus->expected_revenue)) {
        $focus->expected_revenue = SugarCurrency::formatAmountUserLocale($focus->expected_revenue, $focus->currency_id);
    }
    //create edit view status and input buttons
    $cmp_input = '';
    //create edit campaign button
    $cmp_input = "<input id='wiz_next_button' name='SUBMIT'  ";
    $cmp_input .= "onclick=\"this.form.return_module.value='Campaigns';";
    $cmp_input .= "this.form.module.value='Campaigns';";
    $cmp_input .= "this.form.action.value='WizardNewsletter';";
    $cmp_input .= "this.form.return_action.value='WizardHome';";
    $cmp_input .= "this.form.direct_step.value='1';";
    $cmp_input .= "this.form.record.value='" . $focus->id . "';";
    $cmp_input .= "this.form.return_id.value='" . $focus->id . "';\" ";
    $cmp_input .= "class='button' value='" . $mod_strings['LBL_EDIT_EXISTING'] . "' type='submit'> ";
    //create view status button
    if ($focus->campaign_type == 'NewsLetter' || $focus->campaign_type == 'Email') {
        $cmp_input .= " <input id='wiz_status_button' name='SUBMIT'  ";
        $cmp_input .= "onclick=\"this.form.return_module.value='Campaigns';";
        $cmp_input .= "this.form.module.value='Campaigns';";
        $cmp_input .= "this.form.action.value='TrackDetailView';";
        $cmp_input .= "this.form.return_action.value='WizardHome';";
        $cmp_input .= "this.form.record.value='" . $focus->id . "';";
        $cmp_input .= "this.form.return_id.value='" . $focus->id . "';\" ";
        $cmp_input .= "class='button' value='" . $mod_strings['LBL_TRACK_BUTTON_TITLE'] . "' type='submit'>";
    }
    //create view roi button
    $cmp_input .= " <input id='wiz_status_button' name='SUBMIT'  ";
    $cmp_input .= "onclick=\"this.form.return_module.value='Campaigns';";
    $cmp_input .= "this.form.module.value='Campaigns';";
    $cmp_input .= "this.form.action.value='RoiDetailView';";
    $cmp_input .= "this.form.return_action.value='WizardHome';";
    $cmp_input .= "this.form.record.value='" . $focus->id . "';";
    $cmp_input .= "this.form.return_id.value='" . $focus->id . "';\" ";
    $cmp_input .= "class='button' value='" . $mod_strings['LBL_TRACK_ROI_BUTTON_LABEL'] . "' type='submit'>";
    //Create Campaign Header
    $cmpgn_tbl = "<p><table class='edit view' width='100%' border='0' cellspacing='0' cellpadding='0'>";
    $cmpgn_tbl .= "<tr><td class='dataField' align='left'><h4 class='dataLabel'> " . $mod_strings['LBL_LIST_CAMPAIGN_NAME'] . '  ' . $mod_strings['LBL_WIZ_NEWSLETTER_TITLE_SUMMARY'] . " </h4></td>";
    $cmpgn_tbl .= "<td align='right'>{$cmp_input}</td></tr>";
    $colorclass = '';
    foreach ($fields as $key) {
        if (!empty($focus->{$key}) && !empty($mod_strings[$focus->field_name_map[$key]['vname']])) {
            $cmpgn_tbl .= "<tr><td scope='row' width='15%'>" . $mod_strings[$focus->field_name_map[$key]['vname']] . "</td>\n";
            if ($key == 'team_name') {
                require_once 'modules/Teams/TeamSetManager.php';
                $cmpgn_tbl .= "<td scope='row'>" . TeamSetManager::getCommaDelimitedTeams($focus->team_set_id, $focus->team_id, true) . "</td></tr>\n";
            } else {
                $cmpgn_tbl .= "<td scope='row'>" . $focus->{$key} . "</td></tr>\n";
            }
        }
    }
    $cmpgn_tbl .= "</table></p>";
    return $cmpgn_tbl;
}
Beispiel #3
0
if (unformat_number($focus->impressions) > 0) {
    $cost_per_impression = unformat_number($focus->actual_cost) / unformat_number($focus->impressions);
} else {
    $cost_per_impression = format_number(0);
}
$smarty->assign("COST_PER_IMPRESSION", SugarCurrency::formatAmountUserLocale($cost_per_impression, $focus->currency_id));
if (empty($camp_data1['click_thru_link'])) {
    $camp_data1['click_thru_link'] = 0;
}
$click_thru_links = $camp_data1['click_thru_link'];
if ($click_thru_links > 0) {
    $cost_per_click_thru = unformat_number($focus->actual_cost) / unformat_number($click_thru_links);
} else {
    $cost_per_click_thru = format_number(0);
}
$smarty->assign("COST_PER_CLICK_THROUGH", SugarCurrency::formatAmountUserLocale($cost_per_click_thru, $focus->currency_id));
$currency = BeanFactory::getBean('Currencies');
if (isset($focus->currency_id) && !empty($focus->currency_id)) {
    $currency->retrieve($focus->currency_id);
    if ($currency->deleted != 1) {
        $smarty->assign("CURRENCY", $currency->iso4217 . ' ' . $currency->symbol);
    } else {
        $smarty->assign("CURRENCY", $currency->getDefaultISO4217() . ' ' . $currency->getDefaultCurrencySymbol());
    }
} else {
    $smarty->assign("CURRENCY", $currency->getDefaultISO4217() . ' ' . $currency->getDefaultCurrencySymbol());
}
global $current_user;
if (is_admin($current_user) && $_REQUEST['module'] != 'DynamicLayout' && !empty($_SESSION['editinplace'])) {
    $smarty->assign("ADMIN_EDIT", "<a href='index.php?action=index&module=DynamicLayout&from_action=" . $_REQUEST['action'] . "&from_module=" . $_REQUEST['module'] . "&record=" . $_REQUEST['record'] . "'>" . SugarThemeRegistry::current()->getImage("EditLayout", "border='0' align='bottom'", null, null, '.gif', $mod_strings['LBL_EDIT_LAYOUT']) . "</a>");
}
Beispiel #4
0
 /**
  * Retrieve a user's quota using the rollup value, if available.  This method is useful for
  * fetching user quota data when you're unsure about whether or not the given user is a manager.
  * If you would like to force a direct quota, pass a false value to $should_rollup.
  *
  * @param $timeperiod_id String id of the TimePeriod to retrieve quota for
  * @param $user_id String value of the user id to retrieve.  If NULL, the $current_user is used
  * @param $should_rollup boolean value indicating whether or not the quota should be a rollup calculation; false by default
  *
  * @return array [currency_id => int, amount => number, formatted_amount => String]
  */
 public function getRollupQuota($timeperiod_id, $user_id = null, $should_rollup = false)
 {
     if (is_null($user_id)) {
         global $current_user;
         $user_id = $current_user->id;
     }
     // figure out the timeperiod
     // if we didn't find a time period, set the time period to be the current time period
     if (!is_guid($timeperiod_id) && is_numeric($timeperiod_id) && $timeperiod_id != 0) {
         // we have a timestamp, find timeperiod it belongs in
         $timeperiod_id = TimePeriod::getIdFromTimestamp($timeperiod_id);
     }
     if (!is_guid($timeperiod_id)) {
         $timeperiod_id = TimePeriod::getCurrentId();
     }
     $sq = new SugarQuery();
     $sq->select(array('quotas.currency_id', 'quotas.amount'));
     $sq->from(BeanFactory::getBean('Quotas'));
     $sq->where()->equals('user_id', $user_id)->equals('quota_type', $should_rollup ? 'Rollup' : 'Direct')->equals('timeperiod_id', $timeperiod_id);
     $sq->orderBy('date_modified', 'DESC');
     $sq->limit(1);
     // since there is only ever one row, just shift the value off the results
     $row = array_shift($sq->execute());
     if (empty($row)) {
         // This is to prevent return value of false when a given timeperiod has no quota.
         $row = array('currency_id' => -99, 'amount' => 0);
     }
     $row['formatted_amount'] = SugarCurrency::formatAmountUserLocale($row['amount'], $row['currency_id']);
     return $row;
 }
$smarty->assign("STATUS", $app_list_strings['campaign_status_dom'][$focus->status]);
$smarty->assign("NAME", $focus->name);
$smarty->assign("TYPE", $app_list_strings['campaign_type_dom'][$focus->campaign_type]);
$smarty->assign("START_DATE", $focus->start_date);
$smarty->assign("END_DATE", $focus->end_date);
if (!empty($focus->budget)) {
    $smarty->assign("BUDGET", SugarCurrency::formatAmountUserLocale($focus->budget, $focus->currency_id));
}
if (!empty($focus->actual_cost)) {
    $smarty->assign("ACTUAL_COST", SugarCurrency::formatAmountUserLocale($focus->actual_cost, $focus->currency_id));
}
if (!empty($focus->expected_cost)) {
    $smarty->assign("EXPECTED_COST", SugarCurrency::formatAmountUserLocale($focus->expected_cost, $focus->currency_id));
}
if (!empty($focus->expected_revenue)) {
    $smarty->assign("EXPECTED_REVENUE", SugarCurrency::formatAmountUserLocale($focus->expected_revenue, $focus->currency_id));
}
$smarty->assign("OBJECTIVE", nl2br($focus->objective));
$smarty->assign("CONTENT", nl2br($focus->content));
$smarty->assign("DATE_MODIFIED", $focus->date_modified);
$smarty->assign("DATE_ENTERED", $focus->date_entered);
$smarty->assign("CREATED_BY", $focus->created_by_name);
$smarty->assign("MODIFIED_BY", $focus->modified_by_name);
$smarty->assign("TRACKER_URL", $sugar_config['site_url'] . '/campaign_tracker.php?track=' . $focus->tracker_key);
$smarty->assign("TRACKER_COUNT", intval($focus->tracker_count));
$smarty->assign("TRACKER_TEXT", $focus->tracker_text);
$smarty->assign("REFER_URL", $focus->refer_url);
if (isset($focus->campaign_type) && $focus->campaign_type == "Email" || $focus->campaign_type == "NewsLetter") {
    $smarty->assign("TRACK_DELETE_BUTTON", "<input title=\"{$mod_strings['LBL_TRACK_DELETE_BUTTON_TITLE']}\" class=\"button\" onclick=\"this.form.module.value='Campaigns'; this.form.action.value='Delete';this.form.return_module.value='Campaigns'; this.form.return_action.value='TrackDetailView';this.form.mode.value='Test';return confirm('{$mod_strings['LBL_TRACK_DELETE_CONFIRM']}');\" type=\"submit\" name=\"button\" value=\"  {$mod_strings['LBL_TRACK_DELETE_BUTTON_LABEL']}  \">");
}
$currency = BeanFactory::getBean('Currencies');
Beispiel #6
0
 /**
  * @see SugarView::display()
  */
 public function display()
 {
     require_once 'modules/Quotes/Layouts.php';
     require_once 'include/EditView/EditView2.php';
     global $beanFiles;
     require_once $beanFiles['Quote'];
     require_once $beanFiles['TaxRate'];
     require_once $beanFiles['Shipper'];
     global $mod_strings;
     global $app_strings;
     global $app_list_strings;
     global $current_user;
     global $timedate;
     global $locale;
     $original_quote = BeanFactory::getBean('Quotes');
     if ($this->ev->isDuplicate) {
         $this->bean->id = "";
         $this->bean->quote_num = "";
         $original_quote->retrieve($_REQUEST['record']);
     }
     //needed when creating a new quote only with a default account value passed in
     if (empty($this->bean->id) && !$this->ev->isDuplicate) {
         $this->bean->quote_num = '';
         $this->bean->total = '0.00';
         $this->bean->shipping = '0.00';
         $this->bean->tax = '0.00';
         $this->bean->subtotal = '0.00';
         if (isset($_REQUEST['opportunity_name'])) {
             $this->bean->opportunity_name = $_REQUEST['opportunity_name'];
         }
         if (isset($_REQUEST['opportunity_id'])) {
             $this->bean->opportunity_id = $_REQUEST['opportunity_id'];
         }
         if (isset($_REQUEST['account_name'])) {
             $this->bean->billing_account_name = $_REQUEST['account_name'];
             $this->bean->shipping_account_name = $_REQUEST['account_name'];
         }
         if (isset($_REQUEST['account_id'])) {
             $this->bean->billing_account_id = $_REQUEST['account_id'];
             $this->bean->shipping_account_id = $_REQUEST['account_id'];
             require_once $beanFiles['Account'];
             $account = BeanFactory::getBean('Accounts', $this->bean->shipping_account_id);
             $this->bean->shipping_address_street = $account->shipping_address_street;
             $this->bean->shipping_address_city = $account->shipping_address_city;
             $this->bean->shipping_address_state = $account->shipping_address_state;
             $this->bean->shipping_address_country = $account->shipping_address_country;
             $this->bean->shipping_address_postalcode = $account->shipping_address_postalcode;
             $this->bean->billing_address_street = $account->billing_address_street;
             $this->bean->billing_address_city = $account->billing_address_city;
             $this->bean->billing_address_state = $account->billing_address_state;
             $this->bean->billing_address_country = $account->billing_address_country;
             $this->bean->billing_address_postalcode = $account->billing_address_postalcode;
         }
         if (isset($_REQUEST['contact_id'])) {
             $this->bean->contact_id = $_REQUEST['contact_id'];
             require_once $beanFiles['Contact'];
             $contact = BeanFactory::getBean('Contacts', $this->bean->contact_id);
             $this->bean->billing_contact_name = $locale->formatName($contact);
             $this->bean->billing_contact_id = $contact->id;
             $this->bean->shipping_contact_name = $locale->formatName($contact);
             $this->bean->shipping_contact_id = $contact->id;
             $this->bean->shipping_address_street = $contact->primary_address_street;
             $this->bean->shipping_address_city = $contact->primary_address_city;
             $this->bean->shipping_address_state = $contact->primary_address_state;
             $this->bean->shipping_address_country = $contact->primary_address_country;
             $this->bean->shipping_address_postalcode = $contact->primary_address_postalcode;
         }
         if (isset($_REQUEST['date_quote_expected_closed'])) {
             $this->bean->date_quote_expected_closed = $_REQUEST['date_quote_expected_closed'];
         }
         if (isset($_REQUEST['currency_id'])) {
             $this->bean->currency_id = $_REQUEST['currency_id'];
         }
     }
     $currency = BeanFactory::getBean('Currencies', $this->bean->currency_id);
     // Set the number grouping and decimal separators
     $seps = get_number_seperators();
     $dec_sep = $seps[1];
     $num_grp_sep = $seps[0];
     $this->ss->assign('NUM_GRP_SEP', $num_grp_sep);
     $this->ss->assign('DEC_SEP', $dec_sep);
     $significantDigits = $locale->getPrecedentPreference('default_currency_significant_digits', $current_user);
     $this->ss->assign('PRECISION', $significantDigits);
     if ((is_admin($current_user) || is_admin_for_module($GLOBALS['current_user'], 'Quotes')) && $_REQUEST['module'] != 'DynamicLayout' && !empty($_SESSION['editinplace'])) {
         $record = '';
         if (!empty($_REQUEST['record'])) {
             $record = $_REQUEST['record'];
         }
         $this->ss->assign('ADMIN_EDIT', "<a href='index.php?action=index&module=DynamicLayout&from_action=" . $_REQUEST['action'] . "&from_module=" . $_REQUEST['module'] . "&record=" . $record . "'>" . SugarThemeRegistry::current()->getImage("EditLayout", "border='0' align='bottom'", null, null, '.gif', $mod_strings['LBL_EDITLAYOUT']) . "</a>");
     }
     $this->ss->assign('QUOTE_STAGE_OPTIONS', get_select_options_with_id($app_list_strings['quote_stage_dom'], $this->bean->quote_stage));
     $this->ss->assign('DEFAULT_PRODUCT_STATUS', $app_list_strings['product_status_quote_key']);
     if (isset($this->bean->subtotal)) {
         $this->ss->assign('SUBTOTAL', $this->bean->subtotal);
     } else {
         $this->ss->assign('SUBTOTAL', "0.00");
     }
     if (isset($this->bean->tax)) {
         $this->ss->assign('TAX', $this->bean->tax);
     } else {
         $this->ss->assign('TAX', "0.00");
     }
     if (isset($this->bean->shipping)) {
         $this->ss->assign("SHIPPING", $this->bean->shipping);
     } else {
         $this->ss->assign('SHIPPING', "0.00");
     }
     if (isset($this->bean->deal_tot)) {
         $this->ss->assign('DEAL_TOT', $this->bean->deal_tot);
     } else {
         $this->ss->assign('DEAL_TOT', "0.00");
     }
     if (isset($this->bean->new_sub)) {
         $this->ss->assign('NEW_SUB', $this->bean->new_sub);
     } else {
         $this->ss->assign('NEW_SUB', "0.00");
     }
     if (isset($this->bean->total)) {
         $this->ss->assign('TOTAL', $this->bean->total);
     } else {
         $this->ss->assign('TOTAL', "0.00");
     }
     if (isset($this->bean->subtotal_usdollar)) {
         $this->ss->assign('SUBTOTAL_USDOLLAR', $this->bean->subtotal_usdollar);
     } else {
         $this->ss->assign('SUBTOTAL_USDOLLAR', "0.00");
     }
     if (isset($this->bean->tax_usdollar)) {
         $this->ss->assign('TAX_USDOLLAR', $this->bean->tax_usdollar);
     } else {
         $this->ss->assign('TAX_USDOLLAR', "0.00");
     }
     if (isset($this->bean->shipping_usdollar)) {
         $this->ss->assign('SHIPPING_USDOLLAR', $this->bean->shipping_usdollar);
     } else {
         $this->ss->assign('SHIPPING_USDOLLAR', "0.00");
     }
     if (isset($this->bean->total_usdollar)) {
         $this->ss->assign('TOTAL_USDOLLAR', $this->bean->total_usdollar);
     } else {
         $this->ss->assign('TOTAL_USDOLLAR', "0.00");
     }
     $this->ss->assign('USER_DATEFORMAT', '(' . $timedate->get_user_date_format() . ')');
     $this->ss->assign('CALENDAR_DATEFORMAT', $timedate->get_cal_date_format());
     $taxrate = BeanFactory::getBean('TaxRates');
     $this->ss->assign('TAXRATE_OPTIONS', get_select_options_with_id($taxrate->get_taxrates(false), $this->bean->taxrate_id));
     if (empty($this->bean->taxrate_value)) {
         $this->ss->assign('TAXRATE_VALUE', $taxrate->get_default_taxrate_value() / 100);
     } else {
         $this->ss->assign('TAXRATE_VALUE', $this->bean->taxrate_value / 100);
     }
     $shipper = BeanFactory::getBean('Shippers');
     $this->ss->assign('SHIPPER_OPTIONS', get_select_options_with_id($shipper->get_shippers(true), $this->bean->shipper_id));
     if (empty($this->bean->assigned_user_id) && empty($this->bean->id)) {
         $this->bean->assigned_user_id = $current_user->id;
     }
     if (empty($this->bean->assigned_name) && empty($this->bean->id)) {
         $this->bean->assigned_user_name = $current_user->user_name;
     }
     $this->ss->assign('ASSIGNED_USER_OPTIONS', get_select_options_with_id(get_user_array(TRUE, 'Active', $this->bean->assigned_user_id), $this->bean->assigned_user_id));
     $this->ss->assign('ASSIGNED_USER_NAME', $this->bean->assigned_user_name);
     $this->ss->assign('ASSIGNED_USER_ID', $this->bean->assigned_user_id);
     if (!empty($this->bean->calc_grand_total) && $this->bean->calc_grand_total == 1) {
         $this->ss->assign('CALC_GRAND_TOTAL_CHECKED', 'checked');
     }
     if (!empty($this->bean->show_line_nums) && $this->bean->show_line_nums == 1) {
         $this->ss->assign('SHOW_LINE_NUMS_CHECKED', 'checked');
     }
     // Set Currency values and currency javascript
     require_once 'modules/Currencies/ListCurrency.php';
     $currency = new ListCurrency();
     $base_rate = '1.00';
     if (isset($this->bean->currency_id) && !empty($this->bean->currency_id)) {
         $curid = $this->bean->currency_id;
     } elseif (isset($_REQUEST['currency_id']) && !empty($_REQUEST['currency_id'])) {
         $curid = $_REQUEST['currency_id'];
     } elseif (empty($this->bean->id)) {
         $curid = $current_user->getPreference('currency');
         if (empty($curid)) {
             $curid = -99;
         }
     } else {
         $curid = -99;
     }
     if ($this->bean->isClosed()) {
         $base_rate = $this->bean->base_rate;
     } else {
         $base_rate = null;
     }
     $selectCurrency = $currency->getSelectOptions($curid, $base_rate);
     $this->ss->assign("CURRENCY", $selectCurrency);
     $this->ss->assign('CURRENCY_JAVASCRIPT', $currency->getJavascript());
     if ($this->bean->fetched_row['date_quote_expected_closed'] == '1970-01-01' || $this->bean->fetched_row['date_quote_expected_closed'] == '0001-01-01') {
         $this->bean->date_quote_expected_closed = '';
     }
     $add_row = array();
     if (!empty($this->bean->id)) {
         $this->bean->load_relationship('product_bundles');
         $product_bundle_list = $this->bean->product_bundles->getBeans();
         usort($product_bundle_list, array('ProductBundle', 'compareProductBundlesByIndex'));
         $quote_currency_id = $this->bean->currency_id;
         $quote_base_rate = $this->bean->base_rate;
         $convert_format = function ($value, $prod_currency, $prod_base_rate) use($quote_currency_id, $quote_base_rate) {
             if ($prod_currency !== $quote_currency_id) {
                 $value = SugarCurrency::convertWithRate($value, $prod_base_rate, $quote_base_rate);
             }
             return SugarCurrency::formatAmountUserLocale($value, $quote_currency_id, false);
         };
         if (is_array($product_bundle_list)) {
             foreach ($product_bundle_list as $product_bundle) {
                 $bundle_list = $product_bundle->get_product_bundle_line_items();
                 $add_row[] = "quotesManager.addTable('{$product_bundle->id}','{$product_bundle->bundle_stage}', '{$product_bundle->name}', '" . format_money($product_bundle->shipping, FALSE) . "' );\n";
                 if (is_array($bundle_list)) {
                     while (list($key, $line_item) = each($bundle_list)) {
                         if ($line_item->object_name == "Product") {
                             /* @var $line_item Product */
                             $tax_class_name = isset($line_item->tax_class) ? $line_item->tax_class : "";
                             $encoded_name = js_escape(br2nl($line_item->name));
                             $add_row[] = "quotesManager.addRow('{$line_item->id}','" . format_number($line_item->quantity, $significantDigits, $significantDigits) . "','{$line_item->product_template_id}','{$encoded_name}'" . ", '" . $convert_format($line_item->cost_price, $line_item->currency_id, $line_item->base_rate) . "'" . ", '" . $convert_format($line_item->list_price, $line_item->currency_id, $line_item->base_rate) . "'" . ", '" . $convert_format($line_item->discount_price, $line_item->currency_id, $line_item->base_rate) . "'" . ", '', '', '{$line_item->pricing_factor}', '{$line_item->tax_class}', '{$tax_class_name}', '{$line_item->mft_part_num}', '{$product_bundle->id}', '{$product_bundle->bundle_stage}', '{$product_bundle->name}', '" . format_number($product_bundle->shipping) . "', '" . js_escape(br2nl($line_item->description)) . "', '" . $line_item->type_id . "'" . ", '" . format_number($line_item->discount_amount, $significantDigits, $significantDigits) . "'" . ", " . ($line_item->discount_select ? 1 : 0) . ", " . ($line_item->deal_calc ? 1 : 0) . ", '" . $line_item->status . "');\n";
                         } else {
                             if ($line_item->object_name == "ProductBundleNote") {
                                 /* @var $line_item ProductBundleNote */
                                 $encoded_description = js_escape(br2nl($line_item->description));
                                 //$encoded_description = html_entity_decode($encoded_description);
                                 $add_row[] = "quotesManager.addCommentRow('{$line_item->id}', '{$product_bundle->id}', '{$encoded_description}');\n";
                             }
                         }
                     }
                     //while
                 }
                 //if
             }
             //foreach
         }
     } else {
         // this else part is to create a new product_bundle for the duplicate quote
         $original_quote->load_relationship('product_bundles');
         $product_bundle_list = $original_quote->product_bundles->getBeans();
         usort($product_bundle_list, array('ProductBundle', 'compareProductBundlesByIndex'));
         if (is_array($product_bundle_list)) {
             foreach ($product_bundle_list as $product_bundle) {
                 $product_list = $product_bundle->get_products();
                 if (is_array($product_list)) {
                     foreach ($product_list as $line_item) {
                         $tax_class_name = isset($line_item->tax_class) ? $line_item->tax_class : "";
                         $add_row[] = "quotesManager.addRow('','{$line_item->quantity}','{$line_item->product_template_id}','{$line_item->name}'" . ", '" . format_number($line_item->cost_usdollar, $significantDigits, $significantDigits, array('convert' => true, 'currency_id' => $curid)) . "'" . ", '" . format_number($line_item->list_usdollar, $significantDigits, $significantDigits, array('convert' => true, 'currency_id' => $curid)) . "'" . ", '" . format_number($line_item->discount_usdollar, $significantDigits, $significantDigits, array('convert' => true, 'currency_id' => $curid)) . "'" . ", '', '', '{$line_item->pricing_factor}', '{$line_item->tax_class}', '{$tax_class_name}',\n\t\t\t\t\t\t\t\t'{$line_item->mft_part_num}', 'group_{$product_bundle->id}', '{$product_bundle->bundle_stage}', '{$product_bundle->name}', '" . format_money($product_bundle->shipping, FALSE) . "', '" . js_escape(br2nl($line_item->description)) . "', '" . $line_item->type_id . "','" . format_number($line_item->discount_amount_usdollar, $significantDigits, $significantDigits, array('convert' => !$line_item->discount_select, 'currency_id' => $curid)) . "'," . ($line_item->discount_select ? 1 : 0) . ",0, '" . $line_item->status . "');\n";
                     }
                     //foreach
                     if (empty($product_list)) {
                         $add_row[] = "quotesManager.addTable('group_{$product_bundle->id}','{$product_bundle->bundle_stage}', '{$product_bundle->name}' , ' " . format_money($product_bundle->shipping, FALSE) . "');\n";
                     }
                     //if
                     //bug 39573 - Comments are not duplicated in quotes
                     $bundle_list = $product_bundle->get_product_bundle_line_items();
                     if (is_array($bundle_list)) {
                         while (list($key, $line_item) = each($bundle_list)) {
                             if ($line_item->object_name == "ProductBundleNote") {
                                 $encoded_description = js_escape(br2nl($line_item->description));
                                 $add_row[] = "quotesManager.addCommentRow('{$line_item->id}', 'group_{$product_bundle->id}', '{$encoded_description}');\n";
                             }
                         }
                     }
                     //end bug 39573
                 }
                 //if
             }
         }
     }
     //if-else for !empty($this->bean->id)
     //Bug#53607: Create the javascript code to store the rendering function in a queue
     $add_row_js = 'var add_row_stack = [];';
     foreach ($add_row as $script_command) {
         $add_row_js .= "add_row_stack.push(function(){\n                {$script_command}\n            });";
     }
     //Bug#53607: Rather than executing all rendering row script once, it will keep in a queue.
     //           And it will render the specified number of rows every interval.
     $add_row_js .= "function add_rows_on_load() {\n            if(typeof add_row_stack != 'undefined' && add_row_stack.length > 0) {\n                //interval is in msec,\n                //size is the number of rows rendering every time\n                asyncLoading = true; // to indicate that the content is still loading\n                var _interval = 100,\n                    _size = 3,\n                    _exec = add_row_stack.splice(0, _size),\n                    _header_button = document.getElementById('SAVE_HEADER'),\n                    _footer_button = document.getElementById('SAVE_FOOTER');\n                if(_header_button) {\n                    _header_button.disabled = true;\n                }\n                if(_footer_button) {\n                    _footer_button.disabled = true;\n                }\n                for(idx in _exec) {\n                    _exec[idx]();\n                }\n                window.setTimeout(add_rows_on_load, _interval);\n            } else {\n                asyncLoading = false; // content is loaded\n                var _header_button = document.getElementById('SAVE_HEADER'),\n                    _footer_button = document.getElementById('SAVE_FOOTER');\n                if(_header_button) {\n                    _header_button.disabled = false;\n                }\n                if(_footer_button) {\n                    _footer_button.disabled = false;\n                }\n            }\n        }";
     $this->ss->assign("ADD_ROWS", $add_row_js);
     $setup_script = '';
     $taxclass = translate('tax_class_dom');
     foreach ($taxclass as $value => $name) {
         $setup_script .= "quotesManager.add_tax_class('{$name}', '{$value}');\n";
     }
     $this->ss->assign("SETUP_SCRIPT", $setup_script);
     $this->ss->assign('TAXRATE_JAVASCRIPT', $taxrate->get_taxrate_js());
     $this->ss->assign('CALCULATE_FUNCTION', '<script type="text/javascript">YAHOO.util.Event.onDOMReady(function(){quotesManager.calculate(document);});</script>');
     $this->ss->assign('NO_MATCH_VARIABLE', '<script type="text/javascript">sqs_no_match_text = "' . $app_strings['ERR_SQS_NO_MATCH'] . '";</script>');
     $str = "<script language=\"javascript\">\n\t\tYAHOO.util.Event.onAvailable('add_tables', add_rows_on_load);\n\t\t</script>";
     $this->ss->assign('SAVED_SEARCH_SELECTS', $str);
     parent::display();
     echo '<script>sqs_must_match = false;</script>';
 }
/// Users Popup
$popup_request_data = array('call_back_function' => 'set_return', 'form_name' => 'wizform', 'field_to_name_array' => array('id' => 'assigned_user_id', 'user_name' => 'assigned_user_name'));
$ss->assign('encoded_users_popup_request_data', $json->encode($popup_request_data));
$popup_request_data = array('call_back_function' => 'set_return', 'form_name' => 'wizform', 'field_to_name_array' => array('id' => 'team_id', 'name' => 'team_name'));
$ss->assign('encoded_team_popup_request_data', $json->encode($popup_request_data));
if (!empty($focus->budget)) {
    $focus->budget = SugarCurrency::formatAmountUserLocale($focus->budget, $focus->currency_id, false);
}
if (!empty($focus->actual_cost)) {
    $focus->actual_cost = SugarCurrency::formatAmountUserLocale($focus->actual_cost, $focus->currency_id, false);
}
if (!empty($focus->expected_cost)) {
    $focus->expected_cost = SugarCurrency::formatAmountUserLocale($focus->expected_cost, $focus->currency_id, false);
}
if (!empty($focus->expected_revenue)) {
    $focus->expected_revenue = SugarCurrency::formatAmountUserLocale($focus->expected_revenue, $focus->currency_id, false);
}
//set default values
$ss->assign("CALENDAR_LANG", "en");
$ss->assign("USER_DATEFORMAT", '(' . $timedate->get_user_date_format() . ')');
$ss->assign("CALENDAR_DATEFORMAT", $timedate->get_cal_date_format());
$ss->assign("CAMP_DATE_ENTERED", $focus->date_entered);
$ss->assign("CAMP_DATE_MODIFIED", $focus->date_modified);
$ss->assign("CAMP_CREATED_BY", $focus->created_by_name);
$ss->assign("CAMP_MODIFIED_BY", $focus->modified_by_name);
$ss->assign("ID", $focus->id);
$ss->assign("CAMP_TRACKER_TEXT", $focus->tracker_text);
$ss->assign("CAMP_START_DATE", $focus->start_date);
$ss->assign("CAMP_END_DATE", $focus->end_date);
$ss->assign("CAMP_BUDGET", $focus->budget);
$ss->assign("CAMP_ACTUAL_COST", $focus->actual_cost);
 public function displayListPlain($layout_def)
 {
     $value = parent::displayListPlain($layout_def);
     $row_currency = $this->getCurrency($layout_def);
     $format_id = $row_currency['currency_id'];
     global $current_user;
     // when the group by function is empty, and we should show the user prefered currency, it should convert it
     if (empty($layout_def['group_function']) && $current_user->getPreference('currency_show_preferred')) {
         $user_currency = SugarCurrency::getUserLocaleCurrency();
         if ($user_currency->id != $row_currency['currency_id']) {
             $value = SugarCurrency::convertAmount($value, $row_currency['currency_id'], $user_currency->id);
             $format_id = $user_currency->id;
         }
     }
     return SugarCurrency::formatAmountUserLocale($value, $format_id);
 }
Beispiel #9
0
 function get_next_row($result_field_name = 'result', $column_field_name = 'display_columns', $skip_non_summary_columns = false, $exporting = false)
 {
     global $current_user;
     $chart_cells = array();
     if ($this->do_export) {
         $db_row = $this->db->fetchByAssoc($this->{$result_field_name}, false);
     } else {
         $db_row = $this->db->fetchByAssoc($this->{$result_field_name});
     }
     if ($db_row == 0 || sizeof($db_row) == 0) {
         return 0;
     }
     // Call custom hooks
     if (isset($this->full_bean_list) && is_array($this->full_bean_list) && array_key_exists('self', $this->full_bean_list) && is_object($this->full_bean_list['self']) && method_exists($this->full_bean_list['self'], 'call_custom_logic')) {
         $this->full_bean_list['self']->call_custom_logic('process_report_row', array('row' => &$db_row, 'reporter' => $this));
     }
     if ($result_field_name == 'summary_result') {
         if (!empty($this->child_filter) && !empty($db_row[$this->child_filter_name])) {
             $this->child_filter_by = $db_row[$this->child_filter_name];
         } else {
             $this->child_filter = '';
             $this->child_filter_by = '';
             $this->child_filter_name = '';
         }
     }
     $row = array();
     $cells = array();
     $fields = array();
     foreach ($db_row as $key => $value) {
         //if value is null or not set, then change to empty string.  This prevents array index errors while processing
         $fields[strtoupper($key)] = is_null($value) ? '' : $value;
     }
     // here we want to make copies, so use foreach
     foreach ($this->report_def[$column_field_name] as $display_column) {
         $display_column['table_alias'] = $this->getTableFromField($display_column);
         $this->register_field_for_query($display_column);
         if ($skip_non_summary_columns && empty($display_column['group_function'])) {
             if ($exporting || $this->plain_text_output) {
                 array_push($cells, ' ');
             } else {
                 array_push($cells, '&nbsp;');
             }
             continue;
         }
         $display_column['fields'] = $fields;
         if ($this->plain_text_output == true) {
             /*nsingh: bug 13554- date and time fields must be displayed using user's locale settings.
              * Since to_pdf uses plain_text_output=true, we handle the date and time case here by using the 'List' context of the layout_manager
              */
             if ($display_column['type'] == 'date' || $display_column['type'] == 'time' || $display_column['type'] == 'datetimecombo') {
                 $this->layout_manager->setAttribute('context', 'List');
             } else {
                 $this->layout_manager->setAttribute('context', 'ListPlain');
             }
         } else {
             $this->layout_manager->setAttribute('context', 'List');
         }
         // Make sure 'AVG' aggregate is shown as float, regardless of the original field type
         if (!empty($display_column['group_function']) && strtolower($display_column['group_function']) === 'avg' && $display_column['type'] != 'currency') {
             $display_column['type'] = 'float';
         }
         if ($display_column['type'] != 'currency' || substr_count($display_column['name'], '_usdoll') == 0 && (isset($display_column['group_function']) ? $display_column['group_function'] != 'weighted_amount' && $display_column['group_function'] != 'weighted_sum' : true)) {
             $pos = $display_column['table_key'];
             $module_name = '';
             if ($pos) {
                 $module_name = substr($pos, strrpos($pos, ':') + 1);
             }
             $field_name = $this->getColumnFieldName($display_column);
             if ($module_name == 'currencies' && empty($display_column['fields'][$field_name])) {
                 switch ($display_column['name']) {
                     case 'iso4217':
                         $display = $this->currency_obj->getDefaultISO4217();
                         break;
                     case 'symbol':
                         $display = $this->currency_obj->getDefaultCurrencySymbol();
                         break;
                     case 'name':
                         $display = $this->currency_obj->getDefaultCurrencyName();
                         break;
                     default:
                         $display = $this->layout_manager->widgetDisplay($display_column);
                 }
                 $display_column['fields'][$field_name] = $display;
             } else {
                 if (!empty($field_name) && isset($display_column['fields'][$field_name])) {
                     $display_column['fields'][$field_name] = $this->db->fromConvert($display_column['fields'][$field_name], $display_column['type']);
                 }
                 $display = $this->layout_manager->widgetDisplay($display_column);
             }
         } else {
             if (isset($display_column['group_function'])) {
                 $field_name = $this->getTruncatedColumnAlias(strtoupper($display_column['table_alias']) . "_" . strtoupper($display_column['group_function']) . "_" . strtoupper($display_column['name']));
             } else {
                 unset($field_name);
             }
             if (!isset($field_name) || !isset($display_column['fields'][$field_name])) {
                 $field_name = $this->getTruncatedColumnAlias(strtoupper($display_column['table_alias']) . "_" . strtoupper($display_column['name']));
             }
             if (isset($display_column['fields'][$field_name])) {
                 $display = $display_column['fields'][$field_name];
             }
         }
         if ($display_column['type'] == 'currency' && (strpos($display_column['name'], '_usdoll') !== false || !empty($display_column['group_function']))) {
             // convert base to user preferred if set in user prefs
             if ($current_user->getPreference('currency_show_preferred')) {
                 $userCurrency = SugarCurrency::getUserLocaleCurrency();
                 $raw_display = SugarCurrency::convertWithRate($display_column['fields'][$field_name], 1.0, $userCurrency->conversion_rate);
                 $display = SugarCurrency::formatAmountUserLocale($raw_display, $userCurrency->id);
             } else {
                 $raw_display = $display_column['fields'][$field_name];
                 $display = SugarCurrency::formatAmountUserLocale($raw_display, SugarCurrency::getBaseCurrency()->id);
             }
         } else {
             $raw_display = $display;
         }
         if (isset($display_column['type']) && $display_column['type'] == 'float') {
             $display = $this->layout_manager->widgetDisplay($display_column);
         }
         if (isset($display_column['type'])) {
             $alias = $this->alias_lookup[$display_column['table_key']];
             $array_key = strtoupper($alias . '__count');
             if (array_key_exists($array_key, $display_column['fields'])) {
                 $displayData = $display_column['fields'][$array_key];
                 if (empty($displayData) && $display_column['type'] != 'bool' && ($display_column['type'] != 'enum' || $display_column['type'] == 'enum' && $displayData != '0')) {
                     $display = "";
                 }
             }
             // if
             $module_bean = BeanFactory::getBean($this->module);
             if (is_array($module_bean->field_defs)) {
                 if (isset($module_bean->field_defs[$display_column['type']])) {
                     if (isset($module_bean->field_defs[$display_column['type']]['options'])) {
                         $trans_options = translate($module_bean->field_defs[$display_column['type']]['options']);
                         if (isset($trans_options[$display_column['fields'][$field_name]])) {
                             $display = $trans_options[$display_column['fields'][$field_name]];
                         }
                     }
                 }
             }
         }
         // if
         //  for charts
         if ($column_field_name == 'summary_columns' && $this->do_chart) {
             //_pp($display);
             $raw_value = "";
             $keys = array_keys($fields);
             foreach ($this->report_def['summary_columns'] as $index => $column) {
                 if ($column['name'] == $display_column['name'] && isset($keys[$index]) && isset($fields[$keys[$index]])) {
                     $raw_value = $fields[$keys[$index]];
                     break;
                 }
             }
             $cell_arr = array('val' => $raw_display, 'key' => $display_column['column_key'], 'raw_value' => $raw_value);
             //_pp($cell_arr);
             array_push($chart_cells, $cell_arr);
         }
         if ($exporting) {
             global $app_list_strings;
             // parse out checkboxes
             // TODO: wp this should be done in the widget
             if (preg_match('/type.*=.*checkbox/Uis', $display)) {
                 if (preg_match('/checked/i', $display)) {
                     $display = $app_list_strings['dom_switch_bool']['on'];
                 } else {
                     $display = $app_list_strings['dom_switch_bool']['off'];
                 }
             }
         }
         array_push($cells, $display);
     }
     // END foreach
     $row['cells'] = $cells;
     // calculate summary rows count as the product of all count fields in summary
     $count = 1;
     $count_exists = false;
     foreach ($db_row as $count_column => $count_value) {
         if (substr($count_column, -10) == "__allcount" || $count_column == 'count') {
             $count *= max($count_value, 1);
             $count_exists = true;
         }
     }
     if ($count_exists) {
         $row['count'] = $count;
     }
     // for charts
     if ($column_field_name == 'summary_columns' && $this->do_chart) {
         $chart_row = 0;
         if (!empty($db_row['count'])) {
             $chart_row = array('cells' => $chart_cells, 'count' => $db_row['count']);
         } else {
             $chart_row = array('cells' => $chart_cells);
         }
         array_push($this->chart_rows, $chart_row);
     }
     if ($column_field_name == 'summary_columns' && isset($this->chart_group_position) && isset($this->group_header)) {
         $row['group_pos'] = $this->chart_group_position;
         $row['group_header'] = $this->group_header;
         $row['group_column_is_invisible'] = $this->group_column_is_invisible;
     }
     return $row;
 }