/** * Update existing route * * @param void * @return null */ function edit() { if ($this->active_currency->isNew()) { $this->httpError(HTTP_ERR_NOT_FOUND); } // if $currency_data = $this->request->post('currency'); if (!is_array($currency_data)) { $currency_data = array('name' => $this->active_currency->getName(), 'code' => $this->active_currency->getCode(), 'default_rate' => $this->active_currency->getDefaultRate()); } // if $this->smarty->assign('currency_data', $currency_data); if ($this->request->isSubmitted()) { $this->active_currency->setAttributes($currency_data); $save = $this->active_currency->save(); if ($save && !is_error($save)) { flash_success('Currency ":name" has been updated', array('name' => $this->active_currency->getName())); $this->redirectTo('admin_currencies'); } else { $this->smarty->assign('errors', $save); } // if } // if }
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(); } } } }
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 }
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; }
public function tearDown() { global $sugar_config; $this->currency_system->symbol = $this->backupSymbol; $this->currency_system->save(false); $sugar_config['default_currency_symbol'] = $this->backupSymbol; format_number(0, 0, 0, array('currency_id' => $this->currency_51568->id, 'currency_symbol' => $this->currency_51568->symbol)); format_number(0, 0, 0, array('currency_id' => -99, 'currency_symbol' => $this->currency_51568->getDefaultCurrencySymbol())); $this->currency_51568->mark_deleted($this->currency_51568->id); SugarTestHelper::tearDown(); get_number_seperators(true); }
public function actionCreate() { $model = new Currency(); if (isset($_POST['Currency'])) { $model->attributes = $_POST['Currency']; if ($model->validate() && $model->save()) { $this->redirect(array('index')); } } $statusOptions = array(0 => Yii::t('common', 'Disabled'), 1 => Yii::t('common', 'Enabled')); $this->render('create', array('model' => $model, 'statusOptions' => $statusOptions)); }
/** * Store a newly created currency in storage. * * @return Response */ public function store() { $validator = Validator::make($data = Input::all(), Currency::$rules); if ($validator->fails()) { return Redirect::back()->withErrors($validator)->withInput(); } $currency = new Currency(); $currency->name = Input::get('name'); $currency->shortname = Input::get('shortname'); $currency->save(); Audit::logaudit('Currency', 'create', 'created: ' . $currency->name); return Redirect::route('currencies.index'); }
/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $model = new Currency(); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['Currency'])) { $model->attributes = $_POST['Currency']; if ($model->save()) { $this->redirect(array('admin')); } } $this->render('create', array('model' => $model)); }
public static function createCurrency($attributes) { $currency = new Currency(); if (!empty($attributes['id'])) { $currency->new_with_id = true; $currency->id = $attributes['id']; unset($attributes['id']); } foreach ($attributes as $attribute => $value) { $currency->{$attribute} = $value; } $currency->save(); self::$createdCurrencies[] = $currency; return $currency; }
public function testCreateCurrencyAndIsActiveByDefaultAndSettingActiveToFalse() { $currency = new Currency(); $currency->code = 'EUR'; $currency->rateToBase = 2; $this->assertTrue($currency->save()); $currency->forget(); $currency = Currency::getByCode('EUR'); $this->assertEquals(1, $currency->active); $currency->active = false; $this->assertTrue($currency->save()); $currency->forget(); $currency = Currency::getByCode('EUR'); $this->assertEquals(0, $currency->active); }
/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $model = new Currency(); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['Currency'])) { $model->attributes = $_POST['Currency']; $model->created_on = date('Y-m-d'); $model->created_by = Yii::app()->user->id; if ($model->save()) { Yii::app()->user->setFlash('success', 'Saved successfully'); $this->redirect(array('view', 'id' => $model->id)); } } $this->render('create', array('model' => $model)); }
protected function getCurrencies() { $wikipedia = $this->web->get(sfConfig::get('app_source_currencies'), null, array('User-Agent' => 'Steve Lacey <*****@*****.**>', 'Cache-Control' => 'no-cache')); $xml = new SimpleXMLElement($wikipedia->getResponseText()); $article = $xml->page->revision->text; $table = substr($article, strpos($article, '{|'), strpos($article, '|}') - strpos($article, '{|')); foreach (explode('-| ', str_replace(array('[', ']', "\n"), '', $table)) as $row) { $row = explode(' || ', trim($row, '| ')); if (isset($row[2], $row[4]) && is_numeric($row[2])) { $currency = new Currency(); $currency->setCode(sfConfig::get('app_currency_alias_' . $row[0], $row[0])); $currency->setNumber($row[1]); $currency->setDigits(ceil($row[2])); $currency->setName($row[3]); $currency->save(); } } }
protected function execute($arguments = array(), $options = array()) { // initialize the database connection $databaseManager = new sfDatabaseManager($this->configuration); $connection = $databaseManager->getDatabase($options['connection'])->getConnection(); // update rates list($rates) = $this->getRates(); foreach ($rates as $rateInfo) { list($code, $rate) = $rateInfo; $currency = Doctrine_Core::getTable('Currency')->findOneByCode($code); if (!$currency) { $currency = new Currency(); $currency->code = $code; } $currency->rate = $rate; $currency->save(); } $this->logSection('payment', 'Exchange rates have been updated.'); }
/** * Performs the work of inserting or updating the row in the database. * * If the object is new, it inserts it; otherwise an update is performed. * All related objects are also updated in this method. * * @param PropelPDO $con * @return int The number of rows affected by this insert/update and any referring fk objects' save() operations. * @throws PropelException * @see save() */ protected function doSave(PropelPDO $con) { $affectedRows = 0; // initialize var to track total num of affected rows if (!$this->alreadyInSave) { $this->alreadyInSave = true; // We call the save method on the following object(s) if they // were passed to this object by their coresponding set // method. This object relates to these object(s) by a // foreign key reference. if ($this->aCurrency !== null) { if ($this->aCurrency->isModified() || $this->aCurrency->isNew()) { $affectedRows += $this->aCurrency->save($con); } $this->setCurrency($this->aCurrency); } if ($this->isNew() || $this->isModified()) { // persist changes if ($this->isNew()) { $this->doInsert($con); } else { $this->doUpdate($con); } $affectedRows += 1; $this->resetModified(); } if ($this->statesScheduledForDeletion !== null) { if (!$this->statesScheduledForDeletion->isEmpty()) { StateQuery::create()->filterByPrimaryKeys($this->statesScheduledForDeletion->getPrimaryKeys(false))->delete($con); $this->statesScheduledForDeletion = null; } } if ($this->collStates !== null) { foreach ($this->collStates as $referrerFK) { if (!$referrerFK->isDeleted()) { $affectedRows += $referrerFK->save($con); } } } $this->alreadyInSave = false; } return $affectedRows; }
/** * Performs the work of inserting or updating the row in the database. * * If the object is new, it inserts it; otherwise an update is performed. * All related objects are also updated in this method. * * @param ConnectionInterface $con * @return int The number of rows affected by this insert/update and any referring fk objects' save() operations. * @throws PropelException * @see save() */ protected function doSave(ConnectionInterface $con) { $affectedRows = 0; // initialize var to track total num of affected rows if (!$this->alreadyInSave) { $this->alreadyInSave = true; // We call the save method on the following object(s) if they // were passed to this object by their corresponding set // method. This object relates to these object(s) by a // foreign key reference. if ($this->aProduct !== null) { if ($this->aProduct->isModified() || $this->aProduct->isNew()) { $affectedRows += $this->aProduct->save($con); } $this->setProduct($this->aProduct); } if ($this->aAttributeAv !== null) { if ($this->aAttributeAv->isModified() || $this->aAttributeAv->isNew()) { $affectedRows += $this->aAttributeAv->save($con); } $this->setAttributeAv($this->aAttributeAv); } if ($this->aCurrency !== null) { if ($this->aCurrency->isModified() || $this->aCurrency->isNew()) { $affectedRows += $this->aCurrency->save($con); } $this->setCurrency($this->aCurrency); } if ($this->isNew() || $this->isModified()) { // persist changes if ($this->isNew()) { $this->doInsert($con); } else { $this->doUpdate($con); } $affectedRows += 1; $this->resetModified(); } $this->alreadyInSave = false; } return $affectedRows; }
public function actionCreate() { $model = new Currency(); $translate = new TranslateMessage(); if (isset($_POST['Currency'])) { $model->attributes = $_POST['Currency']; if ($model->validate()) { $translate->attributes = $_POST['TranslateMessage']; $translate->category = 'module_currency'; $translate->message = $model->char_code . "_translate"; if ($translate->save()) { $model->save(); Yii::app()->cache->flush(); Yii::app()->user->setFlash('success', tc('Success')); $this->redirect(Yii::app()->createUrl('/currency/backend/main/admin')); } } } $this->render('create', array('model' => $model, 'translate' => $translate)); }
/** * @param DemoDataHelper $demoDataHelper */ public function makeAll(&$demoDataHelper) { assert('$demoDataHelper instanceof DemoDataHelper'); $currency = new Currency(); $currency->code = 'EUR'; $currency->rateToBase = 1.5; $saved = $currency->save(); assert('$saved'); $currency = new Currency(); $currency->code = 'CAD'; $currency->rateToBase = 1.1; $saved = $currency->save(); assert('$saved'); $currency = new Currency(); $currency->code = 'JPY'; $currency->rateToBase = 0.75; $saved = $currency->save(); assert('$saved'); ZurmoConfigurationUtil::setByModuleName('ZurmoModule', 'applicationName', 'Demo Company Inc.'); }
/** * Create new currency * Create fake Opportunity with created currency * Try to get select for currency field and assert that new currency is selected * * @return void * @group 48570 */ public function testCurrencySelect() { $currency = new Currency(); $currency->iso4217 = 'EUR'; $currency->name = 'Euro'; $currency->symbol = 'E'; $currency->conversion_rate = 1.5; $currency->status = 'Active'; $currency->save(); $focus = new Opportunity(); $focus->id = __CLASS__; $focus->currency_id = $currency->id; $focus->team_id = '1'; $editView = new EditView(); $editView->showVCRControl = false; $editView->view = 'EditView'; $editView->setup('Opportunities', $focus); $editView->process(); $currency->mark_deleted($currency->id); $this->assertRegExp('/<option value="' . $focus->currency_id . '" selected>/sim', $editView->fieldDefs['currency_id']['value'], 'No selected option here'); }
/** * Set $currency as default * * @param Currency $currency * @return boolean */ function setDefault($currency) { if ($currency->getIsDefault()) { return true; } // if db_begin_work(); $currency->setIsDefault(true); $update = $currency->save(); if ($update && !is_error($update)) { $update = db_execute('UPDATE ' . TABLE_PREFIX . 'currencies SET is_default = ? WHERE id != ?', false, $currency->getId()); cache_remove_by_pattern(TABLE_PREFIX . 'currencies_id_*'); if ($update && !is_error($update)) { db_commit(); return true; } // if } // if db_rollback(); return $update; }
public static function setUpBeforeClass() { parent::setUpBeforeClass(); SecurityTestHelper::createSuperAdmin(); Currency::getAll(); //In order to create base Currency $currency = new Currency(); $currency->code = 'EUR'; $currency->rateToBase = 2; $saved = $currency->save(); assert('$saved'); // Not Coding Standard self::$sally = UserTestHelper::createBasicUser('sally'); $multiSelectValues = array('Multi 1', 'Multi 2', 'Multi 3'); $customFieldData = CustomFieldData::getByName('TestMultiDropDown'); $customFieldData->serializedData = serialize($multiSelectValues); $saved = $customFieldData->save(); assert('$saved'); // Not Coding Standard $tagCloudValues = array('Cloud 1', 'Cloud 2', 'Cloud 3'); $customFieldData = CustomFieldData::getByName('TestTagCloud'); $customFieldData->serializedData = serialize($tagCloudValues); $saved = $customFieldData->save(); assert('$saved'); // Not Coding Standard $values = array('Test1', 'Test2', 'Test3', 'Sample', 'Demo'); $customFieldData = CustomFieldData::getByName('TestDropDown'); $customFieldData->serializedData = serialize($values); $saved = $customFieldData->save(); assert('$saved'); // Not Coding Standard $a = new Group(); $a->name = 'AAA'; $saved = $a->save(); assert('$saved'); // Not Coding Standard self::$groupA = $a; }
public static function setUpBeforeClass() { parent::setUpBeforeClass(); SecurityTestHelper::createSuperAdmin(); Yii::import('application.core.data.*'); Yii::import('application.modules.contracts.data.*'); $defaultDataMaker = new ContractsDefaultDataMaker(); $defaultDataMaker->make(); Yii::import('application.modules.contacts.data.*'); $defaultDataMaker = new ContactsDefaultDataMaker(); $defaultDataMaker->make(); Currency::getAll(); //forces base currency to be created. $currency = new Currency(); $currency->code = 'EUR'; $currency->rateToBase = 2; assert($currency->save()); // Not Coding Standard $currency = new Currency(); $currency->code = 'GBP'; $currency->rateToBase = 2; assert($currency->save()); // Not Coding Standard }
/** * @depends testGetAndSetCurrencyValue */ public function testConstructDerivedWithUserDefaultCurrency() { $currentUser = Yii::app()->user->userModel; $currencyValue = new CurrencyValue(); //Make a new currency and assign to the current user. $currency = new Currency(); $currency->code = 'EUR'; $currency->rateToBase = 1.5; $this->assertTrue($currency->save()); $currentUser->currency = $currency; $this->assertTrue($currentUser->save()); $this->assertEquals('EUR', Yii::app()->user->userModel->currency->code); $currencyHelper = Yii::app()->currencyHelper; $this->assertEquals('EUR', $currencyHelper->getCodeForCurrentUserForDisplay()); $currencyValue = new CurrencyValue(); $this->assertEquals('EUR', $currencyValue->currency->code); }
/** * @depends testGetChartDataUsingReadOptimization */ public function testGetChartDataConvertedToNewCurrency() { $super = User::getByUsername('super'); Yii::app()->user->userModel = $super; $this->assertNull($super->currency->code); //Make a new currency and assign to the current user. $currency = new Currency(); $currency->code = 'EUR'; $currency->rateToBase = 0.5; //I wish... $this->assertTrue($currency->save()); $super->currency = $currency; $this->assertTrue($super->save()); $chartDataProvider = ChartDataProviderFactory::createByType('ContractsByStage'); $chartData = $chartDataProvider->getChartData(); $compareData = array(array('value' => 1100, 'displayLabel' => 'Negotiating'), array('value' => 200, 'displayLabel' => 'Verbal')); $this->assertEquals($compareData, $chartData); $chartDataProvider = ChartDataProviderFactory::createByType('ContractsBySource'); $chartData = $chartDataProvider->getChartData(); $compareData = array(array('value' => 400, 'displayLabel' => 'Outbound'), array('value' => 900, 'displayLabel' => 'Trade Show')); $this->assertEquals($compareData, $chartData); }
function action_saveadminwizard() { global $current_user; if (!is_admin($current_user)) { sugar_die($GLOBALS['app_strings']['ERR_NOT_ADMIN']); } $focus = new Administration(); $focus->retrieveSettings(); $focus->saveConfig(); $configurator = new Configurator(); $configurator->populateFromPost(); $configurator->handleOverride(); $configurator->parseLoggerSettings(); $configurator->saveConfig(); // Bug 37310 - Delete any existing currency that matches the one we've just set the default to during the admin wizard $currency = new Currency(); $currency->retrieve($currency->retrieve_id_by_name($_REQUEST['default_currency_name'])); if (!empty($currency->id) && $currency->symbol == $_REQUEST['default_currency_symbol'] && $currency->iso4217 == $_REQUEST['default_currency_iso4217']) { $currency->deleted = 1; $currency->save(); } SugarApplication::redirect('index.php?module=Users&action=Wizard&skipwelcome=1'); }
public function testSuperUserCreateAction() { $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super'); Yii::app()->user->userModel = $super; $this->resetGetArray(); $currency = new Currency(); $currency->code = 'USD'; $currency->rateToBase = 1; $currency->save(); $currencyRec = Currency::getByCode('USD'); $currencyValue1Array = array('currency' => array('id' => $currencyRec->id), 'value' => 500.54); ProductTemplateTestHelper::createProductTemplateByName("My Catalog Item 1"); $productTemplate = ProductTemplate::getByName('My Catalog Item 1'); $product = array(); $product['name'] = 'Red Widget'; $product['quantity'] = 5; $product['priceFrequency'] = ProductTemplate::PRICE_FREQUENCY_ONE_TIME; $product['sellPrice'] = $currencyValue1Array; $product['type'] = ProductTemplate::TYPE_PRODUCT; $product['stage']['value'] = Product::OPEN_STAGE; $product['productTemplate'] = array('id' => $productTemplate[0]->id); $this->setPostArray(array('Product' => $product, 'Product_owner_name' => 'Super User')); $redirectUrl = $this->runControllerWithRedirectExceptionAndGetUrl('products/default/create'); $products = Product::getByName('Red Widget'); $this->assertEquals(1, count($products)); $this->assertTrue($products[0]->id > 0); $this->assertEquals(500.54, $products[0]->sellPrice->value); $compareRedirectUrl = Yii::app()->createUrl('products/default/details', array('id' => $products[0]->id)); $this->assertEquals($compareRedirectUrl, $redirectUrl); }
} if (!empty($_SESSION['default_locale_name_format'])) { $sugar_config['default_locale_name_format'] = $_SESSION['default_locale_name_format']; } //$configurator->handleOverride(); installLog('saveConfig'); $configurator->saveConfig(); // Bug 37310 - Delete any existing currency that matches the one we've just set the default to during the admin wizard installLog('new Currency'); $currency = new Currency(); installLog('retrieve'); $currency->retrieve($currency->retrieve_id_by_name($_REQUEST['default_currency_name'])); if (!empty($currency->id) && $currency->symbol == $_REQUEST['default_currency_symbol'] && $currency->iso4217 == $_REQUEST['default_currency_iso4217']) { $currency->deleted = 1; installLog('DBG: save currency'); $currency->save(); } installLog('Save user settings..'); // <------------------------------------------------ // from UsersController->action_saveuserwizard() // ----------------------------------------------------------> // set all of these default parameters since the Users save action will undo the defaults otherwise // load admin $current_user = new User(); $current_user->retrieve(1); $current_user->is_admin = '1'; $sugar_config = get_sugar_config_defaults(); // set local settings - if neccessary you can set here more fields as named in User module / EditView form... if (isset($_REQUEST['timezone']) && $_REQUEST['timezone']) { $current_user->setPreference('timezone', $_REQUEST['timezone']); }
public static function makeBaseCurrency() { $currency = new Currency(); $currency->code = Yii::app()->currencyHelper->getBaseCode(); $currency->rateToBase = 1; $saved = $currency->save(); if (!$saved) { throw new NotSupportedException(); } return $currency; }
function doFix($closed = false) { global $db, $currency, $currencies, $mod_strings; $query = "select id, price,name from prices"; if (!$closed) { $query .= " where prices.sales_stage <> 'Closed Won' AND prices.sales_stage <> 'Closed Lost';"; } $result = $db->query($query); $count = 0; echo get_form_header($mod_strings['UPDATE_FIX'] . ':', '', '') . '<br>'; while ($row = $db->fetchByAssoc($result)) { $price = ''; $symbol = ''; $regs = array(); if ($row['price'] == NULL) { echo $mod_strings['UPDATE_NULL_VALUE'] . ' ' . $row['name'] . '<br>'; updateAmountByID($row['id'], '-99', '0'); } else { if (!is_numeric($row['price'])) { $count++; ereg("([^0-9^\\.^\\]*)([0-9\\.\\,]+)([^0-9^\\.^\\]*)", $row['price'], $regs); if (sizeof($regs) > 3) { $price = $regs[2]; $symbol .= trim($regs[1]) . trim($regs[3]); } if (strpos($price, ',') > strpos($price, '.')) { $price = str_replace('.', '', $price); $price = str_replace(',', '.', $price); } else { $price = str_replace(',', '', $price); } if (!isset($currencies[$symbol])) { $curid = $currency->retrieveIDBySymbol($symbol); if (empty($symbol)) { $curid = '-99'; } if (!empty($curid)) { $currencies[$symbol] = $curid; } else { echo $mod_strings['UPDATE_CREATE_CURRENCY'] . ' ' . $symbol . '<br>'; $temp = new Currency(); $temp->conversion_rate = 1; $temp->iso4217 = substr($symbol, 0, 3); $temp->symbol = $symbol; $temp->name = $symbol; $temp->status = 'Active'; $temp->save(); $currencies[$symbol] = $temp->id; } } if (!empty($price) && !empty($price)) { $query = "update prices set price_backup='" . $row['price'] . "' where id='" . $row['id'] . "' and prices.sales_stage <> 'Closed Won' AND prices.sales_stage <> 'Closed Lost';"; $db->query($query); updateAmountBySymbol($row['id'], $symbol, $price); } } } } print $mod_strings['UPDATE_BUG_COUNT'] . ' ' . $count . '<br>'; print $mod_strings['UPDATE_DONE'] . '<br>'; doVerify(); }
/** * @depends testGetCodeForCurrentUserForDisplay */ public function testGetActiveCurrenciesOrSelectedCurrenciesData() { $super = User::getByUsername('super'); Yii::app()->user->userModel = $super; //Make a second currency for this test. $currency = new Currency(); $currency->code = 'USD'; $currency->rateToBase = 1; $this->assertTrue($currency->save()); $super->currency = $currency; $this->assertTrue($super->save()); $currencies = Currency::getAll(); $this->assertEquals(2, count($currencies)); $activeCurrencies = Yii::app()->currencyHelper->getActiveCurrenciesOrSelectedCurrenciesData(null); $this->assertEquals(2, count($activeCurrencies)); $currency = Currency::getByCode('EUR'); $currency->active = 0; $this->assertTrue($currency->save()); //There should only be one active currency at this point. $activeCurrencies = Yii::app()->currencyHelper->getActiveCurrenciesOrSelectedCurrenciesData(null); $this->assertEquals(1, count($activeCurrencies)); //Confirm that there are 2 active currencies when specifying an inactive one as the selected currency. $activeCurrencies = Yii::app()->currencyHelper->getActiveCurrenciesOrSelectedCurrenciesData($currency->id); $this->assertEquals(2, count($activeCurrencies)); }
public function testSuperUserModifyActiveCurrenciesInCollection() { $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super'); //Create second currency. $currency = new Currency(); $currency->code = 'EUR'; $currency->rateToBase = 1.5; $saved = $currency->save(); $this->assertTrue($saved); $EURCurrencyId = $currency->id; $currencies = Currency::getAll(); $this->assertEquals(2, count($currencies)); $this->assertEquals(1, $currencies[0]->active); $this->assertEquals(1, $currencies[1]->active); //Make EUR inactive. $this->resetGetArray(); $this->setPostArray(array('CurrencyCollection' => array('EUR' => array('active' => ''), 'USD' => array('active' => '1')))); $content = $this->runControllerWithNoExceptionsAndGetContent('zurmo/currency/configurationList'); $this->assertContains('Changes to active currencies saved successfully.', $content); //Confirm that the EUR is inactive and the USD is still active. $currency = Currency::getByCode('EUR'); $this->assertEquals(0, $currency->active); $currency = Currency::getByCode('USD'); $this->assertEquals(1, $currency->active); //Attempt to also make the USD inactive, this should fail since at least one currency must be active. $this->resetGetArray(); $this->setPostArray(array('CurrencyCollection' => array('EUR' => array('active' => ''), 'USD' => array('active' => '')))); $content = $this->runControllerWithNoExceptionsAndGetContent('zurmo/currency/configurationList'); $this->assertContains('You must have at least one active currency.', $content); //Confirm that the EUR is inactive and the USD is still active. $currency = Currency::getByCode('EUR'); $this->assertEquals(0, $currency->active); $currency = Currency::getByCode('USD'); $this->assertEquals(1, $currency->active); }