Exemplo n.º 1
0
	function testNiceFormatting() {
		// Test a bunch of different data values and results in Nice() and Whole()
		$tests = array(
			// Test basic operation
			'$50.00' => array('$50.00', '$50'),
			
			// Test removal of junk text
			'this is -50.29 dollars' => array('($50.29)', '($50)'),
			'this is -50.79 dollars' => array('($50.79)', '($51)'),
			'this is 50.79 dollars' => array('$50.79', '$51'),
			
			// Test negative numbers
			'-1000' => array('($1,000.00)','($1,000)'),
			'-$2,000' => array('($2,000.00)', '($2,000)'),
			
			// Test thousands comma
			'5000' => array('$5,000.00', '$5,000'),
			
			// Test scientific notation
			'5.68434188608E-14' => array('$0.00', '$0'),
			'5.68434188608E7' => array('$56,843,418.86', '$56,843,419'),
			"Sometimes Es are still bad: 51 dollars, even though they\'re used in scientific notation" => array('$51.00', '$51'),
			"What about 5.68434188608E7 in the middle of a string" => array('$56,843,418.86', '$56,843,419'),
		);
		
		foreach($tests as $value => $niceValues) {
			$c = new Currency('MyField');
			$c->setValue($value);
			$this->assertEquals($niceValues[0], $c->Nice());
			$this->assertEquals($niceValues[1], $c->Whole());
		}
	}	
 /**
  * @see DashletGenericChart::display()
  */
 public function display()
 {
     global $current_user, $sugar_config;
     require "modules/Charts/chartdefs.php";
     $chartDef = $chartDefs['lead_source_by_outcome'];
     require_once 'include/SugarCharts/SugarChartFactory.php';
     $sugarChart = SugarChartFactory::getInstance();
     $sugarChart->is_currency = true;
     $currency_symbol = $sugar_config['default_currency_symbol'];
     if ($current_user->getPreference('currency')) {
         $currency = new Currency();
         $currency->retrieve($current_user->getPreference('currency'));
         $currency_symbol = $currency->symbol;
     }
     $subtitle = translate('LBL_OPP_SIZE', 'Charts') . " " . $currency_symbol . "1" . translate('LBL_OPP_THOUSANDS', 'Charts');
     $sugarChart->setProperties('', $subtitle, $chartDef['chartType']);
     $sugarChart->base_url = $chartDef['base_url'];
     $sugarChart->group_by = $chartDef['groupBy'];
     $sugarChart->url_params = array();
     if (count($this->lsbo_ids) > 0) {
         $sugarChart->url_params['assigned_user_id'] = array_values($this->lsbo_ids);
     }
     $sugarChart->getData($this->constuctQuery());
     $sugarChart->data_set = $sugarChart->sortData($sugarChart->data_set, 'lead_source', true, 'sales_stage', true, true);
     $xmlFile = $sugarChart->getXMLFileName($this->id);
     $sugarChart->saveXMLFile($xmlFile, $sugarChart->generateXML());
     return $this->getTitle('<div align="center"></div>') . '<div align="center">' . $sugarChart->display($this->id, $xmlFile, '100%', '480', false) . '</div>' . $this->processAutoRefresh();
 }
