Beispiel #1
0
 /**
  * @depends testCreateAndGetAccountById
  */
 public function testValidatesWithoutOwnerWhenSpecifyingAttributesToValidate()
 {
     $user = User::getByUsername('steven');
     $this->assertTrue($user->id > 0);
     $account = new Account(false);
     $_POST['MassEdit'] = array('employees' => '1');
     $_POST['fake'] = array('employees' => 4);
     PostUtil::sanitizePostForSavingMassEdit('fake');
     $account->setAttributes($_POST['fake']);
     $account->validate(array_keys($_POST['MassEdit']));
     $this->assertEquals(array(), $account->getErrors());
     $account->forget();
     $account = new Account(false);
     $_POST['MassEdit'] = array('owner' => '1');
     $_POST['fake'] = array('owner' => array('id' => ''));
     PostUtil::sanitizePostForSavingMassEdit('fake');
     $account->setAttributes($_POST['fake']);
     $account->validate(array_keys($_POST['MassEdit']));
     //there should be an owner error since it is specified but blank
     $this->assertNotEquals(array(), $account->getErrors());
     $account->forget();
     $account = new Account(false);
     $_POST['MassEdit'] = array('employees' => '1', 'owner' => '2');
     $_POST['fake'] = array('employees' => 4, 'owner' => array('id' => $user->id));
     PostUtil::sanitizePostForSavingMassEdit('fake');
     $account->setAttributes($_POST['fake']);
     $account->validate(array_keys($_POST['MassEdit']));
     $this->assertEquals(array(), $account->getErrors());
 }
Beispiel #2
0
 /**
  * @depends testPopulateCustomAttributes
  */
 public function testPopulateCustomAttributesWithAValueTooLarge()
 {
     $this->setAndGetTextAttribute('testTextSpecial', true);
     $account = new Account();
     $account->testTextSpecialCstm = 'asdasdasdasdasdasdasdasdasdasdsadasdasdasdasdasdasdasdasdasdasdasdasdasdasdasdsadas' . 'asdasdasdasdasdasdasdasdasdasdsadasdasdasdasdasdasdasdasdasdasdasdasdasdasdasdsadas' . 'asdasdasdasdasdasdasdasdasdasdsadasdasdasdasdasdasdasdasdasdasdasdasdasdasdasdsadas';
     $saved = $account->save();
     $this->assertFalse($saved);
     $errors = $account->getErrors();
     $this->assertEquals('Test Text 2 en is too long (maximum is 50 characters).', $errors['testTextSpecialCstm'][0]);
 }
Beispiel #3
0
 public function testUserCanReadEmptyModelWithoutPermissionAndNoDefaultsSetOnModelButCantSaveItUntilTheySetAnOwner()
 {
     $user = UserTestHelper::createBasicUser('atester');
     $this->assertTrue($user->id > 0);
     $item = NamedSecurableItem::getByName('AccountsModule');
     $this->assertEquals(Permission::NONE, $item->getEffectivePermissions($user));
     Yii::app()->user->userModel = $user;
     $account = new Account(false);
     $this->assertEquals('', $account->name);
     $account->name = 'Something Corp';
     $account->validate();
     $this->assertFalse($account->save());
     $this->assertEquals(array('owner' => array('username' => array('Username cannot be blank.'), 'lastName' => array('Last Name cannot be blank.'))), $account->getErrors());
 }
 /**
  * @depends testBulkSetAndGetWithRelatedModels
  */
 public function testEmptyPostValueForRequiredRelations()
 {
     Yii::app()->user->userModel = User::getByUsername('super');
     $_FAKEPOST = array('Account' => array('name' => 'Vomitorio Corp 2', 'officePhone' => '123456789', 'officeFax' => null, 'employees' => 3, 'annualRevenue' => null, 'website' => 'http://barf.com', 'billingAddress' => array('street1' => '123 Road Rd', 'street2' => null, 'city' => 'Cityville', 'postalCode' => '12345', 'country' => 'Countrilia'), 'description' => 'a description', 'owner' => array('id' => ''), 'industry' => array('id' => '')));
     $user = User::getByUsername('bobby');
     $account = new Account();
     $account->owner = $user;
     $account->setAttributes($_FAKEPOST['Account']);
     $this->assertFalse($account->validate());
     $errors = $account->getErrors();
     $this->assertEquals(1, count($errors));
     $this->assertEquals('Username cannot be blank.', $errors['owner']['username'][0]);
     $this->assertEquals('Last Name cannot be blank.', $errors['owner']['lastName'][0]);
 }
