/** * Store a newly created resource in storage. * * @return Response */ public function store() { $validator = Validator::make(Input::all(), array('name' => 'required', 'description' => 'required', 'url' => 'required|url', 'photo' => 'required|image')); if ($validator->fails()) { return Response::json($validator->messages(), 400); } $company = new Company(); $company->name = Input::get('name'); $company->description = Input::get('description'); $company->url = Input::get('url'); //temporary for territory $company->territory_id = 1; $company->save(); //save category and tags if available foreach (Input::get('category') as $catid) { $company->categories()->attach($catid); } foreach (Input::get('tag') as $tagid) { $company->tags()->attach($tagid); } $image = Input::file('photo'); $filename = $company->id; $saveBigUrl = base_path() . '/public/images/companies/' . $filename . '.jpg'; $saveMediumUrl = base_path() . '/public/images/companies/' . $filename . '_medium.jpg'; $saveSmallUrl = base_path() . '/public/images/companies/' . $filename . '_small.jpg'; Image::make($image->getRealPath())->fit(600, null, function ($constraint) { //for big image $constraint->upsize(); })->save($saveBigUrl, 50)->fit(300)->save($saveMediumUrl, 50)->fit(100)->save($saveSmallUrl, 50); $company->big_image_url = url('images/companies/' . $filename . '.jpg'); $company->medium_image_url = url('images/companies/' . $filename . '_medium.jpg'); $company->small_image_url = url('images/companies/' . $filename . '_small.jpg'); $company->save(); return Response::json(array('success_code' => 'OK', 'data' => $company->toArray()), 201); }
public function testSave() { $c = new Company(); $c->name = 'Model Persister Company 2'; $c->save(); $this->assertNotNull($c->id); $c->name = 'Model Persister Company 2 updated'; $c->save(); $c2 = Company::find($c->id); $this->assertEquals($c2->name, 'Model Persister Company 2 updated'); }
public function actionAddcompany() { $companyModel = new Company(); $userLoginModel = new UserLogin(); $userProfileModel = new UserProfile(); if (isset($_POST['Company'])) { $companyModel->attributes = $_POST['Company']; $userLoginModel->attributes = $_POST['UserLogin']; $userProfileModel->attributes = $_POST['UserProfile']; if ($companyModel->validate()) { if ($companyModel->save()) { $userLoginModel->UserRoleID = 2; // $userLoginModel->LoginEmail = '*****@*****.**'; $userLoginModel->UserPassword = md5($userLoginModel->UserPassword); $userLoginModel->IsPasswordReset = 1; $userLoginModel->IsActive = 1; $userLoginModel->save(); $userProfileModel->UserLoginID = $userLoginModel->UserLoginID; $userProfileModel->CompanyID = $companyModel->CompanyID; // $userProfileModel->FirstName = 'Test'; // $userProfileModel->LastName = 'test'; $userProfileModel->AgreeToTerms = 0; $userProfileModel->IsFacilitator = 0; $userProfileModel->save(); $this->redirect(Yii::app()->createUrl('admin/setup', array('id' => $companyModel->CompanyID))); } } } $this->render('add-company', array('companyModel' => $companyModel, 'userLoginModel' => $userLoginModel, 'userProfileModel' => $userProfileModel)); }
/** * Store a newly created resource in storage. * POST /debtors * * @return Response */ public function store() { $contact = new Contact(); $contact->name = Input::get('contact_person'); $contact->email = Input::get('email'); $contact->phone = Input::get('phone'); $contact->mobile = Input::get('mobile'); $contact->web = Input::get('web'); $contact->fax = Input::get('fax'); $contact->save(); $contact_id = $contact->id; $company = new Company(); $company->name = Input::get('company_name'); $company->contact_id = $contact_id; $company->address = Input::get('address'); $company->postal_code = Input::get('postal_code'); $company->city = Input::get('city'); $company->country = Input::get('country'); $company->vat = Input::get('vat'); $company->coc = Input::get('coc'); $company->save(); $company_id = $company->id; //Billing $contact_billing = new Contact(); $contact_billing->name = Input::get('billing_contact_person'); $contact_billing->billing = 'true'; $contact_billing->save(); $contact_billing_id = $contact_billing->id; $company_billing = new Company(); $company_billing->name = Input::get('billing_company_name'); $company_billing->contact_id = $contact_billing_id; $company_billing->address = Input::get('billing_address'); $company_billing->postal_code = Input::get('billing_postal_code'); $company_billing->city = Input::get('billing_city'); $company_billing->country = Input::get('billing_country'); $contact_billing->billing = 'true'; $company_billing->save(); $company_billing_id = $contact_billing->id; $bank = new Bank(); $bank->name = Input::get('bank'); $bank->bic = Input::get('bic'); $bank->save(); $bank_id = $bank->id; $account = new Account(); $account->iban = Input::get('iban'); $account->name = Input::get('account_name'); $account->bank_id = $bank_id; $account->save(); $account_id = $account->id; //Debtor Save $debtor = new Debtor(); $debtor->no = Input::get('debtor_number'); $debtor->legal = Input::get('legal'); $debtor->company_id = $company_id; $debtor->billing_company_id = $company_billing_id; $debtor->account_id = $account_id; $debtor->group_id = Input::get('group'); $debtor->save(); return $this->index(); }
/** * Archive / unarchive this company * * @param void * @return null */ function archive() { if ($this->active_company->isNew()) { $this->httpError(HTTP_ERR_NOT_FOUND); } // if if (!$this->active_company->canArchive($this->logged_user)) { $this->httpError(HTTP_ERR_FORBIDDEN, null); } // if if ($this->request->isSubmitted()) { $new_value = (bool) $this->request->get('set_value'); if ($new_value) { $success_message = lang('":name" has been successfully archived', array('name' => $this->active_company->getName())); $error_message = lang('Failed to archive ":name"', array('name' => $this->active_company->getName())); } else { $success_message = lang('":name" has been successfully moved from archive to the list of active companies', array('name' => $this->active_company->getName())); $error_message = lang('Failed to move ":name" from the archive to the list of active companies', array('name' => $this->active_company->getName())); } // if $this->active_company->setIsArchived($new_value); $save = $this->active_company->save(); if ($save && !is_error($save)) { flash_success($success_message); } else { flash_error($error_message); } // if $this->redirectToUrl($this->active_company->getViewUrl()); } else { $this->httpError(HTTP_ERR_BAD_REQUEST); } // if }
public function createAndSaveMultipleCompanies($count) { for ($i = 65; $i <= 65 + $count - 1; $i++) { $company = new Company(); $company->setName(sprintf($this->getCreatedCompanynamePattern(), chr($i))); $company->save(); } }
public static function add() { return function ($request, $response) { $data = $request->data(); $model = new Company(); $model->name = $data->name; $model->description = $data->description; $model->save(); $response->json($model->as_array()); }; }
/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $model = new Company(); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['Company'])) { $model->attributes = $_POST['Company']; if ($model->save()) { $this->redirect(array('index')); } } $this->render('create', array('model' => $model)); }
public function store() { $rules = ['name' => 'required', 'vat_number' => 'required', 'address' => 'required', 'postal_code' => 'required', 'email' => 'required|email', 'phone' => 'required', 'category_id' => 'required', 'city_id' => 'required']; $validator = Validator::make(Input::all(), $rules); if ($validator->fails()) { return Redirect::back()->withErrors($validator)->withInput(); } else { $password = Input::get('password'); if (Input::has('company_id')) { $id = Input::get('company_id'); $company = CompanyModel::find($id); if ($password !== '') { $company->secure_key = md5($company->salt . $password); } } else { $company = new CompanyModel(); if ($password === '') { $alert['msg'] = 'You have to enter password'; $alert['type'] = 'danger'; return Redirect::route('admin.company.create')->with('alert', $alert); } $company->salt = str_random(8); $company->token = str_random(8); $company->secure_key = md5($company->salt . $password); } $company->name = Input::get('name'); $company->vat_number = Input::get('vat_number'); $company->address = Input::get('address'); $company->postal_code = Input::get('postal_code'); $company->email = Input::get('email'); $company->phone = Input::get('phone'); $company->category_id = Input::get('category_id'); $company->city_id = Input::get('city_id'); $company->save(); if (!Input::has('company_id')) { $setting = new SettingModel(); $setting->company_id = $company->id; $setting->waiting_time = WAITING_TIME; $setting->logo = LOGO; $setting->color = COLOR; $setting->background = BACKGROUND; $setting->start_time = START_TIME; $setting->end_time = END_TIME; $setting->save(); File::makeDirectory(public_path() . "/assets/img/stores/" . $company->id, 0775, true, true); } $alert['msg'] = 'Company has been saved successfully'; $alert['type'] = 'success'; return Redirect::route('admin.company')->with('alert', $alert); } }
/** * create new company & user as creator & admin */ public function register() { $transaction = Yii::app()->db->beginTransaction(); try { //create company first $company = new Company(); $company->name = $this->name; $company->country = $this->country; $company->phone = $this->phone; if (!$company->save()) { $transaction->rollback(); return false; } //create user $user = new User(); $user->username = $this->username; $user->password = $user->encrypt($this->password); $user->password_repeat = $this->password_repeat; $user->email = $this->email; $user->company_id = $company->id; $user->create_time_utc = $user->update_time_utc = time(); if (!$user->save(false)) { $transaction->rollback(); return false; } $company->owner_id = $company->create_user_id = $company->update_user_id = $user->id; if (!$company->update()) { $transaction->rollback(); return false; } $user->create_user_id = $user->update_user_id = $user->id; if (!$user->update()) { $transaction->rollback(); return false; } //create default product folder $defaultProductFolder = new ProductFolder(); $defaultProductFolder->name = 'Main Folder'; $defaultProductFolder->parent_id = 0; $defaultProductFolder->company_id = $company->id; if (!$defaultProductFolder->save()) { $transaction->rollback(); return false; } $transaction->commit(); return true; } catch (Exception $ex) { $transaction->rollback(); return false; } }
public function createUser(RegistrationForm $form) { $transaction = Yii::app()->getDb()->beginTransaction(); try { $user = new User(); $password = rand(1000000, 9999999); $Company = new Company(); if ($form->organization_name) { $Company->name = $form->organization_name; } $Company->create = new CDbExpression('NOW()'); $Company->save(); $user->email = $form->email; $user->contact_phone = $form->phone; $user->contact_phone_prefix = $form->prefphone; $user->company_id = $Company->id; $user->status = User::STATUS_ACTIVE; //Сделать автопроверку выписки $user->setAttribute('hash', $this->hasher->hashPassword($password)); if ($user->save() && ($token = $this->tokenStorage->createAccountActivationToken($user)) !== false) { $user->sendCRMRegistration(); User::savePost($user); \Yii::import('application.modules.rbac.models.*'); $model = new AuthAssignment(); //$model->setAttributes(['userid' => $user->id,'itemname' => 'standart']); //Назаначаем роль владельца компании без инн // $model->setAttributes(['userid' => $user->id,'itemname' => 'own_wo_inn']); //Назаначаем роль владельца компании без инн $model->setAttributes(['userid' => $user->id, 'itemname' => 'owner']); //Назаначаем роль владельца компании без инн if (!$model->save()) { throw new CDbException(Yii::t('UserModule.rbac', 'There is an error occurred when saving data!')); } Yii::app()->eventManager->fire(UserEvents::SUCCESS_REGISTRATION, new UserRegistrationEvent($form, $user, $token, $password)); Yii::log(Yii::t('UserModule.user', 'Account {nick_name} was created', ['{nick_name}' => $user->email]), CLogger::LEVEL_INFO, UserModule::$logCategory); $transaction->commit(); $LoginForm = new LoginForm(); $LoginForm->email = $user->email; $LoginForm->password = $password; Yii::app()->authenticationManager->login($LoginForm, Yii::app()->getUser(), Yii::app()->getRequest()); return $user; } throw new CException(Yii::t('UserModule.user', 'Error creating account!')); } catch (Exception $e) { Yii::log(Yii::t('UserModule.user', 'Error {error} account creating!', ['{error}' => $e->__toString()]), CLogger::LEVEL_INFO, UserModule::$logCategory); $transaction->rollback(); Yii::app()->eventManager->fire(UserEvents::FAILURE_REGISTRATION, new UserRegistrationEvent($form, $user)); return false; } }
public function store() { $input = Input::all(); $company = new Company(); $company->company_name = $input['company_name']; $company->company_address = $input['company_address']; $company->user_id = Auth::user()->id; $rules = array('company_name' => 'required', 'company_address' => 'required'); $validation = Validator::make($input, $rules); if ($validation->passes()) { $company->save(); return View::make('project.projectCreate'); } else { return Redirect::to('companyCreate')->withErrors($validation)->withInput(); } }
/** * Creates a new company */ public function createAction() { if (!$this->request->isPost()) { return $this->dispatcher->forward(array("controller" => "company", "action" => "index")); } $company = new Company(); $company->setId($this->request->getPost("id")); $company->setName($this->request->getPost("name")); if (!$company->save()) { foreach ($company->getMessages() as $message) { $this->flash->error($message); } return $this->dispatcher->forward(array("controller" => "company", "action" => "new")); } $this->flash->success("company was created successfully"); return $this->dispatcher->forward(array("controller" => "company", "action" => "index")); }
public function actionCreate() { if (isset($_POST['company_to_copy']) && $_POST['company_to_copy']) { $copy_data_list = array('Templates', 'Сatalog', 'ProjectStatus', 'PartStatus', 'ProjectFields', 'ProfilesFields'); $prefix = intval($_POST['company_to_copy']) . '_'; $model = new Company(); $model->organization = 1; $model->name = 'New company'; $model->domains = 'new.company.admintrix.com'; $model->language = 'en'; $model->supportEmail = '*****@*****.**'; $model->PaymentCash = 1; $model->save(); $new_prefix = $model->id . '_'; $s = strlen($prefix); $result = Yii::app()->db->createCommand('SHOW TABLES;')->queryAll(); foreach ($result as $item) { if (strpos($item[key($item)], $prefix) === 0) { $list[] = substr($item[key($item)], $s); } } foreach ($list as $table) { $sql = 'CREATE TABLE `' . $new_prefix . $table . '` LIKE `' . $prefix . $table . '`;'; Yii::app()->db->createCommand($sql)->execute(); if (in_array($table, $copy_data_list)) { $sql = 'INSERT `' . $new_prefix . $table . '` SELECT * FROM `' . $prefix . $table . '`;'; Yii::app()->db->createCommand($sql)->execute(); } } /* $sql = 'CREATE TABLE `'.$new_prefix.'Users'.'` LIKE `'.$prefix.'Users'.'`;'; Yii::app()->db->createCommand($sql)->execute(); $sql = 'CREATE TABLE `'.$new_prefix.'AuthAssignment'.'` LIKE `'.$prefix.'AuthAssignment'.'`;'; Yii::app()->db->createCommand($sql)->execute(); */ $sql = 'INSERT INTO `' . $new_prefix . 'Users` (`username`,`password`,`email`,`superuser`,`status`) VALUES ("admin","' . UserModule::encrypting('admin') . '","*****@*****.**",1,1);'; Yii::app()->db->createCommand($sql)->execute(); $sql = 'INSERT INTO `' . $new_prefix . 'AuthAssignment` (`itemname`,`userid`) VALUES ("Admin",1);'; Yii::app()->db->createCommand($sql)->execute(); $this->redirect(array('edit', 'id' => $model->id)); } $companies = Company::getList(); //Yii::app()->theme = 'admin'; $this->render('create', array('companies' => $companies)); }
/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $model = new Company(); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['Company'])) { $model->attributes = $_POST['Company']; $model->ref = Company::createRef(); if (isset($_GET['ref'])) { $ref = $_GET['ref']; $model->parent_id = Company::findParent($ref); } if ($model->save()) { $this->redirect(array('view', 'id' => $model->id)); } } $this->render('create', array('model' => $model)); }
public function storeLocation() { $advisor = Auth::user(); // If form validation passes: $location = new Company(); $location->name = Input::get('name'); if (Input::get('email')) { $location->email = Input::get('email'); } if (Input::get('website')) { $location->website = Input::get('website'); } if (Input::get('company_id')) { $location->company_id = Input::get('company_id'); } $location->advisor_id = $advisor->id; $location->save(); return Redirect::intended('advisor.dashboard'); }
protected function saveModel($company = false) { if (Input::get('id')) { $company = Company::find(Input::get('id')); } if (!$company) { $company = new Company(); } $company->name = Input::get('name'); $company->type = Input::get('type'); $company->references = Input::get('references'); $company->bank_details = Input::get('bank_details'); $company->tax_number = Input::get('tax_number'); $company->notes = Input::get('notes'); $address = $company->address()->first() ?: new Address(); $country = Country::where('id', Input::get('country'))->first(); $address->country()->associate($country); $address->address = Input::get('address_address'); $address->postal_code = Input::get('address_postal_code'); $address->city = Input::get('address_city'); $address->state_province = Input::get('address_state_province'); $address->phone = Input::get('address_phone'); $address->fax = Input::get('address_fax'); $address->email = Input::get('address_email'); $address->website = Input::get('address_website'); $address->save(); $company->address()->associate($address); $company->save(); if (Input::get('venue_id')) { $company->venues()->detach(Venue::find(Input::get('venue_id'))); $company->venues()->attach(Venue::find(Input::get('venue_id'))); } if (Input::get('contact_id')) { $company->contacts()->detach(Contact::find(Input::get('contact_id'))); $company->contacts()->attach(Contact::find(Input::get('contact_id'))); } if (Input::get('event_id')) { $company->events()->detach(Events::find(Input::get('event_id'))); $company->events()->attach(Events::find(Input::get('event_id'))); } return $company; }
function testDestroyAssociatedRecords() { $c = new Company(); $c->set(array('name' => 'destroy_test')); $c->save(); $p = new Project(); $p->set(array('company_id' => $c->id, 'name' => 'destroy_project_test')); $p->save(); $e = new Estimate(); $e->set(array('project_id' => $p->id, 'name' => 'destroy_estimate_test')); $e->save(); $h = new Hour(); $h->set(array('estimate_id' => $e->id, 'name' => 'destroy_hour_test')); $h->save(); $ch = new Charge(); $ch->set(array('company_id' => $c->id, 'name' => 'destroy_charge_test')); $ch->save(); $con = new SupportContract(); $con->set(array('company_id' => $c->id, 'name' => 'destroy_contract_test')); $con->save(); $sup_hr = new Hour(); $sup_hr->set(array('support_contract_id' => $con->id, 'description' => 'destroy_support_hour_test')); $sup_hr->save(); $pay = new Payment(); $pay->set(array('company_id' => $c->id, 'name' => 'destroy_payment_test')); $pay->save(); $deleted_items = array('company' => $c->id, 'project' => $p->id, 'estimate' => $e->id, 'hour' => $h->id, 'support_hour' => $sup_hr->id, 'charge' => $ch->id, 'support_contract' => $con->id, 'payment' => $pay->id); $c->destroyAssociatedRecords(); $c->delete(); $dbcon = AMP::getDb(); foreach ($deleted_items as $table => $id) { if ($table == 'support_hour') { $table = 'hour'; } $sql = 'SELECT * FROM ' . $table . ' WHERE id = ' . $id; if ($records = $dbcon->Execute($sql)) { $this->assertEqual($records->RecordCount(), 0, "{$table} not deleted correctly: %s"); } else { trigger_error($dbcon->ErrorMsg()); } } }
function testSendEmail() { $company = new Company(); $company->set(array('name' => 'Test Company')); $company->save(); $contact = new Contact(); $contact->set(array('first_name' => 'Testy', 'last_name' => 'test', 'email' => '*****@*****.**', 'is_billing_contact' => true, 'company_id' => $company->id)); $contact->save(); $i = new Invoice(); $i->set(array('company_id' => $company->id, 'start_date' => '2010-01-01', 'end_date' => '2010-03-31')); $i->execute(); $i->save(); # here i test sending my invoice require_once 'controller/InvoiceController.php'; $invoice_controller = new InvoiceController(); $invoice_controller->disableRedirect(); $invoice_controller->execute('email', array('id' => $i->id)); $msg = Render::_dumpMessages(); $this->assertPattern('/Email Sent/', $msg); }
public function actionCreate() { if (Yii::app()->user->role != User::POWER_ADMIN) { $this->redirect(array('company/index', 'companyId' => $this->companyId)); } $model = new Company(); $model->create_at = date('Y-m-d H:i:s'); if (Yii::app()->request->isPostRequest) { $model->attributes = Yii::app()->request->getPost('Company'); $model->create_at = date('Y-m-d H:i:s', time()); $model->update_at = date('Y-m-d H:i:s', time()); if ($model->save()) { Yii::app()->user->setFlash('success', yii::t('app', '创建成功')); $this->redirect(array('company/index', 'companyId' => $this->companyId)); } else { Yii::app()->user->setFlash('error', yii::t('app', '创建失败')); } } $printers = $this->getPrinterList(); return $this->render('create', array('model' => $model, 'printers' => $printers, 'companyId' => $this->companyId)); }
public function register() { $user = new User(); $user->first_name = $this->first_name; $user->last_name = $this->last_name; $user->email = $this->email; $user->position = $this->position; $user->phone = $this->phone; $user->password = $this->password; $user->username = $this->username; $user->role = User::ROLE_EMPL; $user->status = User::STATUS_DISABLED; $user->additional_contact = $this->additional_contact; $user->hash = md5(microtime(true) . rand()); if (!$user->save()) { $this->addError('username', 'Can`t create user ' . serialize($user->getErrors())); return false; } UserHelper::sendEmailConfirmation($user); $company = new Company(); $company->name = $this->name; $company->site_url = $this->site_url; $company->address = $this->address; $company->created_at = new CDbExpression('NOW()'); $company->updated_at = new CDbExpression('NOW()'); if (!$company->save()) { $this->addError('name', 'Can`t create company ' . serialize($company->getErrors())); return false; } $bind = new UserToCompany(); $bind->user_id = $user->id; $bind->company_id = $company->id; if (!$bind->save()) { $this->addError('name', 'Can`t bind company ' . serialize($bind->getErrors())); return false; } return true; }
public function store() { if (!$this->companyAddValidator->validate(Input::all())) { Session::flash('error_msg', Utils::buildMessages($this->companyAddValidator->getValidation()->messages()->all())); return Redirect::to('/companies/create')->withInput(); } else { try { $company = new Company(); $company->name = Input::get('name'); $company->description = Input::get('description', ''); $company->domain = Input::get('domain'); $company->user_id = Auth::user()->id; $company->logo = Input::hasFile('logo') ? Utils::imageUpload(Input::file('logo'), 'companies') : ''; $company->save(); RecentActivities::createActivity("Company <a href='/companies/all'>" . $company->name . "</a> created Company ID:" . $company->id . " by User Name " . Auth::user()->name . " User ID " . Auth::user()->id); Session::flash('success_msg', trans('msgs.company_created_success')); return Redirect::to('/companies/create')->withInput(); } catch (\Exception $e) { Session::flash('error_msg', trans('msgs.unable_to_add_company')); return Redirect::to('/companies/create')->withInput(); } } }
public static function createFakeUser($data) { $user = self::model()->findByAttributes(array('contact_phone' => $data->user_phone)); if (isset($user)) { return $user->id; } else { $user = new User(); $user->scenario = 'content'; $password = rand(1000000, 9999999); $Company = new Company(); $Company->name = $data->company_name; $Company->create = new CDbExpression('NOW()'); $Company->save(); $user->email = $data->user_email; $user->contact_phone = $data->user_phone; $user->company_id = $Company->id; $user->status = User::STATUS_ACTIVE; //Сделать автопроверку выписки $user->setAttribute('hash', Yii::app()->userManager->hasher->hashPassword($password)); if ($user->save()) { return $user->id; } } }
})); //CREATE: NEW COMPANY Route::post('/admin/company/new', array('as' => 'adminProcessNewCompany', 'uses' => function () { //return 'Save New Company'; $data = Input::all(); //return dd($data); $rules = array('company_name' => 'required'); $validator = Validator::make($data, $rules); if ($validator->fails()) { $messages = $validator->messages(); return Redirect::to('/admin/company/new')->withErrors($validator); } else { $company = new Company(); $company->name = trim(ucwords($data['company_name'])); //$company->save(); if ($company->save()) { $message = 'Created Successfully.'; return Redirect::to('/admin/company/new')->with('message', $message); } } })); //UPDATE: EXISTING COMPANY Route::get('/admin/company/edit/{id}', array('as' => 'adminEditCompany', 'uses' => function ($id) { $id = (int) $id; //return 'Update Company'; $employeeId = Session::get('userEmployeeId'); $userId = Session::get('userId'); $employee = new Employee(); $employeeInfo = $employee->getEmployeeInfoById($employeeId); return View::make('admin.companyedit', array('id' => $id, 'employeeInfo' => $employeeInfo)); //return Redirect::route('updateCompany', array('id' => $id));
function testCalculateBalanceWithDateRange() { #Company $cp = new Company(); $cp->set(array('name' => 'Test Company', 'status' => 'active')); $cp->save(); $pb = new CompanyPreviousBalance(); $pb->set(array('company_id' => $cp->id, 'amount' => 600.25, 'date' => '2010-01-30')); $pb->save(); $this->assertWithinMargin($pb->getAmount(), '600.25', '.01'); ######### Support $sc = new SupportContract(); $sc->set(array('company_id' => $cp->id, 'domain_name' => 'Test', 'start_date' => '2010-01-01', 'end_date' => '2010-04-30', 'hourly_rate' => '120', 'support_hours' => '.5', 'monthly_rate' => '50')); $sc->save(); # add support hours # before previous balance $h = new Hour(); $h->set(array('description' => 'Test', 'support_contract_id' => $sc->id, 'date' => '2010-01-20', 'hours' => '2.5')); $h->save(); # in range $h = new Hour(); $h->set(array('description' => 'Test', 'support_contract_id' => $sc->id, 'date' => '2010-02-20', 'hours' => '2.5')); $h->save(); # in range $h = new Hour(); $h->set(array('description' => 'Test', 'support_contract_id' => $sc->id, 'date' => '2010-03-20', 'hours' => '2.5')); $h->save(); # out of range $h = new Hour(); $h->set(array('description' => 'Test', 'support_contract_id' => $sc->id, 'date' => '2010-05-20', 'hours' => '2')); $h->save(); ### Support Totals = in range is 2 months x 50 = 100, 4 @ 120 = 480 = 580 $date_range = array('start_date' => '2010-01-01', 'end_date' => '2010-03-31'); $total = $cp->calculateSupportTotal($date_range); $this->assertEqual($total, 580); ###### Project $pj = new Project(); $pj->set(array('name' => 'Test Project', 'company_id' => $cp->id, 'hourly_rate' => '120')); $pj->save(); # Add an Estimate item #1 $es1 = new Estimate(); $es1->set(array('project_id' => $pj->id, 'name' => 'Test Estimate 1', 'high_hours' => '10', 'low_hours' => '5')); $es1->save(); # Add an Estimate item #2 $es2 = new Estimate(); $es2->set(array('project_id' => $pj->id, 'name' => 'Test Estimate 2', 'high_hours' => '10', 'low_hours' => '5')); $es2->save(); # Add some before previous balance hours for #1 - 5 hours at 120 = 600 $hr = new Hour(); $hr->set(array('estimate_id' => $es1->id, 'description' => 'Test Hours for Estimate 1', 'date' => '2010-01-15', 'hours' => '5')); $hr->save(); # Add some in range hours for #1 - 5 hours at 120 = 600 $hr = new Hour(); $hr->set(array('estimate_id' => $es1->id, 'description' => 'Test Hours for Estimate 1', 'date' => '2010-02-15', 'hours' => '5')); $hr->save(); # Add some in range hours for #2 - 5 hours at 120 = 600 $hr = new Hour(); $hr->set(array('estimate_id' => $es2->id, 'description' => 'Test Hours for Estimate 2', 'date' => '2010-02-15', 'hours' => '5')); $hr->save(); # Add some out of range hours for #2 - 5 hours at 120 = 600 $hr = new Hour(); $hr->set(array('estimate_id' => $es2->id, 'description' => 'Test Hours for Estimate 2', 'date' => '2010-05-15', 'hours' => '5')); $hr->save(); ## Project Totals = In range 1200, out of range 1800 $date_range = array('start_date' => '2010-01-01', 'end_date' => '2010-03-31'); $total = $cp->calculateProjectsTotal($date_range); $this->assertEqual($total, 1200); #Charge # before previous balance $cr = new Charge(); $cr->set(array('name' => 'Test', 'company_id' => $cp->id, 'date' => '2010-01-10', 'amount' => '20.50')); $cr->save(); # in date range $cr = new Charge(); $cr->set(array('name' => 'Test', 'company_id' => $cp->id, 'date' => '2010-03-14', 'amount' => '50.25')); $cr->save(); # in date range $cr = new Charge(); $cr->set(array('name' => 'Test', 'company_id' => $cp->id, 'date' => '2010-03-20', 'amount' => '50')); $cr->save(); # out of date range $cr = new Charge(); $cr->set(array('name' => 'Test', 'company_id' => $cp->id, 'date' => '2010-05-15', 'amount' => '50')); $cr->save(); # Total Charges = in range 100.25, out of range 150.25 $date_range = array('start_date' => '2010-01-01', 'end_date' => '2010-03-31'); $charge_total = $cp->calculateChargesTotal($date_range); $this->assertEqual($charge_total, 100.25); ## Test Total Costs # Charges 100.25 + project 1200 + support 580 $date_range = array('start_date' => '2010-01-01', 'end_date' => '2010-03-31'); $total = $cp->calculateCosts($date_range); $this->assertEqual($total, 1880.25); ## Payments # add payment before previous balance date $py = new Payment(); $py->set(array('company_id' => $cp->id, 'date' => '2010-01-22', 'amount' => '20.50')); $py->save(); # add payment in range $py = new Payment(); $py->set(array('company_id' => $cp->id, 'date' => '2010-02-10', 'amount' => '20.00')); $py->save(); # add payment in range $py = new Payment(); $py->set(array('company_id' => $cp->id, 'date' => '2010-03-01', 'amount' => '120.00')); $py->save(); # add payment out of range $py = new Payment(); $py->set(array('company_id' => $cp->id, 'date' => '2010-04-01', 'amount' => '20.25')); $py->save(); # Total Payments are 20 + 120 = 140 in range and after previous balance $date_range = array('start_date' => '2010-01-01', 'end_date' => '2010-03-31'); $payment_total = $cp->calculatePaymentsTotal($date_range); $this->assertEqual($payment_total, 140); #### fails because the previous balance isn't getting included FIX ME!! # Total Balance Costs 1880.25 - Payments 140 + Previous balance 600.25 = 2340.5 $date_range = array('start_date' => '2010-01-01', 'end_date' => '2010-03-31'); $balance = $cp->calculateBalance($date_range); $this->assertWithinMargin($balance, 2340.5, 0.001); ## clean up $cp->destroyAssociatedRecords(); $cp->delete(); }
<?php require_once dirname(__FILE__).'/../bootstrap/bootstrap.php'; Doctrine_Query::create()->from('Company')->delete()->execute(); $company = new Company(); $company->name = 'Company Name 1'; $company->created_at = date('Y-m-d', strtotime('-2 months')); $company->save(); $browser = new sfTestFunctionalTheme(new sfBrowser()); $browser->info('1. - Test generated module show action') ->runTask('sfThemeGenerateTask', array('theme' => 'hadori'), array('application' => 'frontend', 'model' => 'Company', 'module' => 'company')) ->get('/company') ->isModuleAction('company', 'index') ->click(sprintf('#company_%s .actions .show', $company['id'])) ->isModuleAction('company', 'show') ->with('response')->begin() ->matches(sprintf('/%s/', $company['name'])) ->matches(sprintf('/%s/', $company['created_at'])) ->end() ;
public function actionUpload() { parent::actionUpload(); $folder = $_SERVER['DOCUMENT_ROOT'] . Yii::app()->request->baseUrl . '/upload/'; // folder for uploaded files $file = $folder . basename($_FILES['uploadfile']['name']); if (move_uploaded_file($_FILES['uploadfile']['tmp_name'], $file)) { $row = 0; if (($handle = fopen($file, "r")) !== FALSE) { while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) { if ($row > 0) { $model = Company::model()->findByPk((int) $data[0]); if ($model === null) { $model = new Company(); } $model->companyid = (int) $data[0]; $model->companyname = $data[1]; $model->address = $data[2]; $city = City::model()->findbyattributes(array('cityname' => $data[3])); if ($city !== null) { $model->cityid = $city->cityid; } $model->zipcode = $data[4]; $model->taxno = $data[5]; $currency = Currency::model()->findbyattributes(array('currencyname' => $data[6])); if ($currency !== null) { $model->currencyid = $currency->currencyid; } $model->recordstatus = (int) $data[7]; try { if (!$model->save()) { $this->messages = $this->messages . Catalogsys::model()->getcatalog(' upload error at ' . $data[0]); } } catch (Exception $e) { $this->messages = $this->messages . $e->getMessage(); } } $row++; } } else { $this->messages = $this->messages . ' memory or harddisk full'; } fclose($handle); } else { $this->messages = $this->messages . ' check your directory permission'; } if ($this->messages == '') { $this->messages = 'success'; } echo $this->messages; }
/** * 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->aCategory !== null) { if ($this->aCategory->isModified() || $this->aCategory->isNew()) { $affectedRows += $this->aCategory->save($con); } $this->setCategory($this->aCategory); } if ($this->aElementStatus !== null) { if ($this->aElementStatus->isModified() || $this->aElementStatus->isNew()) { $affectedRows += $this->aElementStatus->save($con); } $this->setElementStatus($this->aElementStatus); } if ($this->aCompany !== null) { if ($this->aCompany->isModified() || $this->aCompany->isNew()) { $affectedRows += $this->aCompany->save($con); } $this->setCompany($this->aCompany); } if ($this->isNew()) { $this->modifiedColumns[] = ElementPeer::ID; } // If this object has been modified, then save it to the database. if ($this->isModified()) { if ($this->isNew()) { $pk = ElementPeer::doInsert($this, $con); $affectedRows += 1; // we are assuming that there is only 1 row per doInsert() which // should always be true here (even though technically // BasePeer::doInsert() can insert multiple rows). $this->setId($pk); //[IMV] update autoincrement primary key $this->setNew(false); } else { $affectedRows += ElementPeer::doUpdate($this, $con); } $this->resetModified(); // [HL] After being saved an object is no longer 'modified' } if ($this->collPreferences !== null) { foreach ($this->collPreferences as $referrerFK) { if (!$referrerFK->isDeleted()) { $affectedRows += $referrerFK->save($con); } } } if ($this->collOrders !== null) { foreach ($this->collOrders as $referrerFK) { if (!$referrerFK->isDeleted()) { $affectedRows += $referrerFK->save($con); } } } if ($this->collElementFiles !== null) { foreach ($this->collElementFiles as $referrerFK) { if (!$referrerFK->isDeleted()) { $affectedRows += $referrerFK->save($con); } } } $this->alreadyInSave = false; } return $affectedRows; }
<?php require_once dirname(__FILE__).'/../bootstrap/bootstrap.php'; Doctrine_Query::create()->from('Company')->delete()->execute(); $company1 = new Company(); $company1->name = 'AAA Company'; $company1->created_at = date('Y-m-d', strtotime('-2 months')); $company1->save(); $company2 = new Company(); $company2->name = 'ZZZ Company'; $company2->save(); $browser = new sfTestFunctionalHadori(new sfBrowser()); $browser->info('1. - Test generated module filter actions') ->runTask('sfThemeGenerateTask', array('theme' => 'hadori'), array('application' => 'frontend', 'model' => 'Company', 'module' => 'company')) ->setGeneratorConfigValue('company', array('list' => array('display' => array('name', 'city', 'state', 'zip', 'created_at')))) ->get('/company') ->isModuleAction('company', 'index') ->with('response')->begin() ->matches(sprintf('/%s.*%s/s', $company1['name'], $company2['name'])) ->end() ->info('Filter by name - ASC')
public function syncContacts() { // Title $title = 'Moneybird Contact Sync'; $mContacts = $this->getContacts(); foreach ($mContacts as $mContact) { $contact = Company::whereHas('meta', function ($query) use($mContact) { $query->where('type', 'moneybird')->where('subtype', 'contact')->where('key', 'id')->where('value', $mContact->id); })->first(); if (!$contact) { $contact = new Company(); } $contact->fill(['bedrijfsnaam' => $mContact->companyName, 'voornaam' => $mContact->firstname, 'achternaam' => $mContact->lastname, 'ter_attentie_van' => $mContact->contactName, 'adres_1' => $mContact->address1, 'adres_2' => $mContact->address2, 'postcode' => $mContact->zipcode, 'plaats' => $mContact->city, 'land' => $mContact->country, 'email' => $mContact->email, 'telefoon' => $mContact->phone, 'btw_nummer' => $mContact->taxNumber, 'kvk_nummer' => $mContact->chamberOfCommerce, 'rekening_nummer' => $mContact->sepaIban]); $contact->save(); $customerId = CompanyMeta::firstOrNew(['company_id' => $contact->id, 'type' => 'moneybird', 'subtype' => 'contact', 'key' => 'customerid']); $customerId->value = $mContact->customerId; $customerId->save(); $id = CompanyMeta::firstOrNew(['company_id' => $contact->id, 'type' => 'moneybird', 'subtype' => 'contact', 'key' => 'id']); $id->value = $mContact->id; $id->save(); $contact->meta()->saveMany([$customerId, $id]); } Session::flash('success', 'Contacts succesfully synced'); return View::make('admin/integrations/moneybird/index', compact('title', 'body')); }