Exemplo n.º 3
0
 /**
  * @param money $amount
  * @return money
  */
 public function add(Money $amount)
 {
     if (!$this->currency->equals($amount->getCurrency())) {
         throw new \InvalidArgumentException('Currency mismatch');
     }
     return new Money($this->currency, $this->amount + $amount->getValue());
 }
 public function __construct($controller, $name = "PostagePaymentForm")
 {
     // Get delivery data and postage areas from session
     $delivery_data = Session::get("Commerce.DeliveryDetailsForm.data");
     $country = $delivery_data['DeliveryCountry'];
     $postcode = $delivery_data['DeliveryPostCode'];
     $postage_areas = $controller->getPostageAreas($country, $postcode);
     // Loop through all postage areas and generate a new list
     $postage_array = array();
     foreach ($postage_areas as $area) {
         $area_currency = new Currency("Cost");
         $area_currency->setValue($area->Cost);
         $postage_array[$area->ID] = $area->Title . " (" . $area_currency->Nice() . ")";
     }
     $postage_id = Session::get('Commerce.PostageID') ? Session::get('Commerce.PostageID') : 0;
     // Setup postage fields
     $postage_field = CompositeField::create(HeaderField::create("PostageHeader", _t('Commerce.Postage', "Postage")), OptionsetField::create("PostageID", _t('Commerce.PostageSelection', 'Please select your prefered postage'), $postage_array)->setValue($postage_id))->setName("PostageFields")->addExtraClass("unit")->addExtraClass("size1of2")->addExtraClass("unit-50");
     // Get available payment methods and setup payment
     $payment_methods = SiteConfig::current_site_config()->PaymentMethods();
     // Deal with payment methods
     if ($payment_methods->exists()) {
         $payment_map = $payment_methods->map('ID', 'Label');
         $payment_value = $payment_methods->filter('Default', 1)->first()->ID;
     } else {
         $payment_map = array();
         $payment_value = 0;
     }
     $payment_field = CompositeField::create(HeaderField::create('PaymentHeading', _t('Commerce.Payment', 'Payment'), 2), OptionsetField::create('PaymentMethodID', _t('Commerce.PaymentSelection', 'Please choose how you would like to pay'), $payment_map, $payment_value))->setName("PaymentFields")->addExtraClass("unit")->addExtraClass("size1of2")->addExtraClass("unit-50");
     $fields = FieldList::create(CompositeField::create($postage_field, $payment_field)->setName("PostagePaymentFields")->addExtraClass("units-row")->addExtraClass("line"));
     $back_url = $controller->Link("billing");
     $actions = FieldList::create(LiteralField::create('BackButton', '<a href="' . $back_url . '" class="btn btn-red commerce-action-back">' . _t('Commerce.Back', 'Back') . '</a>'), FormAction::create('doContinue', _t('Commerce.PaymentDetails', 'Enter Payment Details'))->addExtraClass('btn')->addExtraClass('commerce-action-next')->addExtraClass('btn-green'));
     $validator = RequiredFields::create(array("PostageID", "PaymentMethod"));
     parent::__construct($controller, $name, $fields, $actions, $validator);
 }
 public static function setUpBeforeClass()
 {
     parent::setUpBeforeClass();
     $super = User::getByUsername('super');
     $bobby = UserTestHelper::createBasicUser('bobby');
     $sarah = UserTestHelper::createBasicUser('sarah');
     self::$superUserId = $super->id;
     self::$bobbyUserId = $bobby->id;
     self::$sarahUserId = $sarah->id;
     $currency = Currency::makeBaseCurrency();
     assert($currency->code == 'USD');
     // Not Coding Standard
     self::$baseCurrencyId = $currency->id;
     $currency = new Currency();
     $currency->code = 'EUR';
     $currency->rateToBase = 2;
     assert($currency->save());
     // Not Coding Standard
     self::$eurCurrencyId = $currency->id;
     $values = array('A1', 'B2', 'C3', 'D4', 'E5', 'F6');
     $fieldData = CustomFieldData::getByName('WorkflowTestDropDown');
     $fieldData->serializedData = serialize($values);
     $saved = $fieldData->save();
     assert($saved);
     // Not Coding Standard
     $values = array('A1', 'B2', 'C3', 'D4', 'E5', 'F6');
     $fieldData = CustomFieldData::getByName('WorkflowTestRadioDropDown');
     $fieldData->serializedData = serialize($values);
     $saved = $fieldData->save();
     assert($saved);
     // Not Coding Standard
     $values = array('M1', 'M2', 'M3', 'M4', 'M5', 'M6');
     $fieldData = CustomFieldData::getByName('WorkflowTestMultiDropDown');
     $fieldData->serializedData = serialize($values);
     $saved = $fieldData->save();
     assert($saved);
     // Not Coding Standard
     $values = array('M1', 'M2', 'M3', 'M4', 'M5', 'M6');
     $fieldData = CustomFieldData::getByName('WorkflowTestTagCloud');
     $fieldData->serializedData = serialize($values);
     $saved = $fieldData->save();
     assert($saved);
     // Not Coding Standard
     $loaded = ContactsModule::loadStartingData();
     assert($loaded);
     // Not Coding Standard
     $contactStates = ContactState::getByName('New');
     self::$newState = $contactStates[0];
     $contactStates = ContactState::getByName('In progress');
     self::$inProgressState = $contactStates[0];
     self::$groupTest = new Group();
     self::$groupTest->name = 'test';
     $saved = self::$groupTest->save();
     assert($saved);
     // Not Coding Standard
     $group = Group::getByName(Group::EVERYONE_GROUP_NAME);
     $saved = $group->save();
     assert($saved);
     // Not Coding Standard
 }