Beispiel #5
0
 /**
  * Registers new member
  */
 public function actionRegister()
 {
     // is current user has the required privilege ?
     if (!Yii::app()->user->checkAccess('site_register')) {
         throw new CHttpException(403, 'You are not authorized to perform this action.');
     }
     $registration = new RegistrationForm();
     // collect user input data
     if (isset($_POST['RegistrationForm'])) {
         $registration->attributes = $_POST['RegistrationForm'];
         print_r($_POST['RegistrationForm']);
         // validate user input and redirect to the previous page if valid
         if ($registration->validate()) {
             $member = new Member();
             $member->attributes = $registration->attributes;
             if ($member->save()) {
                 // create an account model
                 $account = new Account();
                 $account->username = $registration->username;
                 $account->password = $registration->password;
                 $account->id_member = $member->id;
                 if ($account->save()) {
                     $auth = Yii::app()->authManager;
                     $auth->assign('member', (int) $account->id);
                     // redirects to index page
                     //$this->redirect(array('index'));
                 } else {
                     // what's wrong? get the error message
                     $registration->addErrors($member->getErrors());
                 }
             } else {
                 // what's wrong? get the error message
                 $registration->addErrors($account->getErrors());
             }
         }
     }
     // display the registration form
     $this->render('register', array('model' => $registration));
 }
