public function actionLoadContractsSampler() { if (!Group::isUserASuperAdministrator(Yii::app()->user->userModel)) { throw new NotSupportedException(); } for ($i = 0; $i < 11; $i++) { $owner = Yii::app()->user->userModel; $name = 'Mass Delete ' . $i; $currencies = Currency::getAll(); $currencyValue = new CurrencyValue(); $currencyValue->value = 500.54; $currencyValue->currency = $currencies[0]; $contract = new Contract(); $contract->owner = $owner; $contract->name = $name; $contract->amount = $currencyValue; $contract->closeDate = '2011-01-01'; //eventually fix to make correct format $contract->stage->value = 'Negotiating'; $saved = $contract->save(); if (!$saved) { throw new NotSupportedException(); } } }
public function testLoad() { $customFieldData = CustomFieldData::getByName('Titles'); $this->assertEquals(0, count(unserialize($customFieldData->serializedData))); $customFieldData = CustomFieldData::getByName('AccountTypes'); $this->assertEquals(0, count(unserialize($customFieldData->serializedData))); $customFieldData = CustomFieldData::getByName('LeadSources'); $this->assertEquals(0, count(unserialize($customFieldData->serializedData))); $customFieldData = CustomFieldData::getByName('Industries'); $this->assertEquals(0, count(unserialize($customFieldData->serializedData))); $customFieldData = CustomFieldData::getByName('MeetingCategories'); $this->assertEquals(0, count(unserialize($customFieldData->serializedData))); $this->assertEquals(0, ContactState::getCount()); // do a getAll to ensure we create base currency $baseCurrency = Currency::getAll(); $this->assertCount(1, $baseCurrency); $this->assertEquals(1, Currency::getCount()); $messageLogger = new MessageLogger(); DefaultDataUtil::load($messageLogger); $customFieldData = CustomFieldData::getByName('Titles'); $this->assertEquals(4, count(unserialize($customFieldData->serializedData))); $customFieldData = CustomFieldData::getByName('AccountTypes'); $this->assertEquals(3, count(unserialize($customFieldData->serializedData))); $customFieldData = CustomFieldData::getByName('LeadSources'); $this->assertEquals(4, count(unserialize($customFieldData->serializedData))); $customFieldData = CustomFieldData::getByName('Industries'); $this->assertEquals(9, count(unserialize($customFieldData->serializedData))); $customFieldData = CustomFieldData::getByName('MeetingCategories'); $this->assertEquals(2, count(unserialize($customFieldData->serializedData))); $this->assertEquals(6, ContactState::getCount()); $this->assertEquals(1, Currency::getCount()); }
/** * @param Object $demoDataHelper */ public function makeAll(&$demoDataHelper) { assert('$demoDataHelper instanceof DemoDataHelper'); $currencies = Currency::getAll('id'); $productTemplates = array(); $productTemplateRandomData = self::getProductTemplatesRandomData(); for ($i = 0; $i < count($productTemplateRandomData['names']); $i++) { $productTemplate = new ProductTemplate(); $currencyIndex = array_rand($currencies); $currencyValue = new CurrencyValue(); $currencyValue->currency = $currencies[$currencyIndex]; $productTemplate->cost = $currencyValue; $currencyValue = new CurrencyValue(); $currencyValue->currency = $currencies[$currencyIndex]; $productTemplate->listPrice = $currencyValue; $currencyValue = new CurrencyValue(); $currencyValue->currency = $currencies[$currencyIndex]; $productTemplate->sellPrice = $currencyValue; $this->populateModelData($productTemplate, $i); $saved = $productTemplate->save(); assert('$saved'); $productTemplates[] = $productTemplate->id; } $demoDataHelper->setRangeByModelName('ProductTemplate', $productTemplates[0], $productTemplates[count($productTemplates) - 1]); }
public function testGetExportValue() { $super = User::getByUsername('super'); Yii::app()->user->userModel = $super; $currencies = Currency::getAll(); $currencyValue = new CurrencyValue(); $currencyValue->value = 100; $currencyValue->currency = $currencies[0]; $this->assertEquals('USD', $currencyValue->currency->code); $data = array(); $model = new ExportTestModelItem(); $model->currencyValue = $currencyValue; $model->lastName = "Smith"; $model->string = "Some Test String"; // We have to save model, to get correct currencyValue id. $this->assertTrue($model->save()); $adapter = new CurrencyValueRedBeanModelAttributeValueToExportValueAdapter($model, 'currencyValue'); $adapter->resolveData($data); $compareData = array($currencyValue->value, $currencyValue->currency->code); $this->assertEquals($compareData, $data); $data = array(); $adapter->resolveHeaderData($data); $compareData = array($model->getAttributeLabel('currencyValue'), $model->getAttributeLabel('currencyValue') . " " . Zurmo::t('ZurmoModule', 'Currency')); $this->assertEquals($compareData, $data); $data = array(); $model = new ExportTestModelItem(); $adapter = new CurrencyValueRedBeanModelAttributeValueToExportValueAdapter($model, 'currencyValue'); $adapter->resolveData($data); $compareData = array('', ''); $this->assertEquals($compareData, $data); $data = array(); $adapter->resolveHeaderData($data); $compareData = array($model->getAttributeLabel('currencyValue'), $model->getAttributeLabel('currencyValue') . " " . Zurmo::t('ZurmoModule', 'Currency')); $this->assertEquals($compareData, $data); }
public function make() { $values = array(Zurmo::t('CustomField', 'Mr.'), Zurmo::t('CustomField', 'Mrs.'), Zurmo::t('CustomField', 'Ms.'), Zurmo::t('CustomField', 'Dr.')); static::makeCustomFieldDataByValuesAndDefault('Titles', $values); Currency::getAll(); //build base currency. }
public function testGetExportValue() { $currencies = Currency::getAll(); $this->assertTrue(count($currencies) > 0); $data = array(); $model = new ExportTestModelItem(); $model->currency = $currencies[0]; $adapter = new CurrencyRedBeanModelAttributeValueToExportValueAdapter($model, 'currency'); $adapter->resolveData($data); $compareData = array($currencies[0]->code); $this->assertEquals($compareData, $data); $data = array(); $adapter->resolveHeaderData($data); $compareData = array($model->getAttributeLabel('currency')); $this->assertEquals($compareData, $data); // Test when model doesn't contain currency data. $data = array(); $model = new ExportTestModelItem(); $adapter = new CurrencyRedBeanModelAttributeValueToExportValueAdapter($model, 'currency'); $adapter->resolveData($data); $compareData = array(''); $this->assertEquals($compareData, $data); $data = array(); $adapter->resolveHeaderData($data); $compareData = array($model->getAttributeLabel('currency')); $this->assertEquals($compareData, $data); }
public static function setUpBeforeClass() { parent::setUpBeforeClass(); ContactsModule::loadStartingData(); UserTestHelper::createBasicUser('bobby'); Currency::getAll(); //Ensure USD is present }
public function testSimpleUserImportWhereAllRowsSucceed() { Yii::app()->user->userModel = User::getByUsername('super'); $import = new Import(); $serializedData['importRulesType'] = 'ProductTemplates'; $serializedData['firstRowIsHeaderRow'] = true; $import->serializedData = serialize($serializedData); $this->assertTrue($import->save()); ImportTestHelper::createTempTableByFileNameAndTableName('productTemplates.csv', $import->getTempTableName(), Yii::getPathOfAlias('application.modules.productTemplates.tests.unit.files')); $this->assertEquals(3, ImportDatabaseUtil::getCount($import->getTempTableName())); // includes header rows. $currencies = Currency::getAll(); $mappingData = array('column_0' => ImportMappingUtil::makeStringColumnMappingData('name'), 'column_1' => ImportMappingUtil::makeTextAreaColumnMappingData('description'), 'column_2' => ImportMappingUtil::makeIntegerColumnMappingData('sellPriceFormula__type'), 'column_3' => ImportMappingUtil::makeFloatColumnMappingData('sellPriceFormula__discountOrMarkupPercentage'), 'column_4' => ImportMappingUtil::makeCurrencyColumnMappingData('cost', $currencies[0]), 'column_5' => ImportMappingUtil::makeCurrencyColumnMappingData('listPrice', $currencies[0]), 'column_6' => ImportMappingUtil::makeCurrencyColumnMappingData('sellPrice', $currencies[0]), 'column_7' => ImportMappingUtil::makeIntegerColumnMappingData('priceFrequency'), 'column_8' => ImportMappingUtil::makeIntegerColumnMappingData('type'), 'column_9' => ImportMappingUtil::makeIntegerColumnMappingData('status')); $importRules = ImportRulesUtil::makeImportRulesByType('ProductTemplates'); $page = 0; $config = array('pagination' => array('pageSize' => 50)); //This way all rows are processed. $dataProvider = new ImportDataProvider($import->getTempTableName(), true, $config); $dataProvider->getPagination()->setCurrentPage($page); $importResultsUtil = new ImportResultsUtil($import); $messageLogger = new ImportMessageLogger(); ImportUtil::importByDataProvider($dataProvider, $importRules, $mappingData, $importResultsUtil, new ExplicitReadWriteModelPermissions(), $messageLogger); $importResultsUtil->processStatusAndMessagesForEachRow(); //Confirm that 3 models where created. $productTemplates = ProductTemplate::getAll(); $this->assertEquals(2, count($productTemplates)); $productTemplates = ProductTemplate::getByName('A Gift of Monotheists import'); $this->assertEquals(1, count($productTemplates[0])); $this->assertEquals('A Gift of Monotheists import', $productTemplates[0]->name); $this->assertEquals(2, $productTemplates[0]->sellPriceFormula->type); $this->assertEquals(10, $productTemplates[0]->sellPriceFormula->discountOrMarkupPercentage); $this->assertEquals(180, $productTemplates[0]->sellPrice->value); $this->assertEquals(200, $productTemplates[0]->listPrice->value); $this->assertEquals(200, $productTemplates[0]->cost->value); $this->assertEquals(2, $productTemplates[0]->priceFrequency); $this->assertEquals(2, $productTemplates[0]->type); $this->assertEquals(2, $productTemplates[0]->status); $productTemplates[0]->delete(); $productTemplates = ProductTemplate::getByName('A Gift of Monotheists import Copy'); $this->assertEquals(1, count($productTemplates[0])); $this->assertEquals('A Gift of Monotheists import Copy', $productTemplates[0]->name); $this->assertEquals(2, $productTemplates[0]->sellPriceFormula->type); $this->assertEquals(5, $productTemplates[0]->sellPriceFormula->discountOrMarkupPercentage); $this->assertEquals(180, $productTemplates[0]->sellPrice->value); $this->assertEquals(200, $productTemplates[0]->listPrice->value); $this->assertEquals(200, $productTemplates[0]->cost->value); $this->assertEquals(2, $productTemplates[0]->priceFrequency); $this->assertEquals(2, $productTemplates[0]->type); $this->assertEquals(2, $productTemplates[0]->status); $productTemplates[0]->delete(); //Confirm that 2 rows were processed as 'updated'. $this->assertEquals(0, ImportDatabaseUtil::getCount($import->getTempTableName(), "status = " . ImportRowDataResultsUtil::UPDATED)); //Confirm 2 rows were processed as 'errors'. $this->assertEquals(0, ImportDatabaseUtil::getCount($import->getTempTableName(), "status = " . ImportRowDataResultsUtil::ERROR)); $beansWithErrors = ImportDatabaseUtil::getSubset($import->getTempTableName(), "status = " . ImportRowDataResultsUtil::ERROR); $this->assertEquals(0, count($beansWithErrors)); }
public function testGetAllMakesBaseCurrency() { $this->assertEquals(0, count(Currency::getAll(null, false, null, false))); $currency = Yii::app()->currencyHelper; $this->assertEquals('USD', $currency->getBaseCode()); $this->assertEquals(0, Currency::getCount()); $this->assertEquals(1, count(Currency::getAll())); $this->assertEquals(1, Currency::getCount()); }
public function actionConfigurationList() { $redirectUrlParams = array('/zurmo/' . $this->getId() . '/ConfigurationList'); $currency = new Currency(); $currency = $this->attemptToSaveModelFromPost($currency, $redirectUrlParams); $messageBoxContent = $this->attemptToUpdateActiveCurrenciesFromPostAndGetMessageBoxContent(); $view = new CurrencyTitleBarConfigurationListAndCreateView($this->getId(), $this->getModule()->getId(), $currency, Currency::getAll(), $messageBoxContent); $view = new ZurmoConfigurationPageView(ZurmoDefaultAdminViewUtil::makeStandardViewForCurrentUser($this, $view)); echo $view->render(); }
private static function createEmptyPursesFor($userID) { $purse = new Purse(); $purse->setUserId($userID); $purse->setValue(0.0); $allCurrencies = Currency::getAll(); foreach ($allCurrencies as $currency) { $purse->setCurrencyId($currency['id']); $purse->insert(); } }
public function actionConfigurationList() { $breadCrumbLinks = array(Zurmo::t('ZurmoModule', 'Currencies')); $redirectUrlParams = array('/zurmo/' . $this->getId() . '/ConfigurationList'); $currency = new Currency(); $currency = $this->attemptToSaveModelFromPost($currency, $redirectUrlParams); $messageBoxContent = $this->attemptToUpdateActiveCurrenciesFromPostAndGetMessageBoxContent(); $view = new CurrencyTitleBarConfigurationListAndCreateView($this->getId(), $this->getModule()->getId(), $currency, Currency::getAll(), $messageBoxContent); $view = new ZurmoConfigurationPageView(ZurmoDefaultAdminViewUtil::makeViewWithBreadcrumbsForCurrentUser($this, $view, $breadCrumbLinks, 'SettingsBreadCrumbView')); echo $view->render(); }
public function testGetAllMakesBaseCurrency() { $this->assertEquals(0, count(Currency::getAll(null, false, null, false))); $currency = Yii::app()->currencyHelper; $this->assertEquals('USD', $currency->getBaseCode()); $this->assertEquals(0, Currency::getCount()); // do a getAll to ensure we create base currency $baseCurrency = Currency::getAll(); $this->assertCount(1, $baseCurrency); $this->assertEquals(1, Currency::getCount()); }
private function generate_currency_list() { $currencies = Currency::getAll(); echo '<select class="field" id="currency" name="currency">' . "\n"; if ($selected == '') { echo '<option value="0" selected>Please select a currency</option>' . "\n"; } foreach ($currencies as $currency) { echo '<option value="' . $currency['symbol'] . '">' . $currency['currency'] . ' (' . $currency['symbol'] . ')</option>' . "\n"; } echo '</select>' . "\n"; }
public static function setUpBeforeClass() { parent::setUpBeforeClass(); SecurityTestHelper::createSuperAdmin(); $super = User::getByUsername('super'); Yii::app()->user->userModel = $super; UserTestHelper::createBasicUser('jim'); AllPermissionsOptimizationUtil::rebuild(); ContractTestHelper::createContractStagesIfDoesNotExist(); ContractTestHelper::createContractSourcesIfDoesNotExist(); $currencies = Currency::getAll(); //Make Contracts for testing chart data. $currencyValue = new CurrencyValue(); $currencyValue->value = 200; $currencyValue->currency = $currencies[0]; $contract = new Contract(); $contract->owner = $super; $contract->name = 'abc1'; $contract->amount = $currencyValue; $contract->closeDate = '2011-01-01'; $contract->stage->value = 'Negotiating'; $contract->source->value = 'Outbound'; assert($contract->save()); // Not Coding Standard $currencyValue = new CurrencyValue(); $currencyValue->value = 350; $currencyValue->currency = $currencies[0]; $contract = new Contract(); $contract->owner = $super; $contract->name = 'abc2'; $contract->amount = $currencyValue; $contract->closeDate = '2011-01-01'; $contract->stage->value = 'Negotiating'; $contract->source->value = 'Trade Show'; assert($contract->save()); // Not Coding Standard $currencyValue = new CurrencyValue(); $currencyValue->value = 100; $currencyValue->currency = $currencies[0]; $contract = new Contract(); $contract->owner = $super; $contract->name = 'abc2'; $contract->amount = $currencyValue; $contract->closeDate = '2011-01-01'; $contract->stage->value = 'Verbal'; $contract->source->value = 'Trade Show'; assert($contract->save()); // Not Coding Standard }
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); }
public static function setUpBeforeClass() { parent::setUpBeforeClass(); $super = SecurityTestHelper::createSuperAdmin(); Yii::app()->user->userModel = $super; Yii::app()->timeZoneHelper->load(); $values = array('Test1', 'Test2', 'Test3', 'Sample', 'Demo'); $customFieldData = CustomFieldData::getByName('ImportTestDropDown'); $customFieldData->serializedData = serialize($values); $saved = $customFieldData->save(); assert($saved); // Not Coding Standard Currency::getAll(); //forces base currency to be created. }
public static function setUpBeforeClass() { parent::setUpBeforeClass(); SecurityTestHelper::createSuperAdmin(); Yii::import('application.core.data.*'); Yii::import('application.modules.accounts.data.*'); $defaultDataMaker = new AccountsDefaultDataMaker(); $defaultDataMaker->make(); Yii::import('application.modules.contacts.data.*'); $defaultDataMaker = new ContactsDefaultDataMaker(); $defaultDataMaker->make(); Currency::getAll(); //forces base currency to be created. ContactsModule::loadStartingData(); }
public static function getCurrencyData() { $currencies = Currency::getAll(); $currencyValue1 = new CurrencyValue(); $currencyValue1->value = 500.54; $currencyValue1->currency = $currencies[0]; $currencyValue2 = new CurrencyValue(); $currencyValue2->value = 400.54; $currencyValue2->currency = $currencies[0]; $currencyValue3 = new CurrencyValue(); $currencyValue3->value = 300.54; $currencyValue3->currency = $currencies[0]; $currencyArray = array(); $currencyArray[] = $currencyValue1; $currencyArray[] = $currencyValue2; $currencyArray[] = $currencyValue3; return $currencyArray; }
public static function createProductByNameForOwner($name, $owner) { $currencies = Currency::getAll('id'); $currencyValue = new CurrencyValue(); $currencyValue->currency = $currencies[array_rand($currencies)]; $currencyValue->value = 500.54; $product = new Product(); $product->name = $name; $product->owner = $owner; $product->description = 'Description'; $product->quantity = 2; $product->type = ProductTemplate::TYPE_PRODUCT; $product->stage->value = 'Open'; $product->sellPrice = $currencyValue; $product->priceFrequency = ProductTemplate::PRICE_FREQUENCY_ONE_TIME; $saved = $product->save(); assert('$saved'); return $product; }
public function testResolveValueOnBaseModelAndRelatedModel() { $reportModelTestItem11 = new ReportModelTestItem11(); $reportModelTestItem11->integer = 5; $currencies = Currency::getAll(); $currencyValue = new CurrencyValue(); $currencyValue->value = 100; $currencyValue->currency = $currencies[0]; $reportModelTestItem11->amount = $currencyValue; $reportModelTestItem11b = new ReportModelTestItem11(); $reportModelTestItem11b->integer = 7; $currencyValue = new CurrencyValue(); $currencyValue->value = 200; $currencyValue->currency = $currencies[0]; $reportModelTestItem11b->amount = $currencyValue; $reportModelTestItem10 = new ReportModelTestItem10(); $reportModelTestItem10->integer = 12; $currencyValue = new CurrencyValue(); $currencyValue->value = 400; $currencyValue->currency = $currencies[0]; $reportModelTestItem10->currencyValue = $currencyValue; $reportModelTestItem10->reportModelTestItem11->add($reportModelTestItem11); $reportModelTestItem10->reportModelTestItem11->add($reportModelTestItem11b); $saved = $reportModelTestItem10->save(); $this->assertTrue($saved); $displayAttributeX = new DisplayAttributeForReportForm('ReportsTestModule', 'ReportModelTestItem10', Report::TYPE_ROWS_AND_COLUMNS); $displayAttributeX->setModelAliasUsingTableAliasName('abc'); $displayAttributeX->attributeIndexOrDerivedType = 'reportModelTestItem11___calculated2'; $this->assertEquals('col0', $displayAttributeX->columnAliasName); $displayAttributeY = new DisplayAttributeForReportForm('ReportsTestModule', 'ReportModelTestItem10', Report::TYPE_ROWS_AND_COLUMNS); $displayAttributeY->setModelAliasUsingTableAliasName('def'); $displayAttributeY->attributeIndexOrDerivedType = 'calculated'; $this->assertEquals('col1', $displayAttributeY->columnAliasName); $reportResultsRowData = new ReportResultsRowData(array($displayAttributeX, $displayAttributeY), 4); $reportResultsRowData->addModelAndAlias($reportModelTestItem11b, 'abc'); $reportResultsRowData->addModelAndAlias($reportModelTestItem10, 'def'); //Get value for calculated which is on base model $value = CalculatedNumberForReportListViewColumnAdapter::resolveValue('attribute1', $reportResultsRowData); $this->assertEquals('$412.00', $value); //Get value for calculated2 which is on a relateds model $value = CalculatedNumberForReportListViewColumnAdapter::resolveValue('attribute0', $reportResultsRowData); $this->assertEquals('$207.00', $value); }
public function testListCurrencies() { $super = User::getByUsername('super'); Yii::app()->user->userModel = $super; $authenticationData = $this->login(); $headers = array('Accept: application/json', 'ZURMO_SESSION_ID: ' . $authenticationData['sessionId'], 'ZURMO_TOKEN: ' . $authenticationData['token'], 'ZURMO_API_REQUEST_TYPE: REST'); $currencies = Currency::getAll(); $compareData = array(); foreach ($currencies as $currency) { $compareData[] = $this->getModelToApiDataUtilData($currency); } //Test List $response = $this->createApiCallWithRelativeUrl('list/', 'GET', $headers); $response = json_decode($response, true); $this->assertEquals(ApiResponse::STATUS_SUCCESS, $response['status']); $this->assertEquals(count($currencies), count($response['data']['items'])); $this->assertEquals(count($currencies), $response['data']['totalCount']); $this->assertEquals(1, $response['data']['currentPage']); $this->assertEquals($compareData, $response['data']['items']); }
public function addAgreementProductsCalculation(Costbook $costbook, $quantity, $frequency, $optId) { $tQty = 0; $opportunityProduct = new OpportunityProduct(); $opportunityProduct->Quantity = (double) $quantity; $opportunityProduct->Frequency = (double) $frequency; $opportunityProduct->name = 'Love Name - ' . $costbook->id; //$opportunityProduct->Product = $costbook; $tQty = (double) $quantity; if ($opportunityProduct->Frequency > 0) { $tQty *= $opportunityProduct->Frequency; } //Labor Product calculation if ($costbook->costofgoodssold == 'Labor') { $currencies = Currency::getAll(); $opportunityProduct->Total_MHR = round($costbook->costperunit * $tQty); if ($costbook->departmentreference != null) { $deptReference = DepartmentReference::GetById(intval($costbook->departmentreference)); $burdenCost = new CurrencyValue(); $burdenCost->value = round($deptReference->burdonCost * $tQty, 2); $burdenCost->currency = $currencies[0]; $opportunityProduct->Burden_Cost = $burdenCost; $laborCost = new CurrencyValue(); $laborCost->value = round($deptReference->laborCost * $tQty, 2); $laborCost->currency = $currencies[0]; $opportunityProduct->Labor_Cost = $laborCost; } } $opportunityProduct->Category_GPM = 40; $totalDirectCost = new CurrencyValue(); $totalDirectCost->value = round($opportunityProduct->Labor_Cost->value + $opportunityProduct->Burden_Cost->value, 2); $totalDirectCost->currency = $currencies[0]; $opportunityProduct->Total_Direct_Cost = $totalDirectCost; $finalCost = new CurrencyValue(); $finalCost->value = round($opportunityProduct->Total_Direct_Cost->value / (1 - $opportunityProduct->Category_GPM / 100), 2); $finalCost->currency = $currencies[0]; $opportunityProduct->Final_Cost = $finalCost; $opportunityProduct->opportunity = $opportunity = Opportunity::GetById(intval($optId)); $opportunityProduct->save(); }
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; }
/** * @param DemoDataHelper $demoDataHelper */ public function makeAll(&$demoDataHelper) { assert('$demoDataHelper instanceof DemoDataHelper'); assert('$demoDataHelper->isSetRange("User")'); assert('$demoDataHelper->isSetRange("Account")'); assert('$demoDataHelper->isSetRange("Contact")'); $currencies = Currency::getAll('id'); $opportunities = array(); for ($i = 0; $i < $this->resolveQuantityToLoad(); $i++) { $opportunity = new Opportunity(); $opportunity->contacts->add($demoDataHelper->getRandomByModelName('Contact')); $opportunity->account = $opportunity->contacts[0]->account; $opportunity->owner = $opportunity->contacts[0]->owner; $currencyValue = new CurrencyValue(); $currencyValue->currency = $currencies[array_rand($currencies)]; $opportunity->amount = $currencyValue; $this->populateModel($opportunity); $saved = $opportunity->save(); assert('$saved'); $opportunities[] = $opportunity->id; } $demoDataHelper->setRangeByModelName('Opportunity', $opportunities[0], $opportunities[count($opportunities) - 1]); }
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 testSimpleUserImportWhereAllRowsSucceed */ public function testSimpleUserImportWithRelationsWhereAllRowsSucceed() { Yii::app()->user->userModel = User::getByUsername('super'); //Create account $sampleAccount = Account::getByName('sampleAccount'); $accountId = $sampleAccount[0]->id; //Create Contact $contact = ContactTestHelper::createContactByNameForOwner("My Contact", Yii::app()->user->userModel); $import = new Import(); $serializedData['importRulesType'] = 'Products'; $serializedData['firstRowIsHeaderRow'] = true; $import->serializedData = serialize($serializedData); $this->assertTrue($import->save()); ImportTestHelper::createTempTableByFileNameAndTableName('productsSampleWithRelations.csv', $import->getTempTableName(), true, Yii::getPathOfAlias('application.modules.products.tests.unit.files')); //update the ids of the account column to match the parent account. ZurmoRedBean::exec("update " . $import->getTempTableName() . " set column_9 = " . $contact->id . " where id != 1 limit 3"); $this->assertEquals(3, ImportDatabaseUtil::getCount($import->getTempTableName())); // includes header rows. $currencies = Currency::getAll(); $ownerColumnMappingData = array('attributeIndexOrDerivedType' => 'owner', 'type' => 'importColumn', 'mappingRulesData' => array('DefaultModelNameIdMappingRuleForm' => array('defaultModelId' => null), 'UserValueTypeModelAttributeMappingRuleForm' => array('type' => UserValueTypeModelAttributeMappingRuleForm::ZURMO_USERNAME))); $mappingData = array('column_0' => $ownerColumnMappingData, 'column_1' => ImportMappingUtil::makeStringColumnMappingData('name'), 'column_2' => ImportMappingUtil::makeTextAreaColumnMappingData('description'), 'column_3' => ImportMappingUtil::makeIntegerColumnMappingData('quantity'), 'column_4' => ImportMappingUtil::makeHasOneColumnMappingData('account', RelatedModelValueTypeMappingRuleForm::ZURMO_MODEL_NAME), 'column_5' => ImportMappingUtil::makeStringColumnMappingData('stage'), 'column_6' => ImportMappingUtil::makeCurrencyColumnMappingData('sellPrice', $currencies[0]), 'column_7' => ImportMappingUtil::makeIntegerColumnMappingData('priceFrequency'), 'column_8' => ImportMappingUtil::makeIntegerColumnMappingData('type')); $importRules = ImportRulesUtil::makeImportRulesByType('Products'); $page = 0; $config = array('pagination' => array('pageSize' => 50)); //This way all rows are processed. $dataProvider = new ImportDataProvider($import->getTempTableName(), true, $config); $dataProvider->getPagination()->setCurrentPage($page); $importResultsUtil = new ImportResultsUtil($import); $messageLogger = new ImportMessageLogger(); ImportUtil::importByDataProvider($dataProvider, $importRules, $mappingData, $importResultsUtil, new ExplicitReadWriteModelPermissions(), $messageLogger); $importResultsUtil->processStatusAndMessagesForEachRow(); //Confirm that 3 models where created. $products = Product::getAll(); $this->assertEquals(2, count($products)); $products = Product::getByName('A Bend in the River November Issue import'); $this->assertEquals(1, count($products)); $this->assertEquals('super', $products[0]->owner->username); $this->assertEquals('A Bend in the River November Issue import', $products[0]->name); $this->assertEquals(6, $products[0]->quantity); $this->assertEquals('sampleAccount', $products[0]->account->name); $this->assertEquals('Open', $products[0]->stage->value); $this->assertEquals('Test Desc', $products[0]->description); $this->assertEquals(210, $products[0]->sellPrice->value); $this->assertEquals(2, $products[0]->priceFrequency); $this->assertEquals(2, $products[0]->type); //$this->assertEquals('My Contact', $products[0]->contact->firstName); $products = Product::getByName('A Bend in the River November Issue import copy'); $this->assertEquals(1, count($products)); $this->assertEquals('super', $products[0]->owner->username); $this->assertEquals('A Bend in the River November Issue import copy', $products[0]->name); $this->assertEquals(6, $products[0]->quantity); $this->assertEquals('sampleAccount', $products[0]->account->name); $this->assertEquals('Open', $products[0]->stage->value); $this->assertEquals('Test Desc 1', $products[0]->description); $this->assertEquals(210, $products[0]->sellPrice->value); $this->assertEquals(2, $products[0]->priceFrequency); $this->assertEquals(2, $products[0]->type); //$this->assertEquals('My Contact', $products[0]->contact->firstName); //Confirm that 2 rows were processed as 'updated'. $this->assertEquals(0, ImportDatabaseUtil::getCount($import->getTempTableName(), "status = " . ImportRowDataResultsUtil::UPDATED)); //Confirm 2 rows were processed as 'errors'. $this->assertEquals(0, ImportDatabaseUtil::getCount($import->getTempTableName(), "status = " . ImportRowDataResultsUtil::ERROR)); $beansWithErrors = ImportDatabaseUtil::getSubset($import->getTempTableName(), "status = " . ImportRowDataResultsUtil::ERROR); $this->assertEquals(0, count($beansWithErrors)); }
/** * @depends testCreateDropDownWithMixedCaseAttributeName */ public function testPopulateCustomAttributes() { $currencies = Currency::getAll(); $account = new Account(); $account->name = 'my test account'; $account->owner = Yii::app()->user->userModel; $account->testCheckBox2Cstm = 0; $account->testCurrency2Cstm->value = 728.89; $account->testCurrency2Cstm->currency = $currencies[0]; $account->testDate2Cstm = '2008-09-03'; $account->testDate3Cstm = '2008-09-02'; $account->testDateTime2Cstm = '2008-09-02 03:03:03'; $account->testDateTime3Cstm = '2008-09-01 03:03:03'; $account->testDecimal2Cstm = 45.67; $account->testDecimal3Cstm = 31.05; $account->testAirPlaneCstm->value = 'A380'; //Dive Bomber $account->testInteger2Cstm = 56; $account->testInteger3Cstm = 21; $account->testPhone2Cstm = '345345234'; $account->testPhone3Cstm = '345345221'; $account->testAirPlanePartsCstm->value = 'Seat'; // Wheel $account->testText2Cstm = 'some test stuff'; $account->testText3Cstm = 'some test stuff 3'; $account->testTextArea2Cstm = 'some test text area stuff'; $account->testTextArea3Cstm = 'some test text area stuff 3'; $account->testUrl2Cstm = 'https://www.zurmo.com'; $account->testUrl3Cstm = 'www.zurmo.org'; $account->playMyFavoriteSongCstm->value = 'song2'; // song 3 $account->testCountryCstm->value = 'bbbb'; $account->testStateCstm->value = 'bbb2'; $account->testCityCstm->value = 'bc2'; $account->testEducationCstm->value = 'cccc'; $account->testStreamCstm->value = 'ccc3'; //Set value to Multiselect list. $customHobbyValue1 = new CustomFieldValue(); $customHobbyValue1->value = 'Reading'; $account->testHobbies1Cstm->values->add($customHobbyValue1); $customHobbyValue2 = new CustomFieldValue(); $customHobbyValue2->value = 'Singing'; $account->testHobbies2Cstm->values->add($customHobbyValue2); //Set value to Tagcloud. $customLanguageValue1 = new CustomFieldValue(); $customLanguageValue1->value = 'English'; $account->testLanguages1Cstm->values->add($customLanguageValue1); $customLanguageValue2 = new CustomFieldValue(); $customLanguageValue2->value = 'Spanish'; $account->testLanguages2Cstm->values->add($customLanguageValue2); unset($customHobbyValue1); unset($customHobbyValue2); unset($customLanguageValue1); unset($customLanguageValue2); $saved = $account->save(); $this->assertTrue($saved); $accountId = $account->id; $account->forget(); unset($account); $account = Account::getById($accountId); $this->assertEquals(0, $account->testCheckBox2Cstm); $this->assertEquals(false, (bool) $account->testCheckBox2Cstm); $this->assertEquals(728.89, $account->testCurrency2Cstm->value); $this->assertEquals(1, $account->testCurrency2Cstm->rateToBase); $this->assertEquals('2008-09-03', $account->testDate2Cstm); $this->assertEquals('2008-09-02 03:03:03', $account->testDateTime2Cstm); $this->assertEquals(45.67, $account->testDecimal2Cstm); $this->assertEquals('A380', $account->testAirPlaneCstm->value); $this->assertEquals(56, $account->testInteger2Cstm); $this->assertEquals(345345234, $account->testPhone2Cstm); $this->assertEquals('Seat', $account->testAirPlanePartsCstm->value); $this->assertEquals('some test stuff', $account->testText2Cstm); $this->assertEquals('some test text area stuff', $account->testTextArea2Cstm); $this->assertEquals('https://www.zurmo.com', $account->testUrl2Cstm); $this->assertEquals('http://www.zurmo.org', $account->testUrl3Cstm); $this->assertEquals('song2', $account->playMyFavoriteSongCstm->value); $this->assertContains('Writing', $account->testHobbies1Cstm->values); $this->assertContains('Reading', $account->testHobbies1Cstm->values); $this->assertContains('Singing', $account->testHobbies2Cstm->values); $this->assertContains('English', $account->testLanguages1Cstm->values); $this->assertContains('French', $account->testLanguages1Cstm->values); $this->assertContains('Spanish', $account->testLanguages2Cstm->values); $this->assertEquals('bbbb', $account->testCountryCstm->value); $this->assertEquals('bbb2', $account->testStateCstm->value); $this->assertEquals('bc2', $account->testCityCstm->value); $this->assertEquals('cccc', $account->testEducationCstm->value); $this->assertEquals('ccc3', $account->testStreamCstm->value); $metadata = CalculatedDerivedAttributeMetadata::getByNameAndModelClassName('testCalculatedValue', 'Account'); $testCalculatedValue = CalculatedNumberUtil::calculateByFormulaAndModelAndResolveFormat($metadata->getFormula(), $account); $this->assertEquals('$774.56', $testCalculatedValue); unset($testCalculatedValue); $account->forget(); unset($account); $account = Account::getById($accountId); //Switch values around to cover for any default value pollution on the assertions above. $account->testCheckBox2Cstm = 1; $account->testCurrency2Cstm->value = 728.92; $account->testCurrency2Cstm->currency = $currencies[0]; $account->testDate2Cstm = '2008-09-04'; $account->testDateTime2Cstm = '2008-09-03 03:03:03'; $account->testDecimal2Cstm = 45.68; $account->testAirPlaneCstm->value = 'Dive Bomber'; $account->testInteger2Cstm = 57; $account->testPhone2Cstm = '3453452344'; $account->testAirPlanePartsCstm->value = 'Wheel'; $account->testText2Cstm = 'some test stuff2'; $account->testTextArea2Cstm = 'some test text area stuff2'; $account->testUrl2Cstm = 'http://www.zurmo.org'; $account->playMyFavoriteSongCstm->value = 'song3'; $account->testCountryCstm->value = 'cccc'; $account->testStateCstm->value = 'ccc3'; $account->testCityCstm->value = 'ca3'; $account->testEducationCstm->value = 'aaaa'; $account->testStreamCstm->value = 'aaa1'; $account->testHobbies1Cstm->values->removeAll(); $account->testHobbies2Cstm->values->removeAll(); $account->testLanguages1Cstm->values->removeAll(); $account->testLanguages2Cstm->values->removeAll(); $this->assertEquals(0, $account->testHobbies1Cstm->values->count()); $this->assertEquals(0, $account->testHobbies2Cstm->values->count()); $this->assertEquals(0, $account->testLanguages1Cstm->values->count()); $this->assertEquals(0, $account->testLanguages2Cstm->values->count()); //Set multiple value to Multiselect list. $customHobbyValue1 = new CustomFieldValue(); $customHobbyValue1->value = 'Writing'; $account->testHobbies1Cstm->values->add($customHobbyValue1); $customHobbyValue2 = new CustomFieldValue(); $customHobbyValue2->value = 'Reading'; $account->testHobbies1Cstm->values->add($customHobbyValue2); $customHobbyValue3 = new CustomFieldValue(); $customHobbyValue3->value = 'Singing'; $account->testHobbies2Cstm->values->add($customHobbyValue3); $customHobbyValue4 = new CustomFieldValue(); $customHobbyValue4->value = 'Surfing'; $account->testHobbies2Cstm->values->add($customHobbyValue4); $customHobbyValue5 = new CustomFieldValue(); $customHobbyValue5->value = 'Reading'; $account->testHobbies2Cstm->values->add($customHobbyValue5); //Set multiple value to Tagcloud. $customLanguageValue1 = new CustomFieldValue(); $customLanguageValue1->value = 'English'; $account->testLanguages1Cstm->values->add($customLanguageValue1); $customLanguageValue2 = new CustomFieldValue(); $customLanguageValue2->value = 'Danish'; $account->testLanguages1Cstm->values->add($customLanguageValue2); $customLanguageValue3 = new CustomFieldValue(); $customLanguageValue3->value = 'Spanish'; $account->testLanguages1Cstm->values->add($customLanguageValue3); $customLanguageValue4 = new CustomFieldValue(); $customLanguageValue4->value = 'French'; $account->testLanguages2Cstm->values->add($customLanguageValue4); $customLanguageValue5 = new CustomFieldValue(); $customLanguageValue5->value = 'Spanish'; $account->testLanguages2Cstm->values->add($customLanguageValue5); $saved = $account->save(); $this->assertTrue($saved); $accountId = $account->id; $account->forget(); unset($account); $account = Account::getById($accountId); $this->assertEquals(1, $account->testCheckBox2Cstm); $this->assertEquals(true, (bool) $account->testCheckBox2Cstm); $this->assertEquals(728.92, $account->testCurrency2Cstm->value); $this->assertEquals(1, $account->testCurrency2Cstm->rateToBase); $this->assertEquals('2008-09-04', $account->testDate2Cstm); $this->assertEquals('2008-09-03 03:03:03', $account->testDateTime2Cstm); $this->assertEquals(45.68, $account->testDecimal2Cstm); $this->assertEquals('Dive Bomber', $account->testAirPlaneCstm->value); $this->assertEquals(57, $account->testInteger2Cstm); $this->assertEquals(3453452344, $account->testPhone2Cstm); $this->assertEquals('Wheel', $account->testAirPlanePartsCstm->value); $this->assertEquals('some test stuff2', $account->testText2Cstm); $this->assertEquals('some test text area stuff2', $account->testTextArea2Cstm); $this->assertEquals('http://www.zurmo.org', $account->testUrl2Cstm); $this->assertEquals('song3', $account->playMyFavoriteSongCstm->value); $this->assertEquals(2, $account->testHobbies1Cstm->values->count()); $this->assertEquals(3, $account->testHobbies2Cstm->values->count()); $this->assertEquals(3, $account->testLanguages1Cstm->values->count()); $this->assertEquals(2, $account->testLanguages2Cstm->values->count()); $this->assertContains('Writing', $account->testHobbies1Cstm->values); $this->assertContains('Reading', $account->testHobbies1Cstm->values); $this->assertContains('Singing', $account->testHobbies2Cstm->values); $this->assertContains('Surfing', $account->testHobbies2Cstm->values); $this->assertContains('Reading', $account->testHobbies2Cstm->values); $this->assertContains('English', $account->testLanguages1Cstm->values); $this->assertContains('Danish', $account->testLanguages1Cstm->values); $this->assertContains('Spanish', $account->testLanguages1Cstm->values); $this->assertContains('French', $account->testLanguages2Cstm->values); $this->assertContains('Spanish', $account->testLanguages2Cstm->values); $this->assertEquals('cccc', $account->testCountryCstm->value); $this->assertEquals('ccc3', $account->testStateCstm->value); $this->assertEquals('ca3', $account->testCityCstm->value); $this->assertEquals('aaaa', $account->testEducationCstm->value); $this->assertEquals('aaa1', $account->testStreamCstm->value); }
/** * @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)); }
/** * Process csv and get data * @param array $mappingData * @param array $data */ protected function processSantizerCSVAndGetData(&$mappingData, &$data) { Yii::app()->user->userModel = User::getByUsername('super'); $import = new Import(); $serializedData['importRulesType'] = 'ProductTemplates'; $serializedData['firstRowIsHeaderRow'] = true; $import->serializedData = serialize($serializedData); $this->assertTrue($import->save()); ImportTestHelper::createTempTableByFileNameAndTableName('productTemplatesSanitizer.csv', $import->getTempTableName(), true, Yii::getPathOfAlias('application.modules.productTemplates.tests.unit.files')); $this->assertEquals(5, ImportDatabaseUtil::getCount($import->getTempTableName())); // includes header rows. $currencies = Currency::getAll(); $mappingData = array('column_0' => ImportMappingUtil::makeStringColumnMappingData('name'), 'column_1' => ImportMappingUtil::makeTextAreaColumnMappingData('description'), 'column_2' => ImportMappingUtil::makeIntegerColumnMappingData('sellPriceFormula__type'), 'column_3' => ImportMappingUtil::makeFloatColumnMappingData('sellPriceFormula__discountOrMarkupPercentage'), 'column_4' => ImportMappingUtil::makeCurrencyColumnMappingData('cost', $currencies[0]), 'column_5' => ImportMappingUtil::makeCurrencyColumnMappingData('listPrice', $currencies[0]), 'column_6' => ImportMappingUtil::makeCurrencyColumnMappingData('sellPrice', $currencies[0]), 'column_7' => ImportMappingUtil::makeIntegerColumnMappingData('priceFrequency'), 'column_8' => ImportMappingUtil::makeIntegerColumnMappingData('type'), 'column_9' => ImportMappingUtil::makeIntegerColumnMappingData('status')); $importRules = ImportRulesUtil::makeImportRulesByType('ProductTemplates'); $page = 0; $config = array('pagination' => array('pageSize' => 50)); //This way all rows are processed. $dataProvider = new ImportDataProvider($import->getTempTableName(), true, $config); $dataProvider->getPagination()->setCurrentPage($page); $data = $dataProvider->getData(true); }