Exemplo n.º 6
0
 /**
  * {@inheritdoc}
  */
 public function contains(Currency $currency)
 {
     if (null === self::$currencies) {
         self::$currencies = $this->requireCurrencies();
     }
     return array_key_exists($currency->getCode(), self::$currencies);
 }
 public function display()
 {
     $currency_symbol = $GLOBALS['sugar_config']['default_currency_symbol'];
     if ($GLOBALS['current_user']->getPreference('currency')) {
         require_once 'modules/Currencies/Currency.php';
         $currency = new Currency();
         $currency->retrieve($GLOBALS['current_user']->getPreference('currency'));
         $currency_symbol = $currency->symbol;
     }
     $this->chartDefName = $this->which_chart[0];
     //$chartDef = $this->chartDefs[$this->chartDefName];
     $chartDef = array('type' => 'code', 'id' => 'Chart_invoices_by_month', 'label' => 'Invoices by Month', 'chartUnits' => 'Invoice Size in $1K', 'chartType' => 'stacked group by chart', 'groupBy' => array('m', 'state_in_chart'), 'base_url' => array('module' => 'reg_invoices', 'action' => 'index', 'query' => 'true', 'searchFormTab' => 'advanced_search'), 'url_params' => array('state', 'date_closed'));
     require_once 'include/SugarCharts/SugarChartFactory.php';
     // Special chart config for RegInvoices
     $sugarChart = SugarChartFactory::getInstance('Jit', 'RegInvoices');
     $sugarChart->setProperties('', translate('LBL_FACT_SIZE', 'reg_invoices') . ' ' . $currency_symbol . '1' . translate('LBL_OPP_THOUSANDS', 'Charts'), $chartDef['chartType']);
     $sugarChart->base_url = $chartDef['base_url'];
     $sugarChart->is_currency = true;
     $sugarChart->group_by = $chartDef['groupBy'];
     $sugarChart->url_params = array();
     $sugarChart->getData($this->constructQuery());
     $this->sortData($sugarChart->data_set);
     $xmlFile = $sugarChart->getXMLFileName($this->id);
     $sugarChart->saveXMLFile($xmlFile, $sugarChart->generateXML());
     return $this->getTitle('<div align="center"></div>') . '<div align="center">' . $sugarChart->display($this->id, $xmlFile, '100%', '480', false) . '</div><br />';
 }