Beispiel #6
0
 public function actionRegister()
 {
     $accountMember = new AccountMember();
     if (!Yii::app()->user->checkAccess('Admin')) {
         throw new CHttpException(403, 'You are not authorized to perform this action.');
     }
     // Collect input data
     if (isset($_POST['AccountMember'])) {
         $accountMember->attributes = $_POST['AccountMember'];
         if ($accountMember->validate()) {
             // Create account
             $account = new Account();
             $account->username = $accountMember->username;
             $account->password = $accountMember->password;
             // Create member
             if ($account->save()) {
                 $member = new Member();
                 $member->account_id = $account->id;
                 $member->name = $accountMember->name;
                 $member->department = $accountMember->department;
                 $member->role = $accountMember->role;
                 if ($member->save()) {
                     $auth = new AuthAssignment();
                     $auth->itemname = $member->role;
                     $auth->userid = $account->id;
                     if ($auth->save()) {
                         $this->redirect(array('member'));
                     }
                     //echo $account->password;
                 } else {
                     $accountMember->addErrors($member->getErrors());
                 }
             } else {
                 $accountMember->addErrors($account->getErrors());
             }
         }
     }
     $this->render('register', array('model' => $accountMember));
 }
 public function actionWrite()
 {
     if (isset($_POST['Account'])) {
         $messages = $this->ValidateData(array(array($_POST['Account']['accountname'], 'emptyaccountname', 'emptystring'), array($_POST['Account']['accountcode'], 'emptyaccountcode', 'emptystring'), array($_POST['Account']['currencyid'], 'emptycurrency', 'emptystring')));
         if ($messages == '') {
             //$dataku->attributes=$_POST['Account'];
             if ((int) $_POST['Account']['accountid'] > 0) {
                 $model = $this->loadModel($_POST['Account']['accountid']);
                 $model->accountname = $_POST['Account']['accountname'];
                 $model->accountcode = $_POST['Account']['accountcode'];
                 $model->parentaccountid = $_POST['Account']['parentaccountid'];
                 $model->currencyid = $_POST['Account']['currencyid'];
                 $model->accounttypeid = $_POST['Account']['accounttypeid'];
                 $model->recordstatus = $_POST['Account']['recordstatus'];
             } else {
                 $model = new Account();
                 $model->attributes = $_POST['Account'];
             }
             try {
                 if ($model->save()) {
                     $this->DeleteLock($this->menuname, $_POST['Account']['accountid']);
                     $this->GetSMessage('aaccinsertsuccess');
                 } else {
                     $this->GetMessage($model->getErrors());
                 }
             } catch (Exception $e) {
                 $this->GetMessage($e->getMessage());
             }
         }
     }
 }
 /**
  * @return array Errors  Import Account information
  */
 public static function ImportAccounts($fileNameAndPath)
 {
     $errors = array();
     $dom = new domDocument();
     if (!$dom->load($fileNameAndPath)) {
         $errors[] = Yii::t('lazy8', 'Upload failed.  This is not a valid file.');
         $errors[] = Yii::t('lazy8', 'Select a file and try again');
         return $errors;
     }
     $root = $dom->documentElement;
     if ($root->nodeName != "lazy8webportaccount") {
         $errors[] = Yii::t('lazy8', 'Upload failed.  This is not a valid file.');
         $errors[] = Yii::t('lazy8', 'Select a file and try again');
         return $errors;
     }
     if ($root->getAttribute('version') > 1.0) {
         $errors[] = Yii::t('lazy8', 'There maybe problems because this is a file version greater then this programs version');
         $errors[] = Yii::t('lazy8', 'Select a file and try again');
     }
     $nodesAccountTypes = $root->getElementsByTagName('accounttype');
     foreach ($nodesAccountTypes as $nodeAccountType) {
         $modelAccountType = new AccountType();
         $modelAccountType->companyId = Yii::app()->user->getState('selectedCompanyId');
         $modelAccountType->code = $nodeAccountType->getAttribute('code');
         $modelAccountType->name = $nodeAccountType->getAttribute('name');
         $modelAccountType->sortOrder = $nodeAccountType->getAttribute('sortorder');
         $modelAccountType->isInBalance = $nodeAccountType->getAttribute('isinbalance') == '1' ? 1 : 0;
         if (!$modelAccountType->save()) {
             $errors[] = Yii::t('lazy8', 'Could not create the AccountType, bad paramters') . ';name=' . $modelAccountType->name . ';' . serialize($modelAccountType->getErrors());
             return $errors;
         }
         $nodesAccounts = $nodeAccountType->getElementsByTagName('account');
         foreach ($nodesAccounts as $nodeAccount) {
             $modelAccount = new Account();
             $modelAccount->companyId = Yii::app()->user->getState('selectedCompanyId');
             $modelAccount->code = $nodeAccount->getAttribute('code');
             $modelAccount->accountTypeId = $modelAccountType->id;
             $modelAccount->name = $nodeAccount->getAttribute('name');
             $modelAccount->email = $nodeAccount->getAttribute('email');
             $modelAccount->balance_threshold = $nodeAccount->getAttribute('balance_threshold');
             $modelAccount->days = $nodeAccount->getAttribute('days');
             $modelAccount->report_id = $nodeAccount->getAttribute('report_id');
             if (!$modelAccount->save()) {
                 $modelAccountType->delete();
                 $errors[] = Yii::t('lazy8', 'Could not create the Account, bad paramters') . ';' . serialize($modelAccount->getErrors());
                 return $errors;
             }
         }
     }
     return $errors;
 }
 private function importCompany($fileNameAndPath)
 {
     $allAccounts = array();
     $dom = new domDocument();
     if (!$dom->load($fileNameAndPath)) {
         throw new CException(Yii::t('lazy8', 'input file could not be xml parsed'));
     }
     $root = $dom->documentElement;
     if ($root->nodeName != "lazy8webport") {
         $this->hasErrors = true;
         $this->errors = array(array(Yii::t('lazy8', 'Upload failed.  This is not a valid file.'), Yii::t('lazy8', 'Select a file and try again')));
         $this->render('showimport');
         return 0;
     }
     if ($root->getAttribute('version') > 1.0) {
         $this->errors = array(array(Yii::t('lazy8', 'There maybe problems because this is a file version greater then this programs version'), Yii::t('lazy8', 'Select a file and try again')));
     }
     $nodeCompanys = $root->getElementsByTagName('company');
     unset($root);
     unset($dom);
     $this->lastImportedPeriod = 0;
     foreach ($nodeCompanys as $nodeCompany) {
         //make sure the company code is unique
         $modelCompany = new Company();
         $code = $nodeCompany->getAttribute('code');
         $code--;
         //make sure the company code is valid. Change if not.
         do {
             $code++;
             $comptest = Company::model()->find(array('condition' => 'code=' . $code));
         } while ($comptest !== null);
         //create the company
         $modelCompany = new Company();
         $modelCompany->code = $code;
         $modelCompany->name = $nodeCompany->getAttribute('name');
         $modelCompany->lastAbsTransNum = $nodeCompany->getAttribute('lastAbsTransNum');
         if (!$modelCompany->save()) {
             throw new CException(Yii::t('lazy8', 'Could not create the company, bad paramters') . ';' . var_export($modelCompany->getErrors()));
         }
         try {
             $allAccounts = array();
             $nodesAccountTypes = $nodeCompany->getElementsByTagName('accounttype');
             foreach ($nodesAccountTypes as $nodeAccountType) {
                 $modelAccountType = new AccountType();
                 $modelAccountType->companyId = $modelCompany->id;
                 $modelAccountType->code = $nodeAccountType->getAttribute('code');
                 $modelAccountType->name = $nodeAccountType->getAttribute('name');
                 $modelAccountType->sortOrder = $nodeAccountType->getAttribute('sortorder');
                 $modelAccountType->isInBalance = $nodeAccountType->getAttribute('isinbalance') == "1" ? 1 : 0;
                 if (!$modelAccountType->save()) {
                     $modelCompany->delete();
                     throw new CException(Yii::t('lazy8', 'Could not create the AccountType, bad paramters') . ';name=' . $modelAccountType->name . ';' . serialize($modelAccountType->getErrors()));
                 }
                 $nodesAccounts = $nodeAccountType->getElementsByTagName('account');
                 foreach ($nodesAccounts as $nodeAccount) {
                     $modelAccount = new Account();
                     $modelAccount->companyId = $modelCompany->id;
                     $modelAccount->code = $nodeAccount->getAttribute('code');
                     $modelAccount->accountTypeId = $modelAccountType->id;
                     $modelAccount->name = $nodeAccount->getAttribute('name');
                     if (!$modelAccount->save()) {
                         $modelCompany->delete();
                         throw new CException(Yii::t('lazy8', 'Could not create the Account, bad paramters') . ';' . serialize($modelAccount->getErrors()));
                     }
                     $allAccounts[$modelAccount->code] = $modelAccount->id;
                     unset($nodeAccount);
                     unset($modelAccount);
                 }
                 unset($modelAccountType);
                 unset($nodeAccountType);
             }
             unset($nodesAccountTypes);
             $allCustomers = array();
             $nodesCustomers = $nodeCompany->getElementsByTagName('customer');
             foreach ($nodesCustomers as $nodeCustomer) {
                 $modelCustomer = new Customer();
                 $modelCustomer->companyId = $modelCompany->id;
                 $modelCustomer->code = $nodeCustomer->getAttribute('code');
                 $modelCustomer->accountId = $this->FindAccountIdFromCode($nodeCustomer->getAttribute('accountcode'), $modelCompany->id, $allAccounts, 'customercode=' . $modelCustomer->code, $this->errors, true);
                 $modelCustomer->name = $nodeCustomer->getAttribute('name');
                 $modelCustomer->desc = $nodeCustomer->getAttribute('desc');
                 if (!$modelCustomer->save()) {
                     $modelCompany->delete();
                     throw new CException(Yii::t('lazy8', 'Could not create the Customer, bad paramters') . ';' . serialize($modelCustomer->getErrors()));
                 }
                 $allCustomers[$modelCustomer->code] = $modelCustomer->id;
                 unset($modelCustomer);
                 unset($nodeCustomer);
             }
             unset($nodesCustomers);
             $nodesPeriods = $nodeCompany->getElementsByTagName('period');
             foreach ($nodesPeriods as $nodePeriod) {
                 $modelPeriod = new Period();
                 $modelPeriod->companyId = $modelCompany->id;
                 $modelPeriod->dateStart = $nodePeriod->getAttribute('datestart');
                 $modelPeriod->dateEnd = $nodePeriod->getAttribute('dateend');
                 $modelPeriod->lastPeriodTransNum = $nodePeriod->getAttribute('lastperiodtransnum');
                 if (!$modelPeriod->save()) {
                     $modelCompany->delete();
                     throw new CException(Yii::t('lazy8', 'Could not create the period, bad paramters') . ';' . serialize($modelPeriod->getErrors()));
                 }
                 $this->lastImportedPeriod = $modelPeriod->id;
                 $nodesTransactions = $nodePeriod->getElementsByTagName('transaction');
                 foreach ($nodesTransactions as $nodeTransaction) {
                     $modelTransaction = new Trans();
                     $modelTransaction->companyId = $modelCompany->id;
                     $modelTransaction->companyNum = $nodeTransaction->getAttribute('code');
                     $modelTransaction->periodId = $modelPeriod->id;
                     $modelTransaction->periodNum = $nodeTransaction->getAttribute('periodnum');
                     $modelTransaction->regDate = $nodeTransaction->getAttribute('regdate');
                     $modelTransaction->invDate = $nodeTransaction->getAttribute('invdate');
                     $modelTransaction->notes = $nodeTransaction->getAttribute('notes');
                     $modelTransaction->fileInfo = $nodeTransaction->getAttribute('fileinfo');
                     if (!$modelTransaction->save()) {
                         $modelCompany->delete();
                         throw new CException(Yii::t('lazy8', 'Could not create the Transaction, bad paramters') . ';' . serialize($modelTransaction->getErrors()));
                     }
                     $nodesTransactionAmounts = $nodeTransaction->getElementsByTagName('amount');
                     foreach ($nodesTransactionAmounts as $nodeTransactionAmount) {
                         $modelTransRow = new TransRow();
                         $modelTransRow->transId = $modelTransaction->id;
                         $modelTransRow->accountId = $this->FindAccountIdFromCode($nodeTransactionAmount->getAttribute('accountcode'), $modelCompany->id, $allAccounts, 'TransCode=' . $modelTransaction->companyNum, $this->errors, true, true);
                         $modelTransRow->customerId = $this->FindCustomerIdFromCode($nodeTransactionAmount->getAttribute('customercode'), $modelCompany->id, $allCustomers, 'TransCode=' . $modelTransaction->companyNum, $this->errors, true);
                         $modelTransRow->notes = $nodeTransactionAmount->getAttribute('notes');
                         $modelTransRow->amount = $nodeTransactionAmount->getAttribute('amount');
                         if (!$modelTransRow->save()) {
                             $modelCompany->delete();
                             throw new CException(Yii::t('lazy8', 'Could not create the TransactionAmount, bad paramters') . ';' . serialize($modelTransRow->getErrors()));
                         }
                         unset($modelTransRow);
                     }
                     unset($modelTransaction);
                     unset($nodesTransactionAmounts);
                     unset($nodeTransaction);
                 }
                 unset($modelPeriod);
                 unset($nodePeriod);
                 unset($nodesTransactions);
             }
             unset($nodesPeriods);
         } catch (Exception $e) {
             $modelCompany->delete();
             throw $e;
         }
         $errors = array();
         //we ignore the errors...
         yii::app()->onImport(new Lazy8Event(array('importobject' => 'Company', 'root' => $nodeCompany, 'errors' => $errors), $modelCompany->id));
         unset($nodeCompany);
     }
     unset($nodeCompanys);
     ChangeLog::addLog('ADD', 'Company', 'Imported company ' . $modelCompany->toString());
     return $modelCompany->id;
 }