Exemplo n.º 8
0
 public function test_formats_amount_3()
 {
     $eur = new Currency('EUR');
     $this->assertEquals('560,00', $eur->format(new Decimal2('560.00')));
     $this->assertEquals('-1.560,00', $eur->format(new Decimal2('-1560.00')));
     $this->assertEquals('-100.000.000.000,00', $eur->format(new Decimal2('-100000000000.00')));
 }
 function handleUpdate()
 {
     global $current_user;
     if ($current_user->is_admin) {
         if (isset($_POST['id']) && !empty($_POST['id']) && isset($_POST['name']) && !empty($_POST['name']) && isset($_POST['rate']) && !empty($_POST['rate']) && isset($_POST['symbol']) && !empty($_POST['symbol'])) {
             $ids = $_POST['id'];
             $names = $_POST['name'];
             $symbols = $_POST['symbol'];
             $rates = $_POST['rate'];
             $isos = $_POST['iso'];
             $size = sizeof($ids);
             if ($size != sizeof($names) || $size != sizeof($isos) || $size != sizeof($symbols) || $size != sizeof($rates)) {
                 return;
             }
             require_once 'modules/Currencies/Currency.php';
             $temp = new Currency();
             for ($i = 0; $i < $size; $i++) {
                 $temp->id = $ids[$i];
                 $temp->name = $names[$i];
                 $temp->symbol = $symbols[$i];
                 $temp->iso4217 = $isos[$i];
                 $temp->conversion_rate = $rates[$i];
                 $temp->save();
             }
         }
     }
 }
 /**
  * @param Currency $from
  * @param Currency $to
  * @return string
  * @throws \RuntimeException
  */
 public function getConversionMultiplier(Currency $from, Currency $to)
 {
     $rates = $this->getConversionRatesTable($from);
     if (!isset($rates[$to->getCode()])) {
         throw new \RuntimeException(sprintf('The target currency "%s" is not present in the conversion rates table.', $to->getCode()));
     }
     return $rates[$to->getCode()];
 }
Exemplo n.º 11
0
 public function orderByPrice(Currency $currency, $direction = 'ASC')
 {
     if ('ASC' != $direction) {
         $direction = 'DESC';
     }
     $currency->defineProductJoin($this->selectFilter);
     $this->selectFilter->setOrder(new ARFieldHandle($currency->getJoinAlias(), 'price'), $direction);
 }
Exemplo n.º 12
0
 /**
  * Create an object or return existing one.
  *
  * <code>
  * $currencyId = 1;
  *
  * $currency   = Crowdfunding\Currency::getInstance(\JFactory::getDbo(), $currencyId);
  * </code>
  *
  * @param \JDatabaseDriver $db
  * @param int             $id
  *
  * @return null|self
  */
 public static function getInstance(\JDatabaseDriver $db, $id)
 {
     if (!isset(self::$instances[$id])) {
         $item = new Currency($db);
         $item->load($id);
         self::$instances[$id] = $item;
     }
     return self::$instances[$id];
 }
 /**
  * {@inheritdoc}
  */
 public function convertToPHPValue($value, AbstractPlatform $platform)
 {
     if (!array_key_exists($value, Intl::getCurrencyBundle()->getCurrencyNames())) {
         throw new \RuntimeException(sprintf("'%d' is not a supported currency.", $value));
     }
     $currency = new Currency();
     $currency->setLabel($value);
     return $currency;
 }
Exemplo n.º 14
0
 function display()
 {
     global $app_list_strings;
     $this->ss->assign('APP_LIST', $app_list_strings);
     if (isset($_REQUEST['mode']) && $_REQUEST['mode'] == 'set_target') {
         require_once 'modules/Campaigns/utils.php';
         //call function to create campaign logs
         $mess = track_campaign_prospects($this->bean);
         $confirm_msg = "var ajax_C_LOG_Status = new SUGAR.ajaxStatusClass(); \n            window.setTimeout(\"ajax_C_LOG_Status.showStatus('" . $mess . "')\",1000); \n            window.setTimeout('ajax_C_LOG_Status.hideStatus()', 1500); \n            window.setTimeout(\"ajax_C_LOG_Status.showStatus('" . $mess . "')\",2000); \n            window.setTimeout('ajax_C_LOG_Status.hideStatus()', 5000); ";
         $this->ss->assign("MSG_SCRIPT", $confirm_msg);
     }
     if ($this->bean->campaign_type == 'Email' || $this->bean->campaign_type == 'NewsLetter') {
         $this->ss->assign("ADD_BUTTON_STATE", "submit");
         $this->ss->assign("TARGET_BUTTON_STATE", "hidden");
     } else {
         $this->ss->assign("ADD_BUTTON_STATE", "hidden");
         $this->ss->assign("DISABLE_LINK", "display:none");
         $this->ss->assign("TARGET_BUTTON_STATE", "submit");
     }
     $currency = new Currency();
     if (isset($this->bean->currency_id) && !empty($this->bean->currency_id)) {
         $currency->retrieve($this->bean->currency_id);
         if ($currency->deleted != 1) {
             $this->ss->assign('CURRENCY', $currency->iso4217 . ' ' . $currency->symbol);
         } else {
             $this->ss->assign('CURRENCY', $currency->getDefaultISO4217() . ' ' . $currency->getDefaultCurrencySymbol());
         }
     } else {
         $this->ss->assign('CURRENCY', $currency->getDefaultISO4217() . ' ' . $currency->getDefaultCurrencySymbol());
     }
     parent::display();
     //We want to display subset of available, panels, so we will call subpanel
     //object directly instead of using sugarview.
     $GLOBALS['focus'] = $this->bean;
     require_once 'include/SubPanel/SubPanelTiles.php';
     $subpanel = new SubPanelTiles($this->bean, $this->module);
     //get available list of subpanels
     $alltabs = $subpanel->subpanel_definitions->get_available_tabs();
     if (!empty($alltabs)) {
         //iterate through list, and filter out all but 3 subpanels
         foreach ($alltabs as $key => $name) {
             if ($name != 'prospectlists' && $name != 'emailmarketing' && $name != 'tracked_urls') {
                 //exclude subpanels that are not prospectlists, emailmarketing, or tracked urls
                 $subpanel->subpanel_definitions->exclude_tab($name);
             }
         }
         //only show email marketing subpanel for email/newsletter campaigns
         if ($this->bean->campaign_type != 'Email' && $this->bean->campaign_type != 'NewsLetter') {
             //exclude emailmarketing subpanel if not on an email or newsletter campaign
             $subpanel->subpanel_definitions->exclude_tab('emailmarketing');
             // Bug #49893  - 20120120 - Captivea (ybi) - Remove trackers subpanels if not on an email/newsletter campaign (useless subpannl)
             $subpanel->subpanel_definitions->exclude_tab('tracked_urls');
         }
     }
     //show filtered subpanel list
     echo $subpanel->display();
 }
Exemplo n.º 15
0
function perform_save(&$focus)
{
    //US DOLLAR
    if (isset($focus->amount) && !number_empty($focus->amount)) {
        $currency = new Currency();
        $currency->retrieve($focus->currency_id);
        $focus->amount_usdollar = $currency->convertToDollar($focus->amount);
    }
}
 public function actionDate($date = null)
 {
     $model = new Currency('search');
     $model->unsetAttributes();
     if (isset($_GET['Currency'])) {
         $model->setAttributes($_GET['Currency']);
     }
     $model->date = date('Y-m-d', strtotime($date));
     $this->render('index', ['baseUrl' => Yii::app()->urlManager->createUrl('currency/currencyAdmin/index'), 'refreshUrl' => Yii::app()->urlManager->createUrl('currency/currencyAdmin/parse'), 'date' => $date, 'model' => $model]);
 }
 /**
  * @param Currency $currency
  * @return array
  */
 public function getConversionRatesTable(Currency $currency)
 {
     switch ($currency->getCode()) {
         case 'USD':
             return array('USD' => '1', 'ZAR' => '12.07682');
         default:
             // ZAR
             return array('USD' => '0.082776', 'ZAR' => '1');
     }
 }
function perform_save(&$focus)
{
    require_once 'modules/Currencies/Currency.php';
    //US DOLLAR
    if (isset($focus->price) && !number_empty($focus->price)) {
        $currency = new Currency();
        $currency->retrieve($focus->currency_id);
        $focus->price_usdollar = $currency->convertToDollar(unformat_number($focus->price));
    }
}
Exemplo n.º 19
0
 /**
  * Get available currency.
  * 
  */
 public static function getAvailableCurrencyAsArray()
 {
     $table = new Currency();
     $where = $table->select()->where("enabled=?", true);
     $currencies = $table->fetchAll($where);
     $arr = array();
     foreach ($currencies as $currency) {
         $arr[$currency->id] = $currency->display_cn;
     }
     return $arr;
 }
 /**
  * Overriding display of value of currency because of currencies are not stored in app_list_strings
  *
  * @param array $layout_def
  * @return string for display
  */
 public function &displayListPlain($layout_def)
 {
     static $currencies;
     $value = $this->_get_list_value($layout_def);
     if (empty($currencies[$value])) {
         $currency = new Currency();
         $currency->retrieve($value);
         $currencies[$value] = $currency->symbol . ' ' . $currency->iso4217;
     }
     return $currencies[$value];
 }
Exemplo n.º 21
0
 public static function parse($date)
 {
     $date = date('Y-m-d', strtotime($date));
     require_once 'sources/CurrencySourceBase.php';
     /** @var CurrencyRaw[][] $data */
     $data = [];
     $codes = [];
     foreach (static::$sources as $lang => $sourceClass) {
         require_once 'sources/' . $sourceClass . '.php';
         /** @var CurrencySourceBase $source */
         $source = new $sourceClass();
         $data[$lang] = $source->parse($date);
         $codes = array_merge($codes, array_keys($data[$lang]));
     }
     //        CVarDumper::dump($data, 3, 1);return;
     if (isset($data['ru'][self::UAH_CODE])) {
         $costRubUah = $data['ru'][self::UAH_CODE]->cost;
     } else {
         throw new Exception('Cost RUB:UAH not found');
     }
     $tr = Yii::app()->db->beginTransaction();
     Currency::model()->deleteAll('date = :date', [':date' => $date]);
     foreach ($codes as $code) {
         try {
             /** @var CurrencyRaw $ru */
             /** @var CurrencyRaw $ua */
             $ru = empty($data['ru']) == false && empty($data['ru'][$code]) == false ? $data['ru'][$code] : null;
             $ua = empty($data['ua']) == false && empty($data['ua'][$code]) == false ? $data['ua'][$code] : null;
             if (!$ru && !$ua) {
                 continue;
             }
             $currency = new Currency();
             $currency->date = $date;
             $currency->num_code = $code;
             $currency->char_code = $ru ? $ru->char_code : $ua->char_code;
             $currency->name_ru = $ru ? $ru->name : null;
             $currency->name_ua = $ua ? $ua->name : null;
             $currency->nominal_ru = $ru ? $ru->nominal : null;
             $currency->nominal_ua = $ua ? $ua->nominal : null;
             $currency->cost_rub = $ru ? $ru->cost / $currency->nominal_ru : null;
             $currency->cost_uah = $ua ? $ua->cost / $currency->nominal_ua : null;
             $currency->diff = $ru && $ua ? $currency->cost_uah / $costRubUah - $currency->cost_rub : null;
             if ($currency->save(true) == false) {
                 //                    CVarDumper::dump([$currency->getAttributes(), $currency->errors], 3, 1);
                 //                    $tr->rollback();
                 //                    throw new Exception('Con not save currency in DB');
             }
         } catch (Exception $ex) {
             continue;
         }
     }
     $tr->commit();
     return true;
 }
 protected function getValues($quote)
 {
     $values = array();
     $currency = new Currency($this->access_key);
     foreach ($this->historical as $key => $date) {
         $response = $currency->historical(array('date' => $key, 'currencies' => $this->actions[$quote]['currencies']));
         if ($response['success']) {
             $values[$date] = $quote == 'USDBRL' ? $response['quotes']['USDBRL'] : 1.0 / ($response['quotes'][$quote] / $response['quotes']['USDBRL']);
         }
     }
     return $values;
 }
Exemplo n.º 23
0
 public function CalGas(GasPlan &$plan)
 {
     $daily = $plan->DailyCharge;
     $rate = $plan->Rate;
     $ppd = $plan->PPD;
     $amount = $this->gasAmount;
     $value = ($daily * 30 / 100 + $rate * $amount) * 1.15 * (1 - $ppd);
     $cost = new Currency();
     $cost->setValue($value);
     $plan->cost = $cost;
     return $plan;
 }
Exemplo n.º 24
0
 protected function saveRates($currencies, $rates)
 {
     $currency_model = new Currency();
     foreach ($rates as $rate) {
         $code_from = substr($rate['id'], 0, 3);
         $currency_from = $currencies[$code_from];
         $currency_to = $currency_model->getCurrencyByCode($this->currency_to);
         // getting GMT datetime.
         $date = date('Y-m-d H:i:s', strtotime($rate['Date'] . ' ' . $rate['Time'] . ' -1 hour'));
         $currency_rate_model = new CurrencyRate();
         $data = array('curr_from_id' => $currency_from->id, 'curr_to_id' => $currency_to->id, 'rate' => floatval($rate['Rate']), 'date' => $date, 'source_url' => 'http://query.yahooapis.com/v1/public/yql', 'created' => date('Y-m-d H:i:s'));
         $currency_rate_model->insert($data);
     }
 }
Exemplo n.º 25
0
function get_currency()
{
    global $current_user, $global_currency_obj;
    if (empty($global_currency_obj)) {
        $global_currency_obj = new Currency();
        //  $global_currency_symbol = '$';
        if ($current_user->getPreference('currency')) {
            $global_currency_obj->retrieve($current_user->getPreference('currency'));
        } else {
            $global_currency_obj->retrieve('-99');
        }
    }
    return $global_currency_obj;
}
Exemplo n.º 26
0
 public function _new()
 {
     $flash = Flash::Instance();
     $errors = array();
     $currency = new Currency();
     if ($currency->getCount() == 0) {
         $errors[] = 'No Currencies defined';
     }
     if (count($errors) > 0) {
         $flash->addErrors($errors);
         sendback();
     }
     parent::_new();
 }
Exemplo n.º 27
0
 function save($check_notify = FALSE)
 {
     //"amount_usdollar" is really amount_basecurrency. We need to save a copy of the amount in the base currency.
     if (isset($this->amount) && !number_empty($this->amount)) {
         if (!number_empty($this->currency_id)) {
             $currency = new Currency();
             $currency->retrieve($this->currency_id);
             $this->amount_usdollar = $currency->convertToDollar($this->amount);
         } else {
             $this->amount_usdollar = $this->amount;
         }
     }
     return parent::save($check_notify);
 }
Exemplo n.º 28
0
 /**
  * ajax
  */
 public function refreshratesAction()
 {
     if ($this->getRequest()->getQuery('ajax') == 1 || $this->getRequest()->isXmlHttpRequest()) {
         $params = $this->getRequest()->getParams();
         $result = false;
         $rates_refresher = new RatesRefresherYahoo();
         $rates_refresher->refreshRates();
         $currency_model = new Currency();
         $currencies = $currency_model->getActiveCurrencies();
         $currency_model->loadRates($currencies, 'RUB');
         $result = $currencies;
         $this->_helper->json($result);
     }
 }
Exemplo n.º 29
0
 function populateCurrency()
 {
     global $mod_strings;
     require_once 'modules/Currencies/Currency.php';
     $currency = new Currency();
     $currText = '';
     if (isset($this->bean->currency_id) && !empty($this->bean->currency_id)) {
         $currency->retrieve($this->bean->currency_id);
         if ($currency->deleted != 1) {
             $currText = $currency->iso4217 . ' ' . $currency->symbol;
         } else {
             $currText = $currency->getDefaultISO4217() . ' ' . $currency->getDefaultCurrencySymbol();
         }
     } else {
         $currText = $currency->getDefaultISO4217() . ' ' . $currency->getDefaultCurrencySymbol();
     }
     $javascript = "<script language='javascript'>\n";
     $javascript .= "var CurrencyText = new Array(); \n";
     $javascript .= "CurrencyText['-99'] = '" . $currency->getDefaultISO4217() . ' ' . $currency->getDefaultCurrencySymbol() . "';\n";
     $sql = "SELECT id, iso4217, symbol FROM currencies";
     $res = $this->bean->db->query($sql);
     while ($row = $this->bean->db->fetchByAssoc($res)) {
         $javascript .= "CurrencyText['" . $row['id'] . "'] = '" . $row['iso4217'] . ' ' . $row['symbol'] . "';\n";
     }
     $javascript .= "</script>";
     echo $javascript;
     $this->ss->assign('CURRENCY', "<div id =curr_symbol>{$currText}</div>");
     $mod_strings['LBL_LIST_PRICE'] .= " (" . $currText . ")";
     $mod_strings['LBL_UNIT_PRICE'] .= " (" . $currText . ")";
     $mod_strings['LBL_VAT_AMT'] .= " (" . $currText . ")";
     $mod_strings['LBL_TOTAL_PRICE'] .= " (" . $currText . ")";
     $mod_strings['LBL_SERVICE_PRICE'] .= " (" . $currText . ")";
 }
Exemplo n.º 30
0
 private function default_fields($search_data)
 {
     $slcustomer = new SLCustomer();
     // Name
     $this->addSearchField('name', 'name_contains', 'contains');
     // Search by Active/Inactive Status
     $this->addSearchField('date_inactive', 'Show Customers', 'null', 'null', 'advanced');
     $options = array('' => 'All', 'not null' => 'Inactive', 'null' => 'Active');
     $this->setOptions('date_inactive', $options);
     // Currency
     $this->addSearchField('currency_id', 'currency', 'select', '', 'advanced');
     $currency = new Currency();
     $currency_list = $currency->getAll();
     $options = array('' => 'All');
     $options += $currency_list;
     $this->SetOptions('currency_id', $options);
     // Remittance
     $this->addSearchField('statement', 'statement', 'select', '', 'advanced');
     $options = array('' => 'All', 'TRUE' => 'Yes', 'FALSE' => 'No');
     $this->setOptions('statement', $options);
     // Invoice Method
     $this->addSearchField('invoice_method', 'invoice_method', 'select', '', 'advanced');
     $options = array_merge(array('' => 'All'), $slcustomer->getEnumOptions('invoice_method'));
     $this->setOptions('invoice_method', $options);
     // Payment Type
     $this->addSearchField('payment_type_id', 'payment_type', 'select', '', 'advanced');
     $payment_type = new PaymentType();
     $options = array('' => 'All');
     $options += $payment_type->getAll();
     $this->setOptions('payment_type_id', $options);
     // Payment Terms
     $this->addSearchField('payment_term_id', 'payment_term', 'select', '', 'advanced');
     $payment_term = new PaymentTerm();
     $options = array('' => 'All');
     $options = $payment_term->getAll();
     asort($options);
     $options = array('' => 'All') + $options;
     $this->setOptions('payment_term_id', $options);
     // SL Anaylsis
     $this->addSearchField('sl_analysis_id', 'sl_analysis', 'select', '', 'advanced');
     $sl_analysis = new SLAnalysis();
     $options = array('' => 'All');
     $options += $sl_analysis->getAll();
     $this->setOptions('sl_analysis_id', $options);
     // Account Status
     $this->addSearchField('account_status', 'account_status', 'select', '', 'advanced');
     $options = array_merge(array('' => 'All'), $slcustomer->getEnumOptions('account_status'));
     $this->setOptions('account_status', $options);
 }